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

Rename ICRC-1 memo to icrc1Memo #425

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 11 additions & 6 deletions packages/ledger/src/converters/ledger.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import type {
TransferParams,
} from "../types/ledger.params";

// WARNING: When using the ICRC-1 interface of the ICP ledger, there is no
// relationship between the memo and the icrc1Memo of a transaction. The ICRC-1
// interface simply cannot set the memo field and the non-ICRC-1 interface
// cannot set the icrc1Memo field, even though the icrc1Memo field is called
// just "memo" in canister method params.
export const toTransferArg = ({
from_subaccount,
fee,
created_at_time,
memo,
icrc1Memo,
...rest
}: TransferParams): TransferArg => ({
...rest,
fee: toNullable(fee),
memo: toNullable(memo),
memo: toNullable(icrc1Memo),
from_subaccount: toNullable(from_subaccount),
created_at_time: toNullable(created_at_time),
});
Expand All @@ -28,28 +33,28 @@ export const toTransferFromArgs = ({
spender_subaccount,
fee,
created_at_time,
memo,
icrc1Memo,
...rest
}: TransferFromParams): TransferFromArgs => ({
...rest,
fee: toNullable(fee),
memo: toNullable(memo),
memo: toNullable(icrc1Memo),
spender_subaccount: toNullable(spender_subaccount),
created_at_time: toNullable(created_at_time),
});

export const toApproveArgs = ({
fee,
created_at_time,
memo,
icrc1Memo,
from_subaccount,
expected_allowance,
expires_at,
...rest
}: ApproveParams): ApproveArgs => ({
...rest,
fee: toNullable(fee),
memo: toNullable(memo),
memo: toNullable(icrc1Memo),
from_subaccount: toNullable(from_subaccount),
created_at_time: toNullable(created_at_time),
expected_allowance: toNullable(expected_allowance),
Expand Down
13 changes: 9 additions & 4 deletions packages/ledger/src/types/ledger.params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ import type { IcrcAccount } from "./ledger.responses";
*/
export type BalanceParams = IcrcAccount & QueryParams;

// WARNING: When using the ICRC-1 interface of the ICP ledger, there is no
// relationship between the memo and the icrc1Memo of a transaction. The ICRC-1
// interface simply cannot set the memo field and the non-ICRC-1 interface
// cannot set the icrc1Memo field, even though the icrc1Memo field is called
// just "memo" in canister method params.
/**
* Params to make a transfer in an ICRC-1 ledger
*
* @param {Account} to The account to transfer tokens to.
* @param {Tokens} amount The Amount of tokens to transfer.
* @param {Subaccount?} from_subaccount The subaccount to transfer tokens to.
* @param {Uint8Array?} memo Transfer memo.
* @param {Uint8Array?} icrc1Memo Transfer memo.
* @param {Timestamp?} created_at_time nanoseconds since unix epoc to trigger deduplication and avoid other issues
* See the link for more details on deduplication
* https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-1/README.md#transaction_deduplication
Expand All @@ -28,7 +33,7 @@ export type BalanceParams = IcrcAccount & QueryParams;
export interface TransferParams {
to: Account;
fee?: Tokens;
memo?: Uint8Array;
icrc1Memo?: Uint8Array;
from_subaccount?: Subaccount;
created_at_time?: Timestamp;
amount: Tokens;
Expand All @@ -41,7 +46,7 @@ export interface TransferParams {
* @param {Account} from The account to transfer tokens from.
* @param {Subaccount?} spender_subaccount A spender subaccount.
* @param {Tokens} amount The Amount of tokens to transfer.
* @param {Uint8Array?} memo Transfer memo.
* @param {Uint8Array?} icrc1Memo Transfer memo.
* @param {Timestamp?} created_at_time nanoseconds since unix epoc to trigger deduplication and avoid other issues
* @param {Tokens?} fee The fee of the transfer when it's not the default fee.
*/
Expand All @@ -56,7 +61,7 @@ export type TransferFromParams = Omit<TransferParams, "from_subaccount"> & {
* @param {Account} spender The account of the spender.
* @param {Tokens} amount The Amount of tokens to approve.
* @param {Subaccount?} from_subaccount The subaccount to transfer tokens from.
* @param {Uint8Array?} memo Transfer memo.
* @param {Uint8Array?} icrc1Memo Transfer memo.
* @param {Timestamp?} created_at_time nanoseconds since unix epoc to trigger deduplication and avoid other issues
* @param {Tokens?} fee The fee of the transfer when it's not the default fee.
* @param {Tokens?} expected_allowance The optional allowance expected. If the expected_allowance field is set, the ledger MUST ensure that the current allowance for the spender from the caller's account is equal to the given value and return the AllowanceChanged error otherwise.
Expand Down
50 changes: 25 additions & 25 deletions packages/nns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ Returns the index of the block containing the tx if it was successful.
| --------------- | ---------------------------------------------------- |
| `icrc1Transfer` | `(request: Icrc1TransferRequest) => Promise<bigint>` |

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

### :factory: GovernanceCanister

Expand Down Expand Up @@ -453,7 +453,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#L371)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L373)

##### :gear: setDissolveDelay

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

##### :gear: startDissolving

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

##### :gear: stopDissolving

Expand All @@ -484,7 +484,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#L445)

##### :gear: joinCommunityFund

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

##### :gear: autoStakeMaturity

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

##### :gear: leaveCommunityFund

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

##### :gear: setNodeProviderAccount

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

##### :gear: mergeNeurons

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

##### :gear: simulateMergeNeurons

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

##### :gear: splitNeuron

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

##### :gear: getProposal

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

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

##### :gear: makeProposal

Expand All @@ -583,7 +583,7 @@ Create new proposal
| -------------- | ------------------------------------------------- |
| `makeProposal` | `(request: MakeProposalRequest) => Promise<void>` |

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

##### :gear: registerVote

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

##### :gear: setFollowees

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

##### :gear: disburse

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

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

##### :gear: mergeMaturity

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

##### :gear: stakeMaturity

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

##### :gear: spawnNeuron

Expand All @@ -648,7 +648,7 @@ Merge Maturity of a neuron
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `spawnNeuron` | `({ neuronId, percentageToSpawn, newController, nonce, }: { neuronId: bigint; percentageToSpawn?: number; newController?: Principal; nonce?: bigint; }) => Promise<bigint>` |

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

##### :gear: addHotkey

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

##### :gear: removeHotkey

Expand All @@ -668,7 +668,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#L878)

##### :gear: claimOrRefreshNeuronFromAccount

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

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

##### :gear: claimOrRefreshNeuron

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

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

##### :gear: getNeuron

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

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

### :factory: ICP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,23 @@ export const toTransferRawRequest = ({
: [arrayOfNumberToUint8Array(fromSubAccount)],
});

// WARNING: When using the ICRC-1 interface of the ICP ledger, there is no
// relationship between the memo and the icrc1Memo of a transaction. The ICRC-1
// interface simply cannot set the memo field and the non-ICRC-1 interface
// cannot set the icrc1Memo field, even though the icrc1Memo field is called
// just "memo" in canister method params.
export const toIcrc1TransferRawRequest = ({
fromSubAccount,
to,
amount,
fee,
memo,
icrc1Memo,
createdAt,
}: Icrc1TransferRequest): Icrc1TransferRawRequest => ({
to,
fee: toNullable(fee ?? TRANSACTION_FEE),
amount,
memo: toNullable(memo),
memo: toNullable(icrc1Memo),
created_at_time: toNullable(createdAt),
from_subaccount: toNullable(fromSubAccount),
});
4 changes: 3 additions & 1 deletion packages/nns/src/governance.canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ export class GovernanceCanister {

// Send amount to the ledger.
await ledgerCanister.icrc1Transfer({
memo: nonceBytes,
// WARNING: This does not set the same memo field as the stakeNeuron
// function above and would need to be handled separately from that field.
icrc1Memo: nonceBytes,
amount: stake,
fromSubAccount,
to: {
Expand Down
Loading
Loading