Skip to content

Commit 5b22283

Browse files
authored
Merge pull request #153 from m0-foundation/kurtis/fix-m-mint-create
update CLI cmds & fix transfer in portal
2 parents 9aa7510 + 16773ae commit 5b22283

File tree

6 files changed

+237
-98
lines changed

6 files changed

+237
-98
lines changed

pnpm-lock.yaml

Lines changed: 41 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

programs/portal/src/instructions/transfer.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct TransferBurn<'info> {
135135
impl<'info> TransferBurn<'info> {
136136
// Manually validate accounts instead of using anchor constraints
137137
// so that the context can be shared (nested contexts do not support instruction args)
138-
pub fn validate_accounts(&self, args: &TransferArgs) -> Result<(Pubkey, u8)> {
138+
pub fn validate_accounts(&self, args: &TransferArgs) -> Result<u8> {
139139
let inbox_rate_limit = Pubkey::create_program_address(
140140
&[
141141
InboxRateLimit::SEED_PREFIX,
@@ -181,31 +181,41 @@ impl<'info> TransferBurn<'info> {
181181
return err!(ErrorCode::ConstraintAddress);
182182
}
183183

184-
Ok((session_owner_seed, session_authority_bump))
184+
Ok(session_authority_bump)
185185
}
186186
}
187187

188188
pub fn transfer_burn<'info>(
189189
ctx: Context<'_, '_, '_, 'info, TransferBurn<'info>>,
190190
args: TransferArgs,
191191
) -> Result<()> {
192-
let (session_owner_seed, session_authority_bump) = ctx.accounts.validate_accounts(&args)?;
192+
let amount = args.amount;
193+
transfer_burn_common(ctx, args, amount)
194+
}
195+
196+
pub fn transfer_burn_common<'info>(
197+
ctx: Context<'_, '_, '_, 'info, TransferBurn<'info>>,
198+
args: TransferArgs,
199+
principal_amount_m: u64,
200+
) -> Result<()> {
201+
let session_authority_bump = ctx.accounts.validate_accounts(&args)?;
193202

194203
let accs = ctx.accounts;
195204

196205
let TransferArgs {
197-
amount: principal,
198206
recipient_chain,
199207
recipient_address,
200208
should_queue,
209+
..
201210
} = args;
202211

203212
// The provided "amount" is the principal amount of M to bridge.
204213
// We scale this up to M units using the scaled UI config multiplier.
205214
let scaled_ui_config = earn::utils::conversion::get_scaled_ui_config(&accs.common.mint)?;
215+
206216
// Get the amount of M tokens to transfer using the multiplier
207217
let mut m_amount = earn::utils::conversion::principal_to_amount_down(
208-
principal,
218+
principal_amount_m,
209219
scaled_ui_config.new_multiplier.into(),
210220
)?;
211221

@@ -241,11 +251,11 @@ pub fn transfer_burn<'info>(
241251
accs.common.custody.to_account_info(),
242252
accs.session_authority.to_account_info(),
243253
ctx.remaining_accounts,
244-
principal,
254+
principal_amount_m,
245255
accs.common.mint.decimals,
246256
&[&[
247257
crate::SESSION_AUTHORITY_SEED,
248-
session_owner_seed.as_ref(),
258+
accs.common.payer.key.as_ref(),
249259
args.keccak256().as_ref(),
250260
&[session_authority_bump],
251261
]],
@@ -262,7 +272,7 @@ pub fn transfer_burn<'info>(
262272
},
263273
&[&[crate::TOKEN_AUTHORITY_SEED, &[ctx.bumps.token_authority]]],
264274
),
265-
principal,
275+
principal_amount_m,
266276
)?;
267277

268278
accs.common.custody.reload()?;

programs/portal/src/instructions/transfer_extension.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use ext_swap::{accounts::SwapGlobal, program::ExtSwap};
55

66
use crate::{
77
TransferBurnBumps, __client_accounts_transfer_burn, __cpi_client_accounts_transfer_burn,
8-
instructions::{ext_swap, transfer_burn, TransferArgs, TransferBurn},
9-
ntt_messages::ChainId,
8+
instructions::{ext_swap, transfer_burn_common, TransferArgs, TransferBurn},
109
};
1110

1211
#[derive(Accounts)]
@@ -76,12 +75,21 @@ pub struct TransferExtensionBurn<'info> {
7675

7776
pub fn transfer_extension_burn<'info>(
7877
ctx: Context<'_, '_, '_, 'info, TransferExtensionBurn<'info>>,
79-
ext_principal: u64,
80-
recipient_chain: ChainId,
81-
recipient_address: [u8; 32],
78+
args: TransferArgs,
8279
destination_token: [u8; 32],
83-
should_queue: bool,
8480
) -> Result<()> {
81+
// $M token account should be owned by token authority
82+
if !ctx
83+
.accounts
84+
.common
85+
.common
86+
.from
87+
.owner
88+
.eq(ctx.accounts.common.token_authority.key)
89+
{
90+
return err!(ErrorCode::ConstraintTokenOwner);
91+
}
92+
8593
let m_pre_balance = ctx.accounts.common.common.from.amount;
8694
let token_auth_bump = ctx.bumps.common.token_authority;
8795

@@ -108,7 +116,7 @@ pub fn transfer_extension_burn<'info>(
108116
},
109117
&[&[crate::TOKEN_AUTHORITY_SEED, &[token_auth_bump]]],
110118
),
111-
ext_principal,
119+
args.amount,
112120
)?;
113121

114122
// Amount of $M we got from unwrap
@@ -140,15 +148,7 @@ pub fn transfer_extension_burn<'info>(
140148
);
141149

142150
// TransferBurn $M from unwrap
143-
transfer_burn(
144-
sub_ctx,
145-
TransferArgs {
146-
amount: m_amount,
147-
recipient_chain: recipient_chain,
148-
recipient_address: recipient_address,
149-
should_queue: should_queue,
150-
},
151-
)?;
151+
transfer_burn_common(sub_ctx, args, m_amount)?;
152152

153153
// Overwrite default destination token
154154
ctx.accounts.common.common.outbox_item.destination_token = destination_token;

programs/portal/src/lib.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ pub mod queue;
1717
pub mod registered_transceiver;
1818
pub mod transceivers;
1919

20-
use crate::ntt_messages::ChainId;
21-
use transceivers::wormhole::instructions::*;
22-
2320
use instructions::*;
21+
use transceivers::wormhole::instructions::*;
2422

2523
#[cfg(not(feature = "no-entrypoint"))]
2624
solana_security_txt::security_txt! {
@@ -90,20 +88,10 @@ pub mod portal {
9088

9189
pub fn transfer_extension_burn<'info>(
9290
ctx: Context<'_, '_, '_, 'info, TransferExtensionBurn<'info>>,
93-
ext_principal: u64,
94-
recipient_chain: ChainId,
95-
recipient_address: [u8; 32],
91+
args: TransferArgs,
9692
destination_token: [u8; 32],
97-
should_queue: bool,
9893
) -> Result<()> {
99-
instructions::transfer_extension_burn(
100-
ctx,
101-
ext_principal,
102-
recipient_chain,
103-
recipient_address,
104-
destination_token,
105-
should_queue,
106-
)
94+
instructions::transfer_extension_burn(ctx, args, destination_token)
10795
}
10896

10997
pub fn redeem(ctx: Context<Redeem>, args: RedeemArgs) -> Result<()> {

0 commit comments

Comments
 (0)