Skip to content

Commit

Permalink
Fix all tests except token happy path
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMansanet committed Dec 23, 2024
1 parent 45d7911 commit d6cd830
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 138 deletions.
14 changes: 10 additions & 4 deletions chains/solana/contracts/programs/ccip-router/src/fee_quoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
PerChainPerTokenConfig, Solana2AnyMessage, SolanaTokenAmount, UnpackedDoubleU224,
CCIP_LOCK_OR_BURN_V1_RET_BYTES, FEE_BILLING_SIGNER_SEEDS, MAX_TOKEN_AND_CHAIN_CONFIG_V,
};

// TODO change args and implement
pub fn fee_for_msg(
_dest_chain_selector: u64,
Expand Down Expand Up @@ -43,17 +44,22 @@ pub fn fee_for_msg(
let data_availability_cost = 1u32.e(18);

let premium_multiplier = U256::new(fee_token_config.premium_multiplier_wei_per_eth.into());
let amount = (dbg!(network_fee.premium.0) * dbg!(premium_multiplier)
+ execution_cost
+ data_availability_cost)
/ dbg!(fee_token_price.0);
let amount =
(network_fee.premium.0 * premium_multiplier + execution_cost + data_availability_cost)
/ fee_token_price.0;
let amount: u64 = amount
.try_into()
.map_err(|_| CcipRouterError::InvalidTokenPrice)?;

Ok(SolanaTokenAmount { amount, token })
}

/// Parses and validates the account slice in the order expected by `get_fees`:
///
/// * First, the billing token config accounts for each token involved, including the
/// fee token, sequentially.
/// * Then, the per chain / per token config of those tokens, sequentially in the same
/// order, for the destination chain.
pub fn get_accounts_for_fee_retrieval<'info>(
remaining_accounts: &'info [AccountInfo<'info>],
message: &Solana2AnyMessage,
Expand Down
29 changes: 25 additions & 4 deletions chains/solana/contracts/programs/ccip-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,14 @@ pub mod ccip_router {
/// * `cfg` - The token billing configuration.
pub fn set_token_billing(
ctx: Context<SetTokenBillingConfig>,
_chain_selector: u64,
_mint: Pubkey,
chain_selector: u64,
mint: Pubkey,
cfg: TokenBilling,
) -> Result<()> {
ctx.accounts.per_chain_per_token_config.version = 1; // update this if we change the account struct
ctx.accounts.per_chain_per_token_config.billing = cfg;
ctx.accounts.per_chain_per_token_config.chain_selector = chain_selector;
ctx.accounts.per_chain_per_token_config.mint = mint;
Ok(())
}

Expand Down Expand Up @@ -654,6 +657,16 @@ pub mod ccip_router {
/// * `dest_chain_selector` - The chain selector for the destination chain.
/// * `message` - The message to be sent.
///
/// # Additional accounts
///
/// In addition to the fixed amount of accounts defined in the `GetFee` context,
/// the following accounts must be provided:
///
/// * First, the billing token config accounts for each token involved, including the
/// fee token, sequentially.
/// * Then, the per chain / per token config of those tokens, sequentially in the same
/// order, for the destination chain.
///
/// # Returns
///
/// The fee amount in u64.
Expand Down Expand Up @@ -683,6 +696,16 @@ pub mod ccip_router {
/// The message will be sent to the receiver on the destination chain selector.
/// This message emits the event CCIPSendRequested with all the necessary data to be retrieved by the OffChain Code
///
/// # Additional accounts
///
/// In addition to the fixed amount of accounts defined in the `GetFee` context,
/// the following accounts must be provided:
///
/// * First, the billing token config accounts for each token involved, including the
/// fee token, sequentially.
/// * Then, the per chain / per token config of those tokens, sequentially in the same
/// order, for the destination chain.
///
/// # Arguments
///
/// * `ctx` - The context containing the accounts required for sending the message.
Expand All @@ -698,10 +721,8 @@ pub mod ccip_router {

let dest_chain = &mut ctx.accounts.dest_chain_state;

// TODO this is grossly invalid, just putting it here for now to typecheck. These will come from elsewhere (see below how these accounts are retrieved)
let (token_billing_config_accounts, per_chain_per_token_config_accounts) =
get_accounts_for_fee_retrieval(&ctx.remaining_accounts, &message)?;

let fee = fee_for_msg(
dest_chain_selector,
&message,
Expand Down
20 changes: 20 additions & 0 deletions chains/solana/contracts/target/idl/ccip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,16 @@
"* `dest_chain_selector` - The chain selector for the destination chain.",
"* `message` - The message to be sent.",
"",
"# Additional accounts",
"",
"In addition to the fixed amount of accounts defined in the `GetFee` context,",
"the following accounts must be provided:",
"",
"* First, the billing token config accounts for each token involved, including the",
"fee token, sequentially.",
"* Then, the per chain / per token config of those tokens, sequentially in the same",
"order, for the destination chain.",
"",
"# Returns",
"",
"The fee amount in u64."
Expand Down Expand Up @@ -1026,6 +1036,16 @@
"The message will be sent to the receiver on the destination chain selector.",
"This message emits the event CCIPSendRequested with all the necessary data to be retrieved by the OffChain Code",
"",
"# Additional accounts",
"",
"In addition to the fixed amount of accounts defined in the `GetFee` context,",
"the following accounts must be provided:",
"",
"* First, the billing token config accounts for each token involved, including the",
"fee token, sequentially.",
"* Then, the per chain / per token config of those tokens, sequentially in the same",
"order, for the destination chain.",
"",
"# Arguments",
"",
"* `ctx` - The context containing the accounts required for sending the message.",
Expand Down
Loading

0 comments on commit d6cd830

Please sign in to comment.