-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicp-ledger.ts
71 lines (61 loc) · 2.15 KB
/
icp-ledger.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
import {IDL} from '@dfinity/candid';
import {AccountIdentifier} from '@dfinity/ledger-icp';
import {MAIN_IDENTITY_KEY, MINTER_IDENTITY_KEY} from '../constants/constants';
import {init} from '../declarations/icp_ledger.idl';
import {Module} from '../services/modules.services';
import type {ModuleDescription, ModuleInstallParams} from '../types/module';
export const ICP_LEDGER_CANISTER_ID = 'ryjl3-tyaaa-aaaaa-aaaba-cai';
const ICP_LEDGER: ModuleDescription = {
key: 'icp_ledger',
name: 'ICP Ledger',
canisterId: ICP_LEDGER_CANISTER_ID
};
class IcpLedgerModule extends Module {
override async install(context: ModuleInstallParams): Promise<void> {
const {
identities: {
[MINTER_IDENTITY_KEY]: minterIdentity,
[MAIN_IDENTITY_KEY]: mainIdentity,
...otherIdentities
},
...rest
} = context;
const minterAccountIdentifier = AccountIdentifier.fromPrincipal({
principal: minterIdentity.getPrincipal()
}).toHex();
const ledgerAccountIdentifier = AccountIdentifier.fromPrincipal({
principal: mainIdentity.getPrincipal()
}).toHex();
const initArgs = {
send_whitelist: [],
token_symbol: ['ICP'],
transfer_fee: [{e8s: 10_000n}],
minting_account: minterAccountIdentifier,
maximum_number_of_accounts: [],
accounts_overflow_trim_quantity: [],
transaction_window: [],
max_message_size_bytes: [],
icrc1_minting_account: [],
archive_options: [],
initial_values: [[ledgerAccountIdentifier, {e8s: 100_000_000_000n}]],
token_name: ['Internet Computer'],
feature_flags: []
};
const upgradeArgs = [];
// Type definitions generated by Candid are not clean enough.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const arg = IDL.encode(init({IDL}), [
this.status(context) === 'deployed' ? {Upgrade: upgradeArgs} : {Init: initArgs}
]);
await super.install({
identities: {
[MINTER_IDENTITY_KEY]: minterIdentity,
[MAIN_IDENTITY_KEY]: mainIdentity,
...otherIdentities
},
...rest,
arg
});
}
}
export const icpLedger = new IcpLedgerModule(ICP_LEDGER);