Skip to content

tqtezos/stablecoin

Repository files navigation

⚠️ Note: Morley framework and set of tools are no longer maintained since the activation of protocol "Nairobi" on the Tezos mainnet (June 24th, 2023).

This smart contract is no longer be actively developed since then, but future bugs or security issues will be addressed.

Tezos Stablecoin

Build status

Tezos Stablecoin project implements an FA2-compatible token smart contract. It draws inspiration from popular permissioned asset contracts like CENTRE Fiat Token and other similar contracts. The contract is implemented in the LIGO language. This repository consists of the following:

  1. LIGO source code of the Stablecoin smart contract and auxiliary smart contracts in the ligo/ folder.
  2. Contract specification.
  3. Haskell bindings with data types corresponding to Stablecoin. It is based on the morley framework. It allows us to use features of morley (such as a testing engine called cleveland) with this contract.
  4. stablecoin-client executable that allows deploying and interacting with the Stablecoin smart contract.

Please refer to the haskell/ directory for details regarding stablecoin-client and Haskell bindings.

The project also includes an alternative FA1.2-compatible smart contract, available in the ligo/stablecoin/fa1.2/ folder.

How to get

You can download Michelson source code of all provided smart contracts in release assets. We also provide a static stablecoin-client executable that should work on any x86_64 Linux system. If you are using a different OS or just want to build from sources, see instructions below.

Usage

The recommended way to deploy and interact with Stablecoin is to use stablecoin-client. For example, in order to deploy the contract you can run

./stablecoin-client --user foo deploy --master-minter foo --contract-owner foo --pauser foo --default-expiry 300000

provided you have tezos-client in your $PATH, it's configured to use an appropriate node and knows foo address with sufficient balance to pay for operations.

Build instructions

Tests

Tests are implemented in Haskell. Please refer to the haskell/ directory for details.

Gas / Transaction costs

The tables below show the gas and transaction costs of both versions (FA1.2 and FA2) of the stablecoin contract v1.7.4 in kathmandunet.

kathmandunet

FA1.2 Gas cost FA2 Gas cost FA1.2 Tx cost FA2 Tx cost
origination 7,131 7,052 2.381438 ꜩ 2.414563 ꜩ
transfer 8,047 8,246 0.00114 ꜩ 0.001177 ꜩ

Measuring

To measure and collect these numbers:

  1. Pick a testnet:

    export STABLECOIN_TESTNET=https://kathmandu.testnet.tezos.serokell.team/
    
  2. Create a test account and grab its hash:

    $ tezos-client gen keys stablecoin-moneybag --force
    $ tezos-client -E $STABLECOIN_TESTNET show address stablecoin-moneybag
    Hash: tz1Shin6pHETKn7EroLGyG2afTenW2zT2K6w
    Public Key: edpktpFQUaRZRHPMBgk66W4jQoYK2hzZ95o9ZJrPmH38zqSzfH5Zor
    
  3. Use a testnet faucet to add funds to your account.

  4. Run:

    cd haskell
    stack test --fast --test-arguments \
        "-p \"Lorentz.Contracts.Nettest.FA1_2Comparison\" \
        --cleveland-mode only-network \
        --cleveland-moneybag-alias stablecoin-moneybag \
        -E $STABLECOIN_TESTNET"

    This deploys the FA2 and FA1.2 contracts (the TZIP-16 metadata will be stored in separate contracts), and calls the transfer entrypoint of each contract.

  5. The logs should show these two messages, with two addresses:

    Originated smart contract 'Stablecoin FA1.2' with address <...>
    Originated smart contract 'Stablecoin FA2' with address <...>
    
  6. Search for these addresses in https://better-call.dev/, select the "Contracts" tab, you should get 1 search result. Select it to see the origination and transfer costs.

Note that we also run these tests nightly as part of our CI, so another way to do this measurement is to wait for CI to run these tests and find 2 addresses in the logs of the latest scheduled CI run.

Issue Tracker

We use GitHub issues. Feel free to open a new one.

License

MIT