@taqueria/plugin-taquito 0.22.2 → 0.23.0-rc.2

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/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var $iVZbm$taquerianodesdk = require("@taqueria/node-sdk");
2
2
  var $iVZbm$taquitosigner = require("@taquito/signer");
3
3
  var $iVZbm$taquitotaquito = require("@taquito/taquito");
4
+ var $iVZbm$taquitomichelcodec = require("@taquito/michel-codec");
4
5
  var $iVZbm$fspromises = require("fs/promises");
5
6
  var $iVZbm$path = require("path");
6
- var $iVZbm$taquitomichelcodec = require("@taquito/michel-codec");
7
7
 
8
8
 
9
9
 
@@ -11,295 +11,321 @@ var $iVZbm$taquitomichelcodec = require("@taquito/michel-codec");
11
11
 
12
12
 
13
13
 
14
-
15
- const $806c5c6032403442$var$getFirstAccountAlias = (sandboxName, opts)=>{
16
- const aliases = (0, $iVZbm$taquerianodesdk.getSandboxAccountNames)(opts)(sandboxName);
17
- return aliases.shift();
18
- };
19
- const $806c5c6032403442$var$getContractAbspath = (contractFilename, parsedArgs)=>(0, $iVZbm$path.join)(parsedArgs.config.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`);
20
- const $806c5c6032403442$var$addOrigination = (parsedArgs, batch)=>async (mapping)=>{
21
- const contractAbspath = $806c5c6032403442$var$getContractAbspath(mapping.filename, parsedArgs);
22
- const contractData = await (0, $iVZbm$fspromises.readFile)(contractAbspath, "utf-8");
23
- return (await batch).withOrigination({
24
- code: contractData,
25
- init: mapping.storage
26
- });
27
- };
28
- const $806c5c6032403442$var$getDefaultStorageFilename = (contractName)=>{
29
- const baseFilename = (0, $iVZbm$path.basename)(contractName, (0, $iVZbm$path.extname)(contractName));
30
- const extFilename = (0, $iVZbm$path.extname)(contractName);
31
- const defaultStorage = `${baseFilename}.default_storage${extFilename}`;
32
- return defaultStorage;
33
- };
34
- // TODO: temporary quick solution. May refactor this to only deal with one contract later
35
- const $806c5c6032403442$var$getValidContracts = async (parsedArgs)=>{
36
- const contracts = [
37
- parsedArgs.contract
38
- ];
39
- const storageFilename = parsedArgs.storage ?? $806c5c6032403442$var$getDefaultStorageFilename(contracts[0]);
40
- return contracts.reduce(async (retval, filename)=>{
41
- const storage = await (0, $iVZbm$taquerianodesdk.newGetInitialStorage)(parsedArgs, storageFilename);
42
- if (storage === undefined || storage === null) {
43
- (0, $iVZbm$taquerianodesdk.sendErr)(`❌ No initial storage file was found for ${filename}\nStorage must be specified in a file as a Michelson expression and will automatically be linked to this contract if specified with the name "${$806c5c6032403442$var$getDefaultStorageFilename(contracts[0])}" in the artifacts directory\nYou can also manually pass a storage file to the deploy task using the --storage STORAGE_FILE_NAME option\n`);
44
- // sendErr(
45
- // `Michelson artifact ${filename} has no initial storage specified for the target environment.\nStorage is expected to be specified in .taq/config.json at JSON path: environment.${
46
- // getCurrentEnvironment(parsedArgs)
47
- // }.storage["${filename}"]\nThe value of the above JSON key should be the name of the file (absolute path or relative path with respect to the root of the Taqueria project) that contains the actual value of the storage, as a Michelson expression.\n`,
48
- // );
49
- return retval;
50
- }
51
- return [
52
- ...await retval,
53
- {
54
- filename: filename,
55
- storage: storage
56
- }
57
- ];
58
- }, Promise.resolve([]));
59
- };
60
- const $806c5c6032403442$var$mapOpToContract = async (parsedArgs, contracts, op, destination)=>{
61
- const results = await op.operationResults();
62
- const originationResults = results.filter((result)=>result.kind === "origination").map((result)=>result);
63
- return contracts.reduce((retval, contract)=>{
64
- // If initial storage was provided for the contract
65
- // then we submitted an operation to originate that contract
66
- if (contract.storage) {
67
- // WARNING - using side effect here.
68
- // For each iteration of reduce, results array is being modified-in-place.
69
- // TODO: Adjust to use recursion to avoid side-effect.
70
- const result = originationResults.shift();
71
- const address = result && result.metadata.operation_result.originated_contracts ? result.metadata.operation_result.originated_contracts.join(",") : "Error";
72
- const alias = parsedArgs.alias ?? (0, $iVZbm$path.basename)(contract.filename, (0, $iVZbm$path.extname)(contract.filename));
73
- if (address !== "Error") (0, $iVZbm$taquerianodesdk.updateAddressAlias)(parsedArgs, alias, address);
74
- return [
75
- ...retval,
76
- {
77
- contract: contract.filename,
78
- address: address,
79
- alias: address !== "Error" ? alias : "N/A",
80
- destination: destination
81
- },
82
- ];
83
- }
84
- return [
85
- ...retval,
86
- {
87
- contract: contract.filename,
88
- address: "Error",
89
- alias: "N/A",
90
- destination: destination
91
- },
92
- ];
93
- }, []);
94
- };
95
- const $806c5c6032403442$var$createBatch = async (parsedArgs, tezos, destination)=>{
96
- const contracts = await $806c5c6032403442$var$getValidContracts(parsedArgs);
97
- if (!contracts.length) return undefined;
98
- const batch1 = await contracts.reduce((batch, contractMapping)=>contractMapping.storage ? $806c5c6032403442$var$addOrigination(parsedArgs, batch)(contractMapping) : batch, Promise.resolve(tezos.wallet.batch()));
99
- try {
100
- const op = await batch1.send();
101
- const confirmed = await op.confirmation();
102
- return await $806c5c6032403442$var$mapOpToContract(parsedArgs, contracts, op, destination);
103
- } catch (err) {
104
- const error = err;
105
- if (error.message) {
106
- const msg = error.message;
107
- if (/ENOTFOUND/.test(msg)) (0, $iVZbm$taquerianodesdk.sendErr)(msg + " - The RPC URL may be invalid. Check ./taq/config.json.\n");
108
- else if (/ECONNREFUSED/.test(msg)) (0, $iVZbm$taquerianodesdk.sendErr)(msg + " - The RPC URL may be down or the sandbox is not running.");
109
- else if (/empty_implicit_contract/.test(msg)) {
110
- const result = msg.match(/(?<="implicit":")tz[^"]+(?=")/);
111
- const publicKeyHash = result ? result[0] : undefined;
112
- if (!publicKeyHash) (0, $iVZbm$taquerianodesdk.sendErr)(msg);
113
- else (0, $iVZbm$taquerianodesdk.sendErr)(`The account ${publicKeyHash} for the target environment, "${(0, $iVZbm$taquerianodesdk.getCurrentEnvironment)(parsedArgs)}", may not be funded\nTo fund this account:\n1. Go to https://teztnets.xyz and click "Faucet" of the target testnet\n2. Copy and paste the above key into the 'wallet address field\n3. Request some Tez (Note that you might need to wait for a few seconds for the network to register the funds)`);
114
- } else (0, $iVZbm$taquerianodesdk.sendErr)(msg + " - There was a problem communicating with the chain. Check the RPC URL of the network or sandbox you're targeting in config.json.\n");
115
- }
116
- return undefined;
117
- }
118
- };
119
- async function $806c5c6032403442$export$e4c4fcd791db1d6b(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret) {
120
- if (privateKeyOrEmail && passphrase && mnemonic && secret) return await (0, $iVZbm$taquitosigner.importKey)(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret);
121
- else if (mnemonic) {
122
- const signer = (0, $iVZbm$taquitosigner.InMemorySigner).fromFundraiser(privateKeyOrEmail ?? "", passphrase ?? "", mnemonic);
123
- toolkit.setProvider({
124
- signer: signer
125
- });
126
- const pkh = await signer.publicKeyHash();
127
- let op;
128
- try {
129
- op = await toolkit.tz.activate(pkh, secret ?? "");
130
- if (op) await op.confirmation();
131
- } catch (ex) {}
132
- } else if (privateKeyOrEmail) {
133
- // Fallback to regular import
134
- const signer = await (0, $iVZbm$taquitosigner.InMemorySigner).fromSecretKey(privateKeyOrEmail, passphrase);
135
- toolkit.setProvider({
136
- signer: signer
137
- });
138
- }
139
- }
140
- const $806c5c6032403442$var$originateToNetworks = (parsedArgs, currentEnv)=>currentEnv.networks ? currentEnv.networks.reduce((retval, networkName)=>{
14
+ const $2c87226370e1ba97$export$e1210318d02974b = (parsedArgs, env)=>{
15
+ const targetConstraintErrMsg = "Each environment can only have one target, be it a network or a sandbox";
16
+ if (env.networks?.length === 1 && env.sandboxes?.length === 1) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(targetConstraintErrMsg);
17
+ if (env.networks?.length === 1) {
18
+ const networkName = env.networks[0];
141
19
  const network = (0, $iVZbm$taquerianodesdk.getNetworkConfig)(parsedArgs)(networkName);
142
- if (network) {
143
- if (network.rpcUrl) {
144
- const result = (async ()=>{
145
- const tezos = new (0, $iVZbm$taquitotaquito.TezosToolkit)(network.rpcUrl);
146
- const key = await (0, $iVZbm$taquerianodesdk.getAccountPrivateKey)(parsedArgs, network, "taqRootAccount");
147
- await (0, $iVZbm$taquitosigner.importKey)(tezos, key);
148
- return await $806c5c6032403442$var$createBatch(parsedArgs, tezos, networkName);
149
- })();
150
- return [
151
- ...retval,
152
- result
153
- ];
154
- } else (0, $iVZbm$taquerianodesdk.sendErr)(`Network "${networkName}" is missing an RPC url in config.json.`);
155
- } else (0, $iVZbm$taquerianodesdk.sendErr)(`The current environment is configured to use a network called '${networkName}'; however, no network of this name has been configured in .taq/config.json.`);
156
- return retval;
157
- }, []) : [];
158
- const $806c5c6032403442$var$originateToSandboxes = (parsedArgs, currentEnv)=>currentEnv.sandboxes ? currentEnv.sandboxes.reduce((retval, sandboxName)=>{
20
+ if (!network) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The current environment is configured to use a network called '${networkName}'; however, no network of this name has been configured in .taq/config.json`);
21
+ return Promise.resolve([
22
+ "Network",
23
+ network
24
+ ]);
25
+ }
26
+ if (env.sandboxes?.length === 1) {
27
+ const sandboxName = env.sandboxes[0];
159
28
  const sandbox = (0, $iVZbm$taquerianodesdk.getSandboxConfig)(parsedArgs)(sandboxName);
160
- if (sandbox) {
161
- if (sandbox.rpcUrl) {
162
- let defaultAccount = (0, $iVZbm$taquerianodesdk.getDefaultAccount)(parsedArgs)(sandboxName);
163
- if (!defaultAccount) {
164
- const first = $806c5c6032403442$var$getFirstAccountAlias(sandboxName, parsedArgs);
165
- if (first) {
166
- defaultAccount = (0, $iVZbm$taquerianodesdk.getSandboxAccountConfig)(parsedArgs)(sandboxName)(first);
167
- // TODO: The error should be a warning, not an error. Descriptive string should not begin with 'Warning:'
168
- (0, $iVZbm$taquerianodesdk.sendErr)(`Warning: A default origination account has not been specified for sandbox ${sandboxName}. Taqueria will use the account ${first} for this origination.\nA default account can be specified in .taq/config.json at JSON path: sandbox.${sandboxName}.accounts.default\n`);
169
- }
170
- }
171
- if (defaultAccount) {
172
- const secretKey = defaultAccount.secretKey;
173
- const result = (async ()=>{
174
- const tezos = new (0, $iVZbm$taquitotaquito.TezosToolkit)(sandbox.rpcUrl);
175
- tezos.setProvider({
176
- signer: new (0, $iVZbm$taquitosigner.InMemorySigner)(secretKey.replace(/^unencrypted:/, ""))
177
- });
178
- return await $806c5c6032403442$var$createBatch(parsedArgs, tezos, sandboxName);
179
- })();
180
- return [
181
- ...retval,
182
- result
183
- ];
184
- } else (0, $iVZbm$taquerianodesdk.sendErr)(`No accounts are available for the sandbox called ${sandboxName} to perform origination.`);
185
- } else (0, $iVZbm$taquerianodesdk.sendErr)(`Sandbox "${sandboxName} is missing an RPC url in config.json."`);
186
- } else (0, $iVZbm$taquerianodesdk.sendErr)(`The current environment is configured to use a sandbox called '${sandboxName}'; however, no sandbox of this name has been configured in .taq/config.json.`);
187
- return retval;
188
- }, []) : [];
189
- const $806c5c6032403442$export$acf571c34911f824 = (parsedArgs)=>{
190
- const env = (0, $iVZbm$taquerianodesdk.getCurrentEnvironmentConfig)(parsedArgs);
191
- if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json.`);
192
- const jobs1 = [
193
- ...$806c5c6032403442$var$originateToNetworks(parsedArgs, env),
194
- ...$806c5c6032403442$var$originateToSandboxes(parsedArgs, env),
195
- ];
196
- return Promise.all(jobs1).then((jobs)=>jobs.reduce((retval, originations)=>{
197
- return originations ? [
198
- ...retval,
199
- ...originations
200
- ] : retval;
201
- }, [])).then((results)=>results && results.length > 0 ? (0, $iVZbm$taquerianodesdk.sendJsonRes)(results) : (0, $iVZbm$taquerianodesdk.sendErr)(`No contracts originated.`));
202
- };
203
- var $806c5c6032403442$export$2e2bcd8739ae039 = $806c5c6032403442$export$acf571c34911f824;
204
-
205
-
206
-
207
-
208
-
209
-
210
- const $944e64d99e99b46e$var$getFirstAccountAlias = (sandboxName, opts)=>{
211
- const aliases = (0, $iVZbm$taquerianodesdk.getSandboxAccountNames)(opts)(sandboxName);
212
- return aliases.shift();
29
+ if (!sandbox) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The current environment is configured to use a sandbox called '${sandboxName}'; however, no sandbox of this name has been configured in .taq/config.json`);
30
+ return Promise.resolve([
31
+ "Sandbox",
32
+ sandbox
33
+ ]);
34
+ }
35
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(targetConstraintErrMsg);
213
36
  };
214
- const $944e64d99e99b46e$var$configureToolKitWithSandbox = async (parsedArgs, sandboxName)=>{
215
- const sandbox = (0, $iVZbm$taquerianodesdk.getSandboxConfig)(parsedArgs)(sandboxName);
216
- if (!sandbox) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The current environment is configured to use a sandbox called '${sandboxName}'; however, no sandbox of this name has been configured in .taq/config.json.`);
217
- let defaultAccount = (0, $iVZbm$taquerianodesdk.getDefaultAccount)(parsedArgs)(sandboxName);
218
- if (!defaultAccount) {
219
- const first = $944e64d99e99b46e$var$getFirstAccountAlias(sandboxName, parsedArgs);
220
- if (first) {
221
- defaultAccount = (0, $iVZbm$taquerianodesdk.getSandboxAccountConfig)(parsedArgs)(sandboxName)(first);
222
- (0, $iVZbm$taquerianodesdk.sendErr)(`Warning: A default account has not been specified for sandbox ${sandboxName}. Taqueria will use the account ${first} for this operation.\nA default account can be specified in .taq/config.json at JSON path: sandbox.${sandboxName}.accounts.default\n`);
223
- }
37
+ const $2c87226370e1ba97$export$cf995f4bdbe82fd9 = async (sandbox, sender)=>{
38
+ let accountKey;
39
+ if (sender && sender !== "default") {
40
+ const accounts = $2c87226370e1ba97$export$f9fd6b8c665ab918(sandbox);
41
+ if (accounts.hasOwnProperty(sender)) accountKey = accounts[sender].secretKey;
42
+ else return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`${sender} is not an account instantiated in the current environment. Check .taq/config.json`);
43
+ } else {
44
+ const defaultAccount = (0, $iVZbm$taquerianodesdk.getDefaultSandboxAccount)(sandbox);
45
+ if (!defaultAccount) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`No default account is specified in the sandbox to perform the operation. Please use the --sender flag to explicitly specify the account to use as the sender of the operation`);
46
+ accountKey = defaultAccount.secretKey;
224
47
  }
225
- if (!defaultAccount) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`No accounts are available for the sandbox called ${sandboxName} to perform the operation.`);
226
48
  const tezos = new (0, $iVZbm$taquitotaquito.TezosToolkit)(sandbox.rpcUrl);
227
49
  tezos.setProvider({
228
- signer: new (0, $iVZbm$taquitosigner.InMemorySigner)(defaultAccount.secretKey.replace(/^unencrypted:/, ""))
50
+ signer: new (0, $iVZbm$taquitosigner.InMemorySigner)(accountKey.replace(/^unencrypted:/, ""))
229
51
  });
230
52
  return tezos;
231
53
  };
232
- const $944e64d99e99b46e$var$configureToolKitWithNetwork = async (parsedArgs, networkName)=>{
233
- const network = (0, $iVZbm$taquerianodesdk.getNetworkConfig)(parsedArgs)(networkName);
234
- if (!network) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The current environment is configured to use a network called '${networkName}'; however, no network of this name has been configured in .taq/config.json.`);
54
+ const $2c87226370e1ba97$export$5a1c5b7c3009d1b0 = async (parsedArgs, network, sender)=>{
55
+ let account;
56
+ if (sender && sender !== (0, $iVZbm$taquerianodesdk.TAQ_OPERATOR_ACCOUNT)) {
57
+ const accounts = $2c87226370e1ba97$export$e56de24c31a1cc9e(network);
58
+ if (accounts.hasOwnProperty(sender)) account = sender;
59
+ else return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`${sender} is not an account instantiated in the current environment. Check .taq/config.json`);
60
+ } else account = (0, $iVZbm$taquerianodesdk.TAQ_OPERATOR_ACCOUNT);
235
61
  const tezos = new (0, $iVZbm$taquitotaquito.TezosToolkit)(network.rpcUrl);
236
- const key = await (0, $iVZbm$taquerianodesdk.getAccountPrivateKey)(parsedArgs, network, "taqRootAccount");
62
+ const key = await (0, $iVZbm$taquerianodesdk.getAccountPrivateKey)(parsedArgs, network, account);
237
63
  await (0, $iVZbm$taquitosigner.importKey)(tezos, key);
238
64
  return tezos;
239
65
  };
240
- const $944e64d99e99b46e$var$configureTezosToolKit = (parsedArgs, env)=>{
241
- const targetConstraintErrMsg = "Each environment can only have one target, be it a sandbox or a network";
242
- if (env.sandboxes?.length === 1 && env.networks?.length === 1) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(targetConstraintErrMsg);
243
- if (env.sandboxes?.length === 1) return $944e64d99e99b46e$var$configureToolKitWithSandbox(parsedArgs, env.sandboxes[0]);
244
- if (env.networks?.length === 1) return $944e64d99e99b46e$var$configureToolKitWithNetwork(parsedArgs, env.networks[0]);
245
- return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(targetConstraintErrMsg);
66
+ const $2c87226370e1ba97$export$ac04c99a21479c39 = (parsedArgs)=>Object.entries(parsedArgs.config.accounts).reduce((acc, declaredAccount)=>{
67
+ const alias = declaredAccount[0];
68
+ const mutez = declaredAccount[1];
69
+ return {
70
+ ...acc,
71
+ [alias]: typeof mutez === "string" ? parseFloat(mutez) : mutez
72
+ };
73
+ }, {});
74
+ const $2c87226370e1ba97$export$f9fd6b8c665ab918 = (sandbox)=>sandbox?.accounts ? Object.entries(sandbox.accounts).reduce((acc, instantiatedAccount)=>{
75
+ const alias = instantiatedAccount[0];
76
+ const keys = instantiatedAccount[1];
77
+ return alias !== "default" ? {
78
+ ...acc,
79
+ [alias]: keys
80
+ } : acc;
81
+ }, {}) : {};
82
+ const $2c87226370e1ba97$export$e56de24c31a1cc9e = (network)=>network.accounts ? Object.entries(network.accounts).reduce((acc, instantiatedAccount)=>{
83
+ const alias = instantiatedAccount[0];
84
+ const keys = instantiatedAccount[1];
85
+ return alias !== (0, $iVZbm$taquerianodesdk.TAQ_OPERATOR_ACCOUNT) ? {
86
+ ...acc,
87
+ [alias]: keys
88
+ } : acc;
89
+ }, {}) : {};
90
+ const $2c87226370e1ba97$export$c5dc6d68f9166ad7 = async (parsedArgs, network, account)=>{
91
+ const tezos = new (0, $iVZbm$taquitotaquito.TezosToolkit)(network.rpcUrl);
92
+ const key = await (0, $iVZbm$taquerianodesdk.getAccountPrivateKey)(parsedArgs, network, account);
93
+ await (0, $iVZbm$taquitosigner.importKey)(tezos, key);
94
+ };
95
+ const $2c87226370e1ba97$export$eadeae1f47371140 = (err, env)=>{
96
+ if (err instanceof Error) {
97
+ const msg = err.message;
98
+ if (/ENOTFOUND/.test(msg)) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("The RPC URL may be invalid. Check ./.taq/config.json");
99
+ if (/ECONNREFUSED/.test(msg)) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("The RPC URL may be down or the sandbox is not running");
100
+ if (/empty_implicit_contract/.test(msg)) {
101
+ const result = msg.match(/(?<="implicit":")tz[^"]+(?=")/);
102
+ const publicKeyHash = result ? result[0] : undefined;
103
+ if (publicKeyHash) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The account ${publicKeyHash} for the target environment, "${env}", may not be funded\nTo fund this account:\n1. Go to https://teztnets.xyz and click "Faucet" of the target testnet\n2. Copy and paste the above key into the wallet address field\n3. Request some Tez (Note that you might need to wait for a few seconds for the network to register the funds)`);
104
+ }
105
+ }
106
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`Error while performing operation:\n${err} ${JSON.stringify(err, null, 2)}`);
246
107
  };
108
+
109
+
110
+
111
+
112
+
247
113
  const $944e64d99e99b46e$var$isContractAddress = (contract)=>contract.startsWith("tz1") || contract.startsWith("tz2") || contract.startsWith("tz3") || contract.startsWith("KT1");
248
- const $944e64d99e99b46e$var$getContractInfo = async (parsedArgs, env, tezos)=>{
114
+ const $944e64d99e99b46e$var$getContractInfo = async (parsedArgs, env)=>{
249
115
  const contract = parsedArgs.contract;
250
116
  return {
251
117
  contractAlias: $944e64d99e99b46e$var$isContractAddress(contract) ? "N/A" : contract,
252
118
  contractAddress: $944e64d99e99b46e$var$isContractAddress(contract) ? contract : await (0, $iVZbm$taquerianodesdk.getAddressOfAlias)(env, contract),
253
- tezTransfer: parsedArgs.tez ?? "0",
254
119
  parameter: parsedArgs.param ? await (0, $iVZbm$taquerianodesdk.getParameter)(parsedArgs, parsedArgs.param) : "Unit",
255
120
  entrypoint: parsedArgs.entrypoint ?? "default",
121
+ mutezTransfer: parseInt(parsedArgs.mutez ?? "0")
122
+ };
123
+ };
124
+ const $944e64d99e99b46e$var$createBatchForTransfer = (tezos, contractsInfo)=>contractsInfo.reduce((acc, contractInfo)=>acc.withTransfer({
125
+ to: contractInfo.contractAddress,
126
+ amount: contractInfo.mutezTransfer,
127
+ parameter: {
128
+ entrypoint: contractInfo.entrypoint,
129
+ value: new (0, $iVZbm$taquitomichelcodec.Parser)().parseMichelineExpression(contractInfo.parameter)
130
+ },
131
+ mutez: true
132
+ }), tezos.wallet.batch());
133
+ const $944e64d99e99b46e$export$e61a38557a73155d = async (tezos, env, contractsInfo)=>{
134
+ const batch = $944e64d99e99b46e$var$createBatchForTransfer(tezos, contractsInfo);
135
+ try {
136
+ const op = await batch.send();
137
+ await op.confirmation();
138
+ return op;
139
+ } catch (err) {
140
+ return (0, $2c87226370e1ba97$export$eadeae1f47371140)(err, env);
141
+ }
142
+ };
143
+ const $944e64d99e99b46e$var$prepContractInfoForDisplay = (tezos, contractInfo)=>{
144
+ return {
145
+ contractAlias: contractInfo.contractAlias,
146
+ contractAddress: contractInfo.contractAddress,
147
+ parameter: contractInfo.parameter,
148
+ entrypoint: contractInfo.entrypoint,
149
+ mutezTransfer: contractInfo.mutezTransfer.toString(),
256
150
  destination: tezos.rpc.getRpcUrl()
257
151
  };
258
152
  };
259
- const $944e64d99e99b46e$var$performTransferOp = (tezos, contractInfo, parsedArgs)=>{
260
- return tezos.contract.transfer({
261
- to: contractInfo.contractAddress,
262
- amount: parseFloat(contractInfo.tezTransfer),
263
- parameter: {
264
- entrypoint: contractInfo.entrypoint,
265
- value: new (0, $iVZbm$taquitomichelcodec.Parser)().parseMichelineExpression(contractInfo.parameter)
266
- }
267
- }).then((op)=>op.confirmation().then(()=>op.hash)).catch((err)=>{
268
- if (err instanceof Error) {
269
- if (/empty_implicit_contract/.test(err.message)) {
270
- const result = err.message.match(/(?<="implicit":")tz[^"]+(?=")/);
271
- const publicKeyHash = result ? result[0] : undefined;
272
- if (publicKeyHash) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`The account ${publicKeyHash} for the target environment, "${(0, $iVZbm$taquerianodesdk.getCurrentEnvironment)(parsedArgs)}", may not be funded\nTo fund this account:\n1. Go to https://teztnets.xyz and click "Faucet" of the target testnet\n2. Copy and paste the above key into the 'wallet address field\n3. Request some Tez (Note that you might need to wait for a few seconds for the network to register the funds)`);
273
- }
274
- }
275
- return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`Error during transfer operation:\n${err} ${JSON.stringify(err, null, 2)}`);
153
+ const $944e64d99e99b46e$var$transfer = async (parsedArgs)=>{
154
+ const env = (0, $iVZbm$taquerianodesdk.getCurrentEnvironmentConfig)(parsedArgs);
155
+ if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json`);
156
+ try {
157
+ const [envType, nodeConfig] = await (0, $2c87226370e1ba97$export$e1210318d02974b)(parsedArgs, env);
158
+ const tezos = await (envType === "Network" ? (0, $2c87226370e1ba97$export$5a1c5b7c3009d1b0)(parsedArgs, nodeConfig, parsedArgs.sender) : (0, $2c87226370e1ba97$export$cf995f4bdbe82fd9)(nodeConfig, parsedArgs.sender));
159
+ const contractInfo = await $944e64d99e99b46e$var$getContractInfo(parsedArgs, env);
160
+ await $944e64d99e99b46e$export$e61a38557a73155d(tezos, (0, $iVZbm$taquerianodesdk.getCurrentEnvironment)(parsedArgs), [
161
+ contractInfo
162
+ ]);
163
+ const contractInfoForDisplay = $944e64d99e99b46e$var$prepContractInfoForDisplay(tezos, contractInfo);
164
+ return (0, $iVZbm$taquerianodesdk.sendJsonRes)([
165
+ contractInfoForDisplay
166
+ ]);
167
+ } catch {
168
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("No operations performed");
169
+ }
170
+ };
171
+ var $944e64d99e99b46e$export$2e2bcd8739ae039 = $944e64d99e99b46e$var$transfer;
172
+
173
+
174
+ const $1e142599cb4e04fd$var$getAccountsInfo = (parsedArgs, tezos, instantiatedAccounts)=>Promise.all(Object.entries(instantiatedAccounts).map(async (instantiatedAccount)=>{
175
+ const alias = instantiatedAccount[0];
176
+ const aliasInfo = instantiatedAccount[1];
177
+ const declaredMutez = (0, $2c87226370e1ba97$export$ac04c99a21479c39)(parsedArgs)[alias];
178
+ const currentBalanceInMutez = (await tezos.tz.getBalance(aliasInfo.publicKeyHash)).toNumber();
179
+ const amountToFillInMutez = declaredMutez ? Math.max(declaredMutez - currentBalanceInMutez, 0) : 0;
180
+ if (!declaredMutez) (0, $iVZbm$taquerianodesdk.sendWarn)(`Warning: ${alias} is instantiated in the target environment but not declared in the root level "accounts" field of ./.taq/config.json so ${alias} will not be funded as you don't have a declared tez amount set there for ${alias}\n`);
181
+ return {
182
+ contractAlias: alias,
183
+ contractAddress: aliasInfo.publicKeyHash,
184
+ parameter: "Unit",
185
+ entrypoint: "default",
186
+ mutezTransfer: parseInt(amountToFillInMutez.toString())
187
+ };
188
+ })).then((accountsInfo)=>accountsInfo.filter((accountInfo)=>accountInfo.mutezTransfer !== 0)).catch((err)=>(0, $iVZbm$taquerianodesdk.sendAsyncErr)(`Something went wrong while extracting account information - ${err}`));
189
+ const $1e142599cb4e04fd$var$prepAccountsInfoForDisplay = (accountsInfo)=>accountsInfo.map((accountInfo)=>{
190
+ return {
191
+ accountAlias: accountInfo.contractAlias,
192
+ accountAddress: accountInfo.contractAddress,
193
+ mutezFunded: accountInfo.mutezTransfer.toString()
194
+ };
276
195
  });
196
+ const $1e142599cb4e04fd$var$fund = async (parsedArgs)=>{
197
+ const env = (0, $iVZbm$taquerianodesdk.getCurrentEnvironmentConfig)(parsedArgs);
198
+ if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json`);
199
+ try {
200
+ const [envType, nodeConfig] = await (0, $2c87226370e1ba97$export$e1210318d02974b)(parsedArgs, env);
201
+ if (envType !== "Network") return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("taq fund can only be executed in a network environment");
202
+ const tezos = await (0, $2c87226370e1ba97$export$5a1c5b7c3009d1b0)(parsedArgs, nodeConfig);
203
+ const instantiatedAccounts = (0, $2c87226370e1ba97$export$e56de24c31a1cc9e)(nodeConfig);
204
+ const accountsInfo = await $1e142599cb4e04fd$var$getAccountsInfo(parsedArgs, tezos, instantiatedAccounts);
205
+ if (accountsInfo.length === 0) return (0, $iVZbm$taquerianodesdk.sendJsonRes)(`All instantiated accounts in the current environment, "${parsedArgs.env}", are funded up to or beyond the declared amount`);
206
+ await (0, $944e64d99e99b46e$export$e61a38557a73155d)(tezos, (0, $iVZbm$taquerianodesdk.getCurrentEnvironment)(parsedArgs), accountsInfo);
207
+ const accountsInfoForDisplay = $1e142599cb4e04fd$var$prepAccountsInfoForDisplay(accountsInfo);
208
+ return (0, $iVZbm$taquerianodesdk.sendJsonRes)(accountsInfoForDisplay);
209
+ } catch {
210
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("No operations performed");
211
+ }
277
212
  };
278
- const $944e64d99e99b46e$export$c9b234447cf4ef7c = async (parsedArgs)=>{
213
+ var $1e142599cb4e04fd$export$2e2bcd8739ae039 = $1e142599cb4e04fd$var$fund;
214
+
215
+
216
+
217
+
218
+ const $ae16ebef21e504f4$var$instantiate_account = async (parsedArgs)=>{
279
219
  const env = (0, $iVZbm$taquerianodesdk.getCurrentEnvironmentConfig)(parsedArgs);
280
- if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json.`);
220
+ if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json`);
281
221
  try {
282
- const tezos = await $944e64d99e99b46e$var$configureTezosToolKit(parsedArgs, env);
283
- const contractInfo = await $944e64d99e99b46e$var$getContractInfo(parsedArgs, env, tezos);
284
- await $944e64d99e99b46e$var$performTransferOp(tezos, contractInfo, parsedArgs);
285
- return (0, $iVZbm$taquerianodesdk.sendJsonRes)([
222
+ const [envType, nodeConfig] = await (0, $2c87226370e1ba97$export$e1210318d02974b)(parsedArgs, env);
223
+ if (envType !== "Network") return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("taq instantiate-account can only be executed in a network environment");
224
+ const declaredAccountAliases = Object.keys((0, $2c87226370e1ba97$export$ac04c99a21479c39)(parsedArgs));
225
+ const instantiatedAccounts = (0, $2c87226370e1ba97$export$e56de24c31a1cc9e)(nodeConfig);
226
+ let accountsInstantiated = [];
227
+ for (const declaredAccountAlias of declaredAccountAliases)if (!instantiatedAccounts.hasOwnProperty(declaredAccountAlias)) {
228
+ await (0, $2c87226370e1ba97$export$c5dc6d68f9166ad7)(parsedArgs, nodeConfig, declaredAccountAlias);
229
+ accountsInstantiated.push(declaredAccountAlias);
230
+ } else (0, $iVZbm$taquerianodesdk.sendWarn)(`Note: ${declaredAccountAlias} is already instantiated in the current environment, "${parsedArgs.env}"`);
231
+ if (accountsInstantiated.length !== 0) return (0, $iVZbm$taquerianodesdk.sendJsonRes)(`Accounts instantiated: ${accountsInstantiated.join(", ")}.\nPlease execute "taq fund" targeting the same environment to fund these accounts`);
232
+ else return (0, $iVZbm$taquerianodesdk.sendJsonRes)(`No accounts were instantiated because they were all instantiated in the target environment already`);
233
+ } catch {
234
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("No operations performed");
235
+ }
236
+ };
237
+ var $ae16ebef21e504f4$export$2e2bcd8739ae039 = $ae16ebef21e504f4$var$instantiate_account;
238
+
239
+
240
+
241
+
242
+
243
+
244
+ const $806c5c6032403442$var$getContractPath = (parsedArgs, contractFilename)=>(0, $iVZbm$path.join)(parsedArgs.config.artifactsDir, /\.tz$/.test(contractFilename) ? contractFilename : `${contractFilename}.tz`);
245
+ const $806c5c6032403442$var$getDefaultStorageFilename = (contractName)=>{
246
+ const baseFilename = (0, $iVZbm$path.basename)(contractName, (0, $iVZbm$path.extname)(contractName));
247
+ const extFilename = (0, $iVZbm$path.extname)(contractName);
248
+ const defaultStorage = `${baseFilename}.default_storage${extFilename}`;
249
+ return defaultStorage;
250
+ };
251
+ const $806c5c6032403442$var$getContractInfo = async (parsedArgs)=>{
252
+ const contract = parsedArgs.contract;
253
+ const contractPath = $806c5c6032403442$var$getContractPath(parsedArgs, contract);
254
+ const contractCode = await (0, $iVZbm$fspromises.readFile)(contractPath, "utf-8");
255
+ const storageFilename = parsedArgs.storage ?? $806c5c6032403442$var$getDefaultStorageFilename(contract);
256
+ const contractInitStorage = await (0, $iVZbm$taquerianodesdk.getInitialStorage)(parsedArgs, storageFilename);
257
+ if (contractInitStorage === undefined) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`❌ No initial storage file was found for ${contract}\nStorage must be specified in a file as a Michelson expression and will automatically be linked to this contract if specified with the name "${$806c5c6032403442$var$getDefaultStorageFilename(contract)}" in the artifacts directory\nYou can also manually pass a storage file to the originate task using the --storage STORAGE_FILE_NAME option\n`);
258
+ return {
259
+ contract: contract,
260
+ code: contractCode,
261
+ initStorage: contractInitStorage,
262
+ mutezTransfer: parseInt(parsedArgs.mutez ?? "0")
263
+ };
264
+ };
265
+ const $806c5c6032403442$var$createBatchForOriginate = (tezos, contractsInfo)=>contractsInfo.reduce((acc, contractInfo)=>acc.withOrigination({
266
+ code: contractInfo.code,
267
+ init: contractInfo.initStorage,
268
+ balance: contractInfo.mutezTransfer.toString(),
269
+ mutez: true
270
+ }), tezos.wallet.batch());
271
+ const $806c5c6032403442$export$4737da0e626ec8c7 = async (tezos, env, contractsInfo)=>{
272
+ const batch = $806c5c6032403442$var$createBatchForOriginate(tezos, contractsInfo);
273
+ try {
274
+ const op = await batch.send();
275
+ await op.confirmation();
276
+ return op;
277
+ } catch (err) {
278
+ return (0, $2c87226370e1ba97$export$eadeae1f47371140)(err, env);
279
+ }
280
+ };
281
+ const $806c5c6032403442$var$prepContractInfoForDisplay = async (parsedArgs, tezos, contractInfo, op)=>{
282
+ const operationResults = await op.operationResults();
283
+ const originationResults = operationResults.filter((result)=>result.kind === "origination").map((result)=>result);
284
+ // Length should be 1 since we are batching originate operations into one
285
+ const result1 = originationResults.length === 1 ? originationResults[0] : undefined;
286
+ const address = result1?.metadata?.operation_result?.originated_contracts?.join(",");
287
+ const alias = parsedArgs.alias ?? (0, $iVZbm$path.basename)(contractInfo.contract, (0, $iVZbm$path.extname)(contractInfo.contract));
288
+ if (address) await (0, $iVZbm$taquerianodesdk.updateAddressAlias)(parsedArgs, alias, address);
289
+ return {
290
+ contract: contractInfo.contract,
291
+ address: address ?? "Something went wrong during origination",
292
+ alias: address ? alias : "N/A",
293
+ balanceInMutez: contractInfo.mutezTransfer.toString(),
294
+ destination: tezos.rpc.getRpcUrl()
295
+ };
296
+ };
297
+ const $806c5c6032403442$var$originate = async (parsedArgs)=>{
298
+ const env = (0, $iVZbm$taquerianodesdk.getCurrentEnvironmentConfig)(parsedArgs);
299
+ if (!env) return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`There is no environment called ${parsedArgs.env} in your config.json`);
300
+ try {
301
+ const [envType, nodeConfig] = await (0, $2c87226370e1ba97$export$e1210318d02974b)(parsedArgs, env);
302
+ const tezos = await (envType === "Network" ? (0, $2c87226370e1ba97$export$5a1c5b7c3009d1b0)(parsedArgs, nodeConfig, parsedArgs.sender) : (0, $2c87226370e1ba97$export$cf995f4bdbe82fd9)(nodeConfig, parsedArgs.sender));
303
+ const contractInfo = await $806c5c6032403442$var$getContractInfo(parsedArgs);
304
+ const op = await $806c5c6032403442$export$4737da0e626ec8c7(tezos, (0, $iVZbm$taquerianodesdk.getCurrentEnvironment)(parsedArgs), [
286
305
  contractInfo
287
306
  ]);
307
+ const contractInfoForDisplay = await $806c5c6032403442$var$prepContractInfoForDisplay(parsedArgs, tezos, contractInfo, op);
308
+ return (0, $iVZbm$taquerianodesdk.sendJsonRes)([
309
+ contractInfoForDisplay
310
+ ]);
288
311
  } catch {
289
- return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("No operations performed.");
312
+ return (0, $iVZbm$taquerianodesdk.sendAsyncErr)("No operations performed");
290
313
  }
291
314
  };
292
- var $944e64d99e99b46e$export$2e2bcd8739ae039 = $944e64d99e99b46e$export$c9b234447cf4ef7c;
315
+ var $806c5c6032403442$export$2e2bcd8739ae039 = $806c5c6032403442$var$originate;
316
+
293
317
 
294
318
 
295
319
  const $e6ed693f861ac256$export$71d25adf06a71b9 = (parsedArgs)=>{
296
320
  switch(parsedArgs.task){
297
- case "originate":
298
321
  case "deploy":
299
322
  return (0, $806c5c6032403442$export$2e2bcd8739ae039)(parsedArgs);
300
323
  case "transfer":
301
- case "call":
302
324
  return (0, $944e64d99e99b46e$export$2e2bcd8739ae039)(parsedArgs);
325
+ case "instantiate-account":
326
+ return (0, $ae16ebef21e504f4$export$2e2bcd8739ae039)(parsedArgs);
327
+ case "fund":
328
+ return (0, $1e142599cb4e04fd$export$2e2bcd8739ae039)(parsedArgs);
303
329
  default:
304
330
  return (0, $iVZbm$taquerianodesdk.sendAsyncErr)(`${parsedArgs.task} is not an understood task by the Taquito plugin`);
305
331
  }
@@ -326,6 +352,16 @@ var $e6ed693f861ac256$export$2e2bcd8739ae039 = $e6ed693f861ac256$export$71d25adf
326
352
  flag: "storage",
327
353
  description: "Name of the storage file that contains the storage value as a Michelson expression, in the artifacts directory, used for originating a contract",
328
354
  required: false
355
+ }),
356
+ (0, $iVZbm$taquerianodesdk.Option).create({
357
+ flag: "sender",
358
+ description: "Name of an instantiated account to use as the sender of the originate operation",
359
+ required: false
360
+ }),
361
+ (0, $iVZbm$taquerianodesdk.Option).create({
362
+ flag: "mutez",
363
+ description: "Amount of Mutez to transfer",
364
+ required: false
329
365
  }),
330
366
  ],
331
367
  aliases: [
@@ -340,8 +376,8 @@ var $e6ed693f861ac256$export$2e2bcd8739ae039 = $e6ed693f861ac256$export$71d25adf
340
376
  description: "Transfer/call an implicit account or a smart contract (specified via its alias or address) deployed to a particular environment",
341
377
  options: [
342
378
  (0, $iVZbm$taquerianodesdk.Option).create({
343
- flag: "tez",
344
- description: "Amount of Tez to transfer",
379
+ flag: "mutez",
380
+ description: "Amount of Mutez to transfer",
345
381
  required: false
346
382
  }),
347
383
  (0, $iVZbm$taquerianodesdk.Option).create({
@@ -353,6 +389,11 @@ var $e6ed693f861ac256$export$2e2bcd8739ae039 = $e6ed693f861ac256$export$71d25adf
353
389
  flag: "entrypoint",
354
390
  description: "You may explicitly specify an entrypoint to make the parameter value shorter, without having to specify a chain of (Left (Right ... 14 ...))",
355
391
  required: false
392
+ }),
393
+ (0, $iVZbm$taquerianodesdk.Option).create({
394
+ flag: "sender",
395
+ description: "Name of an instantiated account to use as the sender of the transfer operation",
396
+ required: false
356
397
  }),
357
398
  ],
358
399
  aliases: [
@@ -360,6 +401,20 @@ var $e6ed693f861ac256$export$2e2bcd8739ae039 = $e6ed693f861ac256$export$71d25adf
360
401
  ],
361
402
  handler: "proxy",
362
403
  encoding: "application/json"
404
+ }),
405
+ (0, $iVZbm$taquerianodesdk.Task).create({
406
+ task: "fund",
407
+ command: "fund",
408
+ description: "Fund all the instantiated accounts up to the desired/declared amount in a target environment",
409
+ handler: "proxy",
410
+ encoding: "application/json"
411
+ }),
412
+ (0, $iVZbm$taquerianodesdk.Task).create({
413
+ task: "instantiate-account",
414
+ command: "instantiate-account",
415
+ description: 'Instantiate all accounts declared in the "accounts" field at the root level of the config file to a target environment',
416
+ handler: "proxy",
417
+ encoding: "application/json"
363
418
  }),
364
419
  ],
365
420
  proxy: (0, $e6ed693f861ac256$export$2e2bcd8739ae039)