[Update 2022-03-17]
Alchemix v2 has launched, the devs snuck in the gALCX token! This is a wrapper for ALCX that automatically compounds ALCX rewards. This optimisation saves the individual from compounding, and should make staking much more accessible and sustainable for smaller users. As a result, the strategies identified below are no longer relevant to ALCX stakers! Hooray!
[Original Post]
The Alchemix Discord periodically receives questions regarding compounding an ALCX staking position. This has increased with the steady increase of the gas price in the network throughout 2021. This post exists in order to be a standard reference point for stakers looking for guidance in how to optimise their staking position. The post will be updated over time as things change, so please feel free to provide feedback.
Note that this guide covers manual staking directly in the Alchemix ALCX single staking pool. There are other options for generating a yield on ALCX tokens, including:
Introduction
ALCX staking rewards must be periodically claimed and re-deposited into the staking contract in order to compound the returns. Both the claim and deposit transactions consume gas, so the frequency with which to compound should factor in the amount being claimed and the gas price when claiming in order to maximise the effectiveness of compounding.
One strategy to minimise the gas expense of compounding is to manually adjust the gas price on claim and deposit transactions. This allows for the maximum gas expenditure to be limited to a known level, at the expense of a variable delay in processing the transaction.
For example, if the network gas price is over 100 gwei, a transaction can be submitted with a gas limit of 40 Gwei. This transaction would remain in pending state until the gas price falls to this level, at which point it would be a candidate for inclusion into the next block. If the gas price never falls back to 40, the transaction will remain in pending state indefinitely and may eventually be dropped by the network.
Advantages
This approach is a low-risk strategy that can help to achieve compounding of ALCX token rewards despite high peak gas prices.
Disadvantages
Pending transactions must be finalised in transaction nonce sequence, so any subsequent transactions submitted will be blocked until the claim or deposit transaction is finalised.
If the gas price limit on any pending transaction is unrealistically low, it may remain in the mempool for an excessive time period and could subsequently be dropped. This does not incur any gas.
Steps
0. Estimate gas consumption for compounding
As an input to this exercise, the anticipated gas usage is set at 225,000. This is a nice round number and is based on the worst-case gas limit values in @PhiMarHal's forum post A quick primer to Alchemix gas costs.
Claim: 97,000 gas
Deposit: 128,000 gas
Total: 225,000 gas
1. Identify the value of the currently accrued ALCX staking reward
Visit the ALCX Farms page and confirm the number of accrued ALCX staking rewards. Always confirm that the URL is correct to avoid being scammed:
https://app.alchemix.fi/farms
Determine the Ether valuation of the staking reward. The ratio can be sourced from CoinGecko or CoinMarketCap.
For example:
2.00 ALCX token rewards @ 0.10 ALCX/Ether => 0.2 Ether
Note also that the ratio may be subject to volatility, so check the ratio each time before compounding. Also, confirm that the various price feeds for the ALCX token are in agreement about the ratio of ALCX/Ether.
2. Identify the minimum viable transaction cost to support a 20x ratio of compound value amount to claim expense
A simple rule of thumb is to compound when the value of the claimed token reward exceeds the cumulative gas expense by at least 20x. Alternative compounding strategies are left up to the individual to evaluate.
Maximum Gas Price = 0.2 / (20 * 225,000)
= 0.0000000444... Ether
= ~ 44 Gwei
Therefore, it is recommended to compound at a gas price of at most 44 Gwei given the example ALCX staking reward and ALCX/Ether ratio. The Eth Gas Satation calculator may be also be useful here.
3. Determine whether it is advantageous to compound
Check the minimum viable gas price against recent gas price averages. If the minimum viable gas price has not been observed in the network recently, then compounding is currently not feasible. In this case, defer compounding until gas prices fall, or the ALCX/Ether ratio increases.
Various sites provide historical price averages, for example ethereumprice.org.
If the network has recent blocks with a gas price in the vicinity of the calculated maximum gas then it may be worthwhile to compound. In this case, proceed to the next step. Otherwise, defer compounding and accrue more staking rewards before proceeding again from step 0.
4. When it is time to compound, generate a new transaction via the Alchemix Farms page
The action should be either a claim or deposit transaction, depending on the stage of compounding. Again, always confirm that the URL is correct:
https://app.alchemix.fi/farms
DeFi Dad provides a good example of how to select and control the Priority and Maximum fees in MetaMask.
5. Monitor the transaction on Etherscan and await confirmation
If the transaction is a claim, restart from step #1 to initiate a deposit transaction as soon as the claim transaction has been confirmed. Note that the claim call harvests all available ALCX token rewards, so the time until next claim should be determined based on the time that the current claim transaction was confirmed, as well as any other changes to the staking balance and/or token price.
In the event that a transaction remains in pending state for an extended period of time, or in case another transaction is urgently needed, it may be necessary to cancel or replace it. This can be achieved by generating the new transaction and reusing the same nonce as was included in the existing pending transaction. The nonce of the existing can be seen in MetaMask by selecting the existing transaction, or by looking at the transaction details in Etherscan.
MetaMask have a guide for controlling the nonce for each new transaction.
Additional details
Ethereum Gas Fee Composition
Since EIP-1559 in August 2021, Maximum Fee paid in gas for transactions on the Ethereum network consists of a Base Fee and a Priority Fee. The Base Fee is burned by the network, and the Priority Fee is awarded to the miner of the block in which the transaction is included.
Users transacting on the network have the option of setting both the Maximum fee allowable, as well as the Priority Fee awarded to the miner. The maximum accepted Base Fee is then calculated as follows:
Base Fee = Maximum Fee - Priority Fee
The actual Base Fee paid is not determined until the transaction is confirmed on the network and is a function of broader network demand for block space at time the block is mined. Therefore, setting a high Maximum Fee establishes the upper bound for the gas cost of the transaction, but the actual fee paid may be lower than this if demand for block space is lower at the time the transaction is processed.
A more detailed explanation is available from blocknative.