Skip to content

Commit 577d230

Browse files
authored
correctly triage between T22 and legacy tokens for creator fee transfers (#29)
* correctly triage between T22 and legacy tokens for creator fee transfers * fmt
1 parent 480ec1b commit 577d230

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

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.

toolbox/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name = "tensor-toolbox"
33
description = "Toolbox of useful Rust utilities for Tensor Foundation's Solana programs"
44
repository = "https://github.com/tensor-foundation/toolbox"
55
homepage = "https://github.com/tensor-foundation/toolbox"
6-
version = "0.6.0"
6+
version = "0.7.0"
77
edition = "2021"
88
readme = "../README.md"
99
license = "Apache-2.0"
1010

1111
[features]
12+
default = ["token-2022"]
1213
cnft = ["dep:mpl-bubblegum"]
1314
mpl-core = ["dep:mpl-core"]
1415
token-2022 = []

toolbox/src/common.rs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use mpl_token_metadata::types::TokenStandard;
88
use std::slice::Iter;
99
use tensor_vipers::prelude::*;
1010

11+
use crate::token_2022::transfer::transfer_checked as token_2022_transfer_checked;
1112
use crate::TensorError;
1213

1314
pub const HUNDRED_PCT_BPS: u64 = 10000;
@@ -364,17 +365,40 @@ pub fn transfer_creators_fee<'a, 'info>(
364365
},
365366
))?;
366367

367-
anchor_spl::token::transfer(
368-
CpiContext::new(
369-
token_program.to_account_info(),
370-
anchor_spl::token::Transfer {
371-
from: from_ata.to_account_info(),
372-
to: current_creator_ata_info.to_account_info(),
373-
authority: from.to_account_info(),
374-
},
375-
),
376-
creator_fee,
377-
)?;
368+
match token_program.key() {
369+
anchor_spl::token::ID => {
370+
anchor_spl::token::transfer(
371+
CpiContext::new(
372+
token_program.to_account_info(),
373+
anchor_spl::token::Transfer {
374+
from: from_ata.to_account_info(),
375+
to: current_creator_ata_info.to_account_info(),
376+
authority: from.to_account_info(),
377+
},
378+
),
379+
creator_fee,
380+
)?;
381+
}
382+
anchor_spl::token_interface::ID => {
383+
let mint = anchor_spl::token_interface::Mint::try_deserialize(
384+
&mut &currency.data.borrow()[..],
385+
)?;
386+
token_2022_transfer_checked(
387+
CpiContext::new(
388+
token_program.to_account_info(),
389+
anchor_spl::token_interface::TransferChecked {
390+
from: from_ata.to_account_info(),
391+
mint: currency.to_account_info(),
392+
to: current_creator_ata_info.to_account_info(),
393+
authority: from.to_account_info(),
394+
},
395+
),
396+
creator_fee,
397+
mint.decimals,
398+
)?;
399+
}
400+
_ => return Err(ErrorCode::InvalidProgramId.into()),
401+
}
378402
}
379403
}
380404
}

0 commit comments

Comments
 (0)