VRC25 Specification

VRC25 is the official standard for fungible tokens in Viction ecosystem.

Abstract

The following standard allows for the implementation of a standard API for tokens within smart contracts. This standard provides basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party. This standard also defines how fee should be managed to prevent abuse of the feature.

Motivation

For EVM-based blockchain, ERC20 has became the standard for fungible tokens. This standard works perfectly and had been proven for a long time. However, due to the way smart-contract works in blockchain, it's somewhat difficult for new users to understand, especially web2 users.

VRC25 is developed in effort to simplify the way a token works by eliminate the need of gas when using the token. It means that users won't need to keep native token when they transfer, approve or any other actions available on the token. Instead the fee for the network can be paid by the token itself.

Specification

interface IVRC25 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Fee(address indexed from, address indexed to, address indexed issuer, uint256 value);

    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint256);
    function balanceOf(address owner) external view returns (uint256);
    function issuer() external view returns (address);
    function allowance(address owner, address spender) external view returns (uint256);
    function estimateFee(uint256 value) external view returns (uint256);
    function transfer(address recipient, uint256 value) external returns (bool);
    function approve(address spender, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external  returns (bool);
}

Source: IVRC25.sol

Source: IVRC25Permit.sol

For protocol contract, IVRC25 is enough.

For token contract, IVRC25 and IVRC25Permit must be satisfied to be fully compatible with gas-less protocol on Viction.

Methods

  • decimals: Return the decimals of the token.

  • totalSupply: Returns the token total supply.

  • balanceOf: Returns the account balance of another account with address owner.

  • allowance

Returns the amount which spender is still allowed to withdraw from owner.

  • issuer: Returns the address of the token issuer.

The method returns the address of the token issuer. This is to ensure that only the issuer has the right to decide in regard to paying fees of token-holder transactions to the token contract in terms of the token itself. The method is to verify that no one else is able to change the token contract, except the issuer.

  • estimateFee: Calculate the transaction fee in terms of the token that the transaction makers will have to pay. Transaction fee will be paid to the issuer of the VRC25 token contract.

Ideally, the function will return the transaction fee based on the value (the number of tokens) that the transaction maker wants to transfer. Transaction fee for allowance the function will be estimated if the input parameter value = 0. The way fees are computed is not standardized. Token issuers can fully customize the implementation of the function.

This function will also be called by user wallets to evaluate fees the user must pay.

  • transfer: Transfers value amount of tokens to address recipient, and MUST fire the Transfer and Fee event.

The function will call estimateFee function to compute the transaction fee. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend and to pay transaction fees. Once succeeded, the token balance of the sender should be reduced by value plus the computed transaction fee, the balance of recipient should be increasing value, while the balance of the token issuer should be increased by the computed transaction fee.

  • approve

Allows spender to withdraw from your account multiple times, up to the value amount. If this function is called again it overwrites the current allowance with value. This function also calls estimateFee with input parameter 0 in order to compute the transaction fee in terms of tokens that the transaction sender must pay to the token issuer.

  • transferFrom

Transfers value amount of tokens from the address from to the address to. The function must fire the Transfer and Fee events.

  • nonces

Returns unused nonce for specified owner. Signature with nonce different that this value is invalid thus cannot be used.

  • permit

This is the same as approve function with the different that caller is not necessary the owner. Instead, the caller must provide a valid signature signed by the owner.

Events

  • Transfer

This event MUST be emitted when tokens are transferred in functions transfer and transferFrom.

  • Approval

This event MUST be emitted on any successful call to approve function.

  • Fee

This event MUST be emitted when tokens are transferred in functions transfer and transferFrom in order for clients/DApp/third-party wallets to notify their users about the paid transaction fee in terms of tokens.

Requirement

For a contract to meet VRC25 requirements, it must satisfy the following conditions:

  • The contract should be VRC25Upgradable contract in order to use through proxy.

  • Implement IVRC25 interface in the specification.

  • Have 3 first storage slots in the contracts as follow:

  • Implement Permit extension, as defined in EIP-2612. Permit acts as a fallback for any gas-less protocol to support your token properly, in the case that your token isn't registered for [VIC ZeroGas](../integration/VIC ZeroGas-integration.md).

Implementation

To implement the VRC25 standard, the following fields must be put at the beginning of the smart contract.

This standard will need some basic information to track and

  • _balances: record the balance of each token holder

  • _minFee: the minimum fee in terms of tokens that the transaction sender must pay. Ideally, minFee will be paid when the approve function is called or when the transaction fails.

  • _owner: the address of the token issuer who will receive transaction fees from token holders in terms of the token, but will pay transaction fees to masternodes by means of VIC.

The implementation also defines some additional functions as follows:

  • issuer: Returns the address of the issuer of the token.

  • minFee: Returns the minimum fee for any transaction.

Source: VRC25.sol

Source: VRC25Permit.sol

Example

The following example demonstrates a token using the VRC25 standard with a custom fee.

The easiest way to implement VRC25 specification is to let first inheritance of your contract to be VRC25 or VRC25Permit.

Source: SampleVRC25.sol

Enable gas-less transaction

Once you have deployed a VRC25 compatible contract. You will also need to register for VIC ZeroGas to enable gas-less transaction for your contract. Please refer to VIC ZeroGas page for more information.

Last updated