-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathno_strat_test.go
More file actions
75 lines (66 loc) · 2.35 KB
/
Copy pathno_strat_test.go
File metadata and controls
75 lines (66 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"math/big"
"testing"
cons "uniswap-simulator/lib/constants"
ppool "uniswap-simulator/lib/pool"
ui "uniswap-simulator/uint256"
)
func Test(t *testing.T) {
transactions := getTransactions()
token0 := "USDC"
token1 := "WETH"
fee := 500
sqrtX96big, _ := new(big.Int).SetString("1350174849792634181862360983626536", 10)
sqrtX96, _ := ui.FromBig(sqrtX96big)
pool := ppool.NewPool(token0, token1, fee, sqrtX96)
for _, trans := range transactions {
var amount0, amount1 *ui.Int
switch trans.Type {
case "Mint":
amount0, amount1 = pool.MintStrategy(trans.TickLower, trans.TickUpper, trans.Amount)
if !trans.Amount1.Eq(amount1) || !trans.Amount0.Eq(amount0) {
fmt.Printf("%d %d %d %d\n", trans.Amount1, amount1, trans.Amount0, amount0)
t.Errorf("Not passing sanity check")
}
case "Burn":
amount0, amount1 = pool.BurnStrategy(trans.TickLower, trans.TickUpper, trans.Amount)
if !trans.Amount1.Eq(amount1) || !trans.Amount0.Eq(amount0) {
fmt.Printf("%d %d %d %d\n", trans.Amount1, amount1, trans.Amount0, amount0)
t.Errorf("Not passing sanity check")
}
case "Swap":
if trans.Amount0.Sign() > 0 {
if trans.UseX96 {
amount0, amount1 = pool.ExactInputSwap(trans.Amount0, pool.Token0, trans.SqrtPriceX96)
} else {
amount0, amount1 = pool.ExactInputSwap(trans.Amount0, pool.Token0, cons.Zero)
}
} else if trans.Amount1.Sign() > 0 {
if trans.UseX96 {
amount0, amount1 = pool.ExactInputSwap(trans.Amount1, pool.Token1, trans.SqrtPriceX96)
} else {
amount0, amount1 = pool.ExactInputSwap(trans.Amount1, pool.Token1, cons.Zero)
}
}
if !trans.Amount1.Eq(amount1) || !trans.Amount0.Eq(amount0) || !trans.SqrtPriceX96.Eq(pool.SqrtRatioX96) || trans.Tick != pool.TickCurrent {
fmt.Printf("%d %d %d %d\n", trans.Amount1, amount1, trans.Amount0, amount0)
fmt.Printf("%d %d %d %d\n", trans.SqrtPriceX96, pool.SqrtRatioX96, trans.Tick, pool.TickCurrent)
pool.TickData.Print()
t.Errorf("Not passing sanity check")
}
case "Flash":
pool.Flash(trans.Amount0, trans.Amount1)
}
}
if pool.SqrtRatioX96.ToBig().String() != "1204434112404346008547779933205831" {
t.Errorf("Liquidity incorrect")
}
if pool.Liquidity.ToBig().String() != "30215871190049079976" {
t.Errorf("Liquidity incorrect")
}
if pool.TickCurrent != 192593 {
t.Errorf("Tick incorrect")
}
}