use serde::{Deserialize, Serialize};
pub type Gas = u64;
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct Fraction {
pub numerator: u64,
pub denominator: u64,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct Fee {
send_sir: Gas,
send_not_sir: Gas,
execution: Gas,
}
impl Fee {
pub fn send_fee(&self, sir: bool) -> Gas {
if sir {
self.send_sir
} else {
self.send_not_sir
}
}
pub fn exec_fee(&self) -> Gas {
self.execution
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct RuntimeFeesConfig {
pub ext_costs: ExtCostsConfig,
pub action_receipt_creation_config: Fee,
pub data_receipt_creation_config: DataReceiptCreationConfig,
pub action_creation_config: ActionCreationConfig,
pub storage_usage_config: StorageUsageConfig,
pub burnt_gas_reward: Fraction,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct ExtCostsConfig {
pub input_base: Gas,
pub input_per_byte: Gas,
pub storage_read_base: Gas,
pub storage_read_key_byte: Gas,
pub storage_read_value_byte: Gas,
pub storage_write_base: Gas,
pub storage_write_key_byte: Gas,
pub storage_write_value_byte: Gas,
pub storage_has_key_base: Gas,
pub storage_has_key_byte: Gas,
pub storage_remove_base: Gas,
pub storage_remove_key_byte: Gas,
pub storage_remove_ret_value_byte: Gas,
pub storage_iter_create_prefix_base: Gas,
pub storage_iter_create_range_base: Gas,
pub storage_iter_create_key_byte: Gas,
pub storage_iter_next_base: Gas,
pub storage_iter_next_key_byte: Gas,
pub storage_iter_next_value_byte: Gas,
pub read_register_base: Gas,
pub read_register_byte: Gas,
pub write_register_base: Gas,
pub write_register_byte: Gas,
pub read_memory_base: Gas,
pub read_memory_byte: Gas,
pub write_memory_base: Gas,
pub write_memory_byte: Gas,
pub account_balance: Gas,
pub prepaid_gas: Gas,
pub used_gas: Gas,
pub random_seed_base: Gas,
pub random_seed_per_byte: Gas,
pub sha256: Gas,
pub sha256_byte: Gas,
pub attached_deposit: Gas,
pub storage_usage: Gas,
pub block_index: Gas,
pub block_timestamp: Gas,
pub current_account_id: Gas,
pub current_account_id_byte: Gas,
pub signer_account_id: Gas,
pub signer_account_id_byte: Gas,
pub signer_account_pk: Gas,
pub signer_account_pk_byte: Gas,
pub predecessor_account_id: Gas,
pub predecessor_account_id_byte: Gas,
pub promise_and_base: Gas,
pub promise_and_per_promise: Gas,
pub promise_result_base: Gas,
pub promise_result_byte: Gas,
pub promise_results_count: Gas,
pub promise_return: Gas,
pub log_base: Gas,
pub log_per_byte: Gas,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct DataReceiptCreationConfig {
pub base_cost: Fee,
pub cost_per_byte: Fee,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct ActionCreationConfig {
pub create_account_cost: Fee,
pub deploy_contract_cost: Fee,
pub deploy_contract_cost_per_byte: Fee,
pub function_call_cost: Fee,
pub function_call_cost_per_byte: Fee,
pub transfer_cost: Fee,
pub stake_cost: Fee,
pub add_key_cost: AccessKeyCreationConfig,
pub delete_key_cost: Fee,
pub delete_account_cost: Fee,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct AccessKeyCreationConfig {
pub full_access_cost: Fee,
pub function_call_cost: Fee,
pub function_call_cost_per_byte: Fee,
}
#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct StorageUsageConfig {
pub account_cost: Gas,
pub data_record_cost: Gas,
pub key_cost_per_byte: Gas,
pub value_cost_per_byte: Gas,
pub code_cost_per_byte: Gas,
}
impl Default for RuntimeFeesConfig {
fn default() -> Self {
Self {
ext_costs: ExtCostsConfig {
input_base: 1,
input_per_byte: 1,
storage_read_base: 1,
storage_read_key_byte: 1,
storage_read_value_byte: 1,
storage_write_base: 1,
storage_write_key_byte: 1,
storage_write_value_byte: 1,
storage_has_key_base: 1,
storage_has_key_byte: 1,
storage_remove_base: 1,
storage_remove_key_byte: 1,
storage_remove_ret_value_byte: 1,
storage_iter_create_prefix_base: 1,
storage_iter_create_range_base: 1,
storage_iter_create_key_byte: 1,
storage_iter_next_base: 1,
storage_iter_next_key_byte: 1,
storage_iter_next_value_byte: 1,
read_register_base: 1,
read_register_byte: 1,
write_register_base: 1,
write_register_byte: 1,
read_memory_base: 1,
read_memory_byte: 1,
write_memory_base: 1,
write_memory_byte: 1,
account_balance: 1,
prepaid_gas: 1,
used_gas: 1,
random_seed_base: 1,
random_seed_per_byte: 1,
sha256: 1,
sha256_byte: 1,
attached_deposit: 1,
storage_usage: 1,
block_index: 1,
block_timestamp: 1,
current_account_id: 1,
current_account_id_byte: 1,
signer_account_id: 1,
signer_account_id_byte: 1,
signer_account_pk: 1,
signer_account_pk_byte: 1,
predecessor_account_id: 1,
predecessor_account_id_byte: 1,
promise_and_base: 1,
promise_and_per_promise: 1,
promise_result_base: 1,
promise_result_byte: 1,
promise_results_count: 1,
promise_return: 1,
log_base: 1,
log_per_byte: 1,
},
action_receipt_creation_config: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
data_receipt_creation_config: DataReceiptCreationConfig {
base_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
cost_per_byte: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
},
action_creation_config: ActionCreationConfig {
create_account_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
deploy_contract_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
deploy_contract_cost_per_byte: Fee {
send_sir: 10,
send_not_sir: 10,
execution: 10,
},
function_call_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
function_call_cost_per_byte: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
transfer_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
stake_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
add_key_cost: AccessKeyCreationConfig {
full_access_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
function_call_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
function_call_cost_per_byte: Fee {
send_sir: 10,
send_not_sir: 10,
execution: 10,
},
},
delete_key_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
delete_account_cost: Fee { send_sir: 10, send_not_sir: 10, execution: 10 },
},
storage_usage_config: StorageUsageConfig {
account_cost: 100,
data_record_cost: 40,
key_cost_per_byte: 1,
value_cost_per_byte: 1,
code_cost_per_byte: 1,
},
burnt_gas_reward: Fraction { numerator: 3, denominator: 10 },
}
}
}
impl RuntimeFeesConfig {
pub fn free() -> Self {
let free = Fee { send_sir: 0, send_not_sir: 0, execution: 0 };
RuntimeFeesConfig {
ext_costs: ExtCostsConfig {
input_base: 0,
input_per_byte: 0,
storage_read_base: 0,
storage_read_key_byte: 0,
storage_read_value_byte: 0,
storage_write_base: 0,
storage_write_key_byte: 0,
storage_write_value_byte: 0,
storage_has_key_base: 0,
storage_has_key_byte: 0,
storage_remove_base: 0,
storage_remove_key_byte: 0,
storage_remove_ret_value_byte: 0,
storage_iter_create_prefix_base: 0,
storage_iter_create_range_base: 0,
storage_iter_create_key_byte: 0,
storage_iter_next_base: 0,
storage_iter_next_key_byte: 0,
storage_iter_next_value_byte: 0,
read_register_base: 0,
read_register_byte: 0,
write_register_base: 0,
write_register_byte: 0,
read_memory_base: 0,
read_memory_byte: 0,
write_memory_base: 0,
write_memory_byte: 0,
account_balance: 0,
prepaid_gas: 0,
used_gas: 0,
random_seed_base: 0,
random_seed_per_byte: 0,
sha256: 0,
sha256_byte: 0,
attached_deposit: 0,
storage_usage: 0,
block_index: 0,
block_timestamp: 0,
current_account_id: 0,
current_account_id_byte: 0,
signer_account_id: 0,
signer_account_id_byte: 0,
signer_account_pk: 0,
signer_account_pk_byte: 0,
predecessor_account_id: 0,
predecessor_account_id_byte: 0,
promise_and_base: 0,
promise_and_per_promise: 0,
promise_result_base: 0,
promise_result_byte: 0,
promise_results_count: 0,
promise_return: 0,
log_base: 0,
log_per_byte: 0,
},
action_receipt_creation_config: free.clone(),
data_receipt_creation_config: DataReceiptCreationConfig {
base_cost: free.clone(),
cost_per_byte: free.clone(),
},
action_creation_config: ActionCreationConfig {
create_account_cost: free.clone(),
deploy_contract_cost: free.clone(),
deploy_contract_cost_per_byte: free.clone(),
function_call_cost: free.clone(),
function_call_cost_per_byte: free.clone(),
transfer_cost: free.clone(),
stake_cost: free.clone(),
add_key_cost: AccessKeyCreationConfig {
full_access_cost: free.clone(),
function_call_cost: free.clone(),
function_call_cost_per_byte: free.clone(),
},
delete_key_cost: free.clone(),
delete_account_cost: free.clone(),
},
storage_usage_config: StorageUsageConfig {
account_cost: 0,
data_record_cost: 0,
key_cost_per_byte: 0,
value_cost_per_byte: 0,
code_cost_per_byte: 0,
},
burnt_gas_reward: Fraction { numerator: 0, denominator: 1 },
}
}
}