Skip to content

Commit

Permalink
Merge pull request DefiLlama#4951 from GarbleMoney/main
Browse files Browse the repository at this point in the history
Adapter for Garble.Money
  • Loading branch information
g1nt0ki authored Dec 27, 2022
2 parents 94c578f + f4af5c1 commit 2b5f8b4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 68 deletions.
70 changes: 19 additions & 51 deletions projects/gainsNetwork.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,26 @@
const { transformPolygonAddress } = require('./helper/portedTokens');
const sdk = require('@defillama/sdk');
const { staking } = require('./helper/staking');

const contracts = [
'0x151757c2E830C467B28Fe6C09c3174b6c76aA0c5',
'0x203F5c9567d533038d2da70Cbc20e6E8B3f309F9',
'0x176586Dec2b70df5B72a6Efe158a87f210551798',
'0xaee4d11a16B2bc65EDD6416Fb626EB404a6D65BD',
'0xd7052EC0Fe1fe25b20B7D65F6f3d490fCE58804f'
];
const { pool2 } = require('./helper/pool2');
const { sumTokens2 } = require('./helper/unwrapLPs');

const tokens = {
DAI: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
dQUICK: '0xf28164a485b0b2c90639e47b0f377b4a438a16b1'
DAI: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
dQUICK: '0xf28164a485b0b2c90639e47b0f377b4a438a16b1'
};

async function tvl(timestamp, block, chainBlocks) {
const transform = await transformPolygonAddress();
const balances = {};
block = chainBlocks.polygon;

const DAIbalance = (await sdk.api.abi.multiCall({
calls: contracts.map((c) => ({
target: tokens.DAI,
params: c
})),
abi: "erc20:balanceOf",
block,
chain: 'polygon'
})).output.reduce((a, b) => Number(a) + Number(b.output), 0);

const dQUICKbalance = (await sdk.api.abi.multiCall({
calls: contracts.map((c) => ({
target: tokens.dQUICK,
params: c
})),
abi: "erc20:balanceOf",
block,
chain: 'polygon'
})).output.reduce((a, b) => Number(a) + Number(b.output), 0);

return {
[transform(tokens.DAI)]: DAIbalance,
[transform(tokens.dQUICK)]: dQUICKbalance
};
};
async function tvl(_, _b, _cb, { api, }) {
const tokensAndOwners = [
[tokens.dQUICK, '0x151757c2E830C467B28Fe6C09c3174b6c76aA0c5'],
[tokens.dQUICK, '0x203F5c9567d533038d2da70Cbc20e6E8B3f309F9'],
[tokens.DAI, '0xaee4d11a16B2bc65EDD6416Fb626EB404a6D65BD'],
[tokens.DAI, '0xd7052EC0Fe1fe25b20B7D65F6f3d490fCE58804f'],
[tokens.DAI, '0x91993f2101cc758D0dEB7279d41e880F7dEFe827'],
]
return sumTokens2({ ...api, tokensAndOwners, })
}

// node test.js projects/gainsNetwork.js
module.exports={
polygon: {
tvl,
pool2: staking(
'0x33025b177A35F6275b78f9c25684273fc24B4e43',
'0x6e53cb6942e518376e9e763554db1a45ddcd25c4',
'polygon')
}
module.exports = {
polygon: {
tvl,
pool2: pool2('0x33025b177A35F6275b78f9c25684273fc24B4e43', '0x6e53cb6942e518376e9e763554db1a45ddcd25c4', 'polygon')
}
};
27 changes: 27 additions & 0 deletions projects/garble-money/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const sdk = require('@defillama/sdk')
const { sumTokensExport, nullAddress, } = require('../helper/sumTokens')

async function tvl() {

const balances = {}

sdk.util.sumSingleBalance(balances, 'tether', await getTokenBalance('', ''))
sdk.util.sumSingleBalance(balances, 'tron', await getTrxBalance('') / (10 ** 6))
sdk.util.sumSingleBalance(balances, 'usdd', await getTokenBalance('', ''))
sdk.util.sumSingleBalance(balances, 'justmoney-2', await getTokenBalance('', ''))

return balances
}

module.exports = {
tron: {
tvl: sumTokensExport({
tokensAndOwners: [
[nullAddress, 'TCdY8kA7XsZ5UUw8jEgbVRbS2MVttrY9AC'],
['TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', 'TYaaJsD44isGwQUbvHNuii8nAnTKSxPcND'],
['TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn', 'TWupFtHWnURhDNrWBfB2tK3zD4uALurBgk'],
['TVHH59uHVpHzLDMFFpUgCx2dNAQqCzPhcR', 'TK76Z1mJQHN98WsuUUKeDZnNhwRsj6p5wo'],
]
}),
},
};
3 changes: 2 additions & 1 deletion projects/helper/sumTokens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ibcChains, getUniqueAddresses} = require('./tokenMapping')
const { get, post, } = require('./http')
const { sumTokens2: sumTokensEVM, } = require('./unwrapLPs')
const { sumTokens2: sumTokensEVM, nullAddress, } = require('./unwrapLPs')
const sdk = require('@defillama/sdk')

const helpers = {
Expand Down Expand Up @@ -102,6 +102,7 @@ async function getRippleBalance(account) {
}

module.exports = {
nullAddress,
sumTokensExport,
sumTokens,
}
2 changes: 2 additions & 0 deletions projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ const fixBalancesTokens = {
[nullAddress]: { coingeckoId: "tron", decimals: 6, },
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t": { coingeckoId: "tether", decimals: 6, },
"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8": { coingeckoId: "usd-coin", decimals: 6, },
"TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn": { coingeckoId: "usdd", decimals: 18, },
"TVHH59uHVpHzLDMFFpUgCx2dNAQqCzPhcR": { coingeckoId: "justmoney-2", decimals: 8, },
"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9": { coingeckoId: "bitcoin", decimals: 8, },
"TR3DLthpnDdCGabhVDbD3VMsiJoCXY3bZd": { coingeckoId: "litecoin", decimals: 8, },
"THbVQp8kMjStKNnf2iCY6NEzThKMK5aBHg": { coingeckoId: "dogecoin", decimals: 8, },
Expand Down
30 changes: 16 additions & 14 deletions projects/helper/unknownTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,31 @@ function pool2({ stakingContract, lpToken, chain = "ethereum", transformAddress,
}

function sumTokensExport({ tokensAndOwners = [],
coreAssets = [], owner, tokens, chain = 'ethereum', restrictTokenRatio, blacklist = [], skipConversion = false, onlyLPs, minLPRatio,
coreAssets = [], owner, tokens, restrictTokenRatio, blacklist = [], skipConversion = false, onlyLPs, minLPRatio,
log_coreAssetPrices = [], log_minTokenValue = 1e6, owners = [], lps = [], useDefaultCoreAssets = false,
}) {
return (_, _b, { [chain]: block }) => sumUnknownTokens({ tokensAndOwners, coreAssets, owner, tokens, chain, block, restrictTokenRatio, blacklist, skipConversion, log_coreAssetPrices, log_minTokenValue, owners, lps, useDefaultCoreAssets, })
return (_, _b, _cb, { api }) => sumUnknownTokens({ ...api, tokensAndOwners, onlyLPs, minLPRatio, coreAssets, owner, tokens, chain, block, restrictTokenRatio, blacklist, skipConversion, log_coreAssetPrices, log_minTokenValue, owners, lps, useDefaultCoreAssets, })
}

function staking({ tokensAndOwners = [],
coreAssets = [], owner, tokens, chain = 'ethereum', restrictTokenRatio, blacklist = [], skipConversion = false, onlyLPs, minLPRatio,
coreAssets = [], owner, tokens, restrictTokenRatio, blacklist = [], skipConversion = false, onlyLPs, minLPRatio,
log_coreAssetPrices = [], log_minTokenValue = 1e6, owners = [], lps = [], useDefaultCoreAssets = false,
}) {
if (!coreAssets.length && useDefaultCoreAssets)
coreAssets = getCoreAssets(chain)
blacklist = getUniqueAddresses(blacklist)
if (!tokensAndOwners.length)
if (owners.length)
tokensAndOwners = owners.map(o => tokens.map(t => [t, o])).flat()
else if (owner)
tokensAndOwners = tokens.map(t => [t, owner])
tokensAndOwners = tokensAndOwners.filter(t => !blacklist.includes(t[0]))

return async (_, _b, { [chain]: block }) => {

return async (_, _b, _cb, { api, chain = 'ethereum', block, }) => {
if (!coreAssets.length && useDefaultCoreAssets)
coreAssets = getCoreAssets(chain)
blacklist = getUniqueAddresses(blacklist)
if (!tokensAndOwners.length)
if (owners.length)
tokensAndOwners = owners.map(o => tokens.map(t => [t, o])).flat()
else if (owner)
tokensAndOwners = tokens.map(t => [t, owner])
tokensAndOwners = tokensAndOwners.filter(t => !blacklist.includes(t[0]))

const balances = await sumTokens2({ chain, block, tokensAndOwners })
const { updateBalances, pairBalances, prices, } = await getTokenPrices({ coreAssets, lps: [...tokensAndOwners.map(t => t[0]), ...lps,], chain, block, restrictTokenRatio, blacklist, log_coreAssetPrices, log_minTokenValue, minLPRatio })
// sdk.log(prices, pairBalances, balances)
await updateBalances(balances, { skipConversion, onlyLPs })
const fixBalances = await getFixBalances(chain)
fixBalances(balances)
Expand Down
20 changes: 18 additions & 2 deletions projects/oreoswap/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
const { getUniTVL } = require('../helper/unknownTokens')
const { getUniTVL, staking } = require('../helper/unknownTokens')
const sdk = require('@defillama/sdk')
const uniTvl = getUniTVL({ factory: '0x20fAfD2B0Ba599416D75Eb54f48cda9812964f46', useDefaultCoreAssets: true })
const masterchef = '0xa481384653c484901b301634086c8625e550bbec'
const masterchefOld = '0xeb66b69d1cc6ef04575a11d4b0a6427b1cdacc45'
const oreo = '0x319e222De462ac959BAf2aEc848697AeC2bbD770'
const weth = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1'

module.exports = {
misrepresentedTokens: true,
arbitrum: {
tvl: getUniTVL({ factory: '0x20fAfD2B0Ba599416D75Eb54f48cda9812964f46', useDefaultCoreAssets: true }),
tvl: sdk.util.sumChainTvls([uniTvl, staking({
owners: [masterchefOld, masterchef],
tokens: [weth],
})]),
staking: staking({
owners: [masterchefOld, masterchef],
tokens: [oreo],
onlyLPs: true,
lps: ['0xBf6a0418e31f90b60ae3d19c56a659ad8b2f4D18'],
useDefaultCoreAssets: true,
})
}
};

0 comments on commit 2b5f8b4

Please sign in to comment.