From 7595968dd59c9abff88e32b9c1a00e9008a110a0 Mon Sep 17 00:00:00 2001 From: Coopes <24834768+Cooops@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:43:14 -0600 Subject: [PATCH 1/4] adding arb rewards --- src/adaptors/lodestar-v1/index.js | 42 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/adaptors/lodestar-v1/index.js b/src/adaptors/lodestar-v1/index.js index 12bd64b52d..78c344ce39 100755 --- a/src/adaptors/lodestar-v1/index.js +++ b/src/adaptors/lodestar-v1/index.js @@ -29,6 +29,12 @@ const PROTOCOL_TOKEN = { address: '0xF19547f9ED24aA66b03c3a552D181Ae334FBb8DB'.toLowerCase(), }; +const ARB_TOKEN = { + decimals: 18, + symbol: 'ARB', + address: '0x912CE59144191C1204E64559FE8253a0e49E6548'.toLowerCase(), +} + const getPrices = async (addresses) => { const prices = ( await superagent.get( @@ -153,13 +159,14 @@ const main = async () => { ); const lodePrices = await getPrices([`${CHAIN}:${PROTOCOL_TOKEN.address}`]); + const arbPrices = await getPrices([`${CHAIN}:${ARB_TOKEN.address}`]); const pools = allMarkets.map((market, i) => { const token = underlyingTokens[i] || NATIVE_TOKEN.address; const symbol = // for maker underlyingTokens[i]?.toLowerCase() === - '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2' + '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2' ? 'MKR' : underlyingSymbols[i] || NATIVE_TOKEN.symbol; @@ -188,10 +195,39 @@ const main = async () => { 100 ); }; - const apyReward = calcRewardApy(extraRewards, totalSupplyUsd); + + const baseApyReward = calcRewardApy(extraRewards, totalSupplyUsd); const _apyRewardBorrow = calcRewardApy(extraRewardsBorrow, totalBorrowUsd); const apyRewardBorrow = isNaN(_apyRewardBorrow) ? 0 : _apyRewardBorrow; + // Need to math off the total TVL for ARB and supply and borrow rewards are distributed evenly + let totalTvlUsd = 0; + + // Calculate total TVL (sum of supply and borrow for all markets) + allMarkets.forEach((market, i) => { + const decimals = Number(underlyingDecimals[i]) || NATIVE_TOKEN.decimals; + let price = prices[underlyingTokens[i]?.toLowerCase() || NATIVE_TOKEN.address.toLowerCase()]; + if (price === undefined) + price = underlyingSymbols[i]?.toLowerCase().includes('usd') ? 1 : 0; + + const totalSupplyUsd = + ((Number(marketsCash[i]) + Number(totalBorrows[i])) / 10 ** decimals) * + price; + const totalBorrowUsd = (Number(totalBorrows[i]) / 10 ** decimals) * price; + + totalTvlUsd += totalSupplyUsd + totalBorrowUsd; + }); + + // Calculate ARB APY reward based on total TVL + const calcRewardApyForArb = (denom) => { + return ((arbPrices[ARB_TOKEN.address] * 50892 * 52) / denom) * 100; + }; + + const arbApyReward = calcRewardApyForArb(totalTvlUsd) + + // Computed total (LODE + ARB rewards) + const apyReward = baseApyReward + arbApyReward; + let poolReturned = { pool: market.toLowerCase(), chain: utils.formatChain(CHAIN), @@ -201,7 +237,7 @@ const main = async () => { apyBase, apyReward, underlyingTokens: [token], - rewardTokens: [apyReward ? PROTOCOL_TOKEN.address : null].filter(Boolean), + rewardTokens: [apyReward ? [ARB_TOKEN.address, PROTOCOL_TOKEN.address] : null].filter(Boolean), }; if (isPaused[i] === false) { poolReturned = { From 6ccdd928f9a491d325e0848af38c4ea6ebd95fb1 Mon Sep 17 00:00:00 2001 From: Coopes <24834768+Cooops@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:32:46 -0600 Subject: [PATCH 2/4] fixing test --- src/adaptors/lodestar-v1/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adaptors/lodestar-v1/index.js b/src/adaptors/lodestar-v1/index.js index 78c344ce39..70215d697b 100755 --- a/src/adaptors/lodestar-v1/index.js +++ b/src/adaptors/lodestar-v1/index.js @@ -237,7 +237,7 @@ const main = async () => { apyBase, apyReward, underlyingTokens: [token], - rewardTokens: [apyReward ? [ARB_TOKEN.address, PROTOCOL_TOKEN.address] : null].filter(Boolean), + rewardTokens: [apyReward ? (ARB_TOKEN.address, PROTOCOL_TOKEN.address) : null].filter(Boolean), }; if (isPaused[i] === false) { poolReturned = { From a86ab8712209de0efe68d764b872a4f2387561cc Mon Sep 17 00:00:00 2001 From: Coopes <24834768+Cooops@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:41:28 -0600 Subject: [PATCH 3/4] last fix --- src/adaptors/lodestar-v1/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adaptors/lodestar-v1/index.js b/src/adaptors/lodestar-v1/index.js index 70215d697b..844af6bdb8 100755 --- a/src/adaptors/lodestar-v1/index.js +++ b/src/adaptors/lodestar-v1/index.js @@ -237,7 +237,7 @@ const main = async () => { apyBase, apyReward, underlyingTokens: [token], - rewardTokens: [apyReward ? (ARB_TOKEN.address, PROTOCOL_TOKEN.address) : null].filter(Boolean), + rewardTokens: [ARB_TOKEN.address, PROTOCOL_TOKEN.address], }; if (isPaused[i] === false) { poolReturned = { From 20a638aad739246522529ee0e0311d9d90c5e8aa Mon Sep 17 00:00:00 2001 From: Coopes <24834768+Cooops@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:06:44 -0600 Subject: [PATCH 4/4] adding date based logic --- src/adaptors/lodestar-v1/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/adaptors/lodestar-v1/index.js b/src/adaptors/lodestar-v1/index.js index 844af6bdb8..a5a9d726ca 100755 --- a/src/adaptors/lodestar-v1/index.js +++ b/src/adaptors/lodestar-v1/index.js @@ -223,7 +223,14 @@ const main = async () => { return ((arbPrices[ARB_TOKEN.address] * 50892 * 52) / denom) * 100; }; - const arbApyReward = calcRewardApyForArb(totalTvlUsd) + // Define the cut-off date (February 15th, 2024) for the ARB stip rewards + const cutOffDate = new Date('2024-02-15'); + const currentDate = new Date(); + + let arbApyReward = 0; + if (currentDate <= cutOffDate) { + arbApyReward = calcRewardApyForArb(totalTvlUsd); + } // Computed total (LODE + ARB rewards) const apyReward = baseApyReward + arbApyReward; @@ -237,7 +244,7 @@ const main = async () => { apyBase, apyReward, underlyingTokens: [token], - rewardTokens: [ARB_TOKEN.address, PROTOCOL_TOKEN.address], + rewardTokens: arbApyReward > 0 ? [ARB_TOKEN.address, PROTOCOL_TOKEN.address] : [PROTOCOL_TOKEN.address], }; if (isPaused[i] === false) { poolReturned = {