From 25842f5f5b425fcdf4b3db3678b8ac871f8d9368 Mon Sep 17 00:00:00 2001 From: 0xpeluche <110820448+0xpeluche@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:18:01 +0200 Subject: [PATCH] feat:Adapter,Euclid-finance,ethereum (#1398) --- .vscode/launch.json | 1 + .../euclid-finance/ethereum/balance.ts | 37 +++++++++++++++++++ src/adapters/euclid-finance/ethereum/index.ts | 31 ++++++++++++++++ src/adapters/euclid-finance/index.ts | 10 +++++ src/adapters/index.ts | 2 + 5 files changed, 81 insertions(+) create mode 100644 src/adapters/euclid-finance/ethereum/balance.ts create mode 100644 src/adapters/euclid-finance/ethereum/index.ts create mode 100644 src/adapters/euclid-finance/index.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 9f4eaec4a..ae7b01ddd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -205,6 +205,7 @@ "ethena", "ether.fi", "ethos-reserve", + "euclid-finance", "euler", "everrise", "exactly", diff --git a/src/adapters/euclid-finance/ethereum/balance.ts b/src/adapters/euclid-finance/ethereum/balance.ts new file mode 100644 index 000000000..1a3c68da8 --- /dev/null +++ b/src/adapters/euclid-finance/ethereum/balance.ts @@ -0,0 +1,37 @@ +import type { Balance, BalancesContext, Contract } from '@lib/adapter' +import { call } from '@lib/call' +import { abi as erc20Abi } from '@lib/erc20' +import { parseEther } from 'viem' +const abi = { + elETHPrice: { + inputs: [], + name: 'elETHPrice', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, +} as const + +const oracle: `0x${string}` = '0x0d7fD234d543A04CADEDa3Fc58dF524656707faC' + +const WETH: Contract = { + chain: 'ethereum', + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + decimals: 18, + symbol: 'WETH', +} + +export async function getEuclidBalance(ctx: BalancesContext, elETH: Contract): Promise { + const [userDeposit, exchangeRate] = await Promise.all([ + call({ ctx, target: elETH.address, params: [ctx.address], abi: erc20Abi.balanceOf }), + call({ ctx, target: oracle, abi: abi.elETHPrice }), + ]) + + return { + ...elETH, + amount: userDeposit, + underlyings: [{ ...WETH, amount: (userDeposit * exchangeRate) / parseEther('1.0') }], + rewards: undefined, + category: 'stake', + } +} diff --git a/src/adapters/euclid-finance/ethereum/index.ts b/src/adapters/euclid-finance/ethereum/index.ts new file mode 100644 index 000000000..4cbd5a5ad --- /dev/null +++ b/src/adapters/euclid-finance/ethereum/index.ts @@ -0,0 +1,31 @@ +import { getEuclidBalance } from '@adapters/euclid-finance/ethereum/balance' +import type { AdapterConfig, Contract, GetBalancesHandler } from '@lib/adapter' +import { resolveBalances } from '@lib/balance' + +const elETH: Contract = { + chain: 'ethereum', + address: '0xa1aeea28896f18ba85715ce9367f3689925ed428', + decimals: 18, + symbol: 'elETH', + underlyings: ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'], +} + +export const getContracts = () => { + return { + contracts: { elETH }, + } +} + +export const getBalances: GetBalancesHandler = async (ctx, contracts) => { + const balances = await resolveBalances(ctx, contracts, { + elETH: getEuclidBalance, + }) + + return { + groups: [{ balances }], + } +} + +export const config: AdapterConfig = { + startDate: 1707091200, +} diff --git a/src/adapters/euclid-finance/index.ts b/src/adapters/euclid-finance/index.ts new file mode 100644 index 000000000..593032db2 --- /dev/null +++ b/src/adapters/euclid-finance/index.ts @@ -0,0 +1,10 @@ +import type { Adapter } from '@lib/adapter' + +import * as ethereum from './ethereum' + +const adapter: Adapter = { + id: 'euclid-finance', + ethereum: ethereum, +} + +export default adapter diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 4b470b870..e92b65b69 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -114,6 +114,7 @@ import equilibria from '@adapters/equilibria' import ethena from '@adapters/ethena' import etherFi from '@adapters/ether.fi' import ethosReserve from '@adapters/ethos-reserve' +import euclidFinance from '@adapters/euclid-finance' import euler from '@adapters/euler' import everrise from '@adapters/everrise' import exactly from '@adapters/exactly' @@ -544,6 +545,7 @@ export const adapters: Adapter[] = [ ethena, etherFi, ethosReserve, + euclidFinance, euler, everrise, exactly,