Skip to content

Commit 6cc8bee

Browse files
nvsriramjohnsaigle
andauthored
solana: Add no registered transceivers check (#514)
* Add check for no registered transceivers * Update IDL --------- Co-authored-by: John Saigle <[email protected]>
1 parent 3c626bd commit 6cc8bee

File tree

7 files changed

+94
-15
lines changed

7 files changed

+94
-15
lines changed

solana/programs/example-native-token-transfers/src/bitmap.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ impl Bitmap {
4747
.try_into()
4848
.expect("Bitmap length must not exceed the bounds of u8")
4949
}
50+
51+
pub fn len(self) -> usize {
52+
BM::<128>::from_value(self.map).len()
53+
}
54+
55+
pub fn is_empty(self) -> bool {
56+
BM::<128>::from_value(self.map).is_empty()
57+
}
5058
}
5159

5260
#[cfg(test)]

solana/programs/example-native-token-transfers/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub enum NTTError {
5151
OverflowScaledAmount,
5252
#[msg("BitmapIndexOutOfBounds")]
5353
BitmapIndexOutOfBounds,
54+
#[msg("NoRegisteredTransceivers")]
55+
NoRegisteredTransceivers,
5456
}
5557

5658
impl From<ScalingError> for NTTError {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pub struct Transfer<'info> {
3737
#[account(mut)]
3838
pub payer: Signer<'info>,
3939

40+
// Ensure that there exists at least one enabled transceiver
41+
#[account(
42+
constraint = !config.enabled_transceivers.is_empty() @ NTTError::NoRegisteredTransceivers,
43+
)]
4044
pub config: NotPausedConfig<'info>,
4145

4246
#[account(
@@ -153,6 +157,7 @@ pub fn transfer_burn<'info>(
153157
args: TransferArgs,
154158
) -> Result<()> {
155159
let accs = ctx.accounts;
160+
156161
let TransferArgs {
157162
mut amount,
158163
recipient_chain,
@@ -293,6 +298,7 @@ pub fn transfer_lock<'info>(
293298
args: TransferArgs,
294299
) -> Result<()> {
295300
let accs = ctx.accounts;
301+
296302
let TransferArgs {
297303
mut amount,
298304
recipient_chain,

solana/ts/idl/2_0_0/json/example_native_token_transfers.json

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838
{
3939
"name": "tokenAuthority",
4040
"isMut": false,
41-
"isSigner": false
41+
"isSigner": false,
42+
"docs": [
43+
"In any case, this function is used to set the Config and initialize the program so we",
44+
"assume the caller of this function will have total control over the program.",
45+
"",
46+
"TODO: Using `UncheckedAccount` here leads to \"Access violation in stack frame ...\".",
47+
"Could refactor code to use `Box<_>` to reduce stack size."
48+
]
4249
},
4350
{
4451
"name": "custody",
@@ -508,7 +515,10 @@
508515
{
509516
"name": "tokenAuthority",
510517
"isMut": false,
511-
"isSigner": false
518+
"isSigner": false,
519+
"docs": [
520+
"CHECK The seeds constraint ensures that this is the correct address"
521+
]
512522
},
513523
{
514524
"name": "mint",
@@ -571,7 +581,10 @@
571581
{
572582
"name": "tokenAuthority",
573583
"isMut": false,
574-
"isSigner": false
584+
"isSigner": false,
585+
"docs": [
586+
"CHECK The seeds constraint ensures that this is the correct address"
587+
]
575588
},
576589
{
577590
"name": "mint",
@@ -752,7 +765,10 @@
752765
{
753766
"name": "transceiver",
754767
"isMut": false,
755-
"isSigner": false
768+
"isSigner": false,
769+
"docs": [
770+
"used here that wraps the Transceiver account type."
771+
]
756772
},
757773
{
758774
"name": "registeredTransceiver",
@@ -1927,6 +1943,11 @@
19271943
"code": 6022,
19281944
"name": "BitmapIndexOutOfBounds",
19291945
"msg": "BitmapIndexOutOfBounds"
1946+
},
1947+
{
1948+
"code": 6023,
1949+
"name": "NoRegisteredTransceivers",
1950+
"msg": "NoRegisteredTransceivers"
19301951
}
19311952
]
19321953
}

solana/ts/idl/2_0_0/json/wormhole_governance.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"isMut": true,
1616
"isSigner": false,
1717
"docs": [
18-
"governed program."
18+
"governed program. This account is validated by Wormhole, not this program."
1919
]
2020
},
2121
{

solana/ts/idl/2_0_0/ts/example_native_token_transfers.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ export type ExampleNativeTokenTransfers = {
3838
{
3939
"name": "tokenAuthority",
4040
"isMut": false,
41-
"isSigner": false
41+
"isSigner": false,
42+
"docs": [
43+
"In any case, this function is used to set the Config and initialize the program so we",
44+
"assume the caller of this function will have total control over the program.",
45+
"",
46+
"TODO: Using `UncheckedAccount` here leads to \"Access violation in stack frame ...\".",
47+
"Could refactor code to use `Box<_>` to reduce stack size."
48+
]
4249
},
4350
{
4451
"name": "custody",
@@ -508,7 +515,10 @@ export type ExampleNativeTokenTransfers = {
508515
{
509516
"name": "tokenAuthority",
510517
"isMut": false,
511-
"isSigner": false
518+
"isSigner": false,
519+
"docs": [
520+
"CHECK The seeds constraint ensures that this is the correct address"
521+
]
512522
},
513523
{
514524
"name": "mint",
@@ -571,7 +581,10 @@ export type ExampleNativeTokenTransfers = {
571581
{
572582
"name": "tokenAuthority",
573583
"isMut": false,
574-
"isSigner": false
584+
"isSigner": false,
585+
"docs": [
586+
"CHECK The seeds constraint ensures that this is the correct address"
587+
]
575588
},
576589
{
577590
"name": "mint",
@@ -752,7 +765,10 @@ export type ExampleNativeTokenTransfers = {
752765
{
753766
"name": "transceiver",
754767
"isMut": false,
755-
"isSigner": false
768+
"isSigner": false,
769+
"docs": [
770+
"used here that wraps the Transceiver account type."
771+
]
756772
},
757773
{
758774
"name": "registeredTransceiver",
@@ -1927,6 +1943,11 @@ export type ExampleNativeTokenTransfers = {
19271943
"code": 6022,
19281944
"name": "BitmapIndexOutOfBounds",
19291945
"msg": "BitmapIndexOutOfBounds"
1946+
},
1947+
{
1948+
"code": 6023,
1949+
"name": "NoRegisteredTransceivers",
1950+
"msg": "NoRegisteredTransceivers"
19301951
}
19311952
]
19321953
}
@@ -1970,7 +1991,14 @@ export const IDL: ExampleNativeTokenTransfers = {
19701991
{
19711992
"name": "tokenAuthority",
19721993
"isMut": false,
1973-
"isSigner": false
1994+
"isSigner": false,
1995+
"docs": [
1996+
"In any case, this function is used to set the Config and initialize the program so we",
1997+
"assume the caller of this function will have total control over the program.",
1998+
"",
1999+
"TODO: Using `UncheckedAccount` here leads to \"Access violation in stack frame ...\".",
2000+
"Could refactor code to use `Box<_>` to reduce stack size."
2001+
]
19742002
},
19752003
{
19762004
"name": "custody",
@@ -2440,7 +2468,10 @@ export const IDL: ExampleNativeTokenTransfers = {
24402468
{
24412469
"name": "tokenAuthority",
24422470
"isMut": false,
2443-
"isSigner": false
2471+
"isSigner": false,
2472+
"docs": [
2473+
"CHECK The seeds constraint ensures that this is the correct address"
2474+
]
24442475
},
24452476
{
24462477
"name": "mint",
@@ -2503,7 +2534,10 @@ export const IDL: ExampleNativeTokenTransfers = {
25032534
{
25042535
"name": "tokenAuthority",
25052536
"isMut": false,
2506-
"isSigner": false
2537+
"isSigner": false,
2538+
"docs": [
2539+
"CHECK The seeds constraint ensures that this is the correct address"
2540+
]
25072541
},
25082542
{
25092543
"name": "mint",
@@ -2684,7 +2718,10 @@ export const IDL: ExampleNativeTokenTransfers = {
26842718
{
26852719
"name": "transceiver",
26862720
"isMut": false,
2687-
"isSigner": false
2721+
"isSigner": false,
2722+
"docs": [
2723+
"used here that wraps the Transceiver account type."
2724+
]
26882725
},
26892726
{
26902727
"name": "registeredTransceiver",
@@ -3859,6 +3896,11 @@ export const IDL: ExampleNativeTokenTransfers = {
38593896
"code": 6022,
38603897
"name": "BitmapIndexOutOfBounds",
38613898
"msg": "BitmapIndexOutOfBounds"
3899+
},
3900+
{
3901+
"code": 6023,
3902+
"name": "NoRegisteredTransceivers",
3903+
"msg": "NoRegisteredTransceivers"
38623904
}
38633905
]
38643906
}

solana/ts/idl/2_0_0/ts/wormhole_governance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type WormholeGovernance = {
1515
"isMut": true,
1616
"isSigner": false,
1717
"docs": [
18-
"governed program."
18+
"governed program. This account is validated by Wormhole, not this program."
1919
]
2020
},
2121
{
@@ -91,7 +91,7 @@ export const IDL: WormholeGovernance = {
9191
"isMut": true,
9292
"isSigner": false,
9393
"docs": [
94-
"governed program."
94+
"governed program. This account is validated by Wormhole, not this program."
9595
]
9696
},
9797
{

0 commit comments

Comments
 (0)