Skip to content

Commit

Permalink
[balance-in-vdfyn-vault] Added vdfyn strategy (snapshot-labs#70)
Browse files Browse the repository at this point in the history
* added vdfyn strategy

* Update README.md

Co-authored-by: Vatsal Gupta <[email protected]>
  • Loading branch information
vatsalgupta13 and Vatsal Gupta authored Sep 20, 2021
1 parent 3cf07eb commit ea08f07
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/strategies/balance-in-vdfyn-vault/README.md
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"
}
]
}],
]
}
```
53 changes: 53 additions & 0 deletions src/strategies/balance-in-vdfyn-vault/examples.json
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
}
]
44 changes: 44 additions & 0 deletions src/strategies/balance-in-vdfyn-vault/index.ts
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))])
);
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as contractCall from './contract-call';
import * as dextfVaults from './dextf-staked-in-vaults';
import * as dfynFarms from './dfyn-staked-in-farms';
import * as dfynVaults from './dfyn-staked-in-vaults';
import * as vDfynVault from './balance-in-vdfyn-vault';
import * as ensDomainsOwned from './ens-domains-owned';
import * as ensReverseRecord from './ens-reverse-record';
import * as erc20BalanceOf from './erc20-balance-of';
Expand Down Expand Up @@ -157,6 +158,7 @@ const strategies = {
sunder,
'balancer-smart-pool': balancerSmartPool,
'balancer-erc20-internal-balance-of': balancerErc20InternalBalanceOf,
'balance-in-vdfyn-vault': vDfynVault,
'erc20-received': erc20Received,
'contract-call': contractCall,
'dextf-staked-in-vaults': dextfVaults,
Expand Down

0 comments on commit ea08f07

Please sign in to comment.