-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
8 changed files
with
315 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package position | ||
|
||
import ( | ||
p "gno.land/r/pool" | ||
) | ||
|
||
func DryMint( | ||
tickCurrent int32, | ||
tickLower int32, | ||
tickUpper int32, | ||
amount0Desired bigint, | ||
amount1Desired bigint, | ||
) (amount0, amount1 bigint) { | ||
sqrtRatioX96 := p.TickMathGetSqrtRatioAtTick(tickCurrent) | ||
sqrtLowerX96 := p.TickMathGetSqrtRatioAtTick(tickLower) | ||
sqrtUpperX96 := p.TickMathGetSqrtRatioAtTick(tickUpper) | ||
|
||
liquidity := liquidityAmountsGetLiquidityForAmounts( | ||
sqrtRatioX96, | ||
sqrtLowerX96, | ||
sqrtUpperX96, | ||
amount0Desired, | ||
amount1Desired, | ||
) | ||
|
||
if liquidity != 0 { | ||
if tickCurrent < tickLower { | ||
amount0 = sqrtPriceMathGetAmount0Delta( | ||
sqrtLowerX96, | ||
sqrtUpperX96, | ||
liquidity, | ||
) | ||
} else if tickCurrent < tickUpper { | ||
amount0 = sqrtPriceMathGetAmount0Delta( | ||
sqrtRatioX96, | ||
sqrtUpperX96, | ||
liquidity, | ||
) | ||
|
||
amount1 = sqrtPriceMathGetAmount1Delta( | ||
sqrtLowerX96, | ||
sqrtRatioX96, | ||
liquidity, | ||
) | ||
} else { | ||
amount1 = sqrtPriceMathGetAmount1Delta( | ||
sqrtLowerX96, | ||
sqrtUpperX96, | ||
liquidity, | ||
) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package position | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDryMintInRange(t *testing.T) { | ||
m0, m1 := DryMint( | ||
10000, // tickCurrent int32 | ||
7000, // tickLower int32 | ||
15000, // tickUpper int32 | ||
10000, // amount0Desired bigint | ||
16000, // amount1Desired bigint | ||
) | ||
|
||
shouldEQ(t, m0, bigint(9347)) | ||
shouldEQ(t, m1, bigint(15999)) | ||
} | ||
|
||
func TestDryMintLowerRange(t *testing.T) { | ||
m0, m1 := DryMint( | ||
7000, // tickCurrent int32 | ||
5000, // tickLower int32 | ||
6000, // tickUpper int32 | ||
10000, // amount0Desired bigint | ||
16000, // amount1Desired bigint | ||
) | ||
|
||
shouldEQ(t, m0, bigint(0)) | ||
shouldEQ(t, m1, bigint(15999)) | ||
} | ||
|
||
func TestDryMintUpperRange(t *testing.T) { | ||
m0, m1 := DryMint( | ||
7000, // tickCurrent int32 | ||
9000, // tickLower int32 | ||
11000, // tickUpper int32 | ||
10000, // amount0Desired bigint | ||
16000, // amount1Desired bigint | ||
) | ||
|
||
shouldEQ(t, m0, bigint(9999)) | ||
shouldEQ(t, m1, bigint(0)) | ||
} |
Oops, something went wrong.