aftermath-ts-sdk 1.1.97 → 1.2.0-refactor.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/general/historicalData/historicalData.d.ts +1 -1
- package/dist/general/historicalData/historicalData.d.ts.map +1 -1
- package/dist/general/nfts/nftsApi.d.ts +1 -5
- package/dist/general/nfts/nftsApi.d.ts.map +1 -1
- package/dist/general/nfts/nftsApi.js +15 -29
- package/dist/general/nfts/nftsApiCasting.d.ts +0 -1
- package/dist/general/nfts/nftsApiCasting.d.ts.map +1 -1
- package/dist/general/nfts/nftsApiCasting.js +0 -10
- package/dist/general/nfts/nftsTypes.d.ts +0 -1
- package/dist/general/nfts/nftsTypes.d.ts.map +1 -1
- package/dist/general/prices/{coingecko/coinGeckoTypes.d.ts → coinGeckoTypes.d.ts} +1 -1
- package/dist/general/prices/coinGeckoTypes.d.ts.map +1 -0
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +1 -2
- package/dist/general/providers/aftermathApi.d.ts +1 -34
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +2 -90
- package/dist/general/types/castingTypes.d.ts +0 -7
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/configTypes.d.ts +0 -6
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +0 -3
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/index.d.ts +1 -0
- package/dist/general/types/index.d.ts.map +1 -1
- package/dist/general/types/index.js +1 -0
- package/dist/general/utils/helpers.d.ts +1 -16
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +2 -32
- package/dist/general/utils/index.d.ts +0 -1
- package/dist/general/utils/index.d.ts.map +1 -1
- package/dist/general/utils/index.js +0 -1
- package/dist/packages/coin/api/coinApi.d.ts +1 -12
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +0 -123
- package/dist/packages/dca/api/dcaApi.d.ts +1 -28
- package/dist/packages/dca/api/dcaApi.d.ts.map +1 -1
- package/dist/packages/dca/api/dcaApi.js +0 -172
- package/dist/packages/farms/api/farmsApi.d.ts +1 -24
- package/dist/packages/farms/api/farmsApi.d.ts.map +1 -1
- package/dist/packages/farms/api/farmsApi.js +0 -69
- package/dist/packages/farms/api/farmsApiCasting.d.ts +2 -3
- package/dist/packages/farms/api/farmsApiCasting.d.ts.map +1 -1
- package/dist/packages/farms/api/farmsApiCasting.js +0 -45
- package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +0 -9
- package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.d.ts +0 -5
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +2 -29
- package/dist/packages/faucet/faucet.d.ts +3 -2
- package/dist/packages/faucet/faucet.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.js +2 -2
- package/dist/packages/leveragedStaking/api/leveragedStakingApi.d.ts.map +1 -1
- package/dist/packages/leveragedStaking/api/leveragedStakingApi.js +383 -298
- package/dist/packages/nftAmm/nftAmmMarket.d.ts +9 -5
- package/dist/packages/nftAmm/nftAmmMarket.d.ts.map +1 -1
- package/dist/packages/nftAmm/nftAmmMarket.js +34 -6
- package/dist/packages/oracle/api/oracleApi.d.ts +1 -10
- package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -1
- package/dist/packages/oracle/api/oracleApi.js +0 -38
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts +2 -58
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.js +0 -735
- package/dist/packages/pools/api/poolsApi.d.ts +2 -217
- package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApi.js +0 -752
- package/dist/packages/pools/api/poolsApiCasting.d.ts +3 -15
- package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiCasting.js +0 -86
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +1 -15
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/pools/pools.d.ts +4 -1
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +5 -0
- package/dist/packages/router/api/routerApi.d.ts +2 -116
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +3 -345
- package/dist/packages/router/api/routerApiCasting.d.ts +2 -5
- package/dist/packages/router/api/routerApiCasting.d.ts.map +1 -1
- package/dist/packages/router/api/routerApiCasting.js +0 -104
- package/dist/packages/router/api/routerApiCastingTypes.d.ts +1 -13
- package/dist/packages/router/api/routerApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/router/routerTypes.d.ts +3 -35
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.d.ts +2 -50
- package/dist/packages/staking/api/stakingApi.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.js +0 -226
- package/dist/packages/staking/api/stakingApiCasting.d.ts +2 -4
- package/dist/packages/staking/api/stakingApiCasting.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApiCasting.js +0 -21
- package/dist/packages/staking/api/stakingApiCastingTypes.d.ts +1 -8
- package/dist/packages/staking/api/stakingApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/staking/stakingTypes.d.ts +2 -0
- package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
- package/dist/packages/sui/api/suiApi.d.ts +1 -2
- package/dist/packages/sui/api/suiApi.d.ts.map +1 -1
- package/dist/packages/sui/api/suiApi.js +0 -3
- package/package.json +1 -1
- package/dist/general/dynamicGas/dynamicGasApi.d.ts +0 -15
- package/dist/general/dynamicGas/dynamicGasApi.d.ts.map +0 -1
- package/dist/general/dynamicGas/dynamicGasApi.js +0 -87
- package/dist/general/historicalData/historicalDataApi.d.ts +0 -9
- package/dist/general/historicalData/historicalDataApi.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataApi.js +0 -13
- package/dist/general/historicalData/historicalDataApiInterface.d.ts +0 -12
- package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataApiInterface.js +0 -2
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts +0 -13
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts.map +0 -1
- package/dist/general/historicalData/placeholderHistoricalDataApi.js +0 -26
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +0 -22
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +0 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +0 -179
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts +0 -23
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts.map +0 -1
- package/dist/general/prices/coingecko/coinGeckoPricesApi.js +0 -113
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts.map +0 -1
- package/dist/general/prices/placeholder/placeholderPricesApi.d.ts +0 -20
- package/dist/general/prices/placeholder/placeholderPricesApi.d.ts.map +0 -1
- package/dist/general/prices/placeholder/placeholderPricesApi.js +0 -85
- package/dist/general/prices/pricesApiInterface.d.ts +0 -13
- package/dist/general/prices/pricesApiInterface.d.ts.map +0 -1
- package/dist/general/prices/pricesApiInterface.js +0 -2
- package/dist/general/prices/pyth/pythPricesApi.d.ts +0 -2
- package/dist/general/prices/pyth/pythPricesApi.d.ts.map +0 -1
- package/dist/general/prices/pyth/pythPricesApi.js +0 -52
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts +0 -13
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts.map +0 -1
- package/dist/general/prices/pyth/pythPricesApiHelpers.js +0 -77
- package/dist/general/prices/router/routerPricesApi.d.ts +0 -18
- package/dist/general/prices/router/routerPricesApi.d.ts.map +0 -1
- package/dist/general/prices/router/routerPricesApi.js +0 -126
- package/dist/general/utils/indexerCaller.d.ts +0 -14
- package/dist/general/utils/indexerCaller.d.ts.map +0 -1
- package/dist/general/utils/indexerCaller.js +0 -129
- /package/dist/general/prices/{coingecko/coinGeckoTypes.js → coinGeckoTypes.js} +0 -0
|
@@ -17,10 +17,7 @@ const utils_1 = require("../../../general/utils");
|
|
|
17
17
|
const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers");
|
|
18
18
|
const coin_1 = require("../../coin");
|
|
19
19
|
const sui_1 = require("../../sui");
|
|
20
|
-
const __1 = require("..");
|
|
21
20
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
22
|
-
const duration_1 = __importDefault(require("dayjs/plugin/duration"));
|
|
23
|
-
const __2 = require("../..");
|
|
24
21
|
// import BigNumber from "bignumber.js";
|
|
25
22
|
// import {
|
|
26
23
|
// BalanceSheet,
|
|
@@ -414,111 +411,126 @@ class LeveragedStakingApi {
|
|
|
414
411
|
});
|
|
415
412
|
// TODO(Kevin): Documentation.
|
|
416
413
|
this.fetchBuildLeveragedUnstakeTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const
|
|
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
|
-
|
|
414
|
+
throw new Error("TODO");
|
|
415
|
+
// if (!this.ScallopProviders)
|
|
416
|
+
// throw new Error("Scallop providers not set");
|
|
417
|
+
// const {
|
|
418
|
+
// referrer,
|
|
419
|
+
// walletAddress,
|
|
420
|
+
// leveragedAfSuiPositionId,
|
|
421
|
+
// obligationId,
|
|
422
|
+
// unstakeAmount,
|
|
423
|
+
// desiredUnstakeCoinType,
|
|
424
|
+
// slippage,
|
|
425
|
+
// } = inputs;
|
|
426
|
+
// const scallopTx = this.ScallopProviders.Builder.createTxBlock();
|
|
427
|
+
// const tx = scallopTx.txBlock;
|
|
428
|
+
// tx.setSender(walletAddress);
|
|
429
|
+
// // i. Set the users referrer address.
|
|
430
|
+
// if (referrer)
|
|
431
|
+
// this.Provider.ReferralVault().updateReferrerTx({
|
|
432
|
+
// // @ts-ignore
|
|
433
|
+
// tx,
|
|
434
|
+
// referrer,
|
|
435
|
+
// });
|
|
436
|
+
// // ii. Obtain the user's `LeveragedAfSuiPosition`.
|
|
437
|
+
// const leveragedAfSuiPosition = await this.fetchLeveragedAfSuiPosition({
|
|
438
|
+
// leveragedAfSuiPositionId,
|
|
439
|
+
// obligationId,
|
|
440
|
+
// });
|
|
441
|
+
// // iii. Initiate Unstake tx.
|
|
442
|
+
// const leveragedActionCapId = this.initiateLeverageUnstakeTx({
|
|
443
|
+
// // @ts-ignore
|
|
444
|
+
// tx,
|
|
445
|
+
// leveragedAfSuiPositionId,
|
|
446
|
+
// unstakeAmount,
|
|
447
|
+
// });
|
|
448
|
+
// const afSuiToSuiExchangeRate =
|
|
449
|
+
// await this.Provider.Staking().fetchAfSuiToSuiExchangeRate();
|
|
450
|
+
// // iv. Calculate current leverage ratio.
|
|
451
|
+
// const currentLeverageRatio = LeveragedStaking.calcLeverage({
|
|
452
|
+
// totalSuiDebt: leveragedAfSuiPosition.suiDebt,
|
|
453
|
+
// totalAfSuiCollateral: leveragedAfSuiPosition.afSuiCollateral,
|
|
454
|
+
// afSuiToSuiExchangeRate,
|
|
455
|
+
// });
|
|
456
|
+
// let unstakedCoinId;
|
|
457
|
+
// let unstakedCoinType;
|
|
458
|
+
// // [Edge Case] Position has no debt.
|
|
459
|
+
// if (leveragedAfSuiPosition.suiDebt === BigInt(0)) {
|
|
460
|
+
// // va. Withdraw `unstakeAmount` worth of afSUI collateral.
|
|
461
|
+
// const [unstakedAfSuiCollateral] =
|
|
462
|
+
// await this.fetchBuildWithdrawAfSuiCollateralTx({
|
|
463
|
+
// ...inputs,
|
|
464
|
+
// scallopTx,
|
|
465
|
+
// leveragedActionCapId,
|
|
466
|
+
// withdrawAmount: unstakeAmount,
|
|
467
|
+
// });
|
|
468
|
+
// unstakedCoinId = unstakedAfSuiCollateral;
|
|
469
|
+
// unstakedCoinType = "afsui";
|
|
470
|
+
// } /* (leveragedAfSuiPosition.suiDebt > BigInt(0)) */ else {
|
|
471
|
+
// // vb. Decrease the leverage to the desired leverage ratio.
|
|
472
|
+
// const remainingSuiCoinId = await this.fetchBuildDecreaseLeverageTx({
|
|
473
|
+
// scallopTx,
|
|
474
|
+
// leveragedActionCapId,
|
|
475
|
+
// leveragedAfSuiPositionId,
|
|
476
|
+
// obligationId,
|
|
477
|
+
// totalSuiDebt: leveragedAfSuiPosition.suiDebt,
|
|
478
|
+
// totalAfSuiCollateral: leveragedAfSuiPosition.afSuiCollateral,
|
|
479
|
+
// // REVIEW(Kevin): should we be subtracting from here too?
|
|
480
|
+
// //
|
|
481
|
+
// // totalAfSuiCollateral:
|
|
482
|
+
// // inputs.totalAfSuiCollateral - unstakeAmount,
|
|
483
|
+
// newLeverage: currentLeverageRatio,
|
|
484
|
+
// baseAfSuiCollateral: inputs.baseAfSuiCollateral - unstakeAmount,
|
|
485
|
+
// slippage,
|
|
486
|
+
// });
|
|
487
|
+
// unstakedCoinId = remainingSuiCoinId;
|
|
488
|
+
// unstakedCoinType = "sui";
|
|
489
|
+
// }
|
|
490
|
+
// // vi. Return the unstaked coin to the user in their desired coin (SUI or afSUI).
|
|
491
|
+
// if (unstakedCoinType === inputs.desiredUnstakeCoinType) {
|
|
492
|
+
// // via. Unstaked coin already in desired coin type; no extra work needed.
|
|
493
|
+
// tx.transferObjects([unstakedCoinId], walletAddress);
|
|
494
|
+
// } else if (desiredUnstakeCoinType === "sui") {
|
|
495
|
+
// // vib. Swap withdrawn afSUI into SUI and return to the user.
|
|
496
|
+
// const poolObject = await this.Provider.Pools().fetchPool({
|
|
497
|
+
// objectId:
|
|
498
|
+
// this.addresses.leveragedStaking.objects.afSuiSuiPoolId,
|
|
499
|
+
// });
|
|
500
|
+
// const pool = new Pool(poolObject);
|
|
501
|
+
// const swappedSuiCoinId =
|
|
502
|
+
// await this.Provider.Pools().fetchAddTradeTx({
|
|
503
|
+
// // @ts-ignore
|
|
504
|
+
// tx,
|
|
505
|
+
// pool,
|
|
506
|
+
// coinInAmount: unstakeAmount,
|
|
507
|
+
// coinInId: unstakedCoinId,
|
|
508
|
+
// coinInType: this.Provider.Staking().coinTypes.afSui,
|
|
509
|
+
// coinOutType: Coin.constants.suiCoinType,
|
|
510
|
+
// slippage,
|
|
511
|
+
// });
|
|
512
|
+
// tx.transferObjects([swappedSuiCoinId], walletAddress);
|
|
513
|
+
// } /* if (desiredUnstakeCoinType === "afsui") */ else {
|
|
514
|
+
// // vic. Stake the withdrawn SUI for afSUI and return to the user.
|
|
515
|
+
// let [unstakedAfSuiCollateral] = this.Provider.Staking().stakeTx({
|
|
516
|
+
// // @ts-ignore
|
|
517
|
+
// tx,
|
|
518
|
+
// validatorAddress:
|
|
519
|
+
// this.addresses.staking.objects.aftermathValidator,
|
|
520
|
+
// suiCoin: unstakedCoinId,
|
|
521
|
+
// });
|
|
522
|
+
// tx.transferObjects([unstakedAfSuiCollateral], walletAddress);
|
|
523
|
+
// }
|
|
524
|
+
// // vii. Complete Unstake tx.
|
|
525
|
+
// this.completeActionTx({
|
|
526
|
+
// // @ts-ignore
|
|
527
|
+
// tx,
|
|
528
|
+
// leveragedActionCapId,
|
|
529
|
+
// leveragedAfSuiPositionId,
|
|
530
|
+
// obligationId,
|
|
531
|
+
// });
|
|
532
|
+
// // @ts-ignore
|
|
533
|
+
// return tx;
|
|
522
534
|
});
|
|
523
535
|
// TODO(Kevin): Documentation.
|
|
524
536
|
this.fetchBuildChangeLeverageTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -571,59 +583,83 @@ class LeveragedStakingApi {
|
|
|
571
583
|
});
|
|
572
584
|
// TODO(Kevin): Documentation.
|
|
573
585
|
this.fetchBuildIncreaseLeverageTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
574
|
-
|
|
575
|
-
const
|
|
576
|
-
const
|
|
577
|
-
const
|
|
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
|
-
//
|
|
586
|
+
throw new Error("TODO");
|
|
587
|
+
// const { scallopTx } = inputs;
|
|
588
|
+
// const tx = scallopTx.txBlock;
|
|
589
|
+
// const afSuiToSuiExchangeRate =
|
|
590
|
+
// await this.Provider.Staking().fetchAfSuiToSuiExchangeRate();
|
|
591
|
+
// const newTotalAfSuiCollateral = BigInt(
|
|
592
|
+
// Math.floor(Number(inputs.baseAfSuiCollateral) * inputs.newLeverage)
|
|
593
|
+
// );
|
|
594
|
+
// // ia. Calculate the extra amount of afSUI collateral that must be deposited to reach the new
|
|
595
|
+
// // desired leverage.
|
|
596
|
+
// const increaseInTotalAfSuiCollateral =
|
|
597
|
+
// newTotalAfSuiCollateral - inputs.totalAfSuiCollateral;
|
|
598
|
+
// // ib. Calculate amount of SUI that must be flash loaned to account for
|
|
599
|
+
// // `increaseInAfSuiCollateral`.
|
|
600
|
+
// const flashLoanAmount: Balance = BigInt(
|
|
601
|
+
// Math.floor(
|
|
602
|
+
// Number(increaseInTotalAfSuiCollateral) * afSuiToSuiExchangeRate
|
|
603
|
+
// )
|
|
604
|
+
// );
|
|
605
|
+
// // ii. Flash loan the required amount of SUI from Scallop to increase the position by
|
|
606
|
+
// // `increaseInAfSuiCollateral` afSUI.
|
|
607
|
+
// const [flashLoanedSuiCoinId, loan] = scallopTx.borrowFlashLoan(
|
|
608
|
+
// flashLoanAmount,
|
|
609
|
+
// "sui"
|
|
610
|
+
// );
|
|
611
|
+
// const { afSuiCoinId } = await this.swapOrStakeSuiToAfSui({
|
|
612
|
+
// // @ts-ignore
|
|
613
|
+
// tx,
|
|
614
|
+
// suiAmount: flashLoanAmount,
|
|
615
|
+
// suiCoinId: flashLoanedSuiCoinId,
|
|
616
|
+
// });
|
|
617
|
+
// // iv. Deposit the staked afSUI as collateral on Scallop.
|
|
618
|
+
// this.depositAfSuiCollateralTx({
|
|
619
|
+
// ...inputs,
|
|
620
|
+
// // @ts-ignore
|
|
621
|
+
// tx,
|
|
622
|
+
// afSuiCoinId,
|
|
623
|
+
// obligationId: inputs.obligationId,
|
|
624
|
+
// });
|
|
625
|
+
// // REVIEW(Kevin): check if both assets need to be updated.
|
|
626
|
+
// //
|
|
627
|
+
// await scallopTx.updateAssetPricesQuick(["sui", "afsui"]);
|
|
628
|
+
// // v. Borrow amount of SUI required to pay off flash loan.
|
|
629
|
+
// const [borrowedSuiCoinId] = this.borrowSuiTx({
|
|
630
|
+
// ...inputs,
|
|
631
|
+
// // @ts-ignore
|
|
632
|
+
// tx,
|
|
633
|
+
// borrowAmount: flashLoanAmount + BigInt(/*0__0*/ 50_000_000),
|
|
634
|
+
// // borrowAmount: flashLoanAmount,
|
|
635
|
+
// });
|
|
636
|
+
// const repayLoanSuiCoinId = tx.splitCoins(borrowedSuiCoinId, [
|
|
637
|
+
// flashLoanAmount,
|
|
638
|
+
// ]);
|
|
639
|
+
// // vi. Repay flash loan on Scallop.
|
|
640
|
+
// scallopTx.repayFlashLoan(
|
|
641
|
+
// // flashLoanedSuiCoinId,
|
|
642
|
+
// repayLoanSuiCoinId,
|
|
643
|
+
// // borrowedSuiCoinId,
|
|
644
|
+
// loan,
|
|
645
|
+
// "sui"
|
|
646
|
+
// );
|
|
647
|
+
// // Leftover SUI is used to repay SUI debt.
|
|
621
648
|
// this.repaySuiTx({
|
|
649
|
+
// ...inputs,
|
|
650
|
+
// // @ts-ignore
|
|
622
651
|
// tx,
|
|
623
|
-
// leveragedActionCapId,
|
|
624
|
-
// obligationId,
|
|
625
652
|
// suiCoinId: borrowedSuiCoinId,
|
|
626
653
|
// });
|
|
654
|
+
// // REVIEW(kevin): will there even be any leftover SUI to repay?
|
|
655
|
+
// //
|
|
656
|
+
// // // vii. [Potentially] Use remaining SUI to repay debt.
|
|
657
|
+
// // this.repaySuiTx({
|
|
658
|
+
// // tx,
|
|
659
|
+
// // leveragedActionCapId,
|
|
660
|
+
// // obligationId,
|
|
661
|
+
// // suiCoinId: borrowedSuiCoinId,
|
|
662
|
+
// // });
|
|
627
663
|
});
|
|
628
664
|
// TODO(Kevin): Documentation.
|
|
629
665
|
//
|
|
@@ -636,100 +672,134 @@ class LeveragedStakingApi {
|
|
|
636
672
|
// 5. Convert afSUI to SUI.
|
|
637
673
|
// 6. Repay flash loan.
|
|
638
674
|
this.fetchBuildDecreaseLeverageTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
const
|
|
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
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
//
|
|
690
|
-
|
|
691
|
-
|
|
675
|
+
throw new Error("TODO");
|
|
676
|
+
// const { scallopTx, slippage } = inputs;
|
|
677
|
+
// const tx = scallopTx.txBlock;
|
|
678
|
+
// const afSuiToSuiExchangeRate =
|
|
679
|
+
// await this.Provider.Staking().fetchAfSuiToSuiExchangeRate();
|
|
680
|
+
// let decreaseInAfSuiCollateral;
|
|
681
|
+
// let decreaseInSuiDebt;
|
|
682
|
+
// // [Edge Case] User wants to unstake their entire position.
|
|
683
|
+
// if (inputs.baseAfSuiCollateral === BigInt(0)) {
|
|
684
|
+
// // TODO: [edge case] handle closing of position.
|
|
685
|
+
// //
|
|
686
|
+
// decreaseInAfSuiCollateral = BigInt(inputs.totalAfSuiCollateral);
|
|
687
|
+
// // decreaseInAfSuiCollateral = inputs.totalAfSuiCollateral;
|
|
688
|
+
// decreaseInSuiDebt = inputs.totalSuiDebt;
|
|
689
|
+
// } else {
|
|
690
|
+
// // ia. Calculate the amount of afSUI collateral that must be withdrawn to reach
|
|
691
|
+
// // a leverage ratio of `newLeverage`.
|
|
692
|
+
// const newTotalAfSuiCollateral = BigInt(
|
|
693
|
+
// Math.floor(
|
|
694
|
+
// Number(inputs.baseAfSuiCollateral) * inputs.newLeverage
|
|
695
|
+
// )
|
|
696
|
+
// );
|
|
697
|
+
// decreaseInAfSuiCollateral =
|
|
698
|
+
// inputs.totalAfSuiCollateral - newTotalAfSuiCollateral;
|
|
699
|
+
// // ib. Calculate the amount of SUI debt that must be repayed to allow withdrawing
|
|
700
|
+
// // `decreaseInAfSuiCollateral` worth of afSUI collateral.
|
|
701
|
+
// const newSuiDebt = BigInt(
|
|
702
|
+
// Math.floor(
|
|
703
|
+
// Number(
|
|
704
|
+
// newTotalAfSuiCollateral - inputs.baseAfSuiCollateral
|
|
705
|
+
// ) * afSuiToSuiExchangeRate
|
|
706
|
+
// )
|
|
707
|
+
// );
|
|
708
|
+
// decreaseInSuiDebt = inputs.totalSuiDebt - newSuiDebt;
|
|
709
|
+
// }
|
|
710
|
+
// // ii. Flash loan `decreaseInSuiDebt` worth of SUI from Scallop.
|
|
711
|
+
// const [flashLoanedSuiCoinId, loan] = scallopTx.borrowFlashLoan(
|
|
712
|
+
// decreaseInSuiDebt,
|
|
713
|
+
// "sui"
|
|
714
|
+
// );
|
|
715
|
+
// // iii. Repay `decreaseInSuiDebt` of SUI debt.
|
|
716
|
+
// this.repaySuiTx({
|
|
717
|
+
// ...inputs,
|
|
718
|
+
// // @ts-ignore
|
|
719
|
+
// tx,
|
|
720
|
+
// suiCoinId: flashLoanedSuiCoinId,
|
|
721
|
+
// });
|
|
722
|
+
// // iv. Withdraw `decreaseInCollateralAmount` worth of afSUI collateral.
|
|
723
|
+
// const [afSuiId] = await this.fetchBuildWithdrawAfSuiCollateralTx({
|
|
724
|
+
// ...inputs,
|
|
725
|
+
// withdrawAmount: decreaseInAfSuiCollateral,
|
|
726
|
+
// });
|
|
727
|
+
// // v. Convert `decreaseInCollateralAmount` of withdrawn collateral into SUI.
|
|
728
|
+
// const poolObject = await this.Provider.Pools().fetchPool({
|
|
729
|
+
// objectId: this.addresses.leveragedStaking.objects.afSuiSuiPoolId,
|
|
730
|
+
// });
|
|
731
|
+
// const pool = new Pool(poolObject);
|
|
732
|
+
// const swappedSuiCoinId = await this.Provider.Pools().fetchAddTradeTx({
|
|
733
|
+
// // @ts-ignore
|
|
734
|
+
// tx,
|
|
735
|
+
// pool,
|
|
736
|
+
// coinInAmount: BigInt(
|
|
737
|
+
// Math.floor(Number(decreaseInSuiDebt) * afSuiToSuiExchangeRate)
|
|
738
|
+
// ),
|
|
739
|
+
// coinInId: afSuiId,
|
|
740
|
+
// coinInType: this.Provider.Staking().coinTypes.afSui,
|
|
741
|
+
// coinOutType: Coin.constants.suiCoinType,
|
|
742
|
+
// slippage,
|
|
743
|
+
// });
|
|
744
|
+
// const repayLoanSuiCoinId = tx.splitCoins(swappedSuiCoinId, [
|
|
745
|
+
// decreaseInSuiDebt,
|
|
746
|
+
// ]);
|
|
747
|
+
// // vi. Repay flash loan with converted SUI.
|
|
748
|
+
// scallopTx.repayFlashLoan(repayLoanSuiCoinId, loan, "sui");
|
|
749
|
+
// return swappedSuiCoinId;
|
|
692
750
|
});
|
|
693
751
|
// =========================================================================
|
|
694
752
|
// Helpers
|
|
695
753
|
// =========================================================================
|
|
696
754
|
this.swapOrStakeSuiToAfSui = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
697
|
-
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
let
|
|
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
|
-
|
|
755
|
+
throw new Error("TODO");
|
|
756
|
+
// const { tx, suiAmount, suiCoinId } = inputs;
|
|
757
|
+
// const estimatedSlippageLowerBound = 0.0001; // 0.01%
|
|
758
|
+
// let afSuiCoinId: TransactionObjectArgument;
|
|
759
|
+
// let minAmountOut: Balance;
|
|
760
|
+
// if (suiAmount >= Staking.constants.bounds.minStake) {
|
|
761
|
+
// // Stake SUI into afSUI.
|
|
762
|
+
// afSuiCoinId = this.Provider.Staking().stakeTx({
|
|
763
|
+
// tx,
|
|
764
|
+
// validatorAddress:
|
|
765
|
+
// this.addresses.staking.objects.aftermathValidator,
|
|
766
|
+
// suiCoin: suiCoinId,
|
|
767
|
+
// });
|
|
768
|
+
// const afSuiToSuiExchangeRate =
|
|
769
|
+
// await this.Provider.Staking().fetchAfSuiToSuiExchangeRate();
|
|
770
|
+
// minAmountOut = BigInt(
|
|
771
|
+
// Math.floor(Number(suiAmount) * afSuiToSuiExchangeRate)
|
|
772
|
+
// );
|
|
773
|
+
// } else {
|
|
774
|
+
// const poolObject = await this.Provider.Pools().fetchPool({
|
|
775
|
+
// objectId:
|
|
776
|
+
// this.addresses.leveragedStaking.objects.afSuiSuiPoolId,
|
|
777
|
+
// });
|
|
778
|
+
// const pool = new Pool(poolObject);
|
|
779
|
+
// minAmountOut = BigInt(
|
|
780
|
+
// Math.floor(
|
|
781
|
+
// Number(
|
|
782
|
+
// pool.getTradeAmountOut({
|
|
783
|
+
// coinInAmount: suiAmount,
|
|
784
|
+
// coinInType: Coin.constants.suiCoinType,
|
|
785
|
+
// coinOutType:
|
|
786
|
+
// this.Provider.Staking().coinTypes.afSui,
|
|
787
|
+
// })
|
|
788
|
+
// ) *
|
|
789
|
+
// (1 - estimatedSlippageLowerBound)
|
|
790
|
+
// )
|
|
791
|
+
// );
|
|
792
|
+
// afSuiCoinId = await this.Provider.Pools().fetchAddTradeTx({
|
|
793
|
+
// tx,
|
|
794
|
+
// pool,
|
|
795
|
+
// slippage: 1, // 100%
|
|
796
|
+
// coinInAmount: suiAmount,
|
|
797
|
+
// coinInId: suiCoinId,
|
|
798
|
+
// coinInType: Coin.constants.suiCoinType,
|
|
799
|
+
// coinOutType: this.Provider.Staking().coinTypes.afSui,
|
|
800
|
+
// });
|
|
801
|
+
// }
|
|
802
|
+
// return { afSuiCoinId, minAmountOut };
|
|
733
803
|
});
|
|
734
804
|
// REVIEW: this is only needed if a user's Obligation can have its debt increased by another address.
|
|
735
805
|
// If that isn't possible, then obligation's debt amount + borrow index will always be accurate after
|
|
@@ -793,18 +863,29 @@ class LeveragedStakingApi {
|
|
|
793
863
|
*/
|
|
794
864
|
fetchEventsForUser(inputs) {
|
|
795
865
|
return __awaiter(this, void 0, void 0, function* () {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
866
|
+
throw new Error("TODO");
|
|
867
|
+
// const { walletAddress, cursor, limit } = inputs;
|
|
868
|
+
// return this.Provider.indexerCaller.fetchIndexerEvents(
|
|
869
|
+
// `leveraged-staking/${walletAddress}/events`,
|
|
870
|
+
// {
|
|
871
|
+
// cursor,
|
|
872
|
+
// limit,
|
|
873
|
+
// },
|
|
874
|
+
// (event) => {
|
|
875
|
+
// const eventType = (event as EventOnChain<any>).type;
|
|
876
|
+
// return eventType.includes(this.eventTypes.leveragedStaked)
|
|
877
|
+
// ? Casting.leveragedStaking.leveragedStakedEventFromOnChain(
|
|
878
|
+
// event as LeveragedStakedEventOnChain
|
|
879
|
+
// )
|
|
880
|
+
// : eventType.includes(this.eventTypes.leveragedUnstaked)
|
|
881
|
+
// ? Casting.leveragedStaking.leveragedUnstakedEventFromOnChain(
|
|
882
|
+
// event as LeveragedUnstakedEventOnChain
|
|
883
|
+
// )
|
|
884
|
+
// : Casting.leveragedStaking.leveragedStakeChangedEventFromOnChain(
|
|
885
|
+
// event as LeveragedStakeChangedLeverageEventOnChain
|
|
886
|
+
// );
|
|
887
|
+
// }
|
|
888
|
+
// );
|
|
808
889
|
});
|
|
809
890
|
}
|
|
810
891
|
// =========================================================================
|
|
@@ -817,46 +898,50 @@ class LeveragedStakingApi {
|
|
|
817
898
|
*/
|
|
818
899
|
fetchPerformanceData(inputs) {
|
|
819
900
|
return __awaiter(this, void 0, void 0, function* () {
|
|
820
|
-
const { timeframe, borrowRate, maxLeverage } = inputs;
|
|
821
|
-
|
|
822
|
-
const limit = // days ~ epochs
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
//
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
901
|
+
// const { timeframe, borrowRate, maxLeverage } = inputs;
|
|
902
|
+
// dayjs.extend(duration);
|
|
903
|
+
// const limit = // days ~ epochs
|
|
904
|
+
// dayjs
|
|
905
|
+
// .duration(
|
|
906
|
+
// LeveragedStakingApi.dataTimeframesToDays[timeframe],
|
|
907
|
+
// "days"
|
|
908
|
+
// )
|
|
909
|
+
// // + 2 to account for apy being calculated from events delta
|
|
910
|
+
// // (and possible initial 0 afsui supply)
|
|
911
|
+
// .asDays() + 2;
|
|
912
|
+
// // TODO: fetch borrow rate historically once scallop implements
|
|
913
|
+
// const [recentEpochChanges] = await Promise.all([
|
|
914
|
+
// this.Provider.Staking().fetchEpochWasChangedEvents({
|
|
915
|
+
// limit,
|
|
916
|
+
// }),
|
|
917
|
+
// ]);
|
|
918
|
+
// if (recentEpochChanges.events.length <= 2) return [];
|
|
919
|
+
// const daysInYear = 365;
|
|
920
|
+
// const timeData = recentEpochChanges.events
|
|
921
|
+
// .slice(2)
|
|
922
|
+
// .map((event, index) => {
|
|
923
|
+
// const currentRate = Number(event.totalAfSuiSupply)
|
|
924
|
+
// ? Number(event.totalSuiAmount) /
|
|
925
|
+
// Number(event.totalAfSuiSupply)
|
|
926
|
+
// : 1;
|
|
927
|
+
// const pastEvent = recentEpochChanges.events[index + 1];
|
|
928
|
+
// const pastRate = Number(pastEvent.totalAfSuiSupply)
|
|
929
|
+
// ? Number(pastEvent.totalSuiAmount) /
|
|
930
|
+
// Number(pastEvent.totalAfSuiSupply)
|
|
931
|
+
// : 1;
|
|
932
|
+
// const afSuiApy =
|
|
933
|
+
// ((currentRate - pastRate) / pastRate) * daysInYear;
|
|
934
|
+
// return {
|
|
935
|
+
// time: event.timestamp ?? 0,
|
|
936
|
+
// sui: 0,
|
|
937
|
+
// afSui: afSuiApy,
|
|
938
|
+
// leveragedAfSui:
|
|
939
|
+
// maxLeverage *
|
|
940
|
+
// (afSuiApy - borrowRate * (1 - 1 / maxLeverage)),
|
|
941
|
+
// };
|
|
942
|
+
// });
|
|
943
|
+
// return timeData;
|
|
944
|
+
throw new Error("not implemented");
|
|
860
945
|
});
|
|
861
946
|
}
|
|
862
947
|
// NOTE: ported from Scallop's SDK.
|