Rebalancing
Rebalancing enables tokens swap back to STRK & relayers refunding
Context
Once your paymaster instance is running, your relayers are spending STRK tokens to pay for transaction while your GasTanker is accumulating users tokens. After a while, you could be out of STRK on your relayers to pay for transaction.
To avoid being out of gas token, the rebalancing process will trigger 2 actions when needed:
- Swapping each token listed in
supported-tokens
to STRK - Refill each relayers homogeneously with the resulting STRK balance
Trigger
Rebalancing can be triggered in two ways:
- Manually using the CLI command
- Automatically
Automatic rebalancing is activated as soon as the configuration is set, and can be configured with 3 properties:
- The minimum balance in STRK before triggering the rebalance process
- The interval of time between 2 checks
Swap
The swap process consist of swapping the GasTanker balance of all supported tokens back to STRK. This process is triggered 2 times:
- Periodically
- To smooth the price impact of selling
- To avoid being out of STRK if a refill is needed
- At every triggering of the refilling process
- To be sure to refill the max we can at once
NoteSome FRI could be left in GasTanker after this process because of price variation, they will be used in next refilling round
Swap params
You can configure the swap to avoid loosing money when rebalancing, this include:
- Max price impact
- Slippage
If the condition of one of this 2 params is not met, the swap is aborted for the concerned pair.
Swap provider
You can define the swap provider you want to use for the swap process, currently supported providers:
AVNU
- Mainnet: starknet.api.avnu.fi
- Sepolia: sepolia.api.avnu.fi
Refill
Once the rebalancing as been triggered by a low balance relayer (balance < min-relayer-balance
), the STRK balance resulted from the Swap is distributed among all the relayers to have the most homogeneous balances at the end of the process. For example, a relayers can be omitted from some rebalancing.
The refill is bundled as a multicall composed of transfers from the GasTanker to the relayers.
Rebalancing properties
The rebalancing configuration is optional, it means that if you omit it you'll have to trigger the rebalancing manually.
Prop | Type | Description |
---|---|---|
relayers.rebalancing.check_interval | number | Time interval between 2 epochs of rebalancing check |
relayers.rebalancing.min_relayer_balance | string(FRI) | Min balance of at least 1 relayer to trigger the rebalancing. In FRI |
relayers.rebalancing.swap_config.swap_interval | number | Time interval between 2 epochs of swap. Must be < relayers.rebalancing.check_interval to reduce price impact over time |
relayers.rebalancing.swap_config.max_price_impact | number | Max acceptable price impact between buy and sell USD values for the swap - should be between 0 and 1 inclusive |
relayers.rebalancing.swap_config.slippage | number | Max acceptable slippage for the swap |
relayers.rebalancing.swap_config..min_usd_sell_amount | number | Minimum amount to sell for a swap to be executed |
relayers.rebalancing.swap_config.swap_client.provider | string | Name of the supported provider to use |
relayers.rebalancing.swap_config.swap_client.endpoint | string | RPC endpoint for swap service being used |
relayers.rebalancing.swap_config.swap_client.chain_id | "sepolia"| "mainnet" | Starknet chain identifier |
Example
{
"relayers": {
// ... other relayer properties
"rebalancing": {
"check_interval": 2,
"trigger_balance": "0x1BC16D674EC80000",// 2 strk
"swap_config": {
"swap_interval": 10,
"max_price_impact": 0.08,
"slippage": 0.05,
"min_usd_sell_amount": 1,
"swap_client_config": {
"provider": "avnu",
"endpoint": "https://sepolia.api.avnu.fi",
"chain_id": "sepolia"
}
}
}
// ... other relayer properties
},
}
Updated 11 days ago