@imtbl/sdk 0.14.0-alpha → 0.14.0-alpha.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.
@@ -11524,6 +11524,7 @@ declare enum CheckoutErrorType {
11524
11524
  CONNECT_PROVIDER_ERROR = "CONNECT_PROVIDER_ERROR",
11525
11525
  GET_BALANCE_ERROR = "GET_BALANCE_ERROR",
11526
11526
  GET_ERC20_BALANCE_ERROR = "GET_ERC20_BALANCE_ERROR",
11527
+ GET_ERC721_BALANCE_ERROR = "GET_ERC721_BALANCE_ERROR",
11527
11528
  GET_NETWORK_INFO_ERROR = "GET_NETWORK_INFO_ERROR",
11528
11529
  METAMASK_PROVIDER_ERROR = "METAMASK_PROVIDER_ERROR",
11529
11530
  CHAIN_NOT_SUPPORTED_ERROR = "CHAIN_NOT_SUPPORTED_ERROR",
@@ -11535,6 +11536,7 @@ declare enum CheckoutErrorType {
11535
11536
  UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
11536
11537
  INVALID_GAS_ESTIMATE_TYPE = "INVALID_GAS_ESTIMATE_TYPE",
11537
11538
  UNSUPPORTED_TOKEN_TYPE_ERROR = "UNSUPPORTED_TOKEN_TYPE_ERROR",
11539
+ UNSUPPORTED_BALANCE_REQUIREMENT_ERROR = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR",
11538
11540
  GET_ORDER_LISTING_ERROR = "GET_ORDER_LISTING_ERROR",
11539
11541
  SWITCH_NETWORK_UNSUPPORTED = "SWITCH_NETWORK_UNSUPPORTED",
11540
11542
  GET_ERC20_ALLOWANCE_ERROR = "GET_ERC20_ALLOWANCE_ERROR",
@@ -16176,6 +16176,67 @@ var ActionType;
16176
16176
  ActionType["SIGNABLE"] = "SIGNABLE";
16177
16177
  })(ActionType || (ActionType = {}));
16178
16178
 
16179
+ function mapFromOpenApiOrder(order) {
16180
+ const buyItems = order.buy.map((item) => {
16181
+ if (item.item_type === 'ERC20') {
16182
+ return {
16183
+ type: 'ERC20',
16184
+ contractAddress: item.contract_address,
16185
+ amount: item.start_amount,
16186
+ };
16187
+ }
16188
+ if (item.item_type === 'NATIVE') {
16189
+ return {
16190
+ type: 'NATIVE',
16191
+ amount: item.start_amount,
16192
+ };
16193
+ }
16194
+ throw new Error('Buy items must be either ERC20 or NATIVE');
16195
+ });
16196
+ const sellItems = order.sell.map((item) => {
16197
+ if (item.item_type === 'ERC721') {
16198
+ return {
16199
+ type: 'ERC721',
16200
+ contractAddress: item.contract_address,
16201
+ tokenId: item.token_id,
16202
+ };
16203
+ }
16204
+ throw new Error('Sell items must ERC721');
16205
+ });
16206
+ return {
16207
+ id: order.id,
16208
+ accountAddress: order.account_address,
16209
+ buy: buyItems,
16210
+ sell: sellItems,
16211
+ fees: order.fees.map((fee) => ({
16212
+ amount: fee.amount,
16213
+ recipient: fee.recipient,
16214
+ type: fee.fee_type,
16215
+ })),
16216
+ chain: order.chain,
16217
+ createTime: order.create_time,
16218
+ endTime: order.end_time,
16219
+ protocolData: {
16220
+ counter: order.protocol_data.counter,
16221
+ orderType: order.protocol_data.order_type,
16222
+ seaportAddress: order.protocol_data.seaport_address,
16223
+ seaportVersion: order.protocol_data.seaport_version,
16224
+ zoneAddress: order.protocol_data.zone_address,
16225
+ },
16226
+ salt: order.salt,
16227
+ signature: order.signature,
16228
+ startTime: order.start_time,
16229
+ status: order.status,
16230
+ updateTime: order.update_time,
16231
+ };
16232
+ }
16233
+ function mapFromOpenApiPage(page) {
16234
+ return {
16235
+ nextCursor: page.next_cursor,
16236
+ previousCursor: page.previous_cursor,
16237
+ };
16238
+ }
16239
+
16179
16240
  /* eslint-disable */
16180
16241
  // TODO: Resolve these from seaport-js.
16181
16242
  // There is some bundling issue that is preventing this from working
@@ -16405,7 +16466,17 @@ class Seaport {
16405
16466
  buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods),
16406
16467
  purpose: TransactionPurpose.FULFILL_ORDER,
16407
16468
  });
16408
- return { actions: fulfillmentActions };
16469
+ // Expirtaion bytes in SIP7 extra data [21:29]
16470
+ // In hex string -> [21 * 2 + 2 (0x) : 29 * 2]
16471
+ // In JS slice (start, end_inclusive), (44,60)
16472
+ // 8 bytes uint64 epoch time in seconds
16473
+ const expirationHex = extraData.slice(44, 60);
16474
+ const expirationInSeconds = parseInt(expirationHex, 16);
16475
+ return {
16476
+ actions: fulfillmentActions,
16477
+ expiration: (new Date(expirationInSeconds * 1000)).toISOString(),
16478
+ order: mapFromOpenApiOrder(order),
16479
+ };
16409
16480
  }
16410
16481
  async cancelOrder(order, account) {
16411
16482
  const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
@@ -16525,7 +16596,7 @@ class ImmutableApiClient {
16525
16596
  ],
16526
16597
  fees: makerFee ? [{
16527
16598
  amount: makerFee.amount,
16528
- fee_type: makerFee.type,
16599
+ fee_type: FeeType.MAKER_MARKETPLACE,
16529
16600
  recipient: makerFee.recipient,
16530
16601
  }] : [],
16531
16602
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
@@ -16653,8 +16724,11 @@ class Orderbook {
16653
16724
  * @param {string} listingId - The listingId to find.
16654
16725
  * @return {ListingResult} The returned order result.
16655
16726
  */
16656
- getListing(listingId) {
16657
- return this.apiClient.getListing(listingId);
16727
+ async getListing(listingId) {
16728
+ const apiListing = await this.apiClient.getListing(listingId);
16729
+ return {
16730
+ result: mapFromOpenApiOrder(apiListing.result),
16731
+ };
16658
16732
  }
16659
16733
  /**
16660
16734
  * List orders. This method is used to get a list of orders filtered by conditions specified
@@ -16662,8 +16736,12 @@ class Orderbook {
16662
16736
  * @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
16663
16737
  * @return {ListListingsResult} The paged orders.
16664
16738
  */
16665
- listListings(listOrderParams) {
16666
- return this.apiClient.listListings(listOrderParams);
16739
+ async listListings(listOrderParams) {
16740
+ const apiListings = await this.apiClient.listListings(listOrderParams);
16741
+ return {
16742
+ page: mapFromOpenApiPage(apiListings.page),
16743
+ result: apiListings.result.map(mapFromOpenApiOrder),
16744
+ };
16667
16745
  }
16668
16746
  /**
16669
16747
  * Get required transactions and messages for signing prior to creating a listing
@@ -16685,8 +16763,20 @@ class Orderbook {
16685
16763
  * @param {CreateListingParams} createListingParams - create an order with the given params.
16686
16764
  * @return {ListingResult} The result of the order created in the Immutable services.
16687
16765
  */
16688
- createListing(createListingParams) {
16689
- return this.apiClient.createListing(createListingParams);
16766
+ async createListing(createListingParams) {
16767
+ const makerFee = createListingParams.makerFee
16768
+ ? {
16769
+ ...createListingParams.makerFee,
16770
+ type: FeeType.MAKER_MARKETPLACE,
16771
+ }
16772
+ : undefined;
16773
+ const apiListingResponse = await this.apiClient.createListing({
16774
+ ...createListingParams,
16775
+ makerFee,
16776
+ });
16777
+ return {
16778
+ result: mapFromOpenApiOrder(apiListingResponse.result),
16779
+ };
16690
16780
  }
16691
16781
  /**
16692
16782
  * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
@@ -16703,7 +16793,7 @@ class Orderbook {
16703
16793
  fee: takerFee
16704
16794
  ? {
16705
16795
  amount: takerFee.amount,
16706
- fee_type: takerFee.type,
16796
+ fee_type: FeeType.TAKER_MARKETPLACE,
16707
16797
  recipient: takerFee.recipient,
16708
16798
  }
16709
16799
  : undefined,
@@ -16848,6 +16938,8 @@ const $e768639828688ca3$export$44dde05038008549 = {
16848
16938
 
16849
16939
 
16850
16940
  const $d85ad1457a3f1a83$export$7d3a9eeba384fa59 = "development";
16941
+ const $d85ad1457a3f1a83$export$b80040cb173ba6e9 = "0x0000000000000000000000000000000000001010";
16942
+ const $d85ad1457a3f1a83$export$903389470ba9433c = 18;
16851
16943
  const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
16852
16944
  [$d85ad1457a3f1a83$export$7d3a9eeba384fa59]: "https://checkout-api.dev.immutable.com",
16853
16945
  [(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
@@ -17130,6 +17222,25 @@ const $d85ad1457a3f1a83$export$8b8be7a2a654f23e = [
17130
17222
  payable: false,
17131
17223
  stateMutability: "view",
17132
17224
  type: "function"
17225
+ },
17226
+ {
17227
+ inputs: [
17228
+ {
17229
+ internalType: "uint256",
17230
+ name: "tokenId",
17231
+ type: "uint256"
17232
+ }
17233
+ ],
17234
+ name: "ownerOf",
17235
+ outputs: [
17236
+ {
17237
+ internalType: "address",
17238
+ name: "",
17239
+ type: "address"
17240
+ }
17241
+ ],
17242
+ stateMutability: "view",
17243
+ type: "function"
17133
17244
  }
17134
17245
  ];
17135
17246
 
@@ -17171,6 +17282,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
17171
17282
  CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
17172
17283
  CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
17173
17284
  CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
17285
+ CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
17174
17286
  CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
17175
17287
  CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
17176
17288
  CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
@@ -17182,6 +17294,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
17182
17294
  CheckoutErrorType["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
17183
17295
  CheckoutErrorType["INVALID_GAS_ESTIMATE_TYPE"] = "INVALID_GAS_ESTIMATE_TYPE";
17184
17296
  CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
17297
+ CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
17185
17298
  CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
17186
17299
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
17187
17300
  CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
@@ -17403,39 +17516,48 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
17403
17516
  async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
17404
17517
  return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
17405
17518
  const contract = new (Contract$1)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
17406
- const name = await contract.name();
17407
- const symbol = await contract.symbol();
17408
- const balance = await contract.balanceOf(walletAddress);
17409
- const decimals = await contract.decimals();
17410
- const formattedBalance = (utils).formatUnits(balance, decimals);
17411
- return {
17412
- balance: balance,
17413
- formattedBalance: formattedBalance,
17414
- token: {
17415
- name: name,
17416
- symbol: symbol,
17417
- decimals: decimals,
17418
- address: contractAddress
17419
- }
17420
- };
17519
+ return Promise.all([
17520
+ contract.name(),
17521
+ contract.symbol(),
17522
+ contract.balanceOf(walletAddress),
17523
+ contract.decimals()
17524
+ ]).then(([name, symbol, balance, decimals])=>{
17525
+ const formattedBalance = (utils).formatUnits(balance, decimals);
17526
+ return {
17527
+ balance: balance,
17528
+ formattedBalance: formattedBalance,
17529
+ token: {
17530
+ name: name,
17531
+ symbol: symbol,
17532
+ decimals: decimals,
17533
+ address: contractAddress
17534
+ }
17535
+ };
17536
+ });
17421
17537
  }, {
17422
17538
  type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
17423
17539
  });
17424
17540
  }
17425
- const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, walletAddress, chainId)=>{
17426
- const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
17427
- type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
17428
- chainId: chainId
17429
- });
17541
+ const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, walletAddress, tokens)=>{
17430
17542
  const allBalancePromises = [];
17431
- allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(config, web3Provider, walletAddress));
17432
- tokenList.tokens.forEach((token)=>token.address && allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address)));
17543
+ tokens.forEach((token)=>{
17544
+ // Check for NATIVE token
17545
+ if (!token.address || token.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(config, web3Provider, walletAddress));
17546
+ else allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address));
17547
+ });
17433
17548
  const balanceResults = await Promise.allSettled(allBalancePromises);
17434
- const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
17549
+ const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
17435
17550
  return {
17436
- balances: getBalanceResults
17551
+ balances: balances
17437
17552
  };
17438
17553
  };
17554
+ const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, walletAddress, chainId)=>{
17555
+ const { tokens: tokens } = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
17556
+ type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
17557
+ chainId: chainId
17558
+ });
17559
+ return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
17560
+ };
17439
17561
 
17440
17562
 
17441
17563
 
@@ -18184,6 +18306,278 @@ const $35c3fc7013888ba5$export$be546c525d418988 = async (provider, ownerAddress,
18184
18306
 
18185
18307
 
18186
18308
 
18309
+ /* eslint-disable arrow-body-style */
18310
+
18311
+
18312
+
18313
+
18314
+
18315
+ const $aa6caea9a60d18c7$export$f4d35754ad350071 = (itemRequirements)=>{
18316
+ const aggregatedMap = new Map();
18317
+ const aggregatedItemRequirements = [];
18318
+ itemRequirements.forEach((itemRequirement)=>{
18319
+ const { type: type } = itemRequirement;
18320
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
18321
+ aggregatedItemRequirements.push(itemRequirement);
18322
+ return;
18323
+ }
18324
+ const { amount: amount } = itemRequirement;
18325
+ const aggregateItem = aggregatedMap.get(type);
18326
+ if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
18327
+ else aggregatedMap.set(type, {
18328
+ ...itemRequirement
18329
+ });
18330
+ });
18331
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
18332
+ };
18333
+ const $aa6caea9a60d18c7$export$b8de545554d50911 = (itemRequirements)=>{
18334
+ const aggregatedMap = new Map();
18335
+ const aggregatedItemRequirements = [];
18336
+ itemRequirements.forEach((itemRequirement)=>{
18337
+ const { type: type } = itemRequirement;
18338
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
18339
+ aggregatedItemRequirements.push(itemRequirement);
18340
+ return;
18341
+ }
18342
+ const { contractAddress: contractAddress, amount: amount } = itemRequirement;
18343
+ const key = `${contractAddress}`;
18344
+ const aggregateItem = aggregatedMap.get(key);
18345
+ if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
18346
+ else aggregatedMap.set(key, {
18347
+ ...itemRequirement
18348
+ });
18349
+ });
18350
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
18351
+ };
18352
+ const $aa6caea9a60d18c7$export$74fbc29ef48b4f31 = (itemRequirements)=>{
18353
+ const aggregatedMap = new Map();
18354
+ const aggregatedItemRequirements = [];
18355
+ itemRequirements.forEach((itemRequirement)=>{
18356
+ const { type: type } = itemRequirement;
18357
+ if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) {
18358
+ aggregatedItemRequirements.push(itemRequirement);
18359
+ return;
18360
+ }
18361
+ const { contractAddress: contractAddress, id: id } = itemRequirement;
18362
+ const key = `${contractAddress}${id}`;
18363
+ const aggregateItem = aggregatedMap.get(key);
18364
+ if (!aggregateItem) aggregatedMap.set(key, {
18365
+ ...itemRequirement
18366
+ });
18367
+ });
18368
+ return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
18369
+ };
18370
+ const $aa6caea9a60d18c7$export$f96d1c819a615a64 = (itemRequirements)=>$aa6caea9a60d18c7$export$74fbc29ef48b4f31($aa6caea9a60d18c7$export$b8de545554d50911($aa6caea9a60d18c7$export$f4d35754ad350071(itemRequirements)));
18371
+
18372
+
18373
+ /* eslint-disable arrow-body-style */
18374
+
18375
+ const $73d2282a108cc7e2$export$ed7929b58bab85da = (itemRequirements)=>itemRequirements.map((itemRequirement)=>{
18376
+ if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
18377
+ name: "IMX",
18378
+ symbol: "IMX",
18379
+ address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
18380
+ };
18381
+ return {
18382
+ name: itemRequirement.type,
18383
+ address: itemRequirement.contractAddress
18384
+ };
18385
+ });
18386
+ const $73d2282a108cc7e2$export$9b757e40b19984c3 = (itemRequirement, balances)=>{
18387
+ const requiredBalance = (BigNumber$1).from(1);
18388
+ // Find the requirements related balance
18389
+ const itemBalanceResult = balances.find((balance)=>{
18390
+ const balanceERC721Result = balance;
18391
+ return balanceERC721Result.contractAddress === itemRequirement.contractAddress && balanceERC721Result.id === itemRequirement.id;
18392
+ });
18393
+ // Calculate the balance delta
18394
+ const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
18395
+ const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (BigNumber$1).from(0));
18396
+ let erc721BalanceResult = itemBalanceResult;
18397
+ if (!erc721BalanceResult) erc721BalanceResult = {
18398
+ balance: (BigNumber$1).from(0),
18399
+ formattedBalance: "0",
18400
+ contractAddress: itemRequirement.contractAddress,
18401
+ id: itemRequirement.id
18402
+ };
18403
+ return {
18404
+ sufficient: sufficient,
18405
+ type: itemRequirement.type,
18406
+ delta: {
18407
+ balance: delta,
18408
+ formattedBalance: delta.toString()
18409
+ },
18410
+ current: erc721BalanceResult,
18411
+ required: {
18412
+ ...erc721BalanceResult,
18413
+ balance: (BigNumber$1).from(1),
18414
+ formattedBalance: "1"
18415
+ }
18416
+ };
18417
+ };
18418
+ const $73d2282a108cc7e2$export$6ab9757fda54db7e = (itemRequirement, balances)=>{
18419
+ let itemBalanceResult;
18420
+ // Get the requirements related balance
18421
+ if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) itemBalanceResult = balances.find((balance)=>{
18422
+ return balance.token?.address === itemRequirement.contractAddress;
18423
+ });
18424
+ else if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) itemBalanceResult = balances.find((balance)=>{
18425
+ return !("address" in balance.token) || balance.token?.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
18426
+ });
18427
+ // Calculate the balance delta
18428
+ const requiredBalance = itemRequirement.amount;
18429
+ const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
18430
+ const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (BigNumber$1).from(0));
18431
+ let decimals = ($d85ad1457a3f1a83$export$903389470ba9433c);
18432
+ if (itemBalanceResult) decimals = itemBalanceResult.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
18433
+ let tokenBalanceResult = itemBalanceResult;
18434
+ if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
18435
+ // No token balance so mark as zero native
18436
+ if (!tokenBalanceResult) tokenBalanceResult = {
18437
+ balance: (BigNumber$1).from(0),
18438
+ formattedBalance: "0",
18439
+ token: {
18440
+ name: "IMX",
18441
+ symbol: "IMX",
18442
+ decimals: ($d85ad1457a3f1a83$export$903389470ba9433c),
18443
+ address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
18444
+ }
18445
+ };
18446
+ return {
18447
+ sufficient: sufficient,
18448
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
18449
+ delta: {
18450
+ balance: delta,
18451
+ formattedBalance: (utils).formatUnits(delta, decimals)
18452
+ },
18453
+ current: tokenBalanceResult,
18454
+ required: {
18455
+ ...tokenBalanceResult,
18456
+ balance: (BigNumber$1).from(itemRequirement.amount),
18457
+ formattedBalance: (utils).formatUnits(itemRequirement.amount, decimals)
18458
+ }
18459
+ };
18460
+ }
18461
+ // No token balance so mark as zero
18462
+ if (!tokenBalanceResult) tokenBalanceResult = {
18463
+ balance: (BigNumber$1).from(0),
18464
+ formattedBalance: "0",
18465
+ token: {
18466
+ address: itemRequirement.contractAddress
18467
+ }
18468
+ };
18469
+ return {
18470
+ sufficient: sufficient,
18471
+ type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
18472
+ delta: {
18473
+ balance: delta,
18474
+ formattedBalance: (utils).formatUnits(delta, decimals)
18475
+ },
18476
+ current: tokenBalanceResult,
18477
+ required: {
18478
+ ...tokenBalanceResult,
18479
+ balance: (BigNumber$1).from(itemRequirement.amount),
18480
+ formattedBalance: (utils).formatUnits(itemRequirement.amount, decimals)
18481
+ }
18482
+ };
18483
+ };
18484
+
18485
+
18486
+ /**
18487
+ * Gets the balances for all NATIVE and ERC20 balance requirements.
18488
+ */ const $beb896e098e41faf$var$getTokenBalances = async (config, provider, ownerAddress, itemRequirements)=>{
18489
+ let tokenBalances = [];
18490
+ try {
18491
+ const tokenList = (0, $73d2282a108cc7e2$export$ed7929b58bab85da)(itemRequirements);
18492
+ const { balances: balances } = await (0, $1564e43dde50bb61$export$a3238cee431627c6)(config, provider, ownerAddress, tokenList);
18493
+ tokenBalances = [
18494
+ ...balances.map((balance)=>balance)
18495
+ ];
18496
+ } catch (error) {
18497
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR);
18498
+ }
18499
+ return tokenBalances;
18500
+ };
18501
+ /**
18502
+ * Gets the balances for all ERC721 balance requirements.
18503
+ */ const $beb896e098e41faf$var$getERC721Balances = async (provider, ownerAddress, itemRequirements)=>{
18504
+ const erc721Balances = [];
18505
+ // Setup maps to be able to link data back to the associated promises
18506
+ const erc721s = new Map();
18507
+ const erc721OwnershipPromises = new Map();
18508
+ itemRequirements.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721).forEach((itemRequirement)=>{
18509
+ const erc721Requirement = itemRequirement;
18510
+ const contract = new (Contract$1)(erc721Requirement.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
18511
+ erc721s.set(erc721Requirement.contractAddress, itemRequirement);
18512
+ erc721OwnershipPromises.set(erc721Requirement.contractAddress, contract.ownerOf(erc721Requirement.id));
18513
+ });
18514
+ try {
18515
+ // Convert ERC721 ownership into a balance result
18516
+ const erc721Owners = await Promise.all(erc721OwnershipPromises.values());
18517
+ const erc721OwnersPromiseIds = Array.from(erc721OwnershipPromises.keys());
18518
+ erc721Owners.forEach((erc721OwnerAddress, index)=>{
18519
+ const itemRequirement = erc721s.get(erc721OwnersPromiseIds[index]);
18520
+ let itemCount = 0;
18521
+ if (itemRequirement && ownerAddress === erc721OwnerAddress) itemCount = 1;
18522
+ erc721Balances.push({
18523
+ balance: (0, BigNumber$1).from(itemCount),
18524
+ formattedBalance: itemCount.toString(),
18525
+ contractAddress: itemRequirement.contractAddress,
18526
+ id: itemRequirement.id
18527
+ });
18528
+ });
18529
+ } catch (error) {
18530
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get ERC721 balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_BALANCE_ERROR);
18531
+ }
18532
+ return erc721Balances;
18533
+ };
18534
+ const $beb896e098e41faf$export$ddfc885f43c3cb6e = async (config, provider, ownerAddress, itemRequirements)=>{
18535
+ const aggregatedItems = ($aa6caea9a60d18c7$export$f96d1c819a615a64)(itemRequirements);
18536
+ if (aggregatedItems.filter((itemRequirement)=>{
18537
+ return itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18538
+ }).length > 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unsupported item requirement balance check", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
18539
+ // Get all ERC20 and NATIVE balances
18540
+ const currentBalances = [];
18541
+ const tokenItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 || itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
18542
+ if (tokenItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getTokenBalances(config, provider, ownerAddress, aggregatedItems));
18543
+ // Get all ERC721 balances
18544
+ const erc721ItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721);
18545
+ if (erc721ItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getERC721Balances(provider, ownerAddress, aggregatedItems));
18546
+ // Wait for all balances and calculate the requirements
18547
+ const balanceRequirements = await Promise.all(currentBalances).then((balances)=>{
18548
+ const requirements = [];
18549
+ if (balances.length > 1 || tokenItemRequirements.length > 0) {
18550
+ const tokenBalances = balances[0];
18551
+ tokenItemRequirements.forEach((tokenItemRequirement)=>{
18552
+ requirements.push(($73d2282a108cc7e2$export$6ab9757fda54db7e)(tokenItemRequirement, tokenBalances));
18553
+ });
18554
+ if (erc721ItemRequirements.length > 0) {
18555
+ const erc721Balances = balances[1];
18556
+ erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
18557
+ requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
18558
+ });
18559
+ }
18560
+ } else if (erc721ItemRequirements.length > 0) {
18561
+ // Only erc721
18562
+ const erc721Balances = balances[0];
18563
+ erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
18564
+ requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
18565
+ });
18566
+ }
18567
+ return requirements;
18568
+ });
18569
+ const sufficient = balanceRequirements.reduce((acc, balanceRequirement)=>{
18570
+ return acc && balanceRequirement.sufficient;
18571
+ }, true);
18572
+ return {
18573
+ sufficient: sufficient,
18574
+ itemRequirements: balanceRequirements
18575
+ };
18576
+ };
18577
+
18578
+
18579
+
18580
+
18187
18581
 
18188
18582
 
18189
18583
 
@@ -18240,7 +18634,7 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
18240
18634
  };
18241
18635
 
18242
18636
 
18243
- const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
18637
+ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (config, provider, itemRequirements, transactionOrGasAmount)=>{
18244
18638
  // eslint-disable-next-line no-console
18245
18639
  console.log(provider, itemRequirements, transactionOrGasAmount);
18246
18640
  const ownerAddress = await provider.getSigner().getAddress();
@@ -18259,6 +18653,9 @@ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequireme
18259
18653
  }
18260
18654
  // eslint-disable-next-line no-console
18261
18655
  console.log("Aggregated Items", aggregatedItems);
18656
+ const balanceRequirements = await ($beb896e098e41faf$export$ddfc885f43c3cb6e)(config, provider, ownerAddress, aggregatedItems);
18657
+ // eslint-disable-next-line no-console
18658
+ console.log("Balance Requirements", balanceRequirements);
18262
18659
  return {
18263
18660
  sufficient: true,
18264
18661
  transactionRequirements: [
@@ -18356,13 +18753,13 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18356
18753
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18357
18754
  let contractAddress = "";
18358
18755
  const buyArray = order.result.buy;
18359
- if (buyArray.length > 0) switch(buyArray[0].item_type){
18756
+ if (buyArray.length > 0) switch(buyArray[0].type){
18360
18757
  case "NATIVE":
18361
18758
  type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18362
18759
  break;
18363
18760
  case "ERC20":
18364
18761
  type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
18365
- contractAddress = buyArray[0].contract_address;
18762
+ contractAddress = buyArray[0].contractAddress;
18366
18763
  break;
18367
18764
  default:
18368
18765
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Purchasing token type is unsupported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_TOKEN_TYPE_ERROR, {
@@ -18370,7 +18767,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18370
18767
  });
18371
18768
  }
18372
18769
  buyArray.forEach((item)=>{
18373
- if (item.item_type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((BigNumber$1).from(item.start_amount));
18770
+ if (item.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((BigNumber$1).from(item.amount));
18374
18771
  });
18375
18772
  const feeArray = order.result.fees;
18376
18773
  feeArray.forEach((item)=>{
@@ -18379,7 +18776,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18379
18776
  const itemRequirements = [
18380
18777
  $64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
18381
18778
  ];
18382
- await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
18779
+ await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
18383
18780
  return {
18384
18781
  itemRequirements: itemRequirements,
18385
18782
  gasToken: {
@@ -18548,7 +18945,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
18548
18945
  // eslint-disable-next-line no-console
18549
18946
  console.warn("This endpoint is currently under construction.");
18550
18947
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
18551
- await $0e7419077c373b24$export$9e073f9ada8c81e6(web3Provider, params.itemRequirements, params.transactionOrGasAmount);
18948
+ await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
18552
18949
  }
18553
18950
  /**
18554
18951
  * Checks if the given object is a Web3 provider.
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha";
7
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha.2";
8
8
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
9
9
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
10
10
 
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.14.0-alpha',
19
+ sdkVersion: 'ts-immutable-sdk-0.14.0-alpha.2',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build