Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit eaab561

Browse files
tests for permissioned market activation
1 parent 749ab27 commit eaab561

File tree

2 files changed

+187
-1
lines changed

2 files changed

+187
-1
lines changed

test/activateMarket.js

Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const et = require('./lib/eTestLib');
22

3+
const PRICINGTYPE__UNISWAP3_TWAP = 2
4+
const PRICINGTYPE__CHAINLINK = 4
5+
const NON_ZERO_ADDRESS = '0x0000000000000000000000000000000000000001'
6+
37
et.testSet({
48
desc: "activating markets",
59
})
@@ -19,6 +23,11 @@ et.testSet({
1923
{ call: 'markets.underlyingToEToken', args: [ctx.contracts.tokens.UTST.address], onResult: r => {
2024
et.expect(ctx.stash.eTokenAddr).to.equal(r);
2125
}},
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+
},
2231
],
2332
})
2433

@@ -37,7 +46,22 @@ et.testSet({
3746
.test({
3847
desc: "no uniswap pool",
3948
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+
}, },
4165
],
4266
})
4367

@@ -50,6 +74,11 @@ et.testSet({
5074
await (await ctx.contracts.uniswapPools['TST4/WETH'].mockSetThrowNotInitiated(true)).wait();
5175
},
5276
{ 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+
},
5382
],
5483
})
5584

@@ -78,14 +107,58 @@ et.testSet({
78107
})
79108

80109

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+
81132
.test({
82133
desc: "select second fee uniswap pool",
83134
actions: ctx => [
84135
{ action: 'createUniswapPool', pair: 'TST4/WETH', fee: et.FeeAmount.LOW, },
85136
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST4.address], },
86137
{ 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);
87157
et.expect(r.pricingParameters).to.equal(et.FeeAmount.LOW);
88158
}, },
159+
{ call: 'markets.getChainlinkPriceFeedConfig', args: [ctx.contracts.tokens.TST4.address], onResult: r => {
160+
et.expect(r).to.equal(NON_ZERO_ADDRESS);
161+
}, },
89162
],
90163
})
91164

@@ -96,8 +169,30 @@ et.testSet({
96169
{ action: 'createUniswapPool', pair: 'TST4/WETH', fee: et.FeeAmount.HIGH, },
97170
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST4.address], },
98171
{ 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);
99191
et.expect(r.pricingParameters).to.equal(et.FeeAmount.HIGH);
100192
}, },
193+
{ call: 'markets.getChainlinkPriceFeedConfig', args: [ctx.contracts.tokens.TST4.address], onResult: r => {
194+
et.expect(r).to.equal(NON_ZERO_ADDRESS);
195+
}, },
101196
],
102197
})
103198

@@ -117,8 +212,38 @@ et.testSet({
117212

118213
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST4.address], },
119214
{ call: 'markets.getPricingConfig', args: [ctx.contracts.tokens.TST4.address], onResult: r => {
215+
et.expect(r.pricingType).to.equal(PRICINGTYPE__UNISWAP3_TWAP);
120216
et.expect(r.pricingParameters).to.equal(et.FeeAmount.LOW);
121217
}, },
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+
}, },
122247
],
123248
})
124249

@@ -134,8 +259,35 @@ et.testSet({
134259

135260
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST4.address], },
136261
{ call: 'markets.getPricingConfig', args: [ctx.contracts.tokens.TST4.address], onResult: r => {
262+
et.expect(r.pricingType).to.equal(PRICINGTYPE__UNISWAP3_TWAP);
137263
et.expect(r.pricingParameters).to.equal(et.FeeAmount.HIGH);
138264
}, },
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+
}, },
139291
],
140292
})
141293

@@ -151,8 +303,35 @@ et.testSet({
151303

152304
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST4.address], },
153305
{ call: 'markets.getPricingConfig', args: [ctx.contracts.tokens.TST4.address], onResult: r => {
306+
et.expect(r.pricingType).to.equal(PRICINGTYPE__UNISWAP3_TWAP);
154307
et.expect(r.pricingParameters).to.equal(et.FeeAmount.MEDIUM);
155308
}, },
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+
}, },
156335
],
157336
})
158337

@@ -172,6 +351,11 @@ et.testSet({
172351
}, },
173352

174353
{ 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+
},
175359
],
176360
})
177361

test/pToken.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ et.testSet({
136136
{ send: 'pTokens.pTST.wrap', args: [et.eth(11)], },
137137
{ send: 'markets.activateMarket', args: [ctx.contracts.pTokens.pTST.address], expectError: 'e/markets/invalid-token', },
138138
{ send: 'markets.activatePToken', args: [ctx.contracts.pTokens.pTST.address], expectError: 'e/nested-ptoken', },
139+
140+
{ send: 'markets.activateMarketWithChainlinkPriceFeed', args: [ctx.contracts.pTokens.pTST.address, et.AddressZero], expectError: 'e/markets/invalid-token', },
139141
],
140142
})
141143

0 commit comments

Comments
 (0)