diff --git a/packages/dodoex-api/package.json b/packages/dodoex-api/package.json
index 37994cc7..142a5822 100644
--- a/packages/dodoex-api/package.json
+++ b/packages/dodoex-api/package.json
@@ -1,6 +1,6 @@
{
"name": "@dodoex/api",
- "version": "3.0.1-taiko.6",
+ "version": "3.0.1-taiko.7",
"description": "DODO API Kit",
"source": "src/index.ts",
"types": "dist/types/index.d.ts",
diff --git a/packages/dodoex-api/src/services/pool/PoolApi.ts b/packages/dodoex-api/src/services/pool/PoolApi.ts
index 0e6554e9..a937d46e 100644
--- a/packages/dodoex-api/src/services/pool/PoolApi.ts
+++ b/packages/dodoex-api/src/services/pool/PoolApi.ts
@@ -20,6 +20,8 @@ import {
fetchUniswapV2PairTotalSupply,
fetchUniswapV2PairGetReserves,
fetchUniswapV2PairFeeRate,
+ getUniswapV2Router02ContractAddressByChainId,
+ getUniswapV2FactoryContractAddressByChainId,
} from '@dodoex/dodo-contract-request';
import { formatUnits } from '@dodoex/contract-request';
@@ -1427,10 +1429,22 @@ export class PoolApi {
10 ** 18,
);
} else if (type === 'AMMV2') {
- const result = await fetchUniswapV2PairFeeRate(chainId, poolAddress);
- const feeRate = byWei(result.toString(), 4);
- lpFeeRate = feeRate.times(0.8);
- mtFeeRate = feeRate.times(0.2);
+ if (
+ getUniswapV2Router02ContractAddressByChainId(chainId) &&
+ getUniswapV2FactoryContractAddressByChainId(chainId)
+ ) {
+ const result = await fetchUniswapV2PairFeeRate(
+ chainId,
+ poolAddress,
+ );
+ const feeRate = byWei(result.toString(), 4);
+ lpFeeRate = feeRate.times(0.8);
+ mtFeeRate = feeRate.times(0.2);
+ } else {
+ // For the original contract, the handling fee is fixed.
+ lpFeeRate = new BigNumber(0.003);
+ mtFeeRate = new BigNumber(0);
+ }
} else {
const queryResult = await this.contractRequests.batchCallQuery(
chainId,
diff --git a/packages/dodoex-widgets/package.json b/packages/dodoex-widgets/package.json
index 0960a81b..8c43d651 100644
--- a/packages/dodoex-widgets/package.json
+++ b/packages/dodoex-widgets/package.json
@@ -1,6 +1,6 @@
{
"name": "@dodoex/widgets",
- "version": "3.0.1-taiko.16",
+ "version": "3.0.1-taiko.17",
"description": "DODO Widgets",
"source": "src/index.tsx",
"types": "dist/types/index.d.ts",
@@ -58,7 +58,7 @@
},
"dependencies": {
"@babel/runtime": "^7.17.0",
- "@dodoex/api": "3.0.1-taiko.6",
+ "@dodoex/api": "3.0.1-taiko.7",
"@dodoex/components": "3.0.1-taiko.4",
"@dodoex/contract-request": "^1.3.0",
"@dodoex/dodo-contract-request": "1.7.0-alpha.2",
@@ -154,4 +154,5 @@
"ts-jest": "^29.0.1",
"typescript": "^5.6.3"
}
-}
\ No newline at end of file
+}
+
diff --git a/packages/dodoex-widgets/src/locales/en-US.po b/packages/dodoex-widgets/src/locales/en-US.po
index a3a455ec..77732ed6 100644
--- a/packages/dodoex-widgets/src/locales/en-US.po
+++ b/packages/dodoex-widgets/src/locales/en-US.po
@@ -111,7 +111,7 @@ msgstr "{tokenB} per {tokenA}"
msgid "Create Liquidity Mining"
msgstr "Create Liquidity Mining"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:336
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:339
#: src/widgets/PoolWidget/PoolOperate/components/LiquidityInfo.tsx:336
msgid "By adding liquidity you’ll earn <0>{0}0> of all trades on this pair proportional to your share of the pool. Fees are added to the pool, accrue in real time and can be claimed by withdrawing your liquidity."
msgstr "By adding liquidity you’ll earn <0>{0}0> of all trades on this pair proportional to your share of the pool. Fees are added to the pool, accrue in real time and can be claimed by withdrawing your liquidity."
@@ -588,11 +588,11 @@ msgstr "Added successful"
msgid "Add Initial Liquidity"
msgstr "Add Initial Liquidity"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:202
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:203
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:333
#: src/widgets/PoolWidget/AMMV3/AMMV3PositionManage.tsx:479
#: src/widgets/PoolWidget/AMMV3/components/ReviewModal.tsx:40
-#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:120
+#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:166
msgid "Add liquidity"
msgstr "Add liquidity"
@@ -890,7 +890,7 @@ msgstr "Staking"
msgid "Claiming"
msgstr "Claiming"
-#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:120
+#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:166
msgid "Create AMM V2 Position"
msgstr "Create AMM V2 Position"
@@ -931,7 +931,7 @@ msgstr "Owner"
msgid "The pegged exchange rate refers to the exchange rate between two token assets where one's value is pegged/fixed by the other. For example, the pegged exchange rate between the US Dollar and USDT is 1."
msgstr "The pegged exchange rate refers to the exchange rate between two token assets where one's value is pegged/fixed by the other. For example, the pegged exchange rate between the US Dollar and USDT is 1."
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:271
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:274
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:591
msgid "Deposit amounts"
msgstr "Deposit amounts"
@@ -1124,7 +1124,7 @@ msgstr "You will also claim all rewards from this pool."
msgid "The creator of the liquidity pool can adjust the liquidity distribution by modifying the market-making price parameters. <0>Learn more0>"
msgstr "The creator of the liquidity pool can adjust the liquidity distribution by modifying the market-making price parameters. <0>Learn more0>"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:382
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:385
#: src/widgets/PoolWidget/AMMV3/hooks/useV3DerivedMintInfo.tsx:523
msgid "Invalid pair"
msgstr "Invalid pair"
@@ -1521,7 +1521,7 @@ msgstr "Select pool by tokens"
msgid "Asset"
msgstr "Asset"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:384
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:387
#: src/widgets/PoolWidget/PoolOperate/AddPoolOperate.tsx:106
msgid "Supply"
msgstr "Supply"
@@ -1539,7 +1539,7 @@ msgstr "Mining Type"
msgid "Settler"
msgstr "Settler"
-#: src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts:113
+#: src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts:158
msgid "Remove liquidity"
msgstr "Remove liquidity"
@@ -1606,7 +1606,7 @@ msgstr "I have read, understand, and agree to the <0>Terms of Service0>."
msgid "Modify Confirmation"
msgstr "Modify Confirmation"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:334
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:337
#: src/widgets/PoolWidget/PoolOperate/components/LiquidityInfo.tsx:334
msgid "Tips:"
msgstr "Tips:"
@@ -1856,7 +1856,7 @@ msgstr "Once created, the price cannot be changed. This option applies to assets
#: src/components/Swap/components/SettingsDialog/index.tsx:50
#: src/widgets/PoolWidget/AMMV2Create/Setting.tsx:100
-#: src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx:122
+#: src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx:123
msgid "Slippage Tolerance"
msgstr "Slippage Tolerance"
@@ -1933,7 +1933,7 @@ msgstr "No matching pool found"
msgid "Low"
msgstr "Low"
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:220
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:221
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:369
msgid "Select pair"
msgstr "Select pair"
diff --git a/packages/dodoex-widgets/src/locales/zh-CN.po b/packages/dodoex-widgets/src/locales/zh-CN.po
index 29cc4c4f..aeb18eb4 100644
--- a/packages/dodoex-widgets/src/locales/zh-CN.po
+++ b/packages/dodoex-widgets/src/locales/zh-CN.po
@@ -111,7 +111,7 @@ msgstr ""
msgid "Create Liquidity Mining"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:336
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:339
#: src/widgets/PoolWidget/PoolOperate/components/LiquidityInfo.tsx:336
msgid "By adding liquidity you’ll earn <0>{0}0> of all trades on this pair proportional to your share of the pool. Fees are added to the pool, accrue in real time and can be claimed by withdrawing your liquidity."
msgstr ""
@@ -588,11 +588,11 @@ msgstr ""
msgid "Add Initial Liquidity"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:202
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:203
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:333
#: src/widgets/PoolWidget/AMMV3/AMMV3PositionManage.tsx:479
#: src/widgets/PoolWidget/AMMV3/components/ReviewModal.tsx:40
-#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:120
+#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:166
msgid "Add liquidity"
msgstr ""
@@ -890,7 +890,7 @@ msgstr ""
msgid "Claiming"
msgstr ""
-#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:120
+#: src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts:166
msgid "Create AMM V2 Position"
msgstr ""
@@ -931,7 +931,7 @@ msgstr ""
msgid "The pegged exchange rate refers to the exchange rate between two token assets where one's value is pegged/fixed by the other. For example, the pegged exchange rate between the US Dollar and USDT is 1."
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:271
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:274
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:591
msgid "Deposit amounts"
msgstr ""
@@ -1124,7 +1124,7 @@ msgstr ""
msgid "The creator of the liquidity pool can adjust the liquidity distribution by modifying the market-making price parameters. <0>Learn more0>"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:382
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:385
#: src/widgets/PoolWidget/AMMV3/hooks/useV3DerivedMintInfo.tsx:523
msgid "Invalid pair"
msgstr ""
@@ -1521,7 +1521,7 @@ msgstr ""
msgid "Asset"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:384
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:387
#: src/widgets/PoolWidget/PoolOperate/AddPoolOperate.tsx:106
msgid "Supply"
msgstr ""
@@ -1539,7 +1539,7 @@ msgstr ""
msgid "Settler"
msgstr ""
-#: src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts:113
+#: src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts:158
msgid "Remove liquidity"
msgstr ""
@@ -1606,7 +1606,7 @@ msgstr ""
msgid "Modify Confirmation"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:334
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:337
#: src/widgets/PoolWidget/PoolOperate/components/LiquidityInfo.tsx:334
msgid "Tips:"
msgstr ""
@@ -1856,7 +1856,7 @@ msgstr ""
#: src/components/Swap/components/SettingsDialog/index.tsx:50
#: src/widgets/PoolWidget/AMMV2Create/Setting.tsx:100
-#: src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx:122
+#: src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx:123
msgid "Slippage Tolerance"
msgstr "滑点"
@@ -1933,7 +1933,7 @@ msgstr ""
msgid "Low"
msgstr ""
-#: src/widgets/PoolWidget/AMMV2Create/index.tsx:220
+#: src/widgets/PoolWidget/AMMV2Create/index.tsx:221
#: src/widgets/PoolWidget/AMMV3/AddLiquidityV3.tsx:369
msgid "Select pair"
msgstr ""
diff --git a/packages/dodoex-widgets/src/utils/address.ts b/packages/dodoex-widgets/src/utils/address.ts
index bccf7fb1..6fe94d9e 100644
--- a/packages/dodoex-widgets/src/utils/address.ts
+++ b/packages/dodoex-widgets/src/utils/address.ts
@@ -4,6 +4,7 @@ import { scanUrlDomainMap } from '../constants/chains';
import { keccak256, pack } from '@ethersproject/solidity';
import { TokenInfo } from '../hooks/Token';
import { toWei } from './formatter';
+import { getIsAMMV2DynamicFeeContractByChainId } from '../widgets/PoolWidget/utils';
export const isSameAddress = (
tokenAddress1: string,
@@ -89,8 +90,16 @@ export async function openEtherscanPage(
);
}
-export const UNI_INIT_CODE_HASH =
+const UNI_DYNAMIC_FEE_INIT_CODE_HASH =
'0x67a372377cf6d7f78cfdcc9df0bc21e1139bd49e5a47c33ee0de5389a4396410';
+const UNI_FIXED_FEE_INIT_CODE_HASH =
+ '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f';
+export const getUniInitCodeHash = (chainId: number) => {
+ const isDynamic = getIsAMMV2DynamicFeeContractByChainId(chainId);
+ return isDynamic
+ ? UNI_DYNAMIC_FEE_INIT_CODE_HASH
+ : UNI_FIXED_FEE_INIT_CODE_HASH;
+};
export function sortsBefore(tokenA: TokenInfo, tokenB: TokenInfo): boolean {
if (tokenA.chainId !== tokenB.chainId) {
@@ -114,6 +123,10 @@ export const computePairAddress = ({
const [token0, token1] = sortsBefore(tokenA, tokenB)
? [tokenA, tokenB]
: [tokenB, tokenA]; // does safety checks
+
+ if (tokenA.chainId !== tokenB.chainId) {
+ throw new Error('token is not valid.');
+ }
return getCreate2Address(
factoryAddress,
keccak256(
@@ -125,6 +138,6 @@ export const computePairAddress = ({
),
],
),
- UNI_INIT_CODE_HASH,
+ getUniInitCodeHash(tokenA.chainId),
);
};
diff --git a/packages/dodoex-widgets/src/widgets/PoolWidget/AMMV2Create/index.tsx b/packages/dodoex-widgets/src/widgets/PoolWidget/AMMV2Create/index.tsx
index db7fafff..d64d82be 100644
--- a/packages/dodoex-widgets/src/widgets/PoolWidget/AMMV2Create/index.tsx
+++ b/packages/dodoex-widgets/src/widgets/PoolWidget/AMMV2Create/index.tsx
@@ -32,6 +32,7 @@ import MyLiquidity from './MyLiqidity';
import { useAMMV2AddLiquidity } from '../hooks/useAMMV2AddLiquidity';
import { PoolTab } from '../PoolList/hooks/usePoolListTabs';
import { getUniswapV2Router02ContractAddressByChainId } from '@dodoex/dodo-contract-request';
+import { getIsAMMV2DynamicFeeContractByChainId } from '../utils';
export default function AMMV2Create() {
const [fee, setFee] = React.useState(0.003);
@@ -259,13 +260,15 @@ export default function AMMV2Create() {
occupiedToken={baseToken}
/>
-
+ {(!chainId || getIsAMMV2DynamicFeeContractByChainId(chainId)) && (
+
+ )}
Deposit amounts}
diff --git a/packages/dodoex-widgets/src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx b/packages/dodoex-widgets/src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx
index ee2e9b2e..c6898f5d 100644
--- a/packages/dodoex-widgets/src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx
+++ b/packages/dodoex-widgets/src/widgets/PoolWidget/PoolOperate/components/SlippageSetting.tsx
@@ -17,6 +17,7 @@ import {
AUTO_LIQUIDITY_SLIPPAGE_PROTECTION,
AUTO_SWAP_SLIPPAGE_PROTECTION,
} from '../../../../constants/pool';
+import { PoolType } from '@dodoex/api';
export const useSlipper = ({
address,
@@ -66,7 +67,7 @@ export default function SlippageSetting({
onChange,
sx,
}: {
- type?: 'AMMV2' | 'AMMV3';
+ type?: PoolType;
disabled?: boolean;
value: number | typeof AUTO_SWAP_SLIPPAGE_PROTECTION;
onChange: (val: number | typeof AUTO_SWAP_SLIPPAGE_PROTECTION) => void;
diff --git a/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts b/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts
index b168842d..5183c4c7 100644
--- a/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts
+++ b/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2AddLiquidity.ts
@@ -13,7 +13,10 @@ import { useLingui } from '@lingui/react';
import {
encodeUniswapV2Router02AddLiquidity,
encodeUniswapV2Router02AddLiquidityETH,
+ encodeUniswapV2Router02FixedFeeAddLiquidity,
+ encodeUniswapV2Router02FixedFeeAddLiquidityETH,
getUniswapV2Router02ContractAddressByChainId,
+ getUniswapV2Router02FixedFeeContractAddressByChainId,
} from '@dodoex/dodo-contract-request';
export function useAMMV2AddLiquidity({
@@ -55,7 +58,15 @@ export function useAMMV2AddLiquidity({
const chainId = baseToken.chainId as ChainId;
const basicToken = basicTokenMap[chainId];
const basicTokenAddressLow = basicToken.address.toLowerCase();
- const to = getUniswapV2Router02ContractAddressByChainId(chainId);
+ const dynamicFeeContractAddress =
+ getUniswapV2Router02ContractAddressByChainId(chainId);
+ const fixedFeeContractAddress =
+ getUniswapV2Router02FixedFeeContractAddressByChainId(chainId);
+ const isFixedFee = !dynamicFeeContractAddress;
+ const to = dynamicFeeContractAddress || fixedFeeContractAddress;
+ if (!to) {
+ throw new Error('AMMV2 contract address is not valid.');
+ }
let data = '';
let value = '0x0';
const baseIsETH =
@@ -78,42 +89,77 @@ export function useAMMV2AddLiquidity({
const tokenInAmountMin = quoteInAmountMinBg.toString();
const ethAmountMin = baseInAmountMinBg.toString();
value = NumberToHex(baseInAmountBg) ?? '';
- data = encodeUniswapV2Router02AddLiquidityETH(
- tokenAddress,
- feeWei,
- tokenInAmount,
- tokenInAmountMin,
- ethAmountMin,
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeAddLiquidityETH(
+ tokenAddress,
+ tokenInAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02AddLiquidityETH(
+ tokenAddress,
+ feeWei,
+ tokenInAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ }
} else if (quoteIsETH) {
const tokenAddress = baseToken.address;
const tokenInAmount = baseInAmountBg.toString();
const tokenInAmountMin = baseInAmountMinBg.toString();
const ethAmountMin = quoteInAmountMinBg.toString();
value = NumberToHex(quoteInAmountBg) ?? '';
- data = encodeUniswapV2Router02AddLiquidityETH(
- tokenAddress,
- feeWei,
- tokenInAmount,
- tokenInAmountMin,
- ethAmountMin,
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeAddLiquidityETH(
+ tokenAddress,
+ tokenInAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02AddLiquidityETH(
+ tokenAddress,
+ feeWei,
+ tokenInAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ }
} else {
- data = encodeUniswapV2Router02AddLiquidity(
- baseToken.address,
- quoteToken.address,
- feeWei,
- baseInAmountBg.toString(),
- quoteInAmountBg.toString(),
- baseInAmountMinBg.toString(),
- quoteInAmountMinBg.toString(),
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeAddLiquidity(
+ baseToken.address,
+ quoteToken.address,
+ baseInAmountBg.toString(),
+ quoteInAmountBg.toString(),
+ baseInAmountMinBg.toString(),
+ quoteInAmountMinBg.toString(),
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02AddLiquidity(
+ baseToken.address,
+ quoteToken.address,
+ feeWei,
+ baseInAmountBg.toString(),
+ quoteInAmountBg.toString(),
+ baseInAmountMinBg.toString(),
+ quoteInAmountMinBg.toString(),
+ account,
+ deadline,
+ );
+ }
}
const txResult = await submission.execute(
diff --git a/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts b/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts
index c2bf6a7b..46c0cbe7 100644
--- a/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts
+++ b/packages/dodoex-widgets/src/widgets/PoolWidget/hooks/useAMMV2RemoveLiquidity.ts
@@ -14,6 +14,9 @@ import {
encodeUniswapV2Router02RemoveLiquidityETH,
encodeUniswapV2Router02RemoveLiquidity,
getUniswapV2Router02ContractAddressByChainId,
+ getUniswapV2Router02FixedFeeContractAddressByChainId,
+ encodeUniswapV2Router02FixedFeeRemoveLiquidityETH,
+ encodeUniswapV2Router02FixedFeeRemoveLiquidity,
} from '@dodoex/dodo-contract-request';
export function useAMMV2RemoveLiquidity({
@@ -53,7 +56,15 @@ export function useAMMV2RemoveLiquidity({
const chainId = baseToken.chainId as ChainId;
const basicToken = basicTokenMap[chainId];
const basicTokenAddressLow = basicToken.address.toLowerCase();
- const to = getUniswapV2Router02ContractAddressByChainId(chainId);
+ const dynamicFeeContractAddress =
+ getUniswapV2Router02ContractAddressByChainId(chainId);
+ const fixedFeeContractAddress =
+ getUniswapV2Router02FixedFeeContractAddressByChainId(chainId);
+ const isFixedFee = !dynamicFeeContractAddress;
+ const to = dynamicFeeContractAddress || fixedFeeContractAddress;
+ if (!to) {
+ throw new Error('AMMV2 contract address is not valid.');
+ }
let data = '';
const value = '0x0';
const baseIsETH =
@@ -74,39 +85,73 @@ export function useAMMV2RemoveLiquidity({
const tokenAddress = quoteToken.address;
const tokenInAmountMin = quoteInAmountMinBg.toString();
const ethAmountMin = baseInAmountMinBg.toString();
- data = encodeUniswapV2Router02RemoveLiquidityETH(
- tokenAddress,
- feeWei,
- liquidityAmount,
- tokenInAmountMin,
- ethAmountMin,
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeRemoveLiquidityETH(
+ tokenAddress,
+ liquidityAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02RemoveLiquidityETH(
+ tokenAddress,
+ feeWei,
+ liquidityAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ }
} else if (quoteIsETH) {
const tokenAddress = baseToken.address;
const tokenInAmountMin = baseInAmountMinBg.toString();
const ethAmountMin = quoteInAmountMinBg.toString();
- data = encodeUniswapV2Router02RemoveLiquidityETH(
- tokenAddress,
- feeWei,
- liquidityAmount,
- tokenInAmountMin,
- ethAmountMin,
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeRemoveLiquidityETH(
+ tokenAddress,
+ liquidityAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02RemoveLiquidityETH(
+ tokenAddress,
+ feeWei,
+ liquidityAmount,
+ tokenInAmountMin,
+ ethAmountMin,
+ account,
+ deadline,
+ );
+ }
} else {
- data = encodeUniswapV2Router02RemoveLiquidity(
- baseToken.address,
- quoteToken.address,
- feeWei,
- liquidityAmount,
- baseInAmountMinBg.toString(),
- quoteInAmountMinBg.toString(),
- account,
- deadline,
- );
+ if (isFixedFee) {
+ data = encodeUniswapV2Router02FixedFeeRemoveLiquidity(
+ baseToken.address,
+ quoteToken.address,
+ liquidityAmount,
+ baseInAmountMinBg.toString(),
+ quoteInAmountMinBg.toString(),
+ account,
+ deadline,
+ );
+ } else {
+ data = encodeUniswapV2Router02RemoveLiquidity(
+ baseToken.address,
+ quoteToken.address,
+ feeWei,
+ liquidityAmount,
+ baseInAmountMinBg.toString(),
+ quoteInAmountMinBg.toString(),
+ account,
+ deadline,
+ );
+ }
}
const txResult = await submission.execute(
diff --git a/packages/dodoex-widgets/src/widgets/PoolWidget/utils.ts b/packages/dodoex-widgets/src/widgets/PoolWidget/utils.ts
index 68951126..0d538aed 100644
--- a/packages/dodoex-widgets/src/widgets/PoolWidget/utils.ts
+++ b/packages/dodoex-widgets/src/widgets/PoolWidget/utils.ts
@@ -2,6 +2,10 @@ import { AMMV3Api, ChainId, ExcludeNone, PoolApi, PoolType } from '@dodoex/api';
import { contractRequests } from '../../constants/api';
import { TokenInfo } from '../../hooks/Token';
import { OperatePool } from './PoolOperate/types';
+import {
+ getUniswapV2FactoryContractAddressByChainId,
+ getUniswapV2Router02ContractAddressByChainId,
+} from '@dodoex/dodo-contract-request';
export const poolApi = new PoolApi({
contractRequests,
@@ -143,3 +147,10 @@ export function getPoolAMMOrPMM(type: PoolType) {
return 'PMM';
}
}
+
+export function getIsAMMV2DynamicFeeContractByChainId(chainId: number) {
+ return !!(
+ getUniswapV2FactoryContractAddressByChainId(chainId) &&
+ getUniswapV2Router02ContractAddressByChainId(chainId)
+ );
+}