-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathlib.rs
249 lines (202 loc) · 8.3 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
use anchor_lang::prelude::*;
// TODO: is there a more elegant way of checking that these 3 features are mutually exclusive?
#[cfg(all(feature = "mainnet", feature = "solana-devnet"))]
compile_error!("Cannot enable both mainnet and solana-devnet features at the same time");
#[cfg(all(feature = "mainnet", feature = "tilt-devnet"))]
compile_error!("Cannot enable both mainnet and tilt-devnet features at the same time");
#[cfg(all(feature = "solana-devnet", feature = "tilt-devnet"))]
compile_error!("Cannot enable both solana-devnet and tilt-devnet features at the same time");
pub mod bitmap;
pub mod clock;
pub mod config;
pub mod error;
pub mod instructions;
pub mod messages;
pub mod peer;
pub mod pending_token_authority;
pub mod queue;
pub mod registered_transceiver;
pub mod spl_multisig;
pub mod transceivers;
pub mod transfer;
use transceivers::wormhole::instructions::*;
use instructions::*;
cfg_if::cfg_if! {
if #[cfg(feature = "tilt-devnet2")] {
declare_id!("NTTManager222222222222222222222222222222222");
} else if #[cfg(feature = "tilt-devnet")] {
declare_id!("NTTManager111111111111111111111111111111111");
} else {
declare_id!("nttiK1SepaQt6sZ4WGW5whvc9tEnGXGxuKeptcQPCcS");
}
}
pub const TOKEN_AUTHORITY_SEED: &[u8] = b"token_authority";
/// The seed for the session authority account.
///
/// These accounts are used in the `transfer_*` instructions. The user first
/// approves the session authority to spend the tokens, and then the session
/// authority burns or locks the tokens.
/// This is to avoid the user having to pass their own authority to the program,
/// which in general is dangerous, especially for upgradeable programs.
///
/// There is a session authority associated with each transfer, and is seeded by
/// the sender's pubkey, and (the hash of) all the transfer arguments.
/// These seeds essentially encode the user's intent when approving the
/// spending.
///
/// In practice, the approve instruction is going to be atomically bundled with
/// the transfer instruction, so this encoding makes no difference.
/// However, it does allow it to be done in a separate transaction without the
/// risk of a malicious actor redirecting the funds by frontrunning the transfer
/// instruction.
/// In other words, the transfer instruction has no degrees of freedom; all the
/// arguments are determined in the approval step. Then transfer can be
/// permissionlessly invoked by anyone (even if in practice it's going to be the
/// user, atomically).
pub const SESSION_AUTHORITY_SEED: &[u8] = b"session_authority";
pub const VERSION: &str = "3.0.0";
#[program]
pub mod example_native_token_transfers {
use super::*;
pub fn initialize(ctx: Context<Initialize>, args: InitializeArgs) -> Result<()> {
instructions::initialize(ctx, args)
}
pub fn initialize_lut(ctx: Context<InitializeLUT>, recent_slot: u64) -> Result<()> {
instructions::initialize_lut(ctx, recent_slot)
}
pub fn version(_ctx: Context<Version>) -> Result<String> {
Ok(VERSION.to_string())
}
pub fn transfer_burn<'info>(
ctx: Context<'_, '_, '_, 'info, TransferBurn<'info>>,
args: TransferArgs,
) -> Result<()> {
instructions::transfer_burn(ctx, args)
}
pub fn transfer_lock<'info>(
ctx: Context<'_, '_, '_, 'info, TransferLock<'info>>,
args: TransferArgs,
) -> Result<()> {
instructions::transfer_lock(ctx, args)
}
pub fn redeem(ctx: Context<Redeem>, args: RedeemArgs) -> Result<()> {
instructions::redeem(ctx, args)
}
pub fn release_inbound_mint<'info>(
ctx: Context<'_, '_, '_, 'info, ReleaseInboundMint<'info>>,
args: ReleaseInboundArgs,
) -> Result<()> {
instructions::release_inbound_mint(ctx, args)
}
pub fn release_inbound_unlock<'info>(
ctx: Context<'_, '_, '_, 'info, ReleaseInboundUnlock<'info>>,
args: ReleaseInboundArgs,
) -> Result<()> {
instructions::release_inbound_unlock(ctx, args)
}
pub fn transfer_ownership(ctx: Context<TransferOwnership>) -> Result<()> {
instructions::transfer_ownership(ctx)
}
pub fn transfer_ownership_one_step_unchecked(ctx: Context<TransferOwnership>) -> Result<()> {
instructions::transfer_ownership_one_step_unchecked(ctx)
}
pub fn claim_ownership(ctx: Context<ClaimOwnership>) -> Result<()> {
instructions::claim_ownership(ctx)
}
pub fn accept_token_authority(ctx: Context<AcceptTokenAuthority>) -> Result<()> {
instructions::accept_token_authority(ctx)
}
pub fn accept_token_authority_from_multisig<'info>(
ctx: Context<'_, '_, '_, 'info, AcceptTokenAuthorityFromMultisig<'info>>,
) -> Result<()> {
instructions::accept_token_authority_from_multisig(ctx)
}
pub fn set_token_authority_one_step_unchecked(
ctx: Context<SetTokenAuthorityUnchecked>,
) -> Result<()> {
instructions::set_token_authority_one_step_unchecked(ctx)
}
pub fn set_token_authority(ctx: Context<SetTokenAuthorityChecked>) -> Result<()> {
instructions::set_token_authority(ctx)
}
pub fn revert_token_authority(ctx: Context<RevertTokenAuthority>) -> Result<()> {
instructions::revert_token_authority(ctx)
}
pub fn claim_token_authority(ctx: Context<ClaimTokenAuthority>) -> Result<()> {
instructions::claim_token_authority(ctx)
}
pub fn claim_token_authority_to_multisig(
ctx: Context<ClaimTokenAuthorityToMultisig>,
) -> Result<()> {
instructions::claim_token_authority_to_multisig(ctx)
}
pub fn set_paused(ctx: Context<SetPaused>, pause: bool) -> Result<()> {
instructions::set_paused(ctx, pause)
}
pub fn set_peer(ctx: Context<SetPeer>, args: SetPeerArgs) -> Result<()> {
instructions::set_peer(ctx, args)
}
pub fn register_transceiver(ctx: Context<RegisterTransceiver>) -> Result<()> {
instructions::register_transceiver(ctx)
}
pub fn deregister_transceiver(ctx: Context<DeregisterTransceiver>) -> Result<()> {
instructions::deregister_transceiver(ctx)
}
pub fn set_outbound_limit(
ctx: Context<SetOutboundLimit>,
args: SetOutboundLimitArgs,
) -> Result<()> {
instructions::set_outbound_limit(ctx, args)
}
pub fn set_inbound_limit(
ctx: Context<SetInboundLimit>,
args: SetInboundLimitArgs,
) -> Result<()> {
instructions::set_inbound_limit(ctx, args)
}
pub fn mark_outbox_item_as_released(ctx: Context<MarkOutboxItemAsReleased>) -> Result<bool> {
instructions::mark_outbox_item_as_released(ctx)
}
pub fn set_threshold(ctx: Context<SetThreshold>, threshold: u8) -> Result<()> {
instructions::set_threshold(ctx, threshold)
}
// standalone transceiver stuff
pub fn set_wormhole_peer(
ctx: Context<SetTransceiverPeer>,
args: SetTransceiverPeerArgs,
) -> Result<()> {
transceivers::wormhole::instructions::set_transceiver_peer(ctx, args)
}
pub fn receive_wormhole_message(ctx: Context<ReceiveMessage>) -> Result<()> {
transceivers::wormhole::instructions::receive_message(ctx)
}
pub fn release_wormhole_outbound(
ctx: Context<ReleaseOutbound>,
args: ReleaseOutboundArgs,
) -> Result<()> {
transceivers::wormhole::instructions::release_outbound(ctx, args)
}
pub fn broadcast_wormhole_id(ctx: Context<BroadcastId>) -> Result<()> {
transceivers::wormhole::instructions::broadcast_id(ctx)
}
pub fn broadcast_wormhole_peer(
ctx: Context<BroadcastPeer>,
args: BroadcastPeerArgs,
) -> Result<()> {
transceivers::wormhole::instructions::broadcast_peer(ctx, args)
}
}
// The Version struct is just a dummy type because anchor needs every function
// to have a context. When compiled in CPI mode, anchor generates code that
// assumes that the struct has a lifetime parameter. So in that mode, we bind a
// dummy lifetime parameter (and use it in a dummy account).
// When compiling normally, we don't do this, and just use an empty struct, which anchor is happy with.
#[cfg(feature = "cpi")]
#[derive(Accounts)]
pub struct Version<'info> {
/// CHECK: refer to comment above
pub dummy: UncheckedAccount<'info>,
}
#[cfg(not(feature = "cpi"))]
#[derive(Accounts)]
pub struct Version {}