@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.
Files changed (283) hide show
  1. package/dist/Logger-Cg2iFdpH.d.ts +8 -0
  2. package/dist/builder.cjs +22 -0
  3. package/dist/builder.d.cts +28 -0
  4. package/dist/builder.d.ts +28 -0
  5. package/dist/builder.js +4 -0
  6. package/dist/chunk-33AK5RWM.js +15 -0
  7. package/dist/chunk-6UQ4NWEU.js +3 -0
  8. package/dist/chunk-DIC6P5HB.js +11 -0
  9. package/dist/chunk-S34VOEZN.js +3 -0
  10. package/dist/chunk-VTGQACWU.js +6 -0
  11. package/dist/client.cjs +21 -0
  12. package/dist/client.d.cts +401 -0
  13. package/dist/client.d.ts +401 -0
  14. package/dist/client.js +5 -0
  15. package/dist/errors.cjs +10 -0
  16. package/dist/errors.d.cts +32 -0
  17. package/dist/errors.d.ts +32 -0
  18. package/dist/errors.js +1 -0
  19. package/dist/index.cjs +51 -34
  20. package/dist/index.d.cts +130 -3145
  21. package/dist/index.d.ts +130 -3145
  22. package/dist/index.js +8 -12
  23. package/dist/logger.cjs +6 -0
  24. package/dist/logger.d.cts +7 -0
  25. package/dist/logger.d.ts +7 -0
  26. package/dist/logger.js +1 -0
  27. package/dist/query-DkitepDi.d.ts +3305 -0
  28. package/dist/query.cjs +19 -0
  29. package/dist/query.d.cts +9 -0
  30. package/dist/query.d.ts +9 -0
  31. package/dist/query.js +3 -0
  32. package/dist/types.cjs +2 -0
  33. package/dist/types.d.cts +90 -0
  34. package/dist/types.d.ts +90 -0
  35. package/dist/types.js +1 -0
  36. package/package.json +98 -56
  37. package/src/constants/api.ts +2 -0
  38. package/src/constants/coinType.ts +2 -0
  39. package/src/constants/common.ts +0 -7
  40. package/src/constants/index.ts +2 -0
  41. package/src/constants/queryKeys.ts +14 -7
  42. package/src/constants/testAddress.ts +1 -0
  43. package/src/datasources/api.ts +34 -0
  44. package/src/datasources/indexer.ts +8 -0
  45. package/src/datasources/onchain.ts +121 -0
  46. package/src/entries/builder.ts +5 -0
  47. package/src/entries/client.ts +3 -0
  48. package/src/entries/errors.ts +2 -0
  49. package/src/entries/index.ts +17 -0
  50. package/src/entries/logger.ts +2 -0
  51. package/src/entries/query.ts +6 -0
  52. package/src/entries/types.ts +2 -0
  53. package/src/errors/ScallopConfigError.ts +8 -0
  54. package/src/errors/ScallopError.ts +30 -0
  55. package/src/errors/ScallopIndexerError.ts +8 -0
  56. package/src/errors/ScallopParseError.ts +8 -0
  57. package/src/errors/ScallopRpcError.ts +8 -0
  58. package/src/errors/ScallopTransactionBuildError.ts +8 -0
  59. package/src/errors/index.ts +6 -0
  60. package/src/logger/Logger.ts +6 -0
  61. package/src/logger/consoleLogger.ts +13 -0
  62. package/src/logger/index.ts +3 -0
  63. package/src/logger/noopLogger.ts +8 -0
  64. package/src/mappers/index.ts +1 -0
  65. package/src/mappers/moveTypeMapper.ts +48 -0
  66. package/src/models/index.ts +8 -10
  67. package/src/models/interface.ts +9 -9
  68. package/src/models/scallop.ts +9 -16
  69. package/src/models/scallopAddress/const.ts +416 -0
  70. package/src/models/scallopAddress/index.ts +188 -0
  71. package/src/models/scallopAddress/types.ts +212 -0
  72. package/src/models/{scallopBuilder.ts → scallopBuilder/index.ts} +65 -29
  73. package/src/models/scallopBuilder/types.ts +37 -0
  74. package/src/models/{scallopClient.ts → scallopClient/index.ts} +157 -598
  75. package/src/models/scallopClient/types.ts +25 -0
  76. package/src/models/scallopConstants/config/AddressConfigSource.ts +13 -0
  77. package/src/models/scallopConstants/config/ConfigValidator.ts +70 -0
  78. package/src/models/scallopConstants/config/PoolAddressConfigSource.ts +12 -0
  79. package/src/models/scallopConstants/config/ScallopConfig.ts +80 -0
  80. package/src/models/scallopConstants/config/ScallopConfigSnapshot.ts +46 -0
  81. package/src/models/scallopConstants/config/WhitelistConfigSource.ts +16 -0
  82. package/src/models/scallopConstants/config/index.ts +6 -0
  83. package/src/models/scallopConstants/const.ts +19 -0
  84. package/src/models/scallopConstants/constantsSource.ts +98 -0
  85. package/src/models/scallopConstants/deriveConstants.ts +150 -0
  86. package/src/models/scallopConstants/index.ts +257 -0
  87. package/src/models/scallopConstants/loadConstantsState.ts +135 -0
  88. package/src/models/scallopConstants/types.ts +77 -0
  89. package/src/models/scallopConstants/utils.ts +69 -0
  90. package/src/models/scallopQuery/index.ts +1279 -0
  91. package/src/models/scallopQuery/types.ts +9 -0
  92. package/src/models/scallopQuery/utils.ts +13 -0
  93. package/src/models/scallopUtils/index.ts +505 -0
  94. package/src/models/scallopUtils/types.ts +30 -0
  95. package/src/models/transactionExecutor.ts +122 -0
  96. package/src/repositories/addressApi/helpers.ts +14 -0
  97. package/src/repositories/addressApi/index.ts +24 -0
  98. package/src/repositories/addressApi/schema.ts +0 -0
  99. package/src/repositories/addressApi/types.ts +177 -0
  100. package/src/repositories/base.ts +38 -0
  101. package/src/repositories/borrowIncentive/bcs.ts +11 -0
  102. package/src/repositories/borrowIncentive/helpers.ts +396 -0
  103. package/src/repositories/borrowIncentive/index.ts +52 -0
  104. package/src/{types/query/borrowIncentive.ts → repositories/borrowIncentive/types.ts} +69 -23
  105. package/src/repositories/borrowIncentive/utils.ts +234 -0
  106. package/src/repositories/cache.ts +4 -0
  107. package/src/repositories/coinBalance/helpers.ts +394 -0
  108. package/src/repositories/coinBalance/index.ts +69 -0
  109. package/src/repositories/coinBalance/types.ts +33 -0
  110. package/src/repositories/flashloan/const.ts +3 -0
  111. package/src/repositories/flashloan/helpers.ts +107 -0
  112. package/src/repositories/flashloan/index.ts +34 -0
  113. package/src/repositories/flashloan/types.ts +16 -0
  114. package/src/repositories/isolatedAssets/bcs.ts +4 -0
  115. package/src/repositories/isolatedAssets/const.ts +2 -0
  116. package/src/repositories/isolatedAssets/helpers.ts +91 -0
  117. package/src/repositories/isolatedAssets/index.ts +42 -0
  118. package/src/repositories/isolatedAssets/types.ts +35 -0
  119. package/src/repositories/loyaltyProgram/bcs.ts +7 -0
  120. package/src/repositories/loyaltyProgram/helpers.ts +117 -0
  121. package/src/repositories/loyaltyProgram/index.ts +28 -0
  122. package/src/repositories/loyaltyProgram/schema.ts +18 -0
  123. package/src/repositories/loyaltyProgram/types.ts +37 -0
  124. package/src/repositories/market/const.ts +6 -0
  125. package/src/repositories/market/helpers.ts +740 -0
  126. package/src/repositories/market/index.ts +137 -0
  127. package/src/repositories/market/mapper.ts +30 -0
  128. package/src/repositories/market/types.ts +443 -0
  129. package/src/repositories/market/utils.ts +285 -0
  130. package/src/repositories/obligation/helpers.ts +228 -0
  131. package/src/repositories/obligation/index.ts +51 -0
  132. package/src/repositories/obligation/types.ts +71 -0
  133. package/src/repositories/obligation/utils.ts +57 -0
  134. package/src/repositories/poolAddresses/const.ts +5 -0
  135. package/src/repositories/poolAddresses/helpers.ts +422 -0
  136. package/src/repositories/poolAddresses/index.ts +56 -0
  137. package/src/repositories/poolAddresses/schema.ts +34 -0
  138. package/src/repositories/poolAddresses/types.ts +69 -0
  139. package/src/repositories/price/const.ts +1 -0
  140. package/src/repositories/price/helpers.ts +237 -0
  141. package/src/repositories/price/index.ts +91 -0
  142. package/src/repositories/price/schema.ts +24 -0
  143. package/src/repositories/price/types.ts +56 -0
  144. package/src/repositories/price/utils.ts +21 -0
  145. package/src/repositories/referral/bcs.ts +3 -0
  146. package/src/repositories/referral/helper.ts +24 -0
  147. package/src/repositories/referral/index.ts +31 -0
  148. package/src/repositories/referral/types.ts +33 -0
  149. package/src/repositories/spool/const.ts +1 -0
  150. package/src/repositories/spool/helpers.ts +471 -0
  151. package/src/repositories/spool/index.ts +135 -0
  152. package/src/{types/query/spool.ts → repositories/spool/types.ts} +67 -2
  153. package/src/repositories/spool/utils.ts +215 -0
  154. package/src/repositories/types.ts +39 -0
  155. package/src/repositories/utils.ts +137 -0
  156. package/src/repositories/veSca/bcs.ts +6 -0
  157. package/src/repositories/veSca/helpers.ts +341 -0
  158. package/src/repositories/veSca/index.ts +57 -0
  159. package/src/repositories/veSca/types.ts +79 -0
  160. package/src/repositories/veScaLoyaltyProgram/bcs.ts +3 -0
  161. package/src/repositories/veScaLoyaltyProgram/helpers.ts +135 -0
  162. package/src/repositories/veScaLoyaltyProgram/index.ts +28 -0
  163. package/src/repositories/veScaLoyaltyProgram/schema.ts +15 -0
  164. package/src/repositories/veScaLoyaltyProgram/types.ts +47 -0
  165. package/src/repositories/wiring/datasources.ts +42 -0
  166. package/src/repositories/wiring/metadata.ts +292 -0
  167. package/src/repositories/wiring/registry.ts +194 -0
  168. package/src/repositories/wiring/source.ts +63 -0
  169. package/src/repositories/xOracle/bcs.ts +7 -0
  170. package/src/repositories/xOracle/const.ts +1 -0
  171. package/src/repositories/xOracle/helpers.ts +304 -0
  172. package/src/repositories/xOracle/index.ts +45 -0
  173. package/src/repositories/xOracle/types.ts +96 -0
  174. package/src/repositories/xOracle/utils.ts +3 -0
  175. package/src/services/client/BorrowService.ts +229 -0
  176. package/src/services/client/CollateralService.ts +76 -0
  177. package/src/services/client/LendingService.ts +75 -0
  178. package/src/services/client/ReferralService.ts +71 -0
  179. package/src/services/client/SpoolService.ts +170 -0
  180. package/src/services/client/VeScaService.ts +142 -0
  181. package/src/services/client/types.ts +44 -0
  182. package/src/services/index.ts +8 -0
  183. package/src/services/query/portfolioCalculations.ts +1171 -0
  184. package/src/txBuilders/borrowIncentive/index.ts +80 -0
  185. package/src/txBuilders/borrowIncentive/moveCalls.ts +124 -0
  186. package/src/txBuilders/borrowIncentive/quick.ts +207 -0
  187. package/src/txBuilders/context.ts +62 -0
  188. package/src/txBuilders/core/index.ts +95 -0
  189. package/src/txBuilders/core/moveCalls.ts +241 -0
  190. package/src/txBuilders/core/quick.ts +306 -0
  191. package/src/{builders → txBuilders}/index.ts +35 -9
  192. package/src/txBuilders/loyaltyProgram/index.ts +78 -0
  193. package/src/txBuilders/loyaltyProgram/moveCalls.ts +44 -0
  194. package/src/txBuilders/loyaltyProgram/quick.ts +58 -0
  195. package/src/txBuilders/manifest.ts +160 -0
  196. package/src/txBuilders/modules.ts +70 -0
  197. package/src/{builders → txBuilders}/oracles/index.ts +3 -2
  198. package/src/{builders → txBuilders}/oracles/pyth.ts +4 -3
  199. package/src/txBuilders/referral/index.ts +72 -0
  200. package/src/txBuilders/referral/moveCalls.ts +93 -0
  201. package/src/txBuilders/referral/quick.ts +57 -0
  202. package/src/txBuilders/sCoin/index.ts +72 -0
  203. package/src/txBuilders/sCoin/moveCalls.ts +36 -0
  204. package/src/txBuilders/sCoin/quick.ts +34 -0
  205. package/src/txBuilders/spool/index.ts +82 -0
  206. package/src/txBuilders/spool/moveCalls.ts +79 -0
  207. package/src/{builders/spoolBuilder.ts → txBuilders/spool/quick.ts} +22 -162
  208. package/src/txBuilders/utils.ts +36 -0
  209. package/src/txBuilders/verify.ts +45 -0
  210. package/src/txBuilders/vesca/index.ts +75 -0
  211. package/src/txBuilders/vesca/moveCalls.ts +147 -0
  212. package/src/{builders/vescaBuilder.ts → txBuilders/vesca/quick.ts} +85 -274
  213. package/src/types/address.ts +4 -178
  214. package/src/types/builder/borrowIncentive.ts +4 -3
  215. package/src/types/builder/core.ts +6 -33
  216. package/src/types/builder/index.ts +5 -1
  217. package/src/types/builder/loyaltyProgram.ts +4 -3
  218. package/src/types/builder/modules.ts +49 -0
  219. package/src/types/builder/referral.ts +5 -4
  220. package/src/types/builder/sCoin.ts +20 -2
  221. package/src/types/builder/spool.ts +22 -2
  222. package/src/types/builder/vesca.ts +4 -12
  223. package/src/types/constant/index.ts +3 -1
  224. package/src/types/constant/queryKeys.ts +15 -8
  225. package/src/types/index.ts +5 -6
  226. package/src/types/internal/dto.ts +46 -0
  227. package/src/types/internal/index.ts +2 -0
  228. package/src/types/internal/move.ts +13 -0
  229. package/src/types/public/index.ts +21 -0
  230. package/src/types/query/core.ts +0 -317
  231. package/src/types/query/index.ts +3 -4
  232. package/src/types/query/portfolio.ts +2 -15
  233. package/src/types/repositories/borrowIncentive.ts +12 -0
  234. package/src/types/repositories/index.ts +9 -0
  235. package/src/types/repositories/loyaltyProgram.ts +2 -0
  236. package/src/types/repositories/market.ts +13 -0
  237. package/src/types/repositories/spool.ts +21 -0
  238. package/src/types/repositories/veSca.ts +5 -0
  239. package/src/types/repositories/veScaLoyaltyProgram.ts +2 -0
  240. package/src/types/sui.ts +0 -1
  241. package/src/utils/array.ts +7 -0
  242. package/src/utils/cache.ts +17 -0
  243. package/src/utils/object.ts +30 -12
  244. package/src/utils/query.ts +9 -190
  245. package/src/utils/vesca.ts +0 -8
  246. package/src/builders/borrowIncentiveBuilder.ts +0 -372
  247. package/src/builders/coreBuilder.ts +0 -636
  248. package/src/builders/loyaltyProgramBuilder.ts +0 -142
  249. package/src/builders/referralBuilder.ts +0 -192
  250. package/src/builders/sCoinBuilder.ts +0 -124
  251. package/src/index.ts +0 -13
  252. package/src/models/scallopAddress.ts +0 -841
  253. package/src/models/scallopAxios.ts +0 -185
  254. package/src/models/scallopConstants.ts +0 -380
  255. package/src/models/scallopIndexer.ts +0 -226
  256. package/src/models/scallopQuery.ts +0 -974
  257. package/src/models/scallopQueryClient.ts +0 -29
  258. package/src/models/scallopSuiKit.ts +0 -480
  259. package/src/models/scallopUtils.ts +0 -734
  260. package/src/queries/borrowIncentiveQuery.ts +0 -361
  261. package/src/queries/borrowLimitQuery.ts +0 -33
  262. package/src/queries/coreQuery.ts +0 -1173
  263. package/src/queries/flashloanFeeQuery.ts +0 -92
  264. package/src/queries/index.ts +0 -15
  265. package/src/queries/isolatedAssetQuery.ts +0 -103
  266. package/src/queries/loyaltyProgramQuery.ts +0 -178
  267. package/src/queries/ownerQuery.ts +0 -32
  268. package/src/queries/poolAddressesQuery.ts +0 -340
  269. package/src/queries/portfolioQuery.ts +0 -1149
  270. package/src/queries/priceQuery.ts +0 -37
  271. package/src/queries/referralQuery.ts +0 -42
  272. package/src/queries/sCoinQuery.ts +0 -195
  273. package/src/queries/spoolQuery.ts +0 -542
  274. package/src/queries/supplyLimitQuery.ts +0 -32
  275. package/src/queries/switchboardQuery.ts +0 -65
  276. package/src/queries/vescaQuery.ts +0 -312
  277. package/src/queries/xOracleQuery.ts +0 -149
  278. package/src/types/constant/common.ts +0 -55
  279. package/src/types/query/loyaltyProgram.ts +0 -12
  280. package/src/types/query/vesca.ts +0 -27
  281. package/src/utils/index.ts +0 -7
  282. package/src/utils/indexer.ts +0 -47
  283. /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
- };