Skip to content

Commit

Permalink
[snx-multichain] fix v3 collateral voting power (#1594)
Browse files Browse the repository at this point in the history
* fix: snx-multichain v3 collateral voting power

* iterate over all snx v3 account tokens

* throw if failing on v3 collateral query

* fix lint
  • Loading branch information
barrasso authored Sep 27, 2024
1 parent 101c2ba commit d08d943
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/strategies/snx-multichain/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"addresses": [
"0x27Cc4d6bc95b55a3a981BF1F1c7261CDa7bB0931",
"0xcb68110C43C97b6051FEd5e2Bacc2814aDaD1688",
"0xB08dd71c47Cb8c00E2155C1f12877F0e7d17B449",
"0xf07A2439296e07Bc4320AF924E655a01fb69D89C",
"0x99F4176EE457afedFfCB1839c7aB7A030a5e4A92"
],
"snapshot": 16000000
"snapshot": 20000000
}
]
31 changes: 17 additions & 14 deletions src/strategies/snx-multichain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const COLLATERAL_TYPES = {
};

const accountProxyABI = [
'function balanceOf(address account) view returns (uint256)',
'function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)'
];

Expand Down Expand Up @@ -95,31 +96,33 @@ export async function strategy(
provider
);

// Select the appropriate collateralType based on the network
const collateralType = COLLATERAL_TYPES[network];

let totalCollateral = 0;

try {
// Check the number of tokens owned by the address
// Check if the user has a v3 account
const balance = await accountProxy.balanceOf(address);
if (balance.eq(0)) {
return { [address]: 0 };
}

// Use only the first account (index 0)
const accountId = await accountProxy.tokenOfOwnerByIndex(address, 0);

// Select the appropriate collateralType based on the network
const collateralType = COLLATERAL_TYPES[network];
// Iterate over all accounts based on their token balance
for (let i = 0; i < balance.toNumber(); i++) {
// Fetch the accountId at each index
const accountId = await accountProxy.tokenOfOwnerByIndex(address, i);

// Fetch only the totalDeposited value for the account ID
const { totalDeposited } = await coreProxy.getAccountCollateral(
accountId,
collateralType
);
// Fetch only the totalDeposited value for the account ID
const { totalDeposited } = await coreProxy.getAccountCollateral(
accountId,
collateralType
);

totalCollateral = totalDeposited;
totalCollateral += Number(totalDeposited) / 1e18;
}
} catch (err) {
// Assume the account doesn't exist and continue.
// console.log(`Error fetching v3 collateral for address ${address}:`, err);
throw new Error(`Error fetching v3 collateral for ${address}: ${err}`);
}

return { [address]: totalCollateral };
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/subgraph-split-delegation/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
],
"snapshot": 6716841
}
]
]
12 changes: 3 additions & 9 deletions src/strategies/subgraph-split-delegation/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@
"type": "object"
}
},
"required": [
"name",
"params"
]
"required": ["name", "params"]
}
}
},
"required": [
"subgraphUrl",
"strategies"
],
"required": ["subgraphUrl", "strategies"],
"additionalProperties": false
}
}
}
}

0 comments on commit d08d943

Please sign in to comment.