joystream icon indicating copy to clipboard operation
joystream copied to clipboard

`Argo` bridge runtime pallet

Open kdembler opened this issue 10 months ago • 18 comments

See background in #5084

Goal

Develop argoBridge runtime pallet that will be used for Argo bridge operations.

Required functionalities:

  • Allowing users to request bridging to Ethereum.
  • Allowing bridge operators to finalise transfers from Ethereum.
  • Proper security model as described in the background issue.
  • Letting the Council adjust pallet configuration via a proposal.

Pallet

State

  1. status: enum with options { type: 'active' } | { type: 'paused' } | { type: 'thawn'; thawn_started_at: 123456 }.
  2. operator_account: account ID.
  3. pauser_accounts: list of account IDs with permission to pause the bridge operations.
  4. mint_allowance: number indicating number of tokens that the bridge pallet is able to mint. This should always equal total_burned - total_minted.
  5. bridging_fee: amount of JOY burned as a fee for each transfer.
  6. thawn_duration: number of blocks needed before bridge unpause can be finalised.

Proposal

Single 3/3 proposal allowing the Council to update the following state values:

  1. operator_account
  2. pauser_accounts
  3. bridging_fee
  4. thawn_duration

Emits BridgeConfigUpdated(config)event

Extrinsics

  1. request_outbound_transfer(dest_account, amount, expected_fee) - callable by anybody:
    1. Checks that the status is { type: 'active' }.
    2. Burns the fee
    3. Burns amount of JOY from sender account, increases mint_allowance by amount
    4. Computes transfer_id by hashing (dest_account, amount, block_number, call_index_in_block)
    5. Emits an event OutboundTransferRequested(transfer_id, dest_account, amount, paid_fee)
  2. finalize_inbound_transfer(dest_account, amount, request_block, request_nonce) - callable by operator_account only:
    1. Checks that the status is { type: 'active' }.
    2. Computes transfer_id by hashing (dest_account, amount, request_block, request_nonce)
    3. Checks that amount is not bigger than current mint_allowance
    4. Decreases mint_allowance by amount, mints amount of JOY tokens to dest_account
    5. Emits an event InboundTransferFinalized(transfer_id)
  3. pause_bridge() - callable by any of pauser_accounts:
    1. Changes status to { type: 'paused' }
    2. Emits an event BridgePaused(pauser)
  4. init_unpause_bridge() - callable by any of pauser_accounts:
    1. Changes status to { type: 'thawn'; thawn_started_at: current_block }
    2. Emits an event BridgeThawnStarted(pauser)
  5. finish_unpause_bridge() - callable by operator_account only:
    1. Checks that status.type === 'thawn && current_block > status.thawn_started_at + thawn_duration`
    2. Changes status to { type: 'active' }
    3. Emits an event BridgeThawnFinished()

kdembler avatar Apr 12 '24 13:04 kdembler