@imtbl/sdk 0.28.4 → 0.28.5

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
@@ -1,4 +1,4 @@
1
- import globalAxios$1, { isAxiosError as isAxiosError$1, HttpStatusCode as HttpStatusCode$2 } from 'axios';
1
+ import globalAxios$1, { isAxiosError as isAxiosError$1, AxiosError as AxiosError$1, HttpStatusCode as HttpStatusCode$2 } from 'axios';
2
2
  import { ImmutableX, Config, IMXError, createStarkSigner, generateLegacyStarkPrivateKey, TransfersApi, OrdersApi as OrdersApi$1, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi as TokensApi$1 } from '@imtbl/core-sdk';
3
3
  import { UserManager, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
4
4
  import jwt_decode from 'jwt-decode';
@@ -3629,7 +3629,7 @@ class MultiRollupApiClients {
3629
3629
  }
3630
3630
 
3631
3631
  // eslint-disable-next-line @typescript-eslint/naming-convention
3632
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.4' };
3632
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.5' };
3633
3633
  const createConfig = ({ basePath, headers, }) => {
3634
3634
  if (!basePath.trim()) {
3635
3635
  throw Error('basePath can not be empty');
@@ -3689,7 +3689,7 @@ class APIError extends Error {
3689
3689
 
3690
3690
  /* eslint-disable implicit-arrow-linebreak */
3691
3691
  const defaultHeaders = {
3692
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.4',
3692
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.5',
3693
3693
  };
3694
3694
  /**
3695
3695
  * createAPIConfiguration to create a custom Configuration
@@ -4100,7 +4100,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4100
4100
  chainID,
4101
4101
  coreContractAddress,
4102
4102
  registrationContractAddress,
4103
- sdkVersion: 'ts-immutable-sdk-0.28.4',
4103
+ sdkVersion: 'ts-immutable-sdk-0.28.5',
4104
4104
  });
4105
4105
  /**
4106
4106
  * Sets `sdkVersion` at the time of build
@@ -9045,39 +9045,63 @@ class AuthManager {
9045
9045
  }
9046
9046
  }
9047
9047
 
9048
+ const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
9049
+ const lazyDocumentReady = (initialiseFunction) => {
9050
+ const documentReadyPromise = () => new Promise((resolve) => {
9051
+ if (window.document.readyState === 'complete') {
9052
+ resolve();
9053
+ }
9054
+ else {
9055
+ const onReadyStateChange = () => {
9056
+ if (window.document.readyState === 'complete') {
9057
+ resolve();
9058
+ window.document.removeEventListener('readystatechange', onReadyStateChange);
9059
+ }
9060
+ };
9061
+ window.document.addEventListener('readystatechange', onReadyStateChange);
9062
+ }
9063
+ });
9064
+ return lazyLoad(documentReadyPromise, initialiseFunction);
9065
+ };
9066
+
9048
9067
  class MagicAdapter {
9049
9068
  config;
9050
- magicClient;
9069
+ lazyMagicClient;
9051
9070
  constructor(config) {
9052
9071
  this.config = config;
9053
9072
  if (typeof window !== 'undefined') {
9054
- this.magicClient = this.initMagicClient();
9055
- this.magicClient.preload();
9073
+ this.lazyMagicClient = lazyDocumentReady(() => {
9074
+ const client = new Magic(this.config.magicPublishableApiKey, {
9075
+ extensions: [new OpenIdExtension()],
9076
+ network: this.config.network,
9077
+ });
9078
+ client.preload();
9079
+ return client;
9080
+ });
9081
+ }
9082
+ }
9083
+ get magicClient() {
9084
+ if (!this.lazyMagicClient) {
9085
+ throw new Error('Cannot perform this action outside of the browser');
9056
9086
  }
9087
+ return this.lazyMagicClient;
9057
9088
  }
9058
9089
  async login(idToken) {
9059
9090
  return withPassportError(async () => {
9060
- if (!this.magicClient) {
9061
- this.magicClient = this.initMagicClient();
9062
- }
9063
- await this.magicClient.openid.loginWithOIDC({
9091
+ const magicClient = await this.magicClient;
9092
+ await magicClient.openid.loginWithOIDC({
9064
9093
  jwt: idToken,
9065
9094
  providerId: this.config.magicProviderId,
9066
9095
  });
9067
- return this.magicClient.rpcProvider;
9096
+ return magicClient.rpcProvider;
9068
9097
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
9069
9098
  }
9070
9099
  async logout() {
9071
- if (this.magicClient?.user) {
9072
- await this.magicClient.user.logout();
9100
+ const magicClient = await this.magicClient;
9101
+ if (magicClient.user) {
9102
+ await magicClient.user.logout();
9073
9103
  }
9074
9104
  }
9075
- initMagicClient() {
9076
- return new Magic(this.config.magicPublishableApiKey, {
9077
- extensions: [new OpenIdExtension()],
9078
- network: this.config.network,
9079
- });
9080
- }
9081
9105
  }
9082
9106
 
9083
9107
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -9304,7 +9328,7 @@ var PassportEvents;
9304
9328
  var Networks;
9305
9329
  (function (Networks) {
9306
9330
  Networks["PRODUCTION"] = "mainnet";
9307
- Networks["SANDBOX"] = "goerli";
9331
+ Networks["SANDBOX"] = "sepolia";
9308
9332
  })(Networks || (Networks = {}));
9309
9333
 
9310
9334
  async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
@@ -9653,6 +9677,11 @@ class PassportImxProvider {
9653
9677
  }
9654
9678
  // TODO: Remove once implemented
9655
9679
  // eslint-disable-next-line class-methods-use-this
9680
+ isRegisteredOffchain() {
9681
+ throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
9682
+ }
9683
+ // TODO: Remove once implemented
9684
+ // eslint-disable-next-line class-methods-use-this
9656
9685
  isRegisteredOnchain() {
9657
9686
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
9658
9687
  }
@@ -12649,6 +12678,22 @@ async function registerOffchain(signers, config) {
12649
12678
  });
12650
12679
  return registeredUser.data;
12651
12680
  }
12681
+ async function isRegisteredOffchain(ethAddress, config) {
12682
+ try {
12683
+ const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
12684
+ const getUsersResult = await usersApi.getUsers({
12685
+ user: ethAddress,
12686
+ });
12687
+ const { accounts } = getUsersResult.data;
12688
+ return accounts?.length > 0;
12689
+ }
12690
+ catch (ex) {
12691
+ if (ex instanceof AxiosError$1 && ex.response?.status === 404) {
12692
+ return false;
12693
+ }
12694
+ throw ex;
12695
+ }
12696
+ }
12652
12697
  async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
12653
12698
  await validateChain(ethSigner, config.immutableXConfig);
12654
12699
  const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
@@ -13184,7 +13229,11 @@ class GenericIMXProvider {
13184
13229
  this.signers = { ethSigner, starkSigner };
13185
13230
  }
13186
13231
  async getAddress() {
13187
- return await this.signers.ethSigner.getAddress();
13232
+ return this.signers.ethSigner.getAddress();
13233
+ }
13234
+ async isRegisteredOffchain() {
13235
+ const ethAddress = await this.getAddress();
13236
+ return isRegisteredOffchain(ethAddress, this.config);
13188
13237
  }
13189
13238
  registerOffchain() {
13190
13239
  return registerOffchain(this.signers, this.config);
@@ -30377,6 +30426,7 @@ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAdd
30377
30426
  }
30378
30427
  // Blockscout client singleton per chain id
30379
30428
  const $1564e43dde50bb61$var$blockscoutClientMap = new Map();
30429
+ const $1564e43dde50bb61$export$be5483d07cfa803d = ()=>$1564e43dde50bb61$var$blockscoutClientMap.clear();
30380
30430
  const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId, filterTokens)=>{
30381
30431
  // Shuffle the mapping of the tokens configuration so it is a hashmap
30382
30432
  // for faster access to tokens config objects.
@@ -30478,6 +30528,8 @@ const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, w
30478
30528
  };
30479
30529
  };
30480
30530
  const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, walletAddress, chainId)=>{
30531
+ // eslint-disable-next-line no-param-reassign
30532
+ chainId ||= await web3Provider.getSigner().getChainId();
30481
30533
  const { tokens: tokens } = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
30482
30534
  type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
30483
30535
  chainId: chainId
@@ -30499,7 +30551,7 @@ const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, w
30499
30551
  // Please remove this hack once https://immutable.atlassian.net/browse/WT-1710
30500
30552
  // is done.
30501
30553
  const isL1Chain = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config) === chainId;
30502
- return ($458d407830d66110$export$5280dbcb91c8b391)(config, `Time to fetch balances using blockscout for ${chainId}`, $1564e43dde50bb61$export$8c978679845804d4(walletAddress, chainId, isL1Chain ? tokens : []));
30554
+ return await ($458d407830d66110$export$5280dbcb91c8b391)(config, `Time to fetch balances using blockscout for ${chainId}`, $1564e43dde50bb61$export$8c978679845804d4(walletAddress, chainId, isL1Chain ? tokens : []));
30503
30555
  }
30504
30556
  // This fallback to use ERC20s calls which is a best effort solution
30505
30557
  // Fails in fetching data from the RCP calls might result in some
@@ -30870,6 +30922,7 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
30870
30922
 
30871
30923
 
30872
30924
 
30925
+
30873
30926
  const $ddc6bcd0896481e5$export$2fbfa41a4de56a89 = (erc20allowances, erc721allowances)=>{
30874
30927
  const aggregatedAllowances = [];
30875
30928
  if (!erc20allowances.sufficient) {
@@ -31176,7 +31229,7 @@ const $35c3fc7013888ba5$export$be546c525d418988 = async (provider, ownerAddress,
31176
31229
 
31177
31230
 
31178
31231
 
31179
- /* eslint-disable arrow-body-style */
31232
+
31180
31233
 
31181
31234
 
31182
31235
 
@@ -31369,17 +31422,14 @@ const $73d2282a108cc7e2$export$6ab9757fda54db7e = (itemRequirement, balances)=>{
31369
31422
  /**
31370
31423
  * Gets the balances for all NATIVE and ERC20 balance requirements.
31371
31424
  */ const $beb896e098e41faf$var$getTokenBalances = async (config, provider, ownerAddress, itemRequirements)=>{
31372
- let tokenBalances = [];
31373
31425
  try {
31374
- const tokenList = (0, $73d2282a108cc7e2$export$ed7929b58bab85da)(itemRequirements);
31375
- const { balances: balances } = await (0, $1564e43dde50bb61$export$a3238cee431627c6)(config, provider, ownerAddress, tokenList);
31376
- tokenBalances = [
31377
- ...balances.map((balance)=>balance)
31378
- ];
31426
+ const tokenMap = new Map();
31427
+ (0, $73d2282a108cc7e2$export$ed7929b58bab85da)(itemRequirements).forEach((item)=>tokenMap.set((item.address || "").toLocaleLowerCase(), item));
31428
+ const { balances: balances } = await (0, $1564e43dde50bb61$export$fee49741664a4d7e)(config, provider, ownerAddress);
31429
+ return balances.filter((balance)=>tokenMap.get((balance.token.address || "").toLocaleLowerCase()));
31379
31430
  } catch (error) {
31380
31431
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR);
31381
31432
  }
31382
- return tokenBalances;
31383
31433
  };
31384
31434
  /**
31385
31435
  * Gets the balances for all ERC721 balance requirements.
@@ -31417,42 +31467,46 @@ const $73d2282a108cc7e2$export$6ab9757fda54db7e = (itemRequirement, balances)=>{
31417
31467
  };
31418
31468
  const $beb896e098e41faf$export$ddfc885f43c3cb6e = async (config, provider, ownerAddress, itemRequirements)=>{
31419
31469
  const aggregatedItems = ($aa6caea9a60d18c7$export$f96d1c819a615a64)(itemRequirements);
31420
- if (aggregatedItems.filter((itemRequirement)=>{
31421
- return itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
31422
- }).length > 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unsupported item requirement balance check", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
31470
+ const requiredToken = [];
31471
+ const requiredERC721 = [];
31472
+ aggregatedItems.forEach((item)=>{
31473
+ switch(item.type){
31474
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
31475
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
31476
+ requiredToken.push(item);
31477
+ break;
31478
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721:
31479
+ requiredERC721.push(item);
31480
+ break;
31481
+ }
31482
+ });
31483
+ if (requiredERC721.length === 0 && requiredToken.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unsupported item requirement balance check", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
31423
31484
  // Get all ERC20 and NATIVE balances
31424
- const currentBalances = [];
31425
- const tokenItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 || itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
31426
- if (tokenItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getTokenBalances(config, provider, ownerAddress, aggregatedItems));
31485
+ const balancePromises = [];
31486
+ if (requiredToken.length > 0) balancePromises.push($beb896e098e41faf$var$getTokenBalances(config, provider, ownerAddress, aggregatedItems));
31427
31487
  // Get all ERC721 balances
31428
- const erc721ItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721);
31429
- if (erc721ItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getERC721Balances(provider, ownerAddress, aggregatedItems));
31488
+ if (requiredERC721.length > 0) balancePromises.push($beb896e098e41faf$var$getERC721Balances(provider, ownerAddress, aggregatedItems));
31430
31489
  // Wait for all balances and calculate the requirements
31431
- const balanceRequirements = await Promise.all(currentBalances).then((balances)=>{
31432
- const requirements = [];
31433
- if (balances.length > 1 || tokenItemRequirements.length > 0) {
31434
- const tokenBalances = balances[0];
31435
- tokenItemRequirements.forEach((tokenItemRequirement)=>{
31436
- requirements.push(($73d2282a108cc7e2$export$6ab9757fda54db7e)(tokenItemRequirement, tokenBalances));
31437
- });
31438
- if (erc721ItemRequirements.length > 0) {
31439
- const erc721Balances = balances[1];
31440
- erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
31441
- requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
31442
- });
31443
- }
31444
- } else if (erc721ItemRequirements.length > 0) {
31445
- // Only erc721
31446
- const erc721Balances = balances[0];
31447
- erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
31448
- requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
31449
- });
31450
- }
31451
- return requirements;
31452
- });
31453
- const sufficient = balanceRequirements.reduce((acc, balanceRequirement)=>{
31454
- return acc && balanceRequirement.sufficient;
31455
- }, true);
31490
+ const promisesResponses = await Promise.all(balancePromises);
31491
+ const balanceRequirements = [];
31492
+ // Get all ERC20 and NATIVE balances
31493
+ if (requiredToken.length > 0 && promisesResponses.length > 0) {
31494
+ const result = promisesResponses.shift();
31495
+ if (result) requiredToken.forEach((item)=>{
31496
+ balanceRequirements.push(($73d2282a108cc7e2$export$6ab9757fda54db7e)(item, result));
31497
+ });
31498
+ }
31499
+ // Get all ERC721 balances
31500
+ if (requiredERC721.length > 0 && promisesResponses.length > 0) {
31501
+ const result = promisesResponses.shift();
31502
+ if (result) requiredERC721.forEach((item)=>{
31503
+ balanceRequirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(item, result));
31504
+ });
31505
+ }
31506
+ // Find if there are any requirements that aren't sufficient.
31507
+ // If there is not item with sufficient === false then the requirements
31508
+ // are satisfied.
31509
+ const sufficient = balanceRequirements.find((req)=>req.sufficient === false) === undefined;
31456
31510
  return {
31457
31511
  sufficient: sufficient,
31458
31512
  balanceRequirements: balanceRequirements
@@ -32036,7 +32090,9 @@ const $15fe1c77041bd4f4$export$9e73e22953cebcfc = async (config, readOnlyProvide
32036
32090
 
32037
32091
  const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
32038
32092
  const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
32093
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_MAINNET) return "imtbl-zkevm-mainnet";
32039
32094
  if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
32095
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_DEVNET) return "imtbl-zkevm-devent";
32040
32096
  return "";
32041
32097
  };
32042
32098
  const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
@@ -32857,7 +32913,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
32857
32913
 
32858
32914
 
32859
32915
 
32860
-
32861
32916
  const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
32862
32917
  const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
32863
32918
  const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
@@ -32898,6 +32953,7 @@ const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimal
32898
32953
 
32899
32954
 
32900
32955
 
32956
+
32901
32957
  const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
32902
32958
  switch(type){
32903
32959
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
@@ -32929,16 +32985,24 @@ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, fulfillmentTransact
32929
32985
  };
32930
32986
  };
32931
32987
  const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orders)=>{
32932
- let orderbook;
32988
+ if (orders.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orders were provided to the orders array. Please provide at least one order.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).FULFILL_ORDER_LISTING_ERROR);
32933
32989
  let order;
32934
32990
  let spenderAddress = "";
32991
+ let decimals = 18;
32935
32992
  const gasLimit = (constants).estimatedFulfillmentGasGwei;
32936
- if (orders.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orders were provided to the orders array. Please provide at least one order.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).FULFILL_ORDER_LISTING_ERROR);
32993
+ const orderbook = $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
32994
+ const blockchainClient = $67fc622a2b913d5f$export$436dd76f23f463ff(config);
32995
+ const fulfillerAddress = await ($458d407830d66110$export$5280dbcb91c8b391)(config, "Time to get the address from the provider", provider.getSigner().getAddress());
32996
+ // Prefetch balances and store them in memory
32997
+ ($1564e43dde50bb61$export$be5483d07cfa803d)();
32998
+ ($1564e43dde50bb61$export$fee49741664a4d7e)(config, provider, fulfillerAddress, ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
32999
+ ($1564e43dde50bb61$export$fee49741664a4d7e)(config, provider, fulfillerAddress, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
32937
33000
  const { id: id, takerFees: takerFees } = orders[0];
33001
+ let orderChainName;
32938
33002
  try {
32939
- orderbook = $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
32940
33003
  order = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to fetch the listing from the orderbook", orderbook.getListing(id));
32941
- const { seaportContractAddress: seaportContractAddress } = orderbook.config();
33004
+ const { seaportContractAddress: seaportContractAddress, chainName: chainName } = orderbook.config();
33005
+ orderChainName = chainName;
32942
33006
  spenderAddress = seaportContractAddress;
32943
33007
  } catch (err) {
32944
33008
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while getting the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
@@ -32951,10 +33015,12 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
32951
33015
  message: "No buy side tokens found on order"
32952
33016
  });
32953
33017
  const buyToken = order.result.buy[0];
32954
- let decimals = 18;
32955
- if (order.result.buy[0].type === "ERC20") {
32956
- const tokenContract = $06a6c5c23f7f2479$export$fbbc17f6e6e58544(order.result.buy[0].contractAddress, ($d85ad1457a3f1a83$export$db5daa1b5156ccfe), provider);
32957
- decimals = await ($458d407830d66110$export$5280dbcb91c8b391)(config, "Time to get decimals of token contract for the buy token", tokenContract.decimals());
33018
+ if (buyToken.type === "ERC20") {
33019
+ const token = await ($458d407830d66110$export$5280dbcb91c8b391)(config, "Time to get decimals of token contract for the buy token", blockchainClient.getToken({
33020
+ contractAddress: buyToken.contractAddress,
33021
+ chainName: orderChainName
33022
+ }));
33023
+ if (token.result.decimals) decimals = token.result.decimals;
32958
33024
  }
32959
33025
  let fees = [];
32960
33026
  if (takerFees && takerFees.length > 0) fees = ($9051cee080948594$export$1e69c9cfc42e28d8)(takerFees, buyToken.amount, decimals);
@@ -32963,7 +33029,6 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
32963
33029
  let orderActions = [];
32964
33030
  const fulfillOrderStartTime = performance.now();
32965
33031
  try {
32966
- const fulfillerAddress = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to get the address from the provider", provider.getSigner().getAddress());
32967
33032
  const { actions: actions } = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to call fulfillOrder from the orderbook", orderbook.fulfillOrder(id, fulfillerAddress, fees));
32968
33033
  orderActions = actions;
32969
33034
  unsignedApprovalTransactions = await (0, $458d407830d66110$export$5280dbcb91c8b391)(config, "Time to construct the unsigned approval transactions", (0, $a7367d01c6e76b1c$export$f64a20a30eb98855)(actions));
@@ -33563,7 +33628,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
33563
33628
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
33564
33629
 
33565
33630
 
33566
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.4";
33631
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.5";
33567
33632
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
33568
33633
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
33569
33634
 
@@ -33748,6 +33813,7 @@ $parcel$export($9b3189b6b155842e$exports, "SaleEventType", () => $9b3189b6b15584
33748
33813
  SaleEventType["SUCCESS"] = "success";
33749
33814
  SaleEventType["FAILURE"] = "failure";
33750
33815
  SaleEventType["REJECTED"] = "rejected";
33816
+ SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
33751
33817
  })($9b3189b6b155842e$export$881881ffb3bd733e || ($9b3189b6b155842e$export$881881ffb3bd733e = {}));
33752
33818
 
33753
33819
 
@@ -9732,6 +9732,12 @@ interface IMXProvider {
9732
9732
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
9733
9733
  */
9734
9734
  registerOffchain(): Promise<RegisterUserResponse>;
9735
+ /**
9736
+ * Checks if a User is registered off-chain
9737
+ *
9738
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
9739
+ */
9740
+ isRegisteredOffchain(): Promise<boolean>;
9735
9741
  /**
9736
9742
  * Checks if a User is registered on-chain
9737
9743
  *
@@ -10184,7 +10190,7 @@ type UserProfile = {
10184
10190
  };
10185
10191
  declare enum Networks {
10186
10192
  PRODUCTION = "mainnet",
10187
- SANDBOX = "goerli"
10193
+ SANDBOX = "sepolia"
10188
10194
  }
10189
10195
  interface OidcConfiguration {
10190
10196
  clientId: string;
package/dist/passport.js CHANGED
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
2072
2072
  }
2073
2073
 
2074
2074
  // eslint-disable-next-line @typescript-eslint/naming-convention
2075
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.4' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.5' };
2076
2076
  const createConfig = ({ basePath, headers, }) => {
2077
2077
  if (!basePath.trim()) {
2078
2078
  throw Error('basePath can not be empty');
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2128
2128
  chainID,
2129
2129
  coreContractAddress,
2130
2130
  registrationContractAddress,
2131
- sdkVersion: 'ts-immutable-sdk-0.28.4',
2131
+ sdkVersion: 'ts-immutable-sdk-0.28.5',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -7056,39 +7056,63 @@ class AuthManager {
7056
7056
  }
7057
7057
  }
7058
7058
 
7059
+ const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
7060
+ const lazyDocumentReady = (initialiseFunction) => {
7061
+ const documentReadyPromise = () => new Promise((resolve) => {
7062
+ if (window.document.readyState === 'complete') {
7063
+ resolve();
7064
+ }
7065
+ else {
7066
+ const onReadyStateChange = () => {
7067
+ if (window.document.readyState === 'complete') {
7068
+ resolve();
7069
+ window.document.removeEventListener('readystatechange', onReadyStateChange);
7070
+ }
7071
+ };
7072
+ window.document.addEventListener('readystatechange', onReadyStateChange);
7073
+ }
7074
+ });
7075
+ return lazyLoad(documentReadyPromise, initialiseFunction);
7076
+ };
7077
+
7059
7078
  class MagicAdapter {
7060
7079
  config;
7061
- magicClient;
7080
+ lazyMagicClient;
7062
7081
  constructor(config) {
7063
7082
  this.config = config;
7064
7083
  if (typeof window !== 'undefined') {
7065
- this.magicClient = this.initMagicClient();
7066
- this.magicClient.preload();
7084
+ this.lazyMagicClient = lazyDocumentReady(() => {
7085
+ const client = new Magic(this.config.magicPublishableApiKey, {
7086
+ extensions: [new OpenIdExtension()],
7087
+ network: this.config.network,
7088
+ });
7089
+ client.preload();
7090
+ return client;
7091
+ });
7067
7092
  }
7068
7093
  }
7094
+ get magicClient() {
7095
+ if (!this.lazyMagicClient) {
7096
+ throw new Error('Cannot perform this action outside of the browser');
7097
+ }
7098
+ return this.lazyMagicClient;
7099
+ }
7069
7100
  async login(idToken) {
7070
7101
  return withPassportError(async () => {
7071
- if (!this.magicClient) {
7072
- this.magicClient = this.initMagicClient();
7073
- }
7074
- await this.magicClient.openid.loginWithOIDC({
7102
+ const magicClient = await this.magicClient;
7103
+ await magicClient.openid.loginWithOIDC({
7075
7104
  jwt: idToken,
7076
7105
  providerId: this.config.magicProviderId,
7077
7106
  });
7078
- return this.magicClient.rpcProvider;
7107
+ return magicClient.rpcProvider;
7079
7108
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
7080
7109
  }
7081
7110
  async logout() {
7082
- if (this.magicClient?.user) {
7083
- await this.magicClient.user.logout();
7111
+ const magicClient = await this.magicClient;
7112
+ if (magicClient.user) {
7113
+ await magicClient.user.logout();
7084
7114
  }
7085
7115
  }
7086
- initMagicClient() {
7087
- return new Magic(this.config.magicPublishableApiKey, {
7088
- extensions: [new OpenIdExtension()],
7089
- network: this.config.network,
7090
- });
7091
- }
7092
7116
  }
7093
7117
 
7094
7118
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -7315,7 +7339,7 @@ var PassportEvents;
7315
7339
  var Networks;
7316
7340
  (function (Networks) {
7317
7341
  Networks["PRODUCTION"] = "mainnet";
7318
- Networks["SANDBOX"] = "goerli";
7342
+ Networks["SANDBOX"] = "sepolia";
7319
7343
  })(Networks || (Networks = {}));
7320
7344
 
7321
7345
  async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
@@ -7664,6 +7688,11 @@ class PassportImxProvider {
7664
7688
  }
7665
7689
  // TODO: Remove once implemented
7666
7690
  // eslint-disable-next-line class-methods-use-this
7691
+ isRegisteredOffchain() {
7692
+ throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7693
+ }
7694
+ // TODO: Remove once implemented
7695
+ // eslint-disable-next-line class-methods-use-this
7667
7696
  isRegisteredOnchain() {
7668
7697
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7669
7698
  }
@@ -833,6 +833,12 @@ interface IMXProvider {
833
833
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
834
834
  */
835
835
  registerOffchain(): Promise<RegisterUserResponse>;
836
+ /**
837
+ * Checks if a User is registered off-chain
838
+ *
839
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
840
+ */
841
+ isRegisteredOffchain(): Promise<boolean>;
836
842
  /**
837
843
  * Checks if a User is registered on-chain
838
844
  *
@@ -910,6 +916,7 @@ declare class GenericIMXProvider implements IMXProvider {
910
916
  private readonly signers;
911
917
  constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
912
918
  getAddress(): Promise<string>;
919
+ isRegisteredOffchain(): Promise<boolean>;
913
920
  registerOffchain(): Promise<RegisterUserResponse>;
914
921
  batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
915
922
  cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;
package/dist/provider.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Config, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
2
2
  import BN from 'bn.js';
3
3
  import * as encUtils from 'enc-utils';
4
+ import { AxiosError } from 'axios';
4
5
  import { parseUnits } from '@ethersproject/units';
5
6
  import { BigNumber } from '@ethersproject/bignumber';
6
7
  import { ethers } from 'ethers';
7
8
  import detectEthereumProvider from '@metamask/detect-provider';
8
- import 'axios';
9
9
 
10
10
  // used to sign message with L1 keys. Used for registration
11
11
  function serializeEthSignature(sig) {
@@ -285,6 +285,22 @@ async function registerOffchain(signers, config) {
285
285
  });
286
286
  return registeredUser.data;
287
287
  }
288
+ async function isRegisteredOffchain(ethAddress, config) {
289
+ try {
290
+ const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
291
+ const getUsersResult = await usersApi.getUsers({
292
+ user: ethAddress,
293
+ });
294
+ const { accounts } = getUsersResult.data;
295
+ return accounts?.length > 0;
296
+ }
297
+ catch (ex) {
298
+ if (ex instanceof AxiosError && ex.response?.status === 404) {
299
+ return false;
300
+ }
301
+ throw ex;
302
+ }
303
+ }
288
304
  async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
289
305
  await validateChain(ethSigner, config.immutableXConfig);
290
306
  const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
@@ -820,7 +836,11 @@ class GenericIMXProvider {
820
836
  this.signers = { ethSigner, starkSigner };
821
837
  }
822
838
  async getAddress() {
823
- return await this.signers.ethSigner.getAddress();
839
+ return this.signers.ethSigner.getAddress();
840
+ }
841
+ async isRegisteredOffchain() {
842
+ const ethAddress = await this.getAddress();
843
+ return isRegisteredOffchain(ethAddress, this.config);
824
844
  }
825
845
  registerOffchain() {
826
846
  return registerOffchain(this.signers, this.config);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.28.4",
4
+ "version": "0.28.5",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -14,7 +14,7 @@
14
14
  "@ethersproject/wallet": "^5.7.0",
15
15
  "@imtbl/core-sdk": "^2.4.0",
16
16
  "@jest/globals": "^29.5.0",
17
- "@magic-ext/oidc": "^1.0.1",
17
+ "@magic-ext/oidc": "^4.2.0",
18
18
  "@metamask/detect-provider": "^2.0.0",
19
19
  "@opensea/seaport-js": "2.0.7",
20
20
  "@uniswap/router-sdk": "^1.4.0",
@@ -25,7 +25,7 @@
25
25
  "enc-utils": "^3.0.0",
26
26
  "ethers": "^5.7.2",
27
27
  "jwt-decode": "^3.1.2",
28
- "magic-sdk": "^13.3.1",
28
+ "magic-sdk": "^21.2.0",
29
29
  "oidc-client-ts": "^2.2.1"
30
30
  },
31
31
  "devDependencies": {