Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused stakeNeuronIcrc1 #742

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2024.xx.yy-hhmmZ

# Breaking changes

- Remove `stakeNeuronIcrc1`.

# 2024.10.29-1130Z

## Overview
Expand Down
59 changes: 25 additions & 34 deletions packages/nns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ Parameters:
- [getLastestRewardEvent](#gear-getlastestrewardevent)
- [listProposals](#gear-listproposals)
- [stakeNeuron](#gear-stakeneuron)
- [stakeNeuronIcrc1](#gear-stakeneuronicrc1)
- [increaseDissolveDelay](#gear-increasedissolvedelay)
- [setDissolveDelay](#gear-setdissolvedelay)
- [startDissolving](#gear-startdissolving)
Expand Down Expand Up @@ -271,14 +270,6 @@ Parameters:

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L249)

##### :gear: stakeNeuronIcrc1

| Method | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stakeNeuronIcrc1` | `({ stake, principal, fromSubAccount, ledgerCanister, createdAt, fee, }: { stake: bigint; principal: Principal; fromSubAccount?: Uint8Array 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#L315)

##### :gear: increaseDissolveDelay

Increases dissolve delay of a neuron
Expand All @@ -287,7 +278,7 @@ Increases dissolve delay of a neuron
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `increaseDissolveDelay` | `({ neuronId, additionalDissolveDelaySeconds, }: { neuronId: bigint; additionalDissolveDelaySeconds: number; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L380)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L310)

##### :gear: setDissolveDelay

Expand All @@ -298,7 +289,7 @@ The new date is now + dissolveDelaySeconds.
| ------------------ | ------------------------------------------------------------------------------------------------------------- |
| `setDissolveDelay` | `({ neuronId, dissolveDelaySeconds, }: { neuronId: bigint; dissolveDelaySeconds: number; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L406)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L336)

##### :gear: startDissolving

Expand All @@ -308,7 +299,7 @@ Start dissolving process of a neuron
| ----------------- | ------------------------------------- |
| `startDissolving` | `(neuronId: bigint) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L429)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L359)

##### :gear: stopDissolving

Expand All @@ -318,7 +309,7 @@ Stop dissolving process of a neuron
| ---------------- | ------------------------------------- |
| `stopDissolving` | `(neuronId: bigint) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L443)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L373)

##### :gear: joinCommunityFund

Expand All @@ -328,7 +319,7 @@ Neuron joins the community fund
| ------------------- | ------------------------------------- |
| `joinCommunityFund` | `(neuronId: bigint) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L457)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L387)

##### :gear: autoStakeMaturity

Expand All @@ -343,7 +334,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#L475)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L405)

##### :gear: leaveCommunityFund

Expand All @@ -353,7 +344,7 @@ Neuron leaves the community fund
| -------------------- | ------------------------------------- |
| `leaveCommunityFund` | `(neuronId: bigint) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L490)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L420)

##### :gear: setVisibility

Expand All @@ -363,7 +354,7 @@ Set visibility of a neuron
| --------------- | ------------------------------------------------------------------- |
| `setVisibility` | `(neuronId: bigint, visibility: NeuronVisibility) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L504)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L434)

##### :gear: setNodeProviderAccount

Expand All @@ -374,7 +365,7 @@ Where the reward is paid to.
| ------------------------ | ---------------------------------------------- |
| `setNodeProviderAccount` | `(accountIdentifier: string) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L524)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L454)

##### :gear: mergeNeurons

Expand All @@ -384,7 +375,7 @@ Merge two neurons
| -------------- | --------------------------------------------------------------------------------- |
| `mergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L544)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L474)

##### :gear: simulateMergeNeurons

Expand All @@ -394,7 +385,7 @@ Simulate merging two neurons
| ---------------------- | --------------------------------------------------------------------------------------- |
| `simulateMergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<NeuronInfo>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L561)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L491)

##### :gear: splitNeuron

Expand All @@ -404,7 +395,7 @@ Splits a neuron creating a new one
| ------------- | ----------------------------------------------------------------------------------- |
| `splitNeuron` | `({ neuronId, amount, }: { neuronId: bigint; amount: bigint; }) => Promise<bigint>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L606)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L536)

##### :gear: getProposal

Expand All @@ -417,7 +408,7 @@ it is fetched using a query call.
| ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `getProposal` | `({ proposalId, certified, }: { proposalId: bigint; certified?: boolean or undefined; }) => Promise<ProposalInfo or undefined>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L646)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L576)

##### :gear: makeProposal

Expand All @@ -427,7 +418,7 @@ Create new proposal
| -------------- | ---------------------------------------------------------------- |
| `makeProposal` | `(request: MakeProposalRequest) => Promise<bigint or undefined>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L664)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L594)

##### :gear: registerVote

Expand All @@ -437,7 +428,7 @@ Registers vote for a proposal from the neuron passed.
| -------------- | ----------------------------------------------------------------------------------------------------------- |
| `registerVote` | `({ neuronId, vote, proposalId, }: { neuronId: bigint; vote: Vote; proposalId: bigint; }) => Promise<void>` |

[: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#L615)

##### :gear: setFollowees

Expand All @@ -447,7 +438,7 @@ Edit neuron followees per topic
| -------------- | ------------------------------------------------- |
| `setFollowees` | `(followRequest: FollowRequest) => Promise<void>` |

[: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#L637)

##### :gear: disburse

Expand All @@ -457,7 +448,7 @@ Disburse neuron on Account
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `disburse` | `({ neuronId, toAccountId, amount, }: { neuronId: bigint; toAccountId?: string or undefined; amount?: bigint or undefined; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L722)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L652)

##### :gear: mergeMaturity

Expand All @@ -467,7 +458,7 @@ Merge Maturity of a neuron
| --------------- | ------------------------------------------------------------------------------------------------------- |
| `mergeMaturity` | `({ neuronId, percentageToMerge, }: { neuronId: bigint; percentageToMerge: number; }) => Promise<void>` |

[: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#L688)

##### :gear: stakeMaturity

Expand All @@ -482,7 +473,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#L787)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L717)

##### :gear: spawnNeuron

Expand All @@ -492,7 +483,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<bigint>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L809)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L739)

##### :gear: addHotkey

Expand All @@ -502,7 +493,7 @@ Add hotkey to neuron
| ----------- | ------------------------------------------------------------------------------------------ |
| `addHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L856)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L786)

##### :gear: removeHotkey

Expand All @@ -512,7 +503,7 @@ Remove hotkey to neuron
| -------------- | ------------------------------------------------------------------------------------------ |
| `removeHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L876)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L806)

##### :gear: claimOrRefreshNeuronFromAccount

Expand All @@ -522,7 +513,7 @@ Gets the NeuronID of a newly created neuron.
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `claimOrRefreshNeuronFromAccount` | `({ memo, controller, }: { memo: bigint; controller?: Principal or undefined; }) => Promise<bigint or undefined>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L894)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L824)

##### :gear: claimOrRefreshNeuron

Expand All @@ -533,7 +524,7 @@ Uses query call only.
| ---------------------- | ------------------------------------------------------------------------ |
| `claimOrRefreshNeuron` | `(request: ClaimOrRefreshNeuronRequest) => Promise<bigint or undefined>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L925)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L855)

##### :gear: getNeuron

Expand All @@ -543,7 +534,7 @@ Return the data of the neuron provided as id.
| ----------- | ----------------------------------------------------------------------------------------------------------- |
| `getNeuron` | `({ certified, neuronId, }: { certified: boolean; neuronId: bigint; }) => Promise<NeuronInfo or undefined>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L976)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L906)

### :factory: SnsWasmCanister

Expand Down
127 changes: 0 additions & 127 deletions packages/nns/src/governance.canister.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,133 +365,6 @@ describe("GovernanceCanister", () => {
});
});

describe("GovernanceCanister.stakeNeuronIcrc1", () => {
it("creates new neuron successfully", async () => {
const neuronId = BigInt(10);
const serviceResponse: ManageNeuronResponse = {
command: [
{ ClaimOrRefresh: { refreshed_neuron_id: [{ id: neuronId }] } },
],
};
const service = mock<ActorSubclass<GovernanceService>>();
service.manage_neuron.mockResolvedValue(serviceResponse);

const mockLedger = mock<LedgerCanister>();
mockLedger.icrc1Transfer.mockImplementation(
jest.fn().mockResolvedValue(BigInt(1)),
);

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
});
const response = await governance.stakeNeuronIcrc1({
stake: BigInt(100_000_000),
principal: new AnonymousIdentity().getPrincipal(),
ledgerCanister: mockLedger,
});

expect(mockLedger.icrc1Transfer).toBeCalled();
expect(service.manage_neuron).toBeCalled();
expect(response).toEqual(neuronId);
});

it("stakeNeuron passes fee to the ledger transfer", async () => {
const neuronId = BigInt(10);
const serviceResponse: ManageNeuronResponse = {
command: [
{ ClaimOrRefresh: { refreshed_neuron_id: [{ id: neuronId }] } },
],
};
const service = mock<ActorSubclass<GovernanceService>>();
service.manage_neuron.mockResolvedValue(serviceResponse);

const mockLedger = mock<LedgerCanister>();
mockLedger.icrc1Transfer.mockImplementation(
jest.fn().mockResolvedValue(BigInt(1)),
);
const fee = BigInt(10_000);

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
});
const response = await governance.stakeNeuronIcrc1({
stake: BigInt(100_000_000),
principal: new AnonymousIdentity().getPrincipal(),
ledgerCanister: mockLedger,
fee,
});

expect(mockLedger.icrc1Transfer).toBeCalledWith(
expect.objectContaining({ fee }),
);
});

it("creates new neuron from subaccount successfully", async () => {
const neuronId = BigInt(10);
const serviceResponse: ManageNeuronResponse = {
command: [
{ ClaimOrRefresh: { refreshed_neuron_id: [{ id: neuronId }] } },
],
};
const service = mock<ActorSubclass<GovernanceService>>();
service.manage_neuron.mockResolvedValue(serviceResponse);

const mockLedger = mock<LedgerCanister>();
mockLedger.icrc1Transfer.mockImplementation(
jest.fn().mockResolvedValue(BigInt(1)),
);

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
});
const response = await governance.stakeNeuronIcrc1({
stake: BigInt(100_000_000),
principal: new AnonymousIdentity().getPrincipal(),
ledgerCanister: mockLedger,
fromSubAccount: new Uint8Array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1,
]),
});

expect(mockLedger.icrc1Transfer).toBeCalled();
expect(service.manage_neuron).toBeCalled();
expect(response).toEqual(neuronId);
});

it("returns insufficient amount errors", async () => {
const neuronId = BigInt(1);
const clainNeuronResponse: ClaimOrRefreshNeuronFromAccountResponse = {
result: [{ NeuronId: { id: neuronId } }],
};
const service = mock<ActorSubclass<GovernanceService>>();
service.claim_or_refresh_neuron_from_account.mockResolvedValue(
clainNeuronResponse,
);

const mockLedger = mock<LedgerCanister>();
mockLedger.icrc1Transfer.mockImplementation(jest.fn());

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
});

const call = async () =>
await governance.stakeNeuronIcrc1({
stake: BigInt(10_000_000),
principal: new AnonymousIdentity().getPrincipal(),
ledgerCanister: mockLedger,
});

expect(mockLedger.icrc1Transfer).not.toBeCalled();
expect(service.claim_or_refresh_neuron_from_account).not.toBeCalled();

await expect(call).rejects.toThrow(
new InsufficientAmountError(BigInt(10_000_000)),
);
});
});

describe("GovernanceCanister.listNeurons", () => {
it("list user neurons", async () => {
const service = mock<ActorSubclass<GovernanceService>>();
Expand Down
Loading
Loading