-
Notifications
You must be signed in to change notification settings - Fork 831
Add IntegralDAO strategy [integral-dao] #1122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sumomoliu
wants to merge
7
commits into
snapshot-labs:master
Choose a base branch
from
sumomoliu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3dfee00
Add IntegralDAO strategy
sumomoliu 1de68d9
Fixed not latest blockTag
sumomoliu 80d384c
Merge branch 'master' into master
sumomoliu fbfccde
Merge branch 'master' into master
sumomoliu e51deb3
Add contract size limit
sumomoliu 8c69966
Merge branch 'master' into master
sumomoliu 3f772bd
Merge branch 'master' into master
sumomoliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
[ | ||
{ | ||
"name": "Integral vote weighting strategy", | ||
"strategy": { | ||
"name": "integral-dao", | ||
"params": { | ||
"symbol": "ITGR", | ||
"contractAddresses": [ | ||
"0xd502f487e1841fdc805130e13eae80c61186bc98", | ||
"0x36bD665392236b20bd42e161f02Bf0ae1d9441Ff", | ||
"0xFFc0EAC1a1aE79C697607229Aca43Ef422625a40" | ||
], | ||
"decimals": 18, | ||
"pageSize": 100 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x39C6F54b47c1CCB896221EB5e4e24765108Cf145", | ||
"0x013f107eb48401b1a58607d7bb37127ce075002c", | ||
"0x6b174b2f42dae970fed64cfa61cd0b993d59ef66", | ||
"0x02b2d6a3298a4b20aa4f7a0a57e920e9fc9ad864", | ||
"0xD222674ee29F588Fad1633E850b513b64b0350a9", | ||
"0x384f28360caabd007e27c872b95e63302bf2492f", | ||
"0x6b879dd45cf492b0950e4ac94f2657d811341169", | ||
"0x671e53a32573ab447796bbc6b98b9c166f960fe8", | ||
"0xaef031994435202aa92e1c1f3289d07a89b8ae54", | ||
"0x5bbe5c40af27dbe17adb4cf24a4793d4dbff5614", | ||
"0x430a5965bcee916b7629353be63f0ba9f9fdb18b", | ||
"0xc16f2313e360c53803f728bbd3a798048f656c52", | ||
"0x8f49f0eb2b30ef269dc22b44bdead34c81887e7b" | ||
], | ||
"snapshot": 13569183 | ||
} | ||
] |
This file contains hidden or 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,61 @@ | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'ken'; | ||
export const version = '0.1.0'; | ||
|
||
const abi = [ | ||
'function getCurrentVotes(address account) external view returns (uint96)' | ||
]; | ||
|
||
async function getVotes( | ||
multi: any, | ||
addresses: string[], | ||
contractAddress: string, | ||
decimals: number | ||
) { | ||
addresses.forEach((address) => { | ||
multi.call(address, contractAddress, 'getCurrentVotes', [address]); | ||
}); | ||
const result: Record<string, BigNumberish> = await multi.execute(); | ||
return Object.fromEntries( | ||
Object.entries(result).map(([address, balance]) => [ | ||
address, | ||
parseFloat(formatUnits(balance, decimals)) | ||
]) | ||
); | ||
} | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
if (options.contractAddresses.length > 5) { | ||
throw new Error('Contract number exceed limit 5'); | ||
} | ||
const results = await Promise.all( | ||
options.contractAddresses.map((contractAddress) => | ||
getVotes( | ||
new Multicaller(network, provider, abi, { blockTag }), | ||
addresses, | ||
contractAddress, | ||
options.decimals | ||
) | ||
) | ||
); | ||
|
||
return results.slice(1).reduce((acc, result) => { | ||
Object.keys(result).forEach((address) => { | ||
if (acc[address]) { | ||
acc[address] += result[address]; | ||
} | ||
}); | ||
return acc; | ||
}, results[0]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.