Skip to content

Commit

Permalink
added the rocket-pool-node-operator-v7 strategy (snapshot-labs#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdoherty authored Jul 16, 2024
1 parent a867f38 commit def4606
Show file tree
Hide file tree
Showing 4 changed files with 102 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 @@ -294,6 +294,7 @@ 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 rocketpoolNodeOperatorv7 from './rocketpool-node-operator-v7';
import * as rocketpoolNodeOperatorDelegatev4 from './rocketpool-node-operator-delegate-v4';
import * as rocketpoolNodeOperatorDelegatev5 from './rocketpool-node-operator-delegate-v5';
import * as rocketpoolNodeOperatorDelegatev6 from './rocketpool-node-operator-delegate-v6';
Expand Down Expand Up @@ -742,6 +743,7 @@ const strategies = {
'rocketpool-node-operator-v2': rocketpoolNodeOperatorv2,
'rocketpool-node-operator-v3': rocketpoolNodeOperatorv3,
'rocketpool-node-operator-v4': rocketpoolNodeOperatorv4,
'rocketpool-node-operator-v7': rocketpoolNodeOperatorv7,
'rocketpool-node-operator-delegate-v4': rocketpoolNodeOperatorDelegatev4,
'rocketpool-node-operator-delegate-v5': rocketpoolNodeOperatorDelegatev5,
'rocketpool-node-operator-delegate-v6': rocketpoolNodeOperatorDelegatev6,
Expand Down
13 changes: 13 additions & 0 deletions src/strategies/rocketpool-node-operator-v7/README.md
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
}
```
27 changes: 27 additions & 0 deletions src/strategies/rocketpool-node-operator-v7/examples.json
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
}
]
60 changes: 60 additions & 0 deletions src/strategies/rocketpool-node-operator-v7/index.ts
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))
])
);
}

0 comments on commit def4606

Please sign in to comment.