@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 +25 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -23
- package/dist/index.d.ts +14 -23
- package/dist/index.js +25 -86
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/backend/BackendImpl.ts +3 -2
- package/src/backend/interface.ts +1 -1
- package/src/simulate/simulator.ts +23 -123
- package/src/types/msafe.ts +12 -4
package/dist/index.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ interface IBackend {
|
|
|
67
67
|
getNextIntention(input: IMSafeAddressRequest): Promise<TransactionIntentionItem>;
|
|
68
68
|
getCurrentSequenceNumber(address: string): Promise<number>;
|
|
69
69
|
getNextSequenceNumber(address: string): Promise<number>;
|
|
70
|
-
fetchTransaction(input: IMSafeAddressRequest): Promise<
|
|
70
|
+
fetchTransaction(input: IMSafeAddressRequest): Promise<string[]>;
|
|
71
71
|
createMSafeAccount(input: ICreateMSafeReq): Promise<void>;
|
|
72
72
|
proposeIntention(input: IProposeIntentionRequest): Promise<void>;
|
|
73
73
|
rejectCurrentTx(input: IRejectTransactionRequest): Promise<void>;
|
|
@@ -245,14 +245,20 @@ interface ProposeIntention {
|
|
|
245
245
|
msafeAddress: string;
|
|
246
246
|
signature: SerializedSignature;
|
|
247
247
|
}
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
type SimulationResult = SimulationSuccessResult | SimulationFailedResult;
|
|
249
|
+
interface SimulationSuccessResult {
|
|
250
|
+
success: true;
|
|
250
251
|
gasPrice: bigint;
|
|
251
252
|
gasUsed: GasCostSummary;
|
|
252
253
|
gasBudget: bigint;
|
|
253
254
|
gasObject: SuiObjectRef;
|
|
254
|
-
|
|
255
|
-
|
|
255
|
+
response: DryRunTransactionBlockResponse;
|
|
256
|
+
}
|
|
257
|
+
interface SimulationFailedResult {
|
|
258
|
+
success: false;
|
|
259
|
+
gasPrice: bigint;
|
|
260
|
+
response: DryRunTransactionBlockResponse;
|
|
261
|
+
simulationError: string;
|
|
256
262
|
}
|
|
257
263
|
interface SimulationOption extends IGasOption {
|
|
258
264
|
simulation: boolean;
|
|
@@ -310,30 +316,15 @@ declare class InvitationSDK {
|
|
|
310
316
|
updateMSafeStatus(msafeAddress: string, status: UserMSafeStatus): Promise<void>;
|
|
311
317
|
}
|
|
312
318
|
|
|
313
|
-
type GasPriceOption = MultiplierOption | FixedValueOption;
|
|
314
|
-
type GasBudgetOption = MultiplierOption | FixedValueOption;
|
|
315
|
-
interface MultiplierOption {
|
|
316
|
-
multiplier: {
|
|
317
|
-
numerator: bigint;
|
|
318
|
-
denominator: bigint;
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
interface FixedValueOption {
|
|
322
|
-
fixedVal: bigint;
|
|
323
|
-
}
|
|
324
319
|
declare class Simulator {
|
|
325
320
|
private globals;
|
|
326
321
|
constructor(globals: MSafeGlobals);
|
|
327
322
|
simulate(input: {
|
|
328
323
|
txb: TransactionBlock;
|
|
329
324
|
sender: string;
|
|
330
|
-
}
|
|
325
|
+
}): Promise<SimulationResult>;
|
|
331
326
|
private getGasPrice;
|
|
332
327
|
private toGasBudget;
|
|
333
|
-
private isFixedValue;
|
|
334
|
-
private isMultiplier;
|
|
335
|
-
private applyGasOption;
|
|
336
|
-
private applyBudgetOption;
|
|
337
328
|
private copyTransactionBlock;
|
|
338
329
|
}
|
|
339
330
|
|
|
@@ -384,7 +375,7 @@ declare class MSafeAccount {
|
|
|
384
375
|
forceBuild: boolean;
|
|
385
376
|
}): Promise<void>;
|
|
386
377
|
skipNextFailedIntention(): Promise<void>;
|
|
387
|
-
fetchTransaction(): Promise<
|
|
378
|
+
fetchTransaction(): Promise<string[]>;
|
|
388
379
|
executePendingTx(pending: PendingTx, isRejectTx?: boolean): Promise<_mysten_sui_js_client.SuiTransactionBlockResponse>;
|
|
389
380
|
dashboard(): Promise<_msafe_sui3_utils.IGetDashboardResp>;
|
|
390
381
|
private calculateWeightFromVotes;
|
|
@@ -492,4 +483,4 @@ declare class Coin {
|
|
|
492
483
|
static getBalance(data: SuiObjectData): bigint | undefined;
|
|
493
484
|
}
|
|
494
485
|
|
|
495
|
-
export { AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulationOption, type SimulationResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
|
486
|
+
export { AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulationFailedResult, type SimulationOption, type SimulationResult, type SimulationSuccessResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
|
package/dist/index.js
CHANGED
|
@@ -140,109 +140,47 @@ import { SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN } from "@mysten/wallet-standard";
|
|
|
140
140
|
// src/simulate/simulator.ts
|
|
141
141
|
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
142
142
|
var GAS_SAFE_OVERHEAD = 1000n;
|
|
143
|
-
var DEF_GAS_PRICE_NUM = 120n;
|
|
144
|
-
var DEF_GAS_PRICE_DEN = 100n;
|
|
145
|
-
var DEF_GAS_PRICE_OPTION = {
|
|
146
|
-
multiplier: {
|
|
147
|
-
numerator: DEF_GAS_PRICE_NUM,
|
|
148
|
-
denominator: DEF_GAS_PRICE_DEN
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
var DEF_GAS_BUDGET_NUM = 120n;
|
|
152
|
-
var DEF_GAS_BUDGET_DEN = 100n;
|
|
153
|
-
var DEF_GAS_BUDGET_OPTION = {
|
|
154
|
-
multiplier: {
|
|
155
|
-
numerator: DEF_GAS_BUDGET_NUM,
|
|
156
|
-
denominator: DEF_GAS_BUDGET_DEN
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
143
|
var Simulator = class {
|
|
160
144
|
constructor(globals) {
|
|
161
145
|
this.globals = globals;
|
|
162
146
|
}
|
|
163
|
-
async simulate(input
|
|
147
|
+
async simulate(input) {
|
|
164
148
|
const tx = this.copyTransactionBlock(input.txb);
|
|
165
149
|
const { suiClient } = this.globals;
|
|
166
|
-
const gasPrice = await this.getGasPrice(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const success = inspectResult.effects.status.status === "success";
|
|
174
|
-
let error;
|
|
175
|
-
if (!success) {
|
|
176
|
-
error = inspectResult.effects.status.error;
|
|
177
|
-
}
|
|
150
|
+
const gasPrice = await this.getGasPrice();
|
|
151
|
+
tx.setGasPrice(gasPrice);
|
|
152
|
+
const inspectResult = await suiClient.dryRunTransactionBlock({
|
|
153
|
+
transactionBlock: await tx.build({ client: suiClient })
|
|
154
|
+
});
|
|
155
|
+
const success = inspectResult.effects.status.status === "success";
|
|
156
|
+
if (!success) {
|
|
178
157
|
return {
|
|
179
158
|
success,
|
|
180
159
|
gasPrice,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
gasBudget: this.applyBudgetOption(gasBudget, budgetOption),
|
|
184
|
-
simulationError: error,
|
|
185
|
-
response: inspectResult
|
|
160
|
+
response: inspectResult,
|
|
161
|
+
simulationError: inspectResult.effects.status.error
|
|
186
162
|
};
|
|
187
|
-
} catch (err) {
|
|
188
|
-
if (err instanceof Error) {
|
|
189
|
-
return {
|
|
190
|
-
success: false,
|
|
191
|
-
gasObject: { digest: "", objectId: "", version: "" },
|
|
192
|
-
gasPrice: 0n,
|
|
193
|
-
gasBudget: 0n,
|
|
194
|
-
gasUsed: {
|
|
195
|
-
computationCost: "",
|
|
196
|
-
nonRefundableStorageFee: "",
|
|
197
|
-
storageCost: "",
|
|
198
|
-
storageRebate: ""
|
|
199
|
-
},
|
|
200
|
-
simulationError: err.message
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
throw err;
|
|
204
163
|
}
|
|
164
|
+
const gasBudget = this.toGasBudget(inspectResult.effects.gasUsed, gasPrice);
|
|
165
|
+
return {
|
|
166
|
+
success,
|
|
167
|
+
gasPrice,
|
|
168
|
+
gasObject: inspectResult.effects.gasObject.reference,
|
|
169
|
+
gasUsed: inspectResult.effects.gasUsed,
|
|
170
|
+
gasBudget,
|
|
171
|
+
response: inspectResult
|
|
172
|
+
};
|
|
205
173
|
}
|
|
206
|
-
async getGasPrice(
|
|
207
|
-
|
|
208
|
-
return option.fixedVal;
|
|
209
|
-
}
|
|
210
|
-
const refGasPrice = await this.globals.suiClient.getReferenceGasPrice();
|
|
211
|
-
return this.applyGasOption(refGasPrice, option);
|
|
174
|
+
async getGasPrice() {
|
|
175
|
+
return this.globals.suiClient.getReferenceGasPrice();
|
|
212
176
|
}
|
|
213
177
|
toGasBudget(gasUsed, gasPrice) {
|
|
214
|
-
const { computationCost, storageCost } = gasUsed;
|
|
178
|
+
const { computationCost, storageCost, storageRebate } = gasUsed;
|
|
215
179
|
const safeOverhead = GAS_SAFE_OVERHEAD * gasPrice;
|
|
216
180
|
const baseComputationCostWithOverhead = BigInt(computationCost) + safeOverhead;
|
|
217
|
-
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost);
|
|
181
|
+
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
|
|
218
182
|
return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
|
|
219
183
|
}
|
|
220
|
-
isFixedValue(option) {
|
|
221
|
-
return "fixedVal" in option;
|
|
222
|
-
}
|
|
223
|
-
isMultiplier(option) {
|
|
224
|
-
return "multiplier" in option;
|
|
225
|
-
}
|
|
226
|
-
applyGasOption(val, option) {
|
|
227
|
-
if (this.isFixedValue(option)) {
|
|
228
|
-
return option.fixedVal;
|
|
229
|
-
}
|
|
230
|
-
if (this.isMultiplier(option)) {
|
|
231
|
-
const { multiplier } = option;
|
|
232
|
-
return val * multiplier.numerator / multiplier.denominator;
|
|
233
|
-
}
|
|
234
|
-
throw new Error("Sanity: Unknown gas price option");
|
|
235
|
-
}
|
|
236
|
-
applyBudgetOption(val, option) {
|
|
237
|
-
if (this.isFixedValue(option)) {
|
|
238
|
-
return option.fixedVal;
|
|
239
|
-
}
|
|
240
|
-
if (this.isMultiplier(option)) {
|
|
241
|
-
const { multiplier } = option;
|
|
242
|
-
return val * multiplier.numerator / multiplier.denominator;
|
|
243
|
-
}
|
|
244
|
-
throw new Error("Sanity: Unknown gas budget option");
|
|
245
|
-
}
|
|
246
184
|
copyTransactionBlock(tx) {
|
|
247
185
|
return TransactionBlock.from(tx.serialize());
|
|
248
186
|
}
|
|
@@ -1202,7 +1140,8 @@ var BackendImpl = class _BackendImpl {
|
|
|
1202
1140
|
await this.post(`/transaction/pending/skip`, input, { headers: this.headers() });
|
|
1203
1141
|
}
|
|
1204
1142
|
async fetchTransaction(input) {
|
|
1205
|
-
await this.post(`/transaction/fetch`, input, { headers: this.headers() });
|
|
1143
|
+
const res = await this.post(`/transaction/fetch`, input, { headers: this.headers() });
|
|
1144
|
+
return res.data;
|
|
1206
1145
|
}
|
|
1207
1146
|
async getAddressBookEntries(pagination) {
|
|
1208
1147
|
const res = await this.get(`/address-book`, {
|