Skip to content

Commit e897bdc

Browse files
committed
minter client api update
1 parent 8cc8bb9 commit e897bdc

2 files changed

Lines changed: 9 additions & 152 deletions

File tree

src/minter-client/src/lib.rs

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use candid::{Nat, Principal};
1+
use candid::Principal;
22
use did::build::BuildData;
33
use did::H160;
44
use ic_canister_client::{CanisterClient, CanisterClientResult};
55
use minter_did::error::Result as McResult;
66
use minter_did::id256::Id256;
7-
use minter_did::init::OperationPricing;
87
use minter_did::order::SignedMintOrder;
98
use minter_did::reason::Icrc2Burn;
109

@@ -84,40 +83,12 @@ impl<C: CanisterClient> MinterCanisterClient<C> {
8483
.await
8584
}
8685

87-
/// Returns operation points number of the user.
88-
pub async fn get_user_operation_points(
89-
&self,
90-
user: Option<Principal>,
91-
) -> CanisterClientResult<u32> {
92-
self.client
93-
.query("get_user_operation_points", (user,))
94-
.await
95-
}
96-
97-
/// Returns operations pricing.
98-
/// This method is available for canister owner only.
99-
pub async fn set_operation_pricing(
100-
&mut self,
101-
pricing: OperationPricing,
102-
) -> CanisterClientResult<McResult<()>> {
103-
self.client
104-
.update("set_operation_pricing", (pricing,))
105-
.await
106-
}
107-
108-
/// Returns operation pricing.
109-
pub async fn get_operation_pricing(&self) -> CanisterClientResult<OperationPricing> {
110-
self.client.query("get_operation_pricing", ()).await
111-
}
112-
11386
/// Creates ERC-20 mint order for ICRC-2 tokens burning.
114-
pub async fn create_erc_20_mint_order(
87+
pub async fn burn_icrc2(
11588
&self,
11689
reason: Icrc2Burn,
11790
) -> CanisterClientResult<McResult<SignedMintOrder>> {
118-
self.client
119-
.update("create_erc_20_mint_order", (reason,))
120-
.await
91+
self.client.update("burn_icrc2", (reason,)).await
12192
}
12293

12394
/// Returns `(nonce, mint_order)` pairs for the given sender id.
@@ -131,39 +102,15 @@ impl<C: CanisterClient> MinterCanisterClient<C> {
131102
.await
132103
}
133104

134-
/// Approves ICRC-2 token transfer from minter canister to recepient.
135-
/// Returns approved amount.
136-
///
137-
/// # Arguments
138-
/// - `user` is an address of wallet which has been used for Wrapped token burning.
139-
/// - `operation_id` is an ID retuned by `BFTBridge::burn()` operation.
140-
pub async fn start_icrc2_mint(
141-
&self,
142-
user: &H160,
143-
operation_id: u32,
144-
) -> CanisterClientResult<McResult<Nat>> {
145-
self.client
146-
.update("start_icrc2_mint", (user, operation_id))
147-
.await
148-
}
149-
150-
/// Transfers ICRC-2 tokens from minter canister to recepient.
151-
///
152-
/// Before it can be used, ICRC-2 token must be approved by `start_icrc2_mint` which approves the transfer.
153-
/// After the approval, user should finalize Wrapped token burning, using `BFTBridge::finish_burn()`.
154-
pub async fn finish_icrc2_mint(
105+
/// Returns mint order for the given parameters.
106+
pub async fn get_mint_order(
155107
&self,
108+
sender: Id256,
109+
src_token: Id256,
156110
operation_id: u32,
157-
address: &H160,
158-
icrc2_token: Principal,
159-
recipient: Principal,
160-
amount: Nat,
161-
) -> CanisterClientResult<McResult<Nat>> {
111+
) -> CanisterClientResult<Option<SignedMintOrder>> {
162112
self.client
163-
.update(
164-
"finish_icrc2_mint",
165-
(operation_id, address, icrc2_token, recipient, amount),
166-
)
113+
.query("get_mint_order", (sender, src_token, operation_id))
167114
.await
168115
}
169116

src/minter-did/src/init.rs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
use std::borrow::Cow;
2-
use std::mem::size_of;
3-
41
use candid::{CandidType, Principal};
5-
use did::codec::ByteChunkReader;
62
use eth_signer::sign_strategy::SigningStrategy;
73
use ic_log::LogSettings;
8-
use ic_stable_structures::{Bound, Storable};
94
use serde::Deserialize;
105

116
/// Minter canister initialization data.
@@ -27,88 +22,3 @@ pub struct InitData {
2722
#[serde(default)]
2823
pub log_settings: Option<LogSettings>,
2924
}
30-
31-
#[derive(Debug, PartialEq, Eq, Copy, Clone, CandidType, Deserialize, serde::Serialize)]
32-
pub struct OperationPricing {
33-
pub evmc_notification: u32,
34-
pub evm_registration: u32,
35-
pub icrc_mint_approval: u32,
36-
pub icrc_transfer: u32,
37-
pub erc20_mint: u32,
38-
pub endpoint_query: u32,
39-
}
40-
41-
impl Default for OperationPricing {
42-
fn default() -> Self {
43-
Self {
44-
evmc_notification: 8,
45-
evm_registration: 1,
46-
icrc_mint_approval: 1,
47-
icrc_transfer: 1,
48-
erc20_mint: 1,
49-
endpoint_query: 1,
50-
}
51-
}
52-
}
53-
54-
impl OperationPricing {
55-
pub const STORABLE_BYTE_SIZE: usize = size_of::<u32>() * 6;
56-
}
57-
58-
impl Storable for OperationPricing {
59-
fn to_bytes(&self) -> Cow<'_, [u8]> {
60-
let mut buf = Vec::with_capacity(Self::STORABLE_BYTE_SIZE);
61-
buf.extend_from_slice(&self.evmc_notification.to_be_bytes());
62-
buf.extend_from_slice(&self.evm_registration.to_be_bytes());
63-
buf.extend_from_slice(&self.icrc_mint_approval.to_be_bytes());
64-
buf.extend_from_slice(&self.icrc_transfer.to_be_bytes());
65-
buf.extend_from_slice(&self.erc20_mint.to_be_bytes());
66-
buf.extend_from_slice(&self.endpoint_query.to_be_bytes());
67-
buf.into()
68-
}
69-
70-
fn from_bytes(bytes: Cow<'_, [u8]>) -> Self {
71-
let mut reader = ByteChunkReader::new(&bytes);
72-
let evmc_notification = u32::from_be_bytes(*reader.read_slice());
73-
let evm_registration = u32::from_be_bytes(*reader.read_slice());
74-
let icrc_mint_approval = u32::from_be_bytes(*reader.read_slice());
75-
let icrc_transfer = u32::from_be_bytes(*reader.read_slice());
76-
let erc20_mint = u32::from_be_bytes(*reader.read_slice());
77-
let endpoint_query = u32::from_be_bytes(*reader.read_slice());
78-
Self {
79-
evmc_notification,
80-
evm_registration,
81-
icrc_mint_approval,
82-
icrc_transfer,
83-
erc20_mint,
84-
endpoint_query,
85-
}
86-
}
87-
88-
const BOUND: Bound = Bound::Bounded {
89-
max_size: Self::STORABLE_BYTE_SIZE as _,
90-
is_fixed_size: true,
91-
};
92-
}
93-
94-
#[cfg(test)]
95-
mod tests {
96-
use super::*;
97-
98-
#[test]
99-
fn operation_pricing_storable_roundtrip() {
100-
let operation_pricing = OperationPricing {
101-
evmc_notification: rand::random(),
102-
evm_registration: rand::random(),
103-
icrc_mint_approval: rand::random(),
104-
icrc_transfer: rand::random(),
105-
erc20_mint: rand::random(),
106-
endpoint_query: rand::random(),
107-
};
108-
109-
let bytes = operation_pricing.to_bytes();
110-
let decoded = OperationPricing::from_bytes(bytes);
111-
112-
assert_eq!(operation_pricing, decoded);
113-
}
114-
}

0 commit comments

Comments
 (0)