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 {
pub send_sir: Gas,
pub send_not_sir: Gas,
pub 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 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 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 num_bytes_account: u64,
pub num_extra_bytes_record: u64,
}
impl Default for RuntimeFeesConfig {
fn default() -> Self {
#[allow(clippy::unreadable_literal)]
Self {
action_receipt_creation_config: Fee {
send_sir: 924119500000,
send_not_sir: 924119500000,
execution: 924119500000,
},
data_receipt_creation_config: DataReceiptCreationConfig {
base_cost: Fee {
send_sir: 539890689500,
send_not_sir: 539890689500,
execution: 539890689500,
},
cost_per_byte: Fee {
send_sir: 14234654,
send_not_sir: 14234654,
execution: 14234654,
},
},
action_creation_config: ActionCreationConfig {
create_account_cost: Fee { send_sir: 0, send_not_sir: 0, execution: 0 },
deploy_contract_cost: Fee {
send_sir: 513359000000,
send_not_sir: 513359000000,
execution: 513359000000,
},
deploy_contract_cost_per_byte: Fee {
send_sir: 27106233,
send_not_sir: 27106233,
execution: 27106233,
},
function_call_cost: Fee {
send_sir: 1367372500000,
send_not_sir: 1367372500000,
execution: 1367372500000,
},
function_call_cost_per_byte: Fee {
send_sir: 2354953,
send_not_sir: 2354953,
execution: 2354953,
},
transfer_cost: Fee {
send_sir: 13025000000,
send_not_sir: 13025000000,
execution: 13025000000,
},
stake_cost: Fee { send_sir: 0, send_not_sir: 0, execution: 0 },
add_key_cost: AccessKeyCreationConfig {
full_access_cost: Fee { send_sir: 0, send_not_sir: 0, execution: 0 },
function_call_cost: Fee { send_sir: 0, send_not_sir: 0, execution: 0 },
function_call_cost_per_byte: Fee {
send_sir: 37538150,
send_not_sir: 37538150,
execution: 37538150,
},
},
delete_key_cost: Fee { send_sir: 0, send_not_sir: 0, execution: 0 },
delete_account_cost: Fee {
send_sir: 454830000000,
send_not_sir: 454830000000,
execution: 454830000000,
},
},
storage_usage_config: StorageUsageConfig {
num_bytes_account: 100,
num_extra_bytes_record: 40,
},
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 {
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,
},
storage_usage_config: StorageUsageConfig {
num_bytes_account: 0,
num_extra_bytes_record: 0,
},
burnt_gas_reward: Fraction { numerator: 0, denominator: 1 },
}
}
}