forked from snapshot-labs/snapshot.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tranche staking strategy (snapshot-labs#154)
* Added package-lock.json * Added the tranche-staking strategy * Updated author and reverted changes in package-lock.json
- Loading branch information
1 parent
9d2b132
commit a0adc54
Showing
3 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "tranche-staking", | ||
"params": { | ||
"address": "0x5ce49f584257606426498bfd16d770c50bb20254", | ||
"tokenAddress": "0x0AeE8703D34DD9aE107386d3eFF22AE75Dd616D1", | ||
"symbol": "SLICE", | ||
"decimals": 18, | ||
"start": 12113995 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xd2ddb0e1c223a873c77ee80497e9d82c1002e483", | ||
"0xbfdc3fe26553ac0c6041c1e6e0081f95b8c824b3" | ||
], | ||
"snapshot": 12114000 | ||
} | ||
] |
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,58 @@ | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { multicall } from '../../utils'; | ||
|
||
export const author = 'ayush-jibrel'; | ||
export const version = '0.1.0'; | ||
|
||
const abi = [ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
internalType: 'address', | ||
name: 'user', | ||
type: 'address' | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'token', | ||
type: 'address' | ||
} | ||
], | ||
name: 'balanceOf', | ||
outputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: '', | ||
type: 'uint256' | ||
} | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function' | ||
} | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
const response = await multicall( | ||
network, | ||
provider, | ||
abi, | ||
addresses.map((address: any) => [options.address, 'balanceOf', [address, options.tokenAddress]]), | ||
{ blockTag } | ||
); | ||
return Object.fromEntries( | ||
response.map((value, i) => [ | ||
addresses[i], | ||
parseFloat(formatUnits(value.toString(), options.decimals)) | ||
]) | ||
); | ||
} |