Skip to content

Commit

Permalink
Add Ethena token and filtering for mainnet (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively authored Apr 5, 2024
1 parent aafaa47 commit d39a24c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
11 changes: 9 additions & 2 deletions earn/src/data/LendingPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class LendingPair {
public rewardsRate0: number,
public rewardsRate1: number,
public factoryData: FactoryData,
public oracleData: OracleData
public oracleData: OracleData,
public lastWrite: Date
) {}

equals(other: LendingPair) {
Expand Down Expand Up @@ -187,6 +188,11 @@ export async function getAvailableLendingPairs(
methodName: 'consult',
methodParameters: [market.pool, Q32],
},
{
reference: `${market.pool}-oracleLastWrite`,
methodName: 'lastWrites',
methodParameters: [market.pool],
},
],
});

Expand Down Expand Up @@ -284,7 +290,8 @@ export async function getAvailableLendingPairs(
toImpreciseNumber(basics0[7], 18), // rewardsRate0
toImpreciseNumber(basics1[7], 18), // rewardsRate1
asFactoryData(factoryResult),
asOracleData(oracleResult)
asOracleData(oracleResult),
new Date(oracleReturnContexts[1].returnValues[1] * 1000) // lastWrite.time
)
);
});
Expand Down
79 changes: 43 additions & 36 deletions earn/src/pages/MarketsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,42 +259,49 @@ export default function MarketsPage() {
const token1Balance = balancesMap.get(pair.token1.address)?.value || 0;
const kitty0Balance = balancesMap.get(pair.kitty0.address)?.value || 0;
const kitty1Balance = balancesMap.get(pair.kitty1.address)?.value || 0;
rows.push({
asset: pair.token0,
kitty: pair.kitty0,
apy: pair.kitty0Info.lendAPY * 100,
rewardsRate: pair.rewardsRate0,
collateralAssets: [pair.token1],
totalSupply: pair.kitty0Info.totalAssets.toNumber(),
suppliedBalance: kitty0Balance,
suppliableBalance: token0Balance,
isOptimized: true,
...(token0Price > 0
? {
totalSupplyUsd: pair.kitty0Info.totalAssets.toNumber() * token0Price,
suppliedBalanceUsd: kitty0Balance * token0Price,
suppliableBalanceUsd: token0Balance * token0Price,
}
: {}),
});
rows.push({
asset: pair.token1,
kitty: pair.kitty1,
apy: pair.kitty1Info.lendAPY * 100,
rewardsRate: pair.rewardsRate1,
collateralAssets: [pair.token0],
totalSupply: pair.kitty1Info.totalAssets.toNumber(),
suppliedBalance: kitty1Balance,
suppliableBalance: token1Balance,
isOptimized: true,
...(token1Price > 0
? {
totalSupplyUsd: pair.kitty1Info.totalAssets.toNumber() * token1Price,
suppliedBalanceUsd: kitty1Balance * token1Price,
suppliableBalanceUsd: token1Balance * token1Price,
}
: {}),
});

const oracleHasBeenUpdatedInPastWeek = pair.lastWrite.getTime() > Date.now() - 7 * 24 * 60 * 60 * 1000;

if (kitty0Balance > 0 || oracleHasBeenUpdatedInPastWeek) {
rows.push({
asset: pair.token0,
kitty: pair.kitty0,
apy: pair.kitty0Info.lendAPY * 100,
rewardsRate: pair.rewardsRate0,
collateralAssets: [pair.token1],
totalSupply: pair.kitty0Info.totalAssets.toNumber(),
suppliedBalance: kitty0Balance,
suppliableBalance: token0Balance,
isOptimized: true,
...(token0Price > 0
? {
totalSupplyUsd: pair.kitty0Info.totalAssets.toNumber() * token0Price,
suppliedBalanceUsd: kitty0Balance * token0Price,
suppliableBalanceUsd: token0Balance * token0Price,
}
: {}),
});
}
if (kitty1Balance > 0 || oracleHasBeenUpdatedInPastWeek) {
rows.push({
asset: pair.token1,
kitty: pair.kitty1,
apy: pair.kitty1Info.lendAPY * 100,
rewardsRate: pair.rewardsRate1,
collateralAssets: [pair.token0],
totalSupply: pair.kitty1Info.totalAssets.toNumber(),
suppliedBalance: kitty1Balance,
suppliableBalance: token1Balance,
isOptimized: true,
...(token1Price > 0
? {
totalSupplyUsd: pair.kitty1Info.totalAssets.toNumber() * token1Price,
suppliedBalanceUsd: kitty1Balance * token1Price,
suppliableBalanceUsd: token1Balance * token1Price,
}
: {}),
});
}
});
return rows;
}, [balancesMap, lendingPairs, tokenQuotes]);
Expand Down
Binary file added shared/src/assets/png/ethena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion shared/src/data/TokenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Address } from 'wagmi';
import { arbitrum, optimism, mainnet, goerli } from 'wagmi/chains';

import BrettLogo from '../assets/png/brett.png';
import EthenaLogo from '../assets/png/ethena.png';
import ToshiLogo from '../assets/png/toshi.png';
import {
ApeLogo,
Expand All @@ -28,7 +29,6 @@ import {
RplLogo,
SnxLogo,
UniLogo,
UnknownTokenLogo,
UsdbcLogo,
UsdcLogo,
UsdtLogo,
Expand Down Expand Up @@ -153,6 +153,8 @@ const BADGER_MAINNET = new Token(
BadgerLogo
);

const ENA_MAINNET = new Token(mainnet.id, '0x57e114b691db790c35207b2e685d4a43181e6061', 18, 'ENA', 'ENA', EthenaLogo);

const DAI_OPTIMISM = new Token(
optimism.id,
'0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
Expand Down Expand Up @@ -440,6 +442,7 @@ const TOKEN_DATA: { [chainId: number]: { [address: Address]: Token } } = {
[RPL_MAINNET.address]: RPL_MAINNET,
[MATIC_MAINNET.address]: MATIC_MAINNET,
[LDO_MAINNET.address]: LDO_MAINNET,
[ENA_MAINNET.address]: ENA_MAINNET,
},
[goerli.id]: {
[USDC_GOERLI.address]: USDC_GOERLI,
Expand Down

0 comments on commit d39a24c

Please sign in to comment.