Skip to content

Commit

Permalink
Signature price (#782)
Browse files Browse the repository at this point in the history
* experimantal_signature_deposit

* make dev eenv unstable in the description
  • Loading branch information
volovyks authored Jul 31, 2024
1 parent e7fd025 commit 9ecd806
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
10 changes: 8 additions & 2 deletions chain-signatures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ Key versions refer new versions of the root key that we may choose to generate o
pub const fn latest_key_version(&self) -> u32
```

## `experimantal_signature_deposit()`
This experimantal 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.
```rust
pub fn experimantal_signature_deposit(&self) -> u128
```

For more details check `User contract API` impl block in the [chain-signatures/contracts/src/lib.rs](./chain-signatures/contracts/src/lib.rs) file.

# Environments
Currently, we have 3 environments:
1. Mainnet: `v1.signer.near` // TODO: set when available
1. Mainnet: `v1.signer`
2. Testnet: `v1.sigenr-prod.testnet`
3. Dev: `v1.signer-dev.testnet`
3. Dev (unstable): `v1.signer-dev.testnet`

Contracts can be changed from v1 to v2, etc. Older contracts should continue functioning.
33 changes: 18 additions & 15 deletions chain-signatures/contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl VersionedMpcContract {
}
// Check deposit
let deposit = env::attached_deposit();
let required_deposit = self.signature_deposit();
let required_deposit = self.experimantal_signature_deposit();
if deposit.as_yoctonear() < required_deposit {
return Err(InvalidParameters::InsufficientDeposit.message(format!(
"Attached {}, Required {}",
Expand Down Expand Up @@ -208,6 +208,23 @@ impl VersionedMpcContract {
pub const fn latest_key_version(&self) -> u32 {
0
}

/// This experimantal 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 experimantal_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,
_ => {
(pending_requests - CHEAP_REQUESTS) as u128
* NearToken::from_millinear(50).as_yoctonear()
}
}
}
}

// Node API
Expand Down Expand Up @@ -769,20 +786,6 @@ impl VersionedMpcContract {
}
}

fn 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,
_ => {
(pending_requests - CHEAP_REQUESTS) as u128
* NearToken::from_millinear(50).as_yoctonear()
}
}
}

fn threshold(&self) -> Result<usize, Error> {
match self {
Self::V0(contract) => match &contract.protocol_state {
Expand Down

0 comments on commit 9ecd806

Please sign in to comment.