1
- use std:: ops:: { Deref , DerefMut } ;
2
-
3
1
use anchor_lang:: prelude:: * ;
4
2
use anchor_spl:: token_interface;
5
3
use ntt_messages:: mode:: Mode ;
@@ -68,34 +66,6 @@ pub struct ReleaseInboundMint<'info> {
68
66
common : ReleaseInbound < ' info > ,
69
67
}
70
68
71
- impl < ' info > Deref for ReleaseInboundMint < ' info > {
72
- type Target = ReleaseInbound < ' info > ;
73
-
74
- fn deref ( & self ) -> & Self :: Target {
75
- & self . common
76
- }
77
- }
78
-
79
- impl Deref for ReleaseInboundMintBumps {
80
- type Target = ReleaseInboundBumps ;
81
-
82
- fn deref ( & self ) -> & Self :: Target {
83
- & self . common
84
- }
85
- }
86
-
87
- impl < ' info > DerefMut for ReleaseInboundMint < ' info > {
88
- fn deref_mut ( & mut self ) -> & mut Self :: Target {
89
- & mut self . common
90
- }
91
- }
92
-
93
- #[ derive( Accounts ) ]
94
- pub struct ReleaseInboundMintDefault < ' info > {
95
- #[ account( constraint = common. mint. mint_authority. unwrap( ) == common. token_authority. key( ) ) ]
96
- common : ReleaseInboundMint < ' info > ,
97
- }
98
-
99
69
/// Release an inbound transfer and mint the tokens to the recipient.
100
70
/// When `revert_on_error` is true, the transaction will revert if the
101
71
/// release timestamp has not been reached. When `revert_on_error` is false, the
@@ -104,9 +74,16 @@ pub struct ReleaseInboundMintDefault<'info> {
104
74
/// together with [`crate::instructions::redeem`] in a transaction, so that the minting
105
75
/// is attempted optimistically.
106
76
pub fn release_inbound_mint < ' info > (
107
- ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundMintDefault < ' info > > ,
77
+ ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundMint < ' info > > ,
108
78
args : ReleaseInboundArgs ,
109
79
) -> Result < ( ) > {
80
+ if ctx. accounts . common . mint . mint_authority . unwrap ( ) != ctx. accounts . common . token_authority . key ( )
81
+ {
82
+ return Err ( NTTError :: InvalidMintAuthority . into ( ) ) ;
83
+ }
84
+
85
+ let inbox_item = release_inbox_item ( & mut ctx. accounts . common . inbox_item , args. revert_on_delay ) ?;
86
+
110
87
// NOTE: minting tokens is a two-step process:
111
88
// 1. Mint tokens to the custody account
112
89
// 2. Transfer the tokens from the custody account to the recipient
@@ -136,7 +113,7 @@ pub fn release_inbound_mint<'info>(
136
113
& [ ctx. bumps . common . token_authority ] ,
137
114
] ] ,
138
115
) ,
139
- ctx . accounts . common . inbox_item . amount ,
116
+ inbox_item. amount ,
140
117
) ?;
141
118
142
119
// Step 2: transfer the tokens from the custody account to the recipient
@@ -147,21 +124,23 @@ pub fn release_inbound_mint<'info>(
147
124
ctx. accounts . common . recipient . to_account_info ( ) ,
148
125
ctx. accounts . common . token_authority . to_account_info ( ) ,
149
126
ctx. remaining_accounts ,
150
- ctx . accounts . common . inbox_item . amount ,
127
+ inbox_item. amount ,
151
128
ctx. accounts . common . mint . decimals ,
152
129
& [ & [
153
130
crate :: TOKEN_AUTHORITY_SEED ,
154
131
& [ ctx. bumps . common . token_authority ] ,
155
132
] ] ,
156
133
) ?;
157
-
158
- release_inbox_item ( & mut ctx. accounts . common . inbox_item , args. revert_on_delay )
134
+ Ok ( ( ) )
159
135
}
160
136
161
137
#[ derive( Accounts ) ]
162
138
pub struct ReleaseInboundMintMultisig < ' info > {
163
- #[ account( constraint = common. mint. mint_authority. unwrap( ) == multisig. key( ) ) ]
164
- common : ReleaseInboundMint < ' info > ,
139
+ #[ account(
140
+ constraint = common. config. mode == Mode :: Burning @ NTTError :: InvalidMode ,
141
+ constraint = common. mint. mint_authority. unwrap( ) == multisig. key( )
142
+ ) ]
143
+ common : ReleaseInbound < ' info > ,
165
144
166
145
/// CHECK: multisig account should be mint authority
167
146
pub multisig : UncheckedAccount < ' info > ,
@@ -171,6 +150,8 @@ pub fn release_inbound_mint_multisig<'info>(
171
150
ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundMintMultisig < ' info > > ,
172
151
args : ReleaseInboundArgs ,
173
152
) -> Result < ( ) > {
153
+ let inbox_item = release_inbox_item ( & mut ctx. accounts . common . inbox_item , args. revert_on_delay ) ?;
154
+
174
155
// NOTE: minting tokens is a two-step process:
175
156
// 1. Mint tokens to the custody account
176
157
// 2. Transfer the tokens from the custody account to the recipient
@@ -193,7 +174,7 @@ pub fn release_inbound_mint_multisig<'info>(
193
174
& ctx. accounts . common . custody . key ( ) ,
194
175
& ctx. accounts . multisig . key ( ) ,
195
176
& [ & ctx. accounts . common . token_authority . key ( ) ] ,
196
- ctx . accounts . common . inbox_item . amount ,
177
+ inbox_item. amount ,
197
178
) ?;
198
179
solana_program:: program:: invoke_signed (
199
180
& ix,
@@ -217,30 +198,13 @@ pub fn release_inbound_mint_multisig<'info>(
217
198
ctx. accounts . common . recipient . to_account_info ( ) ,
218
199
ctx. accounts . common . token_authority . to_account_info ( ) ,
219
200
ctx. remaining_accounts ,
220
- ctx . accounts . common . inbox_item . amount ,
201
+ inbox_item. amount ,
221
202
ctx. accounts . common . mint . decimals ,
222
203
& [ & [
223
204
crate :: TOKEN_AUTHORITY_SEED ,
224
205
& [ ctx. bumps . common . token_authority ] ,
225
206
] ] ,
226
207
) ?;
227
-
228
- release_inbox_item ( & mut ctx. accounts . common . inbox_item , args. revert_on_delay )
229
- }
230
-
231
- fn release_inbox_item ( inbox_item : & mut InboxItem , revert_on_delay : bool ) -> Result < ( ) > {
232
- let released = inbox_item. try_release ( ) ?;
233
-
234
- if !released {
235
- if revert_on_delay {
236
- return Err ( NTTError :: CantReleaseYet . into ( ) ) ;
237
- } else {
238
- return Ok ( ( ) ) ;
239
- }
240
- }
241
-
242
- assert ! ( inbox_item. release_status == ReleaseStatus :: Released ) ;
243
-
244
208
Ok ( ( ) )
245
209
}
246
210
@@ -250,6 +214,7 @@ fn release_inbox_item(inbox_item: &mut InboxItem, revert_on_delay: bool) -> Resu
250
214
pub struct ReleaseInboundUnlock < ' info > {
251
215
#[ account(
252
216
constraint = common. config. mode == Mode :: Locking @ NTTError :: InvalidMode ,
217
+ constraint = common. mint. mint_authority. unwrap( ) == common. token_authority. key( )
253
218
) ]
254
219
common : ReleaseInbound < ' info > ,
255
220
}
@@ -265,17 +230,7 @@ pub fn release_inbound_unlock<'info>(
265
230
ctx : Context < ' _ , ' _ , ' _ , ' info , ReleaseInboundUnlock < ' info > > ,
266
231
args : ReleaseInboundArgs ,
267
232
) -> Result < ( ) > {
268
- let inbox_item = & mut ctx. accounts . common . inbox_item ;
269
-
270
- let released = inbox_item. try_release ( ) ?;
271
-
272
- if !released {
273
- if args. revert_on_delay {
274
- return Err ( NTTError :: CantReleaseYet . into ( ) ) ;
275
- } else {
276
- return Ok ( ( ) ) ;
277
- }
278
- }
233
+ let inbox_item = release_inbox_item ( & mut ctx. accounts . common . inbox_item , args. revert_on_delay ) ?;
279
234
280
235
onchain:: invoke_transfer_checked (
281
236
& ctx. accounts . common . token_program . key ( ) ,
@@ -293,3 +248,19 @@ pub fn release_inbound_unlock<'info>(
293
248
) ?;
294
249
Ok ( ( ) )
295
250
}
251
+
252
+ fn release_inbox_item ( inbox_item : & mut InboxItem , revert_on_delay : bool ) -> Result < & mut InboxItem > {
253
+ let released = inbox_item. try_release ( ) ?;
254
+
255
+ if !released {
256
+ if revert_on_delay {
257
+ return Err ( NTTError :: CantReleaseYet . into ( ) ) ;
258
+ } else {
259
+ return Ok ( inbox_item) ;
260
+ }
261
+ }
262
+
263
+ assert ! ( inbox_item. release_status == ReleaseStatus :: Released ) ;
264
+
265
+ Ok ( inbox_item)
266
+ }
0 commit comments