Uniswap V3 routing tests for contract PaymentHub, added fixed routes - #221
Open
0xPuddi wants to merge 3 commits into
Open
Uniswap V3 routing tests for contract PaymentHub, added fixed routes#2210xPuddi wants to merge 3 commits into
0xPuddi wants to merge 3 commits into
Conversation
…for WETH, WBTC, USDC, USDT, DAI, tested routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Route Testing
The objective was to test and implement different routing paths from external tokens and native ETH to be exchanged by the Uniswap V3 router to ZCHF.
Testing is separated into, basic functionality testing of
DirectInvestment.sol, native ETH payment and programmatic testing of external currencies defined withinEXTERNAL_TOKENSintest/Routing.ts.Routes
Routes are defined within
EXTERNAL_TOKENSand with the interface:I spend some words about it because a new entry will generate a new test case.
imperFunder_ADDRESS: "0x...", is the address we can impersonificate to fund the investor address with the external token.imperFunder_AMOUNT: number, is the amount of token to be sent to the investor from the impersonificated address. Note that as shares increase in price as the investor buys them you need to account for such increase, I recommend to fund with an amount of 1000.- with an increase of 200.- for each new token, increase is cumulative by order of keys definition. Consider it with no decimals, the decimal normalization is taken care of.It is important to note that for imperFunder_ADDRESS and imperFunder_AMOUNT you need to consider quantities and prices of block 25464800.
address: "0x.."is the address of the external token.path: ["address", "uint24", "address", "uint24", "address", ...], is where the first address is the output token, the last address the input token and the "unit24" is the fee of the pool between the two adjacent token addresses. Note: you need to follow exactOutput format, so from the out token to the input token.pools: ["0x...", "0x..."], the address of pools that are used within the path, following also the same order.Routes can be used by the frontend to execute swaps.
USDT Approval
For routing we need to allow
PaymentHub.solcontract to spend the external token in order to swap it through the Uniswap V3 pool based on path. For any proposed external token it worked fine, but for USDT theapprovefunction does not return a boolean as prescribed by the ERC20 standard, which makes ethers fail to send and execute the transaction. To address it I tried a workaround within the ethers client but it did not work. To make it function, I added aINoReturnApproveinterface with a silentapproveand defined new public functionsilentApproveERC20, this might be a problem since there would need to be a new deployment of the contract for the USDT token. Could be worth to spend more time if it is possible address it client side.Packages
I added
@uniswap/v3-coreto the packages to have theUniswapV3PoolABI.Small Misecllaneous Changes
Added
.DS_Storeto.gitignore. FormattedPaymentHub.sol. AddedsepoliatoKEYS_TEMPALTE.tsto run tests correctly. Formattedhardhat.config.tsand added mainnet fork with fixed blockmainnetForkAtBlock25464800for routing testings, I did so as tests rely on exchange rates and EOA balances for funding.Notes
I omitted testing for unused
withdrawTokenandmultiPayfromPaymentHub.sol.