@imtbl/sdk 0.44.0 → 0.44.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10641,7 +10641,7 @@ class MultiRollupApiClients {
10641
10641
  }
10642
10642
 
10643
10643
  // eslint-disable-next-line @typescript-eslint/naming-convention
10644
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.44.0' };
10644
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.44.2' };
10645
10645
  const createConfig = ({ basePath, headers, }) => {
10646
10646
  if (!basePath.trim()) {
10647
10647
  throw Error('basePath can not be empty');
@@ -10713,7 +10713,7 @@ class APIError extends Error {
10713
10713
 
10714
10714
  /* eslint-disable implicit-arrow-linebreak */
10715
10715
  const defaultHeaders = {
10716
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.0',
10716
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.2',
10717
10717
  };
10718
10718
  /**
10719
10719
  * createAPIConfiguration to create a custom Configuration
@@ -11152,7 +11152,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11152
11152
  chainID,
11153
11153
  coreContractAddress,
11154
11154
  registrationContractAddress,
11155
- sdkVersion: 'ts-immutable-sdk-0.44.0',
11155
+ sdkVersion: 'ts-immutable-sdk-0.44.2',
11156
11156
  });
11157
11157
  /**
11158
11158
  * Sets `sdkVersion` at the time of build
@@ -17303,27 +17303,43 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
17303
17303
  const types = { ...typedData.types };
17304
17304
  // @ts-ignore
17305
17305
  delete types.EIP712Domain;
17306
- // eslint-disable-next-line no-underscore-dangle
17307
- const digest = ethers.ethers.utils._TypedDataEncoder.hash(typedData.domain, types, typedData.message);
17308
- const completePayload = encodeMessageSubDigest(chainId, walletAddress, digest);
17309
- const hash = ethers.ethers.utils.keccak256(completePayload);
17310
- // Sign the digest
17306
+ // Hash the EIP712 payload and generate the complete payload
17307
+ const { _TypedDataEncoder: typedDataEncoder } = ethers.ethers.utils;
17308
+ const typedDataHash = typedDataEncoder.hash(typedData.domain, types, typedData.message);
17309
+ const messageSubDigest = encodeMessageSubDigest(chainId, walletAddress, typedDataHash);
17310
+ const hash = ethers.ethers.utils.keccak256(messageSubDigest);
17311
+ // Sign the sub digest
17312
+ // https://github.com/immutable/wallet-contracts/blob/7824b5f24b2e0eb2dc465ecb5cd71f3984556b73/src/contracts/modules/commons/ModuleAuth.sol#L155
17311
17313
  const hashArray = ethers.ethers.utils.arrayify(hash);
17312
17314
  const ethsigNoType = await signer.signMessage(hashArray);
17313
17315
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
17314
- const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
17316
+ // Combine the relayer and user signatures; sort by address to match the imageHash order
17317
+ const { signers: relayerSigners } = decodeRelayerTypedDataSignature(relayerSignature);
17318
+ const combinedSigners = [
17319
+ ...relayerSigners,
17320
+ {
17321
+ isDynamic: false,
17322
+ unrecovered: true,
17323
+ weight: SIGNATURE_WEIGHT,
17324
+ signature: signedDigest,
17325
+ address: await signer.getAddress(),
17326
+ },
17327
+ ];
17328
+ const sortedSigners = combinedSigners.sort((a, b) => {
17329
+ const bigA = ethers.BigNumber.from(a.address);
17330
+ const bigB = ethers.BigNumber.from(b.address);
17331
+ if (bigA.lte(bigB)) {
17332
+ return -1;
17333
+ }
17334
+ if (bigA.eq(bigB)) {
17335
+ return 0;
17336
+ }
17337
+ return 1;
17338
+ });
17315
17339
  return core.v1.signature.encodeSignature({
17316
17340
  version: 1,
17317
17341
  threshold: EIP712_SIGNATURE_THRESHOLD,
17318
- signers: [
17319
- ...signers,
17320
- {
17321
- isDynamic: false,
17322
- unrecovered: true,
17323
- weight: SIGNATURE_WEIGHT,
17324
- signature: signedDigest,
17325
- },
17326
- ],
17342
+ signers: sortedSigners,
17327
17343
  });
17328
17344
  };
17329
17345
  const getEip155ChainId = (chainId) => `eip155:${chainId}`;
@@ -17908,9 +17924,6 @@ class Passport {
17908
17924
  return this.passportImxProviderFactory.getProvider();
17909
17925
  }
17910
17926
  connectEvm() {
17911
- if (this.config.baseConfig.environment === 'production') {
17912
- throw new Error('EVM is not supported on production network');
17913
- }
17914
17927
  return new ZkEvmProvider({
17915
17928
  passportEventEmitter: this.passportEventEmitter,
17916
17929
  authManager: this.authManager,
@@ -37025,38 +37038,84 @@ class TokenBridge {
37025
37038
  * @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
37026
37039
  */
37027
37040
  async getTransactionStatus(req) {
37028
- const axelarAPIEndpoint = this.getAxelarEndpoint(req.sourceChainId);
37029
37041
  const txStatusResponse = {
37030
37042
  transactions: [],
37031
37043
  };
37032
- const abiCoder = new AbiCoder();
37033
- const statusPromises = [];
37034
- for (const transaction of req.transactions) {
37035
- statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
37044
+ const txStatusItems = await this.getAxelarStatus(req.transactions, req.sourceChainId);
37045
+ const uniqueReceivers = await this.getUniqueReceivers(txStatusItems, req.sourceChainId);
37046
+ const pendingWithdrawalPromises = [];
37047
+ for (const address of uniqueReceivers) {
37048
+ pendingWithdrawalPromises.push(this.getPendingWithdrawals({ recipient: address }));
37036
37049
  }
37037
- let statusResponses;
37050
+ let pendingWithdrawalResponses = [];
37038
37051
  try {
37039
- statusResponses = await Promise.all(statusPromises);
37052
+ pendingWithdrawalResponses = await Promise.all(pendingWithdrawalPromises);
37040
37053
  }
37041
37054
  catch (err) {
37042
- throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
37055
+ console.log('err', err);
37056
+ throw new BridgeError(`Failed to fetch the pending withdrawals with: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
37043
37057
  }
37044
- const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
37058
+ txStatusResponse.transactions = txStatusItems;
37059
+ // try match a completed transaction to a pending flowRate transaction
37060
+ for (const txStatusRes of txStatusResponse.transactions) {
37061
+ if (txStatusRes.status === StatusResponse.COMPLETE) {
37062
+ (() => {
37063
+ for (const pendingWithdrawals of pendingWithdrawalResponses) {
37064
+ const flowRatedTxIndex = pendingWithdrawals.pending.findIndex((el) => (el.amount.toString() === txStatusRes.amount.toString()
37065
+ && el.token === txStatusRes.token
37066
+ && el.withdrawer === txStatusRes.sender
37067
+ && el.recipient === txStatusRes.recipient));
37068
+ if (flowRatedTxIndex !== -1) {
37069
+ txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
37070
+ txStatusRes.data = {
37071
+ canWithdraw: pendingWithdrawals.pending[flowRatedTxIndex].canWithdraw,
37072
+ timeoutStart: pendingWithdrawals.pending[flowRatedTxIndex].timeoutStart,
37073
+ timeoutEnd: pendingWithdrawals.pending[flowRatedTxIndex].timeoutEnd,
37074
+ };
37075
+ pendingWithdrawals.pending.splice(flowRatedTxIndex, 1);
37076
+ return;
37077
+ }
37078
+ }
37079
+ })();
37080
+ }
37081
+ }
37082
+ // Return the tx status response
37083
+ return txStatusResponse;
37084
+ }
37085
+ async getUniqueReceivers(txStatusItems, sourceChainId) {
37086
+ const uniqueReceivers = [];
37045
37087
  const isWithdraw = [
37046
37088
  ZKEVM_DEVNET_CHAIN_ID,
37047
37089
  ZKEVM_TESTNET_CHAIN_ID,
37048
37090
  ZKEVM_MAINNET_CHAIN_ID
37049
- ].includes(req.sourceChainId);
37050
- let rootBridge;
37051
- if (isWithdraw) {
37052
- rootBridge = await withBridgeError(async () => {
37053
- const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
37054
- return contract;
37055
- }, BridgeErrorType.INTERNAL_ERROR);
37091
+ ].includes(sourceChainId);
37092
+ for (let i = 0, l = txStatusItems.length; i < l; i++) {
37093
+ if (txStatusItems[i].status === StatusResponse.COMPLETE
37094
+ && isWithdraw && txStatusItems[i].recipient) {
37095
+ const receiverIndex = uniqueReceivers.findIndex((el) => el === txStatusItems[i].recipient);
37096
+ if (receiverIndex === -1) {
37097
+ uniqueReceivers.push(txStatusItems[i].recipient);
37098
+ }
37099
+ }
37100
+ } // for
37101
+ return uniqueReceivers;
37102
+ }
37103
+ async getAxelarStatus(transactions, sourceChainId) {
37104
+ const txStatusItems = [];
37105
+ const statusPromises = [];
37106
+ const axelarAPIEndpoint = this.getAxelarEndpoint(sourceChainId);
37107
+ const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
37108
+ const abiCoder = new AbiCoder();
37109
+ for (const transaction of transactions) {
37110
+ statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
37111
+ }
37112
+ let statusResponses;
37113
+ try {
37114
+ statusResponses = await Promise.all(statusPromises);
37115
+ }
37116
+ catch (err) {
37117
+ throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
37056
37118
  }
37057
- const flowRatePromises = [];
37058
- const flowRateLengthPromises = [];
37059
- const flowRatePromisesReceivers = [];
37060
37119
  for (let i = 0, l = statusResponses.length; i < l; i++) {
37061
37120
  let metaStatus;
37062
37121
  // consolidate axelar statuses to our own simplified metaStatus
@@ -37090,7 +37149,7 @@ class TokenBridge {
37090
37149
  }
37091
37150
  }
37092
37151
  let txItem = {
37093
- txHash: req.transactions[i].txHash,
37152
+ txHash: transactions[i].txHash,
37094
37153
  status: metaStatus,
37095
37154
  data: {
37096
37155
  gmpResponse: statusResponses[i].status,
@@ -37107,61 +37166,9 @@ class TokenBridge {
37107
37166
  amount: decodedData[4],
37108
37167
  };
37109
37168
  }
37110
- let flowRatePromiseIndex = flowRatePromisesReceivers.findIndex((el) => el === txItem.recipient);
37111
- if (metaStatus === StatusResponse.COMPLETE
37112
- && isWithdraw && txItem.recipient) {
37113
- // consolidate the calls we have to make to the flow rate by receiver
37114
- if (flowRatePromiseIndex === -1) {
37115
- flowRatePromisesReceivers.push(txItem.recipient);
37116
- flowRatePromiseIndex = flowRatePromisesReceivers.length - 1;
37117
- }
37118
- txItem.data.flowRatePromiseIndex = flowRatePromiseIndex;
37119
- }
37120
- txStatusResponse.transactions.push(txItem);
37169
+ txStatusItems.push(txItem);
37121
37170
  } // for
37122
- for (const flowRateReceiver of flowRatePromisesReceivers) {
37123
- flowRateLengthPromises.push(rootBridge.getPendingWithdrawalsLength(flowRateReceiver));
37124
- }
37125
- let flowRateLengthResponses = [];
37126
- try {
37127
- flowRateLengthResponses = await Promise.all(flowRateLengthPromises);
37128
- }
37129
- catch (err) {
37130
- throw new BridgeError(`Failed to fetch the Flow Rate pending lengths with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
37131
- }
37132
- for (let i = 0, l = flowRatePromisesReceivers.length; i < l; i++) {
37133
- const indices = [];
37134
- const indicesLength = flowRateLengthResponses[i].toNumber();
37135
- for (let j = 0; j < indicesLength; j++) {
37136
- indices.push(j);
37137
- }
37138
- flowRatePromises.push(rootBridge.getPendingWithdrawals(flowRatePromisesReceivers[i], indices));
37139
- }
37140
- let flowRateResponses = [];
37141
- if (flowRatePromises.length > 0) {
37142
- try {
37143
- flowRateResponses = await Promise.all(flowRatePromises);
37144
- }
37145
- catch (err) {
37146
- throw new BridgeError(`Failed to fetch the Flow Rate statuses with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
37147
- }
37148
- }
37149
- for (const txStatusRes of txStatusResponse.transactions) {
37150
- if (txStatusRes.data.flowRatePromiseIndex !== -1 && flowRateResponses[txStatusRes.data.flowRatePromiseIndex]) {
37151
- const flowRatedTx = flowRateResponses[txStatusRes.data.flowRatePromiseIndex].find((el) => (el.amount.toString() === txStatusRes.amount.toString()
37152
- && el.token === txStatusRes.token
37153
- && el.withdrawer === txStatusRes.sender));
37154
- if (flowRatedTx) {
37155
- txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
37156
- txStatusRes.data = {
37157
- timestamp: flowRatedTx.timestamp.toString(),
37158
- };
37159
- }
37160
- }
37161
- delete txStatusRes.data.flowRatePromiseIndex;
37162
- }
37163
- // Return the tx status response
37164
- return txStatusResponse;
37171
+ return txStatusItems;
37165
37172
  }
37166
37173
  /**
37167
37174
  * Queries for the information about which tokens are flowrated and how long the delay is.
@@ -37187,6 +37194,7 @@ class TokenBridge {
37187
37194
  token = ETHEREUM_NATIVE_TOKEN_ADDRESS;
37188
37195
  }
37189
37196
  contractPromises.push(rootBridge.flowRateBuckets(token));
37197
+ contractPromises.push(rootBridge.largeTransferThresholds(token));
37190
37198
  }
37191
37199
  let contractPromisesRes;
37192
37200
  try {
@@ -37196,19 +37204,25 @@ class TokenBridge {
37196
37204
  throw new BridgeError('unable to query contract for flowrate info', BridgeErrorType.INTERNAL_ERROR);
37197
37205
  }
37198
37206
  const tokensRes = {};
37199
- // @note it's i + 2 because the first 2 promises are not token buckets
37207
+ const withdrawalQueueActivated = contractPromisesRes[0];
37208
+ const withdrawalDelay = contractPromisesRes[1].toNumber();
37209
+ // remove first 2 items from promise all response
37210
+ contractPromisesRes.splice(0, 2);
37211
+ // the remaining items should be sets of 2 per token
37200
37212
  for (let i = 0, l = req.tokens.length; i < l; i++) {
37213
+ const shifter = i * 2;
37201
37214
  tokensRes[req.tokens[i]] = {
37202
- capacity: contractPromisesRes[i + 2].capacity,
37203
- depth: contractPromisesRes[i + 2].depth,
37204
- refillTime: contractPromisesRes[i + 2].refillTime.toNumber(),
37205
- refillRate: contractPromisesRes[i + 2].refillRate,
37215
+ capacity: contractPromisesRes[shifter].capacity,
37216
+ depth: contractPromisesRes[shifter].depth,
37217
+ refillTime: contractPromisesRes[shifter].refillTime.toNumber(),
37218
+ refillRate: contractPromisesRes[shifter].refillRate,
37219
+ largeTransferThreshold: contractPromisesRes[shifter + 1],
37206
37220
  };
37207
37221
  }
37208
37222
  // Return the token mappings
37209
37223
  return {
37210
- withdrawalQueueActivated: contractPromisesRes[0],
37211
- withdrawalDelay: contractPromisesRes[1].toNumber(),
37224
+ withdrawalQueueActivated,
37225
+ withdrawalDelay,
37212
37226
  tokens: tokensRes,
37213
37227
  };
37214
37228
  }
@@ -37255,6 +37269,7 @@ class TokenBridge {
37255
37269
  canWithdraw: true,
37256
37270
  };
37257
37271
  }
37272
+ pendingWithdrawals.pending[i].recipient = req.recipient;
37258
37273
  pendingWithdrawals.pending[i].withdrawer = pending[i].withdrawer;
37259
37274
  pendingWithdrawals.pending[i].token = pending[i].token;
37260
37275
  pendingWithdrawals.pending[i].amount = pending[i].amount;
@@ -37298,6 +37313,7 @@ class TokenBridge {
37298
37313
  pendingWithdrawal: {
37299
37314
  canWithdraw: false,
37300
37315
  withdrawer: pending[0].withdrawer,
37316
+ recipient: req.recipient,
37301
37317
  token: pending[0].token,
37302
37318
  amount: pending[0].amount,
37303
37319
  timeoutStart: pending[0].timestamp.toNumber(),
@@ -37311,6 +37327,7 @@ class TokenBridge {
37311
37327
  pendingWithdrawal: {
37312
37328
  canWithdraw: true,
37313
37329
  withdrawer: pending[0].withdrawer,
37330
+ recipient: req.recipient,
37314
37331
  token: pending[0].token,
37315
37332
  amount: pending[0].amount,
37316
37333
  timeoutStart: pending[0].timestamp.toNumber(),
@@ -37336,10 +37353,38 @@ class TokenBridge {
37336
37353
  */
37337
37354
  async getTokenMapping(req) {
37338
37355
  // eslint-disable-next-line no-console
37339
- console.log('stubbed response with req', req);
37356
+ if (req.rootToken.toUpperCase() === 'NATIVE'
37357
+ || req.rootToken === this.config.bridgeContracts.rootChainWrappedETH) {
37358
+ const childBridge = await withBridgeError(async () => {
37359
+ const contract = new Contract(this.config.bridgeContracts.childERC20Bridge, CHILD_ERC20_BRIDGE, this.config.childProvider);
37360
+ return contract;
37361
+ }, BridgeErrorType.INTERNAL_ERROR);
37362
+ const childETHToken = await childBridge.childETHToken();
37363
+ return {
37364
+ rootToken: req.rootToken,
37365
+ childToken: childETHToken,
37366
+ };
37367
+ }
37368
+ const rootBridge = await withBridgeError(async () => {
37369
+ const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
37370
+ return contract;
37371
+ }, BridgeErrorType.INTERNAL_ERROR);
37372
+ const rootTokenChildAddress = await rootBridge.rootTokenToChildToken(req.rootToken);
37373
+ if (rootTokenChildAddress === AddressZero) {
37374
+ return {
37375
+ rootToken: req.rootToken,
37376
+ childToken: null,
37377
+ };
37378
+ }
37379
+ if (rootTokenChildAddress === req.rootToken) {
37380
+ return {
37381
+ rootToken: req.rootToken,
37382
+ childToken: 'NATIVE',
37383
+ };
37384
+ }
37340
37385
  return {
37341
- rootToken: '0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF',
37342
- childToken: 'NATIVE',
37386
+ rootToken: req.rootToken,
37387
+ childToken: rootTokenChildAddress,
37343
37388
  };
37344
37389
  }
37345
37390
  }
@@ -41265,12 +41310,14 @@ const validateProviderDefaults = {
41265
41310
  * @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
41266
41311
  * @property {string} FAILED - If checkout failed due to transactions not settling on chain
41267
41312
  * @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
41313
+ * @property {string} FULFILLMENTS_UNSETTLED - If checkout succeeded but the fulfillment transactions are not yet settled
41268
41314
  */
41269
41315
  var CheckoutStatus;
41270
41316
  (function (CheckoutStatus) {
41271
41317
  CheckoutStatus["SUCCESS"] = "SUCCESS";
41272
41318
  CheckoutStatus["FAILED"] = "FAILED";
41273
41319
  CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
41320
+ CheckoutStatus["FULFILLMENTS_UNSETTLED"] = "FULFILLMENTS_UNSETTLED";
41274
41321
  })(CheckoutStatus || (CheckoutStatus = {}));
41275
41322
  /**
41276
41323
  * An enum representing the item types
@@ -41945,7 +41992,7 @@ const GAS_OVERRIDES = {
41945
41992
  maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
41946
41993
  };
41947
41994
 
41948
- const SDK_VERSION_MARKER = '0.44.0';
41995
+ const SDK_VERSION_MARKER = '0.44.2';
41949
41996
  // This SDK version is replaced by the `yarn build` command ran on the root level
41950
41997
  const globalPackageVersion = () => SDK_VERSION_MARKER;
41951
41998
 
@@ -45006,7 +45053,9 @@ const getTransactionOrGas = (gasLimit, fulfillmentTransactions) => {
45006
45053
  },
45007
45054
  };
45008
45055
  };
45009
- const buy = async (config, provider, orders) => {
45056
+ const buy = async (config, provider, orders, overrides = {
45057
+ waitFulfillmentSettlements: true,
45058
+ }) => {
45010
45059
  if (orders.length === 0) {
45011
45060
  throw new CheckoutError('No orders were provided to the orders array. Please provide at least one order.', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR);
45012
45061
  }
@@ -45134,18 +45183,35 @@ const buy = async (config, provider, orders) => {
45134
45183
  message: err.message,
45135
45184
  });
45136
45185
  }
45137
- const fulfillmentResult = await signFulfillmentTransactions(provider, unsignedFulfillmentTransactions);
45138
- if (fulfillmentResult.type === SignTransactionStatusType.FAILED) {
45186
+ if (overrides.waitFulfillmentSettlements) {
45187
+ const fulfillmentResult = await signFulfillmentTransactions(provider, unsignedFulfillmentTransactions);
45188
+ if (fulfillmentResult.type === SignTransactionStatusType.FAILED) {
45189
+ return {
45190
+ status: CheckoutStatus.FAILED,
45191
+ transactionHash: fulfillmentResult.transactionHash,
45192
+ reason: fulfillmentResult.reason,
45193
+ smartCheckoutResult,
45194
+ };
45195
+ }
45139
45196
  return {
45140
- status: CheckoutStatus.FAILED,
45141
- transactionHash: fulfillmentResult.transactionHash,
45142
- reason: fulfillmentResult.reason,
45197
+ status: CheckoutStatus.SUCCESS,
45143
45198
  smartCheckoutResult,
45144
45199
  };
45145
45200
  }
45201
+ let transactions;
45202
+ try {
45203
+ const response = await Promise.all(unsignedFulfillmentTransactions.map((transaction) => sendTransaction(provider, transaction)));
45204
+ transactions = response.map((result) => result.transactionResponse);
45205
+ }
45206
+ catch (err) {
45207
+ throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
45208
+ message: err.message,
45209
+ });
45210
+ }
45146
45211
  return {
45147
- status: CheckoutStatus.SUCCESS,
45212
+ status: CheckoutStatus.FULFILLMENTS_UNSETTLED,
45148
45213
  smartCheckoutResult,
45214
+ transactions,
45149
45215
  };
45150
45216
  }
45151
45217
  return {
@@ -45722,7 +45788,7 @@ class Checkout {
45722
45788
  console.warn('This endpoint currently only processes the first order in the array.');
45723
45789
  }
45724
45790
  const web3Provider = await validateProvider(this.config, params.provider);
45725
- return await buy(this.config, web3Provider, params.orders);
45791
+ return await buy(this.config, web3Provider, params.orders, params.overrides);
45726
45792
  }
45727
45793
  /**
45728
45794
  * Determines the requirements for performing a sell.
package/dist/index.d.ts CHANGED
@@ -16861,6 +16861,8 @@ type orderbook_d_OrderStatusName = OrderStatusName;
16861
16861
  declare const orderbook_d_OrderStatusName: typeof OrderStatusName;
16862
16862
  type orderbook_d_Orderbook = Orderbook;
16863
16863
  declare const orderbook_d_Orderbook: typeof Orderbook;
16864
+ type orderbook_d_OrderbookModuleConfiguration = OrderbookModuleConfiguration;
16865
+ type orderbook_d_OrderbookOverrides = OrderbookOverrides;
16864
16866
  type orderbook_d_Page = Page;
16865
16867
  type orderbook_d_PrepareCancelOrdersResponse = PrepareCancelOrdersResponse;
16866
16868
  type orderbook_d_PrepareListingParams = PrepareListingParams;
@@ -16902,6 +16904,8 @@ declare namespace orderbook_d {
16902
16904
  orderbook_d_Order as Order,
16903
16905
  orderbook_d_OrderStatusName as OrderStatusName,
16904
16906
  orderbook_d_Orderbook as Orderbook,
16907
+ orderbook_d_OrderbookModuleConfiguration as OrderbookModuleConfiguration,
16908
+ orderbook_d_OrderbookOverrides as OrderbookOverrides,
16905
16909
  orderbook_d_Page as Page,
16906
16910
  orderbook_d_PrepareCancelOrdersResponse as PrepareCancelOrdersResponse,
16907
16911
  orderbook_d_PrepareListingParams as PrepareListingParams,
@@ -17062,7 +17066,7 @@ interface FeePercentage {
17062
17066
  percentageDecimal: number;
17063
17067
  }
17064
17068
 
17065
- type BuyResult = BuyResultSuccess | BuyResultFailed | BuyResultInsufficientFunds;
17069
+ type BuyResult = BuyResultSuccess | BuyResultFailed | BuyResultFulfillmentsUnsettled | BuyResultInsufficientFunds;
17066
17070
  /**
17067
17071
  * Represents the result of {@link Checkout.buy}
17068
17072
  * @property {CheckoutStatus.SUCCESS} status
@@ -17091,6 +17095,20 @@ type BuyResultFailed = {
17091
17095
  /** The sufficient result of smart checkout */
17092
17096
  smartCheckoutResult: SmartCheckoutSufficient;
17093
17097
  };
17098
+ /**
17099
+ * Represents the result of {@link Checkout.buy}
17100
+ * @property {CheckoutStatus.FULFILLMENTS_UNSETTLED} status
17101
+ * @property {SmartCheckoutSufficient} smartCheckoutResult
17102
+ * @property {SendTransactionResult[]} transactions
17103
+ */
17104
+ type BuyResultFulfillmentsUnsettled = {
17105
+ /** The status to indicate success */
17106
+ status: CheckoutStatus.FULFILLMENTS_UNSETTLED;
17107
+ /** The sufficient result of smart checkout */
17108
+ smartCheckoutResult: SmartCheckoutSufficient;
17109
+ /** Array of transaction results */
17110
+ transactions: TransactionResponse[];
17111
+ };
17094
17112
  /**
17095
17113
  * Represents the result of {@link Checkout.buy}
17096
17114
  * @property {CheckoutStatus.INSUFFICIENT_FUNDS} status
@@ -17102,6 +17120,14 @@ type BuyResultInsufficientFunds = {
17102
17120
  /** The insufficient result of smart checkout */
17103
17121
  smartCheckoutResult: SmartCheckoutInsufficient;
17104
17122
  };
17123
+ /**
17124
+ * Represents the overrides available for {@link Checkout.buy}
17125
+ * @property {boolean} waitFulfillmentSettlements
17126
+ */
17127
+ type BuyOverrides = {
17128
+ /** If the buy should wait for the fulfillment transactions to settle */
17129
+ waitFulfillmentSettlements?: boolean;
17130
+ };
17105
17131
  type SellResult = SellResultSuccess | SellResultFailed | SellResultInsufficientFunds;
17106
17132
  /**
17107
17133
  * Represents the result of {@link Checkout.sell}
@@ -17174,11 +17200,13 @@ type CancelResultFailed = {
17174
17200
  * @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
17175
17201
  * @property {string} FAILED - If checkout failed due to transactions not settling on chain
17176
17202
  * @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
17203
+ * @property {string} FULFILLMENTS_UNSETTLED - If checkout succeeded but the fulfillment transactions are not yet settled
17177
17204
  */
17178
17205
  declare enum CheckoutStatus {
17179
17206
  SUCCESS = "SUCCESS",
17180
17207
  FAILED = "FAILED",
17181
- INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"
17208
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
17209
+ FULFILLMENTS_UNSETTLED = "FULFILLMENTS_UNSETTLED"
17182
17210
  }
17183
17211
  /**
17184
17212
  * The type representing the order to buy
@@ -17737,11 +17765,13 @@ type AvailableRoutingOptions = {
17737
17765
  * Interface representing the parameters for {@link Checkout.buy}
17738
17766
  * @property {Web3Provider} provider - The provider to use for the buy.
17739
17767
  * @property {Array<BuyOrder>} orders - The orders to buy
17768
+ * @property {BuyOverrides} overrides - The overrides to use for the buy.
17740
17769
  * Currently only processes the first order in the array until batch processing is supported.
17741
17770
  */
17742
17771
  interface BuyParams {
17743
17772
  provider: Web3Provider;
17744
17773
  orders: Array<BuyOrder>;
17774
+ overrides?: BuyOverrides;
17745
17775
  }
17746
17776
 
17747
17777
  /**
@@ -19470,6 +19500,7 @@ type checkout_d_BridgeTransactionSent = BridgeTransactionSent;
19470
19500
  type checkout_d_BridgeWidgetConfiguration = BridgeWidgetConfiguration;
19471
19501
  type checkout_d_BridgeWidgetParams = BridgeWidgetParams;
19472
19502
  type checkout_d_BuyOrder = BuyOrder;
19503
+ type checkout_d_BuyOverrides = BuyOverrides;
19473
19504
  type checkout_d_BuyParams = BuyParams;
19474
19505
  type checkout_d_BuyResult = BuyResult;
19475
19506
  type checkout_d_BuyResultFailed = BuyResultFailed;
@@ -19679,6 +19710,7 @@ declare namespace checkout_d {
19679
19710
  checkout_d_BridgeWidgetConfiguration as BridgeWidgetConfiguration,
19680
19711
  checkout_d_BridgeWidgetParams as BridgeWidgetParams,
19681
19712
  checkout_d_BuyOrder as BuyOrder,
19713
+ checkout_d_BuyOverrides as BuyOverrides,
19682
19714
  checkout_d_BuyParams as BuyParams,
19683
19715
  checkout_d_BuyResult as BuyResult,
19684
19716
  checkout_d_BuyResultFailed as BuyResultFailed,