MinterGateway
Inherits: IMinterGateway, ContinuousIndexing, ERC712Extended
Author: M^0 Labs
Minting Gateway of M Token for all approved by TTG and activated minters.
State Variables
ONE
Descaler for variables in basis points. Effectively, 100% in basis points.
MAX_MINT_RATIO
Mint ratio cap. 650% in basis points.
MIN_UPDATE_COLLATERAL_INTERVAL
IMinterGateway
UPDATE_COLLATERAL_TYPEHASH
The EIP-712 typehash for the updateCollateral
method.
keccak256("UpdateCollateral(address minter,uint256 collateral,uint256[] retrievalIds,bytes32 metadataHash,uint256 timestamp)")
ttgRegistrar
The address of TTG Registrar contract.
ttgVault
The address of TTG Vault contract.
mToken
The address of M token
totalInactiveOwedM
The total owed M for all inactive minters.
principalOfTotalActiveOwedM
The principal of total owed M for all active minters.
_mintNonce
Nonce used to generate unique mint proposal IDs.
_retrievalNonce
Nonce used to generate unique retrieval proposal IDs.
_minterStates
The state of each minter, their collaterals, relevant timestamps, and total pending retrievals.
_mintProposals
The mint proposals of minter (mint ID, creation timestamp, destination, amount).
_rawOwedM
The owed M of active and inactive minters (principal of active, inactive).
_pendingCollateralRetrievals
The pending collateral retrievals of minter (retrieval ID, amount).
_lastSignatureTimestamp
The last update signature timestamp of each validator for each minter.
Functions
onlyActiveMinter
Only allow active minter to call function.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter to check. |
onlyApprovedValidator
Only allow approved validator in TTG to call function.
onlyUnfrozenMinter
Only allow unfrozen minter to call function.
constructor
Constructor.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the TTG Registrar contract. |
|
| The address of the M Token. |
updateCollateral
Updates collateral for minters
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| minTimestamp The minimum timestamp of all validators' signatures |
proposeRetrieval
Proposes retrieval of minter's off-chain collateral
Parameters
Name | Type | Description |
---|---|---|
|
|
Returns
Name | Type | Description |
---|---|---|
|
| retrievalId The unique id of created retrieval proposal |
proposeMint
Proposes minting of M tokens
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| mintId The unique id of created mint proposal |
mintM
Executes minting of M tokens
Parameters
Name | Type | Description |
---|---|---|
|
|
Returns
Name | Type | Description |
---|---|---|
|
| principalAmount The amount of principal of owed M minted. |
|
| amount The amount of M tokens minted. |
burnM
Burns M tokens
If amount to burn is greater than minter's owedM including penalties, burn all up to owedM.
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| principalAmount The amount of principal of owed M burned. |
|
| amount The amount of M tokens burned. |
burnM
Burns M tokens
If amount to burn is greater than minter's owedM including penalties, burn all up to owedM.
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| principalAmount The amount of principal of owed M burned. |
|
| amount The amount of M tokens burned. |
cancelMint
Cancels minting request for selected minter by validator
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
|
freezeMinter
Freezes minter
Parameters
Name | Type | Description |
---|---|---|
|
|
Returns
Name | Type | Description |
---|---|---|
|
| frozenUntil The timestamp until which minter is frozen |
activateMinter
Activate an approved minter.
MUST revert if minter
is not recorded as an approved minter in TTG Registrar.
Parameters
Name | Type | Description |
---|---|---|
|
|
deactivateMinter
Deactivates an active minter.
MUST revert if the minter is still approved.
Parameters
Name | Type | Description |
---|---|---|
|
|
Returns
Name | Type | Description |
---|---|---|
|
| inactiveOwedM The inactive owed M for the deactivated minter. |
updateIndex
Updates the latest index and latest accrual time in storage.
Returns
Name | Type | Description |
---|---|---|
|
| index The new stored index for computing present amounts from principal amounts. |
totalActiveOwedM
The total owed M for all active minters.
totalOwedM
The total owed M for all minters.
excessOwedM
The difference between total owed M and M token total supply.
minterRate
The last saved value of Minter rate.
isActiveMinter
Checks if minter was activated after approval by TTG
isDeactivatedMinter
Checks if minter was deactivated after removal by TTG
isFrozenMinter
Checks if minter was frozen by validator
principalOfActiveOwedMOf
The principal of active owed M of minter.
activeOwedMOf
The active owed M of minter.
maxAllowedActiveOwedMOf
The max allowed active owed M of minter taking into account collateral amount and retrieval proposals.
This is the only present value that requires a uint256
since it is the result of a multiplication between a uint240
and a value that has a max of 65,000
(the mint ratio).
inactiveOwedMOf
The inactive owed M of deactivated minter.
collateralOf
The collateral of a given minter.
collateralUpdateTimestampOf
The timestamp of the last collateral update of minter.
collateralPenaltyDeadlineOf
The timestamp after which an additional penalty for a missed update interval will be charged.
collateralExpiryTimestampOf
The timestamp after which the minter's collateral is assumed to be 0 due to a missed update.
penalizedUntilOf
The timestamp until which minter is already penalized for missed collateral updates.
latestProposedRetrievalTimestampOf
The timestamp when minter
created their latest retrieval proposal.
getLastSignatureTimestamp
Returns the last signature timestamp used by validator
to update collateral for minter
.
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| The last signature timestamp used. |
getUpdateCollateralDigest
Returns the EIP-712 digest for updateCollateral method.
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| |
|
| |
|
| |
|
|
mintProposalOf
The mint proposal of minters, only 1 active proposal per minter
pendingCollateralRetrievalOf
The amount of a pending retrieval request for an active minter.
totalPendingCollateralRetrievalOf
The total amount of pending retrieval requests for an active minter.
frozenUntilOf
The timestamp when minter becomes unfrozen after being frozen by validator.
isMinterApproved
Checks if minter was approved by TTG
isValidatorApproved
Checks if validator was approved by TTG
updateCollateralInterval
The interval that defines the required frequency of collateral updates.
updateCollateralValidatorThreshold
The number of signatures required for successful collateral update.
mintRatio
The allowed activeOwedM to collateral ratio.
mintDelay
The delay between mint proposal creation and its earliest execution.
mintTTL
The time while mint request can still be processed before it is considered expired.
minterFreezeTime
The freeze time for minter.
penaltyRate
The % that defines penalty amount for missed collateral updates or excessive owedM value
rateModel
The smart contract that defines the minter rate.
currentIndex
The current index that would be written to storage if updateIndex
is called.
_imposePenalty
Imposes penalty on an active minter. Calling this for an inactive minter will break accounting.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The principal of the base for penalization. |
Returns
Name | Type | Description |
---|---|---|
|
| The principal of the imposed penalty. |
_imposePenaltyIfMissedCollateralUpdates
Imposes penalty if minter missed collateral updates.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
_imposePenaltyIfUndercollateralized
Imposes penalty if minter is undercollateralized.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The timestamp of the collateral update. |
_repayForActiveMinter
Repays active minter's owed M.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The maximum principal amount of active owed M to repay. |
|
| The maximum amount of active owed M to repay. |
Returns
Name | Type | Description |
---|---|---|
|
| The principal amount of active owed M that was actually repaid. |
|
| The amount of active owed M that was actually repaid. |
_repayForDeactivatedMinter
Repays deactivated minter's owed M.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The maximum amount of inactive owed M to repay. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of inactive owed M that was actually repaid. |
_resolvePendingRetrievals
Resolves the collateral retrieval IDs and updates the total pending collateral retrieval amount.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The list of outstanding collateral retrieval IDs to resolve. |
Returns
Name | Type | Description |
---|---|---|
|
| The total amount of collateral retrieval resolved. |
_updateCollateral
Updates the collateral amount and update timestamp for the minter.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The amount of collateral. |
|
| The timestamp of the collateral update. |
_getMissedCollateralUpdateParameters
Returns the penalization base and the penalized until timestamp.
Parameters
Name | Type | Description |
---|---|---|
|
| The last timestamp at which the minter updated their collateral. |
|
| The timestamp before which the minter shouldn't be penalized for missed updates. |
|
| The update collateral interval. |
Returns
Name | Type | Description |
---|---|---|
|
| The number of missed update intervals. |
|
| The timestamp until which |
_getPresentAmount
Returns the present amount (rounded up) given the principal amount, using the current index. All present amounts are rounded up in favor of the protocol, since they are owed.
Parameters
Name | Type | Description |
---|---|---|
|
| The principal amount. |
Returns
Name | Type | Description |
---|---|---|
|
| The present amount. |
_getUpdateCollateralDigest
Returns the EIP-712 digest for updateCollateral method.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The amount of collateral. |
|
| The list of outstanding collateral retrieval IDs to resolve. |
|
| The hash of metadata of the collateral update, reserved for future informational use. |
|
| The timestamp of the collateral update. |
Returns
Name | Type | Description |
---|---|---|
|
| The EIP-712 digest. |
_rate
Returns the current rate from the rate model contract.
_revertIfFrozenMinter
Reverts if minter is frozen by validator.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter |
_revertIfInactiveMinter
Reverts if minter is inactive.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter |
_revertIfNotApprovedValidator
Reverts if validator is not approved.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the validator |
_revertIfUndercollateralized
Reverts if minter position will be undercollateralized after changes.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter |
|
| The amount of additional owed M the action will add to minter's position |
_verifyValidatorSignatures
Checks that enough valid unique signatures were provided.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The amount of collateral. |
|
| The list of outstanding collateral retrieval IDs to resolve. |
|
| The hash of metadata of the collateral update, reserved for future informational use. |
|
| The list of validators. |
|
| The list of validator timestamps for the collateral update signatures. |
|
| The list of signatures. |
Returns
Name | Type | Description |
---|---|---|
|
| The minimum timestamp across all valid timestamps with valid signatures. |
_verifyValidatorSignature
Checks that a signature is a valid validator signature.
Parameters
Name | Type | Description |
---|---|---|
|
| The address of the minter. |
|
| The amount of collateral. |
|
| The list of outstanding collateral retrieval IDs to resolve. |
|
| The hash of metadata of the collateral update, reserved for future informational use. |
|
| The address of a validator. |
|
| The timestamp for the collateral update signature. |
|
| The signature from the validator. |
Returns
Name | Type | Description |
---|---|---|
|
| Whether the signature is a valid validator signature or not. |
Structs
MintProposal
Mint proposal struct.
Properties
Name | Type | Description |
---|---|---|
|
| The unique ID of the mint proposal. |
|
| The timestamp at which the mint proposal was created. |
|
| The address to mint M to. |
|
| The amount of M to mint. |
MinterState
Minter state struct.
Properties
Name | Type | Description |
---|---|---|
|
| Whether the minter is active or not. |
|
| Whether the minter is deactivated or not. |
|
| The amount of collateral the minter has. |
|
| The total amount of pending retrievals. |
|
| The timestamp at which the minter last updated their collateral. |
|
| The timestamp until which the minter is penalized. |
|
| The timestamp until which the minter is frozen. |
|
| The timestamp at which the minter last proposed a retrieval. |