diff --git a/src/components/Deposit.tsx b/src/components/Deposit.tsx index f5ace6e..ea0ce96 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, uint256 } 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 @@ -90,11 +93,12 @@ export default function Deposit(props: DepositProps) { // constructs tx calls const { calls, actions } = useMemo(() => { - const amountParam = - isMaxClicked && !isDeposit - ? new MyNumber(uint256.UINT_256_MAX.toString(), amount.decimals) - : amount; - const actions = props.callsInfo(amountParam, 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 }; diff --git a/src/strategies/IStrategy.ts b/src/strategies/IStrategy.ts index 67265f2..a45e7dc 100755 --- a/src/strategies/IStrategy.ts +++ b/src/strategies/IStrategy.ts @@ -79,6 +79,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 +123,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 9dd75bb..be091ad 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 ff5f631..90a6188 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 ]);