Skip to content

Relay Design

hashmesan edited this page Jun 21, 2021 · 2 revisions

Motivation

The smart contract wallet will be created separately, and will be used independently (self-sufficient) from the user's existing wallet. Therefore a relayer is necessary to relay transactions and deduct the fees from the smart contract.

In the case of wallet creation, the user is also required to send a first deposit to include at minimum the initial network fee to create the wallet. This is a scalable process where the fees will not be a burden to the relay operator. In addition user-experience wise, the user is more likely to use the wallet in the future if he/she has some of her funds in the account. It is inline with the typical blockchain experience of sending funds to activate address.

Technical Design

Smart contracts

WalletFactory(implementation) => Wallet Factory clones wallet implementation. Implementation can be switched out to newer wallets as we have new features and bug fixes.

Forwarder => Forwarder addresses only purpose is to forward any funds received to the Relayer. It acts as a unique way to identify which funds associate to what New Wallet information. 2 Also referenced Quanta labs work on crosschain.

Relayer (walletfactory) => Relayer uses walletfactory to generate new wallets. Here's the process of how relayer wallet creation works.

  1. Client requests API => Contract Relayer::submitNewWalletQueue(config, networkFee, createForwarderIfNeeded) : networkFee is determined by the application-relayer - it can be determined by some historical networkFee the operator incurred. config is the basic wallet creation information (owner, rootHash, merkelHeight, etc). The smart contract queues up and associate the data to a new forwarding address.
  2. Client receives a forwarding address and deposit funds into that address.
  3. Forwarder receives the funds and forward to Relayer
  4. Client requests API => Contract Relayer::getStatus(forwarder) to check on deposits and status whether it can be processed.
  5. Client requests API => Contract Relayer::processWallet(forwarder) to create the new wallet and transfer deposits to the smart contract.
  6. Daily/Weekly: the relayer operator will call Contract Relayer:collectFees(), and this replenish relayer's fees to continue calling (1)(5).

As a technical note, Relayer and WalletFactory uses CREATE2 to create counterfactual addresses.

TOTPWallet => This is the smart contract wallet. It implements

    function executeMetaTx(
            bytes   calldata data,
            bytes   calldata signatures,
            uint256 nonce,
            uint256 gasPrice,
            uint256 gasLimit,
            address refundToken,
            address refundAddress            
        ) external 

Based on argent 1 This function allows any self - execution of function and verify single or multsig (social recovery), and deduct the fees to the refundAddress.

Web Service

The web service implements the account creation flows above, basic account queries, and forward meta tx (smart wallet operations). The relayer shall have a regular account to pay for all the fees. MetaTX fees will be refunded directly by the smart wallet contract on every execution.

References

[1] https://github.com/argentlabs/argent-contracts/blob/79b60e224353d4f9bbb22b1c7d157e46103c122b/contracts/modules/RelayerManager.sol#L81

[2] https://github.com/argentlabs/deposit-forwarder

[3] https://github.com/Loopring/protocols/blob/master/packages/hebao_v2/contracts/base/WalletFactory.sol

Clone this wiki locally