Giter Site home page Giter Site logo

ton-dynasty / tondynasty-contracts Goto Github PK

View Code? Open in Web Editor NEW
79.0 1.0 13.0 482 KB

Ton-Dynasty Contracts is a library for efficient smart contract development by tact-lang

Home Page: https://ton-dynasty.github.io/docs.contracts/

TypeScript 99.00% Shell 1.00%
tact ton jetton nft contracts template

tondynasty-contracts's Introduction

Ton-Dynasty Contracts

Telegram

Ton Dynasty Contract developed by Perman Lab is a library for efficient smart contract development by tact-lang.

  • Implementations of standards like TEP-0062, TEP-0074
  • Reusable traits for common contract types like Lockable, Estimatible, etc.
  • Provide series of template for ton developers to utilize.
  • Perman Lab will always stand by you. Ask for our help in Perman Lab Community.

Overview

Installation

Warning

Now we are in the early stage of development. The library is not ready for production use.

Important

Currently, Tact does not support importing from node modules. So you need to copy the source code of the library to your project. We will fix this issue in the future.

git clone https://github.com/Ton-Dynasty/tondynasty-contracts.git

Usage

Once you leverage our library, you can build contracts efficiently.

Example Jetton Contract

import "@stdlib/deploy";
import "./packages/token/jetton/JettonMaster";
import "./packages/token/jetton/JettonWallet";

contract ExampleJettonWallet with JettonWallet {
    balance: Int as coins = 0;
    owner: Address;
    jetton_master: Address;

    init(owner: Address, jetton_master: Address) {
        self.owner = owner;
        self.jetton_master = jetton_master;
    }

    override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit {
        return initOf ExampleJettonWallet(owner_address, self.jetton_master);
    }
}

contract ExampleJettonMaster with JettonMaster, Deployable {
    total_supply: Int as coins = 0;
    mintable: Bool = true;
    owner: Address;
    jetton_content: Cell;

    init(owner: Address, jetton_content: Cell){
        self.owner = owner;
        self.jetton_content = jetton_content;
    }

    receive("Mint:1") {
        let ctx: Context = context();
        let msg: JettonMint = JettonMint{
            origin: ctx.sender,
            receiver: ctx.sender,
            amount: ton("1"),
            custom_payload: emptyCell(),
            forward_ton_amount: 0,
            forward_payload: emptySlice()
        };
        self._mint_validate(ctx, msg);
        self._mint(ctx, msg);
    }

    override inline fun _mint_validate(ctx: Context, msg: JettonMint) {
        require(self.mintable, "JettonMaster: Jetton is not mintable");
    }

    override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit {
        return initOf ExampleJettonWallet(owner_address, myAddress());
    }
}

The above code is an example of a jetton contract. You can view Jetton as ERC20 token contract but on TON.

Development Guide

Project structure

  • contracts - source code of all the smart contracts of the project and their dependencies.
  • wrappers - wrapper classes (implementing Contract from ton-core) for the contracts, including any [de]serialization primitives and compilation functions.
  • tests - tests for the contracts.
  • scripts - scripts used by the project, mainly the deployment scripts.

How to use

Build

yarn build

Test

yarn test

Deploy or run another script

yarn start

Star History

Star History Chart

tondynasty-contracts's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tondynasty-contracts's Issues

Feature - uint56 floating point encode and decode with funC

Implement floating point encoding and decoding by uint56. The first 50 digits is floating point part, whereas the remaining 6 digits used to represent the exponent of 16. The example in solidity would be like:

    function _encodeFloat(uint value) private pure returns (uint56) {
        uint exponent = 0; 
        while (value > 0x3FFFFFFFFFFFF) {
            value >>= 4;
            ++exponent;
        }
        return uint56((value << 6) | exponent);
    }

    function _decodeFloat(uint56 floatValue) private pure returns (uint) {
        return (uint(floatValue) >> 6) << ((uint(floatValue) & 0x3F) << 2);
    }

This utility requires to be written in funC within extlib.fc

Feature - Upgradable trait

Disclaimer: Hi guys, I'm relative new to TON ecosystem but AFAIK there's no standardized approach for upgradable contracts in Tact.

Motivation

Motivation for this issue is to discuss some approaches for making contract upgrades here because tondynasty is relatively popular and it will be easier to find this information for newcomers.

Solution

A couple weeks ago @wedvjin created proof of concept repo.
Using his example and tondynasty's traits approach I've created a basic Upgradable trait:

@name(set_code)
native setCode(code: Cell);

@name(set_data)
native setData(d: Cell);

message UpgradeContract {
  code: Cell;
  data: Cell?;
}

trait Upgradable {
  owner: Address;

  // @dev  Upgrade
  receive(msg: UpgradeContract) {
    let ctx: Context = context();
    self._upgrade_validate(ctx, msg);
    self._upgrade(ctx, msg);
  }

  // @dev  _upgrade_validate conduct some custom validating before upgrade
  virtual inline fun _upgrade_validate(ctx: Context, msg: UpgradeContract) {
    require(ctx.sender == self.owner, "Upgradable: Sender is not a contract owner");
  }

  // @dev  _upgrade
  virtual inline fun _upgrade(ctx: Context, msg: UpgradeContract) {
    setCode(msg.code);
    if (msg.data != null) {
      setData(msg.data)
    }
  }
}

Limitations

https://github.com/wedvjin/ton-tact-contract-upgrade?tab=readme-ov-file#issue

@alan890104 @howardpen9 please take a look, maybe you have some different approaches for this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.