From e043857f9a0e840cf93767a92b25fa17c9572d1c Mon Sep 17 00:00:00 2001 From: cesarsld Date: Fri, 1 Oct 2021 19:37:18 +0200 Subject: [PATCH] [cyberkongz] Add cyberkongz strategy (#90) * Add cyberkongz strategy * Update src/strategies/cyberkongz/index.ts Co-authored-by: Chaitanya --- src/strategies/cyberkongz/examples.json | 26 ++++++++++++++ src/strategies/cyberkongz/index.ts | 48 +++++++++++++++++++++++++ src/strategies/index.ts | 4 ++- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/strategies/cyberkongz/examples.json create mode 100644 src/strategies/cyberkongz/index.ts diff --git a/src/strategies/cyberkongz/examples.json b/src/strategies/cyberkongz/examples.json new file mode 100644 index 000000000..0c14e73b6 --- /dev/null +++ b/src/strategies/cyberkongz/examples.json @@ -0,0 +1,26 @@ +[{ + "name": "CyberKongz, CyberKongz VX and Banana holdings", + "strategy": { + "name": "cyberkongz", + "params": { + "symbol": "KONGZ", + "registries": [ + "0x57a204aa1042f6e66dd7730813f4024114d74f37", + "0x7ea3cca10668b8346aec0bf1844a49e995527c8b", + "0xe2311ae37502105b442bbef831e9b53c5d2e9b3b" + ] + } + }, + "network": "1", + "addresses": [ + "0xf521Bb7437bEc77b0B15286dC3f49A87b9946773", + "0x721931508df2764fd4f70c53da646cb8aed16ace", + "0xa63571f2ce7cf4e9a566a1f248f5d0ad3ba78726", + "0x9279c4cfb0e85e2dff8825ce141f9794c7c7170a", + "0x6f35b0cfc58eb1e21eef8a439bbb0ce4c929d32a", + "0xe34bded2b256430a9be53cbf5cba3b6d866d55f3", + "0x031c690be2932403cbdd85f8853f596794cff6c3" + ], + "snapshot": 13322697 + }] + \ No newline at end of file diff --git a/src/strategies/cyberkongz/index.ts b/src/strategies/cyberkongz/index.ts new file mode 100644 index 000000000..4a533363e --- /dev/null +++ b/src/strategies/cyberkongz/index.ts @@ -0,0 +1,48 @@ +import { formatUnits } from '@ethersproject/units'; +import { multicall } from '../../utils'; + +export const author = 'cesarsld'; +export const version = '0.1.0'; + +const abi = [ + 'function balanceOf(address account) external view returns (uint256)', + 'function totalSupply() external view returns (uint256)' +]; + +export async function strategy( + space, + network, + provider, + addresses, + options, + snapshot +) { + const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; + + const calls: any[] = []; + options.registries.forEach((registry) => { + addresses.forEach((address: any) => { + calls.push([registry, 'balanceOf', [address]]); + }); + }); + + const response = await multicall(network, provider, abi, calls, { blockTag }); + const nanaCall = [['0xe2311ae37502105b442bbef831e9b53c5d2e9b3b', 'totalSupply', []]] + const nanaSupply = await multicall(network, provider, abi, nanaCall, { blockTag }); + + + const merged = {}; + response.map((value: any, i: number) => { + + const address = calls[i][2][0]; + merged[address] = (merged[address] || 0) as number; + if(Math.floor(i / addresses.length) == 0) + merged[address] += parseFloat(formatUnits((3 * value).toString(), 0)); + else if(Math.floor(i / addresses.length) == 1) + merged[address] += parseFloat(formatUnits(value.toString(), 0)); + else if(Math.floor(i / addresses.length) == 2) + merged[address] += parseFloat(formatUnits((Math.floor(15000 * value / nanaSupply)).toString(), 0)); + }); + + return merged; +} diff --git a/src/strategies/index.ts b/src/strategies/index.ts index 994b35fb0..26d5ba62e 100644 --- a/src/strategies/index.ts +++ b/src/strategies/index.ts @@ -155,6 +155,7 @@ import * as occStakeOf from './occ-stake-of'; import * as hoprStaking from './hopr-staking'; import * as hoprBridgedBalance from './hopr-bridged-balance'; import * as lootCharacterGuilds from './loot-character-guilds'; +import * as cyberkongz from './cyberkongz'; const strategies = { coordinape, @@ -311,7 +312,8 @@ const strategies = { 'hopr-bridged-balance': hoprBridgedBalance, 'occ-stake-of': occStakeOf, 'holds-tokens': holdsTokens, - 'loot-character-guilds': lootCharacterGuilds + 'loot-character-guilds': lootCharacterGuilds, + 'cyberkongz': cyberkongz }; Object.keys(strategies).forEach(function (strategyName) {