@imtbl/sdk 0.20.1 → 0.22.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.
@@ -16167,8 +16167,8 @@ var Fee;
16167
16167
  (function (Fee) {
16168
16168
  (function (fee_type) {
16169
16169
  fee_type["ROYALTY"] = "ROYALTY";
16170
- fee_type["MAKER_MARKETPLACE"] = "MAKER_MARKETPLACE";
16171
- fee_type["TAKER_MARKETPLACE"] = "TAKER_MARKETPLACE";
16170
+ fee_type["MAKER_ECOSYSTEM"] = "MAKER_ECOSYSTEM";
16171
+ fee_type["TAKER_ECOSYSTEM"] = "TAKER_ECOSYSTEM";
16172
16172
  fee_type["PROTOCOL"] = "PROTOCOL";
16173
16173
  })(Fee.fee_type || (Fee.fee_type = {}));
16174
16174
  })(Fee || (Fee = {}));
@@ -16201,8 +16201,8 @@ var ProtocolData;
16201
16201
 
16202
16202
  var FeeType;
16203
16203
  (function (FeeType) {
16204
- FeeType["MAKER_MARKETPLACE"] = "MAKER_MARKETPLACE";
16205
- FeeType["TAKER_MARKETPLACE"] = "TAKER_MARKETPLACE";
16204
+ FeeType["MAKER_ECOSYSTEM"] = "MAKER_ECOSYSTEM";
16205
+ FeeType["TAKER_ECOSYSTEM"] = "TAKER_ECOSYSTEM";
16206
16206
  FeeType["PROTOCOL"] = "PROTOCOL";
16207
16207
  FeeType["ROYALTY"] = "ROYALTY";
16208
16208
  })(FeeType || (FeeType = {}));
@@ -16259,8 +16259,8 @@ function mapFromOpenApiOrder(order) {
16259
16259
  type: fee.fee_type,
16260
16260
  })),
16261
16261
  chain: order.chain,
16262
- createTime: order.create_time,
16263
- endTime: order.end_time,
16262
+ createdAt: order.created_at,
16263
+ endAt: order.end_at,
16264
16264
  protocolData: {
16265
16265
  counter: order.protocol_data.counter,
16266
16266
  orderType: order.protocol_data.order_type,
@@ -16270,9 +16270,9 @@ function mapFromOpenApiOrder(order) {
16270
16270
  },
16271
16271
  salt: order.salt,
16272
16272
  signature: order.signature,
16273
- startTime: order.start_time,
16273
+ startAt: order.start_at,
16274
16274
  status: order.status,
16275
- updateTime: order.update_time,
16275
+ updatedAt: order.updated_at,
16276
16276
  };
16277
16277
  }
16278
16278
  function mapFromOpenApiTrade(trade) {
@@ -16475,8 +16475,8 @@ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress)
16475
16475
  };
16476
16476
  }),
16477
16477
  counter,
16478
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
16479
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
16478
+ endTime: Math.round(new Date(order.end_at).getTime() / 1000).toString(),
16479
+ startTime: Math.round(new Date(order.start_at).getTime() / 1000).toString(),
16480
16480
  salt: order.salt,
16481
16481
  offerer: order.account_address,
16482
16482
  zone: zoneAddress,
@@ -16704,10 +16704,10 @@ class ImmutableApiClient {
16704
16704
  ],
16705
16705
  fees: makerFees.map((x) => ({
16706
16706
  amount: x.amount,
16707
- fee_type: FeeType.MAKER_MARKETPLACE,
16707
+ fee_type: FeeType.MAKER_ECOSYSTEM,
16708
16708
  recipient: x.recipient,
16709
16709
  })),
16710
- end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
16710
+ end_at: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
16711
16711
  protocol_data: {
16712
16712
  order_type: ProtocolData.order_type.FULL_RESTRICTED,
16713
16713
  zone_address: orderComponents.zone,
@@ -16724,7 +16724,7 @@ class ImmutableApiClient {
16724
16724
  },
16725
16725
  ],
16726
16726
  signature: orderSignature,
16727
- start_time: new Date(parseInt(`${orderComponents.startTime.toString()}000`, 10)).toISOString(),
16727
+ start_at: new Date(parseInt(`${orderComponents.startTime.toString()}000`, 10)).toISOString(),
16728
16728
  },
16729
16729
  });
16730
16730
  }
@@ -16917,16 +16917,19 @@ class Orderbook {
16917
16917
  order_id: listingId,
16918
16918
  fees: takerFees.map((fee) => ({
16919
16919
  amount: fee.amount,
16920
- fee_type: FeeType.TAKER_MARKETPLACE,
16920
+ fee_type: FeeType.TAKER_ECOSYSTEM,
16921
16921
  recipient: fee.recipient,
16922
16922
  })),
16923
16923
  },
16924
16924
  ]);
16925
- if (fulfillmentDataRes.result.length !== 1) {
16926
- throw new Error('unexpected fulfillment data result length');
16925
+ if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
16926
+ throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
16927
16927
  }
16928
- const extraData = fulfillmentDataRes.result[0].extra_data;
16929
- const orderResult = fulfillmentDataRes.result[0].order;
16928
+ else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
16929
+ throw new Error('unexpected fulfillable order result length');
16930
+ }
16931
+ const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
16932
+ const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
16930
16933
  if (orderResult.status !== OrderStatus$1.ACTIVE) {
16931
16934
  throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
16932
16935
  }
@@ -17039,6 +17042,18 @@ const assertParamExists = function (functionName, paramName, paramValue) {
17039
17042
  throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
17040
17043
  }
17041
17044
  };
17045
+ /**
17046
+ *
17047
+ * @export
17048
+ */
17049
+ const setApiKeyToObject = async function (object, keyParamName, configuration) {
17050
+ if (configuration && configuration.apiKey) {
17051
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
17052
+ ? await configuration.apiKey(keyParamName)
17053
+ : await configuration.apiKey;
17054
+ object[keyParamName] = localVarApiKeyValue;
17055
+ }
17056
+ };
17042
17057
  /**
17043
17058
  *
17044
17059
  * @export
@@ -17588,6 +17603,46 @@ const CollectionsApiAxiosParamCreator = function (configuration) {
17588
17603
  options: localVarRequestOptions,
17589
17604
  };
17590
17605
  },
17606
+ /**
17607
+ * Refresh collection metadata
17608
+ * @summary Refresh collection metadata
17609
+ * @param {string} contractAddress The address contract
17610
+ * @param {string} chainName The name of chain
17611
+ * @param {RefreshCollectionMetadataRequest} refreshCollectionMetadataRequest The request body
17612
+ * @param {*} [options] Override http request option.
17613
+ * @throws {RequiredError}
17614
+ */
17615
+ refreshCollectionMetadata: async (contractAddress, chainName, refreshCollectionMetadataRequest, options = {}) => {
17616
+ // verify required parameter 'contractAddress' is not null or undefined
17617
+ assertParamExists('refreshCollectionMetadata', 'contractAddress', contractAddress);
17618
+ // verify required parameter 'chainName' is not null or undefined
17619
+ assertParamExists('refreshCollectionMetadata', 'chainName', chainName);
17620
+ // verify required parameter 'refreshCollectionMetadataRequest' is not null or undefined
17621
+ assertParamExists('refreshCollectionMetadata', 'refreshCollectionMetadataRequest', refreshCollectionMetadataRequest);
17622
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/refresh-metadata`
17623
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
17624
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
17625
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
17626
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
17627
+ let baseOptions;
17628
+ if (configuration) {
17629
+ baseOptions = configuration.baseOptions;
17630
+ }
17631
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
17632
+ const localVarHeaderParameter = {};
17633
+ const localVarQueryParameter = {};
17634
+ // authentication ImmutableApiKey required
17635
+ await setApiKeyToObject(localVarHeaderParameter, "X-Immutable-API-Key", configuration);
17636
+ localVarHeaderParameter['Content-Type'] = 'application/json';
17637
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
17638
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
17639
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
17640
+ localVarRequestOptions.data = serializeDataIfNeeded(refreshCollectionMetadataRequest, localVarRequestOptions, configuration);
17641
+ return {
17642
+ url: toPathString(localVarUrlObj),
17643
+ options: localVarRequestOptions,
17644
+ };
17645
+ },
17591
17646
  };
17592
17647
  };
17593
17648
  /**
@@ -17636,6 +17691,19 @@ const CollectionsApiFp = function (configuration) {
17636
17691
  const localVarAxiosArgs = await localVarAxiosParamCreator.listCollectionsByNFTOwner(accountAddress, chainName, pageCursor, pageSize, options);
17637
17692
  return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17638
17693
  },
17694
+ /**
17695
+ * Refresh collection metadata
17696
+ * @summary Refresh collection metadata
17697
+ * @param {string} contractAddress The address contract
17698
+ * @param {string} chainName The name of chain
17699
+ * @param {RefreshCollectionMetadataRequest} refreshCollectionMetadataRequest The request body
17700
+ * @param {*} [options] Override http request option.
17701
+ * @throws {RequiredError}
17702
+ */
17703
+ async refreshCollectionMetadata(contractAddress, chainName, refreshCollectionMetadataRequest, options) {
17704
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshCollectionMetadata(contractAddress, chainName, refreshCollectionMetadataRequest, options);
17705
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17706
+ },
17639
17707
  };
17640
17708
  };
17641
17709
  /**
@@ -17681,6 +17749,18 @@ const CollectionsApiFactory = function (configuration, basePath, axios) {
17681
17749
  listCollectionsByNFTOwner(accountAddress, chainName, pageCursor, pageSize, options) {
17682
17750
  return localVarFp.listCollectionsByNFTOwner(accountAddress, chainName, pageCursor, pageSize, options).then((request) => request(axios, basePath));
17683
17751
  },
17752
+ /**
17753
+ * Refresh collection metadata
17754
+ * @summary Refresh collection metadata
17755
+ * @param {string} contractAddress The address contract
17756
+ * @param {string} chainName The name of chain
17757
+ * @param {RefreshCollectionMetadataRequest} refreshCollectionMetadataRequest The request body
17758
+ * @param {*} [options] Override http request option.
17759
+ * @throws {RequiredError}
17760
+ */
17761
+ refreshCollectionMetadata(contractAddress, chainName, refreshCollectionMetadataRequest, options) {
17762
+ return localVarFp.refreshCollectionMetadata(contractAddress, chainName, refreshCollectionMetadataRequest, options).then((request) => request(axios, basePath));
17763
+ },
17684
17764
  };
17685
17765
  };
17686
17766
  /**
@@ -17723,6 +17803,210 @@ class CollectionsApi extends BaseAPI {
17723
17803
  listCollectionsByNFTOwner(requestParameters, options) {
17724
17804
  return CollectionsApiFp(this.configuration).listCollectionsByNFTOwner(requestParameters.accountAddress, requestParameters.chainName, requestParameters.pageCursor, requestParameters.pageSize, options).then((request) => request(this.axios, this.basePath));
17725
17805
  }
17806
+ /**
17807
+ * Refresh collection metadata
17808
+ * @summary Refresh collection metadata
17809
+ * @param {CollectionsApiRefreshCollectionMetadataRequest} requestParameters Request parameters.
17810
+ * @param {*} [options] Override http request option.
17811
+ * @throws {RequiredError}
17812
+ * @memberof CollectionsApi
17813
+ */
17814
+ refreshCollectionMetadata(requestParameters, options) {
17815
+ return CollectionsApiFp(this.configuration).refreshCollectionMetadata(requestParameters.contractAddress, requestParameters.chainName, requestParameters.refreshCollectionMetadataRequest, options).then((request) => request(this.axios, this.basePath));
17816
+ }
17817
+ }
17818
+
17819
+ /* tslint:disable */
17820
+ /* eslint-disable */
17821
+ /**
17822
+ * Immutable zkEVM API
17823
+ * Immutable Multi Rollup API
17824
+ *
17825
+ * The version of the OpenAPI document: 1.0.0
17826
+ * Contact: support@immutable.com
17827
+ *
17828
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
17829
+ * https://openapi-generator.tech
17830
+ * Do not edit the class manually.
17831
+ */
17832
+ /**
17833
+ * MetadataApi - axios parameter creator
17834
+ * @export
17835
+ */
17836
+ const MetadataApiAxiosParamCreator = function (configuration) {
17837
+ return {
17838
+ /**
17839
+ * Get a single metadata by ID
17840
+ * @summary Get a single metadata by ID
17841
+ * @param {string} chainName The name of chain
17842
+ * @param {string} contractAddress The address of metadata contract
17843
+ * @param {string} metadataId The id of the metadata
17844
+ * @param {*} [options] Override http request option.
17845
+ * @throws {RequiredError}
17846
+ */
17847
+ getMetadata: async (chainName, contractAddress, metadataId, options = {}) => {
17848
+ // verify required parameter 'chainName' is not null or undefined
17849
+ assertParamExists('getMetadata', 'chainName', chainName);
17850
+ // verify required parameter 'contractAddress' is not null or undefined
17851
+ assertParamExists('getMetadata', 'contractAddress', contractAddress);
17852
+ // verify required parameter 'metadataId' is not null or undefined
17853
+ assertParamExists('getMetadata', 'metadataId', metadataId);
17854
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/metadata/{metadata_id}`
17855
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)))
17856
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
17857
+ .replace(`{${"metadata_id"}}`, encodeURIComponent(String(metadataId)));
17858
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
17859
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
17860
+ let baseOptions;
17861
+ if (configuration) {
17862
+ baseOptions = configuration.baseOptions;
17863
+ }
17864
+ const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
17865
+ const localVarHeaderParameter = {};
17866
+ const localVarQueryParameter = {};
17867
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
17868
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
17869
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
17870
+ return {
17871
+ url: toPathString(localVarUrlObj),
17872
+ options: localVarRequestOptions,
17873
+ };
17874
+ },
17875
+ /**
17876
+ * Refresh shared metadata for a collection
17877
+ * @param {string} chainName The name of chain
17878
+ * @param {string} contractAddress Contract address
17879
+ * @param {RefreshMetadataByIDRequest} refreshMetadataByIDRequest NFT Metadata Refresh Request
17880
+ * @param {*} [options] Override http request option.
17881
+ * @throws {RequiredError}
17882
+ */
17883
+ refreshMetadataByID: async (chainName, contractAddress, refreshMetadataByIDRequest, options = {}) => {
17884
+ // verify required parameter 'chainName' is not null or undefined
17885
+ assertParamExists('refreshMetadataByID', 'chainName', chainName);
17886
+ // verify required parameter 'contractAddress' is not null or undefined
17887
+ assertParamExists('refreshMetadataByID', 'contractAddress', contractAddress);
17888
+ // verify required parameter 'refreshMetadataByIDRequest' is not null or undefined
17889
+ assertParamExists('refreshMetadataByID', 'refreshMetadataByIDRequest', refreshMetadataByIDRequest);
17890
+ const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/metadata/refresh-metadata`
17891
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)))
17892
+ .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)));
17893
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
17894
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
17895
+ let baseOptions;
17896
+ if (configuration) {
17897
+ baseOptions = configuration.baseOptions;
17898
+ }
17899
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
17900
+ const localVarHeaderParameter = {};
17901
+ const localVarQueryParameter = {};
17902
+ // authentication ImmutableApiKey required
17903
+ await setApiKeyToObject(localVarHeaderParameter, "X-Immutable-API-Key", configuration);
17904
+ localVarHeaderParameter['Content-Type'] = 'application/json';
17905
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
17906
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
17907
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
17908
+ localVarRequestOptions.data = serializeDataIfNeeded(refreshMetadataByIDRequest, localVarRequestOptions, configuration);
17909
+ return {
17910
+ url: toPathString(localVarUrlObj),
17911
+ options: localVarRequestOptions,
17912
+ };
17913
+ },
17914
+ };
17915
+ };
17916
+ /**
17917
+ * MetadataApi - functional programming interface
17918
+ * @export
17919
+ */
17920
+ const MetadataApiFp = function (configuration) {
17921
+ const localVarAxiosParamCreator = MetadataApiAxiosParamCreator(configuration);
17922
+ return {
17923
+ /**
17924
+ * Get a single metadata by ID
17925
+ * @summary Get a single metadata by ID
17926
+ * @param {string} chainName The name of chain
17927
+ * @param {string} contractAddress The address of metadata contract
17928
+ * @param {string} metadataId The id of the metadata
17929
+ * @param {*} [options] Override http request option.
17930
+ * @throws {RequiredError}
17931
+ */
17932
+ async getMetadata(chainName, contractAddress, metadataId, options) {
17933
+ const localVarAxiosArgs = await localVarAxiosParamCreator.getMetadata(chainName, contractAddress, metadataId, options);
17934
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17935
+ },
17936
+ /**
17937
+ * Refresh shared metadata for a collection
17938
+ * @param {string} chainName The name of chain
17939
+ * @param {string} contractAddress Contract address
17940
+ * @param {RefreshMetadataByIDRequest} refreshMetadataByIDRequest NFT Metadata Refresh Request
17941
+ * @param {*} [options] Override http request option.
17942
+ * @throws {RequiredError}
17943
+ */
17944
+ async refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options) {
17945
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options);
17946
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
17947
+ },
17948
+ };
17949
+ };
17950
+ /**
17951
+ * MetadataApi - factory interface
17952
+ * @export
17953
+ */
17954
+ const MetadataApiFactory = function (configuration, basePath, axios) {
17955
+ const localVarFp = MetadataApiFp(configuration);
17956
+ return {
17957
+ /**
17958
+ * Get a single metadata by ID
17959
+ * @summary Get a single metadata by ID
17960
+ * @param {string} chainName The name of chain
17961
+ * @param {string} contractAddress The address of metadata contract
17962
+ * @param {string} metadataId The id of the metadata
17963
+ * @param {*} [options] Override http request option.
17964
+ * @throws {RequiredError}
17965
+ */
17966
+ getMetadata(chainName, contractAddress, metadataId, options) {
17967
+ return localVarFp.getMetadata(chainName, contractAddress, metadataId, options).then((request) => request(axios, basePath));
17968
+ },
17969
+ /**
17970
+ * Refresh shared metadata for a collection
17971
+ * @param {string} chainName The name of chain
17972
+ * @param {string} contractAddress Contract address
17973
+ * @param {RefreshMetadataByIDRequest} refreshMetadataByIDRequest NFT Metadata Refresh Request
17974
+ * @param {*} [options] Override http request option.
17975
+ * @throws {RequiredError}
17976
+ */
17977
+ refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options) {
17978
+ return localVarFp.refreshMetadataByID(chainName, contractAddress, refreshMetadataByIDRequest, options).then((request) => request(axios, basePath));
17979
+ },
17980
+ };
17981
+ };
17982
+ /**
17983
+ * MetadataApi - object-oriented interface
17984
+ * @export
17985
+ * @class MetadataApi
17986
+ * @extends {BaseAPI}
17987
+ */
17988
+ class MetadataApi extends BaseAPI {
17989
+ /**
17990
+ * Get a single metadata by ID
17991
+ * @summary Get a single metadata by ID
17992
+ * @param {MetadataApiGetMetadataRequest} requestParameters Request parameters.
17993
+ * @param {*} [options] Override http request option.
17994
+ * @throws {RequiredError}
17995
+ * @memberof MetadataApi
17996
+ */
17997
+ getMetadata(requestParameters, options) {
17998
+ return MetadataApiFp(this.configuration).getMetadata(requestParameters.chainName, requestParameters.contractAddress, requestParameters.metadataId, options).then((request) => request(this.axios, this.basePath));
17999
+ }
18000
+ /**
18001
+ * Refresh shared metadata for a collection
18002
+ * @param {MetadataApiRefreshMetadataByIDRequest} requestParameters Request parameters.
18003
+ * @param {*} [options] Override http request option.
18004
+ * @throws {RequiredError}
18005
+ * @memberof MetadataApi
18006
+ */
18007
+ refreshMetadataByID(requestParameters, options) {
18008
+ return MetadataApiFp(this.configuration).refreshMetadataByID(requestParameters.chainName, requestParameters.contractAddress, requestParameters.refreshMetadataByIDRequest, options).then((request) => request(this.axios, this.basePath));
18009
+ }
17726
18010
  }
17727
18011
 
17728
18012
  /* tslint:disable */
@@ -18363,7 +18647,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
18363
18647
  * @param {string} chainName
18364
18648
  * @param {string} [accountAddress]
18365
18649
  * @param {number} [pageSize] Maximum number of trades to return per page
18366
- * @param {'created_at'} [sortBy] Trade field to sort by
18650
+ * @param {'indexed_at'} [sortBy] Trade field to sort by
18367
18651
  * @param {'asc' | 'desc'} [sortDirection] Ascending or descending direction for sort
18368
18652
  * @param {string} [pageCursor] Page cursor to retrieve previous or next page. Use the value returned in the response.
18369
18653
  * @param {*} [options] Override http request option.
@@ -18488,7 +18772,7 @@ const OrdersApiFp = function (configuration) {
18488
18772
  * @param {string} chainName
18489
18773
  * @param {string} [accountAddress]
18490
18774
  * @param {number} [pageSize] Maximum number of trades to return per page
18491
- * @param {'created_at'} [sortBy] Trade field to sort by
18775
+ * @param {'indexed_at'} [sortBy] Trade field to sort by
18492
18776
  * @param {'asc' | 'desc'} [sortDirection] Ascending or descending direction for sort
18493
18777
  * @param {string} [pageCursor] Page cursor to retrieve previous or next page. Use the value returned in the response.
18494
18778
  * @param {*} [options] Override http request option.
@@ -18575,7 +18859,7 @@ const OrdersApiFactory = function (configuration, basePath, axios) {
18575
18859
  * @param {string} chainName
18576
18860
  * @param {string} [accountAddress]
18577
18861
  * @param {number} [pageSize] Maximum number of trades to return per page
18578
- * @param {'created_at'} [sortBy] Trade field to sort by
18862
+ * @param {'indexed_at'} [sortBy] Trade field to sort by
18579
18863
  * @param {'asc' | 'desc'} [sortDirection] Ascending or descending direction for sort
18580
18864
  * @param {string} [pageCursor] Page cursor to retrieve previous or next page. Use the value returned in the response.
18581
18865
  * @param {*} [options] Override http request option.
@@ -19481,6 +19765,10 @@ var index = /*#__PURE__*/Object.freeze({
19481
19765
  ERC20ItemItemTypeEnum: ERC20ItemItemTypeEnum,
19482
19766
  ERC721ItemItemTypeEnum: ERC721ItemItemTypeEnum,
19483
19767
  FeeFeeTypeEnum: FeeFeeTypeEnum,
19768
+ MetadataApi: MetadataApi,
19769
+ MetadataApiAxiosParamCreator: MetadataApiAxiosParamCreator,
19770
+ MetadataApiFactory: MetadataApiFactory,
19771
+ MetadataApiFp: MetadataApiFp,
19484
19772
  NFTContractType: NFTContractType,
19485
19773
  NativeItemItemTypeEnum: NativeItemItemTypeEnum,
19486
19774
  NftOwnersApi: NftOwnersApi,
@@ -19528,7 +19816,7 @@ class APIError extends Error {
19528
19816
 
19529
19817
  /* eslint-disable implicit-arrow-linebreak */
19530
19818
  const defaultHeaders = {
19531
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.20.1',
19819
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.0-alpha.1',
19532
19820
  };
19533
19821
  /**
19534
19822
  * createAPIConfiguration to create a custom Configuration
@@ -20303,14 +20591,16 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
20303
20591
  CheckoutErrorType["CANCEL_ORDER_LISTING_ERROR"] = "CANCEL_ORDER_LISTING_ERROR";
20304
20592
  CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
20305
20593
  CheckoutErrorType["CREATE_ORDER_LISTING_ERROR"] = "CREATE_ORDER_LISTING_ERROR";
20594
+ CheckoutErrorType["FULFILL_ORDER_LISTING_ERROR"] = "FULFILL_ORDER_LISTING_ERROR";
20306
20595
  CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
20307
20596
  CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
20308
20597
  CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
20309
20598
  CheckoutErrorType["EXECUTE_APPROVAL_TRANSACTION_ERROR"] = "EXECUTE_APPROVAL_TRANSACTION_ERROR";
20310
- CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
20599
+ CheckoutErrorType["EXECUTE_FULFILLMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILLMENT_TRANSACTION_ERROR";
20311
20600
  CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
20312
20601
  CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
20313
20602
  CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
20603
+ CheckoutErrorType["ITEM_REQUIREMENTS_ERROR"] = "ITEM_REQUIREMENTS_ERROR";
20314
20604
  })($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
20315
20605
  class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
20316
20606
  message;
@@ -21164,6 +21454,12 @@ function $67fc622a2b913d5f$export$436dd76f23f463ff(config) {
21164
21454
 
21165
21455
 
21166
21456
 
21457
+ function $06a6c5c23f7f2479$export$fbbc17f6e6e58544(address, contractInterface, signerOrProvider) {
21458
+ return new (Contract$1)(address, contractInterface, signerOrProvider);
21459
+ }
21460
+
21461
+
21462
+
21167
21463
 
21168
21464
 
21169
21465
  const $2e7bf45a7c9a9570$var$DUMMY_WALLET_ADDRESS = "0x0000000000000000000000000000000000000001";
@@ -21891,7 +22187,7 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
21891
22187
  if (item.approvalTransaction === undefined) continue;
21892
22188
  estimateGasPromises.push($7d1bfafb81e64d74$export$e0580ae1f48db848(provider, item.approvalTransaction));
21893
22189
  }
21894
- // If the transaction is a fulfilment transaction get the estimate gas promise
22190
+ // If the transaction is a fulfillment transaction get the estimate gas promise
21895
22191
  // Otherwise use the gas amount with the limit to estimate the gas
21896
22192
  if (transactionOrGas.type === ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION) estimateGasPromises.push($7d1bfafb81e64d74$export$e0580ae1f48db848(provider, transactionOrGas.transaction));
21897
22193
  else {
@@ -21951,6 +22247,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
21951
22247
 
21952
22248
 
21953
22249
 
22250
+
21954
22251
  var $b23305044c0e096a$export$3057de18ac0c076;
21955
22252
  (function(RouteCalculatorType) {
21956
22253
  RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
@@ -22012,83 +22309,195 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
22012
22309
  };
22013
22310
 
22014
22311
 
22015
- /* eslint-disable @typescript-eslint/no-unused-vars */
22016
22312
 
22017
22313
 
22018
22314
 
22019
- const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
22020
- for (const balance of balances.balances){
22021
- if (!balance.token.address || balance.token.address === "") return balance.balance;
22022
- }
22023
- return (BigNumber$1).from(0);
22024
- };
22315
+
22316
+ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
22317
+ if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
22318
+ if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
22319
+ const readOnlyProviders = new Map();
22320
+ const allowedNetworks = await $de192de6ef100f9f$export$3043f6442a9ef563(config, {
22321
+ type: ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL
22322
+ });
22323
+ allowedNetworks.networks.forEach((networkInfo)=>{
22324
+ const rpcUrl = config.networkMap.get(networkInfo.chainId)?.rpcUrls[0];
22325
+ const provider = new (JsonRpcProvider)(rpcUrl);
22326
+ readOnlyProviders.set(networkInfo.chainId, provider);
22327
+ });
22328
+ return readOnlyProviders;
22329
+ }
22025
22330
 
22026
22331
 
22027
22332
 
22028
22333
 
22029
22334
 
22030
22335
 
22031
- const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
22336
+
22337
+
22338
+ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
22339
+ const dexQuotes = new Map();
22340
+ // Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
22341
+ const slippagePercent = 1;
22032
22342
  try {
22033
- const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
22034
- gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
22035
- isSpendingCapApprovalRequired: false
22036
- }, readOnlyProviders, config);
22037
- const gasEstimate = estimate.gasFee.estimatedAmount;
22038
- const bridgeFee = estimate.bridgeFee.estimatedAmount;
22039
- let totalFees = (0, BigNumber$1).from(0);
22040
- if (gasEstimate) totalFees = totalFees.add(gasEstimate);
22041
- if (bridgeFee) totalFees = totalFees.add(bridgeFee);
22042
- return totalFees;
22043
- } catch (err) {
22044
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
22045
- message: err.message
22343
+ const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
22344
+ const dexTransactionResponsePromises = [];
22345
+ // Create a quote for each swappable token
22346
+ for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
22347
+ // Resolve all the quotes and link them back to the swappable token
22348
+ // The swappable token array is in the same position in the array as the quote in the promise array
22349
+ const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
22350
+ dexTransactionResponse.forEach((response, index)=>{
22351
+ const swappableToken = swappableTokens[index];
22352
+ dexQuotes.set(swappableToken, {
22353
+ quote: response.quote,
22354
+ approval: response.approval?.gasFeeEstimate,
22355
+ swap: response.swap.gasFeeEstimate
22356
+ });
22046
22357
  });
22358
+ return dexQuotes;
22359
+ } catch {
22360
+ return dexQuotes;
22047
22361
  }
22048
22362
  };
22049
22363
 
22050
22364
 
22051
-
22052
- const $823db9fb0ca4bc15$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
22053
- const $823db9fb0ca4bc15$export$1430626eec86fce9 = (chainId)=>{
22054
- if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
22055
- return "";
22056
- };
22057
- const $823db9fb0ca4bc15$export$53e663abd9b77fc1 = (chainId)=>{
22058
- if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA) return "0x2Fa06C6672dDCc066Ab04631192738799231dE4a";
22059
- if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM) return "0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF";
22060
- return "";
22365
+ const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
22366
+ const dexQuotes = dexQuoteCache.get(requiredToken.address);
22367
+ if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
22368
+ const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
22369
+ dexQuoteCache.set(requiredToken.address, quotes);
22370
+ return quotes;
22061
22371
  };
22062
22372
 
22063
22373
 
22064
-
22065
-
22066
-
22067
-
22068
-
22069
- const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
22070
- try {
22071
- const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
22072
- const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
22073
- depositorAddress: depositorAddress,
22074
- token: token,
22075
- depositAmount: depositAmount
22076
- });
22077
- if (unsignedTx === null) return (0, BigNumber$1).from(0);
22078
- return await l1provider.estimateGas(unsignedTx);
22079
- } catch (err) {
22080
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
22081
- message: err.message
22082
- });
22374
+ const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
22375
+ let address = "";
22376
+ let amount = (BigNumber$1).from(0);
22377
+ switch(balanceRequirement.type){
22378
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
22379
+ address = balanceRequirement.required.token.address ?? "";
22380
+ amount = balanceRequirement.delta.balance;
22381
+ break;
22382
+ case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
22383
+ address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
22384
+ amount = balanceRequirement.delta.balance;
22385
+ break;
22083
22386
  }
22387
+ return {
22388
+ address: address,
22389
+ amount: amount
22390
+ };
22084
22391
  };
22085
- const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
22086
- if (l1Address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
22087
- const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
22088
- const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
22089
- return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
22392
+ const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
22393
+ // Check if approval required
22394
+ if (!approval) return {
22395
+ sufficient: true,
22396
+ approvalGasFee: (BigNumber$1).from(0),
22397
+ approvalGasTokenAddress: ""
22398
+ };
22399
+ const approvalGasFee = approval.value;
22400
+ const approvalGasTokenAddress = approval.token.address;
22401
+ // No balance on L2 to cover approval fees
22402
+ if (l2Balances.length === 0) return {
22403
+ sufficient: false,
22404
+ approvalGasFee: approvalGasFee,
22405
+ approvalGasTokenAddress: approvalGasTokenAddress
22406
+ };
22407
+ // Find the users balance of the approval token
22408
+ const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
22409
+ if (!l2BalanceOfApprovalToken) return {
22410
+ sufficient: false,
22411
+ approvalGasFee: approvalGasFee,
22412
+ approvalGasTokenAddress: approvalGasTokenAddress
22413
+ };
22414
+ // If the user does not have enough of the token to cover approval fees then return sufficient false
22415
+ if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
22416
+ sufficient: false,
22417
+ approvalGasFee: approvalGasFee,
22418
+ approvalGasTokenAddress: approvalGasTokenAddress
22419
+ };
22420
+ // The user has enough to cover approval gas fees
22421
+ return {
22422
+ sufficient: true,
22423
+ approvalGasFee: approvalGasFee,
22424
+ approvalGasTokenAddress: approvalGasTokenAddress
22425
+ };
22426
+ };
22427
+ const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
22428
+ // Set up a map of token addresses to amounts for each of the swap fees
22429
+ const feeMap = new Map();
22430
+ // Add the approval fee to list of fees
22431
+ if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
22432
+ // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
22433
+ if (tokenBeingSwapped) {
22434
+ const fee = feeMap.get(tokenBeingSwapped.address);
22435
+ if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
22436
+ else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
22437
+ }
22438
+ // Get all the fees and key them by their token id
22439
+ for (const swapFee of swapFees){
22440
+ const fee = feeMap.get(swapFee.amount.token.address);
22441
+ if (fee) {
22442
+ feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
22443
+ continue;
22444
+ }
22445
+ feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
22446
+ }
22447
+ // Go through the map and for each token address check if the user has enough balance to cover the fee
22448
+ for (const [tokenAddress, fee] of feeMap.entries()){
22449
+ if (fee === (BigNumber$1).from(0)) continue;
22450
+ const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
22451
+ if (!l2BalanceOfFeeToken) return false;
22452
+ if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
22453
+ }
22454
+ return true;
22455
+ };
22456
+ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
22457
+ const fundingSteps = [];
22458
+ if (!availableRoutingOptions.swap) return fundingSteps;
22459
+ if (swappableTokens.length === 0) return fundingSteps;
22460
+ const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
22461
+ if (requiredToken.address === "") return fundingSteps;
22462
+ const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22463
+ if (!l2TokenBalanceResult) return fundingSteps;
22464
+ const l2Balances = l2TokenBalanceResult.balances;
22465
+ if (l2Balances.length === 0) return fundingSteps;
22466
+ const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
22467
+ const quoteTokenAddresses = Array.from(quotes.keys());
22468
+ for (const quoteTokenAddress of quoteTokenAddresses){
22469
+ const quote = quotes.get(quoteTokenAddress);
22470
+ if (!quote) continue;
22471
+ // Find the balance the user has for this quoted token
22472
+ const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
22473
+ // If no balance found on L2 for this quoted token then continue
22474
+ if (!userBalanceOfQuotedToken) continue;
22475
+ // Check the amount of quoted token required against the user balance
22476
+ const amountOfQuoteTokenRequired = quote.quote.amount;
22477
+ // If user does not have enough balance to perform the swap with this token then continue
22478
+ if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
22479
+ const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
22480
+ // If user does not have enough to cover approval fees then continue
22481
+ if (!approvalFees.sufficient) continue;
22482
+ // If user does not have enough to cover swap fees then continue
22483
+ if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
22484
+ amount: amountOfQuoteTokenRequired.value,
22485
+ address: quoteTokenAddress
22486
+ })) continue;
22487
+ // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
22488
+ // Currently we are not prioritising any particular token so just taking the first sufficient token
22489
+ fundingSteps.push({
22490
+ type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
22491
+ chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
22492
+ asset: {
22493
+ balance: userBalanceOfQuotedToken.balance,
22494
+ formattedBalance: userBalanceOfQuotedToken.formattedBalance,
22495
+ token: userBalanceOfQuotedToken.token
22496
+ }
22497
+ });
22498
+ }
22499
+ return fundingSteps;
22090
22500
  };
22091
-
22092
22501
 
22093
22502
 
22094
22503
 
@@ -22136,29 +22545,122 @@ const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances,
22136
22545
  };
22137
22546
 
22138
22547
 
22139
- const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
22140
- const balance = ($f730af3b727f04ac$export$22fea095b15361de)(balances);
22141
- return balance.gte(totalFees);
22548
+
22549
+
22550
+
22551
+
22552
+
22553
+
22554
+
22555
+ const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
22556
+ for (const balance of balances.balances){
22557
+ if (!balance.token.address || balance.token.address === "") return balance.balance;
22558
+ }
22559
+ return (BigNumber$1).from(0);
22560
+ };
22561
+
22562
+
22563
+
22564
+
22565
+
22566
+
22567
+ const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
22568
+ try {
22569
+ const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
22570
+ gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
22571
+ isSpendingCapApprovalRequired: false
22572
+ }, readOnlyProviders, config);
22573
+ const gasEstimate = estimate.gasFee.estimatedAmount;
22574
+ const bridgeFee = estimate.bridgeFee.estimatedAmount;
22575
+ let totalFees = (0, BigNumber$1).from(0);
22576
+ if (gasEstimate) totalFees = totalFees.add(gasEstimate);
22577
+ if (bridgeFee) totalFees = totalFees.add(bridgeFee);
22578
+ return totalFees;
22579
+ } catch (err) {
22580
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
22581
+ message: err.message
22582
+ });
22583
+ }
22142
22584
  };
22143
- const $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f = (balanceRequirement)=>{
22144
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return $d85ad1457a3f1a83$export$b80040cb173ba6e9;
22145
- if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return balanceRequirement.required.token.address ?? "";
22585
+
22586
+
22587
+
22588
+
22589
+
22590
+
22591
+
22592
+
22593
+
22594
+ const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
22595
+ const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
22596
+ if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
22146
22597
  return "";
22147
22598
  };
22148
- const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirement)=>{
22149
- const l2address = $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f(balanceRequirement);
22150
- if (l2address === "") return "";
22151
- if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return ($823db9fb0ca4bc15$export$53e663abd9b77fc1)(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
22152
- const chainName = ($823db9fb0ca4bc15$export$1430626eec86fce9)(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22153
- if (chainName === "") return ""; // Chain name not a valid indexer chain name
22599
+ const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
22600
+ const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
22601
+ return imxMappingConfig[chainId] ?? "";
22602
+ };
22603
+ const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
22604
+ if (l2address === "") return {
22605
+ l1address: "",
22606
+ l2address: l2address
22607
+ };
22608
+ if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
22609
+ l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
22610
+ l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
22611
+ };
22612
+ const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22613
+ if (chainName === "") return {
22614
+ l1address: "",
22615
+ l2address: l2address
22616
+ }; // Chain name not a valid indexer chain name
22154
22617
  const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
22155
22618
  const tokenData = await blockchainData.getToken({
22156
22619
  chainName: chainName,
22157
22620
  contractAddress: l2address
22158
22621
  });
22159
22622
  const l1address = tokenData.result.root_contract_address;
22160
- if (l1address === null) return ""; // No L1 representation of this token
22161
- return l1address;
22623
+ if (l1address === null) return {
22624
+ l1address: "",
22625
+ l2address: l2address
22626
+ }; // No L1 representation of this token
22627
+ return {
22628
+ l1address: l1address,
22629
+ l2address: l2address
22630
+ };
22631
+ };
22632
+
22633
+
22634
+ const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
22635
+ try {
22636
+ const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
22637
+ const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
22638
+ depositorAddress: depositorAddress,
22639
+ token: token,
22640
+ depositAmount: depositAmount
22641
+ });
22642
+ if (unsignedTx === null) return (0, BigNumber$1).from(0);
22643
+ return await l1provider.estimateGas(unsignedTx);
22644
+ } catch (err) {
22645
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
22646
+ message: err.message
22647
+ });
22648
+ }
22649
+ };
22650
+ const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
22651
+ if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
22652
+ const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
22653
+ const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
22654
+ return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
22655
+ };
22656
+
22657
+
22658
+
22659
+
22660
+
22661
+ const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
22662
+ const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
22663
+ return balance.gte(totalFees);
22162
22664
  };
22163
22665
  const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
22164
22666
  let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
@@ -22185,230 +22687,319 @@ const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
22185
22687
  if (!address || address === "") return true;
22186
22688
  return false;
22187
22689
  };
22188
- const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, balanceRequirement, balances, feeEstimates)=>{
22690
+ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
22189
22691
  if (!availableRoutingOptions.bridge) return undefined;
22692
+ if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
22190
22693
  const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
22191
- const tokenBalanceResult = balances.get(chainId);
22694
+ const tokenBalanceResult = tokenBalanceResults.get(chainId);
22192
22695
  const l1provider = readOnlyProviders.get(chainId);
22193
22696
  if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
22194
22697
  chainId: chainId.toString()
22195
22698
  });
22196
22699
  // If no balances on layer 1 then Bridge cannot be an option
22197
22700
  if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
22198
- const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, balances, availableRoutingOptions);
22701
+ const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
22199
22702
  if (allowedTokenList.length === 0) return undefined;
22200
22703
  const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
22201
22704
  // If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
22202
22705
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
22203
- const l1address = await $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6(config, balanceRequirement);
22706
+ const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
22707
+ // No mapping on L1 for this token
22708
+ const { l1address: l1address } = l1RepresentationResult;
22204
22709
  if (l1address === "") return undefined;
22205
22710
  // Ensure l1address is in the allowed token list
22206
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
22711
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
22207
22712
  if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
22208
22713
  } else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
22209
- const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, balanceRequirement.delta.balance);
22714
+ const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
22210
22715
  if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
22211
22716
  // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
22212
- if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
22717
+ if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
22213
22718
  const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
22214
- if (nativeETHBalance && nativeETHBalance.balance.gte(balanceRequirement.delta.balance.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
22719
+ if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
22215
22720
  return undefined;
22216
22721
  }
22217
22722
  // Find the balance of the L1 representation of the token and check if the balance covers the delta
22218
22723
  const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
22219
- if (erc20balance && erc20balance.balance.gte(balanceRequirement.delta.balance)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
22724
+ if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
22220
22725
  return undefined;
22221
22726
  };
22222
22727
 
22223
22728
 
22224
22729
 
22225
22730
 
22226
-
22227
-
22228
- async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
22229
- if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
22230
- if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
22231
- const readOnlyProviders = new Map();
22232
- const allowedNetworks = await $de192de6ef100f9f$export$3043f6442a9ef563(config, {
22233
- type: ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL
22234
- });
22235
- allowedNetworks.networks.forEach((networkInfo)=>{
22236
- const rpcUrl = config.networkMap.get(networkInfo.chainId)?.rpcUrls[0];
22237
- const provider = new (JsonRpcProvider)(rpcUrl);
22238
- readOnlyProviders.set(networkInfo.chainId, provider);
22239
- });
22240
- return readOnlyProviders;
22241
- }
22242
-
22243
-
22244
-
22245
-
22246
-
22247
-
22248
-
22249
-
22250
- const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
22251
- const dexQuotes = new Map();
22252
- try {
22253
- const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
22254
- const dexTransactionResponsePromises = [];
22255
- // Create a quote for each swappable token
22256
- for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
22257
- // Resolve all the quotes and link them back to the swappable token
22258
- // The swappable token array is in the same position in the array as the quote in the promise array
22259
- const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
22260
- dexTransactionResponse.forEach((response, index)=>{
22261
- const swappableToken = swappableTokens[index];
22262
- dexQuotes.set(swappableToken, {
22263
- quote: response.quote,
22264
- approval: response.approval?.gasFeeEstimate,
22265
- swap: response.swap.gasFeeEstimate
22266
- });
22267
- });
22268
- return dexQuotes;
22269
- } catch {
22270
- return dexQuotes;
22271
- }
22272
- };
22273
-
22274
-
22275
- const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
22276
- const dexQuotes = dexQuoteCache.get(requiredToken.address);
22277
- if (dexQuotes) return dexQuotes;
22278
- const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
22279
- dexQuoteCache.set(requiredToken.address, quotes);
22280
- return quotes;
22281
- };
22282
-
22283
-
22284
- const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
22285
- let address = "";
22286
- let amount = (BigNumber$1).from(0);
22287
- switch(balanceRequirement.type){
22288
- case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
22289
- address = balanceRequirement.required.token.address ?? "";
22290
- amount = balanceRequirement.delta.balance;
22291
- break;
22292
- case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
22293
- address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
22294
- amount = balanceRequirement.delta.balance;
22295
- break;
22296
- }
22297
- return {
22298
- address: address,
22299
- amount: amount
22300
- };
22301
- };
22302
- const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
22303
- // Check if approval required
22304
- if (!approval) return {
22305
- sufficient: true,
22306
- approvalGasFee: (BigNumber$1).from(0),
22307
- approvalGasTokenAddress: ""
22308
- };
22309
- const approvalGasFee = approval.value;
22310
- const approvalGasTokenAddress = approval.token.address;
22311
- // No balance on L2 to cover approval fees
22312
- if (l2Balances.length === 0) return {
22313
- sufficient: false,
22314
- approvalGasFee: approvalGasFee,
22315
- approvalGasTokenAddress: approvalGasTokenAddress
22316
- };
22317
- // Find the users balance of the approval token
22318
- const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
22319
- if (!l2BalanceOfApprovalToken) return {
22320
- sufficient: false,
22321
- approvalGasFee: approvalGasFee,
22322
- approvalGasTokenAddress: approvalGasTokenAddress
22323
- };
22324
- // If the user does not have enough of the token to cover approval fees then return sufficient false
22325
- if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
22326
- sufficient: false,
22327
- approvalGasFee: approvalGasFee,
22328
- approvalGasTokenAddress: approvalGasTokenAddress
22731
+ const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
22732
+ const balances = {
22733
+ l1balances: [],
22734
+ l2balances: []
22329
22735
  };
22330
- // The user has enough to cover approval gas fees
22736
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
22737
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22738
+ // If there are no l1 balance then cannot bridge
22739
+ if (!l1balancesResult) return balances;
22740
+ if (l1balancesResult.error !== undefined) return balances;
22741
+ if (!l1balancesResult.success) return balances;
22742
+ // If there are no l2 balance then cannot swap
22743
+ if (!l2balancesResult) return balances;
22744
+ if (l2balancesResult.error !== undefined) return balances;
22745
+ if (!l2balancesResult.success) return balances;
22746
+ const l1balances = l1balancesResult.balances;
22747
+ const l2balances = l2balancesResult.balances;
22331
22748
  return {
22332
- sufficient: true,
22333
- approvalGasFee: approvalGasFee,
22334
- approvalGasTokenAddress: approvalGasTokenAddress
22749
+ l1balances: l1balances,
22750
+ l2balances: l2balances
22335
22751
  };
22336
22752
  };
22337
- const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
22338
- // Set up a map of token addresses to amounts for each of the swap fees
22339
- const feeMap = new Map();
22340
- // Add the approval fee to list of fees
22341
- if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
22342
- // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
22343
- if (tokenBeingSwapped) {
22344
- const fee = feeMap.get(tokenBeingSwapped.address);
22345
- if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
22346
- else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
22753
+
22754
+
22755
+
22756
+
22757
+
22758
+ const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
22759
+ let fees = (BigNumber$1).from(0);
22760
+ dexQuote.quote.fees.forEach((fee)=>{
22761
+ if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
22762
+ });
22763
+ if (dexQuote.approval) {
22764
+ if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
22347
22765
  }
22348
- // Get all the fees and key them by their token id
22349
- for (const swapFee of swapFees){
22350
- const fee = feeMap.get(swapFee.amount.token.address);
22351
- if (fee) {
22352
- feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
22353
- continue;
22766
+ return fees;
22767
+ };
22768
+ // The token that is being bridged may also be a balance requirement
22769
+ // Since this token is going to be swapped after bridging then get the
22770
+ // balance requirement amount so this can be considered when bridging
22771
+ // enough of the token across
22772
+ const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
22773
+ let amount = (BigNumber$1).from(0);
22774
+ balanceRequirements.balanceRequirements.forEach((requirement)=>{
22775
+ if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
22776
+ if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
22354
22777
  }
22355
- feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
22356
- }
22357
- // Go through the map and for each token address check if the user has enough balance to cover the fee
22358
- for (const [tokenAddress, fee] of feeMap.entries()){
22359
- if (fee === (BigNumber$1).from(0)) continue;
22360
- const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
22361
- if (!l2BalanceOfFeeToken) return false;
22362
- if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
22778
+ });
22779
+ return amount;
22780
+ };
22781
+ const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
22782
+ const bridgeRequirements = [];
22783
+ for (const [tokenAddress, quote] of dexQuotes){
22784
+ // Get the L2 balance for the token address
22785
+ const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
22786
+ const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
22787
+ if (!l1tol2TokenMapping) continue;
22788
+ const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
22789
+ if (!l1address) continue;
22790
+ // If the user does not have any L1 balance for this token then cannot bridge
22791
+ const l1balance = l1balances.find((balance)=>{
22792
+ if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
22793
+ return balance.token.address === l1address;
22794
+ });
22795
+ if (!l1balance) continue;
22796
+ // Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
22797
+ const quotedAmount = quote.quote.amountWithMaxSlippage.value;
22798
+ // Add fees to the quoted amount if the fees are in the same token as the token being swapped
22799
+ const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
22800
+ // If the token being bridged is a balance requirement then add this to the total
22801
+ // to ensure when its swapped the balance requirement can still be fulfilled
22802
+ const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
22803
+ // Add all the amounts together
22804
+ const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
22805
+ // Subtract any L2 balance from the total amount to only bridge the necessary amount
22806
+ const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
22807
+ if (amountToBridge.lte(0)) continue;
22808
+ if (amountToBridge.gt(l1balance.balance)) continue;
22809
+ bridgeRequirements.push({
22810
+ amount: amountToBridge,
22811
+ formattedAmount: (utils).formatUnits(amountToBridge, l1balance.token.decimals),
22812
+ l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
22813
+ l2address
22814
+ });
22363
22815
  }
22364
- return true;
22816
+ return bridgeRequirements;
22365
22817
  };
22366
- const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
22367
- if (!availableRoutingOptions.swap) return undefined;
22368
- if (swappableTokens.length === 0) return undefined;
22369
- const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
22370
- if (requiredToken.address === "") return undefined;
22371
- const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22372
- if (!l2TokenBalanceResult) return undefined;
22373
- const l2Balances = l2TokenBalanceResult.balances;
22374
- if (l2Balances.length === 0) return undefined;
22375
- const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
22376
- const quoteTokenAddresses = Array.from(quotes.keys());
22377
- for (const quoteTokenAddress of quoteTokenAddresses){
22378
- const quote = quotes.get(quoteTokenAddress);
22379
- if (!quote) continue;
22380
- // Find the balance the user has for this quoted token
22381
- const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
22382
- // If no balance found on L2 for this quoted token then continue
22383
- if (!userBalanceOfQuotedToken) continue;
22384
- // Check the amount of quoted token required against the user balance
22385
- const amountOfQuoteTokenRequired = quote.quote.amount;
22386
- // If user does not have enough balance to perform the swap with this token then continue
22387
- if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
22388
- const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
22389
- // If user does not have enough to cover approval fees then continue
22390
- if (!approvalFees.sufficient) continue;
22391
- // If user does not have enough to cover swap fees then continue
22392
- if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
22393
- amount: amountOfQuoteTokenRequired.value,
22394
- address: quoteTokenAddress
22395
- })) continue;
22396
- // User has sufficient funds to cover any approval and swap fees so use this token for the funding route
22397
- // Currently we are not prioritising any particular token so just taking the first sufficient token
22398
- return {
22399
- type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
22400
- chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
22401
- asset: {
22402
- balance: userBalanceOfQuotedToken.balance,
22403
- formattedBalance: userBalanceOfQuotedToken.formattedBalance,
22404
- token: userBalanceOfQuotedToken.token
22405
- }
22406
- };
22818
+
22819
+
22820
+
22821
+ const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
22822
+ const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
22823
+ return await Promise.all(l1tol2addressMappingPromises);
22824
+ };
22825
+
22826
+
22827
+
22828
+
22829
+ const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
22830
+ const filteredSwappableTokensAddresses = [];
22831
+ for (const token of filteredSwappableTokens){
22832
+ if (!token.address) continue;
22833
+ filteredSwappableTokensAddresses.push(token.address);
22407
22834
  }
22408
- return undefined;
22835
+ const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
22836
+ address: requiredTokenAddress,
22837
+ amount: insufficientRequirement.delta.balance
22838
+ }, filteredSwappableTokensAddresses);
22839
+ return dexQuotes;
22409
22840
  };
22410
22841
 
22411
22842
 
22843
+ const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
22844
+ if (bridgeableTokens.length === 0) return true;
22845
+ if (swappableTokens.length === 0) return true;
22846
+ if (l1balances.length === 0) return true;
22847
+ if (l2balances.length === 0) return true;
22848
+ if (!availableRoutingOptions.bridge) return true;
22849
+ if (!availableRoutingOptions.swap) return true;
22850
+ if (requiredTokenAddress === undefined) return true;
22851
+ if (requiredTokenAddress === "") return true;
22852
+ return false;
22853
+ };
22854
+ const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
22855
+ const filteredSwappableTokens = [];
22856
+ for (const addresses of l1tol2Addresses){
22857
+ if (addresses.l1address === "") continue;
22858
+ if (addresses.l2address === "") continue;
22859
+ if (!bridgeableTokens.includes(addresses.l1address)) continue;
22860
+ // Filter out the token that is required from the swappable tokens list
22861
+ if (addresses.l2address === requiredTokenAddress) continue;
22862
+ const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
22863
+ if (!tokenInfo) continue;
22864
+ filteredSwappableTokens.push(tokenInfo);
22865
+ }
22866
+ return filteredSwappableTokens;
22867
+ };
22868
+ // Modifies a users balance to include the amount as if the user successfully bridged
22869
+ // This is so the swap route can check against the balance once the user has performed a bridge
22870
+ const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
22871
+ const modifiedTokenBalances = new Map();
22872
+ for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
22873
+ success: tokenBalance.success,
22874
+ balances: tokenBalance.balances
22875
+ });
22876
+ // Construct a map of balances to the L2 token address to make
22877
+ // it easier to adjust the balances for the tokens that can be bridged
22878
+ const balanceMap = new Map();
22879
+ for (const balance of l2balances){
22880
+ if (!balance.token.address) continue;
22881
+ balanceMap.set(balance.token.address, balance);
22882
+ }
22883
+ // Go through each of the tokens that can be bridged
22884
+ // and adjust the balances to fake the bridge
22885
+ for (const bridgedToken of bridgedTokens){
22886
+ const { amount: amount, l2address: l2address } = bridgedToken;
22887
+ if (l2address === "") continue;
22888
+ let l2balance = (BigNumber$1).from(0);
22889
+ // Find the current balance of this token
22890
+ const currentBalance = balanceMap.get(l2address);
22891
+ if (currentBalance) l2balance = currentBalance.balance;
22892
+ const newBalance = l2balance.add(amount);
22893
+ const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
22894
+ balanceMap.set(l2address, {
22895
+ balance: newBalance,
22896
+ formattedBalance: (utils).formatUnits(newBalance, tokenInfo.decimals),
22897
+ token: tokenInfo
22898
+ });
22899
+ }
22900
+ const updatedBalances = Array.from(balanceMap.values());
22901
+ modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
22902
+ success: true,
22903
+ balances: updatedBalances
22904
+ });
22905
+ return modifiedTokenBalances;
22906
+ };
22907
+ const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
22908
+ const originalSwapSteps = [];
22909
+ for (const route of swapRoutes){
22910
+ const { chainId: chainId, asset: asset } = route;
22911
+ const tokenBalance = tokenBalances.get(chainId);
22912
+ if (!tokenBalance) continue;
22913
+ let originalBalance = (BigNumber$1).from(0);
22914
+ let originalFormattedBalance = "0";
22915
+ const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
22916
+ if (l2balance) {
22917
+ originalBalance = l2balance.balance;
22918
+ originalFormattedBalance = l2balance.formattedBalance;
22919
+ }
22920
+ route.asset.balance = originalBalance;
22921
+ route.asset.formattedBalance = originalFormattedBalance;
22922
+ originalSwapSteps.push(route);
22923
+ }
22924
+ return originalSwapSteps;
22925
+ };
22926
+ const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
22927
+ const bridgeAndSwapRoutes = [];
22928
+ for (const bridgeFundingStep of bridgeFundingSteps){
22929
+ if (!bridgeFundingStep) continue;
22930
+ const mapping = l1tol2Addresses.find((addresses)=>{
22931
+ if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
22932
+ return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
22933
+ });
22934
+ if (!mapping) continue;
22935
+ const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
22936
+ if (!swapFundingStep) continue;
22937
+ bridgeAndSwapRoutes.push({
22938
+ bridgeFundingStep: bridgeFundingStep,
22939
+ swapFundingStep: swapFundingStep
22940
+ });
22941
+ }
22942
+ return bridgeAndSwapRoutes;
22943
+ };
22944
+ const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
22945
+ const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
22946
+ const requiredTokenAddress = insufficientRequirement.required.token.address;
22947
+ if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
22948
+ // Fetch L2 to L1 address mapping and based on the L1 address existing then
22949
+ // filter the bridgeable and swappable tokens list further to only include
22950
+ // tokens that can be both swapped and bridged
22951
+ const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
22952
+ const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
22953
+ if (filteredSwappableTokens.length === 0) return [];
22954
+ // Fetch all the dex quotes from the list of swappable tokens
22955
+ const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
22956
+ // Construct bridge requirements based on L2 balances, slippage and swap fees
22957
+ const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
22958
+ if (bridgeRequirements.length === 0) return [];
22959
+ // Create a mapping of bridge routes to L2 addresses
22960
+ const bridgePromises = new Map();
22961
+ // Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
22962
+ const bridgeableRequirementsMap = new Map();
22963
+ const bridgedTokens = [];
22964
+ for (const bridgeRequirement of bridgeRequirements){
22965
+ if (!bridgeRequirement.l2address) continue;
22966
+ bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
22967
+ bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
22968
+ amount: bridgeRequirement.amount,
22969
+ formattedAmount: bridgeRequirement.formattedAmount,
22970
+ l2address: bridgeRequirement.l2address
22971
+ });
22972
+ }
22973
+ const bridgeResults = await Promise.all(bridgePromises.values());
22974
+ const bridgeKeys = Array.from(bridgePromises.keys());
22975
+ // Create an array to store all the tokens that are able to be bridged
22976
+ const swappableTokensAfterBridging = [];
22977
+ // Iterate through all the bridge route results
22978
+ // If a bridge route result was successful then add this token to the
22979
+ // list of tokens that should be checked with the swap route
22980
+ bridgeResults.forEach((result, index)=>{
22981
+ const key = bridgeKeys[index];
22982
+ if (result === undefined) return;
22983
+ swappableTokensAfterBridging.push(key);
22984
+ const bridgedToken = bridgeableRequirementsMap.get(key);
22985
+ if (!bridgedToken) return;
22986
+ bridgedTokens.push({
22987
+ amount: bridgedToken.amount,
22988
+ formattedAmount: bridgedToken.formattedAmount,
22989
+ l2address: bridgedToken.l2address
22990
+ });
22991
+ });
22992
+ // Bridge route determined that no tokens could be bridged
22993
+ if (swappableTokensAfterBridging.length === 0) return [];
22994
+ if (bridgedTokens.length === 0) return []; // No tokens were bridged
22995
+ // Modify the users L2 balance to include the amount as if the user successfully bridged
22996
+ const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
22997
+ // Call the swap route with the faked bridged balances
22998
+ const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
22999
+ if (!swapRoutes) return [];
23000
+ const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
23001
+ return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
23002
+ };
22412
23003
 
22413
23004
 
22414
23005
 
@@ -22440,6 +23031,8 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
22440
23031
 
22441
23032
 
22442
23033
 
23034
+
23035
+ const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
22443
23036
  const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
22444
23037
  let insufficientBalanceCount = 0;
22445
23038
  let insufficientRequirement;
@@ -22450,18 +23043,51 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
22450
23043
  if (insufficientBalanceCount === 1) return insufficientRequirement;
22451
23044
  return undefined;
22452
23045
  };
22453
- const $c16168a9c28ae4fd$export$c39a7b7dc167cdb4 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
22454
- if (!availableRoutingOptions.swap) return undefined;
23046
+ const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
23047
+ let bridgeFundingStep;
22455
23048
  if (insufficientRequirement === undefined) return undefined;
22456
- if (swapTokenAllowList === undefined) return undefined;
23049
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
23050
+ const bridgeRequirement = {
23051
+ amount: insufficientRequirement.delta.balance,
23052
+ formattedAmount: insufficientRequirement.delta.formattedBalance,
23053
+ l2address: insufficientRequirement.required.token.address ?? ""
23054
+ };
23055
+ if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
23056
+ return bridgeFundingStep;
23057
+ };
23058
+ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
23059
+ const fundingSteps = [];
23060
+ if (!availableRoutingOptions.swap) return fundingSteps;
23061
+ if (insufficientRequirement === undefined) return fundingSteps;
23062
+ if (swapTokenAllowList === undefined) return fundingSteps;
22457
23063
  const tokenBalanceResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
22458
- if (!tokenBalanceResult) return undefined;
22459
- if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return undefined;
22460
- if (swapTokenAllowList.length === 0) return undefined;
23064
+ if (!tokenBalanceResult) return fundingSteps;
23065
+ if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return fundingSteps;
23066
+ if (swapTokenAllowList.length === 0) return fundingSteps;
22461
23067
  const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
22462
- if (swappableTokens.length === 0) return undefined;
22463
- const swapFundingStep = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
22464
- return swapFundingStep;
23068
+ if (swappableTokens.length === 0) return fundingSteps;
23069
+ return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
23070
+ };
23071
+ const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
23072
+ if (!insufficientRequirement) return [];
23073
+ const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
23074
+ const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
23075
+ // If there are no l1 balance then cannot bridge
23076
+ if (!l1balancesResult) return [];
23077
+ if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
23078
+ // If there are no l2 balance then cannot swap
23079
+ if (!l2balancesResult) return [];
23080
+ if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
23081
+ // Get a list of all the swappable tokens
23082
+ const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
23083
+ const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
23084
+ if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
23085
+ return token.address;
23086
+ });
23087
+ const swapTokenAllowList = tokenAllowList?.swap ?? [];
23088
+ if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
23089
+ const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
23090
+ return routes;
22465
23091
  };
22466
23092
  const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
22467
23093
  if (!availableRoutingOptions.onRamp) return undefined;
@@ -22470,6 +23096,13 @@ const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutin
22470
23096
  return onRampFundingStep;
22471
23097
  };
22472
23098
  const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
23099
+ if (!$c16168a9c28ae4fd$var$hasAvailableRoutingOptions(availableRoutingOptions)) return {
23100
+ response: {
23101
+ type: ($b23305044c0e096a$export$3057de18ac0c076).NO_OPTIONS,
23102
+ message: "No options available"
23103
+ },
23104
+ fundingRoutes: []
23105
+ };
22473
23106
  let readOnlyProviders;
22474
23107
  try {
22475
23108
  readOnlyProviders = await (0, $0e0060cb42e136d2$export$339cb2be73677b30)(config);
@@ -22484,16 +23117,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
22484
23117
  const feeEstimates = new Map();
22485
23118
  // Dex quotes cache
22486
23119
  const dexQuoteCache = new Map();
22487
- // Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
23120
+ // Ensures only 1 balance requirement is insufficient
22488
23121
  const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
23122
+ const routePromises = [];
23123
+ routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
23124
+ routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
23125
+ routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
23126
+ routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
23127
+ const resolved = await Promise.all(routePromises);
22489
23128
  let bridgeFundingStep;
22490
- if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
22491
- const swapFundingStep = await $c16168a9c28ae4fd$export$c39a7b7dc167cdb4(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
22492
- const onRampFundingStep = await $c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement);
22493
- // Check swap routes
22494
- // > Could bridge first
22495
- // > Could on-ramp first
22496
- // > Could double swap
23129
+ let swapFundingSteps = [];
23130
+ let onRampFundingStep;
23131
+ let bridgeAndSwapFundingSteps = [];
23132
+ resolved.forEach((result, index)=>{
23133
+ if (index === 0) bridgeFundingStep = result;
23134
+ if (index === 1) swapFundingSteps = result;
23135
+ if (index === 2) onRampFundingStep = result;
23136
+ if (index === 3) bridgeAndSwapFundingSteps = result;
23137
+ });
22497
23138
  const response = {
22498
23139
  response: {
22499
23140
  type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
@@ -22502,7 +23143,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
22502
23143
  fundingRoutes: []
22503
23144
  };
22504
23145
  let priority = 0;
22505
- if (bridgeFundingStep || swapFundingStep || onRampFundingStep) {
23146
+ if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
22506
23147
  response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
22507
23148
  response.response.message = "Routes found";
22508
23149
  }
@@ -22515,13 +23156,15 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
22515
23156
  ]
22516
23157
  });
22517
23158
  }
22518
- if (swapFundingStep) {
23159
+ if (swapFundingSteps.length > 0) {
22519
23160
  priority++;
22520
- response.fundingRoutes.push({
22521
- priority: priority,
22522
- steps: [
22523
- swapFundingStep
22524
- ]
23161
+ swapFundingSteps.forEach((swapFundingStep)=>{
23162
+ response.fundingRoutes.push({
23163
+ priority: priority,
23164
+ steps: [
23165
+ swapFundingStep
23166
+ ]
23167
+ });
22525
23168
  });
22526
23169
  }
22527
23170
  if (onRampFundingStep) {
@@ -22533,6 +23176,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
22533
23176
  ]
22534
23177
  });
22535
23178
  }
23179
+ if (bridgeAndSwapFundingSteps) {
23180
+ priority++;
23181
+ bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
23182
+ const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
23183
+ const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
23184
+ response.fundingRoutes.push({
23185
+ priority: priority,
23186
+ steps: [
23187
+ bridgeStep,
23188
+ swapStep
23189
+ ]
23190
+ });
23191
+ });
23192
+ }
23193
+ // eslint-disable-next-line no-console
23194
+ console.log("** response", response);
22536
23195
  return response;
22537
23196
  };
22538
23197
 
@@ -22606,13 +23265,13 @@ const $25ac589234c10b67$export$19693ca396db083e = async (provider, approvalTrans
22606
23265
  type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).SUCCESS
22607
23266
  };
22608
23267
  };
22609
- const $25ac589234c10b67$export$2161274619257102 = async (provider, fulfilmentTransactions)=>{
23268
+ const $25ac589234c10b67$export$3f05b33bd1f29038 = async (provider, fulfillmentTransactions)=>{
22610
23269
  let receipts = [];
22611
23270
  try {
22612
- const response = await Promise.all(fulfilmentTransactions.map((transaction)=>provider.getSigner().sendTransaction(transaction)));
23271
+ const response = await Promise.all(fulfillmentTransactions.map((transaction)=>provider.getSigner().sendTransaction(transaction)));
22613
23272
  receipts = await Promise.all(response.map((transaction)=>transaction.wait()));
22614
23273
  } catch (err) {
22615
- throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while executing the fulfilment transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).EXECUTE_FULFILMENT_TRANSACTION_ERROR, {
23274
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while executing the fulfillment transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
22616
23275
  message: err.message
22617
23276
  });
22618
23277
  }
@@ -22620,7 +23279,7 @@ const $25ac589234c10b67$export$2161274619257102 = async (provider, fulfilmentTra
22620
23279
  if (receipt.status === 0) return {
22621
23280
  type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED,
22622
23281
  transactionHash: receipt.transactionHash,
22623
- reason: "Fulfilment transaction failed and was reverted"
23282
+ reason: "Fulfillment transaction failed and was reverted"
22624
23283
  };
22625
23284
  }
22626
23285
  return {
@@ -22645,23 +23304,43 @@ const $25ac589234c10b67$export$1d9a7a8a40780de = async (provider, unsignedMessag
22645
23304
 
22646
23305
 
22647
23306
 
22648
- const $a7367d01c6e76b1c$export$b087719c36e0f2dc = async (actions)=>{
23307
+ const $a7367d01c6e76b1c$export$c5b3365853cb6159 = async (actions)=>{
22649
23308
  let approvalTransactions = [];
22650
- let fulfilmentTransactions = [];
23309
+ let fulfillmentTransactions = [];
22651
23310
  const approvalPromises = [];
22652
- const fulfilmentPromises = [];
23311
+ const fulfillmentPromises = [];
22653
23312
  for (const action of actions){
22654
23313
  if (action.type !== (ActionType).TRANSACTION) continue;
22655
23314
  if (action.purpose === (TransactionPurpose).APPROVAL) approvalPromises.push(action.buildTransaction());
22656
- if (action.purpose === (TransactionPurpose).FULFILL_ORDER) fulfilmentPromises.push(action.buildTransaction());
23315
+ if (action.purpose === (TransactionPurpose).FULFILL_ORDER) fulfillmentPromises.push(action.buildTransaction());
22657
23316
  }
22658
23317
  approvalTransactions = await Promise.all(approvalPromises);
22659
- fulfilmentTransactions = await Promise.all(fulfilmentPromises);
23318
+ fulfillmentTransactions = await Promise.all(fulfillmentPromises);
22660
23319
  return {
22661
23320
  approvalTransactions: approvalTransactions,
22662
- fulfilmentTransactions: fulfilmentTransactions
23321
+ fulfillmentTransactions: fulfillmentTransactions
22663
23322
  };
22664
23323
  };
23324
+ const $a7367d01c6e76b1c$export$f64a20a30eb98855 = async (actions)=>{
23325
+ let approvalTransactions = [];
23326
+ const approvalPromises = [];
23327
+ for (const action of actions){
23328
+ if (action.type !== (ActionType).TRANSACTION) continue;
23329
+ if (action.purpose === (TransactionPurpose).APPROVAL) approvalPromises.push(action.buildTransaction());
23330
+ }
23331
+ approvalTransactions = await Promise.all(approvalPromises);
23332
+ return approvalTransactions;
23333
+ };
23334
+ const $a7367d01c6e76b1c$export$396bd6ce7d3ab533 = async (actions)=>{
23335
+ let fulfillmentTransactions = [];
23336
+ const fulfillmentPromises = [];
23337
+ for (const action of actions){
23338
+ if (action.type !== (ActionType).TRANSACTION) continue;
23339
+ if (action.purpose === (TransactionPurpose).FULFILL_ORDER) fulfillmentPromises.push(action.buildTransaction());
23340
+ }
23341
+ fulfillmentTransactions = await Promise.all(fulfillmentPromises);
23342
+ return fulfillmentTransactions;
23343
+ };
22665
23344
  const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, actions)=>{
22666
23345
  let unsignedMessage;
22667
23346
  for (const action of actions){
@@ -22684,6 +23363,49 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
22684
23363
 
22685
23364
 
22686
23365
 
23366
+
23367
+
23368
+
23369
+
23370
+ const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
23371
+ const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
23372
+ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
23373
+ const feePercentage = orderFee.amount;
23374
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
23375
+ const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
23376
+ const bnFeeAmount = amountBn.mul((BigNumber$1).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
23377
+ return bnFeeAmount;
23378
+ };
23379
+ const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
23380
+ const feeToken = orderFee.amount;
23381
+ const bnFeeAmount = (parseUnits)(feeToken.token, decimals);
23382
+ return bnFeeAmount;
23383
+ };
23384
+ const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
23385
+ let totalTokenFees = (BigNumber$1).from(0);
23386
+ const amountBn = (BigNumber$1).from(weiAmount);
23387
+ // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
23388
+ const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
23389
+ const calculateFeesResult = [];
23390
+ for (const orderFee of orderFees){
23391
+ let currentFeeBn = (BigNumber$1).from(0);
23392
+ if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
23393
+ currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
23394
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
23395
+ } else if (Object.hasOwn(orderFee.amount, "token")) {
23396
+ currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
23397
+ totalTokenFees = totalTokenFees.add(currentFeeBn);
23398
+ } else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
23399
+ if (totalTokenFees.gt(totalAllowableFees)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`The combined fees are above the allowed maximum of ${$9051cee080948594$export$9ac1563efd38130 * 100}%`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
23400
+ if (currentFeeBn.gt(0)) calculateFeesResult.push({
23401
+ amount: currentFeeBn.toString(),
23402
+ recipient: orderFee.recipient
23403
+ });
23404
+ } // for
23405
+ return calculateFeesResult;
23406
+ };
23407
+
23408
+
22687
23409
  const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
22688
23410
  switch(type){
22689
23411
  case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
@@ -22701,10 +23423,10 @@ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount
22701
23423
  };
22702
23424
  }
22703
23425
  };
22704
- const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, unsignedTransactions)=>{
22705
- if (unsignedTransactions.fulfilmentTransactions.length > 0) return {
23426
+ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, fulfillmentTransactions)=>{
23427
+ if (fulfillmentTransactions.length > 0) return {
22706
23428
  type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
22707
- transaction: unsignedTransactions.fulfilmentTransactions[0]
23429
+ transaction: fulfillmentTransactions[0]
22708
23430
  };
22709
23431
  return {
22710
23432
  type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
@@ -22714,34 +23436,54 @@ const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, unsignedTransaction
22714
23436
  }
22715
23437
  };
22716
23438
  };
22717
- const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orderId)=>{
23439
+ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, orders)=>{
22718
23440
  let orderbook;
22719
23441
  let order;
22720
23442
  let spenderAddress = "";
22721
23443
  const gasLimit = (constants).estimatedFulfillmentGasGwei;
23444
+ if (orders.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orders were passed in, must pass at least one order", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).FULFILL_ORDER_LISTING_ERROR);
23445
+ const { id: id, takerFees: takerFees } = orders[0];
22722
23446
  try {
22723
23447
  orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
22724
- order = await orderbook.getListing(orderId);
23448
+ order = await orderbook.getListing(id);
22725
23449
  const { seaportContractAddress: seaportContractAddress } = orderbook.config();
22726
23450
  spenderAddress = seaportContractAddress;
22727
23451
  } catch (err) {
22728
23452
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while getting the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
22729
- orderId: orderId,
23453
+ orderId: id,
22730
23454
  message: err.message
22731
23455
  });
22732
23456
  }
22733
- let unsignedTransactions = {
22734
- approvalTransactions: [],
22735
- fulfilmentTransactions: []
22736
- };
23457
+ if (order.result.buy.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred with the get order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ORDER_LISTING_ERROR, {
23458
+ orderId: id,
23459
+ message: "No buy side tokens found on order"
23460
+ });
23461
+ const buyToken = order.result.buy[0];
23462
+ let decimals = 18;
23463
+ if (order.result.buy[0].type === "ERC20") {
23464
+ const tokenContract = $06a6c5c23f7f2479$export$fbbc17f6e6e58544(order.result.buy[0].contractAddress, ($d85ad1457a3f1a83$export$db5daa1b5156ccfe), provider);
23465
+ decimals = await tokenContract.decimals();
23466
+ }
23467
+ let fees = [];
23468
+ if (takerFees && takerFees.length > 0) fees = ($9051cee080948594$export$1e69c9cfc42e28d8)(takerFees, buyToken.amount, decimals);
23469
+ let unsignedApprovalTransactions = [];
23470
+ let unsignedFulfillmentTransactions = [];
23471
+ let orderActions = [];
22737
23472
  try {
22738
23473
  const fulfillerAddress = await provider.getSigner().getAddress();
22739
- const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress, []);
22740
- unsignedTransactions = await (0, $a7367d01c6e76b1c$export$b087719c36e0f2dc)(actions);
23474
+ const { actions: actions } = await orderbook.fulfillOrder(id, fulfillerAddress, fees);
23475
+ orderActions = actions;
23476
+ unsignedApprovalTransactions = await (0, $a7367d01c6e76b1c$export$f64a20a30eb98855)(actions);
22741
23477
  } catch {
22742
23478
  // Silently ignore error as this is usually thrown if user does not have enough balance
22743
23479
  // todo: if balance error - can we determine if its the balance error otherwise throw?
22744
23480
  }
23481
+ try {
23482
+ unsignedFulfillmentTransactions = await (0, $a7367d01c6e76b1c$export$396bd6ce7d3ab533)(orderActions);
23483
+ } catch {
23484
+ // if cannot estimate gas then silently continue and use gas limit in smartCheckout
23485
+ // but get the fulfillment transactions after they have approved the spending
23486
+ }
22745
23487
  let amount = (BigNumber$1).from("0");
22746
23488
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
22747
23489
  let contractAddress = "";
@@ -22756,7 +23498,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
22756
23498
  break;
22757
23499
  default:
22758
23500
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Purchasing token type is unsupported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_TOKEN_TYPE_ERROR, {
22759
- orderId: orderId
23501
+ orderId: id
22760
23502
  });
22761
23503
  }
22762
23504
  buyArray.forEach((item)=>{
@@ -22769,31 +23511,38 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
22769
23511
  const itemRequirements = [
22770
23512
  $64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
22771
23513
  ];
22772
- const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransactions));
23514
+ const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedFulfillmentTransactions));
22773
23515
  if (smartCheckoutResult.sufficient) {
22774
- const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
23516
+ const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedApprovalTransactions);
22775
23517
  if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
22776
23518
  smartCheckoutResult: smartCheckoutResult,
22777
- orderId: orderId,
23519
+ orderId: id,
22778
23520
  status: {
22779
23521
  type: ($aa144554f9ef124b$export$226b052ecb8ca80).FAILED,
22780
23522
  transactionHash: approvalResult.transactionHash,
22781
23523
  reason: approvalResult.reason
22782
23524
  }
22783
23525
  };
22784
- const fulfilmentResult = await ($25ac589234c10b67$export$2161274619257102)(provider, unsignedTransactions.fulfilmentTransactions);
22785
- if (fulfilmentResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
23526
+ try {
23527
+ if (unsignedFulfillmentTransactions.length === 0) unsignedFulfillmentTransactions = await (0, $a7367d01c6e76b1c$export$396bd6ce7d3ab533)(orderActions);
23528
+ } catch (err) {
23529
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error fetching fulfillment transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).FULFILL_ORDER_LISTING_ERROR, {
23530
+ message: err.message
23531
+ });
23532
+ }
23533
+ const fulfillmentResult = await ($25ac589234c10b67$export$3f05b33bd1f29038)(provider, unsignedFulfillmentTransactions);
23534
+ if (fulfillmentResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
22786
23535
  smartCheckoutResult: smartCheckoutResult,
22787
- orderId: orderId,
23536
+ orderId: id,
22788
23537
  status: {
22789
23538
  type: ($aa144554f9ef124b$export$226b052ecb8ca80).FAILED,
22790
- transactionHash: fulfilmentResult.transactionHash,
22791
- reason: fulfilmentResult.reason
23539
+ transactionHash: fulfillmentResult.transactionHash,
23540
+ reason: fulfillmentResult.reason
22792
23541
  }
22793
23542
  };
22794
23543
  return {
22795
23544
  smartCheckoutResult: smartCheckoutResult,
22796
- orderId: orderId,
23545
+ orderId: id,
22797
23546
  status: {
22798
23547
  type: ($aa144554f9ef124b$export$226b052ecb8ca80).SUCCESS
22799
23548
  }
@@ -22801,7 +23550,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
22801
23550
  }
22802
23551
  return {
22803
23552
  smartCheckoutResult: smartCheckoutResult,
22804
- orderId: orderId
23553
+ orderId: id
22805
23554
  };
22806
23555
  };
22807
23556
 
@@ -22813,8 +23562,11 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
22813
23562
 
22814
23563
 
22815
23564
 
22816
- const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, orderId)=>{
23565
+ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, orderIds)=>{
22817
23566
  let unsignedCancelOrderTransaction;
23567
+ if (orderIds.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orderIds were passed in, must pass at least one orderId to cancel", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CANCEL_ORDER_LISTING_ERROR);
23568
+ // Update this when bulk cancel is supproted
23569
+ const orderId = orderIds[0];
22818
23570
  try {
22819
23571
  const offererAddress = await provider.getSigner().getAddress();
22820
23572
  const orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
@@ -22826,7 +23578,7 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
22826
23578
  message: err.message
22827
23579
  });
22828
23580
  }
22829
- const result = await ($25ac589234c10b67$export$2161274619257102)(provider, [
23581
+ const result = await ($25ac589234c10b67$export$3f05b33bd1f29038)(provider, [
22830
23582
  unsignedCancelOrderTransaction
22831
23583
  ]);
22832
23584
  if (result.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
@@ -22859,47 +23611,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
22859
23611
 
22860
23612
 
22861
23613
 
22862
-
22863
-
22864
- const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
22865
- const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
22866
- const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
22867
- const feePercentage = orderFee.amount;
22868
- // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
22869
- const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
22870
- const bnFeeAmount = amountBn.mul((BigNumber$1).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
22871
- return bnFeeAmount;
22872
- };
22873
- const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
22874
- const feeToken = orderFee.amount;
22875
- const bnFeeAmount = (parseUnits)(feeToken.token, decimals);
22876
- return bnFeeAmount;
22877
- };
22878
- const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
22879
- let totalTokenFees = (BigNumber$1).from(0);
22880
- const amountBn = (BigNumber$1).from(weiAmount);
22881
- // note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
22882
- const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
22883
- const calculateFeesResult = [];
22884
- for (const orderFee of orderFees){
22885
- let currentFeeBn = (BigNumber$1).from(0);
22886
- if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
22887
- currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
22888
- totalTokenFees = totalTokenFees.add(currentFeeBn);
22889
- } else if (Object.hasOwn(orderFee.amount, "token")) {
22890
- currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
22891
- totalTokenFees = totalTokenFees.add(currentFeeBn);
22892
- } else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
22893
- if (totalTokenFees.gt(totalAllowableFees)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`The combined fees are above the allowed maximum of ${$9051cee080948594$export$9ac1563efd38130 * 100}%`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
22894
- if (currentFeeBn.gt(0)) calculateFeesResult.push({
22895
- amount: currentFeeBn.toString(),
22896
- recipient: orderFee.recipient
22897
- });
22898
- } // for
22899
- return calculateFeesResult;
22900
- };
22901
-
22902
-
22903
23614
  const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
22904
23615
  type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
22905
23616
  id: id,
@@ -22928,7 +23639,7 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, order
22928
23639
  if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
22929
23640
  // get this from the allowed list
22930
23641
  const buyTokenContract = new (Contract$1)(buyToken.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
22931
- decimals = buyTokenContract.decimals();
23642
+ decimals = await buyTokenContract.decimals();
22932
23643
  }
22933
23644
  const buyTokenOrNative = $9085b221b72ac69e$export$586d02673c66d423(buyToken, decimals);
22934
23645
  try {
@@ -22971,7 +23682,7 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, order
22971
23682
  collectionAddress: sellToken.collectionAddress
22972
23683
  });
22973
23684
  const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
22974
- const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
23685
+ const unsignedTransactions = await ($a7367d01c6e76b1c$export$c5b3365853cb6159)(listing.actions);
22975
23686
  const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
22976
23687
  if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
22977
23688
  id: sellToken.id,
@@ -23071,6 +23782,38 @@ class $a77d203f701a3b72$export$1453e9b801542ef4 {
23071
23782
 
23072
23783
 
23073
23784
 
23785
+
23786
+
23787
+
23788
+ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements) {
23789
+ // Get all decimal values by calling contracts for each ERC20
23790
+ const decimalPromises = [];
23791
+ requirements.forEach((itemRequirementParam)=>{
23792
+ if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
23793
+ const { contractAddress: contractAddress } = itemRequirementParam;
23794
+ decimalPromises.push(($06a6c5c23f7f2479$export$fbbc17f6e6e58544)(contractAddress, ($d85ad1457a3f1a83$export$db5daa1b5156ccfe), provider).decimals());
23795
+ }
23796
+ });
23797
+ const decimals = await Promise.all(decimalPromises);
23798
+ // Map ItemRequirementsParam objects to ItemRequirement by parsing amounts from formatted string to BigNumebrs
23799
+ const itemRequirements = requirements.map((itemRequirementParam, index)=>{
23800
+ if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
23801
+ ...itemRequirementParam,
23802
+ amount: (parseUnits)(itemRequirementParam.amount, 18)
23803
+ };
23804
+ if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
23805
+ ...itemRequirementParam,
23806
+ amount: (parseUnits)(itemRequirementParam.amount, decimals[index])
23807
+ };
23808
+ return itemRequirementParam;
23809
+ });
23810
+ return itemRequirements;
23811
+ }
23812
+
23813
+
23814
+
23815
+
23816
+
23074
23817
  const $a8cb37a3fc8eb863$var$SANDBOX_CONFIGURATION = {
23075
23818
  baseConfig: {
23076
23819
  environment: (Environment$1).SANDBOX
@@ -23197,8 +23940,10 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
23197
23940
  if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
23198
23941
  // eslint-disable-next-line no-console
23199
23942
  console.warn("This endpoint is currently under construction.");
23943
+ if (params.orders.length > 1) // eslint-disable-next-line no-console
23944
+ console.warn("This endpoint currently only actions the first order in the array.");
23200
23945
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
23201
- await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
23946
+ await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orders);
23202
23947
  }
23203
23948
  /**
23204
23949
  * Determines the requirements for performing a sell.
@@ -23221,8 +23966,10 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
23221
23966
  if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
23222
23967
  // eslint-disable-next-line no-console
23223
23968
  console.warn("This endpoint is currently under construction.");
23969
+ // eslint-disable-next-line no-console
23970
+ console.warn("This endpoint currently only actions the first order in the array.");
23224
23971
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
23225
- await $9c3db1bb9c8b69d3$export$70b61ad426ddbe54(this.config, web3Provider, params.orderId);
23972
+ await $9c3db1bb9c8b69d3$export$70b61ad426ddbe54(this.config, web3Provider, params.orderIds);
23226
23973
  }
23227
23974
  /**
23228
23975
  * Determines the transaction requirements to complete a purchase.
@@ -23232,8 +23979,13 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
23232
23979
  // eslint-disable-next-line no-console
23233
23980
  console.warn("This endpoint is currently under construction.");
23234
23981
  const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
23235
- // console.log('Smart Checkout Params ::', params);
23236
- await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
23982
+ let itemRequirements = [];
23983
+ try {
23984
+ itemRequirements = await (0, $d35036efee31c5d1$export$dc8635800ef20f4b)(web3Provider, params.itemRequirements);
23985
+ } catch {
23986
+ throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to map item requirements", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ITEM_REQUIREMENTS_ERROR);
23987
+ }
23988
+ await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
23237
23989
  }
23238
23990
  /**
23239
23991
  * Checks if the given object is a Web3 provider.