From b28ac581592e44886119251b0d65eeedd95be47a Mon Sep 17 00:00:00 2001 From: Akira <156126180+akiraonstarknet@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:02:40 +0530 Subject: [PATCH] Bug: max withdraw, Optimize STRKFarm APYs loading (#149) * feat: harvest time ui * feat: display API data * fix: imports * fix: lint * fix: remove mock contract * fix: remove mock contract * fix: change query * Add tx history (#78) * Add GraphQL tx history (#77) * feat: use STRKFarm Graphql API to show tx history * add console.log statements for debugging * modify graphql query * fix: fix apollo client * refac: modify graphgl query * feat: implement function to get tx history using graphql * feat: show tx history in Strategy page * fix: fix linting issue * feat: implement function to get strategy address --------- Co-authored-by: Mystic <149405096+Gift-Naomi@users.noreply.github.com> Co-authored-by: Gift-Naomi * fix tx toast update delay, add earnings info, cleaned tx component --------- Co-authored-by: Mystic <149405096+Gift-Naomi@users.noreply.github.com> Co-authored-by: Gift-Naomi * add cache to /stats * Update og_nft_eligible_users.json * use u256 max for max withdraw * use u256 max for max withdraw * use u256 max for max withdraw [bug fix] * optimization: load strkfarm apy from api * optimization: load strkfarm apy from api [2] --------- Co-authored-by: Iwueseiter <156322726+Iwueseiter@users.noreply.github.com> Co-authored-by: Mystic <149405096+Gift-Naomi@users.noreply.github.com> Co-authored-by: Gift-Naomi --- package.json | 2 + public/og_nft_eligible_users.json | 18 ++- src/app/api/stats/route.ts | 6 +- src/app/api/strategies/route.ts | 16 ++- .../[strategyId]/_components/Strategy.tsx | 5 + src/components/Deposit.tsx | 34 +++-- src/components/HarvestTime.tsx | 29 +++- src/constants.ts | 3 + src/store/protocols.ts | 20 +-- src/store/strategies.atoms.ts | 13 +- src/store/strkfarm.atoms.ts | 132 ++++++++++++++++++ src/strategies/IStrategy.ts | 22 +-- src/strategies/auto_strk.strat.ts | 18 +-- src/strategies/delta_neutral_mm.ts | 23 ++- yarn.lock | 18 +++ 15 files changed, 293 insertions(+), 66 deletions(-) create mode 100644 src/store/strkfarm.atoms.ts diff --git a/package.json b/package.json index d49baa45..c57a3423 100755 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "@nikolovlazar/chakra-ui-prose": "1.2.1", "@prisma/client": "5.18.0", "@starknet-react/chains": "0.1.7", + "@apollo/client": "^3.11.8", + "graphql": "^16.9.0", "@starknet-react/core": "2.8.0", "@tanstack/query-core": "5.28.0", "@types/mixpanel-browser": "2.49.0", diff --git a/public/og_nft_eligible_users.json b/public/og_nft_eligible_users.json index 553b1d8e..209d843e 100644 --- a/public/og_nft_eligible_users.json +++ b/public/og_nft_eligible_users.json @@ -1,4 +1,5 @@ [ + "0x52a2dffcfa271420af69ae50b13345ccaa38fc04b09f350f33c8d0e3850a232", "0x5b55db55f5884856860e63f3595b2ec6b2c9555f3f507b4ca728d8e427b7864", "0x5095078578a59f8a9c17df97188db1b59574c6d4836dd3e705fe8537624228a", "0x18489438975ee3c6bc18add415d7889a9630547398f26bb5dee27481216a67d", @@ -19,6 +20,7 @@ "0x7a900c5b496d15bbb1c3c69d090e890a4b19dbceabee72232d4f2bec67ff4c", "0x7f5d5b58f2a1c504f6a8d0e47269c903485582308b6f3415c27a561e0d1a6fa", "0x17603b7963b1e2357a57e3c16f83abacef6bd8cf59e5394c34ae72ce566da2", + "0x27391b415a803a1aa7fffbed7db19336cf4b7f9bb1d3468986eef9a26341356", "0x4bbdde9359d8bc7e513f510f9080306dbf267acb41228a4706d1b55f2fd065d", "0x4015548595f22ccf56f6f42ada31a5d8eb7cb307c4e9e550b578d44fa25bcc", "0x50393e851e40de930abcd9569d9df55883b9f2836d4bae724f126d2258cd292", @@ -27,16 +29,26 @@ "0x14f59c23735b4aaaf6b6c0df567cacff9adc27f50dcb8b5270cf1237605c263", "0x6733e297fe300f78f48c7106ad550626377aa732cef360867218c08a536ea5e", "0x1ca34f742a91a588a3e770c8c8c8618a0713d7f64fda7935d42dcfcf4adffa0", + "0x571d4b6f5a34d7a43517d2eca4166804f753a643ec28bec0f51143bef50a9a6", "0x6a98eef8b1ce965ec9f6daf4c896f5c21217f2365652c30d462b13a1858ed7c", "0x5105649f42252f79109356e1c8765b7dcdb9bf4a6a68534e7fc962421c7efd2", "0x36177b6741a43c219602ce857c18e445920d5a6ea5f4ee3a0240e8ae319bbf5", - "0x679316db27cdb5d579d0508859ce450db3c2a2483e3628f7c1fc80b52e87634", - "0x7463d3ebcd4c6de2035cca849814bbba4dd7820dac25e074e78087903d1b585", + "0x47ccae4b7dccabd0689624812f7deeb3ed283dc3349b826974ff88107d71f4c", + "0x9fb60ac230ceeda227d28f138e327d2509d01531d20d9c8b2c4a7bf65afd8c", + "0x1f13873d0e2ff24321ca91d0530f093c25dc7b52d9316df8c2ec1a17fbfb5c1", "0x7342070d73d4ceef7e7c84420acb3026720e88fef10302fc11fd25a7ee0b715", "0x2b27457428b94b38ccad5339ebc17a211b7c482c008ac8ad22e01b30e923628", "0x67b72d3df972e5816b07ad4794af8e85c968409554281880149e96f09df1d56", + "0x1eb945a1b881a2d8f8d8ea5eada7ec42c999ab5e5ed225af7b62f00865bafbd", "0x73298a2ca8b06596d7bc85311c1c9d06458664a02a341655dee4e663600ac53", "0x297268ffc3c342f9c7fa3df6a5a6ef63ef5a5232ceaaf67168df686283effca", "0x16d730875c5dd15f3c1086523683bf5463fc11572405c8bee6e1ec65bead84e", - "0x5c755ba1828c70314349ec4c4ddaf310e648d5773f9bb6c4eb6ce2369288569" + "0x4d1b676e430b55175ce9ecbe073486a15411a8605c99aff8a14804fd4088da5", + "0x147b941bec50a2b497eb1bd966cf36e33ad3da7e508ebd5ea994978fa5be5a6", + "0x5a39462a82784de9f0f30c356f3fd5dfe71c7fa510bf22e8893cec254f59fc2", + "0x7364ce0a8aab411beddf7780f222b3508af4daf5c542bb258e9fe55ae5846ba", + "0x3d87ee70baf292cdc23c654153cfd711ff580a076d1dccc0dfd9d3eb62df311", + "0x63d87659aeb300ce268e872fd16d3d2ad5821444c438fae86f2b1fc39d26c17", + "0x6afcff37fe09b4d92f834475c70452c91ede180ddd387ec09191333f1f908a", + "0x6857c54d51eb6410f3a4974fc7f89b7735f4b135c587d62ca8bb725b7848bb9" ] diff --git a/src/app/api/stats/route.ts b/src/app/api/stats/route.ts index ee639367..c7c7b4f7 100755 --- a/src/app/api/stats/route.ts +++ b/src/app/api/stats/route.ts @@ -1,7 +1,7 @@ import { getStrategies } from '@/store/strategies.atoms'; import { NextResponse } from 'next/server'; -export const revalidate = 60; +export const revalidate = 1800; export async function GET(_req: Request) { const strategies = getStrategies(); @@ -28,7 +28,9 @@ export async function GET(_req: Request) { const result = await Promise.all(values); - return NextResponse.json({ + const response = NextResponse.json({ tvl: result.reduce((a, b) => a + b, 0), }); + + return response; } diff --git a/src/app/api/strategies/route.ts b/src/app/api/strategies/route.ts index 9b8ef1dd..29a3de66 100755 --- a/src/app/api/strategies/route.ts +++ b/src/app/api/strategies/route.ts @@ -4,7 +4,7 @@ import ZkLendAtoms from '@/store/zklend.store'; import { PoolInfo } from '@/store/pools'; import NostraLendingAtoms from '@/store/nostralending.store'; import { RpcProvider } from 'starknet'; -import { getStrategies } from '@/store/strategies.atoms'; +import { getLiveStatusNumber, getStrategies } from '@/store/strategies.atoms'; import { MY_STORE } from '@/store'; import MyNumber from '@/utils/MyNumber'; import { IStrategy, NFTInfo, TokenInfo } from '@/strategies/IStrategy'; @@ -42,7 +42,12 @@ async function getStrategyInfo(strategy: IStrategy) { id: strategy.id, apy: strategy.netYield, depositToken: strategy - .depositMethods(MyNumber.fromZero(), '', provider) + .depositMethods({ + amount: MyNumber.fromZero(), + address: '', + provider, + isMax: false, + }) .map((t) => t.tokenInfo.token), leverage: strategy.leverage, contract: strategy.holdingTokens.map((t) => ({ @@ -50,7 +55,12 @@ async function getStrategyInfo(strategy: IStrategy) { address: (t).token ? (t).token : (t).address, })), tvlUsd: tvl.usdValue || 0, - status: strategy.liveStatus, + status: { + number: getLiveStatusNumber(strategy.liveStatus), + value: strategy.liveStatus, + }, + riskFactor: strategy.riskFactor, + logo: strategy.holdingTokens[0].logo, }; } diff --git a/src/app/strategy/[strategyId]/_components/Strategy.tsx b/src/app/strategy/[strategyId]/_components/Strategy.tsx index d9866875..c8470759 100755 --- a/src/app/strategy/[strategyId]/_components/Strategy.tsx +++ b/src/app/strategy/[strategyId]/_components/Strategy.tsx @@ -440,6 +440,11 @@ const Strategy = ({ params }: StrategyParams) => { ))} + {strategy.actions.length == 0 && ( +
+ +
+ )} diff --git a/src/components/Deposit.tsx b/src/components/Deposit.tsx index fe8e568a..ea0ce96f 100755 --- a/src/components/Deposit.tsx +++ b/src/components/Deposit.tsx @@ -1,7 +1,11 @@ import { DUMMY_BAL_ATOM } from '@/store/balance.atoms'; import { StrategyInfo } from '@/store/strategies.atoms'; import { StrategyTxProps } from '@/store/transactions.atom'; -import { IStrategyActionHook, TokenInfo } from '@/strategies/IStrategy'; +import { + DepositActionInputs, + IStrategyActionHook, + TokenInfo, +} from '@/strategies/IStrategy'; import { MyMenuItemProps, MyMenuListProps } from '@/utils'; import MyNumber from '@/utils/MyNumber'; import { ChevronDownIcon } from '@chakra-ui/icons'; @@ -31,7 +35,6 @@ import { useAccount, useProvider } from '@starknet-react/core'; import { useAtomValue } from 'jotai'; import mixpanel from 'mixpanel-browser'; import { useEffect, useMemo, useState } from 'react'; -import { ProviderInterface } from 'starknet'; import LoadingWrap from './LoadingWrap'; import TxButton from './TxButton'; @@ -40,11 +43,7 @@ interface DepositProps { // ? If you want to add more button text, you can add here // ? @dev ensure below actionType is updated accordingly buttonText: 'Deposit' | 'Redeem'; - callsInfo: ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ) => IStrategyActionHook[]; + callsInfo: (inputs: DepositActionInputs) => IStrategyActionHook[]; } export default function Deposit(props: DepositProps) { @@ -57,8 +56,12 @@ export default function Deposit(props: DepositProps) { // This is the selected market token const [selectedMarket, setSelectedMarket] = useState( - props.callsInfo(MyNumber.fromZero(), address || '0x0', provider)[0] - .tokenInfo, + props.callsInfo({ + amount: MyNumber.fromZero(), + address: address || '0x0', + provider, + isMax: isMaxClicked, + })[0].tokenInfo, ); // This is processed amount stored in MyNumber format and meant for sending tx @@ -69,11 +72,13 @@ export default function Deposit(props: DepositProps) { // This is used to store the raw amount entered by the user const [rawAmount, setRawAmount] = useState(''); + const isDeposit = useMemo(() => props.buttonText === 'Deposit', [props]); + // use to maintain tx history and show toasts const txInfo: StrategyTxProps = useMemo(() => { return { strategyId: props.strategy.id, - actionType: props.buttonText === 'Deposit' ? 'deposit' : 'withdraw', + actionType: isDeposit ? 'deposit' : 'withdraw', amount, tokenAddr: selectedMarket.token, }; @@ -88,11 +93,16 @@ export default function Deposit(props: DepositProps) { // constructs tx calls const { calls, actions } = useMemo(() => { - const actions = props.callsInfo(amount, address || '0x0', provider); + const actions = props.callsInfo({ + amount, + address: address || '0x0', + provider, + isMax: isMaxClicked, + }); const hook = actions.find((a) => a.tokenInfo.name === selectedMarket.name); if (!hook) return { calls: [], actions }; return { calls: hook.calls, actions }; - }, [selectedMarket, amount, address, provider]); + }, [selectedMarket, amount, address, provider, isMaxClicked]); const balData = useAtomValue( actions.find((a) => a.tokenInfo.name === selectedMarket.name) diff --git a/src/components/HarvestTime.tsx b/src/components/HarvestTime.tsx index 7fa6a5b5..7c1b372f 100644 --- a/src/components/HarvestTime.tsx +++ b/src/components/HarvestTime.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from 'react'; import { Box, Flex, + Spinner, Stat, StatLabel, StatNumber, @@ -15,6 +16,9 @@ import { HarvestTimeAtom } from '@/store/harvest.atom'; import { useAtomValue } from 'jotai'; import { formatTimediff, getDisplayCurrencyAmount, timeAgo } from '@/utils'; import { isMobile } from 'react-device-detect'; +import STRKFarmAtoms, { + STRKFarmStrategyAPIResult, +} from '@/store/strkfarm.atoms'; interface HarvestTimeProps { strategy: StrategyInfo; @@ -70,6 +74,24 @@ const HarvestTime: React.FC = ({ strategy, balData }) => { return formatTimediff(nextHarvest); }, [data?.timestamp, lastHarvest]); + const strategiesInfo = useAtomValue(STRKFarmAtoms.baseAPRs!); + + const strategyInfo = useMemo(() => { + if (!strategiesInfo || !strategiesInfo.data) return null; + + const strategiesList: STRKFarmStrategyAPIResult[] = + strategiesInfo.data.strategies; + const strategyInfo = strategiesList.find( + (strat) => strat.id == strategy.id, + ); + return strategyInfo ? strategyInfo : null; + }, [strategiesInfo]); + + const leverage = useMemo(() => { + if (!strategyInfo) return 0; + return strategyInfo.leverage || 0; + }, [strategyInfo]); + return ( @@ -82,7 +104,7 @@ const HarvestTime: React.FC = ({ strategy, balData }) => { > APY - {(strategy.netYield * 100).toFixed(2)}% + {((strategyInfo?.apy || 0) * 100).toFixed(2)}% @@ -93,7 +115,10 @@ const HarvestTime: React.FC = ({ strategy, balData }) => { fontSize={'12px'} padding={'2px 5px'} > - 🔥{strategy.leverage.toFixed(2)}x boosted + 🔥{leverage.toFixed(2)}x boosted + {leverage == 0 && ( + + )} diff --git a/src/constants.ts b/src/constants.ts index bf22ad80..e69827ce 100755 --- a/src/constants.ts +++ b/src/constants.ts @@ -42,6 +42,9 @@ const CONSTANTS = { HAIKO: { BASE_APR_API: 'haiko/markets?network=mainnet', }, + STRKFarm: { + BASE_APR_API: '/api/strategies', + }, MY_SWAP: { POOLS_API: '/myswap/data/pools/all.json', BASE_APR_API: '/myswap/data/pools', diff --git a/src/store/protocols.ts b/src/store/protocols.ts index 4ad5a43a..14e0a707 100644 --- a/src/store/protocols.ts +++ b/src/store/protocols.ts @@ -17,8 +17,14 @@ import { Category, PoolInfo, PoolType } from './pools'; import { strategiesAtom } from './strategies.atoms'; import strkfarmLogo from '@public/logo.png'; import { IStrategyProps } from '@/strategies/IStrategy'; +import STRKFarmAtoms, { strkfarm } from './strkfarm.atoms'; export const PROTOCOLS = [ + { + name: strkfarm.name, + class: strkfarm, + atoms: STRKFarmAtoms, + }, { name: ekubo.name, class: ekubo, @@ -98,16 +104,10 @@ export const PROTOCOLS = [ export const ALL_FILTER = 'All'; -const allProtocols = [ - { - name: 'STRKFarm', - logo: strkfarmLogo.src, - }, - ...PROTOCOLS.map((p) => ({ - name: p.name, - logo: p.class.logo, - })), -]; +const allProtocols = PROTOCOLS.map((p) => ({ + name: p.name, + logo: p.class.logo, +})); export const filters = { categories: [...Object.values(Category)], types: [...Object.values(PoolType)], diff --git a/src/store/strategies.atoms.ts b/src/store/strategies.atoms.ts index dd465c5f..aba4eeca 100755 --- a/src/store/strategies.atoms.ts +++ b/src/store/strategies.atoms.ts @@ -110,7 +110,7 @@ export const strategiesAtom = atom((get) => { return strategies; }); -function getLiveStatusNumber(status: StrategyLiveStatus) { +export function getLiveStatusNumber(status: StrategyLiveStatus) { if (status == StrategyLiveStatus.NEW) { return 1; } else if (status == StrategyLiveStatus.ACTIVE) { @@ -120,3 +120,14 @@ function getLiveStatusNumber(status: StrategyLiveStatus) { } return 4; } + +export function getLiveStatusEnum(status: number) { + if (status == 1) { + return StrategyLiveStatus.NEW; + } else if (status == 2) { + return StrategyLiveStatus.ACTIVE; + } else if (status == 3) { + return StrategyLiveStatus.COMING_SOON; + } + return StrategyLiveStatus.RETIRED; +} diff --git a/src/store/strkfarm.atoms.ts b/src/store/strkfarm.atoms.ts new file mode 100644 index 00000000..6bda9228 --- /dev/null +++ b/src/store/strkfarm.atoms.ts @@ -0,0 +1,132 @@ +import CONSTANTS from '@/constants'; +import { + APRSplit, + Category, + PoolInfo, + PoolMetadata, + PoolType, + ProtocolAtoms, +} from './pools'; +import { atom } from 'jotai'; +import { IDapp } from './IDapp.store'; +import { AtomWithQueryResult, atomWithQuery } from 'jotai-tanstack-query'; +import strkfarmLogo from '@public/logo.png'; +import { getLiveStatusEnum } from './strategies.atoms'; + +export interface STRKFarmStrategyAPIResult { + name: string; + id: string; + apy: number; + depositToken: string[]; + leverage: number; + contract: { name: string; address: string }[]; + tvlUsd: number; + status: { + number: number; + value: string; + }; + riskFactor: number; + logo: string; +} + +export class STRKFarm extends IDapp { + name = 'STRKFarm'; + link = strkfarmLogo.src; + logo = 'https://app.jediswap.xyz/favicon/favicon-32x32.png'; + incentiveDataKey = 'Jediswap_v1'; + + _computePoolsInfo(data: any) { + const rawPools: STRKFarmStrategyAPIResult[] = data.strategies; + const pools: PoolInfo[] = []; + return rawPools.map((rawPool) => { + let category = Category.Others; + const poolName = rawPool.name; + const riskFactor = rawPool.riskFactor; + if (poolName.includes('USDC') || poolName.includes('USDT')) { + category = Category.Stable; + } else if (poolName.includes('STRK')) { + category = Category.STRK; + } + const poolInfo: PoolInfo = { + pool: { + id: rawPool.id, + name: poolName, + logos: [rawPool.logo], + }, + protocol: { + name: this.name, + link: this.link, + logo: this.logo, + }, + apr: rawPool.apy, + tvl: rawPool.tvlUsd, + aprSplits: [], + category, + type: PoolType.Derivatives, + lending: { + collateralFactor: 0, + }, + borrow: { + borrowFactor: 0, + apr: 0, + }, + additional: { + riskFactor, + tags: [getLiveStatusEnum(rawPool.status.number)], + isAudited: true, + }, + }; + return poolInfo; + }); + } + + getBaseAPY(p: PoolInfo, data: AtomWithQueryResult) { + const aprData: STRKFarmStrategyAPIResult[] = data.data.strategies; + let baseAPY: number | 'Err' = 'Err'; + let splitApr: APRSplit | null = null; + const metadata: PoolMetadata | null = null; + if (data.isSuccess) { + const item = aprData.find((doc) => doc.id === p.pool.id); + if (item) { + baseAPY = item.apy; + splitApr = { + apr: baseAPY, + title: 'Net APY', + description: 'Includes fees & Defi spring rewards', + }; + } + } + return { + baseAPY, + splitApr, + metadata, + }; + } +} + +export const strkfarm = new STRKFarm(); +const STRKFarmAtoms: ProtocolAtoms = { + baseAPRs: atomWithQuery((get) => ({ + queryKey: ['strkfarm_base_aprs'], + queryFn: async ({ + queryKey, + }): Promise<{ + strategies: STRKFarmStrategyAPIResult[]; + }> => { + const response = await fetch(`${CONSTANTS.STRKFarm.BASE_APR_API}`); + const data = await response.json(); + return data; + }, + })), + pools: atom((get) => { + const empty: PoolInfo[] = []; + if (!STRKFarmAtoms.baseAPRs) return empty; + const baseInfo = get(STRKFarmAtoms.baseAPRs); + if (baseInfo.data) { + const pools = strkfarm._computePoolsInfo(baseInfo.data); + return strkfarm.addBaseAPYs(pools, baseInfo); + } + return empty; + }), +}; +export default STRKFarmAtoms; diff --git a/src/strategies/IStrategy.ts b/src/strategies/IStrategy.ts index 67265f2d..db40a895 100755 --- a/src/strategies/IStrategy.ts +++ b/src/strategies/IStrategy.ts @@ -25,6 +25,7 @@ export interface TokenInfo { token: string; decimals: number; displayDecimals: number; + address?: string; name: string; logo: any; minAmount: MyNumber; @@ -79,6 +80,15 @@ export interface AmountInfo { tokenInfo: TokenInfo; } +export interface DepositActionInputs { + amount: MyNumber; + address: string; + provider: ProviderInterface; + isMax: boolean; +} + +export interface WithdrawActionInputs extends DepositActionInputs {} + export class IStrategyProps { readonly liveStatus: StrategyLiveStatus; readonly id: string; @@ -114,19 +124,11 @@ export class IStrategyProps { return `Risk factor: ${this.riskFactor}/5 (${factorLevel} risk)`; } - depositMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ): IStrategyActionHook[] => { + depositMethods = (inputs: DepositActionInputs): IStrategyActionHook[] => { return []; }; - withdrawMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ): IStrategyActionHook[] => { + withdrawMethods = (inputs: WithdrawActionInputs): IStrategyActionHook[] => { return []; }; diff --git a/src/strategies/auto_strk.strat.ts b/src/strategies/auto_strk.strat.ts index 9dd75bbf..be091ade 100755 --- a/src/strategies/auto_strk.strat.ts +++ b/src/strategies/auto_strk.strat.ts @@ -1,17 +1,19 @@ import CONSTANTS, { TOKENS, TokenName } from '@/constants'; import { PoolInfo } from '@/store/pools'; import { + DepositActionInputs, IStrategy, IStrategySettings, StrategyAction, StrategyLiveStatus, TokenInfo, + WithdrawActionInputs, } from './IStrategy'; import ERC20Abi from '@/abi/erc20.abi.json'; import AutoStrkAbi from '@/abi/autoStrk.abi.json'; import MasterAbi from '@/abi/master.abi.json'; import MyNumber from '@/utils/MyNumber'; -import { Contract, ProviderInterface, uint256 } from 'starknet'; +import { Contract, uint256 } from 'starknet'; import { atom } from 'jotai'; import { DUMMY_BAL_ATOM, @@ -165,11 +167,8 @@ export class AutoTokenStrategy extends IStrategy { // this.leverage = this.netYield / normalYield; // } - depositMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ) => { + depositMethods = (inputs: DepositActionInputs) => { + const { amount, address, provider } = inputs; const baseTokenInfo: TokenInfo = TOKENS.find( (t) => t.name == this.token.name, ) as TokenInfo; // @@ -247,11 +246,8 @@ export class AutoTokenStrategy extends IStrategy { ]; }; - withdrawMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ) => { + withdrawMethods = (inputs: WithdrawActionInputs) => { + const { amount, address, provider } = inputs; const frmToken: TokenInfo = TOKENS.find( (t) => t.token == this.strategyAddress, ) as TokenInfo; diff --git a/src/strategies/delta_neutral_mm.ts b/src/strategies/delta_neutral_mm.ts index ff5f6312..90a61887 100755 --- a/src/strategies/delta_neutral_mm.ts +++ b/src/strategies/delta_neutral_mm.ts @@ -1,18 +1,20 @@ import CONSTANTS, { NFTS, TokenName } from '@/constants'; import { PoolInfo } from '@/store/pools'; import { + DepositActionInputs, IStrategy, IStrategySettings, NFTInfo, StrategyAction, StrategyLiveStatus, TokenInfo, + WithdrawActionInputs, } from './IStrategy'; import { zkLend } from '@/store/zklend.store'; import ERC20Abi from '@/abi/erc20.abi.json'; import DeltaNeutralAbi from '@/abi/deltraNeutral.abi.json'; import MyNumber from '@/utils/MyNumber'; -import { Call, Contract, ProviderInterface, uint256 } from 'starknet'; +import { Call, Contract, uint256 } from 'starknet'; import { nostraLending } from '@/store/nostralending.store'; import { getPrice, getTokenInfoFromName, standariseAddress } from '@/utils'; import { @@ -233,11 +235,8 @@ export class DeltaNeutralMM extends IStrategy { ]; } - depositMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ) => { + depositMethods = (inputs: DepositActionInputs) => { + const { amount, address, provider } = inputs; const baseTokenInfo = this.token; if (!address || address == '0x0') { @@ -336,11 +335,8 @@ export class DeltaNeutralMM extends IStrategy { } }; - withdrawMethods = ( - amount: MyNumber, - address: string, - provider: ProviderInterface, - ) => { + withdrawMethods = (inputs: WithdrawActionInputs) => { + const { amount, address, provider, isMax } = inputs; const mainToken = { ...this.token }; // removing max amount restrictions on withdrawal @@ -365,8 +361,11 @@ export class DeltaNeutralMM extends IStrategy { provider, ); + const finalAmount = isMax + ? new MyNumber(uint256.UINT_256_MAX.toString(), amount.decimals) + : amount; const call = strategyContract.populate('withdraw', [ - uint256.bnToUint256(amount.toString()), + uint256.bnToUint256(finalAmount.toString()), address, 500, // 5% max slippage ]); diff --git a/yarn.lock b/yarn.lock index 24bb6498..8d96df68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6494,6 +6494,11 @@ rehackt@^0.1.0: resolved "https://registry.yarnpkg.com/rehackt/-/rehackt-0.1.0.tgz#a7c5e289c87345f70da8728a7eb878e5d03c696b" integrity sha512-7kRDOuLHB87D/JESKxQoRwv4DzbIdwkAGQ7p6QKGdVlY1IZheUnVhlk/4UZlNUVxdAXpyxikE3URsG067ybVzw== +<<<<<<< HEAD +<<<<<<< HEAD +======= +======= +>>>>>>> fb93dff (Add tx history (#78)) request-promise-core@1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.3.tgz#e9a3c081b51380dfea677336061fea879a829ee9" @@ -6501,6 +6506,7 @@ request-promise-core@1.1.3: dependencies: lodash "^4.17.15" +>>>>>>> e9f234a0c9a1a6d378aa3ac9ba7310f3486707ef require-directory@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" @@ -7321,6 +7327,11 @@ tslib@^2.3.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== +<<<<<<< HEAD +<<<<<<< HEAD +======= +======= +>>>>>>> fb93dff (Add tx history (#78)) tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" @@ -7333,6 +7344,7 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA== +>>>>>>> e9f234a0c9a1a6d378aa3ac9ba7310f3486707ef type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -7799,11 +7811,17 @@ yocto-queue@^1.0.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.1.1.tgz#fef65ce3ac9f8a32ceac5a634f74e17e5b232110" integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g== +<<<<<<< HEAD +======= yoctocolors-cjs@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242" integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA== +<<<<<<< HEAD +>>>>>>> e9f234a0c9a1a6d378aa3ac9ba7310f3486707ef +======= +>>>>>>> fb93dff (Add tx history (#78)) zen-observable-ts@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-1.2.5.tgz#6c6d9ea3d3a842812c6e9519209365a122ba8b58"