Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overnight formula #736

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/liquidity-source/overnight-usdp/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -142,13 +142,13 @@ 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,
big.NewInt(s.usdPlusDecimals-s.assetDecimals),
nil,
)

return amountOut.Mul(amountIn, divisor)
return amountOut.Div(amountIn, divisor)
}
38 changes: 34 additions & 4 deletions pkg/liquidity-source/overnight-usdp/pool_simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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+",
Expand Down