toronetdeploy 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/ci.yml +29 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/index.js +230 -0
- package/package.json +36 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.1.3/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": true,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
ci:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: '20'
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: npm install
|
|
27
|
+
|
|
28
|
+
- name: Run CI
|
|
29
|
+
run: npm run ci
|
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Emmanuel Nwafor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# toronetdeploy
|
|
2
|
+
|
|
3
|
+
Deploy smart contracts to ToroNet.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Run via `npx` (no global install required):
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npx toronetdeploy --file contracts/MyToken.sol --contract MyToken \
|
|
11
|
+
--owner 0xYourOwnerAddress --args '["0xabc...", "1000"]' --network testnet
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage Options
|
|
15
|
+
|
|
16
|
+
- `--file` Path to the Solidity file containing the contract
|
|
17
|
+
- `--contract` Name of the contract to deploy (must be in the specified file)
|
|
18
|
+
- `--owner` Address of the owner deploying the contract
|
|
19
|
+
- `--args` Constructor arguments as JSON array or comma-separated values
|
|
20
|
+
- `--network` Network to deploy to (default: `testnet`)
|
|
21
|
+
- `--token` Optional token for deployment
|
|
22
|
+
|
|
23
|
+
License: MIT
|
|
24
|
+
|
|
25
|
+
Author: [Emmanuel Nwafor](https://github.com/emmo00)
|
package/index.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
Reusable deploy script for ToroSDK
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
npx toronetdeploy --file contracts/MyToken.sol --contract MyToken \
|
|
7
|
+
--owner 0xYourOwnerAddress --args '["0xabc...", "1000"]' --network testnet
|
|
8
|
+
|
|
9
|
+
Install dependencies:
|
|
10
|
+
npm install solc torosdk
|
|
11
|
+
|
|
12
|
+
This script compiles a single Solidity file and deploys the specified contract
|
|
13
|
+
using ToroSDK's `deploySmartContract`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const solc = require('solc');
|
|
19
|
+
const { initializeSDK, deploySmartContract } = require('torosdk');
|
|
20
|
+
|
|
21
|
+
function usage() {
|
|
22
|
+
console.log(
|
|
23
|
+
'Usage:\n\tnpx toronetdeploy --file <path> --contract <name> --owner <address> [--args <json|csv>] [--network testnet|mainnet] [--token <token>]\n\n\
|
|
24
|
+
Options:\n\t--file: Path to Solidity file containing the contract\n\t--contract: Name of the contract to deploy (must be in the specified file)\n\t--owner: Address of the owner deploying the contract\n\t--args: Constructor arguments as JSON array or comma-separated values\n\t--network: Network to deploy to (default: testnet)\n\t--token: Optional token for deployment if required by your setup\n\t--help, -h: Show this help message',
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseArgs() {
|
|
30
|
+
const argv = process.argv.slice(2);
|
|
31
|
+
const out = {};
|
|
32
|
+
for (let i = 0; i < argv.length; i++) {
|
|
33
|
+
const a = argv[i];
|
|
34
|
+
if (a === '--file') out.file = argv[++i];
|
|
35
|
+
else if (a === '--contract') out.contract = argv[++i];
|
|
36
|
+
else if (a === '--owner') out.owner = argv[++i];
|
|
37
|
+
else if (a === '--network') out.network = argv[++i];
|
|
38
|
+
else if (a === '--token') out.token = argv[++i];
|
|
39
|
+
else if (a === '--args') out.args = argv[++i];
|
|
40
|
+
else if (a === '--help' || a === '-h') usage();
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseConstructorArgs(argStr) {
|
|
46
|
+
if (!argStr) return [];
|
|
47
|
+
argStr = argStr.trim();
|
|
48
|
+
if (argStr.startsWith('[')) {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(argStr);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw new Error('Invalid JSON for --args');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// comma-separated
|
|
56
|
+
return argStr
|
|
57
|
+
.split(',')
|
|
58
|
+
.map((s) => s.trim())
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function compileSolidity(filePath, contractName) {
|
|
63
|
+
const absPath = path.resolve(filePath);
|
|
64
|
+
if (!fs.existsSync(absPath)) throw new Error('Solidity file not found: ' + absPath);
|
|
65
|
+
const source = fs.readFileSync(absPath, 'utf8');
|
|
66
|
+
|
|
67
|
+
const input = {
|
|
68
|
+
language: 'Solidity',
|
|
69
|
+
sources: {
|
|
70
|
+
[path.basename(absPath)]: { content: source },
|
|
71
|
+
},
|
|
72
|
+
settings: {
|
|
73
|
+
optimizer: { enabled: true, runs: 200 },
|
|
74
|
+
evmVersion: 'paris', // important
|
|
75
|
+
outputSelection: {
|
|
76
|
+
'*': { '*': ['abi', 'evm.bytecode'] },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// load remappings from lib/*/remappings.txt (common in Foundry projects)
|
|
82
|
+
function loadRemappings() {
|
|
83
|
+
const remaps = [];
|
|
84
|
+
const projectRoot = process.cwd();
|
|
85
|
+
|
|
86
|
+
// 1) read foundry.toml remappings if present
|
|
87
|
+
const foundryFile = path.join(projectRoot, 'foundry.toml');
|
|
88
|
+
if (fs.existsSync(foundryFile)) {
|
|
89
|
+
try {
|
|
90
|
+
const txt = fs.readFileSync(foundryFile, 'utf8');
|
|
91
|
+
const m = txt.match(/remappings\s*=\s*\[([^\]]*)\]/m);
|
|
92
|
+
if (m && m[1]) {
|
|
93
|
+
const items = m[1]
|
|
94
|
+
.split(',')
|
|
95
|
+
.map((s) => s.trim())
|
|
96
|
+
.filter(Boolean);
|
|
97
|
+
for (let it of items) {
|
|
98
|
+
// remove quotes
|
|
99
|
+
it = it.replace(/^\s*['"]?/, '').replace(/['"]?\s*$/, '');
|
|
100
|
+
// expect format prefix=target
|
|
101
|
+
const parts = it.split('=');
|
|
102
|
+
if (parts.length !== 2) continue;
|
|
103
|
+
const prefix = parts[0];
|
|
104
|
+
const target = parts[1];
|
|
105
|
+
const absTarget = path.resolve(projectRoot, target);
|
|
106
|
+
remaps.push([prefix, absTarget]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
// ignore parsing errors
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 2) read lib/*/remappings.txt (foundry style)
|
|
115
|
+
const libDir = path.resolve(projectRoot, 'lib');
|
|
116
|
+
if (fs.existsSync(libDir)) {
|
|
117
|
+
const libs = fs
|
|
118
|
+
.readdirSync(libDir, { withFileTypes: true })
|
|
119
|
+
.filter((d) => d.isDirectory())
|
|
120
|
+
.map((d) => d.name);
|
|
121
|
+
for (const l of libs) {
|
|
122
|
+
const rfile = path.join(libDir, l, 'remappings.txt');
|
|
123
|
+
if (!fs.existsSync(rfile)) continue;
|
|
124
|
+
const lines = fs
|
|
125
|
+
.readFileSync(rfile, 'utf8')
|
|
126
|
+
.split(/\r?\n/)
|
|
127
|
+
.map((s) => s.trim())
|
|
128
|
+
.filter(Boolean);
|
|
129
|
+
for (const line of lines) {
|
|
130
|
+
const parts = line.split('=');
|
|
131
|
+
if (parts.length !== 2) continue;
|
|
132
|
+
const prefix = parts[0];
|
|
133
|
+
const target = parts[1];
|
|
134
|
+
// make target absolute relative to remappings.txt
|
|
135
|
+
const absTarget = path.resolve(path.dirname(rfile), target);
|
|
136
|
+
remaps.push([prefix, absTarget]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return remaps;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const remappings = loadRemappings();
|
|
145
|
+
|
|
146
|
+
const mainDir = path.dirname(absPath);
|
|
147
|
+
|
|
148
|
+
function findImports(importPath) {
|
|
149
|
+
// Try remappings first (e.g. @openzeppelin/...)
|
|
150
|
+
for (const [prefix, targetDir] of remappings) {
|
|
151
|
+
// match exact prefix or prefix + '/'
|
|
152
|
+
if (importPath === prefix || importPath.startsWith(prefix + '/')) {
|
|
153
|
+
const rest = importPath === prefix ? '' : importPath.slice(prefix.length + 1);
|
|
154
|
+
const candidate = path.join(targetDir, rest);
|
|
155
|
+
if (fs.existsSync(candidate)) return { contents: fs.readFileSync(candidate, 'utf8') };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// node_modules fallback
|
|
160
|
+
const nmCandidate = path.join(process.cwd(), 'node_modules', importPath);
|
|
161
|
+
if (fs.existsSync(nmCandidate)) return { contents: fs.readFileSync(nmCandidate, 'utf8') };
|
|
162
|
+
|
|
163
|
+
// relative to main file
|
|
164
|
+
const relCandidate = path.resolve(mainDir, importPath);
|
|
165
|
+
if (fs.existsSync(relCandidate)) return { contents: fs.readFileSync(relCandidate, 'utf8') };
|
|
166
|
+
|
|
167
|
+
// absolute / project-root relative
|
|
168
|
+
const rootCandidate = path.resolve(process.cwd(), importPath);
|
|
169
|
+
if (fs.existsSync(rootCandidate)) return { contents: fs.readFileSync(rootCandidate, 'utf8') };
|
|
170
|
+
|
|
171
|
+
return { error: 'File import callback not supported for ' + importPath };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const output = JSON.parse(solc.compile(JSON.stringify(input), { import: findImports }));
|
|
175
|
+
if (output.errors) {
|
|
176
|
+
const hasFatal = output.errors.some((e) => e.severity === 'error');
|
|
177
|
+
output.errors.forEach((e) => console.error(e.formattedMessage || e.message));
|
|
178
|
+
if (hasFatal) throw new Error('Compilation failed with errors');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const fileContracts = output.contracts[path.basename(absPath)];
|
|
182
|
+
if (!fileContracts) throw new Error('No contracts found in compilation output');
|
|
183
|
+
const contract = fileContracts[contractName];
|
|
184
|
+
if (!contract) throw new Error(`Contract ${contractName} not found in ${filePath}`);
|
|
185
|
+
|
|
186
|
+
const abi = contract.abi;
|
|
187
|
+
const bytecode = contract.evm.bytecode.object;
|
|
188
|
+
if (!bytecode || bytecode.length === 0)
|
|
189
|
+
throw new Error('Bytecode is empty (abstract contract or interface?)');
|
|
190
|
+
|
|
191
|
+
return { abi, bytecode: '0x' + bytecode };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function main() {
|
|
195
|
+
const opts = parseArgs();
|
|
196
|
+
if (!opts.file || !opts.contract || !opts.owner) usage();
|
|
197
|
+
|
|
198
|
+
const constructorArgs = parseConstructorArgs(opts.args);
|
|
199
|
+
const network = opts.network || 'testnet';
|
|
200
|
+
const token = opts.token || undefined;
|
|
201
|
+
|
|
202
|
+
console.log('Compiling', opts.file, 'contract', opts.contract);
|
|
203
|
+
const { abi, bytecode } = compileSolidity(opts.file, opts.contract);
|
|
204
|
+
|
|
205
|
+
console.log('Initializing ToroSDK (network:', network + ')');
|
|
206
|
+
initializeSDK({ network });
|
|
207
|
+
|
|
208
|
+
console.log('Deploying contract...');
|
|
209
|
+
try {
|
|
210
|
+
const result = await deploySmartContract({
|
|
211
|
+
owner: opts.owner,
|
|
212
|
+
constructorArgs,
|
|
213
|
+
abi,
|
|
214
|
+
bytecode,
|
|
215
|
+
token,
|
|
216
|
+
network: network, // optional override; initializeSDK already set network as well
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
console.log('Deployed address:', result.address);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
console.error('Deployment failed:', err && err.message ? err.message.toString() : err.toString());
|
|
222
|
+
console.error(err);
|
|
223
|
+
process.exitCode = 1;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
main().catch((err) => {
|
|
228
|
+
console.error(err);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toronetdeploy",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Deploy smart contracts to ToroNet",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"toronetdeploy": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"check-format": "prettier --check .",
|
|
12
|
+
"ci": "npm run check-format",
|
|
13
|
+
"local-release": "changeset version && changeset publish",
|
|
14
|
+
"prepublishOnly": "npm run ci",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"toronet",
|
|
19
|
+
"smart-contracts",
|
|
20
|
+
"deployment"
|
|
21
|
+
],
|
|
22
|
+
"author": "emmo00",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Emmo00/toronetdeploy.git"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"solc": "^0.8.34",
|
|
31
|
+
"torosdk": "^0.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@changesets/cli": "^2.30.0"
|
|
35
|
+
}
|
|
36
|
+
}
|