@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.4 → 2.3.0-lst-x-oracle-alpha.6
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 +2869 -11
- package/dist/index.d.ts +2869 -11
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -1
- package/package.json +6 -35
- package/src/builders/borrowIncentiveBuilder.ts +2 -2
- package/src/builders/coreBuilder.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +2 -2
- package/src/builders/oracles/index.ts +1 -1
- package/src/builders/oracles/oraclePackageRegistry.ts +2 -3
- package/src/builders/oracles/priceFeedUpdater.ts +1 -1
- package/src/builders/oracles/xOracleUpdateStrategy.ts +1 -1
- package/src/builders/oracles/xOracleUpdater.ts +1 -1
- package/src/builders/referralBuilder.ts +2 -2
- package/src/builders/sCoinBuilder.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/constants/testAddress.ts +2 -2
- package/src/index.ts +12 -3
- package/src/models/scallop.ts +1 -1
- package/src/models/scallopAddress.ts +1 -1
- package/src/models/scallopBuilder.ts +1 -1
- package/src/models/scallopClient.ts +1 -1
- package/src/models/scallopConstants.ts +1 -1
- package/src/models/scallopQuery.ts +2 -2
- package/src/models/scallopUtils.ts +2 -2
- package/src/models/utils.ts +97 -0
- package/src/queries/borrowIncentiveQuery.ts +2 -2
- package/src/queries/coreQuery.ts +2 -2
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/poolAddressesQuery.ts +3 -1
- package/src/queries/portfolioQuery.ts +2 -2
- package/src/queries/priceQuery.ts +3 -2
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +5 -5
- package/src/{utils/query.ts → queries/utils.ts} +19 -1
- package/src/queries/vescaQuery.ts +1 -1
- package/src/queries/xOracleQuery.ts +1 -1
- package/src/types/builder/index.ts +1 -26
- package/src/types/builder/type.ts +25 -0
- package/src/types/constant/package.ts +15 -2
- package/dist/address-CW2IpaLn.d.ts +0 -165
- package/dist/chunk-E3URAUAC.js +0 -25
- package/dist/chunk-YA77R5GT.mjs +0 -5
- package/dist/constants/index.d.mts +0 -262
- package/dist/constants/index.d.ts +0 -262
- package/dist/constants/index.js +0 -86
- package/dist/constants/index.mjs +0 -5
- package/dist/models/index.d.mts +0 -393
- package/dist/models/index.d.ts +0 -393
- package/dist/models/index.js +0 -34
- package/dist/models/index.mjs +0 -16
- package/dist/queryKeys-AaZqDYle.d.ts +0 -43
- package/dist/scallopUtils-BZLZd2z8.d.ts +0 -2404
- package/dist/types/index.d.mts +0 -9
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.js +0 -2
- package/dist/types/index.mjs +0 -1
- package/src/constants/package.ts +0 -14
- package/src/types/index.ts +0 -5
- package/src/utils/core.ts +0 -18
- package/src/utils/index.ts +0 -5
- package/src/utils/indexer.ts +0 -47
- package/src/utils/util.ts +0 -42
- /package/src/{utils/builder.ts → builders/utils.ts} +0 -0
- /package/src/types/{utils.ts → util.ts} +0 -0
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
ScallopTxBlock,
|
|
9
9
|
SuiTxBlockWithSCoinNormalMethods,
|
|
10
10
|
sCoinPkgIds,
|
|
11
|
-
} from 'src/types';
|
|
12
|
-
import { requireSender } from '
|
|
11
|
+
} from 'src/types/builder';
|
|
12
|
+
import { requireSender } from './utils';
|
|
13
13
|
|
|
14
14
|
const generateSCoinNormalMethod: GenerateSCoinNormalMethod = ({
|
|
15
15
|
builder,
|
|
@@ -2,7 +2,7 @@ import { Transaction } from '@mysten/sui/transactions';
|
|
|
2
2
|
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
3
3
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
4
|
import { getStakeAccounts } from '../queries/spoolQuery';
|
|
5
|
-
import { requireSender } from '
|
|
5
|
+
import { requireSender } from './utils';
|
|
6
6
|
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
7
7
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
8
8
|
import type { ScallopBuilder } from 'src/models';
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
SpoolTxBlock,
|
|
15
15
|
ScallopTxBlock,
|
|
16
16
|
SuiTxBlockWithSCoin,
|
|
17
|
-
} from 'src/types';
|
|
17
|
+
} from 'src/types/builder';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Check and get stake account id from transaction block.
|
|
@@ -14,21 +14,21 @@ import {
|
|
|
14
14
|
checkExtendLockAmount,
|
|
15
15
|
checkRenewExpiredVeSca,
|
|
16
16
|
checkVesca,
|
|
17
|
-
} from '
|
|
17
|
+
} from './utils';
|
|
18
18
|
import type {
|
|
19
19
|
TransactionObjectArgument,
|
|
20
20
|
SuiObjectArg,
|
|
21
21
|
} from '@scallop-io/sui-kit';
|
|
22
22
|
import type {
|
|
23
|
-
AddressesInterface,
|
|
24
23
|
GenerateVeScaNormalMethod,
|
|
25
24
|
GenerateVeScaQuickMethod,
|
|
26
25
|
QuickMethodReturnType,
|
|
27
26
|
ScallopTxBlock,
|
|
28
27
|
SuiTxBlockWithVeScaNormalMethods,
|
|
29
28
|
VeScaTxBlock,
|
|
30
|
-
} from 'src/types';
|
|
29
|
+
} from 'src/types/builder';
|
|
31
30
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
31
|
+
import { AddressesInterface } from 'src/types/address';
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Check and get veSCA data from transaction block.
|
package/src/constants/index.ts
CHANGED
|
@@ -449,7 +449,7 @@ export const TEST_ADDRESSES: AddressesInterface = {
|
|
|
449
449
|
},
|
|
450
450
|
};
|
|
451
451
|
|
|
452
|
-
export const
|
|
452
|
+
export const TEST_WHITELIST = {
|
|
453
453
|
lending: new Set([
|
|
454
454
|
'usdc',
|
|
455
455
|
// 'sbeth',
|
|
@@ -584,7 +584,7 @@ export const WHITELIST = {
|
|
|
584
584
|
emerging: new Set(['wal', 'deep', 'sca', 'cetus']),
|
|
585
585
|
};
|
|
586
586
|
|
|
587
|
-
export const
|
|
587
|
+
export const TEST_POOL_ADDRESSES = {
|
|
588
588
|
usdc: {
|
|
589
589
|
coinName: 'usdc',
|
|
590
590
|
symbol: 'USDC',
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export {
|
|
3
|
+
Scallop,
|
|
4
|
+
ScallopConstants,
|
|
5
|
+
ScallopAddress,
|
|
6
|
+
ScallopBuilder,
|
|
7
|
+
ScallopQuery,
|
|
8
|
+
ScallopSuiKit,
|
|
9
|
+
ScallopClient,
|
|
10
|
+
ScallopIndexer,
|
|
11
|
+
ScallopUtils,
|
|
12
|
+
} from './models';
|
package/src/models/scallop.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { AddressesInterface, AddressStringPath } from 'src/types/address';
|
|
|
5
5
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
6
6
|
import { QueryKey } from '@tanstack/query-core';
|
|
7
7
|
import { AxiosRequestConfig } from 'axios';
|
|
8
|
-
import { parseUrl } from '
|
|
8
|
+
import { parseUrl } from './utils';
|
|
9
9
|
|
|
10
10
|
export type ScallopAddressParams = {
|
|
11
11
|
addressId?: string;
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
SuiTxArg,
|
|
13
13
|
SuiVecTxArg,
|
|
14
14
|
} from '@scallop-io/sui-kit';
|
|
15
|
-
import type { ScallopTxBlock, SelectCoinReturnType } from 'src/types';
|
|
15
|
+
import type { ScallopTxBlock, SelectCoinReturnType } from 'src/types/builder';
|
|
16
16
|
import { ScallopBuilderInterface } from './interface';
|
|
17
17
|
|
|
18
18
|
export type ScallopBuilderParams = {
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
TransactionObjectArgument,
|
|
6
6
|
TransactionResult,
|
|
7
7
|
} from '@mysten/sui/transactions';
|
|
8
|
-
import { requireSender } from '
|
|
8
|
+
import { requireSender } from './utils';
|
|
9
9
|
import type { NetworkType, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
10
10
|
import { ScallopClientInterface } from './interface';
|
|
11
11
|
import { ScallopTxBlock } from 'src/types/builder';
|
|
@@ -2,7 +2,7 @@ import { PoolAddress, Whitelist } from 'src/types/constant';
|
|
|
2
2
|
import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
|
|
3
3
|
import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
|
|
4
4
|
import { queryKeys } from 'src/constants/queryKeys';
|
|
5
|
-
import { parseUrl } from '
|
|
5
|
+
import { parseUrl } from './utils';
|
|
6
6
|
|
|
7
7
|
const isEmptyObject = (obj: object) => {
|
|
8
8
|
return Object.keys(obj).length === 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ScallopUtils, { ScallopUtilsParams } from './scallopUtils';
|
|
2
2
|
import ScallopIndexer, { ScallopIndexerParams } from './scallopIndexer';
|
|
3
|
-
import { withIndexerFallback } from '
|
|
3
|
+
import { withIndexerFallback } from './utils';
|
|
4
4
|
import {
|
|
5
5
|
MarketCollaterals,
|
|
6
6
|
MarketPool,
|
|
@@ -76,7 +76,7 @@ import {
|
|
|
76
76
|
getPriceUpdatePolicies,
|
|
77
77
|
getAssetOracles,
|
|
78
78
|
} from 'src/queries/xOracleQuery';
|
|
79
|
-
import { CoinPrices } from 'src/types/
|
|
79
|
+
import { CoinPrices } from 'src/types/util';
|
|
80
80
|
import { SupportOracleType, xOracleRules } from 'src/types/constant';
|
|
81
81
|
|
|
82
82
|
export type ScallopQueryParams = {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
Transaction,
|
|
8
8
|
} from '@scallop-io/sui-kit';
|
|
9
9
|
import ScallopConstants, { ScallopConstantsParams } from './scallopConstants';
|
|
10
|
-
import { findClosestUnlockRound } from '
|
|
10
|
+
import { findClosestUnlockRound } from './utils';
|
|
11
11
|
import { PriceFeed, SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
12
12
|
import ScallopSuiKit, { ScallopSuiKitParams } from './scallopSuiKit';
|
|
13
13
|
import { SuiObjectData } from '@mysten/sui/dist/cjs/client';
|
|
@@ -16,7 +16,7 @@ import { ScallopUtilsInterface } from './interface';
|
|
|
16
16
|
import { MAX_LOCK_DURATION, UNLOCK_ROUND_DURATION } from 'src/constants/vesca';
|
|
17
17
|
import { queryKeys } from 'src/constants/queryKeys';
|
|
18
18
|
import { CoinWrappedType, PoolAddress } from 'src/types/constant';
|
|
19
|
-
import { CoinPrices } from 'src/types/
|
|
19
|
+
import { CoinPrices } from 'src/types/util';
|
|
20
20
|
|
|
21
21
|
export type ScallopUtilsParams = {
|
|
22
22
|
pythEndpoints?: string[];
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic wrapper for methods with indexer fallback.
|
|
3
|
+
*
|
|
4
|
+
* @param method - The method to call with fallback behavior.
|
|
5
|
+
* @param context - The context (`this`) of the class instance.
|
|
6
|
+
* @param args - The arguments to pass to the method.
|
|
7
|
+
* @returns The result of the method call.
|
|
8
|
+
*/
|
|
9
|
+
export async function callMethodWithIndexerFallback(
|
|
10
|
+
method: Function,
|
|
11
|
+
context: any,
|
|
12
|
+
...args: any[]
|
|
13
|
+
) {
|
|
14
|
+
const lastArgs = args[args.length - 1]; // Assume last argument is always `indexer`
|
|
15
|
+
|
|
16
|
+
if (typeof lastArgs === 'object' && lastArgs.indexer) {
|
|
17
|
+
try {
|
|
18
|
+
return await method.apply(context, args);
|
|
19
|
+
} catch (e: any) {
|
|
20
|
+
console.warn(
|
|
21
|
+
`Indexer requests failed: ${e.message}. Retrying without indexer..`
|
|
22
|
+
);
|
|
23
|
+
return await method.apply(context, [
|
|
24
|
+
...args.slice(0, -1),
|
|
25
|
+
{
|
|
26
|
+
...lastArgs,
|
|
27
|
+
indexer: false,
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return await method.apply(context, args);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This function creates a wrapper for methods that have an indexer parameter.
|
|
37
|
+
* It ensures fallback behavior if indexer fails.
|
|
38
|
+
*
|
|
39
|
+
* @param method - The method to wrap.
|
|
40
|
+
* @returns A function that applies indexer fallback.
|
|
41
|
+
*/
|
|
42
|
+
export function withIndexerFallback(method: Function) {
|
|
43
|
+
return (...args: any[]) => {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return callMethodWithIndexerFallback(method, this, ...args); // Preserve `this` with arrow function
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
import { SuiTxBlock } from '@scallop-io/sui-kit';
|
|
50
|
+
import { MAX_LOCK_DURATION } from 'src/constants/vesca';
|
|
51
|
+
// import { ScallopConstants } from 'src/models/scallopConstants';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Find the closest unlock round timestamp (12AM) to the given unlock at timestamp in seconds.
|
|
55
|
+
*
|
|
56
|
+
* @param unlockAtInSecondTimestamp - Unlock at in seconds timestamp to find the closest round.
|
|
57
|
+
* @returns Closest round (12AM) in seconds timestamp.
|
|
58
|
+
*/
|
|
59
|
+
export const findClosestUnlockRound = (unlockAtInSecondTimestamp: number) => {
|
|
60
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1000);
|
|
61
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1000);
|
|
62
|
+
|
|
63
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0); // Set the time to the next 12 AM UTC
|
|
64
|
+
|
|
65
|
+
// If the current time is past 12 AM, set the date to the next day
|
|
66
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
67
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const now = new Date().getTime();
|
|
71
|
+
// check if unlock period > 4 years
|
|
72
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1000) {
|
|
73
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
74
|
+
}
|
|
75
|
+
return Math.floor(closestTwelveAM.getTime() / 1000);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const parseUrl = (url: string) => {
|
|
79
|
+
if (url.endsWith('/')) {
|
|
80
|
+
url = url.slice(0, -1);
|
|
81
|
+
}
|
|
82
|
+
return url;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Check and get the sender from the transaction block.
|
|
87
|
+
*
|
|
88
|
+
* @param txBlock - TxBlock created by SuiKit.
|
|
89
|
+
* @return Sender of transaction.
|
|
90
|
+
*/
|
|
91
|
+
export const requireSender = (txBlock: SuiTxBlock) => {
|
|
92
|
+
const sender = txBlock.blockData.sender;
|
|
93
|
+
if (!sender) {
|
|
94
|
+
throw new Error('Sender is required');
|
|
95
|
+
}
|
|
96
|
+
return sender;
|
|
97
|
+
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
parseOriginBorrowIncentivePoolData,
|
|
4
4
|
parseOriginBorrowIncentiveAccountData,
|
|
5
5
|
calculateBorrowIncentivePoolPointData,
|
|
6
|
-
} from '
|
|
6
|
+
} from './utils';
|
|
7
7
|
import type {
|
|
8
8
|
ScallopAddress,
|
|
9
9
|
ScallopQuery,
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
} from 'src/types/query';
|
|
21
21
|
import BigNumber from 'bignumber.js';
|
|
22
22
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
23
|
-
import { CoinPrices, OptionalKeys } from 'src/types/
|
|
23
|
+
import { CoinPrices, OptionalKeys } from 'src/types/util';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Query borrow incentive pools data using moveCall
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
parseOriginMarketCollateralData,
|
|
6
6
|
calculateMarketCollateralData,
|
|
7
7
|
parseObjectAs,
|
|
8
|
-
} from '
|
|
8
|
+
} from './utils';
|
|
9
9
|
import type {
|
|
10
10
|
SuiObjectResponse,
|
|
11
11
|
SuiObjectData,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
ScallopIndexer,
|
|
44
44
|
ScallopAddress,
|
|
45
45
|
} from 'src/models';
|
|
46
|
-
import { CoinPrices, OptionalKeys } from 'src/types';
|
|
46
|
+
import { CoinPrices, OptionalKeys } from 'src/types/util';
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Query market data.
|
|
@@ -2,7 +2,7 @@ import { SuiObjectData } from '@mysten/sui/client';
|
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
3
|
import { MAX_LOCK_DURATION } from 'src/constants/vesca';
|
|
4
4
|
import { ScallopQuery } from 'src/models';
|
|
5
|
-
import { LoyaltyProgramInfo, VeScaLoyaltyProgramInfo } from 'src/types';
|
|
5
|
+
import { LoyaltyProgramInfo, VeScaLoyaltyProgramInfo } from 'src/types/query';
|
|
6
6
|
import { z as zod } from 'zod';
|
|
7
7
|
|
|
8
8
|
const rewardPoolFieldsZod = zod
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getFullnodeUrl, SuiClient, SuiParsedData } from '@mysten/sui/client';
|
|
2
|
-
import { AddressesInterface
|
|
2
|
+
import { AddressesInterface } from 'src/types/address';
|
|
3
|
+
import { PoolAddress } from 'src/types/constant';
|
|
4
|
+
import { OptionalKeys } from 'src/types/util';
|
|
3
5
|
|
|
4
6
|
const RPC_PROVIDERS = [
|
|
5
7
|
getFullnodeUrl('mainnet'),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { minBigNumber, estimatedFactor } from '
|
|
2
|
+
import { minBigNumber, estimatedFactor } from './utils';
|
|
3
3
|
import type { ScallopQuery } from 'src/models';
|
|
4
4
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
5
5
|
import { normalizeStructTag, SUI_TYPE_ARG } from '@scallop-io/sui-kit';
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
StakeAccount,
|
|
19
19
|
TotalValueLocked,
|
|
20
20
|
} from 'src/types/query';
|
|
21
|
-
import { CoinPrices } from 'src/types/
|
|
21
|
+
import { CoinPrices } from 'src/types/util';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Get user lending infomation for specific pools.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
2
|
import type { ScallopAddress, ScallopQuery, ScallopSuiKit } from 'src/models';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MarketPools } from 'src/types/query';
|
|
4
|
+
import type { CoinPrices } from 'src/types/util';
|
|
4
5
|
import BigNumber from 'bignumber.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -150,7 +151,7 @@ export const getAllCoinPrices = async (
|
|
|
150
151
|
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
const sCoinPrices:
|
|
154
|
+
const sCoinPrices: CoinPrices = {};
|
|
154
155
|
query.constants.whitelist.scoin.forEach((sCoinName) => {
|
|
155
156
|
const coinName = query.utils.parseCoinName(sCoinName);
|
|
156
157
|
sCoinPrices[sCoinName] = BigNumber(coinPrices[coinName] ?? 0)
|
|
@@ -2,7 +2,7 @@ import { bcs } from '@mysten/sui/bcs';
|
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { ScallopQuery, ScallopUtils } from 'src/models';
|
|
5
|
-
import { OptionalKeys } from 'src/types';
|
|
5
|
+
import { OptionalKeys } from 'src/types/util';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get total supply of sCoin
|
|
@@ -5,10 +5,9 @@ import {
|
|
|
5
5
|
parseOriginSpoolRewardPoolData,
|
|
6
6
|
calculateSpoolRewardPoolData,
|
|
7
7
|
parseObjectAs,
|
|
8
|
-
} from '
|
|
8
|
+
} from './utils';
|
|
9
9
|
import type { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';
|
|
10
10
|
import type { ScallopQuery, ScallopUtils } from 'src/models';
|
|
11
|
-
import { CoinPrices } from 'src/types';
|
|
12
11
|
import {
|
|
13
12
|
OriginSpoolData,
|
|
14
13
|
OriginSpoolRewardPoolData,
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
StakePool,
|
|
21
20
|
StakeRewardPool,
|
|
22
21
|
} from 'src/types/query';
|
|
22
|
+
import { CoinPrices } from 'src/types/util';
|
|
23
23
|
|
|
24
24
|
const queryRequiredSpoolObjects = async (
|
|
25
25
|
query: ScallopQuery,
|
|
@@ -164,11 +164,11 @@ export const getSpools = async (
|
|
|
164
164
|
if (!stakeMarketCoinNames.includes(spool.marketCoinName)) return;
|
|
165
165
|
const coinName = query.utils.parseCoinName(spool.marketCoinName);
|
|
166
166
|
const rewardCoinName = query.utils.getSpoolRewardCoinName();
|
|
167
|
-
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
167
|
+
spool.coinPrice = coinPrices?.[coinName] ?? spool.coinPrice;
|
|
168
168
|
spool.marketCoinPrice =
|
|
169
|
-
coinPrices[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
169
|
+
coinPrices?.[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
170
170
|
spool.rewardCoinPrice =
|
|
171
|
-
coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
171
|
+
coinPrices?.[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
172
172
|
spools[spool.marketCoinName] = spool;
|
|
173
173
|
};
|
|
174
174
|
Object.values(spoolsIndexer)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
3
|
-
import type { ScallopUtils } from '
|
|
3
|
+
import type { ScallopUtils } from 'src/models';
|
|
4
4
|
import {
|
|
5
5
|
OriginMarketPoolData,
|
|
6
6
|
ParsedMarketPoolData,
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
OriginBorrowIncentiveAccountData,
|
|
25
25
|
ParsedBorrowIncentiveAccountData,
|
|
26
26
|
} from 'src/types/query';
|
|
27
|
+
import { SuiObjectData } from '@mysten/sui/client';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Parse origin market pool data to a more readable format.
|
|
@@ -642,3 +643,20 @@ export const estimatedFactor = (
|
|
|
642
643
|
|
|
643
644
|
return adjustFactor;
|
|
644
645
|
};
|
|
646
|
+
|
|
647
|
+
export const parseObjectAs = <T>(object: SuiObjectData): T => {
|
|
648
|
+
if (!(object && object.content && 'fields' in object.content))
|
|
649
|
+
throw new Error(`Failed to parse object ${object}`);
|
|
650
|
+
|
|
651
|
+
const fields = object.content.fields as any;
|
|
652
|
+
|
|
653
|
+
if (typeof fields === 'object' && 'value' in fields) {
|
|
654
|
+
const value = fields.value;
|
|
655
|
+
if (typeof value === 'object' && 'fields' in value)
|
|
656
|
+
return value.fields as T;
|
|
657
|
+
return value as T;
|
|
658
|
+
} else if (typeof fields === 'object') {
|
|
659
|
+
return fields as T;
|
|
660
|
+
}
|
|
661
|
+
return fields as T;
|
|
662
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
2
2
|
import { ScallopAddress, ScallopSuiKit, ScallopUtils } from 'src/models';
|
|
3
|
-
import { SupportOracleType, xOracleRuleType } from 'src/types';
|
|
3
|
+
import { SupportOracleType, xOracleRuleType } from 'src/types/constant';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Query the price update policy table ids. Usually the value for these table will be constant.
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
import type { CoreTxBlock, NestedResult } from './core';
|
|
2
|
-
import type { SpoolTxBlock } from './spool';
|
|
3
|
-
import type { BorrowIncentiveTxBlock } from './borrowIncentive';
|
|
4
|
-
import type { VeScaTxBlock } from './vesca';
|
|
5
|
-
import type { ReferralTxBlock } from './referral';
|
|
6
|
-
import { LoyaltyProgramTxBlock } from './loyaltyProgram';
|
|
7
|
-
import { SCoinTxBlock } from './sCoin';
|
|
8
|
-
|
|
9
1
|
export type * from './core';
|
|
10
2
|
export type * from './spool';
|
|
11
3
|
export type * from './borrowIncentive';
|
|
12
4
|
export type * from './vesca';
|
|
13
5
|
export type * from './loyaltyProgram';
|
|
14
6
|
export type * from './sCoin';
|
|
15
|
-
|
|
16
|
-
export type BaseScallopTxBlock = ReferralTxBlock &
|
|
17
|
-
LoyaltyProgramTxBlock &
|
|
18
|
-
BorrowIncentiveTxBlock &
|
|
19
|
-
VeScaTxBlock;
|
|
20
|
-
|
|
21
|
-
export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
|
|
22
|
-
export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
|
|
23
|
-
export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
|
|
24
|
-
|
|
25
|
-
export type SelectCoinReturnType<T extends string> = T extends 'sui'
|
|
26
|
-
? {
|
|
27
|
-
takeCoin: NestedResult;
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
takeCoin: NestedResult;
|
|
31
|
-
leftCoin: NestedResult;
|
|
32
|
-
};
|
|
7
|
+
export type * from './type';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CoreTxBlock, NestedResult } from './core';
|
|
2
|
+
import type { SpoolTxBlock } from './spool';
|
|
3
|
+
import type { BorrowIncentiveTxBlock } from './borrowIncentive';
|
|
4
|
+
import type { VeScaTxBlock } from './vesca';
|
|
5
|
+
import type { ReferralTxBlock } from './referral';
|
|
6
|
+
import type { LoyaltyProgramTxBlock } from './loyaltyProgram';
|
|
7
|
+
import type { SCoinTxBlock } from './sCoin';
|
|
8
|
+
|
|
9
|
+
export type BaseScallopTxBlock = ReferralTxBlock &
|
|
10
|
+
LoyaltyProgramTxBlock &
|
|
11
|
+
BorrowIncentiveTxBlock &
|
|
12
|
+
VeScaTxBlock;
|
|
13
|
+
|
|
14
|
+
export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
|
|
15
|
+
export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
|
|
16
|
+
export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
|
|
17
|
+
|
|
18
|
+
export type SelectCoinReturnType<T extends string> = T extends 'sui'
|
|
19
|
+
? {
|
|
20
|
+
takeCoin: NestedResult;
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
takeCoin: NestedResult;
|
|
24
|
+
leftCoin: NestedResult;
|
|
25
|
+
};
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const _PACKAGE_NAMES = [
|
|
2
|
+
'coinDecimalsRegistry',
|
|
3
|
+
'math',
|
|
4
|
+
'whitelist',
|
|
5
|
+
'x',
|
|
6
|
+
'protocol',
|
|
7
|
+
'protocolWhitelist',
|
|
8
|
+
'query',
|
|
9
|
+
'supra',
|
|
10
|
+
'pyth',
|
|
11
|
+
'switchboard',
|
|
12
|
+
'xOracle',
|
|
13
|
+
'testCoin',
|
|
14
|
+
] as const;
|
|
2
15
|
|
|
3
|
-
export type PackageName = (typeof
|
|
16
|
+
export type PackageName = (typeof _PACKAGE_NAMES)[number];
|