Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Adapter,Ethena,Ethereum #1368

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"ellipsis-finance",
"equalizer-exchange",
"equilibria",
"ethena",
"ether.fi",
"ethos-reserve",
"euler",
Expand Down
64 changes: 64 additions & 0 deletions src/adapters/ethena/ethereum/balance.ts
Original file line number Diff line number Diff line change
@@ -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<Balance> {
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<Balance> {
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',
}
}
36 changes: 36 additions & 0 deletions src/adapters/ethena/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
staker: getEthenaStakeBalance,
farmer: getEthenaFarmBalance,
})

return {
groups: [{ balances }],
}
}

export const config: AdapterConfig = {
startDate: undefined,
}
10 changes: 10 additions & 0 deletions src/adapters/ethena/index.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -509,6 +510,7 @@ export const adapters: Adapter[] = [
ellipsisFinance,
equalizerExchange,
equilibria,
ethena,
etherFi,
ethosReserve,
euler,
Expand Down
Loading