Skip to content

Commit

Permalink
feat:Adapter,Bank-ai,ethereum (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche authored Apr 9, 2024
1 parent d366d37 commit 585484b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"badger-dao",
"balancer",
"bancor-v3",
"bank-ai",
"basedmarkets",
"baseswap",
"bedrock-unieth",
Expand Down
33 changes: 33 additions & 0 deletions src/adapters/bank-ai/ethereum/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Balance, BalancesContext, Contract } from '@lib/adapter'
import { call } from '@lib/call'
import { abi as erc20Abi } from '@lib/erc20'

const abi = {
getLockPeriodEnd: {
inputs: [{ internalType: 'address', name: '_address', type: 'address' }],
name: 'getLockPeriodEnd',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
} as const

export async function getBankAiLockBalance(ctx: BalancesContext, locker: Contract): Promise<Balance> {
const [userBalance, userLockEnd] = await Promise.all([
call({ ctx, target: locker.address, params: [ctx.address], abi: erc20Abi.balanceOf }),
call({ ctx, target: locker.address, params: [ctx.address], abi: abi.getLockPeriodEnd }),
])

const now = Date.now() / 1000
const unlockAt = Number(userLockEnd)

return {
...locker,
amount: userBalance,
underlyings: undefined,
claimable: now > unlockAt ? userLockEnd : 0n,
unlockAt,
rewards: undefined,
category: 'lock',
}
}
29 changes: 29 additions & 0 deletions src/adapters/bank-ai/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { getBankAiLockBalance } from '@adapters/bank-ai/ethereum/balance'
import type { AdapterConfig, Contract, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'

const locker: Contract = {
chain: 'ethereum',
address: '0x140fae0a43190a3d0cbf8dbdb347200eb84e81d1',
token: '0xf19693068120185664E211F619c4F0530cE07088',
}

export const getContracts = () => {
return {
contracts: { locker },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
locker: getBankAiLockBalance,
})

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

export const config: AdapterConfig = {
startDate: 1711152000,
}
10 changes: 10 additions & 0 deletions src/adapters/bank-ai/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: 'bank-ai',
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 @@ -43,6 +43,7 @@ import babylonFinance from '@adapters/babylon-finance'
import badgerDao from '@adapters/badger-dao'
import balancer from '@adapters/balancer'
import bancorV3 from '@adapters/bancor-v3'
import bankAi from '@adapters/bank-ai'
import basedmarkets from '@adapters/basedmarkets'
import baseswap from '@adapters/baseswap'
import bedrockUnieth from '@adapters/bedrock-unieth'
Expand Down Expand Up @@ -472,6 +473,7 @@ export const adapters: Adapter[] = [
badgerDao,
balancer,
bancorV3,
bankAi,
basedmarkets,
baseswap,
bedrockUnieth,
Expand Down

0 comments on commit 585484b

Please sign in to comment.