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.
[balance-in-vdfyn-vault] Added vdfyn strategy (snapshot-labs#70)
* added vdfyn strategy * Update README.md Co-authored-by: Vatsal Gupta <[email protected]>
- Loading branch information
1 parent
3cf07eb
commit ea08f07
Showing
4 changed files
with
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# vDfyn contract call strategy | ||
|
||
This strategy allows users to calculate the total amount of Dfyn staked by the user in the vDfyn vault. | ||
|
||
## Example | ||
|
||
The space config will look like this: | ||
|
||
```JSON | ||
{ | ||
"strategies": [ | ||
["balance-in-vdfyn-vault", { | ||
// vDfyn vault contract | ||
"contractAddress": "0x75455c3DE45dD32CBE9a5aD5E518D3D50823c976", | ||
// scoreMultiplier can be used to increase users' scores by a certain magnitude | ||
"scoreMultiplier": 2, | ||
// ABI for balanceOf method | ||
"methodABI": [ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "account", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "ratio", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "dfynAmount_", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
}], | ||
] | ||
} | ||
``` |
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,53 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "balance-in-vdfyn-vault", | ||
"params": { | ||
"name": "vDfyn Vault", | ||
"contractAddress": "0x75455c3DE45dD32CBE9a5aD5E518D3D50823c976", | ||
"scoreMultiplier": 1, | ||
"methodABI": [ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "account", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "ratio", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "dfynAmount_", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
} | ||
}, | ||
"network": "137", | ||
"addresses": [ | ||
"0x41CdE29bF9aea095fDD204D150451678b2c6A736", | ||
"0xD7B26f34775fa41D6dCE182851642573aBF9B532" | ||
], | ||
"snapshot": 19310208 | ||
} | ||
] |
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,44 @@ | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { call, multicall } from '../../utils'; | ||
|
||
export const author = 'vatsalgupta13'; | ||
export const version = '0.1.0'; | ||
|
||
function chunk(array, chunkSize) { | ||
const tempArray: any[] = []; | ||
for (let i = 0, len = array.length; i < len; i += chunkSize) | ||
tempArray.push(array.slice(i, i + chunkSize)); | ||
return tempArray; | ||
} | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
let callData: [any, string, [any]][] = []; | ||
const ratio = await call(provider, options.methodABI, [options.contractAddress, 'ratio', []]) | ||
console.log('ratio: ', ratio.toString()) | ||
addresses.map((userAddress: any) => { | ||
callData.push([options.contractAddress, 'balanceOf', [userAddress]]); | ||
}); | ||
callData = [...chunk(callData, 2000)]; // chunking the callData into multiple arrays of 2000 requests | ||
let response: any[] = []; | ||
for (let i = 0; i < callData.length; i++) { | ||
const tempArray = await multicall( | ||
network, | ||
provider, | ||
options.methodABI, | ||
callData[i], | ||
{ blockTag } | ||
); | ||
response.push(...tempArray); | ||
} | ||
return Object.fromEntries( | ||
response.map((value, i) => [addresses[i], options.scoreMultiplier * ratio * parseFloat(formatUnits(value.toString(), 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