1
1
const et = require ( './lib/eTestLib' ) ;
2
2
3
+ const PRICINGTYPE__UNISWAP3_TWAP = 2
4
+ const PRICINGTYPE__CHAINLINK = 4
5
+ const NON_ZERO_ADDRESS = '0x0000000000000000000000000000000000000001'
6
+
3
7
et . testSet ( {
4
8
desc : "activating markets" ,
5
9
} )
@@ -19,6 +23,11 @@ et.testSet({
19
23
{ call : 'markets.underlyingToEToken' , args : [ ctx . contracts . tokens . UTST . address ] , onResult : r => {
20
24
et . expect ( ctx . stash . eTokenAddr ) . to . equal ( r ) ;
21
25
} } ,
26
+
27
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
28
+ args : [ ctx . contracts . tokens . UTST . address , et . AddressZero ] ,
29
+ expectError : 'e/market/underlying-already-activated'
30
+ } ,
22
31
] ,
23
32
} )
24
33
@@ -37,7 +46,22 @@ et.testSet({
37
46
. test ( {
38
47
desc : "no uniswap pool" ,
39
48
actions : ctx => [
40
- { send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , expectError : 'e/no-uniswap-pool-avail' , } ,
49
+ // error for permissionless activation
50
+ { send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , expectError : 'e/markets/pricing-type-invalid' , } ,
51
+
52
+ // succeeds for permissioned activation with Chainlink
53
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
54
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
55
+ } ,
56
+
57
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
58
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
59
+ et . expect ( r . pricingParameters ) . to . equal ( 0 ) ;
60
+ } , } ,
61
+
62
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
63
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
64
+ } , } ,
41
65
] ,
42
66
} )
43
67
@@ -50,6 +74,11 @@ et.testSet({
50
74
await ( await ctx . contracts . uniswapPools [ 'TST4/WETH' ] . mockSetThrowNotInitiated ( true ) ) . wait ( ) ;
51
75
} ,
52
76
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , expectError : 'e/risk/uniswap-pool-not-inited' , } ,
77
+
78
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
79
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
80
+ expectError : 'e/risk/uniswap-pool-not-inited'
81
+ } ,
53
82
] ,
54
83
} )
55
84
@@ -78,14 +107,58 @@ et.testSet({
78
107
} )
79
108
80
109
110
+ . test ( {
111
+ desc : "activation with chainlink - non-governor" ,
112
+ actions : ctx => [
113
+ { from : ctx . wallet2 , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
114
+ args : [ ctx . contracts . tokens . TST4 . address , et . AddressZero ] ,
115
+ expectError : 'e/markets/unauthorized'
116
+ } ,
117
+ ] ,
118
+ } )
119
+
120
+
121
+ . test ( {
122
+ desc : "activation with chainlink - bad chainlink address" ,
123
+ actions : ctx => [
124
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
125
+ args : [ ctx . contracts . tokens . TST4 . address , et . AddressZero ] ,
126
+ expectError : 'e/markets/bad-chainlink-address'
127
+ } ,
128
+ ] ,
129
+ } )
130
+
131
+
81
132
. test ( {
82
133
desc : "select second fee uniswap pool" ,
83
134
actions : ctx => [
84
135
{ action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . LOW , } ,
85
136
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , } ,
86
137
{ call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
138
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__UNISWAP3_TWAP ) ;
139
+ et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . LOW ) ;
140
+ } , } ,
141
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
142
+ et . expect ( r ) . to . equal ( et . AddressZero ) ;
143
+ } , } ,
144
+ ] ,
145
+ } )
146
+
147
+
148
+ . test ( {
149
+ desc : "select second fee uniswap pool with chainlink" ,
150
+ actions : ctx => [
151
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . LOW , } ,
152
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
153
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
154
+ } ,
155
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
156
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
87
157
et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . LOW ) ;
88
158
} , } ,
159
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
160
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
161
+ } , } ,
89
162
] ,
90
163
} )
91
164
@@ -96,8 +169,30 @@ et.testSet({
96
169
{ action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . HIGH , } ,
97
170
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , } ,
98
171
{ call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
172
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__UNISWAP3_TWAP ) ;
173
+ et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . HIGH ) ;
174
+ } , } ,
175
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
176
+ et . expect ( r ) . to . equal ( et . AddressZero ) ;
177
+ } , } ,
178
+ ] ,
179
+ } )
180
+
181
+
182
+ . test ( {
183
+ desc : "select third fee uniswap pool with chainlink" ,
184
+ actions : ctx => [
185
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . HIGH , } ,
186
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
187
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
188
+ } ,
189
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
190
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
99
191
et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . HIGH ) ;
100
192
} , } ,
193
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
194
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
195
+ } , } ,
101
196
] ,
102
197
} )
103
198
@@ -117,8 +212,38 @@ et.testSet({
117
212
118
213
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , } ,
119
214
{ call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
215
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__UNISWAP3_TWAP ) ;
120
216
et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . LOW ) ;
121
217
} , } ,
218
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
219
+ et . expect ( r ) . to . equal ( et . AddressZero ) ;
220
+ } , } ,
221
+ ] ,
222
+ } )
223
+
224
+
225
+ . test ( {
226
+ desc : "choose pool with best liquidity with chainlink" ,
227
+ actions : ctx => [
228
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . MEDIUM , } ,
229
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 6000 ] , } ,
230
+
231
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . LOW , } ,
232
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 9000 ] , } ,
233
+
234
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . HIGH , } ,
235
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 7000 ] , } ,
236
+
237
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
238
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
239
+ } ,
240
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
241
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
242
+ et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . LOW ) ;
243
+ } , } ,
244
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
245
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
246
+ } , } ,
122
247
] ,
123
248
} )
124
249
@@ -134,8 +259,35 @@ et.testSet({
134
259
135
260
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , } ,
136
261
{ call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
262
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__UNISWAP3_TWAP ) ;
137
263
et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . HIGH ) ;
138
264
} , } ,
265
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
266
+ et . expect ( r ) . to . equal ( et . AddressZero ) ;
267
+ } , } ,
268
+ ] ,
269
+ } )
270
+
271
+
272
+ . test ( {
273
+ desc : "choose pool with best liquidity, 2, with chainlink" ,
274
+ actions : ctx => [
275
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . MEDIUM , } ,
276
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 6000 ] , } ,
277
+
278
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . HIGH , } ,
279
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 7000 ] , } ,
280
+
281
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
282
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
283
+ } ,
284
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
285
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
286
+ et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . HIGH ) ;
287
+ } , } ,
288
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
289
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
290
+ } , } ,
139
291
] ,
140
292
} )
141
293
@@ -151,8 +303,35 @@ et.testSet({
151
303
152
304
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , } ,
153
305
{ call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
306
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__UNISWAP3_TWAP ) ;
154
307
et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . MEDIUM ) ;
155
308
} , } ,
309
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
310
+ et . expect ( r ) . to . equal ( et . AddressZero ) ;
311
+ } , } ,
312
+ ] ,
313
+ } )
314
+
315
+
316
+ . test ( {
317
+ desc : "choose pool with best liquidity, 3, with chainlink" ,
318
+ actions : ctx => [
319
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . MEDIUM , } ,
320
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 7000 ] , } ,
321
+
322
+ { action : 'createUniswapPool' , pair : 'TST4/WETH' , fee : et . FeeAmount . HIGH , } ,
323
+ { send : 'uniswapPools.TST4/WETH.mockSetLiquidity' , args : [ 6000 ] , } ,
324
+
325
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
326
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
327
+ } ,
328
+ { call : 'markets.getPricingConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
329
+ et . expect ( r . pricingType ) . to . equal ( PRICINGTYPE__CHAINLINK ) ;
330
+ et . expect ( r . pricingParameters ) . to . equal ( et . FeeAmount . MEDIUM ) ;
331
+ } , } ,
332
+ { call : 'markets.getChainlinkPriceFeedConfig' , args : [ ctx . contracts . tokens . TST4 . address ] , onResult : r => {
333
+ et . expect ( r ) . to . equal ( NON_ZERO_ADDRESS ) ;
334
+ } , } ,
156
335
] ,
157
336
} )
158
337
@@ -172,6 +351,11 @@ et.testSet({
172
351
} , } ,
173
352
174
353
{ send : 'markets.activateMarket' , args : [ ctx . contracts . tokens . TST4 . address ] , expectError : 'e/bad-uniswap-pool-addr' } ,
354
+
355
+ { from : ctx . wallet , send : 'markets.activateMarketWithChainlinkPriceFeed' ,
356
+ args : [ ctx . contracts . tokens . TST4 . address , NON_ZERO_ADDRESS ] ,
357
+ expectError : 'e/bad-uniswap-pool-addr' ,
358
+ } ,
175
359
] ,
176
360
} )
177
361
0 commit comments