Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Balance of At Scaled as well as erc721 collateral held #1327

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/strategies/erc721-collateral-held/index.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @publu One PR should contain changes of one strategy only.

Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ export async function strategy(

// get the vault number owned by each user.
const multi2 = new Multicaller(network, provider, abi, { blockTag });
const tokenIds: Record<string, BigNumberish[]> = Object.fromEntries(
addresses.map((address) => [address, []])
);
const tokenIds: Record<string, BigNumberish[]> = Object.fromEntries(addresses.map((address) => [address, []]));
for (const address of addresses) {
const balance = result[address];
for (let i = 0; i < balance; i++) {
multi2.call(`${address}_${i}`, options.address, 'tokenOfOwnerByIndex', [
address,
i
]);
multi2.call(`${address}_${i}`, options.address, 'tokenOfOwnerByIndex', [address, i]);
}
}
const tokenIdsResult = await multi2.execute();

for (const key in tokenIdsResult) {
const [address] = key.split('_');
const [address,] = key.split('_');
tokenIds[address].push(tokenIdsResult[key]);
}

Expand All @@ -61,9 +56,7 @@ export async function strategy(
const resultWithDefault = {};
for (const address of addresses) {
const balance = collaterals[address] || 0;
resultWithDefault[address] = parseFloat(
formatUnits(balance, options.decimals)
);
resultWithDefault[address] = parseFloat(formatUnits(balance, options.decimals));
}

// Convert addresses to checksum format before returning
Expand Down
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ import * as spacey2025 from './spacey2025';
import * as sandmanDao from './sandman-dao';
import * as ethercatsFounderSeries from './ethercats-founder-series';
import * as veBalanceOfAt from './ve-balance-of-at';
import * as veBalanceOfAtScaled from './ve-balance-of-at-scaled';
import * as veRibbon from './ve-ribbon';
import * as veRibbonVotingPower from './ve-ribbon-voting-power';
import * as chubbykaijudao from './chubbykaijudao';
Expand Down Expand Up @@ -791,6 +792,7 @@ const strategies = {
'sandman-dao': sandmanDao,
'ethercats-founder-series': ethercatsFounderSeries,
've-balance-of-at': veBalanceOfAt,
've-balance-of-at-scaled': veBalanceOfAtScaled,
've-ribbon': veRibbon,
've-ribbon-voting-power': veRibbonVotingPower,
chubbykaijudao: chubbykaijudao,
Expand Down
16 changes: 16 additions & 0 deletions src/strategies/ve-balance-of-at-scaled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ve-balance-of-at-scaled

This strategy returns the voting power of the voters for a ve-like token by calling `balanceOfAt` on the contract and then scales the result by a provided scale factor.

Here is an example of parameters:

```json
{
"address": "0x1bffabc6dfcafb4177046db6686e3f135e8bc732",
"symbol": "aveQI",
"decimals": 18,
"scaleValue": 1
}
```

The `scaleValue` parameter is used to scale the result of the `balanceOfAt` call. For example, if `scaleValue` is 1, the result is not scaled. If `scaleValue` is 0.01, the result is scaled down by a factor of 100.
22 changes: 22 additions & 0 deletions src/strategies/ve-balance-of-at-scaled/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "Example query",
"strategy": {
"name": "ve-balance-of-at-scaled",
"params": {
"address": "0x1bffabc6dfcafb4177046db6686e3f135e8bc732",
"symbol": "aveQI",
"decimals": 18,
"scaleValue": 4
}
},
"network": "1",
"addresses": [
"0x55C1568eFD6D19Edec498330952fA7e582FEA20A",
"0xc06320d9028F851c6cE46e43F04aFF0A426F446c",
"0x044325aCCB1A131cD00B4Cef674E9a8d9b60ad72",
"0x680963fe5e628c5486C3A282ca12Aa575820e446"
],
"snapshot": 18383737
}
]
35 changes: 35 additions & 0 deletions src/strategies/ve-balance-of-at-scaled/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'publu';
export const version = '0.0.1';

const abi = [
'function balanceOfAt(address _user,uint256 _blockNumber) external view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag =
typeof snapshot === 'number' ? snapshot : await provider.getBlockNumber();

const multi = new Multicaller(network, provider, abi);
addresses.forEach((address) =>
multi.call(address, options.address, 'balanceOfAt', [address, blockTag])
);
const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, options.decimals)) * options.scaleValue
])
);
Comment on lines +20 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could you math strategy for this @publu let me know if you have some trouble doing so :)

}
35 changes: 35 additions & 0 deletions src/strategies/ve-balance-of-at-scaled/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"symbol": {
"type": "string",
"title": "Symbol",
"examples": ["e.g. aveQI"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x1bffabc6dfcafb4177046db6686e3f135e8bc732"]
},
"decimals": {
"type": "number",
"title": "Decimals",
"examples": ["e.g. 18"]
},
"scaleValue": {
"type": "number",
"title": "Scale Value",
"examples": ["e.g. 4"]
}
},
"required": ["address", "decimals", "scaleValue"],
"additionalProperties": false
}
}
}
Loading