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: Add get_icp_xdr_conversion_rate to mock cmc #145

Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased] - ReleaseDate

## [1.0.2] - 2024-10-28
* Added `get_icp_xdr_conversion_rate` to mock CMC
No changes to the cycles ledger. Released because a community project relies on the mock CMC and would like to have this feature available.

## [1.0.1] - 2024-08-22
* Update `ic-cdk` dependency to patch a security issue.

Expand All @@ -28,7 +32,8 @@
## [0.1.0] - 2023-07-12

<!-- next-url -->
[Unreleased]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v1.0.1...HEAD
[Unreleased]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v1.0.2...HEAD
[1.0.2]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v1.0.1...cycles-ledger-v1.0.2
[1.0.1]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v1.0.0...cycles-ledger-v1.0.1
[1.0.0]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v0.6.0...cycles-ledger-v1.0.0
[0.6.0]: https://github.com/dfinity/cycles-ledger/compare/cycles-ledger-v0.5.0...cycles-ledger-v0.6.0
Expand Down
13 changes: 13 additions & 0 deletions fake-cmc/fake-cmc.did
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ type SubnetSelection = variant {
Filter : SubnetFilter;
Subnet : record { subnet : principal };
};

type IcpXdrConversionRate = record {
timestamp_seconds : nat64;
xdr_permyriad_per_icp : nat64;
};

type IcpXdrConversionRateResponse = record {
data : IcpXdrConversionRate;
hash_tree : blob;
certificate : blob;
};

service : {
create_canister : (CmcCreateCanisterArgs) -> (CmcCreateCanisterResult);
fail_next_create_canister_with : (CmcCreateCanisterError) -> ();
last_create_canister_args : () -> (CmcCreateCanisterArgs) query;
get_icp_xdr_conversion_rate : () -> (IcpXdrConversionRateResponse) query;
};
27 changes: 27 additions & 0 deletions fake-cmc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
use candid::CandidType;
use cycles_ledger::endpoints::{CmcCreateCanisterArgs, CmcCreateCanisterError};
use ic_cdk::api::time;
use serde::Deserialize;

const NANOSECONDS_PER_SECOND: u64 = 1_000_000_000;

#[derive(Debug, Deserialize, Eq, PartialEq, Default)]
pub struct State {
pub last_create_canister_args: Option<CmcCreateCanisterArgs>,
pub fail_next_create_canister_with: Option<CmcCreateCanisterError>,
}

#[derive(CandidType, Deserialize, Default)]
pub struct IcpXdrConversionRateResponse {
pub certificate: Vec<u8>,
pub data: IcpXdrConversionRate,
pub hash_tree: Vec<u8>,
}

#[derive(CandidType, Deserialize)]
pub struct IcpXdrConversionRate {
pub xdr_permyriad_per_icp: u64,
pub timestamp_seconds: u64,
}

impl Default for IcpXdrConversionRate {
fn default() -> Self {
Self {
// mocked value
xdr_permyriad_per_icp: 50_000,
timestamp_seconds: time() / NANOSECONDS_PER_SECOND,
}
}
}
8 changes: 7 additions & 1 deletion fake-cmc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use candid::{candid_method, Principal};
use core::panic;
use cycles_ledger::endpoints::{CmcCreateCanisterArgs, CmcCreateCanisterError};
use fake_cmc::State;
use fake_cmc::{IcpXdrConversionRateResponse, State};
use ic_cdk::{
api::{
call::{msg_cycles_accept128, msg_cycles_available128},
Expand Down Expand Up @@ -75,6 +75,12 @@ fn fail_next_create_canister_with(error: CmcCreateCanisterError) {
STATE.with(|s| s.borrow_mut().fail_next_create_canister_with = Some(error))
}

#[candid_method]
#[query]
fn get_icp_xdr_conversion_rate() -> IcpXdrConversionRateResponse {
Default::default()
}

#[candid_method]
#[query]
fn last_create_canister_args() -> CmcCreateCanisterArgs {
Expand Down
Loading