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.
added the rocket-pool-node-operator-v7 strategy (snapshot-labs#1532)
- Loading branch information
1 parent
a867f38
commit def4606
Showing
4 changed files
with
102 additions
and
0 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,13 @@ | ||
# rocketpool-node-operator-delegate-v7 | ||
|
||
This is a strategy for node operators, it returns the vote power for a node address. | ||
|
||
Here is an example of parameters: | ||
|
||
```json | ||
{ | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
``` |
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,27 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "rocketpool-node-operator-v7", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xc942B5aA63A3410a13358a7a3aEdF33d9e9D3AC3", | ||
"0x9Fe9FfbfD57ab78D4d01973482258bfC4BB70bE3", | ||
"0x57767D8000859535431Fbc57EBFEc43FD0515902", | ||
"0x8fBfD009C4B6a99EDD7a1b9561e696A98b6E48dC", | ||
"0xDe506279b3704064Ee5ED2Fcf5515b7629eDAB1D", | ||
"0x48ee0aBAe316499E6d9375671c4B6AE406bd288B", | ||
"0x07f771B6C79b3F86E12585580654A946448A9020", | ||
"0xF912051684b910FFA7972aDa6E8c1EC46CBBE075", | ||
"0x0e973A3757ed841EfbBE4139a7d52a5EebDa03DB", | ||
"0x427d42983CC65d27e83A2Df5815b46F1F55e6445" | ||
], | ||
"snapshot": 20309057 | ||
} | ||
] |
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,60 @@ | ||
import { Multicaller } from '../../utils'; | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
|
||
export const author = 'rocket-pool'; | ||
export const version = '0.1.7'; | ||
|
||
const rocketNetworkVoting = '0xA9d27E1952f742d659143a544d3e535fFf3Eebe1'; | ||
const rocketNetworkVotingAbi = [ | ||
'function getVotingPower(address _nodeAddress, uint32 _block) external view returns (uint256)' | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = | ||
typeof snapshot === 'number' ? snapshot : await provider.getBlockNumber(); | ||
|
||
const nodeVotingPower = new Multicaller( | ||
network, | ||
provider, | ||
rocketNetworkVotingAbi, | ||
{ blockTag } | ||
); | ||
|
||
addresses.forEach((address) => { | ||
nodeVotingPower.call(address, rocketNetworkVoting, 'getVotingPower', [ | ||
address, | ||
blockTag | ||
]); | ||
}); | ||
|
||
const nodeVotingPowerResponse: Record<string, BigNumberish> = | ||
await nodeVotingPower.execute(); | ||
|
||
const merged = addresses.map((address) => { | ||
const votePower = nodeVotingPowerResponse[address]; | ||
return { | ||
address: address, | ||
votePower: votePower | ||
}; | ||
}); | ||
|
||
const reduced: Record<string, BigNumberish> = merged.reduce((acc, obj) => { | ||
acc[obj.address] = obj.votePower; | ||
return acc; | ||
}, {}); | ||
|
||
return Object.fromEntries( | ||
Object.entries(reduced).map(([address, votePower]) => [ | ||
address, | ||
parseFloat(formatUnits(votePower, options.decimals)) | ||
]) | ||
); | ||
} |