Consistent Amounts #937
Replies: 3 comments 5 replies
-
This is, imo, the easiest tradeoff here. Again imo, but the whole "requires middleware contracts" is a great opportunity for us to establish common patterns / practices for devs building xapps. Do you need the exact amount as input to your contract? Use our ExactAmountFormatter middleware contract - even just as an example / starting point. I see this making the most sense short-term for sure, and I think devs will understand the decision-making behind it. Long term, we'll want to consider providing an option to do |
Beta Was this translation helpful? Give feedback.
-
Still having an exact amount on the destination chain is needed for many use case, e.g. when working with DEX aggregators, the callData can not be adjusted to update the passed amounts. For those calls which require an exact amount a reusable middleware contract could be added, which can pass arbitrary calldata, gets information which token and exact amount is needed for the call and has access to a fallback address. After executing the call with the intended amount, it could refund the remaining balance to the fallback address. This would require additional passed parameters, but e.g. a fallback address if the contract call fails as in nxtp may be needed. |
Beta Was this translation helpful? Give feedback.
-
It would be really helpful to devs who build the xapps if we get this feature. To have a fallback address is absolutely needed as calldata arguments for some failure cases. |
Beta Was this translation helpful? Give feedback.
-
Motivation
The amarok hardfork of nxtp is built on top of the nomad token bridge. The nomad bridge will lock tokens on some origin domain, and mint mad-assets (representations of the original locked asset) on the destination domain. On domains where there is already an adopted/commonly used asset, this can lead to lots of added complexity (i.e. if you are using nomad to exit usdc from polygon you get mad-pos-usdc). To address this, nxtp has a stable swap built in to swap between adopted assets and mad assets. If you are bridging usdc from polygon to arbitrum, for example, you would:
The problem arises when you try to make use of calldata. NXTP allows for arbitrary calldata to be passed through the system so you can execute some function on a destination domain without writing middleware contracts. Unfortunately, most functions require an amount to be included in that calldata (i.e. a swap), which is difficult to include when using AMMs (in the above example, how do i know what the ultimate arbitrum usdc value will be a-priori).
Design Requirements
amount
in the destination domain calldata contextProposal
There are a few options:
Use
exactOut
One way to solve this problem is to create an exactOut path so you know exactly how much you will receive on the destination chain. This does allow you to calculate the amount to be used in the calldata up front, but just shifts the uncertainty around amounts to be on the amount you put in not what you get out.
Expose amount
This would allow contracts that need the amount delivered in the calldata to create simple parser contracts that construct the appropriate arguments. The problem here is it does require middleware contracts to account for the amount properly.
Get rid of AMMs
Using mad assets
This is relatively straightforward on the destination domain (router supplies liquidity in adopted asset, takes on risk for stable swap either independently or when the funds travel through the bridge), but much more difficult on the origin domain. Imagine the case where you exit polygon without the AMM swapping pos-usdc for mad-usdc -- the router would get reimbursed with mad-pos-usdc and you would either need a funded amm on the destination domain to swap for the right asset, or come up with a way to properly unwind. This introduces much more complex liquidity management, but the amount bridged would be easily calculated.
Liquidity pools
Another way to remove AMMs is to make use of liquidity pools and abandon bridge assets completely. In this model, instead of funding an AMM you would fund a liquidity pool. Routers would front their own capital in the same manner, and rather than using a nomad router that mints assets, we would use nomad to pass authenticated claims on the pool from one domain to another. This improves capital efficiency (just have to fund fast liquidity + pool rather than both sides of an AMM), but introduces liquidity imbalances across domains. You could introduce VAMMs to solve that, but this adds an additional layer of complexity and comes with its own drawbacks.
Open Questions
exactOut
path?Beta Was this translation helpful? Give feedback.
All reactions