diff --git a/.vscode/launch.json b/.vscode/launch.json index 12d9b5af5..730fd9806 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -194,6 +194,7 @@ "ellipsis-finance", "equalizer-exchange", "equilibria", + "ethena", "ether.fi", "ethos-reserve", "euler", diff --git a/src/adapters/ethena/ethereum/balance.ts b/src/adapters/ethena/ethereum/balance.ts new file mode 100644 index 000000000..8c671e85a --- /dev/null +++ b/src/adapters/ethena/ethereum/balance.ts @@ -0,0 +1,64 @@ +import type { Balance, BalancesContext, Contract } from '@lib/adapter' +import { call } from '@lib/call' +import { abi as erc20Abi } from '@lib/erc20' + +const abi = { + stakes: { + inputs: [ + { internalType: 'address', name: '', type: 'address' }, + { internalType: 'address', name: '', type: 'address' }, + ], + name: 'stakes', + outputs: [ + { internalType: 'uint256', name: 'stakedAmount', type: 'uint256' }, + { internalType: 'uint152', name: 'coolingDownAmount', type: 'uint152' }, + { internalType: 'uint104', name: 'cooldownStartTimestamp', type: 'uint104' }, + ], + stateMutability: 'view', + type: 'function', + }, + convertToAssets: { + inputs: [{ internalType: 'uint256', name: 'shares', type: 'uint256' }], + name: 'convertToAssets', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, +} as const + +const USDe: Contract = { + chain: 'ethereum', + address: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3', + decimals: 18, + symbol: 'USDe', +} + +export async function getEthenaFarmBalance(ctx: BalancesContext, farmer: Contract): Promise { + const [stakedAmount, coolingDownAmount] = await call({ + ctx, + target: farmer.address, + params: [ctx.address, farmer.token!], + abi: abi.stakes, + }) + + return { + ...farmer, + amount: stakedAmount + coolingDownAmount, + underlyings: undefined, + rewards: undefined, + category: 'farm', + } +} + +export async function getEthenaStakeBalance(ctx: BalancesContext, staker: Contract): Promise { + const userShare = await call({ ctx, target: staker.address, params: [ctx.address], abi: erc20Abi.balanceOf }) + const userAsset = await call({ ctx, target: staker.address, params: [userShare], abi: abi.convertToAssets }) + + return { + ...staker, + amount: userShare, + underlyings: [{ ...USDe, amount: userAsset }], + rewards: undefined, + category: 'stake', + } +} diff --git a/src/adapters/ethena/ethereum/index.ts b/src/adapters/ethena/ethereum/index.ts new file mode 100644 index 000000000..b50094a87 --- /dev/null +++ b/src/adapters/ethena/ethereum/index.ts @@ -0,0 +1,36 @@ +import { getEthenaFarmBalance, getEthenaStakeBalance } from '@adapters/ethena/ethereum/balance' +import type { AdapterConfig, Contract, GetBalancesHandler } from '@lib/adapter' +import { resolveBalances } from '@lib/balance' + +const staker: Contract = { + chain: 'ethereum', + address: '0x9d39a5de30e57443bff2a8307a4256c8797a3497', + underlyings: ['0x4c9edd5852cd905f086c759e8383e09bff1e68b3'], +} + +const farmer: Contract = { + chain: 'ethereum', + address: '0x8707f238936c12c309bfc2b9959c35828acfc512', + token: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3', +} + +export const getContracts = () => { + return { + contracts: { staker, farmer }, + } +} + +export const getBalances: GetBalancesHandler = async (ctx, contracts) => { + const balances = await resolveBalances(ctx, contracts, { + staker: getEthenaStakeBalance, + farmer: getEthenaFarmBalance, + }) + + return { + groups: [{ balances }], + } +} + +export const config: AdapterConfig = { + startDate: undefined, +} diff --git a/src/adapters/ethena/index.ts b/src/adapters/ethena/index.ts new file mode 100644 index 000000000..3a75dae10 --- /dev/null +++ b/src/adapters/ethena/index.ts @@ -0,0 +1,10 @@ +import type { Adapter } from '@lib/adapter' + +import * as ethereum from './ethereum' + +const adapter: Adapter = { + id: 'ethena', + ethereum: ethereum, +} + +export default adapter diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 97436621b..a98422fca 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -103,6 +103,7 @@ import elephantMoney from '@adapters/elephant-money' import ellipsisFinance from '@adapters/ellipsis-finance' import equalizerExchange from '@adapters/equalizer-exchange' import equilibria from '@adapters/equilibria' +import ethena from '@adapters/ethena' import etherFi from '@adapters/ether.fi' import ethosReserve from '@adapters/ethos-reserve' import euler from '@adapters/euler' @@ -509,6 +510,7 @@ export const adapters: Adapter[] = [ ellipsisFinance, equalizerExchange, equilibria, + ethena, etherFi, ethosReserve, euler,