@@ -24,9 +24,6 @@ pub struct Transfer<'info> {
24
24
25
25
pub config : NotPausedConfig < ' info > ,
26
26
27
- /// This signer will be encoded in the outbox.
28
- sender : Signer < ' info > ,
29
-
30
27
#[ account(
31
28
mut ,
32
29
address = config. mint,
@@ -38,6 +35,8 @@ pub struct Transfer<'info> {
38
35
mut ,
39
36
token:: mint = mint,
40
37
) ]
38
+ /// CHECK: the spl token program will check that the session_authority
39
+ /// account can spend these tokens.
41
40
pub from : InterfaceAccount < ' info , token_interface:: TokenAccount > ,
42
41
43
42
pub token_program : Interface < ' info , token_interface:: TokenInterface > ,
@@ -52,14 +51,6 @@ pub struct Transfer<'info> {
52
51
#[ account( mut ) ]
53
52
pub outbox_rate_limit : Account < ' info , OutboxRateLimit > ,
54
53
55
- /// CHECK: This authority will need to have been delegated authority to
56
- /// transfer or burn tokens in the [from](Self::from) account.
57
- #[ account(
58
- seeds = [ crate :: TOKEN_AUTHORITY_SEED ] ,
59
- bump,
60
- ) ]
61
- token_authority : AccountInfo < ' info > ,
62
-
63
54
pub system_program : Program < ' info , System > ,
64
55
}
65
56
@@ -71,6 +62,23 @@ pub struct TransferArgs {
71
62
pub should_queue : bool ,
72
63
}
73
64
65
+ impl TransferArgs {
66
+ pub fn keccak256 ( & self ) -> solana_program:: keccak:: Hash {
67
+ let TransferArgs {
68
+ amount,
69
+ recipient_chain,
70
+ recipient_address,
71
+ should_queue,
72
+ } = self ;
73
+ solana_program:: keccak:: hashv ( & [
74
+ amount. to_be_bytes ( ) . as_ref ( ) ,
75
+ recipient_chain. id . to_be_bytes ( ) . as_ref ( ) ,
76
+ recipient_address,
77
+ & [ * should_queue as u8 ] ,
78
+ ] )
79
+ }
80
+ }
81
+
74
82
// Burn/mint
75
83
76
84
#[ derive( Accounts ) ]
@@ -92,9 +100,18 @@ pub struct TransferBurn<'info> {
92
100
bump = peer. bump,
93
101
) ]
94
102
pub peer : Account < ' info , NttManagerPeer > ,
103
+
104
+ #[ account(
105
+ seeds = [
106
+ crate :: SESSION_AUTHORITY_SEED ,
107
+ common. from. owner. as_ref( ) ,
108
+ args. keccak256( ) . as_ref( )
109
+ ] ,
110
+ bump,
111
+ ) ]
112
+ pub session_authority : AccountInfo < ' info > ,
95
113
}
96
114
97
- // TODO: fees for relaying?
98
115
pub fn transfer_burn ( ctx : Context < TransferBurn > , args : TransferArgs ) -> Result < ( ) > {
99
116
require_eq ! (
100
117
ctx. accounts. common. config. mode,
@@ -123,11 +140,13 @@ pub fn transfer_burn(ctx: Context<TransferBurn>, args: TransferArgs) -> Result<(
123
140
token_interface:: Burn {
124
141
mint : accs. common . mint . to_account_info ( ) ,
125
142
from : accs. common . from . to_account_info ( ) ,
126
- authority : accs. common . token_authority . to_account_info ( ) ,
143
+ authority : accs. session_authority . to_account_info ( ) ,
127
144
} ,
128
145
& [ & [
129
- crate :: TOKEN_AUTHORITY_SEED ,
130
- & [ ctx. bumps . common . token_authority ] ,
146
+ crate :: SESSION_AUTHORITY_SEED ,
147
+ accs. common . from . owner . as_ref ( ) ,
148
+ args. keccak256 ( ) . as_ref ( ) ,
149
+ & [ ctx. bumps . session_authority ] ,
131
150
] ] ,
132
151
) ,
133
152
amount,
@@ -169,15 +188,23 @@ pub struct TransferLock<'info> {
169
188
) ]
170
189
pub peer : Account < ' info , NttManagerPeer > ,
171
190
191
+ #[ account(
192
+ seeds = [
193
+ crate :: SESSION_AUTHORITY_SEED ,
194
+ common. from. owner. as_ref( ) ,
195
+ args. keccak256( ) . as_ref( )
196
+ ] ,
197
+ bump,
198
+ ) ]
199
+ pub session_authority : AccountInfo < ' info > ,
200
+
172
201
#[ account(
173
202
mut ,
174
203
address = common. config. custody
175
204
) ]
176
205
pub custody : InterfaceAccount < ' info , token_interface:: TokenAccount > ,
177
206
}
178
207
179
- // TODO: fees for relaying?
180
- // TODO: factor out common bits
181
208
pub fn transfer_lock ( ctx : Context < TransferLock > , args : TransferArgs ) -> Result < ( ) > {
182
209
require_eq ! (
183
210
ctx. accounts. common. config. mode,
@@ -206,12 +233,14 @@ pub fn transfer_lock(ctx: Context<TransferLock>, args: TransferArgs) -> Result<(
206
233
token_interface:: TransferChecked {
207
234
from : accs. common . from . to_account_info ( ) ,
208
235
to : accs. custody . to_account_info ( ) ,
209
- authority : accs. common . token_authority . to_account_info ( ) ,
236
+ authority : accs. session_authority . to_account_info ( ) ,
210
237
mint : accs. common . mint . to_account_info ( ) ,
211
238
} ,
212
239
& [ & [
213
- crate :: TOKEN_AUTHORITY_SEED ,
214
- & [ ctx. bumps . common . token_authority ] ,
240
+ crate :: SESSION_AUTHORITY_SEED ,
241
+ accs. common . from . owner . as_ref ( ) ,
242
+ args. keccak256 ( ) . as_ref ( ) ,
243
+ & [ ctx. bumps . session_authority ] ,
215
244
] ] ,
216
245
) ,
217
246
amount,
@@ -260,7 +289,7 @@ fn insert_into_outbox(
260
289
261
290
common. outbox_item . set_inner ( OutboxItem {
262
291
amount : trimmed_amount,
263
- sender : common. sender . key ( ) ,
292
+ sender : common. from . owner ,
264
293
recipient_chain,
265
294
recipient_ntt_manager,
266
295
recipient_address,
0 commit comments