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

feat(cycles-minting): Cycles Minting canister refunds automatically. #3484

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rs/nns/cmc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DEV_DEPENDENCIES = [
"//rs/types/types_test_utils",
"@crate_index//:candid_parser",
"@crate_index//:futures",
"@crate_index//:maplit",
"@crate_index//:serde_bytes",
]

Expand Down
1 change: 1 addition & 0 deletions rs/nns/cmc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ yansi = "0.5.0"

[dev-dependencies]
candid_parser = { workspace = true }
maplit = "1.0.2"
futures = { workspace = true }
ic-types-test-utils = { path = "../../types/types_test_utils" }
serde_bytes = { workspace = true }
Expand Down
15 changes: 15 additions & 0 deletions rs/nns/cmc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use icp_ledger::{
use icrc_ledger_types::icrc1::account::Account;
use serde::{Deserialize, Serialize};

pub const IS_AUTOMATIC_REFUND_ENABLED: bool = false;

pub const DEFAULT_CYCLES_PER_XDR: u128 = 1_000_000_000_000u128; // 1T cycles = 1 XDR

pub const PERMYRIAD_DECIMAL_PLACES: u32 = 4;
Expand Down Expand Up @@ -313,10 +315,23 @@ pub struct CyclesLedgerDepositResult {
pub block_index: Nat,
}

// When a user sends us ICP, they indicate via memo (or icrc1_memo) what
// operation they want to perform.
//
// We promise that we will NEVER use 0 as one of these values. (This would be
// very bad, because if no memo is explicitly supplied, the Transaction might
// implicitly have 0 in the memo field.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it be bad, though?

//
// Note to developers: If you add new values, update MEANINGFUL_MEMOS.
pub const MEMO_CREATE_CANISTER: Memo = Memo(0x41455243); // == 'CREA'
pub const MEMO_TOP_UP_CANISTER: Memo = Memo(0x50555054); // == 'TPUP'
pub const MEMO_MINT_CYCLES: Memo = Memo(0x544e494d); // == 'MINT'

// New values might be added to this later. Do NOT assume that values won't be
// added to this array later.
pub const MEANINGFUL_MEMOS: [Memo; 3] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use lazy_static to define these values in a hash map?

Something like

lazy_static! {
    RESERVED_MEMOS: BTreeMap<String, Memo> = btreemap! {
        "CREATE_CANISTER".to_string() => Memo(0x41455243),
        // ...
    };
}

[MEMO_CREATE_CANISTER, MEMO_TOP_UP_CANISTER, MEMO_MINT_CYCLES];

pub fn create_canister_txn(
amount: Tokens,
from_subaccount: Option<Subaccount>,
Expand Down
Loading
Loading