Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codewithgun/20b3165c9e051bb5b5ef0e8a62dd49bb to your computer and use it in GitHub Desktop.
Save codewithgun/20b3165c9e051bb5b5ef0e8a62dd49bb to your computer and use it in GitHub Desktop.

Revisions

  1. codewithgun created this gist Jun 7, 2023.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    function test_getFeeAmount() public {
    // Configuration was copied from BTC.b/USDC pair
    bytes32 params;
    uint16 binStep = 10;

    params = params.setStaticFeeParameters(10000, 30, 600, 5000, 40000, 1000, 350000);
    // Set volatility accumulator to the max
    params = params.setVolatilityAccumulator(350000);

    // 5900000000000000 => 0.59%
    console2.log("Total fee %s", totalFee);

    uint128 totalFee = params.getTotalFee(binStep);
    uint128 inAmount = 1234567;

    uint128 feeAmount = inAmount.getFeeAmount(totalFee);

    // feeAmount = 7328. However, Math.ceil(1234567 * 0.0059) = 7284. Extra 44 wei has been charged
    console.log("Fee amount %s", feeAmount);
    }