This page provides general information about the used contract and required files around the contract. All contract source codes can be found under the src folder.
The following are the main contract features:
-
Fork of Uniswap V3 for Polygon.
-
Tiered transaction fees.
-
Allow users add arbitrary coin/ERC20 Pools.
-
Concentrated liquidity model
- Default range of +/-20% of current price
- Option for custom ranges (for a fee)
-
Yield and dividend features:
- Auto-compounds yields into the pool
- Provides harvestable rewards for LPs (native coin or token e.g. HKD)
The contracts are covered by unit tests. Both happy paths and unhappy paths should be sufficiently covered.
You can run unit tests with Hardhat: npx hardhat test.
To start development on the project, you should do (at least) the following:
-
Install packages:
npm i -
Compile contracts:
npx hardhat compile -
Run unit tests:
npx hardhat test
A sample deployment script has been created. It deploys all the contracts and also verifies them in Etherscan. You can run the script by following these steps:
-
Set up environment variables in a file called
.env. There is an example of the settings in.env.example. -
Run script with
npx hardhat run scripts/deploy.ts --network [network]- base-amoy: This is for Polygon test Network
- base-polygon: This is for Poygon main Network
- sepolia: This is for Ethereum test Network
- base-ethereum: This is for Ethereum main Network
- base-binance: This is for Binance main Network
-
Create Polygon scan API KEY(update .env file) and run the script.
npx hardhat verify --network [network] deployed_address args -
here is example
npx hardhat verify --network base-amoy 0x1A8F35390151042886dDf2221886AAc25E689b3F
- Reorder of the Token A and Token B addresses is required:
if (token0.address.toUpperCase() > token1.address.toUpperCase()) { let temp = token0; token0 = token1; token1 = temp; }
- Customized price range should be provided as
starting tick pointandending tick point
The latest test deployment to Amoy network is following
Description for the usage of Dex contract.
-
Creat a Pool
createPoolis a function for creating a pool- there are 4 input parameters
tokenA: first token address like0x6D502C7Ec05e89aDDBF2B0Cf2Eea28a1534Dd362tokenB: second token address like0xF8bb0a8fd3A54b5B35Cc9E75214eD851C923E9E5fee: this is representing fee choice of swaping. there are 4 tired fee options:100(0.01%),500(0.05%),3000(0.3%),10000(1%)currentPrice: this is the price ratio between tokenA and tokenB. this value is calculated likeWarning: becareful for the order of tokenA and tokenB. Refer this: Jump to Frontend CollaborationscurrentPrice = tokenB.price / tokenA.price * 10 ^ 10
-
Add Liquidity
mintfunction is for Adding Liquidity.- there are 9 parameters are required.
tokenAis for the ordered first token address.tokenBis for the ordered second token address.feeis representing pool fee amount.lowerTickis the starting tick point.upperTickis the eding tick point.amount0Desiredthis is the desired tokenA amountaomount1Desiredthis is the desired tokenB amountamount0Minthis is minimum amount for tokenAamount1Minthi is minimum amount for tokenB
Warning:
tokenA,tokenBandfeeare used to indicate the pool contract.- default
lowerTickandupperTickare found fromgetStandardSlot0()
-
Swap
swapSingleis for swapping tokens for existing token pairs.- there are 4 input parameters
tokenIn: this is for token address that will be swapped.tokenOut: this is token addresss that will get after swapping.fee: this is swaping fee. this would be used to indicate the pool together withtokenInandtokenOut
-
Remove Liquidity
burnis the function for removing liquidity.- there are 6 input parameters
tokenAtokenBfeelowerTickupperTickliquiditythis is the amount for withdrawal of liquidity
Warning:
lowerTickandupperTickshould be same as adding liquidity unless it would fail.- if the
liquidityis above the actual amount of LP's liquidity amount, it will withdraw his total amount.
-
Yield Farming
collectis the function for yielding accumulated liquid revenue.- there are 8 input parameters
tokenAtokenBfeerecipientthis is wallet address for receiving the liquidity revenue.lowerTickupperTickamount0Desiredamount1Desired
-
Yield Owner Fee
collectOwnerFeeis the function for collecting accumulated Admin fee.- this is similar to Yield Farmining
Precaution
- before starting the transactions like mint and swap you need to make sure that you approved allowance to the contract for the amount you want to transfer.