From 5d8e6b0c4ce6755592631185c268910eec0e3c00 Mon Sep 17 00:00:00 2001 From: Gerald Date: Tue, 9 May 2023 15:22:43 +0100 Subject: [PATCH 1/3] fix: dai address --- projects/union-finance/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/union-finance/index.js b/projects/union-finance/index.js index 1122b1918c..e1045bf739 100644 --- a/projects/union-finance/index.js +++ b/projects/union-finance/index.js @@ -8,12 +8,12 @@ const config = { }, arbitrum: { userManager: "0xb71F3D4342AaE0b8D531E14D2CF2F45d6e458A5F", - DAI: "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1", + DAI: "0x6b175474e89094c44da98b954eedeac495271d0f", uDAI: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", }, optimism: { userManager: "0x8E195D65b9932185Fcc76dB5144534e0f3597628", - DAI: "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1", + DAI: "0x6b175474e89094c44da98b954eedeac495271d0f", uDAI: "0xE478b5e7A423d7CDb224692d0a816CA146A744b2", }, }; From 7a688863b7319d97bf8637daaecd9a164cd35ed5 Mon Sep 17 00:00:00 2001 From: Max Weng Date: Mon, 23 Dec 2024 17:59:15 +0800 Subject: [PATCH 2/3] chg: add base support --- projects/union-finance/index.js | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/projects/union-finance/index.js b/projects/union-finance/index.js index e1045bf739..99e8e342b6 100644 --- a/projects/union-finance/index.js +++ b/projects/union-finance/index.js @@ -3,18 +3,23 @@ const sdk = require("@defillama/sdk"); const config = { ethereum: { userManager: "0x49c910Ba694789B58F53BFF80633f90B8631c195", - DAI: "0x6b175474e89094c44da98b954eedeac495271d0f", - uDAI: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", + underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + uToken: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", }, arbitrum: { userManager: "0xb71F3D4342AaE0b8D531E14D2CF2F45d6e458A5F", - DAI: "0x6b175474e89094c44da98b954eedeac495271d0f", - uDAI: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", + underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + uToken: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", }, optimism: { userManager: "0x8E195D65b9932185Fcc76dB5144534e0f3597628", - DAI: "0x6b175474e89094c44da98b954eedeac495271d0f", - uDAI: "0xE478b5e7A423d7CDb224692d0a816CA146A744b2", + underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + uToken: "0xE478b5e7A423d7CDb224692d0a816CA146A744b2", + }, + base: { + userManager: "0xfd745A1e2A220C6aC327EC55d2Cb404CD939f56b", + underlying: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + uToken: "0xc2447f36FfdA08E278D25D08Ea91D942f0C2d6ea", }, }; @@ -71,7 +76,7 @@ function tvl(chain) { return async function (_, __, chainBlocks) { const chainBlock = chainBlocks[chain]; - const { userManager, uDAI } = config[chain]; + const { userManager, uToken } = config[chain]; const totalStaked = ( await sdk.api.abi.call({ @@ -86,7 +91,7 @@ function tvl(chain) { const totalRedeemable = ( await sdk.api.abi.call({ abi: abi.totalRedeemable, - target: uDAI, + target: uToken, params: [], chain, block: chainBlock, @@ -96,7 +101,7 @@ function tvl(chain) { const totalReserves = ( await sdk.api.abi.call({ abi: abi.totalReserves, - target: uDAI, + target: uToken, params: [], chain, block: chainBlock, @@ -109,7 +114,7 @@ function tvl(chain) { ); return { - [config[chain].DAI]: total, + [config[chain].underlying]: total, }; }; } @@ -118,12 +123,12 @@ function borrowing(chain) { return async function (_, __, chainBlocks) { const chainBlock = chainBlocks[chain]; - const { uDAI } = config[chain]; + const { uToken } = config[chain]; const totalBorrows = ( await sdk.api.abi.call({ abi: abi.totalBorrows, - target: uDAI, + target: uToken, params: [], chain, block: chainBlock, @@ -131,7 +136,7 @@ function borrowing(chain) { ).output; return { - [config[chain].DAI]: totalBorrows, + [config[chain].underlying]: totalBorrows, }; }; } @@ -153,4 +158,8 @@ module.exports = { tvl: tvl("optimism"), borrowed: borrowing("optimism"), }, + base: { + tvl: tvl("base"), + borrowed: borrowing("base"), + }, }; From 327465da9ecbf30abd114e03e39009869cd50cdc Mon Sep 17 00:00:00 2001 From: Max Weng Date: Fri, 3 Jan 2025 20:42:04 +0800 Subject: [PATCH 3/3] chg: update to the latest version --- projects/union-finance/index.js | 118 +++++++------------------------- 1 file changed, 26 insertions(+), 92 deletions(-) diff --git a/projects/union-finance/index.js b/projects/union-finance/index.js index e19134cd34..86474d309a 100644 --- a/projects/union-finance/index.js +++ b/projects/union-finance/index.js @@ -1,24 +1,25 @@ -const sdk = require("@defillama/sdk"); +const ADDRESSES = require('../helper/coreAssets.json'); +const methodologies = require('../helper/methodologies'); const config = { ethereum: { userManager: "0x49c910Ba694789B58F53BFF80633f90B8631c195", - underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + underlying: ADDRESSES.ethereum.DAI, uToken: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", }, arbitrum: { userManager: "0xb71F3D4342AaE0b8D531E14D2CF2F45d6e458A5F", - underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + underlying: ADDRESSES.arbitrum.DAI, uToken: "0x954F20DF58347b71bbC10c94827bE9EbC8706887", }, optimism: { userManager: "0x8E195D65b9932185Fcc76dB5144534e0f3597628", - underlying: "0x6b175474e89094c44da98b954eedeac495271d0f", + underlying: ADDRESSES.optimism.DAI, uToken: "0xE478b5e7A423d7CDb224692d0a816CA146A744b2", }, base: { userManager: "0xfd745A1e2A220C6aC327EC55d2Cb404CD939f56b", - underlying: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + underlying: ADDRESSES.base.USDC, uToken: "0xc2447f36FfdA08E278D25D08Ea91D942f0C2d6ea", }, }; @@ -30,96 +31,29 @@ const abi = { totalBorrows: "uint256:totalBorrows", }; -function tvl(chain) { - return async function (_, __, chainBlocks) { - const chainBlock = chainBlocks[chain]; - - const { userManager, uToken } = config[chain]; - - const totalStaked = ( - await sdk.api.abi.call({ - abi: abi.totalStaked, - target: userManager, - params: [], - chain, - block: chainBlock, - }) - ).output; - - const totalRedeemable = ( - await sdk.api.abi.call({ - abi: abi.totalRedeemable, - target: uToken, - params: [], - chain, - block: chainBlock, - }) - ).output; - - const totalReserves = ( - await sdk.api.abi.call({ - abi: abi.totalReserves, - target: uToken, - params: [], - chain, - block: chainBlock, - }) - ).output; - - const total = [totalStaked, totalRedeemable, totalReserves].reduce( - (acc, n) => Number(n) + Number(acc), - 0 - ); - - return { - [config[chain].underlying]: total, - }; - }; +async function tvl(api) { + const { userManager, underlying, uToken } = config[api.chain] + console.log({ userManager, underlying, uToken }) + const bals = await api.batchCall([ + { target: userManager, abi: abi.totalStaked }, + { target: uToken, abi: abi.totalRedeemable }, + { target: uToken, abi: abi.totalReserves }, + ]) + bals.forEach(i => api.add(underlying, i)) } -function borrowing(chain) { - return async function (_, __, chainBlocks) { - const chainBlock = chainBlocks[chain]; - - const { uToken } = config[chain]; - - const totalBorrows = ( - await sdk.api.abi.call({ - abi: abi.totalBorrows, - target: uToken, - params: [], - chain, - block: chainBlock, - }) - ).output; - - return { - [config[chain].underlying]: totalBorrows, - }; - }; +async function borrowed(api) { + const { underlying, uToken } = config[api.chain] + const borrows = await api.call({ target: uToken, abi: abi.totalBorrows, }) + api.add(underlying, borrows) } module.exports = { - timetravel: true, - misrepresentedTokens: false, - methodology: - "Counts the tokens locked in the contracts to be used to underwrite or to borrow. Borrowed coins are not counted towards the TVL, so only the coins actually locked in the contracts are counted.", - ethereum: { - tvl: tvl("ethereum"), - borrowed: borrowing("ethereum"), - }, - arbitrum: { - tvl: tvl("arbitrum"), - borrowed: borrowing("arbitrum"), - }, - optimism: { - tvl: tvl("optimism"), - borrowed: borrowing("optimism"), - }, - base: { - tvl: tvl("base"), - borrowed: borrowing("base"), - } -} - + methodology: methodologies.lendingMarket, +}; +Object.keys(config).forEach(chain => { + module.exports[chain] = { + tvl, borrowed, + } +})