@imtbl/sdk 0.27.8 → 0.27.10
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 +19 -5
- package/dist/checkout_sdk.js +122 -71
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +255 -175
- package/dist/index.d.ts +20 -5
- package/dist/index.js +238 -158
- package/dist/passport.d.ts +1 -0
- package/dist/passport.js +116 -87
- package/package.json +1 -1
package/dist/checkout_sdk.d.ts
CHANGED
|
@@ -566,7 +566,8 @@ interface ModuleConfiguration<T> {
|
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
/**
|
|
569
|
-
*
|
|
569
|
+
* Type representing an ERC20 token
|
|
570
|
+
* @property {string} type - The token type, used to discriminate between {@link ERC20} and {@link Native}
|
|
570
571
|
* @property {number} chainId - The chain ID
|
|
571
572
|
* @property {string} address - The token address
|
|
572
573
|
* @property {number} decimals - The token decimals
|
|
@@ -582,7 +583,8 @@ type ERC20 = {
|
|
|
582
583
|
name?: string;
|
|
583
584
|
};
|
|
584
585
|
/**
|
|
585
|
-
*
|
|
586
|
+
* Type representing a native token
|
|
587
|
+
* @property {string} type - The token type, used to discriminate between {@link ERC20} and {@link Native}
|
|
586
588
|
* @property {number} chainId - The chain ID
|
|
587
589
|
* @property {number} decimals - The token decimals
|
|
588
590
|
* @property {string | undefined} symbol - The token symbol or undefined if it is not available
|
|
@@ -595,13 +597,25 @@ type Native = {
|
|
|
595
597
|
symbol?: string;
|
|
596
598
|
name?: string;
|
|
597
599
|
};
|
|
598
|
-
|
|
600
|
+
/**
|
|
601
|
+
* Type representing a token, either an {@link ERC20} or {@link Native}
|
|
602
|
+
*/
|
|
603
|
+
type Coin = ERC20 | Native;
|
|
604
|
+
/**
|
|
605
|
+
* Type representing the overrides for the {@link Exchange} module
|
|
606
|
+
* @property {string} rpcURL - The RPC URL for the chain
|
|
607
|
+
* @property {ExchangeContracts} exchangeContracts - The DEX contract addresses
|
|
608
|
+
* @property {ERC20[]} commonRoutingTokens - The tokens used to find available pools for a swap
|
|
609
|
+
* @property {Coin} nativeToken - The native token of the chain
|
|
610
|
+
* @property {ERC20} wrappedNativeToken - The wrapped native token of the chain
|
|
611
|
+
*/
|
|
612
|
+
type ExchangeOverrides = {
|
|
599
613
|
rpcURL: string;
|
|
600
614
|
exchangeContracts: ExchangeContracts;
|
|
601
615
|
commonRoutingTokens: ERC20[];
|
|
602
|
-
nativeToken:
|
|
616
|
+
nativeToken: Coin;
|
|
603
617
|
wrappedNativeToken: ERC20;
|
|
604
|
-
}
|
|
618
|
+
};
|
|
605
619
|
|
|
606
620
|
/**
|
|
607
621
|
* @typedef {string} Address - Represents an Ethereum address.
|
package/dist/checkout_sdk.js
CHANGED
|
@@ -2,7 +2,8 @@ import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as Bi
|
|
|
2
2
|
import globalAxios, { HttpStatusCode } from 'axios';
|
|
3
3
|
import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
|
|
4
4
|
import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
|
|
5
|
-
import
|
|
5
|
+
import * as Uniswap from '@uniswap/sdk-core';
|
|
6
|
+
import { TradeType, Percent } from '@uniswap/sdk-core';
|
|
6
7
|
import assert from 'assert';
|
|
7
8
|
import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
|
|
8
9
|
import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
|
|
@@ -14681,10 +14682,8 @@ const quoteReturnMapping = {
|
|
|
14681
14682
|
* @param poolB the other pool
|
|
14682
14683
|
*/
|
|
14683
14684
|
function poolEquals(poolA, poolB) {
|
|
14684
|
-
return (poolA === poolB
|
|
14685
|
-
|
|
14686
|
-
&& poolA.token1.equals(poolB.token1)
|
|
14687
|
-
&& poolA.fee === poolB.fee));
|
|
14685
|
+
return (poolA === poolB ||
|
|
14686
|
+
(poolA.token0.equals(poolB.token0) && poolA.token1.equals(poolB.token1) && poolA.fee === poolB.fee));
|
|
14688
14687
|
}
|
|
14689
14688
|
async function getERC20Decimals(tokenAddress, provider) {
|
|
14690
14689
|
const decimalsFunctionSig = ethers.utils.id('decimals()').substring(0, 10);
|
|
@@ -14717,7 +14716,7 @@ function isValidNonZeroAddress(address) {
|
|
|
14717
14716
|
}
|
|
14718
14717
|
const erc20ToUniswapToken = (token) =>
|
|
14719
14718
|
// eslint-disable-next-line implicit-arrow-linebreak
|
|
14720
|
-
new Token(token.chainId, token.address, token.decimals, token.symbol, token.name);
|
|
14719
|
+
new Uniswap.Token(token.chainId, token.address, token.decimals, token.symbol, token.name);
|
|
14721
14720
|
const uniswapTokenToERC20 = (token) => ({
|
|
14722
14721
|
chainId: token.chainId,
|
|
14723
14722
|
address: token.address,
|
|
@@ -14728,25 +14727,74 @@ const uniswapTokenToERC20 = (token) => ({
|
|
|
14728
14727
|
});
|
|
14729
14728
|
const toCurrencyAmount = (amount) => {
|
|
14730
14729
|
const token = erc20ToUniswapToken(amount.token);
|
|
14731
|
-
return CurrencyAmount.fromRawAmount(token, amount.value.toString());
|
|
14730
|
+
return Uniswap.CurrencyAmount.fromRawAmount(token, amount.value.toString());
|
|
14732
14731
|
};
|
|
14733
14732
|
const newAmount = (amount, token) => ({
|
|
14734
14733
|
value: amount,
|
|
14735
14734
|
token,
|
|
14736
14735
|
});
|
|
14737
14736
|
const isERC20Amount = (amount) => amount.token.type === 'erc20';
|
|
14737
|
+
const isNativeAmount = (amount) => amount.token.type === 'native';
|
|
14738
14738
|
const addERC20Amount = (a, b) => {
|
|
14739
14739
|
// Make sure the ERC20s have the same address
|
|
14740
14740
|
if (a.token.address !== b.token.address)
|
|
14741
14741
|
throw new Error('Token mismatch: token addresses must be the same');
|
|
14742
14742
|
return { value: a.value.add(b.value), token: a.token };
|
|
14743
14743
|
};
|
|
14744
|
+
const addNativeAmount = (a, b) => ({
|
|
14745
|
+
value: a.value.add(b.value),
|
|
14746
|
+
token: a.token,
|
|
14747
|
+
});
|
|
14748
|
+
const addAmount = (a, b) => {
|
|
14749
|
+
if (isERC20Amount(a) && isERC20Amount(b)) {
|
|
14750
|
+
return addERC20Amount(a, b);
|
|
14751
|
+
}
|
|
14752
|
+
if (isNativeAmount(a) && isNativeAmount(b)) {
|
|
14753
|
+
return addNativeAmount(a, b);
|
|
14754
|
+
}
|
|
14755
|
+
throw new Error('Token mismatch: token types must be the same');
|
|
14756
|
+
};
|
|
14744
14757
|
const subtractERC20Amount = (a, b) => {
|
|
14745
14758
|
// Make sure the ERC20s have the same address
|
|
14746
14759
|
if (a.token.address !== b.token.address)
|
|
14747
14760
|
throw new Error('Token mismatch: token addresses must be the same');
|
|
14748
14761
|
return { value: a.value.sub(b.value), token: a.token };
|
|
14749
14762
|
};
|
|
14763
|
+
const subtractNativeAmount = (a, b) => ({
|
|
14764
|
+
value: a.value.sub(b.value),
|
|
14765
|
+
token: a.token,
|
|
14766
|
+
});
|
|
14767
|
+
const subtractAmount = (a, b) => {
|
|
14768
|
+
if (isERC20Amount(a) && isERC20Amount(b)) {
|
|
14769
|
+
return subtractERC20Amount(a, b);
|
|
14770
|
+
}
|
|
14771
|
+
if (isNativeAmount(a) && isNativeAmount(b)) {
|
|
14772
|
+
return subtractNativeAmount(a, b);
|
|
14773
|
+
}
|
|
14774
|
+
throw new Error('Token mismatch: token types must be the same');
|
|
14775
|
+
};
|
|
14776
|
+
/**
|
|
14777
|
+
* Converts our internal token type which could be ERC20 or Native
|
|
14778
|
+
* into a format consumable by Checkout. They require an address to be
|
|
14779
|
+
* present. We populate the address with empty string if it's Native.
|
|
14780
|
+
* If it's ERC20, we don't need to change it.
|
|
14781
|
+
*/
|
|
14782
|
+
const toPublicTokenType = (token) => {
|
|
14783
|
+
if (token.type === 'native') {
|
|
14784
|
+
return {
|
|
14785
|
+
address: '',
|
|
14786
|
+
chainId: token.chainId,
|
|
14787
|
+
decimals: token.decimals,
|
|
14788
|
+
symbol: token.symbol,
|
|
14789
|
+
name: token.name,
|
|
14790
|
+
};
|
|
14791
|
+
}
|
|
14792
|
+
return token;
|
|
14793
|
+
};
|
|
14794
|
+
const toPublicAmount = (amount) => ({
|
|
14795
|
+
token: toPublicTokenType(amount.token),
|
|
14796
|
+
value: amount.value,
|
|
14797
|
+
});
|
|
14750
14798
|
|
|
14751
14799
|
const amountIndex = 0;
|
|
14752
14800
|
const gasEstimateIndex = 3;
|
|
@@ -15120,11 +15168,11 @@ const getUnsignedERC20ApproveTransaction = (ownerAddress, tokenAmount, spenderAd
|
|
|
15120
15168
|
from: ownerAddress,
|
|
15121
15169
|
};
|
|
15122
15170
|
};
|
|
15123
|
-
const prepareApproval = (tradeType, amountSpecified, amountWithSlippage,
|
|
15171
|
+
const prepareApproval = (tradeType, amountSpecified, amountWithSlippage, contracts, secondaryFees) => {
|
|
15124
15172
|
const amountOfTokenIn = tradeType === TradeType.EXACT_INPUT ? amountSpecified : amountWithSlippage;
|
|
15125
15173
|
const spender = secondaryFees.length === 0
|
|
15126
|
-
?
|
|
15127
|
-
:
|
|
15174
|
+
? contracts.routerAddress
|
|
15175
|
+
: contracts.secondaryFeeAddress;
|
|
15128
15176
|
return { spender, amount: amountOfTokenIn };
|
|
15129
15177
|
};
|
|
15130
15178
|
/**
|
|
@@ -15157,7 +15205,7 @@ async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tok
|
|
|
15157
15205
|
from: ownerAddress,
|
|
15158
15206
|
});
|
|
15159
15207
|
}
|
|
15160
|
-
const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice
|
|
15208
|
+
const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) => {
|
|
15161
15209
|
const approveTransaction = await getApproveTransaction(provider, ownerAddress, preparedApproval.amount, preparedApproval.spender);
|
|
15162
15210
|
if (!approveTransaction) {
|
|
15163
15211
|
return null;
|
|
@@ -15166,8 +15214,7 @@ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice, n
|
|
|
15166
15214
|
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
|
|
15167
15215
|
return {
|
|
15168
15216
|
transaction: approveTransaction,
|
|
15169
|
-
|
|
15170
|
-
gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
|
|
15217
|
+
gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
|
|
15171
15218
|
};
|
|
15172
15219
|
};
|
|
15173
15220
|
|
|
@@ -15203,25 +15250,8 @@ function applySlippage(tradeType, amount, slippage) {
|
|
|
15203
15250
|
const amountWithSlippage = maybeInverted.multiply(amount.toString()).quotient;
|
|
15204
15251
|
return ethers.BigNumber.from(amountWithSlippage.toString());
|
|
15205
15252
|
}
|
|
15206
|
-
function prepareUserQuote(otherToken, tradeInfo, slippage, fees) {
|
|
15207
|
-
const quote = getQuoteAmountFromTradeType(tradeInfo);
|
|
15208
|
-
const amountWithSlippage = applySlippage(tradeInfo.tradeType, quote.value, slippage);
|
|
15209
|
-
return {
|
|
15210
|
-
amount: quote,
|
|
15211
|
-
amountWithMaxSlippage: {
|
|
15212
|
-
token: otherToken,
|
|
15213
|
-
value: amountWithSlippage,
|
|
15214
|
-
},
|
|
15215
|
-
slippage,
|
|
15216
|
-
fees: fees.withAmounts(),
|
|
15217
|
-
};
|
|
15218
|
-
}
|
|
15219
15253
|
function getOurQuoteReqAmount(amountSpecified, // the amount specified by the user, either exactIn or exactOut
|
|
15220
15254
|
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
|
-
}
|
|
15225
15255
|
if (tradeType === TradeType.EXACT_OUTPUT) {
|
|
15226
15256
|
// For an exact output swap, we do not need to subtract fees from the given amount
|
|
15227
15257
|
return nativeTokenService.maybeWrapAmount(amountSpecified);
|
|
@@ -15252,14 +15282,17 @@ class Fees {
|
|
|
15252
15282
|
this.secondaryFees = secondaryFees;
|
|
15253
15283
|
this.amount = newAmount(BigNumber$1.from(0), token);
|
|
15254
15284
|
}
|
|
15285
|
+
get token() {
|
|
15286
|
+
return this.amount.token;
|
|
15287
|
+
}
|
|
15255
15288
|
addAmount(amount) {
|
|
15256
|
-
this.amount =
|
|
15289
|
+
this.amount = addAmount(this.amount, amount);
|
|
15257
15290
|
}
|
|
15258
15291
|
amountWithFeesApplied() {
|
|
15259
|
-
return
|
|
15292
|
+
return addAmount(this.amount, this.total());
|
|
15260
15293
|
}
|
|
15261
15294
|
amountLessFees() {
|
|
15262
|
-
return
|
|
15295
|
+
return subtractAmount(this.amount, this.total());
|
|
15263
15296
|
}
|
|
15264
15297
|
withAmounts() {
|
|
15265
15298
|
return this.secondaryFees.map((fee) => {
|
|
@@ -15278,7 +15311,7 @@ class Fees {
|
|
|
15278
15311
|
const feeAmount = this.amount.value
|
|
15279
15312
|
.mul(fee.basisPoints)
|
|
15280
15313
|
.div(BASIS_POINT_PRECISION);
|
|
15281
|
-
totalFees =
|
|
15314
|
+
totalFees = addAmount(totalFees, newAmount(feeAmount, this.amount.token));
|
|
15282
15315
|
}
|
|
15283
15316
|
return totalFees;
|
|
15284
15317
|
}
|
|
@@ -15292,11 +15325,14 @@ class NativeTokenService {
|
|
|
15292
15325
|
this.wrappedToken = wrappedToken;
|
|
15293
15326
|
}
|
|
15294
15327
|
wrapAmount(amount) {
|
|
15328
|
+
if (!this.isNativeToken(amount.token)) {
|
|
15329
|
+
throw new Error(`cannot wrap non-native token: ${amount.token.address}`);
|
|
15330
|
+
}
|
|
15295
15331
|
return newAmount(amount.value, this.wrappedToken);
|
|
15296
15332
|
}
|
|
15297
15333
|
unwrapAmount(amount) {
|
|
15298
15334
|
if (amount.token !== this.wrappedToken) {
|
|
15299
|
-
throw new Error(`token ${amount.token.address}
|
|
15335
|
+
throw new Error(`cannot unwrap non-wrapped token ${amount.token.address}`);
|
|
15300
15336
|
}
|
|
15301
15337
|
return newAmount(amount.value, this.nativeToken);
|
|
15302
15338
|
}
|
|
@@ -15316,14 +15352,6 @@ class NativeTokenService {
|
|
|
15316
15352
|
|
|
15317
15353
|
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
15318
15354
|
const IMMUTABLE_TESTNET_CHAIN_ID = 13472;
|
|
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
|
-
};
|
|
15327
15355
|
const TIMX_IMMUTABLE_TESTNET = {
|
|
15328
15356
|
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
15329
15357
|
address: '0x0000000000000000000000000000000000001010',
|
|
@@ -15454,21 +15482,33 @@ function getSwap(adjustedQuote, fromAddress, slippage, deadline, peripheryRouter
|
|
|
15454
15482
|
gasFeeEstimate: gasFeeEstimate ? nativeTokenService.maybeWrapAmount(gasFeeEstimate) : null,
|
|
15455
15483
|
};
|
|
15456
15484
|
}
|
|
15457
|
-
|
|
15485
|
+
const adjustAmountIn = (ourQuote, amountSpecified, fees, nativeTokenService) => {
|
|
15458
15486
|
if (ourQuote.tradeType === TradeType.EXACT_OUTPUT) {
|
|
15459
|
-
fees
|
|
15460
|
-
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
|
|
15464
|
-
|
|
15465
|
-
|
|
15466
|
-
|
|
15467
|
-
|
|
15487
|
+
// when doing exact output, calculate the fees based on the amountIn
|
|
15488
|
+
const amountToAdd = nativeTokenService.isNativeToken(fees.token)
|
|
15489
|
+
? nativeTokenService.unwrapAmount(ourQuote.amountIn)
|
|
15490
|
+
: ourQuote.amountIn;
|
|
15491
|
+
fees.addAmount(amountToAdd);
|
|
15492
|
+
return nativeTokenService.maybeWrapAmount(fees.amountWithFeesApplied());
|
|
15493
|
+
}
|
|
15494
|
+
return nativeTokenService.maybeWrapAmount(amountSpecified);
|
|
15495
|
+
};
|
|
15496
|
+
/**
|
|
15497
|
+
* adjustQuoteWithFees adjusts the amountIn of the quote to account for fees
|
|
15498
|
+
* EXACT_OUTPUT swaps will have the fees added to the amountIn if there are fees specified
|
|
15499
|
+
* EXACT_INPUT swaps will have amountIn set to the user-specified amount
|
|
15500
|
+
* @param ourQuote The quote from calling the Quoter contract
|
|
15501
|
+
* @param amountSpecified The user-specified amount for the swap (EXACT...)
|
|
15502
|
+
* @param fees The fees applied to the swap
|
|
15503
|
+
* @param tokenWrapper Helper class for the native token and associated ERC20
|
|
15504
|
+
* @returns {QuoteResult} The adjusted quote
|
|
15505
|
+
*/
|
|
15506
|
+
function adjustQuoteWithFees(ourQuote, amountSpecified, fees, nativeTokenService) {
|
|
15507
|
+
const adjustedAmountIn = adjustAmountIn(ourQuote, amountSpecified, fees, nativeTokenService);
|
|
15468
15508
|
return {
|
|
15469
15509
|
gasEstimate: ourQuote.gasEstimate,
|
|
15470
15510
|
route: ourQuote.route,
|
|
15471
|
-
amountIn:
|
|
15511
|
+
amountIn: adjustedAmountIn,
|
|
15472
15512
|
amountOut: ourQuote.amountOut,
|
|
15473
15513
|
tradeType: ourQuote.tradeType,
|
|
15474
15514
|
};
|
|
@@ -15489,7 +15529,7 @@ const SUPPORTED_SANDBOX_CHAINS = {
|
|
|
15489
15529
|
rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
|
|
15490
15530
|
contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
|
|
15491
15531
|
commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
|
|
15492
|
-
nativeToken:
|
|
15532
|
+
nativeToken: TIMX_IMMUTABLE_TESTNET,
|
|
15493
15533
|
wrappedNativeToken: TIMX_IMMUTABLE_TESTNET, // TODO: TP-1649: Change to WIMX when ready.
|
|
15494
15534
|
},
|
|
15495
15535
|
};
|
|
@@ -15561,6 +15601,15 @@ class ExchangeConfiguration {
|
|
|
15561
15601
|
}
|
|
15562
15602
|
}
|
|
15563
15603
|
|
|
15604
|
+
const toPublicQuote = (amount, amountWithMaxSlippage, slippage, fees) => ({
|
|
15605
|
+
amount,
|
|
15606
|
+
amountWithMaxSlippage,
|
|
15607
|
+
slippage,
|
|
15608
|
+
fees: fees.withAmounts().map((fee) => ({
|
|
15609
|
+
...fee,
|
|
15610
|
+
amount: toPublicAmount(fee.amount),
|
|
15611
|
+
})),
|
|
15612
|
+
});
|
|
15564
15613
|
class Exchange {
|
|
15565
15614
|
provider;
|
|
15566
15615
|
router;
|
|
@@ -15569,6 +15618,8 @@ class Exchange {
|
|
|
15569
15618
|
wrappedNativeToken;
|
|
15570
15619
|
secondaryFees;
|
|
15571
15620
|
nativeTokenService;
|
|
15621
|
+
secondaryFeeContractAddress;
|
|
15622
|
+
routerContractAddress;
|
|
15572
15623
|
constructor(configuration) {
|
|
15573
15624
|
const config = new ExchangeConfiguration(configuration);
|
|
15574
15625
|
this.chainId = config.chain.chainId;
|
|
@@ -15576,13 +15627,13 @@ class Exchange {
|
|
|
15576
15627
|
this.wrappedNativeToken = config.chain.wrappedNativeToken;
|
|
15577
15628
|
this.nativeTokenService = new NativeTokenService(this.nativeToken, this.wrappedNativeToken);
|
|
15578
15629
|
this.secondaryFees = config.secondaryFees;
|
|
15630
|
+
this.routerContractAddress = config.chain.contracts.peripheryRouter;
|
|
15631
|
+
this.secondaryFeeContractAddress = config.chain.contracts.secondaryFee;
|
|
15579
15632
|
this.provider = new ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
|
|
15580
15633
|
this.router = new Router(this.provider, config.chain.commonRoutingTokens, {
|
|
15581
15634
|
multicallAddress: config.chain.contracts.multicall,
|
|
15582
15635
|
factoryAddress: config.chain.contracts.coreFactory,
|
|
15583
15636
|
quoterAddress: config.chain.contracts.quoterV2,
|
|
15584
|
-
peripheryRouterAddress: config.chain.contracts.peripheryRouter,
|
|
15585
|
-
secondaryFeeAddress: config.chain.contracts.secondaryFee,
|
|
15586
15637
|
});
|
|
15587
15638
|
}
|
|
15588
15639
|
static validate(tokenInAddress, tokenOutAddress, maxHops, slippagePercent, fromAddress) {
|
|
@@ -15599,7 +15650,7 @@ class Exchange {
|
|
|
15599
15650
|
if (this.secondaryFees.length === 0) {
|
|
15600
15651
|
return [];
|
|
15601
15652
|
}
|
|
15602
|
-
const secondaryFeeContract = SecondaryFee__factory.connect(this.
|
|
15653
|
+
const secondaryFeeContract = SecondaryFee__factory.connect(this.secondaryFeeContractAddress, this.provider);
|
|
15603
15654
|
if (await secondaryFeeContract.paused()) {
|
|
15604
15655
|
// Do not use secondary fees if the contract is paused
|
|
15605
15656
|
return [];
|
|
@@ -15627,8 +15678,7 @@ class Exchange {
|
|
|
15627
15678
|
decimals: tokenOutDecimals,
|
|
15628
15679
|
};
|
|
15629
15680
|
// determine which amount was specified for the swap from the TradeType
|
|
15630
|
-
const [tokenSpecified, otherToken] = tradeType === TradeType.EXACT_INPUT
|
|
15631
|
-
? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
15681
|
+
const [tokenSpecified, otherToken] = tradeType === TradeType.EXACT_INPUT ? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
15632
15682
|
const amountSpecified = newAmount(amount, tokenSpecified);
|
|
15633
15683
|
const fees = new Fees(secondaryFees, tokenIn);
|
|
15634
15684
|
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType, this.nativeTokenService);
|
|
@@ -15637,17 +15687,18 @@ class Exchange {
|
|
|
15637
15687
|
this.router.findOptimalRoute(ourQuoteReqAmount, otherToken, tradeType, maxHops),
|
|
15638
15688
|
fetchGasPrice(this.provider, this.nativeToken),
|
|
15639
15689
|
]);
|
|
15640
|
-
const adjustedQuote =
|
|
15641
|
-
const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.
|
|
15642
|
-
const
|
|
15643
|
-
const
|
|
15690
|
+
const adjustedQuote = adjustQuoteWithFees(ourQuote, amountSpecified, fees, this.nativeTokenService);
|
|
15691
|
+
const swap = getSwap(adjustedQuote, fromAddress, slippagePercent, deadline, this.routerContractAddress, this.secondaryFeeContractAddress, gasPrice, secondaryFees, this.nativeTokenService);
|
|
15692
|
+
const quotedAmount = getQuoteAmountFromTradeType(adjustedQuote);
|
|
15693
|
+
const amountWithMaxSlippage = newAmount(applySlippage(adjustedQuote.tradeType, quotedAmount.value, slippagePercent), otherToken);
|
|
15694
|
+
const preparedApproval = prepareApproval(tradeType, amountSpecified, amountWithMaxSlippage, {
|
|
15695
|
+
routerAddress: this.routerContractAddress,
|
|
15696
|
+
secondaryFeeAddress: this.secondaryFeeContractAddress,
|
|
15697
|
+
}, secondaryFees);
|
|
15644
15698
|
// preparedApproval always uses the tokenIn address because we are always selling the tokenIn
|
|
15645
|
-
const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice
|
|
15646
|
-
|
|
15647
|
-
|
|
15648
|
-
swap,
|
|
15649
|
-
quote: userQuote,
|
|
15650
|
-
};
|
|
15699
|
+
const approval = await getApproval(this.provider, fromAddress, preparedApproval, gasPrice);
|
|
15700
|
+
const quote = toPublicQuote(quotedAmount, amountWithMaxSlippage, slippagePercent, fees);
|
|
15701
|
+
return { quote, approval, swap };
|
|
15651
15702
|
}
|
|
15652
15703
|
/**
|
|
15653
15704
|
* Get the unsigned swap transaction given the amount to sell.
|
|
@@ -20503,7 +20554,7 @@ class APIError extends Error {
|
|
|
20503
20554
|
|
|
20504
20555
|
/* eslint-disable implicit-arrow-linebreak */
|
|
20505
20556
|
const defaultHeaders = {
|
|
20506
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.
|
|
20557
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.27.10',
|
|
20507
20558
|
};
|
|
20508
20559
|
/**
|
|
20509
20560
|
* createAPIConfiguration to create a custom Configuration
|
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.10";
|
|
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.10',
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
22
|
* Sets `sdkVersion` at the time of build
|