Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 11, 2023 22:00
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/494d3ecef4cf20ffdc79c3b07c19faa4 to your computer and use it in GitHub Desktop.
Save chuckbergeron/494d3ecef4cf20ffdc79c3b07c19faa4 to your computer and use it in GitHub Desktop.
PoolTogether v5 Hyperstructure - Arbitrage Bot, Optimal Amount Outs
const { originalMaxAmountOut, wantedAmountsOut } = await calculateAmountOut(
liquidationPairContract,
context,
);
// Calculates necessary input parameters for the swap call based on current state
// of the contracts
const calculateAmountOut = async (
liquidationPair: Contract,
context: ArbLiquidatorContext,
): Promise<{
originalMaxAmountOut: BigNumber;
wantedAmountsOut: BigNumber[];
}> => {
const wantedAmountsOut = [];
const amountOut = await liquidationPair.callStatic.maxAmountOut();
// Get multiple data points across the auction function to determine
// the most amount of profitability (most amount out for least amount
// of token in depending on the state of the gradual auction)
for (let i = 1; i <= 100; i++) {
const amountToSendPercent = i;
const wantedAmountOut = amountOut
.mul(ethers.BigNumber.from(amountToSendPercent))
.div(100);
wantedAmountsOut.push(wantedAmountOut);
}
return {
originalMaxAmountOut: amountOut,
wantedAmountsOut,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment