@imtbl/sdk 0.44.1 → 0.44.3
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/blockchain_data.js +1 -1
- package/dist/browser/checkout/sdk.js +3 -3
- package/dist/browser/checkout/widgets.js +60 -60
- package/dist/checkout.d.ts +33 -4
- package/dist/checkout.js +213 -143
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +11 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +215 -145
- package/dist/index.d.ts +38 -3
- package/dist/index.js +215 -145
- package/dist/orderbook.d.ts +1 -1
- package/dist/passport.js +2 -2
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -10619,7 +10619,7 @@ class MultiRollupApiClients {
|
|
|
10619
10619
|
}
|
|
10620
10620
|
|
|
10621
10621
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10622
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.44.
|
|
10622
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.44.3' };
|
|
10623
10623
|
const createConfig = ({ basePath, headers, }) => {
|
|
10624
10624
|
if (!basePath.trim()) {
|
|
10625
10625
|
throw Error('basePath can not be empty');
|
|
@@ -10691,7 +10691,7 @@ class APIError extends Error {
|
|
|
10691
10691
|
|
|
10692
10692
|
/* eslint-disable implicit-arrow-linebreak */
|
|
10693
10693
|
const defaultHeaders = {
|
|
10694
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.
|
|
10694
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.3',
|
|
10695
10695
|
};
|
|
10696
10696
|
/**
|
|
10697
10697
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11130,7 +11130,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11130
11130
|
chainID,
|
|
11131
11131
|
coreContractAddress,
|
|
11132
11132
|
registrationContractAddress,
|
|
11133
|
-
sdkVersion: 'ts-immutable-sdk-0.44.
|
|
11133
|
+
sdkVersion: 'ts-immutable-sdk-0.44.3',
|
|
11134
11134
|
});
|
|
11135
11135
|
/**
|
|
11136
11136
|
* Sets `sdkVersion` at the time of build
|
|
@@ -36426,6 +36426,7 @@ var BridgeMethodsGasLimit;
|
|
|
36426
36426
|
BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_SOURCE"] = 200000] = "MAP_TOKEN_SOURCE";
|
|
36427
36427
|
BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_DESTINATION"] = 200000] = "MAP_TOKEN_DESTINATION";
|
|
36428
36428
|
BridgeMethodsGasLimit[BridgeMethodsGasLimit["FINALISE_WITHDRAWAL"] = 200000] = "FINALISE_WITHDRAWAL";
|
|
36429
|
+
BridgeMethodsGasLimit[BridgeMethodsGasLimit["APPROVE_TOKEN"] = 55000] = "APPROVE_TOKEN";
|
|
36429
36430
|
})(BridgeMethodsGasLimit || (BridgeMethodsGasLimit = {}));
|
|
36430
36431
|
var StatusResponse;
|
|
36431
36432
|
(function (StatusResponse) {
|
|
@@ -36613,8 +36614,12 @@ class TokenBridge {
|
|
|
36613
36614
|
throw new BridgeError(`Finalised withdrawals must be on the root chain (${this.config.bridgeInstance.rootChainID})`, BridgeErrorType.UNSUPPORTED_ERROR);
|
|
36614
36615
|
}
|
|
36615
36616
|
let sourceChainGas = BigNumber.from(0);
|
|
36617
|
+
let approvalFee = BigNumber.from(0);
|
|
36616
36618
|
let bridgeFee = BigNumber.from(0);
|
|
36617
36619
|
const imtblFee = BigNumber.from(0);
|
|
36620
|
+
if ('token' in req && req.token !== 'NATIVE') {
|
|
36621
|
+
approvalFee = await this.getGasEstimates(this.config.rootProvider, BridgeMethodsGasLimit.APPROVE_TOKEN);
|
|
36622
|
+
}
|
|
36618
36623
|
if (req.action === BridgeFeeActions.FINALISE_WITHDRAWAL) {
|
|
36619
36624
|
sourceChainGas = await this.getGasEstimates(this.config.rootProvider, BridgeMethodsGasLimit.FINALISE_WITHDRAWAL);
|
|
36620
36625
|
}
|
|
@@ -36625,9 +36630,10 @@ class TokenBridge {
|
|
|
36625
36630
|
const feeResult = await this.calculateBridgeFee(req.sourceChainId, req.destinationChainId, BridgeMethodsGasLimit[`${req.action}_DESTINATION`], req.gasMultiplier);
|
|
36626
36631
|
bridgeFee = feeResult.bridgeFee;
|
|
36627
36632
|
}
|
|
36628
|
-
const totalFees = sourceChainGas.add(bridgeFee).add(imtblFee);
|
|
36633
|
+
const totalFees = sourceChainGas.add(approvalFee).add(bridgeFee).add(imtblFee);
|
|
36629
36634
|
return {
|
|
36630
36635
|
sourceChainGas,
|
|
36636
|
+
approvalFee,
|
|
36631
36637
|
bridgeFee,
|
|
36632
36638
|
imtblFee,
|
|
36633
36639
|
totalFees,
|
|
@@ -36857,6 +36863,8 @@ class TokenBridge {
|
|
|
36857
36863
|
gasMultiplier,
|
|
36858
36864
|
sourceChainId,
|
|
36859
36865
|
destinationChainId,
|
|
36866
|
+
token,
|
|
36867
|
+
amount,
|
|
36860
36868
|
});
|
|
36861
36869
|
const canReceive = await this.checkReceiver(provider, recipient);
|
|
36862
36870
|
if (!canReceive) {
|
|
@@ -37016,38 +37024,84 @@ class TokenBridge {
|
|
|
37016
37024
|
* @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
|
|
37017
37025
|
*/
|
|
37018
37026
|
async getTransactionStatus(req) {
|
|
37019
|
-
const axelarAPIEndpoint = this.getAxelarEndpoint(req.sourceChainId);
|
|
37020
37027
|
const txStatusResponse = {
|
|
37021
37028
|
transactions: [],
|
|
37022
37029
|
};
|
|
37023
|
-
const
|
|
37024
|
-
const
|
|
37025
|
-
|
|
37026
|
-
|
|
37030
|
+
const txStatusItems = await this.getAxelarStatus(req.transactions, req.sourceChainId);
|
|
37031
|
+
const uniqueReceivers = await this.getUniqueReceivers(txStatusItems, req.sourceChainId);
|
|
37032
|
+
const pendingWithdrawalPromises = [];
|
|
37033
|
+
for (const address of uniqueReceivers) {
|
|
37034
|
+
pendingWithdrawalPromises.push(this.getPendingWithdrawals({ recipient: address }));
|
|
37027
37035
|
}
|
|
37028
|
-
let
|
|
37036
|
+
let pendingWithdrawalResponses = [];
|
|
37029
37037
|
try {
|
|
37030
|
-
|
|
37038
|
+
pendingWithdrawalResponses = await Promise.all(pendingWithdrawalPromises);
|
|
37031
37039
|
}
|
|
37032
37040
|
catch (err) {
|
|
37033
|
-
|
|
37041
|
+
console.log('err', err);
|
|
37042
|
+
throw new BridgeError(`Failed to fetch the pending withdrawals with: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
|
|
37034
37043
|
}
|
|
37035
|
-
|
|
37044
|
+
txStatusResponse.transactions = txStatusItems;
|
|
37045
|
+
// try match a completed transaction to a pending flowRate transaction
|
|
37046
|
+
for (const txStatusRes of txStatusResponse.transactions) {
|
|
37047
|
+
if (txStatusRes.status === StatusResponse.COMPLETE) {
|
|
37048
|
+
(() => {
|
|
37049
|
+
for (const pendingWithdrawals of pendingWithdrawalResponses) {
|
|
37050
|
+
const flowRatedTxIndex = pendingWithdrawals.pending.findIndex((el) => (el.amount.toString() === txStatusRes.amount.toString()
|
|
37051
|
+
&& el.token === txStatusRes.token
|
|
37052
|
+
&& el.withdrawer === txStatusRes.sender
|
|
37053
|
+
&& el.recipient === txStatusRes.recipient));
|
|
37054
|
+
if (flowRatedTxIndex !== -1) {
|
|
37055
|
+
txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
|
|
37056
|
+
txStatusRes.data = {
|
|
37057
|
+
canWithdraw: pendingWithdrawals.pending[flowRatedTxIndex].canWithdraw,
|
|
37058
|
+
timeoutStart: pendingWithdrawals.pending[flowRatedTxIndex].timeoutStart,
|
|
37059
|
+
timeoutEnd: pendingWithdrawals.pending[flowRatedTxIndex].timeoutEnd,
|
|
37060
|
+
};
|
|
37061
|
+
pendingWithdrawals.pending.splice(flowRatedTxIndex, 1);
|
|
37062
|
+
return;
|
|
37063
|
+
}
|
|
37064
|
+
}
|
|
37065
|
+
})();
|
|
37066
|
+
}
|
|
37067
|
+
}
|
|
37068
|
+
// Return the tx status response
|
|
37069
|
+
return txStatusResponse;
|
|
37070
|
+
}
|
|
37071
|
+
async getUniqueReceivers(txStatusItems, sourceChainId) {
|
|
37072
|
+
const uniqueReceivers = [];
|
|
37036
37073
|
const isWithdraw = [
|
|
37037
37074
|
ZKEVM_DEVNET_CHAIN_ID,
|
|
37038
37075
|
ZKEVM_TESTNET_CHAIN_ID,
|
|
37039
37076
|
ZKEVM_MAINNET_CHAIN_ID
|
|
37040
|
-
].includes(
|
|
37041
|
-
let
|
|
37042
|
-
|
|
37043
|
-
|
|
37044
|
-
const
|
|
37045
|
-
|
|
37046
|
-
|
|
37077
|
+
].includes(sourceChainId);
|
|
37078
|
+
for (let i = 0, l = txStatusItems.length; i < l; i++) {
|
|
37079
|
+
if (txStatusItems[i].status === StatusResponse.COMPLETE
|
|
37080
|
+
&& isWithdraw && txStatusItems[i].recipient) {
|
|
37081
|
+
const receiverIndex = uniqueReceivers.findIndex((el) => el === txStatusItems[i].recipient);
|
|
37082
|
+
if (receiverIndex === -1) {
|
|
37083
|
+
uniqueReceivers.push(txStatusItems[i].recipient);
|
|
37084
|
+
}
|
|
37085
|
+
}
|
|
37086
|
+
} // for
|
|
37087
|
+
return uniqueReceivers;
|
|
37088
|
+
}
|
|
37089
|
+
async getAxelarStatus(transactions, sourceChainId) {
|
|
37090
|
+
const txStatusItems = [];
|
|
37091
|
+
const statusPromises = [];
|
|
37092
|
+
const axelarAPIEndpoint = this.getAxelarEndpoint(sourceChainId);
|
|
37093
|
+
const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
|
|
37094
|
+
const abiCoder = new AbiCoder();
|
|
37095
|
+
for (const transaction of transactions) {
|
|
37096
|
+
statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
|
|
37097
|
+
}
|
|
37098
|
+
let statusResponses;
|
|
37099
|
+
try {
|
|
37100
|
+
statusResponses = await Promise.all(statusPromises);
|
|
37101
|
+
}
|
|
37102
|
+
catch (err) {
|
|
37103
|
+
throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
|
|
37047
37104
|
}
|
|
37048
|
-
const flowRatePromises = [];
|
|
37049
|
-
const flowRateLengthPromises = [];
|
|
37050
|
-
const flowRatePromisesReceivers = [];
|
|
37051
37105
|
for (let i = 0, l = statusResponses.length; i < l; i++) {
|
|
37052
37106
|
let metaStatus;
|
|
37053
37107
|
// consolidate axelar statuses to our own simplified metaStatus
|
|
@@ -37081,7 +37135,7 @@ class TokenBridge {
|
|
|
37081
37135
|
}
|
|
37082
37136
|
}
|
|
37083
37137
|
let txItem = {
|
|
37084
|
-
txHash:
|
|
37138
|
+
txHash: transactions[i].txHash,
|
|
37085
37139
|
status: metaStatus,
|
|
37086
37140
|
data: {
|
|
37087
37141
|
gmpResponse: statusResponses[i].status,
|
|
@@ -37098,61 +37152,9 @@ class TokenBridge {
|
|
|
37098
37152
|
amount: decodedData[4],
|
|
37099
37153
|
};
|
|
37100
37154
|
}
|
|
37101
|
-
|
|
37102
|
-
if (metaStatus === StatusResponse.COMPLETE
|
|
37103
|
-
&& isWithdraw && txItem.recipient) {
|
|
37104
|
-
// consolidate the calls we have to make to the flow rate by receiver
|
|
37105
|
-
if (flowRatePromiseIndex === -1) {
|
|
37106
|
-
flowRatePromisesReceivers.push(txItem.recipient);
|
|
37107
|
-
flowRatePromiseIndex = flowRatePromisesReceivers.length - 1;
|
|
37108
|
-
}
|
|
37109
|
-
txItem.data.flowRatePromiseIndex = flowRatePromiseIndex;
|
|
37110
|
-
}
|
|
37111
|
-
txStatusResponse.transactions.push(txItem);
|
|
37155
|
+
txStatusItems.push(txItem);
|
|
37112
37156
|
} // for
|
|
37113
|
-
|
|
37114
|
-
flowRateLengthPromises.push(rootBridge.getPendingWithdrawalsLength(flowRateReceiver));
|
|
37115
|
-
}
|
|
37116
|
-
let flowRateLengthResponses = [];
|
|
37117
|
-
try {
|
|
37118
|
-
flowRateLengthResponses = await Promise.all(flowRateLengthPromises);
|
|
37119
|
-
}
|
|
37120
|
-
catch (err) {
|
|
37121
|
-
throw new BridgeError(`Failed to fetch the Flow Rate pending lengths with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
|
|
37122
|
-
}
|
|
37123
|
-
for (let i = 0, l = flowRatePromisesReceivers.length; i < l; i++) {
|
|
37124
|
-
const indices = [];
|
|
37125
|
-
const indicesLength = flowRateLengthResponses[i].toNumber();
|
|
37126
|
-
for (let j = 0; j < indicesLength; j++) {
|
|
37127
|
-
indices.push(j);
|
|
37128
|
-
}
|
|
37129
|
-
flowRatePromises.push(rootBridge.getPendingWithdrawals(flowRatePromisesReceivers[i], indices));
|
|
37130
|
-
}
|
|
37131
|
-
let flowRateResponses = [];
|
|
37132
|
-
if (flowRatePromises.length > 0) {
|
|
37133
|
-
try {
|
|
37134
|
-
flowRateResponses = await Promise.all(flowRatePromises);
|
|
37135
|
-
}
|
|
37136
|
-
catch (err) {
|
|
37137
|
-
throw new BridgeError(`Failed to fetch the Flow Rate statuses with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
|
|
37138
|
-
}
|
|
37139
|
-
}
|
|
37140
|
-
for (const txStatusRes of txStatusResponse.transactions) {
|
|
37141
|
-
if (txStatusRes.data.flowRatePromiseIndex !== -1 && flowRateResponses[txStatusRes.data.flowRatePromiseIndex]) {
|
|
37142
|
-
const flowRatedTx = flowRateResponses[txStatusRes.data.flowRatePromiseIndex].find((el) => (el.amount.toString() === txStatusRes.amount.toString()
|
|
37143
|
-
&& el.token === txStatusRes.token
|
|
37144
|
-
&& el.withdrawer === txStatusRes.sender));
|
|
37145
|
-
if (flowRatedTx) {
|
|
37146
|
-
txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
|
|
37147
|
-
txStatusRes.data = {
|
|
37148
|
-
timestamp: flowRatedTx.timestamp.toString(),
|
|
37149
|
-
};
|
|
37150
|
-
}
|
|
37151
|
-
}
|
|
37152
|
-
delete txStatusRes.data.flowRatePromiseIndex;
|
|
37153
|
-
}
|
|
37154
|
-
// Return the tx status response
|
|
37155
|
-
return txStatusResponse;
|
|
37157
|
+
return txStatusItems;
|
|
37156
37158
|
}
|
|
37157
37159
|
/**
|
|
37158
37160
|
* Queries for the information about which tokens are flowrated and how long the delay is.
|
|
@@ -37178,6 +37180,7 @@ class TokenBridge {
|
|
|
37178
37180
|
token = ETHEREUM_NATIVE_TOKEN_ADDRESS;
|
|
37179
37181
|
}
|
|
37180
37182
|
contractPromises.push(rootBridge.flowRateBuckets(token));
|
|
37183
|
+
contractPromises.push(rootBridge.largeTransferThresholds(token));
|
|
37181
37184
|
}
|
|
37182
37185
|
let contractPromisesRes;
|
|
37183
37186
|
try {
|
|
@@ -37187,19 +37190,25 @@ class TokenBridge {
|
|
|
37187
37190
|
throw new BridgeError('unable to query contract for flowrate info', BridgeErrorType.INTERNAL_ERROR);
|
|
37188
37191
|
}
|
|
37189
37192
|
const tokensRes = {};
|
|
37190
|
-
|
|
37193
|
+
const withdrawalQueueActivated = contractPromisesRes[0];
|
|
37194
|
+
const withdrawalDelay = contractPromisesRes[1].toNumber();
|
|
37195
|
+
// remove first 2 items from promise all response
|
|
37196
|
+
contractPromisesRes.splice(0, 2);
|
|
37197
|
+
// the remaining items should be sets of 2 per token
|
|
37191
37198
|
for (let i = 0, l = req.tokens.length; i < l; i++) {
|
|
37199
|
+
const shifter = i * 2;
|
|
37192
37200
|
tokensRes[req.tokens[i]] = {
|
|
37193
|
-
capacity: contractPromisesRes[
|
|
37194
|
-
depth: contractPromisesRes[
|
|
37195
|
-
refillTime: contractPromisesRes[
|
|
37196
|
-
refillRate: contractPromisesRes[
|
|
37201
|
+
capacity: contractPromisesRes[shifter].capacity,
|
|
37202
|
+
depth: contractPromisesRes[shifter].depth,
|
|
37203
|
+
refillTime: contractPromisesRes[shifter].refillTime.toNumber(),
|
|
37204
|
+
refillRate: contractPromisesRes[shifter].refillRate,
|
|
37205
|
+
largeTransferThreshold: contractPromisesRes[shifter + 1],
|
|
37197
37206
|
};
|
|
37198
37207
|
}
|
|
37199
37208
|
// Return the token mappings
|
|
37200
37209
|
return {
|
|
37201
|
-
withdrawalQueueActivated
|
|
37202
|
-
withdrawalDelay
|
|
37210
|
+
withdrawalQueueActivated,
|
|
37211
|
+
withdrawalDelay,
|
|
37203
37212
|
tokens: tokensRes,
|
|
37204
37213
|
};
|
|
37205
37214
|
}
|
|
@@ -37246,6 +37255,7 @@ class TokenBridge {
|
|
|
37246
37255
|
canWithdraw: true,
|
|
37247
37256
|
};
|
|
37248
37257
|
}
|
|
37258
|
+
pendingWithdrawals.pending[i].recipient = req.recipient;
|
|
37249
37259
|
pendingWithdrawals.pending[i].withdrawer = pending[i].withdrawer;
|
|
37250
37260
|
pendingWithdrawals.pending[i].token = pending[i].token;
|
|
37251
37261
|
pendingWithdrawals.pending[i].amount = pending[i].amount;
|
|
@@ -37289,6 +37299,7 @@ class TokenBridge {
|
|
|
37289
37299
|
pendingWithdrawal: {
|
|
37290
37300
|
canWithdraw: false,
|
|
37291
37301
|
withdrawer: pending[0].withdrawer,
|
|
37302
|
+
recipient: req.recipient,
|
|
37292
37303
|
token: pending[0].token,
|
|
37293
37304
|
amount: pending[0].amount,
|
|
37294
37305
|
timeoutStart: pending[0].timestamp.toNumber(),
|
|
@@ -37302,6 +37313,7 @@ class TokenBridge {
|
|
|
37302
37313
|
pendingWithdrawal: {
|
|
37303
37314
|
canWithdraw: true,
|
|
37304
37315
|
withdrawer: pending[0].withdrawer,
|
|
37316
|
+
recipient: req.recipient,
|
|
37305
37317
|
token: pending[0].token,
|
|
37306
37318
|
amount: pending[0].amount,
|
|
37307
37319
|
timeoutStart: pending[0].timestamp.toNumber(),
|
|
@@ -37327,10 +37339,38 @@ class TokenBridge {
|
|
|
37327
37339
|
*/
|
|
37328
37340
|
async getTokenMapping(req) {
|
|
37329
37341
|
// eslint-disable-next-line no-console
|
|
37330
|
-
|
|
37342
|
+
if (req.rootToken.toUpperCase() === 'NATIVE'
|
|
37343
|
+
|| req.rootToken === this.config.bridgeContracts.rootChainWrappedETH) {
|
|
37344
|
+
const childBridge = await withBridgeError(async () => {
|
|
37345
|
+
const contract = new Contract(this.config.bridgeContracts.childERC20Bridge, CHILD_ERC20_BRIDGE, this.config.childProvider);
|
|
37346
|
+
return contract;
|
|
37347
|
+
}, BridgeErrorType.INTERNAL_ERROR);
|
|
37348
|
+
const childETHToken = await childBridge.childETHToken();
|
|
37349
|
+
return {
|
|
37350
|
+
rootToken: req.rootToken,
|
|
37351
|
+
childToken: childETHToken,
|
|
37352
|
+
};
|
|
37353
|
+
}
|
|
37354
|
+
const rootBridge = await withBridgeError(async () => {
|
|
37355
|
+
const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
|
|
37356
|
+
return contract;
|
|
37357
|
+
}, BridgeErrorType.INTERNAL_ERROR);
|
|
37358
|
+
const rootTokenChildAddress = await rootBridge.rootTokenToChildToken(req.rootToken);
|
|
37359
|
+
if (rootTokenChildAddress === AddressZero) {
|
|
37360
|
+
return {
|
|
37361
|
+
rootToken: req.rootToken,
|
|
37362
|
+
childToken: null,
|
|
37363
|
+
};
|
|
37364
|
+
}
|
|
37365
|
+
if (rootTokenChildAddress === req.rootToken) {
|
|
37366
|
+
return {
|
|
37367
|
+
rootToken: req.rootToken,
|
|
37368
|
+
childToken: 'NATIVE',
|
|
37369
|
+
};
|
|
37370
|
+
}
|
|
37331
37371
|
return {
|
|
37332
|
-
rootToken:
|
|
37333
|
-
childToken:
|
|
37372
|
+
rootToken: req.rootToken,
|
|
37373
|
+
childToken: rootTokenChildAddress,
|
|
37334
37374
|
};
|
|
37335
37375
|
}
|
|
37336
37376
|
}
|
|
@@ -41256,12 +41296,14 @@ const validateProviderDefaults = {
|
|
|
41256
41296
|
* @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
|
|
41257
41297
|
* @property {string} FAILED - If checkout failed due to transactions not settling on chain
|
|
41258
41298
|
* @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
|
|
41299
|
+
* @property {string} FULFILLMENTS_UNSETTLED - If checkout succeeded but the fulfillment transactions are not yet settled
|
|
41259
41300
|
*/
|
|
41260
41301
|
var CheckoutStatus;
|
|
41261
41302
|
(function (CheckoutStatus) {
|
|
41262
41303
|
CheckoutStatus["SUCCESS"] = "SUCCESS";
|
|
41263
41304
|
CheckoutStatus["FAILED"] = "FAILED";
|
|
41264
41305
|
CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
41306
|
+
CheckoutStatus["FULFILLMENTS_UNSETTLED"] = "FULFILLMENTS_UNSETTLED";
|
|
41265
41307
|
})(CheckoutStatus || (CheckoutStatus = {}));
|
|
41266
41308
|
/**
|
|
41267
41309
|
* An enum representing the item types
|
|
@@ -41572,7 +41614,7 @@ async function switchWalletNetwork(config, web3Provider, chainId) {
|
|
|
41572
41614
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
41573
41615
|
}
|
|
41574
41616
|
catch (err) {
|
|
41575
|
-
throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
41617
|
+
throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, { error: err });
|
|
41576
41618
|
}
|
|
41577
41619
|
}
|
|
41578
41620
|
else {
|
|
@@ -41936,7 +41978,7 @@ const GAS_OVERRIDES = {
|
|
|
41936
41978
|
maxPriorityFeePerGas: BigNumber$1.from(101e9),
|
|
41937
41979
|
};
|
|
41938
41980
|
|
|
41939
|
-
const SDK_VERSION_MARKER = '0.44.
|
|
41981
|
+
const SDK_VERSION_MARKER = '0.44.3';
|
|
41940
41982
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
41941
41983
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
41942
41984
|
|
|
@@ -41966,8 +42008,8 @@ class RemoteConfigFetcher {
|
|
|
41966
42008
|
try {
|
|
41967
42009
|
responseData = JSON.parse(response.data);
|
|
41968
42010
|
}
|
|
41969
|
-
catch (
|
|
41970
|
-
throw new CheckoutError('Invalid configuration', CheckoutErrorType.API_ERROR);
|
|
42011
|
+
catch (err) {
|
|
42012
|
+
throw new CheckoutError('Invalid configuration', CheckoutErrorType.API_ERROR, { error: err });
|
|
41971
42013
|
}
|
|
41972
42014
|
}
|
|
41973
42015
|
return responseData;
|
|
@@ -41980,7 +42022,7 @@ class RemoteConfigFetcher {
|
|
|
41980
42022
|
response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
|
|
41981
42023
|
}
|
|
41982
42024
|
catch (err) {
|
|
41983
|
-
throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR);
|
|
42025
|
+
throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR, { error: err });
|
|
41984
42026
|
}
|
|
41985
42027
|
// Ensure that the configuration is valid
|
|
41986
42028
|
this.configCache = this.parseResponse(response);
|
|
@@ -41994,7 +42036,7 @@ class RemoteConfigFetcher {
|
|
|
41994
42036
|
response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
|
|
41995
42037
|
}
|
|
41996
42038
|
catch (err) {
|
|
41997
|
-
throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR);
|
|
42039
|
+
throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR, { error: err });
|
|
41998
42040
|
}
|
|
41999
42041
|
// Ensure that the configuration is valid
|
|
42000
42042
|
this.tokensCache = this.parseResponse(response);
|
|
@@ -42357,7 +42399,7 @@ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) =
|
|
|
42357
42399
|
// means we are safe to assume that a 404 is a missing wallet due to inactivity
|
|
42358
42400
|
// or simply an incorrect wallet address was provided.
|
|
42359
42401
|
if (err?.code !== HttpStatusCode$3.NotFound) {
|
|
42360
|
-
throw new CheckoutError(err.message || 'InternalServerError | getTokensByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, err);
|
|
42402
|
+
throw new CheckoutError(err.message || 'InternalServerError | getTokensByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, { error: err });
|
|
42361
42403
|
}
|
|
42362
42404
|
}
|
|
42363
42405
|
};
|
|
@@ -42376,7 +42418,7 @@ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) =
|
|
|
42376
42418
|
// means we are safe to assume that a 404 is a missing wallet due to inactivity
|
|
42377
42419
|
// or simply an incorrect wallet address was provided.
|
|
42378
42420
|
if (err?.code !== HttpStatusCode$3.NotFound) {
|
|
42379
|
-
throw new CheckoutError(err.message || 'InternalServerError | getNativeTokenByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, err);
|
|
42421
|
+
throw new CheckoutError(err.message || 'InternalServerError | getNativeTokenByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, { error: err });
|
|
42380
42422
|
}
|
|
42381
42423
|
}
|
|
42382
42424
|
};
|
|
@@ -42489,6 +42531,7 @@ async function checkIsWalletConnected(web3Provider) {
|
|
|
42489
42531
|
}
|
|
42490
42532
|
catch (err) {
|
|
42491
42533
|
throw new CheckoutError('Check wallet connection request failed', CheckoutErrorType.PROVIDER_REQUEST_FAILED_ERROR, {
|
|
42534
|
+
error: err,
|
|
42492
42535
|
rpcMethod: WalletAction.CHECK_CONNECTION,
|
|
42493
42536
|
});
|
|
42494
42537
|
}
|
|
@@ -42581,7 +42624,7 @@ async function validateProvider(config, web3Provider, validateProviderOptions) {
|
|
|
42581
42624
|
}
|
|
42582
42625
|
}
|
|
42583
42626
|
catch (err) {
|
|
42584
|
-
throw new CheckoutError('Unable to detect the web3Provider network', CheckoutErrorType.WEB3_PROVIDER_ERROR);
|
|
42627
|
+
throw new CheckoutError('Unable to detect the web3Provider network', CheckoutErrorType.WEB3_PROVIDER_ERROR, { error: err });
|
|
42585
42628
|
}
|
|
42586
42629
|
if (web3ChainId !== underlyingChainId && !options.allowMistmatchedChainId) {
|
|
42587
42630
|
throw new CheckoutError('Your wallet has changed network, please switch to a supported network', CheckoutErrorType.WEB3_PROVIDER_ERROR);
|
|
@@ -42633,15 +42676,15 @@ const sendTransaction = async (web3Provider, transaction) => {
|
|
|
42633
42676
|
}
|
|
42634
42677
|
catch (err) {
|
|
42635
42678
|
if (err.code === ethers.errors.INSUFFICIENT_FUNDS) {
|
|
42636
|
-
throw new CheckoutError(err.message, CheckoutErrorType.INSUFFICIENT_FUNDS);
|
|
42679
|
+
throw new CheckoutError(err.message, CheckoutErrorType.INSUFFICIENT_FUNDS, { error: err });
|
|
42637
42680
|
}
|
|
42638
42681
|
if (err.code === ethers.errors.ACTION_REJECTED) {
|
|
42639
|
-
throw new CheckoutError(err.message, CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
42682
|
+
throw new CheckoutError(err.message, CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, { error: err });
|
|
42640
42683
|
}
|
|
42641
42684
|
if (err.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
|
|
42642
|
-
throw new CheckoutError(err.message, CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT);
|
|
42685
|
+
throw new CheckoutError(err.message, CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, { error: err });
|
|
42643
42686
|
}
|
|
42644
|
-
throw new CheckoutError(err.message, CheckoutErrorType.TRANSACTION_FAILED);
|
|
42687
|
+
throw new CheckoutError(err.message, CheckoutErrorType.TRANSACTION_FAILED, { error: err });
|
|
42645
42688
|
}
|
|
42646
42689
|
};
|
|
42647
42690
|
|
|
@@ -42654,6 +42697,8 @@ async function getBridgeFeeEstimate$1(tokenBridge, fromChainId, toChainId, confi
|
|
|
42654
42697
|
gasMultiplier: 1.1,
|
|
42655
42698
|
sourceChainId: fromChainId.toString(),
|
|
42656
42699
|
destinationChainId: toChainId.toString(),
|
|
42700
|
+
token: NATIVE.toUpperCase(),
|
|
42701
|
+
amount: BigNumber$1.from(0),
|
|
42657
42702
|
});
|
|
42658
42703
|
}
|
|
42659
42704
|
|
|
@@ -42733,6 +42778,7 @@ async function bridgeToL2GasEstimator(readOnlyProviders, config) {
|
|
|
42733
42778
|
gasEstimateType: GasEstimateType.BRIDGE_TO_L2,
|
|
42734
42779
|
fees: {
|
|
42735
42780
|
sourceChainGas: BigNumber$1.from(0),
|
|
42781
|
+
approvalFee: BigNumber$1.from(0),
|
|
42736
42782
|
bridgeFee: BigNumber$1.from(0),
|
|
42737
42783
|
imtblFee: BigNumber$1.from(0),
|
|
42738
42784
|
totalFees: BigNumber$1.from(0),
|
|
@@ -42882,7 +42928,7 @@ const getERC20Allowance = async (provider, ownerAddress, contractAddress, spende
|
|
|
42882
42928
|
return await contract.allowance(ownerAddress, spenderAddress);
|
|
42883
42929
|
}
|
|
42884
42930
|
catch (err) {
|
|
42885
|
-
throw new CheckoutError('Failed to get the allowance for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress });
|
|
42931
|
+
throw new CheckoutError('Failed to get the allowance for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress, error: err });
|
|
42886
42932
|
}
|
|
42887
42933
|
};
|
|
42888
42934
|
// Returns the approval transaction for the ERC20 that the owner can sign
|
|
@@ -42895,8 +42941,8 @@ const getERC20ApprovalTransaction = async (provider, ownerAddress, contractAddre
|
|
|
42895
42941
|
approveTransaction.from = ownerAddress;
|
|
42896
42942
|
return approveTransaction;
|
|
42897
42943
|
}
|
|
42898
|
-
catch {
|
|
42899
|
-
throw new CheckoutError('Failed to get the approval transaction for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress });
|
|
42944
|
+
catch (err) {
|
|
42945
|
+
throw new CheckoutError('Failed to get the approval transaction for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress, error: err });
|
|
42900
42946
|
}
|
|
42901
42947
|
};
|
|
42902
42948
|
const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
|
|
@@ -42968,7 +43014,12 @@ const getERC721ApprovedForAll = async (provider, ownerAddress, contractAddress,
|
|
|
42968
43014
|
return await contract.isApprovedForAll(ownerAddress, spenderAddress);
|
|
42969
43015
|
}
|
|
42970
43016
|
catch (err) {
|
|
42971
|
-
throw new CheckoutError('Failed to check approval for all ERC721s of collection', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
|
|
43017
|
+
throw new CheckoutError('Failed to check approval for all ERC721s of collection', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
|
|
43018
|
+
ownerAddress,
|
|
43019
|
+
contractAddress,
|
|
43020
|
+
spenderAddress,
|
|
43021
|
+
error: err,
|
|
43022
|
+
});
|
|
42972
43023
|
}
|
|
42973
43024
|
};
|
|
42974
43025
|
// Returns a populated transaction to approve the ERC721 for the spender.
|
|
@@ -42982,7 +43033,11 @@ const getApproveTransaction = async (provider, ownerAddress, contractAddress, sp
|
|
|
42982
43033
|
}
|
|
42983
43034
|
catch (err) {
|
|
42984
43035
|
throw new CheckoutError('Failed to get the approval transaction for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
|
|
42985
|
-
id: id.toString(),
|
|
43036
|
+
id: id.toString(),
|
|
43037
|
+
contractAddress,
|
|
43038
|
+
spenderAddress,
|
|
43039
|
+
ownerAddress,
|
|
43040
|
+
error: err,
|
|
42986
43041
|
});
|
|
42987
43042
|
}
|
|
42988
43043
|
};
|
|
@@ -42994,7 +43049,11 @@ const getERC721ApprovedAddress = async (provider, contractAddress, id) => {
|
|
|
42994
43049
|
return await contract.getApproved(id);
|
|
42995
43050
|
}
|
|
42996
43051
|
catch (err) {
|
|
42997
|
-
throw new CheckoutError('Failed to get approved address for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
|
|
43052
|
+
throw new CheckoutError('Failed to get approved address for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
|
|
43053
|
+
id: id.toString(),
|
|
43054
|
+
contractAddress,
|
|
43055
|
+
error: err,
|
|
43056
|
+
});
|
|
42998
43057
|
}
|
|
42999
43058
|
};
|
|
43000
43059
|
const convertIdToNumber = (id, contractAddress) => {
|
|
@@ -43322,8 +43381,8 @@ const getTokenBalances = async (config, provider, ownerAddress, itemRequirements
|
|
|
43322
43381
|
const { balances } = await getAllBalances(config, provider, ownerAddress, getL2ChainId(config));
|
|
43323
43382
|
return balances.filter((balance) => tokenMap.get((balance.token.address || NATIVE).toLocaleLowerCase()));
|
|
43324
43383
|
}
|
|
43325
|
-
catch (
|
|
43326
|
-
throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR);
|
|
43384
|
+
catch (err) {
|
|
43385
|
+
throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR, { error: err });
|
|
43327
43386
|
}
|
|
43328
43387
|
};
|
|
43329
43388
|
/**
|
|
@@ -43361,8 +43420,8 @@ const getERC721Balances = async (provider, ownerAddress, itemRequirements) => {
|
|
|
43361
43420
|
});
|
|
43362
43421
|
});
|
|
43363
43422
|
}
|
|
43364
|
-
catch (
|
|
43365
|
-
throw new CheckoutError('Failed to get ERC721 balances', CheckoutErrorType.GET_ERC721_BALANCE_ERROR);
|
|
43423
|
+
catch (err) {
|
|
43424
|
+
throw new CheckoutError('Failed to get ERC721 balances', CheckoutErrorType.GET_ERC721_BALANCE_ERROR, { error: err });
|
|
43366
43425
|
}
|
|
43367
43426
|
return erc721Balances;
|
|
43368
43427
|
};
|
|
@@ -43432,7 +43491,7 @@ const estimateGas = async (provider, transaction) => {
|
|
|
43432
43491
|
return await provider.estimateGas(transaction);
|
|
43433
43492
|
}
|
|
43434
43493
|
catch (err) {
|
|
43435
|
-
throw new CheckoutError('Failed to estimate gas for transaction', CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT);
|
|
43494
|
+
throw new CheckoutError('Failed to estimate gas for transaction', CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, { error: err });
|
|
43436
43495
|
}
|
|
43437
43496
|
};
|
|
43438
43497
|
const getGasItemRequirement = (gas, transactionOrGas) => {
|
|
@@ -43496,14 +43555,14 @@ const availabilityService = (isDevelopment, isProduction) => {
|
|
|
43496
43555
|
try {
|
|
43497
43556
|
response = await globalAxios$1.post(`${postEndpoint()}/v1/availability/checkout/swap`);
|
|
43498
43557
|
}
|
|
43499
|
-
catch (
|
|
43558
|
+
catch (err) {
|
|
43500
43559
|
// The request was made and the server responded with a status code
|
|
43501
43560
|
// that falls out of the range of 2xx
|
|
43502
|
-
response =
|
|
43561
|
+
response = err.response;
|
|
43503
43562
|
// If 403 then the service is geo-blocked
|
|
43504
43563
|
if (response.status === 403)
|
|
43505
43564
|
return false;
|
|
43506
|
-
throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
43565
|
+
throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR, { error: err });
|
|
43507
43566
|
}
|
|
43508
43567
|
return true;
|
|
43509
43568
|
};
|
|
@@ -44014,7 +44073,7 @@ const getBridgeFeeEstimate = async (config, readOnlyProviders, fromChainId, toCh
|
|
|
44014
44073
|
};
|
|
44015
44074
|
}
|
|
44016
44075
|
catch (err) {
|
|
44017
|
-
throw new CheckoutError('Error estimating gas for bridge', CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
44076
|
+
throw new CheckoutError('Error estimating gas for bridge', CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR, { error: err });
|
|
44018
44077
|
}
|
|
44019
44078
|
};
|
|
44020
44079
|
|
|
@@ -44664,7 +44723,7 @@ const routingCalculator = async (config, ownerAddress, balanceRequirements, avai
|
|
|
44664
44723
|
readOnlyProviders = await createReadOnlyProviders(config);
|
|
44665
44724
|
}
|
|
44666
44725
|
catch (err) {
|
|
44667
|
-
throw new CheckoutError('Error occurred while creating read only providers', CheckoutErrorType.PROVIDER_ERROR, {
|
|
44726
|
+
throw new CheckoutError('Error occurred while creating read only providers', CheckoutErrorType.PROVIDER_ERROR, { error: err });
|
|
44668
44727
|
}
|
|
44669
44728
|
const tokenBalances = await measureAsyncExecution(config, 'Time to get token balances inside router', getAllTokenBalances(config, readOnlyProviders, ownerAddress, availableRoutingOptions));
|
|
44670
44729
|
const allowList = await measureAsyncExecution(config, 'Time to get routing allowlist', allowListCheck(config, tokenBalances, availableRoutingOptions));
|
|
@@ -44787,9 +44846,7 @@ const signApprovalTransactions = async (provider, approvalTransactions) => {
|
|
|
44787
44846
|
receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
|
|
44788
44847
|
}
|
|
44789
44848
|
catch (err) {
|
|
44790
|
-
throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, {
|
|
44791
|
-
message: err.message,
|
|
44792
|
-
});
|
|
44849
|
+
throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, { error: err });
|
|
44793
44850
|
}
|
|
44794
44851
|
for (const receipt of receipts) {
|
|
44795
44852
|
if (receipt.status === 0) {
|
|
@@ -44811,9 +44868,7 @@ const signFulfillmentTransactions = async (provider, fulfillmentTransactions) =>
|
|
|
44811
44868
|
receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
|
|
44812
44869
|
}
|
|
44813
44870
|
catch (err) {
|
|
44814
|
-
throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
|
|
44815
|
-
message: err.message,
|
|
44816
|
-
});
|
|
44871
|
+
throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, { error: err });
|
|
44817
44872
|
}
|
|
44818
44873
|
for (const receipt of receipts) {
|
|
44819
44874
|
if (receipt.status === 0) {
|
|
@@ -44839,9 +44894,7 @@ const signMessage = async (provider, unsignedMessage) => {
|
|
|
44839
44894
|
};
|
|
44840
44895
|
}
|
|
44841
44896
|
catch (err) {
|
|
44842
|
-
throw new CheckoutError('An error occurred while signing the message', CheckoutErrorType.SIGN_MESSAGE_ERROR, {
|
|
44843
|
-
message: err.message,
|
|
44844
|
-
});
|
|
44897
|
+
throw new CheckoutError('An error occurred while signing the message', CheckoutErrorType.SIGN_MESSAGE_ERROR, { error: err });
|
|
44845
44898
|
}
|
|
44846
44899
|
};
|
|
44847
44900
|
|
|
@@ -44997,7 +45050,9 @@ const getTransactionOrGas = (gasLimit, fulfillmentTransactions) => {
|
|
|
44997
45050
|
},
|
|
44998
45051
|
};
|
|
44999
45052
|
};
|
|
45000
|
-
const buy = async (config, provider, orders
|
|
45053
|
+
const buy = async (config, provider, orders, overrides = {
|
|
45054
|
+
waitFulfillmentSettlements: true,
|
|
45055
|
+
}) => {
|
|
45001
45056
|
if (orders.length === 0) {
|
|
45002
45057
|
throw new CheckoutError('No orders were provided to the orders array. Please provide at least one order.', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR);
|
|
45003
45058
|
}
|
|
@@ -45022,8 +45077,8 @@ const buy = async (config, provider, orders) => {
|
|
|
45022
45077
|
}
|
|
45023
45078
|
catch (err) {
|
|
45024
45079
|
throw new CheckoutError('An error occurred while getting the order listing', CheckoutErrorType.GET_ORDER_LISTING_ERROR, {
|
|
45080
|
+
error: err,
|
|
45025
45081
|
orderId: id,
|
|
45026
|
-
message: err.message,
|
|
45027
45082
|
});
|
|
45028
45083
|
}
|
|
45029
45084
|
if (order.result.buy.length === 0) {
|
|
@@ -45062,7 +45117,7 @@ const buy = async (config, provider, orders) => {
|
|
|
45062
45117
|
if (!err.message.includes('The fulfiller does not have the balances needed to fulfill')) {
|
|
45063
45118
|
throw new CheckoutError('Error occurred while trying to fulfill the order', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, {
|
|
45064
45119
|
orderId: id,
|
|
45065
|
-
|
|
45120
|
+
error: err,
|
|
45066
45121
|
});
|
|
45067
45122
|
}
|
|
45068
45123
|
}
|
|
@@ -45121,22 +45176,37 @@ const buy = async (config, provider, orders) => {
|
|
|
45121
45176
|
}
|
|
45122
45177
|
}
|
|
45123
45178
|
catch (err) {
|
|
45124
|
-
throw new CheckoutError('Error fetching fulfillment transaction', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, {
|
|
45125
|
-
message: err.message,
|
|
45126
|
-
});
|
|
45179
|
+
throw new CheckoutError('Error fetching fulfillment transaction', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, { error: err });
|
|
45127
45180
|
}
|
|
45128
|
-
|
|
45129
|
-
|
|
45181
|
+
if (overrides.waitFulfillmentSettlements) {
|
|
45182
|
+
const fulfillmentResult = await signFulfillmentTransactions(provider, unsignedFulfillmentTransactions);
|
|
45183
|
+
if (fulfillmentResult.type === SignTransactionStatusType.FAILED) {
|
|
45184
|
+
return {
|
|
45185
|
+
status: CheckoutStatus.FAILED,
|
|
45186
|
+
transactionHash: fulfillmentResult.transactionHash,
|
|
45187
|
+
reason: fulfillmentResult.reason,
|
|
45188
|
+
smartCheckoutResult,
|
|
45189
|
+
};
|
|
45190
|
+
}
|
|
45130
45191
|
return {
|
|
45131
|
-
status: CheckoutStatus.
|
|
45132
|
-
transactionHash: fulfillmentResult.transactionHash,
|
|
45133
|
-
reason: fulfillmentResult.reason,
|
|
45192
|
+
status: CheckoutStatus.SUCCESS,
|
|
45134
45193
|
smartCheckoutResult,
|
|
45135
45194
|
};
|
|
45136
45195
|
}
|
|
45196
|
+
let transactions;
|
|
45197
|
+
try {
|
|
45198
|
+
const response = await Promise.all(unsignedFulfillmentTransactions.map((transaction) => sendTransaction(provider, transaction)));
|
|
45199
|
+
transactions = response.map((result) => result.transactionResponse);
|
|
45200
|
+
}
|
|
45201
|
+
catch (err) {
|
|
45202
|
+
throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
|
|
45203
|
+
message: err.message,
|
|
45204
|
+
});
|
|
45205
|
+
}
|
|
45137
45206
|
return {
|
|
45138
|
-
status: CheckoutStatus.
|
|
45207
|
+
status: CheckoutStatus.FULFILLMENTS_UNSETTLED,
|
|
45139
45208
|
smartCheckoutResult,
|
|
45209
|
+
transactions,
|
|
45140
45210
|
};
|
|
45141
45211
|
}
|
|
45142
45212
|
return {
|
|
@@ -45161,7 +45231,7 @@ const cancel = async (config, provider, orderIds) => {
|
|
|
45161
45231
|
catch (err) {
|
|
45162
45232
|
throw new CheckoutError('An error occurred while cancelling the order listing', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, {
|
|
45163
45233
|
orderId,
|
|
45164
|
-
|
|
45234
|
+
error: err,
|
|
45165
45235
|
});
|
|
45166
45236
|
}
|
|
45167
45237
|
const result = await signFulfillmentTransactions(provider, [unsignedCancelOrderTransaction]);
|
|
@@ -45230,7 +45300,7 @@ const sell = async (config, provider, orders) => {
|
|
|
45230
45300
|
}
|
|
45231
45301
|
catch (err) {
|
|
45232
45302
|
throw new CheckoutError('An error occurred while preparing the listing', CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR, {
|
|
45233
|
-
|
|
45303
|
+
error: err,
|
|
45234
45304
|
id: sellToken.id,
|
|
45235
45305
|
collectionAddress: sellToken.collectionAddress,
|
|
45236
45306
|
});
|
|
@@ -45286,7 +45356,7 @@ const sell = async (config, provider, orders) => {
|
|
|
45286
45356
|
}
|
|
45287
45357
|
catch (err) {
|
|
45288
45358
|
throw new CheckoutError('An error occurred while creating the listing', CheckoutErrorType.CREATE_ORDER_LISTING_ERROR, {
|
|
45289
|
-
|
|
45359
|
+
error: err,
|
|
45290
45360
|
collectionId: sellToken.id,
|
|
45291
45361
|
collectionAddress: sellToken.collectionAddress,
|
|
45292
45362
|
});
|
|
@@ -45583,7 +45653,7 @@ class Checkout {
|
|
|
45583
45653
|
}
|
|
45584
45654
|
}
|
|
45585
45655
|
catch (err) {
|
|
45586
|
-
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, {
|
|
45656
|
+
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
45587
45657
|
}
|
|
45588
45658
|
});
|
|
45589
45659
|
return factory;
|
|
@@ -45713,7 +45783,7 @@ class Checkout {
|
|
|
45713
45783
|
console.warn('This endpoint currently only processes the first order in the array.');
|
|
45714
45784
|
}
|
|
45715
45785
|
const web3Provider = await validateProvider(this.config, params.provider);
|
|
45716
|
-
return await buy(this.config, web3Provider, params.orders);
|
|
45786
|
+
return await buy(this.config, web3Provider, params.orders, params.overrides);
|
|
45717
45787
|
}
|
|
45718
45788
|
/**
|
|
45719
45789
|
* Determines the requirements for performing a sell.
|
|
@@ -45749,8 +45819,8 @@ class Checkout {
|
|
|
45749
45819
|
try {
|
|
45750
45820
|
itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements);
|
|
45751
45821
|
}
|
|
45752
|
-
catch (
|
|
45753
|
-
throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
|
|
45822
|
+
catch (err) {
|
|
45823
|
+
throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR, { error: err });
|
|
45754
45824
|
}
|
|
45755
45825
|
return await smartCheckout(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
|
|
45756
45826
|
}
|