Last active
September 11, 2023 22:09
-
-
Save chuckbergeron/12695619dadb67d17f92d319db85de10 to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Arbitrage Bot, Optimal Amount Ins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BigNumber, ethers } from 'ethers'; | |
import { Contract } from 'ethers'; | |
import { Provider } from '@ethersproject/providers'; | |
import { getLiquidationPairComputeExactAmountInMulticall } | |
from '@generationsoftware/pt-v5-autotasks-library'; | |
const { amountIn, amountInMin, wantedAmountsIn } = await calculateAmountIn( | |
readProvider, | |
liquidationPairContract, | |
originalMaxAmountOut, | |
wantedAmountsOut, | |
); | |
// Calculates optimal input parameters for the swap call based on current | |
// state of the auction | |
const calculateAmountIn = async ( | |
readProvider: Provider, | |
liquidationPairContract: Contract, | |
originalMaxAmountOut: BigNumber, | |
wantedAmountsOut: BigNumber[], | |
): Promise<{ | |
amountIn: BigNumber; | |
amountInMin: BigNumber; | |
wantedAmountsIn: BigNumber[]; | |
}> => { | |
let wantedAmountsIn = []; | |
const amountIn: BigNumber = await liquidationPairContract | |
.callStatic.computeExactAmountIn(originalMaxAmountOut); | |
const amountInMin = ethers.constants.MaxInt256; | |
wantedAmountsIn = await getLiquidationPairComputeExactAmountInMulticall( | |
liquidationPairContract, | |
wantedAmountsOut, | |
readProvider, | |
); | |
return { | |
amountIn, | |
amountInMin, | |
wantedAmountsIn, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment