From 1d7858010aff820de5d46897e7b515cc44e671d4 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 16 Aug 2023 15:39:15 +0300 Subject: [PATCH 1/5] makerdao fix --- src/factory/provider.spec.ts | 5 ++++ .../providers/ethereum/makerdao/index.ts | 23 +------------------ 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/factory/provider.spec.ts b/src/factory/provider.spec.ts index 3a3fb79d..98e2685a 100644 --- a/src/factory/provider.spec.ts +++ b/src/factory/provider.spec.ts @@ -30,6 +30,11 @@ describe(process.argv[6], () => { chain, block, date: '0', + autointegrationParams: { + autointegrated: 'false', + dappType: undefined, + addresses: undefined, + }, }); console.log('balances:', balances); if (showPoolBalancesFlg) console.log('poolBalances:', poolBalances); diff --git a/src/factory/providers/ethereum/makerdao/index.ts b/src/factory/providers/ethereum/makerdao/index.ts index 780764d9..b032f81c 100644 --- a/src/factory/providers/ethereum/makerdao/index.ts +++ b/src/factory/providers/ethereum/makerdao/index.ts @@ -6,7 +6,6 @@ import formatter from '../../../../util/formatter'; import util from '../../../../util/blockchainUtil'; import basicUtil from '../../../../util/basicUtil'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; -import { log } from '../../../../util/logger/logger'; async function getJoins(block, chain, provider, web3) { const relyTopic = @@ -19,12 +18,11 @@ async function getJoins(block, chain, provider, web3) { chain, provider, ); - console.log(stored_log); + let i = Math.max(MakerMCDConstants.STARTBLOCK, Number(stored_log.block) || 0); const logs = stored_log.data || []; for (;;) { - console.log(i); if (i > block) { break; } @@ -132,25 +130,6 @@ async function tvl(params: ITvlParams): Promise> { ); formatter.sumMultiBalanceOf(balances, balanceResults); - - try { - const pie = await new web3.eth.Contract( - MakerMCDConstants.abi, - MakerMCDConstants.POT, - ).methods - .Pie() - .call(null, block); - balances[MakerMCDConstants.DAI] = balances[MakerMCDConstants.DAI] - ? balances[MakerMCDConstants.DAI].plus(new BigNumber(pie)) - : new BigNumber(pie); - } catch (e) { - log.error({ - message: e?.message || '', - stack: e?.stack || '', - detail: `Error: Failed to get Pie ethereum/makerdao`, - endpoint: 'tvl', - }); - } } formatter.convertBalancesToFixed(balances); From d361aaf5586ac26b9cff446e4f51d53fed284db8 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 16 Aug 2023 15:47:10 +0300 Subject: [PATCH 2/5] maker dao integration --- .../providers/ethereum/maker-dao/data.json | 7 + .../providers/ethereum/maker-dao/index.ts | 139 ++++++++++++++++++ .../ethereum/maker-dao/maker-mcd.json | 40 +++++ .../ethereum/maker-dao/makerdao.json | 5 + 4 files changed, 191 insertions(+) create mode 100644 src/factory/providers/ethereum/maker-dao/data.json create mode 100644 src/factory/providers/ethereum/maker-dao/index.ts create mode 100644 src/factory/providers/ethereum/maker-dao/maker-mcd.json create mode 100644 src/factory/providers/ethereum/maker-dao/makerdao.json diff --git a/src/factory/providers/ethereum/maker-dao/data.json b/src/factory/providers/ethereum/maker-dao/data.json new file mode 100644 index 00000000..cf26b0d6 --- /dev/null +++ b/src/factory/providers/ethereum/maker-dao/data.json @@ -0,0 +1,7 @@ +{ + "address": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", + "name": "Maker", + "symbol": "MKR", + "decimals": 18, + "logo": "https://user-dashboard.s3.us-east-2.amazonaws.com/token_images/prod/0f/mkr_small.png" +} \ No newline at end of file diff --git a/src/factory/providers/ethereum/maker-dao/index.ts b/src/factory/providers/ethereum/maker-dao/index.ts new file mode 100644 index 00000000..b032f81c --- /dev/null +++ b/src/factory/providers/ethereum/maker-dao/index.ts @@ -0,0 +1,139 @@ +import BigNumber from 'bignumber.js'; +import ERC20_ABI from '../../../../constants/abi/erc20.json'; +import MakerSCDConstants from './makerdao.json'; +import MakerMCDConstants from './maker-mcd.json'; +import formatter from '../../../../util/formatter'; +import util from '../../../../util/blockchainUtil'; +import basicUtil from '../../../../util/basicUtil'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; + +async function getJoins(block, chain, provider, web3) { + const relyTopic = + '0x65fae35e00000000000000000000000000000000000000000000000000000000'; + + // get list of auths + let offset = 100000; + const stored_log = await basicUtil.readFromCache( + 'makerdao_log.json', + chain, + provider, + ); + + let i = Math.max(MakerMCDConstants.STARTBLOCK, Number(stored_log.block) || 0); + const logs = stored_log.data || []; + + for (;;) { + if (i > block) { + break; + } + try { + const seperatedLogs = await web3.eth.getPastLogs({ + fromBlock: i, + toBlock: Math.min(i + offset, block), + topics: [relyTopic], + address: MakerMCDConstants.VAT, + }); + const tokens = seperatedLogs.map( + (log) => `0x${log.topics[1].substr(26)}`, + ); + tokens.forEach((token) => { + if (!logs.includes(token)) { + logs.push(token); + } + }); + i += offset; + if (offset < 20) { + offset += 2; + } else if (offset < 200) { + offset += 20; + } else if (offset < 2000) { + offset += 200; + } else { + offset += 2000; + } + } catch (e) { + if (offset > 2000) { + offset -= 2000; + } else if (offset > 200) { + offset -= 200; + } else if (offset > 20) { + offset -= 20; + } else if (offset > 2) { + offset -= 2; + } else { + break; + } + } + } + + const log_data = { + block: undefined, + data: undefined, + }; + log_data.block = Math.max(Number(stored_log.block) || 0, block); + log_data.data = []; + + const ilkResults = await util.executeCallOfMultiTargets( + logs, + MakerMCDConstants.abi, + 'ilk', + [], + block, + chain, + web3, + ); + ilkResults.forEach((result, index) => { + if (result) { + log_data.data.push(logs[index]); + } + }); + + await basicUtil.saveIntoCache(log_data, 'makerdao_log.json', chain, provider); + return log_data.data; +} + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + const balances = {}; + + const scdContract = new web3.eth.Contract( + ERC20_ABI, + MakerSCDConstants.WETH_ADDRESS, + ); + balances[MakerSCDConstants.WETH_ADDRESS] = new BigNumber( + await scdContract.methods + .balanceOf(MakerSCDConstants.TUB_ADDRESS) + .call(null, block), + ); + + if (block >= MakerMCDConstants.STARTBLOCK) { + let joins = await getJoins(block, chain, provider, web3); + + let gemResults = await util.executeCallOfMultiTargets( + joins, + MakerMCDConstants.abi, + 'gem', + [], + block, + chain, + web3, + ); + + joins = joins.filter((_, index) => gemResults[index]); + gemResults = gemResults.filter((_, index) => gemResults[index]); + const balanceResults = await util.getTokenBalancesOfHolders( + joins, + gemResults, + block, + chain, + web3, + ); + + formatter.sumMultiBalanceOf(balances, balanceResults); + } + + formatter.convertBalancesToFixed(balances); + return { balances }; +} + +export { tvl }; diff --git a/src/factory/providers/ethereum/maker-dao/maker-mcd.json b/src/factory/providers/ethereum/maker-dao/maker-mcd.json new file mode 100644 index 00000000..6f870322 --- /dev/null +++ b/src/factory/providers/ethereum/maker-dao/maker-mcd.json @@ -0,0 +1,40 @@ +{ + "KOVANVAT": "0xba987bdb501d131f766fee8180da5d81b34b69d9", + "KOVANPOT": "0xea190dbdc7adf265260ec4da6e9675fd4f5a78bb", + "KOVANJUG": "0xcbb7718c9f39d05aeede1c472ca8bf804b2f1ead", + "KOVANSTARTBLOCK": 14764534, + "VAT": "0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b", + "POT": "0x197e90f9fad81970ba7976f33cbd77088e5d7cf7", + "JUG": "0x19c0976f590d67707e62397c87829d896dc0f1f1", + "DAI": "0x6b175474e89094c44da98b954eedeac495271d0f", + "STARTBLOCK": 8928152, + "abi": [ + { + "constant": true, + "inputs": [], + "name": "ilk", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "gem", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "Pie", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + } + ] +} diff --git a/src/factory/providers/ethereum/maker-dao/makerdao.json b/src/factory/providers/ethereum/maker-dao/makerdao.json new file mode 100644 index 00000000..65545187 --- /dev/null +++ b/src/factory/providers/ethereum/maker-dao/makerdao.json @@ -0,0 +1,5 @@ + { + "TUB_ADDRESS": "0x448a5065aebb8e423f0896e6c5d525c040f59af3", + "DAI_ADDRESS": "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359", + "WETH_ADDRESS": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" +} From 4dabe368ba7420a1ffb79ca20cca314b2b499932 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 16 Aug 2023 15:47:57 +0300 Subject: [PATCH 3/5] Update index.ts --- .../providers/ethereum/makerdao/index.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/factory/providers/ethereum/makerdao/index.ts b/src/factory/providers/ethereum/makerdao/index.ts index b032f81c..780764d9 100644 --- a/src/factory/providers/ethereum/makerdao/index.ts +++ b/src/factory/providers/ethereum/makerdao/index.ts @@ -6,6 +6,7 @@ import formatter from '../../../../util/formatter'; import util from '../../../../util/blockchainUtil'; import basicUtil from '../../../../util/basicUtil'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import { log } from '../../../../util/logger/logger'; async function getJoins(block, chain, provider, web3) { const relyTopic = @@ -18,11 +19,12 @@ async function getJoins(block, chain, provider, web3) { chain, provider, ); - + console.log(stored_log); let i = Math.max(MakerMCDConstants.STARTBLOCK, Number(stored_log.block) || 0); const logs = stored_log.data || []; for (;;) { + console.log(i); if (i > block) { break; } @@ -130,6 +132,25 @@ async function tvl(params: ITvlParams): Promise> { ); formatter.sumMultiBalanceOf(balances, balanceResults); + + try { + const pie = await new web3.eth.Contract( + MakerMCDConstants.abi, + MakerMCDConstants.POT, + ).methods + .Pie() + .call(null, block); + balances[MakerMCDConstants.DAI] = balances[MakerMCDConstants.DAI] + ? balances[MakerMCDConstants.DAI].plus(new BigNumber(pie)) + : new BigNumber(pie); + } catch (e) { + log.error({ + message: e?.message || '', + stack: e?.stack || '', + detail: `Error: Failed to get Pie ethereum/makerdao`, + endpoint: 'tvl', + }); + } } formatter.convertBalancesToFixed(balances); From 3f4de1ff7794865bcd29cd8c8c939ecb0c533c67 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 16 Aug 2023 15:49:10 +0300 Subject: [PATCH 4/5] Delete data.json --- src/factory/providers/ethereum/maker-dao/data.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/factory/providers/ethereum/maker-dao/data.json diff --git a/src/factory/providers/ethereum/maker-dao/data.json b/src/factory/providers/ethereum/maker-dao/data.json deleted file mode 100644 index cf26b0d6..00000000 --- a/src/factory/providers/ethereum/maker-dao/data.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "address": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", - "name": "Maker", - "symbol": "MKR", - "decimals": 18, - "logo": "https://user-dashboard.s3.us-east-2.amazonaws.com/token_images/prod/0f/mkr_small.png" -} \ No newline at end of file From de1504575d6ff7d765b2c8fc17f663db6b504ab1 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 16 Aug 2023 16:18:53 +0300 Subject: [PATCH 5/5] Update index.ts --- .../providers/ethereum/maker-dao/index.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/factory/providers/ethereum/maker-dao/index.ts b/src/factory/providers/ethereum/maker-dao/index.ts index b032f81c..66d9c7da 100644 --- a/src/factory/providers/ethereum/maker-dao/index.ts +++ b/src/factory/providers/ethereum/maker-dao/index.ts @@ -12,15 +12,21 @@ async function getJoins(block, chain, provider, web3) { '0x65fae35e00000000000000000000000000000000000000000000000000000000'; // get list of auths - let offset = 100000; - const stored_log = await basicUtil.readFromCache( - 'makerdao_log.json', - chain, - provider, - ); + let offset = 10000; + let stored_log; + try { + stored_log = await basicUtil.readFromCache( + 'makerdao_log.json', + chain, + provider, + ); + } catch {} - let i = Math.max(MakerMCDConstants.STARTBLOCK, Number(stored_log.block) || 0); - const logs = stored_log.data || []; + let i = Math.max( + MakerMCDConstants.STARTBLOCK, + Number(stored_log?.block) || 0, + ); + const logs = stored_log?.data || []; for (;;) { if (i > block) {