@imtbl/sdk 0.16.0 → 0.17.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.
- package/dist/blockchain_data.d.ts +151 -26
- package/dist/blockchain_data.js +351 -33
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +236 -3
- package/dist/checkout_sdk.js +1139 -309
- package/dist/checkout_widgets.d.ts +1 -0
- package/dist/checkout_widgets.js +1 -1
- package/dist/erc721.d.ts +40 -0
- package/dist/erc721.js +173 -1
- package/dist/erc721_mint_by_id.d.ts +14 -0
- package/dist/erc721_mint_by_id.js +165 -19
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +15 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +1967 -489
- package/dist/index.d.ts +594 -18
- package/dist/index.js +1809 -331
- package/dist/orderbook.d.ts +150 -4
- package/dist/orderbook.js +135 -0
- package/dist/passport.d.ts +1 -0
- package/dist/passport.js +275 -12
- package/package.json +6 -2
package/dist/checkout_sdk.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants as constants$1 } from 'ethers';
|
|
2
2
|
import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
|
|
3
|
+
import $7v2Z6$axios, { HttpStatusCode } from 'axios';
|
|
3
4
|
import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
|
|
4
|
-
import { TradeType, Token,
|
|
5
|
+
import { TradeType, Token, CurrencyAmount, Percent } from '@uniswap/sdk-core';
|
|
5
6
|
import assert from 'assert';
|
|
6
|
-
import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
|
|
7
7
|
import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
|
|
8
8
|
import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
|
|
9
9
|
import { SwapRouter } from '@uniswap/router-sdk';
|
|
10
|
-
import axios from 'axios';
|
|
11
10
|
import FormData from 'form-data';
|
|
12
11
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
13
12
|
|
|
@@ -12492,38 +12491,6 @@ class AlreadyApprovedError extends ExchangeError {
|
|
|
12492
12491
|
}
|
|
12493
12492
|
}
|
|
12494
12493
|
|
|
12495
|
-
/**
|
|
12496
|
-
* Determines whether or not the chain supports EIP-1559 by checking for the existence
|
|
12497
|
-
* of {@link FeeData.maxFeePerGas} and {@link FeeData.maxPriorityFeePerGas}
|
|
12498
|
-
*
|
|
12499
|
-
* @param {FeeData} fee - The fee data for the chain
|
|
12500
|
-
*/
|
|
12501
|
-
const doesChainSupportEIP1559 = (fee) => {
|
|
12502
|
-
const supportsEIP1559 = !!fee.maxFeePerGas && !!fee.maxPriorityFeePerGas;
|
|
12503
|
-
return supportsEIP1559;
|
|
12504
|
-
};
|
|
12505
|
-
/**
|
|
12506
|
-
* Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
|
|
12507
|
-
* @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
|
|
12508
|
-
* @returns {BigNumber | null} - The gas price in the smallest denomination of the chain's currency,
|
|
12509
|
-
* or null if no gas price is available
|
|
12510
|
-
*/
|
|
12511
|
-
const fetchGasPrice = async (provider) => {
|
|
12512
|
-
const feeData = await provider.getFeeData().catch(() => null);
|
|
12513
|
-
if (!feeData) {
|
|
12514
|
-
return null;
|
|
12515
|
-
}
|
|
12516
|
-
return doesChainSupportEIP1559(feeData) ? feeData.maxFeePerGas.add(feeData.maxPriorityFeePerGas) : feeData.gasPrice;
|
|
12517
|
-
};
|
|
12518
|
-
/**
|
|
12519
|
-
* Calculate the gas fee from the gas price and gas units used for the transaction
|
|
12520
|
-
*
|
|
12521
|
-
* @param {BigNumber} gasPriceInWei - The price of gas in wei
|
|
12522
|
-
* @param {BigNumber} gasUsed - The total gas units that will be used for the transaction
|
|
12523
|
-
* @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
|
|
12524
|
-
*/
|
|
12525
|
-
const calculateGasFee = (gasPriceInWei, gasUsed) => gasUsed.mul(gasPriceInWei);
|
|
12526
|
-
|
|
12527
12494
|
/* Autogenerated file. Do not edit manually. */
|
|
12528
12495
|
/* tslint:disable */
|
|
12529
12496
|
/* eslint-disable */
|
|
@@ -12759,179 +12726,6 @@ class ERC20__factory {
|
|
|
12759
12726
|
}
|
|
12760
12727
|
}
|
|
12761
12728
|
|
|
12762
|
-
/**
|
|
12763
|
-
* Get the amount of an ERC20 token that needs to be approved by
|
|
12764
|
-
* checking the existing allowance for the spender
|
|
12765
|
-
*
|
|
12766
|
-
* @param provider - The provider to use for the call
|
|
12767
|
-
* @param ownerAddress - The address of the owner of the token
|
|
12768
|
-
* @param tokenAmount - The amount of the token to approve
|
|
12769
|
-
* @param spenderAddress - The address of the spender
|
|
12770
|
-
* @returns - The amount of the token that needs to be approved
|
|
12771
|
-
*/
|
|
12772
|
-
const getERC20AmountToApprove = async (provider, ownerAddress, tokenAddress, tokenAmount, spenderAddress) => {
|
|
12773
|
-
// create an instance of the ERC20 token contract
|
|
12774
|
-
const erc20Contract = ERC20__factory.connect(tokenAddress, provider);
|
|
12775
|
-
// get the allowance for the token spender
|
|
12776
|
-
// minimum is 0 - no allowance
|
|
12777
|
-
let allowance;
|
|
12778
|
-
try {
|
|
12779
|
-
allowance = await erc20Contract.allowance(ownerAddress, spenderAddress);
|
|
12780
|
-
}
|
|
12781
|
-
catch (e) {
|
|
12782
|
-
const message = e instanceof Error ? e.message : 'Unknown Error';
|
|
12783
|
-
throw new ApproveError(`failed to get allowance: ${message}`);
|
|
12784
|
-
}
|
|
12785
|
-
// get the amount that needs to be approved
|
|
12786
|
-
const requiredAmount = BigNumber$2.from(tokenAmount).sub(allowance);
|
|
12787
|
-
if (requiredAmount.isNegative() || requiredAmount.isZero()) {
|
|
12788
|
-
throw new AlreadyApprovedError(tokenAmount.toString(), tokenAddress, spenderAddress);
|
|
12789
|
-
}
|
|
12790
|
-
return requiredAmount;
|
|
12791
|
-
};
|
|
12792
|
-
/**
|
|
12793
|
-
* Get an unsigned ERC20 approve transaction
|
|
12794
|
-
*
|
|
12795
|
-
* @param ownerAddress - The address of the owner of the token
|
|
12796
|
-
* @param tokenAmount - The amount of the token to approve
|
|
12797
|
-
* @param spenderAddress - The address of the spender
|
|
12798
|
-
* @returns - The unsigned ERC20 approve transaction
|
|
12799
|
-
*/
|
|
12800
|
-
const getUnsignedERC20ApproveTransaction = (ownerAddress, tokenAddress, tokenAmount, spenderAddress) => {
|
|
12801
|
-
if (ownerAddress === spenderAddress) {
|
|
12802
|
-
throw new ApproveError('owner and spender addresses are the same');
|
|
12803
|
-
}
|
|
12804
|
-
const erc20Contract = ERC20__factory.createInterface();
|
|
12805
|
-
const callData = erc20Contract.encodeFunctionData('approve', [spenderAddress, tokenAmount]);
|
|
12806
|
-
return {
|
|
12807
|
-
data: callData,
|
|
12808
|
-
to: tokenAddress,
|
|
12809
|
-
value: 0,
|
|
12810
|
-
from: ownerAddress,
|
|
12811
|
-
};
|
|
12812
|
-
};
|
|
12813
|
-
const prepareApproval = (tradeType, amountSpecified, amountWithSlippage, routingContracts, secondaryFees) => {
|
|
12814
|
-
const amount = tradeType === TradeType.EXACT_INPUT ? amountSpecified : amountWithSlippage;
|
|
12815
|
-
const spender = secondaryFees.length === 0
|
|
12816
|
-
? routingContracts.peripheryRouterAddress
|
|
12817
|
-
: routingContracts.secondaryFeeAddress;
|
|
12818
|
-
return { spender, amount };
|
|
12819
|
-
};
|
|
12820
|
-
/**
|
|
12821
|
-
* Get an unsigned approval transaction if needed
|
|
12822
|
-
*
|
|
12823
|
-
* @param provider The provider to use for the call
|
|
12824
|
-
* @param ownerAddress The address of the owner of the token
|
|
12825
|
-
* @param tokenAddress The address of the token to approve
|
|
12826
|
-
* @param tokenAmount The amount of the token to approve
|
|
12827
|
-
* @param spenderAddress The address of the spender
|
|
12828
|
-
* @returns The unsigned ERC20 approve transaction, or null if no approval is needed
|
|
12829
|
-
*/
|
|
12830
|
-
const getApproveTransaction = async (provider, ownerAddress, tokenAddress, tokenAmount, spenderAddress) => {
|
|
12831
|
-
let amountToApprove;
|
|
12832
|
-
try {
|
|
12833
|
-
amountToApprove = await getERC20AmountToApprove(provider, ownerAddress, tokenAddress, BigNumber$2.from(tokenAmount), spenderAddress);
|
|
12834
|
-
}
|
|
12835
|
-
catch (e) {
|
|
12836
|
-
if (e instanceof AlreadyApprovedError) {
|
|
12837
|
-
// already approved for the required amount, nothing to do
|
|
12838
|
-
return null;
|
|
12839
|
-
}
|
|
12840
|
-
throw e;
|
|
12841
|
-
}
|
|
12842
|
-
return getUnsignedERC20ApproveTransaction(ownerAddress, tokenAddress, amountToApprove, spenderAddress);
|
|
12843
|
-
};
|
|
12844
|
-
async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tokenAddress) {
|
|
12845
|
-
const erc20Contract = ERC20__factory.connect(tokenAddress, provider);
|
|
12846
|
-
return await erc20Contract.estimateGas.approve(spenderAddress, ethers.constants.MaxUint256, {
|
|
12847
|
-
from: ownerAddress,
|
|
12848
|
-
});
|
|
12849
|
-
}
|
|
12850
|
-
const getApproval = async (nativeToken, provider, ownerAddress, tokenAddress, preparedApproval, gasPrice) => {
|
|
12851
|
-
const approveTransaction = await getApproveTransaction(provider, ownerAddress, tokenAddress, preparedApproval.amount, preparedApproval.spender);
|
|
12852
|
-
if (!approveTransaction) {
|
|
12853
|
-
return null;
|
|
12854
|
-
}
|
|
12855
|
-
const gasEstimate = await getApproveGasEstimate(provider, ownerAddress, preparedApproval.spender, tokenAddress);
|
|
12856
|
-
const gasFeeEstimate = gasPrice ? {
|
|
12857
|
-
token: nativeToken,
|
|
12858
|
-
value: calculateGasFee(gasPrice, gasEstimate),
|
|
12859
|
-
} : null;
|
|
12860
|
-
return {
|
|
12861
|
-
transaction: approveTransaction,
|
|
12862
|
-
gasFeeEstimate,
|
|
12863
|
-
};
|
|
12864
|
-
};
|
|
12865
|
-
|
|
12866
|
-
// slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
|
|
12867
|
-
// converts it to the Uniswap equivalent type
|
|
12868
|
-
const slippageToFraction = (slippage) => {
|
|
12869
|
-
// If we receive a whole number, we can return slippage/100
|
|
12870
|
-
const noDecimals = slippage.toString().split('.').length === 1;
|
|
12871
|
-
if (noDecimals) {
|
|
12872
|
-
return new Percent(slippage, 100);
|
|
12873
|
-
}
|
|
12874
|
-
// Divide the slippage number by 100 to get the decimal
|
|
12875
|
-
const slippageDecimal = slippage / 100;
|
|
12876
|
-
// Split into two parts by the decimal place
|
|
12877
|
-
const parts = slippageDecimal.toString().split('.');
|
|
12878
|
-
// Get the numerator by adding the two parts together
|
|
12879
|
-
const numerator = parts[0] + parts[1];
|
|
12880
|
-
// Get the denominator by multiplying decimals^10
|
|
12881
|
-
const denominator = 10 ** parts[1].length;
|
|
12882
|
-
return new Percent(numerator, denominator);
|
|
12883
|
-
};
|
|
12884
|
-
|
|
12885
|
-
function getQuoteAmountFromTradeType(tradeInfo) {
|
|
12886
|
-
if (tradeInfo.tradeType === TradeType.EXACT_INPUT) {
|
|
12887
|
-
return tradeInfo.amountOut;
|
|
12888
|
-
}
|
|
12889
|
-
return tradeInfo.amountIn;
|
|
12890
|
-
}
|
|
12891
|
-
function applySlippage(tradeType, amount, slippage) {
|
|
12892
|
-
const slippageTolerance = slippageToFraction(slippage);
|
|
12893
|
-
const slippagePlusOne = slippageTolerance.add(1);
|
|
12894
|
-
const maybeInverted = tradeType === TradeType.EXACT_INPUT ? slippagePlusOne.invert() : slippagePlusOne;
|
|
12895
|
-
const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
|
|
12896
|
-
return ethers.BigNumber.from(amountWithSlippage.toString());
|
|
12897
|
-
}
|
|
12898
|
-
function prepareUserQuote(otherToken, tradeInfo, slippage, fees) {
|
|
12899
|
-
const quote = getQuoteAmountFromTradeType(tradeInfo);
|
|
12900
|
-
const amountWithSlippage = applySlippage(tradeInfo.tradeType, quote.value, slippage);
|
|
12901
|
-
return {
|
|
12902
|
-
amount: quote,
|
|
12903
|
-
amountWithMaxSlippage: {
|
|
12904
|
-
token: otherToken,
|
|
12905
|
-
value: amountWithSlippage,
|
|
12906
|
-
},
|
|
12907
|
-
slippage,
|
|
12908
|
-
fees: fees.withAmounts(),
|
|
12909
|
-
};
|
|
12910
|
-
}
|
|
12911
|
-
function getOurQuoteReqAmount(amount, fees, tradeType) {
|
|
12912
|
-
if (tradeType === TradeType.EXACT_OUTPUT) {
|
|
12913
|
-
// For an exact output swap, we do not need to subtract fees from the given amount
|
|
12914
|
-
return amount;
|
|
12915
|
-
}
|
|
12916
|
-
fees.addAmount(amount);
|
|
12917
|
-
return fees.amountLessFees();
|
|
12918
|
-
}
|
|
12919
|
-
|
|
12920
|
-
// 0.1% default slippage
|
|
12921
|
-
const DEFAULT_SLIPPAGE = 0.1;
|
|
12922
|
-
// 15 minutes from the current Unix time
|
|
12923
|
-
const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
|
|
12924
|
-
// most swaps will be able to resolve with 2 hops
|
|
12925
|
-
const DEFAULT_MAX_HOPS = 2;
|
|
12926
|
-
// after 10 hops, it is very unlikely a route will be available
|
|
12927
|
-
const MAX_MAX_HOPS = 10;
|
|
12928
|
-
// a max hop of 1 will require a direct swap with no intermediary pools
|
|
12929
|
-
const MIN_MAX_HOPS = 1;
|
|
12930
|
-
// precision used to calculate percentage from basis points
|
|
12931
|
-
const BASIS_POINT_PRECISION = 10000;
|
|
12932
|
-
// 10% maximum secondary fee
|
|
12933
|
-
const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
|
|
12934
|
-
|
|
12935
12729
|
/* Autogenerated file. Do not edit manually. */
|
|
12936
12730
|
/* tslint:disable */
|
|
12937
12731
|
/* eslint-disable */
|
|
@@ -15224,40 +15018,246 @@ startTokenIn = tokenIn) => {
|
|
|
15224
15018
|
return routes;
|
|
15225
15019
|
};
|
|
15226
15020
|
|
|
15227
|
-
|
|
15228
|
-
|
|
15229
|
-
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15021
|
+
/**
|
|
15022
|
+
* Determines whether or not the chain supports EIP-1559 by checking for the existence
|
|
15023
|
+
* of {@link FeeData.maxFeePerGas} and {@link FeeData.maxPriorityFeePerGas}
|
|
15024
|
+
*
|
|
15025
|
+
* @param {FeeData} fee - The fee data for the chain
|
|
15026
|
+
*/
|
|
15027
|
+
const doesChainSupportEIP1559 = (fee) => {
|
|
15028
|
+
const supportsEIP1559 = !!fee.maxFeePerGas && !!fee.maxPriorityFeePerGas;
|
|
15029
|
+
return supportsEIP1559;
|
|
15030
|
+
};
|
|
15031
|
+
/**
|
|
15032
|
+
* Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
|
|
15033
|
+
* @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
|
|
15034
|
+
* @returns {Amount | null} - The gas price in the smallest denomination of the chain's currency,
|
|
15035
|
+
* or null if no gas price is available
|
|
15036
|
+
*/
|
|
15037
|
+
const fetchGasPrice = async (provider, nativeToken) => {
|
|
15038
|
+
const feeData = await provider.getFeeData().catch(() => null);
|
|
15039
|
+
if (!feeData)
|
|
15040
|
+
return null;
|
|
15041
|
+
if (doesChainSupportEIP1559(feeData)) {
|
|
15042
|
+
return newAmount(feeData.maxFeePerGas.add(feeData.maxPriorityFeePerGas), nativeToken);
|
|
15236
15043
|
}
|
|
15237
|
-
|
|
15238
|
-
|
|
15044
|
+
return feeData.gasPrice ? newAmount(feeData.gasPrice, nativeToken) : null;
|
|
15045
|
+
};
|
|
15046
|
+
/**
|
|
15047
|
+
* Calculate the gas fee from the gas price and gas units used for the transaction
|
|
15048
|
+
*
|
|
15049
|
+
* @param {Amount} gasPriceInWei - The price of gas
|
|
15050
|
+
* @param {BigNumber} gasUsed - The total gas units that will be used for the transaction
|
|
15051
|
+
* @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
|
|
15052
|
+
*/
|
|
15053
|
+
const calculateGasFee = (gasPrice, gasEstimate) =>
|
|
15054
|
+
// eslint-disable-next-line implicit-arrow-linebreak
|
|
15055
|
+
newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
|
|
15056
|
+
|
|
15057
|
+
/**
|
|
15058
|
+
* Get the amount of an ERC20 token that needs to be approved by
|
|
15059
|
+
* checking the existing allowance for the spender
|
|
15060
|
+
*
|
|
15061
|
+
* @param provider - The provider to use for the call
|
|
15062
|
+
* @param ownerAddress - The address of the owner of the token
|
|
15063
|
+
* @param tokenAmount - The amount of the token to approve
|
|
15064
|
+
* @param spenderAddress - The address of the spender
|
|
15065
|
+
* @returns - The amount of the token that needs to be approved
|
|
15066
|
+
*/
|
|
15067
|
+
const getERC20AmountToApprove = async (provider, ownerAddress, tokenAmount, spenderAddress) => {
|
|
15068
|
+
// create an instance of the ERC20 token contract
|
|
15069
|
+
const erc20Contract = ERC20__factory.connect(tokenAmount.token.address, provider);
|
|
15070
|
+
// get the allowance for the token spender
|
|
15071
|
+
// minimum is 0 - no allowance
|
|
15072
|
+
let allowance;
|
|
15073
|
+
try {
|
|
15074
|
+
allowance = await erc20Contract.allowance(ownerAddress, spenderAddress);
|
|
15239
15075
|
}
|
|
15240
|
-
|
|
15241
|
-
|
|
15076
|
+
catch (e) {
|
|
15077
|
+
const message = e instanceof Error ? e.message : 'Unknown Error';
|
|
15078
|
+
throw new ApproveError(`failed to get allowance: ${message}`);
|
|
15242
15079
|
}
|
|
15243
|
-
|
|
15244
|
-
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
.div(BASIS_POINT_PRECISION);
|
|
15248
|
-
return {
|
|
15249
|
-
...fee,
|
|
15250
|
-
amount: newAmount(feeAmount, this.amount.token),
|
|
15251
|
-
};
|
|
15252
|
-
});
|
|
15080
|
+
// get the amount that needs to be approved
|
|
15081
|
+
const requiredAmount = tokenAmount.value.sub(allowance);
|
|
15082
|
+
if (requiredAmount.isNegative() || requiredAmount.isZero()) {
|
|
15083
|
+
throw new AlreadyApprovedError(tokenAmount.toString(), tokenAmount.token.address, spenderAddress);
|
|
15253
15084
|
}
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
|
|
15257
|
-
|
|
15258
|
-
|
|
15259
|
-
|
|
15260
|
-
|
|
15085
|
+
return newAmount(requiredAmount, tokenAmount.token);
|
|
15086
|
+
};
|
|
15087
|
+
/**
|
|
15088
|
+
* Get an unsigned ERC20 approve transaction
|
|
15089
|
+
*
|
|
15090
|
+
* @param ownerAddress - The address of the owner of the token
|
|
15091
|
+
* @param tokenAmount - The amount of the token to approve
|
|
15092
|
+
* @param spenderAddress - The address of the spender
|
|
15093
|
+
* @returns - The unsigned ERC20 approve transaction
|
|
15094
|
+
*/
|
|
15095
|
+
const getUnsignedERC20ApproveTransaction = (ownerAddress, tokenAmount, spenderAddress) => {
|
|
15096
|
+
if (ownerAddress === spenderAddress) {
|
|
15097
|
+
throw new ApproveError('owner and spender addresses are the same');
|
|
15098
|
+
}
|
|
15099
|
+
const erc20Contract = ERC20__factory.createInterface();
|
|
15100
|
+
const callData = erc20Contract.encodeFunctionData('approve', [spenderAddress, tokenAmount.value]);
|
|
15101
|
+
return {
|
|
15102
|
+
data: callData,
|
|
15103
|
+
to: tokenAmount.token.address,
|
|
15104
|
+
value: 0,
|
|
15105
|
+
from: ownerAddress,
|
|
15106
|
+
};
|
|
15107
|
+
};
|
|
15108
|
+
const prepareApproval = (tradeType, amountSpecified, amountWithSlippage, routingContracts, secondaryFees) => {
|
|
15109
|
+
const amountOfTokenIn = tradeType === TradeType.EXACT_INPUT ? amountSpecified : amountWithSlippage;
|
|
15110
|
+
const spender = secondaryFees.length === 0
|
|
15111
|
+
? routingContracts.peripheryRouterAddress
|
|
15112
|
+
: routingContracts.secondaryFeeAddress;
|
|
15113
|
+
return { spender, amount: amountOfTokenIn };
|
|
15114
|
+
};
|
|
15115
|
+
/**
|
|
15116
|
+
* Get an unsigned approval transaction if needed
|
|
15117
|
+
*
|
|
15118
|
+
* @param provider The provider to use for the call
|
|
15119
|
+
* @param ownerAddress The address of the owner of the token
|
|
15120
|
+
* @param tokenAddress The address of the token to approve
|
|
15121
|
+
* @param tokenAmount The amount of the token to approve
|
|
15122
|
+
* @param spenderAddress The address of the spender
|
|
15123
|
+
* @returns The unsigned ERC20 approve transaction, or null if no approval is needed
|
|
15124
|
+
*/
|
|
15125
|
+
const getApproveTransaction = async (provider, ownerAddress, tokenAmount, spenderAddress) => {
|
|
15126
|
+
let amountToApprove;
|
|
15127
|
+
try {
|
|
15128
|
+
amountToApprove = await getERC20AmountToApprove(provider, ownerAddress, tokenAmount, spenderAddress);
|
|
15129
|
+
}
|
|
15130
|
+
catch (e) {
|
|
15131
|
+
if (e instanceof AlreadyApprovedError) {
|
|
15132
|
+
// already approved for the required amount, nothing to do
|
|
15133
|
+
return null;
|
|
15134
|
+
}
|
|
15135
|
+
throw e;
|
|
15136
|
+
}
|
|
15137
|
+
return getUnsignedERC20ApproveTransaction(ownerAddress, amountToApprove, spenderAddress);
|
|
15138
|
+
};
|
|
15139
|
+
async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tokenAddress) {
|
|
15140
|
+
const erc20Contract = ERC20__factory.connect(tokenAddress, provider);
|
|
15141
|
+
return await erc20Contract.estimateGas.approve(spenderAddress, ethers.constants.MaxUint256, {
|
|
15142
|
+
from: ownerAddress,
|
|
15143
|
+
});
|
|
15144
|
+
}
|
|
15145
|
+
const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) => {
|
|
15146
|
+
const approveTransaction = await getApproveTransaction(provider, ownerAddress, preparedApproval.amount, preparedApproval.spender);
|
|
15147
|
+
if (!approveTransaction) {
|
|
15148
|
+
return null;
|
|
15149
|
+
}
|
|
15150
|
+
const gasEstimate = await getApproveGasEstimate(provider, ownerAddress, preparedApproval.spender, preparedApproval.amount.token.address);
|
|
15151
|
+
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
|
|
15152
|
+
return {
|
|
15153
|
+
transaction: approveTransaction,
|
|
15154
|
+
gasFeeEstimate,
|
|
15155
|
+
};
|
|
15156
|
+
};
|
|
15157
|
+
|
|
15158
|
+
// slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
|
|
15159
|
+
// converts it to the Uniswap equivalent type
|
|
15160
|
+
const slippageToFraction = (slippage) => {
|
|
15161
|
+
// If we receive a whole number, we can return slippage/100
|
|
15162
|
+
const noDecimals = slippage.toString().split('.').length === 1;
|
|
15163
|
+
if (noDecimals) {
|
|
15164
|
+
return new Percent(slippage, 100);
|
|
15165
|
+
}
|
|
15166
|
+
// Divide the slippage number by 100 to get the decimal
|
|
15167
|
+
const slippageDecimal = slippage / 100;
|
|
15168
|
+
// Split into two parts by the decimal place
|
|
15169
|
+
const parts = slippageDecimal.toString().split('.');
|
|
15170
|
+
// Get the numerator by adding the two parts together
|
|
15171
|
+
const numerator = parts[0] + parts[1];
|
|
15172
|
+
// Get the denominator by multiplying decimals^10
|
|
15173
|
+
const denominator = 10 ** parts[1].length;
|
|
15174
|
+
return new Percent(numerator, denominator);
|
|
15175
|
+
};
|
|
15176
|
+
|
|
15177
|
+
function getQuoteAmountFromTradeType(tradeInfo) {
|
|
15178
|
+
if (tradeInfo.tradeType === TradeType.EXACT_INPUT) {
|
|
15179
|
+
return tradeInfo.amountOut;
|
|
15180
|
+
}
|
|
15181
|
+
return tradeInfo.amountIn;
|
|
15182
|
+
}
|
|
15183
|
+
function applySlippage(tradeType, amount, slippage) {
|
|
15184
|
+
const slippageTolerance = slippageToFraction(slippage);
|
|
15185
|
+
const slippagePlusOne = slippageTolerance.add(1);
|
|
15186
|
+
const maybeInverted = tradeType === TradeType.EXACT_INPUT ? slippagePlusOne.invert() : slippagePlusOne;
|
|
15187
|
+
const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
|
|
15188
|
+
return ethers.BigNumber.from(amountWithSlippage.toString());
|
|
15189
|
+
}
|
|
15190
|
+
function prepareUserQuote(otherToken, tradeInfo, slippage, fees) {
|
|
15191
|
+
const quote = getQuoteAmountFromTradeType(tradeInfo);
|
|
15192
|
+
const amountWithSlippage = applySlippage(tradeInfo.tradeType, quote.value, slippage);
|
|
15193
|
+
return {
|
|
15194
|
+
amount: quote,
|
|
15195
|
+
amountWithMaxSlippage: {
|
|
15196
|
+
token: otherToken,
|
|
15197
|
+
value: amountWithSlippage,
|
|
15198
|
+
},
|
|
15199
|
+
slippage,
|
|
15200
|
+
fees: fees.withAmounts(),
|
|
15201
|
+
};
|
|
15202
|
+
}
|
|
15203
|
+
function getOurQuoteReqAmount(amount, fees, tradeType) {
|
|
15204
|
+
if (tradeType === TradeType.EXACT_OUTPUT) {
|
|
15205
|
+
// For an exact output swap, we do not need to subtract fees from the given amount
|
|
15206
|
+
return amount;
|
|
15207
|
+
}
|
|
15208
|
+
fees.addAmount(amount);
|
|
15209
|
+
return fees.amountLessFees();
|
|
15210
|
+
}
|
|
15211
|
+
|
|
15212
|
+
// 0.1% default slippage
|
|
15213
|
+
const DEFAULT_SLIPPAGE = 0.1;
|
|
15214
|
+
// 15 minutes from the current Unix time
|
|
15215
|
+
const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
|
|
15216
|
+
// most swaps will be able to resolve with 2 hops
|
|
15217
|
+
const DEFAULT_MAX_HOPS = 2;
|
|
15218
|
+
// after 10 hops, it is very unlikely a route will be available
|
|
15219
|
+
const MAX_MAX_HOPS = 10;
|
|
15220
|
+
// a max hop of 1 will require a direct swap with no intermediary pools
|
|
15221
|
+
const MIN_MAX_HOPS = 1;
|
|
15222
|
+
// precision used to calculate percentage from basis points
|
|
15223
|
+
const BASIS_POINT_PRECISION = 10000;
|
|
15224
|
+
// 10% maximum secondary fee
|
|
15225
|
+
const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
|
|
15226
|
+
|
|
15227
|
+
class Fees {
|
|
15228
|
+
secondaryFees;
|
|
15229
|
+
amount;
|
|
15230
|
+
constructor(secondaryFees, token) {
|
|
15231
|
+
this.secondaryFees = secondaryFees;
|
|
15232
|
+
this.amount = newAmount(BigNumber$1.from(0), token);
|
|
15233
|
+
}
|
|
15234
|
+
addAmount(amount) {
|
|
15235
|
+
this.amount = addAmount(this.amount, amount);
|
|
15236
|
+
}
|
|
15237
|
+
amountWithFeesApplied() {
|
|
15238
|
+
return addAmount(this.amount, this.total());
|
|
15239
|
+
}
|
|
15240
|
+
amountLessFees() {
|
|
15241
|
+
return subtractAmount(this.amount, this.total());
|
|
15242
|
+
}
|
|
15243
|
+
withAmounts() {
|
|
15244
|
+
return this.secondaryFees.map((fee) => {
|
|
15245
|
+
const feeAmount = this.amount.value
|
|
15246
|
+
.mul(fee.basisPoints)
|
|
15247
|
+
.div(BASIS_POINT_PRECISION);
|
|
15248
|
+
return {
|
|
15249
|
+
...fee,
|
|
15250
|
+
amount: newAmount(feeAmount, this.amount.token),
|
|
15251
|
+
};
|
|
15252
|
+
});
|
|
15253
|
+
}
|
|
15254
|
+
total() {
|
|
15255
|
+
let totalFees = newAmount(BigNumber$1.from(0), this.amount.token);
|
|
15256
|
+
for (const fee of this.secondaryFees) {
|
|
15257
|
+
const feeAmount = this.amount.value
|
|
15258
|
+
.mul(fee.basisPoints)
|
|
15259
|
+
.div(BASIS_POINT_PRECISION);
|
|
15260
|
+
totalFees = addAmount(totalFees, newAmount(feeAmount, this.amount.token));
|
|
15261
15261
|
}
|
|
15262
15262
|
return totalFees;
|
|
15263
15263
|
}
|
|
@@ -15371,13 +15371,10 @@ function createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, se
|
|
|
15371
15371
|
}
|
|
15372
15372
|
return createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees);
|
|
15373
15373
|
}
|
|
15374
|
-
function getSwap(
|
|
15374
|
+
function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees) {
|
|
15375
15375
|
const calldata = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
|
|
15376
15376
|
// TODO: Add additional gas fee estimates for secondary fees
|
|
15377
|
-
const gasFeeEstimate = gasPrice ?
|
|
15378
|
-
token: nativeToken,
|
|
15379
|
-
value: calculateGasFee(gasPrice, adjustedQuote.gasEstimate),
|
|
15380
|
-
} : null;
|
|
15377
|
+
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
|
|
15381
15378
|
return {
|
|
15382
15379
|
transaction: {
|
|
15383
15380
|
data: calldata,
|
|
@@ -15561,14 +15558,14 @@ class Exchange {
|
|
|
15561
15558
|
// get quote and gas details
|
|
15562
15559
|
const [ourQuote, gasPrice] = await Promise.all([
|
|
15563
15560
|
this.router.findOptimalRoute(ourQuoteReqAmount, otherToken, tradeType, maxHops),
|
|
15564
|
-
fetchGasPrice(this.provider),
|
|
15561
|
+
fetchGasPrice(this.provider, this.nativeToken),
|
|
15565
15562
|
]);
|
|
15566
15563
|
const adjustedQuote = prepareSwap(ourQuote, amountSpecified, fees);
|
|
15567
|
-
const swap = getSwap(
|
|
15564
|
+
const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, secondaryFees);
|
|
15568
15565
|
const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent, fees);
|
|
15569
|
-
const preparedApproval = prepareApproval(tradeType,
|
|
15570
|
-
//
|
|
15571
|
-
const approval = await getApproval(this.
|
|
15566
|
+
const preparedApproval = prepareApproval(tradeType, amountSpecified, userQuote.amountWithMaxSlippage, this.router.routingContracts, secondaryFees);
|
|
15567
|
+
// preparedApproval always uses the tokenIn address because we are always selling the tokenIn
|
|
15568
|
+
const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice);
|
|
15572
15569
|
return {
|
|
15573
15570
|
approval,
|
|
15574
15571
|
swap,
|
|
@@ -15888,7 +15885,7 @@ const getRequestBody = (options) => {
|
|
|
15888
15885
|
return undefined;
|
|
15889
15886
|
};
|
|
15890
15887
|
const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
15891
|
-
const source = axios.CancelToken.source();
|
|
15888
|
+
const source = $7v2Z6$axios.CancelToken.source();
|
|
15892
15889
|
const requestConfig = {
|
|
15893
15890
|
url,
|
|
15894
15891
|
headers,
|
|
@@ -15899,7 +15896,7 @@ const sendRequest = async (config, options, url, body, formData, headers, onCanc
|
|
|
15899
15896
|
};
|
|
15900
15897
|
onCancel(() => source.cancel('The user aborted a request.'));
|
|
15901
15898
|
try {
|
|
15902
|
-
return await axios.request(requestConfig);
|
|
15899
|
+
return await $7v2Z6$axios.request(requestConfig);
|
|
15903
15900
|
}
|
|
15904
15901
|
catch (error) {
|
|
15905
15902
|
const axiosError = error;
|
|
@@ -16093,6 +16090,54 @@ class OrdersService {
|
|
|
16093
16090
|
},
|
|
16094
16091
|
});
|
|
16095
16092
|
}
|
|
16093
|
+
/**
|
|
16094
|
+
* List all trades
|
|
16095
|
+
* List all trades
|
|
16096
|
+
* @returns ListTradeResult OK response.
|
|
16097
|
+
* @throws ApiError
|
|
16098
|
+
*/
|
|
16099
|
+
listTrades({ chainName, accountAddress, pageSize, sortBy, sortDirection, pageCursor, }) {
|
|
16100
|
+
return this.httpRequest.request({
|
|
16101
|
+
method: 'GET',
|
|
16102
|
+
url: '/v1/chains/{chain_name}/trades',
|
|
16103
|
+
path: {
|
|
16104
|
+
'chain_name': chainName,
|
|
16105
|
+
},
|
|
16106
|
+
query: {
|
|
16107
|
+
'account_address': accountAddress,
|
|
16108
|
+
'page_size': pageSize,
|
|
16109
|
+
'sort_by': sortBy,
|
|
16110
|
+
'sort_direction': sortDirection,
|
|
16111
|
+
'page_cursor': pageCursor,
|
|
16112
|
+
},
|
|
16113
|
+
errors: {
|
|
16114
|
+
400: `Bad Request (400)`,
|
|
16115
|
+
404: `The specified resource was not found (404)`,
|
|
16116
|
+
500: `Internal Server Error (500)`,
|
|
16117
|
+
},
|
|
16118
|
+
});
|
|
16119
|
+
}
|
|
16120
|
+
/**
|
|
16121
|
+
* Get a single trade by ID
|
|
16122
|
+
* Get a single trade by ID
|
|
16123
|
+
* @returns TradeResult OK response.
|
|
16124
|
+
* @throws ApiError
|
|
16125
|
+
*/
|
|
16126
|
+
getTrade({ chainName, tradeId, }) {
|
|
16127
|
+
return this.httpRequest.request({
|
|
16128
|
+
method: 'GET',
|
|
16129
|
+
url: '/v1/chains/{chain_name}/trades/{trade_id}',
|
|
16130
|
+
path: {
|
|
16131
|
+
'chain_name': chainName,
|
|
16132
|
+
'trade_id': tradeId,
|
|
16133
|
+
},
|
|
16134
|
+
errors: {
|
|
16135
|
+
400: `Bad Request (400)`,
|
|
16136
|
+
404: `The specified resource was not found (404)`,
|
|
16137
|
+
500: `Internal Server Error (500)`,
|
|
16138
|
+
},
|
|
16139
|
+
});
|
|
16140
|
+
}
|
|
16096
16141
|
}
|
|
16097
16142
|
|
|
16098
16143
|
class OrderBookClient {
|
|
@@ -16229,6 +16274,57 @@ function mapFromOpenApiOrder(order) {
|
|
|
16229
16274
|
updateTime: order.update_time,
|
|
16230
16275
|
};
|
|
16231
16276
|
}
|
|
16277
|
+
function mapFromOpenApiTrade(trade) {
|
|
16278
|
+
const buyItems = trade.buy.map((item) => {
|
|
16279
|
+
if (item.item_type === 'ERC20') {
|
|
16280
|
+
return {
|
|
16281
|
+
type: 'ERC20',
|
|
16282
|
+
contractAddress: item.contract_address,
|
|
16283
|
+
amount: item.start_amount,
|
|
16284
|
+
};
|
|
16285
|
+
}
|
|
16286
|
+
if (item.item_type === 'NATIVE') {
|
|
16287
|
+
return {
|
|
16288
|
+
type: 'NATIVE',
|
|
16289
|
+
amount: item.start_amount,
|
|
16290
|
+
};
|
|
16291
|
+
}
|
|
16292
|
+
throw new Error('Buy items must be either ERC20 or NATIVE');
|
|
16293
|
+
});
|
|
16294
|
+
const sellItems = trade.sell.map((item) => {
|
|
16295
|
+
if (item.item_type === 'ERC721') {
|
|
16296
|
+
return {
|
|
16297
|
+
type: 'ERC721',
|
|
16298
|
+
contractAddress: item.contract_address,
|
|
16299
|
+
tokenId: item.token_id,
|
|
16300
|
+
};
|
|
16301
|
+
}
|
|
16302
|
+
throw new Error('Sell items must ERC721');
|
|
16303
|
+
});
|
|
16304
|
+
return {
|
|
16305
|
+
id: trade.id,
|
|
16306
|
+
orderId: trade.order_id,
|
|
16307
|
+
buy: buyItems,
|
|
16308
|
+
sell: sellItems,
|
|
16309
|
+
buyerFees: trade.buyer_fees.map((fee) => ({
|
|
16310
|
+
amount: fee.amount,
|
|
16311
|
+
recipient: fee.recipient,
|
|
16312
|
+
type: fee.fee_type,
|
|
16313
|
+
})),
|
|
16314
|
+
chain: trade.chain,
|
|
16315
|
+
indexedAt: trade.indexed_at,
|
|
16316
|
+
blockchainMetadata: {
|
|
16317
|
+
blockNumber: trade.blockchain_metadata.block_number,
|
|
16318
|
+
logIndex: trade.blockchain_metadata.log_index,
|
|
16319
|
+
transactionHash: trade.blockchain_metadata.transaction_hash,
|
|
16320
|
+
transactionIndex: trade.blockchain_metadata.transaction_index,
|
|
16321
|
+
},
|
|
16322
|
+
buyerAddress: trade.buyer_address,
|
|
16323
|
+
makerAddress: trade.maker_address,
|
|
16324
|
+
sellerAddress: trade.seller_address,
|
|
16325
|
+
takerAddress: trade.taker_address,
|
|
16326
|
+
};
|
|
16327
|
+
}
|
|
16232
16328
|
function mapFromOpenApiPage(page) {
|
|
16233
16329
|
return {
|
|
16234
16330
|
nextCursor: page.next_cursor,
|
|
@@ -16558,12 +16654,24 @@ class ImmutableApiClient {
|
|
|
16558
16654
|
listingId,
|
|
16559
16655
|
});
|
|
16560
16656
|
}
|
|
16657
|
+
async getTrade(tradeId) {
|
|
16658
|
+
return this.orderbookService.getTrade({
|
|
16659
|
+
chainName: this.chainName,
|
|
16660
|
+
tradeId,
|
|
16661
|
+
});
|
|
16662
|
+
}
|
|
16561
16663
|
async listListings(listOrderParams) {
|
|
16562
16664
|
return this.orderbookService.listListings({
|
|
16563
16665
|
chainName: this.chainName,
|
|
16564
16666
|
...listOrderParams,
|
|
16565
16667
|
});
|
|
16566
16668
|
}
|
|
16669
|
+
async listTrades(listTradesParams) {
|
|
16670
|
+
return this.orderbookService.listTrades({
|
|
16671
|
+
chainName: this.chainName,
|
|
16672
|
+
...listTradesParams,
|
|
16673
|
+
});
|
|
16674
|
+
}
|
|
16567
16675
|
async createListing({ orderHash, orderComponents, orderSignature, makerFee, }) {
|
|
16568
16676
|
if (orderComponents.offer.length !== 1) {
|
|
16569
16677
|
throw new Error('Only one item can be listed at a time');
|
|
@@ -16729,6 +16837,17 @@ class Orderbook {
|
|
|
16729
16837
|
result: mapFromOpenApiOrder(apiListing.result),
|
|
16730
16838
|
};
|
|
16731
16839
|
}
|
|
16840
|
+
/**
|
|
16841
|
+
* Get a trade by ID
|
|
16842
|
+
* @param {string} tradeId - The tradeId to find.
|
|
16843
|
+
* @return {TradeResult} The returned order result.
|
|
16844
|
+
*/
|
|
16845
|
+
async getTrade(tradeId) {
|
|
16846
|
+
const apiListing = await this.apiClient.getTrade(tradeId);
|
|
16847
|
+
return {
|
|
16848
|
+
result: mapFromOpenApiTrade(apiListing.result),
|
|
16849
|
+
};
|
|
16850
|
+
}
|
|
16732
16851
|
/**
|
|
16733
16852
|
* List orders. This method is used to get a list of orders filtered by conditions specified
|
|
16734
16853
|
* in the params object.
|
|
@@ -16742,6 +16861,19 @@ class Orderbook {
|
|
|
16742
16861
|
result: apiListings.result.map(mapFromOpenApiOrder),
|
|
16743
16862
|
};
|
|
16744
16863
|
}
|
|
16864
|
+
/**
|
|
16865
|
+
* List trades. This method is used to get a list of trades filtered by conditions specified
|
|
16866
|
+
* in the params object
|
|
16867
|
+
* @param {ListTradesParams} listTradesParams - Filtering, ordering and page parameters.
|
|
16868
|
+
* @return {ListTradesResult} The paged trades.
|
|
16869
|
+
*/
|
|
16870
|
+
async listTrades(listTradesParams) {
|
|
16871
|
+
const apiListings = await this.apiClient.listTrades(listTradesParams);
|
|
16872
|
+
return {
|
|
16873
|
+
page: mapFromOpenApiPage(apiListings.page),
|
|
16874
|
+
result: apiListings.result.map(mapFromOpenApiTrade),
|
|
16875
|
+
};
|
|
16876
|
+
}
|
|
16745
16877
|
/**
|
|
16746
16878
|
* Get required transactions and messages for signing prior to creating a listing
|
|
16747
16879
|
* through the createListing method
|
|
@@ -16842,6 +16974,18 @@ const constants = {
|
|
|
16842
16974
|
|
|
16843
16975
|
|
|
16844
16976
|
|
|
16977
|
+
var $aa144554f9ef124b$export$226b052ecb8ca80;
|
|
16978
|
+
(function(BuyStatusType) {
|
|
16979
|
+
BuyStatusType["SUCCESS"] = "SUCCESS";
|
|
16980
|
+
BuyStatusType["FAILED"] = "FAILED";
|
|
16981
|
+
})($aa144554f9ef124b$export$226b052ecb8ca80 || ($aa144554f9ef124b$export$226b052ecb8ca80 = {}));
|
|
16982
|
+
|
|
16983
|
+
|
|
16984
|
+
var $1e6b81bbd98b3a91$export$c0189a8c30039654;
|
|
16985
|
+
(function(CancelStatusType) {
|
|
16986
|
+
CancelStatusType["SUCCESS"] = "SUCCESS";
|
|
16987
|
+
CancelStatusType["FAILED"] = "FAILED";
|
|
16988
|
+
})($1e6b81bbd98b3a91$export$c0189a8c30039654 || ($1e6b81bbd98b3a91$export$c0189a8c30039654 = {}));
|
|
16845
16989
|
|
|
16846
16990
|
|
|
16847
16991
|
/**
|
|
@@ -16889,6 +17033,13 @@ var $a47e48dd2c04791b$export$1f05a55fe0680cc7;
|
|
|
16889
17033
|
|
|
16890
17034
|
|
|
16891
17035
|
|
|
17036
|
+
var $c2874b006e92b115$export$a9780122aaa0801a;
|
|
17037
|
+
(function(SellStatusType) {
|
|
17038
|
+
SellStatusType["SUCCESS"] = "SUCCESS";
|
|
17039
|
+
SellStatusType["FAILED"] = "FAILED";
|
|
17040
|
+
})($c2874b006e92b115$export$a9780122aaa0801a || ($c2874b006e92b115$export$a9780122aaa0801a = {}));
|
|
17041
|
+
|
|
17042
|
+
|
|
16892
17043
|
var $08d5ddc39acd6833$export$fd9b17d87f4121d2;
|
|
16893
17044
|
(function(TokenFilterTypes) {
|
|
16894
17045
|
TokenFilterTypes["ALL"] = "all";
|
|
@@ -16939,14 +17090,26 @@ const $e768639828688ca3$export$44dde05038008549 = {
|
|
|
16939
17090
|
const $d85ad1457a3f1a83$export$7d3a9eeba384fa59 = "development";
|
|
16940
17091
|
const $d85ad1457a3f1a83$export$b80040cb173ba6e9 = "0x0000000000000000000000000000000000001010";
|
|
16941
17092
|
const $d85ad1457a3f1a83$export$903389470ba9433c = 18;
|
|
17093
|
+
const $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN = {
|
|
17094
|
+
name: "IMX",
|
|
17095
|
+
symbol: "IMX",
|
|
17096
|
+
decimals: $d85ad1457a3f1a83$export$903389470ba9433c,
|
|
17097
|
+
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17098
|
+
};
|
|
16942
17099
|
const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
|
|
16943
17100
|
[$d85ad1457a3f1a83$export$7d3a9eeba384fa59]: "https://checkout-api.dev.immutable.com",
|
|
16944
17101
|
[(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
|
|
16945
17102
|
[(Environment$1).PRODUCTION]: "https://checkout-api.immutable.com"
|
|
16946
17103
|
};
|
|
16947
|
-
|
|
16948
|
-
|
|
16949
|
-
|
|
17104
|
+
const $d85ad1457a3f1a83$export$72176e2233d7d5d = true;
|
|
17105
|
+
const $d85ad1457a3f1a83$export$566b5975cc83d6b4 = true;
|
|
17106
|
+
const $d85ad1457a3f1a83$export$261cde2078dba35b = true;
|
|
17107
|
+
const $d85ad1457a3f1a83$export$fc55ed5a42b458ba = {
|
|
17108
|
+
[($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET]: {
|
|
17109
|
+
url: "https://explorer.testnet.immutable.com",
|
|
17110
|
+
nativeToken: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17111
|
+
}
|
|
17112
|
+
};
|
|
16950
17113
|
const $d85ad1457a3f1a83$export$6f24f3cef7d501c4 = new Map([
|
|
16951
17114
|
[
|
|
16952
17115
|
($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM,
|
|
@@ -16974,12 +17137,7 @@ const $d85ad1457a3f1a83$export$6f24f3cef7d501c4 = new Map([
|
|
|
16974
17137
|
rpcUrls: [
|
|
16975
17138
|
"https://rpc.immutable.com"
|
|
16976
17139
|
],
|
|
16977
|
-
nativeCurrency:
|
|
16978
|
-
name: "IMX",
|
|
16979
|
-
symbol: "IMX",
|
|
16980
|
-
decimals: 18,
|
|
16981
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
16982
|
-
}
|
|
17140
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
16983
17141
|
}
|
|
16984
17142
|
]
|
|
16985
17143
|
]);
|
|
@@ -17010,12 +17168,7 @@ const $d85ad1457a3f1a83$export$3e81fc0987227f10 = new Map([
|
|
|
17010
17168
|
rpcUrls: [
|
|
17011
17169
|
"https://rpc.testnet.immutable.com"
|
|
17012
17170
|
],
|
|
17013
|
-
nativeCurrency:
|
|
17014
|
-
name: "IMX",
|
|
17015
|
-
symbol: "IMX",
|
|
17016
|
-
decimals: 18,
|
|
17017
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17018
|
-
}
|
|
17171
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17019
17172
|
}
|
|
17020
17173
|
]
|
|
17021
17174
|
]);
|
|
@@ -17046,12 +17199,7 @@ const $d85ad1457a3f1a83$export$3a9ebede6a150274 = new Map([
|
|
|
17046
17199
|
rpcUrls: [
|
|
17047
17200
|
"https://rpc.dev.immutable.com"
|
|
17048
17201
|
],
|
|
17049
|
-
nativeCurrency:
|
|
17050
|
-
name: "IMX",
|
|
17051
|
-
symbol: "IMX",
|
|
17052
|
-
decimals: 18,
|
|
17053
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17054
|
-
}
|
|
17202
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17055
17203
|
}
|
|
17056
17204
|
]
|
|
17057
17205
|
]);
|
|
@@ -17279,6 +17427,7 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
|
|
|
17279
17427
|
CheckoutErrorType["DEFAULT_PROVIDER_ERROR"] = "DEFAULT_PROVIDER_ERROR";
|
|
17280
17428
|
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
17281
17429
|
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
17430
|
+
CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
|
|
17282
17431
|
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
17283
17432
|
CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
|
|
17284
17433
|
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
@@ -17294,9 +17443,15 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
|
|
|
17294
17443
|
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
17295
17444
|
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
17296
17445
|
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
17446
|
+
CheckoutErrorType["CANCEL_ORDER_LISTING_ERROR"] = "CANCEL_ORDER_LISTING_ERROR";
|
|
17447
|
+
CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
|
|
17448
|
+
CheckoutErrorType["CREATE_ORDER_LISTING_ERROR"] = "CREATE_ORDER_LISTING_ERROR";
|
|
17297
17449
|
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
17298
17450
|
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
17299
17451
|
CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
|
|
17452
|
+
CheckoutErrorType["EXECUTE_APPROVAL_TRANSACTION_ERROR"] = "EXECUTE_APPROVAL_TRANSACTION_ERROR";
|
|
17453
|
+
CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
|
|
17454
|
+
CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
|
|
17300
17455
|
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
17301
17456
|
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
17302
17457
|
message;
|
|
@@ -17484,7 +17639,7 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async (config, { type: type =
|
|
|
17484
17639
|
case ($08d5ddc39acd6833$export$fd9b17d87f4121d2).BRIDGE:
|
|
17485
17640
|
case ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL:
|
|
17486
17641
|
default:
|
|
17487
|
-
tokens = await config.remote.
|
|
17642
|
+
tokens = (await config.remote.getTokensConfig(chainId)).allowed;
|
|
17488
17643
|
}
|
|
17489
17644
|
if (!exclude || exclude?.length === 0) return {
|
|
17490
17645
|
tokens: tokens
|
|
@@ -17497,6 +17652,141 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async (config, { type: type =
|
|
|
17497
17652
|
|
|
17498
17653
|
|
|
17499
17654
|
|
|
17655
|
+
|
|
17656
|
+
|
|
17657
|
+
const $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL = 60; // seconds
|
|
17658
|
+
class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
|
|
17659
|
+
url;
|
|
17660
|
+
nativeToken;
|
|
17661
|
+
ttl;
|
|
17662
|
+
chainId;
|
|
17663
|
+
cacheMap;
|
|
17664
|
+
static async makeHttpRequest(url) {
|
|
17665
|
+
return ($7v2Z6$axios).get(url);
|
|
17666
|
+
}
|
|
17667
|
+
setCache(key, data) {
|
|
17668
|
+
this.cacheMap[key] = {
|
|
17669
|
+
data: data,
|
|
17670
|
+
ttl: new Date().getTime() + this.ttl * 1000
|
|
17671
|
+
};
|
|
17672
|
+
}
|
|
17673
|
+
getCache(key) {
|
|
17674
|
+
const d = this.cacheMap[key];
|
|
17675
|
+
if (!d || d.ttl <= new Date().getTime()) return null;
|
|
17676
|
+
return d.data;
|
|
17677
|
+
}
|
|
17678
|
+
/**
|
|
17679
|
+
* Blockscout constructor
|
|
17680
|
+
* @param chainId target chain
|
|
17681
|
+
* @param ttl cache TTL
|
|
17682
|
+
*/ constructor(params){
|
|
17683
|
+
this.chainId = params.chainId;
|
|
17684
|
+
this.url = ($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[this.chainId].url;
|
|
17685
|
+
const native = ($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[this.chainId].nativeToken;
|
|
17686
|
+
this.nativeToken = {
|
|
17687
|
+
address: native.address ?? "",
|
|
17688
|
+
decimals: native.decimals.toString(),
|
|
17689
|
+
name: native.name,
|
|
17690
|
+
symbol: native.symbol
|
|
17691
|
+
};
|
|
17692
|
+
this.cacheMap = {};
|
|
17693
|
+
this.ttl = params.ttl !== undefined ? params.ttl : $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL;
|
|
17694
|
+
}
|
|
17695
|
+
/**
|
|
17696
|
+
* isChainSupported verifies if the chain is supported by Blockscout
|
|
17697
|
+
* @param chainId
|
|
17698
|
+
*/ static isChainSupported = (chainId)=>Boolean(($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[chainId]);
|
|
17699
|
+
/**
|
|
17700
|
+
* isBlockscoutError verifies if the error is a Blockscout client error
|
|
17701
|
+
* @param err error to evaluate
|
|
17702
|
+
*/ static isBlockscoutError = (err)=>"code" in err;
|
|
17703
|
+
/**
|
|
17704
|
+
* getTokensByWalletAddress fetches the list of tokens (by type) owned by the wallet address.
|
|
17705
|
+
* @param walletAddress wallet address
|
|
17706
|
+
* @param tokenType token type
|
|
17707
|
+
* @param nextPage parameters for the next page, to be provided alongside walletAddress and tokenType
|
|
17708
|
+
* @returns list of tokens given the wallet address and the token types
|
|
17709
|
+
*/ async getTokensByWalletAddress(params) {
|
|
17710
|
+
try {
|
|
17711
|
+
let url = `${this.url}/api/v2/addresses/${params.walletAddress}/tokens?type=${params.tokenType}`;
|
|
17712
|
+
if (params.nextPage) url += `&${new URLSearchParams(params.nextPage)}`;
|
|
17713
|
+
// Cache response data to prevent unnecessary requests
|
|
17714
|
+
const cached = this.getCache(url);
|
|
17715
|
+
if (cached && cached.status < 400) return Promise.resolve(cached.data);
|
|
17716
|
+
const response = await $fd8a8472dcc3ec2b$export$ef140a6b05dfc786.makeHttpRequest(url);
|
|
17717
|
+
if (response.status >= 400) return Promise.reject({
|
|
17718
|
+
code: response.status,
|
|
17719
|
+
message: response.statusText
|
|
17720
|
+
});
|
|
17721
|
+
// To get around an issue with native tokens being an ERC-20, there is the need
|
|
17722
|
+
// to remove IMX from `resp` and add it back in using getNativeTokenByWalletAddress.
|
|
17723
|
+
// This has affected some of the early wallets, and it might not be an issue in mainnet
|
|
17724
|
+
// however, let's enforce it.
|
|
17725
|
+
const data = {
|
|
17726
|
+
items: response.data?.items?.filter((token)=>token.token.address && token.token.address !== this.nativeToken.address),
|
|
17727
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
17728
|
+
next_page_params: response.data?.next_page_params
|
|
17729
|
+
};
|
|
17730
|
+
this.setCache(url, data);
|
|
17731
|
+
return Promise.resolve(data);
|
|
17732
|
+
} catch (err) {
|
|
17733
|
+
let code = (HttpStatusCode).InternalServerError;
|
|
17734
|
+
let message = "InternalServerError";
|
|
17735
|
+
if (($7v2Z6$axios).isAxiosError(err)) {
|
|
17736
|
+
code = err.response?.status || code;
|
|
17737
|
+
message = err.message;
|
|
17738
|
+
}
|
|
17739
|
+
return Promise.reject({
|
|
17740
|
+
code: code,
|
|
17741
|
+
message: message
|
|
17742
|
+
});
|
|
17743
|
+
}
|
|
17744
|
+
}
|
|
17745
|
+
/**
|
|
17746
|
+
* getNativeTokenByWalletAddress fetches the native token owned by the wallet address.
|
|
17747
|
+
* @param walletAddress wallet address
|
|
17748
|
+
* @returns list of tokens given the wallet address and the token types
|
|
17749
|
+
*/ async getNativeTokenByWalletAddress(params) {
|
|
17750
|
+
try {
|
|
17751
|
+
const url = `${this.url}/api/v2/addresses/${params.walletAddress}`;
|
|
17752
|
+
// Cache response data to prevent unnecessary requests
|
|
17753
|
+
const cached = this.getCache(url);
|
|
17754
|
+
if (cached && cached.status < 400) return Promise.resolve(cached.data);
|
|
17755
|
+
const response = await $fd8a8472dcc3ec2b$export$ef140a6b05dfc786.makeHttpRequest(url);
|
|
17756
|
+
if (response.status >= 400) return Promise.reject({
|
|
17757
|
+
code: response.status,
|
|
17758
|
+
message: response.statusText
|
|
17759
|
+
});
|
|
17760
|
+
const data = {
|
|
17761
|
+
token: this.nativeToken,
|
|
17762
|
+
value: response.data.coin_balance
|
|
17763
|
+
};
|
|
17764
|
+
this.setCache(url, data);
|
|
17765
|
+
return Promise.resolve(data);
|
|
17766
|
+
} catch (err) {
|
|
17767
|
+
let code = (HttpStatusCode).InternalServerError;
|
|
17768
|
+
let message = "InternalServerError";
|
|
17769
|
+
if (($7v2Z6$axios).isAxiosError(err)) {
|
|
17770
|
+
code = err.response?.status || code;
|
|
17771
|
+
message = err.message;
|
|
17772
|
+
}
|
|
17773
|
+
return Promise.reject({
|
|
17774
|
+
code: code,
|
|
17775
|
+
message: message
|
|
17776
|
+
});
|
|
17777
|
+
}
|
|
17778
|
+
}
|
|
17779
|
+
}
|
|
17780
|
+
|
|
17781
|
+
|
|
17782
|
+
/* eslint @typescript-eslint/naming-convention: off */ var $887a00f8f72d61f0$export$5bd1ea2b3d18210;
|
|
17783
|
+
(function(BlockscoutTokenType) {
|
|
17784
|
+
BlockscoutTokenType["ERC20"] = "ERC-20";
|
|
17785
|
+
})($887a00f8f72d61f0$export$5bd1ea2b3d18210 || ($887a00f8f72d61f0$export$5bd1ea2b3d18210 = {}));
|
|
17786
|
+
|
|
17787
|
+
|
|
17788
|
+
|
|
17789
|
+
|
|
17500
17790
|
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, walletAddress)=>await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
17501
17791
|
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(config, web3Provider);
|
|
17502
17792
|
if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
|
|
@@ -17536,6 +17826,65 @@ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAdd
|
|
|
17536
17826
|
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
17537
17827
|
});
|
|
17538
17828
|
}
|
|
17829
|
+
// Blockscout client singleton
|
|
17830
|
+
let $1564e43dde50bb61$var$blockscoutClient;
|
|
17831
|
+
const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId, rename)=>{
|
|
17832
|
+
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
17833
|
+
// for faster access to tokens config objects.
|
|
17834
|
+
const mapRename = Object.assign({}, ...rename.map((t)=>({
|
|
17835
|
+
[t.address || ""]: t
|
|
17836
|
+
})));
|
|
17837
|
+
// Ensure singleton is present and match the selected chain
|
|
17838
|
+
if (!$1564e43dde50bb61$var$blockscoutClient || $1564e43dde50bb61$var$blockscoutClient.chainId !== chainId) $1564e43dde50bb61$var$blockscoutClient = new ($fd8a8472dcc3ec2b$export$ef140a6b05dfc786)({
|
|
17839
|
+
chainId: chainId
|
|
17840
|
+
});
|
|
17841
|
+
// Hold the items in an array for post-fetching processing
|
|
17842
|
+
const items = [];
|
|
17843
|
+
const tokenType = ($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20;
|
|
17844
|
+
// Given that the widgets aren't yet designed to support pagination,
|
|
17845
|
+
// fetch all the possible tokens associated to a given wallet address.
|
|
17846
|
+
let resp;
|
|
17847
|
+
try {
|
|
17848
|
+
do {
|
|
17849
|
+
// eslint-disable-next-line no-await-in-loop
|
|
17850
|
+
resp = await $1564e43dde50bb61$var$blockscoutClient.getTokensByWalletAddress({
|
|
17851
|
+
walletAddress: walletAddress,
|
|
17852
|
+
tokenType: tokenType,
|
|
17853
|
+
nextPage: resp?.next_page_params
|
|
17854
|
+
});
|
|
17855
|
+
items.push(...resp.items);
|
|
17856
|
+
}while (resp.next_page_params);
|
|
17857
|
+
} catch (err) {
|
|
17858
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getTokensByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
|
|
17859
|
+
}
|
|
17860
|
+
try {
|
|
17861
|
+
const respNative = await $1564e43dde50bb61$var$blockscoutClient.getNativeTokenByWalletAddress({
|
|
17862
|
+
walletAddress: walletAddress
|
|
17863
|
+
});
|
|
17864
|
+
items.push(respNative);
|
|
17865
|
+
} catch (err) {
|
|
17866
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError | getNativeTokenByWalletAddress", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, err);
|
|
17867
|
+
}
|
|
17868
|
+
return {
|
|
17869
|
+
balances: items.map((item)=>{
|
|
17870
|
+
const tokenData = item.token || {};
|
|
17871
|
+
const balance = (BigNumber$1).from(item.value);
|
|
17872
|
+
const renamed = mapRename[tokenData.address] || {};
|
|
17873
|
+
const token = {
|
|
17874
|
+
...tokenData,
|
|
17875
|
+
name: renamed.name ?? tokenData.name,
|
|
17876
|
+
symbol: renamed.symbol ?? tokenData.symbol,
|
|
17877
|
+
decimals: parseInt(tokenData.decimals, 10)
|
|
17878
|
+
};
|
|
17879
|
+
const formattedBalance = (utils).formatUnits(item.value, token.decimals);
|
|
17880
|
+
return {
|
|
17881
|
+
balance: balance,
|
|
17882
|
+
formattedBalance: formattedBalance,
|
|
17883
|
+
token: token
|
|
17884
|
+
};
|
|
17885
|
+
})
|
|
17886
|
+
};
|
|
17887
|
+
};
|
|
17539
17888
|
const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, walletAddress, tokens)=>{
|
|
17540
17889
|
const allBalancePromises = [];
|
|
17541
17890
|
tokens.forEach((token)=>{
|
|
@@ -17544,7 +17893,7 @@ const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, w
|
|
|
17544
17893
|
else allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address));
|
|
17545
17894
|
});
|
|
17546
17895
|
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
17547
|
-
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((
|
|
17896
|
+
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((result)=>result.value);
|
|
17548
17897
|
return {
|
|
17549
17898
|
balances: balances
|
|
17550
17899
|
};
|
|
@@ -17554,6 +17903,20 @@ const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, w
|
|
|
17554
17903
|
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
17555
17904
|
chainId: chainId
|
|
17556
17905
|
});
|
|
17906
|
+
// In order to prevent unnecessary RPC calls
|
|
17907
|
+
// let's use the Indexer if available for the
|
|
17908
|
+
// given chain.
|
|
17909
|
+
let flag = false;
|
|
17910
|
+
try {
|
|
17911
|
+
flag = (await config.remote.getTokensConfig(chainId)).blockscout || flag;
|
|
17912
|
+
} catch (err) {
|
|
17913
|
+
// eslint-disable-next-line no-console
|
|
17914
|
+
console.error(err);
|
|
17915
|
+
}
|
|
17916
|
+
if (flag && ($fd8a8472dcc3ec2b$export$ef140a6b05dfc786).isChainSupported(chainId)) return await $1564e43dde50bb61$export$8c978679845804d4(walletAddress, chainId, tokens);
|
|
17917
|
+
// This fallback to use ERC20s calls which is a best effort solution
|
|
17918
|
+
// Fails in fetching data from the RCP calls might result in some
|
|
17919
|
+
// missing data.
|
|
17557
17920
|
return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
|
|
17558
17921
|
};
|
|
17559
17922
|
|
|
@@ -17822,7 +18185,7 @@ class $a492ee374ae7b613$export$d902b56530cd5f87 {
|
|
|
17822
18185
|
static async makeHttpRequest(url) {
|
|
17823
18186
|
let response;
|
|
17824
18187
|
try {
|
|
17825
|
-
response = await (0, axios).get(url);
|
|
18188
|
+
response = await (0, $7v2Z6$axios).get(url);
|
|
17826
18189
|
} catch (error) {
|
|
17827
18190
|
throw new Error(`Error fetching from api: ${error.message}`);
|
|
17828
18191
|
}
|
|
@@ -17852,10 +18215,10 @@ class $a492ee374ae7b613$export$d902b56530cd5f87 {
|
|
|
17852
18215
|
if (!key) return config;
|
|
17853
18216
|
return config[key];
|
|
17854
18217
|
}
|
|
17855
|
-
async
|
|
18218
|
+
async getTokensConfig(chainId) {
|
|
17856
18219
|
const config = await this.loadConfigTokens();
|
|
17857
|
-
if (!config) return
|
|
17858
|
-
return config[chainId]
|
|
18220
|
+
if (!config || !config[chainId]) return {};
|
|
18221
|
+
return config[chainId] ?? [];
|
|
17859
18222
|
}
|
|
17860
18223
|
}
|
|
17861
18224
|
|
|
@@ -17889,6 +18252,9 @@ class $4013c5c91bb535f6$export$4823433c4a67bbc6 {
|
|
|
17889
18252
|
// Environment.DEVELOPMENT
|
|
17890
18253
|
isDevelopment = false;
|
|
17891
18254
|
isProduction;
|
|
18255
|
+
isOnRampEnabled;
|
|
18256
|
+
isSwapEnabled;
|
|
18257
|
+
isBridgeEnabled;
|
|
17892
18258
|
remote;
|
|
17893
18259
|
environment;
|
|
17894
18260
|
networkMap;
|
|
@@ -17897,6 +18263,9 @@ class $4013c5c91bb535f6$export$4823433c4a67bbc6 {
|
|
|
17897
18263
|
this.environment = config.baseConfig.environment;
|
|
17898
18264
|
// Developer mode will super set any environment configuration
|
|
17899
18265
|
this.isProduction = !this.isDevelopment && this.environment === (Environment$1).PRODUCTION;
|
|
18266
|
+
this.isOnRampEnabled = config.isOnRampEnabled ?? ($d85ad1457a3f1a83$export$72176e2233d7d5d);
|
|
18267
|
+
this.isSwapEnabled = config.isSwapEnabled ?? ($d85ad1457a3f1a83$export$566b5975cc83d6b4);
|
|
18268
|
+
this.isBridgeEnabled = config.isBridgeEnabled ?? ($d85ad1457a3f1a83$export$261cde2078dba35b);
|
|
17900
18269
|
this.networkMap = $4013c5c91bb535f6$var$networkMap(this.isProduction, this.isDevelopment);
|
|
17901
18270
|
this.remote = new ($a492ee374ae7b613$export$d902b56530cd5f87)({
|
|
17902
18271
|
isDevelopment: this.isDevelopment,
|
|
@@ -18008,6 +18377,7 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
|
|
|
18008
18377
|
|
|
18009
18378
|
|
|
18010
18379
|
|
|
18380
|
+
|
|
18011
18381
|
const $ddc6bcd0896481e5$export$2fbfa41a4de56a89 = (erc20allowances, erc721allowances)=>{
|
|
18012
18382
|
const aggregatedAllowances = [];
|
|
18013
18383
|
if (!erc20allowances.sufficient) {
|
|
@@ -18178,7 +18548,9 @@ const $35c3fc7013888ba5$export$90366d6b714c6f69 = async (provider, ownerAddress,
|
|
|
18178
18548
|
return await contract.isApprovedForAll(ownerAddress, spenderAddress);
|
|
18179
18549
|
} catch (err) {
|
|
18180
18550
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to check approval for all ERC721s of collection", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
|
|
18181
|
-
|
|
18551
|
+
ownerAddress: ownerAddress,
|
|
18552
|
+
contractAddress: contractAddress,
|
|
18553
|
+
spenderAddress: spenderAddress
|
|
18182
18554
|
});
|
|
18183
18555
|
}
|
|
18184
18556
|
};
|
|
@@ -18190,7 +18562,10 @@ const $35c3fc7013888ba5$export$ebb2a35f2b4cf5f6 = async (provider, ownerAddress,
|
|
|
18190
18562
|
return transaction;
|
|
18191
18563
|
} catch (err) {
|
|
18192
18564
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get the approval transaction for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
|
|
18193
|
-
|
|
18565
|
+
id: id.toString(),
|
|
18566
|
+
contractAddress: contractAddress,
|
|
18567
|
+
spenderAddress: spenderAddress,
|
|
18568
|
+
ownerAddress: ownerAddress
|
|
18194
18569
|
});
|
|
18195
18570
|
}
|
|
18196
18571
|
};
|
|
@@ -18200,6 +18575,7 @@ const $35c3fc7013888ba5$export$c4605a8dd415eeea = async (provider, contractAddre
|
|
|
18200
18575
|
return await contract.getApproved(id);
|
|
18201
18576
|
} catch (err) {
|
|
18202
18577
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get approved address for ERC721", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_ALLOWANCE_ERROR, {
|
|
18578
|
+
id: id.toString(),
|
|
18203
18579
|
contractAddress: contractAddress
|
|
18204
18580
|
});
|
|
18205
18581
|
}
|
|
@@ -18649,6 +19025,164 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
|
|
|
18649
19025
|
|
|
18650
19026
|
|
|
18651
19027
|
|
|
19028
|
+
const $1fda5c40669a566d$export$1fac8e857d728583 = async ()=>true;
|
|
19029
|
+
const $1fda5c40669a566d$export$2e83e9eeaf217e20 = async ()=>true;
|
|
19030
|
+
|
|
19031
|
+
|
|
19032
|
+
const $7f2e17f026d4fc8d$var$isPassportProvider = (provider)=>(provider.provider?.isPassport === true) ?? false;
|
|
19033
|
+
const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
|
|
19034
|
+
const availableRoutingOptions = {
|
|
19035
|
+
onRamp: config.isOnRampEnabled,
|
|
19036
|
+
swap: config.isSwapEnabled,
|
|
19037
|
+
bridge: config.isBridgeEnabled
|
|
19038
|
+
};
|
|
19039
|
+
// Geo-blocking checks
|
|
19040
|
+
const geoBlockingChecks = [];
|
|
19041
|
+
if (availableRoutingOptions.onRamp) geoBlockingChecks.push({
|
|
19042
|
+
id: "onRamp",
|
|
19043
|
+
promise: ($1fda5c40669a566d$export$1fac8e857d728583)()
|
|
19044
|
+
});
|
|
19045
|
+
if (availableRoutingOptions.swap) geoBlockingChecks.push({
|
|
19046
|
+
id: "swap",
|
|
19047
|
+
promise: ($1fda5c40669a566d$export$2e83e9eeaf217e20)()
|
|
19048
|
+
});
|
|
19049
|
+
if (geoBlockingChecks.length > 0) {
|
|
19050
|
+
const promises = geoBlockingChecks.map((geoBlockingCheck)=>geoBlockingCheck.promise);
|
|
19051
|
+
const geoBlockingStatus = await Promise.allSettled(promises);
|
|
19052
|
+
geoBlockingStatus.forEach((result, index)=>{
|
|
19053
|
+
const statusId = geoBlockingChecks[index].id;
|
|
19054
|
+
availableRoutingOptions[statusId] = availableRoutingOptions[statusId] && result.status === "fulfilled" && !result.value;
|
|
19055
|
+
});
|
|
19056
|
+
}
|
|
19057
|
+
// Bridge not available if passport provider
|
|
19058
|
+
availableRoutingOptions.bridge = availableRoutingOptions.bridge && !$7f2e17f026d4fc8d$var$isPassportProvider(provider);
|
|
19059
|
+
return availableRoutingOptions;
|
|
19060
|
+
};
|
|
19061
|
+
|
|
19062
|
+
|
|
19063
|
+
|
|
19064
|
+
|
|
19065
|
+
|
|
19066
|
+
|
|
19067
|
+
|
|
19068
|
+
|
|
19069
|
+
|
|
19070
|
+
async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
|
|
19071
|
+
if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
|
|
19072
|
+
if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
|
|
19073
|
+
const readOnlyProviders = new Map();
|
|
19074
|
+
const allowedNetworks = await $de192de6ef100f9f$export$3043f6442a9ef563(config, {
|
|
19075
|
+
type: ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL
|
|
19076
|
+
});
|
|
19077
|
+
allowedNetworks.networks.forEach((networkInfo)=>{
|
|
19078
|
+
const rpcUrl = config.networkMap.get(networkInfo.chainId)?.rpcUrls[0];
|
|
19079
|
+
const provider = new (JsonRpcProvider)(rpcUrl);
|
|
19080
|
+
readOnlyProviders.set(networkInfo.chainId, provider);
|
|
19081
|
+
});
|
|
19082
|
+
return readOnlyProviders;
|
|
19083
|
+
}
|
|
19084
|
+
|
|
19085
|
+
|
|
19086
|
+
|
|
19087
|
+
|
|
19088
|
+
const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, ownerAddress, availableRoutingOptions)=>{
|
|
19089
|
+
const chainBalances = new Map();
|
|
19090
|
+
const chainBalancePromises = new Map();
|
|
19091
|
+
let readOnlyProviders = new Map();
|
|
19092
|
+
let providerError;
|
|
19093
|
+
try {
|
|
19094
|
+
readOnlyProviders = await (0, $0e0060cb42e136d2$export$339cb2be73677b30)(config);
|
|
19095
|
+
} catch (error) {
|
|
19096
|
+
providerError = error;
|
|
19097
|
+
}
|
|
19098
|
+
if (readOnlyProviders.size === 0) {
|
|
19099
|
+
const noProviderResult = {
|
|
19100
|
+
success: false,
|
|
19101
|
+
error: providerError || new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider failed", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR),
|
|
19102
|
+
balances: []
|
|
19103
|
+
};
|
|
19104
|
+
chainBalances.set(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), noProviderResult);
|
|
19105
|
+
chainBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), noProviderResult);
|
|
19106
|
+
return chainBalances;
|
|
19107
|
+
}
|
|
19108
|
+
// Only get L1 Balances if we can bridge
|
|
19109
|
+
if (availableRoutingOptions.bridge) {
|
|
19110
|
+
const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
19111
|
+
if (readOnlyProviders.has(chainId)) chainBalancePromises.set(chainId, ($1564e43dde50bb61$export$fee49741664a4d7e)(config, readOnlyProviders.get(chainId), ownerAddress, chainId));
|
|
19112
|
+
else chainBalances.set(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), {
|
|
19113
|
+
success: false,
|
|
19114
|
+
error: new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`No L1 provider available for ${chainId}`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR),
|
|
19115
|
+
balances: []
|
|
19116
|
+
});
|
|
19117
|
+
}
|
|
19118
|
+
const chainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
|
|
19119
|
+
if (readOnlyProviders.has(chainId)) chainBalancePromises.set(chainId, ($1564e43dde50bb61$export$fee49741664a4d7e)(config, readOnlyProviders.get(chainId), ownerAddress, chainId));
|
|
19120
|
+
else chainBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
|
|
19121
|
+
success: false,
|
|
19122
|
+
error: new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`No L2 provider available for ${chainId}`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR),
|
|
19123
|
+
balances: []
|
|
19124
|
+
});
|
|
19125
|
+
if (chainBalancePromises.size > 0) {
|
|
19126
|
+
const chainIds = Array.from(chainBalancePromises.keys());
|
|
19127
|
+
const balanceSettledResults = await Promise.allSettled(chainBalancePromises.values());
|
|
19128
|
+
balanceSettledResults.forEach((balanceSettledResult, index)=>{
|
|
19129
|
+
const balanceChainId = chainIds[index];
|
|
19130
|
+
if (balanceSettledResult.status === "fulfilled") chainBalances.set(balanceChainId, {
|
|
19131
|
+
success: true,
|
|
19132
|
+
balances: balanceSettledResult.value.balances
|
|
19133
|
+
});
|
|
19134
|
+
else chainBalances.set(balanceChainId, {
|
|
19135
|
+
success: false,
|
|
19136
|
+
error: new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Error getting ${chainId} balances`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR),
|
|
19137
|
+
balances: []
|
|
19138
|
+
});
|
|
19139
|
+
});
|
|
19140
|
+
}
|
|
19141
|
+
return chainBalances;
|
|
19142
|
+
};
|
|
19143
|
+
|
|
19144
|
+
|
|
19145
|
+
const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
|
|
19146
|
+
// eslint-disable-next-line no-console
|
|
19147
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19148
|
+
await ($33acec7b4a26c053$export$23ddeb2642d2f9d)(config, ownerAddress, availableRoutingOptions);
|
|
19149
|
+
// Get allowed tokens?
|
|
19150
|
+
// Check bridging routes
|
|
19151
|
+
// Check on-ramp routes
|
|
19152
|
+
// Check swap routes
|
|
19153
|
+
// > Could bridge first
|
|
19154
|
+
// > Could on-ramp first
|
|
19155
|
+
// > Could double swap
|
|
19156
|
+
return {
|
|
19157
|
+
availableOptions: [],
|
|
19158
|
+
response: {
|
|
19159
|
+
type: "ROUTES_FOUND",
|
|
19160
|
+
message: "Routes found"
|
|
19161
|
+
},
|
|
19162
|
+
fundingRoutes: [
|
|
19163
|
+
{
|
|
19164
|
+
priority: 1,
|
|
19165
|
+
steps: [
|
|
19166
|
+
{
|
|
19167
|
+
type: "bridge",
|
|
19168
|
+
chainId: 1,
|
|
19169
|
+
asset: {
|
|
19170
|
+
balance: (BigNumber$1).from(0),
|
|
19171
|
+
formattedBalance: "0",
|
|
19172
|
+
token: {
|
|
19173
|
+
name: "ETH",
|
|
19174
|
+
symbol: "ETH",
|
|
19175
|
+
decimals: 18
|
|
19176
|
+
}
|
|
19177
|
+
}
|
|
19178
|
+
}
|
|
19179
|
+
]
|
|
19180
|
+
}
|
|
19181
|
+
]
|
|
19182
|
+
};
|
|
19183
|
+
};
|
|
19184
|
+
|
|
19185
|
+
|
|
18652
19186
|
const $0e7419077c373b24$export$4a2a19d99fef3b1b = (balanceCheckResult)=>{
|
|
18653
19187
|
let sufficient = true;
|
|
18654
19188
|
const transactionRequirements = [];
|
|
@@ -18679,12 +19213,123 @@ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (config, provider, itemR
|
|
|
18679
19213
|
aggregatedItems = ($074f75878f618031$export$c804c9ade5c28607)(aggregatedItems);
|
|
18680
19214
|
}
|
|
18681
19215
|
const balanceRequirements = await ($beb896e098e41faf$export$ddfc885f43c3cb6e)(config, provider, ownerAddress, aggregatedItems);
|
|
19216
|
+
// Determine which services are available
|
|
19217
|
+
const availableRoutingOptions = await ($7f2e17f026d4fc8d$export$f1ca3744c025ab81)(config, provider);
|
|
19218
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19219
|
+
await ($c16168a9c28ae4fd$export$92606e71d0a264ff)(config, ownerAddress, balanceRequirements, availableRoutingOptions);
|
|
18682
19220
|
return $0e7419077c373b24$export$4a2a19d99fef3b1b(balanceRequirements);
|
|
18683
19221
|
};
|
|
18684
19222
|
|
|
18685
19223
|
|
|
18686
19224
|
|
|
18687
19225
|
|
|
19226
|
+
|
|
19227
|
+
var $d855a5ba32004345$export$f51b97f3aaf2d5a8;
|
|
19228
|
+
(function(SignTransactionStatusType) {
|
|
19229
|
+
SignTransactionStatusType["SUCCESS"] = "SUCCESS";
|
|
19230
|
+
SignTransactionStatusType["FAILED"] = "FAILED";
|
|
19231
|
+
})($d855a5ba32004345$export$f51b97f3aaf2d5a8 || ($d855a5ba32004345$export$f51b97f3aaf2d5a8 = {}));
|
|
19232
|
+
|
|
19233
|
+
|
|
19234
|
+
const $25ac589234c10b67$export$19693ca396db083e = async (provider, approvalTransactions)=>{
|
|
19235
|
+
let receipts = [];
|
|
19236
|
+
try {
|
|
19237
|
+
const response = await Promise.all(approvalTransactions.map((transaction)=>provider.getSigner().sendTransaction(transaction)));
|
|
19238
|
+
receipts = await Promise.all(response.map((transaction)=>transaction.wait()));
|
|
19239
|
+
} catch (err) {
|
|
19240
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while executing the approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).EXECUTE_APPROVAL_TRANSACTION_ERROR, {
|
|
19241
|
+
message: err.message
|
|
19242
|
+
});
|
|
19243
|
+
}
|
|
19244
|
+
for (const receipt of receipts){
|
|
19245
|
+
if (receipt.status === 0) return {
|
|
19246
|
+
type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED,
|
|
19247
|
+
transactionHash: receipt.transactionHash,
|
|
19248
|
+
reason: "Approval transaction failed and was reverted"
|
|
19249
|
+
};
|
|
19250
|
+
}
|
|
19251
|
+
return {
|
|
19252
|
+
type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).SUCCESS
|
|
19253
|
+
};
|
|
19254
|
+
};
|
|
19255
|
+
const $25ac589234c10b67$export$2161274619257102 = async (provider, fulfilmentTransactions)=>{
|
|
19256
|
+
let receipts = [];
|
|
19257
|
+
try {
|
|
19258
|
+
const response = await Promise.all(fulfilmentTransactions.map((transaction)=>provider.getSigner().sendTransaction(transaction)));
|
|
19259
|
+
receipts = await Promise.all(response.map((transaction)=>transaction.wait()));
|
|
19260
|
+
} catch (err) {
|
|
19261
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while executing the fulfilment transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).EXECUTE_FULFILMENT_TRANSACTION_ERROR, {
|
|
19262
|
+
message: err.message
|
|
19263
|
+
});
|
|
19264
|
+
}
|
|
19265
|
+
for (const receipt of receipts){
|
|
19266
|
+
if (receipt.status === 0) return {
|
|
19267
|
+
type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED,
|
|
19268
|
+
transactionHash: receipt.transactionHash,
|
|
19269
|
+
reason: "Fulfilment transaction failed and was reverted"
|
|
19270
|
+
};
|
|
19271
|
+
}
|
|
19272
|
+
return {
|
|
19273
|
+
type: ($d855a5ba32004345$export$f51b97f3aaf2d5a8).SUCCESS
|
|
19274
|
+
};
|
|
19275
|
+
};
|
|
19276
|
+
const $25ac589234c10b67$export$1d9a7a8a40780de = async (provider, unsignedMessage)=>{
|
|
19277
|
+
try {
|
|
19278
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
19279
|
+
const signedMessage = await provider.getSigner()._signTypedData(unsignedMessage.unsignedMessage.domain, unsignedMessage.unsignedMessage.types, unsignedMessage.unsignedMessage.value);
|
|
19280
|
+
return {
|
|
19281
|
+
orderComponents: unsignedMessage.orderComponents,
|
|
19282
|
+
orderHash: unsignedMessage.orderHash,
|
|
19283
|
+
signedMessage: signedMessage
|
|
19284
|
+
};
|
|
19285
|
+
} catch (err) {
|
|
19286
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while signing the message", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).SIGN_MESSAGE_ERROR, {
|
|
19287
|
+
message: err.message
|
|
19288
|
+
});
|
|
19289
|
+
}
|
|
19290
|
+
};
|
|
19291
|
+
|
|
19292
|
+
|
|
19293
|
+
|
|
19294
|
+
const $a7367d01c6e76b1c$export$b087719c36e0f2dc = async (actions)=>{
|
|
19295
|
+
let approvalTransactions = [];
|
|
19296
|
+
let fulfilmentTransactions = [];
|
|
19297
|
+
const approvalPromises = [];
|
|
19298
|
+
const fulfilmentPromises = [];
|
|
19299
|
+
for (const action of actions){
|
|
19300
|
+
if (action.type !== (ActionType).TRANSACTION) continue;
|
|
19301
|
+
if (action.purpose === (TransactionPurpose).APPROVAL) approvalPromises.push(action.buildTransaction());
|
|
19302
|
+
if (action.purpose === (TransactionPurpose).FULFILL_ORDER) fulfilmentPromises.push(action.buildTransaction());
|
|
19303
|
+
}
|
|
19304
|
+
approvalTransactions = await Promise.all(approvalPromises);
|
|
19305
|
+
fulfilmentTransactions = await Promise.all(fulfilmentPromises);
|
|
19306
|
+
return {
|
|
19307
|
+
approvalTransactions: approvalTransactions,
|
|
19308
|
+
fulfilmentTransactions: fulfilmentTransactions
|
|
19309
|
+
};
|
|
19310
|
+
};
|
|
19311
|
+
const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, actions)=>{
|
|
19312
|
+
let unsignedMessage;
|
|
19313
|
+
for (const action of actions){
|
|
19314
|
+
if (action.type !== (ActionType).SIGNABLE) continue;
|
|
19315
|
+
if (action.purpose === (SignablePurpose).CREATE_LISTING) unsignedMessage = {
|
|
19316
|
+
domain: action.message.domain,
|
|
19317
|
+
types: action.message.types,
|
|
19318
|
+
value: action.message.value
|
|
19319
|
+
};
|
|
19320
|
+
}
|
|
19321
|
+
if (!unsignedMessage) return undefined;
|
|
19322
|
+
return {
|
|
19323
|
+
orderHash: orderHash,
|
|
19324
|
+
orderComponents: orderComponents,
|
|
19325
|
+
unsignedMessage: unsignedMessage
|
|
19326
|
+
};
|
|
19327
|
+
};
|
|
19328
|
+
|
|
19329
|
+
|
|
19330
|
+
|
|
19331
|
+
|
|
19332
|
+
|
|
18688
19333
|
const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
|
|
18689
19334
|
switch(type){
|
|
18690
19335
|
case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
|
|
@@ -18702,17 +19347,10 @@ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount
|
|
|
18702
19347
|
};
|
|
18703
19348
|
}
|
|
18704
19349
|
};
|
|
18705
|
-
const $64863c39386de592$export$
|
|
18706
|
-
|
|
18707
|
-
if (action.type === (ActionType).TRANSACTION && action.purpose === (TransactionPurpose).FULFILL_ORDER) // eslint-disable-next-line no-await-in-loop
|
|
18708
|
-
return await action.buildTransaction();
|
|
18709
|
-
}
|
|
18710
|
-
return undefined;
|
|
18711
|
-
};
|
|
18712
|
-
const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, transaction)=>{
|
|
18713
|
-
if (transaction) return {
|
|
19350
|
+
const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, unsignedTransactions)=>{
|
|
19351
|
+
if (unsignedTransactions.fulfilmentTransactions.length > 0) return {
|
|
18714
19352
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
|
|
18715
|
-
transaction:
|
|
19353
|
+
transaction: unsignedTransactions.fulfilmentTransactions[0]
|
|
18716
19354
|
};
|
|
18717
19355
|
return {
|
|
18718
19356
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
|
|
@@ -18738,12 +19376,18 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
18738
19376
|
message: err.message
|
|
18739
19377
|
});
|
|
18740
19378
|
}
|
|
18741
|
-
let
|
|
19379
|
+
let unsignedTransactions = {
|
|
19380
|
+
approvalTransactions: [],
|
|
19381
|
+
fulfilmentTransactions: []
|
|
19382
|
+
};
|
|
18742
19383
|
try {
|
|
18743
19384
|
const fulfillerAddress = await provider.getSigner().getAddress();
|
|
18744
19385
|
const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress);
|
|
18745
|
-
|
|
18746
|
-
} catch {
|
|
19386
|
+
unsignedTransactions = await (0, $a7367d01c6e76b1c$export$b087719c36e0f2dc)(actions);
|
|
19387
|
+
} catch {
|
|
19388
|
+
// Silently ignore error as this is usually thrown if user does not have enough balance
|
|
19389
|
+
// todo: if balance error - can we determine if its the balance error otherwise throw?
|
|
19390
|
+
}
|
|
18747
19391
|
let amount = (BigNumber$1).from("0");
|
|
18748
19392
|
let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
18749
19393
|
let contractAddress = "";
|
|
@@ -18771,12 +19415,78 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
18771
19415
|
const itemRequirements = [
|
|
18772
19416
|
$64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
|
|
18773
19417
|
];
|
|
18774
|
-
await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit,
|
|
19418
|
+
const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransactions));
|
|
19419
|
+
if (smartCheckoutResult.sufficient) {
|
|
19420
|
+
const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
|
|
19421
|
+
if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
|
|
19422
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19423
|
+
orderId: orderId,
|
|
19424
|
+
status: {
|
|
19425
|
+
type: ($aa144554f9ef124b$export$226b052ecb8ca80).FAILED,
|
|
19426
|
+
transactionHash: approvalResult.transactionHash,
|
|
19427
|
+
reason: approvalResult.reason
|
|
19428
|
+
}
|
|
19429
|
+
};
|
|
19430
|
+
const fulfilmentResult = await ($25ac589234c10b67$export$2161274619257102)(provider, unsignedTransactions.fulfilmentTransactions);
|
|
19431
|
+
if (fulfilmentResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
|
|
19432
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19433
|
+
orderId: orderId,
|
|
19434
|
+
status: {
|
|
19435
|
+
type: ($aa144554f9ef124b$export$226b052ecb8ca80).FAILED,
|
|
19436
|
+
transactionHash: fulfilmentResult.transactionHash,
|
|
19437
|
+
reason: fulfilmentResult.reason
|
|
19438
|
+
}
|
|
19439
|
+
};
|
|
19440
|
+
return {
|
|
19441
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19442
|
+
orderId: orderId,
|
|
19443
|
+
status: {
|
|
19444
|
+
type: ($aa144554f9ef124b$export$226b052ecb8ca80).SUCCESS
|
|
19445
|
+
}
|
|
19446
|
+
};
|
|
19447
|
+
}
|
|
18775
19448
|
return {
|
|
18776
|
-
|
|
18777
|
-
|
|
18778
|
-
|
|
18779
|
-
|
|
19449
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19450
|
+
orderId: orderId
|
|
19451
|
+
};
|
|
19452
|
+
};
|
|
19453
|
+
|
|
19454
|
+
|
|
19455
|
+
|
|
19456
|
+
|
|
19457
|
+
|
|
19458
|
+
|
|
19459
|
+
|
|
19460
|
+
|
|
19461
|
+
|
|
19462
|
+
const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, orderId)=>{
|
|
19463
|
+
let unsignedCancelOrderTransaction;
|
|
19464
|
+
try {
|
|
19465
|
+
const offererAddress = await provider.getSigner().getAddress();
|
|
19466
|
+
const orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
|
|
19467
|
+
const cancelOrderResponse = await orderbook.cancelOrder(orderId, offererAddress);
|
|
19468
|
+
unsignedCancelOrderTransaction = cancelOrderResponse.unsignedCancelOrderTransaction;
|
|
19469
|
+
} catch (err) {
|
|
19470
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while cancelling the order listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CANCEL_ORDER_LISTING_ERROR, {
|
|
19471
|
+
orderId: orderId,
|
|
19472
|
+
message: err.message
|
|
19473
|
+
});
|
|
19474
|
+
}
|
|
19475
|
+
const result = await ($25ac589234c10b67$export$2161274619257102)(provider, [
|
|
19476
|
+
unsignedCancelOrderTransaction
|
|
19477
|
+
]);
|
|
19478
|
+
if (result.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
|
|
19479
|
+
orderId: orderId,
|
|
19480
|
+
status: {
|
|
19481
|
+
type: ($1e6b81bbd98b3a91$export$c0189a8c30039654).FAILED,
|
|
19482
|
+
transactionHash: result.transactionHash,
|
|
19483
|
+
reason: result.reason
|
|
19484
|
+
}
|
|
19485
|
+
};
|
|
19486
|
+
return {
|
|
19487
|
+
orderId: orderId,
|
|
19488
|
+
status: {
|
|
19489
|
+
type: ($1e6b81bbd98b3a91$export$c0189a8c30039654).SUCCESS
|
|
18780
19490
|
}
|
|
18781
19491
|
};
|
|
18782
19492
|
};
|
|
@@ -18789,20 +19499,119 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
18789
19499
|
|
|
18790
19500
|
|
|
18791
19501
|
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
type: ($
|
|
19502
|
+
|
|
19503
|
+
|
|
19504
|
+
|
|
19505
|
+
|
|
19506
|
+
const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
|
|
19507
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
19508
|
+
id: id,
|
|
19509
|
+
contractAddress: contractAddress,
|
|
19510
|
+
spenderAddress: spenderAddress
|
|
18798
19511
|
});
|
|
18799
|
-
|
|
18800
|
-
|
|
18801
|
-
|
|
18802
|
-
|
|
19512
|
+
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
|
|
19513
|
+
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
19514
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
19515
|
+
amount: buyToken.amount.toString()
|
|
19516
|
+
};
|
|
19517
|
+
return {
|
|
19518
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
|
|
19519
|
+
amount: buyToken.amount.toString(),
|
|
19520
|
+
contractAddress: buyToken.contractAddress
|
|
19521
|
+
};
|
|
19522
|
+
};
|
|
19523
|
+
const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, contractAddress, buyToken)=>{
|
|
19524
|
+
let orderbook;
|
|
19525
|
+
let listing;
|
|
19526
|
+
let spenderAddress = "";
|
|
19527
|
+
try {
|
|
19528
|
+
const walletAddress = await provider.getSigner().getAddress();
|
|
19529
|
+
orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
|
|
19530
|
+
const { seaportContractAddress: seaportContractAddress } = orderbook.config();
|
|
19531
|
+
spenderAddress = seaportContractAddress;
|
|
19532
|
+
listing = await orderbook.prepareListing({
|
|
19533
|
+
makerAddress: walletAddress,
|
|
19534
|
+
buy: $9085b221b72ac69e$export$586d02673c66d423(buyToken),
|
|
19535
|
+
sell: {
|
|
19536
|
+
type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
19537
|
+
contractAddress: contractAddress,
|
|
19538
|
+
tokenId: id
|
|
19539
|
+
}
|
|
19540
|
+
});
|
|
19541
|
+
} catch (err) {
|
|
19542
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
|
|
19543
|
+
message: err.message,
|
|
19544
|
+
id: id,
|
|
19545
|
+
collectionAddress: contractAddress
|
|
19546
|
+
});
|
|
19547
|
+
}
|
|
19548
|
+
const itemRequirements = [
|
|
19549
|
+
$9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
|
|
19550
|
+
];
|
|
19551
|
+
const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
|
|
19552
|
+
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
|
|
19553
|
+
gasToken: {
|
|
19554
|
+
type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
|
|
19555
|
+
limit: (BigNumber$1).from((constants).estimatedFulfillmentGasGwei)
|
|
19556
|
+
}
|
|
18803
19557
|
});
|
|
18804
|
-
|
|
18805
|
-
|
|
19558
|
+
if (smartCheckoutResult.sufficient) {
|
|
19559
|
+
const unsignedMessage = ($a7367d01c6e76b1c$export$d62081fac18000c2)(listing.orderHash, listing.orderComponents, listing.actions);
|
|
19560
|
+
if (!unsignedMessage) // For sell it is expected the orderbook will always return an unsigned message
|
|
19561
|
+
// If for some reason it is missing then we cannot proceed with the create listing
|
|
19562
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("The unsigned message is missing after preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).SIGN_MESSAGE_ERROR, {
|
|
19563
|
+
id: id,
|
|
19564
|
+
collectionAddress: contractAddress
|
|
19565
|
+
});
|
|
19566
|
+
const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
|
|
19567
|
+
const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
|
|
19568
|
+
const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
|
|
19569
|
+
if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
|
|
19570
|
+
id: id,
|
|
19571
|
+
collectionAddress: contractAddress,
|
|
19572
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19573
|
+
status: {
|
|
19574
|
+
type: ($c2874b006e92b115$export$a9780122aaa0801a).FAILED,
|
|
19575
|
+
transactionHash: approvalResult.transactionHash,
|
|
19576
|
+
reason: approvalResult.reason
|
|
19577
|
+
}
|
|
19578
|
+
};
|
|
19579
|
+
let orderId = "";
|
|
19580
|
+
try {
|
|
19581
|
+
const order = await orderbook.createListing({
|
|
19582
|
+
orderComponents: signedMessage.orderComponents,
|
|
19583
|
+
orderHash: signedMessage.orderHash,
|
|
19584
|
+
orderSignature: signedMessage.signedMessage
|
|
19585
|
+
});
|
|
19586
|
+
orderId = order.result.id;
|
|
19587
|
+
} catch (err) {
|
|
19588
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while creating the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR, {
|
|
19589
|
+
message: err.message,
|
|
19590
|
+
id: id,
|
|
19591
|
+
collectionAddress: contractAddress
|
|
19592
|
+
});
|
|
19593
|
+
}
|
|
19594
|
+
return {
|
|
19595
|
+
id: id,
|
|
19596
|
+
collectionAddress: contractAddress,
|
|
19597
|
+
smartCheckoutResult: smartCheckoutResult,
|
|
19598
|
+
status: {
|
|
19599
|
+
type: ($c2874b006e92b115$export$a9780122aaa0801a).SUCCESS,
|
|
19600
|
+
orderId: orderId
|
|
19601
|
+
}
|
|
19602
|
+
};
|
|
19603
|
+
}
|
|
19604
|
+
return {
|
|
19605
|
+
id: id,
|
|
19606
|
+
collectionAddress: contractAddress,
|
|
19607
|
+
smartCheckoutResult: smartCheckoutResult
|
|
19608
|
+
};
|
|
19609
|
+
};
|
|
19610
|
+
|
|
19611
|
+
|
|
19612
|
+
|
|
19613
|
+
|
|
19614
|
+
|
|
18806
19615
|
|
|
18807
19616
|
|
|
18808
19617
|
const $a8cb37a3fc8eb863$var$SANDBOX_CONFIGURATION = {
|
|
@@ -18933,6 +19742,26 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
18933
19742
|
await $64863c39386de592$export$7f8e2b98eca5a7f0(this.config, web3Provider, params.orderId);
|
|
18934
19743
|
}
|
|
18935
19744
|
/**
|
|
19745
|
+
* Determines the requirements for performing a sell.
|
|
19746
|
+
* @param {SellParams} params - The parameters for the sell.
|
|
19747
|
+
*/ async sell(params) {
|
|
19748
|
+
if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
|
|
19749
|
+
// eslint-disable-next-line no-console
|
|
19750
|
+
console.warn("This endpoint is currently under construction.");
|
|
19751
|
+
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
19752
|
+
await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
|
|
19753
|
+
}
|
|
19754
|
+
/**
|
|
19755
|
+
* Cancels a sell.
|
|
19756
|
+
* @param {CancelParams} params - The parameters for the cancel.
|
|
19757
|
+
*/ async cancel(params) {
|
|
19758
|
+
if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
|
|
19759
|
+
// eslint-disable-next-line no-console
|
|
19760
|
+
console.warn("This endpoint is currently under construction.");
|
|
19761
|
+
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
19762
|
+
await $9c3db1bb9c8b69d3$export$70b61ad426ddbe54(this.config, web3Provider, params.orderId);
|
|
19763
|
+
}
|
|
19764
|
+
/**
|
|
18936
19765
|
* Determines the transaction requirements to complete a purchase.
|
|
18937
19766
|
* @params {SmartCheckoutParams} params - The parameters for smart checkout.
|
|
18938
19767
|
*/ async smartCheckout(params) {
|
|
@@ -18940,6 +19769,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
18940
19769
|
// eslint-disable-next-line no-console
|
|
18941
19770
|
console.warn("This endpoint is currently under construction.");
|
|
18942
19771
|
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
19772
|
+
// console.log('Smart Checkout Params ::', params);
|
|
18943
19773
|
await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
18944
19774
|
}
|
|
18945
19775
|
/**
|