@scallop-io/sui-scallop-sdk 3.0.2 → 4.1.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/Logger-Cg2iFdpH.d.ts +8 -0
- package/dist/builder.cjs +22 -0
- package/dist/builder.d.cts +28 -0
- package/dist/builder.d.ts +28 -0
- package/dist/builder.js +4 -0
- package/dist/chunk-33AK5RWM.js +15 -0
- package/dist/chunk-6UQ4NWEU.js +3 -0
- package/dist/chunk-DIC6P5HB.js +11 -0
- package/dist/chunk-S34VOEZN.js +3 -0
- package/dist/chunk-VTGQACWU.js +6 -0
- package/dist/client.cjs +21 -0
- package/dist/client.d.cts +401 -0
- package/dist/client.d.ts +401 -0
- package/dist/client.js +5 -0
- package/dist/errors.cjs +10 -0
- package/dist/errors.d.cts +32 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +1 -0
- package/dist/index.cjs +51 -34
- package/dist/index.d.cts +130 -3145
- package/dist/index.d.ts +130 -3145
- package/dist/index.js +8 -12
- package/dist/logger.cjs +6 -0
- package/dist/logger.d.cts +7 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +1 -0
- package/dist/query-DkitepDi.d.ts +3305 -0
- package/dist/query.cjs +19 -0
- package/dist/query.d.cts +9 -0
- package/dist/query.d.ts +9 -0
- package/dist/query.js +3 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +90 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +1 -0
- package/package.json +98 -56
- package/src/constants/api.ts +2 -0
- package/src/constants/coinType.ts +2 -0
- package/src/constants/common.ts +0 -7
- package/src/constants/index.ts +2 -0
- package/src/constants/queryKeys.ts +14 -7
- package/src/constants/testAddress.ts +1 -0
- package/src/datasources/api.ts +34 -0
- package/src/datasources/indexer.ts +8 -0
- package/src/datasources/onchain.ts +121 -0
- package/src/entries/builder.ts +5 -0
- package/src/entries/client.ts +3 -0
- package/src/entries/errors.ts +2 -0
- package/src/entries/index.ts +17 -0
- package/src/entries/logger.ts +2 -0
- package/src/entries/query.ts +6 -0
- package/src/entries/types.ts +2 -0
- package/src/errors/ScallopConfigError.ts +8 -0
- package/src/errors/ScallopError.ts +30 -0
- package/src/errors/ScallopIndexerError.ts +8 -0
- package/src/errors/ScallopParseError.ts +8 -0
- package/src/errors/ScallopRpcError.ts +8 -0
- package/src/errors/ScallopTransactionBuildError.ts +8 -0
- package/src/errors/index.ts +6 -0
- package/src/logger/Logger.ts +6 -0
- package/src/logger/consoleLogger.ts +13 -0
- package/src/logger/index.ts +3 -0
- package/src/logger/noopLogger.ts +8 -0
- package/src/mappers/index.ts +1 -0
- package/src/mappers/moveTypeMapper.ts +48 -0
- package/src/models/index.ts +8 -10
- package/src/models/interface.ts +9 -9
- package/src/models/scallop.ts +9 -16
- package/src/models/scallopAddress/const.ts +416 -0
- package/src/models/scallopAddress/index.ts +188 -0
- package/src/models/scallopAddress/types.ts +212 -0
- package/src/models/{scallopBuilder.ts → scallopBuilder/index.ts} +65 -29
- package/src/models/scallopBuilder/types.ts +37 -0
- package/src/models/{scallopClient.ts → scallopClient/index.ts} +157 -598
- package/src/models/scallopClient/types.ts +25 -0
- package/src/models/scallopConstants/config/AddressConfigSource.ts +13 -0
- package/src/models/scallopConstants/config/ConfigValidator.ts +70 -0
- package/src/models/scallopConstants/config/PoolAddressConfigSource.ts +12 -0
- package/src/models/scallopConstants/config/ScallopConfig.ts +80 -0
- package/src/models/scallopConstants/config/ScallopConfigSnapshot.ts +46 -0
- package/src/models/scallopConstants/config/WhitelistConfigSource.ts +16 -0
- package/src/models/scallopConstants/config/index.ts +6 -0
- package/src/models/scallopConstants/const.ts +19 -0
- package/src/models/scallopConstants/constantsSource.ts +98 -0
- package/src/models/scallopConstants/deriveConstants.ts +150 -0
- package/src/models/scallopConstants/index.ts +257 -0
- package/src/models/scallopConstants/loadConstantsState.ts +135 -0
- package/src/models/scallopConstants/types.ts +77 -0
- package/src/models/scallopConstants/utils.ts +69 -0
- package/src/models/scallopQuery/index.ts +1279 -0
- package/src/models/scallopQuery/types.ts +9 -0
- package/src/models/scallopQuery/utils.ts +13 -0
- package/src/models/scallopUtils/index.ts +505 -0
- package/src/models/scallopUtils/types.ts +30 -0
- package/src/models/transactionExecutor.ts +122 -0
- package/src/repositories/addressApi/helpers.ts +14 -0
- package/src/repositories/addressApi/index.ts +24 -0
- package/src/repositories/addressApi/schema.ts +0 -0
- package/src/repositories/addressApi/types.ts +177 -0
- package/src/repositories/base.ts +38 -0
- package/src/repositories/borrowIncentive/bcs.ts +11 -0
- package/src/repositories/borrowIncentive/helpers.ts +396 -0
- package/src/repositories/borrowIncentive/index.ts +52 -0
- package/src/{types/query/borrowIncentive.ts → repositories/borrowIncentive/types.ts} +69 -23
- package/src/repositories/borrowIncentive/utils.ts +234 -0
- package/src/repositories/cache.ts +4 -0
- package/src/repositories/coinBalance/helpers.ts +394 -0
- package/src/repositories/coinBalance/index.ts +69 -0
- package/src/repositories/coinBalance/types.ts +33 -0
- package/src/repositories/flashloan/const.ts +3 -0
- package/src/repositories/flashloan/helpers.ts +107 -0
- package/src/repositories/flashloan/index.ts +34 -0
- package/src/repositories/flashloan/types.ts +16 -0
- package/src/repositories/isolatedAssets/bcs.ts +4 -0
- package/src/repositories/isolatedAssets/const.ts +2 -0
- package/src/repositories/isolatedAssets/helpers.ts +91 -0
- package/src/repositories/isolatedAssets/index.ts +42 -0
- package/src/repositories/isolatedAssets/types.ts +35 -0
- package/src/repositories/loyaltyProgram/bcs.ts +7 -0
- package/src/repositories/loyaltyProgram/helpers.ts +117 -0
- package/src/repositories/loyaltyProgram/index.ts +28 -0
- package/src/repositories/loyaltyProgram/schema.ts +18 -0
- package/src/repositories/loyaltyProgram/types.ts +37 -0
- package/src/repositories/market/const.ts +6 -0
- package/src/repositories/market/helpers.ts +740 -0
- package/src/repositories/market/index.ts +137 -0
- package/src/repositories/market/mapper.ts +30 -0
- package/src/repositories/market/types.ts +443 -0
- package/src/repositories/market/utils.ts +285 -0
- package/src/repositories/obligation/helpers.ts +228 -0
- package/src/repositories/obligation/index.ts +51 -0
- package/src/repositories/obligation/types.ts +71 -0
- package/src/repositories/obligation/utils.ts +57 -0
- package/src/repositories/poolAddresses/const.ts +5 -0
- package/src/repositories/poolAddresses/helpers.ts +422 -0
- package/src/repositories/poolAddresses/index.ts +56 -0
- package/src/repositories/poolAddresses/schema.ts +34 -0
- package/src/repositories/poolAddresses/types.ts +69 -0
- package/src/repositories/price/const.ts +1 -0
- package/src/repositories/price/helpers.ts +237 -0
- package/src/repositories/price/index.ts +91 -0
- package/src/repositories/price/schema.ts +24 -0
- package/src/repositories/price/types.ts +56 -0
- package/src/repositories/price/utils.ts +21 -0
- package/src/repositories/referral/bcs.ts +3 -0
- package/src/repositories/referral/helper.ts +24 -0
- package/src/repositories/referral/index.ts +31 -0
- package/src/repositories/referral/types.ts +33 -0
- package/src/repositories/spool/const.ts +1 -0
- package/src/repositories/spool/helpers.ts +471 -0
- package/src/repositories/spool/index.ts +135 -0
- package/src/{types/query/spool.ts → repositories/spool/types.ts} +67 -2
- package/src/repositories/spool/utils.ts +215 -0
- package/src/repositories/types.ts +39 -0
- package/src/repositories/utils.ts +137 -0
- package/src/repositories/veSca/bcs.ts +6 -0
- package/src/repositories/veSca/helpers.ts +341 -0
- package/src/repositories/veSca/index.ts +57 -0
- package/src/repositories/veSca/types.ts +79 -0
- package/src/repositories/veScaLoyaltyProgram/bcs.ts +3 -0
- package/src/repositories/veScaLoyaltyProgram/helpers.ts +135 -0
- package/src/repositories/veScaLoyaltyProgram/index.ts +28 -0
- package/src/repositories/veScaLoyaltyProgram/schema.ts +15 -0
- package/src/repositories/veScaLoyaltyProgram/types.ts +47 -0
- package/src/repositories/wiring/datasources.ts +42 -0
- package/src/repositories/wiring/metadata.ts +292 -0
- package/src/repositories/wiring/registry.ts +194 -0
- package/src/repositories/wiring/source.ts +63 -0
- package/src/repositories/xOracle/bcs.ts +7 -0
- package/src/repositories/xOracle/const.ts +1 -0
- package/src/repositories/xOracle/helpers.ts +304 -0
- package/src/repositories/xOracle/index.ts +45 -0
- package/src/repositories/xOracle/types.ts +96 -0
- package/src/repositories/xOracle/utils.ts +3 -0
- package/src/services/client/BorrowService.ts +229 -0
- package/src/services/client/CollateralService.ts +76 -0
- package/src/services/client/LendingService.ts +75 -0
- package/src/services/client/ReferralService.ts +71 -0
- package/src/services/client/SpoolService.ts +170 -0
- package/src/services/client/VeScaService.ts +142 -0
- package/src/services/client/types.ts +44 -0
- package/src/services/index.ts +8 -0
- package/src/services/query/portfolioCalculations.ts +1171 -0
- package/src/txBuilders/borrowIncentive/index.ts +80 -0
- package/src/txBuilders/borrowIncentive/moveCalls.ts +124 -0
- package/src/txBuilders/borrowIncentive/quick.ts +207 -0
- package/src/txBuilders/context.ts +62 -0
- package/src/txBuilders/core/index.ts +95 -0
- package/src/txBuilders/core/moveCalls.ts +241 -0
- package/src/txBuilders/core/quick.ts +306 -0
- package/src/{builders → txBuilders}/index.ts +35 -9
- package/src/txBuilders/loyaltyProgram/index.ts +78 -0
- package/src/txBuilders/loyaltyProgram/moveCalls.ts +44 -0
- package/src/txBuilders/loyaltyProgram/quick.ts +58 -0
- package/src/txBuilders/manifest.ts +160 -0
- package/src/txBuilders/modules.ts +70 -0
- package/src/{builders → txBuilders}/oracles/index.ts +3 -2
- package/src/{builders → txBuilders}/oracles/pyth.ts +4 -3
- package/src/txBuilders/referral/index.ts +72 -0
- package/src/txBuilders/referral/moveCalls.ts +93 -0
- package/src/txBuilders/referral/quick.ts +57 -0
- package/src/txBuilders/sCoin/index.ts +72 -0
- package/src/txBuilders/sCoin/moveCalls.ts +36 -0
- package/src/txBuilders/sCoin/quick.ts +34 -0
- package/src/txBuilders/spool/index.ts +82 -0
- package/src/txBuilders/spool/moveCalls.ts +79 -0
- package/src/{builders/spoolBuilder.ts → txBuilders/spool/quick.ts} +22 -162
- package/src/txBuilders/utils.ts +36 -0
- package/src/txBuilders/verify.ts +45 -0
- package/src/txBuilders/vesca/index.ts +75 -0
- package/src/txBuilders/vesca/moveCalls.ts +147 -0
- package/src/{builders/vescaBuilder.ts → txBuilders/vesca/quick.ts} +85 -274
- package/src/types/address.ts +4 -178
- package/src/types/builder/borrowIncentive.ts +4 -3
- package/src/types/builder/core.ts +6 -33
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/loyaltyProgram.ts +4 -3
- package/src/types/builder/modules.ts +49 -0
- package/src/types/builder/referral.ts +5 -4
- package/src/types/builder/sCoin.ts +20 -2
- package/src/types/builder/spool.ts +22 -2
- package/src/types/builder/vesca.ts +4 -12
- package/src/types/constant/index.ts +3 -1
- package/src/types/constant/queryKeys.ts +15 -8
- package/src/types/index.ts +5 -6
- package/src/types/internal/dto.ts +46 -0
- package/src/types/internal/index.ts +2 -0
- package/src/types/internal/move.ts +13 -0
- package/src/types/public/index.ts +21 -0
- package/src/types/query/core.ts +0 -317
- package/src/types/query/index.ts +3 -4
- package/src/types/query/portfolio.ts +2 -15
- package/src/types/repositories/borrowIncentive.ts +12 -0
- package/src/types/repositories/index.ts +9 -0
- package/src/types/repositories/loyaltyProgram.ts +2 -0
- package/src/types/repositories/market.ts +13 -0
- package/src/types/repositories/spool.ts +21 -0
- package/src/types/repositories/veSca.ts +5 -0
- package/src/types/repositories/veScaLoyaltyProgram.ts +2 -0
- package/src/types/sui.ts +0 -1
- package/src/utils/array.ts +7 -0
- package/src/utils/cache.ts +17 -0
- package/src/utils/object.ts +30 -12
- package/src/utils/query.ts +9 -190
- package/src/utils/vesca.ts +0 -8
- package/src/builders/borrowIncentiveBuilder.ts +0 -372
- package/src/builders/coreBuilder.ts +0 -636
- package/src/builders/loyaltyProgramBuilder.ts +0 -142
- package/src/builders/referralBuilder.ts +0 -192
- package/src/builders/sCoinBuilder.ts +0 -124
- package/src/index.ts +0 -13
- package/src/models/scallopAddress.ts +0 -841
- package/src/models/scallopAxios.ts +0 -185
- package/src/models/scallopConstants.ts +0 -380
- package/src/models/scallopIndexer.ts +0 -226
- package/src/models/scallopQuery.ts +0 -974
- package/src/models/scallopQueryClient.ts +0 -29
- package/src/models/scallopSuiKit.ts +0 -480
- package/src/models/scallopUtils.ts +0 -734
- package/src/queries/borrowIncentiveQuery.ts +0 -361
- package/src/queries/borrowLimitQuery.ts +0 -33
- package/src/queries/coreQuery.ts +0 -1173
- package/src/queries/flashloanFeeQuery.ts +0 -92
- package/src/queries/index.ts +0 -15
- package/src/queries/isolatedAssetQuery.ts +0 -103
- package/src/queries/loyaltyProgramQuery.ts +0 -178
- package/src/queries/ownerQuery.ts +0 -32
- package/src/queries/poolAddressesQuery.ts +0 -340
- package/src/queries/portfolioQuery.ts +0 -1149
- package/src/queries/priceQuery.ts +0 -37
- package/src/queries/referralQuery.ts +0 -42
- package/src/queries/sCoinQuery.ts +0 -195
- package/src/queries/spoolQuery.ts +0 -542
- package/src/queries/supplyLimitQuery.ts +0 -32
- package/src/queries/switchboardQuery.ts +0 -65
- package/src/queries/vescaQuery.ts +0 -312
- package/src/queries/xOracleQuery.ts +0 -149
- package/src/types/constant/common.ts +0 -55
- package/src/types/query/loyaltyProgram.ts +0 -12
- package/src/types/query/vesca.ts +0 -27
- package/src/utils/index.ts +0 -7
- package/src/utils/indexer.ts +0 -47
- /package/src/{models → datasources}/rateLimiter.ts +0 -0
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import {
|
|
3
|
-
parseOriginBorrowIncentivePoolData,
|
|
4
|
-
parseOriginBorrowIncentiveAccountData,
|
|
5
|
-
calculateBorrowIncentivePoolPointData,
|
|
6
|
-
getSharedObjectData,
|
|
7
|
-
parseObjectAs,
|
|
8
|
-
getDfObjectIdAndName,
|
|
9
|
-
} from 'src/utils/index.js';
|
|
10
|
-
import type {
|
|
11
|
-
ScallopAddress,
|
|
12
|
-
ScallopQuery,
|
|
13
|
-
ScallopSuiKit,
|
|
14
|
-
ScallopUtils,
|
|
15
|
-
} from 'src/models/index.js';
|
|
16
|
-
import type {
|
|
17
|
-
BorrowIncentivePoolsQueryInterface,
|
|
18
|
-
BorrowIncentivePools,
|
|
19
|
-
BorrowIncentiveAccountsQueryInterface,
|
|
20
|
-
BorrowIncentiveAccounts,
|
|
21
|
-
BorrowIncentivePoolPoints,
|
|
22
|
-
OptionalKeys,
|
|
23
|
-
CoinPrices,
|
|
24
|
-
MarketPools,
|
|
25
|
-
} from 'src/types/index.js';
|
|
26
|
-
import { BigNumber } from 'bignumber.js';
|
|
27
|
-
import { SuiTxBlock } from '@scallop-io/sui-kit';
|
|
28
|
-
import { queryKeys } from 'src/constants/index.js';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Query borrow incentive pools data using moveCall
|
|
32
|
-
* @param address
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
const queryBorrowIncentivePools = async ({
|
|
36
|
-
address,
|
|
37
|
-
scallopSuiKit,
|
|
38
|
-
}: {
|
|
39
|
-
address: ScallopAddress;
|
|
40
|
-
scallopSuiKit: ScallopSuiKit;
|
|
41
|
-
}) => {
|
|
42
|
-
const queryPkgId = address.get('borrowIncentive.query');
|
|
43
|
-
const incentivePoolsId = address.get('borrowIncentive.incentivePools');
|
|
44
|
-
|
|
45
|
-
const txBlock = new SuiTxBlock();
|
|
46
|
-
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
47
|
-
const incentivePoolsSharedObject = await getSharedObjectData(scallopSuiKit, {
|
|
48
|
-
tx: txBlock,
|
|
49
|
-
object: incentivePoolsId,
|
|
50
|
-
mutable: true,
|
|
51
|
-
});
|
|
52
|
-
const args = [incentivePoolsSharedObject];
|
|
53
|
-
const queryResult = await scallopSuiKit.queryInspectTxn({
|
|
54
|
-
queryTarget,
|
|
55
|
-
args,
|
|
56
|
-
txBlock,
|
|
57
|
-
keys: queryKeys.rpc.getInspectTxn({
|
|
58
|
-
queryTarget,
|
|
59
|
-
args: [incentivePoolsId],
|
|
60
|
-
node: scallopSuiKit.currentFullNode,
|
|
61
|
-
}),
|
|
62
|
-
});
|
|
63
|
-
// SDK v2: Extract transaction result using discriminated union pattern
|
|
64
|
-
const tx = queryResult?.Transaction ?? queryResult?.FailedTransaction;
|
|
65
|
-
const borrowIncentivePoolsQueryData = (tx?.events?.[0] as any)?.parsedJson as
|
|
66
|
-
| BorrowIncentivePoolsQueryInterface
|
|
67
|
-
| undefined;
|
|
68
|
-
return borrowIncentivePoolsQueryData;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get borrow incentive pools data.
|
|
73
|
-
*
|
|
74
|
-
* @param query - The Scallop query instance.
|
|
75
|
-
* @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
|
|
76
|
-
* @param indexer - Whether to use indexer.
|
|
77
|
-
* @return Borrow incentive pools data.
|
|
78
|
-
*/
|
|
79
|
-
export const getBorrowIncentivePools = async (
|
|
80
|
-
query: ScallopQuery,
|
|
81
|
-
borrowIncentiveCoinNames: string[] = [...query.constants.whitelist.lending],
|
|
82
|
-
indexer: boolean = false,
|
|
83
|
-
marketPools?: MarketPools,
|
|
84
|
-
coinPrices?: CoinPrices
|
|
85
|
-
) => {
|
|
86
|
-
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
87
|
-
marketPools =
|
|
88
|
-
marketPools ??
|
|
89
|
-
(await query.getMarketPools(undefined, { coinPrices, indexer })).pools;
|
|
90
|
-
coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
|
|
91
|
-
|
|
92
|
-
const borrowIncentivePoolsQueryData = await queryBorrowIncentivePools(query);
|
|
93
|
-
|
|
94
|
-
for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
|
|
95
|
-
const borrowIncentivePoolPoints: OptionalKeys<
|
|
96
|
-
Record<string, BorrowIncentivePoolPoints>
|
|
97
|
-
> = {};
|
|
98
|
-
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
|
|
99
|
-
query.utils,
|
|
100
|
-
pool
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const poolCoinType = normalizeStructTag(pool.pool_type.name);
|
|
104
|
-
const poolCoinName = query.utils.parseCoinNameFromType(poolCoinType);
|
|
105
|
-
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
106
|
-
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
107
|
-
|
|
108
|
-
// Filter pools not yet supported by the SDK.
|
|
109
|
-
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// pool points for borrow incentive reward
|
|
114
|
-
for (const [coinName, poolPoint] of Object.entries(
|
|
115
|
-
parsedBorrowIncentivePoolData.poolPoints
|
|
116
|
-
)) {
|
|
117
|
-
if (!poolPoint) continue;
|
|
118
|
-
const rewardCoinType = poolPoint.pointType;
|
|
119
|
-
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
120
|
-
rewardCoinType
|
|
121
|
-
) as string;
|
|
122
|
-
// handle for scoin name
|
|
123
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
124
|
-
if (rewardCoinDecimal === undefined)
|
|
125
|
-
throw new Error(`Coin decimal not found for ${rewardCoinName}`);
|
|
126
|
-
|
|
127
|
-
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
128
|
-
|
|
129
|
-
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
130
|
-
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
131
|
-
|
|
132
|
-
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
133
|
-
// parsedBorrowIncentivePoolData,
|
|
134
|
-
poolPoint,
|
|
135
|
-
rewardCoinPrice,
|
|
136
|
-
rewardCoinDecimal,
|
|
137
|
-
poolCoinPrice,
|
|
138
|
-
poolCoinDecimal
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
if (poolPoint.points > calculatedPoolPoint.accumulatedPoints) {
|
|
142
|
-
borrowIncentivePoolPoints[coinName as string] = {
|
|
143
|
-
symbol,
|
|
144
|
-
coinName: rewardCoinName,
|
|
145
|
-
coinType: rewardCoinType,
|
|
146
|
-
coinDecimal,
|
|
147
|
-
coinPrice: rewardCoinPrice,
|
|
148
|
-
points: poolPoint.points,
|
|
149
|
-
distributedPoint: poolPoint.distributedPoint,
|
|
150
|
-
weightedAmount: poolPoint.weightedAmount,
|
|
151
|
-
...calculatedPoolPoint,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
|
|
157
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
158
|
-
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
159
|
-
|
|
160
|
-
borrowIncentivePools[poolCoinName] = {
|
|
161
|
-
coinName: poolCoinName,
|
|
162
|
-
symbol: query.utils.parseSymbol(poolCoinName),
|
|
163
|
-
coinType: poolCoinType,
|
|
164
|
-
coinDecimal: poolCoinDecimal,
|
|
165
|
-
coinPrice: poolCoinPrice,
|
|
166
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
167
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
168
|
-
stakedValue: stakedValue.toNumber(),
|
|
169
|
-
points: borrowIncentivePoolPoints,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return borrowIncentivePools;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Query borrow incentive accounts data.
|
|
178
|
-
*
|
|
179
|
-
* @param query - The Scallop query instance.
|
|
180
|
-
* @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
|
|
181
|
-
* @return Borrow incentive accounts data.
|
|
182
|
-
*/
|
|
183
|
-
export const queryBorrowIncentiveAccounts = async (
|
|
184
|
-
{ utils }: { utils: ScallopUtils },
|
|
185
|
-
obligationId: string,
|
|
186
|
-
borrowIncentiveCoinNames: string[] = [...utils.constants.whitelist.lending]
|
|
187
|
-
) => {
|
|
188
|
-
const txBlock = new SuiTxBlock();
|
|
189
|
-
const queryPkgId = utils.address.get('borrowIncentive.query');
|
|
190
|
-
const incentiveAccountsId = utils.address.get(
|
|
191
|
-
'borrowIncentive.incentiveAccounts'
|
|
192
|
-
);
|
|
193
|
-
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
194
|
-
const [incentiveAccountVersion, obligationDataVersion] = await Promise.all([
|
|
195
|
-
getSharedObjectData(utils.scallopSuiKit, {
|
|
196
|
-
tx: txBlock,
|
|
197
|
-
object: incentiveAccountsId,
|
|
198
|
-
mutable: true,
|
|
199
|
-
}),
|
|
200
|
-
getSharedObjectData(utils.scallopSuiKit, {
|
|
201
|
-
tx: txBlock,
|
|
202
|
-
object: obligationId,
|
|
203
|
-
mutable: true,
|
|
204
|
-
}),
|
|
205
|
-
]);
|
|
206
|
-
|
|
207
|
-
const args = [incentiveAccountVersion, obligationDataVersion];
|
|
208
|
-
|
|
209
|
-
const queryResult = await utils.scallopSuiKit.queryInspectTxn({
|
|
210
|
-
queryTarget,
|
|
211
|
-
args,
|
|
212
|
-
txBlock,
|
|
213
|
-
keys: queryKeys.rpc.getInspectTxn({
|
|
214
|
-
queryTarget,
|
|
215
|
-
args: [incentiveAccountsId, obligationId],
|
|
216
|
-
node: utils.scallopSuiKit.currentFullNode,
|
|
217
|
-
}),
|
|
218
|
-
});
|
|
219
|
-
// SDK v2: Extract transaction result using discriminated union pattern
|
|
220
|
-
const tx = queryResult?.Transaction ?? queryResult?.FailedTransaction;
|
|
221
|
-
const borrowIncentiveAccountsQueryData = (tx?.events?.[0] as any)
|
|
222
|
-
?.parsedJson as BorrowIncentiveAccountsQueryInterface | undefined;
|
|
223
|
-
|
|
224
|
-
const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
|
|
225
|
-
borrowIncentiveAccountsQueryData?.pool_records ?? []
|
|
226
|
-
).reduce((accounts, accountData) => {
|
|
227
|
-
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(
|
|
228
|
-
utils,
|
|
229
|
-
accountData
|
|
230
|
-
);
|
|
231
|
-
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
232
|
-
const coinName = utils.parseCoinNameFromType(poolType);
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
borrowIncentiveCoinNames &&
|
|
236
|
-
borrowIncentiveCoinNames.includes(coinName)
|
|
237
|
-
) {
|
|
238
|
-
accounts[coinName] = parsedBorrowIncentiveAccount;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return accounts;
|
|
242
|
-
}, {} as BorrowIncentiveAccounts);
|
|
243
|
-
|
|
244
|
-
return borrowIncentiveAccounts;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* @deprecated Use getBindedObligation instead
|
|
249
|
-
*/
|
|
250
|
-
export const getBindedObligationId = async (
|
|
251
|
-
{
|
|
252
|
-
address,
|
|
253
|
-
scallopSuiKit,
|
|
254
|
-
}: {
|
|
255
|
-
address: ScallopAddress;
|
|
256
|
-
scallopSuiKit: ScallopSuiKit;
|
|
257
|
-
},
|
|
258
|
-
veScaKeyId: string
|
|
259
|
-
) => {
|
|
260
|
-
return (
|
|
261
|
-
await getBindedObligation(
|
|
262
|
-
{
|
|
263
|
-
address,
|
|
264
|
-
scallopSuiKit,
|
|
265
|
-
},
|
|
266
|
-
veScaKeyId
|
|
267
|
-
)
|
|
268
|
-
)?.obligationId;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Check veSca bind status
|
|
273
|
-
* @param query
|
|
274
|
-
* @param veScaKey
|
|
275
|
-
* @returns { obligationId, obligationKey } if binded, otherwise null
|
|
276
|
-
*/
|
|
277
|
-
export const getBindedObligation = async (
|
|
278
|
-
{
|
|
279
|
-
address,
|
|
280
|
-
scallopSuiKit,
|
|
281
|
-
}: {
|
|
282
|
-
address: ScallopAddress;
|
|
283
|
-
scallopSuiKit: ScallopSuiKit;
|
|
284
|
-
},
|
|
285
|
-
veScaKeyId: string
|
|
286
|
-
): Promise<{ obligationId: string; obligationKey: string } | null> => {
|
|
287
|
-
const borrowIncentiveObjectId = address.get('borrowIncentive.object');
|
|
288
|
-
const incentivePoolsId = address.get('borrowIncentive.incentivePools');
|
|
289
|
-
const veScaObjId = address.get('vesca.object');
|
|
290
|
-
|
|
291
|
-
// get incentive pools
|
|
292
|
-
const incentivePoolsResponse =
|
|
293
|
-
await scallopSuiKit.queryGetObject(incentivePoolsId);
|
|
294
|
-
|
|
295
|
-
const incentivePoolsObject = incentivePoolsResponse?.object;
|
|
296
|
-
if (!incentivePoolsObject) return null;
|
|
297
|
-
const incentivePoolFields = parseObjectAs<{ ve_sca_bind: { id: string } }>(
|
|
298
|
-
incentivePoolsObject
|
|
299
|
-
);
|
|
300
|
-
const veScaBindTableId = incentivePoolFields.ve_sca_bind.id as string;
|
|
301
|
-
|
|
302
|
-
// check if veSca is inside the bind table
|
|
303
|
-
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
|
|
304
|
-
const veScaBindTableResponse = await scallopSuiKit.queryGetDynamicFieldObject(
|
|
305
|
-
{
|
|
306
|
-
parentId: veScaBindTableId,
|
|
307
|
-
name: {
|
|
308
|
-
type: keyType,
|
|
309
|
-
value: veScaKeyId,
|
|
310
|
-
},
|
|
311
|
-
}
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
const veScaBindObject = veScaBindTableResponse?.object;
|
|
315
|
-
if (!veScaBindObject) return null;
|
|
316
|
-
const { id: obligationId } = parseObjectAs<{ id: string }>(veScaBindObject);
|
|
317
|
-
const { name: obligationKey } = getDfObjectIdAndName(veScaBindObject);
|
|
318
|
-
|
|
319
|
-
return { obligationId, obligationKey };
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
export const getBindedVeScaKey = async (
|
|
323
|
-
{
|
|
324
|
-
address,
|
|
325
|
-
scallopSuiKit,
|
|
326
|
-
}: {
|
|
327
|
-
address: ScallopAddress;
|
|
328
|
-
scallopSuiKit: ScallopSuiKit;
|
|
329
|
-
},
|
|
330
|
-
obligationId: string
|
|
331
|
-
): Promise<string | null> => {
|
|
332
|
-
const borrowIncentiveObjectId = address.get('borrowIncentive.object');
|
|
333
|
-
const incentiveAccountsId = address.get('borrowIncentive.incentiveAccounts');
|
|
334
|
-
const corePkg = address.get('core.object');
|
|
335
|
-
|
|
336
|
-
// get IncentiveAccounts object
|
|
337
|
-
const incentiveAccountsObject =
|
|
338
|
-
await scallopSuiKit.queryGetObject(incentiveAccountsId);
|
|
339
|
-
if (!incentiveAccountsObject?.object) return null;
|
|
340
|
-
const incentiveAccountsTableId = (
|
|
341
|
-
parseObjectAs<Record<string, unknown>>(
|
|
342
|
-
incentiveAccountsObject.object
|
|
343
|
-
) as any
|
|
344
|
-
).accounts.id;
|
|
345
|
-
|
|
346
|
-
// Search in the table
|
|
347
|
-
const bindedIncentiveAcc = await scallopSuiKit.queryGetDynamicFieldObject({
|
|
348
|
-
parentId: incentiveAccountsTableId,
|
|
349
|
-
name: {
|
|
350
|
-
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
351
|
-
value: obligationId,
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
if (!bindedIncentiveAcc?.object) return null;
|
|
356
|
-
const bindedIncentiveAccFields = parseObjectAs<Record<string, unknown>>(
|
|
357
|
-
bindedIncentiveAcc.object
|
|
358
|
-
) as any;
|
|
359
|
-
|
|
360
|
-
return bindedIncentiveAccFields.binded_ve_sca_key?.id ?? null;
|
|
361
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ScallopUtils } from 'src/models/index.js';
|
|
2
|
-
import { parseObjectAs } from 'src/utils/index.js';
|
|
3
|
-
|
|
4
|
-
const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
|
|
5
|
-
// const borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Return supply limit of a pool (including the decimals)
|
|
9
|
-
* @param utils
|
|
10
|
-
* @param poolName
|
|
11
|
-
* @returns supply limit (decimals included)
|
|
12
|
-
*/
|
|
13
|
-
export const getBorrowLimit = async (utils: ScallopUtils, poolName: string) => {
|
|
14
|
-
try {
|
|
15
|
-
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
16
|
-
const marketObject = utils.address.get('core.market');
|
|
17
|
-
if (!marketObject) return null;
|
|
18
|
-
|
|
19
|
-
const object = await utils.scallopSuiKit.queryGetDynamicFieldObject({
|
|
20
|
-
parentId: marketObject,
|
|
21
|
-
name: {
|
|
22
|
-
type: borrowLimitKeyType,
|
|
23
|
-
value: poolCoinType,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!object?.object?.json) return '0';
|
|
28
|
-
return parseObjectAs<string>(object.object);
|
|
29
|
-
} catch (e: any) {
|
|
30
|
-
console.error(`Error in getBorrowLimit for ${poolName}: ${e.message}`);
|
|
31
|
-
return '0';
|
|
32
|
-
}
|
|
33
|
-
};
|