@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.5 → 2.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 (55) hide show
  1. package/dist/index.d.mts +622 -697
  2. package/dist/index.d.ts +622 -697
  3. package/dist/index.js +32 -33
  4. package/dist/index.mjs +10 -10
  5. package/package.json +8 -18
  6. package/src/builders/borrowIncentiveBuilder.ts +9 -21
  7. package/src/builders/coreBuilder.ts +2 -2
  8. package/src/builders/index.ts +2 -2
  9. package/src/builders/oracles/index.ts +2 -3
  10. package/src/builders/oracles/pyth.ts +2 -2
  11. package/src/builders/spoolBuilder.ts +2 -2
  12. package/src/builders/vescaBuilder.ts +14 -132
  13. package/src/constants/queryKeys.ts +29 -54
  14. package/src/constants/testAddress.ts +6 -12
  15. package/src/index.ts +11 -1
  16. package/src/models/index.ts +11 -9
  17. package/src/models/interface.ts +36 -0
  18. package/src/models/scallop.ts +38 -133
  19. package/src/models/scallopAddress.ts +127 -142
  20. package/src/models/scallopAxios.ts +185 -0
  21. package/src/models/scallopBuilder.ts +45 -75
  22. package/src/models/scallopClient.ts +124 -154
  23. package/src/models/scallopConstants.ts +248 -323
  24. package/src/models/scallopIndexer.ts +54 -98
  25. package/src/models/scallopQuery.ts +145 -190
  26. package/src/models/scallopQueryClient.ts +29 -0
  27. package/src/models/scallopSuiKit.ts +432 -0
  28. package/src/models/scallopUtils.ts +260 -164
  29. package/src/queries/borrowIncentiveQuery.ts +28 -16
  30. package/src/queries/borrowLimitQuery.ts +1 -1
  31. package/src/queries/coreQuery.ts +148 -107
  32. package/src/queries/flashloanFeeQuery.ts +12 -6
  33. package/src/queries/index.ts +0 -1
  34. package/src/queries/isolatedAssetQuery.ts +3 -3
  35. package/src/queries/loyaltyProgramQuery.ts +10 -8
  36. package/src/queries/ownerQuery.ts +32 -0
  37. package/src/queries/portfolioQuery.ts +4 -5
  38. package/src/queries/priceQuery.ts +14 -8
  39. package/src/queries/referralQuery.ts +9 -3
  40. package/src/queries/sCoinQuery.ts +4 -4
  41. package/src/queries/spoolQuery.ts +11 -11
  42. package/src/queries/supplyLimitQuery.ts +1 -1
  43. package/src/queries/switchboardQuery.ts +1 -1
  44. package/src/queries/vescaQuery.ts +31 -27
  45. package/src/queries/xOracleQuery.ts +13 -8
  46. package/src/types/address.ts +0 -3
  47. package/src/types/builder/core.ts +1 -1
  48. package/src/types/builder/vesca.ts +10 -20
  49. package/src/types/constant/queryKeys.ts +48 -0
  50. package/src/types/index.ts +0 -1
  51. package/src/utils/builder.ts +1 -1
  52. package/src/utils/util.ts +1 -33
  53. package/src/models/scallopCache.ts +0 -428
  54. package/src/queries/objectsQuery.ts +0 -18
  55. package/src/types/model.ts +0 -117
@@ -4,7 +4,12 @@ import {
4
4
  parseOriginBorrowIncentiveAccountData,
5
5
  calculateBorrowIncentivePoolPointData,
6
6
  } from 'src/utils';
7
- import type { ScallopAddress, ScallopQuery, ScallopUtils } from 'src/models';
7
+ import type {
8
+ ScallopAddress,
9
+ ScallopQuery,
10
+ ScallopSuiKit,
11
+ ScallopUtils,
12
+ } from 'src/models';
8
13
  import type {
9
14
  BorrowIncentivePoolsQueryInterface,
10
15
  BorrowIncentivePools,
@@ -23,13 +28,19 @@ import { SuiObjectRef } from '@mysten/sui/client';
23
28
  * @param address
24
29
  * @returns
25
30
  */
26
- export const queryBorrowIncentivePools = async (address: ScallopAddress) => {
31
+ export const queryBorrowIncentivePools = async ({
32
+ address,
33
+ scallopSuiKit,
34
+ }: {
35
+ address: ScallopAddress;
36
+ scallopSuiKit: ScallopSuiKit;
37
+ }) => {
27
38
  const queryPkgId = address.get('borrowIncentive.query');
28
39
  const incentivePoolsId = address.get('borrowIncentive.incentivePools');
29
40
 
30
41
  const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
31
42
  const args = [incentivePoolsId];
32
- const queryResult = await address.cache.queryInspectTxn({
43
+ const queryResult = await scallopSuiKit.queryInspectTxn({
33
44
  queryTarget,
34
45
  args,
35
46
  });
@@ -60,9 +71,7 @@ export const getBorrowIncentivePools = async (
60
71
  (await query.getMarketPools(undefined, { coinPrices, indexer })).pools;
61
72
  coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
62
73
 
63
- const borrowIncentivePoolsQueryData = await queryBorrowIncentivePools(
64
- query.address
65
- );
74
+ const borrowIncentivePoolsQueryData = await queryBorrowIncentivePools(query);
66
75
 
67
76
  for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
68
77
  const borrowIncentivePoolPoints: OptionalKeys<
@@ -152,11 +161,7 @@ export const getBorrowIncentivePools = async (
152
161
  * @return Borrow incentive accounts data.
153
162
  */
154
163
  export const queryBorrowIncentiveAccounts = async (
155
- {
156
- utils,
157
- }: {
158
- utils: ScallopUtils;
159
- },
164
+ { utils }: { utils: ScallopUtils },
160
165
  obligationId: string | SuiObjectRef,
161
166
  borrowIncentiveCoinNames: string[] = [...utils.constants.whitelist.lending]
162
167
  ) => {
@@ -167,7 +172,10 @@ export const queryBorrowIncentiveAccounts = async (
167
172
  const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
168
173
  const args = [incentiveAccountsId, obligationId];
169
174
 
170
- const queryResult = await utils.cache.queryInspectTxn({ queryTarget, args });
175
+ const queryResult = await utils.scallopSuiKit.queryInspectTxn({
176
+ queryTarget,
177
+ args,
178
+ });
171
179
  const borrowIncentiveAccountsQueryData = queryResult?.events[0]
172
180
  ?.parsedJson as BorrowIncentiveAccountsQueryInterface | undefined;
173
181
 
@@ -203,8 +211,10 @@ export const queryBorrowIncentiveAccounts = async (
203
211
  export const getBindedObligationId = async (
204
212
  {
205
213
  address,
214
+ scallopSuiKit,
206
215
  }: {
207
216
  address: ScallopAddress;
217
+ scallopSuiKit: ScallopSuiKit;
208
218
  },
209
219
  veScaKeyId: string
210
220
  ): Promise<string | null> => {
@@ -214,7 +224,7 @@ export const getBindedObligationId = async (
214
224
 
215
225
  // get incentive pools
216
226
  const incentivePoolsResponse =
217
- await address.cache.queryGetObject(incentivePoolsId);
227
+ await scallopSuiKit.queryGetObject(incentivePoolsId);
218
228
 
219
229
  if (incentivePoolsResponse?.data?.content?.dataType !== 'moveObject')
220
230
  return null;
@@ -224,7 +234,7 @@ export const getBindedObligationId = async (
224
234
 
225
235
  // check if veSca is inside the bind table
226
236
  const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
227
- const veScaBindTableResponse = await address.cache.queryGetDynamicFieldObject(
237
+ const veScaBindTableResponse = await scallopSuiKit.queryGetDynamicFieldObject(
228
238
  {
229
239
  parentId: veScaBindTableId,
230
240
  name: {
@@ -247,8 +257,10 @@ export const getBindedObligationId = async (
247
257
  export const getBindedVeScaKey = async (
248
258
  {
249
259
  address,
260
+ scallopSuiKit,
250
261
  }: {
251
262
  address: ScallopAddress;
263
+ scallopSuiKit: ScallopSuiKit;
252
264
  },
253
265
  obligationId: string
254
266
  ): Promise<string | null> => {
@@ -258,7 +270,7 @@ export const getBindedVeScaKey = async (
258
270
 
259
271
  // get IncentiveAccounts object
260
272
  const incentiveAccountsObject =
261
- await address.cache.queryGetObject(incentiveAccountsId);
273
+ await scallopSuiKit.queryGetObject(incentiveAccountsId);
262
274
  if (incentiveAccountsObject?.data?.content?.dataType !== 'moveObject')
263
275
  return null;
264
276
  const incentiveAccountsTableId = (
@@ -266,7 +278,7 @@ export const getBindedVeScaKey = async (
266
278
  ).accounts.fields.id.id;
267
279
 
268
280
  // Search in the table
269
- const bindedIncentiveAcc = await address.cache.queryGetDynamicFieldObject({
281
+ const bindedIncentiveAcc = await scallopSuiKit.queryGetDynamicFieldObject({
270
282
  parentId: incentiveAccountsTableId,
271
283
  name: {
272
284
  type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
@@ -31,7 +31,7 @@ export const getBorrowLimit = async (utils: ScallopUtils, poolName: string) => {
31
31
  const marketObject = utils.address.get('core.market');
32
32
  if (!marketObject) return null;
33
33
 
34
- const object = await utils.cache.queryGetDynamicFieldObject({
34
+ const object = await utils.scallopSuiKit.queryGetDynamicFieldObject({
35
35
  parentId: marketObject,
36
36
  name: {
37
37
  type: borrowLimitKeyType,