From b76d1ce5e1dd4f05263fdbcc88c94f2192b0d59c Mon Sep 17 00:00:00 2001 From: sunspirit99 Date: Thu, 20 Feb 2025 19:39:35 +0700 Subject: [PATCH] tmp --- .../overnight-usdp/pool_simulator.go | 8 ++-- .../overnight-usdp/pool_simulator_test.go | 38 +++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/pkg/liquidity-source/overnight-usdp/pool_simulator.go b/pkg/liquidity-source/overnight-usdp/pool_simulator.go index 3db5e517b..59ced0f8e 100644 --- a/pkg/liquidity-source/overnight-usdp/pool_simulator.go +++ b/pkg/liquidity-source/overnight-usdp/pool_simulator.go @@ -119,7 +119,7 @@ func (s *PoolSimulator) mint(amountIn *big.Int) *big.Int { nil, ) - return new(big.Int).Mul(amountIn, divisor) + return new(big.Int).Div(amountIn, divisor) } divisor = divisor.Exp( @@ -128,7 +128,7 @@ func (s *PoolSimulator) mint(amountIn *big.Int) *big.Int { nil, ) - return new(big.Int).Div(amountIn, divisor) + return new(big.Int).Mul(amountIn, divisor) } func (s *PoolSimulator) redeem(amountIn *big.Int) *big.Int { @@ -142,7 +142,7 @@ func (s *PoolSimulator) redeem(amountIn *big.Int) *big.Int { nil, ) - return amountOut.Div(amountIn, divisor) + return amountOut.Mul(amountIn, divisor) } divisor = divisor.Exp( bignumber.Ten, @@ -150,5 +150,5 @@ func (s *PoolSimulator) redeem(amountIn *big.Int) *big.Int { nil, ) - return amountOut.Mul(amountIn, divisor) + return amountOut.Div(amountIn, divisor) } diff --git a/pkg/liquidity-source/overnight-usdp/pool_simulator_test.go b/pkg/liquidity-source/overnight-usdp/pool_simulator_test.go index 0a37bac48..6e75d55a4 100644 --- a/pkg/liquidity-source/overnight-usdp/pool_simulator_test.go +++ b/pkg/liquidity-source/overnight-usdp/pool_simulator_test.go @@ -18,7 +18,37 @@ func TestPoolSimulator_CalcAmountOut(t *testing.T) { expectedError error }{ { - name: "Mint USD+ from USDC", + name: "BSC : Mint USD+ from USDC", + poolSimulator: &PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Tokens: []string{ + "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", + "0xe80772eaf6e2e18b651f160bc9158b2a5cafca65", + }, + Reserves: []*big.Int{ + bignumber.NewBig(defaultReserves), + bignumber.NewBig(defaultReserves), + }, + }, + }, + isPaused: false, + buyFee: bignumber.Ten, + redeemFee: bignumber.Ten, + usdPlusDecimals: 6, + assetDecimals: 18, + }, + param: poolpkg.CalcAmountOutParams{ + TokenAmountIn: poolpkg.TokenAmount{ + Amount: bignumber.NewBig("1000000000000000000"), + Token: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", + }, + TokenOut: "0xe80772eaf6e2e18b651f160bc9158b2a5cafca65", + }, + expectedAmountOut: bignumber.NewBig("999900"), + }, + { + name: "Base : Mint USD+ from USDC", poolSimulator: &PoolSimulator{ Pool: poolpkg.Pool{ Info: poolpkg.PoolInfo{ @@ -36,16 +66,16 @@ func TestPoolSimulator_CalcAmountOut(t *testing.T) { buyFee: bignumber.Ten, redeemFee: bignumber.Ten, usdPlusDecimals: 6, - assetDecimals: 18, + assetDecimals: 6, }, param: poolpkg.CalcAmountOutParams{ TokenAmountIn: poolpkg.TokenAmount{ - Amount: bignumber.NewBig("1000000000"), + Amount: bignumber.NewBig("1000000"), Token: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", }, TokenOut: "0xB79DD08EA68A908A97220C76d19A6aA9cBDE4376", }, - expectedAmountOut: bignumber.NewBig("999900000000000000000"), + expectedAmountOut: bignumber.NewBig("999900"), }, { name: "Redeem USDC from USD+",