import { IParaSwapLiquiditySwapAdapter__factory , IParaSwapLiquiditySwapAdapter , } from '../contract-types' ; import LiquiditySwapAdapterInterface from '../interfaces/LiquiditySwapAdapterParaswap' ; import { Configuration , eEthereumTxType , EthereumTransactionTypeExtended , LendingPoolMarketConfig , ProtocolAction , transactionType , } from '../types' ; import { SwapAndDepositMethodType } from '../types/LiquiditySwapAdapterParaswapMethodTypes' ; import { LiquiditySwapValidator } from '../validators/methodValidators' ; import { IsEthAddress , IsPositiveAmount } from '../validators/paramValidators' ; import BaseService from './BaseService' ; export function augustusFromAmountOffsetFromCalldata ( calldata ) { switch ( calldata . slice ( 0 , 10 ) ) { case '0xda8567c8' : return 100 ; case '0x58b9d179' : return 4 ; case '0x0863b7ac' : return 68 ; case '0x8f00eccb' : return 68 ; case '0xec1d21dd' : return 68 ; case '0x54840d1a' : return 4 ; case '0xf5661034' : return 68 ; case '0x64466805' : return 68 ; case '0xa94e78ef' : return 68 ; case '0x46c67b6d' : return 68 ; default : throw new Error ( 'Unrecognized function selector for Augustus' ) ; } } export default class LiquiditySwapAdapterService extends BaseService < IParaSwapLiquiditySwapAdapter > implements LiquiditySwapAdapterInterface { readonly liquiditySwapAdapterAddress : string ; readonly swapCollateralConfig : LendingPoolMarketConfig | undefined ; constructor ( config , swapCollateralConfig ) { super ( config , IParaSwapLiquiditySwapAdapter__factory ) ; this . swapCollateralConfig = swapCollateralConfig ; this . liquiditySwapAdapterAddress = this . swapCollateralConfig ?. SWAP_COLLATERAL_ADAPTER || '' ; } @ LiquiditySwapValidator public swapAndDeposit ( @ IsEthAddress ( 'user' ) @ IsEthAddress ( 'assetToSwapFrom' ) @ IsEthAddress ( 'assetToSwapTo' ) @ IsEthAddress ( 'augustus' ) @ IsPositiveAmount ( 'amountToSwap' ) @ IsPositiveAmount ( 'minAmountToReceive' ) { user , assetToSwapFrom , assetToSwapTo , amountToSwap , minAmountToReceive , permitParams , augustus , swapCallData , swapAll , } , txs ? ) { const liquiditySwapContract = this . getContractInstance ( this . liquiditySwapAdapterAddress ) ; const txCallback = this . generateTxCallback ( { rawTxMethod : ( ) => liquiditySwapContract . populateTransaction . swapAndDeposit ( assetToSwapFrom , assetToSwapTo , amountToSwap , minAmountToReceive , swapAll ? augustusFromAmountOffsetFromCalldata ( swapCallData as string ) : 0 , swapCallData , augustus , permitParams ) , from : user , } ) ; return { tx : txCallback , txType : eEthereumTxType . DLP_ACTION , gas : this . generateTxPriceEstimation ( txs || [ ] , txCallback , ProtocolAction . swapCollateral ) , } ; } }