Skip to content

Commit

Permalink
func 0.2.0 / readme / onchain data multicell support (ton-blockchain#12)
Browse files Browse the repository at this point in the history
* build works

* in prog

* in prog

* in prog

* tests pass

* lib removal in prog

* lib removal in prog

* deploy in prog

* -

* axios in prog

* fix tests

* tests + deploy pass

* readme

* -
  • Loading branch information
shaharyakir authored Jun 16, 2022
1 parent 1f6f992 commit fd5e8ef
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 1,210 deletions.
87 changes: 15 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,24 @@
# Jetton deployer
# Jetton deployer contracts

> A library for deploying [Jettons](https://github.com/ton-blockchain/TIPs/issues/74) on the [Ton blockchain](https://ton.org/)
## How to use
A library for building and deploying [Jettons](https://github.com/ton-blockchain/TIPs/issues/74) on the [Ton blockchain](https://ton.org/)

> Note: This library is in alpha. Use at your own risk.
1. Instantiate a `JettonDeployController`

```
const dep = new JettonDeployController();
```

2. Connect a wallet provider

The provider is responsible for sending the transcations necessary for creating the jetton contract.

Current supported wallet providers are:

- Tonhub (via [ton-x](https://github.com/ton-foundation/ton-x) connector)
- Ton wallet chrome extension
- Mnemonic-based provider

Further providers can be added (PRs are welcome).

Example:

```
const tonHubCon = new TonConnection(
new TonhubProvider({
isSandbox: true,
onSessionLinkReady: (session) => {
// For example, display `session.link` as a QR code for the mobile tonhub wallet to scan
},
persistenceProvider: localStorage, // If you want the persist the session
}),
EnvProfiles[Environments.SANDBOX].rpcApi
);
const wallet = await tonHubCon.connect(); // Get wallet details
```

1. Create the jetton

```
const contractAddress = await dep.createJetton(
{
owner: ... // Wallet address of owner,
onProgress: (depState, err, extra) => {},
jettonName: jettonParams.name,
jettonSymbol: jettonParams.symbol,
amountToMint: toNano(jettonParams.mintAmount),
},
tonHubCon
);
```

## Building jetton contracts from source

The library relies on precompiled jetton contracts. Their source code is available at contracts/jetton-minter.fc and contracts/jetton-wallet.fc.

The contract code can be modified and built using `npm run build`, which will generate compiled code as hex to be consumed by the deployer.

To build, follow instructions at `https://github.com/ton-defi-org/tonstarter-contracts`.

## Running on web

In order to use this package with a web app, a node-compatible buffer library should be available. (See [buffer](https://www.npmjs.com/package/buffer))
## Overview
This project contains the necessary components for deploying a jetton token on the ton network.

See example at https://github.com/jetton-deployer/jetton-deployer-web
## Building
1. You should have the latest ton binaries installed. See the [tonstarter-contracts repo for instructions](https://github.com/ton-defi-org/tonstarter-contracts/#dependencies-and-requirements)
2. The contracts in this repo are compatible with the [vanilla jetton contracts](https://github.com/ton-blockchain/token-contract), updated for the func 0.2.0. If you wish to modify them to support different jetton configurations (such as max supply), edit the contract files (jetton-minter.fc and jetton-wallet.fc) as needed.
3. Run `npm run build`

## Roadmap
## Deploying
The easiest way is to use the [webapp](https://ton-defi-org.github.io/jetton-deployer-webclient), if you're using vanilla contracts.

- Support max supply tokens
- Support minting to different addresses
If you want to deploy manually and/or change the contract code:

## Test
> This part uses the standard method of deploying, as defined in the [tonstarter-contracts repo](https://github.com/ton-defi-org/tonstarter-contracts/#development-instructions)
- In the root repo dir, run in terminal `npm run test`
- Don't forget to build (or rebuild) before running tests
- Tests are running inside Node.js by running TVM in web-assembly using `ton-contract-executor`
1. Make sure you have a ton wallet with at least 0.25 TON balance.
1. Edit `jettonParams` in `jetton-minter.deploy.ts` to set the jetton's name, symbol etc.
1. Run `npm run deploy`
66 changes: 25 additions & 41 deletions build/_build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import process from "process";
import child_process from "child_process";
import glob from "fast-glob";
import { Cell } from "ton";
import semver from "semver";

async function main() {
console.log("=================================================================");
Expand All @@ -24,14 +25,15 @@ async function main() {
}

// make sure func compiler is available
let funcVersion = "";
const minSupportFunc = "0.2.0";
try {
funcVersion = child_process.execSync("func -V").toString();
const funcVersion = child_process
.execSync("func -V")
.toString()
.match(/semantic version: v([0-9.]+)/)?.[1];
if (!semver.gte(semver.coerce(funcVersion) ?? "", minSupportFunc)) throw new Error("Nonexistent version or outdated");
} catch (e) {
/*ignore*/
}
if (!funcVersion.includes("Func build information")) {
console.log("\nFATAL ERROR: 'func' executable is not found, is it installed and in path?");
console.log(`\nFATAL ERROR: 'func' with version >= ${minSupportFunc} executable is not found, is it installed and in path?`);
process.exit(1);
}

Expand Down Expand Up @@ -73,7 +75,7 @@ async function main() {
console.log(` - Deleting old build artifact '${cellArtifact}'`);
fs.unlinkSync(cellArtifact);
}
const hexArtifact = `build/${contractName}-hex.json`;
const hexArtifact = `build/${contractName}.compiled.json`;
if (fs.existsSync(hexArtifact)) {
console.log(` - Deleting old build artifact '${hexArtifact}'`);
fs.unlinkSync(hexArtifact);
Expand All @@ -89,42 +91,20 @@ async function main() {
const crc = crc32(tlbOpMessage);
const asQuery = `0x${(crc & 0x7fffffff).toString(16)}`;
const asResponse = `0x${((crc | 0x80000000) >>> 0).toString(16)}`;
console.log(
` op '${
tlbOpMessage.split(" ")[0]
}': '${asQuery}' as query (&0x7fffffff), '${asResponse}' as response (|0x80000000)`
);
console.log(` op '${tlbOpMessage.split(" ")[0]}': '${asQuery}' as query (&0x7fffffff), '${asResponse}' as response (|0x80000000)`);
}
} else {
console.log(
` - Warning: TL-B file for contract '${tlbFile}' not found, are your op consts according to standard?`
);
}

// create a merged fc file with source code from all dependencies
let sourceToCompile = "";
const importFiles = glob.sync([
"contracts/imports/*.fc",
"contracts/imports/*.func",
`contracts/imports/${contractName}/*.fc`,
`contracts/imports/${contractName}/*.func`,
]);
for (const importFile of importFiles) {
console.log(` - Adding import '${importFile}'`);
sourceToCompile += `${fs.readFileSync(importFile).toString()}\n`;
console.log(` - Warning: TL-B file for contract '${tlbFile}' not found, are your op consts according to standard?`);
}
console.log(` - Adding the contract itself '${rootContract}'`);
sourceToCompile += `${fs.readFileSync(rootContract).toString()}\n`;
fs.writeFileSync(mergedFuncArtifact, sourceToCompile);
console.log(` - Build artifact created '${mergedFuncArtifact}'`);

// run the func compiler to create a fif file
console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`);
const buildErrors = child_process
.execSync(
`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1 1>node_modules/.tmpfunc`
)
.toString();
console.log(` - Trying to compile '${rootContract}' with 'func' compiler..`);
let buildErrors: string;
try {
buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${rootContract} 2>&1 1>node_modules/.tmpfunc`).toString();
} catch (e) {
buildErrors = e.stdout.toString();
}
if (buildErrors.length > 0) {
console.log(" - OH NO! Compilation Errors! The compiler output was:");
console.log(`\n${buildErrors}`);
Expand All @@ -142,7 +122,7 @@ async function main() {
}

// create a temp cell.fif that will generate the cell
let fiftCellSource = '"Asm.fif" include\n';
let fiftCellSource = "\"Asm.fif\" include\n";
fiftCellSource += `${fs.readFileSync(fiftArtifact).toString()}\n`;
fiftCellSource += `boc>B "${cellArtifact}" B>file`;
fs.writeFileSync(fiftCellArtifact, fiftCellSource);
Expand All @@ -155,13 +135,15 @@ async function main() {
process.exit(1);
}

// Remove intermediary
fs.unlinkSync(fiftCellArtifact);

// make sure cell build artifact was created
if (!fs.existsSync(cellArtifact)) {
console.log(` - For some reason '${cellArtifact}' was not created!`);
process.exit(1);
} else {
console.log(` - Build artifact created '${cellArtifact}'`);
fs.unlinkSync(fiftCellArtifact);
}

fs.writeFileSync(
Expand All @@ -171,13 +153,15 @@ async function main() {
})
);

// Remove intermediary
fs.unlinkSync(cellArtifact);

// make sure hex artifact was created
if (!fs.existsSync(hexArtifact)) {
console.log(` - For some reason '${hexArtifact}' was not created!`);
process.exit(1);
} else {
console.log(` - Build artifact created '${hexArtifact}'`);
fs.unlinkSync(cellArtifact);
}
}

Expand Down
Loading

0 comments on commit fd5e8ef

Please sign in to comment.