Skip to content

Commit dc0ed91

Browse files
authored
Make router::get_fee return fewer fields that FQ (#757)
1 parent 6cdbae0 commit dc0ed91

File tree

14 files changed

+176
-37
lines changed

14 files changed

+176
-37
lines changed

chains/solana/contracts/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chains/solana/contracts/programs/ccip-router/src/instructions/interfaces.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use anchor_lang::prelude::*;
2-
use fee_quoter::messages::GetFeeResult;
32

43
use crate::context::{
54
AcceptOwnership, AddChainSelector, AddOfframp, CcipSend, RemoveOfframp, TransferOwnership,
65
UpdateConfigCCIPRouter, UpdateDestChainSelectorConfig, UpdateDestChainSelectorConfigNoRealloc,
76
WithdrawBilledFunds,
87
};
9-
use crate::messages::SVM2AnyMessage;
8+
use crate::messages::{GetFeeResult, SVM2AnyMessage};
109
use crate::state::{CodeVersion, DestChainConfig};
1110
use crate::token_context::{
1211
AcceptAdminRoleTokenAdminRegistry, ModifyTokenAdminRegistry,

chains/solana/contracts/programs/ccip-router/src/instructions/v1/onramp.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::events::on_ramp as events;
2+
use crate::messages::GetFeeResult;
23
use anchor_lang::prelude::*;
34
use anchor_spl::token_interface;
45
use ccip_common::seed;
56
use ccip_common::v1::{validate_and_parse_token_accounts, TokenAccounts};
6-
use fee_quoter::messages::{GetFeeResult, TokenTransferAdditionalData};
7+
use fee_quoter::messages::TokenTransferAdditionalData;
78

89
use super::super::interfaces::OnRamp;
910
use super::fees::{get_fee_cpi, transfer_and_wrap_native_sol, transfer_fee};
@@ -250,7 +251,7 @@ impl OnRamp for Impl {
250251
dest_chain_selector: u64,
251252
message: SVM2AnyMessage,
252253
) -> Result<GetFeeResult> {
253-
get_fee_cpi(
254+
let fq_result = get_fee_cpi(
254255
ctx.accounts.fee_quoter.to_account_info(),
255256
ctx.accounts.fee_quoter_config.to_account_info(),
256257
ctx.accounts.fee_quoter_dest_chain.to_account_info(),
@@ -261,7 +262,14 @@ impl OnRamp for Impl {
261262
dest_chain_selector,
262263
&message,
263264
ctx.remaining_accounts.to_vec(),
264-
)
265+
)?;
266+
267+
// not all fields that fee quoter returns are relevant for the user, so just pick the important ones
268+
Ok(GetFeeResult {
269+
amount: fq_result.amount,
270+
juels: fq_result.juels,
271+
token: fq_result.token,
272+
})
265273
}
266274
}
267275

chains/solana/contracts/programs/ccip-router/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::state::*;
1313
mod event;
1414
use crate::event::*;
1515

16-
mod messages;
16+
pub mod messages;
1717
use crate::messages::*;
1818

1919
mod instructions;
@@ -37,8 +37,6 @@ declare_id!("Ccip842gzYHhvdDkSyi2YVCoAWPbYJoApMFzSxQroE9C");
3737
pub mod ccip_router {
3838
#![warn(missing_docs)]
3939

40-
use fee_quoter::messages::GetFeeResult;
41-
4240
use super::*;
4341

4442
//////////////////////////

chains/solana/contracts/programs/ccip-router/src/messages.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ impl<T: Into<ethnum::U256>> From<T> for CrossChainAmount {
8080
}
8181
}
8282
}
83+
84+
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Default, Debug)]
85+
pub struct GetFeeResult {
86+
pub amount: u64,
87+
pub juels: u128,
88+
pub token: Pubkey,
89+
}

chains/solana/contracts/programs/example-ccip-sender/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ custom-heap = []
2020
solana-program = "1.17.25" # pin solana to 1.17
2121
anchor-lang = { version = "0.29.0", features = [] }
2222
anchor-spl = "0.29.0"
23-
fee_quoter = { version = "0.1.0-dev", path = "../fee-quoter", features = ["no-entrypoint"]}
23+
ccip_router = { version = "0.1.0-dev", path = "../ccip-router", features = ["no-entrypoint"]}
2424
smalloc = "0.1.2"

chains/solana/contracts/programs/example-ccip-sender/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
#![allow(unexpected_cfgs)]
2+
13
use anchor_lang::prelude::*;
24
use anchor_spl::token_2022::spl_token_2022::{self, instruction::transfer_checked};
3-
use fee_quoter::messages::{GetFeeResult, SVM2AnyMessage, SVMTokenAmount};
45
use solana_program::{
56
instruction::Instruction,
67
program::{get_return_data, invoke, invoke_signed},
78
};
89

10+
use ccip_router::messages::{GetFeeResult, SVM2AnyMessage, SVMTokenAmount};
11+
912
declare_id!("4LfBQWYaU6zQZbDyYjX8pbY4qjzrhoumUFYZEZEqMNhJ");
1013

1114
#[cfg(target_os = "solana")]
@@ -29,7 +32,7 @@ use tokens::*;
2932
pub const CHAIN_CONFIG_SEED: &[u8] = b"remote_chain_config";
3033
pub const CCIP_SENDER: &[u8] = b"ccip_sender";
3134

32-
pub const CCIP_SEND_DISCIRIMINATOR: [u8; 8] = [108, 216, 134, 191, 249, 234, 33, 84]; // ccip_send
35+
pub const CCIP_SEND_DISCRIMINATOR: [u8; 8] = [108, 216, 134, 191, 249, 234, 33, 84]; // ccip_send
3336
pub const CCIP_GET_FEE_DISCRIMINATOR: [u8; 8] = [115, 195, 235, 161, 25, 219, 60, 29]; // get_fee
3437

3538
/// This program an example of a CCIP Sender Program.
@@ -85,6 +88,9 @@ pub mod example_ccip_sender {
8588
// CPI: get fee from router
8689
let fee: GetFeeResult = {
8790
let mut acc_infos: Vec<AccountInfo> = [
91+
ctx.accounts.ccip_config.to_account_info(),
92+
ctx.accounts.ccip_dest_chain_state.to_account_info(),
93+
ctx.accounts.ccip_fee_quoter.to_account_info(),
8894
ctx.accounts.ccip_fee_quoter_config.to_account_info(),
8995
ctx.accounts.ccip_fee_quoter_dest_chain.to_account_info(),
9096
ctx.accounts
@@ -115,7 +121,7 @@ pub mod example_ccip_sender {
115121
.collect();
116122

117123
let instruction = Instruction {
118-
program_id: ctx.accounts.ccip_fee_quoter.key(),
124+
program_id: ctx.accounts.ccip_router.key(),
119125
accounts: acc_metas,
120126
data: builder::instruction(
121127
&message,
@@ -192,7 +198,7 @@ pub mod example_ccip_sender {
192198
accounts: acc_metas,
193199
data: builder::instruction_with_token_indexes(
194200
&message,
195-
CCIP_SEND_DISCIRIMINATOR,
201+
CCIP_SEND_DISCRIMINATOR,
196202
dest_chain_selector,
197203
&ccip_token_indexes,
198204
),

chains/solana/contracts/programs/example-ccip-sender/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl RemoteChainConfig {
6969

7070
pub mod builder {
7171
use anchor_lang::AnchorSerialize;
72-
use fee_quoter::messages::SVM2AnyMessage;
72+
use ccip_router::messages::SVM2AnyMessage;
7373

7474
pub fn instruction(
7575
msg: &SVM2AnyMessage,

chains/solana/contracts/programs/example-ccip-sender/src/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anchor_spl::{
66
},
77
token_interface,
88
};
9-
use fee_quoter::messages::SVMTokenAmount;
9+
use ccip_router::messages::SVMTokenAmount;
1010
use solana_program::{address_lookup_table::state::AddressLookupTable, program::invoke_signed};
1111

1212
#[allow(clippy::too_many_arguments)]

chains/solana/contracts/target/idl/ccip_router.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,26 @@
14131413
]
14141414
}
14151415
},
1416+
{
1417+
"name": "GetFeeResult",
1418+
"type": {
1419+
"kind": "struct",
1420+
"fields": [
1421+
{
1422+
"name": "amount",
1423+
"type": "u64"
1424+
},
1425+
{
1426+
"name": "juels",
1427+
"type": "u128"
1428+
},
1429+
{
1430+
"name": "token",
1431+
"type": "publicKey"
1432+
}
1433+
]
1434+
}
1435+
},
14161436
{
14171437
"name": "DestChainState",
14181438
"type": {

0 commit comments

Comments
 (0)