-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dappcomposer-getvotingunits) added strategies (#1689)
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
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
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 | ||
} | ||
] |
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,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
|
||
`${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; | ||
} |
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