Skip to content

Instantly share code, notes, and snippets.

@chuckbergeron
Last active September 11, 2023 22:00
Show Gist options
  • Select an option

  • Save chuckbergeron/494d3ecef4cf20ffdc79c3b07c19faa4 to your computer and use it in GitHub Desktop.

Select an option

Save chuckbergeron/494d3ecef4cf20ffdc79c3b07c19faa4 to your computer and use it in GitHub Desktop.

Revisions

  1. chuckbergeron renamed this gist Sep 11, 2023. 1 changed file with 0 additions and 0 deletions.
  2. chuckbergeron revised this gist Sep 11, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion pt-v5-arb-3-optimal-amounts.ts
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,9 @@ const calculateAmountOut = async (
    // 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);
    const wantedAmountOut = amountOut
    .mul(ethers.BigNumber.from(amountToSendPercent))
    .div(100);

    wantedAmountsOut.push(wantedAmountOut);
    }
  3. chuckbergeron revised this gist Sep 11, 2023. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions pt-v5-arb-3-optimal-amounts.ts
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,8 @@ const { originalMaxAmountOut, wantedAmountsOut } = await calculateAmountOut(
    context,
    );

    /**
    * Calculates necessary input parameters for the swap call based on current state of the contracts
    * @returns {Promise} Promise object with the input parameters exactAmountIn and amountOutMin
    */
    // Calculates necessary input parameters for the swap call based on current state
    // of the contracts
    const calculateAmountOut = async (
    liquidationPair: Contract,
    context: ArbLiquidatorContext,
    @@ -17,8 +15,9 @@ const calculateAmountOut = async (
    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, depends on the state of the gradual auction)
    // 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);
  4. chuckbergeron revised this gist Sep 11, 2023. 1 changed file with 32 additions and 14 deletions.
    46 changes: 32 additions & 14 deletions pt-v5-arb-3-optimal-amounts.ts
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,33 @@

    const { originalMaxAmountOut, wantedAmountsOut } = await calculateAmountOut(
    liquidationPairContract,
    context,
    );
    if (originalMaxAmountOut.eq(0)) {
    stats.push({
    pair,
    estimatedProfitUsd: 0,
    error: `amountOut is 0`,
    });
    logNextPair(liquidationPair, liquidationPairContracts);
    continue;
    }

    liquidationPairContract,
    context,
    );

    /**
    * Calculates necessary input parameters for the swap call based on current state of the contracts
    * @returns {Promise} Promise object with the input parameters exactAmountIn and amountOutMin
    */
    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, depends 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,
    };
    };
  5. chuckbergeron renamed this gist Sep 11, 2023. 1 changed file with 0 additions and 0 deletions.
  6. chuckbergeron renamed this gist Sep 11, 2023. 1 changed file with 0 additions and 0 deletions.
  7. chuckbergeron created this gist Sep 11, 2023.
    15 changes: 15 additions & 0 deletions pt-v5-arb-3-optimal-amounts.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@

    const { originalMaxAmountOut, wantedAmountsOut } = await calculateAmountOut(
    liquidationPairContract,
    context,
    );
    if (originalMaxAmountOut.eq(0)) {
    stats.push({
    pair,
    estimatedProfitUsd: 0,
    error: `amountOut is 0`,
    });
    logNextPair(liquidationPair, liquidationPairContracts);
    continue;
    }