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.
Motivation
I've been integrating the Aurora SDK in my orderbook implementation on Near (not yet open source) to do XCC from Aurora to Near, however there is one essential thing missing which are refunds on token transfers.
Imagine the following two scenarios:
Scenario 1:
ft_transfer
orft_transfer_call
to FT contractScenario 2:
ft_transfer_call
to FT contractft_on_transfer
to receiver contract (e.g. a DEX)ft_resolve_transfer
and does the refund to XCC addressTokens being stuck without the possibility for a recovery is unacceptable for obvious reasons. Receipts can easily fail as you can see in scenario 2 where slippage constraint might not be met.
I have been in contact with @birchmd for quite a while to help me integrate Aurora SDK into the orderbook contract and everything works really good so far except the lack of refund. The orderbook I develop will be an upcoming product of Orderly Network. I really want to emphasize how essential a refund mechanism for bridged FT is. Without it you basically can't use Aurora SDK in DeFi.
Solution
My solution is WIP and I need help to fully implement it.
Let me demonstrate the solution for the updated scenario 2:
ft_transfer_call
,ft_on_transfer
receipt fail,ft_resolve_transfer
refund to XCCft_transfer_call
to Aurora engine address to bridge FT back to EVM addressft_resolve_transfer
returns the used amount of tokens. If the receipt failed no tokens at all have been used.I stumbled across the following problems:
PromiseCreateArgs
to also include the EVM sender addressit seems like the XCC account no longer gets created with my changes and all I can see is a revert of the Aurora tx, but the Near tx seems to succeedno solution so far, but I am clearly missing a change to update the input of the Near call to also include the sender. Where do I need to look for this?wasm-opt -Oz target/wasm32-unknown-unknown/release/xcc_router.wasm -o target/wasm32-unknown-unknown/release/xcc_router_opt.wasm --strip-debug --vacuum
I shrinked the binary size from 219KB to 183KB and storage staking is now sufficient with 2NEAR. Also keep in mind that only wasm-opt v110 generates proper binary output for Near Protocol. Any newer version produces unusable WASM files. Not sure about a workaround though.(As a side note I have some problems compiling rocksdb even though I have llvm and clang installed. Not sure what's the exact problem, but if I check out the most recent rocksdb from crates.io it can be compiled. Maybe worth looking into upgrading the dep?)
I know this is quite a drastic change and I haven't created a prior AIP. Please let me know what we need to do to get this implemented.
TODOs
ft_transfer_call
refundft_transfer
refund