@@ -1450,24 +1450,107 @@ describe('Withdraw Stable Pool', async function () {
1450
1450
) ;
1451
1451
} ) ;
1452
1452
1453
- it ( 'should remove stable liquidity' , async ( ) => {
1454
- // Clear wNEAR 'usn' account.
1455
- await global . wnearContract . burn ( {
1456
- args : {
1457
- account_id : config . usnId ,
1458
- amount : await global . wnearContract . ft_balance_of ( {
1459
- account_id : config . usnId ,
1460
- } ) ,
1453
+ it ( 'should fail trying to withdraw 100% because there is only 1 participant' , async ( ) => {
1454
+ await assert . rejects (
1455
+ async ( ) => {
1456
+ await global . usnContract . withdraw_stable_pool ( {
1457
+ args : { percent : 100 } ,
1458
+ amount : 3 * ONE_YOCTO ,
1459
+ gas : GAS_FOR_CALL ,
1460
+ } ) ;
1461
+ } ,
1462
+ ( err ) => {
1463
+ assert . match ( err . message , / C a l l b a c k c o m p u t a t i o n 0 w a s n o t s u c c e s s f u l / ) ;
1464
+ return true ;
1465
+ }
1466
+ ) ;
1467
+ } ) ;
1468
+
1469
+ it ( 'should fail trying to withdraw 101% of liquidity' , async ( ) => {
1470
+ await assert . rejects (
1471
+ async ( ) => {
1472
+ await global . usnContract . withdraw_stable_pool ( {
1473
+ args : { percent : 101 } ,
1474
+ amount : 3 * ONE_YOCTO ,
1475
+ gas : GAS_FOR_CALL ,
1476
+ } ) ;
1461
1477
} ,
1478
+ ( err ) => {
1479
+ assert . match ( err . message , / M a x i m u m 1 0 0 % / ) ;
1480
+ return true ;
1481
+ }
1482
+ ) ;
1483
+ } ) ;
1484
+
1485
+ it ( 'should withdraw 99% of shares' , async ( ) => {
1486
+ const poolInfoBefore = await global . refContract . get_stable_pool ( {
1487
+ pool_id : 0 ,
1488
+ } ) ;
1489
+
1490
+ await global . usnContract . withdraw_stable_pool ( {
1491
+ args : { percent : 99 } ,
1492
+ amount : 3 * ONE_YOCTO ,
1462
1493
gas : GAS_FOR_CALL ,
1463
1494
} ) ;
1464
1495
1465
- const wrapAmountBefore = await global . wnearContract . ft_balance_of ( {
1496
+ const poolInfoAfter = await global . refContract . get_stable_pool ( {
1497
+ pool_id : 0 ,
1498
+ } ) ;
1499
+
1500
+ const usnDeposit = await global . refContract . get_deposit ( {
1466
1501
account_id : config . usnId ,
1502
+ token_id : config . usnId ,
1503
+ } ) ;
1504
+ const usdtDeposit = await global . refContract . get_deposit ( {
1505
+ account_id : config . usnId ,
1506
+ token_id : config . usdtId ,
1467
1507
} ) ;
1508
+ const wrapDeposit = await global . refContract . get_deposit ( {
1509
+ account_id : config . usnId ,
1510
+ token_id : config . wnearId ,
1511
+ } ) ;
1512
+ assert . equal ( usnDeposit , '0' ) ;
1513
+ assert . equal ( usdtDeposit , '0' ) ;
1514
+ assert . equal ( wrapDeposit , '0' ) ;
1515
+
1516
+ assert (
1517
+ new BN ( poolInfoBefore . amounts [ 0 ] ) . gt ( new BN ( poolInfoAfter . amounts [ 0 ] ) )
1518
+ ) ;
1468
1519
1469
- assert . equal ( wrapAmountBefore , '0' ) ;
1520
+ assert (
1521
+ new BN ( poolInfoBefore . amounts [ 1 ] ) . gt ( new BN ( poolInfoAfter . amounts [ 1 ] ) )
1522
+ ) ;
1470
1523
1524
+ const poolUsn99Percent = new BN ( poolInfoBefore . amounts [ 0 ] )
1525
+ . mul ( new BN ( 991 ) )
1526
+ . div ( new BN ( 1000 ) ) ;
1527
+ const poolUsn98Percent = new BN ( poolInfoBefore . amounts [ 0 ] )
1528
+ . mul ( new BN ( 98 ) )
1529
+ . div ( new BN ( 100 ) ) ;
1530
+ const usnAmountDiff = new BN ( poolInfoBefore . amounts [ 0 ] ) . sub (
1531
+ new BN ( poolInfoAfter . amounts [ 0 ] )
1532
+ ) ;
1533
+
1534
+ // Withdrawn 98% < USN < 99%
1535
+ assert ( usnAmountDiff . gt ( new BN ( poolUsn98Percent ) ) ) ;
1536
+ assert ( usnAmountDiff . lt ( new BN ( poolUsn99Percent ) ) ) ;
1537
+
1538
+ const poolUsdt99Percent = new BN ( poolInfoBefore . amounts [ 1 ] )
1539
+ . mul ( new BN ( 991 ) )
1540
+ . div ( new BN ( 1000 ) ) ;
1541
+ const poolUsdt98Percent = new BN ( poolInfoBefore . amounts [ 1 ] )
1542
+ . mul ( new BN ( 98 ) )
1543
+ . div ( new BN ( 100 ) ) ;
1544
+ const usdtAmountDiff = new BN ( poolInfoBefore . amounts [ 1 ] ) . sub (
1545
+ new BN ( poolInfoAfter . amounts [ 1 ] )
1546
+ ) ;
1547
+
1548
+ // Withdrawn 98% < USDT < 99%
1549
+ assert ( usdtAmountDiff . gt ( new BN ( poolUsdt98Percent ) ) ) ;
1550
+ assert ( usdtAmountDiff . lt ( new BN ( poolUsdt99Percent ) ) ) ;
1551
+ } ) ;
1552
+
1553
+ it ( 'should withdraw 5% of shares' , async ( ) => {
1471
1554
const poolInfoBefore = await global . refContract . get_stable_pool ( {
1472
1555
pool_id : 0 ,
1473
1556
} ) ;
@@ -1494,14 +1577,9 @@ describe('Withdraw Stable Pool', async function () {
1494
1577
account_id : config . usnId ,
1495
1578
token_id : config . wnearId ,
1496
1579
} ) ;
1497
- const wrapAmount = await global . wnearContract . ft_balance_of ( {
1498
- account_id : config . usnId ,
1499
- } ) ;
1500
-
1501
1580
assert . equal ( usnDeposit , '0' ) ;
1502
1581
assert . equal ( usdtDeposit , '0' ) ;
1503
1582
assert . equal ( wrapDeposit , '0' ) ;
1504
- assert . equal ( wrapAmount , '0' ) ;
1505
1583
1506
1584
assert (
1507
1585
new BN ( poolInfoBefore . amounts [ 0 ] ) . gt ( new BN ( poolInfoAfter . amounts [ 0 ] ) )
0 commit comments