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 erc20-balance-of-pcape #1283

Open
wants to merge 3 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
13 changes: 13 additions & 0 deletions src/strategies/erc20-balance-of-pcape/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# erc20-balance-of-pcape

This is the most common strategy, it returns the balances of the voters for a specific ERC20 token.

Here is an example of parameters:

```json
{
"address": "0x8383B691ffE89BA6915d2458648BDD515DE7202D",
"symbol": "pcAPE",
"decimals": 18
}
```
48 changes: 48 additions & 0 deletions src/strategies/erc20-balance-of-pcape/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"name": "pcAPE query",
"strategy": {
"name": "erc20-balance-of-pcape",
"params": {
"address": "0x8383B691ffE89BA6915d2458648BDD515DE7202D",
"symbol": "pcAPE",
"decimals": 18
}
},
"network": "1",
"addresses": [
"0xfec29ac8a954317e4c27449506db469e20119d24",
"0xcc026bd03311c37f11900ca4f552e7f733a5e022",
"0x8f26d3c449e4685c9b472a80514f12e8bb497837",
"0xf4a89c75ee829926c492fee034a5a8236a757598",
"0x50c0946a0562d3f9dd63d34199889d7fc2ef4974",
"0x3538480926dc87947756091fa9d5d550f3bcda7b",
"0xb5a07049e03e7a2f016f52e146fc6beea7e321f5",
"0xc7a26ca791d2b9448ed33889f861eb849cea0c8c",
"0xf7598c34cd39a2bfea3865d711d9301450113bc3",
"0x66a2fdc7b9a0d16913dfb1d779bc61ea4d39e60a",
"0x4f690b3b2c9316be7bb0355045819809764178e4",
"0x83ede5881f280aacb5c863cefb53771fd7e4f4d9",
"0x4496678922007c367504d50b16d6a7cdf303c7d1",
"0xb913251da5371b8d641e7ad084777aaf737a4170",
"0xbdea17fef43b51df3f62bfb968ad350a35cf041a",
"0xfd9f0bf2a0236e998ab2524a19ab34b64ea52eab",
"0x8b1f70a60f402652d857abec7f86ee510a5472df",
"0xdc2b2ce1396a32acca5886f1cbce04556176b01b",
"0xc776a6ae36f5db33ee47923ff6c0949938903e4d",
"0x3dc57748b1375907cbb7a8cf9210cd2a4a577b7b",
"0x5c1ca6ac33800f6f88e3c46099271b304ca6f366",
"0x350eb0576d8d1fece46259fb2ca91a99853ad15e",
"0xd0d4f4faa1404a7604aa0a34bfb27f5bc8ee4a38",
"0xd74170150175fae8161140f1f16cf3099899e0e5",
"0x243f07a74efe77bec4f1a5eb3e542d2783755b8d",
"0x9327f858ee0f65f275d46794152e5d8d1ea8bbee",
"0xa33f323009d006b2d2edd55e773ae1125dfa32fd",
"0x42b823865349e67a145037f904057c0c3bfa07ff",
"0x499822a60f18cf1692fb328907ed0b7d46c48d0f",
"0x8b3b2f3e62268c6d2226fbee94adb36e056a9e62",
"0x260643d41d1dffebfc8c79a28c79e1c22d913c4c"
],
"snapshot": 18174560
}
]
34 changes: 34 additions & 0 deletions src/strategies/erc20-balance-of-pcape/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

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

const abi = [
'function balanceOf(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, options.address, 'balanceOf', [address])
);
const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, options.decimals))
])
);
}
33 changes: 33 additions & 0 deletions src/strategies/erc20-balance-of-pcape/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$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. pcAPE"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x8383B691ffE89BA6915d2458648BDD515DE7202D"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"decimals": {
"type": "number",
"title": "Decimals",
"examples": ["e.g. 18"]
}
},
"required": ["address", "decimals"],
"additionalProperties": false
}
}
}