Skip to content

Instantly share code, notes, and snippets.

@Ro5s
Created August 1, 2021 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ro5s/3f84b7097a04cbbb425097ead3796208 to your computer and use it in GitHub Desktop.
Save Ro5s/3f84b7097a04cbbb425097ead3796208 to your computer and use it in GitHub Desktop.
stake xsushi atoken into xsushi bento shares
import { t } from '@lingui/macro'
import { AXSUSHI, XSUSHI } from '../../../constants'
import { ChainId, SUSHI_ADDRESS } from '@sushiswap/sdk'
import { tryParseAmount } from '../../../functions'
import { useBentoBalance } from '../../bentobox/hooks'
import { useActiveWeb3React } from '../../../hooks'
import { useTokenBalances } from '../../wallet/hooks'
import { StrategyGeneralInfo, StrategyHook, StrategyTokenDefinitions } from '../types'
import useBaseInariStrategy from './useBaseInariStrategy'
import { useEffect, useMemo } from 'react'
export const general: StrategyGeneralInfo = {
name: 'Aave → Bento',
steps: ['AXSUSHI', 'xSUSHI', 'BentoBox'],
zapMethod: 'aaveToBento',
unzapMethod: 'bentoToAave',
description: t`Migrate xSUSHI from Aave into BentoBox in one click. xSUSHI in BentoBox is automatically
invested into a passive yield strategy, and can be lent or used as collateral for borrowing in Kashi.`,
inputSymbol: 'xSUSHI in Aave',
outputSymbol: 'xSUSHI in BentoBox',
}
export const tokenDefinitions: StrategyTokenDefinitions = {
inputToken: {
chainId: ChainId.MAINNET,
address: '0xf256cc7847e919fac9b808cc216cac87ccf2f47a',
decimals: 18,
symbol: 'aXSUSHI',
},
outputToken: {
chainId: ChainId.MAINNET,
address: '0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272',
decimals: 18,
symbol: 'XSUSHI',
},
}
const useAaveToBentoStrategy = (): StrategyHook => {
const { account } = useActiveWeb3React()
const balances = useTokenBalances(account, [AXSUSHI, XSUSHI])
const xSushiBentoBalance = useBentoBalance(XSUSHI.address)
const { setBalances, ...baseStrategy } = useBaseInariStrategy({
id: 'aaveToBentoStrategy',
general,
tokenDefinitions,
usesBentoBox: true,
})
useEffect(() => {
if (!balances) return
setBalances({
inputTokenBalance: balances[AXSUSHI[ChainId.MAINNET].address],
outputTokenBalance: tryParseAmount(xSushiBentoBalance?.value?.toFixed(18) || '0', XSUSHI),
})
}, [balances, setBalances, xSushiBentoBalance?.value])
return useMemo(
() => ({
setBalances,
...baseStrategy,
}),
[baseStrategy, setBalances]
)
}
export default useAaveToBentoStrategy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment