@@ -23,7 +23,9 @@ let accounts: Signer[],
23
23
userC : Signer ,
24
24
userCAddress : string ,
25
25
ampl : Contract ,
26
- wAMPL : Contract
26
+ wAMPL : Contract ,
27
+ balanceBefore : BigNumber ,
28
+ balanceAfter : BigNumber
27
29
28
30
async function setupContracts ( ) {
29
31
accounts = await ethers . getSigners ( )
@@ -108,8 +110,10 @@ describe('WAMPL:deposit', () => {
108
110
await wAMPL . connect ( deployer ) . callStatic . deposit ( amplesDeposited ) ,
109
111
) . to . eq ( wamplesMinted )
110
112
113
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
111
114
r = wAMPL . connect ( deployer ) . deposit ( amplesDeposited )
112
115
await r
116
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
113
117
} )
114
118
115
119
it ( 'should mint wamples' , async function ( ) {
@@ -127,6 +131,7 @@ describe('WAMPL:deposit', () => {
127
131
await expect ( r )
128
132
. to . emit ( ampl , 'Transfer' )
129
133
. withArgs ( deployerAddress , wAMPL . address , amplesDeposited )
134
+ expect ( balanceBefore . sub ( balanceAfter ) ) . to . eq ( amplesDeposited )
130
135
} )
131
136
132
137
it ( 'should log mint' , async function ( ) {
@@ -157,8 +162,10 @@ describe('WAMPL:depositFor', () => {
157
162
. callStatic . depositFor ( userBAddress , amplesDeposited ) ,
158
163
) . to . eq ( wamplesMinted )
159
164
165
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
160
166
r = wAMPL . connect ( deployer ) . depositFor ( userBAddress , amplesDeposited )
161
167
await r
168
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
162
169
} )
163
170
164
171
it ( 'should mint wamples' , async function ( ) {
@@ -176,6 +183,7 @@ describe('WAMPL:depositFor', () => {
176
183
await expect ( r )
177
184
. to . emit ( ampl , 'Transfer' )
178
185
. withArgs ( deployerAddress , wAMPL . address , amplesDeposited )
186
+ expect ( balanceBefore . sub ( balanceAfter ) ) . to . eq ( amplesDeposited )
179
187
} )
180
188
181
189
it ( 'should log mint' , async function ( ) {
@@ -220,8 +228,10 @@ describe('WAMPL:withdraw', () => {
220
228
await wAMPL . connect ( deployer ) . callStatic . withdraw ( amplesWithdrawn ) ,
221
229
) . to . eq ( wamplesBurnt )
222
230
231
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
223
232
r = wAMPL . connect ( deployer ) . withdraw ( amplesWithdrawn )
224
233
await r
234
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
225
235
} )
226
236
227
237
it ( 'should burn wamples' , async function ( ) {
@@ -239,6 +249,7 @@ describe('WAMPL:withdraw', () => {
239
249
await expect ( r )
240
250
. to . emit ( ampl , 'Transfer' )
241
251
. withArgs ( wAMPL . address , deployerAddress , amplesWithdrawn )
252
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesWithdrawn )
242
253
} )
243
254
244
255
it ( 'should log burn' , async function ( ) {
@@ -285,8 +296,10 @@ describe('WAMPL:withdrawTo', () => {
285
296
. callStatic . withdrawTo ( userBAddress , amplesWithdrawn ) ,
286
297
) . to . eq ( wamplesBurnt )
287
298
299
+ balanceBefore = await ampl . balanceOf ( userBAddress )
288
300
r = wAMPL . connect ( deployer ) . withdrawTo ( userBAddress , amplesWithdrawn )
289
301
await r
302
+ balanceAfter = await ampl . balanceOf ( userBAddress )
290
303
} )
291
304
292
305
it ( 'should burn wamples' , async function ( ) {
@@ -306,6 +319,7 @@ describe('WAMPL:withdrawTo', () => {
306
319
await expect ( r )
307
320
. to . emit ( ampl , 'Transfer' )
308
321
. withArgs ( wAMPL . address , userBAddress , amplesWithdrawn )
322
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesWithdrawn )
309
323
} )
310
324
311
325
it ( 'should log burn' , async function ( ) {
@@ -336,8 +350,10 @@ describe('WAMPL:withdrawAll', () => {
336
350
wamplesMinted ,
337
351
)
338
352
353
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
339
354
r = wAMPL . connect ( deployer ) . withdrawAll ( )
340
355
await r
356
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
341
357
} )
342
358
343
359
it ( 'should burn wamples' , async function ( ) {
@@ -353,6 +369,7 @@ describe('WAMPL:withdrawAll', () => {
353
369
await expect ( r )
354
370
. to . emit ( ampl , 'Transfer' )
355
371
. withArgs ( wAMPL . address , deployerAddress , amplesDeposited )
372
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesDeposited )
356
373
} )
357
374
358
375
it ( 'should log burn' , async function ( ) {
@@ -383,8 +400,10 @@ describe('WAMPL:withdrawAllTo', () => {
383
400
await wAMPL . connect ( deployer ) . callStatic . withdrawAllTo ( userBAddress ) ,
384
401
) . to . eq ( wamplesMinted )
385
402
403
+ balanceBefore = await ampl . balanceOf ( userBAddress )
386
404
r = wAMPL . connect ( deployer ) . withdrawAllTo ( userBAddress )
387
405
await r
406
+ balanceAfter = await ampl . balanceOf ( userBAddress )
388
407
} )
389
408
390
409
it ( 'should burn wamples' , async function ( ) {
@@ -402,6 +421,7 @@ describe('WAMPL:withdrawAllTo', () => {
402
421
await expect ( r )
403
422
. to . emit ( ampl , 'Transfer' )
404
423
. withArgs ( wAMPL . address , userBAddress , amplesDeposited )
424
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesDeposited )
405
425
} )
406
426
407
427
it ( 'should log burn' , async function ( ) {
@@ -430,8 +450,10 @@ describe('WAMPL:mint', () => {
430
450
amplesDeposited ,
431
451
)
432
452
453
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
433
454
r = wAMPL . connect ( deployer ) . mint ( wamplesMinted )
434
455
await r
456
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
435
457
} )
436
458
437
459
it ( 'should mint wamples' , async function ( ) {
@@ -449,6 +471,7 @@ describe('WAMPL:mint', () => {
449
471
await expect ( r )
450
472
. to . emit ( ampl , 'Transfer' )
451
473
. withArgs ( deployerAddress , wAMPL . address , amplesDeposited )
474
+ expect ( balanceBefore . sub ( balanceAfter ) ) . to . eq ( amplesDeposited )
452
475
} )
453
476
454
477
it ( 'should log mint' , async function ( ) {
@@ -479,8 +502,10 @@ describe('WAMPL:mintFor', () => {
479
502
. callStatic . mintFor ( userBAddress , wamplesMinted ) ,
480
503
) . to . eq ( amplesDeposited )
481
504
505
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
482
506
r = wAMPL . connect ( deployer ) . mintFor ( userBAddress , wamplesMinted )
483
507
await r
508
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
484
509
} )
485
510
486
511
it ( 'should mint wamples' , async function ( ) {
@@ -498,6 +523,7 @@ describe('WAMPL:mintFor', () => {
498
523
await expect ( r )
499
524
. to . emit ( ampl , 'Transfer' )
500
525
. withArgs ( deployerAddress , wAMPL . address , amplesDeposited )
526
+ expect ( balanceBefore . sub ( balanceAfter ) ) . to . eq ( amplesDeposited )
501
527
} )
502
528
503
529
it ( 'should log mint' , async function ( ) {
@@ -542,8 +568,10 @@ describe('WAMPL:burn', () => {
542
568
amplesWithdrawn ,
543
569
)
544
570
571
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
545
572
r = wAMPL . connect ( deployer ) . burn ( wamplesBurnt )
546
573
await r
574
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
547
575
} )
548
576
549
577
it ( 'should burn wamples' , async function ( ) {
@@ -561,6 +589,7 @@ describe('WAMPL:burn', () => {
561
589
await expect ( r )
562
590
. to . emit ( ampl , 'Transfer' )
563
591
. withArgs ( wAMPL . address , deployerAddress , amplesWithdrawn )
592
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesWithdrawn )
564
593
} )
565
594
566
595
it ( 'should log burn' , async function ( ) {
@@ -607,8 +636,10 @@ describe('WAMPL:burnTo', () => {
607
636
. callStatic . burnTo ( userBAddress , wamplesBurnt ) ,
608
637
) . to . eq ( amplesWithdrawn )
609
638
639
+ balanceBefore = await ampl . balanceOf ( userBAddress )
610
640
r = wAMPL . connect ( deployer ) . burnTo ( userBAddress , wamplesBurnt )
611
641
await r
642
+ balanceAfter = await ampl . balanceOf ( userBAddress )
612
643
} )
613
644
614
645
it ( 'should burn wamples' , async function ( ) {
@@ -628,6 +659,7 @@ describe('WAMPL:burnTo', () => {
628
659
await expect ( r )
629
660
. to . emit ( ampl , 'Transfer' )
630
661
. withArgs ( wAMPL . address , userBAddress , amplesWithdrawn )
662
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesWithdrawn )
631
663
} )
632
664
633
665
it ( 'should log burn' , async function ( ) {
@@ -658,8 +690,10 @@ describe('WAMPL:burnAll', () => {
658
690
amplesDeposited ,
659
691
)
660
692
693
+ balanceBefore = await ampl . balanceOf ( deployerAddress )
661
694
r = wAMPL . connect ( deployer ) . burnAll ( )
662
695
await r
696
+ balanceAfter = await ampl . balanceOf ( deployerAddress )
663
697
} )
664
698
665
699
it ( 'should burn wamples' , async function ( ) {
@@ -681,6 +715,7 @@ describe('WAMPL:burnAll', () => {
681
715
await expect ( r )
682
716
. to . emit ( wAMPL , 'Transfer' )
683
717
. withArgs ( deployerAddress , ethers . constants . AddressZero , wamplesMinted )
718
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesDeposited )
684
719
} )
685
720
} )
686
721
@@ -705,8 +740,10 @@ describe('WAMPL:burnAllTo', () => {
705
740
await wAMPL . connect ( deployer ) . callStatic . burnAllTo ( userBAddress ) ,
706
741
) . to . eq ( amplesDeposited )
707
742
743
+ balanceBefore = await ampl . balanceOf ( userBAddress )
708
744
r = wAMPL . connect ( deployer ) . withdrawAllTo ( userBAddress )
709
745
await r
746
+ balanceAfter = await ampl . balanceOf ( userBAddress )
710
747
} )
711
748
712
749
it ( 'should burn wamples' , async function ( ) {
@@ -724,6 +761,7 @@ describe('WAMPL:burnAllTo', () => {
724
761
await expect ( r )
725
762
. to . emit ( ampl , 'Transfer' )
726
763
. withArgs ( wAMPL . address , userBAddress , amplesDeposited )
764
+ expect ( balanceAfter . sub ( balanceBefore ) ) . to . eq ( amplesDeposited )
727
765
} )
728
766
729
767
it ( 'should log burn' , async function ( ) {
@@ -854,3 +892,64 @@ describe('Underlying Rebase:Contraction', async function () {
854
892
expect ( await wAMPL . balanceOf ( userCAddress ) ) . to . eq ( toWAMPLFixedPt ( '60000' ) )
855
893
} )
856
894
} )
895
+
896
+
897
+ describe ( 'user sends funds to the contract incorrectly' , async function ( ) {
898
+ beforeEach ( 'setup WAMPL contract' , setupContracts )
899
+
900
+ beforeEach ( async function ( ) {
901
+ await ampl
902
+ . connect ( deployer )
903
+ . transfer ( userAAddress , toAMPLFixedPt ( '1000000' ) )
904
+ await ampl
905
+ . connect ( deployer )
906
+ . transfer ( userBAddress , toAMPLFixedPt ( '1000000' ) )
907
+ await ampl
908
+ . connect ( deployer )
909
+ . transfer ( userCAddress , toAMPLFixedPt ( '1000000' ) )
910
+
911
+ await ampl . connect ( userA ) . approve ( wAMPL . address , toAMPLFixedPt ( '100000' ) )
912
+ await ampl . connect ( userB ) . approve ( wAMPL . address , toAMPLFixedPt ( '200000' ) )
913
+ await ampl . connect ( userC ) . approve ( wAMPL . address , toAMPLFixedPt ( '300000' ) )
914
+
915
+ await wAMPL . connect ( userA ) . deposit ( toAMPLFixedPt ( '100000' ) )
916
+ await wAMPL . connect ( userB ) . deposit ( toAMPLFixedPt ( '200000' ) )
917
+ await wAMPL . connect ( userC ) . deposit ( toAMPLFixedPt ( '300000' ) )
918
+ } )
919
+
920
+ it ( 'should not affect balances' , async function ( ) {
921
+ expect ( await wAMPL . totalUnderlying ( ) ) . to . eq ( toAMPLFixedPt ( '600000' ) )
922
+ expect ( await wAMPL . balanceOfUnderlying ( userAAddress ) ) . to . eq (
923
+ toAMPLFixedPt ( '100000' ) ,
924
+ )
925
+ expect ( await wAMPL . balanceOfUnderlying ( userBAddress ) ) . to . eq (
926
+ toAMPLFixedPt ( '200000' ) ,
927
+ )
928
+ expect ( await wAMPL . balanceOfUnderlying ( userCAddress ) ) . to . eq (
929
+ toAMPLFixedPt ( '300000' ) ,
930
+ )
931
+
932
+ expect ( await wAMPL . totalSupply ( ) ) . to . eq ( toWAMPLFixedPt ( '120000' ) )
933
+ expect ( await wAMPL . balanceOf ( userAAddress ) ) . to . eq ( toWAMPLFixedPt ( '20000' ) )
934
+ expect ( await wAMPL . balanceOf ( userBAddress ) ) . to . eq ( toWAMPLFixedPt ( '40000' ) )
935
+ expect ( await wAMPL . balanceOf ( userCAddress ) ) . to . eq ( toWAMPLFixedPt ( '60000' ) )
936
+
937
+ await ampl . transfer ( wAMPL . address , toAMPLFixedPt ( '300000' ) )
938
+
939
+ expect ( await wAMPL . totalUnderlying ( ) ) . to . eq ( toAMPLFixedPt ( '600000' ) )
940
+ expect ( await wAMPL . balanceOfUnderlying ( userAAddress ) ) . to . eq (
941
+ toAMPLFixedPt ( '100000' ) ,
942
+ )
943
+ expect ( await wAMPL . balanceOfUnderlying ( userBAddress ) ) . to . eq (
944
+ toAMPLFixedPt ( '200000' ) ,
945
+ )
946
+ expect ( await wAMPL . balanceOfUnderlying ( userCAddress ) ) . to . eq (
947
+ toAMPLFixedPt ( '300000' ) ,
948
+ )
949
+
950
+ expect ( await wAMPL . totalSupply ( ) ) . to . eq ( toWAMPLFixedPt ( '120000' ) )
951
+ expect ( await wAMPL . balanceOf ( userAAddress ) ) . to . eq ( toWAMPLFixedPt ( '20000' ) )
952
+ expect ( await wAMPL . balanceOf ( userBAddress ) ) . to . eq ( toWAMPLFixedPt ( '40000' ) )
953
+ expect ( await wAMPL . balanceOf ( userCAddress ) ) . to . eq ( toWAMPLFixedPt ( '60000' ) )
954
+ } )
955
+ } )
0 commit comments