-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patharmPrices.test.js
More file actions
116 lines (103 loc) · 2.69 KB
/
Copy patharmPrices.test.js
File metadata and controls
116 lines (103 loc) · 2.69 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const assert = require("assert");
const {
capDexAmountBySwapLiquidity,
haveSwapCapsChanged,
resolveDexQuoteAmount,
} = require("../../src/js/utils/priceUpdate");
const multiBaseContext = (buyLiquidityRemaining, sellLiquidityRemaining) => ({
version: "multiBase",
config: {
buyLiquidityRemaining,
sellLiquidityRemaining,
},
});
assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(10n, 20n), 10n, 20n),
false,
"unchanged buy and sell amounts should not trigger an update",
);
assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(9n, 20n), 10n, 20n),
true,
"a changed buy amount should trigger an update",
);
assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(10n, 19n), 10n, 20n),
true,
"a changed sell amount should trigger an update",
);
assert.strictEqual(
haveSwapCapsChanged({ version: "legacy" }, 10n, 20n),
false,
"legacy ARMs do not support buy and sell amounts",
);
assert.strictEqual(
capDexAmountBySwapLiquidity({
amount: 100,
buyLiquidity: 50000000n,
sellLiquidity: (1n << 128n) - 1n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"50.0",
"buy quote amount should not exceed buy liquidity",
);
assert.strictEqual(
capDexAmountBySwapLiquidity({
amount: 100,
buyLiquidity: (1n << 128n) - 1n,
sellLiquidity: 25000000000000000000n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"25.0",
"sell quote amount should not exceed sell liquidity",
);
assert.strictEqual(
capDexAmountBySwapLiquidity({
amount: 20,
buyLiquidity: 30000000n,
sellLiquidity: 10000000000000000000n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"10.0",
"quote amount should use the lower of buy and sell liquidity",
);
assert.strictEqual(
capDexAmountBySwapLiquidity({
amount: 20,
buyLiquidity: 30000000n,
sellLiquidity: 40000000000000000000n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"20",
"quote amount within both liquidity limits should be unchanged",
);
assert.strictEqual(
resolveDexQuoteAmount({
amount: 100,
liquidityAssets: 50000000n,
baseAssetReserve: 25000000000000000000n,
buyLiquidity: 30000000n,
sellLiquidity: 10000000000000000000n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"100",
"an explicit quote amount should override reserves and price liquidity",
);
assert.strictEqual(
resolveDexQuoteAmount({
liquidityAssets: 50000000n,
baseAssetReserve: 40000000000000000000n,
buyLiquidity: 30000000n,
sellLiquidity: 20000000000000000000n,
liquidityDecimals: 6,
baseDecimals: 18,
}),
"20.0",
"an automatic quote amount should use the smallest reserve or price liquidity limit",
);
console.log("ARM price tests passed");