-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
153 lines (134 loc) · 5.81 KB
/
index.ts
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import inquirer from 'inquirer';
import {
askForDeployer,
askForContractName,
askForConstructorParams,
} from './src/deployment/deploymentUtils';
import { getAccount } from './src/get_account';
import { getSalt } from './src/get_salt';
import { generate } from './src/generate_salts';
import { setRPC } from './src/select_rpc';
import { getDeployedContractAddresses } from './src/get_deployed_ups';
import { interactWithUP } from './src/interact_with_up';
import { formatEther } from 'ethers';
import {
LSP16ComputeAddress,
LSP16DeployContract,
askForInitializeCalldata,
} from './src/deployment/lsp16_deployment';
import {
LSP23ComputeAddresses,
LSP23DeployContracts,
} from './src/deployment/lsp23_deployment';
const main = async () => {
console.clear();
inquirer
.prompt({
type: 'list',
name: 'main',
message: 'Select action from the list:',
choices: [
'1. get secret public address',
'2. get secret balance',
'3. generate salts',
'4. check your salt',
'5. get contract deployment address',
'6. deploy contract',
'7. get your up addresses',
'8. interact with up',
],
})
.then(async ({ main }) => {
if (main === '1. get secret public address') {
await setRPC();
const { publicAddress } = await getAccount();
console.log(publicAddress);
} else if (main === '2. get secret balance') {
await setRPC();
const { provider, publicAddress } = await getAccount();
const balance = await provider.getBalance(publicAddress);
console.log(`${formatEther(balance)} LYX`);
} else if (main === '3. generate salts') {
await setRPC();
await generate();
} else if (main === '4. check your salt') {
const salt = await getSalt();
console.log(salt);
} else if (main === '5. get deployment address') {
await setRPC();
const deployerName = await askForDeployer();
if (deployerName === 'LSP16') {
const computedAddress = LSP16ComputeAddress();
console.log(computedAddress);
} else if (deployerName === 'LSP23') {
const computedAddress = LSP23ComputeAddresses();
console.log(computedAddress);
}
} else if (main === '6. deploy contract') {
const { explorerBaseLink } = await setRPC();
const { account, chainId } = await getAccount();
const deployerName = await askForDeployer();
if (deployerName === 'LSP16') {
const { txHash, deployedContractAddress } =
await LSP16DeployContract(account, chainId);
console.log(`Contract address: ${deployedContractAddress}`);
console.log(`${explorerBaseLink}tx/${txHash}`);
console.log(
`${explorerBaseLink}address/${deployedContractAddress}`,
);
} else if (deployerName === 'LSP23') {
const {
txHash,
primaryContractAddress,
secondaryContractAddress,
} = await LSP23DeployContracts(account, chainId);
console.log(
`Primary Contract Address: ${primaryContractAddress}`,
);
console.log(
`Priamry Contract: ${explorerBaseLink}address/${primaryContractAddress}`,
);
console.log(
`Secondary Contract Address: ${secondaryContractAddress}`,
);
console.log(
`Secondary Contract: ${explorerBaseLink}address/${secondaryContractAddress}`,
);
console.log(`${explorerBaseLink}tx/${txHash}`);
}
} else if (main === '7. get your contract addresses') {
await setRPC();
const { publicAddress, chainId } = await getAccount();
const deployerName = await askForDeployer();
const contractName = await askForContractName();
const contractAddresses = await getDeployedContractAddresses(
publicAddress,
chainId,
deployerName,
contractName,
);
console.log(contractAddresses);
} else if (main === '8. interact with up') {
const { explorerBaseLink } = await setRPC();
const { account, publicAddress, chainId } = await getAccount();
const deployerName = await askForDeployer();
const contractName = await askForContractName();
if (contractName !== 'LSP0ERC725Account')
throw new Error(
"Error: Only 'LSP0ERC725Account' is supported now",
);
const contractAddresses = await getDeployedContractAddresses(
publicAddress,
chainId,
deployerName,
contractName,
);
const txHash = await interactWithUP(account, contractAddresses);
console.log(`${explorerBaseLink}tx/${txHash}`);
} else
throw new Error(
'Unexpected Error: None of the main menu options were selected.',
);
});
};
main();