-
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.
- Loading branch information
Showing
18 changed files
with
205 additions
and
34 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
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,43 @@ | ||
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(`${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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/Strategy", | ||
"definitions": { | ||
"Strategy": { | ||
"title": "Strategy", | ||
"type": "object", | ||
"properties": { | ||
"symbol": { | ||
"type": "string", | ||
"title": "Symbol", | ||
"examples": ["e.g. UNI"], | ||
"maxLength": 16 | ||
}, | ||
"address": { | ||
"type": "string", | ||
"title": "Contract address", | ||
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
"pattern": "^0x[a-fA-F0-9]{40}$", | ||
"minLength": 42, | ||
"maxLength": 42 | ||
}, | ||
"tokenId": { | ||
"type": "string", | ||
"title": "Token ID", | ||
"examples": ["e.g. 1, 0x8"], | ||
"maxLength": 100 | ||
}, | ||
"decimals": { | ||
"type": "number", | ||
"title": "Decimals", | ||
"examples": ["e.g. 18"], | ||
"minimum": 0 | ||
} | ||
}, | ||
"required": ["address", "tokenId", "decimals"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
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,11 @@ | ||
# erc20-votes strategy | ||
|
||
This strategy gets voting power from compound like contracts, it uses `getVotes` function to get the voting power of an address. | ||
|
||
## Params | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
|`address`|`string`|The address of the contract to get the voting power from| | ||
|`symbol`|`string`|The symbol of the token| | ||
|`decimals`|`number`|The decimals of the token| |
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,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/Strategy", | ||
"definitions": { | ||
"Strategy": { | ||
"title": "Strategy", | ||
"type": "object", | ||
"properties": { | ||
"symbol": { | ||
"type": "string", | ||
"title": "Symbol", | ||
"examples": ["e.g. ENS"], | ||
"maxLength": 16 | ||
}, | ||
"address": { | ||
"type": "string", | ||
"title": "Contract address", | ||
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
"pattern": "^0x[a-fA-F0-9]{40}$", | ||
"minLength": 42, | ||
"maxLength": 42 | ||
}, | ||
"decimals": { | ||
"type": "integer", | ||
"title": "Decimals", | ||
"examples": ["e.g. 18"], | ||
"minimum": 0, | ||
"maximum": 18 | ||
} | ||
}, | ||
"required": ["address"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
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
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
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
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
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