Skip to content

Commit

Permalink
feat: refactoring, add gov ixs and some utility test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
swimricky committed Oct 19, 2022
1 parent 72b491c commit 51dd9ed
Show file tree
Hide file tree
Showing 39 changed files with 5,081 additions and 2,554 deletions.
1 change: 1 addition & 0 deletions packages/solana-contracts/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ initialize_pool = "yarn run ts-node scripts/initializePool.ts"
initialize_propeller = "yarn run ts-node scripts/initializePropeller.ts"
scratch = "yarn run ts-node scripts/scratch.ts"
add_to_pool = "yarn run ts-node scripts/addToPool.ts"
parse_account = "yarn run ts-node scripts/parseAccount.ts"

[test]
startup_wait = 100000
Expand Down
47 changes: 9 additions & 38 deletions packages/solana-contracts/programs/propeller/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ pub const PROPELLER_MINIMUM_OUTPUT_AMOUNT: u64 = 0u64;
// pub const LAMPORTS_PER_SOL_DECIMAL: Decimal = Decimal::from_u64(1_000_000_000u64).unwrap();
pub const LAMPORTS_PER_SOL_DECIMAL: Decimal = Decimal::from_parts(1_000_000_000u32, 0, 0, false, 0u32);

#[cfg(all(feature = "localnet", not(feature = "devnet"), not(feature = "mainnet")))]
pub const TOKEN_BRIDGE_PROGRAM_ID: &str = "B6RHG3mfcckmrYN1UhmJzyS1XX3fZKbkeUcpJe9Sy3FE";

#[cfg(all(feature = "devnet", not(feature = "localnet"), not(feature = "mainnet")))]
pub const TOKEN_BRIDGE_PROGRAM_ID: &str = "DZnkkTmCiFWfYTfT41X3Rd1kDgozqzxWaHqsw6W4x2oe";

#[cfg(all(feature = "mainnet", not(feature = "localnet"), not(feature = "devnet")))]
pub const TOKEN_BRIDGE_PROGRAM_ID: &str = "wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb";

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -33,41 +42,3 @@ mod test {
// println!("token_bridge_id2: {}", ID);
}
}
// // vaa payload types
// pub const PAYLOAD_SALE_INIT_SOLANA: u8 = 5; // 1 for everyone else
// pub const PAYLOAD_ATTEST_CONTRIBUTIONS: u8 = 2;
// pub const PAYLOAD_SALE_SEALED: u8 = 3;
// pub const PAYLOAD_SALE_ABORTED: u8 = 4;
//
// // universal
// pub const PAYLOAD_HEADER_LEN: usize = 33; // payload + sale id
// pub const INDEX_SALE_ID: usize = 1;
//
// // for sale init
// pub const INDEX_SALE_INIT_TOKEN_ADDRESS: usize = 33;
// pub const INDEX_SALE_INIT_TOKEN_CHAIN: usize = 65;
// pub const INDEX_SALE_INIT_TOKEN_DECIMALS: usize = 67;
// pub const INDEX_SALE_INIT_SALE_START: usize = 68;
// pub const INDEX_SALE_INIT_SALE_END: usize = 100;
// pub const INDEX_SALE_INIT_ACCEPTED_TOKENS_START: usize = 132;
//
// pub const ACCEPTED_TOKEN_NUM_BYTES: usize = 33;
// pub const ACCEPTED_TOKENS_MAX: usize = 8;
// pub const INDEX_ACCEPTED_TOKEN_INDEX: usize = 0;
// pub const INDEX_ACCEPTED_TOKEN_ADDRESS: usize = 1;
// pub const INDEX_ACCEPTED_TOKEN_END: usize = 33;
//
// // for attest contributions
// pub const ATTEST_CONTRIBUTIONS_ELEMENT_LEN: usize = 33; // token index + amount
//
// // for sale sealed
// pub const INDEX_SALE_SEALED_ALLOCATIONS_START: usize = 33;
//
// pub const ALLOCATION_NUM_BYTES: usize = 65;
// pub const INDEX_ALLOCATIONS_AMOUNT: usize = 1;
// pub const INDEX_ALLOCATIONS_EXCESS: usize = 33;
// pub const INDEX_ALLOCATIONS_END: usize = 65;

// misc
// pub const PAD_U8: usize = 31;
// pub const PAD_U64: usize = 24;
50 changes: 34 additions & 16 deletions packages/solana-contracts/programs/propeller/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum PropellerError {
#[msg("Not a valid Switchboard account")]
InvalidSwitchboardAccount,

#[msg("Switchboard feed has not been updated in 5 minutes")]
#[msg("Switchboard feed value is stale ")]
StaleFeed,

#[msg("Switchboard feed exceeded provided confidence interval")]
Expand All @@ -81,29 +81,35 @@ pub enum PropellerError {
#[msg("Insufficient Amount being transferred")]
InsufficientAmount,

#[msg("Invalid Wormhole Claim Account")]
InvalidWormholeClaimAccount,

#[msg("Invalid claim data")]
InvalidClaimData,

#[msg("Claim Account not claimed")]
ClaimNotClaimed,

#[msg("Invalid Propeller Admin")]
InvalidPropellerAdmin,
#[msg("Invalid Propeller GovernanceKey")]
InvalidPropellerGovernanceKey,

#[msg("Invalid Propeller Pause Key")]
InvalidPropellerPauseKey,

#[msg("Invalid Pool for Token Id Map")]
InvalidTokenIdMapPool,
#[msg("Invalid Pool for Token Number Map")]
InvalidTokenNumberMapPool,

#[msg("Invalid Output Token Index")]
InvalidOutputTokenIndex,

#[msg("Invalid Pool Token Index for Token Id Map")]
InvalidTokenIdMapPoolTokenIndex,
#[msg("Invalid Pool Token Index for Token Number Map")]
InvalidTokenNumberMapPoolTokenIndex,

#[msg("Invalid Pool Token Mint for Token Id Map")]
InvalidTokenIdMapPoolTokenMint,
#[msg("Invalid Pool Token Mint for Token Number Map")]
InvalidTokenNumberMapPoolTokenMint,

#[msg("Invalid Pool Ix for Token Id Map")]
InvalidTokenIdMapPoolIx,
#[msg("Invalid To Token Step for Token Number Map")]
InvalidTokenNumberMapToTokenStep,

#[msg("Invalid Gas Kickstart parameter in Swim Payload")]
InvalidSwimPayloadGasKickstart,
Expand Down Expand Up @@ -144,11 +150,8 @@ pub enum PropellerError {
#[msg("Owner of token account != swimPayload.owner")]
IncorrectOwnerForCreateTokenAccount,

#[msg("TokenIdMap exists. Please use the correct instruction")]
TokenIdMapExists,

#[msg("Invalid address for TokenIdMap account")]
InvalidTokenIdMapAccountAddress,
#[msg("TokenNumberMap exists. Please use the correct instruction")]
TokenNumberMapExists,

#[msg("Invalid Swim Payload version")]
InvalidSwimPayloadVersion,
Expand All @@ -158,4 +161,19 @@ pub enum PropellerError {

#[msg("Invalid Fee Vault")]
InvalidFeeVault,

#[msg("Invalid Memo")]
InvalidMemo,

#[msg("ToTokenNumber does not match SwimPayload.to_tokenNumber")]
ToTokenNumberMismatch,

#[msg("Routing Contract is paused")]
IsPaused,

#[msg("Target Chain is paused")]
TargetChainIsPaused,

#[msg("Invalid SwimPayloadMessagePayer")]
InvalidSwimPayloadMessagePayer,
}
2 changes: 1 addition & 1 deletion packages/solana-contracts/programs/propeller/src/fees.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {crate::TOKEN_COUNT, anchor_lang::prelude::*, two_pool::BorshDecimal};

pub trait Fees<'info> {
/// Calculating the fees, including txn and rent exmptions, in lamports.
/// Calculate the fees, including txn and rent exemptions, in lamports.
fn calculate_fees_in_lamports(&self) -> Result<u64>;
fn get_marginal_prices(&self) -> Result<[BorshDecimal; TOKEN_COUNT]>;
fn convert_fees_to_swim_usd_atomic(&self, fee_in_lamports: u64) -> Result<u64>;
Expand Down
Loading

0 comments on commit 51dd9ed

Please sign in to comment.