forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[occ-stake-of] New strategy for OCC token stake balance (snapshot-lab…
…s#72) * Addition of OCC stake balance strategy * Field name consistency
- Loading branch information
Showing
4 changed files
with
82 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
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,15 @@ | ||
# occ-stake-of | ||
|
||
This is the OCC staking strategy, it returns the OCC staking balances of the voters. | ||
|
||
Here is an example of parameters: | ||
|
||
```json | ||
{ | ||
"stakingContractAddress": [ | ||
"0xeBC86Fb12ab0fFaC6CBcaFCe2f049BfE7eFAda0D" | ||
], | ||
"symbol": "OCC", | ||
"decimals": 18 | ||
} | ||
``` |
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,28 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "occ-stake-of", | ||
"params": { | ||
"stakingContractAddress": [ | ||
"0xeBC86Fb12ab0fFaC6CBcaFCe2f049BfE7eFAda0D" | ||
], | ||
"symbol": "OCC", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xa95f8f54dc55281852b5c972e4874264c7b5d3de", | ||
"0x77752aE2Cb765BDd09568E69B740a2276187F052", | ||
"0xd3aecf9e0856822bd320873e905ae9f78a2977e7", | ||
"0x2C2ADD1C863551A0644876be227604C8E458dD7e", | ||
"0x8af630f68dd02c589b9449158455735814b452a3", | ||
"0x252e2e0e4cc5bd7391acb47634fb6bb382d08586", | ||
"0x4bf455074e67848dc7e1c55b45a32aafca2e9c9c", | ||
"0xb623964e5761C1b04A4a46b9aE8D1809dEFa7efB" | ||
], | ||
"snapshot": 12381658 | ||
} | ||
] | ||
|
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 @@ | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'OccamFi'; | ||
export const version = '0.1.0'; | ||
|
||
const abi = [ | ||
'function getStake(address user) public view returns (uint stake)' | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
const multi = new Multicaller(network, provider, abi, { blockTag }); | ||
|
||
addresses.forEach((address) => | ||
multi.call(address, options.stakingContractAddress[0], 'getStake', [address]) | ||
); | ||
|
||
const result: Record<string, BigNumberish> = await multi.execute(); | ||
|
||
return Object.fromEntries( | ||
Object.entries(result).map(([address, stake]) => [ | ||
address, | ||
parseFloat(formatUnits(stake, options.decimals)) | ||
]) | ||
); | ||
} |