ADD: Stateless EVM Router V6

Background

!4094 (merged)

Router V6 has the following upgrades

  1. Stateless: routes tokens to vaults directly
  2. Makes expiry optional on deposit
  3. Supports Mixed Batched Outbounds (ETH + ERC20)
  4. More advanced Dex Aggregation (passes additional parameters)

note: Batched Dex Aggregation support is not included.

Stateless

Router V4 is stateful, holding ERC20 tokens.

  1. Different pattern to every other asset, which is held on the vaults instead.
  2. Makes Router upgrades hard (requires a router migration)
  3. Prevents memoless deposits for ERC20s since they can not be "sent" to a vault.

The router is only needed to emit a "memo" in an event. The memo is optional when needed for memoless (the amount encodes intent instead) #1569 (closed)

Deposits

Current:

safeAmount = safeTransferFrom(asset, amount); // Transfer asset here
_vaultAllowance[vault][asset] += safeAmount; // Credit to chosen vault

Change:

safeAmount = safeTransferFrom(asset, amount, vault); // move tokens to vault

TransferOuts

Instead of

_vaultAllowance[msg.sender][asset] -= amount; // Reduce allowance
asset.call(abi.encodeWithSignature("transfer(address,uint256)" , to, amount));

Change

safeAmount = safeTransferFrom(asset, amount, to); // Send direct to recipient

Balance Tracking

instead of

return _vaultAllowance[vault][token];

change

return iERC20(token).balanceOf(vault);

Optional Expiry

Expiry can be set to 0 on deposit to skip expiry check

Expiry was added prior to TC processing refunds to inactive vaults, less important now.

Batching

batchTransferOut() is added back in to accept an array of coins.

Upgraded Dex Aggregation

Emit Failure Log

transferOutAndCall() now emits a failure log if failing

V2 Function

transferOutAndCallV2() is added with additional parameters

struct Params {
        address payable target;
        address fromAsset;
        uint256 fromAmount; // new for tracking
        address toAsset;
        address recipient;
        uint256 amountOutMin;
        string memo;
        bytes payload; // new for tracking 
        string originAddress; // new for refunds
      }
Edited by THORChain