@msafe/sui3-sdk 0.0.75 → 0.0.77

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/index.cjs CHANGED
@@ -192,109 +192,47 @@ var import_wallet_standard = require("@mysten/wallet-standard");
192
192
  // src/simulate/simulator.ts
193
193
  var import_transactions = require("@mysten/sui.js/transactions");
194
194
  var GAS_SAFE_OVERHEAD = 1000n;
195
- var DEF_GAS_PRICE_NUM = 120n;
196
- var DEF_GAS_PRICE_DEN = 100n;
197
- var DEF_GAS_PRICE_OPTION = {
198
- multiplier: {
199
- numerator: DEF_GAS_PRICE_NUM,
200
- denominator: DEF_GAS_PRICE_DEN
201
- }
202
- };
203
- var DEF_GAS_BUDGET_NUM = 120n;
204
- var DEF_GAS_BUDGET_DEN = 100n;
205
- var DEF_GAS_BUDGET_OPTION = {
206
- multiplier: {
207
- numerator: DEF_GAS_BUDGET_NUM,
208
- denominator: DEF_GAS_BUDGET_DEN
209
- }
210
- };
211
195
  var Simulator = class {
212
196
  constructor(globals) {
213
197
  this.globals = globals;
214
198
  }
215
- async simulate(input, gasOption = DEF_GAS_PRICE_OPTION, budgetOption = DEF_GAS_BUDGET_OPTION) {
199
+ async simulate(input) {
216
200
  const tx = this.copyTransactionBlock(input.txb);
217
201
  const { suiClient } = this.globals;
218
- const gasPrice = await this.getGasPrice(gasOption);
219
- try {
220
- const inspectResult = await suiClient.dryRunTransactionBlock({
221
- transactionBlock: await tx.build({ client: suiClient })
222
- });
223
- const { gasUsed } = inspectResult.effects;
224
- const gasBudget = this.toGasBudget(gasUsed, gasPrice);
225
- const success = inspectResult.effects.status.status === "success";
226
- let error;
227
- if (!success) {
228
- error = inspectResult.effects.status.error;
229
- }
202
+ const gasPrice = await this.getGasPrice();
203
+ tx.setGasPrice(gasPrice);
204
+ const inspectResult = await suiClient.dryRunTransactionBlock({
205
+ transactionBlock: await tx.build({ client: suiClient })
206
+ });
207
+ const success = inspectResult.effects.status.status === "success";
208
+ if (!success) {
230
209
  return {
231
210
  success,
232
211
  gasPrice,
233
- gasObject: inspectResult.effects.gasObject.reference,
234
- gasUsed,
235
- gasBudget: this.applyBudgetOption(gasBudget, budgetOption),
236
- simulationError: error,
237
- response: inspectResult
212
+ response: inspectResult,
213
+ simulationError: inspectResult.effects.status.error
238
214
  };
239
- } catch (err) {
240
- if (err instanceof Error) {
241
- return {
242
- success: false,
243
- gasObject: { digest: "", objectId: "", version: "" },
244
- gasPrice: 0n,
245
- gasBudget: 0n,
246
- gasUsed: {
247
- computationCost: "",
248
- nonRefundableStorageFee: "",
249
- storageCost: "",
250
- storageRebate: ""
251
- },
252
- simulationError: err.message
253
- };
254
- }
255
- throw err;
256
215
  }
216
+ const gasBudget = this.toGasBudget(inspectResult.effects.gasUsed, gasPrice);
217
+ return {
218
+ success,
219
+ gasPrice,
220
+ gasObject: inspectResult.effects.gasObject.reference,
221
+ gasUsed: inspectResult.effects.gasUsed,
222
+ gasBudget,
223
+ response: inspectResult
224
+ };
257
225
  }
258
- async getGasPrice(option) {
259
- if (this.isFixedValue(option)) {
260
- return option.fixedVal;
261
- }
262
- const refGasPrice = await this.globals.suiClient.getReferenceGasPrice();
263
- return this.applyGasOption(refGasPrice, option);
226
+ async getGasPrice() {
227
+ return this.globals.suiClient.getReferenceGasPrice();
264
228
  }
265
229
  toGasBudget(gasUsed, gasPrice) {
266
- const { computationCost, storageCost } = gasUsed;
230
+ const { computationCost, storageCost, storageRebate } = gasUsed;
267
231
  const safeOverhead = GAS_SAFE_OVERHEAD * gasPrice;
268
232
  const baseComputationCostWithOverhead = BigInt(computationCost) + safeOverhead;
269
- const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost);
233
+ const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
270
234
  return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
271
235
  }
272
- isFixedValue(option) {
273
- return "fixedVal" in option;
274
- }
275
- isMultiplier(option) {
276
- return "multiplier" in option;
277
- }
278
- applyGasOption(val, option) {
279
- if (this.isFixedValue(option)) {
280
- return option.fixedVal;
281
- }
282
- if (this.isMultiplier(option)) {
283
- const { multiplier } = option;
284
- return val * multiplier.numerator / multiplier.denominator;
285
- }
286
- throw new Error("Sanity: Unknown gas price option");
287
- }
288
- applyBudgetOption(val, option) {
289
- if (this.isFixedValue(option)) {
290
- return option.fixedVal;
291
- }
292
- if (this.isMultiplier(option)) {
293
- const { multiplier } = option;
294
- return val * multiplier.numerator / multiplier.denominator;
295
- }
296
- throw new Error("Sanity: Unknown gas budget option");
297
- }
298
236
  copyTransactionBlock(tx) {
299
237
  return import_transactions.TransactionBlock.from(tx.serialize());
300
238
  }
@@ -1251,7 +1189,8 @@ var BackendImpl = class _BackendImpl {
1251
1189
  await this.post(`/transaction/pending/skip`, input, { headers: this.headers() });
1252
1190
  }
1253
1191
  async fetchTransaction(input) {
1254
- await this.post(`/transaction/fetch`, input, { headers: this.headers() });
1192
+ const res = await this.post(`/transaction/fetch`, input, { headers: this.headers() });
1193
+ return res.data;
1255
1194
  }
1256
1195
  async getAddressBookEntries(pagination) {
1257
1196
  const res = await this.get(`/address-book`, {