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-v4 strategy (snapshot-labs#1516)
- Loading branch information
1 parent
3eb851c
commit 28bd4e1
Showing
4 changed files
with
100 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-v4 | ||
|
||
This is a strategy for staking 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,24 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "rocketpool-node-operator-v4", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x7ba728C1D84c2313F319D267fD9847F2CEA8D758", | ||
"0xC76DCF5ed10555C417d3c85aF987F2b7D2f63415", | ||
"0xb74006917f66E4b7f005713f061d1f20Ef2A029C", | ||
"0x3b6d43E181BeFCE59732De6098cADF7f35b97b1e", | ||
"0xB0De8cB8Dcc8c5382c4b7F3E978b491140B2bC55", | ||
"0x4F44C1226eb9d13ae5941dEd9cC1e6a4E099a68f", | ||
"0x2d2BfE2389B7b3779fa04d101f75a89F6A62DcD6" | ||
], | ||
"snapshot": 20172818 | ||
} | ||
] |
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,61 @@ | ||
import { Multicaller } from '../../utils'; | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
|
||
export const author = 'rocket-pool'; | ||
export const version = '0.1.4'; | ||
|
||
const rocketNetworkVoting = '0xA9d27E1952f742d659143a544d3e535fFf3Eebe1'; | ||
const rocketNetworkVotingAbi = [ | ||
'function getVotingPower(address _nodeAddress, uint32 _block) external view returns (uint256)' | ||
]; | ||
|
||
|
||
Check failure on line 13 in src/strategies/rocketpool-node-operator-v4/index.ts GitHub Actions / lint / Lint
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
|
||
Check failure on line 22 in src/strategies/rocketpool-node-operator-v4/index.ts GitHub Actions / lint / Lint
|
||
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, | ||
Check failure on line 46 in src/strategies/rocketpool-node-operator-v4/index.ts GitHub Actions / lint / Lint
|
||
}; | ||
}); | ||
|
||
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)) | ||
]) | ||
); | ||
} |