-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/vault swaps ccm #242
Feat/vault swaps ccm #242
Conversation
Updates after some discussions: |
Refund address to be changed from address to bytes, for consistency for how we expect addresses.. It is unclear if it will be used for gas refunds or for refunding failed swaps or any of that. A byte can also be used to represent ingress/egress addresses. |
First draft of the updated logic and tests to enable cross chain messaging, both ingress and egress.
The intention of this PR is to enable both swapping through the Vault contract, also allowing CCM (cross-chain messaging).
Swapping through the Vault is enabled via
xSwapNative
andxSwapToken
, which will basically emit an event that will be witnessed.xCallNative
andxCallToken
will allow for cross-chain calls with or without a swap at the same time (depending on the swapIntent). That call will be a call viacfReceive()
on the egress chain with an additional message passed as a parameter. On the egress chain, that is done on viaexecutexSwapAndCall
. Also, in the case of a xCall, the destination native gas that the user wants to pay for, as well as a refundAddress needs to be specified. This is because the user will pay for the gas on the egress chain (we will take subtract it from the input amount and swap it to egress native token) and we will refund them with any remaining gas. The refunding part is not yet decided, but it would just be a matter of removing that parameter.For all these functions I am particularly interested in discussing the interfaces. Please have in mind that those parameters are targeting all chains, not only EVM's. This is my reasoning for the parameters:
Regarding the
_executexSwapAndCall
I have considered having a try-catch statement to ensure the tokens are transferred even in case of reverting of the call. However, I have decided against it for a few reasons: (just fyi, Axelar also does it this way)1- When a swap is done via a DEX aggregator ( AGG -> CF -> CF -> AGG) they already have that safeguard to ensure the tokens end at the user's address. Having our try-catch that basically would end up transferring the tokens to the AGG contract doesn't solve anything.
2- If the dstAddress is an EOA, it's all good. If it's a contract, they have the flexibility to implement the try-catch or not, depending on what they want to do. We will clearly state that we advise that logic in case there is any risk of reverting.
3- In our protocol, we will have an easy time allowing for the user to replay the transaction in case of revertion. This is because anyone can send the signed transaction (msg.sender is irrelevant). Therefore, allowing it to revert makes it so users that prefer being able to replay a xCall instead of the tokens being transferred and the xCall being executed. It can happen that the xcall will never succeed when replayed, but in that case it is the user's responsibility to have implemented a try-catch or a way to ensure the xCall can succeed eventually.
Gas topups is commented out as it's unclear we want that in the contract at this point.
Topics for this PR:
DexAggMock.sol
and tests can be interesting to understand how it should work, but not really code we will deploy.Still some open questions at the protocol level (not for this PR):
Which enable signals do we need? swapsEnabled? xCallEnabled?