@scallop-io/sui-scallop-sdk 0.44.28 → 0.46.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 (60) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +1 -1
  2. package/dist/builders/referralBuilder.d.ts +12 -0
  3. package/dist/constants/cache.d.ts +8 -0
  4. package/dist/constants/common.d.ts +1 -1
  5. package/dist/index.js +890 -419
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +967 -493
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/index.d.ts +1 -0
  10. package/dist/models/scallop.d.ts +7 -1
  11. package/dist/models/scallopAddress.d.ts +4 -2
  12. package/dist/models/scallopBuilder.d.ts +2 -0
  13. package/dist/models/scallopCache.d.ts +75 -0
  14. package/dist/models/scallopClient.d.ts +2 -0
  15. package/dist/models/scallopIndexer.d.ts +5 -3
  16. package/dist/models/scallopQuery.d.ts +28 -28
  17. package/dist/models/scallopUtils.d.ts +1 -0
  18. package/dist/queries/coreQuery.d.ts +3 -29
  19. package/dist/queries/index.d.ts +1 -0
  20. package/dist/queries/priceQuery.d.ts +3 -1
  21. package/dist/queries/referralQuery.d.ts +7 -0
  22. package/dist/queries/vescaQuery.d.ts +6 -2
  23. package/dist/types/address.d.ts +15 -0
  24. package/dist/types/builder/core.d.ts +2 -0
  25. package/dist/types/builder/index.d.ts +2 -1
  26. package/dist/types/builder/referral.d.ts +30 -0
  27. package/dist/types/builder/vesca.d.ts +1 -0
  28. package/dist/types/model.d.ts +2 -0
  29. package/package.json +8 -6
  30. package/src/builders/borrowIncentiveBuilder.ts +12 -21
  31. package/src/builders/coreBuilder.ts +54 -0
  32. package/src/builders/index.ts +5 -2
  33. package/src/builders/referralBuilder.ts +178 -0
  34. package/src/builders/vescaBuilder.ts +8 -6
  35. package/src/constants/cache.ts +15 -0
  36. package/src/constants/common.ts +9 -2
  37. package/src/constants/vesca.ts +1 -3
  38. package/src/models/index.ts +1 -0
  39. package/src/models/scallop.ts +26 -7
  40. package/src/models/scallopAddress.ts +87 -38
  41. package/src/models/scallopBuilder.ts +14 -4
  42. package/src/models/scallopCache.ts +285 -0
  43. package/src/models/scallopClient.ts +15 -4
  44. package/src/models/scallopIndexer.ts +58 -84
  45. package/src/models/scallopQuery.ts +54 -5
  46. package/src/models/scallopUtils.ts +66 -37
  47. package/src/queries/borrowIncentiveQuery.ts +6 -12
  48. package/src/queries/coreQuery.ts +83 -260
  49. package/src/queries/index.ts +1 -0
  50. package/src/queries/priceQuery.ts +48 -9
  51. package/src/queries/referralQuery.ts +27 -0
  52. package/src/queries/spoolQuery.ts +20 -27
  53. package/src/queries/vescaQuery.ts +95 -17
  54. package/src/types/address.ts +15 -0
  55. package/src/types/builder/core.ts +14 -0
  56. package/src/types/builder/index.ts +2 -0
  57. package/src/types/builder/referral.ts +51 -0
  58. package/src/types/builder/vesca.ts +1 -0
  59. package/src/types/model.ts +2 -0
  60. package/src/types/query/borrowIncentive.ts +0 -107
@@ -1,8 +1,14 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { Vesca } from '../types';
3
- import type { SuiObjectResponse, SuiObjectData } from '@mysten/sui.js/client';
3
+ import {
4
+ type SuiObjectResponse,
5
+ type SuiObjectData,
6
+ DevInspectResults,
7
+ } from '@mysten/sui.js/client';
4
8
  import type { ScallopQuery } from '../models';
5
- import { IS_VE_SCA_TEST, MAX_LOCK_DURATION } from 'src/constants';
9
+ import { MAX_LOCK_DURATION } from 'src/constants';
10
+ import { SUI_CLOCK_OBJECT_ID, SuiTxBlock } from '@scallop-io/sui-kit';
11
+ import { bcs } from '@mysten/sui.js/bcs';
6
12
  /**
7
13
  * Query all owned veSca key.
8
14
  *
@@ -15,10 +21,8 @@ export const getVescaKeys = async (
15
21
  ownerAddress?: string
16
22
  ) => {
17
23
  const owner = ownerAddress || query.suiKit.currentAddress();
18
- const veScaPkgId = IS_VE_SCA_TEST
19
- ? '0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8'
20
- : query.address.get('vesca.id');
21
- const veScaKeyType = `${veScaPkgId}::ve_sca::VeScaKey`;
24
+ const veScaObjId = query.address.get('vesca.object');
25
+ const veScaKeyType = `${veScaObjId}::ve_sca::VeScaKey`;
22
26
  const keyObjectsResponse: SuiObjectResponse[] = [];
23
27
  let hasNextPage = false;
24
28
  let nextCursor: string | null | undefined = null;
@@ -61,13 +65,18 @@ export const getVeScas = async (query: ScallopQuery, ownerAddress?: string) => {
61
65
  const keyObjectDatas = await getVescaKeys(query, ownerAddress);
62
66
  const keyObjectId: string[] = keyObjectDatas.map((data) => data.objectId);
63
67
 
64
- const veScas: Vesca[] = [];
65
- for (const keyId of keyObjectId) {
68
+ const veScas: (Vesca | undefined)[] = Array(keyObjectId.length).fill(null);
69
+ const tasks = keyObjectId.map(async (keyId, idx) => {
66
70
  const veSca = await getVeSca(query, keyId);
67
- if (veSca) veScas.push(veSca);
68
- }
71
+ if (veSca) {
72
+ veScas[idx] = veSca;
73
+ }
74
+ });
75
+ await Promise.allSettled(tasks);
69
76
 
70
- return veScas;
77
+ return veScas
78
+ .filter(Boolean)
79
+ .sort((a, b) => a!.currentVeScaBalance - b!.currentVeScaBalance);
71
80
  };
72
81
 
73
82
  /**
@@ -83,17 +92,14 @@ export const getVeSca = async (
83
92
  veScaKeyId?: string,
84
93
  ownerAddress?: string
85
94
  ) => {
86
- const tableId = IS_VE_SCA_TEST
87
- ? '0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd'
88
- : query.address.get(`vesca.tableId`);
95
+ const tableId = query.address.get(`vesca.tableId`);
89
96
  veScaKeyId =
90
97
  veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
91
98
 
92
99
  let vesca: Vesca | undefined = undefined;
93
100
 
94
- const veScaDynamicFieldObjectResponse = await query.suiKit
95
- .client()
96
- .getDynamicFieldObject({
101
+ const veScaDynamicFieldObjectResponse =
102
+ await query.cache.queryGetDynamicFieldObject({
97
103
  parentId: tableId,
98
104
  name: {
99
105
  type: '0x2::object::ID',
@@ -135,3 +141,75 @@ export const getVeSca = async (
135
141
 
136
142
  return vesca;
137
143
  };
144
+
145
+ /**
146
+ * Get current total veSca treasury amount.
147
+ */
148
+ export const getTotalVeScaTreasuryAmount = async (
149
+ query: ScallopQuery
150
+ ): Promise<string> => {
151
+ const veScaPkgId = query.address.get('vesca.id');
152
+ const veScaConfig = query.address.get('vesca.config');
153
+ const veScaTreasury = query.address.get('vesca.treasury');
154
+
155
+ // refresh query
156
+ const refreshQueryTarget = `${veScaPkgId}::treasury::refresh`;
157
+ const refreshArgs = [veScaConfig, veScaTreasury, SUI_CLOCK_OBJECT_ID];
158
+
159
+ // query total veSca amount
160
+ const veScaAmountQueryTarget = `${veScaPkgId}::treasury::total_ve_sca_amount`;
161
+ const veScaAmountArgs = [veScaTreasury, SUI_CLOCK_OBJECT_ID];
162
+
163
+ // resolve each args
164
+ const resolvedRefreshArgs = await Promise.all(
165
+ refreshArgs.map(async (arg) => {
166
+ if (typeof arg === 'string') {
167
+ return (await query.cache.queryGetObject(arg, { showContent: true }))
168
+ .data;
169
+ }
170
+ return arg;
171
+ })
172
+ );
173
+
174
+ const resolvedVeScaAmountArgs = await Promise.all(
175
+ veScaAmountArgs.map(async (arg) => {
176
+ if (typeof arg === 'string') {
177
+ return (await query.cache.queryGetObject(arg, { showContent: true }))
178
+ .data;
179
+ }
180
+ return arg;
181
+ })
182
+ );
183
+
184
+ const txb = new SuiTxBlock();
185
+ // refresh first
186
+ txb.moveCall(refreshQueryTarget, resolvedRefreshArgs);
187
+ txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
188
+
189
+ const txBytes = await txb.txBlock.build({
190
+ client: query.suiKit.client(),
191
+ onlyTransactionKind: true,
192
+ protocolConfig: await query.cache.getProtocolConfig(),
193
+ });
194
+
195
+ // return result
196
+ const res = await query.cache.queryClient.fetchQuery<DevInspectResults>({
197
+ queryKey: [
198
+ 'getTotalVeScaTreasuryAmount',
199
+ JSON.stringify([...refreshArgs, ...veScaAmountArgs]),
200
+ ],
201
+ queryFn: async () => {
202
+ return await query.suiKit.inspectTxn(txBytes);
203
+ },
204
+ staleTime: 8000,
205
+ });
206
+
207
+ const results = res.results;
208
+ if (results && results[1].returnValues) {
209
+ const value = Uint8Array.from(results[1].returnValues[0][0]);
210
+ const type = results[1].returnValues[0][1];
211
+ return bcs.de(type, value);
212
+ }
213
+
214
+ return '0';
215
+ };
@@ -73,6 +73,7 @@ export interface AddressesInterface {
73
73
  id: string;
74
74
  adminCap: string;
75
75
  object: string;
76
+ config: string;
76
77
  pools: Partial<
77
78
  Record<
78
79
  SupportStakeMarketCoins,
@@ -94,12 +95,26 @@ export interface AddressesInterface {
94
95
  };
95
96
  vesca: {
96
97
  id: string;
98
+ object: string;
97
99
  adminCap: string;
98
100
  tableId: string;
99
101
  table: string;
100
102
  treasury: string;
101
103
  config: string;
102
104
  };
105
+ referral: {
106
+ id: string;
107
+ version: string;
108
+ object: string;
109
+ adminCap: string;
110
+ referralBindings: string;
111
+ bindingTableId: string;
112
+ referralRevenuePool: string;
113
+ revenueTableId: string;
114
+ referralTiers: string;
115
+ tiersTableId: string;
116
+ authorizedWitnessList: string;
117
+ };
103
118
  }
104
119
 
105
120
  type AddressPathsProps<T> = T extends string
@@ -57,6 +57,13 @@ export type CoreNormalMethods = {
57
57
  amount: SuiTxArg,
58
58
  poolCoinName: SupportPoolCoins
59
59
  ) => TransactionResult;
60
+ borrowWithReferral: (
61
+ obligation: SuiAddressArg,
62
+ obligationKey: SuiAddressArg,
63
+ borrowReferral: SuiObjectArg,
64
+ amount: SuiTxArg,
65
+ poolCoinName: SupportPoolCoins
66
+ ) => TransactionResult;
60
67
  borrowEntry: (
61
68
  obligation: SuiAddressArg,
62
69
  obligationKey: SuiAddressArg,
@@ -97,6 +104,13 @@ export type CoreQuickMethods = {
97
104
  obligationId?: SuiAddressArg,
98
105
  obligationKey?: SuiAddressArg
99
106
  ) => Promise<TransactionResult>;
107
+ borrowWithReferralQuick: (
108
+ amount: number,
109
+ poolCoinName: SupportPoolCoins,
110
+ borrowReferral: SuiObjectArg,
111
+ obligationId?: SuiAddressArg,
112
+ obligationKey?: SuiAddressArg
113
+ ) => Promise<TransactionResult>;
100
114
  depositQuick: (
101
115
  amount: number,
102
116
  poolCoinName: SupportPoolCoins
@@ -2,6 +2,7 @@ import type { CoreTxBlock } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
3
  import type { BorrowIncentiveTxBlock } from './borrowIncentive';
4
4
  import type { VeScaTxBlock } from './vesca';
5
+ import type { ReferralTxBlock } from './referral';
5
6
 
6
7
  export type * from './core';
7
8
  export type * from './spool';
@@ -10,5 +11,6 @@ export type * from './vesca';
10
11
 
11
12
  export type ScallopTxBlock = CoreTxBlock &
12
13
  SpoolTxBlock &
14
+ ReferralTxBlock &
13
15
  BorrowIncentiveTxBlock &
14
16
  VeScaTxBlock;
@@ -0,0 +1,51 @@
1
+ import {
2
+ SuiObjectArg,
3
+ TransactionResult,
4
+ SuiTxBlock as SuiKitTxBlock,
5
+ } from '@scallop-io/sui-kit';
6
+ import { ScallopBuilder } from 'src/models';
7
+ import { SupportPoolCoins } from '../constant';
8
+
9
+ export type ReferralIds = {
10
+ referralPgkId: string;
11
+ referralBindings: string;
12
+ referralRevenuePool: string;
13
+ referralTiers: string;
14
+ authorizedWitnessList: string;
15
+ version: string;
16
+ };
17
+
18
+ export type ReferralNormalMethods = {
19
+ bindToReferral: (veScaKeyId: string) => void;
20
+ claimReferralTicket: (poolCoinName: SupportPoolCoins) => TransactionResult;
21
+ burnReferralTicket: (
22
+ ticket: SuiObjectArg,
23
+ poolCoinName: SupportPoolCoins
24
+ ) => void;
25
+ claimReferralRevenue: (
26
+ veScaKey: SuiObjectArg,
27
+ poolCoinName: SupportPoolCoins
28
+ ) => TransactionResult;
29
+ };
30
+
31
+ export type ReferralQuickMethods = {
32
+ claimReferralRevenueQuick: (
33
+ veScaKey: SuiObjectArg,
34
+ coinNames: SupportPoolCoins[]
35
+ ) => Promise<void>;
36
+ };
37
+
38
+ export type SuiTxBlockWithReferralNormalMethods = SuiKitTxBlock &
39
+ ReferralNormalMethods;
40
+ export type ReferralTxBlock = SuiTxBlockWithReferralNormalMethods &
41
+ ReferralQuickMethods;
42
+
43
+ export type GenerateReferralNormalMethod = (params: {
44
+ builder: ScallopBuilder;
45
+ txBlock: SuiKitTxBlock;
46
+ }) => ReferralNormalMethods;
47
+
48
+ export type GenerateReferralQuickMethod = (params: {
49
+ builder: ScallopBuilder;
50
+ txBlock: SuiTxBlockWithReferralNormalMethods;
51
+ }) => ReferralQuickMethods;
@@ -29,6 +29,7 @@ export type VeScaNormalMethods = {
29
29
  newUnlockAtInSecondTimestamp: SuiTxArg
30
30
  ) => void;
31
31
  redeemSca: (veScaKey: SuiObjectArg) => TransactionResult;
32
+ mintEmptyVeSca: () => TransactionResult;
32
33
  };
33
34
 
34
35
  export type VeScaQuickMethods = {
@@ -7,6 +7,7 @@ import type {
7
7
  ScallopUtils,
8
8
  ScallopBuilder,
9
9
  } from '../models';
10
+ import { ScallopCache } from 'src/models/scallopCache';
10
11
 
11
12
  export type ScallopClientFnReturnType<T extends boolean> = T extends true
12
13
  ? SuiTransactionBlockResponse
@@ -18,6 +19,7 @@ export type ScallopInstanceParams = {
18
19
  query?: ScallopQuery;
19
20
  utils?: ScallopUtils;
20
21
  builder?: ScallopBuilder;
22
+ cache: ScallopCache;
21
23
  };
22
24
 
23
25
  export type ScallopAddressParams = {
@@ -16,24 +16,6 @@ export type BorrowIncentivePools = OptionalKeys<
16
16
  Record<SupportBorrowIncentiveCoins, BorrowIncentivePool>
17
17
  >;
18
18
 
19
- // export type BorrowIncentivePool = {
20
- // coinName: SupportBorrowIncentiveCoins;
21
- // symbol: string;
22
- // coinType: string;
23
- // rewardCoinType: string;
24
- // coinDecimal: number;
25
- // rewardCoinDecimal: number;
26
- // coinPrice: number;
27
- // rewardCoinPrice: number;
28
- // } & Required<
29
- // Pick<
30
- // ParsedBorrowIncentivePoolData,
31
- // 'maxPoints' | 'distributedPoint' | 'maxStake'
32
- // >
33
- // > &
34
- // CalculatedBorrowIncentivePoolData &
35
- // BorrowIncentiveRewardPool;
36
-
37
19
  export type BorrowIncentivePoolPoints = {
38
20
  symbol: string;
39
21
  coinName: SupportBorrowIncentiveRewardCoins;
@@ -60,21 +42,6 @@ export type BorrowIncentivePool = {
60
42
  >;
61
43
  };
62
44
 
63
- // export type OriginBorrowIncentivePoolData = {
64
- // created_at: string;
65
- // distributed_point: string;
66
- // distributed_point_per_period: string;
67
- // index: string;
68
- // last_update: string;
69
- // max_distributed_point: string;
70
- // max_stakes: string;
71
- // point_distribution_time: string;
72
- // pool_type: {
73
- // name: string;
74
- // };
75
- // stakes: string;
76
- // };
77
-
78
45
  export type OriginBorrowIncentivePoolPointData = {
79
46
  point_type: {
80
47
  name: string;
@@ -112,18 +79,6 @@ export type ParsedBorrowIncentivePoolPointData = {
112
79
  lastUpdate: number;
113
80
  };
114
81
 
115
- // export type ParsedBorrowIncentivePoolData = {
116
- // poolType: string;
117
- // maxPoint: number;
118
- // distributedPoint: number;
119
- // pointPerPeriod: number;
120
- // period: number;
121
- // maxStake: number;
122
- // staked: number;
123
- // index: number;
124
- // createdAt: number;
125
- // lastUpdate: number;
126
- // };
127
82
  export type ParsedBorrowIncentivePoolData = {
128
83
  poolType: string;
129
84
  poolPoints: OptionalKeys<
@@ -154,54 +109,10 @@ export type CalculatedBorrowIncentivePoolPointData = {
154
109
  rewardPerSec: number;
155
110
  };
156
111
 
157
- // export type BorrowIncentiveRewardPool = CalculatedBorrowIncentiveRewardPoolData;
158
-
159
- // export type OriginBorrowIncentiveRewardPoolData = {
160
- // claimed_rewards: string;
161
- // exchange_rate_denominator: string;
162
- // exchange_rate_numerator: string;
163
- // remaining_reward: string;
164
- // reward_type: {
165
- // name: string;
166
- // };
167
- // };
168
-
169
- // export type ParsedBorrowIncentiveRewardPoolData = {
170
- // rewardType: string;
171
- // claimedRewards: number;
172
- // exchangeRateDenominator: number;
173
- // exchangeRateNumerator: number;
174
- // remainingRewards: number;
175
- // };
176
-
177
- // export type CalculatedBorrowIncentiveRewardPoolData = {
178
- // rewardApr: number;
179
- // totalRewardAmount: number;
180
- // totalRewardCoin: number;
181
- // totalRewardValue: number;
182
- // // remaindRewardAmount: number;
183
- // // remaindRewardCoin: number;
184
- // // remaindRewardValue: number;
185
- // // claimedRewardAmount: number;
186
- // // claimedRewardCoin: number;
187
- // // claimedRewardValue: number;
188
- // rewardPerSec: number;
189
- // };
190
-
191
112
  export type BorrowIncentiveAccounts = OptionalKeys<
192
113
  Record<SupportBorrowIncentiveCoins, ParsedBorrowIncentiveAccountData>
193
114
  >;
194
115
 
195
- // export type OriginBorrowIncentiveAccountData = {
196
- // amount: string;
197
- // index: string;
198
- // points: string;
199
- // pool_type: {
200
- // name: string;
201
- // };
202
- // total_points: string;
203
- // };
204
-
205
116
  export type OriginBorrowIncentiveAccountPoolData = {
206
117
  point_type: {
207
118
  name: string;
@@ -220,14 +131,6 @@ export type OriginBorrowIncentiveAccountData = {
220
131
  debt_amount: string;
221
132
  };
222
133
 
223
- // export type ParsedBorrowIncentiveAccountData = {
224
- // poolType: string;
225
- // amount: number;
226
- // index: number;
227
- // points: number;
228
- // totalPoints: number;
229
- // };
230
-
231
134
  export type ParsedBorrowIncentiveAccountPoolData = {
232
135
  pointType: string;
233
136
  weightedAmount: number;
@@ -250,11 +153,6 @@ export type ParsedBorrowIncentiveAccountData = {
250
153
  /**
251
154
  * The query interface for `incentive_pools_query::incentive_pools_data` inspectTxn.
252
155
  */
253
- // export interface BorrowIncentivePoolsQueryInterface {
254
- // incentive_pools: OriginBorrowIncentivePoolData[];
255
- // reward_pool: OriginBorrowIncentiveRewardPoolData;
256
- // }
257
-
258
156
  export interface BorrowIncentivePoolsQueryInterface {
259
157
  incentive_pools: OriginBorrowIncentivePoolData[];
260
158
  }
@@ -262,11 +160,6 @@ export interface BorrowIncentivePoolsQueryInterface {
262
160
  /**
263
161
  * The query interface for `incentive_account_query::incentive_account_data` inspectTxn.
264
162
  */
265
- // export interface BorrowIncentiveAccountsQueryInterface {
266
- // incentive_states: OriginBorrowIncentiveAccountData[];
267
- // total_points: string;
268
- // }
269
-
270
163
  export interface BorrowIncentiveAccountsQueryInterface {
271
164
  pool_records: OriginBorrowIncentiveAccountData[];
272
165
  }