Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRC-4; Flash Mint Standard #7

Open
SwayStar123 opened this issue May 16, 2023 · 1 comment
Open

SRC-4; Flash Mint Standard #7

SwayStar123 opened this issue May 16, 2023 · 1 comment
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

Comments

@SwayStar123
Copy link
Member

SwayStar123 commented May 16, 2023

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 forwarding gas_required gas and amount coins.

The target ContractId MUST implement the FlashBorrower 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 minting amount of coins

fn 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

enum FlashLoanError {
    // The loan was not repaid. The missing amount is logged
    LoanNotRepaid: u64,
}

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

@bitzoic bitzoic changed the title SRC-4 SRC-4; Flash Mint Standard May 17, 2023
@bitzoic bitzoic added Draft This standard is currently in draft. Experimentation and feedback is encouraged. SRC 4 Label used to filter for the standard issue labels May 17, 2023
@dmihal
Copy link
Contributor

dmihal commented Sep 5, 2023

Standard is ready for review, but we can't make a proper implementation without serialization, so tabling this for now

@bitzoic bitzoic added the New Standard Label used to filter for the introduction of a new standard label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants