-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate.js
124 lines (102 loc) · 3.27 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require('dotenv').config();
const fs = require('fs');
const { generateWallet, getStxAddress } = require('@stacks/wallet-sdk');
const { TransactionVersion } = require('@stacks/transactions');
const assertEnvVars = (vars) => {
const _vars = typeof vars === 'object' ? [...vars] : [vars];
const rv = [];
for (let v of _vars) {
if (!process.env[v]) {
throw (`${v} env variable required!`);
}
rv.push(process.env[v]);
}
return rv;
}
const [NETWORK,] = assertEnvVars('NETWORK');
const getNetwork = () => {
if (!['mainnet', 'testnet'].includes(NETWORK)) {
throw new Error(`Invalid network: ${NETWORK}`);
}
return NETWORK;
}
const [MNEMONIC,] = assertEnvVars('MNEMONIC');
const getAccountWithAddress = async () => {
const wallet = await generateWallet({
secretKey: MNEMONIC,
password: '',
});
const [account,] = wallet.accounts;
const address = getStxAddress({ account, transactionVersion: (getNetwork() === 'mainnet' ? TransactionVersion.Mainnet : TransactionVersion.Testnet) });
return { account, address };
}
const DEPLOY_LIST = [
{
name: "multisafe-traits",
file: "traits.clar"
},
{
name: "ft-none",
file: "helper/ft-none.clar"
},
{
name: "nft-none",
file: "helper/nft-none.clar"
},
{
name: "add-owner",
file: "executors/add-owner.clar"
},
{
name: "remove-owner",
file: "executors/remove-owner.clar"
},
{
name: "set-threshold",
file: "executors/set-threshold.clar"
},
{
name: "transfer-stx",
file: "executors/transfer-stx.clar"
},
{
name: "transfer-sip-009",
file: "executors/transfer-sip-009.clar"
},
{
name: "transfer-sip-010",
file: "executors/transfer-sip-010.clar"
},
{
name: "magic-bridge-send",
file: "executors/magic-bridge-send.clar"
}
];
const main = async () => {
const { account, address } = await getAccountWithAddress();
console.log(`Account: ${address}`);
console.log(`Network: ${getNetwork()}`);
const TRAIT_SEARCH = 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.traits';
const TRAIT_REPLACE = `${address}.multisafe-traits`;
const MAGIC_BRIDGE_SEARCH = 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.magic-bridge';
let MAGIC_BRIDGE_REPLACE = 'ST2ZTY9KK9H0FA0NVN3K8BGVN6R7GYVFG6BE7TAR1.bridge';
if(NETWORK === 'mainnet'){
throw new Error('Magic bridge hasn`t deployed on mainnet yet');
}
if (fs.existsSync('generated')) {
fs.rmSync('generated', { recursive: true, force: true });
}
const savePath = `generated/${NETWORK}`;
fs.mkdirSync(savePath, { recursive: true });
let i = 1;
for (let D of DEPLOY_LIST) {
const contents = fs.readFileSync(`contracts/${D.file}`, { encoding: 'utf-8' });
let codeReplaced = contents.replace(new RegExp(TRAIT_SEARCH, 'g'), TRAIT_REPLACE);
codeReplaced = codeReplaced.replace(MAGIC_BRIDGE_SEARCH, MAGIC_BRIDGE_REPLACE);
const codeToSave = `${D.name}\n\n${codeReplaced}`;
fs.writeFileSync(`${savePath}/${i}-${D.name}`, codeToSave, { encoding: 'utf-8' });
i++;
}
console.log("Done");
}
main().catch(console.log);