Skip to content

Commit

Permalink
feat(dappcomposer-getvotingunits) added strategies (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
sokardys authored Feb 6, 2025
1 parent d15969e commit 92da69c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/strategies/dappcomposer-getvotingunits/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"name": "dAppComposer query",
"strategy": {
"name": "dappcomposer-getvotingunits",
"params": {
"address": "0xBcAA291f9b84A8B8dA02584F79587cCaEDfFE38a",
"decimals": 18
}
},
"network": "11155111",
"addresses": [
"0x890a8A5B2e0335a22DdB0a2Bd991f079591ff44C",
"0xC16A3fE7F94E8e55Dd50c8848380093fEA5aa714",
"0x6Fb67e33D101465065C87734a563731aB8c30bB1"
],
"snapshot": 7594600
},
{
"name": "dAppComposer query",
"strategy": {
"name": "dappcomposer-getvotingunits",
"params": {
"address": "0xBcAA291f9b84A8B8dA02584F79587cCaEDfFE38a",
"decimals": 18
}
},
"network": "11155111",
"addresses": [
"0x890a8A5B2e0335a22DdB0a2Bd991f079591ff44C",
"0xC16A3fE7F94E8e55Dd50c8848380093fEA5aa714",
"0x6Fb67e33D101465065C87734a563731aB8c30bB1"
],
"snapshot": 6456459
}
]
48 changes: 48 additions & 0 deletions src/strategies/dappcomposer-getvotingunits/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { Multicaller } from '../../utils';
import { formatUnits } from '@ethersproject/units';

export const author = 'tutellus';
export const version = '0.1.0';
export const name = 'dappcomposer-getvotingunits';

const veTokenABI = [
'function getVotingUnits(address account) public view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const blockTag = typeof snapshot === 'number' ? snapshot : undefined;

// Initialize Multicaller
const multi = new Multicaller(network, provider, veTokenABI, { blockTag });

// Third batch: Get voting power for each token
addresses.forEach((address) => {
multi.call(

Check failure on line 28 in src/strategies/dappcomposer-getvotingunits/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `⏎······`${address}`,⏎······options.address,⏎······'getVotingUnits',⏎······[address]⏎····` with ``${address}`,·options.address,·'getVotingUnits',·[address]`
`${address}`,
options.address,
'getVotingUnits',
[address]
);
});

const voteByTokenIds: Record<string, BigNumberish> = await multi.execute();

// Calculate final scores
const scores = {};
addresses.forEach((address) => {
let totalVotingPower = 0;
const power = voteByTokenIds[address];
totalVotingPower += Number(formatUnits(power, options.decimals || 18));
scores[address] = totalVotingPower;
});

return scores;
}
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ import * as realt from './realt';
import * as superfluidVesting from './superfluid-vesting';
import * as spookyLpSonic from './spooky-lp-sonic';
import * as synapse from './synapse';
import * as dappcomposerGetVotingUnits from './dappcomposer-getvotingunits';

const strategies = {
'spooky-lp-sonic': spookyLpSonic,
Expand Down Expand Up @@ -958,7 +959,8 @@ const strategies = {
'lizcoin-strategy-2024': lizcoinStrategy2024,
realt,
'superfluid-vesting': superfluidVesting,
synapse
synapse,
'dappcomposer-getvotingunits': dappcomposerGetVotingUnits,

Check failure on line 963 in src/strategies/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `,`
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down

0 comments on commit 92da69c

Please sign in to comment.