@imtbl/sdk 0.3.0-alpha.3 → 0.3.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -9,10 +9,10 @@ var oidc = require('@magic-ext/oidc');
9
9
  var BN$2 = require('bn.js');
10
10
  var encUtils = require('enc-utils');
11
11
  var providers = require('@ethersproject/providers');
12
+ var events = require('events');
12
13
  var ethers = require('ethers');
13
14
  var abi = require('@0xsequence/abi');
14
15
  var config = require('@0xsequence/config');
15
- var events = require('events');
16
16
  var FormData$2 = require('form-data');
17
17
  var seaportJs = require('@opensea/seaport-js');
18
18
  var units = require('@ethersproject/units');
@@ -5551,7 +5551,7 @@ class MultiRollupApiClients {
5551
5551
  }
5552
5552
 
5553
5553
  // eslint-disable-next-line @typescript-eslint/naming-convention
5554
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.3.0-alpha.3' };
5554
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.3.1-alpha' };
5555
5555
  const createConfig = ({ basePath, headers, }) => {
5556
5556
  if (!basePath.trim()) {
5557
5557
  throw Error('basePath can not be empty');
@@ -5611,7 +5611,7 @@ class APIError extends Error {
5611
5611
 
5612
5612
  /* eslint-disable implicit-arrow-linebreak */
5613
5613
  const defaultHeaders = {
5614
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.3.0-alpha.3',
5614
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.3.1-alpha',
5615
5615
  };
5616
5616
  /**
5617
5617
  * createAPIConfiguration to create a custom Configuration
@@ -5877,7 +5877,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
5877
5877
  chainID,
5878
5878
  coreContractAddress,
5879
5879
  registrationContractAddress,
5880
- sdkVersion: 'ts-immutable-sdk-0.3.0-alpha.3',
5880
+ sdkVersion: 'ts-immutable-sdk-0.3.1-alpha',
5881
5881
  });
5882
5882
  /**
5883
5883
  * Sets `sdkVersion` at the time of build
@@ -9601,6 +9601,8 @@ var globalAxios = axios;
9601
9601
  * https://openapi-generator.tech
9602
9602
  * Do not edit the class manually.
9603
9603
  */
9604
+ // Some imports not used depending on template conditions
9605
+ // @ts-ignore
9604
9606
  const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
9605
9607
  /**
9606
9608
  *
@@ -9628,10 +9630,10 @@ class BaseAPI {
9628
9630
  */
9629
9631
  class RequiredError extends Error {
9630
9632
  field;
9633
+ name = "RequiredError";
9631
9634
  constructor(field, msg) {
9632
9635
  super(msg);
9633
9636
  this.field = field;
9634
- this.name = "RequiredError";
9635
9637
  }
9636
9638
  }
9637
9639
 
@@ -9676,8 +9678,6 @@ const setBearerAuthToObject = async function (object, configuration) {
9676
9678
  }
9677
9679
  };
9678
9680
  function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
9679
- if (parameter == null)
9680
- return;
9681
9681
  if (typeof parameter === "object") {
9682
9682
  if (Array.isArray(parameter)) {
9683
9683
  parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
@@ -9833,7 +9833,7 @@ const TransactionsApiAxiosParamCreator = function (configuration) {
9833
9833
  * @summary Info for a specific transaction
9834
9834
  * @param {string} transactionID The id of the starkex transaction to retrieve
9835
9835
  * @param {'starkex' | 'evm'} chainType roll up type
9836
- * @param {number} [chainID] ID of evm chain
9836
+ * @param {string} [chainID] ID of evm chain
9837
9837
  * @param {*} [options] Override http request option.
9838
9838
  * @throws {RequiredError}
9839
9839
  */
@@ -9908,7 +9908,7 @@ const TransactionsApiFp = function (configuration) {
9908
9908
  * @summary Info for a specific transaction
9909
9909
  * @param {string} transactionID The id of the starkex transaction to retrieve
9910
9910
  * @param {'starkex' | 'evm'} chainType roll up type
9911
- * @param {number} [chainID] ID of evm chain
9911
+ * @param {string} [chainID] ID of evm chain
9912
9912
  * @param {*} [options] Override http request option.
9913
9913
  * @throws {RequiredError}
9914
9914
  */
@@ -10595,6 +10595,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
10595
10595
  amount_sell: amountSell,
10596
10596
  token_sell: convertToSignableToken(request.sell),
10597
10597
  fees: request.fees,
10598
+ split_fees: true,
10598
10599
  expiration_timestamp: request.expiration_timestamp,
10599
10600
  };
10600
10601
  const getSignableOrderResponse = await ordersApi.getSignableOrder({
@@ -11108,7 +11109,7 @@ class PassportConfiguration {
11108
11109
  this.imxPublicApiDomain = 'https://api.immutable.com';
11109
11110
  this.zkEvmRpcUrl = ''; // TODO: ID-785 Update once mainnet has been deployed
11110
11111
  this.zkEvmChainId = ''; // TODO: ID-785 Update once mainnet has been deployed
11111
- this.relayerUrl = 'https://relayer.immutable.com'; // TODO: ID-784 Update once we have added Relayer URL to config
11112
+ this.relayerUrl = 'https://api.immutable.com/relayer-mr';
11112
11113
  this.multiRollupConfig = multiRollupConfig.getProduction();
11113
11114
  break;
11114
11115
  }
@@ -11122,7 +11123,7 @@ class PassportConfiguration {
11122
11123
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
11123
11124
  this.zkEvmRpcUrl = 'https://zkevm-rpc.sandbox.x.immutable.com';
11124
11125
  this.zkEvmChainId = 'eip155:13392';
11125
- this.relayerUrl = 'https://evm-relayer.sandbox.imtbl.com'; // TODO: ID-784 Update once we have added Relayer URL to config
11126
+ this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
11126
11127
  this.multiRollupConfig = multiRollupConfig.getSandbox();
11127
11128
  break;
11128
11129
  }
@@ -11284,6 +11285,169 @@ class ConfirmationScreen {
11284
11285
  }
11285
11286
  }
11286
11287
 
11288
+ var RelayerTransactionStatus;
11289
+ (function (RelayerTransactionStatus) {
11290
+ RelayerTransactionStatus["PENDING"] = "PENDING";
11291
+ RelayerTransactionStatus["SUBMITTED"] = "SUBMITTED";
11292
+ RelayerTransactionStatus["SUCCESSFUL"] = "SUCCESSFUL";
11293
+ RelayerTransactionStatus["REVERTED"] = "REVERTED";
11294
+ RelayerTransactionStatus["FAILED"] = "FAILED";
11295
+ })(RelayerTransactionStatus || (RelayerTransactionStatus = {}));
11296
+ exports.ProviderEvent = void 0;
11297
+ (function (ProviderEvent) {
11298
+ ProviderEvent["ACCOUNTS_CHANGED"] = "accountsChanged";
11299
+ })(exports.ProviderEvent || (exports.ProviderEvent = {}));
11300
+
11301
+ class TypedEventEmitter {
11302
+ emitter = new events.EventEmitter();
11303
+ emit(eventName, ...eventArg) {
11304
+ this.emitter.emit(eventName, ...eventArg);
11305
+ }
11306
+ on(eventName, handler) {
11307
+ this.emitter.on(eventName, handler);
11308
+ }
11309
+ removeListener(eventName, handler) {
11310
+ this.emitter.removeListener(eventName, handler);
11311
+ }
11312
+ }
11313
+
11314
+ class RelayerClient {
11315
+ config;
11316
+ constructor({ config }) {
11317
+ this.config = config;
11318
+ }
11319
+ async postToRelayer(request) {
11320
+ const body = {
11321
+ id: 1,
11322
+ jsonrpc: '2.0',
11323
+ ...request,
11324
+ };
11325
+ const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
11326
+ method: 'POST',
11327
+ headers: {
11328
+ 'Content-Type': 'application/json',
11329
+ },
11330
+ body: JSON.stringify(body),
11331
+ });
11332
+ const jsonResponse = await response.json();
11333
+ if (jsonResponse.error) {
11334
+ throw jsonResponse.error;
11335
+ }
11336
+ return jsonResponse;
11337
+ }
11338
+ async ethSendTransaction(to, data) {
11339
+ const payload = {
11340
+ method: 'eth_sendTransaction',
11341
+ params: [{
11342
+ to,
11343
+ data,
11344
+ chainId: this.config.zkEvmChainId.toString(),
11345
+ }],
11346
+ };
11347
+ const { result } = await this.postToRelayer(payload);
11348
+ return result;
11349
+ }
11350
+ async imGetTransactionByHash(hash) {
11351
+ const payload = {
11352
+ method: 'im_getTransactionByHash',
11353
+ params: [hash],
11354
+ };
11355
+ const { result } = await this.postToRelayer(payload);
11356
+ return result;
11357
+ }
11358
+ async imGetFeeOptions(userAddress, data) {
11359
+ const payload = {
11360
+ method: 'im_getFeeOptions',
11361
+ params: [{
11362
+ userAddress,
11363
+ data,
11364
+ chainId: this.config.zkEvmChainId.toString(),
11365
+ }],
11366
+ };
11367
+ const { result } = await this.postToRelayer(payload);
11368
+ return result;
11369
+ }
11370
+ }
11371
+
11372
+ /**
11373
+ * ProviderErrors should take priority over RpcErrorCodes
11374
+ */
11375
+ exports.ProviderErrorCode = void 0;
11376
+ (function (ProviderErrorCode) {
11377
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
11378
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
11379
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
11380
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
11381
+ })(exports.ProviderErrorCode || (exports.ProviderErrorCode = {}));
11382
+ exports.RpcErrorCode = void 0;
11383
+ (function (RpcErrorCode) {
11384
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
11385
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
11386
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
11387
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
11388
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
11389
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
11390
+ })(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
11391
+ class JsonRpcError extends Error {
11392
+ message;
11393
+ code;
11394
+ constructor(code, message) {
11395
+ super(message);
11396
+ this.message = message;
11397
+ this.code = code;
11398
+ }
11399
+ }
11400
+
11401
+ const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
11402
+ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, }) {
11403
+ const web3Provider = new providers.Web3Provider(magicProvider);
11404
+ const ethSigner = web3Provider.getSigner();
11405
+ const ethereumAddress = await ethSigner.getAddress();
11406
+ const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
11407
+ const headers = { Authorization: `Bearer ${accessToken}` };
11408
+ try {
11409
+ await multiRollupApiClients.passportApi.createCounterfactualAddress({
11410
+ createCounterfactualAddressRequest: {
11411
+ ethereumAddress,
11412
+ ethereumSignature,
11413
+ },
11414
+ }, { headers });
11415
+ }
11416
+ catch (error) {
11417
+ throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
11418
+ }
11419
+ const user = await authManager.loginSilent();
11420
+ if (!user?.zkEvm) {
11421
+ throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
11422
+ }
11423
+ return user;
11424
+ }
11425
+
11426
+ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, }) => {
11427
+ const user = await authManager.getUser() || await authManager.login();
11428
+ if (!user.idToken) {
11429
+ throw new Error('User is missing idToken');
11430
+ }
11431
+ const magicProvider = await magicAdapter.login(user.idToken, config.network);
11432
+ if (!user.zkEvm) {
11433
+ // Generate counterfactual address and retrieve updated Auth0 user
11434
+ const userZkevm = await registerZkEvmUser({
11435
+ authManager,
11436
+ magicProvider,
11437
+ multiRollupApiClients,
11438
+ accessToken: user.accessToken,
11439
+ });
11440
+ return {
11441
+ user: userZkevm,
11442
+ magicProvider,
11443
+ };
11444
+ }
11445
+ return {
11446
+ user: user,
11447
+ magicProvider,
11448
+ };
11449
+ };
11450
+
11287
11451
  // These are ignored by the Relayer but for consistency we set them to the
11288
11452
  // appropriate values for a 1/1 wallet.
11289
11453
  //
@@ -11359,51 +11523,48 @@ const chainIdNumber = (chainId) => {
11359
11523
  return ethers.BigNumber.from(caip2Components[1]);
11360
11524
  };
11361
11525
 
11362
- var RelayerTransactionStatus;
11363
- (function (RelayerTransactionStatus) {
11364
- RelayerTransactionStatus["PENDING"] = "PENDING";
11365
- RelayerTransactionStatus["SUBMITTED"] = "SUBMITTED";
11366
- RelayerTransactionStatus["SUCCESSFUL"] = "SUCCESSFUL";
11367
- RelayerTransactionStatus["REVERTED"] = "REVERTED";
11368
- RelayerTransactionStatus["FAILED"] = "FAILED";
11369
- })(RelayerTransactionStatus || (RelayerTransactionStatus = {}));
11370
- exports.ProviderEventNames = void 0;
11371
- (function (ProviderEventNames) {
11372
- ProviderEventNames["ACCOUNTS_CHANGED"] = "accountsChanged";
11373
- })(exports.ProviderEventNames || (exports.ProviderEventNames = {}));
11374
-
11375
- /**
11376
- * ProviderErrors should take priority over RpcErrorCodes
11377
- */
11378
- exports.ProviderErrorCode = void 0;
11379
- (function (ProviderErrorCode) {
11380
- ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
11381
- ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
11382
- ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
11383
- ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
11384
- })(exports.ProviderErrorCode || (exports.ProviderErrorCode = {}));
11385
- exports.RpcErrorCode = void 0;
11386
- (function (RpcErrorCode) {
11387
- RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
11388
- RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
11389
- RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
11390
- RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
11391
- RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
11392
- RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
11393
- })(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
11394
- class JsonRpcError extends Error {
11395
- message;
11396
- code;
11397
- constructor(code, message) {
11398
- super(message);
11399
- this.message = message;
11400
- this.code = code;
11401
- }
11402
- }
11403
-
11404
11526
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
11405
11527
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
11406
- const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, config, user, }) => {
11528
+ const converBigNumberishToNumber = (value) => ethers.BigNumber.from(value).toNumber();
11529
+ const transformGardianTransactions = (txs) => {
11530
+ try {
11531
+ return txs.map((t) => ({
11532
+ delegateCall: t.delegateCall === true,
11533
+ revertOnError: t.revertOnError === true,
11534
+ gasLimit: t.gasLimit ? converBigNumberishToNumber(t.gasLimit).toString() : '0',
11535
+ target: t.to ?? ethers.ethers.constants.AddressZero,
11536
+ value: t.value ? converBigNumberishToNumber(t.value).toString() : '0',
11537
+ data: t.data ? t.data.toString() : '0x00',
11538
+ }));
11539
+ }
11540
+ catch (error) {
11541
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
11542
+ throw new JsonRpcError(exports.RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
11543
+ }
11544
+ };
11545
+ const guardianValidation = async ({ transactionAPI, chainId, nonce, user, metaTransactions, }) => {
11546
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
11547
+ const guardianTransactions = transformGardianTransactions(metaTransactions);
11548
+ try {
11549
+ await transactionAPI.evaluateTransaction({
11550
+ id: 'evm',
11551
+ transactionEvaluationRequest: {
11552
+ chainType: 'evm',
11553
+ chainId,
11554
+ transactionData: {
11555
+ nonce,
11556
+ userAddress: user.zkEvm.ethAddress,
11557
+ metaTransactions: guardianTransactions,
11558
+ },
11559
+ },
11560
+ }, { headers });
11561
+ }
11562
+ catch (error) {
11563
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
11564
+ throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
11565
+ }
11566
+ };
11567
+ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, transactionAPI, config, user, }) => {
11407
11568
  const transactionRequest = params[0];
11408
11569
  if (!transactionRequest.to) {
11409
11570
  throw new JsonRpcError(exports.RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
@@ -11441,6 +11602,13 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
11441
11602
  value: imxFeeOption.tokenPrice,
11442
11603
  revertOnError: true,
11443
11604
  };
11605
+ await guardianValidation({
11606
+ transactionAPI,
11607
+ chainId: config.zkEvmChainId,
11608
+ nonce: converBigNumberishToNumber(nonce),
11609
+ user,
11610
+ metaTransactions: [metaTransaction, feeMetaTransaction],
11611
+ });
11444
11612
  // NOTE: We sign again because we now are adding the fee transaction, so the
11445
11613
  // whole payload is different and needs a new signature.
11446
11614
  const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainId, user.zkEvm.ethAddress, signer);
@@ -11468,146 +11636,30 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
11468
11636
  return relayerTransaction.hash;
11469
11637
  };
11470
11638
 
11471
- class TypedEventEmitter {
11472
- emitter = new events.EventEmitter();
11473
- emit(eventName, ...eventArg) {
11474
- this.emitter.emit(eventName, ...eventArg);
11475
- }
11476
- on(eventName, handler) {
11477
- this.emitter.on(eventName, handler);
11478
- }
11479
- removeListener(eventName, handler) {
11480
- this.emitter.removeListener(eventName, handler);
11481
- }
11482
- }
11483
-
11484
- class RelayerClient {
11485
- config;
11486
- constructor({ config }) {
11487
- this.config = config;
11488
- }
11489
- async postToRelayer(request) {
11490
- const body = {
11491
- id: 1,
11492
- jsonrpc: '2.0',
11493
- ...request,
11494
- };
11495
- const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
11496
- method: 'POST',
11497
- headers: {
11498
- 'Content-Type': 'application/json',
11499
- },
11500
- body: JSON.stringify(body),
11501
- });
11502
- const jsonResponse = await response.json();
11503
- if (jsonResponse.error) {
11504
- throw jsonResponse.error;
11505
- }
11506
- return jsonResponse;
11507
- }
11508
- async ethSendTransaction(to, data) {
11509
- const payload = {
11510
- method: 'eth_sendTransaction',
11511
- params: [{
11512
- to,
11513
- data,
11514
- chainId: this.config.zkEvmChainId.toString(),
11515
- }],
11516
- };
11517
- const { result } = await this.postToRelayer(payload);
11518
- return result;
11519
- }
11520
- async imGetTransactionByHash(hash) {
11521
- const payload = {
11522
- method: 'im_getTransactionByHash',
11523
- params: [hash],
11524
- };
11525
- const { result } = await this.postToRelayer(payload);
11526
- return result;
11527
- }
11528
- async imGetFeeOptions(userAddress, data) {
11529
- const payload = {
11530
- method: 'im_getFeeOptions',
11531
- params: [{
11532
- userAddress,
11533
- data,
11534
- chainId: this.config.zkEvmChainId.toString(),
11535
- }],
11536
- };
11537
- const { result } = await this.postToRelayer(payload);
11538
- return result;
11539
- }
11540
- }
11541
-
11542
- const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
11543
- async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, }) {
11544
- const web3Provider = new providers.Web3Provider(magicProvider);
11545
- const ethSigner = web3Provider.getSigner();
11546
- const ethereumAddress = await ethSigner.getAddress();
11547
- const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
11548
- const headers = { Authorization: `Bearer ${accessToken}` };
11549
- try {
11550
- await multiRollupApiClients.passportApi.createCounterfactualAddress({
11551
- createCounterfactualAddressRequest: {
11552
- ethereumAddress,
11553
- ethereumSignature,
11554
- },
11555
- }, { headers });
11556
- }
11557
- catch (error) {
11558
- throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
11559
- }
11560
- const user = await authManager.loginSilent();
11561
- if (!user?.zkEvm) {
11562
- throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
11563
- }
11564
- return user;
11565
- }
11566
-
11567
- const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, }) => {
11568
- const user = await authManager.getUser() || await authManager.login();
11569
- if (!user.idToken) {
11570
- throw new Error('User is missing idToken');
11571
- }
11572
- const magicProvider = await magicAdapter.login(user.idToken, config.network);
11573
- if (!user.zkEvm) {
11574
- // Generate counterfactual address and retrieve updated Auth0 user
11575
- const userZkevm = await registerZkEvmUser({
11576
- authManager,
11577
- magicProvider,
11578
- multiRollupApiClients,
11579
- accessToken: user.accessToken,
11580
- });
11581
- return {
11582
- user: userZkevm,
11583
- magicProvider,
11584
- };
11585
- }
11586
- return {
11587
- user: user,
11588
- magicProvider,
11589
- };
11590
- };
11591
-
11592
- class ZkEvmProvider extends TypedEventEmitter {
11639
+ class ZkEvmProvider {
11593
11640
  authManager;
11594
11641
  config;
11595
11642
  confirmationScreen;
11596
11643
  magicAdapter;
11597
11644
  relayerClient;
11645
+ transactionAPI;
11598
11646
  multiRollupApiClients;
11599
- jsonRpcProvider; // Used for read operations
11647
+ jsonRpcProvider; // Used for read
11648
+ eventEmitter;
11600
11649
  magicProvider; // Used for signing
11601
11650
  user;
11602
11651
  constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, }) {
11603
- super();
11604
11652
  this.authManager = authManager;
11605
11653
  this.magicAdapter = magicAdapter;
11606
11654
  this.config = config;
11607
11655
  this.confirmationScreen = confirmationScreen;
11608
11656
  this.relayerClient = new RelayerClient({ config });
11657
+ this.transactionAPI = new TransactionsApi(new Configuration({
11658
+ basePath: this.config.imxPublicApiDomain,
11659
+ }));
11609
11660
  this.jsonRpcProvider = new providers.JsonRpcProvider(this.config.zkEvmRpcUrl);
11610
11661
  this.multiRollupApiClients = multiRollupApiClients;
11662
+ this.eventEmitter = new TypedEventEmitter();
11611
11663
  }
11612
11664
  isLoggedIn() {
11613
11665
  return this.magicProvider !== undefined && this.user !== undefined;
@@ -11626,7 +11678,7 @@ class ZkEvmProvider extends TypedEventEmitter {
11626
11678
  });
11627
11679
  this.user = user;
11628
11680
  this.magicProvider = magicProvider;
11629
- this.emit(exports.ProviderEventNames.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
11681
+ this.eventEmitter.emit(exports.ProviderEvent.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
11630
11682
  return [this.user.zkEvm.ethAddress];
11631
11683
  }
11632
11684
  case 'eth_sendTransaction': {
@@ -11636,6 +11688,7 @@ class ZkEvmProvider extends TypedEventEmitter {
11636
11688
  return sendTransaction({
11637
11689
  params: request.params || [],
11638
11690
  magicProvider: this.magicProvider,
11691
+ transactionAPI: this.transactionAPI,
11639
11692
  jsonRpcProvider: this.jsonRpcProvider,
11640
11693
  config: this.config,
11641
11694
  relayerClient: this.relayerClient,
@@ -11755,6 +11808,12 @@ class ZkEvmProvider extends TypedEventEmitter {
11755
11808
  }
11756
11809
  throw new JsonRpcError(exports.RpcErrorCode.INVALID_REQUEST, 'Invalid request');
11757
11810
  }
11811
+ on(event, listener) {
11812
+ this.eventEmitter.on(event, listener);
11813
+ }
11814
+ removeListener(event, listener) {
11815
+ this.eventEmitter.removeListener(event, listener);
11816
+ }
11758
11817
  }
11759
11818
 
11760
11819
  class Passport {
@@ -25067,7 +25126,7 @@ const ETH_MAINNET_CHAIN_ID = 'eip155:1';
25067
25126
  /**
25068
25127
  * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
25069
25128
  */
25070
- const ZKEVM_DEVNET_CHAIN_ID = 'eip155:13403';
25129
+ const ZKEVM_DEVNET_CHAIN_ID = 'eip155:13423';
25071
25130
  /**
25072
25131
  /**
25073
25132
  * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
@@ -25125,8 +25184,8 @@ const SUPPORTED_BRIDGES_FOR_ENVIRONMENT = {
25125
25184
  */
25126
25185
  const CONTRACTS_FOR_BRIDGE = new Map()
25127
25186
  .set(ETH_SEPOLIA_TO_ZKEVM_DEVNET, {
25128
- rootChainERC20Predicate: '0x15Dd735de418B6d290727aed82cC25F8966dE4A5',
25129
- rootChainStateSender: '0xb3Bac13799dAca9D9eC9307303a65fA1218b4724',
25187
+ rootChainERC20Predicate: '0xf0b3435411A74F1aeCBD0fd6D53a90D5227fEeba',
25188
+ rootChainStateSender: '0x868097dbAcfD431F441d09D0e4D3B5eD3182E597',
25130
25189
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
25131
25190
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
25132
25191
  })
@@ -28113,16 +28172,19 @@ async function $5c763be0b0b81038$var$getMetaMaskProvider() {
28113
28172
  if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", (exports.CheckoutErrorType).METAMASK_PROVIDER_ERROR);
28114
28173
  return new (providers.Web3Provider)(provider);
28115
28174
  }
28116
- async function $5c763be0b0b81038$export$500fbc0cd14cdbaa(defaultProvider) {
28117
- let web3Provider = null;
28118
- switch(defaultProvider){
28175
+ async function $5c763be0b0b81038$export$500fbc0cd14cdbaa(walletProviderName) {
28176
+ let provider = null;
28177
+ switch(walletProviderName){
28119
28178
  case (exports.WalletProviderName).METAMASK:
28120
- web3Provider = await $5c763be0b0b81038$var$getMetaMaskProvider();
28179
+ provider = await $5c763be0b0b81038$var$getMetaMaskProvider();
28121
28180
  break;
28122
28181
  default:
28123
28182
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider not supported", (exports.CheckoutErrorType).DEFAULT_PROVIDER_ERROR);
28124
28183
  }
28125
- return web3Provider;
28184
+ return {
28185
+ provider: provider,
28186
+ walletProviderName: walletProviderName
28187
+ };
28126
28188
  }
28127
28189
 
28128
28190
 
@@ -28518,10 +28580,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28518
28580
  * @param {CreateProviderParams} params - The parameters for creating the provider.
28519
28581
  * @returns {Promise<CreateProviderResult>} A promise that resolves to the created provider.
28520
28582
  */ async createProvider(params) {
28521
- const web3Provider = await $5c763be0b0b81038$export$500fbc0cd14cdbaa(params.walletProvider);
28522
- return {
28523
- provider: web3Provider
28524
- };
28583
+ return await $5c763be0b0b81038$export$500fbc0cd14cdbaa(params.walletProvider);
28525
28584
  }
28526
28585
  /**
28527
28586
  * Checks if a wallet is connected to the specified provider.
@@ -28638,7 +28697,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28638
28697
  function $parcel$export(e, n, v, s) {
28639
28698
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
28640
28699
  }
28641
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.3.0-alpha.3";
28700
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.3.1-alpha";
28642
28701
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
28643
28702
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
28644
28703
 
package/dist/index.d.ts CHANGED
@@ -12480,14 +12480,14 @@ declare class ImmutableXClient {
12480
12480
  * @returns a promise that resolves with the requested Order
12481
12481
  * @throws {@link index.IMXError}
12482
12482
  */
12483
- getOrder(request: OrdersApiGetOrderRequest): Promise<Order>;
12483
+ getOrder(request: OrdersApiGetOrderRequest): Promise<OrderV3>;
12484
12484
  /**
12485
12485
  * Get a list of Orders
12486
12486
  * @param request - optional object containing the parameters to be provided in the API request
12487
12487
  * @returns a promise that resolves with the requested list of Orders
12488
12488
  * @throws {@link index.IMXError}
12489
12489
  */
12490
- listOrders(request?: OrdersApiListOrdersRequest): Promise<ListOrdersResponse>;
12490
+ listOrders(request?: OrdersApiListOrdersRequest): Promise<ListOrdersResponseV3>;
12491
12491
  /**
12492
12492
  * Get details of a Trade with the given ID
12493
12493
  * @param request - the request object containing the parameters to be provided in the API request
@@ -12826,7 +12826,7 @@ type Provider = {
12826
12826
  on: (event: string, listener: (...args: any[]) => void) => void;
12827
12827
  removeListener: (event: string, listener: (...args: any[]) => void) => void;
12828
12828
  };
12829
- declare enum ProviderEventNames {
12829
+ declare enum ProviderEvent {
12830
12830
  ACCOUNTS_CHANGED = "accountsChanged"
12831
12831
  }
12832
12832
  type AccountsChangedEvent = Array<string>;
@@ -13347,9 +13347,11 @@ interface CreateProviderParams {
13347
13347
  /**
13348
13348
  * Represents the result of creating a Web3 provider {@link Checkout.createProvider}.
13349
13349
  * @property {Web3Provider} provider - The created Web3 provider.
13350
+ * @property {WalletProviderName} providerName - The name of the wallet provider.
13350
13351
  */
13351
13352
  type CreateProviderResult = {
13352
13353
  provider: Web3Provider;
13354
+ walletProviderName: WalletProviderName;
13353
13355
  };
13354
13356
  /**
13355
13357
  * Interface representing a wallet filter to be used in {@link GetWalletAllowListParams}.
@@ -28594,4 +28596,4 @@ declare class ERC721PermissionedMintable {
28594
28596
  }): Promise<PopulatedTransaction>;
28595
28597
  }
28596
28598
 
28597
- export { APIError, AccountsChangedEvent, ActivityType, AllowedNetworkConfig, BlockchainData, BlockchainDataModuleConfiguration, BridgeEventType, BridgeFailed, BridgeReact, BridgeReactProps, BridgeSuccess, CHECKOUT_API_BASE_URL, ChainId, ChainName, CheckConnectionParams, CheckConnectionResult, Checkout, CheckoutErrorType, CheckoutModuleConfiguration, CheckoutWidgetTagNames, CheckoutWidgets, CheckoutWidgetsConfig, ConnectEventType, ConnectParams, ConnectReact, ConnectResult, ConnectionFailed, ConnectionSuccess, DeviceConnectResponse, DeviceTokenResponse, DexConfig, ERC20, ERC721PermissionedMintable, Environment, ErrorType, GasEstimateBridgeToL2Result, GasEstimateParams, GasEstimateSwapResult, GasEstimateTokenConfig, GasEstimateType, GenericIMXProvider, GetAllBalancesParams, GetAllBalancesResult, GetBalanceParams, GetBalanceResult, GetNetworkAllowListParams, GetNetworkAllowListResult, GetNetworkParams, GetTokenAllowListParams, GetTokenAllowListResult, GetWalletAllowListParams, GetWalletAllowListResult, IMTBLWidgetEvents, IMXProvider, ImmutableConfiguration, ImmutableXClient, ImtblBridgeProps, ImtblConnectProps, ImtblSwapProps, ImtblWalletProps, ImxModuleConfiguration as ImxClientModuleConfiguration, WalletConnection as ImxClientWalletConnection, JsonRpcError, JsonRpcRequestCallback, JsonRpcRequestPayload, JsonRpcResponsePayload, MetaMaskIMXProvider, ModuleConfiguration, NetworkFilter, NetworkFilterTypes, NetworkInfo, Networks, OrchestrationEventType, Orderbook, Passport, PassportError, PassportModuleConfiguration, PassportOverrides, Provider, ProviderConfiguration, ProviderErrorCode, ProviderEventNames, RemoteConfiguration, RequestArguments, RequestBridgeEvent, RequestConnectEvent, RequestOnrampEvent, RequestSwapEvent, RequestWalletEvent, RpcErrorCode, SemanticVersion, SendTransactionParams, SendTransactionResult, SwapEventType, SwapFailed, SwapReact, SwapReactProps, SwapRejected, SwapSuccess, SwitchNetworkParams, SwitchNetworkResult, TokenFilter, TokenFilterTypes, TokenInfo, UpdateConfig, UserProfile, WalletDisconnectWalletEvent, WalletEventType, WalletFilter, WalletFilterTypes, WalletInfo, WalletNetworkSwitchEvent, WalletProviderName, WalletReact, WalletReactProps, WidgetEvent, WidgetTheme, createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey, module };
28599
+ export { APIError, AccountsChangedEvent, ActivityType, AllowedNetworkConfig, BlockchainData, BlockchainDataModuleConfiguration, BridgeEventType, BridgeFailed, BridgeReact, BridgeReactProps, BridgeSuccess, CHECKOUT_API_BASE_URL, ChainId, ChainName, CheckConnectionParams, CheckConnectionResult, Checkout, CheckoutErrorType, CheckoutModuleConfiguration, CheckoutWidgetTagNames, CheckoutWidgets, CheckoutWidgetsConfig, ConnectEventType, ConnectParams, ConnectReact, ConnectResult, ConnectionFailed, ConnectionSuccess, DeviceConnectResponse, DeviceTokenResponse, DexConfig, ERC20, ERC721PermissionedMintable, Environment, ErrorType, GasEstimateBridgeToL2Result, GasEstimateParams, GasEstimateSwapResult, GasEstimateTokenConfig, GasEstimateType, GenericIMXProvider, GetAllBalancesParams, GetAllBalancesResult, GetBalanceParams, GetBalanceResult, GetNetworkAllowListParams, GetNetworkAllowListResult, GetNetworkParams, GetTokenAllowListParams, GetTokenAllowListResult, GetWalletAllowListParams, GetWalletAllowListResult, IMTBLWidgetEvents, IMXProvider, ImmutableConfiguration, ImmutableXClient, ImtblBridgeProps, ImtblConnectProps, ImtblSwapProps, ImtblWalletProps, ImxModuleConfiguration as ImxClientModuleConfiguration, WalletConnection as ImxClientWalletConnection, JsonRpcError, JsonRpcRequestCallback, JsonRpcRequestPayload, JsonRpcResponsePayload, MetaMaskIMXProvider, ModuleConfiguration, NetworkFilter, NetworkFilterTypes, NetworkInfo, Networks, OrchestrationEventType, Orderbook, Passport, PassportError, PassportModuleConfiguration, PassportOverrides, Provider, ProviderConfiguration, ProviderErrorCode, ProviderEvent, RemoteConfiguration, RequestArguments, RequestBridgeEvent, RequestConnectEvent, RequestOnrampEvent, RequestSwapEvent, RequestWalletEvent, RpcErrorCode, SemanticVersion, SendTransactionParams, SendTransactionResult, SwapEventType, SwapFailed, SwapReact, SwapReactProps, SwapRejected, SwapSuccess, SwitchNetworkParams, SwitchNetworkResult, TokenFilter, TokenFilterTypes, TokenInfo, UpdateConfig, UserProfile, WalletDisconnectWalletEvent, WalletEventType, WalletFilter, WalletFilterTypes, WalletInfo, WalletNetworkSwitchEvent, WalletProviderName, WalletReact, WalletReactProps, WidgetEvent, WidgetTheme, createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey, module };