Skip to content

Commit

Permalink
feat:Adapter,Mover,Ethreum (#1391)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche authored Apr 3, 2024
1 parent bc30bbd commit 2b88df6
Show file tree
Hide file tree
Showing 5 changed files with 126 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 @@ -317,6 +317,7 @@
"morpho-blue",
"morpho-compound",
"mountain-protocol",
"mover",
"mstable",
"mu-exchange",
"mugenfinance",
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ import morphoAavev3 from '@adapters/morpho-aavev3'
import morphoBlue from '@adapters/morpho-blue'
import morphoCompound from '@adapters/morpho-compound'
import mountainProtocol from '@adapters/mountain-protocol'
import mover from '@adapters/mover'
import mstable from '@adapters/mstable'
import muExchange from '@adapters/mu-exchange'
import mugenfinance from '@adapters/mugenfinance'
Expand Down Expand Up @@ -650,6 +651,7 @@ export const adapters: Adapter[] = [
morphoBlue,
morphoCompound,
mountainProtocol,
mover,
mstable,
muExchange,
mugenfinance,
Expand Down
83 changes: 83 additions & 0 deletions src/adapters/mover/ethereum/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { Balance, BalancesContext, Contract } from '@lib/adapter'
import { call } from '@lib/call'
import { abi as erc20Abi } from '@lib/erc20'
import { getUnderlyingBalances } from '@lib/uniswap/v2/pair'

const abi = {
pendingBonus: {
inputs: [{ internalType: 'address', name: '_account', type: 'address' }],
name: 'pendingBonus',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
userInfoMove: {
inputs: [{ internalType: 'address', name: '', type: 'address' }],
name: 'userInfoMove',
outputs: [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'uint256', name: 'rewardTally', type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
userInfoMoveEthLP: {
inputs: [{ internalType: 'address', name: '', type: 'address' }],
name: 'userInfoMoveEthLP',
outputs: [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'uint256', name: 'rewardTally', type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
} as const

const MOVE: Contract = {
chain: 'ethereum',
address: '0x3fa729b4548becbad4eab6ef18413470e6d5324c',
decimals: 18,
symbol: 'MOVE',
}

const WETH: Contract = {
chain: 'ethereum',
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
decimals: 18,
symbol: 'WETH',
}

export async function getMoverBalance(ctx: BalancesContext, farmer: Contract): Promise<Balance | undefined> {
const underlyings = farmer.underlyings as Contract[]
const subUnderlyings = [MOVE, WETH]
if (!underlyings) return

const [userShare, [moveAmount], [ethAmount], pendingBonus] = await Promise.all([
call({ ctx, target: farmer.address, params: [ctx.address], abi: erc20Abi.balanceOf }),
call({ ctx, target: farmer.address, params: [ctx.address], abi: abi.userInfoMove }),
call({ ctx, target: farmer.address, params: [ctx.address], abi: abi.userInfoMoveEthLP }),
call({ ctx, target: farmer.address, params: [ctx.address], abi: abi.pendingBonus }),
])

const amounts = [moveAmount, ethAmount]

for (let i = 0; i < underlyings.length; i++) {
underlyings[i].amount = amounts[i]
}

if (underlyings[1] && underlyings[1].amount! > 0n) {
underlyings[1].underlyings = subUnderlyings
const [subUnderlyingsBalance] = await getUnderlyingBalances(ctx, [underlyings[1] as Balance])

underlyings[0].amount! += (subUnderlyingsBalance.underlyings![0] as Contract).amount!
underlyings[1] = subUnderlyingsBalance.underlyings![1] as Contract
}

return {
...farmer,
amount: userShare,
underlyings,
rewards: [{ ...(farmer.rewards![0] as Contract), amount: pendingBonus }],
category: 'stake',
}
}
30 changes: 30 additions & 0 deletions src/adapters/mover/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getMoverBalance } from '@adapters/mover/ethereum/balance'
import type { AdapterConfig, Contract, GetBalancesHandler } from '@lib/adapter'
import { resolveBalances } from '@lib/balance'

const MOBO: Contract = {
chain: 'ethereum',
address: '0x94f748bfd1483750a7df01acd993213ab64c960f',
underlyings: ['0x3fa729b4548becbad4eab6ef18413470e6d5324c', '0x87b918e76c92818db0c76a4e174447aee6e6d23f'],
rewards: ['0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'],
}

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

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

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

export const config: AdapterConfig = {
startDate: 1642550400,
}
10 changes: 10 additions & 0 deletions src/adapters/mover/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: 'mover',
ethereum: ethereum,
}

export default adapter

0 comments on commit 2b88df6

Please sign in to comment.