@imtbl/sdk 1.43.2-alpha.8 → 1.43.2-alpha.9

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 (36) hide show
  1. package/dist/blockchain_data.js +2 -2
  2. package/dist/browser/checkout/{BridgeWidget-658e152c.js → BridgeWidget-65a6f548.js} +1 -1
  3. package/dist/browser/checkout/{OnRampWidget-fea8789a.js → OnRampWidget-2ad8527a.js} +1 -1
  4. package/dist/browser/checkout/{SaleWidget-03dd6551.js → SaleWidget-39f46402.js} +1 -1
  5. package/dist/browser/checkout/{SpendingCapHero-220f61bf.js → SpendingCapHero-5ea5ca00.js} +1 -1
  6. package/dist/browser/checkout/{SwapWidget-d09f2ca0.js → SwapWidget-8f257923.js} +1 -1
  7. package/dist/browser/checkout/{TopUpView-4e4983da.js → TopUpView-1ee96622.js} +1 -1
  8. package/dist/browser/checkout/{WalletWidget-28ba6bfb.js → WalletWidget-d34a438a.js} +1 -1
  9. package/dist/browser/checkout/{auto-track-f8c278b4.js → auto-track-4bc18a69.js} +1 -1
  10. package/dist/browser/checkout/{balance-78f9d53c.js → balance-de2a2c73.js} +1 -1
  11. package/dist/browser/checkout/{index-d6bb330e.js → index-1672c9aa.js} +1 -1
  12. package/dist/browser/checkout/{index-a08c7054.js → index-1838fda1.js} +1 -1
  13. package/dist/browser/checkout/{index-963082eb.js → index-2244a7f0.js} +1 -1
  14. package/dist/browser/checkout/{index-1d657ceb.js → index-a5536772.js} +3 -3
  15. package/dist/browser/checkout/{index-a40f8006.js → index-b2a772fc.js} +1 -1
  16. package/dist/browser/checkout/{index-9fbf62cf.js → index-cc166624.js} +1 -1
  17. package/dist/browser/checkout/{index-e6efd23e.js → index-d8d68038.js} +1 -1
  18. package/dist/browser/checkout/index-f426b9fd.js +1 -0
  19. package/dist/browser/checkout/{index.umd-06c44429.js → index.umd-fd3873f7.js} +1 -1
  20. package/dist/browser/checkout/{retry-4841e554.js → retry-f5c958f0.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 +1 -1
  24. package/dist/checkout.js +90 -57
  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 +93 -60
  29. package/dist/index.js +93 -60
  30. package/dist/minting_backend.js +2 -2
  31. package/dist/orderbook.js +1 -1
  32. package/dist/passport.js +4 -4
  33. package/dist/webhook.js +1 -1
  34. package/dist/x.js +3 -3
  35. package/package.json +1 -1
  36. package/dist/browser/checkout/index-0ab42d36.js +0 -1
package/dist/checkout.js CHANGED
@@ -141,7 +141,7 @@ const flattenProperties$1 = (properties) => {
141
141
  };
142
142
 
143
143
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
144
- const SDK_VERSION$1 = '1.43.2-alpha.8';
144
+ const SDK_VERSION$1 = '1.43.2-alpha.9';
145
145
  const getFrameParentDomain$1 = () => {
146
146
  if (isNode$1()) {
147
147
  return '';
@@ -14311,13 +14311,8 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
14311
14311
  }
14312
14312
 
14313
14313
  /* eslint-disable @typescript-eslint/naming-convention */
14314
- // TODO generate a type for these state objects. Readability could be improved from the double nested Record
14315
14314
  /**
14316
- * Submits tenderly simulations, returning an array of gas usage estimates
14317
- * @param chainId ID of network to estimate transactions on
14318
- * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
14319
- * @param state_objects A double-nested record which can be used to change the state of smart contracts in the simulation.
14320
- * @returns Array of gas usage estimates.
14315
+ * We want to convert a StateObject type to the following format (Record<string, Record<string, Record<string, string>>>):
14321
14316
  * @example An example of a state object that changes the state at slot 0xe1b959...2585e to 1 at address 0xe43215...8E31:
14322
14317
  * {
14323
14318
  * "0xe432150cce91c13a887f7D836923d5597adD8E31": {
@@ -14328,9 +14323,32 @@ async function getWithdrawRootToken(childToken, destinationChainId, childProvide
14328
14323
  * }
14329
14324
  * }
14330
14325
  */
14331
- async function submitTenderlySimulations(chainId, simulations, state_objects) {
14326
+ function unwrapStateObjects(stateObjects) {
14327
+ const unwrappedStateObjects = {};
14328
+ stateObjects.forEach((stateObject) => {
14329
+ const { contractAddress, stateDiff } = stateObject;
14330
+ const { storageSlot, value } = stateDiff;
14331
+ if (unwrappedStateObjects[contractAddress] === undefined) {
14332
+ unwrappedStateObjects[contractAddress] = {
14333
+ stateDiff: {},
14334
+ };
14335
+ }
14336
+ unwrappedStateObjects[contractAddress].stateDiff[storageSlot] = value;
14337
+ });
14338
+ return unwrappedStateObjects;
14339
+ }
14340
+ /**
14341
+ * Submits tenderly simulations, returning an array of gas usage estimates
14342
+ * @param chainId ID of network to estimate transactions on
14343
+ * @param simulations Array of TenderlySimulation objects (transactions) to estimate gas usage for
14344
+ * @param stateObjects An array of `StateObject`s. Each `StateObject` represents one smart contract state change.
14345
+ * These `StateObject`s get unwrapped into Tenderly's required format.
14346
+ * @returns Array of gas usage estimates.
14347
+ */
14348
+ async function submitTenderlySimulations(chainId, simulations, stateObjects) {
14332
14349
  let axiosResponse;
14333
14350
  const tenderlyAPI = getTenderlyEndpoint(chainId);
14351
+ const state_objects = stateObjects ? unwrapStateObjects(stateObjects) : undefined;
14334
14352
  try {
14335
14353
  axiosResponse = await axios$1.post(tenderlyAPI, {
14336
14354
  jsonrpc: '2.0',
@@ -14370,6 +14388,54 @@ async function submitTenderlySimulations(chainId, simulations, state_objects) {
14370
14388
  return gas;
14371
14389
  }
14372
14390
 
14391
+ const trueInHex = '0x0000000000000000000000000000000000000000000000000000000000000001';
14392
+
14393
+ /**
14394
+ * @param sender Bridge depositer/withdrawer
14395
+ * @param recipient Deposit or withdrawal recipient
14396
+ * @param amount Amount to deposit or withdraw
14397
+ * @param token Token to deposit or withdraw. NATIVE if native asset on the source chain.
14398
+ * @param currentBridgeMethods A Record mapping bridge operation names to contract method names
14399
+ * @param bridgeContract: The bridge contract to be interacting with dependinig on network and if it's a deposit or withdrawal
14400
+ * @returns calldata for the requested bridge transaction (i.e. tx.data)
14401
+ */
14402
+ async function getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract) {
14403
+ let functionName;
14404
+ let parameters;
14405
+ /**
14406
+ * Handle bridge transaction for native token
14407
+ */
14408
+ if (token.toUpperCase() === NATIVE$1) {
14409
+ if (sender === recipient) {
14410
+ // Deposit or withdraw native token
14411
+ functionName = currentBridgeMethods.native;
14412
+ parameters = [amount];
14413
+ }
14414
+ else {
14415
+ // Deposit or withdraw native token TO
14416
+ functionName = currentBridgeMethods.nativeTo;
14417
+ parameters = [recipient, amount];
14418
+ }
14419
+ }
14420
+ else {
14421
+ /**
14422
+ * Handle bridge transaction for ERC20
14423
+ */
14424
+ const erc20Token = getAddress(token);
14425
+ if (sender === recipient) {
14426
+ // Deposit or withdraw ERC20
14427
+ functionName = currentBridgeMethods.token;
14428
+ parameters = [erc20Token, amount];
14429
+ }
14430
+ else {
14431
+ // Deposit or withdraw ERC20 TO.
14432
+ functionName = currentBridgeMethods.tokenTo;
14433
+ parameters = [erc20Token, recipient, amount];
14434
+ }
14435
+ }
14436
+ return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
14437
+ }
14438
+
14373
14439
  const ROOT_ERC20_BRIDGE_FLOW_RATE = [
14374
14440
  {
14375
14441
  inputs: [
@@ -18210,43 +18276,10 @@ class TokenBridge {
18210
18276
  * @param sourceChainId Chain ID of the source chain
18211
18277
  * @returns calldata for the requested bridge transaction (i.e. tx.data)
18212
18278
  */
18213
- async getTxData(sender, recipient, amount, token, direction) {
18279
+ async getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction) {
18214
18280
  const currentBridgeMethods = await this.getBridgeMethods(direction);
18215
18281
  const bridgeContract = await this.getBridgeContract(direction);
18216
- let functionName;
18217
- let parameters;
18218
- /**
18219
- * Handle bridge transaction for native token
18220
- */
18221
- if (token.toUpperCase() === NATIVE$1) {
18222
- if (sender === recipient) {
18223
- // Deposit or withdraw native token
18224
- functionName = currentBridgeMethods.native;
18225
- parameters = [amount];
18226
- }
18227
- else {
18228
- // Deposit or withdraw native token TO
18229
- functionName = currentBridgeMethods.nativeTo;
18230
- parameters = [recipient, amount];
18231
- }
18232
- }
18233
- else {
18234
- /**
18235
- * Handle bridge transaction for ERC20
18236
- */
18237
- const erc20Token = getAddress(token);
18238
- if (sender === recipient) {
18239
- // Deposit or withdraw ERC20
18240
- functionName = currentBridgeMethods.token;
18241
- parameters = [erc20Token, amount];
18242
- }
18243
- else {
18244
- // Deposit or withdraw ERC20 TO.
18245
- functionName = currentBridgeMethods.tokenTo;
18246
- parameters = [erc20Token, recipient, amount];
18247
- }
18248
- }
18249
- return await withBridgeError(async () => bridgeContract.interface.encodeFunctionData(functionName, parameters), BridgeErrorType.INTERNAL_ERROR);
18282
+ return getBridgeTxCalldata(sender, recipient, amount, token, currentBridgeMethods, bridgeContract);
18250
18283
  }
18251
18284
  /**
18252
18285
  * Generates an unsigned deposit or withdrawal transaction for a user to sign and submit to the bridge.
@@ -18475,7 +18508,7 @@ class TokenBridge {
18475
18508
  unsignedApprovalTx = null;
18476
18509
  }
18477
18510
  // Deposit transaction & fees.
18478
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
18511
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
18479
18512
  const txValue = (token.toUpperCase() === NATIVE$1)
18480
18513
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
18481
18514
  const unsignedBridgeTx = {
@@ -18537,7 +18570,7 @@ class TokenBridge {
18537
18570
  unsignedApprovalTx = null;
18538
18571
  }
18539
18572
  // Withdraw transaction & fees.
18540
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
18573
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
18541
18574
  const txValue = (token.toUpperCase() === NATIVE$1)
18542
18575
  ? amount.add(bridgeFee).toString() : bridgeFee.toString();
18543
18576
  const unsignedBridgeTx = {
@@ -18586,7 +18619,7 @@ class TokenBridge {
18586
18619
  destinationChainId: this.config.bridgeInstance.childChainID,
18587
18620
  };
18588
18621
  // Get tx data
18589
- const txData = await this.getTxData(sender, recipient, amount, token, direction);
18622
+ const txData = await this.getConfigAndBridgeTxCalldata(sender, recipient, amount, token, direction);
18590
18623
  // tx value for simulation mocked as amount + 1 wei for a native bridge and 1 wei for token bridges
18591
18624
  // hexValue() is required to remove leading zeros, which tenderly does not support.
18592
18625
  const txValue = (token.toUpperCase() !== NATIVE$1) ? '0x1' : hexValue(amount.add('1').toHexString());
@@ -18622,7 +18655,7 @@ class TokenBridge {
18622
18655
  // Calculate slot key for given command ID.
18623
18656
  const command = defaultAbiCoder.encode(['bytes32', 'bytes32', 'string', 'string', 'address', 'bytes32'], [SLOT_PREFIX_CONTRACT_CALL_APPROVED, commandId, sourceChain, sourceAddress, destinationAddress, payloadHash]);
18624
18657
  const commandHash = keccak256(command);
18625
- const slot = keccak256(concat([
18658
+ const gatewayCallApprovedSlot = keccak256(concat([
18626
18659
  commandHash,
18627
18660
  hexlify(zeroPad(hexlify(SLOT_POS_CONTRACT_CALL_APPROVED), 32)),
18628
18661
  ]));
@@ -18637,14 +18670,14 @@ class TokenBridge {
18637
18670
  to: destinationAddress,
18638
18671
  data: executeData,
18639
18672
  }];
18640
- const gas = await submitTenderlySimulations(destinationChainId, simulations, {
18641
- [axelarGateway]: {
18642
- stateDiff: {
18643
- // Override storage to approve this command.
18644
- [slot]: '0x0000000000000000000000000000000000000000000000000000000000000001',
18645
- },
18673
+ const stateObject = {
18674
+ contractAddress: axelarGateway,
18675
+ stateDiff: {
18676
+ storageSlot: gatewayCallApprovedSlot,
18677
+ value: trueInHex,
18646
18678
  },
18647
- });
18679
+ };
18680
+ const gas = await submitTenderlySimulations(destinationChainId, simulations, [stateObject]);
18648
18681
  return gas[0];
18649
18682
  }
18650
18683
  async getAllowance(direction, token, sender) {
@@ -19518,7 +19551,7 @@ const flattenProperties = (properties) => {
19518
19551
  };
19519
19552
 
19520
19553
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
19521
- const SDK_VERSION = '1.43.2-alpha.8';
19554
+ const SDK_VERSION = '1.43.2-alpha.9';
19522
19555
  const getFrameParentDomain = () => {
19523
19556
  if (isNode()) {
19524
19557
  return '';
@@ -31072,7 +31105,7 @@ class APIError extends Error {
31072
31105
 
31073
31106
  /* eslint-disable implicit-arrow-linebreak */
31074
31107
  const defaultHeaders = {
31075
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.8',
31108
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.43.2-alpha.9',
31076
31109
  };
31077
31110
  /**
31078
31111
  * createAPIConfiguration to create a custom Configuration
@@ -32604,7 +32637,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
32604
32637
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
32605
32638
  };
32606
32639
 
32607
- const SDK_VERSION_MARKER = '1.43.2-alpha.8';
32640
+ const SDK_VERSION_MARKER = '1.43.2-alpha.9';
32608
32641
  // This SDK version is replaced by the `yarn build` command ran on the root level
32609
32642
  const globalPackageVersion = () => SDK_VERSION_MARKER;
32610
32643
 
package/dist/config.js CHANGED
@@ -128,7 +128,7 @@ const flattenProperties = (properties) => {
128
128
  };
129
129
 
130
130
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
131
- const SDK_VERSION = '1.43.2-alpha.8';
131
+ const SDK_VERSION = '1.43.2-alpha.9';
132
132
  const getFrameParentDomain = () => {
133
133
  if (isNode()) {
134
134
  return '';