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

feat: add token-locker-weight #1623

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10,062 changes: 10,062 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"jest": "^29.7.0",
"prettier": "^2.7.1",
"ts-jest": "^29.1.0",
"typescript": "^4.7.4"
Expand Down
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ import * as moxie from './moxie';
import * as stakingAmountDurationLinear from './staking-amount-duration-linear';
import * as stakingAmountDurationExponential from './staking-amount-duration-exponential';
import * as sacraSubgraph from './sacra-subgraph';
import * as tokenLockerWeight from './token-locker-weight';

const strategies = {
'delegatexyz-erc721-balance-of': delegatexyzErc721BalanceOf,
Expand Down Expand Up @@ -934,7 +935,8 @@ const strategies = {
moxie: moxie,
'staking-amount-duration-linear': stakingAmountDurationLinear,
'staking-amount-duration-exponential': stakingAmountDurationExponential,
'sacra-subgraph': sacraSubgraph
'sacra-subgraph': sacraSubgraph,
'token-locker-weight': tokenLockerWeight
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
13 changes: 13 additions & 0 deletions src/strategies/token-locker-weight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ve-asf

This strategy returns the veASF balance in token locker of the voters (it actually returns the weight)

Here is an example of parameters:

```json
{
"address": "0xF119B5Aa93a7755b09952B3a88D04cdAf5329034",
"symbol": "veASF",
"decimals": 1
}
```
20 changes: 20 additions & 0 deletions src/strategies/token-locker-weight/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "Example query",
"strategy": {
"name": "token-locker-weight",
"params": {
"address": "0xF119B5Aa93a7755b09952B3a88D04cdAf5329034",
"symbol": "veASF",
"decimals": 1
}
},
"network": "1",
"addresses": [
"0x288adAe4E3639DD1f4a558E8636BD15F998Ae2C1",
"0x4f9ccE86D68Ee24275B9A2EDfC4eF52bd5e5b87c",
"0x318d0059efE546b5687FA6744aF4339391153981"
],
"snapshot": 21112712
}
]
36 changes: 36 additions & 0 deletions src/strategies/token-locker-weight/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'johnnyonline';
export const version = '0.1.1';

const TOKEN_LOCKER = '0xF119B5Aa93a7755b09952B3a88D04cdAf5329034';

const abi = [
'function getAccountWeight(address account) external view returns (uint256)'
];

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

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

return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, options.decimals))
])
Copy link
Member

Choose a reason for hiding this comment

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

Hi @johnnyonline You can use the contract-call strategy directly on your space instead of a new strategy. you tried?

Copy link
Author

Choose a reason for hiding this comment

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

Hi ser no i did not - how would i do it? Not sure i understand.

Copy link
Member

Choose a reason for hiding this comment

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

In your space settings you can select a contract-call and change the args accordingly

Copy link
Author

Choose a reason for hiding this comment

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

Done here ser 0fca9ad

Copy link
Member

Choose a reason for hiding this comment

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

No i mean while adding a strategy in your space settings, you can select contract-call strategy https://docs.snapshot.org/user-guides/spaces/settings#voting-strategies

Copy link
Author

Choose a reason for hiding this comment

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

Oh, you mean we don't need a custom strategy here (?). Did not understand that, ok.

);
}
34 changes: 34 additions & 0 deletions src/strategies/token-locker-weight/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$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. UNI"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"decimals": {
"type": "number",
"title": "Decimals",
"examples": ["e.g. 18"],
"minimum": 0
}
},
"required": ["address", "decimals"],
"additionalProperties": false
}
}
}
Loading