Skip to content

Commit

Permalink
added the rocket-pool-node-operator-v4 strategy (snapshot-labs#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdoherty authored Jun 26, 2024
1 parent 3eb851c commit 28bd4e1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ import * as auraBalanceOfSingleAsset from './aura-vault-balance-of-single-asset'
import * as rocketpoolNodeOperator from './rocketpool-node-operator';
import * as rocketpoolNodeOperatorv2 from './rocketpool-node-operator-v2';
import * as rocketpoolNodeOperatorv3 from './rocketpool-node-operator-v3';
import * as rocketpoolNodeOperatorv4 from './rocketpool-node-operator-v4';
import * as earthfundChildDaoStakingBalance from './earthfund-child-dao-staking-balance';
import * as unipilotVaultPilotBalance from './unipilot-vault-pilot-balance';
import * as sdBoostTWAVP from './sd-boost-twavp';
Expand Down Expand Up @@ -736,6 +737,7 @@ const strategies = {
'rocketpool-node-operator': rocketpoolNodeOperator,
'rocketpool-node-operator-v2': rocketpoolNodeOperatorv2,
'rocketpool-node-operator-v3': rocketpoolNodeOperatorv3,
'rocketpool-node-operator-v4': rocketpoolNodeOperatorv4,
'earthfund-child-dao-staking-balance': earthfundChildDaoStakingBalance,
'sd-boost-twavp': sdBoostTWAVP,
'unipilot-vault-pilot-balance': unipilotVaultPilotBalance,
Expand Down
13 changes: 13 additions & 0 deletions src/strategies/rocketpool-node-operator-v4/README.md
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
}
```
24 changes: 24 additions & 0 deletions src/strategies/rocketpool-node-operator-v4/examples.json
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
}
]
61 changes: 61 additions & 0 deletions src/strategies/rocketpool-node-operator-v4/index.ts
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

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `⏎`

Check failure on line 13 in src/strategies/rocketpool-node-operator-v4/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `⏎`
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

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `⏎··const·blockTag·=` with `··const·blockTag·=⏎···`

Check failure on line 22 in src/strategies/rocketpool-node-operator-v4/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `⏎··const·blockTag·=` with `··const·blockTag·=⏎···`
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

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `,`

Check failure on line 46 in src/strategies/rocketpool-node-operator-v4/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `,`
};
});

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))
])
);
}

0 comments on commit 28bd4e1

Please sign in to comment.