-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOriginalVirtualLiquidityPoolTests.m
126 lines (114 loc) · 4.86 KB
/
OriginalVirtualLiquidityPoolTests.m
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
117
118
119
120
121
122
123
classdef OriginalVirtualLiquidityPoolTests < matlab.unittest.TestCase
methods (Test)
function testPoolInitialization(TestCase)
T_stable = Token("TokenA", false);
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
actValues = [pool.T_stable, pool.T_volatile, pool.BasePool, ...
pool.PoolRecoveryPeriod];
expValues = [T_stable, T_volatile, BasePool, PoolRecoveryPeriod];
TestCase.verifyEqual(actValues, expValues);
end
function testPoolSingleTokenSwap(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
K = BasePool^2;
expValue = 1;
pool.swap(T_stable, 1);
actValue = pool.Delta;
TestCase.verifyEqual(actValue, expValue);
end
function testPoolStableSwapReturnedValue(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 100000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
K = BasePool^2;
expValue = K / (BasePool * P_volatile) - K / ((BasePool + 100) * P_volatile );
[~, actValue] = pool.swap(T_stable, 100);
TestCase.verifyEqual(actValue, expValue);
end
function testPoolVolatileSwapReturnedValue(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 100000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
K = BasePool^2;
poolVolatile = K / (BasePool * P_volatile);
expValue = BasePool - K / ((poolVolatile + 10) * P_volatile );
[~, actValue] = pool.swap(T_volatile, 10);
TestCase.verifyEqual(actValue, expValue);
end
function testMultipleSwaps(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
quantity = 2;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
expValue = 2 * quantity;
pool.swap(T_stable, quantity);
pool.swap(T_stable, quantity);
actValue = pool.Delta;
TestCase.verifyEqual(actValue, expValue);
end
function testComputeSwapValue(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
actValue = pool.computeSwapValue(T_volatile, 1);
expValue = BasePool - BasePool^2 / ((BasePool/P_volatile + 1) * P_volatile);
TestCase.verifyEqual(actValue, expValue);
end
function testUpdateVolatileTokenPrice(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 36;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
pool.updateVolatileTokenPrice(3.0);
actValue = pool.P_volatile;
expValue = 3.0;
TestCase.verifyEqual(actValue, expValue);
end
function testPoolReplenishing(TestCase)
T_stable = Token("TokenA");
T_volatile = Token("TokenB");
BasePool = 10000;
P_volatile = 10;
PoolRecoveryPeriod = 3;
pool = OriginalVirtualLiquidityPool(T_stable, T_volatile, P_volatile, ...
BasePool, PoolRecoveryPeriod);
pool.swap(T_stable, 12);
pool.swap(T_stable, 0);
pool.swap(T_stable, 0);
pool.restoreDelta();
deltaExpected = 8;
delta = pool.Delta;
TestCase.verifyEqual(delta, deltaExpected);
end
end
end