@imtbl/sdk 0.16.0-alpha.1 → 0.17.0
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 +106 -7
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +218 -40
- package/dist/checkout_sdk.js +751 -297
- 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 +14 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +1213 -341
- package/dist/index.d.ts +415 -48
- package/dist/index.js +1198 -326
- package/dist/passport.js +77 -6
- package/package.json +6 -2
package/dist/checkout_sdk.js
CHANGED
|
@@ -2,9 +2,8 @@ import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as Bi
|
|
|
2
2
|
import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
|
|
3
3
|
import $7v2Z6$axios, { HttpStatusCode } from 'axios';
|
|
4
4
|
import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
|
|
5
|
-
import { TradeType, Token,
|
|
5
|
+
import { TradeType, Token, CurrencyAmount, Percent } from '@uniswap/sdk-core';
|
|
6
6
|
import assert from 'assert';
|
|
7
|
-
import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
|
|
8
7
|
import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
|
|
9
8
|
import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
|
|
10
9
|
import { SwapRouter } from '@uniswap/router-sdk';
|
|
@@ -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,6 +15018,212 @@ startTokenIn = tokenIn) => {
|
|
|
15224
15018
|
return routes;
|
|
15225
15019
|
};
|
|
15226
15020
|
|
|
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);
|
|
15043
|
+
}
|
|
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);
|
|
15075
|
+
}
|
|
15076
|
+
catch (e) {
|
|
15077
|
+
const message = e instanceof Error ? e.message : 'Unknown Error';
|
|
15078
|
+
throw new ApproveError(`failed to get allowance: ${message}`);
|
|
15079
|
+
}
|
|
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);
|
|
15084
|
+
}
|
|
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
15227
|
class Fees {
|
|
15228
15228
|
secondaryFees;
|
|
15229
15229
|
amount;
|
|
@@ -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,
|
|
@@ -16977,6 +16974,18 @@ const constants = {
|
|
|
16977
16974
|
|
|
16978
16975
|
|
|
16979
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 = {}));
|
|
16980
16989
|
|
|
16981
16990
|
|
|
16982
16991
|
/**
|
|
@@ -17024,6 +17033,13 @@ var $a47e48dd2c04791b$export$1f05a55fe0680cc7;
|
|
|
17024
17033
|
|
|
17025
17034
|
|
|
17026
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
|
+
|
|
17027
17043
|
var $08d5ddc39acd6833$export$fd9b17d87f4121d2;
|
|
17028
17044
|
(function(TokenFilterTypes) {
|
|
17029
17045
|
TokenFilterTypes["ALL"] = "all";
|
|
@@ -17074,13 +17090,25 @@ const $e768639828688ca3$export$44dde05038008549 = {
|
|
|
17074
17090
|
const $d85ad1457a3f1a83$export$7d3a9eeba384fa59 = "development";
|
|
17075
17091
|
const $d85ad1457a3f1a83$export$b80040cb173ba6e9 = "0x0000000000000000000000000000000000001010";
|
|
17076
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
|
+
};
|
|
17077
17099
|
const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
|
|
17078
17100
|
[$d85ad1457a3f1a83$export$7d3a9eeba384fa59]: "https://checkout-api.dev.immutable.com",
|
|
17079
17101
|
[(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
|
|
17080
17102
|
[(Environment$1).PRODUCTION]: "https://checkout-api.immutable.com"
|
|
17081
17103
|
};
|
|
17104
|
+
const $d85ad1457a3f1a83$export$72176e2233d7d5d = true;
|
|
17105
|
+
const $d85ad1457a3f1a83$export$566b5975cc83d6b4 = true;
|
|
17106
|
+
const $d85ad1457a3f1a83$export$261cde2078dba35b = true;
|
|
17082
17107
|
const $d85ad1457a3f1a83$export$fc55ed5a42b458ba = {
|
|
17083
|
-
[($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET]:
|
|
17108
|
+
[($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET]: {
|
|
17109
|
+
url: "https://explorer.testnet.immutable.com",
|
|
17110
|
+
nativeToken: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17111
|
+
}
|
|
17084
17112
|
};
|
|
17085
17113
|
const $d85ad1457a3f1a83$export$6f24f3cef7d501c4 = new Map([
|
|
17086
17114
|
[
|
|
@@ -17109,12 +17137,7 @@ const $d85ad1457a3f1a83$export$6f24f3cef7d501c4 = new Map([
|
|
|
17109
17137
|
rpcUrls: [
|
|
17110
17138
|
"https://rpc.immutable.com"
|
|
17111
17139
|
],
|
|
17112
|
-
nativeCurrency:
|
|
17113
|
-
name: "IMX",
|
|
17114
|
-
symbol: "IMX",
|
|
17115
|
-
decimals: 18,
|
|
17116
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17117
|
-
}
|
|
17140
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17118
17141
|
}
|
|
17119
17142
|
]
|
|
17120
17143
|
]);
|
|
@@ -17145,12 +17168,7 @@ const $d85ad1457a3f1a83$export$3e81fc0987227f10 = new Map([
|
|
|
17145
17168
|
rpcUrls: [
|
|
17146
17169
|
"https://rpc.testnet.immutable.com"
|
|
17147
17170
|
],
|
|
17148
|
-
nativeCurrency:
|
|
17149
|
-
name: "IMX",
|
|
17150
|
-
symbol: "IMX",
|
|
17151
|
-
decimals: 18,
|
|
17152
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17153
|
-
}
|
|
17171
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17154
17172
|
}
|
|
17155
17173
|
]
|
|
17156
17174
|
]);
|
|
@@ -17181,12 +17199,7 @@ const $d85ad1457a3f1a83$export$3a9ebede6a150274 = new Map([
|
|
|
17181
17199
|
rpcUrls: [
|
|
17182
17200
|
"https://rpc.dev.immutable.com"
|
|
17183
17201
|
],
|
|
17184
|
-
nativeCurrency:
|
|
17185
|
-
name: "IMX",
|
|
17186
|
-
symbol: "IMX",
|
|
17187
|
-
decimals: 18,
|
|
17188
|
-
address: $d85ad1457a3f1a83$export$b80040cb173ba6e9
|
|
17189
|
-
}
|
|
17202
|
+
nativeCurrency: $d85ad1457a3f1a83$var$ZKEVM_NATIVE_TOKEN
|
|
17190
17203
|
}
|
|
17191
17204
|
]
|
|
17192
17205
|
]);
|
|
@@ -17430,10 +17443,15 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
|
|
|
17430
17443
|
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
17431
17444
|
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
17432
17445
|
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
17446
|
+
CheckoutErrorType["CANCEL_ORDER_LISTING_ERROR"] = "CANCEL_ORDER_LISTING_ERROR";
|
|
17433
17447
|
CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
|
|
17448
|
+
CheckoutErrorType["CREATE_ORDER_LISTING_ERROR"] = "CREATE_ORDER_LISTING_ERROR";
|
|
17434
17449
|
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
17435
17450
|
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
17436
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";
|
|
17437
17455
|
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
17438
17456
|
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
17439
17457
|
message;
|
|
@@ -17639,6 +17657,7 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = async (config, { type: type =
|
|
|
17639
17657
|
const $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL = 60; // seconds
|
|
17640
17658
|
class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
|
|
17641
17659
|
url;
|
|
17660
|
+
nativeToken;
|
|
17642
17661
|
ttl;
|
|
17643
17662
|
chainId;
|
|
17644
17663
|
cacheMap;
|
|
@@ -17662,7 +17681,14 @@ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
|
|
|
17662
17681
|
* @param ttl cache TTL
|
|
17663
17682
|
*/ constructor(params){
|
|
17664
17683
|
this.chainId = params.chainId;
|
|
17665
|
-
this.url = ($d85ad1457a3f1a83$export$fc55ed5a42b458ba)[this.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
|
+
};
|
|
17666
17692
|
this.cacheMap = {};
|
|
17667
17693
|
this.ttl = params.ttl !== undefined ? params.ttl : $fd8a8472dcc3ec2b$var$CACHE_DATA_TTL;
|
|
17668
17694
|
}
|
|
@@ -17675,14 +17701,14 @@ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
|
|
|
17675
17701
|
* @param err error to evaluate
|
|
17676
17702
|
*/ static isBlockscoutError = (err)=>"code" in err;
|
|
17677
17703
|
/**
|
|
17678
|
-
*
|
|
17704
|
+
* getTokensByWalletAddress fetches the list of tokens (by type) owned by the wallet address.
|
|
17679
17705
|
* @param walletAddress wallet address
|
|
17680
|
-
* @param tokenType token
|
|
17681
|
-
* @param nextPage parameters for the next page, to be provided
|
|
17706
|
+
* @param tokenType token type
|
|
17707
|
+
* @param nextPage parameters for the next page, to be provided alongside walletAddress and tokenType
|
|
17682
17708
|
* @returns list of tokens given the wallet address and the token types
|
|
17683
|
-
*/ async
|
|
17709
|
+
*/ async getTokensByWalletAddress(params) {
|
|
17684
17710
|
try {
|
|
17685
|
-
let url = `${this.url}/api/v2/addresses/${params.walletAddress}/tokens?type=${params.tokenType
|
|
17711
|
+
let url = `${this.url}/api/v2/addresses/${params.walletAddress}/tokens?type=${params.tokenType}`;
|
|
17686
17712
|
if (params.nextPage) url += `&${new URLSearchParams(params.nextPage)}`;
|
|
17687
17713
|
// Cache response data to prevent unnecessary requests
|
|
17688
17714
|
const cached = this.getCache(url);
|
|
@@ -17692,8 +17718,51 @@ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
|
|
|
17692
17718
|
code: response.status,
|
|
17693
17719
|
message: response.statusText
|
|
17694
17720
|
});
|
|
17695
|
-
|
|
17696
|
-
|
|
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);
|
|
17697
17766
|
} catch (err) {
|
|
17698
17767
|
let code = (HttpStatusCode).InternalServerError;
|
|
17699
17768
|
let message = "InternalServerError";
|
|
@@ -17771,16 +17840,14 @@ const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId,
|
|
|
17771
17840
|
});
|
|
17772
17841
|
// Hold the items in an array for post-fetching processing
|
|
17773
17842
|
const items = [];
|
|
17774
|
-
const tokenType =
|
|
17775
|
-
($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20
|
|
17776
|
-
];
|
|
17843
|
+
const tokenType = ($887a00f8f72d61f0$export$5bd1ea2b3d18210).ERC20;
|
|
17777
17844
|
// Given that the widgets aren't yet designed to support pagination,
|
|
17778
17845
|
// fetch all the possible tokens associated to a given wallet address.
|
|
17779
17846
|
let resp;
|
|
17780
17847
|
try {
|
|
17781
17848
|
do {
|
|
17782
17849
|
// eslint-disable-next-line no-await-in-loop
|
|
17783
|
-
resp = await $1564e43dde50bb61$var$blockscoutClient.
|
|
17850
|
+
resp = await $1564e43dde50bb61$var$blockscoutClient.getTokensByWalletAddress({
|
|
17784
17851
|
walletAddress: walletAddress,
|
|
17785
17852
|
tokenType: tokenType,
|
|
17786
17853
|
nextPage: resp?.next_page_params
|
|
@@ -17788,7 +17855,15 @@ const $1564e43dde50bb61$export$8c978679845804d4 = async (walletAddress, chainId,
|
|
|
17788
17855
|
items.push(...resp.items);
|
|
17789
17856
|
}while (resp.next_page_params);
|
|
17790
17857
|
} catch (err) {
|
|
17791
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(err.message || "InternalServerError", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_INDEXER_BALANCE_ERROR, 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);
|
|
17792
17867
|
}
|
|
17793
17868
|
return {
|
|
17794
17869
|
balances: items.map((item)=>{
|
|
@@ -17818,7 +17893,7 @@ const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, w
|
|
|
17818
17893
|
else allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address));
|
|
17819
17894
|
});
|
|
17820
17895
|
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
17821
|
-
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((
|
|
17896
|
+
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((result)=>result.value);
|
|
17822
17897
|
return {
|
|
17823
17898
|
balances: balances
|
|
17824
17899
|
};
|
|
@@ -17839,6 +17914,9 @@ const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, w
|
|
|
17839
17914
|
console.error(err);
|
|
17840
17915
|
}
|
|
17841
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.
|
|
17842
17920
|
return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
|
|
17843
17921
|
};
|
|
17844
17922
|
|
|
@@ -18174,6 +18252,9 @@ class $4013c5c91bb535f6$export$4823433c4a67bbc6 {
|
|
|
18174
18252
|
// Environment.DEVELOPMENT
|
|
18175
18253
|
isDevelopment = false;
|
|
18176
18254
|
isProduction;
|
|
18255
|
+
isOnRampEnabled;
|
|
18256
|
+
isSwapEnabled;
|
|
18257
|
+
isBridgeEnabled;
|
|
18177
18258
|
remote;
|
|
18178
18259
|
environment;
|
|
18179
18260
|
networkMap;
|
|
@@ -18182,6 +18263,9 @@ class $4013c5c91bb535f6$export$4823433c4a67bbc6 {
|
|
|
18182
18263
|
this.environment = config.baseConfig.environment;
|
|
18183
18264
|
// Developer mode will super set any environment configuration
|
|
18184
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);
|
|
18185
18269
|
this.networkMap = $4013c5c91bb535f6$var$networkMap(this.isProduction, this.isDevelopment);
|
|
18186
18270
|
this.remote = new ($a492ee374ae7b613$export$d902b56530cd5f87)({
|
|
18187
18271
|
isDevelopment: this.isDevelopment,
|
|
@@ -18293,6 +18377,7 @@ async function $2e7bf45a7c9a9570$export$942c8de7174809fc(params, readOnlyProvide
|
|
|
18293
18377
|
|
|
18294
18378
|
|
|
18295
18379
|
|
|
18380
|
+
|
|
18296
18381
|
const $ddc6bcd0896481e5$export$2fbfa41a4de56a89 = (erc20allowances, erc721allowances)=>{
|
|
18297
18382
|
const aggregatedAllowances = [];
|
|
18298
18383
|
if (!erc20allowances.sufficient) {
|
|
@@ -18940,6 +19025,164 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
|
|
|
18940
19025
|
|
|
18941
19026
|
|
|
18942
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
|
+
|
|
18943
19186
|
const $0e7419077c373b24$export$4a2a19d99fef3b1b = (balanceCheckResult)=>{
|
|
18944
19187
|
let sufficient = true;
|
|
18945
19188
|
const transactionRequirements = [];
|
|
@@ -18970,12 +19213,123 @@ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (config, provider, itemR
|
|
|
18970
19213
|
aggregatedItems = ($074f75878f618031$export$c804c9ade5c28607)(aggregatedItems);
|
|
18971
19214
|
}
|
|
18972
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);
|
|
18973
19220
|
return $0e7419077c373b24$export$4a2a19d99fef3b1b(balanceRequirements);
|
|
18974
19221
|
};
|
|
18975
19222
|
|
|
18976
19223
|
|
|
18977
19224
|
|
|
18978
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
|
+
|
|
18979
19333
|
const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount, spenderAddress)=>{
|
|
18980
19334
|
switch(type){
|
|
18981
19335
|
case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
|
|
@@ -18993,17 +19347,10 @@ const $64863c39386de592$export$4249179755829904 = (type, contractAddress, amount
|
|
|
18993
19347
|
};
|
|
18994
19348
|
}
|
|
18995
19349
|
};
|
|
18996
|
-
const $64863c39386de592$export$
|
|
18997
|
-
|
|
18998
|
-
if (action.type === (ActionType).TRANSACTION && action.purpose === (TransactionPurpose).FULFILL_ORDER) // eslint-disable-next-line no-await-in-loop
|
|
18999
|
-
return await action.buildTransaction();
|
|
19000
|
-
}
|
|
19001
|
-
return undefined;
|
|
19002
|
-
};
|
|
19003
|
-
const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, transaction)=>{
|
|
19004
|
-
if (transaction) return {
|
|
19350
|
+
const $64863c39386de592$export$8f2ff92ab8657f0b = (gasLimit, unsignedTransactions)=>{
|
|
19351
|
+
if (unsignedTransactions.fulfilmentTransactions.length > 0) return {
|
|
19005
19352
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).TRANSACTION,
|
|
19006
|
-
transaction:
|
|
19353
|
+
transaction: unsignedTransactions.fulfilmentTransactions[0]
|
|
19007
19354
|
};
|
|
19008
19355
|
return {
|
|
19009
19356
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
|
|
@@ -19029,12 +19376,18 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
19029
19376
|
message: err.message
|
|
19030
19377
|
});
|
|
19031
19378
|
}
|
|
19032
|
-
let
|
|
19379
|
+
let unsignedTransactions = {
|
|
19380
|
+
approvalTransactions: [],
|
|
19381
|
+
fulfilmentTransactions: []
|
|
19382
|
+
};
|
|
19033
19383
|
try {
|
|
19034
19384
|
const fulfillerAddress = await provider.getSigner().getAddress();
|
|
19035
19385
|
const { actions: actions } = await orderbook.fulfillOrder(orderId, fulfillerAddress);
|
|
19036
|
-
|
|
19037
|
-
} 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
|
+
}
|
|
19038
19391
|
let amount = (BigNumber$1).from("0");
|
|
19039
19392
|
let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
19040
19393
|
let contractAddress = "";
|
|
@@ -19062,12 +19415,78 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
19062
19415
|
const itemRequirements = [
|
|
19063
19416
|
$64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
|
|
19064
19417
|
];
|
|
19065
|
-
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
|
+
}
|
|
19066
19448
|
return {
|
|
19067
|
-
|
|
19068
|
-
|
|
19069
|
-
|
|
19070
|
-
|
|
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
|
|
19071
19490
|
}
|
|
19072
19491
|
};
|
|
19073
19492
|
};
|
|
@@ -19081,13 +19500,16 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
19081
19500
|
|
|
19082
19501
|
|
|
19083
19502
|
|
|
19503
|
+
|
|
19504
|
+
|
|
19505
|
+
|
|
19084
19506
|
const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
|
|
19085
19507
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
19086
19508
|
id: id,
|
|
19087
19509
|
contractAddress: contractAddress,
|
|
19088
19510
|
spenderAddress: spenderAddress
|
|
19089
19511
|
});
|
|
19090
|
-
const $9085b221b72ac69e$export$
|
|
19512
|
+
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
|
|
19091
19513
|
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
19092
19514
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
19093
19515
|
amount: buyToken.amount.toString()
|
|
@@ -19109,7 +19531,7 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
19109
19531
|
spenderAddress = seaportContractAddress;
|
|
19110
19532
|
listing = await orderbook.prepareListing({
|
|
19111
19533
|
makerAddress: walletAddress,
|
|
19112
|
-
buy: $9085b221b72ac69e$export$
|
|
19534
|
+
buy: $9085b221b72ac69e$export$586d02673c66d423(buyToken),
|
|
19113
19535
|
sell: {
|
|
19114
19536
|
type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
19115
19537
|
contractAddress: contractAddress,
|
|
@@ -19126,8 +19548,6 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
19126
19548
|
const itemRequirements = [
|
|
19127
19549
|
$9085b221b72ac69e$export$af768ccdf17d5c04(id, contractAddress, spenderAddress)
|
|
19128
19550
|
];
|
|
19129
|
-
// eslint-disable-next-line no-console
|
|
19130
|
-
console.log(listing); // TODO: Get order signature, provider.getSigner()._signTypedData to sign
|
|
19131
19551
|
const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
|
|
19132
19552
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
|
|
19133
19553
|
gasToken: {
|
|
@@ -19135,14 +19555,55 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
19135
19555
|
limit: (BigNumber$1).from((constants).estimatedFulfillmentGasGwei)
|
|
19136
19556
|
}
|
|
19137
19557
|
});
|
|
19138
|
-
|
|
19139
|
-
|
|
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
|
+
}
|
|
19140
19604
|
return {
|
|
19141
|
-
|
|
19142
|
-
|
|
19143
|
-
type: ($4b58188d47aafe8d$export$537fa3efd10ed435).NATIVE,
|
|
19144
|
-
limit: (BigNumber$1).from((constants).estimatedFulfillmentGasGwei)
|
|
19145
|
-
},
|
|
19605
|
+
id: id,
|
|
19606
|
+
collectionAddress: contractAddress,
|
|
19146
19607
|
smartCheckoutResult: smartCheckoutResult
|
|
19147
19608
|
};
|
|
19148
19609
|
};
|
|
@@ -19153,24 +19614,6 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
19153
19614
|
|
|
19154
19615
|
|
|
19155
19616
|
|
|
19156
|
-
|
|
19157
|
-
|
|
19158
|
-
async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
|
|
19159
|
-
if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
|
|
19160
|
-
if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
|
|
19161
|
-
const readOnlyProviders = new Map();
|
|
19162
|
-
const allowedNetworks = await $de192de6ef100f9f$export$3043f6442a9ef563(config, {
|
|
19163
|
-
type: ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL
|
|
19164
|
-
});
|
|
19165
|
-
allowedNetworks.networks.forEach((networkInfo)=>{
|
|
19166
|
-
const rpcUrl = config.networkMap.get(networkInfo.chainId)?.rpcUrls[0];
|
|
19167
|
-
const provider = new (JsonRpcProvider)(rpcUrl);
|
|
19168
|
-
readOnlyProviders.set(networkInfo.chainId, provider);
|
|
19169
|
-
});
|
|
19170
|
-
return readOnlyProviders;
|
|
19171
|
-
}
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
19617
|
const $a8cb37a3fc8eb863$var$SANDBOX_CONFIGURATION = {
|
|
19175
19618
|
baseConfig: {
|
|
19176
19619
|
environment: (Environment$1).SANDBOX
|
|
@@ -19309,6 +19752,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
19309
19752
|
await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.id, params.collectionAddress, params.buyToken);
|
|
19310
19753
|
}
|
|
19311
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
|
+
/**
|
|
19312
19765
|
* Determines the transaction requirements to complete a purchase.
|
|
19313
19766
|
* @params {SmartCheckoutParams} params - The parameters for smart checkout.
|
|
19314
19767
|
*/ async smartCheckout(params) {
|
|
@@ -19316,6 +19769,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
19316
19769
|
// eslint-disable-next-line no-console
|
|
19317
19770
|
console.warn("This endpoint is currently under construction.");
|
|
19318
19771
|
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
19772
|
+
// console.log('Smart Checkout Params ::', params);
|
|
19319
19773
|
await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
19320
19774
|
}
|
|
19321
19775
|
/**
|