diff --git a/CHANGELOG.md b/CHANGELOG.md index bb08cd9e..706e460a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Support `NervousSystemParameters.automatically_advance_target_version` in `@dfinity/sns`. - Add converters to encode or decode base64 string into Uint8Array. +- Support `neuron_subaccounts` in `list_neurons` from `@dfinity/nns`. # 2025.01.20-1800Z diff --git a/packages/nns/README.md b/packages/nns/README.md index c96f15db..c3411102 100644 --- a/packages/nns/README.md +++ b/packages/nns/README.md @@ -173,7 +173,7 @@ Parameters: ### :factory: GovernanceCanister -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L91) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L92) #### Methods @@ -217,7 +217,7 @@ Parameters: | -------- | ------------------------------------------------------------- | | `create` | `(options?: GovernanceCanisterOptions) => GovernanceCanister` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L106) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L107) ##### :gear: listNeurons @@ -230,11 +230,11 @@ it is fetched using a query call. The backend treats `includeEmptyNeurons` as false if absent. -| Method | Type | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `listNeurons` | `({ certified, neuronIds, includeEmptyNeurons, includePublicNeurons, }: { certified: boolean; neuronIds?: bigint[] or undefined; includeEmptyNeurons?: boolean or undefined; includePublicNeurons?: boolean or undefined; }) => Promise` | +| Method | Type | +| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `listNeurons` | `({ certified, neuronIds, includeEmptyNeurons, includePublicNeurons, neuronSubaccounts, }: { certified: boolean; neuronIds?: bigint[] or undefined; includeEmptyNeurons?: boolean or undefined; includePublicNeurons?: boolean or undefined; neuronSubaccounts?: NeuronSubaccount[] or undefined; }) => Promise<...>` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L146) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L147) ##### :gear: listKnownNeurons @@ -248,7 +248,7 @@ it is fetched using a query call. | ------------------ | ------------------------------------------------- | | `listKnownNeurons` | `(certified?: boolean) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L189) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L193) ##### :gear: getLastestRewardEvent @@ -261,7 +261,7 @@ it's fetched using a query call. | ----------------------- | ----------------------------------------------- | | `getLastestRewardEvent` | `(certified?: boolean) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L211) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L215) ##### :gear: listProposals @@ -280,7 +280,7 @@ Parameters: - `request`: the options to list the proposals (limit number of results, topics to search for, etc.) - `certified`: query or update calls -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L227) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L231) ##### :gear: stakeNeuron @@ -288,7 +288,7 @@ Parameters: | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `stakeNeuron` | `({ stake, principal, fromSubAccount, ledgerCanister, createdAt, fee, }: { stake: bigint; principal: Principal; fromSubAccount?: number[] or undefined; ledgerCanister: LedgerCanister; createdAt?: bigint or undefined; fee?: bigint or undefined; }) => Promise<...>` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L246) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L250) ##### :gear: increaseDissolveDelay @@ -298,7 +298,7 @@ Increases dissolve delay of a neuron | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | `increaseDissolveDelay` | `({ neuronId, additionalDissolveDelaySeconds, }: { neuronId: bigint; additionalDissolveDelaySeconds: number; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L307) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L311) ##### :gear: setDissolveDelay @@ -309,7 +309,7 @@ The new date is now + dissolveDelaySeconds. | ------------------ | ------------------------------------------------------------------------------------------------------------- | | `setDissolveDelay` | `({ neuronId, dissolveDelaySeconds, }: { neuronId: bigint; dissolveDelaySeconds: number; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L333) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L337) ##### :gear: startDissolving @@ -319,7 +319,7 @@ Start dissolving process of a neuron | ----------------- | ------------------------------------- | | `startDissolving` | `(neuronId: bigint) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L356) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L360) ##### :gear: stopDissolving @@ -329,7 +329,7 @@ Stop dissolving process of a neuron | ---------------- | ------------------------------------- | | `stopDissolving` | `(neuronId: bigint) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L370) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L374) ##### :gear: joinCommunityFund @@ -339,7 +339,7 @@ Neuron joins the community fund | ------------------- | ------------------------------------- | | `joinCommunityFund` | `(neuronId: bigint) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L384) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L388) ##### :gear: autoStakeMaturity @@ -354,7 +354,7 @@ Parameters: - `neuronId`: The id of the neuron for which to request a change of the auto stake feature - `autoStake`: `true` to enable the auto-stake maturity for this neuron, `false` to turn it off -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L402) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L406) ##### :gear: leaveCommunityFund @@ -364,7 +364,7 @@ Neuron leaves the community fund | -------------------- | ------------------------------------- | | `leaveCommunityFund` | `(neuronId: bigint) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L417) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L421) ##### :gear: setVisibility @@ -374,7 +374,7 @@ Set visibility of a neuron | --------------- | ------------------------------------------------------------------- | | `setVisibility` | `(neuronId: bigint, visibility: NeuronVisibility) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L431) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L435) ##### :gear: setNodeProviderAccount @@ -385,7 +385,7 @@ Where the reward is paid to. | ------------------------ | ---------------------------------------------- | | `setNodeProviderAccount` | `(accountIdentifier: string) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L451) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L455) ##### :gear: mergeNeurons @@ -395,7 +395,7 @@ Merge two neurons | -------------- | --------------------------------------------------------------------------------- | | `mergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L471) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L475) ##### :gear: simulateMergeNeurons @@ -405,7 +405,7 @@ Simulate merging two neurons | ---------------------- | --------------------------------------------------------------------------------------- | | `simulateMergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L488) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L492) ##### :gear: splitNeuron @@ -415,7 +415,7 @@ Splits a neuron creating a new one | ------------- | ----------------------------------------------------------------------------------- | | `splitNeuron` | `({ neuronId, amount, }: { neuronId: bigint; amount: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L533) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L537) ##### :gear: getProposal @@ -428,7 +428,7 @@ it is fetched using a query call. | ------------- | ------------------------------------------------------------------------------------------------------------------------------- | | `getProposal` | `({ proposalId, certified, }: { proposalId: bigint; certified?: boolean or undefined; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L573) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L577) ##### :gear: makeProposal @@ -438,7 +438,7 @@ Create new proposal | -------------- | ---------------------------------------------------------------- | | `makeProposal` | `(request: MakeProposalRequest) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L591) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L595) ##### :gear: registerVote @@ -448,7 +448,7 @@ Registers vote for a proposal from the neuron passed. | -------------- | ----------------------------------------------------------------------------------------------------------- | | `registerVote` | `({ neuronId, vote, proposalId, }: { neuronId: bigint; vote: Vote; proposalId: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L612) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L616) ##### :gear: setFollowees @@ -458,7 +458,7 @@ Edit neuron followees per topic | -------------- | ------------------------------------------------- | | `setFollowees` | `(followRequest: FollowRequest) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L634) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L638) ##### :gear: disburse @@ -468,7 +468,7 @@ Disburse neuron on Account | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `disburse` | `({ neuronId, toAccountId, amount, }: { neuronId: bigint; toAccountId?: string or undefined; amount?: bigint or undefined; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L649) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L653) ##### :gear: refreshVotingPower @@ -480,7 +480,7 @@ parameter of the neuron to the current time). | -------------------- | --------------------------------------------------------- | | `refreshVotingPower` | `({ neuronId, }: { neuronId: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L685) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L689) ##### :gear: mergeMaturity @@ -490,7 +490,7 @@ Merge Maturity of a neuron | --------------- | ------------------------------------------------------------------------------------------------------- | | `mergeMaturity` | `({ neuronId, percentageToMerge, }: { neuronId: bigint; percentageToMerge: number; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L707) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L711) ##### :gear: stakeMaturity @@ -505,7 +505,7 @@ Parameters: - `neuronId`: The id of the neuron for which to stake the maturity - `percentageToStake`: Optional. Percentage of the current maturity to stake. If not provided, all of the neuron's current maturity will be staked. -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L736) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L740) ##### :gear: spawnNeuron @@ -515,7 +515,7 @@ Merge Maturity of a neuron | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `spawnNeuron` | `({ neuronId, percentageToSpawn, newController, nonce, }: { neuronId: bigint; percentageToSpawn?: number or undefined; newController?: Principal or undefined; nonce?: bigint or undefined; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L758) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L762) ##### :gear: addHotkey @@ -525,7 +525,7 @@ Add hotkey to neuron | ----------- | ------------------------------------------------------------------------------------------ | | `addHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L805) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L809) ##### :gear: removeHotkey @@ -535,7 +535,7 @@ Remove hotkey to neuron | -------------- | ------------------------------------------------------------------------------------------ | | `removeHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L825) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L829) ##### :gear: claimOrRefreshNeuronFromAccount @@ -545,7 +545,7 @@ Gets the NeuronID of a newly created neuron. | --------------------------------- | ----------------------------------------------------------------------------------------------------------------- | | `claimOrRefreshNeuronFromAccount` | `({ memo, controller, }: { memo: bigint; controller?: Principal or undefined; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L843) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L847) ##### :gear: claimOrRefreshNeuron @@ -556,7 +556,7 @@ Uses query call only. | ---------------------- | ------------------------------------------------------------------------ | | `claimOrRefreshNeuron` | `(request: ClaimOrRefreshNeuronRequest) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L874) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L878) ##### :gear: getNeuron @@ -566,7 +566,7 @@ Return the data of the neuron provided as id. | ----------- | ----------------------------------------------------------------------------------------------------------- | | `getNeuron` | `({ certified, neuronId, }: { certified: boolean; neuronId: bigint; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L899) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L903) ##### :gear: getNetworkEconomicsParameters @@ -576,7 +576,7 @@ Return the [Network Economics](https://github.com/dfinity/ic/blob/d90e934eb440c7 | ------------------------------- | ------------------------------------------------------------------------ | | `getNetworkEconomicsParameters` | `({ certified, }: { certified: boolean; }) => Promise` | -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L920) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L924) ### :factory: SnsWasmCanister diff --git a/packages/nns/src/canisters/governance/request.converters.ts b/packages/nns/src/canisters/governance/request.converters.ts index 4ced7f8b..5f930fcc 100644 --- a/packages/nns/src/canisters/governance/request.converters.ts +++ b/packages/nns/src/canisters/governance/request.converters.ts @@ -13,6 +13,7 @@ import { import type { Amount, ListProposalInfo, + NeuronSubaccount, AccountIdentifier as RawAccountIdentifier, ProposalActionRequest as RawAction, By as RawBy, @@ -1017,10 +1018,12 @@ export const fromListNeurons = ({ neuronIds, includeEmptyNeurons, includePublicNeurons, + neuronSubaccounts, }: { neuronIds?: NeuronId[]; includeEmptyNeurons?: boolean; includePublicNeurons?: boolean; + neuronSubaccounts?: NeuronSubaccount[]; }): RawListNeurons => ({ neuron_ids: BigUint64Array.from(neuronIds ?? []), include_neurons_readable_by_caller: neuronIds ? false : true, @@ -1028,6 +1031,7 @@ export const fromListNeurons = ({ include_public_neurons_in_full_neurons: toNullable(includePublicNeurons), page_number: [], page_size: [], + neuron_subaccounts: toNullable(neuronSubaccounts), }); export const fromManageNeuron = ({ diff --git a/packages/nns/src/governance.canister.spec.ts b/packages/nns/src/governance.canister.spec.ts index 2229c3fb..3dfb3468 100644 --- a/packages/nns/src/governance.canister.spec.ts +++ b/packages/nns/src/governance.canister.spec.ts @@ -451,6 +451,7 @@ describe("GovernanceCanister", () => { include_public_neurons_in_full_neurons: [true], page_number: [], page_size: [], + neuron_subaccounts: [], }); expect(certifiedService.list_neurons).toBeCalledTimes(1); expect(neurons.length).toBe(1); @@ -479,6 +480,7 @@ describe("GovernanceCanister", () => { include_public_neurons_in_full_neurons: [], page_number: [], page_size: [], + neuron_subaccounts: [], }); expect(service.list_neurons).toBeCalledTimes(1); expect(neurons.length).toBe(1); @@ -505,6 +507,44 @@ describe("GovernanceCanister", () => { include_public_neurons_in_full_neurons: [false], page_number: [], page_size: [], + neuron_subaccounts: [], + }); + expect(service.list_neurons).toBeCalledTimes(1); + expect(neurons.length).toBe(1); + }); + + it("list user neurons by neurons sub-account", async () => { + const service = mock>(); + const oldService = mock>(); + service.list_neurons.mockResolvedValue(mockListNeuronsResponse); + + const governance = GovernanceCanister.create({ + certifiedServiceOverride: service, + serviceOverride: service, + oldListNeuronsServiceOverride: oldService, + }); + const neurons = await governance.listNeurons({ + certified: true, + includeEmptyNeurons: true, + includePublicNeurons: true, + neuronSubaccounts: [ + { subaccount: new Uint8Array([1, 2, 3]) }, + { subaccount: new Uint8Array([4, 5, 6]) }, + ], + }); + expect(service.list_neurons).toBeCalledWith({ + neuron_ids: new BigUint64Array(), + include_neurons_readable_by_caller: true, + include_empty_neurons_readable_by_caller: [true], + include_public_neurons_in_full_neurons: [true], + page_number: [], + page_size: [], + neuron_subaccounts: [ + [ + { subaccount: new Uint8Array([1, 2, 3]) }, + { subaccount: new Uint8Array([4, 5, 6]) }, + ], + ], }); expect(service.list_neurons).toBeCalledTimes(1); expect(neurons.length).toBe(1); @@ -534,6 +574,8 @@ describe("GovernanceCanister", () => { page_number: [], // The field is present in the argument but ignored by the old service. page_size: [], + // The field is present in the argument but ignored by the old service. + neuron_subaccounts: [], }); expect(oldService.list_neurons).toBeCalledTimes(1); expect(neurons.length).toBe(1); @@ -561,6 +603,7 @@ describe("GovernanceCanister", () => { include_public_neurons_in_full_neurons: [], page_number: [], page_size: [], + neuron_subaccounts: [], }); expect(service.list_neurons).toBeCalledTimes(1); expect(neurons.length).toBe(1); diff --git a/packages/nns/src/governance.canister.ts b/packages/nns/src/governance.canister.ts index 382ef381..b59e4b90 100644 --- a/packages/nns/src/governance.canister.ts +++ b/packages/nns/src/governance.canister.ts @@ -17,6 +17,7 @@ import type { _SERVICE as GovernanceService, ListProposalInfo, MergeResponse, + NeuronSubaccount, Neuron as RawNeuron, NeuronInfo as RawNeuronInfo, ProposalInfo as RawProposalInfo, @@ -148,16 +149,19 @@ export class GovernanceCanister { neuronIds, includeEmptyNeurons, includePublicNeurons, + neuronSubaccounts, }: { certified: boolean; neuronIds?: NeuronId[]; includeEmptyNeurons?: boolean; includePublicNeurons?: boolean; + neuronSubaccounts?: NeuronSubaccount[]; }): Promise => { const rawRequest = fromListNeurons({ neuronIds, includeEmptyNeurons, includePublicNeurons, + neuronSubaccounts, }); // The Ledger app version 2.4.9 does not support // include_empty_neurons_readable_by_caller nor include_public_neurons_in_full_neurons,