@scallop-io/sui-scallop-sdk 0.37.3

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 (47) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +276 -0
  3. package/dist/constants/common.d.ts +7 -0
  4. package/dist/constants/index.d.ts +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +1487 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +1444 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/models/index.d.ts +4 -0
  11. package/dist/models/scallop.d.ts +46 -0
  12. package/dist/models/scallopAddress.d.ts +107 -0
  13. package/dist/models/scallopClient.d.ts +151 -0
  14. package/dist/models/scallopUtils.d.ts +56 -0
  15. package/dist/queries/index.d.ts +2 -0
  16. package/dist/queries/market.d.ts +4 -0
  17. package/dist/queries/obligation.d.ts +8 -0
  18. package/dist/txBuilders/coin.d.ts +67 -0
  19. package/dist/txBuilders/index.d.ts +1 -0
  20. package/dist/txBuilders/normalMethods.d.ts +3 -0
  21. package/dist/txBuilders/oracle.d.ts +7 -0
  22. package/dist/txBuilders/quickMethods.d.ts +7 -0
  23. package/dist/types/data.d.ts +127 -0
  24. package/dist/types/index.d.ts +3 -0
  25. package/dist/types/model.d.ts +9 -0
  26. package/dist/types/txBuilder.d.ts +66 -0
  27. package/package.json +147 -0
  28. package/src/constants/common.ts +36 -0
  29. package/src/constants/index.ts +1 -0
  30. package/src/index.ts +3 -0
  31. package/src/models/index.ts +4 -0
  32. package/src/models/scallop.ts +76 -0
  33. package/src/models/scallopAddress.ts +460 -0
  34. package/src/models/scallopClient.ts +461 -0
  35. package/src/models/scallopUtils.ts +133 -0
  36. package/src/queries/index.ts +2 -0
  37. package/src/queries/market.ts +16 -0
  38. package/src/queries/obligation.ts +44 -0
  39. package/src/txBuilders/coin.ts +38 -0
  40. package/src/txBuilders/index.ts +1 -0
  41. package/src/txBuilders/normalMethods.ts +216 -0
  42. package/src/txBuilders/oracle.ts +376 -0
  43. package/src/txBuilders/quickMethods.ts +231 -0
  44. package/src/types/data.ts +170 -0
  45. package/src/types/index.ts +3 -0
  46. package/src/types/model.ts +15 -0
  47. package/src/types/txBuilder.ts +136 -0
@@ -0,0 +1,216 @@
1
+ import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js';
2
+ import { SuiTxBlock } from '@scallop-io/sui-kit';
3
+ import { ScallopAddress, ScallopUtils } from '../models';
4
+ import type {
5
+ ScallopNormalMethodsHandler,
6
+ SuiTxBlockWithNormalScallopMethods,
7
+ CoreIds,
8
+ } from '../types';
9
+
10
+ const scallopNormalMethodsHandler: ScallopNormalMethodsHandler = {
11
+ openObligation:
12
+ ({ txBlock, coreIds }) =>
13
+ () =>
14
+ txBlock.moveCall(
15
+ `${coreIds.protocolPkg}::open_obligation::open_obligation`,
16
+ [coreIds.version]
17
+ ),
18
+ returnObligation:
19
+ ({ txBlock, coreIds }) =>
20
+ (obligation, obligationHotPotato) =>
21
+ txBlock.moveCall(
22
+ `${coreIds.protocolPkg}::open_obligation::return_obligation`,
23
+ [coreIds.version, obligation, obligationHotPotato]
24
+ ),
25
+ openObligationEntry:
26
+ ({ txBlock, coreIds }) =>
27
+ () =>
28
+ txBlock.moveCall(
29
+ `${coreIds.protocolPkg}::open_obligation::open_obligation_entry`,
30
+ [coreIds.version]
31
+ ),
32
+ addCollateral:
33
+ ({ txBlock, coreIds, scallopUtils, scallopAddress }) =>
34
+ (obligation, coin, coinName) => {
35
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
36
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
37
+ return txBlock.moveCall(
38
+ `${coreIds.protocolPkg}::deposit_collateral::deposit_collateral`,
39
+ [coreIds.version, obligation, coreIds.market, coin],
40
+ [coinType]
41
+ );
42
+ },
43
+ takeCollateral:
44
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
45
+ (obligation, obligationKey, amount, coinName) => {
46
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
47
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
48
+ return txBlock.moveCall(
49
+ `${coreIds.protocolPkg}::withdraw_collateral::withdraw_collateral`,
50
+ [
51
+ coreIds.version,
52
+ obligation,
53
+ obligationKey,
54
+ coreIds.market,
55
+ coreIds.dmlR,
56
+ amount,
57
+ coreIds.oracle,
58
+ SUI_CLOCK_OBJECT_ID,
59
+ ],
60
+ [coinType]
61
+ );
62
+ },
63
+ deposit:
64
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
65
+ (coin, coinName) => {
66
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
67
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
68
+ return txBlock.moveCall(
69
+ `${coreIds.protocolPkg}::mint::mint`,
70
+ [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],
71
+ [coinType]
72
+ );
73
+ },
74
+ depositEntry:
75
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
76
+ (coin, coinName) => {
77
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
78
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
79
+ return txBlock.moveCall(
80
+ `${coreIds.protocolPkg}::mint::mint_entry`,
81
+ [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],
82
+ [coinType]
83
+ );
84
+ },
85
+ withdraw:
86
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
87
+ (marketCoin, coinName) => {
88
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
89
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
90
+ return txBlock.moveCall(
91
+ `${coreIds.protocolPkg}::redeem::redeem`,
92
+ [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],
93
+ [coinType]
94
+ );
95
+ },
96
+ withdrawEntry:
97
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
98
+ (marketCoin, coinName) => {
99
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
100
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
101
+ return txBlock.moveCall(
102
+ `${coreIds.protocolPkg}::redeem::redeem_entry`,
103
+ [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],
104
+ [coinType]
105
+ );
106
+ },
107
+ borrow:
108
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
109
+ (obligation, obligationKey, amount, coinName) => {
110
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
111
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
112
+ return txBlock.moveCall(
113
+ `${coreIds.protocolPkg}::borrow::borrow`,
114
+ [
115
+ coreIds.version,
116
+ obligation,
117
+ obligationKey,
118
+ coreIds.market,
119
+ coreIds.dmlR,
120
+ amount,
121
+ coreIds.oracle,
122
+ SUI_CLOCK_OBJECT_ID,
123
+ ],
124
+ [coinType]
125
+ );
126
+ },
127
+ borrowEntry:
128
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
129
+ (obligation, obligationKey, amount, coinName) => {
130
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
131
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
132
+ return txBlock.moveCall(
133
+ `${coreIds.protocolPkg}::borrow::borrow_entry`,
134
+ [
135
+ coreIds.version,
136
+ obligation,
137
+ obligationKey,
138
+ coreIds.market,
139
+ coreIds.dmlR,
140
+ amount,
141
+ coreIds.oracle,
142
+ SUI_CLOCK_OBJECT_ID,
143
+ ],
144
+ [coinType]
145
+ );
146
+ },
147
+ repay:
148
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
149
+ (obligation, coin, coinName) => {
150
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
151
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
152
+ return txBlock.moveCall(
153
+ `${coreIds.protocolPkg}::repay::repay`,
154
+ [
155
+ coreIds.version,
156
+ obligation,
157
+ coreIds.market,
158
+ coin,
159
+ SUI_CLOCK_OBJECT_ID,
160
+ ],
161
+ [coinType]
162
+ );
163
+ },
164
+ borrowFlashLoan:
165
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
166
+ (amount, coinName) => {
167
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
168
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
169
+ return txBlock.moveCall(
170
+ `${coreIds.protocolPkg}::flash_loan::borrow_flash_loan`,
171
+ [coreIds.version, coreIds.market, amount],
172
+ [coinType]
173
+ );
174
+ },
175
+ repayFlashLoan:
176
+ ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>
177
+ (coin, loan, coinName) => {
178
+ const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
179
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
180
+ return txBlock.moveCall(
181
+ `${coreIds.protocolPkg}::flash_loan::repay_flash_loan`,
182
+ [coreIds.version, coreIds.market, coin, loan],
183
+ [coinType]
184
+ );
185
+ },
186
+ };
187
+
188
+ export const newTxBlock = (
189
+ scallopAddress: ScallopAddress,
190
+ scallopUtils: ScallopUtils
191
+ ) => {
192
+ const coreIds: CoreIds = {
193
+ protocolPkg: scallopAddress.get('core.packages.protocol.id'),
194
+ market: scallopAddress.get('core.market'),
195
+ version: scallopAddress.get('core.version'),
196
+ dmlR: scallopAddress.get('core.coinDecimalsRegistry'),
197
+ oracle: scallopAddress.get('core.oracles.xOracle'),
198
+ };
199
+ const txBlock = new SuiTxBlock();
200
+ const txBlockProxy = new Proxy(txBlock, {
201
+ get: (target, prop) => {
202
+ if (prop in scallopNormalMethodsHandler) {
203
+ return scallopNormalMethodsHandler[
204
+ prop as keyof ScallopNormalMethodsHandler
205
+ ]({
206
+ txBlock: target,
207
+ coreIds,
208
+ scallopAddress,
209
+ scallopUtils,
210
+ });
211
+ }
212
+ return target[prop as keyof SuiTxBlock];
213
+ },
214
+ });
215
+ return txBlockProxy as SuiTxBlockWithNormalScallopMethods;
216
+ };
@@ -0,0 +1,376 @@
1
+ import { fromB64 } from '@mysten/bcs';
2
+ import { SUI_CLOCK_OBJECT_ID, TransactionArgument } from '@mysten/sui.js';
3
+ import { SuiTxBlock, SuiKit } from '@scallop-io/sui-kit';
4
+ import { ScallopAddress, ScallopUtils } from '../models';
5
+ import { SupportCoins, SupportAssetCoins, SupportOracleType } from '../types';
6
+ import { queryObligation } from '../queries';
7
+
8
+ export const updateOraclesForWithdrawCollateral = async (
9
+ txBlock: SuiTxBlock,
10
+ address: ScallopAddress,
11
+ scallopUtils: ScallopUtils,
12
+ suiKit: SuiKit,
13
+ obligationId: string,
14
+ isTestnet: boolean
15
+ ) => {
16
+ const obligationCoinNames = await getObligationCoinNames(
17
+ suiKit,
18
+ obligationId,
19
+ address,
20
+ scallopUtils
21
+ );
22
+ return updateOracles(
23
+ txBlock,
24
+ address,
25
+ scallopUtils,
26
+ obligationCoinNames,
27
+ isTestnet
28
+ );
29
+ };
30
+
31
+ export const updateOraclesForLiquidation = async (
32
+ txBlock: SuiTxBlock,
33
+ address: ScallopAddress,
34
+ scallopUtils: ScallopUtils,
35
+ suiKit: SuiKit,
36
+ obligationId: string,
37
+ isTestnet: boolean
38
+ ) => {
39
+ const obligationCoinNames = await getObligationCoinNames(
40
+ suiKit,
41
+ obligationId,
42
+ address,
43
+ scallopUtils
44
+ );
45
+ return updateOracles(
46
+ txBlock,
47
+ address,
48
+ scallopUtils,
49
+ obligationCoinNames,
50
+ isTestnet
51
+ );
52
+ };
53
+
54
+ export const updateOraclesForBorrow = async (
55
+ txBlock: SuiTxBlock,
56
+ address: ScallopAddress,
57
+ scallopUtils: ScallopUtils,
58
+ suiKit: SuiKit,
59
+ obligationId: string,
60
+ borrowCoinName: SupportAssetCoins,
61
+ isTestnet: boolean
62
+ ) => {
63
+ const obligationCoinNames = await getObligationCoinNames(
64
+ suiKit,
65
+ obligationId,
66
+ address,
67
+ scallopUtils
68
+ );
69
+ const updateCoinNames = [
70
+ ...new Set([...obligationCoinNames, borrowCoinName]),
71
+ ];
72
+ return updateOracles(
73
+ txBlock,
74
+ address,
75
+ scallopUtils,
76
+ updateCoinNames,
77
+ isTestnet
78
+ );
79
+ };
80
+
81
+ const getObligationCoinNames = async (
82
+ suiKit: SuiKit,
83
+ obligationId: string,
84
+ address: ScallopAddress,
85
+ scallopUtils: ScallopUtils
86
+ ) => {
87
+ const obligation = await queryObligation(obligationId, address, suiKit);
88
+ const collateralCoinTypes = obligation.collaterals.map((collateral) => {
89
+ return `0x${collateral.type.name}`;
90
+ });
91
+ const debtCoinTypes = obligation.debts.map((debt) => {
92
+ return `0x${debt.type.name}`;
93
+ });
94
+ const obligationCoinTypes = [
95
+ ...new Set([...collateralCoinTypes, ...debtCoinTypes]),
96
+ ];
97
+ const obligationCoinNames = obligationCoinTypes.map((coinType) => {
98
+ return scallopUtils.getCoinNameFromCoinType(coinType);
99
+ });
100
+ return obligationCoinNames;
101
+ };
102
+
103
+ export const updateOracles = async (
104
+ txBlock: SuiTxBlock,
105
+ address: ScallopAddress,
106
+ scallopUtils: ScallopUtils,
107
+ coinNames: SupportCoins[],
108
+ isTestnet: boolean
109
+ ) => {
110
+ const updateCoinTypes = [...new Set(coinNames)];
111
+ for (const coinName of updateCoinTypes) {
112
+ await updateOracle(txBlock, address, scallopUtils, coinName, isTestnet);
113
+ }
114
+ };
115
+
116
+ const updateOracle = async (
117
+ txBlock: SuiTxBlock,
118
+ address: ScallopAddress,
119
+ scallopUtils: ScallopUtils,
120
+ coinName: SupportCoins,
121
+ isTestnet: boolean
122
+ ) => {
123
+ const coinPackageId = address.get(`core.coins.${coinName}.id`);
124
+ const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
125
+ const [vaaFromFeeId] = await scallopUtils.getVaas(
126
+ [address.get(`core.coins.${coinName}.oracle.pyth.feed`)],
127
+ isTestnet
128
+ );
129
+
130
+ updatePrice(
131
+ txBlock,
132
+ isTestnet ? ['pyth'] : ['pyth'],
133
+ address.get('core.packages.xOracle.id'),
134
+ address.get('core.oracles.xOracle'),
135
+ address.get('core.packages.pyth.id'),
136
+ address.get('core.oracles.pyth.registry'),
137
+ address.get('core.oracles.pyth.state'),
138
+ address.get('core.oracles.pyth.wormholeState'),
139
+ address.get(`core.coins.${coinName}.oracle.pyth.feedObject`),
140
+ vaaFromFeeId,
141
+ address.get('core.packages.switchboard.id'),
142
+ address.get('core.oracles.switchboard.registry'),
143
+ address.get(`core.coins.${coinName}.oracle.switchboard`),
144
+ address.get('core.packages.supra.id'),
145
+ address.get('core.oracles.supra.registry'),
146
+ address.get(`core.oracles.supra.holder`),
147
+ coinType
148
+ );
149
+ };
150
+
151
+ /**
152
+ * Construct a transaction block for update the price.
153
+ *
154
+ * @param txBlock - The transaction block.
155
+ * @param rules - The oracle rules.
156
+ * @param xOraclePackageId - The xOracle package id.
157
+ * @param xOracleId - The xOracle Id from xOracle package.
158
+ * @param pythPackageId - The pyth package id.
159
+ * @param pythRegistryId - The registry id from pyth package.
160
+ * @param pythStateId - The price state id from pyth package.
161
+ * @param pythWormholeStateId - The whormhole state id from pyth package.
162
+ * @param pythFeedObjectId - The feed object id from pyth package.
163
+ * @param pythVaaFromFeeId - The vaa from pyth api with feed id.
164
+ * @param switchboardPackageId - The switchboard package id.
165
+ * @param switchboardRegistryId - The registry id from switchboard package.
166
+ * @param switchboardAggregatorId - The aggregator id from switchboard package.
167
+ * @param supraPackageId - The supra package id.
168
+ * @param supraRegistryId - The registry id from supra package.
169
+ * @param supraHolderId - The holder id from supra package.
170
+ * @param coinType - The type of coin.
171
+ * @returns Sui-Kit type transaction block.
172
+ */
173
+ function updatePrice(
174
+ txBlock: SuiTxBlock,
175
+ rules: SupportOracleType[],
176
+ xOraclePackageId: string,
177
+ xOracleId: TransactionArgument | string,
178
+ pythPackageId: string,
179
+ pythRegistryId: TransactionArgument | string,
180
+ pythStateId: TransactionArgument | string,
181
+ pythWormholeStateId: TransactionArgument | string,
182
+ pythFeedObjectId: TransactionArgument | string,
183
+ pythVaaFromFeeId: string,
184
+ switchboardPackageId: string,
185
+ switchboardRegistryId: TransactionArgument | string,
186
+ switchboardAggregatorId: TransactionArgument | string,
187
+ supraPackageId: string,
188
+ supraRegistryId: TransactionArgument | string,
189
+ supraHolderId: TransactionArgument | string,
190
+ coinType: string
191
+ ) {
192
+ const request = priceUpdateRequest(
193
+ txBlock,
194
+ xOraclePackageId,
195
+ xOracleId,
196
+ coinType
197
+ );
198
+ if (rules.includes('pyth')) {
199
+ updatePythPrice(
200
+ txBlock,
201
+ pythPackageId,
202
+ request,
203
+ pythStateId,
204
+ pythWormholeStateId,
205
+ pythFeedObjectId,
206
+ pythVaaFromFeeId,
207
+ pythRegistryId,
208
+ coinType
209
+ );
210
+ }
211
+ if (rules.includes('switchboard')) {
212
+ updateSwitchboardPrice(
213
+ txBlock,
214
+ switchboardPackageId,
215
+ request,
216
+ switchboardAggregatorId,
217
+ switchboardRegistryId,
218
+ coinType
219
+ );
220
+ }
221
+ if (rules.includes('supra')) {
222
+ updateSupraPrice(
223
+ txBlock,
224
+ supraPackageId,
225
+ request,
226
+ supraHolderId,
227
+ supraRegistryId,
228
+ coinType
229
+ );
230
+ }
231
+ confirmPriceUpdateRequest(
232
+ txBlock,
233
+ xOraclePackageId,
234
+ xOracleId,
235
+ request,
236
+ coinType
237
+ );
238
+ return txBlock;
239
+ }
240
+
241
+ /**
242
+ * Construct a transaction block for request price update.
243
+ *
244
+ * @param txBlock - The transaction block.
245
+ * @param packageId - The xOracle package id.
246
+ * @param xOracleId - The xOracle Id from xOracle package.
247
+ * @param coinType - The type of coin.
248
+ * @returns Sui-Kit type transaction block.
249
+ */
250
+ function priceUpdateRequest(
251
+ txBlock: SuiTxBlock,
252
+ packageId: string,
253
+ xOracleId: TransactionArgument | string,
254
+ coinType: string
255
+ ) {
256
+ const target = `${packageId}::x_oracle::price_update_request`;
257
+ const typeArgs = [coinType];
258
+ return txBlock.moveCall(target, [xOracleId], typeArgs);
259
+ }
260
+
261
+ /**
262
+ * Construct a transaction block for confirm price update request.
263
+ *
264
+ * @param txBlock - The transaction block.
265
+ * @param packageId - The xOracle package id.
266
+ * @param xOracleId - The xOracle Id from xOracle package.
267
+ * @param request - The result of the request.
268
+ * @param coinType - The type of coin.
269
+ * @returns Sui-Kit type transaction block.
270
+ */
271
+ function confirmPriceUpdateRequest(
272
+ txBlock: SuiTxBlock,
273
+ packageId: string,
274
+ xOracleId: TransactionArgument | string,
275
+ request: TransactionArgument,
276
+ coinType: string
277
+ ) {
278
+ const target = `${packageId}::x_oracle::confirm_price_update_request`;
279
+ const typeArgs = [coinType];
280
+ txBlock.moveCall(target, [xOracleId, request, SUI_CLOCK_OBJECT_ID], typeArgs);
281
+ return txBlock;
282
+ }
283
+
284
+ /**
285
+ * Construct a transaction block for update supra price.
286
+ *
287
+ * @param txBlock - The transaction block.
288
+ * @param packageId - The supra package id.
289
+ * @param request - The result of the request.
290
+ * @param holderId - The holder id from supra package.
291
+ * @param registryId - The registry id from supra package.
292
+ * @param coinType - The type of coin.
293
+ * @returns Sui-Kit type transaction block.
294
+ */
295
+ function updateSupraPrice(
296
+ txBlock: SuiTxBlock,
297
+ packageId: string,
298
+ request: TransactionArgument,
299
+ holderId: TransactionArgument | string,
300
+ registryId: TransactionArgument | string,
301
+ coinType: string
302
+ ) {
303
+ txBlock.moveCall(
304
+ `${packageId}::rule::set_price`,
305
+ [request, holderId, registryId, SUI_CLOCK_OBJECT_ID],
306
+ [coinType]
307
+ );
308
+ }
309
+
310
+ /**
311
+ * Construct a transaction block for update switchboard price.
312
+ *
313
+ * @param txBlock - The transaction block.
314
+ * @param packageId - The switchboard package id.
315
+ * @param request - The result of the request.
316
+ * @param aggregatorId - The aggregator id from switchboard package.
317
+ * @param registryId - The registry id from switchboard package.
318
+ * @param coinType - The type of coin.
319
+ * @returns Sui-Kit type transaction block.
320
+ */
321
+ function updateSwitchboardPrice(
322
+ txBlock: SuiTxBlock,
323
+ packageId: string,
324
+ request: TransactionArgument,
325
+ aggregatorId: TransactionArgument | string,
326
+ registryId: TransactionArgument | string,
327
+ coinType: string
328
+ ) {
329
+ txBlock.moveCall(
330
+ `${packageId}::rule::set_price`,
331
+ [request, aggregatorId, registryId, SUI_CLOCK_OBJECT_ID],
332
+ [coinType]
333
+ );
334
+ }
335
+
336
+ /**
337
+ * Construct a transaction block for update pyth price.
338
+ *
339
+ * @param txBlock - The transaction block.
340
+ * @param packageId - The pyth package id.
341
+ * @param request - The result of the request.
342
+ * @param stateId - The price state id from pyth package.
343
+ * @param wormholeStateId - The whormhole state id from pyth package.
344
+ * @param feedObjectId - The feed object id from pyth package.
345
+ * @param vaaFromFeeId - The vaa from pyth api with feed id.
346
+ * @param registryId - The registry id from pyth package.
347
+ * @param coinType - The type of coin.
348
+ * @returns Sui-Kit type transaction block.
349
+ */
350
+ function updatePythPrice(
351
+ txBlock: SuiTxBlock,
352
+ packageId: string,
353
+ request: TransactionArgument,
354
+ stateId: TransactionArgument | string,
355
+ wormholeStateId: TransactionArgument | string,
356
+ feedObjectId: TransactionArgument | string,
357
+ vaaFromFeeId: string,
358
+ registryId: TransactionArgument | string,
359
+ coinType: string
360
+ ) {
361
+ const [updateFee] = txBlock.splitSUIFromGas([1]);
362
+ txBlock.moveCall(
363
+ `${packageId}::rule::set_price`,
364
+ [
365
+ request,
366
+ wormholeStateId,
367
+ stateId,
368
+ feedObjectId,
369
+ registryId,
370
+ txBlock.pure([...fromB64(vaaFromFeeId)]),
371
+ updateFee,
372
+ SUI_CLOCK_OBJECT_ID,
373
+ ],
374
+ [coinType]
375
+ );
376
+ }