aurora-is-near / aurora-engine

⚙️ Aurora Engine implements an Ethereum Virtual Machine (EVM) on the NEAR Protocol.
https://doc.aurora.dev/develop/compat/evm
325 stars 78 forks source link

draft: refund on XCC token transfer #801

Closed Tarnadas closed 1 year ago

Tarnadas commented 1 year ago

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:

Scenario 2:

Tokens 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:

I stumbled across the following problems:

  1. we don't know in the XCC contract what the EVM address is for the refund
    • (Solution): we need to extend the PromiseCreateArgs to also include the EVM sender address
  2. it 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 succeed
    • no 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?

(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.