DyDx TVL translation

This commit is contained in:
arman37 2020-04-30 02:42:54 +06:00
parent 252412f9df
commit 3d5b353644
1 changed files with 77 additions and 0 deletions

77
projects/dydx/index.js Normal file
View File

@ -0,0 +1,77 @@
/*==================================================
Modules
==================================================*/
const sdk = require('../../sdk');
const _ = require('underscore');
const BigNumber = require("bignumber.js");
/*==================================================
Settings
==================================================*/
const contracts = [
'0x5199071825CC1d6cd019B0D7D42B08106f6CF16D',
'0x1e0447b19bb6ecfdae1e4ae1694b0c3659614e4e'
];
const tokens = [
'0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'0x6B175474E89094C44Da98b954EedeAC495271d0F'
];
/*==================================================
Main
==================================================*/
async function tvl (timestamp, block) {
const balances = {};
let balanceOfCalls = [];
_.forEach(contracts, (contract) => {
balanceOfCalls = [
...balanceOfCalls,
..._.map(tokens, (token) => ({
target: token,
params: contract
}))
];
});
const balanceOfResult = (await sdk.api.abi.multiCall({
block,
calls: balanceOfCalls,
abi: 'erc20:balanceOf',
})).output;
/* combine token volumes on multiple contracts */
_.forEach(balanceOfResult, (result) => {
let balance = new BigNumber(result.output || 0);
if (balance <= 0) return;
let asset = result.input.target;
let total = balances[asset];
if (total) {
balances[asset] = balance.plus(total).toFixed();
} else {
balances[asset] = balance.toFixed();
}
});
return balances;
}
/*==================================================
Exports
==================================================*/
module.exports = {
name: 'dYdX',
token: null,
category: 'Lending',
start: 1538179200, // 09/29/2018 @ 12:00am (UTC)
tvl,
};