diff --git a/src/strategies/balancer-erc20-internal-balance-of/index.ts b/src/strategies/balancer-erc20-internal-balance-of/index.ts index f75fc8a3c..b3a808a2d 100644 --- a/src/strategies/balancer-erc20-internal-balance-of/index.ts +++ b/src/strategies/balancer-erc20-internal-balance-of/index.ts @@ -5,7 +5,9 @@ import { Multicaller } from '../../utils'; export const author = 'gerrrg'; export const version = '0.0.1'; -const abi = ['function getInternalBalance(address user, address[] tokens) external view returns (uint256[] balances)']; +const abi = [ + 'function getInternalBalance(address user, address[] tokens) external view returns (uint256[] balances)' +]; export async function strategy( space, @@ -19,7 +21,10 @@ export async function strategy( const multi = new Multicaller(network, provider, abi, { blockTag }); addresses.forEach((address) => - multi.call(address, options.vault, 'getInternalBalance', [address, [options.token]]) + multi.call(address, options.vault, 'getInternalBalance', [ + address, + [options.token] + ]) ); const result: Record = await multi.execute(); diff --git a/src/strategies/coordinape/README.md b/src/strategies/coordinape/README.md new file mode 100644 index 000000000..a318bd020 --- /dev/null +++ b/src/strategies/coordinape/README.md @@ -0,0 +1,11 @@ +# Coordinape + +Use Coordinape circle epoch tokens as voting power. + +Here is an example of parameters: +```json +{ + "symbol": "CIRCLE", + "circle": "92" +} +``` diff --git a/src/strategies/coordinape/examples.json b/src/strategies/coordinape/examples.json new file mode 100644 index 000000000..181bc2a5a --- /dev/null +++ b/src/strategies/coordinape/examples.json @@ -0,0 +1,19 @@ +[ + { + "name": "Example query", + "strategy": { + "name": "coordinape", + "params": { + "symbol": "CIRCLE", + "circle": "92" + } + }, + "network": "1", + "addresses": [ + "0x823b92d6a4b2AED4b15675c7917c9f922ea8ADAD", + "0xd337fccaec6ea113baacca3a41eb8766706a0706", + "0xeF8305E140ac520225DAf050e2f71d5fBcC543e7" + ], + "snapshot": 13219000 + } +] diff --git a/src/strategies/coordinape/index.ts b/src/strategies/coordinape/index.ts new file mode 100644 index 000000000..629d381c5 --- /dev/null +++ b/src/strategies/coordinape/index.ts @@ -0,0 +1,36 @@ +import fetch from 'cross-fetch'; +import { getAddress } from '@ethersproject/address'; + +export const author = 'bonustrack'; +export const version = '0.1.0'; + +export async function strategy( + space, + network, + provider, + addresses, + options, + snapshot +) { + const url = `https://coordinape.me/api/${options.circle}/token-gifts?latest_epoch=1&snapshot=${snapshot}`; + const res = await fetch(url, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + } + }); + const gifts = await res.json(); + const scores = {}; + gifts.forEach(gift => { + const address = getAddress(gift.recipient_address); + if (!scores[address]) scores[address] = 0; + scores[address] += gift.tokens; + }); + return Object.fromEntries( + addresses.map(address => [ + address, + scores[getAddress(address)] || 0 + ]) + ); +} diff --git a/src/strategies/crucible-erc20-balance-of/index.ts b/src/strategies/crucible-erc20-balance-of/index.ts index 04357117b..f92a9ecea 100644 --- a/src/strategies/crucible-erc20-balance-of/index.ts +++ b/src/strategies/crucible-erc20-balance-of/index.ts @@ -85,7 +85,7 @@ export async function strategy( walletIDToCrucibleAddresses )) { callCrucibleToLpBalance.call(walletID, options.erc20_address, 'balanceOf', [ - hexZeroPad(crucibleAddress.toHexString(), 20) + hexZeroPad(crucibleAddress.toHexString(), 20) ]); } const walletIDToLpBalance: Record< diff --git a/src/strategies/delegation/index.ts b/src/strategies/delegation/index.ts index c529398a8..9aff4f04b 100644 --- a/src/strategies/delegation/index.ts +++ b/src/strategies/delegation/index.ts @@ -39,7 +39,7 @@ export async function strategy( addresses.map((address) => { const addressScore = delegations[address] ? delegations[address].reduce( - (a, b) => a + scores.reduce((x, y) => y[b] ? (x + y[b]) : x, 0), + (a, b) => a + scores.reduce((x, y) => (y[b] ? x + y[b] : x), 0), 0 ) : 0; diff --git a/src/strategies/dfyn-staked-in-farms/index.ts b/src/strategies/dfyn-staked-in-farms/index.ts index 64d1ac1bf..91c63ab5e 100644 --- a/src/strategies/dfyn-staked-in-farms/index.ts +++ b/src/strategies/dfyn-staked-in-farms/index.ts @@ -5,12 +5,11 @@ import { subgraphRequest } from '../../utils'; export const author = 'vatsalgupta13'; export const version = '0.1.0'; - -const DFYN_SUBGRAPH_URL = "https://api.thegraph.com/subgraphs/name/ss-sonic/dfyn-v5" +const DFYN_SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/ss-sonic/dfyn-v5'; const getAllLP = async (skip, stakedLP, snapshot) => { - let params = - { + const params = { pairs: { __args: { where: { @@ -25,45 +24,51 @@ const getAllLP = async (skip, stakedLP, snapshot) => { totalSupply: true, token0: { id: true, - symbol: true, + symbol: true }, token1: { id: true, - symbol: true, + symbol: true } } - } + }; if (snapshot !== 'latest') { // @ts-ignore params.pairs.__args.block = { number: snapshot }; } try { - const response = await subgraphRequest(DFYN_SUBGRAPH_URL, params) + const response = await subgraphRequest(DFYN_SUBGRAPH_URL, params); return response.pairs; } catch (error) { console.error(error); } -} +}; const getLP = async (stakedLP, snapshot) => { - let lp = [] - let results = [] + let lp = []; + let results = []; do { results = await getAllLP(lp.length, stakedLP, snapshot); - lp = lp.concat(results) + lp = lp.concat(results); } while (results.length === 1000); - return lp -} + return lp; +}; function chunk(array, chunkSize) { - let tempArray: any[] = []; + const tempArray: any[] = []; for (let i = 0, len = array.length; i < len; i += chunkSize) tempArray.push(array.slice(i, i + chunkSize)); return tempArray; } -function calcTokenBalance(user_lp_balance, total_lp_supply, total_token_reserve) { - return total_lp_supply === 0 ? 0 : (total_token_reserve / total_lp_supply) * user_lp_balance +function calcTokenBalance( + user_lp_balance, + total_lp_supply, + total_token_reserve +) { + return total_lp_supply === 0 + ? 0 + : (total_token_reserve / total_lp_supply) * user_lp_balance; } export async function strategy( @@ -75,22 +80,28 @@ export async function strategy( snapshot ) { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; - var callData: [any, string, [any]][] = [] - var callStakedAddress: [any, string][] = [] - options.contractAddresses.map((contractAddress: any) => { callStakedAddress.push([contractAddress, options.methodABI_2.name]) }) - addresses.map((userAddress: any) => { options.contractAddresses.map((contractAddress: any) => { callData.push([contractAddress, options.methodABI_1.name, [userAddress]]) }) }) - callData = [...chunk(callData, 2000)] // chunking the callData into multiple arrays of 2000 requests + let callData: [any, string, [any]][] = []; + const callStakedAddress: [any, string][] = []; + options.contractAddresses.map((contractAddress: any) => { + callStakedAddress.push([contractAddress, options.methodABI_2.name]); + }); + addresses.map((userAddress: any) => { + options.contractAddresses.map((contractAddress: any) => { + callData.push([contractAddress, options.methodABI_1.name, [userAddress]]); + }); + }); + callData = [...chunk(callData, 2000)]; // chunking the callData into multiple arrays of 2000 requests - let LP_balances: any[] = [] + let LP_balances: any[] = []; for (let i = 0; i < callData.length; i++) { - let tempArray = await multicall( + const tempArray = await multicall( network, provider, [options.methodABI_1], callData[i], { blockTag } ); - LP_balances.push(...tempArray) + LP_balances.push(...tempArray); } let stakedLP = await multicall( @@ -101,13 +112,12 @@ export async function strategy( { blockTag } ); - stakedLP = [].concat.apply([], stakedLP) - let dfyn_lp: any[] = await getLP(stakedLP, snapshot) + stakedLP = [].concat.apply([], stakedLP); + const dfyn_lp: any[] = await getLP(stakedLP, snapshot); let temp: any = []; if (options.contractAddresses.length > 1) { - // sorting dfyn_lp such that it aligns with users' lp balances - var itemPositions = {}; + const itemPositions = {}; for (let i = 0; i < stakedLP.length; i++) { itemPositions[stakedLP[i].toLowerCase()] = i; } @@ -118,24 +128,26 @@ export async function strategy( for (let i = addresses.length; i > 0; i--) { temp.push(LP_balances.splice(0, Math.ceil(LP_balances.length / i))); } - } - else { - temp = [...LP_balances] + } else { + temp = [...LP_balances]; } // finding users token balance from their lp balances - LP_balances = [] + LP_balances = []; temp.map((item, index) => { let sum = 0; temp[index].map((element, i) => { - element = calcTokenBalance(parseFloat(formatUnits(element.toString(), 18)), parseFloat(dfyn_lp[i].totalSupply), + element = calcTokenBalance( + parseFloat(formatUnits(element.toString(), 18)), + parseFloat(dfyn_lp[i].totalSupply), options.tokenAddress.toLowerCase() === dfyn_lp[i].token0.id ? parseFloat(dfyn_lp[i].reserve0) - : parseFloat(dfyn_lp[i].reserve1)) + : parseFloat(dfyn_lp[i].reserve1) + ); sum = sum + element; - }) - LP_balances.push(sum) - }) + }); + LP_balances.push(sum); + }); return Object.fromEntries( LP_balances.map((value, i) => [ diff --git a/src/strategies/dfyn-staked-in-vaults/index.ts b/src/strategies/dfyn-staked-in-vaults/index.ts index ccb0c34d3..54d430947 100644 --- a/src/strategies/dfyn-staked-in-vaults/index.ts +++ b/src/strategies/dfyn-staked-in-vaults/index.ts @@ -5,7 +5,7 @@ export const author = 'vatsalgupta13'; export const version = '0.1.0'; function chunk(array, chunkSize) { - let tempArray: any[] = []; + const tempArray: any[] = []; for (let i = 0, len = array.length; i < len; i += chunkSize) tempArray.push(array.slice(i, i + chunkSize)); return tempArray; @@ -20,41 +20,42 @@ export async function strategy( snapshot ) { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; - var callData: [any, string, [any]][] = [] - addresses.map((userAddress: any) => { options.contractAddresses.map((vaultAddress: any) => { callData.push([vaultAddress, options.methodABI.name, [userAddress]]) }) }) - callData = [...chunk(callData, 2000)] // chunking the callData into multiple arrays of 2000 requests - let response: any[] = [] + let callData: [any, string, [any]][] = []; + addresses.map((userAddress: any) => { + options.contractAddresses.map((vaultAddress: any) => { + callData.push([vaultAddress, options.methodABI.name, [userAddress]]); + }); + }); + callData = [...chunk(callData, 2000)]; // chunking the callData into multiple arrays of 2000 requests + let response: any[] = []; for (let i = 0; i < callData.length; i++) { - let tempArray = await multicall( + const tempArray = await multicall( network, provider, [options.methodABI], callData[i], { blockTag } ); - response.push(...tempArray) + response.push(...tempArray); } if (options.contractAddresses.length > 1) { // grouping all balances of a particular address together - let result: any = []; + const result: any = []; response = [].concat.apply([], response); for (let i = addresses.length; i > 0; i--) { result.push(response.splice(0, Math.ceil(response.length / i))); } // performing summation over all balances of the user - response = [] + response = []; result.map((item, index) => { - let sum = 0 + let sum = 0; result[index].map((element) => { - sum = sum + parseFloat(formatUnits(element.toString(), 18)) - }) - response.push(sum) - }) + sum = sum + parseFloat(formatUnits(element.toString(), 18)); + }); + response.push(sum); + }); } return Object.fromEntries( - response.map((value, i) => [ - addresses[i], - options.scoreMultiplier * value - ]) + response.map((value, i) => [addresses[i], options.scoreMultiplier * value]) ); } diff --git a/src/strategies/has-rock/index.ts b/src/strategies/has-rock/index.ts index 6110bf89f..b93a9073e 100644 --- a/src/strategies/has-rock/index.ts +++ b/src/strategies/has-rock/index.ts @@ -17,34 +17,24 @@ export async function strategy( ) { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; - let calls = [] as any; - for (var i=0; i< 100; i++){ - calls.push([ - options.address, - 'rocks', - [i] - ]) + const calls = [] as any; + for (let i = 0; i < 100; i++) { + calls.push([options.address, 'rocks', [i]]); } - const response = await multicall( - network, - provider, - abi, - calls, - { blockTag } - ); + const response = await multicall(network, provider, abi, calls, { blockTag }); - let result = {} as any; + const result = {} as any; - addresses.forEach((address, x)=> { + addresses.forEach((address, x) => { let addressRocks = 0; response.forEach((rockObject, i) => { - if (rockObject.owner == address){ - addressRocks++; - } - }) - result[address] = addressRocks - }) + if (rockObject.owner == address) { + addressRocks++; + } + }); + result[address] = addressRocks; + }); return result; } diff --git a/src/strategies/honeyswap/index.ts b/src/strategies/honeyswap/index.ts index 6afc73397..d960b8fbe 100644 --- a/src/strategies/honeyswap/index.ts +++ b/src/strategies/honeyswap/index.ts @@ -1,7 +1,6 @@ import { getAddress } from '@ethersproject/address'; import { subgraphRequest } from '../../utils'; - export const author = 'Kittyslasher'; export const version = '0.1.0'; @@ -78,4 +77,4 @@ export async function strategy( }); } return score || {}; -} \ No newline at end of file +} diff --git a/src/strategies/index.ts b/src/strategies/index.ts index f7ddf480a..ad6f6f0dd 100644 --- a/src/strategies/index.ts +++ b/src/strategies/index.ts @@ -105,6 +105,7 @@ import * as erc721 from './erc721'; import * as erc721MultiRegistry from './erc721-multi-registry'; import * as apescape from './apescape'; import * as liftkitchen from './liftkitchen'; +import * as coordinape from './coordinape'; import * as decentralandEstateSize from './decentraland-estate-size'; import * as iotexBalance from './iotex-balance'; import * as iotexStakedBalance from './iotex-staked-balance'; @@ -142,6 +143,7 @@ import * as crucibleERC20BalanceOf from './crucible-erc20-balance-of'; import * as hasrock from './has-rock'; const strategies = { + coordinape, 'anti-whale': antiWhale, balancer, sunder, @@ -281,7 +283,7 @@ const strategies = { snowswap, meebitsdao, 'crucible-erc20-balance-of': crucibleERC20BalanceOf, - 'has-rock':hasrock + 'has-rock': hasrock }; Object.keys(strategies).forEach(function (strategyName) { diff --git a/src/strategies/infinityprotocol-liquidity-pools/index.ts b/src/strategies/infinityprotocol-liquidity-pools/index.ts index 43b044c4d..f56272ca5 100644 --- a/src/strategies/infinityprotocol-liquidity-pools/index.ts +++ b/src/strategies/infinityprotocol-liquidity-pools/index.ts @@ -54,8 +54,11 @@ export async function strategy( } const tokenAddress = options.address.toLowerCase(); const result = await subgraphRequest( - options.subGraphURL ? options.subGraphURL : INFINITYPROTOCOL_SUBGRAPH_URL[network], - params); + options.subGraphURL + ? options.subGraphURL + : INFINITYPROTOCOL_SUBGRAPH_URL[network], + params + ); const score = {}; if (result && result.users) { result.users.forEach((u) => { @@ -73,7 +76,7 @@ export async function strategy( ? token0perShard * lp.liquidityTokenBalance : token1perShard * lp.liquidityTokenBalance; if (options.scoreMultiplier) { - userScore = userScore * options.scoreMultiplier + userScore = userScore * options.scoreMultiplier; } const userAddress = getAddress(u.id); if (!score[userAddress]) score[userAddress] = 0; diff --git a/src/strategies/mcn-farm/index.ts b/src/strategies/mcn-farm/index.ts index f794dbf64..08250566b 100644 --- a/src/strategies/mcn-farm/index.ts +++ b/src/strategies/mcn-farm/index.ts @@ -51,11 +51,11 @@ export async function strategy( const [tokenBalanceInLP] = res[1]; const tokensPerLP = tokenBalanceInLP.div(totalSupply); const response = res.slice(2); - let values = {}; + const values = {}; response.forEach(([userInfo, rewards], i) => { - let address_i = i % addresses.length; - let address = addresses[address_i]; - let pool_i = Math.floor(i / addresses.length); + const address_i = i % addresses.length; + const address = addresses[address_i]; + const pool_i = Math.floor(i / addresses.length); values[address] = values.hasOwnProperty(address) ? values[address].add(rewards[0]) : BigNumber.from(rewards[0]); @@ -68,9 +68,9 @@ export async function strategy( } }); - for (let address in values) { + for (const address in values) { if (values.hasOwnProperty(address)) { - let value = parseFloat(formatUnits(values[address], 18)); + const value = parseFloat(formatUnits(values[address], 18)); values[address] = value; } }