Add constant time fee calculation function
Change-Id: Ifc6dcfce4066d6767bf03f79133920daea112697
This commit is contained in:
parent
b0e7e363c5
commit
aab8efec63
|
@ -6,8 +6,50 @@ use crate::{
|
||||||
types::{BridgeConfig, Index},
|
types::{BridgeConfig, Index},
|
||||||
PublishMessage,
|
PublishMessage,
|
||||||
Result,
|
Result,
|
||||||
|
MAX_LEN_GUARDIAN_KEYS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Constant fee for VAA transactions, measured in lamports.
|
||||||
|
const VAA_TX_FEE: u64 = 18 * 10000;
|
||||||
|
|
||||||
pub fn publish_message(bridge: &mut Bridge, ctx: Context<PublishMessage>) -> Result<()> {
|
pub fn publish_message(bridge: &mut Bridge, ctx: Context<PublishMessage>) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A const time calculation of the fee required to publish a message.
|
||||||
|
//
|
||||||
|
// Cost breakdown:
|
||||||
|
// - 2 Signatures
|
||||||
|
// - 1 Claimed VAA Rent
|
||||||
|
// - 2x Guardian Fees
|
||||||
|
const fn calculate_transfer_fee() -> u64 {
|
||||||
|
use std::mem::size_of;
|
||||||
|
const SIGNATURE_COST: u64 = size_of::<SignatureState>() as u64;
|
||||||
|
const VAA_COST: u64 = size_of::<ClaimedVAA>() as u64;
|
||||||
|
const VAA_FEE: u64 = VAA_TX_FEE;
|
||||||
|
SIGNATURE_COST + VAA_COST + VAA_FEE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Signature state
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct SignatureState {
|
||||||
|
/// signatures of validators
|
||||||
|
pub signatures: [[u8; 65]; MAX_LEN_GUARDIAN_KEYS],
|
||||||
|
|
||||||
|
/// hash of the data
|
||||||
|
pub hash: [u8; 32],
|
||||||
|
|
||||||
|
/// index of the guardian set
|
||||||
|
pub guardian_set_index: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record of a claimed VAA
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
|
pub struct ClaimedVAA {
|
||||||
|
/// hash of the vaa
|
||||||
|
pub hash: [u8; 32],
|
||||||
|
/// time the vaa was submitted
|
||||||
|
pub vaa_time: u32,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue