Gate Module
Adapters for collateral tokens
The Gate module acts as an adapter and custodian for collateral tokens. When users deposit collateral into a trove, the underlying collateral token is sent to the Gate module. Each collateral token will have its own Gate module.
As the Gate is an internal-facing module, users will not be able to, and are not expected to, interact with the Gate directly.
Description of key functions
enter
: transfers a specified amount of the collateral token from the user to the Gate, and returns the corresponding amount ofyang
.exit
: transfers an amount of the collateral token corresponding to the specified amount ofyang
from the Gate to the user, and returns the corresponding amount of assets.
Conversion of assets to and from `yang`
The Gate module does not enforce a fixed conversion rate from the underlying collateral token to yang
and vice versa. Instead, the conversion rate is calculated based on the total yang
amount in Shrine and the collateral token balance of the Gate module at the time of the transaction. This is intentional so that redistributions of collateral in the Shrine can be efficiently performed via rebasing i.e. the amount of underlying collateral token corresponding to per unit of yang
increases.
A consequence of this design is that it exposes the Gate module to the first depositor front-running vulnerability that is known to afflict ERC-4626. The conventional approach to defend against this exploit is to deduct a small amount of shares from the first depositor and mint it to the zero address so that this amount is non-withdrawable but is accounted for in the total supply when calculating the conversion rate.
In the case of Opus, we mitigate against this vulnerability by requiring a small amount of collateral token (and consequently the yang
representing this amount) to be donated to the Shrine upon adding the collateral as a yang
in Shrine via the Sentinel module. This lets Opus bear the burden of the initial deposit instead of the first depositor.
Rounding
Both enter
and exit
performs rounding down by default in favour of the protocol.
When depositing collateral tokens for
yang
, the amount ofyang
is rounded down.When withdrawing
yang
for collateral tokens, the amount of collateral tokens is rounded down.
Properties
These are some properties of the Gate module that should hold true at all times:
The conversion rate of a
yang
to its underlying collateral asset is monotonic while the Shrine is live, meaning it never decreases in value.The conversion rate of a
yang
to its underlying collateral asset should remain unchanged in bothenter
(if there is non-zero amount of the collateral asset beforeenter
) andexit
(if there is non-zero amount of the collateral asset afterexit
)
Last updated