|
| 1 | +import {IDL} from '@dfinity/candid'; |
| 2 | +import {GovernanceCanister, NnsFunction, type MakeProposalRequest} from '@dfinity/nns'; |
| 3 | +import {Principal} from '@dfinity/principal'; |
| 4 | +import {arrayBufferToUint8Array, createAgent} from '@dfinity/utils'; |
| 5 | +import {MAIN_IDENTITY_KEY} from '../../constants/constants'; |
| 6 | +import {NEURON_ID} from '../../constants/modules.constants'; |
| 7 | +import type {ModuleInstallParams} from '../../types/module'; |
| 8 | + |
| 9 | +export const makeAuthorizedSubnetworksProposal = async ({ |
| 10 | + identities |
| 11 | +}: Pick<ModuleInstallParams, 'identities'>) => { |
| 12 | + const {[MAIN_IDENTITY_KEY]: identity} = identities; |
| 13 | + |
| 14 | + const agent = await createAgent({ |
| 15 | + identity, |
| 16 | + host: 'http://127.0.0.1:5987', |
| 17 | + fetchRootKey: true |
| 18 | + }); |
| 19 | + |
| 20 | + const {makeProposal} = GovernanceCanister.create({ |
| 21 | + agent |
| 22 | + }); |
| 23 | + |
| 24 | + const subnetId = Principal.selfAuthenticating(arrayBufferToUint8Array(agent.rootKey)); |
| 25 | + |
| 26 | + const arg = IDL.encode( |
| 27 | + [ |
| 28 | + IDL.Record({ |
| 29 | + who: IDL.Opt(IDL.Principal), |
| 30 | + subnets: IDL.Vec(IDL.Principal) |
| 31 | + }) |
| 32 | + ], |
| 33 | + [ |
| 34 | + { |
| 35 | + who: [], |
| 36 | + subnets: [subnetId] |
| 37 | + } |
| 38 | + ] |
| 39 | + ); |
| 40 | + |
| 41 | + const request: MakeProposalRequest = { |
| 42 | + neuronId: BigInt(NEURON_ID), |
| 43 | + url: 'https://forum.dfinity.org', |
| 44 | + title: 'Authorize CMC to create canisters in subnets', |
| 45 | + summary: 'The lack of documentation makes developing anything with the CMC canister a pain.', |
| 46 | + action: { |
| 47 | + ExecuteNnsFunction: { |
| 48 | + nnsFunctionId: NnsFunction.SetAuthorizedSubnetworks, |
| 49 | + payloadBytes: arg |
| 50 | + } |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + await makeProposal(request); |
| 55 | +}; |
0 commit comments