Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 0fbe989

Browse files
committed
feat: erc20-balance-starknet strategy
1 parent 95492d0 commit 0fbe989

5 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# erc20-balance-starknet
2+
3+
This strategy returns the balance of the voters for a specific Starknet ERC20 token.
4+
5+
Here is an example of parameters:
6+
7+
```json
8+
{
9+
"address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
10+
"symbol": "ETH",
11+
"decimals": 18
12+
}
13+
```
14+
15+
List of tokens and its details can be found on https://starkscan.co/top-tokens
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"name": "Top STRK Holders's balance",
4+
"strategy": {
5+
"name": "erc20-balance-of",
6+
"params": {
7+
"address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
8+
"symbol": "STRK",
9+
"decimals": 18
10+
}
11+
},
12+
"network": "1",
13+
"addresses": [
14+
"0x00ca1702e64c81d9a07b86bd2c540188d92a2c73cf5cc0e508d949015e7e84a7",
15+
"0x076601136372fcdbbd914eea797082f7504f828e122288ad45748b0c8b0c9696",
16+
"0x04164013f90b05d67f026779bf96e9c401c96f3485b645a786166e6935fba116",
17+
"0x0620102ea610be8518125cf2de850d0c4f5d0c5d81f969cff666fb53b05042d2",
18+
"0x04098bc6868cc52385b33ebcc7ede01ff6e6bc2ee7f1da6bebece088ee23f6c2",
19+
"0x032cfb78d9f64ece832b7f868253c232f085a374365d0ed859ee0164a2ac0588",
20+
"0x059a943ca214c10234b9a3b61c558ac20c005127d183b86a99a8f3c60a08b4ff",
21+
"0x02a67f5ab24f4354755dbc4ab684ba6d5c1520ea45aad99f4e7a9f996ced075d",
22+
"0x07cd150a7a0b45b5f413e56e45964c7ecdd665dca029d1bc8bdae7d4b71470fd",
23+
"0x0480eeffbc7f47d92e72fa330883c17f6fb34f109c0d6ccc6aaebb88ea393071",
24+
"0x0294e0596df21f2eb007a898cc1492a58aaee07de9ffcb95532dc0182153397d",
25+
"0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
26+
"0x069a7818562b608ce8c5d0039e7f6d1c6ee55f36978f633b151858d85c022d2f",
27+
"0x048f1578bdca1a208441e1c58982c2789c8d3a4e7f56690bb8f1838db439d0dc",
28+
"0x044716d416ff66f83a4c3ac811d713cf256017f6906d3412b976ae1f4f35af36",
29+
"0x002f96a7f4baf4d6e59534cd1614973778c205f419bbcb513c20fa1b717e8fde",
30+
"0x0213c67ed78bc280887234fe5ed5e77272465317978ae86c25a71531d9332a2d",
31+
"0x07dddb7d3a1321a854691e736f951704deaf33bde78c49a32e9e7e8e8a1e9537"
32+
],
33+
"snapshot": 1459522
34+
}
35+
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { BigNumberish } from '@ethersproject/bignumber';
2+
import { formatUnits } from '@ethersproject/units';
3+
import { Multicaller } from '../../utils';
4+
5+
export const author = 'waOx6e';
6+
export const version = '0.O.1';
7+
8+
const abi = [
9+
{
10+
name: 'balanceOf',
11+
type: 'function',
12+
inputs: [
13+
{
14+
name: 'account',
15+
type: 'core::starknet::contract_address::ContractAddress'
16+
}
17+
],
18+
outputs: [
19+
{
20+
type: 'core::integer::u256'
21+
}
22+
],
23+
state_mutability: 'view'
24+
}
25+
];
26+
27+
export async function strategy(
28+
space: string,
29+
network: string,
30+
provider,
31+
addresses: string[],
32+
options: { address: string; decimals: number; symbol?: string },
33+
snapshot: 'latest' | number
34+
): Promise<Record<string, number>> {
35+
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
36+
37+
const multi = new Multicaller(network, provider, abi, { blockTag });
38+
addresses.forEach((voterAddress) =>
39+
multi.call(voterAddress, options.address, 'balanceOf', [voterAddress])
40+
);
41+
const result: Record<string, BigNumberish> = await multi.execute();
42+
43+
return Object.fromEntries(
44+
Object.entries(result).map(([address, balance]) => [
45+
address,
46+
parseFloat(formatUnits(balance, options.decimals))
47+
])
48+
);
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/Strategy",
4+
"definitions": {
5+
"Strategy": {
6+
"title": "Strategy",
7+
"type": "object",
8+
"properties": {
9+
"symbol": {
10+
"type": "string",
11+
"title": "Symbol",
12+
"examples": ["e.g. STRK"],
13+
"maxLength": 16
14+
},
15+
"address": {
16+
"type": "string",
17+
"title": "Contract address",
18+
"examples": ["e.g. 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"],
19+
"pattern": "^0x[a-fA-F0-9]{64}$",
20+
"minLength": 66,
21+
"maxLength": 66,
22+
"errorMessage": "Must be a valid lowercase and padded Starknet contract address"
23+
},
24+
"decimals": {
25+
"type": "number",
26+
"title": "Decimals",
27+
"examples": ["e.g. 18"],
28+
"minimum": 0
29+
}
30+
},
31+
"required": ["address", "decimals"],
32+
"additionalProperties": false
33+
}
34+
}
35+
}

src/strategies/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as erc20BalanceOfWithDelegation from './erc20-balance-of-with-delegatio
3636
import * as erc20BalanceOfQuadraticDelegation from './erc20-balance-of-quadratic-delegation';
3737
import * as erc20BalanceOfTopHolders from './erc20-balance-of-top-holders';
3838
import * as erc20BalanceOfWeighted from './erc20-balance-of-weighted';
39+
import * as erc20BalanceStarknet from './erc20-balance-starknet';
3940
import * as ethalendBalanceOf from './ethalend-balance-of';
4041
import * as prepoVesting from './prepo-vesting';
4142
import * as erc20BalanceOfIndexed from './erc20-balance-of-indexed';
@@ -539,6 +540,7 @@ const strategies = {
539540
'erc20-balance-of-top-holders': erc20BalanceOfTopHolders,
540541
'erc20-balance-of-weighted': erc20BalanceOfWeighted,
541542
'erc20-balance-of-indexed': erc20BalanceOfIndexed,
543+
'erc20-balance-starknet': erc20BalanceStarknet,
542544
'erc20-price': erc20Price,
543545
'ethalend-balance-of': ethalendBalanceOf,
544546
'balance-of-with-min': balanceOfWithMin,

0 commit comments

Comments
 (0)