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

Signature price #782

Merged
merged 2 commits into from
Jul 31, 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
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
Loading