-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-utils.js
91 lines (81 loc) · 10.8 KB
/
script-utils.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
import { $, fs } from 'zx';
import { oneLine } from 'common-tags';
import { spawnSync } from 'child_process';
function checkFilesExists(files = []) {
try {
return files.reduce((acc, cur) => fs.existsSync(cur) && acc, true);
} catch (e) {
return false;
}
};
async function zxRaw(cmd) {
const escaping = $.quote;
$.quote = (...all) => all;
const res = await $`${cmd}`;
$.quote = escaping;
return res;
};
async function restartDfxBackgroundClean () {
await $`dfx stop`;
spawnSync('dfx', ['start', '--clean', '--background'], {
detached: true,
stdio: 'ignore',
});
};
async function getCanisterId(dfxJsonName) { return `${await $`dfx canister id ${dfxJsonName}`}`.trim(); }
async function getCurrentDfxIdPrincipal() { return `${await $`dfx identity get-principal`}`.trim(); }
function uint8ArrayToCandidVec(subaccount) {
return `vec { ${subaccount.reverse().reduce((acc, cur) => `${cur}; ${acc}`, "").slice(0, -2)}};`;
}
function getICRC1TokenCanisterDfxDeploymentCmd({
mintersPrincipal,
dfxJsonIcrc1CanisterName,
tokenName,
tokenSymbol,
fee = 10
})
{
return oneLine`dfx deploy ${dfxJsonIcrc1CanisterName} --argument '(variant { Init =
record {
token_symbol = "${tokenSymbol}";
token_name = "${tokenName}";
minting_account = record { owner = principal"${mintersPrincipal}"; };
transfer_fee = ${fee};
metadata = vec { ${getLotusSvgLogo()} };
initial_balances = vec {};
archive_options = record {
num_blocks_to_archive = 2000;
trigger_threshold = 1000;
controller_id = principal"${mintersPrincipal}";
};
}
})'`;
};
const getICRC1TransferDfxCmd = ({
amount = 10000000000,
account
}) => {
const { owner, subaccount = null } = account;
const sub = subaccount ? `subaccount = opt ${uint8ArrayToCandidVec(subaccount)} ` : '';
return oneLine`dfx canister call icrc1_token_canister icrc1_transfer '(
record {
to = record {
owner = principal"${owner.toString()}";
${sub}
};
amount = ${amount};
}
)'`;
}
const getLotusSvgLogo = () => {
return `record { "icrc1:logo"; variant { Text = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj48cGF0aCBmaWxsPSIjZjA4YzAwIiBkPSJNMTkuMDIzIDQuMDAyYTMuOTk0IDMuOTk0IDAgMCAwLS40My40NGE5LjM4OSA5LjM4OSAwIDAgMC0xLjMxLTEuNjMyYTEuODQ3IDEuODQ3IDAgMCAwLTIuNjE3IDBhOS4zOSA5LjM5IDAgMCAwLTEuMjkgMS41OTdhNC4wMDYgNC4wMDYgMCAwIDAtMy42OTYtMS4zNGE0LjAxIDQuMDEgMCAwIDAtMS42MDYuNjQ0QTEzLjgxMyAxMy44MTMgMCAwIDAgMiAxNS4xODRhMTQgMTQgMCAwIDAgMTMuMTg2IDEzLjk1M2ExLjg1MiAxLjg1MiAwIDAgMCAxLjU4My4wMDNBMTQgMTQgMCAwIDAgMzAgMTUuMTM3QTEzLjggMTMuOCAwIDAgMCAyMy44OTMgMy42OWEzLjk5MyAzLjk5MyAwIDAgMC00Ljg3LjMxM1ptNS45ODYgMjAuMzYzYS44NDcuODQ3IDAgMCAxLS43ODIuNTI2YTguNDUgOC40NSAwIDAgMS0uNzM3LS4wMzJhMi4yMjcgMi4yMjcgMCAwIDEtLjE0LS4wMTdhMy4wMDQgMy4wMDQgMCAwIDAtLjEwMy0uMDE0bC0uMS0uMDEyYTYuODM1IDYuODM1IDAgMCAxLS4zNzctLjA1YTMuMTA2IDMuMTA2IDAgMCAxLS4xNzItLjAzNmwtLjEwMi0uMDIzYTYuMDI2IDYuMDI2IDAgMCAxLS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