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

u128 -> U128 in experimental_signature_deposit #815

Merged
merged 4 commits into from
Aug 28, 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
12 changes: 7 additions & 5 deletions chain-signatures/contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use k256::elliptic_curve::sec1::ToEncodedPoint;
use k256::Scalar;
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::LookupMap;
use near_sdk::json_types::U128;
use near_sdk::{
env, log, near_bindgen, AccountId, CryptoHash, Gas, GasWeight, NearToken, Promise,
PromiseError, PublicKey,
Expand Down Expand Up @@ -134,7 +135,7 @@ impl VersionedMpcContract {
}
// Check deposit
let deposit = env::attached_deposit();
let required_deposit = self.experimental_signature_deposit();
let required_deposit: u128 = self.experimental_signature_deposit().into();
if deposit.as_yoctonear() < required_deposit {
return Err(InvalidParameters::InsufficientDeposit.message(format!(
"Attached {}, Required {}",
Expand Down Expand Up @@ -217,16 +218,17 @@ impl VersionedMpcContract {
/// This experimental function calculates the fee for a signature request.
/// The fee is volatile and depends on the number of pending requests.
/// If used on a client side, it can give outdate results.
pub fn experimental_signature_deposit(&self) -> u128 {
pub fn experimental_signature_deposit(&self) -> U128 {
const CHEAP_REQUESTS: u32 = 3;
let pending_requests = match self {
Self::V0(mpc_contract) => mpc_contract.request_counter,
};
match pending_requests {
0..=CHEAP_REQUESTS => 1,
0..=CHEAP_REQUESTS => U128::from(1),
_ => {
(pending_requests - CHEAP_REQUESTS) as u128
* NearToken::from_millinear(50).as_yoctonear()
let expensive_requests = (pending_requests - CHEAP_REQUESTS) as u128;
let price = expensive_requests * NearToken::from_millinear(50).as_yoctonear();
U128::from(price)
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions chain-signatures/contract/tests/user_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ async fn test_experimental_signature_deposit() -> anyhow::Result<()> {
.view("experimental_signature_deposit")
.await
.unwrap()
.json()
.unwrap();
assert_eq!(deposit, 1u128);
.json::<String>()
.unwrap()
.parse()?;
assert_eq!(deposit, 1);

let alice = worker.dev_create_account().await?;
let path = "test";
Expand Down Expand Up @@ -92,8 +93,9 @@ async fn test_experimental_signature_deposit() -> anyhow::Result<()> {
.view("experimental_signature_deposit")
.await
.unwrap()
.json()
.unwrap();
.json::<String>()
.unwrap()
.parse()?;
assert_eq!(deposit, NearToken::from_millinear(50).as_yoctonear());
Ok(())
}
Loading