@imtbl/sdk 1.5.0 → 1.5.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.
package/dist/index.js CHANGED
@@ -151,7 +151,7 @@ const flattenProperties$1 = (properties) => {
151
151
  };
152
152
 
153
153
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
154
- const SDK_VERSION$1 = '1.5.0';
154
+ const SDK_VERSION$1 = '1.5.2';
155
155
  let initialised$1 = false;
156
156
  const isInitialised$1 = () => initialised$1;
157
157
  const getReferrer$1 = () => {
@@ -11238,7 +11238,7 @@ class MultiRollupApiClients {
11238
11238
  }
11239
11239
 
11240
11240
  // eslint-disable-next-line @typescript-eslint/naming-convention
11241
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.0' };
11241
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.2' };
11242
11242
  const createConfig = ({ basePath, headers, }) => {
11243
11243
  if (!basePath.trim()) {
11244
11244
  throw Error('basePath can not be empty');
@@ -11310,7 +11310,7 @@ class APIError extends Error {
11310
11310
 
11311
11311
  /* eslint-disable implicit-arrow-linebreak */
11312
11312
  const defaultHeaders = {
11313
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.0',
11313
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.2',
11314
11314
  };
11315
11315
  /**
11316
11316
  * createAPIConfiguration to create a custom Configuration
@@ -11743,7 +11743,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11743
11743
  chainID,
11744
11744
  coreContractAddress,
11745
11745
  registrationContractAddress,
11746
- sdkVersion: 'ts-immutable-sdk-1.5.0',
11746
+ sdkVersion: 'ts-immutable-sdk-1.5.2',
11747
11747
  });
11748
11748
  /**
11749
11749
  * Sets `sdkVersion` at the time of build
@@ -16813,12 +16813,14 @@ class GuardianClient {
16813
16813
  messageAPI;
16814
16814
  confirmationScreen;
16815
16815
  crossSdkBridgeEnabled;
16816
- constructor({ confirmationScreen, config }) {
16816
+ authManager;
16817
+ constructor({ confirmationScreen, config, authManager }) {
16817
16818
  const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
16818
16819
  this.confirmationScreen = confirmationScreen;
16819
16820
  this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
16820
16821
  this.messageAPI = new MessagesApi(guardianConfiguration);
16821
16822
  this.transactionAPI = new TransactionsApi(guardianConfiguration);
16823
+ this.authManager = authManager;
16822
16824
  }
16823
16825
  /**
16824
16826
  * Open confirmation screen and close it automatically if the
@@ -16842,10 +16844,11 @@ class GuardianClient {
16842
16844
  withDefaultConfirmationScreenTask(task) {
16843
16845
  return this.withConfirmationScreenTask()(task);
16844
16846
  }
16845
- async evaluateImxTransaction({ payloadHash, user }) {
16847
+ async evaluateImxTransaction({ payloadHash }) {
16846
16848
  const finallyFn = () => {
16847
16849
  this.confirmationScreen.closeWindow();
16848
16850
  };
16851
+ const user = await this.authManager.getUser();
16849
16852
  const headers = { Authorization: `Bearer ${user.accessToken}` };
16850
16853
  const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
16851
16854
  transactionID: payloadHash,
@@ -16874,7 +16877,8 @@ class GuardianClient {
16874
16877
  this.confirmationScreen.closeWindow();
16875
16878
  }
16876
16879
  }
16877
- async evaluateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
16880
+ async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16881
+ const user = await this.authManager.getUser();
16878
16882
  const headers = { Authorization: `Bearer ${user.accessToken}` };
16879
16883
  const guardianTransactions = transformGuardianTransactions(metaTransactions);
16880
16884
  try {
@@ -16897,11 +16901,10 @@ class GuardianClient {
16897
16901
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
16898
16902
  }
16899
16903
  }
16900
- async validateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
16904
+ async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16901
16905
  const transactionEvaluationResponse = await this.evaluateEVMTransaction({
16902
16906
  chainId,
16903
16907
  nonce,
16904
- user,
16905
16908
  metaTransactions,
16906
16909
  });
16907
16910
  const { confirmationRequired, transactionId } = transactionEvaluationResponse;
@@ -16909,6 +16912,7 @@ class GuardianClient {
16909
16912
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
16910
16913
  }
16911
16914
  if (confirmationRequired && !!transactionId) {
16915
+ const user = await this.authManager.getUser();
16912
16916
  const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
16913
16917
  if (!confirmationResult.confirmed) {
16914
16918
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
@@ -16918,8 +16922,12 @@ class GuardianClient {
16918
16922
  this.confirmationScreen.closeWindow();
16919
16923
  }
16920
16924
  }
16921
- async evaluateMessage({ chainID, payload, user }) {
16925
+ async evaluateMessage({ chainID, payload }) {
16922
16926
  try {
16927
+ const user = await this.authManager.getUser();
16928
+ if (user === null) {
16929
+ throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
16930
+ }
16923
16931
  const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
16924
16932
  return messageEvalResponse.data;
16925
16933
  }
@@ -16928,12 +16936,13 @@ class GuardianClient {
16928
16936
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
16929
16937
  }
16930
16938
  }
16931
- async validateMessage({ chainID, payload, user }) {
16932
- const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload, user });
16939
+ async validateMessage({ chainID, payload }) {
16940
+ const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
16933
16941
  if (confirmationRequired && this.crossSdkBridgeEnabled) {
16934
16942
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
16935
16943
  }
16936
16944
  if (confirmationRequired && !!messageId) {
16945
+ const user = await this.authManager.getUser();
16937
16946
  const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
16938
16947
  if (!confirmationResult.confirmed) {
16939
16948
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
@@ -17015,7 +17024,6 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
17015
17024
  getSignableOrderRequestV3,
17016
17025
  }, { headers });
17017
17026
  await guardianClient.evaluateImxTransaction({
17018
- user,
17019
17027
  payloadHash: getSignableOrderResponse.data.payload_hash,
17020
17028
  });
17021
17029
  const { payload_hash: payloadHash } = getSignableOrderResponse.data;
@@ -17058,7 +17066,6 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
17058
17066
  getSignableCancelOrderRequest,
17059
17067
  }, { headers });
17060
17068
  await guardianClient.evaluateImxTransaction({
17061
- user,
17062
17069
  payloadHash: getSignableCancelOrderResponse.data.payload_hash,
17063
17070
  });
17064
17071
  const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
@@ -17120,7 +17127,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
17120
17127
  getSignableTradeRequest,
17121
17128
  }, { headers });
17122
17129
  await guardianClient.evaluateImxTransaction({
17123
- user,
17124
17130
  payloadHash: getSignableTradeResponse.data.payload_hash,
17125
17131
  });
17126
17132
  const { payload_hash: payloadHash } = getSignableTradeResponse.data;
@@ -17168,7 +17174,6 @@ async function transfer$1({ request, transfersApi, starkSigner, user, guardianCl
17168
17174
  getSignableTransferRequest,
17169
17175
  }, { headers });
17170
17176
  await guardianClient.evaluateImxTransaction({
17171
- user,
17172
17177
  payloadHash: signableResult.data.payload_hash,
17173
17178
  });
17174
17179
  const signableResultData = signableResult.data;
@@ -17219,7 +17224,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
17219
17224
  },
17220
17225
  }, { headers });
17221
17226
  await guardianClient.evaluateImxTransaction({
17222
- user,
17223
17227
  payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
17224
17228
  });
17225
17229
  const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
@@ -17299,6 +17303,7 @@ class PassportImxProvider {
17299
17303
  this.guardianClient = new GuardianClient({
17300
17304
  confirmationScreen,
17301
17305
  config,
17306
+ authManager,
17302
17307
  });
17303
17308
  this.magicAdapter = magicAdapter;
17304
17309
  this.imxApiClients = imxApiClients;
@@ -17930,11 +17935,11 @@ const getEip155ChainId = (chainId) => `eip155:${chainId}`;
17930
17935
  class RelayerClient {
17931
17936
  config;
17932
17937
  jsonRpcProvider;
17933
- user;
17934
- constructor({ config, jsonRpcProvider, user }) {
17938
+ authManager;
17939
+ constructor({ config, jsonRpcProvider, authManager }) {
17935
17940
  this.config = config;
17936
17941
  this.jsonRpcProvider = jsonRpcProvider;
17937
- this.user = user;
17942
+ this.authManager = authManager;
17938
17943
  }
17939
17944
  async postToRelayer(request) {
17940
17945
  const body = {
@@ -17942,10 +17947,11 @@ class RelayerClient {
17942
17947
  jsonrpc: '2.0',
17943
17948
  ...request,
17944
17949
  };
17950
+ const user = await this.authManager.getUser();
17945
17951
  const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
17946
17952
  method: 'POST',
17947
17953
  headers: {
17948
- Authorization: `Bearer ${this.user.accessToken}`,
17954
+ Authorization: `Bearer ${user?.accessToken}`,
17949
17955
  'Content-Type': 'application/json',
17950
17956
  },
17951
17957
  body: JSON.stringify(body),
@@ -18104,7 +18110,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
18104
18110
  }
18105
18111
  return [metaTransaction, feeMetaTransaction];
18106
18112
  };
18107
- const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
18113
+ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
18108
18114
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
18109
18115
  const transactionRequest = params[0];
18110
18116
  if (!transactionRequest.to) {
@@ -18114,7 +18120,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18114
18120
  const chainIdBigNumber = BigNumber$1.from(chainId);
18115
18121
  const magicWeb3Provider = new Web3Provider(magicProvider);
18116
18122
  const signer = magicWeb3Provider.getSigner();
18117
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
18123
+ const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
18118
18124
  const metaTransaction = {
18119
18125
  to: transactionRequest.to,
18120
18126
  data: transactionRequest.data,
@@ -18122,17 +18128,16 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18122
18128
  value: transactionRequest.value,
18123
18129
  revertOnError: true,
18124
18130
  };
18125
- const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer, relayerClient);
18131
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, signer, relayerClient);
18126
18132
  await guardianClient.validateEVMTransaction({
18127
18133
  chainId: getEip155ChainId(chainId),
18128
18134
  nonce: convertBigNumberishToString(nonce),
18129
- user,
18130
18135
  metaTransactions,
18131
18136
  });
18132
18137
  // NOTE: We sign again because we now are adding the fee transaction, so the
18133
18138
  // whole payload is different and needs a new signature.
18134
- const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
18135
- const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
18139
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, signer);
18140
+ const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
18136
18141
  const retrieveRelayerTransaction = async () => {
18137
18142
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
18138
18143
  // NOTE: The transaction hash is only available from the Relayer once the
@@ -18200,7 +18205,7 @@ const transformTypedData = (typedData, chainId) => {
18200
18205
  }
18201
18206
  return transformedTypedData;
18202
18207
  };
18203
- const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
18208
+ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
18204
18209
  .withConfirmationScreen({ width: 480, height: 730 })(async () => {
18205
18210
  const fromAddress = params[0];
18206
18211
  const typedDataParam = params[1];
@@ -18209,7 +18214,7 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
18209
18214
  }
18210
18215
  const { chainId } = await jsonRpcProvider.ready;
18211
18216
  const typedData = transformTypedData(typedDataParam, chainId);
18212
- await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData, user });
18217
+ await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
18213
18218
  const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
18214
18219
  const magicWeb3Provider = new Web3Provider(magicProvider);
18215
18220
  const signer = magicWeb3Provider.getSigner();
@@ -18227,7 +18232,7 @@ class ZkEvmProvider {
18227
18232
  guardianClient;
18228
18233
  relayerClient;
18229
18234
  magicProvider; // Used for signing
18230
- user;
18235
+ zkevmAddress;
18231
18236
  isPassport = true;
18232
18237
  constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
18233
18238
  this.authManager = authManager;
@@ -18252,7 +18257,6 @@ class ZkEvmProvider {
18252
18257
  handleLogout = () => {
18253
18258
  const shouldEmitAccountsChanged = this.isLoggedIn();
18254
18259
  this.magicProvider = undefined;
18255
- this.user = undefined;
18256
18260
  this.relayerClient = undefined;
18257
18261
  this.guardianClient = undefined;
18258
18262
  if (shouldEmitAccountsChanged) {
@@ -18261,7 +18265,7 @@ class ZkEvmProvider {
18261
18265
  };
18262
18266
  isLoggedIn() {
18263
18267
  return this.magicProvider !== undefined
18264
- && this.user !== undefined
18268
+ && this.zkevmAddress !== undefined
18265
18269
  && this.relayerClient !== undefined
18266
18270
  && this.guardianClient !== undefined;
18267
18271
  }
@@ -18269,7 +18273,7 @@ class ZkEvmProvider {
18269
18273
  switch (request.method) {
18270
18274
  case 'eth_requestAccounts': {
18271
18275
  if (this.isLoggedIn()) {
18272
- return [this.user.zkEvm.ethAddress];
18276
+ return [this.zkevmAddress];
18273
18277
  }
18274
18278
  const { magicProvider, user } = await loginZkEvmUser({
18275
18279
  authManager: this.authManager,
@@ -18278,19 +18282,20 @@ class ZkEvmProvider {
18278
18282
  multiRollupApiClients: this.multiRollupApiClients,
18279
18283
  jsonRpcProvider: this.jsonRpcProvider,
18280
18284
  });
18281
- this.user = user;
18282
18285
  this.magicProvider = magicProvider;
18283
18286
  this.relayerClient = new RelayerClient({
18284
18287
  config: this.config,
18285
18288
  jsonRpcProvider: this.jsonRpcProvider,
18286
- user: this.user,
18289
+ authManager: this.authManager,
18287
18290
  });
18288
18291
  this.guardianClient = new GuardianClient({
18289
18292
  confirmationScreen: this.confirmationScreen,
18290
18293
  config: this.config,
18294
+ authManager: this.authManager,
18291
18295
  });
18292
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
18293
- return [this.user.zkEvm.ethAddress];
18296
+ this.zkevmAddress = user.zkEvm.ethAddress;
18297
+ this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
18298
+ return [user.zkEvm.ethAddress];
18294
18299
  }
18295
18300
  case 'eth_sendTransaction': {
18296
18301
  if (!this.isLoggedIn()) {
@@ -18302,11 +18307,11 @@ class ZkEvmProvider {
18302
18307
  guardianClient: this.guardianClient,
18303
18308
  jsonRpcProvider: this.jsonRpcProvider,
18304
18309
  relayerClient: this.relayerClient,
18305
- user: this.user,
18310
+ zkevmAddress: this.zkevmAddress,
18306
18311
  });
18307
18312
  }
18308
18313
  case 'eth_accounts': {
18309
- return this.isLoggedIn() ? [this.user.zkEvm.ethAddress] : [];
18314
+ return this.zkevmAddress ? [this.zkevmAddress] : [];
18310
18315
  }
18311
18316
  case 'eth_signTypedData':
18312
18317
  case 'eth_signTypedData_v4': {
@@ -18319,7 +18324,6 @@ class ZkEvmProvider {
18319
18324
  magicProvider: this.magicProvider,
18320
18325
  jsonRpcProvider: this.jsonRpcProvider,
18321
18326
  relayerClient: this.relayerClient,
18322
- user: this.user,
18323
18327
  guardianClient: this.guardianClient,
18324
18328
  });
18325
18329
  }
@@ -37040,7 +37044,7 @@ const flattenProperties = (properties) => {
37040
37044
  };
37041
37045
 
37042
37046
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37043
- const SDK_VERSION = '1.5.0';
37047
+ const SDK_VERSION = '1.5.2';
37044
37048
  let initialised = false;
37045
37049
  const isInitialised = () => initialised;
37046
37050
  const getReferrer = () => {
@@ -39859,6 +39863,9 @@ const MIN_MAX_HOPS = 1;
39859
39863
  const BASIS_POINT_PRECISION = 10000;
39860
39864
  // 10% maximum secondary fee
39861
39865
  const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;
39866
+ // How much more gas does a swap with secondary fees cost?
39867
+ // This number is the average difference of a number of different swaps with different hop amounts, etc.
39868
+ const AVERAGE_SECONDARY_FEE_EXTRA_GAS = 50876;
39862
39869
 
39863
39870
  const quoteReturnMapping = {
39864
39871
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -40279,6 +40286,59 @@ startTokenIn = tokenIn) => {
40279
40286
  return routes;
40280
40287
  };
40281
40288
 
40289
+ const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
40290
+ const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
40291
+
40292
+ const IMMUTABLE_MAINNET_RPC_URL = 'https://rpc.immutable.com';
40293
+ const IMMUTABLE_MAINNET_CHAIN_ID = 13371;
40294
+
40295
+ const NATIVE_IMX_IMMUTABLE_TESTNET = {
40296
+ chainId: IMMUTABLE_TESTNET_CHAIN_ID,
40297
+ decimals: 18,
40298
+ symbol: 'tIMX',
40299
+ name: 'Immutable Testnet Token',
40300
+ type: 'native',
40301
+ };
40302
+ const WIMX_IMMUTABLE_TESTNET = {
40303
+ chainId: IMMUTABLE_TESTNET_CHAIN_ID,
40304
+ address: '0x1CcCa691501174B4A623CeDA58cC8f1a76dc3439',
40305
+ decimals: 18,
40306
+ symbol: 'WIMX',
40307
+ name: 'Wrapped Immutable Testnet Token',
40308
+ type: 'erc20',
40309
+ };
40310
+ const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
40311
+ WIMX_IMMUTABLE_TESTNET,
40312
+ ];
40313
+
40314
+ const NATIVE_IMX_IMMUTABLE_MAINNET = {
40315
+ chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40316
+ decimals: 18,
40317
+ symbol: 'IMX',
40318
+ name: 'Immutable Token',
40319
+ type: 'native',
40320
+ };
40321
+ const WIMX_IMMUTABLE_MAINNET = {
40322
+ chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40323
+ address: '0x3a0c2ba54d6cbd3121f01b96dfd20e99d1696c9d',
40324
+ decimals: 18,
40325
+ symbol: 'WIMX',
40326
+ name: 'Wrapped Immutable Token',
40327
+ type: 'erc20',
40328
+ };
40329
+ const ETH_IMMUTABLE_MAINNET = {
40330
+ chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40331
+ address: '0x52a6c53869ce09a731cd772f245b97a4401d3348',
40332
+ decimals: 18,
40333
+ symbol: 'ETH',
40334
+ name: 'Ethereum',
40335
+ type: 'erc20',
40336
+ };
40337
+ const IMMUTABLE_MAINNET_COMMON_ROUTING_TOKENS = [
40338
+ WIMX_IMMUTABLE_MAINNET,
40339
+ ETH_IMMUTABLE_MAINNET,
40340
+ ];
40341
+
40282
40342
  const getFeeData = async (provider) => {
40283
40343
  const [block, maxPriorityFeePerGas] = await Promise.all([
40284
40344
  provider.getBlock('latest'),
@@ -40314,9 +40374,13 @@ const fetchGasPrice = async (provider, nativeToken) => {
40314
40374
  * @param {BigNumber} gasEstimate - The total gas units that will be used for the transaction
40315
40375
  * @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
40316
40376
  */
40317
- const calculateGasFee = (gasPrice, gasEstimate) =>
40318
- // eslint-disable-next-line implicit-arrow-linebreak
40319
- newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
40377
+ const calculateGasFee = (hasSecondaryFees, gasPrice, gasEstimate) => {
40378
+ const baseGasFee = newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
40379
+ if (!hasSecondaryFees)
40380
+ return baseGasFee;
40381
+ return newAmount(baseGasFee.value.add(gasPrice.value.mul(AVERAGE_SECONDARY_FEE_EXTRA_GAS)), gasPrice.token);
40382
+ // eslint-disable-next-line implicit-arrow-linebreak
40383
+ };
40320
40384
 
40321
40385
  /**
40322
40386
  * Check if the spender needs approval for the token
@@ -40403,7 +40467,7 @@ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) =
40403
40467
  return null;
40404
40468
  }
40405
40469
  const gasEstimate = await getApproveGasEstimate(provider, ownerAddress, preparedApproval.spender, preparedApproval.amount.token.address);
40406
- const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
40470
+ const gasFeeEstimate = gasPrice ? calculateGasFee(false, gasPrice, gasEstimate) : null;
40407
40471
  return {
40408
40472
  transaction: approveTransaction,
40409
40473
  gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
@@ -40552,59 +40616,6 @@ const IMX_WRAP_GAS_COST = 45038;
40552
40616
  // to avoid an extra remote call.
40553
40617
  const IMX_UNWRAP_GAS_COST = 35216;
40554
40618
 
40555
- const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
40556
- const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
40557
-
40558
- const IMMUTABLE_MAINNET_RPC_URL = 'https://rpc.immutable.com';
40559
- const IMMUTABLE_MAINNET_CHAIN_ID = 13371;
40560
-
40561
- const NATIVE_IMX_IMMUTABLE_TESTNET = {
40562
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
40563
- decimals: 18,
40564
- symbol: 'tIMX',
40565
- name: 'Immutable Testnet Token',
40566
- type: 'native',
40567
- };
40568
- const WIMX_IMMUTABLE_TESTNET = {
40569
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
40570
- address: '0x1CcCa691501174B4A623CeDA58cC8f1a76dc3439',
40571
- decimals: 18,
40572
- symbol: 'WIMX',
40573
- name: 'Wrapped Immutable Testnet Token',
40574
- type: 'erc20',
40575
- };
40576
- const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
40577
- WIMX_IMMUTABLE_TESTNET,
40578
- ];
40579
-
40580
- const NATIVE_IMX_IMMUTABLE_MAINNET = {
40581
- chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40582
- decimals: 18,
40583
- symbol: 'IMX',
40584
- name: 'Immutable Token',
40585
- type: 'native',
40586
- };
40587
- const WIMX_IMMUTABLE_MAINNET = {
40588
- chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40589
- address: '0x3a0c2ba54d6cbd3121f01b96dfd20e99d1696c9d',
40590
- decimals: 18,
40591
- symbol: 'WIMX',
40592
- name: 'Wrapped Immutable Token',
40593
- type: 'erc20',
40594
- };
40595
- const ETH_IMMUTABLE_MAINNET = {
40596
- chainId: IMMUTABLE_MAINNET_CHAIN_ID,
40597
- address: '0x52a6c53869ce09a731cd772f245b97a4401d3348',
40598
- decimals: 18,
40599
- symbol: 'ETH',
40600
- name: 'Ethereum',
40601
- type: 'erc20',
40602
- };
40603
- const IMMUTABLE_MAINNET_COMMON_ROUTING_TOKENS = [
40604
- WIMX_IMMUTABLE_MAINNET,
40605
- ETH_IMMUTABLE_MAINNET,
40606
- ];
40607
-
40608
40619
  const zeroNativeCurrencyValue = '0x00';
40609
40620
  const multicallWithDeadlineFunctionSignature = 'multicall(uint256,bytes[])';
40610
40621
  function buildSinglePoolSwap(tokenIn, tokenOut, recipient, trade, route, amountIn, amountOut, routerContract, paymentsContract) {
@@ -40845,8 +40856,8 @@ const getSwapRecipient = (tokenOut, fromAddress, routerContractAddress, secondar
40845
40856
  function getSwap(tokenIn, tokenOut, adjustedQuote, fromAddress, slippage, deadline, routerContractAddress, secondaryFeesContractAddress, gasPrice, secondaryFees) {
40846
40857
  const swapRecipient = getSwapRecipient(tokenOut, fromAddress, routerContractAddress, secondaryFeesContractAddress, secondaryFees);
40847
40858
  const { calldata, maximumAmountIn } = createSwapParameters(tokenIn, tokenOut, adjustedQuote, swapRecipient, slippage, deadline, secondaryFees);
40848
- // TODO: Add additional gas fee estimates for secondary fees
40849
- const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
40859
+ const hasSecondaryFees = secondaryFees.length > 0;
40860
+ const gasFeeEstimate = gasPrice ? calculateGasFee(hasSecondaryFees, gasPrice, adjustedQuote.gasEstimate) : null;
40850
40861
  const transactionValue = getTransactionValue(tokenIn, maximumAmountIn);
40851
40862
  return {
40852
40863
  transaction: {
@@ -41068,7 +41079,7 @@ class Exchange {
41068
41079
  async getUnwrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
41069
41080
  const calldata = wimxInterface.encodeFunctionData('withdraw', [tokenAmount]);
41070
41081
  const gasEstimate = ethers.BigNumber.from(IMX_UNWRAP_GAS_COST);
41071
- const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
41082
+ const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(false, gasPrice, gasEstimate)) : null;
41072
41083
  // This transaction is for calling calling `withdraw` on the WETH/WIMX contract.
41073
41084
  const transactionDetails = {
41074
41085
  transaction: {
@@ -41086,7 +41097,7 @@ class Exchange {
41086
41097
  getWrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
41087
41098
  const calldata = wimxInterface.encodeFunctionData('deposit');
41088
41099
  const gasEstimate = ethers.BigNumber.from(IMX_WRAP_GAS_COST);
41089
- const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
41100
+ const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(false, gasPrice, gasEstimate)) : null;
41090
41101
  // This transaction is for calling calling `deposit` on the WETH/WIMX contract.
41091
41102
  const transactionDetails = {
41092
41103
  transaction: {
@@ -42148,7 +42159,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42148
42159
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
42149
42160
  };
42150
42161
 
42151
- const SDK_VERSION_MARKER = '1.5.0';
42162
+ const SDK_VERSION_MARKER = '1.5.2';
42152
42163
  // This SDK version is replaced by the `yarn build` command ran on the root level
42153
42164
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42154
42165
 
@@ -45410,9 +45421,7 @@ const buy = async (config, provider, orders, overrides = {
45410
45421
  };
45411
45422
  };
45412
45423
 
45413
- const cancel = async (config, provider, orderIds, overrides = {
45414
- waitFulfillmentSettlements: true,
45415
- }) => {
45424
+ const cancelOnChain = async (config, orderbook, provider, orderIds, waitFulfillmentSettlements) => {
45416
45425
  let unsignedCancelOrderTransaction;
45417
45426
  if (orderIds.length === 0) {
45418
45427
  throw new CheckoutError('No orderIds were provided to the orderIds array. Please provide at least one orderId.', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR);
@@ -45421,7 +45430,6 @@ const cancel = async (config, provider, orderIds, overrides = {
45421
45430
  const orderId = orderIds[0];
45422
45431
  try {
45423
45432
  const offererAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
45424
- const orderbook = createOrderbookInstance(config);
45425
45433
  const cancelOrderResponse = await measureAsyncExecution(config, 'Time to get the cancel order from the orderbook', orderbook.cancelOrdersOnChain([orderId], offererAddress));
45426
45434
  unsignedCancelOrderTransaction = await cancelOrderResponse.cancellationAction.buildTransaction();
45427
45435
  }
@@ -45431,7 +45439,7 @@ const cancel = async (config, provider, orderIds, overrides = {
45431
45439
  error: err,
45432
45440
  });
45433
45441
  }
45434
- if (overrides.waitFulfillmentSettlements) {
45442
+ if (waitFulfillmentSettlements) {
45435
45443
  const result = await signFulfillmentTransactions(provider, [unsignedCancelOrderTransaction]);
45436
45444
  if (result.type === SignTransactionStatusType.FAILED) {
45437
45445
  return {
@@ -45459,6 +45467,56 @@ const cancel = async (config, provider, orderIds, overrides = {
45459
45467
  transactions,
45460
45468
  };
45461
45469
  };
45470
+ const gaslessCancel = async (orderbook, provider, orderIds) => {
45471
+ try {
45472
+ const signer = provider.getSigner();
45473
+ const address = await signer.getAddress();
45474
+ const { signableAction } = await orderbook.prepareOrderCancellations(orderIds);
45475
+ // eslint-disable-next-line no-underscore-dangle
45476
+ const signedMessage = await signer._signTypedData(signableAction.message.domain, signableAction.message.types, signableAction.message.value);
45477
+ const { result } = await orderbook.cancelOrders(orderIds, address, signedMessage);
45478
+ const successfulCancellations = [];
45479
+ const failedCancellations = [];
45480
+ const pendingCancellations = [];
45481
+ for (const success of result.successful_cancellations) {
45482
+ successfulCancellations.push({
45483
+ orderId: success,
45484
+ });
45485
+ }
45486
+ for (const failed of result.failed_cancellations) {
45487
+ failedCancellations.push({
45488
+ orderId: failed.order,
45489
+ reason: failed.reason_code,
45490
+ });
45491
+ }
45492
+ for (const pending of result.pending_cancellations) {
45493
+ pendingCancellations.push({
45494
+ orderId: pending,
45495
+ });
45496
+ }
45497
+ return {
45498
+ successfulCancellations,
45499
+ failedCancellations,
45500
+ pendingCancellations,
45501
+ };
45502
+ }
45503
+ catch (err) {
45504
+ throw new CheckoutError('An error occurred while cancelling the order listing', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, {
45505
+ orderIds,
45506
+ error: err,
45507
+ });
45508
+ }
45509
+ };
45510
+ const cancel = async (config, provider, orderIds, overrides = {
45511
+ waitFulfillmentSettlements: true,
45512
+ useGaslessCancel: false,
45513
+ }) => {
45514
+ const orderbook = createOrderbookInstance(config);
45515
+ if (overrides.useGaslessCancel) {
45516
+ return await gaslessCancel(orderbook, provider, orderIds);
45517
+ }
45518
+ return await cancelOnChain(config, orderbook, provider, orderIds, overrides.waitFulfillmentSettlements ?? true);
45519
+ };
45462
45520
 
45463
45521
  const getERC721Requirement = (id, contractAddress, spenderAddress) => ({
45464
45522
  type: ItemType.ERC721,
package/dist/orderbook.js CHANGED
@@ -126,7 +126,7 @@ const flattenProperties = (properties) => {
126
126
  };
127
127
 
128
128
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
129
- const SDK_VERSION = '1.5.0';
129
+ const SDK_VERSION = '1.5.2';
130
130
  let initialised = false;
131
131
  const isInitialised = () => initialised;
132
132
  const getReferrer = () => {