@@ -23,10 +23,18 @@ const WRAPPED_MINT_SEED: &[u8] = br"mint";
2323pub ( crate ) fn get_wrapped_mint_address_with_seed (
2424 unwrapped_mint : & Pubkey ,
2525 wrapped_token_program_id : & Pubkey ,
26+ ) -> ( Pubkey , u8 ) {
27+ get_wrapped_mint_address_with_seed_for_program ( unwrapped_mint, wrapped_token_program_id, & id ( ) )
28+ }
29+
30+ pub ( crate ) fn get_wrapped_mint_address_with_seed_for_program (
31+ unwrapped_mint : & Pubkey ,
32+ wrapped_token_program_id : & Pubkey ,
33+ program_id : & Pubkey ,
2634) -> ( Pubkey , u8 ) {
2735 Pubkey :: find_program_address (
2836 & get_wrapped_mint_seeds ( unwrapped_mint, wrapped_token_program_id) ,
29- & id ( ) ,
37+ program_id ,
3038 )
3139}
3240
@@ -59,7 +67,22 @@ pub fn get_wrapped_mint_address(
5967 unwrapped_mint : & Pubkey ,
6068 wrapped_token_program_id : & Pubkey ,
6169) -> Pubkey {
62- get_wrapped_mint_address_with_seed ( unwrapped_mint, wrapped_token_program_id) . 0
70+ get_wrapped_mint_address_for_program ( unwrapped_mint, wrapped_token_program_id, & id ( ) )
71+ }
72+
73+ /// Derive the SPL Token wrapped mint address associated with an unwrapped mint
74+ /// for a specific Token Wrap program deployment.
75+ pub fn get_wrapped_mint_address_for_program (
76+ unwrapped_mint : & Pubkey ,
77+ wrapped_token_program_id : & Pubkey ,
78+ program_id : & Pubkey ,
79+ ) -> Pubkey {
80+ get_wrapped_mint_address_with_seed_for_program (
81+ unwrapped_mint,
82+ wrapped_token_program_id,
83+ program_id,
84+ )
85+ . 0
6386}
6487
6588const WRAPPED_MINT_AUTHORITY_SEED : & [ u8 ] = br"authority" ;
@@ -80,12 +103,28 @@ pub(crate) fn get_wrapped_mint_authority_signer_seeds<'a>(
80103}
81104
82105pub ( crate ) fn get_wrapped_mint_authority_with_seed ( wrapped_mint : & Pubkey ) -> ( Pubkey , u8 ) {
83- Pubkey :: find_program_address ( & get_wrapped_mint_authority_seeds ( wrapped_mint) , & id ( ) )
106+ get_wrapped_mint_authority_with_seed_for_program ( wrapped_mint, & id ( ) )
107+ }
108+
109+ pub ( crate ) fn get_wrapped_mint_authority_with_seed_for_program (
110+ wrapped_mint : & Pubkey ,
111+ program_id : & Pubkey ,
112+ ) -> ( Pubkey , u8 ) {
113+ Pubkey :: find_program_address ( & get_wrapped_mint_authority_seeds ( wrapped_mint) , program_id)
84114}
85115
86116/// Derive the SPL Token wrapped mint authority address
87117pub fn get_wrapped_mint_authority ( wrapped_mint : & Pubkey ) -> Pubkey {
88- get_wrapped_mint_authority_with_seed ( wrapped_mint) . 0
118+ get_wrapped_mint_authority_for_program ( wrapped_mint, & id ( ) )
119+ }
120+
121+ /// Derive the SPL Token wrapped mint authority address for a specific Token
122+ /// Wrap program deployment
123+ pub fn get_wrapped_mint_authority_for_program (
124+ wrapped_mint : & Pubkey ,
125+ program_id : & Pubkey ,
126+ ) -> Pubkey {
127+ get_wrapped_mint_authority_with_seed_for_program ( wrapped_mint, program_id) . 0
89128}
90129
91130const WRAPPED_MINT_BACKPOINTER_SEED : & [ u8 ] = br"backpointer" ;
@@ -107,16 +146,32 @@ pub(crate) fn get_wrapped_mint_backpointer_address_signer_seeds<'a>(
107146
108147pub ( crate ) fn get_wrapped_mint_backpointer_address_with_seed (
109148 wrapped_mint : & Pubkey ,
149+ ) -> ( Pubkey , u8 ) {
150+ get_wrapped_mint_backpointer_address_with_seed_for_program ( wrapped_mint, & id ( ) )
151+ }
152+
153+ pub ( crate ) fn get_wrapped_mint_backpointer_address_with_seed_for_program (
154+ wrapped_mint : & Pubkey ,
155+ program_id : & Pubkey ,
110156) -> ( Pubkey , u8 ) {
111157 Pubkey :: find_program_address (
112158 & get_wrapped_mint_backpointer_address_seeds ( wrapped_mint) ,
113- & id ( ) ,
159+ program_id ,
114160 )
115161}
116162
117163/// Derive the SPL Token wrapped mint backpointer address
118164pub fn get_wrapped_mint_backpointer_address ( wrapped_mint : & Pubkey ) -> Pubkey {
119- get_wrapped_mint_backpointer_address_with_seed ( wrapped_mint) . 0
165+ get_wrapped_mint_backpointer_address_for_program ( wrapped_mint, & id ( ) )
166+ }
167+
168+ /// Derive the SPL Token wrapped mint backpointer address for a specific Token
169+ /// Wrap program deployment.
170+ pub fn get_wrapped_mint_backpointer_address_for_program (
171+ wrapped_mint : & Pubkey ,
172+ program_id : & Pubkey ,
173+ ) -> Pubkey {
174+ get_wrapped_mint_backpointer_address_with_seed_for_program ( wrapped_mint, program_id) . 0
120175}
121176
122177/// Derive the escrow `ATA` that backs a given wrapped mint.
@@ -125,12 +180,68 @@ pub fn get_escrow_address(
125180 unwrapped_token_program_id : & Pubkey ,
126181 wrapped_token_program_id : & Pubkey ,
127182) -> Pubkey {
128- let wrapped_mint = get_wrapped_mint_address ( unwrapped_mint, wrapped_token_program_id) ;
129- let mint_authority = get_wrapped_mint_authority ( & wrapped_mint) ;
183+ get_escrow_address_for_program (
184+ unwrapped_mint,
185+ unwrapped_token_program_id,
186+ wrapped_token_program_id,
187+ & id ( ) ,
188+ )
189+ }
190+
191+ /// Derive the escrow `ATA` for a specific Token Wrap program deployment.
192+ pub fn get_escrow_address_for_program (
193+ unwrapped_mint : & Pubkey ,
194+ unwrapped_token_program_id : & Pubkey ,
195+ wrapped_token_program_id : & Pubkey ,
196+ program_id : & Pubkey ,
197+ ) -> Pubkey {
198+ let wrapped_mint =
199+ get_wrapped_mint_address_for_program ( unwrapped_mint, wrapped_token_program_id, program_id) ;
200+ let mint_authority = get_wrapped_mint_authority_for_program ( & wrapped_mint, program_id) ;
130201
131202 get_associated_token_address_with_program_id (
132203 & mint_authority,
133204 unwrapped_mint,
134205 unwrapped_token_program_id,
135206 )
136207}
208+
209+ const CANONICAL_POINTER_SEED : & [ u8 ] = br"canonical_pointer" ;
210+
211+ /// Derives the canonical pointer address and bump seed for a specific
212+ /// Token Wrap program deployment.
213+ pub ( crate ) fn get_canonical_pointer_address_with_seed_for_program (
214+ unwrapped_mint : & Pubkey ,
215+ program_id : & Pubkey ,
216+ ) -> ( Pubkey , u8 ) {
217+ Pubkey :: find_program_address (
218+ & [ CANONICAL_POINTER_SEED , unwrapped_mint. as_ref ( ) ] ,
219+ program_id,
220+ )
221+ }
222+
223+ pub ( crate ) fn get_canonical_pointer_address_signer_seeds < ' a > (
224+ unwrapped_mint : & ' a Pubkey ,
225+ bump_seed : & ' a [ u8 ] ,
226+ ) -> [ & ' a [ u8 ] ; 3 ] {
227+ [ CANONICAL_POINTER_SEED , unwrapped_mint. as_ref ( ) , bump_seed]
228+ }
229+
230+ /// Derives the canonical pointer address and bump seed.
231+ pub ( crate ) fn get_canonical_pointer_address_with_seed ( unwrapped_mint : & Pubkey ) -> ( Pubkey , u8 ) {
232+ get_canonical_pointer_address_with_seed_for_program ( unwrapped_mint, & id ( ) )
233+ }
234+
235+ /// Derives the canonical pointer address for an unwrapped mint.
236+ pub fn get_canonical_pointer_address ( unwrapped_mint : & Pubkey ) -> Pubkey {
237+ get_canonical_pointer_address_for_program ( unwrapped_mint, & id ( ) )
238+ }
239+
240+ /// Derives the canonical pointer address for an unwrapped mint for a specific
241+ /// Token Wrap program deployment.
242+ pub fn get_canonical_pointer_address_for_program (
243+ unwrapped_mint : & Pubkey ,
244+ program_id : & Pubkey ,
245+ ) -> Pubkey {
246+ get_canonical_pointer_address_with_seed_for_program ( unwrapped_mint, program_id) . 0
247+ }
0 commit comments