Skip to content

Commit

Permalink
refactor(solana-contracts): rename account names in completeWithPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
swimricky committed Oct 12, 2022
1 parent 3ce681c commit 030eaa2
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 587 deletions.
6 changes: 6 additions & 0 deletions packages/solana-contracts/programs/propeller/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pub enum PropellerError {
#[msg("Invalid Gas Kickstart parameter in Swim Payload")]
InvalidSwimPayloadGasKickstart,

#[msg("Invalid Marginal Price Pool")]
InvalidMarginalPricePool,

#[msg("Invalid Marginal Price Pool Accounts")]
InvalidMarginalPricePoolAccounts,

Expand Down Expand Up @@ -152,4 +155,7 @@ pub enum PropellerError {

#[msg("Invalid Aggregator")]
InvalidAggregator,

#[msg("Invalid Fee Vault")]
InvalidFeeVault,
}
11 changes: 4 additions & 7 deletions packages/solana-contracts/programs/propeller/src/fees.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use {crate::TOKEN_COUNT, anchor_lang::prelude::*, two_pool::BorshDecimal};

pub trait Fees {
pub trait Fees<'info> {
/// Calculating the fees, including txn and rent exmptions, in lamports.
fn calculate_fees_in_lamports(&self) -> Result<u64>;
fn convert_fees_to_swim_usd_atomic(
&self,
fee_in_lamports: u64,
marginal_prices: [BorshDecimal; TOKEN_COUNT],
max_staleness: i64,
) -> 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>;
fn track_and_transfer_fees(&mut self, fees_in_swim_usd: u64) -> Result<()>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
crate::{error::*, Propeller},
anchor_lang::prelude::*,
anchor_spl::{
associated_token::{create, AssociatedToken, Create},
associated_token::{create, get_associated_token_address, AssociatedToken, Create},
token::{self, Mint, Token, TokenAccount, Transfer},
},
two_pool::state::TwoPool,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<'info> InitializeFeeTracker<'info> {
pub fn handle_initialize_fee_tracker(ctx: Context<InitializeFeeTracker>) -> Result<()> {
let fee_tracker = &mut ctx.accounts.fee_tracker;
fee_tracker.bump = *ctx.bumps.get("fee_tracker").unwrap();
fee_tracker.payer = ctx.accounts.payer.key();
fee_tracker.fees_recipient = ctx.accounts.payer.key();
fee_tracker.fees_owed = 0;
fee_tracker.fees_mint = ctx.accounts.swim_usd_mint.key();
Ok(())
Expand All @@ -59,7 +59,7 @@ pub fn handle_initialize_fee_tracker(ctx: Context<InitializeFeeTracker>) -> Resu
#[account]
pub struct FeeTracker {
pub bump: u8,
pub payer: Pubkey,
pub fees_recipient: Pubkey,
pub fees_owed: u64,
pub fees_mint: Pubkey,
}
Expand All @@ -73,13 +73,13 @@ pub struct ClaimFees<'info> {
#[account(
seeds = [b"propeller".as_ref(), propeller.swim_usd_mint.as_ref()],
bump = propeller.bump,
has_one = fee_vault,
has_one = fee_vault @ PropellerError::InvalidFeeVault,
)]
pub propeller: Box<Account<'info, Propeller>>,

#[account(
mut,
seeds = [b"propeller".as_ref(), b"fee".as_ref(), fee_tracker.fees_mint.as_ref(), fee_tracker.payer.as_ref()],
seeds = [b"propeller".as_ref(), b"fee".as_ref(), fee_tracker.fees_mint.as_ref(), fee_tracker.fees_recipient.as_ref()],
bump = fee_tracker.bump
)]
pub fee_tracker: Account<'info, FeeTracker>,
Expand All @@ -89,16 +89,11 @@ pub struct ClaimFees<'info> {

#[account(
mut,
token::mint = fee_tracker.fees_mint,
token::authority = fee_tracker.payer,
address = get_associated_token_address(&fee_tracker.fees_recipient, &fee_tracker.fees_mint),
)]
pub fee_account: Account<'info, TokenAccount>,

#[account(
mut,
token::mint = fee_tracker.fees_mint,
token::authority = propeller,
)]
#[account(mut)]
pub fee_vault: Account<'info, TokenAccount>,

pub token_program: Program<'info, Token>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub struct InitializeParams {
pub marginal_price_pool: Pubkey,
pub marginal_price_pool_token_index: u8,
pub marginal_price_pool_token_mint: Pubkey,
pub max_staleness: i64,
// pub evm_routing_contract_address: [u8; 32],
}

Expand Down
Loading

0 comments on commit 030eaa2

Please sign in to comment.