Skip to content

Commit

Permalink
feat: remove nonexistent pool check
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpion9979 committed Apr 4, 2022
1 parent 32e12ff commit 032c064
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,32 @@ export class Bot {
tokenA: collateral,
tokenB: underlying,
});
if ((await this.provider.getCode(pair)) !== "0x") {
const contract = new Contract(pair, IUniswapV2Pair__factory.abi, this.signer) as IUniswapV2Pair;
// TODO: profitibility calculation for liquidation
// TODO: pop the collateral from persistence list after liquidation
const swapArgs: [BigNumberish, BigNumberish, string, string] = [
addressesAreEqual(token0, underlying) ? swapAmount : 0,
addressesAreEqual(token1, underlying) ? swapAmount : 0,
this.network.contracts.flashSwap,
utils.defaultAbiCoder.encode(
["tuple(address borrower, address bond, address collateral, int256 turnout)"],
[
{
borrower: account,
bond: bond,
collateral: collateral,
turnout: MinInt256,
},
],
),
];
// TODO: profitibility calculation (including gas)
const gLimit = await contract.estimateGas.swap(...swapArgs);
const gPrice = await this.provider.getGasPrice();
const gPriceMod = gPrice.mul(150).div(100);
const tx = await contract.swap(...swapArgs, { gasPrice: gPriceMod, gasLimit: gLimit });
const receipt = await tx.wait(1);
Logger.notice("Submitted liquidation at hash: %s", receipt.transactionHash);
}
const contract = new Contract(pair, IUniswapV2Pair__factory.abi, this.signer) as IUniswapV2Pair;
// TODO: profitibility calculation for liquidation
// TODO: pop the collateral from persistence list after liquidation
const swapArgs: [BigNumberish, BigNumberish, string, string] = [
addressesAreEqual(token0, underlying) ? swapAmount : 0,
addressesAreEqual(token1, underlying) ? swapAmount : 0,
this.network.contracts.flashSwap,
utils.defaultAbiCoder.encode(
["tuple(address borrower, address bond, address collateral, int256 turnout)"],
[
{
borrower: account,
bond: bond,
collateral: collateral,
turnout: MinInt256,
},
],
),
];
// TODO: profitibility calculation (including gas)
const gLimit = await contract.estimateGas.swap(...swapArgs);
const gPrice = await this.provider.getGasPrice();
const gPriceMod = gPrice.mul(150).div(100);
const tx = await contract.swap(...swapArgs, { gasPrice: gPriceMod, gasLimit: gLimit });
const receipt = await tx.wait(1);
Logger.notice("Submitted liquidation at hash: %s", receipt.transactionHash);
}

private async liquidateAllMature(_latestBlock: number): Promise<void> {
Expand Down

0 comments on commit 032c064

Please sign in to comment.