@imtbl/sdk 0.27.7 → 0.27.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockchain_data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +20 -4
- package/dist/checkout_sdk.js +137 -45
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +5 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +140 -48
- package/dist/index.d.ts +32 -5
- package/dist/index.js +140 -48
- package/dist/orderbook.d.ts +9 -2
- package/dist/orderbook.js +28 -11
- package/dist/passport.js +2 -2
- package/package.json +1 -1
package/dist/checkout_sdk.d.ts
CHANGED
|
@@ -566,25 +566,41 @@ interface ModuleConfiguration<T> {
|
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
/**
|
|
569
|
-
* Interface representing
|
|
569
|
+
* Interface representing an ERC20 token
|
|
570
570
|
* @property {number} chainId - The chain ID
|
|
571
571
|
* @property {string} address - The token address
|
|
572
572
|
* @property {number} decimals - The token decimals
|
|
573
573
|
* @property {string | undefined} symbol - The token symbol or undefined if it is not available
|
|
574
574
|
* @property {string | undefined} name - The token name or undefined if it is not available
|
|
575
575
|
*/
|
|
576
|
-
type
|
|
576
|
+
type ERC20 = {
|
|
577
|
+
type: 'erc20';
|
|
577
578
|
chainId: number;
|
|
578
579
|
address: string;
|
|
579
580
|
decimals: number;
|
|
580
581
|
symbol?: string;
|
|
581
582
|
name?: string;
|
|
582
583
|
};
|
|
584
|
+
/**
|
|
585
|
+
* Interface representing a native token
|
|
586
|
+
* @property {number} chainId - The chain ID
|
|
587
|
+
* @property {number} decimals - The token decimals
|
|
588
|
+
* @property {string | undefined} symbol - The token symbol or undefined if it is not available
|
|
589
|
+
* @property {string | undefined} name - The token name or undefined if it is not available
|
|
590
|
+
*/
|
|
591
|
+
type Native = {
|
|
592
|
+
type: 'native';
|
|
593
|
+
chainId: number;
|
|
594
|
+
decimals: number;
|
|
595
|
+
symbol?: string;
|
|
596
|
+
name?: string;
|
|
597
|
+
};
|
|
583
598
|
interface ExchangeOverrides {
|
|
584
599
|
rpcURL: string;
|
|
585
600
|
exchangeContracts: ExchangeContracts;
|
|
586
|
-
commonRoutingTokens:
|
|
587
|
-
nativeToken:
|
|
601
|
+
commonRoutingTokens: ERC20[];
|
|
602
|
+
nativeToken: Native;
|
|
603
|
+
wrappedNativeToken: ERC20;
|
|
588
604
|
}
|
|
589
605
|
|
|
590
606
|
/**
|
package/dist/checkout_sdk.js
CHANGED
|
@@ -14715,23 +14715,36 @@ function isValidNonZeroAddress(address) {
|
|
|
14715
14715
|
return false;
|
|
14716
14716
|
}
|
|
14717
14717
|
}
|
|
14718
|
-
const
|
|
14718
|
+
const erc20ToUniswapToken = (token) =>
|
|
14719
|
+
// eslint-disable-next-line implicit-arrow-linebreak
|
|
14720
|
+
new Token(token.chainId, token.address, token.decimals, token.symbol, token.name);
|
|
14721
|
+
const uniswapTokenToERC20 = (token) => ({
|
|
14722
|
+
chainId: token.chainId,
|
|
14723
|
+
address: token.address,
|
|
14724
|
+
decimals: token.decimals,
|
|
14725
|
+
symbol: token.symbol,
|
|
14726
|
+
name: token.name,
|
|
14727
|
+
type: 'erc20',
|
|
14728
|
+
});
|
|
14719
14729
|
const toCurrencyAmount = (amount) => {
|
|
14720
|
-
const token =
|
|
14730
|
+
const token = erc20ToUniswapToken(amount.token);
|
|
14721
14731
|
return CurrencyAmount.fromRawAmount(token, amount.value.toString());
|
|
14722
14732
|
};
|
|
14723
14733
|
const newAmount = (amount, token) => ({
|
|
14724
14734
|
value: amount,
|
|
14725
14735
|
token,
|
|
14726
14736
|
});
|
|
14727
|
-
const
|
|
14737
|
+
const isERC20Amount = (amount) => amount.token.type === 'erc20';
|
|
14738
|
+
const addERC20Amount = (a, b) => {
|
|
14739
|
+
// Make sure the ERC20s have the same address
|
|
14728
14740
|
if (a.token.address !== b.token.address)
|
|
14729
|
-
throw new Error('Token mismatch');
|
|
14741
|
+
throw new Error('Token mismatch: token addresses must be the same');
|
|
14730
14742
|
return { value: a.value.add(b.value), token: a.token };
|
|
14731
14743
|
};
|
|
14732
|
-
const
|
|
14744
|
+
const subtractERC20Amount = (a, b) => {
|
|
14745
|
+
// Make sure the ERC20s have the same address
|
|
14733
14746
|
if (a.token.address !== b.token.address)
|
|
14734
|
-
throw new Error('Token mismatch');
|
|
14747
|
+
throw new Error('Token mismatch: token addresses must be the same');
|
|
14735
14748
|
return { value: a.value.sub(b.value), token: a.token };
|
|
14736
14749
|
};
|
|
14737
14750
|
|
|
@@ -14771,10 +14784,12 @@ async function getQuotesForRoutes(multicallContract, quoterContractAddress, rout
|
|
|
14771
14784
|
const quoteAmount = decodedQuoteResult[amountIndex];
|
|
14772
14785
|
if (!(quoteAmount instanceof BigNumber$1))
|
|
14773
14786
|
throw new Error('Expected BigNumber');
|
|
14787
|
+
const input = uniswapTokenToERC20(routes[i].input);
|
|
14788
|
+
const output = uniswapTokenToERC20(routes[i].output);
|
|
14774
14789
|
decodedQuoteResults.push({
|
|
14775
14790
|
route: routes[i],
|
|
14776
|
-
amountIn: tradeType === TradeType.EXACT_INPUT ? amountSpecified : newAmount(quoteAmount,
|
|
14777
|
-
amountOut: tradeType === TradeType.EXACT_INPUT ? newAmount(quoteAmount,
|
|
14791
|
+
amountIn: tradeType === TradeType.EXACT_INPUT ? amountSpecified : newAmount(quoteAmount, input),
|
|
14792
|
+
amountOut: tradeType === TradeType.EXACT_INPUT ? newAmount(quoteAmount, output) : amountSpecified,
|
|
14778
14793
|
gasEstimate: ethers.BigNumber.from(decodedQuoteResult[gasEstimateIndex]),
|
|
14779
14794
|
tradeType,
|
|
14780
14795
|
});
|
|
@@ -14905,7 +14920,7 @@ const fetchValidPools = async (multicallContract, erc20Pair, commonRoutingERC20s
|
|
|
14905
14920
|
if (zeroPrice || zeroLiquidity) {
|
|
14906
14921
|
return;
|
|
14907
14922
|
}
|
|
14908
|
-
const validPool = new Pool(
|
|
14923
|
+
const validPool = new Pool(erc20ToUniswapToken(poolID.erc20Pair[0]), erc20ToUniswapToken(poolID.erc20Pair[1]), poolID.fee, poolSlot0.sqrtPriceX96.toString(), poolLiquidity.toString(), poolSlot0.tick);
|
|
14909
14924
|
validPools.push(validPool);
|
|
14910
14925
|
});
|
|
14911
14926
|
return validPools;
|
|
@@ -14991,9 +15006,9 @@ maxHops, // the maximum number of pools that can be traversed
|
|
|
14991
15006
|
currentRoute = [], // list of pools already traversed
|
|
14992
15007
|
routes = [], // list of all routes found so far
|
|
14993
15008
|
startTokenIn = tokenIn) => {
|
|
14994
|
-
const currencyIn =
|
|
14995
|
-
const currencyOut =
|
|
14996
|
-
const startCurrencyIn =
|
|
15009
|
+
const currencyIn = erc20ToUniswapToken(tokenIn);
|
|
15010
|
+
const currencyOut = erc20ToUniswapToken(tokenOut);
|
|
15011
|
+
const startCurrencyIn = erc20ToUniswapToken(startTokenIn);
|
|
14997
15012
|
for (const pool of pools) {
|
|
14998
15013
|
// if the pool doesn't have the tokenIn or if it has already been traversed,
|
|
14999
15014
|
// skip to the next pool
|
|
@@ -15012,7 +15027,7 @@ startTokenIn = tokenIn) => {
|
|
|
15012
15027
|
else if (maxHops > 1) {
|
|
15013
15028
|
// otherwise, if we haven't exceeded the maximum number of pools that can be traversed,
|
|
15014
15029
|
// recursively call this function with the output token as the new starting currency
|
|
15015
|
-
generateAllAcyclicPaths(outputToken, tokenOut, pools, maxHops - 1, [...currentRoute, pool], routes, startTokenIn);
|
|
15030
|
+
generateAllAcyclicPaths(uniswapTokenToERC20(outputToken), tokenOut, pools, maxHops - 1, [...currentRoute, pool], routes, startTokenIn);
|
|
15016
15031
|
}
|
|
15017
15032
|
}
|
|
15018
15033
|
return routes;
|
|
@@ -15142,7 +15157,7 @@ async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tok
|
|
|
15142
15157
|
from: ownerAddress,
|
|
15143
15158
|
});
|
|
15144
15159
|
}
|
|
15145
|
-
const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) => {
|
|
15160
|
+
const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice, nativeTokenService) => {
|
|
15146
15161
|
const approveTransaction = await getApproveTransaction(provider, ownerAddress, preparedApproval.amount, preparedApproval.spender);
|
|
15147
15162
|
if (!approveTransaction) {
|
|
15148
15163
|
return null;
|
|
@@ -15151,7 +15166,8 @@ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) =
|
|
|
15151
15166
|
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
|
|
15152
15167
|
return {
|
|
15153
15168
|
transaction: approveTransaction,
|
|
15154
|
-
|
|
15169
|
+
// TODO: TP-1649: Remove the wrapping here
|
|
15170
|
+
gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
|
|
15155
15171
|
};
|
|
15156
15172
|
};
|
|
15157
15173
|
|
|
@@ -15200,13 +15216,18 @@ function prepareUserQuote(otherToken, tradeInfo, slippage, fees) {
|
|
|
15200
15216
|
fees: fees.withAmounts(),
|
|
15201
15217
|
};
|
|
15202
15218
|
}
|
|
15203
|
-
function getOurQuoteReqAmount(
|
|
15219
|
+
function getOurQuoteReqAmount(amountSpecified, // the amount specified by the user, either exactIn or exactOut
|
|
15220
|
+
fees, tradeType, nativeTokenService) {
|
|
15221
|
+
// TODO: TP-1649: Remove this when we support Native
|
|
15222
|
+
if (!isERC20Amount(amountSpecified)) {
|
|
15223
|
+
throw new Error('Not implemented yet!');
|
|
15224
|
+
}
|
|
15204
15225
|
if (tradeType === TradeType.EXACT_OUTPUT) {
|
|
15205
15226
|
// For an exact output swap, we do not need to subtract fees from the given amount
|
|
15206
|
-
return
|
|
15227
|
+
return nativeTokenService.maybeWrapAmount(amountSpecified);
|
|
15207
15228
|
}
|
|
15208
|
-
fees.addAmount(
|
|
15209
|
-
return fees.amountLessFees();
|
|
15229
|
+
fees.addAmount(amountSpecified);
|
|
15230
|
+
return nativeTokenService.maybeWrapAmount(fees.amountLessFees());
|
|
15210
15231
|
}
|
|
15211
15232
|
|
|
15212
15233
|
// 0.1% default slippage
|
|
@@ -15222,7 +15243,7 @@ const MIN_MAX_HOPS = 1;
|
|
|
15222
15243
|
// precision used to calculate percentage from basis points
|
|
15223
15244
|
const BASIS_POINT_PRECISION = 10000;
|
|
15224
15245
|
// 10% maximum secondary fee
|
|
15225
|
-
const MAX_SECONDARY_FEE_BASIS_POINTS =
|
|
15246
|
+
const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;
|
|
15226
15247
|
|
|
15227
15248
|
class Fees {
|
|
15228
15249
|
secondaryFees;
|
|
@@ -15232,13 +15253,13 @@ class Fees {
|
|
|
15232
15253
|
this.amount = newAmount(BigNumber$1.from(0), token);
|
|
15233
15254
|
}
|
|
15234
15255
|
addAmount(amount) {
|
|
15235
|
-
this.amount =
|
|
15256
|
+
this.amount = addERC20Amount(this.amount, amount);
|
|
15236
15257
|
}
|
|
15237
15258
|
amountWithFeesApplied() {
|
|
15238
|
-
return
|
|
15259
|
+
return addERC20Amount(this.amount, this.total());
|
|
15239
15260
|
}
|
|
15240
15261
|
amountLessFees() {
|
|
15241
|
-
return
|
|
15262
|
+
return subtractERC20Amount(this.amount, this.total());
|
|
15242
15263
|
}
|
|
15243
15264
|
withAmounts() {
|
|
15244
15265
|
return this.secondaryFees.map((fee) => {
|
|
@@ -15257,24 +15278,71 @@ class Fees {
|
|
|
15257
15278
|
const feeAmount = this.amount.value
|
|
15258
15279
|
.mul(fee.basisPoints)
|
|
15259
15280
|
.div(BASIS_POINT_PRECISION);
|
|
15260
|
-
totalFees =
|
|
15281
|
+
totalFees = addERC20Amount(totalFees, newAmount(feeAmount, this.amount.token));
|
|
15261
15282
|
}
|
|
15262
15283
|
return totalFees;
|
|
15263
15284
|
}
|
|
15264
15285
|
}
|
|
15265
15286
|
|
|
15287
|
+
class NativeTokenService {
|
|
15288
|
+
nativeToken;
|
|
15289
|
+
wrappedToken;
|
|
15290
|
+
constructor(nativeToken, wrappedToken) {
|
|
15291
|
+
this.nativeToken = nativeToken;
|
|
15292
|
+
this.wrappedToken = wrappedToken;
|
|
15293
|
+
}
|
|
15294
|
+
wrapAmount(amount) {
|
|
15295
|
+
return newAmount(amount.value, this.wrappedToken);
|
|
15296
|
+
}
|
|
15297
|
+
unwrapAmount(amount) {
|
|
15298
|
+
if (amount.token !== this.wrappedToken) {
|
|
15299
|
+
throw new Error(`token ${amount.token.address} is not wrapped`);
|
|
15300
|
+
}
|
|
15301
|
+
return newAmount(amount.value, this.nativeToken);
|
|
15302
|
+
}
|
|
15303
|
+
maybeWrapToken(token) {
|
|
15304
|
+
if (this.isNativeToken(token)) {
|
|
15305
|
+
return this.wrappedToken;
|
|
15306
|
+
}
|
|
15307
|
+
return token;
|
|
15308
|
+
}
|
|
15309
|
+
maybeWrapAmount(amount) {
|
|
15310
|
+
return newAmount(amount.value, this.maybeWrapToken(amount.token));
|
|
15311
|
+
}
|
|
15312
|
+
isNativeToken(token) {
|
|
15313
|
+
return token === this.nativeToken;
|
|
15314
|
+
}
|
|
15315
|
+
}
|
|
15316
|
+
|
|
15266
15317
|
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
15267
15318
|
const IMMUTABLE_TESTNET_CHAIN_ID = 13472;
|
|
15268
15319
|
|
|
15320
|
+
const NATIVE_IMX_IMMUTABLE_TESTNET = {
|
|
15321
|
+
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
15322
|
+
decimals: 18,
|
|
15323
|
+
symbol: 'tIMX',
|
|
15324
|
+
name: 'Immutable Testnet Token',
|
|
15325
|
+
type: 'native',
|
|
15326
|
+
};
|
|
15269
15327
|
const TIMX_IMMUTABLE_TESTNET = {
|
|
15270
15328
|
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
15271
15329
|
address: '0x0000000000000000000000000000000000001010',
|
|
15272
15330
|
decimals: 18,
|
|
15273
15331
|
symbol: 'tIMX',
|
|
15274
15332
|
name: 'Immutable Testnet Token',
|
|
15333
|
+
type: 'erc20',
|
|
15334
|
+
};
|
|
15335
|
+
const WIMX_IMMUTABLE_TESTNET = {
|
|
15336
|
+
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
15337
|
+
address: '0xAf7cf5D4Af0BFAa85d384d42b8D410762Ccbce69',
|
|
15338
|
+
decimals: 18,
|
|
15339
|
+
symbol: 'WIMX',
|
|
15340
|
+
name: 'Wrapped Immutable Testnet Token',
|
|
15341
|
+
type: 'erc20',
|
|
15275
15342
|
};
|
|
15276
15343
|
const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
|
|
15277
15344
|
TIMX_IMMUTABLE_TESTNET,
|
|
15345
|
+
WIMX_IMMUTABLE_TESTNET,
|
|
15278
15346
|
];
|
|
15279
15347
|
|
|
15280
15348
|
const zeroNativeCurrencyValue = '0x00';
|
|
@@ -15371,7 +15439,7 @@ function createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, se
|
|
|
15371
15439
|
}
|
|
15372
15440
|
return createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees);
|
|
15373
15441
|
}
|
|
15374
|
-
function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees) {
|
|
15442
|
+
function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees, nativeTokenService) {
|
|
15375
15443
|
const calldata = createSwapParameters(adjustedQuote, fromAddress, slippage, deadline, secondaryFees);
|
|
15376
15444
|
// TODO: Add additional gas fee estimates for secondary fees
|
|
15377
15445
|
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
|
|
@@ -15382,7 +15450,8 @@ function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouter
|
|
|
15382
15450
|
value: zeroNativeCurrencyValue,
|
|
15383
15451
|
from: fromAddress,
|
|
15384
15452
|
},
|
|
15385
|
-
|
|
15453
|
+
// TODO: TP-1649: Remove the wrapping here
|
|
15454
|
+
gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
|
|
15386
15455
|
};
|
|
15387
15456
|
}
|
|
15388
15457
|
function prepareSwap(ourQuote, amountSpecified, fees) {
|
|
@@ -15420,7 +15489,8 @@ const SUPPORTED_SANDBOX_CHAINS = {
|
|
|
15420
15489
|
rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
|
|
15421
15490
|
contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
|
|
15422
15491
|
commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
|
|
15423
|
-
nativeToken:
|
|
15492
|
+
nativeToken: NATIVE_IMX_IMMUTABLE_TESTNET,
|
|
15493
|
+
wrappedNativeToken: TIMX_IMMUTABLE_TESTNET, // TODO: TP-1649: Change to WIMX when ready.
|
|
15424
15494
|
},
|
|
15425
15495
|
};
|
|
15426
15496
|
const SUPPORTED_PRODUCTION_CHAINS = {};
|
|
@@ -15478,6 +15548,7 @@ class ExchangeConfiguration {
|
|
|
15478
15548
|
contracts: overrides.exchangeContracts,
|
|
15479
15549
|
commonRoutingTokens: overrides.commonRoutingTokens,
|
|
15480
15550
|
nativeToken: overrides.nativeToken,
|
|
15551
|
+
wrappedNativeToken: overrides.wrappedNativeToken,
|
|
15481
15552
|
};
|
|
15482
15553
|
this.secondaryFees = secondaryFees || [];
|
|
15483
15554
|
return;
|
|
@@ -15495,11 +15566,15 @@ class Exchange {
|
|
|
15495
15566
|
router;
|
|
15496
15567
|
chainId;
|
|
15497
15568
|
nativeToken;
|
|
15569
|
+
wrappedNativeToken;
|
|
15498
15570
|
secondaryFees;
|
|
15571
|
+
nativeTokenService;
|
|
15499
15572
|
constructor(configuration) {
|
|
15500
15573
|
const config = new ExchangeConfiguration(configuration);
|
|
15501
15574
|
this.chainId = config.chain.chainId;
|
|
15502
15575
|
this.nativeToken = config.chain.nativeToken;
|
|
15576
|
+
this.wrappedNativeToken = config.chain.wrappedNativeToken;
|
|
15577
|
+
this.nativeTokenService = new NativeTokenService(this.nativeToken, this.wrappedNativeToken);
|
|
15503
15578
|
this.secondaryFees = config.secondaryFees;
|
|
15504
15579
|
this.provider = new ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
|
|
15505
15580
|
this.router = new Router(this.provider, config.chain.commonRoutingTokens, {
|
|
@@ -15540,11 +15615,13 @@ class Exchange {
|
|
|
15540
15615
|
this.getSecondaryFees(),
|
|
15541
15616
|
]);
|
|
15542
15617
|
const tokenIn = {
|
|
15618
|
+
type: 'erc20',
|
|
15543
15619
|
address: tokenInAddress,
|
|
15544
15620
|
chainId: this.chainId,
|
|
15545
15621
|
decimals: tokenInDecimals,
|
|
15546
15622
|
};
|
|
15547
15623
|
const tokenOut = {
|
|
15624
|
+
type: 'erc20',
|
|
15548
15625
|
address: tokenOutAddress,
|
|
15549
15626
|
chainId: this.chainId,
|
|
15550
15627
|
decimals: tokenOutDecimals,
|
|
@@ -15554,18 +15631,18 @@ class Exchange {
|
|
|
15554
15631
|
? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
15555
15632
|
const amountSpecified = newAmount(amount, tokenSpecified);
|
|
15556
15633
|
const fees = new Fees(secondaryFees, tokenIn);
|
|
15557
|
-
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType);
|
|
15634
|
+
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType, this.nativeTokenService);
|
|
15558
15635
|
// get quote and gas details
|
|
15559
15636
|
const [ourQuote, gasPrice] = await Promise.all([
|
|
15560
15637
|
this.router.findOptimalRoute(ourQuoteReqAmount, otherToken, tradeType, maxHops),
|
|
15561
15638
|
fetchGasPrice(this.provider, this.nativeToken),
|
|
15562
15639
|
]);
|
|
15563
15640
|
const adjustedQuote = prepareSwap(ourQuote, amountSpecified, fees);
|
|
15564
|
-
const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, secondaryFees);
|
|
15641
|
+
const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, secondaryFees, this.nativeTokenService);
|
|
15565
15642
|
const userQuote = prepareUserQuote(otherToken, adjustedQuote, slippagePercent, fees);
|
|
15566
15643
|
const preparedApproval = prepareApproval(tradeType, amountSpecified, userQuote.amountWithMaxSlippage, this.router.routingContracts, secondaryFees);
|
|
15567
15644
|
// preparedApproval always uses the tokenIn address because we are always selling the tokenIn
|
|
15568
|
-
const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice);
|
|
15645
|
+
const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice, this.nativeTokenService);
|
|
15569
15646
|
return {
|
|
15570
15647
|
approval,
|
|
15571
15648
|
swap,
|
|
@@ -16604,9 +16681,6 @@ class Seaport {
|
|
|
16604
16681
|
};
|
|
16605
16682
|
}
|
|
16606
16683
|
async fulfillBulkOrders(fulfillingOrders, account) {
|
|
16607
|
-
// TODO: this function right now does not handle errors from the seaport.js
|
|
16608
|
-
// we should figure out why orders are rejected and return a submission
|
|
16609
|
-
// transaction on best efforts basis
|
|
16610
16684
|
const fulfillOrderDetails = fulfillingOrders.map((o) => {
|
|
16611
16685
|
const { orderComponents, tips } = this.mapImmutableOrderToSeaportOrderComponents(o.order);
|
|
16612
16686
|
return {
|
|
@@ -17025,14 +17099,34 @@ class Orderbook {
|
|
|
17025
17099
|
recipient: fee.recipient,
|
|
17026
17100
|
})),
|
|
17027
17101
|
})));
|
|
17028
|
-
|
|
17029
|
-
|
|
17030
|
-
|
|
17031
|
-
|
|
17032
|
-
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17102
|
+
try {
|
|
17103
|
+
return {
|
|
17104
|
+
...(await this.seaport.fulfillBulkOrders(fulfillmentDataRes.result.fulfillable_orders, takerAddress)),
|
|
17105
|
+
fulfillableOrders: fulfillmentDataRes.result.fulfillable_orders.map((o) => mapFromOpenApiOrder(o.order)),
|
|
17106
|
+
unfulfillableOrders: fulfillmentDataRes.result.unfulfillable_orders.map((o) => ({
|
|
17107
|
+
orderId: o.order_id,
|
|
17108
|
+
reason: o.reason,
|
|
17109
|
+
})),
|
|
17110
|
+
sufficientBalance: true,
|
|
17111
|
+
};
|
|
17112
|
+
}
|
|
17113
|
+
catch (e) {
|
|
17114
|
+
// if insufficient balance error, we return FulfillBulkOrdersInsufficientBalanceResponse
|
|
17115
|
+
if (String(e).includes('The fulfiller does not have the balances needed to fulfill.')) {
|
|
17116
|
+
return {
|
|
17117
|
+
fulfillableOrders: fulfillmentDataRes.result.fulfillable_orders.map((o) => mapFromOpenApiOrder(o.order)),
|
|
17118
|
+
unfulfillableOrders: fulfillmentDataRes.result.unfulfillable_orders.map((o) => ({
|
|
17119
|
+
orderId: o.order_id,
|
|
17120
|
+
reason: o.reason,
|
|
17121
|
+
})),
|
|
17122
|
+
sufficientBalance: false,
|
|
17123
|
+
};
|
|
17124
|
+
}
|
|
17125
|
+
// if some other error is thrown,
|
|
17126
|
+
// there likely is a race condition of the original order validity
|
|
17127
|
+
// we throw the error back out
|
|
17128
|
+
throw e;
|
|
17129
|
+
}
|
|
17036
17130
|
}
|
|
17037
17131
|
/**
|
|
17038
17132
|
* Get an unsigned cancel order transaction. Orders can only be cancelled by
|
|
@@ -20409,7 +20503,7 @@ class APIError extends Error {
|
|
|
20409
20503
|
|
|
20410
20504
|
/* eslint-disable implicit-arrow-linebreak */
|
|
20411
20505
|
const defaultHeaders = {
|
|
20412
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.
|
|
20506
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.8',
|
|
20413
20507
|
};
|
|
20414
20508
|
/**
|
|
20415
20509
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -22935,8 +23029,6 @@ const $5e9bcae98dc8ff19$export$1165ca270f090a66 = (isDevelopment, isProduction)=
|
|
|
22935
23029
|
return ($d85ad1457a3f1a83$export$89133ca13c5ee30)[(Environment$1).SANDBOX];
|
|
22936
23030
|
};
|
|
22937
23031
|
const checkDexAvailability = async ()=>{
|
|
22938
|
-
// TEMP FIX: Returns true for sandbox environment
|
|
22939
|
-
if (!isDevelopment && !isProduction) return true;
|
|
22940
23032
|
let response;
|
|
22941
23033
|
try {
|
|
22942
23034
|
response = await (0, globalAxios).post(`${postEndpoint()}/v1/availability/checkout/swap`);
|
|
@@ -23101,7 +23193,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
|
|
|
23101
23193
|
const swappableToken = fromToken[index];
|
|
23102
23194
|
dexQuotes.set(swappableToken, {
|
|
23103
23195
|
quote: response.value.quote,
|
|
23104
|
-
approval: response.value.approval?.gasFeeEstimate,
|
|
23196
|
+
approval: response.value.approval?.gasFeeEstimate ?? null,
|
|
23105
23197
|
swap: response.value.swap.gasFeeEstimate
|
|
23106
23198
|
});
|
|
23107
23199
|
});
|
package/dist/checkout_widgets.js
CHANGED
|
@@ -25,7 +25,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
|
|
|
25
25
|
})($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.
|
|
28
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.27.8";
|
|
29
29
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
30
30
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
31
31
|
|
|
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
16
16
|
chainID,
|
|
17
17
|
coreContractAddress,
|
|
18
18
|
registrationContractAddress,
|
|
19
|
-
sdkVersion: 'ts-immutable-sdk-0.27.
|
|
19
|
+
sdkVersion: 'ts-immutable-sdk-0.27.8',
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
22
|
* Sets `sdkVersion` at the time of build
|