@msafe/sui3-sdk 0.0.75 → 0.0.76
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 +22 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +22 -55
- 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 +19 -61
- package/src/types/msafe.ts +12 -4
package/dist/index.d.cts
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;
|
|
@@ -311,7 +317,6 @@ declare class InvitationSDK {
|
|
|
311
317
|
}
|
|
312
318
|
|
|
313
319
|
type GasPriceOption = MultiplierOption | FixedValueOption;
|
|
314
|
-
type GasBudgetOption = MultiplierOption | FixedValueOption;
|
|
315
320
|
interface MultiplierOption {
|
|
316
321
|
multiplier: {
|
|
317
322
|
numerator: bigint;
|
|
@@ -327,13 +332,12 @@ declare class Simulator {
|
|
|
327
332
|
simulate(input: {
|
|
328
333
|
txb: TransactionBlock;
|
|
329
334
|
sender: string;
|
|
330
|
-
}, gasOption?: GasPriceOption
|
|
335
|
+
}, gasOption?: GasPriceOption): Promise<SimulationResult>;
|
|
331
336
|
private getGasPrice;
|
|
332
337
|
private toGasBudget;
|
|
333
338
|
private isFixedValue;
|
|
334
339
|
private isMultiplier;
|
|
335
340
|
private applyGasOption;
|
|
336
|
-
private applyBudgetOption;
|
|
337
341
|
private copyTransactionBlock;
|
|
338
342
|
}
|
|
339
343
|
|
|
@@ -384,7 +388,7 @@ declare class MSafeAccount {
|
|
|
384
388
|
forceBuild: boolean;
|
|
385
389
|
}): Promise<void>;
|
|
386
390
|
skipNextFailedIntention(): Promise<void>;
|
|
387
|
-
fetchTransaction(): Promise<
|
|
391
|
+
fetchTransaction(): Promise<string[]>;
|
|
388
392
|
executePendingTx(pending: PendingTx, isRejectTx?: boolean): Promise<_mysten_sui_js_client.SuiTransactionBlockResponse>;
|
|
389
393
|
dashboard(): Promise<_msafe_sui3_utils.IGetDashboardResp>;
|
|
390
394
|
private calculateWeightFromVotes;
|
|
@@ -492,4 +496,4 @@ declare class Coin {
|
|
|
492
496
|
static getBalance(data: SuiObjectData): bigint | undefined;
|
|
493
497
|
}
|
|
494
498
|
|
|
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 };
|
|
499
|
+
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.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;
|
|
@@ -311,7 +317,6 @@ declare class InvitationSDK {
|
|
|
311
317
|
}
|
|
312
318
|
|
|
313
319
|
type GasPriceOption = MultiplierOption | FixedValueOption;
|
|
314
|
-
type GasBudgetOption = MultiplierOption | FixedValueOption;
|
|
315
320
|
interface MultiplierOption {
|
|
316
321
|
multiplier: {
|
|
317
322
|
numerator: bigint;
|
|
@@ -327,13 +332,12 @@ declare class Simulator {
|
|
|
327
332
|
simulate(input: {
|
|
328
333
|
txb: TransactionBlock;
|
|
329
334
|
sender: string;
|
|
330
|
-
}, gasOption?: GasPriceOption
|
|
335
|
+
}, gasOption?: GasPriceOption): Promise<SimulationResult>;
|
|
331
336
|
private getGasPrice;
|
|
332
337
|
private toGasBudget;
|
|
333
338
|
private isFixedValue;
|
|
334
339
|
private isMultiplier;
|
|
335
340
|
private applyGasOption;
|
|
336
|
-
private applyBudgetOption;
|
|
337
341
|
private copyTransactionBlock;
|
|
338
342
|
}
|
|
339
343
|
|
|
@@ -384,7 +388,7 @@ declare class MSafeAccount {
|
|
|
384
388
|
forceBuild: boolean;
|
|
385
389
|
}): Promise<void>;
|
|
386
390
|
skipNextFailedIntention(): Promise<void>;
|
|
387
|
-
fetchTransaction(): Promise<
|
|
391
|
+
fetchTransaction(): Promise<string[]>;
|
|
388
392
|
executePendingTx(pending: PendingTx, isRejectTx?: boolean): Promise<_mysten_sui_js_client.SuiTransactionBlockResponse>;
|
|
389
393
|
dashboard(): Promise<_msafe_sui3_utils.IGetDashboardResp>;
|
|
390
394
|
private calculateWeightFromVotes;
|
|
@@ -492,4 +496,4 @@ declare class Coin {
|
|
|
492
496
|
static getBalance(data: SuiObjectData): bigint | undefined;
|
|
493
497
|
}
|
|
494
498
|
|
|
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 };
|
|
499
|
+
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
|
@@ -148,60 +148,36 @@ var DEF_GAS_PRICE_OPTION = {
|
|
|
148
148
|
denominator: DEF_GAS_PRICE_DEN
|
|
149
149
|
}
|
|
150
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
151
|
var Simulator = class {
|
|
160
152
|
constructor(globals) {
|
|
161
153
|
this.globals = globals;
|
|
162
154
|
}
|
|
163
|
-
async simulate(input, gasOption = DEF_GAS_PRICE_OPTION
|
|
155
|
+
async simulate(input, gasOption = DEF_GAS_PRICE_OPTION) {
|
|
164
156
|
const tx = this.copyTransactionBlock(input.txb);
|
|
165
157
|
const { suiClient } = this.globals;
|
|
166
158
|
const gasPrice = await this.getGasPrice(gasOption);
|
|
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
|
-
}
|
|
159
|
+
tx.setGasPrice(gasPrice);
|
|
160
|
+
const inspectResult = await suiClient.dryRunTransactionBlock({
|
|
161
|
+
transactionBlock: await tx.build({ client: suiClient })
|
|
162
|
+
});
|
|
163
|
+
const success = inspectResult.effects.status.status === "success";
|
|
164
|
+
if (!success) {
|
|
178
165
|
return {
|
|
179
166
|
success,
|
|
180
167
|
gasPrice,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
gasBudget: this.applyBudgetOption(gasBudget, budgetOption),
|
|
184
|
-
simulationError: error,
|
|
185
|
-
response: inspectResult
|
|
168
|
+
response: inspectResult,
|
|
169
|
+
simulationError: inspectResult.effects.status.error
|
|
186
170
|
};
|
|
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
171
|
}
|
|
172
|
+
const gasBudget = this.toGasBudget(inspectResult.effects.gasUsed, gasPrice);
|
|
173
|
+
return {
|
|
174
|
+
success,
|
|
175
|
+
gasPrice,
|
|
176
|
+
gasObject: inspectResult.effects.gasObject.reference,
|
|
177
|
+
gasUsed: inspectResult.effects.gasUsed,
|
|
178
|
+
gasBudget,
|
|
179
|
+
response: inspectResult
|
|
180
|
+
};
|
|
205
181
|
}
|
|
206
182
|
async getGasPrice(option) {
|
|
207
183
|
if (this.isFixedValue(option)) {
|
|
@@ -211,10 +187,10 @@ var Simulator = class {
|
|
|
211
187
|
return this.applyGasOption(refGasPrice, option);
|
|
212
188
|
}
|
|
213
189
|
toGasBudget(gasUsed, gasPrice) {
|
|
214
|
-
const { computationCost, storageCost } = gasUsed;
|
|
190
|
+
const { computationCost, storageCost, storageRebate } = gasUsed;
|
|
215
191
|
const safeOverhead = GAS_SAFE_OVERHEAD * gasPrice;
|
|
216
192
|
const baseComputationCostWithOverhead = BigInt(computationCost) + safeOverhead;
|
|
217
|
-
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost);
|
|
193
|
+
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
|
|
218
194
|
return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
|
|
219
195
|
}
|
|
220
196
|
isFixedValue(option) {
|
|
@@ -233,16 +209,6 @@ var Simulator = class {
|
|
|
233
209
|
}
|
|
234
210
|
throw new Error("Sanity: Unknown gas price option");
|
|
235
211
|
}
|
|
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
212
|
copyTransactionBlock(tx) {
|
|
247
213
|
return TransactionBlock.from(tx.serialize());
|
|
248
214
|
}
|
|
@@ -1202,7 +1168,8 @@ var BackendImpl = class _BackendImpl {
|
|
|
1202
1168
|
await this.post(`/transaction/pending/skip`, input, { headers: this.headers() });
|
|
1203
1169
|
}
|
|
1204
1170
|
async fetchTransaction(input) {
|
|
1205
|
-
await this.post(`/transaction/fetch`, input, { headers: this.headers() });
|
|
1171
|
+
const res = await this.post(`/transaction/fetch`, input, { headers: this.headers() });
|
|
1172
|
+
return res.data;
|
|
1206
1173
|
}
|
|
1207
1174
|
async getAddressBookEntries(pagination) {
|
|
1208
1175
|
const res = await this.get(`/address-book`, {
|