Skip to content

Commit

Permalink
Better type for TokenProgram when it can be 2022 or pre-2022
Browse files Browse the repository at this point in the history
  • Loading branch information
toblich committed Dec 20, 2024
1 parent 4e2de67 commit c773fbc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 54 deletions.
24 changes: 3 additions & 21 deletions chains/solana/contracts/programs/ccip-router/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,7 @@ pub struct AddBillingTokenConfig<'info> {
)]
pub billing_token_config: Account<'info, BillingTokenConfigWrapper>,

/// CHECK: This is the token program OR the token-2022 program. Given that there are 2 options, this can't have the
/// type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount
/// with a constraint enforcing that it is one of the two allowed programs.
#[account(
constraint = TokenInterface::ids().contains(&token_program.key()) @ CcipRouterError::InvalidInputs,
)]
pub token_program: UncheckedAccount<'info>,
pub token_program: Interface<'info, TokenInterface>,

#[account(
owner = token_program.key() @ CcipRouterError::InvalidInputs,
Expand Down Expand Up @@ -425,13 +419,7 @@ pub struct RemoveBillingTokenConfig<'info> {
)]
pub billing_token_config: Account<'info, BillingTokenConfigWrapper>,

/// CHECK: This is the token program OR the token-2022 program. Given that there are 2 options, this can't have the
/// type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount
/// with a constraint enforcing that it is one of the two allowed programs.
#[account(
constraint = TokenInterface::ids().contains(&token_program.key()) @ CcipRouterError::InvalidInputs,
)]
pub token_program: UncheckedAccount<'info>,
pub token_program: Interface<'info, TokenInterface>,

#[account(
owner = token_program.key() @ CcipRouterError::InvalidInputs,
Expand Down Expand Up @@ -497,13 +485,7 @@ pub struct CcipSend<'info> {
// billing token //
///////////////////
// TODO improve all usages of CcipRouterError::InvalidInputs to be more specific
/// CHECK: This is the token program OR the token-2022 program. Given that there are 2 options, this can't have the
/// type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount
/// with a constraint enforcing that it is one of the two allowed programs.
#[account(
constraint = TokenInterface::ids().contains(&fee_token_program.key()) @ CcipRouterError::InvalidInputs,
)]
pub fee_token_program: UncheckedAccount<'info>,
pub fee_token_program: Interface<'info, TokenInterface>,

#[account(
owner = fee_token_program.key() @ CcipRouterError::InvalidInputs,
Expand Down
18 changes: 3 additions & 15 deletions chains/solana/contracts/target/idl/ccip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,7 @@
{
"name": "tokenProgram",
"isMut": false,
"isSigner": false,
"docs": [
"type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount",
"with a constraint enforcing that it is one of the two allowed programs."
]
"isSigner": false
},
{
"name": "feeTokenMint",
Expand Down Expand Up @@ -944,11 +940,7 @@
{
"name": "tokenProgram",
"isMut": false,
"isSigner": false,
"docs": [
"type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount",
"with a constraint enforcing that it is one of the two allowed programs."
]
"isSigner": false
},
{
"name": "feeTokenMint",
Expand Down Expand Up @@ -1066,11 +1058,7 @@
{
"name": "feeTokenProgram",
"isMut": false,
"isSigner": false,
"docs": [
"type of a specific program (which would enforce its ID). Thus, it's an UncheckedAccount",
"with a constraint enforcing that it is one of the two allowed programs."
]
"isSigner": false
},
{
"name": "feeTokenMint",
Expand Down
6 changes: 0 additions & 6 deletions chains/solana/gobindings/ccip_router/AddBillingTokenConfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions chains/solana/gobindings/ccip_router/CcipSend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c773fbc

Please sign in to comment.