Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 11, 2023 22:09
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 chuckbergeron/12695619dadb67d17f92d319db85de10 to your computer and use it in GitHub Desktop.
Save chuckbergeron/12695619dadb67d17f92d319db85de10 to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Arbitrage Bot, Optimal Amount Ins
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