Skip to content

Commit

Permalink
feat: allow fixed fee contract
Browse files Browse the repository at this point in the history
  • Loading branch information
junjieit committed Dec 9, 2024
1 parent 36f12e2 commit 36b1560
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 99 deletions.
2 changes: 1 addition & 1 deletion packages/dodoex-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 18 additions & 4 deletions packages/dodoex-api/src/services/pool/PoolApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
fetchUniswapV2PairTotalSupply,
fetchUniswapV2PairGetReserves,
fetchUniswapV2PairFeeRate,
getUniswapV2Router02ContractAddressByChainId,
getUniswapV2FactoryContractAddressByChainId,
} from '@dodoex/dodo-contract-request';
import { formatUnits } from '@dodoex/contract-request';

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions packages/dodoex-widgets/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -154,4 +154,5 @@
"ts-jest": "^29.0.1",
"typescript": "^5.6.3"
}
}
}

22 changes: 11 additions & 11 deletions packages/dodoex-widgets/src/locales/en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 more</0>"
msgstr "The creator of the liquidity pool can adjust the liquidity distribution by modifying the market-making price parameters. <0>Learn more</0>"

#: 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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -1606,7 +1606,7 @@ msgstr "I have read, understand, and agree to the <0>Terms of Service</0>."
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:"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
22 changes: 11 additions & 11 deletions packages/dodoex-widgets/src/locales/zh-CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 more</0>"
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 ""
Expand Down Expand Up @@ -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 ""
Expand All @@ -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 ""

Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 "滑点"

Expand Down Expand Up @@ -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 ""
Expand Down
17 changes: 15 additions & 2 deletions packages/dodoex-widgets/src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand All @@ -125,6 +138,6 @@ export const computePairAddress = ({
),
],
),
UNI_INIT_CODE_HASH,
getUniInitCodeHash(tokenA.chainId),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -259,13 +260,15 @@ export default function AMMV2Create() {
occupiedToken={baseToken}
/>
</Box>
<FeeEdit
fee={fee}
onChange={setFee}
feeList={feeList}
hasCustom
disabled={needToken}
/>
{(!chainId || getIsAMMV2DynamicFeeContractByChainId(chainId)) && (
<FeeEdit
fee={fee}
onChange={setFee}
feeList={feeList}
hasCustom
disabled={needToken}
/>
)}
</CreateItem>
<CreateItem
title={<Trans>Deposit amounts</Trans>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 36b1560

Please sign in to comment.