starknet 7.2.0 → 7.4.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.
@@ -60,6 +60,8 @@ var starknet = (() => {
60
60
  OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
61
61
  OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
62
62
  OutsideExecutionVersion: () => OutsideExecutionVersion,
63
+ PaymasterInterface: () => PaymasterInterface,
64
+ PaymasterRpc: () => PaymasterRpc,
63
65
  Provider: () => RpcProvider2,
64
66
  ProviderInterface: () => ProviderInterface,
65
67
  RPC: () => api_exports3,
@@ -98,6 +100,7 @@ var starknet = (() => {
98
100
  config: () => config,
99
101
  constants: () => constants_exports,
100
102
  contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
103
+ defaultPaymaster: () => defaultPaymaster,
101
104
  defaultProvider: () => defaultProvider,
102
105
  ec: () => ec_exports,
103
106
  encode: () => encode_exports,
@@ -127,6 +130,7 @@ var starknet = (() => {
127
130
  num: () => num_exports,
128
131
  outsideExecution: () => outsideExecution_exports,
129
132
  parseCalldataField: () => parseCalldataField,
133
+ paymaster: () => paymaster_exports,
130
134
  provider: () => provider_exports,
131
135
  selector: () => selector_exports,
132
136
  shortString: () => shortString_exports,
@@ -161,6 +165,7 @@ var starknet = (() => {
161
165
  MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
162
166
  NetworkName: () => _NetworkName,
163
167
  OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
168
+ PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
164
169
  PRIME: () => PRIME,
165
170
  RANGE_FELT: () => RANGE_FELT,
166
171
  RANGE_I128: () => RANGE_I128,
@@ -202,6 +207,7 @@ var starknet = (() => {
202
207
  EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
203
208
  JRPC: () => jsonrpc_exports,
204
209
  L1_DA_MODE: () => L1_DA_MODE,
210
+ PAYMASTER_API: () => snip_29_exports,
205
211
  PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
206
212
  PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
207
213
  Permission: () => Permission2,
@@ -377,6 +383,7 @@ var starknet = (() => {
377
383
  ETransactionVersion3: () => ETransactionVersion32,
378
384
  EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
379
385
  L1_DA_MODE: () => L1_DA_MODE,
386
+ PAYMASTER_API: () => snip_29_exports,
380
387
  PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
381
388
  PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
382
389
  Permission: () => Permission2,
@@ -571,6 +578,9 @@ var starknet = (() => {
571
578
  LEGACY: "0"
572
579
  };
573
580
 
581
+ // node_modules/starknet-types-08/dist/esm/snip-29/index.js
582
+ var snip_29_exports = {};
583
+
574
584
  // src/utils/encode.ts
575
585
  var encode_exports = {};
576
586
  __export(encode_exports, {
@@ -910,21 +920,20 @@ var starknet = (() => {
910
920
  websocket: void 0
911
921
  };
912
922
  var RPC_DEFAULT_NODES = {
913
- SN_MAIN: [
914
- `https://starknet-mainnet.public.blastapi.io/rpc/`,
915
- `https://free-rpc.nethermind.io/mainnet-juno/`
916
- ],
917
- SN_SEPOLIA: [
918
- `https://starknet-sepolia.public.blastapi.io/rpc/`,
919
- `https://free-rpc.nethermind.io/sepolia-juno/`
920
- ]
923
+ SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
924
+ SN_SEPOLIA: [`https://starknet-sepolia.public.blastapi.io/rpc/`]
925
+ };
926
+ var PAYMASTER_RPC_NODES = {
927
+ SN_MAIN: [`https://starknet.paymaster.avnu.fi`],
928
+ SN_SEPOLIA: [`https://sepolia.paymaster.avnu.fi`]
921
929
  };
922
930
  var SYSTEM_MESSAGES = {
923
931
  legacyTxWarningMessage: "You are using a deprecated transaction version (V0,V1,V2)!\nUpdate to the latest V3 transactions!",
924
932
  legacyTxRPC08Message: "RPC 0.8 do not support legacy transactions",
925
933
  SWOldV3: "RPC 0.7 V3 tx (improper resource bounds) not supported in RPC 0.8",
926
934
  channelVersionMismatch: "Channel specification version is not compatible with the connected node Specification Version",
927
- unsupportedSpecVersion: "The connected node specification version is not supported by this library"
935
+ unsupportedSpecVersion: "The connected node specification version is not supported by this library",
936
+ maxFeeInV3: "maxFee is not supported in V3 transactions, use resourceBounds instead"
928
937
  };
929
938
 
930
939
  // src/global/config.ts
@@ -1914,6 +1923,15 @@ ${indent}}` : "}";
1914
1923
  throw new Error(message || "Assertion failure");
1915
1924
  }
1916
1925
  }
1926
+ function assertX(condition, method) {
1927
+ if (!condition) {
1928
+ if (method.length === 0) {
1929
+ method();
1930
+ } else {
1931
+ throw new Error("AssertionX failure: message function should not require arguments");
1932
+ }
1933
+ }
1934
+ }
1917
1935
 
1918
1936
  // src/utils/num.ts
1919
1937
  var num_exports = {};
@@ -2682,6 +2700,7 @@ ${indent}}` : "}";
2682
2700
  // src/utils/hash/selector.ts
2683
2701
  var selector_exports = {};
2684
2702
  __export(selector_exports, {
2703
+ getL1MessageHash: () => getL1MessageHash,
2685
2704
  getL2MessageHash: () => getL2MessageHash,
2686
2705
  getSelector: () => getSelector,
2687
2706
  getSelectorFromName: () => getSelectorFromName,
@@ -4914,6 +4933,9 @@ ${indent}}` : "}";
4914
4933
  ...l2Calldata
4915
4934
  ]);
4916
4935
  }
4936
+ function getL1MessageHash(fromL2Address, toL1Address, payload) {
4937
+ return solidityUint256PackedKeccak256([fromL2Address, toL1Address, payload.length, ...payload]);
4938
+ }
4917
4939
 
4918
4940
  // src/utils/shortString.ts
4919
4941
  var shortString_exports = {};
@@ -7067,6 +7089,7 @@ ${indent}}` : "}";
7067
7089
  computePoseidonHashOnElements: () => computePoseidonHashOnElements,
7068
7090
  computeSierraContractClassHash: () => computeSierraContractClassHash,
7069
7091
  formatSpaces: () => formatSpaces,
7092
+ getL1MessageHash: () => getL1MessageHash,
7070
7093
  getL2MessageHash: () => getL2MessageHash,
7071
7094
  getSelector: () => getSelector,
7072
7095
  getSelectorFromName: () => getSelectorFromName,
@@ -11962,7 +11985,18 @@ ${indent}}` : "}";
11962
11985
  INVALID_SUBSCRIPTION_ID: 66,
11963
11986
  TOO_MANY_ADDRESSES_IN_FILTER: 67,
11964
11987
  TOO_MANY_BLOCKS_BACK: 68,
11965
- COMPILATION_ERROR: 100
11988
+ COMPILATION_ERROR: 100,
11989
+ INVALID_ADDRESS: 150,
11990
+ TOKEN_NOT_SUPPORTED: 151,
11991
+ INVALID_SIGNATURE: 153,
11992
+ MAX_AMOUNT_TOO_LOW: 154,
11993
+ CLASS_HASH_NOT_SUPPORTED: 155,
11994
+ PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
11995
+ INVALID_TIME_BOUNDS: 157,
11996
+ INVALID_DEPLOYMENT_DATA: 158,
11997
+ INVALID_CLASS_HASH: 159,
11998
+ INVALID_ID: 160,
11999
+ UNKNOWN_ERROR: 163
11966
12000
  };
11967
12001
  var rpc_default = errorCodes;
11968
12002
 
@@ -12757,6 +12791,11 @@ ${indent}}` : "}";
12757
12791
  fee_data_availability_mode: details.feeDataAvailabilityMode
12758
12792
  }
12759
12793
  });
12794
+ assertX(!details.maxFee, () => {
12795
+ logger.warn(SYSTEM_MESSAGES.maxFeeInV3, {
12796
+ type: esm_exports.ETransactionType.INVOKE
12797
+ });
12798
+ });
12760
12799
  }
12761
12800
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12762
12801
  }
@@ -12827,6 +12866,11 @@ ${indent}}` : "}";
12827
12866
  fee_data_availability_mode: details.feeDataAvailabilityMode
12828
12867
  }
12829
12868
  });
12869
+ assertX(!details.maxFee, () => {
12870
+ logger.warn(SYSTEM_MESSAGES.maxFeeInV3, {
12871
+ type: esm_exports.ETransactionType.DECLARE
12872
+ });
12873
+ });
12830
12874
  } else {
12831
12875
  throw Error("declare unspotted parameters");
12832
12876
  }
@@ -12868,6 +12912,11 @@ ${indent}}` : "}";
12868
12912
  fee_data_availability_mode: details.feeDataAvailabilityMode
12869
12913
  }
12870
12914
  });
12915
+ assertX(!details.maxFee, () => {
12916
+ logger.warn(SYSTEM_MESSAGES.maxFeeInV3, {
12917
+ type: esm_exports.ETransactionType.DEPLOY_ACCOUNT
12918
+ });
12919
+ });
12871
12920
  }
12872
12921
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12873
12922
  }
@@ -12938,6 +12987,12 @@ ${indent}}` : "}";
12938
12987
  fee_data_availability_mode: invocation.feeDataAvailabilityMode,
12939
12988
  account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it))
12940
12989
  };
12990
+ assertX(!invocation.maxFee, () => {
12991
+ logger.warn(SYSTEM_MESSAGES.maxFeeInV3, {
12992
+ type: invocation.type,
12993
+ versionType
12994
+ });
12995
+ });
12941
12996
  }
12942
12997
  if (invocation.type === TransactionType.INVOKE) {
12943
12998
  return {
@@ -17218,19 +17273,20 @@ ${indent}}` : "}";
17218
17273
  }
17219
17274
  function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
17220
17275
  const ret = providerReceivedEvents.flat().reduce((acc, recEvent) => {
17221
- let abiEvent = abiEvents[recEvent.keys.shift() ?? 0];
17276
+ const currentEvent = JSON.parse(JSON.stringify(recEvent));
17277
+ let abiEvent = abiEvents[currentEvent.keys.shift() ?? 0];
17222
17278
  if (!abiEvent) {
17223
17279
  return acc;
17224
17280
  }
17225
17281
  while (!abiEvent.name) {
17226
- const hashName = recEvent.keys.shift();
17282
+ const hashName = currentEvent.keys.shift();
17227
17283
  assert(!!hashName, 'Not enough data in "keys" property of this event.');
17228
17284
  abiEvent = abiEvent[hashName];
17229
17285
  }
17230
17286
  const parsedEvent = {};
17231
17287
  parsedEvent[abiEvent.name] = {};
17232
- const keysIter = recEvent.keys[Symbol.iterator]();
17233
- const dataIter = recEvent.data[Symbol.iterator]();
17288
+ const keysIter = currentEvent.keys[Symbol.iterator]();
17289
+ const dataIter = currentEvent.data[Symbol.iterator]();
17234
17290
  const abiEventKeys = abiEvent.members?.filter((it) => it.kind === "key") || abiEvent.keys;
17235
17291
  const abiEventData = abiEvent.members?.filter((it) => it.kind === "data") || abiEvent.data;
17236
17292
  abiEventKeys.forEach((key) => {
@@ -17251,9 +17307,10 @@ ${indent}}` : "}";
17251
17307
  parsedEvent[abiEvent.name]
17252
17308
  );
17253
17309
  });
17254
- if ("block_hash" in recEvent) parsedEvent.block_hash = recEvent.block_hash;
17255
- if ("block_number" in recEvent) parsedEvent.block_number = recEvent.block_number;
17256
- if ("transaction_hash" in recEvent) parsedEvent.transaction_hash = recEvent.transaction_hash;
17310
+ if ("block_hash" in currentEvent) parsedEvent.block_hash = currentEvent.block_hash;
17311
+ if ("block_number" in currentEvent) parsedEvent.block_number = currentEvent.block_number;
17312
+ if ("transaction_hash" in currentEvent)
17313
+ parsedEvent.transaction_hash = currentEvent.transaction_hash;
17257
17314
  acc.push(parsedEvent);
17258
17315
  return acc;
17259
17316
  }, []);
@@ -17287,8 +17344,19 @@ ${indent}}` : "}";
17287
17344
  buildExecuteFromOutsideCall: () => buildExecuteFromOutsideCall,
17288
17345
  buildExecuteFromOutsideCallData: () => buildExecuteFromOutsideCallData,
17289
17346
  getOutsideCall: () => getOutsideCall,
17290
- getTypedData: () => getTypedData
17347
+ getTypedData: () => getTypedData,
17348
+ toOutsideCallV2: () => toOutsideCallV2
17291
17349
  });
17350
+ function toOutsideCallV2(call) {
17351
+ if ("calldata_len" in call) {
17352
+ return {
17353
+ To: call.to,
17354
+ Selector: call.selector,
17355
+ Calldata: call.calldata
17356
+ };
17357
+ }
17358
+ return call;
17359
+ }
17292
17360
  function getOutsideCall(call) {
17293
17361
  const callData = call.calldata ?? [];
17294
17362
  const callDataCompiled = Array.isArray(callData) ? callData : CallData.compile(callData);
@@ -17395,13 +17463,332 @@ ${indent}}` : "}";
17395
17463
  }
17396
17464
  }
17397
17465
 
17466
+ // src/utils/paymaster.ts
17467
+ var paymaster_exports = {};
17468
+ __export(paymaster_exports, {
17469
+ assertCallsAreStrictlyEqual: () => assertCallsAreStrictlyEqual,
17470
+ assertPaymasterTransactionSafety: () => assertPaymasterTransactionSafety,
17471
+ getDefaultPaymasterNodeUrl: () => getDefaultPaymasterNodeUrl
17472
+ });
17473
+ var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
17474
+ if (!mute) {
17475
+ logger.info("Using default public node url, please provide nodeUrl in provider options!");
17476
+ }
17477
+ const nodes = PAYMASTER_RPC_NODES[networkName ?? _NetworkName.SN_SEPOLIA];
17478
+ const randIdx = Math.floor(Math.random() * nodes.length);
17479
+ return nodes[randIdx];
17480
+ };
17481
+ var assertGasFeeFromUnsafeCalls = (unsafeCalls, fees) => {
17482
+ const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
17483
+ const unsafeGasTokenCalldata = CallData.toCalldata(unsafeCall.Calldata);
17484
+ const unsafeGasTokenValue = unsafeGasTokenCalldata[1];
17485
+ assert(
17486
+ BigInt(unsafeGasTokenValue) === BigInt(fees),
17487
+ "Gas token value is not equal to the provided gas fees"
17488
+ );
17489
+ };
17490
+ var assertGasTokenFromUnsafeCalls = (unsafeCalls, gasToken) => {
17491
+ const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
17492
+ assert(
17493
+ BigInt(unsafeCall.To) === BigInt(gasToken),
17494
+ "Gas token address is not equal to the provided gas token"
17495
+ );
17496
+ };
17497
+ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
17498
+ const baseError = "Provided calls are not strictly equal to the returned calls";
17499
+ assert(
17500
+ unsafeCalls.length - 1 === originalCalls.length,
17501
+ `${baseError}: Expected ${originalCalls.length + 1} calls, got ${unsafeCalls.length}`
17502
+ );
17503
+ for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
17504
+ const originalCall = originalCalls[callIndex];
17505
+ const unsafeCall = toOutsideCallV2(unsafeCalls[callIndex]);
17506
+ const normalizeAddress = (address) => {
17507
+ return toBigInt(address).toString(16).toLowerCase();
17508
+ };
17509
+ const originalAddress = normalizeAddress(originalCall.contractAddress);
17510
+ const unsafeAddress = normalizeAddress(unsafeCall.To);
17511
+ assert(
17512
+ originalAddress === unsafeAddress,
17513
+ `${baseError}: Contract address mismatch at call ${callIndex}. Expected: ${originalCall.contractAddress}, Got: ${unsafeCall.To}`
17514
+ );
17515
+ assert(
17516
+ getSelectorFromName(originalCall.entrypoint) === unsafeCall.Selector,
17517
+ `${baseError}: Entrypoint mismatch at call ${callIndex}. Expected: ${originalCall.entrypoint}, Got: ${unsafeCall.Selector}`
17518
+ );
17519
+ const originalCalldata = CallData.toCalldata(originalCall.calldata);
17520
+ const unsafeCalldata = CallData.toCalldata(unsafeCall.Calldata);
17521
+ assert(
17522
+ originalCalldata.length === unsafeCalldata.length,
17523
+ `${baseError}: Calldata length mismatch at call ${callIndex}. Expected length: ${originalCalldata.length}, Got length: ${unsafeCalldata.length}`
17524
+ );
17525
+ for (let dataIndex = 0; dataIndex < originalCalldata.length; dataIndex += 1) {
17526
+ const originalValue = BigInt(originalCalldata[dataIndex]);
17527
+ const unsafeValue = BigInt(unsafeCalldata[dataIndex]);
17528
+ assert(
17529
+ originalValue === unsafeValue,
17530
+ `${baseError}: Calldata value mismatch at call ${callIndex}, parameter ${dataIndex}. Expected: ${originalCalldata[dataIndex]}, Got: ${unsafeCalldata[dataIndex]}`
17531
+ );
17532
+ }
17533
+ }
17534
+ }
17535
+ var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) => {
17536
+ if (paymasterDetails.feeMode.mode !== "sponsored") {
17537
+ if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
17538
+ const unsafeCalls = "calls" in preparedTransaction.typed_data.message ? preparedTransaction.typed_data.message.calls : preparedTransaction.typed_data.message.Calls;
17539
+ assertCallsAreStrictlyEqual(calls, unsafeCalls);
17540
+ assertGasTokenFromUnsafeCalls(unsafeCalls, paymasterDetails.feeMode.gasToken);
17541
+ if (maxFeeInGasToken) {
17542
+ assert(
17543
+ preparedTransaction.fee.suggested_max_fee_in_gas_token <= maxFeeInGasToken,
17544
+ "Gas token price is too high"
17545
+ );
17546
+ assertGasFeeFromUnsafeCalls(
17547
+ unsafeCalls,
17548
+ preparedTransaction.fee.suggested_max_fee_in_gas_token
17549
+ );
17550
+ }
17551
+ }
17552
+ }
17553
+ };
17554
+
17555
+ // src/paymaster/rpc.ts
17556
+ var convertCalls = (calls) => calls.map((call) => ({
17557
+ to: call.contractAddress,
17558
+ selector: getSelectorFromName(call.entrypoint),
17559
+ calldata: CallData.toHex(call.calldata)
17560
+ }));
17561
+ var convertFeeMode = (feeMode) => {
17562
+ if (feeMode.mode === "sponsored") {
17563
+ return { mode: "sponsored" };
17564
+ }
17565
+ return { mode: "default", gas_token: feeMode.gasToken };
17566
+ };
17567
+ var convertFEE_MODE = (feeMode) => {
17568
+ if (feeMode.mode === "sponsored") {
17569
+ return { mode: "sponsored" };
17570
+ }
17571
+ return { mode: "default", gasToken: feeMode.gas_token };
17572
+ };
17573
+ var convertTimeBounds = (timeBounds) => timeBounds && timeBounds.executeAfter && timeBounds.executeBefore ? {
17574
+ execute_after: timeBounds.executeAfter.getTime().toString(),
17575
+ execute_before: timeBounds.executeBefore.getTime().toString()
17576
+ } : void 0;
17577
+ var convertTIME_BOUNDS = (timeBounds) => timeBounds && timeBounds.execute_after && timeBounds.execute_before ? {
17578
+ executeAfter: new Date(timeBounds.execute_after),
17579
+ executeBefore: new Date(timeBounds.execute_before)
17580
+ } : void 0;
17581
+ var convertEXECUTION_PARAMETERS = (parameters) => ({
17582
+ version: parameters.version,
17583
+ feeMode: convertFEE_MODE(parameters.fee_mode),
17584
+ timeBounds: convertTIME_BOUNDS(parameters.time_bounds)
17585
+ });
17586
+ var defaultOptions3 = {
17587
+ headers: { "Content-Type": "application/json" }
17588
+ };
17589
+ var PaymasterRpc = class _PaymasterRpc {
17590
+ nodeUrl;
17591
+ headers;
17592
+ baseFetch;
17593
+ requestId;
17594
+ constructor(options) {
17595
+ if (options instanceof _PaymasterRpc) {
17596
+ this.nodeUrl = options.nodeUrl;
17597
+ this.headers = { ...defaultOptions3.headers, ...options.headers };
17598
+ this.baseFetch = options.baseFetch;
17599
+ this.requestId = options.requestId;
17600
+ return;
17601
+ }
17602
+ if (options && "nodeUrl" in options && "headers" in options && "baseFetch" in options) {
17603
+ this.nodeUrl = options.nodeUrl ?? getDefaultPaymasterNodeUrl(void 0);
17604
+ this.headers = { ...defaultOptions3.headers, ...options.headers };
17605
+ this.baseFetch = options.baseFetch ?? fetch_default;
17606
+ this.requestId = 0;
17607
+ return;
17608
+ }
17609
+ const { nodeUrl, headers, baseFetch } = options || {};
17610
+ if (nodeUrl && Object.values(_NetworkName).includes(nodeUrl)) {
17611
+ this.nodeUrl = getDefaultPaymasterNodeUrl(nodeUrl, options?.default);
17612
+ } else if (nodeUrl) {
17613
+ this.nodeUrl = nodeUrl;
17614
+ } else {
17615
+ this.nodeUrl = getDefaultPaymasterNodeUrl(void 0, options?.default);
17616
+ }
17617
+ this.baseFetch = baseFetch ?? fetch_default;
17618
+ this.headers = { ...defaultOptions3.headers, ...headers };
17619
+ this.requestId = 0;
17620
+ }
17621
+ fetch(method, params, id = 0) {
17622
+ const rpcRequestBody = {
17623
+ id,
17624
+ jsonrpc: "2.0",
17625
+ method,
17626
+ ...params && { params }
17627
+ };
17628
+ return this.baseFetch(this.nodeUrl, {
17629
+ method: "POST",
17630
+ body: stringify2(rpcRequestBody),
17631
+ headers: this.headers
17632
+ });
17633
+ }
17634
+ errorHandler(method, params, rpcError, otherError) {
17635
+ if (rpcError) {
17636
+ throw new RpcError(rpcError, method, params);
17637
+ }
17638
+ if (otherError instanceof LibraryError) {
17639
+ throw otherError;
17640
+ }
17641
+ if (otherError) {
17642
+ throw Error(otherError.message);
17643
+ }
17644
+ }
17645
+ async fetchEndpoint(method, params) {
17646
+ try {
17647
+ this.requestId += 1;
17648
+ const rawResult = await this.fetch(method, params, this.requestId);
17649
+ const { error, result } = await rawResult.json();
17650
+ this.errorHandler(method, params, error);
17651
+ return result;
17652
+ } catch (error) {
17653
+ this.errorHandler(method, params, error?.response?.data, error);
17654
+ throw error;
17655
+ }
17656
+ }
17657
+ async isAvailable() {
17658
+ return this.fetchEndpoint("paymaster_isAvailable");
17659
+ }
17660
+ async buildTransaction(transaction, parameters) {
17661
+ let userTransaction;
17662
+ switch (transaction.type) {
17663
+ case "invoke":
17664
+ userTransaction = {
17665
+ ...transaction,
17666
+ invoke: {
17667
+ user_address: transaction.invoke.userAddress,
17668
+ calls: convertCalls(transaction.invoke.calls)
17669
+ }
17670
+ };
17671
+ break;
17672
+ case "deploy_and_invoke":
17673
+ userTransaction = {
17674
+ ...transaction,
17675
+ invoke: {
17676
+ user_address: transaction.invoke.userAddress,
17677
+ calls: convertCalls(transaction.invoke.calls)
17678
+ }
17679
+ };
17680
+ break;
17681
+ case "deploy":
17682
+ default:
17683
+ userTransaction = transaction;
17684
+ break;
17685
+ }
17686
+ const executionParameters = {
17687
+ version: parameters.version,
17688
+ fee_mode: convertFeeMode(parameters.feeMode),
17689
+ time_bounds: convertTimeBounds(parameters.timeBounds)
17690
+ };
17691
+ const response = await this.fetchEndpoint("paymaster_buildTransaction", {
17692
+ transaction: userTransaction,
17693
+ parameters: executionParameters
17694
+ });
17695
+ const fee = {
17696
+ gas_token_price_in_strk: BigInt(response.fee.gas_token_price_in_strk),
17697
+ estimated_fee_in_strk: BigInt(response.fee.estimated_fee_in_strk),
17698
+ estimated_fee_in_gas_token: BigInt(response.fee.estimated_fee_in_gas_token),
17699
+ suggested_max_fee_in_strk: BigInt(response.fee.suggested_max_fee_in_strk),
17700
+ suggested_max_fee_in_gas_token: BigInt(response.fee.suggested_max_fee_in_gas_token)
17701
+ };
17702
+ switch (response.type) {
17703
+ case "invoke":
17704
+ return {
17705
+ type: "invoke",
17706
+ typed_data: response.typed_data,
17707
+ parameters: convertEXECUTION_PARAMETERS(response.parameters),
17708
+ fee
17709
+ };
17710
+ case "deploy_and_invoke":
17711
+ return {
17712
+ type: "deploy_and_invoke",
17713
+ deployment: response.deployment,
17714
+ typed_data: response.typed_data,
17715
+ parameters: convertEXECUTION_PARAMETERS(response.parameters),
17716
+ fee
17717
+ };
17718
+ case "deploy":
17719
+ default:
17720
+ return {
17721
+ type: "deploy",
17722
+ deployment: response.deployment,
17723
+ parameters: convertEXECUTION_PARAMETERS(response.parameters),
17724
+ fee
17725
+ };
17726
+ }
17727
+ }
17728
+ async executeTransaction(transaction, parameters) {
17729
+ let user_transaction;
17730
+ switch (transaction.type) {
17731
+ case "invoke":
17732
+ user_transaction = {
17733
+ ...transaction,
17734
+ invoke: {
17735
+ user_address: transaction.invoke.userAddress,
17736
+ typed_data: transaction.invoke.typedData,
17737
+ signature: signatureToHexArray(transaction.invoke.signature)
17738
+ }
17739
+ };
17740
+ break;
17741
+ case "deploy_and_invoke":
17742
+ user_transaction = {
17743
+ ...transaction,
17744
+ invoke: {
17745
+ user_address: transaction.invoke.userAddress,
17746
+ typed_data: transaction.invoke.typedData,
17747
+ signature: signatureToHexArray(transaction.invoke.signature)
17748
+ }
17749
+ };
17750
+ break;
17751
+ case "deploy":
17752
+ default:
17753
+ user_transaction = transaction;
17754
+ break;
17755
+ }
17756
+ const executionParameters = {
17757
+ version: parameters.version,
17758
+ fee_mode: convertFeeMode(parameters.feeMode),
17759
+ time_bounds: convertTimeBounds(parameters.timeBounds)
17760
+ };
17761
+ return this.fetchEndpoint("paymaster_executeTransaction", {
17762
+ transaction: user_transaction,
17763
+ parameters: executionParameters
17764
+ });
17765
+ }
17766
+ async getSupportedTokens() {
17767
+ return this.fetchEndpoint("paymaster_getSupportedTokens").then(
17768
+ (tokens) => tokens.map((token) => ({
17769
+ token_address: token.token_address,
17770
+ decimals: token.decimals,
17771
+ priceInStrk: BigInt(token.price_in_strk)
17772
+ }))
17773
+ );
17774
+ }
17775
+ };
17776
+
17777
+ // src/paymaster/interface.ts
17778
+ var PaymasterInterface = class {
17779
+ };
17780
+
17781
+ // src/paymaster/index.ts
17782
+ var defaultPaymaster = new PaymasterRpc({ default: true });
17783
+
17398
17784
  // src/account/default.ts
17399
17785
  var Account = class extends RpcProvider2 {
17400
17786
  signer;
17401
17787
  address;
17402
17788
  cairoVersion;
17403
17789
  transactionVersion;
17404
- constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = config.get("transactionVersion")) {
17790
+ paymaster;
17791
+ constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = config.get("transactionVersion"), paymaster) {
17405
17792
  super(providerOrOptions);
17406
17793
  this.address = address.toLowerCase();
17407
17794
  this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
@@ -17409,6 +17796,7 @@ ${indent}}` : "}";
17409
17796
  this.cairoVersion = cairoVersion.toString();
17410
17797
  }
17411
17798
  this.transactionVersion = transactionVersion;
17799
+ this.paymaster = paymaster ? new PaymasterRpc(paymaster) : defaultPaymaster;
17412
17800
  logger.debug("Account setup", {
17413
17801
  transactionVersion: this.transactionVersion,
17414
17802
  cairoVersion: this.cairoVersion,
@@ -17639,6 +18027,95 @@ ${indent}}` : "}";
17639
18027
  }
17640
18028
  );
17641
18029
  }
18030
+ async buildPaymasterTransaction(calls, paymasterDetails) {
18031
+ if (!paymasterDetails.deploymentData) {
18032
+ const snip9Version = await this.getSnip9Version();
18033
+ if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
18034
+ throw Error("Account is not compatible with SNIP-9");
18035
+ }
18036
+ }
18037
+ const parameters = {
18038
+ version: "0x1",
18039
+ feeMode: paymasterDetails.feeMode,
18040
+ timeBounds: paymasterDetails.timeBounds
18041
+ };
18042
+ let transaction;
18043
+ if (paymasterDetails.deploymentData) {
18044
+ if (calls.length > 0) {
18045
+ transaction = {
18046
+ type: "deploy_and_invoke",
18047
+ invoke: { userAddress: this.address, calls },
18048
+ deployment: paymasterDetails.deploymentData
18049
+ };
18050
+ } else {
18051
+ transaction = {
18052
+ type: "deploy",
18053
+ deployment: paymasterDetails.deploymentData
18054
+ };
18055
+ }
18056
+ } else {
18057
+ transaction = {
18058
+ type: "invoke",
18059
+ invoke: { userAddress: this.address, calls }
18060
+ };
18061
+ }
18062
+ return this.paymaster.buildTransaction(transaction, parameters);
18063
+ }
18064
+ async estimatePaymasterTransactionFee(calls, paymasterDetails) {
18065
+ const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
18066
+ return preparedTransaction.fee;
18067
+ }
18068
+ async preparePaymasterTransaction(preparedTransaction) {
18069
+ let transaction;
18070
+ switch (preparedTransaction.type) {
18071
+ case "deploy_and_invoke": {
18072
+ const signature = await this.signMessage(preparedTransaction.typed_data);
18073
+ transaction = {
18074
+ type: "deploy_and_invoke",
18075
+ invoke: {
18076
+ userAddress: this.address,
18077
+ typedData: preparedTransaction.typed_data,
18078
+ signature: signatureToHexArray(signature)
18079
+ },
18080
+ deployment: preparedTransaction.deployment
18081
+ };
18082
+ break;
18083
+ }
18084
+ case "invoke": {
18085
+ const signature = await this.signMessage(preparedTransaction.typed_data);
18086
+ transaction = {
18087
+ type: "invoke",
18088
+ invoke: {
18089
+ userAddress: this.address,
18090
+ typedData: preparedTransaction.typed_data,
18091
+ signature: signatureToHexArray(signature)
18092
+ }
18093
+ };
18094
+ break;
18095
+ }
18096
+ case "deploy": {
18097
+ transaction = {
18098
+ type: "deploy",
18099
+ deployment: preparedTransaction.deployment
18100
+ };
18101
+ break;
18102
+ }
18103
+ default:
18104
+ throw Error("Invalid transaction type");
18105
+ }
18106
+ return transaction;
18107
+ }
18108
+ async executePaymasterTransaction(calls, paymasterDetails, maxFeeInGasToken) {
18109
+ const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
18110
+ assertPaymasterTransactionSafety(
18111
+ preparedTransaction,
18112
+ calls,
18113
+ paymasterDetails,
18114
+ maxFeeInGasToken
18115
+ );
18116
+ const transaction = await this.preparePaymasterTransaction(preparedTransaction);
18117
+ return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
18118
+ }
17642
18119
  /**
17643
18120
  * First check if contract is already declared, if not declare it
17644
18121
  * If contract already declared returned transaction_hash is ''.
@@ -18185,8 +18662,8 @@ ${indent}}` : "}";
18185
18662
  // src/wallet/account.ts
18186
18663
  var WalletAccount = class _WalletAccount extends Account {
18187
18664
  walletProvider;
18188
- constructor(providerOrOptions, walletProvider, address, cairoVersion) {
18189
- super(providerOrOptions, address, "", cairoVersion);
18665
+ constructor(providerOrOptions, walletProvider, address, cairoVersion, paymaster) {
18666
+ super(providerOrOptions, address, "", cairoVersion, void 0, paymaster);
18190
18667
  this.walletProvider = walletProvider;
18191
18668
  this.walletProvider.on("accountsChanged", (res) => {
18192
18669
  if (!res) return;
@@ -18268,12 +18745,12 @@ ${indent}}` : "}";
18268
18745
  signMessage(typedData) {
18269
18746
  return signMessage(this.walletProvider, typedData);
18270
18747
  }
18271
- static async connect(provider, walletProvider, cairoVersion, silentMode = false) {
18748
+ static async connect(provider, walletProvider, cairoVersion, paymaster, silentMode = false) {
18272
18749
  const [accountAddress] = await requestAccounts(walletProvider, silentMode);
18273
- return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion);
18750
+ return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion, paymaster);
18274
18751
  }
18275
- static async connectSilent(provider, walletProvider, cairoVersion) {
18276
- return _WalletAccount.connect(provider, walletProvider, cairoVersion, true);
18752
+ static async connectSilent(provider, walletProvider, cairoVersion, paymaster) {
18753
+ return _WalletAccount.connect(provider, walletProvider, cairoVersion, paymaster, true);
18277
18754
  }
18278
18755
  // TODO: MISSING ESTIMATES
18279
18756
  };