SRC-4; Flash Mint Standard #7
Labels
Draft
This standard is currently in draft. Experimentation and feedback is encouraged.
New Standard
Label used to filter for the introduction of a new standard
SRC 4
Label used to filter for the standard issue
Abstract
The following standard allows for the implementation of a standard API for flash mints for native-assets using the Sway language. This standard is an optional add-on to the SRC-20 standard.
Motivation
Flash mints allow anyone to temporarily mint out a large number of tokens and use them for any purpose with the requirement that they be returned within the same transaction. This pattern is highly useful and would greatly benefit from standardisation
Prior Art
Flash mints have been thoroughly explored on Ethereum and with EIP 3156 they have their own standard for it. However as Fuel's native assets are fundamentally different to Ethereum's ERC-20 tokens, the implementation will differ, but the interface may be used as reference.
Specification
Required public functions
The following functions MUST be implemented (on top of the SRC-20 functions) to follow the SRC-4 standard
fn flash_mint(amount: u64, target: ContractId, calldata: Vec<u8>, gas_required: u64)
Calls the
target
ContractId forwardinggas_required
gas andamount
coins.The
target
ContractId MUST implement theFlashBorrower
abi.The contract balance for the asset_id being minted MUST be greater than or equal to the balance prior to calling the
target
Contract + the flash fee to be charged for flash mintingamount
of coinsfn flash_fee(amount: u64)
Read only function that returns the fee that would be charged for a flashloan of the given amount
The parameters of the function may change depending on the implementation of native multi tokens on Fuel.
Required logs
The following logs MUST be emitted at the specified occasions
The
LoanNotRepaid
variant of this enum must be logged in the event that the entire expected amount is not repaid to the contract. The amount remaining to be paid must be the value associated.Rationale
The ABI discussed is simple and covers the known use cases of flash mints while allowing safe implementations
Backwards compatibility
This standard is fully compatible with the SRC-20 standard
Security Considerations
Incorrect implementation of flashmints could allow attackers to gain very large number of tokens. It is recommended to properly audit any code using this standard to ensure exploits are not possible.
Reference implementation
Full reference implementation can be seen here
This is a draft standard
The text was updated successfully, but these errors were encountered: