Skip to content

Commit

Permalink
Add erc20-votes strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bonustrack committed Nov 3, 2021
1 parent cf0daa1 commit 28bd810
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/strategies/digitalax-lp-stakers/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"0xa59ba4eebfbd28e5a61dea4b9bcf358320e8d53b",
"0xaa3e5ee4fdc831e5274fe7836c95d670dc2502e6",
"0xea41cd3f972db6237ffa2918df9199b547172420",
"0xbfd5493b94ead64d3dcada5700dbee9409acc345"],
"0xbfd5493b94ead64d3dcada5700dbee9409acc345"
],
"snapshot": 13526042
}
]
3 changes: 1 addition & 2 deletions src/strategies/digitalax-mona-quickswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { subgraphRequest } from '../../utils';
import { strategy as erc20BalanceOfStrategy } from '../erc20-balance-of';


export const author = 'onigiri-x';
export const version = '0.1.0';

Expand Down Expand Up @@ -45,7 +44,7 @@ export async function strategy(
: monaReserve.pair.totalSupply;

return Object.fromEntries(
addresses.map(address => [
addresses.map((address) => [
address,
(erc20Balances[address] * monaReserve.pair.reserve0) / totalLPSupply
])
Expand Down
5 changes: 1 addition & 4 deletions src/strategies/erc20-balance-of-weighted/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export async function strategy(
snapshot
);
return Object.fromEntries(
Object.entries(scores).map((score) => [
score[0],
score[1] * options.weight
])
Object.entries(scores).map((score) => [score[0], score[1] * options.weight])
);
}
18 changes: 18 additions & 0 deletions src/strategies/erc20-votes/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "Example query",
"strategy": {
"name": "erc20-votes",
"params": {
"address": "0xc00e94cb662c3520282e6f5717214004a7f26888",
"symbol": "ENS"
}
},
"network": "1",
"addresses": [
"0x2B384212EDc04Ae8bB41738D05BA20E33277bf33",
"0xAC5720d6EE2d7872b88914C9c5Fa9BF38e72FaF6"
],
"snapshot": 12050071
}
]
35 changes: 35 additions & 0 deletions src/strategies/erc20-votes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { formatUnits } from '@ethersproject/units';
import { multicall } from '../../utils';

export const author = 'bonustrack';
export const version = '0.1.0';

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

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const response = await multicall(
network,
provider,
abi,
addresses.map((address: any) => [
options.address,
'getVotes',
[address.toLowerCase()]
]),
{ blockTag }
);
return Object.fromEntries(
response.map((value, i) => [
addresses[i],
parseFloat(formatUnits(value.toString(), options.decimals))
])
);
}
4 changes: 2 additions & 2 deletions src/strategies/galaxy-nft-with-score/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"params": {
"symbol": "GLX",
"params": {
"nftCoreAddresses":["0x0966a53f2533EaF01D0bB2fa0E2274f3002287F1"],
"nftCoreAddresses": ["0x0966a53f2533EaF01D0bB2fa0E2274f3002287F1"],
"chain": "ETHEREUM",
"configs":[
"configs": [
{
"name": "Woofster",
"weight": 5,
Expand Down
80 changes: 42 additions & 38 deletions src/strategies/galaxy-nft-with-score/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import fetch from 'cross-fetch'
import fetch from 'cross-fetch';

export const author = 'alberthaotan'
export const version = '0.1.0'
export const author = 'alberthaotan';
export const version = '0.1.0';

const GALAXY_GRAPHQL_URL = 'https://graphigo.prd.galaxy.eco/query'
const GALAXY_GRAPHQL_URL = 'https://graphigo.prd.galaxy.eco/query';

interface Config {
name: string,
weight: number,
cumulative: boolean
name: string;
weight: number;
cumulative: boolean;
}

interface OwnerWithNfts {
owner: string,
owner: string;
nfts: {
id: string,
name: string
}[]
id: string;
name: string;
}[];
}

interface OwnerToNftCount {
[owner: string]: {
[name: string]: number
}
[name: string]: number;
};
}

interface OwnerToScore {
[owner: string]: number
[owner: string]: number;
}

export async function strategy(
Expand All @@ -37,10 +37,10 @@ export async function strategy(
options,
snapshot
) {
let fetchRes = await fetch(GALAXY_GRAPHQL_URL, {
const fetchRes = await fetch(GALAXY_GRAPHQL_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
operationName: 'allNFTsByOwnersCoresAndChain',
Expand All @@ -60,38 +60,42 @@ export async function strategy(
chain: options.params.chain,
owners: addresses
}
},
}),
})
}
})
});

let fetchData = await fetchRes.json()
let ownersWithNfts: OwnerWithNfts[] = fetchData.data.allNFTsByOwnersCoresAndChain
let configs: Config[] = options.params.configs
let ownerToNftCount: OwnerToNftCount = Object.fromEntries(addresses.map(addr => [addr, {}]))
let ownerToScore: OwnerToScore = {}
const fetchData = await fetchRes.json();
const ownersWithNfts: OwnerWithNfts[] =
fetchData.data.allNFTsByOwnersCoresAndChain;
const configs: Config[] = options.params.configs;
const ownerToNftCount: OwnerToNftCount = Object.fromEntries(
addresses.map((addr) => [addr, {}])
);
const ownerToScore: OwnerToScore = {};

ownersWithNfts.forEach(ownerWithNfts => {
ownerWithNfts.nfts.forEach(nft => {
ownersWithNfts.forEach((ownerWithNfts) => {
ownerWithNfts.nfts.forEach((nft) => {
if (nft.name in ownerToNftCount[ownerWithNfts.owner]) {
ownerToNftCount[ownerWithNfts.owner][nft.name]++
ownerToNftCount[ownerWithNfts.owner][nft.name]++;
} else {
ownerToNftCount[ownerWithNfts.owner][nft.name] = 1
ownerToNftCount[ownerWithNfts.owner][nft.name] = 1;
}
})
})
});
});

Object.keys(ownerToNftCount).forEach(owner => {
ownerToScore[owner] = 0
configs.forEach(config => {
Object.keys(ownerToNftCount).forEach((owner) => {
ownerToScore[owner] = 0;
configs.forEach((config) => {
if (config.name in ownerToNftCount[owner]) {
if (config.cumulative) {
ownerToScore[owner] += config.weight * ownerToNftCount[owner][config.name]
ownerToScore[owner] +=
config.weight * ownerToNftCount[owner][config.name];
} else {
ownerToScore[owner] += config.weight * 1
ownerToScore[owner] += config.weight * 1;
}
}
})
})
});
});

return ownerToScore
return ownerToScore;
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from 'fs';
import path from 'path';
import * as erc20Votes from './erc20-votes';
import * as antiWhale from './anti-whale';
import * as balancer from './balancer';
import * as balancerErc20InternalBalanceOf from './balancer-erc20-internal-balance-of';
Expand Down Expand Up @@ -194,6 +195,7 @@ const strategies = {
'ens-domains-owned': ensDomainsOwned,
'ens-reverse-record': ensReverseRecord,
'erc20-balance-of': erc20BalanceOf,
'erc20-votes': erc20Votes,
'erc20-balance-of-fixed-total': erc20BalanceOfFixedTotal,
'erc20-balance-of-cv': erc20BalanceOfCv,
'erc20-balance-of-coeff': erc20BalanceOfCoeff,
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/mcb-balance-from-graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function strategy(
options,
snapshot
) {
const _addresses = addresses.map(x => x.toLowerCase())
const _addresses = addresses.map((x) => x.toLowerCase());
const addressSubsets = Array.apply(
null,
Array(Math.ceil(_addresses.length / LIMIT))
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/radicle-community-tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function strategy(
snapshot
): Promise<Record<string, number>> {
let params = {};
let fundingProject = options.fundingProject;
const fundingProject = options.fundingProject;
const mainField: string = fundingProject ? 'fundingProjects' : 'nfts';

if (fundingProject) {
Expand Down

0 comments on commit 28bd810

Please sign in to comment.