forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"1": { | ||
"key": "1", | ||
"name": "In Memory Ethereum Mainnet", | ||
"chainId": 33133, | ||
"network": "homestead", | ||
"multicall": "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0", | ||
"rpc": [ | ||
{ | ||
"url": "http://localhost:8545/" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { StaticJsonRpcProvider } from '@ethersproject/providers'; | ||
import set from 'lodash.set'; | ||
import { multicall } from '../utils'; | ||
|
||
export default class Multicaller { | ||
public network: string; | ||
public provider: StaticJsonRpcProvider; | ||
public abi: any[]; | ||
public options: any = {}; | ||
public calls: any[] = []; | ||
public paths: any[] = []; | ||
|
||
constructor( | ||
network: string, | ||
provider: StaticJsonRpcProvider, | ||
abi: any[], | ||
options? | ||
) { | ||
this.network = network; | ||
this.provider = provider; | ||
this.abi = abi; | ||
this.options = options || {}; | ||
} | ||
|
||
call(path, address, fn, params?): Multicaller { | ||
this.calls.push([address, fn, params]); | ||
this.paths.push(path); | ||
return this; | ||
} | ||
|
||
async execute(from?: any): Promise<any> { | ||
const obj = from || {}; | ||
const result = await multicall( | ||
this.network, | ||
this.provider, | ||
this.abi, | ||
this.calls, | ||
this.options | ||
); | ||
result.forEach((r, i) => set(obj, this.paths[i], r.length > 1 ? r : r[0])); | ||
this.calls = []; | ||
this.paths = []; | ||
return obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function loadNetworks() { | ||
const networksFile = | ||
process.env['npm_config_networks_file'] || | ||
process.argv | ||
.find((arg) => arg.includes('--networks-file')) | ||
?.split('--networks-file') | ||
?.pop(); | ||
|
||
if (networksFile === undefined) { | ||
return require('@snapshot-labs/snapshot.js/src/networks.json'); | ||
} else { | ||
try { | ||
return require(networksFile); | ||
} catch (e) { | ||
throw new Error('Cannot find networks file: ' + networksFile); | ||
} | ||
} | ||
} | ||
|
||
const networks = loadNetworks(); | ||
|
||
module.exports = networks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters