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