Browse Source

Add support for glitch

master
Tal Kol 2 years ago
parent
commit
8b21162f59
  1. 3
      .gitignore
  2. 8
      .setup.glitch.sh
  3. 7
      README.md
  4. 1
      build/.gitignore
  5. 6
      build/build.ts
  6. 28
      build/deploy.ts
  7. 17
      package-lock.json
  8. 4
      package.json

3
.gitignore vendored

@ -1 +1,4 @@
node_modules node_modules
.env
.wget-hsts
bin

8
.setup.glitch.sh

@ -0,0 +1,8 @@
# this will download all dependencies for Ubuntu 16 (fift, func executables) and place them in ./bin
mkdir bin
wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/fift -P ./bin
chmod +x ./bin/fift
wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/func -P ./bin
chmod +x ./bin/func
wget https://github.com/ton-defi-org/ton-binaries/releases/download/fiftlib/fiftlib.zip -P ./bin
unzip ./bin/fiftlib.zip -d ./bin/fiftlib

7
README.md

@ -30,7 +30,7 @@ Some of the opinionated choices made here include:
## Dependencies and requirements ## Dependencies and requirements
To setup your machine for development, please make sure you have the following: To setup your local machine for development, please make sure you have the following:
* A modern version of Node.js * A modern version of Node.js
* Installation instructions can be found [here](https://nodejs.org/) * Installation instructions can be found [here](https://nodejs.org/)
@ -45,6 +45,8 @@ To setup your machine for development, please make sure you have the following:
* A decent IDE with FunC and TypeScript support * A decent IDE with FunC and TypeScript support
* We recommend using [Visual Studio Code](https://code.visualstudio.com/) with the [FunC plugin](https://marketplace.visualstudio.com/items?itemName=tonwhales.func-vscode) installed * We recommend using [Visual Studio Code](https://code.visualstudio.com/) with the [FunC plugin](https://marketplace.visualstudio.com/items?itemName=tonwhales.func-vscode) installed
Alternatively, you can ignore the above requirements and develop in your web browser with an online IDE and zero setup. Simply open this repo inside [Glitch](https://glitch.com/) without installing anything.
## Development instructions ## Development instructions
* Install * Install
@ -77,7 +79,8 @@ To setup your machine for development, please make sure you have the following:
* Deploy * Deploy
* Make sure all contracts are built and your setup is ready to deploy: * Make sure all contracts are built and your setup is ready to deploy:
* Each contract to deploy should have a script `build/mycontract.deploy.ts` to return its init data cell * Each contract to deploy should have a script `build/mycontract.deploy.ts` to return its init data cell
* The deployment wallet is configured in `build/deploy.config.json` (file will be created if not found) * The deployment wallet is configured in `.env` (will be created automatically if not exists), with contents:<br>
`DEPLOYER_MNEMONIC="mad nation chief flavor ..."`
* To deploy to mainnet (production), run in terminal `npm run deploy` * To deploy to mainnet (production), run in terminal `npm run deploy`
* To deploy to testnet instead (where TON is free), run `npm run deploy:testnet` * To deploy to testnet instead (where TON is free), run `npm run deploy:testnet`
* Follow the on-screen instructions of the deploy script * Follow the on-screen instructions of the deploy script

1
build/.gitignore vendored

@ -1,4 +1,3 @@
*.fif *.fif
*.fc *.fc
*.cell *.cell
deploy.config.json

6
build/build.ts

@ -16,6 +16,12 @@ async function main() {
console.log(`=================================================================`); console.log(`=================================================================`);
console.log(`Build script running, let's find some FunC contracts to compile..`); console.log(`Build script running, let's find some FunC contracts to compile..`);
// if we have an explicit bin directory, use the executables there (needed for glitch.com)
if (fs.existsSync("bin")) {
process.env.PATH = __dirname + "/../bin/:" + process.env.PATH;
process.env.FIFTPATH = __dirname + "/../bin/fiftlib";
}
// make sure func compiler is available // make sure func compiler is available
let funcVersion = ""; let funcVersion = "";
try { try {

28
build/deploy.ts

@ -2,12 +2,15 @@
// Every contract you want to deploy should have a mycontract.deploy.ts script that returns its init data // Every contract you want to deploy should have a mycontract.deploy.ts script that returns its init data
// The script assumes that it is running from the repo root, and the directories are organized this way: // The script assumes that it is running from the repo root, and the directories are organized this way:
// ./build/ - directory for build artifacts (mycontract.cell) and deploy init data scripts (mycontract.deploy.ts) // ./build/ - directory for build artifacts (mycontract.cell) and deploy init data scripts (mycontract.deploy.ts)
// ./build/deploy.config.json - JSON config file with secret mnemonic of deploying wallet (will be created if not found) // ./.env - config file with DEPLOYER_MNEMONIC - secret mnemonic of deploying wallet (will be created if not found)
import axios from "axios"; import axios from "axios";
import axiosThrottle from "axios-request-throttle"; import axiosThrottle from "axios-request-throttle";
axiosThrottle.use(axios, { requestsPerSecond: 0.5 }); // required since toncenter jsonRPC limits to 1 req/sec without API key axiosThrottle.use(axios, { requestsPerSecond: 0.5 }); // required since toncenter jsonRPC limits to 1 req/sec without API key
import dotenv from "dotenv";
dotenv.config();
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import glob from "fast-glob"; import glob from "fast-glob";
@ -28,27 +31,26 @@ async function main() {
// initialize globals // initialize globals
const client = new TonClient({ endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` }); const client = new TonClient({ endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` });
const deployerWalletType = "org.ton.wallets.v3.r2"; // see WalletV3R2Source class used below const deployerWalletType = "org.ton.wallets.v3.r2"; // also see WalletV3R2Source class used below
const newContractFunding = toNano(0.02); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent const newContractFunding = toNano(0.02); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent
const workchain = 0; // normally 0, only special contracts should be deployed to masterchain (-1) const workchain = 0; // normally 0, only special contracts should be deployed to masterchain (-1)
// make sure we have a wallet mnemonic to deploy from (or create one if not found) // make sure we have a wallet mnemonic to deploy from (or create one if not found)
const deployConfigJson = `build/deploy.config.json`; const deployConfigEnv = ".env";
let deployerMnemonic; let deployerMnemonic;
if (!fs.existsSync(deployConfigJson)) { if (!fs.existsSync(deployConfigEnv)) {
console.log(`\n* Config file '${deployConfigJson}' not found, creating a new wallet for deploy..`); console.log(`\n* Config file '${deployConfigEnv}' not found, creating a new wallet for deploy..`);
deployerMnemonic = (await mnemonicNew(24)).join(" "); deployerMnemonic = (await mnemonicNew(24)).join(" ");
const deployWalletJsonContent = { created: new Date().toISOString(), deployerWalletType, deployerMnemonic }; const deployWalletEnvContent = `DEPLOYER_WALLET=${deployerWalletType}\nDEPLOYER_MNEMONIC="${deployerMnemonic}"\n`;
fs.writeFileSync(deployConfigJson, JSON.stringify(deployWalletJsonContent, null, 2)); fs.writeFileSync(deployConfigEnv, deployWalletEnvContent);
console.log(` - Created new wallet in '${deployConfigJson}' - keep this file secret!`); console.log(` - Created new wallet in '${deployConfigEnv}' - keep this file secret!`);
} else { } else {
console.log(`\n* Config file '${deployConfigJson}' found and will be used for deployment!`); console.log(`\n* Config file '${deployConfigEnv}' found and will be used for deployment!`);
const deployConfigJsonContent = require(__dirname + "/../" + deployConfigJson); if (!process.env.DEPLOYER_MNEMONIC) {
if (!deployConfigJsonContent.deployerMnemonic) { console.log(` - ERROR: '${deployConfigEnv}' does not contain key 'DEPLOYER_MNEMONIC'`);
console.log(` - ERROR: '${deployConfigJson}' does not have the key 'deployerMnemonic'`);
process.exit(1); process.exit(1);
} }
deployerMnemonic = deployConfigJsonContent.deployerMnemonic; deployerMnemonic = process.env.DEPLOYER_MNEMONIC;
} }
// open the wallet and make sure it has enough TON // open the wallet and make sure it has enough TON

17
package-lock.json generated

@ -7,6 +7,7 @@
"": { "": {
"name": "tonstarter-contracts", "name": "tonstarter-contracts",
"version": "0.0.0", "version": "0.0.0",
"hasInstallScript": true,
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/bn.js": "^5.1.0", "@types/bn.js": "^5.1.0",
@ -15,6 +16,7 @@
"axios-request-throttle": "^1.0.0", "axios-request-throttle": "^1.0.0",
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-bn": "^0.3.1", "chai-bn": "^0.3.1",
"dotenv": "^16.0.0",
"fast-glob": "^3.2.11", "fast-glob": "^3.2.11",
"mocha": "^9.1.3", "mocha": "^9.1.3",
"prando": "^6.0.1", "prando": "^6.0.1",
@ -522,6 +524,15 @@
"node": ">=0.3.1" "node": ">=0.3.1"
} }
}, },
"node_modules/dotenv": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
"dev": true,
"engines": {
"node": ">=12"
}
},
"node_modules/emoji-regex": { "node_modules/emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
@ -2092,6 +2103,12 @@
"integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==",
"dev": true "dev": true
}, },
"dotenv": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
"dev": true
},
"emoji-regex": { "emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",

4
package.json

@ -9,7 +9,8 @@
"test": "mocha --exit test/**/*.spec.ts", "test": "mocha --exit test/**/*.spec.ts",
"build": "ts-node ./build/build.ts", "build": "ts-node ./build/build.ts",
"deploy": "ts-node ./build/deploy.ts", "deploy": "ts-node ./build/deploy.ts",
"deploy:testnet": "export TESTNET=1 && ts-node ./build/deploy.ts" "deploy:testnet": "export TESTNET=1 && ts-node ./build/deploy.ts",
"postinstall": "! test -f /app/.glitchdotcom.json || test -d /app/bin || bash .setup.glitch.sh"
}, },
"devDependencies": { "devDependencies": {
"@types/bn.js": "^5.1.0", "@types/bn.js": "^5.1.0",
@ -18,6 +19,7 @@
"axios-request-throttle": "^1.0.0", "axios-request-throttle": "^1.0.0",
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-bn": "^0.3.1", "chai-bn": "^0.3.1",
"dotenv": "^16.0.0",
"fast-glob": "^3.2.11", "fast-glob": "^3.2.11",
"mocha": "^9.1.3", "mocha": "^9.1.3",
"prando": "^6.0.1", "prando": "^6.0.1",

Loading…
Cancel
Save