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.
- 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.
- Execute deposit
- Send the appropriate amount based on the calculated final fee when executing the deposit.
Fee strategy defines a set of rules on how fees should be charged when executing deposits on the source chain.
Supported on: EVM | Fee can be paid in: Native asset
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.
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
-
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
Based on route type, there are two concrete implementations of dynamic fees fee handlers:
-
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)
- Parameter
-
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.
- Parameter
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.
Supported on: EVM, Substrate | Fee can be paid in: Native asset
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.
Supported on: EVM, Substrate | Fee can be paid in: Transferred asset
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.
On the diagram below, we use Sygma SDK for interaction with all services.
Check out the solidity documentation for details on EVM implementation.
Check out the substrate pallet documentation for details on Substrate implementation.