Thanks to visit codestin.com
Credit goes to github.com

Skip to content
forked from tact-lang/jetton

Work-in-progress: Jetton implementation in Tact compatible with TEP-74 (do not use in production yet)

License

Notifications You must be signed in to change notification settings

arghaffari/jetton

 
 

Repository files navigation

Jetton (Fungible Token) Implementation in Tact

Work in Progress

This will definitely be a stable version of Jettons, but not for now. Please, do not use this code in production. It might have some bugs.

Overview

This project includes a complete setup for working with Tact-based Jetton smart contracts. It provides:

  • A pre-configured Tact compiler.
  • Smart contracts written in the Tact language.
  • TypeScript + Jest testing environment with @ton/sandbox.

Goals

This implementation is fully compatible with the following TON standards:

You can use this implementation as an alternative to the reference Jetton contracts available in the TON Blockchain repository.

Improvements and additional features

This implementation also includes new features, that will allow developers and users on TON to easier integrate and work with Jettons in their applications

Balance on-chain API

This additional receiver provides functionality similar to TEP-89, but with wallet balance. You can request and then receive balance from any Jetton wallet with possible additional info for transaction verification

Transaction scheme

sequenceDiagram
    participant D as Any Account
    participant C as Jetton Wallet

    D ->>+ C: ProvideWalletBalance<BR />(0x7ac8d559)
    C ->>+ D: TakeWalletBalance<BR />(0xca77fdc2)
Loading

TLB

provide_wallet_balance#7ac8d559 receiver:MsgAddress include_verify_info:Bool = InternalMsgBody;

verify_info$_ owner:MsgAddress minter:MsgAddress code:^Cell = VerifyInfo;
take_wallet_balance#ca77fdc2 balance:Coins verify_info:(Maybe VerifyInfo) = InternalMsgBody;

Claim TON from Jetton Wallet/Minter

These receivers both on Jetton Wallet and Jetton Minter allow to claim stale TON coins from contracts, leaving just enough balance for them to not freeze and function properly. Message body includes receiver field, that allows to specify funds receiver

Transaction scheme

sequenceDiagram
    participant D as Owner
    participant C as Jetton Wallet/Minter
    participant F as msg.receiver

    D ->>+ C: ClaimTON<BR />(0x0393b1ce)
    C ->>+ F: TON's<BR />(empty body)
Loading

TLB

claim_ton#0393b1ce receiver:MsgAddress = InternalMsgBody;

Getting Started

1. Install Dependencies

Run the following command to install all required dependencies:

yarn install

2. Build Contracts

Compile the smart contracts with:

yarn build

3. Deploy Contracts

Customize your Jetton by editing the contract.deploy.ts file. This file also includes a detailed deployment guide. Deploy the contracts with:

yarn deploy

4. Deployment Verification

To verify that your Jetton contract was deployed correctly, you can use the built-in verification test:

Run the verification test:

yarn verify-deployment

This verification test will check:

  • If the contract is active
  • If the contract parameters match what you specified
  • If the contract metadata is correctly set up

5. Test Contracts

Run tests in the @ton/sandbox environment:

yarn test

Jetton Architecture

If you're new to Jettons, read the TON Jettons Processing.

Project Structure

Smart contracts, their tests, and the deployment script are located in the src directory:

src/
│
│   # Contracts and auxiliary Tact code
├── contracts/
│   ├── jetton-minter.tact
│   ├── jetton-wallet.tact
│   ├── messages.tact
│   └── constants.tact
│
│   # Tests
├── tests/
│   └── jetton.spec.ts
│
│   # Deployment script
├── scripts/
│   ├── contract.deploy.ts
│   └── contract.read.ts
│
│   # Miscellaneous utility things
└── utils/

Note that tests and the deployment script require the compiled contracts to be present in the src/output directory.

The configuration for the Tact compiler is in tact.config.json in the root of the repository. In most cases, you won't need to change this file.

Smart Contracts Structure

The main smart contract is jetton_minter.tact, it imports messages.tact and jetton_wallet.tact. With the default configuration of tact.config.json targeting jetton_minter.tact, they're all compiled automatically.

Inherited traits

Jetton Minter uses only OwnableTransferable, which is inherited from the Ownable trait. Jetton Wallet only uses the Ownable trait. All these traits come from the Tact's standard libraries.

Schemes of inheritance and imports:

graph LR
    B[jetton_minter.tact] -->|import| A[messages.tact]
    C[jetton_wallet.tact] -->|import| A[messages.tact]
    B[jetton_minter.tact] -->|import| C[jetton_wallet.tact]

    C[jetton_wallet.tact] -->|uses| E[ownable]
    B[jetton_minter.tact] -->|uses| F[ownableTransferable]
    F[ownableTransferable] -->|inherits| E[ownable]

    class E,F ownableStyle;

    classDef ownableStyle stroke-width:2,rx:25,ry:25;

Loading

Read more about those traits in the Tact standard library.

Best Practices

License

This project is licensed under the MIT License.

About

Work-in-progress: Jetton implementation in Tact compatible with TEP-74 (do not use in production yet)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 88.0%
  • Tact 9.0%
  • JavaScript 2.9%
  • Shell 0.1%