@toruslabs/ethereum-controllers 7.1.0 → 7.1.2

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.
@@ -3655,7 +3655,7 @@ __webpack_require__.d(__webpack_exports__, {
3655
3655
  // UNUSED EXPORTS: setErrorConfig
3656
3656
 
3657
3657
  ;// ../../node_modules/viem/_esm/errors/version.js
3658
- const version = '2.21.55';
3658
+ const version = '2.22.8';
3659
3659
  //# sourceMappingURL=version.js.map
3660
3660
  ;// ../../node_modules/viem/_esm/errors/base.js
3661
3661
 
@@ -4237,7 +4237,14 @@ class RpcRequestError extends _base_js__WEBPACK_IMPORTED_MODULE_0__/* .BaseError
4237
4237
  writable: true,
4238
4238
  value: void 0
4239
4239
  });
4240
+ Object.defineProperty(this, "data", {
4241
+ enumerable: true,
4242
+ configurable: true,
4243
+ writable: true,
4244
+ value: void 0
4245
+ });
4240
4246
  this.code = error.code;
4247
+ this.data = error.data;
4241
4248
  }
4242
4249
  }
4243
4250
  class SocketClosedError extends _base_js__WEBPACK_IMPORTED_MODULE_0__/* .BaseError */ .C {
@@ -9434,7 +9441,7 @@ Object.defineProperty(src_AccountNotDeployedError, "message", {
9434
9441
  value: /aa20/
9435
9442
  });
9436
9443
  class src_ExecutionRevertedError extends src_base/* BaseError */.C {
9437
- constructor({ cause, message, } = {}) {
9444
+ constructor({ cause, data, message, } = {}) {
9438
9445
  const reason = message
9439
9446
  ?.replace('execution reverted: ', '')
9440
9447
  ?.replace('execution reverted', '');
@@ -9442,6 +9449,13 @@ class src_ExecutionRevertedError extends src_base/* BaseError */.C {
9442
9449
  cause,
9443
9450
  name: 'ExecutionRevertedError',
9444
9451
  });
9452
+ Object.defineProperty(this, "data", {
9453
+ enumerable: true,
9454
+ configurable: true,
9455
+ writable: true,
9456
+ value: void 0
9457
+ });
9458
+ this.data = data;
9445
9459
  }
9446
9460
  }
9447
9461
  Object.defineProperty(src_ExecutionRevertedError, "code", {
@@ -10211,6 +10225,7 @@ function src_getBundlerError(err, args) {
10211
10225
  if (error.code === src_ExecutionRevertedError.code)
10212
10226
  return new src_ExecutionRevertedError({
10213
10227
  cause: err,
10228
+ data: error.data,
10214
10229
  message: error.details,
10215
10230
  });
10216
10231
  if (error.code === src_InvalidFieldsError.code)
@@ -10271,7 +10286,7 @@ function src_getUserOperationError(err, { calls, docsPath, ...args }) {
10271
10286
  const cause = src_getBundlerError(err, args);
10272
10287
  if (calls && cause instanceof src_ExecutionRevertedError) {
10273
10288
  const revertData = src_getRevertData(cause);
10274
- const contractCalls = calls?.filter((call) => call.abi || call.data);
10289
+ const contractCalls = calls?.filter((call) => call.abi);
10275
10290
  if (revertData && contractCalls.length > 0)
10276
10291
  return src_getContractError({ calls: contractCalls, revertData });
10277
10292
  }
@@ -10949,7 +10964,7 @@ async function src_prepareUserOperation(client, parameters_) {
10949
10964
  if (parameters.calls)
10950
10965
  return account.encodeCalls(parameters.calls.map((call_) => {
10951
10966
  const call = call_;
10952
- if ('abi' in call)
10967
+ if (call.abi)
10953
10968
  return {
10954
10969
  data: (0,src_abi_encodeFunctionData/* encodeFunctionData */.p)(call),
10955
10970
  to: call.to,
@@ -11845,6 +11860,7 @@ class src_AccountAbstractionController extends src_base_controllers_namespaceObj
11845
11860
  throw new Error("Invalid address");
11846
11861
  }
11847
11862
  const txParams = tx;
11863
+ // @ts-expect-error TODO: viem types are too deep
11848
11864
  const userOperationParams = {
11849
11865
  account: this.smartAccount,
11850
11866
  calls: [{
@@ -11868,7 +11884,6 @@ class src_AccountAbstractionController extends src_base_controllers_namespaceObj
11868
11884
  status: src_base_controllers_namespaceObject.TransactionStatus.approved
11869
11885
  };
11870
11886
  this.updateUserOpMeta(id, userOpMeta);
11871
- // @ts-expect-error viem types are too deep
11872
11887
  const userOpHash = await this.bundlerClient.sendUserOperation(userOperationParams);
11873
11888
  this.updateUserOpMeta(id, {
11874
11889
  userOpHash,
@@ -11894,35 +11909,56 @@ class src_AccountAbstractionController extends src_base_controllers_namespaceObj
11894
11909
  if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) throw new Error("Invalid address");
11895
11910
  const calls = [{
11896
11911
  to: txParams.to,
11897
- value: BigInt(txParams.value),
11912
+ value: txParams.value ? BigInt(txParams.value) : undefined,
11898
11913
  data: txParams.data
11899
11914
  }];
11900
- let maxFeePerGas = txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined;
11901
- let maxPriorityFeePerGas = txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined;
11902
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
11903
- // if maxFeePerGas and maxPriorityFeePerGas are not provided, prepareUserOperation will estimate them
11904
- const userOp = await this.bundlerClient.prepareUserOperation({
11905
- account: this.smartAccount,
11906
- calls
11907
- });
11908
- maxFeePerGas = userOp === null || userOp === void 0 ? void 0 : userOp.maxFeePerGas;
11909
- maxPriorityFeePerGas = userOp === null || userOp === void 0 ? void 0 : userOp.maxPriorityFeePerGas;
11910
- }
11915
+ const maxFeePerGas = txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined;
11916
+ const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined;
11911
11917
 
11912
- // estimate gas: maxFeePerGas and maxPriorityFeePerGas are required
11918
+ // estimate gas: maxFeePerGas and maxPriorityFeePerGas are not required
11913
11919
  const estimateGasParams = {
11920
+ account: this.smartAccount,
11914
11921
  calls,
11915
11922
  maxFeePerGas,
11916
- maxPriorityFeePerGas
11923
+ maxPriorityFeePerGas,
11924
+ stateOverride: [
11925
+ // override state to estimate gas for an ERC-20 transfer without causing a RPC error due to insufficient funds
11926
+ // ref: https://docs.cometh.io/connect-4337/bundler/bundler-api/eth_estimateuseroperationgas#optional-state-override-set
11927
+ {
11928
+ address: this.smartAccount.address,
11929
+ balance: (0,src_external_viem_namespaceObject.parseEther)("1")
11930
+ }]
11917
11931
  };
11932
+
11933
+ // bundler only support factoryArgs for estimate user operation gas in entryPoint v0.7
11934
+ let factoryArgs;
11935
+ if (this.smartAccount.entryPoint.version !== "0.6") {
11936
+ factoryArgs = await this.smartAccount.getFactoryArgs(); // will return undefined if smart account already deployed
11937
+ }
11938
+ if (factoryArgs) {
11939
+ // using object spread here will cause type error because of viem's excessively deep types
11940
+ // TODO: currently using single property assignment, check again when viem types are updated
11941
+ if (factoryArgs.factory) {
11942
+ estimateGasParams.factory = factoryArgs.factory;
11943
+ }
11944
+ if (factoryArgs.factoryData) {
11945
+ estimateGasParams.factoryData = factoryArgs.factoryData;
11946
+ }
11947
+ }
11918
11948
  const result = await this.bundlerClient.estimateUserOperationGas(estimateGasParams);
11919
- return {
11949
+ const gasData = {
11920
11950
  callGasLimit: (0,src_external_viem_namespaceObject.toHex)(result.callGasLimit),
11921
11951
  preVerificationGas: (0,src_external_viem_namespaceObject.toHex)(result.preVerificationGas),
11922
- verificationGasLimit: (0,src_external_viem_namespaceObject.toHex)(result.verificationGasLimit),
11923
- paymasterVerificationGasLimit: (0,src_external_viem_namespaceObject.toHex)(result.paymasterVerificationGasLimit || 0),
11924
- paymasterPostOpGasLimit: (0,src_external_viem_namespaceObject.toHex)(result.paymasterPostOpGasLimit || 0)
11952
+ verificationGasLimit: (0,src_external_viem_namespaceObject.toHex)(result.verificationGasLimit)
11925
11953
  };
11954
+ // NOTE: paymasterVerificationGasLimit and paymasterPostOpGasLimit are optional don't include it in the object otherwise bundler rpc call will throw error (depend on bundler)
11955
+ if (result.paymasterVerificationGasLimit) {
11956
+ gasData.paymasterVerificationGasLimit = (0,src_external_viem_namespaceObject.toHex)(result.paymasterVerificationGasLimit);
11957
+ }
11958
+ if (result.paymasterPostOpGasLimit) {
11959
+ gasData.paymasterPostOpGasLimit = (0,src_external_viem_namespaceObject.toHex)(result.paymasterPostOpGasLimit);
11960
+ }
11961
+ return gasData;
11926
11962
  }
11927
11963
  async signMessage(message, address) {
11928
11964
  if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) {
@@ -13664,23 +13700,27 @@ class src_UnknownRpcError extends src_RpcError {
13664
13700
 
13665
13701
 
13666
13702
 
13703
+
13667
13704
  const src_EXECUTION_REVERTED_ERROR_CODE = 3;
13668
13705
  function src_getContractError_getContractError(err, { abi, address, args, docsPath, functionName, sender, }) {
13669
- const { code, data, message, shortMessage } = (err instanceof src_contract/* RawContractError */.$S
13706
+ const error = (err instanceof src_contract/* RawContractError */.$S
13670
13707
  ? err
13671
13708
  : err instanceof src_base/* BaseError */.C
13672
13709
  ? err.walk((err) => 'data' in err) || err.walk()
13673
13710
  : {});
13711
+ const { code, data, details, message, shortMessage } = error;
13674
13712
  const cause = (() => {
13675
13713
  if (err instanceof src_errors_abi/* AbiDecodingZeroDataError */.O)
13676
13714
  return new src_contract/* ContractFunctionZeroDataError */.rR({ functionName });
13677
13715
  if ([src_EXECUTION_REVERTED_ERROR_CODE, src_InternalRpcError.code].includes(code) &&
13678
- (data || message || shortMessage)) {
13716
+ (data || details || message || shortMessage)) {
13679
13717
  return new src_contract/* ContractFunctionRevertedError */.M({
13680
13718
  abi,
13681
13719
  data: typeof data === 'object' ? data.data : data,
13682
13720
  functionName,
13683
- message: shortMessage ?? message,
13721
+ message: error instanceof src_request/* RpcRequestError */.J8
13722
+ ? details
13723
+ : (shortMessage ?? message),
13684
13724
  });
13685
13725
  }
13686
13726
  return err;
@@ -14406,7 +14446,8 @@ function src_getTypesForEIP712Domain({ domain, }) {
14406
14446
  return [
14407
14447
  typeof domain?.name === 'string' && { name: 'name', type: 'string' },
14408
14448
  domain?.version && { name: 'version', type: 'string' },
14409
- typeof domain?.chainId === 'number' && {
14449
+ (typeof domain?.chainId === 'number' ||
14450
+ typeof domain?.chainId === 'bigint') && {
14410
14451
  name: 'chainId',
14411
14452
  type: 'uint256',
14412
14453
  },
@@ -17227,9 +17268,6 @@ async function src_toEcdsaKernelSmartAccount(parameters) {
17227
17268
 
17228
17269
 
17229
17270
 
17230
-
17231
- // use type of function so we don't need to pass in generic to parameter type
17232
-
17233
17271
  class src_KernelSmartAccount {
17234
17272
  constructor(options) {
17235
17273
  src_defineProperty_default()(this, "name", src_SMART_ACCOUNT.KERNEL);
@@ -18485,9 +18523,6 @@ async function src_toSafeSmartAccount(parameters) {
18485
18523
 
18486
18524
 
18487
18525
 
18488
-
18489
- // use type of function so we don't need to pass in generic to parameter type
18490
-
18491
18526
  class src_SafeSmartAccount {
18492
18527
  constructor(options) {
18493
18528
  src_defineProperty_default()(this, "name", src_SMART_ACCOUNT.SAFE);
@@ -18757,9 +18792,6 @@ async function src_toTrustSmartAccount(parameters) {
18757
18792
 
18758
18793
 
18759
18794
 
18760
-
18761
- // use type of function so we don't need to pass in generic to parameter type
18762
-
18763
18795
  class src_TrustSmartAccount {
18764
18796
  constructor(options) {
18765
18797
  src_defineProperty_default()(this, "name", src_SMART_ACCOUNT.TRUST);
@@ -6,7 +6,7 @@ import { BrowserProvider, toQuantity, Contract, isHexString, SigningKey, hashMes
6
6
  import log from 'loglevel';
7
7
  import { addHexPrefix, stripHexPrefix, isHexString as isHexString$1, bytesToHex, privateToPublic, toChecksumAddress, privateToAddress, ecsign, bigIntToBytes, isValidAddress } from '@ethereumjs/util';
8
8
  import { JRPCEngine, providerFromEngine, createAsyncMiddleware, mergeMiddleware, createScaffoldMiddleware, providerFromMiddleware, rpcErrors, SafeEventEmitter, providerErrors } from '@web3auth/auth';
9
- import { defineChain, createPublicClient, http, createWalletClient, toHex } from 'viem';
9
+ import { defineChain, createPublicClient, http, createWalletClient, parseEther, toHex } from 'viem';
10
10
  import { createPaymasterClient, createBundlerClient, entryPoint06Address, entryPoint07Address } from 'viem/account-abstraction';
11
11
  import { get } from '@toruslabs/http-helpers';
12
12
  import BigNumber from 'bignumber.js';
@@ -1125,6 +1125,7 @@ class AccountAbstractionController extends BaseController {
1125
1125
  throw new Error("Invalid address");
1126
1126
  }
1127
1127
  const txParams = tx;
1128
+ // @ts-expect-error TODO: viem types are too deep
1128
1129
  const userOperationParams = {
1129
1130
  account: this.smartAccount,
1130
1131
  calls: [{
@@ -1148,7 +1149,6 @@ class AccountAbstractionController extends BaseController {
1148
1149
  status: TransactionStatus.approved
1149
1150
  };
1150
1151
  this.updateUserOpMeta(id, userOpMeta);
1151
- // @ts-expect-error viem types are too deep
1152
1152
  const userOpHash = await this.bundlerClient.sendUserOperation(userOperationParams);
1153
1153
  this.updateUserOpMeta(id, {
1154
1154
  userOpHash,
@@ -1174,35 +1174,56 @@ class AccountAbstractionController extends BaseController {
1174
1174
  if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) throw new Error("Invalid address");
1175
1175
  const calls = [{
1176
1176
  to: txParams.to,
1177
- value: BigInt(txParams.value),
1177
+ value: txParams.value ? BigInt(txParams.value) : undefined,
1178
1178
  data: txParams.data
1179
1179
  }];
1180
- let maxFeePerGas = txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined;
1181
- let maxPriorityFeePerGas = txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined;
1182
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
1183
- // if maxFeePerGas and maxPriorityFeePerGas are not provided, prepareUserOperation will estimate them
1184
- const userOp = await this.bundlerClient.prepareUserOperation({
1185
- account: this.smartAccount,
1186
- calls
1187
- });
1188
- maxFeePerGas = userOp === null || userOp === void 0 ? void 0 : userOp.maxFeePerGas;
1189
- maxPriorityFeePerGas = userOp === null || userOp === void 0 ? void 0 : userOp.maxPriorityFeePerGas;
1190
- }
1180
+ const maxFeePerGas = txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined;
1181
+ const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined;
1191
1182
 
1192
- // estimate gas: maxFeePerGas and maxPriorityFeePerGas are required
1183
+ // estimate gas: maxFeePerGas and maxPriorityFeePerGas are not required
1193
1184
  const estimateGasParams = {
1185
+ account: this.smartAccount,
1194
1186
  calls,
1195
1187
  maxFeePerGas,
1196
- maxPriorityFeePerGas
1188
+ maxPriorityFeePerGas,
1189
+ stateOverride: [
1190
+ // override state to estimate gas for an ERC-20 transfer without causing a RPC error due to insufficient funds
1191
+ // ref: https://docs.cometh.io/connect-4337/bundler/bundler-api/eth_estimateuseroperationgas#optional-state-override-set
1192
+ {
1193
+ address: this.smartAccount.address,
1194
+ balance: parseEther("1")
1195
+ }]
1197
1196
  };
1197
+
1198
+ // bundler only support factoryArgs for estimate user operation gas in entryPoint v0.7
1199
+ let factoryArgs;
1200
+ if (this.smartAccount.entryPoint.version !== "0.6") {
1201
+ factoryArgs = await this.smartAccount.getFactoryArgs(); // will return undefined if smart account already deployed
1202
+ }
1203
+ if (factoryArgs) {
1204
+ // using object spread here will cause type error because of viem's excessively deep types
1205
+ // TODO: currently using single property assignment, check again when viem types are updated
1206
+ if (factoryArgs.factory) {
1207
+ estimateGasParams.factory = factoryArgs.factory;
1208
+ }
1209
+ if (factoryArgs.factoryData) {
1210
+ estimateGasParams.factoryData = factoryArgs.factoryData;
1211
+ }
1212
+ }
1198
1213
  const result = await this.bundlerClient.estimateUserOperationGas(estimateGasParams);
1199
- return {
1214
+ const gasData = {
1200
1215
  callGasLimit: toHex(result.callGasLimit),
1201
1216
  preVerificationGas: toHex(result.preVerificationGas),
1202
- verificationGasLimit: toHex(result.verificationGasLimit),
1203
- paymasterVerificationGasLimit: toHex(result.paymasterVerificationGasLimit || 0),
1204
- paymasterPostOpGasLimit: toHex(result.paymasterPostOpGasLimit || 0)
1217
+ verificationGasLimit: toHex(result.verificationGasLimit)
1205
1218
  };
1219
+ // NOTE: paymasterVerificationGasLimit and paymasterPostOpGasLimit are optional don't include it in the object otherwise bundler rpc call will throw error (depend on bundler)
1220
+ if (result.paymasterVerificationGasLimit) {
1221
+ gasData.paymasterVerificationGasLimit = toHex(result.paymasterVerificationGasLimit);
1222
+ }
1223
+ if (result.paymasterPostOpGasLimit) {
1224
+ gasData.paymasterPostOpGasLimit = toHex(result.paymasterPostOpGasLimit);
1225
+ }
1226
+ return gasData;
1206
1227
  }
1207
1228
  async signMessage(message, address) {
1208
1229
  if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) {
@@ -1271,8 +1292,6 @@ class BiconomySmartAccount {
1271
1292
  }
1272
1293
  }
1273
1294
 
1274
- // use type of function so we don't need to pass in generic to parameter type
1275
-
1276
1295
  class KernelSmartAccount {
1277
1296
  constructor(options) {
1278
1297
  _defineProperty(this, "name", SMART_ACCOUNT.KERNEL);
@@ -1308,8 +1327,6 @@ class NexusSmartAccount {
1308
1327
  }
1309
1328
  }
1310
1329
 
1311
- // use type of function so we don't need to pass in generic to parameter type
1312
-
1313
1330
  class SafeSmartAccount {
1314
1331
  constructor(options) {
1315
1332
  _defineProperty(this, "name", SMART_ACCOUNT.SAFE);
@@ -1331,8 +1348,6 @@ class SafeSmartAccount {
1331
1348
  }
1332
1349
  }
1333
1350
 
1334
- // use type of function so we don't need to pass in generic to parameter type
1335
-
1336
1351
  class TrustSmartAccount {
1337
1352
  constructor(options) {
1338
1353
  _defineProperty(this, "name", SMART_ACCOUNT.TRUST);