Skip to content

Commit 5271959

Browse files
committed
solana: rename NativeTokenTransferConcrete, fixes #526
1 parent 67df547 commit 5271959

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

solana/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ See the [NttManager](../docs/NttManager.md) doc for wire format details.
105105

106106
Modify [transfer.rs](./programs/example-native-token-transfers/src/transfer.rs) and replace the `EmptyPayload` with your own custom struct. See [ntt.rs](./modules/ntt-messages/src/ntt.rs) for an example. It is highly encouraged to use a 4-byte prefix for your payload.
107107

108-
The additional payload field should then have your custom struct available everywhere `NativeTokenTransferConcrete` is used. Due to typing, parsing, and account allocation restrictions, this implementation expects that _all_ `NativeTokenTransfer` payloads for your contract adhere to your custom struct definition.
108+
The additional payload field should then have your custom struct available everywhere `NativeTokenTransfer<Payload>` is used. Due to typing, parsing, and account allocation restrictions, this implementation expects that _all_ `NativeTokenTransfer` payloads for your contract adhere to your custom struct definition.
109109

110110
You can then modify [release_outbound](./programs/example-native-token-transfers/src/transceivers/wormhole/instructions/release_outbound.rs) and [redeem](./programs/example-native-token-transfers/src/instructions/redeem.rs) to generate and process the additional payload.
111111

solana/programs/example-native-token-transfers/src/instructions/redeem.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anchor_lang::prelude::*;
22
use anchor_spl::token_interface;
3-
use ntt_messages::ntt_manager::NttManagerMessage;
3+
use ntt_messages::{ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage};
44

55
use crate::{
66
bitmap::Bitmap,
@@ -14,7 +14,7 @@ use crate::{
1414
rate_limit::RateLimitResult,
1515
},
1616
registered_transceiver::*,
17-
transfer::NativeTokenTransferConcrete,
17+
transfer::Payload,
1818
};
1919

2020
#[derive(Accounts)]
@@ -45,7 +45,7 @@ pub struct Redeem<'info> {
4545
owner = transceiver.transceiver_address,
4646
)]
4747
pub transceiver_message:
48-
Account<'info, ValidatedTransceiverMessage<NativeTokenTransferConcrete>>,
48+
Account<'info, ValidatedTransceiverMessage<NativeTokenTransfer<Payload>>>,
4949

5050
#[account(
5151
constraint = config.enabled_transceivers.get(transceiver.id)? @ NTTError::DisabledTransceiver
@@ -105,7 +105,7 @@ pub struct RedeemArgs {}
105105
pub fn redeem(ctx: Context<Redeem>, _args: RedeemArgs) -> Result<()> {
106106
let accs = ctx.accounts;
107107

108-
let message: NttManagerMessage<NativeTokenTransferConcrete> =
108+
let message: NttManagerMessage<NativeTokenTransfer<Payload>> =
109109
accs.transceiver_message.message.ntt_manager_payload.clone();
110110

111111
// Calculate the scaled amount based on the appropriate decimal encoding for the token.

solana/programs/example-native-token-transfers/src/transceivers/wormhole/instructions/receive_message.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use anchor_lang::prelude::*;
22

33
use ntt_messages::{
44
chain_id::ChainId,
5+
ntt::NativeTokenTransfer,
56
transceiver::{TransceiverMessage, TransceiverMessageData},
67
transceivers::wormhole::WormholeTransceiver,
78
};
89
use wormhole_anchor_sdk::wormhole::PostedVaa;
910

1011
use crate::{
1112
config::*, error::NTTError, messages::ValidatedTransceiverMessage,
12-
transceivers::accounts::peer::TransceiverPeer, transfer::NativeTokenTransferConcrete,
13+
transceivers::accounts::peer::TransceiverPeer, transfer::Payload,
1314
};
1415

1516
#[derive(Accounts)]
@@ -37,15 +38,15 @@ pub struct ReceiveMessage<'info> {
3738
)]
3839
pub vaa: Account<
3940
'info,
40-
PostedVaa<TransceiverMessage<WormholeTransceiver, NativeTokenTransferConcrete>>,
41+
PostedVaa<TransceiverMessage<WormholeTransceiver, NativeTokenTransfer<Payload>>>,
4142
>,
4243

4344
#[account(
4445
init,
4546
payer = payer,
46-
space = 8 + ValidatedTransceiverMessage::<TransceiverMessageData<NativeTokenTransferConcrete>>::INIT_SPACE,
47+
space = 8 + ValidatedTransceiverMessage::<TransceiverMessageData<NativeTokenTransfer<Payload>>>::INIT_SPACE,
4748
seeds = [
48-
ValidatedTransceiverMessage::<TransceiverMessageData<NativeTokenTransferConcrete>>::SEED_PREFIX,
49+
ValidatedTransceiverMessage::<TransceiverMessageData<NativeTokenTransfer<Payload>>>::SEED_PREFIX,
4950
vaa.emitter_chain().to_be_bytes().as_ref(),
5051
vaa.message().ntt_manager_payload.id.as_ref(),
5152
],
@@ -56,7 +57,7 @@ pub struct ReceiveMessage<'info> {
5657
// attested to the transfer. Then we only release it if there's quorum.
5758
// We would need to maybe_init this account in that case.
5859
pub transceiver_message:
59-
Account<'info, ValidatedTransceiverMessage<NativeTokenTransferConcrete>>,
60+
Account<'info, ValidatedTransceiverMessage<NativeTokenTransfer<Payload>>>,
6061

6162
pub system_program: Program<'info, System>,
6263
}

solana/programs/example-native-token-transfers/src/transceivers/wormhole/instructions/release_outbound.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use anchor_lang::prelude::*;
22

33
use ntt_messages::{
4-
ntt::EmptyPayload, ntt_manager::NttManagerMessage, transceiver::TransceiverMessage,
4+
ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage, transceiver::TransceiverMessage,
55
transceivers::wormhole::WormholeTransceiver,
66
};
77

88
use crate::{
99
config::*, error::NTTError, queue::outbox::OutboxItem, registered_transceiver::*,
10-
transceivers::wormhole::accounts::*, transfer::NativeTokenTransferConcrete,
10+
transceivers::wormhole::accounts::*, transfer::Payload,
1111
};
1212

1313
#[derive(Accounts)]
@@ -66,20 +66,20 @@ pub fn release_outbound(ctx: Context<ReleaseOutbound>, args: ReleaseOutboundArgs
6666
}
6767

6868
assert!(accs.outbox_item.released.get(accs.transceiver.id)?);
69-
let message: TransceiverMessage<WormholeTransceiver, NativeTokenTransferConcrete> =
69+
let message: TransceiverMessage<WormholeTransceiver, NativeTokenTransfer<Payload>> =
7070
TransceiverMessage::new(
7171
// TODO: should we just put the ntt id here statically?
7272
accs.outbox_item.to_account_info().owner.to_bytes(),
7373
accs.outbox_item.recipient_ntt_manager,
7474
NttManagerMessage {
7575
id: accs.outbox_item.key().to_bytes(),
7676
sender: accs.outbox_item.sender.to_bytes(),
77-
payload: NativeTokenTransferConcrete {
77+
payload: NativeTokenTransfer {
7878
amount: accs.outbox_item.amount,
7979
source_token: accs.config.mint.to_bytes(),
8080
to: accs.outbox_item.recipient_address,
8181
to_chain: accs.outbox_item.recipient_chain,
82-
additional_payload: EmptyPayload {},
82+
additional_payload: Payload {},
8383
},
8484
},
8585
vec![],
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
use ntt_messages::{ntt::EmptyPayload, ntt::NativeTokenTransfer};
1+
use ntt_messages::ntt::EmptyPayload;
22

3-
pub type NativeTokenTransferConcrete = NativeTokenTransfer<EmptyPayload>;
3+
pub type Payload = EmptyPayload;

solana/programs/example-native-token-transfers/tests/cancel_flow.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use example_native_token_transfers::{
77
error::NTTError,
88
instructions::{RedeemArgs, TransferArgs},
99
queue::{inbox::InboxRateLimit, outbox::OutboxRateLimit},
10-
transfer::NativeTokenTransferConcrete,
10+
transfer::Payload,
1111
};
1212
use ntt_messages::{
13-
chain_id::ChainId, mode::Mode, ntt::EmptyPayload, ntt_manager::NttManagerMessage,
13+
chain_id::ChainId, mode::Mode, ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage,
1414
transceiver::TransceiverMessage, transceivers::wormhole::WormholeTransceiver,
1515
trimmed_amount::TrimmedAmount,
1616
};
@@ -69,7 +69,7 @@ fn init_redeem_accs(
6969
ctx: &mut ProgramTestContext,
7070
test_data: &TestData,
7171
chain_id: u16,
72-
ntt_manager_message: NttManagerMessage<NativeTokenTransferConcrete>,
72+
ntt_manager_message: NttManagerMessage<NativeTokenTransfer<Payload>>,
7373
) -> Redeem {
7474
Redeem {
7575
payer: ctx.payer.pubkey(),
@@ -110,23 +110,23 @@ async fn post_transfer_vaa(
110110
// dedicated receive transfer test suite
111111
recipient_ntt_manager: Option<&Pubkey>,
112112
recipient: &Keypair,
113-
) -> (Pubkey, NttManagerMessage<NativeTokenTransferConcrete>) {
113+
) -> (Pubkey, NttManagerMessage<NativeTokenTransfer<Payload>>) {
114114
let ntt_manager_message = NttManagerMessage {
115115
id,
116116
sender: [4u8; 32],
117-
payload: NativeTokenTransferConcrete {
117+
payload: NativeTokenTransfer {
118118
amount: TrimmedAmount {
119119
amount,
120120
decimals: 9,
121121
},
122122
source_token: [3u8; 32],
123123
to_chain: ChainId { id: THIS_CHAIN },
124124
to: recipient.pubkey().to_bytes(),
125-
additional_payload: EmptyPayload {},
125+
additional_payload: Payload {},
126126
},
127127
};
128128

129-
let transceiver_message: TransceiverMessage<WormholeTransceiver, NativeTokenTransferConcrete> =
129+
let transceiver_message: TransceiverMessage<WormholeTransceiver, NativeTokenTransfer<Payload>> =
130130
TransceiverMessage::new(
131131
OTHER_MANAGER,
132132
recipient_ntt_manager

solana/programs/example-native-token-transfers/tests/sdk/accounts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use example_native_token_transfers::{
77
outbox::OutboxRateLimit,
88
},
99
registered_transceiver::RegisteredTransceiver,
10-
transfer::NativeTokenTransferConcrete,
10+
transfer::Payload,
1111
SESSION_AUTHORITY_SEED, TOKEN_AUTHORITY_SEED,
1212
};
13-
use ntt_messages::ntt_manager::NttManagerMessage;
13+
use ntt_messages::{ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage};
1414
use sha3::{Digest, Keccak256};
1515
use wormhole_anchor_sdk::wormhole;
1616
use wormhole_io::TypePrefixedPayload;
@@ -120,7 +120,7 @@ impl NTT {
120120
pub fn inbox_item(
121121
&self,
122122
chain: u16,
123-
ntt_manager_message: NttManagerMessage<NativeTokenTransferConcrete>,
123+
ntt_manager_message: NttManagerMessage<NativeTokenTransfer<Payload>>,
124124
) -> Pubkey {
125125
let mut hasher = Keccak256::new();
126126
hasher.update(chain.to_be_bytes());

solana/programs/example-native-token-transfers/tests/transfer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use example_native_token_transfers::{
1010
instructions::TransferArgs,
1111
queue::outbox::{OutboxItem, OutboxRateLimit},
1212
transceivers::wormhole::ReleaseOutboundArgs,
13-
transfer::NativeTokenTransferConcrete,
13+
transfer::Payload,
1414
};
1515
use ntt_messages::{
16-
chain_id::ChainId, mode::Mode, ntt::EmptyPayload, ntt_manager::NttManagerMessage,
16+
chain_id::ChainId, mode::Mode, ntt::NativeTokenTransfer, ntt_manager::NttManagerMessage,
1717
transceiver::TransceiverMessage, transceivers::wormhole::WormholeTransceiver,
1818
trimmed_amount::TrimmedAmount,
1919
};
@@ -195,7 +195,7 @@ async fn test_transfer(ctx: &mut ProgramTestContext, test_data: &TestData, mode:
195195
// They are identical modulo the discriminator, which we just skip by using
196196
// the unchecked deserialiser.
197197
// TODO: update the sdk to export PostedMessage
198-
let msg: PostedVaa<TransceiverMessage<WormholeTransceiver, NativeTokenTransferConcrete>> =
198+
let msg: PostedVaa<TransceiverMessage<WormholeTransceiver, NativeTokenTransfer<Payload>>> =
199199
ctx.get_account_data_anchor_unchecked(wh_message).await;
200200

201201
let transceiver_message = msg.data();
@@ -208,15 +208,15 @@ async fn test_transfer(ctx: &mut ProgramTestContext, test_data: &TestData, mode:
208208
NttManagerMessage {
209209
id: outbox_item.pubkey().to_bytes(),
210210
sender: test_data.user.pubkey().to_bytes(),
211-
payload: NativeTokenTransferConcrete {
211+
payload: NativeTokenTransfer {
212212
amount: TrimmedAmount {
213213
amount: 1,
214214
decimals: 7
215215
},
216216
source_token: test_data.mint.to_bytes(),
217217
to: [1u8; 32],
218218
to_chain: ChainId { id: 2 },
219-
additional_payload: EmptyPayload {}
219+
additional_payload: Payload {}
220220
}
221221
},
222222
vec![]

0 commit comments

Comments
 (0)