-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,67 @@ | ||
# Fees | ||
|
||
Sygma allows granular control of handling fees for each resource. Even though specific implementations differ based on | ||
chain architecture, general functionality is the same. The concept is that each resource is assigned a fee strategy for | ||
every potential destination domain, with this mapping also outlining all potential bridging routes for a given resource. | ||
Sygma allows granular control of handling fees for each resource. Although specific implementations differ based on chain architecture, the general functionality is the same. Each resource is assigned a fee strategy for every potential destination domain, and this mapping also outlines all potential bridging routes for a given resource. | ||
|
||
![](/docs/resources/fee-router-general.png) | ||
### Deposit flow | ||
|
||
1. **Calculate the final fee** | ||
- Call the contract to calculate the fee. This call, under the hood, fetches information on price from the on-chain oracle (for dynamic fee strategy) or uses predefined rules for fixed and percentage-based strategies. | ||
2. **Execute deposit** | ||
- Send the appropriate amount based on the calculated final fee when executing the deposit. | ||
|
||
## Fee strategies | ||
|
||
Fee strategy defines a set of rules on how fees should be charged when executing deposits on the source chain. | ||
|
||
### Fixed fee strategy | ||
|
||
This strategy always requires a predefined fixed fee amount per deposit. **EVM imlementation can only collect fees in the native | ||
currency of the source chain, while Substrate implementation allows for fee to be collected in any configured asset**. | ||
|
||
*On the diagram below, we use [Sygma SDK](https://github.com/sygmaprotocol/sygma-sdk) for interaction with all services.* | ||
|
||
![](/docs/resources/static-fee-general.png) | ||
### Dynamic fee strategy (EVM only) | ||
_Supported on: **EVM**_ | _Fee can be paid in:_ **Native asset** | ||
|
||
#### Deposit flow | ||
This strategy utilizes the on-chain `TwapOracle` contract to pull price information and calculate fees. The final fee is calculated based on the execution cost for the destination chain and can be paid in the native currency of the source chain. | ||
|
||
1) Calculate the final fee | ||
- Based on resourceID and domainsID, request a final fee amount that will be required to execute the deposit. | ||
2) Execute deposit | ||
- Send the appropriate base currency amount based on the calculated final fee when executing the deposit. | ||
Calculated fee consists out of two parts: | ||
`fee = execution cost + protocol fee` | ||
- **execution cost**: price of executing destination transaction | ||
- `destination_network_gasprice * gas_used * destination_coin_price_from_twap` | ||
|
||
|
||
### Percentage based fee strategy | ||
- **protocol fee**: fee that the protocol takes for maintenance costs | ||
- _fixed:_ constant amount of native tokens added on top of the execution cost | ||
- _percentage:_ percentage of the execution cost added on top of the execution cost | ||
- _** it is possible for some routes for protocol fee to be 0_ | ||
|
||
This strategy calculates fee amount based on the amount of token being transferred. | ||
Based on route type, there are two concrete implementations of dynamic fees fee handlers: | ||
|
||
It always collects fee in token that is being transferred, so it only makes sense for fungible token routes. | ||
- **For asset transfers**: `TwapNativeTokenFeeHandler.sol` | ||
- Parameter `gas_used` is fixed and configured in the contract (generally, transactions transferring specific type of asset use a fixed amount of gas) | ||
|
||
<img src="/docs/resources/percentage-formula-general.png" data-canonical-src="/docs/resources/percentage-formula-general.png" width="386" height="267" /> | ||
|
||
*On the diagram below, we use [Sygma SDK](https://github.com/sygmaprotocol/sygma-sdk) for interaction with all services.* | ||
- **For GMP (generic message) transfers**: `TwapGenericFeeHandler.sol` | ||
- Parameter `gas_used` is provided by the user with deposit data. This value will be set by the relayer executing this transaction, so the user must understand what they are executing. | ||
|
||
![](/docs/resources/percentage-fee-general.png) | ||
#### TwapOracle | ||
The TwapOracle is a wrapper contract around the Uniswap TWAP oracle system. Based on the configuration, this contract will either pull the price of the destination gas token periodically from Uniswap or use the configured fixed price of the destination gas token. | ||
|
||
#### Deposit flow | ||
### Fixed fee strategy | ||
_Supported on: **EVM**, **Substrate**_ | _Fee can be paid in:_ **Native asset** | ||
|
||
1) Calculate the final fee | ||
- Based on resourceID, domainsID and amount, request a final fee amount that will be required to execute the deposit. | ||
2) Execute deposit | ||
- Send the appropriate token amount based on the calculated final fee when executing the deposit. | ||
This strategy always requires a predefined fixed fee amount per deposit. **EVM implementation can only collect fees in the native currency of the source chain, while Substrate implementation allows for fees to be collected in any configured asset**. | ||
|
||
### Dynamic fee strategy (EVM only) | ||
### Percentage-based fee strategy | ||
_Supported on: **EVM**, **Substrate**_ | _Fee can be paid in:_ **Transferred asset** | ||
|
||
This strategy utilizes the [Sygma Fee Oracle service](https://github.com/sygmaprotocol/sygma-fee-oracle), which issues | ||
fee estimates with details on the gas price for the destination chain. In addition, fee oracle can provide price | ||
information for different tokens, enabling paying bridging fees in the not native currency. Each issued gas estimate has | ||
a limited time validity in which it needs to be executed. | ||
This strategy calculates the fee amount based on the amount of token being transferred. It always collects fees in the token that is being transferred, so it only makes sense for fungible token routes. | ||
|
||
Check out | ||
the [Sygma Fee Oracle technical documentation](https://github.com/sygmaprotocol/sygma-fee-oracle/blob/main/docs/Home.md) for | ||
more details on the service and the format of the issued fee estimates. | ||
<img src="/docs/resources/percentage-formula-general.png" data-canonical-src="/docs/resources/percentage-formula-general.png" width="386" height="267" /> | ||
|
||
## Architecture overview | ||
*On the diagram below, we use [Sygma SDK](https://github.com/sygmaprotocol/sygma-sdk) for interaction with all services.* | ||
|
||
![](/docs/resources/dynamic-fee-general.png) | ||
|
||
#### Deposit flow | ||
|
||
1) Fetch fee estimate | ||
- Based on resource ID and domains ID, request fee estimate from Fee Oracle service. This fee estimate is valid | ||
until `expiresAt`. | ||
2) Validate fee estimate and calculate the final fee | ||
- Validate the signature on the fee estimate. | ||
- Get the final fee amount that will be collected on deposit. | ||
3) Execute deposit | ||
- Provide fee estimate data as an argument when executing the deposit. | ||
|
||
## Implementations | ||
|
||
#### EVM | ||
|
||
Check out the [solidity documentation](https://github.com/sygmaprotocol/sygma-solidity/blob/main/docs/Home.md) for | ||
details on EVM implementation. | ||
![](/docs/resources/fees-diagram.png) | ||
|
||
#### Substrate | ||
### EVM | ||
|
||
Check out | ||
the [substrate pallet documentation](https://github.com/sygmaprotocol/sygma-substrate-pallets/blob/main/docs/Home.md) | ||
for details on Substrate implementation. | ||
Check out the [solidity documentation](https://github.com/sygmaprotocol/sygma-solidity/blob/master/docs/Home.md) for details on EVM implementation. | ||
|
||
### Substrate | ||
|
||
Check out the [substrate pallet documentation](https://github.com/sygmaprotocol/sygma-substrate-pallets/blob/master/docs/Home.md) for details on Substrate implementation. |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.