-
Notifications
You must be signed in to change notification settings - Fork 8
/
LexLocker.test.js
821 lines (614 loc) · 33.9 KB
/
LexLocker.test.js
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
const { artifacts, ethers } = require("hardhat");
const { BigNumber, utils: { keccak256, defaultAbiCoder, toUtf8Bytes, solidityPack }, } = require("ethers")
const { expect } = require("chai");
const chai = require("chai");
const { solidity } = require("ethereum-waffle");
const { ecsign } = require("ethereumjs-util");
const bentoAddress = "0xF5BCE5077908a1b7370B9ae04AdC565EBd643966";
const wethAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const carolPrivateKey = "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a";
const PERMIT_TYPEHASH = keccak256(toUtf8Bytes("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"));
chai
.use(solidity)
.should();
const BASE_TEN = 10;
// Defaults to e18 using amount * 10^18
function getBigNumber(amount, decimals = 18) {
return BigNumber.from(amount).mul(BigNumber.from(BASE_TEN).pow(decimals))
}
function getDomainSeparator(tokenAddress, chainId) {
return keccak256(
defaultAbiCoder.encode(
["bytes32", "uint256", "address"],
[keccak256(toUtf8Bytes("EIP712Domain(uint256 chainId,address verifyingContract)")), chainId, tokenAddress]
)
)
}
function getApprovalDigest(token, approve, nonce, deadline, chainId = 1) {
const DOMAIN_SEPARATOR = getDomainSeparator(token.address, chainId)
const msg = defaultAbiCoder.encode(
["bytes32", "address", "address", "uint256", "uint256", "uint256"],
[PERMIT_TYPEHASH, approve.owner, approve.spender, approve.value, nonce, deadline]
)
const pack = solidityPack(["bytes1", "bytes1", "bytes32", "bytes32"], ["0x19", "0x01", DOMAIN_SEPARATOR, keccak256(msg)])
return keccak256(pack)
}
async function advanceBlock() {
return ethers.provider.send("evm_mine", [])
}
async function advanceBlockTo(blockNumber) {
for (let i = await ethers.provider.getBlockNumber(); i < blockNumber; i++) {
await advanceBlock()
}
}
async function increase(value) {
await ethers.provider.send("evm_increaseTime", [value.toNumber()])
await advanceBlock()
}
async function latest() {
const block = await ethers.provider.getBlock("latest")
return BigNumber.from(block.timestamp)
}
async function advanceTimeAndBlock(time) {
await advanceTime(time)
await advanceBlock()
}
async function advanceTime(time) {
await ethers.provider.send("evm_increaseTime", [time])
}
const duration = {
seconds: function (val) {
return BigNumber.from(val)
},
minutes: function (val) {
return BigNumber.from(val).mul(this.seconds("60"))
},
hours: function (val) {
return BigNumber.from(val).mul(this.minutes("60"))
},
days: function (val) {
return BigNumber.from(val).mul(this.hours("24"))
},
weeks: function (val) {
return BigNumber.from(val).mul(this.days("7"))
},
years: function (val) {
return BigNumber.from(val).mul(this.days("365"))
},
}
describe("LexLocker", function () {
it("Should take an ERC20 token deposit and allow release by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(2000)], 0, false, "TEST");
await locker.release(1);
await locker.release(1);
});
it("Should take an ETH deposit and allow release by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
// we use a token address as well to ensure nothing weird happens if user screws up
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(5000)], 0, false, "TEST", { value: getBigNumber(6000) });
await locker.release(1);
await locker.release(1);
});
it("Should enforce ETH deposit and locker value parity", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(10000)], 0, false, "TEST", { value: getBigNumber(1000) }).should.be.revertedWith("WRONG_MSG_VALUE");
});
it("Should take an ERC20 token deposit, wrap into BentoBox, and allow release by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const bento = await ethers.getContractAt("IBentoBoxMinimal", bentoAddress);
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.depositBento(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(3000)], 0, true, "TEST");
await locker.release(1);
await locker.release(1);
});
it("Should take an ETH deposit, wrap into BentoBox, and allow release by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const bento = await ethers.getContractAt("IBentoBoxMinimal", bentoAddress);
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.depositBento(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, true, "TEST", { value: getBigNumber(2000) });
await locker.release(1);
await locker.release(1);
});
it("Should enforce ETH deposit and locker value parity for BentoBox", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await locker.connect(resolver).registerResolver(true, 20);
await locker.depositBento(receiver.address, resolver.address, token.address, [getBigNumber(10000)], 0, true, "TEST", { value: getBigNumber(1000) }).should.be.revertedWith("WRONG_MSG_VALUE");
});
it("Should take an ERC721 NFT deposit and allow release by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const NFT = await ethers.getContractFactory("TestERC721");
const nft = await NFT.deploy("poc", "poc");
await nft.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await nft.approve(locker.address, 1);
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, nft.address, [1], 0, true, "TEST");
await locker.release(1);
});
it("Should forbid deposit if resolver not registered", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST").should.be.revertedWith("RESOLVER_NOT_ACTIVE");
});
it("Should forbid BentoBox deposit if resolver not registered", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const bento = await ethers.getContractAt("IBentoBoxMinimal", bentoAddress);
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.depositBento(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, true, "TEST").should.be.revertedWith("RESOLVER_NOT_ACTIVE");
});
it("Should forbid deposit if resolver is party to locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(depositor).registerResolver(true, 20);
await locker.connect(receiver).registerResolver(true, 20);
await locker.deposit(receiver.address, depositor.address, token.address, [getBigNumber(1000)], 0, false, "TEST").should.be.revertedWith("RESOLVER_CANNOT_BE_PARTY");
await locker.deposit(receiver.address, receiver.address, token.address, [getBigNumber(1000)], 0, false, "TEST").should.be.revertedWith("RESOLVER_CANNOT_BE_PARTY");
});
it("Should forbid BentoBox deposit if resolver is party to locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(depositor).registerResolver(true, 20);
await locker.connect(receiver).registerResolver(true, 20);
await locker.depositBento(receiver.address, depositor.address, token.address, [getBigNumber(1000)], 0, true, "TEST").should.be.revertedWith("RESOLVER_CANNOT_BE_PARTY");
await locker.depositBento(receiver.address, receiver.address, token.address, [getBigNumber(1000)], 0, true, "TEST").should.be.revertedWith("RESOLVER_CANNOT_BE_PARTY");
});
it("Should forbid release by non-depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST");
await locker.connect(receiver).release(1).should.be.revertedWith("NOT_DEPOSITOR");
await locker.connect(resolver).release(1).should.be.revertedWith("NOT_DEPOSITOR");
});
it("Should forbid release of nonexistent locker", async function () {
let lexDAO;
[lexDAO] = await ethers.getSigners();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await locker.release(1).should.be.reverted;
});
it("Should forbid repeat release", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(2000)], 0, false, "TEST");
await locker.release(1);
await locker.release(1);
await locker.release(1).should.be.reverted;
});
it("Should forbid release of locked locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST");
await locker.lock(1, "TEST");
await locker.connect(receiver).lock(1, "TEST");
await locker.release(1).should.be.revertedWith("LOCKED");
});
it("Should allow withdrawal by depositor after termination time", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.withdraw(1);
});
it("Should forbid withdrawal by non-depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST");
await locker.connect(receiver).withdraw(1).should.be.revertedWith("NOT_DEPOSITOR");
});
it("Should forbid withdrawal after lock", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.lock(1, "TEST");
await locker.withdraw(1).should.be.revertedWith("LOCKED");
});
it("Should forbid withdrawal by depositor before termination time", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
// term is set to August 29, 2023 5:30:30 AM GMT-04:00 DST
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 1693301430, false, "TEST");
await locker.withdraw(1).should.be.revertedWith("NOT_TERMINATED");
});
it("Should forbid withdrawal of nonexistent locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
// term is set to August 29, 2023 5:30:30 AM GMT-04:00 DST
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.withdraw(2).should.be.reverted;
});
it("Should allow lock by depositor", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.lock(1, "TEST");
});
it("Should allow lock by receiver", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.connect(receiver).lock(1, "TEST");
});
it("Should forbid lock by non-party", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.connect(resolver).lock(1, "TEST").should.be.revertedWith("NOT_PARTY");
});
it("Should forbid lock of nonexistent locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.lock(2).should.be.reverted;
await locker.connect(receiver).lock(2, "TEST").should.be.reverted;
await locker.connect(resolver).lock(2, "TEST").should.be.reverted;
});
it("Should allow resolution by resolver over ERC20", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.release(1);
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(1000).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST");
});
it("Should allow resolution by resolver over ETH", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(500), getBigNumber(500)], 0, false, "TEST", { value: getBigNumber(1000) });
await locker.release(1);
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(500).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST");
});
it("Should allow resolution by resolver over BentoBox shares", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const bento = await ethers.getContractAt("IBentoBoxMinimal", bentoAddress);
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.depositBento(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, true, "TEST");
await locker.release(1);
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(1000).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST");
});
it("Should allow resolution by resolver over NFT", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const NFT = await ethers.getContractFactory("TestERC721");
const nft = await NFT.deploy("poc", "poc");
await nft.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
await nft.approve(locker.address, 1);
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, nft.address, [1], 0, true, "TEST");
await locker.lock(1, "TEST");
await locker.connect(resolver).resolve(1, 1, 0, "TEST");
});
it("Should forbid resolution by non-resolver", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.release(1);
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(1000).div(2);
await locker.connect(depositor).resolve(1, resolutionAmount, resolutionAmount, "TEST").should.be.revertedWith("NOT_RESOLVER");
await locker.connect(receiver).resolve(1, resolutionAmount, resolutionAmount, "TEST").should.be.revertedWith("NOT_RESOLVER");
});
it("Should forbid resolution of unlocked locker", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST");
const resolutionAmount = getBigNumber(1000).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST").should.be.revertedWith("NOT_LOCKED");
});
it("Should forbid resolution that is not balanced with locked remainder", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000), getBigNumber(1000)], 0, false, "TEST");
await locker.release(1);
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(2000).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST").should.be.revertedWith("NOT_REMAINDER");
});
it("Should forbid repeat resolution", async function () {
let depositor, receiver, resolver, lexDAO;
[depositor, receiver, resolver, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
token.approve(locker.address, getBigNumber(10000));
await locker.connect(resolver).registerResolver(true, 20);
await locker.deposit(receiver.address, resolver.address, token.address, [getBigNumber(1000)], 0, false, "TEST");
await locker.lock(1, "TEST");
const resolutionAmount = getBigNumber(1000).div(2);
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST");
await locker.connect(resolver).resolve(1, resolutionAmount, resolutionAmount, "TEST").should.be.reverted;
});
it("Should allow LexDAO to store agreements", async function () {
let lexDAO;
[lexDAO] = await ethers.getSigners();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
locker.registerAgreement(1, "TEST");
});
it("Should forbid non-LexDAO accounts from storing agreements", async function () {
let lexDAO, nonLexDAO;
[lexDAO, nonLexDAO] = await ethers.getSigners();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
locker.connect(nonLexDAO).registerAgreement(1, "TEST").should.be.revertedWith("NOT_LEXDAO");
});
it("Should allow LexDAO to transfer role", async function () {
let lexDAO, newLexDAO;
[lexDAO, newLexDAO] = await ethers.getSigners();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
locker.updateLexDAO(newLexDAO.address);
});
it("Should forbid non-LexDAO accounts from transferring role", async function () {
let lexDAO, newLexDAO, nonLexDAO;
[lexDAO, newLexDAO, nonLexDAO] = await ethers.getSigners();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
locker.connect(nonLexDAO).updateLexDAO(newLexDAO.address).should.be.revertedWith("NOT_LEXDAO");
});
it.skip("Should execute ERC20 token permit", async function () {
let depositor, lexDAO;
[depositor, lexDAO] = await ethers.getSigners();
const Token = await ethers.getContractFactory("TestERC20");
const token = await Token.deploy("poc", "poc");
await token.deployed();
const Locker = await ethers.getContractFactory("LexLocker");
const locker = await Locker.deploy(bentoAddress, lexDAO.address, wethAddress);
await locker.deployed();
const nonce = await token.nonces(depositor.address);
// deadline is set to August 29, 2023 5:30:30 AM GMT-04:00 DST
const deadline = 1693301430;
const digest = getApprovalDigest(
token,
{
owner: depositor.address,
spender: locker.address,
value: 1,
},
nonce,
deadline,
locker.provider._network.chainId
)
const { v, r, s } = ecsign(Buffer.from(digest.slice(2), "hex"), Buffer.from(carolPrivateKey.replace("0x", ""), "hex"))
await token.connect(depositor).permit(depositor.address, locker.address, 1, deadline, v, r, s, {
from: depositor.address,
})
})
});