Deep Dive: Ampleforth Rebase
This article was written to hopefully answer two questions brought up by a publish0x community member, Tomatosoup. Both questions pertain to the aspect of the rebase function in Ampleforth's protocol.
1. How the Ampleforth protocol 'removes' Ample tokens from a wallet without a transaction being authorized by a private key?
2. How the gas fees for the addition or removal of Ample from a wallet get paid?
How does Ampleforth protocol 'remove' Ample tokens from a wallet without a transaction being authorized by a private key?
To begin, we have to start with the explaining of what amples are. First, the protocol is a system of three smart contracts, the Ampleforth ERC-20 Contract, Market Oracle Contract and the Monetary Policy Contract.
Image from Ampleforth an Ideal Money
As mentioned above, one of the three smart contracts is the Ampleforth ERC-20 Contract. Ampleforth's ERC-20 contract is different in that it has an additional function called rebase(uint256 epoch, int256 supplyDelta) and overwrites several public interfaces. The rebase function instructs the token contract to add or remove tokens from the total supply. Rebase is only callable by the Monetary Policy Contract. Any user can call the rebase function once every 24 hrs., making the protocol less reliant on the devs and more decentralized. The rebase function when called queries the Market Oracle for price, adds a "rebase reaction lag" and then adjust total token supply accordingly(expand or contract, if necessary). Rebase reaction lag is a dampening system to smooth token price fluctuations.
Because of Ample's ERC-20 contract adding rebase it can change token parameters, by adjusting total supply of ample token the protocol doesn't need access to your wallet per se. Since total supply is adjusted it returns to how and why a wallets balance is calculated based on you actual percentage holding and not how many units.
How do the gas fees for the addition or removal of Ample from a wallet get paid?
Except for the person calling the rebase function no gas would be needed, so gas is being paid. This is accomplished because of a little magic on Ampleforth's side.
"To execute this process efficiently, we avoid generating a transaction for each wallet. Instead, Ampleforth balances are internally represented by a hidden internal denomination. All external interfaces to the system reference the external denomination, while all internal operations reference the hidden internal denomination."
"The conversion rate between the hidden internal denomination and the external denomination is controlled
by an exchange rate that equals hiddenSupply/uFragmentSupply. This rate, sometimes referred to
as the splitRatio, is represented rationally as the quotient of two numbers in the codebase."
What it breaks down to is there are two numbers are really at work to what we see. The best analogy that I could think of is a typical crypto price feed website. When you log-in the price of eth is reflected at $500. That price is only accurate the moment you logged in as the market is constantly moving the real price. After staring at your screen for 5 minutes nothing has changed, eth is still $500. Then, you decide to hit refresh after tirelessly waiting for the price to change and now it shows eth at $505. During those 5 minutes the real price of eth was actively moving because of the markets. Only by hitting refresh were you able to call the current price. Essentially, the rebase function is the refresh button for what we see. The movement is never drastic due to dampening. This is all accomplished because the rebase function changes total supply meaning when that single person calls the rebase function whether devs or you, all wallets are affected.
Reference: Ampleforth- An Ideal Money (2018)
Evan Kuo and Brandon Iles