@imtbl/sdk 1.43.2-alpha.1 → 1.43.2-alpha.11

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.
Files changed (38) hide show
  1. package/dist/blockchain_data.js +2 -2
  2. package/dist/browser/checkout/{BridgeWidget-d56cb3d9.js → BridgeWidget-faa80cbb.js} +1 -1
  3. package/dist/browser/checkout/{OnRampWidget-7a1d5914.js → OnRampWidget-39daba24.js} +1 -1
  4. package/dist/browser/checkout/{SaleWidget-dd7cc880.js → SaleWidget-76b380a7.js} +1 -1
  5. package/dist/browser/checkout/{SpendingCapHero-d8d812d1.js → SpendingCapHero-f53897d8.js} +1 -1
  6. package/dist/browser/checkout/SwapWidget-4db6fe96.js +1 -0
  7. package/dist/browser/checkout/{TopUpView-15ccc8b9.js → TopUpView-61f1b017.js} +1 -1
  8. package/dist/browser/checkout/{WalletWidget-45c16667.js → WalletWidget-ef863614.js} +1 -1
  9. package/dist/browser/checkout/{auto-track-2e6f5359.js → auto-track-a5ccbe2f.js} +1 -1
  10. package/dist/browser/checkout/balance-7b5c1f2d.js +1 -0
  11. package/dist/browser/checkout/index-075dcca8.js +1 -0
  12. package/dist/browser/checkout/{index-1c955634.js → index-07b088f2.js} +1 -1
  13. package/dist/browser/checkout/{index-4e6fd4fb.js → index-22bb5d56.js} +3 -3
  14. package/dist/browser/checkout/{index-7a309739.js → index-26fa00e0.js} +1 -1
  15. package/dist/browser/checkout/{index-4e330c2b.js → index-4d6c7551.js} +1 -1
  16. package/dist/browser/checkout/{index-835a0b7b.js → index-6b2c601a.js} +1 -1
  17. package/dist/browser/checkout/{index-714e543c.js → index-88935bab.js} +1 -1
  18. package/dist/browser/checkout/{index-364cedbf.js → index-9fd8e0ab.js} +1 -1
  19. package/dist/browser/checkout/{index.umd-1b02f542.js → index.umd-70520bfe.js} +1 -1
  20. package/dist/browser/checkout/{retry-54b25cfd.js → retry-397e624a.js} +1 -1
  21. package/dist/browser/checkout/sdk.js +5 -5
  22. package/dist/browser/checkout/widgets-esm.js +1 -1
  23. package/dist/browser/checkout/widgets.js +3 -3
  24. package/dist/checkout.js +91 -58
  25. package/dist/config.js +1 -1
  26. package/dist/index.browser.js +5 -5
  27. package/dist/index.browser.js.map +1 -1
  28. package/dist/index.cjs +108 -66
  29. package/dist/index.js +108 -66
  30. package/dist/minting_backend.js +2 -2
  31. package/dist/orderbook.js +1 -1
  32. package/dist/passport.js +18 -9
  33. package/dist/webhook.js +1 -1
  34. package/dist/x.js +3 -3
  35. package/package.json +1 -2
  36. package/dist/browser/checkout/SwapWidget-18657ab4.js +0 -1
  37. package/dist/browser/checkout/balance-3621d500.js +0 -1
  38. package/dist/browser/checkout/index-f3fb0a60.js +0 -1
package/dist/index.cjs CHANGED
@@ -185,7 +185,7 @@ const flattenProperties$1 = (properties) => {
185
185
  };
186
186
 
187
187
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
188
- const SDK_VERSION$1 = '1.43.2-alpha.1';
188
+ const SDK_VERSION$1 = '1.43.2-alpha.11';
189
189
  const getFrameParentDomain$1 = () => {
190
190
  if (isNode$1()) {
191
191
  return '';
@@ -14212,7 +14212,7 @@ class MultiRollupApiClients {
14212
14212
  }
14213
14213
 
14214
14214
  // eslint-disable-next-line @typescript-eslint/naming-convention
14215
- const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.1' };
14215
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.11' };
14216
14216
  const createConfig$1 = ({ basePath, headers, }) => {
14217
14217
  if (!basePath.trim()) {
14218
14218
  throw Error('basePath can not be empty');
@@ -14284,7 +14284,7 @@ class APIError extends Error {
14284
14284
 
14285
14285
  /* eslint-disable implicit-arrow-linebreak */
14286
14286
  const defaultHeaders$1 = {
14287
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.1',
14287
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.11',
14288
14288
  };
14289
14289
  /**
14290
14290
  * createAPIConfiguration to create a custom Configuration
@@ -14758,7 +14758,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
14758
14758
  /* eslint-disable @typescript-eslint/naming-convention */
14759
14759
  class ApiConfiguration extends index$2.Configuration {
14760
14760
  }
14761
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.1' };
14761
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.11' };
14762
14762
  /**
14763
14763
  * @dev use createImmutableXConfiguration instead
14764
14764
  */
@@ -14799,7 +14799,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
14799
14799
  coreContractAddress,
14800
14800
  registrationContractAddress,
14801
14801
  registrationV4ContractAddress,
14802
- sdkVersion: 'ts-immutable-sdk-1.43.2-alpha.1',
14802
+ sdkVersion: 'ts-immutable-sdk-1.43.2-alpha.11',
14803
14803
  baseConfig,
14804
14804
  });
14805
14805
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -30623,18 +30623,27 @@ class ZkEvmProvider {
30623
30623
  return ethers.utils.hexlify(chainId);
30624
30624
  }
30625
30625
  // Pass through methods
30626
- case 'eth_gasPrice':
30627
30626
  case 'eth_getBalance':
30628
30627
  case 'eth_getCode':
30629
- case 'eth_getStorageAt':
30630
- case 'eth_estimateGas':
30628
+ case 'eth_getTransactionCount': {
30629
+ const [address, blockNumber] = request.params || [];
30630
+ return this.#rpcProvider.send(request.method, [address, blockNumber || 'latest']);
30631
+ }
30632
+ case 'eth_getStorageAt': {
30633
+ const [address, storageSlot, blockNumber] = request.params || [];
30634
+ return this.#rpcProvider.send(request.method, [address, storageSlot, blockNumber || 'latest']);
30635
+ }
30631
30636
  case 'eth_call':
30637
+ case 'eth_estimateGas': {
30638
+ const [transaction, blockNumber] = request.params || [];
30639
+ return this.#rpcProvider.send(request.method, [transaction, blockNumber || 'latest']);
30640
+ }
30641
+ case 'eth_gasPrice':
30632
30642
  case 'eth_blockNumber':
30633
30643
  case 'eth_getBlockByHash':
30634
30644
  case 'eth_getBlockByNumber':
30635
30645
  case 'eth_getTransactionByHash':
30636
- case 'eth_getTransactionReceipt':
30637
- case 'eth_getTransactionCount': {
30646
+ case 'eth_getTransactionReceipt': {
30638
30647
  return this.#rpcProvider.send(request.method, request.params || []);
30639
30648
  }
30640
30649
  default: {
@@ -47019,13 +47028,8 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
47019
47028
  }
47020
47029
 
47021
47030
  /* eslint-disable @typescript-eslint/naming-convention */
47022
- // TODO generate a type for these state objects. Readability could be improved from the double nested Record
47023
47031
  /**
47024
- * Submits tenderly simulations, returning an array of gas usage estimates
47025
- * @param chainId ID of network to estimate transactions on
47026
- * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
47027
- * @param state_objects A double-nested record which can be used to change the state of smart contracts in the simulation.
47028
- * @returns Array of gas usage estimates.
47032
+ * We want to convert a StateObject type to the following format (Record<string, Record<string, Record<string, string>>>):
47029
47033
  * @example An example of a state object that changes the state at slot 0xe1b959...2585e to 1 at address 0xe43215...8E31:
47030
47034
  * {
47031
47035
  * "0xe432150cce91c13a887f7D836923d5597adD8E31": {
@@ -47036,9 +47040,32 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
47036
47040
  * }
47037
47041
  * }
47038
47042
  */
47039
- async function submitTenderlySimulations(chainId, simulations, state_objects) {
47043
+ function unwrapStateObjects(stateObjects) {
47044
+ const unwrappedStateObjects = {};
47045
+ stateObjects.forEach((stateObject) => {
47046
+ const { contractAddress, stateDiff } = stateObject;
47047
+ const { storageSlot, value } = stateDiff;
47048
+ if (unwrappedStateObjects[contractAddress] === undefined) {
47049
+ unwrappedStateObjects[contractAddress] = {
47050
+ stateDiff: {},
47051
+ };
47052
+ }
47053
+ unwrappedStateObjects[contractAddress].stateDiff[storageSlot] = value;
47054
+ });
47055
+ return unwrappedStateObjects;
47056
+ }
47057
+ /**
47058
+ * Submits tenderly simulations, returning an array of gas usage estimates
47059
+ * @param chainId ID of network to estimate transactions on
47060
+ * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
47061
+ * @param stateObjects An array of `StateObject`s. Each `StateObject` represents one smart contract state change.
47062
+ * These `StateObject`s get unwrapped into Tenderly's required format.
47063
+ * @returns Array of gas usage estimates.
47064
+ */
47065
+ async function submitTenderlySimulations(chainId, simulations, stateObjects) {
47040
47066
  let axiosResponse;
47041
47067
  const tenderlyAPI = getTenderlyEndpoint(chainId);
47068
+ const state_objects = stateObjects ? unwrapStateObjects(stateObjects) : undefined;
47042
47069
  try {
47043
47070
  axiosResponse = await axios$1.post(tenderlyAPI, {
47044
47071
  jsonrpc: '2.0',
@@ -47078,6 +47105,54 @@ async function submitTenderlySimulations(chainId, simulations, state_objects) {
47078
47105
  return gas;
47079
47106
  }
47080
47107
 
47108
+ const trueInHex = '0x0000000000000000000000000000000000000000000000000000000000000001';
47109
+
47110
+ /**
47111
+ * @param sender Bridge depositer/withdrawer
47112
+ * @param recipient Deposit or withdrawal recipient
47113
+ * @param amount Amount to deposit or withdraw
47114
+ * @param token Token to deposit or withdraw. NATIVE if native asset on the source chain.
47115
+ * @param currentBridgeMethods A Record mapping bridge operation names to contract method names
47116
+ * @param bridgeContract: The bridge contract to be interacting with dependinig on network and if it's a deposit or withdrawal
47117
+ * @returns calldata for the requested bridge transaction (i.e. tx.data)
47118
+ */
47119
+ async function getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract) {
47120
+ let functionName;
47121
+ let parameters;
47122
+ /**
47123
+ * Handle bridge transaction for native token
47124
+ */
47125
+ if (token.toUpperCase() === NATIVE$1) {
47126
+ if (sender === recipient) {
47127
+ // Deposit or withdraw native token
47128
+ functionName = currentBridgeMethods.native;
47129
+ parameters = [amount];
47130
+ }
47131
+ else {
47132
+ // Deposit or withdraw native token TO
47133
+ functionName = currentBridgeMethods.nativeTo;
47134
+ parameters = [recipient, amount];
47135
+ }
47136
+ }
47137
+ else {
47138
+ /**
47139
+ * Handle bridge transaction for ERC20
47140
+ */
47141
+ const erc20Token = getAddress(token);
47142
+ if (sender === recipient) {
47143
+ // Deposit or withdraw ERC20
47144
+ functionName = currentBridgeMethods.token;
47145
+ parameters = [erc20Token, amount];
47146
+ }
47147
+ else {
47148
+ // Deposit or withdraw ERC20 TO.
47149
+ functionName = currentBridgeMethods.tokenTo;
47150
+ parameters = [erc20Token, recipient, amount];
47151
+ }
47152
+ }
47153
+ return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
47154
+ }
47155
+
47081
47156
  const ROOT_ERC20_BRIDGE_FLOW_RATE = [
47082
47157
  {
47083
47158
  inputs: [
@@ -50770,7 +50845,7 @@ class TokenBridge {
50770
50845
  if (isValidDeposit(direction, this.config.bridgeInstance)) {
50771
50846
  approvalFee = calculateGasFee$1(feeData, BridgeMethodsGasLimit.APPROVE_TOKEN);
50772
50847
  }
50773
- else if (isWithdrawWrappedIMX(req.token, direction, this.config.bridgeInstance)) {
50848
+ else if ('token' in req && isWithdrawWrappedIMX(req.token, direction, this.config.bridgeInstance)) {
50774
50849
  // On child chain, only WIMX requires approval.
50775
50850
  approvalFee = calculateGasFee$1(feeData, BridgeMethodsGasLimit.APPROVE_TOKEN);
50776
50851
  }
@@ -50918,43 +50993,10 @@ class TokenBridge {
50918
50993
  * @param sourceChainId Chain ID of the source chain
50919
50994
  * @returns calldata for the requested bridge transaction (i.e. tx.data)
50920
50995
  */
50921
- async getTxData(sender, recipient, amount, token, direction) {
50996
+ async getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction) {
50922
50997
  const currentBridgeMethods = await this.getBridgeMethods(direction);
50923
50998
  const bridgeContract = await this.getBridgeContract(direction);
50924
- let functionName;
50925
- let parameters;
50926
- /**
50927
- * Handle bridge transaction for native token
50928
- */
50929
- if (token.toUpperCase() === NATIVE$1) {
50930
- if (sender === recipient) {
50931
- // Deposit or withdraw native token
50932
- functionName = currentBridgeMethods.native;
50933
- parameters = [amount];
50934
- }
50935
- else {
50936
- // Deposit or withdraw native token TO
50937
- functionName = currentBridgeMethods.nativeTo;
50938
- parameters = [recipient, amount];
50939
- }
50940
- }
50941
- else {
50942
- /**
50943
- * Handle bridge transaction for ERC20
50944
- */
50945
- const erc20Token = getAddress(token);
50946
- if (sender === recipient) {
50947
- // Deposit or withdraw ERC20
50948
- functionName = currentBridgeMethods.token;
50949
- parameters = [erc20Token, amount];
50950
- }
50951
- else {
50952
- // Deposit or withdraw ERC20 TO.
50953
- functionName = currentBridgeMethods.tokenTo;
50954
- parameters = [erc20Token, recipient, amount];
50955
- }
50956
- }
50957
- return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
50999
+ return getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract);
50958
51000
  }
50959
51001
  /**
50960
51002
  * Generates an unsigned deposit or withdrawal transaction for a user to sign and submit to the bridge.
@@ -51183,7 +51225,7 @@ class TokenBridge {
51183
51225
  unsignedApprovalTx = null;
51184
51226
  }
51185
51227
  // Deposit transaction & fees.
51186
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51228
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51187
51229
  const txValue = (token.toUpperCase() === NATIVE$1)
51188
51230
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
51189
51231
  const unsignedBridgeTx = {
@@ -51245,7 +51287,7 @@ class TokenBridge {
51245
51287
  unsignedApprovalTx = null;
51246
51288
  }
51247
51289
  // Withdraw transaction & fees.
51248
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51290
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51249
51291
  const txValue = (token.toUpperCase() === NATIVE$1)
51250
51292
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
51251
51293
  const unsignedBridgeTx = {
@@ -51294,7 +51336,7 @@ class TokenBridge {
51294
51336
  destinationChainId: this.config.bridgeInstance.childChainID,
51295
51337
  };
51296
51338
  // Get tx data
51297
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51339
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51298
51340
  // tx value for simulation mocked as amount + 1 wei for a native bridge and 1 wei for token bridges
51299
51341
  // hexValue() is required to remove leading zeros, which tenderly does not support.
51300
51342
  const txValue = (token.toUpperCase() !== NATIVE$1) ? '0x1' : hexValue(amount.add('1').toHexString());
@@ -51330,7 +51372,7 @@ class TokenBridge {
51330
51372
  // Calculate slot key for given command ID.
51331
51373
  const command = defaultAbiCoder.encode(['bytes32', 'bytes32', 'string', 'string', 'address', 'bytes32'], [SLOT_PREFIX_CONTRACT_CALL_APPROVED, commandId, sourceChain, sourceAddress, destinationAddress, payloadHash]);
51332
51374
  const commandHash = keccak256(command);
51333
- const slot = keccak256(concat([
51375
+ const gatewayCallApprovedSlot = keccak256(concat([
51334
51376
  commandHash,
51335
51377
  hexlify(zeroPad(hexlify(SLOT_POS_CONTRACT_CALL_APPROVED), 32)),
51336
51378
  ]));
@@ -51345,14 +51387,14 @@ class TokenBridge {
51345
51387
  to: destinationAddress,
51346
51388
  data: executeData,
51347
51389
  }];
51348
- const gas = await submitTenderlySimulations(destinationChainId, simulations, {
51349
- [axelarGateway]: {
51350
- stateDiff: {
51351
- // Override storage to approve this command.
51352
- [slot]: '0x0000000000000000000000000000000000000000000000000000000000000001',
51353
- },
51390
+ const stateObject = {
51391
+ contractAddress: axelarGateway,
51392
+ stateDiff: {
51393
+ storageSlot: gatewayCallApprovedSlot,
51394
+ value: trueInHex,
51354
51395
  },
51355
- });
51396
+ };
51397
+ const gas = await submitTenderlySimulations(destinationChainId, simulations, [stateObject]);
51356
51398
  return gas[0];
51357
51399
  }
51358
51400
  async getAllowance(direction, token, sender) {
@@ -52226,7 +52268,7 @@ const flattenProperties = (properties) => {
52226
52268
  };
52227
52269
 
52228
52270
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
52229
- const SDK_VERSION = '1.43.2-alpha.1';
52271
+ const SDK_VERSION = '1.43.2-alpha.11';
52230
52272
  const getFrameParentDomain = () => {
52231
52273
  if (isNode()) {
52232
52274
  return '';
@@ -57545,7 +57587,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
57545
57587
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
57546
57588
  };
57547
57589
 
57548
- const SDK_VERSION_MARKER = '1.43.2-alpha.1';
57590
+ const SDK_VERSION_MARKER = '1.43.2-alpha.11';
57549
57591
  // This SDK version is replaced by the `yarn build` command ran on the root level
57550
57592
  const globalPackageVersion = () => SDK_VERSION_MARKER;
57551
57593
 
package/dist/index.js CHANGED
@@ -162,7 +162,7 @@ const flattenProperties$1 = (properties) => {
162
162
  };
163
163
 
164
164
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
165
- const SDK_VERSION$1 = '1.43.2-alpha.1';
165
+ const SDK_VERSION$1 = '1.43.2-alpha.11';
166
166
  const getFrameParentDomain$1 = () => {
167
167
  if (isNode$1()) {
168
168
  return '';
@@ -14189,7 +14189,7 @@ class MultiRollupApiClients {
14189
14189
  }
14190
14190
 
14191
14191
  // eslint-disable-next-line @typescript-eslint/naming-convention
14192
- const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.1' };
14192
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.11' };
14193
14193
  const createConfig$1 = ({ basePath, headers, }) => {
14194
14194
  if (!basePath.trim()) {
14195
14195
  throw Error('basePath can not be empty');
@@ -14261,7 +14261,7 @@ class APIError extends Error {
14261
14261
 
14262
14262
  /* eslint-disable implicit-arrow-linebreak */
14263
14263
  const defaultHeaders$1 = {
14264
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.1',
14264
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.11',
14265
14265
  };
14266
14266
  /**
14267
14267
  * createAPIConfiguration to create a custom Configuration
@@ -14735,7 +14735,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
14735
14735
  /* eslint-disable @typescript-eslint/naming-convention */
14736
14736
  class ApiConfiguration extends index$2.Configuration {
14737
14737
  }
14738
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.1' };
14738
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.43.2-alpha.11' };
14739
14739
  /**
14740
14740
  * @dev use createImmutableXConfiguration instead
14741
14741
  */
@@ -14776,7 +14776,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
14776
14776
  coreContractAddress,
14777
14777
  registrationContractAddress,
14778
14778
  registrationV4ContractAddress,
14779
- sdkVersion: 'ts-immutable-sdk-1.43.2-alpha.1',
14779
+ sdkVersion: 'ts-immutable-sdk-1.43.2-alpha.11',
14780
14780
  baseConfig,
14781
14781
  });
14782
14782
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -30600,18 +30600,27 @@ class ZkEvmProvider {
30600
30600
  return utils$3.hexlify(chainId);
30601
30601
  }
30602
30602
  // Pass through methods
30603
- case 'eth_gasPrice':
30604
30603
  case 'eth_getBalance':
30605
30604
  case 'eth_getCode':
30606
- case 'eth_getStorageAt':
30607
- case 'eth_estimateGas':
30605
+ case 'eth_getTransactionCount': {
30606
+ const [address, blockNumber] = request.params || [];
30607
+ return this.#rpcProvider.send(request.method, [address, blockNumber || 'latest']);
30608
+ }
30609
+ case 'eth_getStorageAt': {
30610
+ const [address, storageSlot, blockNumber] = request.params || [];
30611
+ return this.#rpcProvider.send(request.method, [address, storageSlot, blockNumber || 'latest']);
30612
+ }
30608
30613
  case 'eth_call':
30614
+ case 'eth_estimateGas': {
30615
+ const [transaction, blockNumber] = request.params || [];
30616
+ return this.#rpcProvider.send(request.method, [transaction, blockNumber || 'latest']);
30617
+ }
30618
+ case 'eth_gasPrice':
30609
30619
  case 'eth_blockNumber':
30610
30620
  case 'eth_getBlockByHash':
30611
30621
  case 'eth_getBlockByNumber':
30612
30622
  case 'eth_getTransactionByHash':
30613
- case 'eth_getTransactionReceipt':
30614
- case 'eth_getTransactionCount': {
30623
+ case 'eth_getTransactionReceipt': {
30615
30624
  return this.#rpcProvider.send(request.method, request.params || []);
30616
30625
  }
30617
30626
  default: {
@@ -46996,13 +47005,8 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
46996
47005
  }
46997
47006
 
46998
47007
  /* eslint-disable @typescript-eslint/naming-convention */
46999
- // TODO generate a type for these state objects. Readability could be improved from the double nested Record
47000
47008
  /**
47001
- * Submits tenderly simulations, returning an array of gas usage estimates
47002
- * @param chainId ID of network to estimate transactions on
47003
- * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
47004
- * @param state_objects A double-nested record which can be used to change the state of smart contracts in the simulation.
47005
- * @returns Array of gas usage estimates.
47009
+ * We want to convert a StateObject type to the following format (Record<string, Record<string, Record<string, string>>>):
47006
47010
  * @example An example of a state object that changes the state at slot 0xe1b959...2585e to 1 at address 0xe43215...8E31:
47007
47011
  * {
47008
47012
  * "0xe432150cce91c13a887f7D836923d5597adD8E31": {
@@ -47013,9 +47017,32 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
47013
47017
  * }
47014
47018
  * }
47015
47019
  */
47016
- async function submitTenderlySimulations(chainId, simulations, state_objects) {
47020
+ function unwrapStateObjects(stateObjects) {
47021
+ const unwrappedStateObjects = {};
47022
+ stateObjects.forEach((stateObject) => {
47023
+ const { contractAddress, stateDiff } = stateObject;
47024
+ const { storageSlot, value } = stateDiff;
47025
+ if (unwrappedStateObjects[contractAddress] === undefined) {
47026
+ unwrappedStateObjects[contractAddress] = {
47027
+ stateDiff: {},
47028
+ };
47029
+ }
47030
+ unwrappedStateObjects[contractAddress].stateDiff[storageSlot] = value;
47031
+ });
47032
+ return unwrappedStateObjects;
47033
+ }
47034
+ /**
47035
+ * Submits tenderly simulations, returning an array of gas usage estimates
47036
+ * @param chainId ID of network to estimate transactions on
47037
+ * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
47038
+ * @param stateObjects An array of `StateObject`s. Each `StateObject` represents one smart contract state change.
47039
+ * These `StateObject`s get unwrapped into Tenderly's required format.
47040
+ * @returns Array of gas usage estimates.
47041
+ */
47042
+ async function submitTenderlySimulations(chainId, simulations, stateObjects) {
47017
47043
  let axiosResponse;
47018
47044
  const tenderlyAPI = getTenderlyEndpoint(chainId);
47045
+ const state_objects = stateObjects ? unwrapStateObjects(stateObjects) : undefined;
47019
47046
  try {
47020
47047
  axiosResponse = await axios$1.post(tenderlyAPI, {
47021
47048
  jsonrpc: '2.0',
@@ -47055,6 +47082,54 @@ async function submitTenderlySimulations(chainId, simulations, state_objects) {
47055
47082
  return gas;
47056
47083
  }
47057
47084
 
47085
+ const trueInHex = '0x0000000000000000000000000000000000000000000000000000000000000001';
47086
+
47087
+ /**
47088
+ * @param sender Bridge depositer/withdrawer
47089
+ * @param recipient Deposit or withdrawal recipient
47090
+ * @param amount Amount to deposit or withdraw
47091
+ * @param token Token to deposit or withdraw. NATIVE if native asset on the source chain.
47092
+ * @param currentBridgeMethods A Record mapping bridge operation names to contract method names
47093
+ * @param bridgeContract: The bridge contract to be interacting with dependinig on network and if it's a deposit or withdrawal
47094
+ * @returns calldata for the requested bridge transaction (i.e. tx.data)
47095
+ */
47096
+ async function getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract) {
47097
+ let functionName;
47098
+ let parameters;
47099
+ /**
47100
+ * Handle bridge transaction for native token
47101
+ */
47102
+ if (token.toUpperCase() === NATIVE$1) {
47103
+ if (sender === recipient) {
47104
+ // Deposit or withdraw native token
47105
+ functionName = currentBridgeMethods.native;
47106
+ parameters = [amount];
47107
+ }
47108
+ else {
47109
+ // Deposit or withdraw native token TO
47110
+ functionName = currentBridgeMethods.nativeTo;
47111
+ parameters = [recipient, amount];
47112
+ }
47113
+ }
47114
+ else {
47115
+ /**
47116
+ * Handle bridge transaction for ERC20
47117
+ */
47118
+ const erc20Token = getAddress(token);
47119
+ if (sender === recipient) {
47120
+ // Deposit or withdraw ERC20
47121
+ functionName = currentBridgeMethods.token;
47122
+ parameters = [erc20Token, amount];
47123
+ }
47124
+ else {
47125
+ // Deposit or withdraw ERC20 TO.
47126
+ functionName = currentBridgeMethods.tokenTo;
47127
+ parameters = [erc20Token, recipient, amount];
47128
+ }
47129
+ }
47130
+ return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
47131
+ }
47132
+
47058
47133
  const ROOT_ERC20_BRIDGE_FLOW_RATE = [
47059
47134
  {
47060
47135
  inputs: [
@@ -50747,7 +50822,7 @@ class TokenBridge {
50747
50822
  if (isValidDeposit(direction, this.config.bridgeInstance)) {
50748
50823
  approvalFee = calculateGasFee$1(feeData, BridgeMethodsGasLimit.APPROVE_TOKEN);
50749
50824
  }
50750
- else if (isWithdrawWrappedIMX(req.token, direction, this.config.bridgeInstance)) {
50825
+ else if ('token' in req && isWithdrawWrappedIMX(req.token, direction, this.config.bridgeInstance)) {
50751
50826
  // On child chain, only WIMX requires approval.
50752
50827
  approvalFee = calculateGasFee$1(feeData, BridgeMethodsGasLimit.APPROVE_TOKEN);
50753
50828
  }
@@ -50895,43 +50970,10 @@ class TokenBridge {
50895
50970
  * @param sourceChainId Chain ID of the source chain
50896
50971
  * @returns calldata for the requested bridge transaction (i.e. tx.data)
50897
50972
  */
50898
- async getTxData(sender, recipient, amount, token, direction) {
50973
+ async getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction) {
50899
50974
  const currentBridgeMethods = await this.getBridgeMethods(direction);
50900
50975
  const bridgeContract = await this.getBridgeContract(direction);
50901
- let functionName;
50902
- let parameters;
50903
- /**
50904
- * Handle bridge transaction for native token
50905
- */
50906
- if (token.toUpperCase() === NATIVE$1) {
50907
- if (sender === recipient) {
50908
- // Deposit or withdraw native token
50909
- functionName = currentBridgeMethods.native;
50910
- parameters = [amount];
50911
- }
50912
- else {
50913
- // Deposit or withdraw native token TO
50914
- functionName = currentBridgeMethods.nativeTo;
50915
- parameters = [recipient, amount];
50916
- }
50917
- }
50918
- else {
50919
- /**
50920
- * Handle bridge transaction for ERC20
50921
- */
50922
- const erc20Token = getAddress(token);
50923
- if (sender === recipient) {
50924
- // Deposit or withdraw ERC20
50925
- functionName = currentBridgeMethods.token;
50926
- parameters = [erc20Token, amount];
50927
- }
50928
- else {
50929
- // Deposit or withdraw ERC20 TO.
50930
- functionName = currentBridgeMethods.tokenTo;
50931
- parameters = [erc20Token, recipient, amount];
50932
- }
50933
- }
50934
- return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
50976
+ return getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract);
50935
50977
  }
50936
50978
  /**
50937
50979
  * Generates an unsigned deposit or withdrawal transaction for a user to sign and submit to the bridge.
@@ -51160,7 +51202,7 @@ class TokenBridge {
51160
51202
  unsignedApprovalTx = null;
51161
51203
  }
51162
51204
  // Deposit transaction & fees.
51163
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51205
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51164
51206
  const txValue = (token.toUpperCase() === NATIVE$1)
51165
51207
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
51166
51208
  const unsignedBridgeTx = {
@@ -51222,7 +51264,7 @@ class TokenBridge {
51222
51264
  unsignedApprovalTx = null;
51223
51265
  }
51224
51266
  // Withdraw transaction & fees.
51225
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51267
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51226
51268
  const txValue = (token.toUpperCase() === NATIVE$1)
51227
51269
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
51228
51270
  const unsignedBridgeTx = {
@@ -51271,7 +51313,7 @@ class TokenBridge {
51271
51313
  destinationChainId: this.config.bridgeInstance.childChainID,
51272
51314
  };
51273
51315
  // Get tx data
51274
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
51316
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
51275
51317
  // tx value for simulation mocked as amount + 1 wei for a native bridge and 1 wei for token bridges
51276
51318
  // hexValue() is required to remove leading zeros, which tenderly does not support.
51277
51319
  const txValue = (token.toUpperCase() !== NATIVE$1) ? '0x1' : hexValue(amount.add('1').toHexString());
@@ -51307,7 +51349,7 @@ class TokenBridge {
51307
51349
  // Calculate slot key for given command ID.
51308
51350
  const command = defaultAbiCoder.encode(['bytes32', 'bytes32', 'string', 'string', 'address', 'bytes32'], [SLOT_PREFIX_CONTRACT_CALL_APPROVED, commandId, sourceChain, sourceAddress, destinationAddress, payloadHash]);
51309
51351
  const commandHash = keccak256(command);
51310
- const slot = keccak256(concat([
51352
+ const gatewayCallApprovedSlot = keccak256(concat([
51311
51353
  commandHash,
51312
51354
  hexlify(zeroPad(hexlify(SLOT_POS_CONTRACT_CALL_APPROVED), 32)),
51313
51355
  ]));
@@ -51322,14 +51364,14 @@ class TokenBridge {
51322
51364
  to: destinationAddress,
51323
51365
  data: executeData,
51324
51366
  }];
51325
- const gas = await submitTenderlySimulations(destinationChainId, simulations, {
51326
- [axelarGateway]: {
51327
- stateDiff: {
51328
- // Override storage to approve this command.
51329
- [slot]: '0x0000000000000000000000000000000000000000000000000000000000000001',
51330
- },
51367
+ const stateObject = {
51368
+ contractAddress: axelarGateway,
51369
+ stateDiff: {
51370
+ storageSlot: gatewayCallApprovedSlot,
51371
+ value: trueInHex,
51331
51372
  },
51332
- });
51373
+ };
51374
+ const gas = await submitTenderlySimulations(destinationChainId, simulations, [stateObject]);
51333
51375
  return gas[0];
51334
51376
  }
51335
51377
  async getAllowance(direction, token, sender) {
@@ -52203,7 +52245,7 @@ const flattenProperties = (properties) => {
52203
52245
  };
52204
52246
 
52205
52247
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
52206
- const SDK_VERSION = '1.43.2-alpha.1';
52248
+ const SDK_VERSION = '1.43.2-alpha.11';
52207
52249
  const getFrameParentDomain = () => {
52208
52250
  if (isNode()) {
52209
52251
  return '';
@@ -57522,7 +57564,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
57522
57564
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
57523
57565
  };
57524
57566
 
57525
- const SDK_VERSION_MARKER = '1.43.2-alpha.1';
57567
+ const SDK_VERSION_MARKER = '1.43.2-alpha.11';
57526
57568
  // This SDK version is replaced by the `yarn build` command ran on the root level
57527
57569
  const globalPackageVersion = () => SDK_VERSION_MARKER;
57528
57570
 
@@ -5286,7 +5286,7 @@ const flattenProperties = (properties) => {
5286
5286
  };
5287
5287
 
5288
5288
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
5289
- const SDK_VERSION = '1.43.2-alpha.1';
5289
+ const SDK_VERSION = '1.43.2-alpha.11';
5290
5290
  const getFrameParentDomain = () => {
5291
5291
  if (isNode()) {
5292
5292
  return '';
@@ -5554,7 +5554,7 @@ class APIError extends Error {
5554
5554
 
5555
5555
  /* eslint-disable implicit-arrow-linebreak */
5556
5556
  const defaultHeaders = {
5557
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.1',
5557
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.11',
5558
5558
  };
5559
5559
  /**
5560
5560
  * createAPIConfiguration to create a custom Configuration
package/dist/orderbook.js CHANGED
@@ -133,7 +133,7 @@ const flattenProperties = (properties) => {
133
133
  };
134
134
 
135
135
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
136
- const SDK_VERSION = '1.43.2-alpha.1';
136
+ const SDK_VERSION = '1.43.2-alpha.11';
137
137
  const getFrameParentDomain = () => {
138
138
  if (isNode()) {
139
139
  return '';