@imtbl/sdk 0.15.2-alpha → 0.16.0-alpha.1

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.
@@ -10925,6 +10925,7 @@ declare class Passport {
10925
10925
  getUserInfoDeviceFlow(): Promise<UserProfile | undefined>;
10926
10926
  getIdToken(): Promise<string | undefined>;
10927
10927
  getAccessToken(): Promise<string | undefined>;
10928
+ getLinkedAddresses(): Promise<string[]>;
10928
10929
  }
10929
10930
 
10930
10931
  /**
@@ -11213,6 +11214,15 @@ type GasEstimateSwapTokenConfig = {
11213
11214
  inAddress: string;
11214
11215
  outAddress: string;
11215
11216
  };
11217
+ /**
11218
+ * A type representing all the feature flags available.
11219
+ * @property {TokenInfo[] | undefined} allowed - List of allowed tokens for a given chain.
11220
+ * @property {boolean | undefined} blockscout - Feature flag to enable/disable blockscout integration.
11221
+ */
11222
+ type ChainTokensConfig = {
11223
+ allowed?: TokenInfo[];
11224
+ blockscout?: boolean;
11225
+ };
11216
11226
  /**
11217
11227
  * Represents information about a network.
11218
11228
  * @interface NetworkInfo
@@ -11523,6 +11533,7 @@ declare enum CheckoutErrorType {
11523
11533
  DEFAULT_PROVIDER_ERROR = "DEFAULT_PROVIDER_ERROR",
11524
11534
  CONNECT_PROVIDER_ERROR = "CONNECT_PROVIDER_ERROR",
11525
11535
  GET_BALANCE_ERROR = "GET_BALANCE_ERROR",
11536
+ GET_INDEXER_BALANCE_ERROR = "GET_INDEXER_BALANCE_ERROR",
11526
11537
  GET_ERC20_BALANCE_ERROR = "GET_ERC20_BALANCE_ERROR",
11527
11538
  GET_ERC721_BALANCE_ERROR = "GET_ERC721_BALANCE_ERROR",
11528
11539
  GET_NETWORK_INFO_ERROR = "GET_NETWORK_INFO_ERROR",
@@ -11538,6 +11549,7 @@ declare enum CheckoutErrorType {
11538
11549
  UNSUPPORTED_TOKEN_TYPE_ERROR = "UNSUPPORTED_TOKEN_TYPE_ERROR",
11539
11550
  UNSUPPORTED_BALANCE_REQUIREMENT_ERROR = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR",
11540
11551
  GET_ORDER_LISTING_ERROR = "GET_ORDER_LISTING_ERROR",
11552
+ PREPARE_ORDER_LISTING_ERROR = "PREPARE_ORDER_LISTING_ERROR",
11541
11553
  SWITCH_NETWORK_UNSUPPORTED = "SWITCH_NETWORK_UNSUPPORTED",
11542
11554
  GET_ERC20_ALLOWANCE_ERROR = "GET_ERC20_ALLOWANCE_ERROR",
11543
11555
  GET_ERC721_ALLOWANCE_ERROR = "GET_ERC721_ALLOWANCE_ERROR"
@@ -11562,7 +11574,7 @@ type RemoteConfigParams = {
11562
11574
  declare class RemoteConfigFetcher {
11563
11575
  constructor(params: RemoteConfigParams);
11564
11576
  getConfig(key?: keyof RemoteConfiguration): Promise<RemoteConfiguration | RemoteConfiguration[keyof RemoteConfiguration] | undefined>;
11565
- getTokens(chainId: ChainId): Promise<TokenInfo[]>;
11577
+ getTokensConfig(chainId: ChainId): Promise<ChainTokensConfig>;
11566
11578
  }
11567
11579
  declare class CheckoutConfiguration {
11568
11580
  readonly isDevelopment: boolean;
@@ -11572,6 +11584,44 @@ declare class CheckoutConfiguration {
11572
11584
  readonly networkMap: NetworkMap;
11573
11585
  constructor(config: CheckoutModuleConfiguration);
11574
11586
  }
11587
+ /**
11588
+ * Interface representing the parameters for {@link Checkout.sell}
11589
+ * @property {Web3Provider} provider - The provider to use for the sell.
11590
+ * @property {string} id - The ERC721 ID.
11591
+ * @property {string} collectionAddress - The contract address of the ERC721s collection.
11592
+ * @property {BuyToken} buyToken - The token to buy the item with.
11593
+ */
11594
+ interface SellParams {
11595
+ provider: Web3Provider;
11596
+ id: string;
11597
+ collectionAddress: string;
11598
+ buyToken: BuyToken;
11599
+ }
11600
+ /**
11601
+ * Represents the token that the item can be bought with once listed for sale.
11602
+ * NativeBuyToken or ERC20BuyToken {@link Checkout.smartCheckout}.
11603
+ */
11604
+ type BuyToken = NativeBuyToken | ERC20BuyToken;
11605
+ /**
11606
+ * Represents a native buy token
11607
+ * @property {ItemType} type - The type indicate this is a native token.
11608
+ * @property {BigNumber} amount - The amount of native token.
11609
+ */
11610
+ type NativeBuyToken = {
11611
+ type: ItemType.NATIVE;
11612
+ amount: BigNumber;
11613
+ };
11614
+ /**
11615
+ * Represents a ERC20 buy token
11616
+ * @property {ItemType} type - The type indicate this is a ERC20 token.
11617
+ * @property {BigNumber} amount - The amount of native token.
11618
+ * @property {string} contractAddress - The contract address of the ERC20.
11619
+ */
11620
+ type ERC20BuyToken = {
11621
+ type: ItemType.ERC20;
11622
+ amount: BigNumber;
11623
+ contractAddress: string;
11624
+ };
11575
11625
  declare class Checkout {
11576
11626
  readonly config: CheckoutConfiguration;
11577
11627
  /**
@@ -11651,6 +11701,11 @@ declare class Checkout {
11651
11701
  * @param {BuyParams} params - The parameters for the buy.
11652
11702
  */
11653
11703
  buy(params: BuyParams): Promise<void>;
11704
+ /**
11705
+ * Determines the requirements for performing a sell.
11706
+ * @param {SellParams} params - The parameters for the sell.
11707
+ */
11708
+ sell(params: SellParams): Promise<void>;
11654
11709
  /**
11655
11710
  * Determines the transaction requirements to complete a purchase.
11656
11711
  * @params {SmartCheckoutParams} params - The parameters for smart checkout.
@@ -1,5 +1,6 @@
1
1
  import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants as constants$1 } from 'ethers';
2
2
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
3
+ import $7v2Z6$axios, { HttpStatusCode } from 'axios';
3
4
  import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
4
5
  import { TradeType, Token, Percent, CurrencyAmount } from '@uniswap/sdk-core';
5
6
  import assert from 'assert';
@@ -7,7 +8,6 @@ import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
7
8
  import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
8
9
  import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
9
10
  import { SwapRouter } from '@uniswap/router-sdk';
10
- import axios from 'axios';
11
11
  import FormData from 'form-data';
12
12
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
13
13
 
@@ -36,8 +36,7 @@ const ETH_MAINNET_CHAIN_ID = '1';
36
36
  /**
37
37
  * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
38
38
  */
39
- const ZKEVM_DEVNET_CHAIN_ID = '13433';
40
- /**
39
+ const ZKEVM_DEVNET_CHAIN_ID = '13473';
41
40
  /**
42
41
  * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
43
42
  */
@@ -12318,10 +12317,10 @@ const SUPPORTED_BRIDGES_FOR_ENVIRONMENT = {
12318
12317
  */
12319
12318
  const CONTRACTS_FOR_BRIDGE = new Map()
12320
12319
  .set(ETH_SEPOLIA_TO_ZKEVM_DEVNET, {
12321
- rootChainERC20Predicate: '0xAC0f2096732D40096B3356AD76ba60a2f02366c8',
12322
- rootChainStateSender: '0xeA76fcCdD791A9c231CAda787ae7535c8a5E55B5',
12323
- rootChainCheckpointManager: '0x321A466aa78F5957C6E2375114915EcD14DAdE44',
12324
- rootChainExitHelper: '0x55cA8C418bbB0aC87414F9ea6FFC6a33860Cf967',
12320
+ rootChainERC20Predicate: '0x75E468cF088F947B96422996132FbE71160F21F1',
12321
+ rootChainStateSender: '0xbdC11416f01b122b7621855e61c99C7ED986F894',
12322
+ rootChainCheckpointManager: '0x0721b564a96466b864A998D31846Ba409d21092B',
12323
+ rootChainExitHelper: '0x0a2cb3f90aE65429E5c516af500F59d8fed51844',
12325
12324
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
12326
12325
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
12327
12326
  })
@@ -15889,7 +15888,7 @@ const getRequestBody = (options) => {
15889
15888
  return undefined;
15890
15889
  };
15891
15890
  const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
15892
- const source = axios.CancelToken.source();
15891
+ const source = $7v2Z6$axios.CancelToken.source();
15893
15892
  const requestConfig = {
15894
15893
  url,
15895
15894
  headers,
@@ -15900,7 +15899,7 @@ const sendRequest = async (config, options, url, body, formData, headers, onCanc
15900
15899
  };
15901
15900
  onCancel(() => source.cancel('The user aborted a request.'));
15902
15901
  try {
15903
- return await axios.request(requestConfig);
15902
+ return await $7v2Z6$axios.request(requestConfig);
15904
15903
  }
15905
15904
  catch (error) {
15906
15905
  const axiosError = error;
@@ -16094,6 +16093,54 @@ class OrdersService {
16094
16093
  },
16095
16094
  });
16096
16095
  }
16096
+ /**
16097
+ * List all trades
16098
+ * List all trades
16099
+ * @returns ListTradeResult OK response.
16100
+ * @throws ApiError
16101
+ */
16102
+ listTrades({ chainName, accountAddress, pageSize, sortBy, sortDirection, pageCursor, }) {
16103
+ return this.httpRequest.request({
16104
+ method: 'GET',
16105
+ url: '/v1/chains/{chain_name}/trades',
16106
+ path: {
16107
+ 'chain_name': chainName,
16108
+ },
16109
+ query: {
16110
+ 'account_address': accountAddress,
16111
+ 'page_size': pageSize,
16112
+ 'sort_by': sortBy,
16113
+ 'sort_direction': sortDirection,
16114
+ 'page_cursor': pageCursor,
16115
+ },
16116
+ errors: {
16117
+ 400: `Bad Request (400)`,
16118
+ 404: `The specified resource was not found (404)`,
16119
+ 500: `Internal Server Error (500)`,
16120
+ },
16121
+ });
16122
+ }
16123
+ /**
16124
+ * Get a single trade by ID
16125
+ * Get a single trade by ID
16126
+ * @returns TradeResult OK response.
16127
+ * @throws ApiError
16128
+ */
16129
+ getTrade({ chainName, tradeId, }) {
16130
+ return this.httpRequest.request({
16131
+ method: 'GET',
16132
+ url: '/v1/chains/{chain_name}/trades/{trade_id}',
16133
+ path: {
16134
+ 'chain_name': chainName,
16135
+ 'trade_id': tradeId,
16136
+ },
16137
+ errors: {
16138
+ 400: `Bad Request (400)`,
16139
+ 404: `The specified resource was not found (404)`,
16140
+ 500: `Internal Server Error (500)`,
16141
+ },
16142
+ });
16143
+ }
16097
16144
  }
16098
16145
 
16099
16146
  class OrderBookClient {
@@ -16230,6 +16277,57 @@ function mapFromOpenApiOrder(order) {
16230
16277
  updateTime: order.update_time,
16231
16278
  };
16232
16279
  }
16280
+ function mapFromOpenApiTrade(trade) {
16281
+ const buyItems = trade.buy.map((item) => {
16282
+ if (item.item_type === 'ERC20') {
16283
+ return {
16284
+ type: 'ERC20',
16285
+ contractAddress: item.contract_address,
16286
+ amount: item.start_amount,
16287
+ };
16288
+ }
16289
+ if (item.item_type === 'NATIVE') {
16290
+ return {
16291
+ type: 'NATIVE',
16292
+ amount: item.start_amount,
16293
+ };
16294
+ }
16295
+ throw new Error('Buy items must be either ERC20 or NATIVE');
16296
+ });
16297
+ const sellItems = trade.sell.map((item) => {
16298
+ if (item.item_type === 'ERC721') {
16299
+ return {
16300
+ type: 'ERC721',
16301
+ contractAddress: item.contract_address,
16302
+ tokenId: item.token_id,
16303
+ };
16304
+ }
16305
+ throw new Error('Sell items must ERC721');
16306
+ });
16307
+ return {
16308
+ id: trade.id,
16309
+ orderId: trade.order_id,
16310
+ buy: buyItems,
16311
+ sell: sellItems,
16312
+ buyerFees: trade.buyer_fees.map((fee) => ({
16313
+ amount: fee.amount,
16314
+ recipient: fee.recipient,
16315
+ type: fee.fee_type,
16316
+ })),
16317
+ chain: trade.chain,
16318
+ indexedAt: trade.indexed_at,
16319
+ blockchainMetadata: {
16320
+ blockNumber: trade.blockchain_metadata.block_number,
16321
+ logIndex: trade.blockchain_metadata.log_index,
16322
+ transactionHash: trade.blockchain_metadata.transaction_hash,
16323
+ transactionIndex: trade.blockchain_metadata.transaction_index,
16324
+ },
16325
+ buyerAddress: trade.buyer_address,
16326
+ makerAddress: trade.maker_address,
16327
+ sellerAddress: trade.seller_address,
16328
+ takerAddress: trade.taker_address,
16329
+ };
16330
+ }
16233
16331
  function mapFromOpenApiPage(page) {
16234
16332
  return {
16235
16333
  nextCursor: page.next_cursor,
@@ -16559,12 +16657,24 @@ class ImmutableApiClient {
16559
16657
  listingId,
16560
16658
  });
16561
16659
  }
16660
+ async getTrade(tradeId) {
16661
+ return this.orderbookService.getTrade({
16662
+ chainName: this.chainName,
16663
+ tradeId,
16664
+ });
16665
+ }
16562
16666
  async listListings(listOrderParams) {
16563
16667
  return this.orderbookService.listListings({
16564
16668
  chainName: this.chainName,
16565
16669
  ...listOrderParams,
16566
16670
  });
16567
16671
  }
16672
+ async listTrades(listTradesParams) {
16673
+ return this.orderbookService.listTrades({
16674
+ chainName: this.chainName,
16675
+ ...listTradesParams,
16676
+ });
16677
+ }
16568
16678
  async createListing({ orderHash, orderComponents, orderSignature, makerFee, }) {
16569
16679
  if (orderComponents.offer.length !== 1) {
16570
16680
  throw new Error('Only one item can be listed at a time');
@@ -16730,6 +16840,17 @@ class Orderbook {
16730
16840
  result: mapFromOpenApiOrder(apiListing.result),
16731
16841
  };
16732
16842
  }
16843
+ /**
16844
+ * Get a trade by ID
16845
+ * @param {string} tradeId - The tradeId to find.
16846
+ * @return {TradeResult} The returned order result.
16847
+ */
16848
+ async getTrade(tradeId) {
16849
+ const apiListing = await this.apiClient.getTrade(tradeId);
16850
+ return {
16851
+ result: mapFromOpenApiTrade(apiListing.result),
16852
+ };
16853
+ }
16733
16854
  /**
16734
16855
  * List orders. This method is used to get a list of orders filtered by conditions specified
16735
16856
  * in the params object.
@@ -16743,6 +16864,19 @@ class Orderbook {
16743
16864
  result: apiListings.result.map(mapFromOpenApiOrder),
16744
16865
  };
16745
16866
  }
16867
+ /**
16868
+ * List trades. This method is used to get a list of trades filtered by conditions specified
16869
+ * in the params object
16870
+ * @param {ListTradesParams} listTradesParams - Filtering, ordering and page parameters.
16871
+ * @return {ListTradesResult} The paged trades.
16872
+ */
16873
+ async listTrades(listTradesParams) {
16874
+ const apiListings = await this.apiClient.listTrades(listTradesParams);
16875
+ return {
16876
+ page: mapFromOpenApiPage(apiListings.page),
16877
+ result: apiListings.result.map(mapFromOpenApiTrade),
16878
+ };
16879
+ }
16746
16880
  /**
16747
16881
  * Get required transactions and messages for signing prior to creating a listing
16748
16882
  * through the createListing method
@@ -16945,6 +17079,9 @@ const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
16945
17079
  [(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
16946
17080
  [(Environment$1).PRODUCTION]: "https://checkout-api.immutable.com"
16947
17081
  };
17082
+ const $d85ad1457a3f1a83$export$fc55ed5a42b458ba = {
17083
+ [($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET]: "https://explorer.testnet.immutable.com"
17084
+ };
16948
17085
  const $d85ad1457a3f1a83$export$6f24f3cef7d501c4 = new Map([
16949
17086
  [
16950
17087
  ($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM,
@@ -17277,6 +17414,7 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
17277
17414
  CheckoutErrorType["DEFAULT_PROVIDER_ERROR"] = "DEFAULT_PROVIDER_ERROR";
17278
17415
  CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
17279
17416
  CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
17417
+ CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
17280
17418
  CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
17281
17419
  CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
17282
17420
  CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
@@ -17292,6 +17430,7 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
17292
17430
  CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
17293
17431
  CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
17294
17432
  CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
17433
+ CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
17295
17434
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
17296
17435
  CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
17297
17436
  CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
@@ -17482,7 +17621,7 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async (config, { type: type =
17482
17621
  case ($08d5ddc39acd6833$export$fd9b17d87f4121d2).BRIDGE:
17483
17622
  case ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL:
17484
17623
  default:
17485
- tokens = await config.remote.getTokens(chainId);
17624
+ tokens = (await config.remote.getTokensConfig(chainId)).allowed;
17486
17625
  }
17487
17626
  if (!exclude || exclude?.length === 0) return {
17488
17627
  tokens: tokens
@@ -17495,6 +17634,90 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async (config, { type: type =
17495
17634
 
17496
17635
 
17497
17636
 
17637
+
17638
+
17639
+ const $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL = 60; // seconds
17640
+ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
17641
+ url;
17642
+ ttl;
17643
+ chainId;
17644
+ cacheMap;
17645
+ static async makeHttpRequest(url) {
17646
+ return ($7v2Z6$axios).get(url);
17647
+ }
17648
+ setCache(key, data) {
17649
+ this.cacheMap[key] = {
17650
+ data: data,
17651
+ ttl: new Date().getTime() + this.ttl * 1000
17652
+ };
17653
+ }
17654
+ getCache(key) {
17655
+ const d = this.cacheMap[key];
17656
+ if (!d || d.ttl <= new Date().getTime()) return null;
17657
+ return d.data;
17658
+ }
17659
+ /**
17660
+ * Blockscout constructor
17661
+ * @param chainId target chain
17662
+ * @param ttl cache TTL
17663
+ */ constructor(params){
17664
+ this.chainId = params.chainId;
17665
+ this.url = ($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[this.chainId];
17666
+ this.cacheMap = {};
17667
+ this.ttl = params.ttl !== undefined ? params.ttl : $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL;
17668
+ }
17669
+ /**
17670
+ * isChainSupported verifies if the chain is supported by Blockscout
17671
+ * @param chainId
17672
+ */ static isChainSupported = (chainId)=>Boolean(($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[chainId]);
17673
+ /**
17674
+ * isBlockscoutError verifies if the error is a Blockscout client error
17675
+ * @param err error to evaluate
17676
+ */ static isBlockscoutError = (err)=>"code" in err;
17677
+ /**
17678
+ * getAddressTokens fetches the list of tokens (by type) owned by the wallet address.
17679
+ * @param walletAddress wallet address
17680
+ * @param tokenType token types
17681
+ * @param nextPage parameters for the next page, to be provided along side walletAddress and tokenType
17682
+ * @returns list of tokens given the wallet address and the token types
17683
+ */ async getAddressTokens(params) {
17684
+ try {
17685
+ let url = `${this.url}/api/v2/addresses/${params.walletAddress}/tokens?type=${params.tokenType.join(",")}`;
17686
+ if (params.nextPage) url += `&${new URLSearchParams(params.nextPage)}`;
17687
+ // Cache response data to prevent unnecessary requests
17688
+ const cached = this.getCache(url);
17689
+ if (cached && cached.status < 400) return Promise.resolve(cached.data);
17690
+ const response = await $fd8a8472dcc3ec2b$export$ef140a6b05dfc786.makeHttpRequest(url);
17691
+ if (response.status >= 400) return Promise.reject({
17692
+ code: response.status,
17693
+ message: response.statusText
17694
+ });
17695
+ this.setCache(url, response);
17696
+ return Promise.resolve(response.data);
17697
+ } catch (err) {
17698
+ let code = (HttpStatusCode).InternalServerError;
17699
+ let message = "InternalServerError";
17700
+ if (($7v2Z6$axios).isAxiosError(err)) {
17701
+ code = err.response?.status || code;
17702
+ message = err.message;
17703
+ }
17704
+ return Promise.reject({
17705
+ code: code,
17706
+ message: message
17707
+ });
17708
+ }
17709
+ }
17710
+ }
17711
+
17712
+
17713
+ /* eslint @typescript-eslint/naming-convention: off */ var $887a00f8f72d61f0$export$5bd1ea2b3d18210;
17714
+ (function(BlockscoutTokenType) {
17715
+ BlockscoutTokenType["ERC20"] = "ERC-20";
17716
+ })($887a00f8f72d61f0$export$5bd1ea2b3d18210 || ($887a00f8f72d61f0$export$5bd1ea2b3d18210 = {}));
17717
+
17718
+
17719
+
17720
+
17498
17721
  const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, walletAddress)=>await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
17499
17722
  const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(config, web3Provider);
17500
17723
  if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
@@ -17534,6 +17757,59 @@ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAdd
17534
17757
  type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
17535
17758
  });
17536
17759
  }
17760
+ // Blockscout client singleton
17761
+ let $1564e43dde50bb61$var$blockscoutClient;
17762
+ const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId, rename)=>{
17763
+ // Shuffle the mapping of the tokens configuration so it is a hashmap
17764
+ // for faster access to tokens config objects.
17765
+ const mapRename = Object.assign({}, ...rename.map((t)=>({
17766
+ [t.address || ""]: t
17767
+ })));
17768
+ // Ensure singleton is present and match the selected chain
17769
+ if (!$1564e43dde50bb61$var$blockscoutClient || $1564e43dde50bb61$var$blockscoutClient.chainId !== chainId) $1564e43dde50bb61$var$blockscoutClient = new ($fd8a8472dcc3ec2b$export$ef140a6b05dfc786)({
17770
+ chainId: chainId
17771
+ });
17772
+ // Hold the items in an array for post-fetching processing
17773
+ const items = [];
17774
+ const tokenType = [
17775
+ ($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20
17776
+ ];
17777
+ // Given that the widgets aren't yet designed to support pagination,
17778
+ // fetch all the possible tokens associated to a given wallet address.
17779
+ let resp;
17780
+ try {
17781
+ do {
17782
+ // eslint-disable-next-line no-await-in-loop
17783
+ resp = await $1564e43dde50bb61$var$blockscoutClient.getAddressTokens({
17784
+ walletAddress: walletAddress,
17785
+ tokenType: tokenType,
17786
+ nextPage: resp?.next_page_params
17787
+ });
17788
+ items.push(...resp.items);
17789
+ }while (resp.next_page_params);
17790
+ } catch (err) {
17791
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
17792
+ }
17793
+ return {
17794
+ balances: items.map((item)=>{
17795
+ const tokenData = item.token || {};
17796
+ const balance = (BigNumber$1).from(item.value);
17797
+ const renamed = mapRename[tokenData.address] || {};
17798
+ const token = {
17799
+ ...tokenData,
17800
+ name: renamed.name ?? tokenData.name,
17801
+ symbol: renamed.symbol ?? tokenData.symbol,
17802
+ decimals: parseInt(tokenData.decimals, 10)
17803
+ };
17804
+ const formattedBalance = (utils).formatUnits(item.value, token.decimals);
17805
+ return {
17806
+ balance: balance,
17807
+ formattedBalance: formattedBalance,
17808
+ token: token
17809
+ };
17810
+ })
17811
+ };
17812
+ };
17537
17813
  const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, walletAddress, tokens)=>{
17538
17814
  const allBalancePromises = [];
17539
17815
  tokens.forEach((token)=>{
@@ -17552,6 +17828,17 @@ const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, w
17552
17828
  type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
17553
17829
  chainId: chainId
17554
17830
  });
17831
+ // In order to prevent unnecessary RPC calls
17832
+ // let's use the Indexer if available for the
17833
+ // given chain.
17834
+ let flag = false;
17835
+ try {
17836
+ flag = (await config.remote.getTokensConfig(chainId)).blockscout || flag;
17837
+ } catch (err) {
17838
+ // eslint-disable-next-line no-console
17839
+ console.error(err);
17840
+ }
17841
+ if (flag && ($fd8a8472dcc3ec2b$export$ef140a6b05dfc786).isChainSupported(chainId)) return await $1564e43dde50bb61$export$8c978679845804d4(walletAddress, chainId, tokens);
17555
17842
  return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
17556
17843
  };
17557
17844
 
@@ -17820,7 +18107,7 @@ class $a492ee374ae7b613$export$d902b56530cd5f87 {
17820
18107
  static async makeHttpRequest(url) {
17821
18108
  let response;
17822
18109
  try {
17823
- response = await (0, axios).get(url);
18110
+ response = await (0, $7v2Z6$axios).get(url);
17824
18111
  } catch (error) {
17825
18112
  throw new Error(`Error fetching from api: ${error.message}`);
17826
18113
  }
@@ -17850,10 +18137,10 @@ class $a492ee374ae7b613$export$d902b56530cd5f87 {
17850
18137
  if (!key) return config;
17851
18138
  return config[key];
17852
18139
  }
17853
- async getTokens(chainId) {
18140
+ async getTokensConfig(chainId) {
17854
18141
  const config = await this.loadConfigTokens();
17855
- if (!config) return [];
17856
- return config[chainId]?.allowed ?? [];
18142
+ if (!config || !config[chainId]) return {};
18143
+ return config[chainId] ?? [];
17857
18144
  }
17858
18145
  }
17859
18146
 
@@ -18176,7 +18463,9 @@ const $35c3fc7013888ba5$export$90366d6b714c6f69 = async (provider, ownerAddress,
18176
18463
  return await contract.isApprovedForAll(ownerAddress, spenderAddress);
18177
18464
  } catch (err) {
18178
18465
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to check approval for all ERC721s of collection", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18179
- contractAddress: contractAddress
18466
+ ownerAddress: ownerAddress,
18467
+ contractAddress: contractAddress,
18468
+ spenderAddress: spenderAddress
18180
18469
  });
18181
18470
  }
18182
18471
  };
@@ -18188,7 +18477,10 @@ const $35c3fc7013888ba5$export$ebb2a35f2b4cf5f6 = async (provider, ownerAddress,
18188
18477
  return transaction;
18189
18478
  } catch (err) {
18190
18479
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18191
- contractAddress: contractAddress
18480
+ id: id.toString(),
18481
+ contractAddress: contractAddress,
18482
+ spenderAddress: spenderAddress,
18483
+ ownerAddress: ownerAddress
18192
18484
  });
18193
18485
  }
18194
18486
  };
@@ -18198,6 +18490,7 @@ const $35c3fc7013888ba5$export$c4605a8dd415eeea = async (provider, contractAddre
18198
18490
  return await contract.getApproved(id);
18199
18491
  } catch (err) {
18200
18492
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get approved address for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
18493
+ id: id.toString(),
18201
18494
  contractAddress: contractAddress
18202
18495
  });
18203
18496
  }
@@ -18787,6 +19080,81 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18787
19080
 
18788
19081
 
18789
19082
 
19083
+
19084
+ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
19085
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
19086
+ id: id,
19087
+ contractAddress: contractAddress,
19088
+ spenderAddress: spenderAddress
19089
+ });
19090
+ const $9085b221b72ac69e$export$d2da5a4d143c85e5 = (buyToken)=>{
19091
+ if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
19092
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
19093
+ amount: buyToken.amount.toString()
19094
+ };
19095
+ return {
19096
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
19097
+ amount: buyToken.amount.toString(),
19098
+ contractAddress: buyToken.contractAddress
19099
+ };
19100
+ };
19101
+ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, contractAddress, buyToken)=>{
19102
+ let orderbook;
19103
+ let listing;
19104
+ let spenderAddress = "";
19105
+ try {
19106
+ const walletAddress = await provider.getSigner().getAddress();
19107
+ orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
19108
+ const { seaportContractAddress: seaportContractAddress } = orderbook.config();
19109
+ spenderAddress = seaportContractAddress;
19110
+ listing = await orderbook.prepareListing({
19111
+ makerAddress: walletAddress,
19112
+ buy: $9085b221b72ac69e$export$d2da5a4d143c85e5(buyToken),
19113
+ sell: {
19114
+ type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
19115
+ contractAddress: contractAddress,
19116
+ tokenId: id
19117
+ }
19118
+ });
19119
+ } catch (err) {
19120
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
19121
+ message: err.message,
19122
+ id: id,
19123
+ collectionAddress: contractAddress
19124
+ });
19125
+ }
19126
+ const itemRequirements = [
19127
+ $9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
19128
+ ];
19129
+ // eslint-disable-next-line no-console
19130
+ console.log(listing); // TODO: Get order signature, provider.getSigner()._signTypedData to sign
19131
+ const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
19132
+ type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
19133
+ gasToken: {
19134
+ type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
19135
+ limit: (BigNumber$1).from((constants).estimatedFulfillmentGasGwei)
19136
+ }
19137
+ });
19138
+ // eslint-disable-next-line no-console
19139
+ console.log("transactionRequirements", smartCheckoutResult);
19140
+ return {
19141
+ itemRequirements: itemRequirements,
19142
+ gasToken: {
19143
+ type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
19144
+ limit: (BigNumber$1).from((constants).estimatedFulfillmentGasGwei)
19145
+ },
19146
+ smartCheckoutResult: smartCheckoutResult
19147
+ };
19148
+ };
19149
+
19150
+
19151
+
19152
+
19153
+
19154
+
19155
+
19156
+
19157
+
18790
19158
  async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
18791
19159
  if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
18792
19160
  if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
@@ -18931,6 +19299,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
18931
19299
  await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
18932
19300
  }
18933
19301
  /**
19302
+ * Determines the requirements for performing a sell.
19303
+ * @param {SellParams} params - The parameters for the sell.
19304
+ */ async sell(params) {
19305
+ if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
19306
+ // eslint-disable-next-line no-console
19307
+ console.warn("This endpoint is currently under construction.");
19308
+ const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
19309
+ await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
19310
+ }
19311
+ /**
18934
19312
  * Determines the transaction requirements to complete a purchase.
18935
19313
  * @params {SmartCheckoutParams} params - The parameters for smart checkout.
18936
19314
  */ async smartCheckout(params) {