Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Update Fee market docs (#178)
Browse files Browse the repository at this point in the history
* Update doc

* Update example
  • Loading branch information
boundless-forest authored and jiguantong committed Sep 29, 2022
1 parent fa2d416 commit 6d1f926
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions modules/fee-market/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Requirements

1. Users use native tokens of the source chain as the only method of cross-chain payment.
1. Users use native tokens of the source chain as the only method of cross-chain payment;
2. The cross-chain fees paid by users are generated by the fee market system and the final price quoted by the fee market is influenced by all relayers involved in the delivery of messages throughout the market.
3. The cost on the target chain is at the expense of the relayer who claims the handling fee on the source chain with the proof of delivery after delivery is completed successfully. To incentivize relayers, the fee market system should ensure the relayers gain is greater than the cost in long term. If an automatic pricing mechanism is infeasible, relayers should be able to give their offers manually and shoulder the cost of offering. The relayers should be punished if they fail to relay the message as expected.
4. Relayers and Users constitute a secondary supply-and-demand market, where quotes rise when relayers number is low and fall when relayers number is abundant. There are no access restrictions for relayers, and anyone can enter. Relayer should evaluate and quote at their own discretion as an economically rational person. An incomplete list of risks that relayers should take into account is as follows:
Expand All @@ -26,7 +26,7 @@ In any time, the message delivery and confirmation relayer can be anyone, do not

When calculating rewards and penalties, the following parameters are crucial.

- DutyRelayersRewardRatio: `20% by default`
- GuardRelayersRewardRatio: `20% by default`
- MessageRelayersRewardRatio: `80% by default`
- ConfirmRelayersRewardRatio: `20% by default`
- AssignedRelayerSlashRatio: `20% by default`
Expand All @@ -40,31 +40,12 @@ After a user sends a cross-chain transaction, the fee market system calculates t

As long as the order is confirmed before the last block of the nth slot, we consider it to be delivered on time, and the calculation of rewards and penalties varies depending on when the message is confirmed.

Suppose the cross-chain message has n slots, the message is confirmed at the m-th slot, and `Pm` denotes the quote price of m-th slot. At this point, the assigned relayers from 0 to m slots will be penalized, and the penalty will be calculated as `AssignedRelayerSlashRatio * collateral`, while the assigned relayers from m to n slots will receive a reward for ensuring the message is completed on time `(DutyRelayersRewardRatio * (fee - Pm)) / (n - m)`. `Pm` plus the penalties for the other assigned relayers mentioned above will be distributed as new rewards to the message delivery relayer and the message confirm relayer, where the message delivery relayer receive the `MessageRelayersRewardRatio` of this reward, the message confirm relayer gets the `ConfirmRelayersRewardRatio` of this reward. The rest of the fee will be given to treasury.
Suppose the cross-chain message has n slots, the message is confirmed at the m-th slot, and `Pm` denotes the quote price of m-th slot. At this point, the assigned relayers from 0 to m slots will be penalized, and the penalty will be calculated as `AssignedRelayerSlashRatio * collateral`, while the assigned relayers from m to n slots will receive a reward for ensuring the message is completed on time `(GuardRelayersRewardRatio * (fee - Pm)) / (n - m)`. `Pm` plus the penalties for the other assigned relayers mentioned above will be distributed as new rewards to the message delivery relayer and the message confirm relayer, where the message delivery relayer receive the `MessageRelayersRewardRatio` of this reward, the message confirm relayer gets the `ConfirmRelayersRewardRatio` of this reward. The rest of the fee will be given to treasury.

- The cross-chain transaction is confirmed after the last block of the n slot.

We believe that this cross-chain transaction is severely delayed, in which case all assigned relayers will be heavily penalized by deducting the `AssignedRelayerSlashRatio` of the collateral and calculating an additional penalty amount based on the delay time. These penalty amounts, plus the cross-chain fees paid by users, will be distributed as new rewards to the message delivery relayer and the message confirm relayer, where the message delivery relayer receive the `MessageRelayersRewardRatio` of this reward, the message confirm relayer gets the `ConfirmRelayersRewardRatio` of this reward.


The following diagram shows how rewards are distributed:

```sh

assigned offensive relayers collateral
| |---> messaage delivery relayer
| |
|- slot price + slot offensive slash(may have) = message reward --> |
| |
message fee - |---> message confirm relayer
| ---> treasury
| |
|- message surplus -|
|
---> slot duty rewards -> assigned duty relayers

```

### An example

1. Assume that relayers `R1`, `R2`, `R3`, `R4` and `R5` have registered with the fee market and are all running relayer clients capable of delivering messages with quote prices of `P1=10`, `P2=20`, `P3=30`, `P4=4`0 and `P5=50` and are registered with a locked asset of `100`.
Expand All @@ -85,7 +66,7 @@ The slash, reward analysis is divided into two cases.

Reward Summary:

* To assigned relayers (R1, R2, R3): `(DutyRelayersRewardRatio * (30 - 10)) / 3 = 1`
* To assigned relayers (R1, R2, R3): `(GuardRelayersRewardRatio * (30 - 10)) / 3 = 1`
* To treasury: `30 - 10 - 1 * 3 = 17`
* To message delivery relayer: `10 * MessageRelayersRewardRatio = 8`
* To message confirm relayer: `10 * ConfirmRelayersRewardRatio = 2`
Expand All @@ -100,7 +81,7 @@ The slash, reward analysis is divided into two cases.

Reward Summary:

* To assigned relayers (R2, R3) = `(DutyRelayersRewardRatio * (30 - 20)) / 2 = 1`
* To assigned relayers (R2, R3) = `(GuardRelayersRewardRatio * (30 - 20)) / 2 = 1`
* To treasury: `30 - 20 - 1 * 2 = 8`
* To message delivery relayer: `(20 + 20) * MessageRelayersRewardRatio = 32`
* To message confirm relayer: `(20 + 20) * MessageRelayersRewardRatio = 8`
Expand All @@ -117,7 +98,7 @@ The slash, reward analysis is divided into two cases.

Reward Summary:

* To assigned relayers (R3) = `(DutyRelayersRewardRatio * (30 - 30)) / 1 = 0`
* To assigned relayers (R3) = `(GuardRelayersRewardRatio * (30 - 30)) / 1 = 0`
* To treasury: `30 - 30 - 0 = 0`
* To message delivery relayer: `(10 + 20 * 2) * MessageRelayersRewardRatio = 56`
* To message confirm relayer: `(10 + 20 * 2) * MessageRelayersRewardRatio = 14`
Expand All @@ -139,4 +120,4 @@ The slash, reward analysis is divided into two cases.
* To assigned relayers: `0`
* To treasury: `0`
* To message delivery relayer: `(30 + 40 * 3) * MessageRelayersRewardRatio = 120`
* To message confirm relayer: `(30 + 40 * 3) * MessageRelayersRewardRatio = 30`
* To message confirm relayer: `(30 + 40 * 3) * MessageRelayersRewardRatio = 30`

0 comments on commit 6d1f926

Please sign in to comment.