@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.9 → 2.3.1
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/index.d.mts +1841 -1809
- package/dist/index.d.ts +1841 -1809
- package/dist/index.js +49 -2
- package/dist/index.mjs +15 -2
- package/package.json +8 -7
- package/src/builders/borrowIncentiveBuilder.ts +4 -4
- package/src/builders/coreBuilder.ts +86 -59
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +2 -2
- package/src/builders/oracles/index.ts +365 -114
- package/src/builders/oracles/pyth.ts +135 -0
- package/src/builders/referralBuilder.ts +4 -10
- package/src/builders/sCoinBuilder.ts +2 -2
- package/src/builders/spoolBuilder.ts +5 -8
- package/src/builders/vescaBuilder.ts +5 -5
- package/src/constants/common.ts +3 -0
- package/src/constants/index.ts +1 -1
- package/src/constants/queryKeys.ts +1 -1
- package/src/constants/rpc.ts +0 -1
- package/src/constants/testAddress.ts +99 -271
- package/src/constants/xoracle.ts +2 -8
- package/src/index.ts +1 -1
- package/src/models/index.ts +1 -2
- package/src/models/interface.ts +7 -7
- package/src/models/rateLimiter.ts +55 -0
- package/src/models/scallop.ts +2 -2
- package/src/models/scallopAddress.ts +7 -35
- package/src/models/scallopBuilder.ts +19 -12
- package/src/models/scallopClient.ts +47 -33
- package/src/models/scallopConstants.ts +3 -3
- package/src/models/scallopIndexer.ts +3 -4
- package/src/models/scallopQuery.ts +113 -57
- package/src/models/scallopQueryClient.ts +1 -1
- package/src/models/scallopSuiKit.ts +1 -1
- package/src/models/scallopUtils.ts +12 -7
- package/src/queries/borrowIncentiveQuery.ts +4 -3
- package/src/queries/coreQuery.ts +114 -186
- package/src/queries/index.ts +3 -4
- package/src/queries/loyaltyProgramQuery.ts +2 -2
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/poolAddressesQuery.ts +1 -4
- package/src/queries/portfolioQuery.ts +68 -16
- package/src/queries/priceQuery.ts +2 -3
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +57 -74
- package/src/queries/vescaQuery.ts +3 -3
- package/src/queries/xOracleQuery.ts +4 -21
- package/src/types/address.ts +47 -98
- package/src/types/builder/core.ts +40 -15
- package/src/types/builder/index.ts +17 -1
- package/src/types/constant/enum.ts +64 -0
- package/src/types/constant/index.ts +1 -2
- package/src/types/constant/xOracle.ts +7 -10
- package/src/types/index.ts +1 -1
- package/src/types/query/core.ts +3 -0
- package/src/types/query/index.ts +1 -0
- package/src/types/query/sCoin.ts +1 -0
- package/src/{builders/utils.ts → utils/builder.ts} +1 -1
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/indexer.ts +47 -0
- package/src/{queries/utils.ts → utils/query.ts} +7 -25
- package/src/utils/util.ts +42 -0
- package/src/builders/oracles/error.ts +0 -18
- package/src/builders/oracles/oraclePackageRegistry.ts +0 -336
- package/src/builders/oracles/priceFeedUpdater.ts +0 -112
- package/src/builders/oracles/priceUpdateRequester.ts +0 -50
- package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -214
- package/src/builders/oracles/xOracleUpdater.ts +0 -153
- package/src/constants/api.ts +0 -2
- package/src/models/utils.ts +0 -97
- package/src/types/builder/type.ts +0 -25
- package/src/types/constant/package.ts +0 -16
- /package/src/types/{util.ts → utils.ts} +0 -0
|
@@ -1,83 +1,68 @@
|
|
|
1
1
|
import ScallopUtils, { ScallopUtilsParams } from './scallopUtils';
|
|
2
2
|
import ScallopIndexer, { ScallopIndexerParams } from './scallopIndexer';
|
|
3
|
-
import { withIndexerFallback } from '
|
|
3
|
+
import { withIndexerFallback } from 'src/utils';
|
|
4
4
|
import {
|
|
5
|
+
CoinPrices,
|
|
5
6
|
MarketCollaterals,
|
|
6
7
|
MarketPool,
|
|
7
8
|
MarketPools,
|
|
8
9
|
StakePools,
|
|
9
10
|
StakeRewardPools,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { ScallopQueryInterface } from './interface';
|
|
11
|
+
SupportOracleType,
|
|
12
|
+
xOracleRules,
|
|
13
|
+
} from 'src/types';
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
getAllCoinPrices,
|
|
16
|
+
getAssetOracles,
|
|
17
17
|
getBindedObligationId,
|
|
18
18
|
getBindedVeScaKey,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
queryMarket,
|
|
23
|
-
getMarketPools,
|
|
24
|
-
getMarketCollaterals,
|
|
25
|
-
getMarketCollateral,
|
|
26
|
-
getObligations,
|
|
27
|
-
queryObligation,
|
|
28
|
-
getCoinAmounts,
|
|
19
|
+
getBorrowIncentivePools,
|
|
20
|
+
getBorrowLimit,
|
|
29
21
|
getCoinAmount,
|
|
30
|
-
|
|
31
|
-
getMarketCoinAmount,
|
|
22
|
+
getCoinAmounts,
|
|
32
23
|
getFlashLoanFees,
|
|
33
|
-
} from 'src/queries/coreQuery';
|
|
34
|
-
import {
|
|
35
24
|
getIsolatedAssets,
|
|
36
|
-
isIsolatedAsset,
|
|
37
|
-
} from 'src/queries/isolatedAssetQuery';
|
|
38
|
-
import {
|
|
39
|
-
getLoyaltyProgramInformations,
|
|
40
|
-
getVeScaLoyaltyProgramInformations,
|
|
41
|
-
} from 'src/queries/loyaltyProgramQuery';
|
|
42
|
-
import { getPoolAddresses } from 'src/queries/poolAddressesQuery';
|
|
43
|
-
import {
|
|
44
|
-
getLendings,
|
|
45
25
|
getLending,
|
|
26
|
+
getLendings,
|
|
27
|
+
getLoyaltyProgramInformations,
|
|
28
|
+
getMarketCoinAmount,
|
|
29
|
+
getMarketCoinAmounts,
|
|
30
|
+
getMarketCollateral,
|
|
31
|
+
getMarketCollaterals,
|
|
32
|
+
getMarketPools,
|
|
33
|
+
getObligationAccount,
|
|
46
34
|
getObligationAccounts,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
getObligationAccountsByIds,
|
|
36
|
+
getObligations,
|
|
37
|
+
getOnDemandAggObjectIds,
|
|
38
|
+
getPoolAddresses,
|
|
39
|
+
getPriceUpdatePolicies,
|
|
51
40
|
getPythPrice,
|
|
52
41
|
getPythPrices,
|
|
53
|
-
getAllCoinPrices,
|
|
54
|
-
} from 'src/queries/priceQuery';
|
|
55
|
-
import { queryVeScaKeyIdFromReferralBindings } from 'src/queries/referralQuery';
|
|
56
|
-
import {
|
|
57
|
-
getSCoinTotalSupply,
|
|
58
|
-
getSCoinAmounts,
|
|
59
42
|
getSCoinAmount,
|
|
43
|
+
getSCoinAmounts,
|
|
60
44
|
getSCoinSwapRate,
|
|
61
|
-
|
|
62
|
-
import {
|
|
45
|
+
getSCoinTotalSupply,
|
|
63
46
|
getSpools,
|
|
64
47
|
getStakeAccounts,
|
|
65
48
|
getStakePool,
|
|
66
49
|
getStakeRewardPool,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
import {
|
|
50
|
+
getSupplyLimit,
|
|
51
|
+
getTotalValueLocked,
|
|
52
|
+
getUserPortfolio,
|
|
71
53
|
getVeSca,
|
|
54
|
+
getVeScaLoyaltyProgramInformations,
|
|
72
55
|
getVeScas,
|
|
73
56
|
getVeScaTreasuryInfo,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
import {
|
|
57
|
+
isIsolatedAsset,
|
|
58
|
+
queryBorrowIncentiveAccounts,
|
|
59
|
+
queryMarket,
|
|
60
|
+
queryObligation,
|
|
61
|
+
queryVeScaKeyIdFromReferralBindings,
|
|
62
|
+
} from 'src/queries';
|
|
63
|
+
import { SuiObjectRef, SuiObjectData } from '@mysten/sui/dist/cjs/client';
|
|
64
|
+
import { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
65
|
+
import { ScallopQueryInterface } from './interface';
|
|
81
66
|
|
|
82
67
|
export type ScallopQueryParams = {
|
|
83
68
|
indexer?: ScallopIndexer;
|
|
@@ -89,7 +74,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
89
74
|
public readonly indexer: ScallopIndexer;
|
|
90
75
|
public readonly utils: ScallopUtils;
|
|
91
76
|
|
|
92
|
-
constructor(params: ScallopQueryParams) {
|
|
77
|
+
constructor(params: ScallopQueryParams = {}) {
|
|
93
78
|
this.utils = params.utils ?? new ScallopUtils(params);
|
|
94
79
|
this.indexer =
|
|
95
80
|
params.indexer ??
|
|
@@ -125,6 +110,14 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
125
110
|
this,
|
|
126
111
|
this.getObligationAccounts
|
|
127
112
|
);
|
|
113
|
+
this.getObligationAccountsByIds = withIndexerFallback.call(
|
|
114
|
+
this,
|
|
115
|
+
this.getObligationAccountsByIds
|
|
116
|
+
);
|
|
117
|
+
this.getObligationAccountById = withIndexerFallback.call(
|
|
118
|
+
this,
|
|
119
|
+
this.getObligationAccountById
|
|
120
|
+
);
|
|
128
121
|
this.getObligationAccount = withIndexerFallback.call(
|
|
129
122
|
this,
|
|
130
123
|
this.getObligationAccount
|
|
@@ -575,13 +568,13 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
575
568
|
}
|
|
576
569
|
|
|
577
570
|
/**
|
|
578
|
-
* Get user all obligation accounts information.
|
|
571
|
+
* Get user all obligation accounts information from ownerAddress.
|
|
579
572
|
*
|
|
580
573
|
* @description
|
|
581
574
|
* All collateral and borrowing information in all obligation accounts owned by the user.
|
|
582
575
|
*
|
|
583
576
|
* @param ownerAddress - The owner address.
|
|
584
|
-
* @param
|
|
577
|
+
* @param args - Additional arguments.
|
|
585
578
|
* @return All obligation accounts information.
|
|
586
579
|
*/
|
|
587
580
|
async getObligationAccounts(
|
|
@@ -604,6 +597,68 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
604
597
|
);
|
|
605
598
|
}
|
|
606
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Get user all obligation accounts information from obligationIds.
|
|
602
|
+
*
|
|
603
|
+
* @description
|
|
604
|
+
* All collateral and borrowing information in all obligation accounts.
|
|
605
|
+
*
|
|
606
|
+
* @param obligationIds - Obligation IDs.
|
|
607
|
+
* @param args - Additional arguments.
|
|
608
|
+
* @return All obligation accounts information.
|
|
609
|
+
*/
|
|
610
|
+
async getObligationAccountsByIds(
|
|
611
|
+
obligationIds: string[],
|
|
612
|
+
args?: {
|
|
613
|
+
market?: {
|
|
614
|
+
collaterals: MarketCollaterals;
|
|
615
|
+
pools: MarketPools;
|
|
616
|
+
};
|
|
617
|
+
coinPrices?: CoinPrices;
|
|
618
|
+
indexer?: boolean;
|
|
619
|
+
}
|
|
620
|
+
) {
|
|
621
|
+
return await getObligationAccountsByIds(
|
|
622
|
+
this,
|
|
623
|
+
obligationIds,
|
|
624
|
+
args?.market,
|
|
625
|
+
args?.coinPrices,
|
|
626
|
+
args?.indexer
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Get obligation account by id
|
|
632
|
+
*
|
|
633
|
+
* @description
|
|
634
|
+
* All collateral and borrowing information in obligation account.
|
|
635
|
+
*
|
|
636
|
+
* @param obligationId - Obligation ID.
|
|
637
|
+
* @param args - Additional arguments.
|
|
638
|
+
* @return All obligation accounts information.
|
|
639
|
+
*/
|
|
640
|
+
async getObligationAccountById(
|
|
641
|
+
obligationId: string,
|
|
642
|
+
args?: {
|
|
643
|
+
market?: {
|
|
644
|
+
collaterals: MarketCollaterals;
|
|
645
|
+
pools: MarketPools;
|
|
646
|
+
};
|
|
647
|
+
coinPrices?: CoinPrices;
|
|
648
|
+
indexer?: boolean;
|
|
649
|
+
}
|
|
650
|
+
) {
|
|
651
|
+
return await getObligationAccount(
|
|
652
|
+
this,
|
|
653
|
+
obligationId,
|
|
654
|
+
'',
|
|
655
|
+
args?.indexer,
|
|
656
|
+
args?.market,
|
|
657
|
+
args?.coinPrices,
|
|
658
|
+
{}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
|
|
607
662
|
/**
|
|
608
663
|
* Get obligation account information for specific id.
|
|
609
664
|
*
|
|
@@ -612,7 +667,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
612
667
|
*
|
|
613
668
|
* @param obligationId - The obligation id.
|
|
614
669
|
* @param ownerAddress - The owner address.
|
|
615
|
-
* @param
|
|
670
|
+
* @param args - Additional arguments.
|
|
616
671
|
* @return Borrowing and collateral information.
|
|
617
672
|
*/
|
|
618
673
|
async getObligationAccount(
|
|
@@ -868,6 +923,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
868
923
|
|
|
869
924
|
/**
|
|
870
925
|
* Return the supported primary and secondary oracles for all supported pool assets
|
|
926
|
+
* @returns
|
|
871
927
|
*/
|
|
872
928
|
async getAssetOracles() {
|
|
873
929
|
const [primary, secondary] = await Promise.all([
|
|
@@ -7,16 +7,18 @@ import {
|
|
|
7
7
|
Transaction,
|
|
8
8
|
} from '@scallop-io/sui-kit';
|
|
9
9
|
import ScallopConstants, { ScallopConstantsParams } from './scallopConstants';
|
|
10
|
-
import {
|
|
10
|
+
import { CoinPrices, CoinWrappedType, PoolAddress } from 'src/types';
|
|
11
|
+
import { findClosestUnlockRound } from 'src/utils';
|
|
12
|
+
import {
|
|
13
|
+
MAX_LOCK_DURATION,
|
|
14
|
+
queryKeys,
|
|
15
|
+
UNLOCK_ROUND_DURATION,
|
|
16
|
+
} from 'src/constants';
|
|
11
17
|
import { PriceFeed, SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
12
18
|
import ScallopSuiKit, { ScallopSuiKitParams } from './scallopSuiKit';
|
|
13
19
|
import { SuiObjectData } from '@mysten/sui/dist/cjs/client';
|
|
14
|
-
import { queryObligation } from 'src/queries
|
|
20
|
+
import { queryObligation } from 'src/queries';
|
|
15
21
|
import { ScallopUtilsInterface } from './interface';
|
|
16
|
-
import { MAX_LOCK_DURATION, UNLOCK_ROUND_DURATION } from 'src/constants/vesca';
|
|
17
|
-
import { queryKeys } from 'src/constants/queryKeys';
|
|
18
|
-
import { CoinWrappedType, PoolAddress } from 'src/types/constant';
|
|
19
|
-
import { CoinPrices } from 'src/types/util';
|
|
20
22
|
|
|
21
23
|
export type ScallopUtilsParams = {
|
|
22
24
|
pythEndpoints?: string[];
|
|
@@ -29,6 +31,7 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
29
31
|
public pythEndpoints: string[];
|
|
30
32
|
public readonly scallopSuiKit: ScallopSuiKit;
|
|
31
33
|
public readonly constants: ScallopConstants;
|
|
34
|
+
public readonly timeout: number;
|
|
32
35
|
|
|
33
36
|
constructor(params: ScallopUtilsParams = {}) {
|
|
34
37
|
this.constants = params.scallopConstants ?? new ScallopConstants(params);
|
|
@@ -42,6 +45,8 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
42
45
|
this.pythEndpoints = params.pythEndpoints ?? [
|
|
43
46
|
'https://hermes.pyth.network',
|
|
44
47
|
];
|
|
48
|
+
|
|
49
|
+
this.timeout = params.axiosTimeout ?? 4000;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
get walletAddress() {
|
|
@@ -536,7 +541,7 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
536
541
|
|
|
537
542
|
const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
|
|
538
543
|
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
539
|
-
timeout:
|
|
544
|
+
timeout: this.timeout,
|
|
540
545
|
});
|
|
541
546
|
|
|
542
547
|
try {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
parseOriginBorrowIncentivePoolData,
|
|
4
4
|
parseOriginBorrowIncentiveAccountData,
|
|
5
5
|
calculateBorrowIncentivePoolPointData,
|
|
6
|
-
} from '
|
|
6
|
+
} from 'src/utils';
|
|
7
7
|
import type {
|
|
8
8
|
ScallopAddress,
|
|
9
9
|
ScallopQuery,
|
|
@@ -16,11 +16,12 @@ import type {
|
|
|
16
16
|
BorrowIncentiveAccountsQueryInterface,
|
|
17
17
|
BorrowIncentiveAccounts,
|
|
18
18
|
BorrowIncentivePoolPoints,
|
|
19
|
+
OptionalKeys,
|
|
20
|
+
CoinPrices,
|
|
19
21
|
MarketPools,
|
|
20
|
-
} from 'src/types
|
|
22
|
+
} from 'src/types';
|
|
21
23
|
import BigNumber from 'bignumber.js';
|
|
22
24
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
23
|
-
import { CoinPrices, OptionalKeys } from 'src/types/util';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Query borrow incentive pools data using moveCall
|