Expose Governance types/functions
Change-Id: I10fb14fa5d9d283cf831ea3d8585141e834e40b5
This commit is contained in:
parent
21c7399d55
commit
44384e635f
|
@ -16,6 +16,8 @@ use solitaire::{
|
||||||
use crate::{
|
use crate::{
|
||||||
accounts::{
|
accounts::{
|
||||||
Bridge,
|
Bridge,
|
||||||
|
Claim,
|
||||||
|
ClaimDerivationData,
|
||||||
FeeCollector,
|
FeeCollector,
|
||||||
GuardianSet,
|
GuardianSet,
|
||||||
GuardianSetDerivationData,
|
GuardianSetDerivationData,
|
||||||
|
@ -26,9 +28,21 @@ use crate::{
|
||||||
SignatureSet,
|
SignatureSet,
|
||||||
SignatureSetDerivationData,
|
SignatureSetDerivationData,
|
||||||
},
|
},
|
||||||
|
types::{
|
||||||
|
GovernancePayloadUpgrade,
|
||||||
|
PostedMessage,
|
||||||
|
},
|
||||||
BridgeConfig,
|
BridgeConfig,
|
||||||
|
InitializeData,
|
||||||
|
PayloadMessage,
|
||||||
PostMessageData,
|
PostMessageData,
|
||||||
PostVAAData,
|
PostVAAData,
|
||||||
|
SetFees,
|
||||||
|
SetFeesData,
|
||||||
|
TransferFees,
|
||||||
|
TransferFeesData,
|
||||||
|
UpgradeContractData,
|
||||||
|
UpgradeGuardianSetData,
|
||||||
VerifySignaturesData,
|
VerifySignaturesData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -193,6 +207,150 @@ pub fn post_vaa(program_id: Pubkey, payer: Pubkey, vaa: PostVAAData) -> Instruct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn upgrade_contract(
|
||||||
|
program_id: Pubkey,
|
||||||
|
payer: Pubkey,
|
||||||
|
payload_message: Pubkey,
|
||||||
|
spill: Pubkey,
|
||||||
|
) -> Instruction {
|
||||||
|
let claim = Claim::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&ClaimDerivationData {
|
||||||
|
emitter_address: [0u8; 32],
|
||||||
|
emitter_chain: 1,
|
||||||
|
sequence: 0,
|
||||||
|
},
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
let (upgrade_authority, _) =
|
||||||
|
Pubkey::find_program_address(&["upgrade_authority".as_bytes()], &program_id);
|
||||||
|
|
||||||
|
Instruction {
|
||||||
|
program_id,
|
||||||
|
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(payer, true),
|
||||||
|
AccountMeta::new(payload_message, false),
|
||||||
|
AccountMeta::new(claim, false),
|
||||||
|
AccountMeta::new(upgrade_authority, false),
|
||||||
|
AccountMeta::new(spill, false),
|
||||||
|
],
|
||||||
|
|
||||||
|
data: crate::instruction::Instruction::UpgradeContract(UpgradeContractData {})
|
||||||
|
.try_to_vec()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn upgrade_guardian_set(
|
||||||
|
program_id: Pubkey,
|
||||||
|
payer: Pubkey,
|
||||||
|
payload_message: Pubkey,
|
||||||
|
emitter: Pubkey,
|
||||||
|
old_index: u32,
|
||||||
|
new_index: u32,
|
||||||
|
) -> Instruction {
|
||||||
|
let bridge = Bridge::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
|
||||||
|
let claim = Claim::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&ClaimDerivationData {
|
||||||
|
emitter_address: emitter.to_bytes(),
|
||||||
|
emitter_chain: 1,
|
||||||
|
sequence: 0,
|
||||||
|
},
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
let guardian_set_old = GuardianSet::<'_, { AccountState::Initialized }>::key(
|
||||||
|
&GuardianSetDerivationData { index: old_index },
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
let guardian_set_new = GuardianSet::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&GuardianSetDerivationData { index: new_index },
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
Instruction {
|
||||||
|
program_id,
|
||||||
|
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(payer, true),
|
||||||
|
AccountMeta::new(bridge, false),
|
||||||
|
AccountMeta::new(payload_message, false),
|
||||||
|
AccountMeta::new(claim, false),
|
||||||
|
AccountMeta::new(guardian_set_old, false),
|
||||||
|
AccountMeta::new(guardian_set_new, false),
|
||||||
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
|
],
|
||||||
|
|
||||||
|
data: crate::instruction::Instruction::UpgradeGuardianSet(UpgradeGuardianSetData {})
|
||||||
|
.try_to_vec()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_fees(program_id: Pubkey, payer: Pubkey, fee: u32) -> Instruction {
|
||||||
|
let bridge = Bridge::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
|
||||||
|
let payload_message = Pubkey::new_unique();
|
||||||
|
let claim = Claim::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&ClaimDerivationData {
|
||||||
|
emitter_address: [0u8; 32],
|
||||||
|
emitter_chain: 1,
|
||||||
|
sequence: 0,
|
||||||
|
},
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
Instruction {
|
||||||
|
program_id,
|
||||||
|
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(payer, true),
|
||||||
|
AccountMeta::new(bridge, false),
|
||||||
|
AccountMeta::new(payload_message, false),
|
||||||
|
AccountMeta::new(claim, false),
|
||||||
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
|
],
|
||||||
|
|
||||||
|
data: crate::instruction::Instruction::SetFees(SetFeesData {})
|
||||||
|
.try_to_vec()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn transfer_fees(program_id: Pubkey, payer: Pubkey, recipient: Pubkey) -> Instruction {
|
||||||
|
let bridge = Bridge::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
|
||||||
|
let payload_message = Pubkey::new_unique();
|
||||||
|
let claim = Claim::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&ClaimDerivationData {
|
||||||
|
emitter_address: [0u8; 32],
|
||||||
|
emitter_chain: 1,
|
||||||
|
sequence: 0,
|
||||||
|
},
|
||||||
|
&program_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
let fee_collector = FeeCollector::key(None, &program_id);
|
||||||
|
|
||||||
|
Instruction {
|
||||||
|
program_id,
|
||||||
|
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(payer, true),
|
||||||
|
AccountMeta::new(bridge, false),
|
||||||
|
AccountMeta::new(payload_message, false),
|
||||||
|
AccountMeta::new(claim, false),
|
||||||
|
AccountMeta::new(fee_collector, false),
|
||||||
|
AccountMeta::new(recipient, false),
|
||||||
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
|
],
|
||||||
|
|
||||||
|
data: crate::instruction::Instruction::TransferFees(TransferFeesData {})
|
||||||
|
.try_to_vec()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Convert a full VAA structure into the serialization of its unique components, this structure is
|
// Convert a full VAA structure into the serialization of its unique components, this structure is
|
||||||
// what is hashed and verified by Guardians.
|
// what is hashed and verified by Guardians.
|
||||||
pub fn serialize_vaa(vaa: &PostVAAData) -> Vec<u8> {
|
pub fn serialize_vaa(vaa: &PostVAAData) -> Vec<u8> {
|
||||||
|
|
|
@ -18,15 +18,22 @@ pub use api::{
|
||||||
initialize,
|
initialize,
|
||||||
post_message,
|
post_message,
|
||||||
post_vaa,
|
post_vaa,
|
||||||
|
set_fees,
|
||||||
|
transfer_fees,
|
||||||
upgrade_contract,
|
upgrade_contract,
|
||||||
upgrade_guardian_set,
|
upgrade_guardian_set,
|
||||||
verify_signatures,
|
verify_signatures,
|
||||||
Initialize,
|
Initialize,
|
||||||
|
InitializeData,
|
||||||
PostMessage,
|
PostMessage,
|
||||||
PostMessageData,
|
PostMessageData,
|
||||||
PostVAA,
|
PostVAA,
|
||||||
PostVAAData,
|
PostVAAData,
|
||||||
|
SetFees,
|
||||||
|
SetFeesData,
|
||||||
Signature,
|
Signature,
|
||||||
|
TransferFees,
|
||||||
|
TransferFeesData,
|
||||||
UninitializedMessage,
|
UninitializedMessage,
|
||||||
UpgradeContract,
|
UpgradeContract,
|
||||||
UpgradeContractData,
|
UpgradeContractData,
|
||||||
|
@ -35,6 +42,14 @@ pub use api::{
|
||||||
VerifySignatures,
|
VerifySignatures,
|
||||||
VerifySignaturesData,
|
VerifySignaturesData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use vaa::{
|
||||||
|
DeserializePayload,
|
||||||
|
PayloadMessage,
|
||||||
|
SerializePayload,
|
||||||
|
};
|
||||||
|
|
||||||
|
// BridgeConfig is the type of the main state the program maintains for itself.
|
||||||
use types::BridgeConfig;
|
use types::BridgeConfig;
|
||||||
|
|
||||||
const MAX_LEN_GUARDIAN_KEYS: usize = 19;
|
const MAX_LEN_GUARDIAN_KEYS: usize = 19;
|
||||||
|
@ -67,10 +82,12 @@ impl From<Error> for SolitaireError {
|
||||||
}
|
}
|
||||||
|
|
||||||
solitaire! {
|
solitaire! {
|
||||||
Initialize(BridgeConfig) => initialize,
|
Initialize(InitializeData) => initialize,
|
||||||
PostVAA(PostVAAData) => post_vaa,
|
|
||||||
PostMessage(PostMessageData) => post_message,
|
PostMessage(PostMessageData) => post_message,
|
||||||
VerifySignatures(VerifySignaturesData) => verify_signatures,
|
PostVAA(PostVAAData) => post_vaa,
|
||||||
|
SetFees(SetFeesData) => set_fees,
|
||||||
|
TransferFees(TransferFeesData) => transfer_fees,
|
||||||
UpgradeContract(UpgradeContractData) => upgrade_contract,
|
UpgradeContract(UpgradeContractData) => upgrade_contract,
|
||||||
UpgradeGuardianSet(UpgradeGuardianSetData) => upgrade_guardian_set,
|
UpgradeGuardianSet(UpgradeGuardianSetData) => upgrade_guardian_set,
|
||||||
|
VerifySignatures(VerifySignaturesData) => verify_signatures,
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ use solana_sdk::{
|
||||||
|
|
||||||
use bridge::{
|
use bridge::{
|
||||||
accounts::{
|
accounts::{
|
||||||
|
FeeCollector,
|
||||||
GuardianSet,
|
GuardianSet,
|
||||||
GuardianSetDerivationData,
|
GuardianSetDerivationData,
|
||||||
Message,
|
Message,
|
||||||
MessageDerivationData,
|
MessageDerivationData,
|
||||||
SignatureSet,
|
SignatureSet,
|
||||||
SignatureSetDerivationData,
|
SignatureSetDerivationData,
|
||||||
FeeCollector,
|
|
||||||
},
|
},
|
||||||
instruction,
|
instruction,
|
||||||
instructions,
|
instructions,
|
||||||
|
@ -60,6 +60,7 @@ use bridge::{
|
||||||
SequenceTracker,
|
SequenceTracker,
|
||||||
},
|
},
|
||||||
Initialize,
|
Initialize,
|
||||||
|
InitializeData,
|
||||||
PostMessageData,
|
PostMessageData,
|
||||||
PostVAAData,
|
PostVAAData,
|
||||||
UninitializedMessage,
|
UninitializedMessage,
|
||||||
|
|
Loading…
Reference in New Issue