1
1
import { Program } from "@coral-xyz/anchor" ;
2
- import { associatedAddress } from "@coral-xyz/anchor/dist/cjs/utils/token.js" ;
3
2
import * as splToken from "@solana/spl-token" ;
4
3
import {
5
4
createAssociatedTokenAccountInstruction ,
9
8
Connection ,
10
9
Keypair ,
11
10
PublicKey ,
11
+ SystemProgram ,
12
12
Transaction ,
13
13
TransactionInstruction ,
14
14
TransactionMessage ,
@@ -236,16 +236,11 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
236
236
) ;
237
237
}
238
238
239
- const custodyAddress = associatedAddress ( {
240
- mint : args . mint ,
241
- owner : this . pdas . tokenAuthority ( ) ,
242
- } ) ;
243
-
244
239
const tokenProgram = mintInfo . owner ;
245
240
const limit = new BN ( args . outboundLimit . toString ( ) ) ;
246
241
const ix = await this . program . methods
247
242
. initialize ( { chainId, limit : limit , mode } )
248
- . accounts ( {
243
+ . accountsStrict ( {
249
244
payer : args . payer . publicKey ,
250
245
deployer : args . owner . publicKey ,
251
246
programData : programDataAddress ( this . program . programId ) ,
@@ -254,8 +249,10 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
254
249
rateLimit : this . pdas . outboxRateLimitAccount ( ) ,
255
250
tokenProgram,
256
251
tokenAuthority : this . pdas . tokenAuthority ( ) ,
257
- custody : custodyAddress ,
252
+ custody : await this . custodyAccountAddress ( args . mint , tokenProgram ) ,
258
253
bpfLoaderUpgradeableProgram : BPF_LOADER_UPGRADEABLE_PROGRAM_ID ,
254
+ associatedTokenProgram : splToken . ASSOCIATED_TOKEN_PROGRAM_ID ,
255
+ systemProgram : SystemProgram . programId ,
259
256
} )
260
257
. instruction ( ) ;
261
258
@@ -278,14 +275,15 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
278
275
279
276
const ix = await this . program . methods
280
277
. registerTransceiver ( )
281
- . accounts ( {
278
+ . accountsStrict ( {
282
279
payer : args . payer . publicKey ,
283
280
owner : args . owner . publicKey ,
284
281
config : this . pdas . configAccount ( ) ,
285
282
transceiver : args . transceiver ,
286
283
registeredTransceiver : this . pdas . registeredTransceiver (
287
284
args . transceiver
288
285
) ,
286
+ systemProgram : SystemProgram . programId ,
289
287
} )
290
288
. instruction ( ) ;
291
289
@@ -307,6 +305,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
307
305
feeCollector : whAccs . wormholeFeeCollector ,
308
306
sequence : whAccs . wormholeSequence ,
309
307
program : this . core . address ,
308
+ systemProgram : SystemProgram . programId ,
310
309
} ,
311
310
} )
312
311
. instruction ( ) ;
@@ -337,11 +336,12 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
337
336
chainId : { id : toChainId ( peer . chain ) } ,
338
337
address : Array . from ( peer . address . toUniversalAddress ( ) . toUint8Array ( ) ) ,
339
338
} )
340
- . accounts ( {
339
+ . accountsStrict ( {
341
340
payer : sender ,
342
341
owner : sender ,
343
342
config : this . pdas . configAccount ( ) ,
344
343
peer : this . pdas . transceiverPeerAccount ( peer . chain ) ,
344
+ systemProgram : SystemProgram . programId ,
345
345
} )
346
346
. instruction ( ) ,
347
347
this . program . methods
@@ -390,12 +390,13 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
390
390
limit : new BN ( inboundLimit . toString ( ) ) ,
391
391
tokenDecimals : tokenDecimals ,
392
392
} )
393
- . accounts ( {
393
+ . accountsStrict ( {
394
394
payer : sender ,
395
395
owner : sender ,
396
396
config : this . pdas . configAccount ( ) ,
397
397
peer : this . pdas . peerAccount ( peer . chain ) ,
398
398
inboxRateLimit : this . pdas . inboxRateLimitAccount ( peer . chain ) ,
399
+ systemProgram : SystemProgram . programId ,
399
400
} )
400
401
. instruction ( ) ;
401
402
@@ -671,7 +672,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
671
672
) ,
672
673
shouldQueue : args . transferArgs . shouldQueue ,
673
674
} )
674
- . accounts ( {
675
+ . accountsStrict ( {
675
676
common : {
676
677
payer : args . payer ,
677
678
config : { config : this . pdas . configAccount ( ) } ,
@@ -680,10 +681,11 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
680
681
tokenProgram : config . tokenProgram ,
681
682
outboxItem : args . outboxItem ,
682
683
outboxRateLimit : this . pdas . outboxRateLimitAccount ( ) ,
684
+ systemProgram : SystemProgram . programId ,
685
+ custody : config . custody ,
683
686
} ,
684
687
peer : this . pdas . peerAccount ( recipientChain ) ,
685
688
inboxRateLimit : this . pdas . inboxRateLimitAccount ( recipientChain ) ,
686
- custody : config . custody ,
687
689
sessionAuthority : sessionAuthority ,
688
690
} )
689
691
. instruction ( ) ;
@@ -712,21 +714,25 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
712
714
) ,
713
715
shouldQueue : args . transferArgs . shouldQueue ,
714
716
} )
715
- . accounts ( {
717
+ . accountsStrict ( {
716
718
common : {
717
719
payer : args . payer ,
718
720
config : { config : this . pdas . configAccount ( ) } ,
719
721
mint : config . mint ,
720
722
from : args . from ,
721
723
outboxItem : args . outboxItem ,
722
724
outboxRateLimit : this . pdas . outboxRateLimitAccount ( ) ,
725
+ custody : config . custody ,
726
+ tokenProgram : config . tokenProgram ,
727
+ systemProgram : SystemProgram . programId ,
723
728
} ,
724
729
peer : this . pdas . peerAccount ( recipientChain ) ,
725
730
inboxRateLimit : this . pdas . inboxRateLimitAccount ( recipientChain ) ,
726
731
sessionAuthority : this . pdas . sessionAuthority (
727
732
args . fromAuthority ,
728
733
args . transferArgs
729
734
) ,
735
+ tokenAuthority : this . pdas . tokenAuthority ( ) ,
730
736
} )
731
737
. instruction ( ) ;
732
738
}
@@ -757,6 +763,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
757
763
feeCollector : whAccs . wormholeFeeCollector ,
758
764
sequence : whAccs . wormholeSequence ,
759
765
program : this . core . address ,
766
+ systemProgram : SystemProgram . programId ,
760
767
} ,
761
768
} )
762
769
. instruction ( ) ;
@@ -773,7 +780,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
773
780
const emitterChain = wormholeNTT . emitterChain ;
774
781
return await this . program . methods
775
782
. receiveWormholeMessage ( )
776
- . accounts ( {
783
+ . accountsStrict ( {
777
784
payer : payer ,
778
785
config : { config : this . pdas . configAccount ( ) } ,
779
786
peer : this . pdas . transceiverPeerAccount ( emitterChain ) ,
@@ -785,6 +792,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
785
792
emitterChain ,
786
793
nttMessage . id
787
794
) ,
795
+ systemProgram : SystemProgram . programId ,
788
796
} )
789
797
. instruction ( ) ;
790
798
}
@@ -805,7 +813,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
805
813
806
814
return await this . program . methods
807
815
. redeem ( { } )
808
- . accounts ( {
816
+ . accountsStrict ( {
809
817
payer : payer ,
810
818
config : this . pdas . configAccount ( ) ,
811
819
peer : nttManagerPeer ,
@@ -818,6 +826,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
818
826
inboxItem,
819
827
inboxRateLimit,
820
828
outboxRateLimit : this . pdas . outboxRateLimitAccount ( ) ,
829
+ systemProgram : SystemProgram . programId ,
821
830
} )
822
831
. instruction ( ) ;
823
832
}
@@ -847,7 +856,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
847
856
. releaseInboundMint ( {
848
857
revertOnDelay : args . revertOnDelay ,
849
858
} )
850
- . accounts ( {
859
+ . accountsStrict ( {
851
860
common : {
852
861
payer : args . payer ,
853
862
config : { config : this . pdas . configAccount ( ) } ,
@@ -858,6 +867,8 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
858
867
) ,
859
868
mint : config . mint ,
860
869
tokenAuthority : this . pdas . tokenAuthority ( ) ,
870
+ custody : config . custody ,
871
+ tokenProgram : config . tokenProgram ,
861
872
} ,
862
873
} )
863
874
. instruction ( ) ;
@@ -888,7 +899,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
888
899
. releaseInboundUnlock ( {
889
900
revertOnDelay : args . revertOnDelay ,
890
901
} )
891
- . accounts ( {
902
+ . accountsStrict ( {
892
903
common : {
893
904
payer : args . payer ,
894
905
config : { config : this . pdas . configAccount ( ) } ,
@@ -899,17 +910,37 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
899
910
) ,
900
911
mint : config . mint ,
901
912
tokenAuthority : this . pdas . tokenAuthority ( ) ,
913
+ custody : config . custody ,
914
+ tokenProgram : config . tokenProgram ,
902
915
} ,
903
- custody : config . custody ,
904
916
} )
905
917
. instruction ( ) ;
906
918
}
907
919
908
- async custodyAccountAddress ( mint : PublicKey ) : Promise < PublicKey > {
909
- return associatedAddress ( {
910
- mint : mint ,
911
- owner : this . pdas . tokenAuthority ( ) ,
912
- } ) ;
920
+ /**
921
+ * Returns the address of the custody account. If the config is available
922
+ * (i.e. the program is initialised), the mint is derived from the config.
923
+ * Otherwise, the mint must be provided.
924
+ */
925
+ async custodyAccountAddress (
926
+ configOrMint : NttBindings . Config | PublicKey ,
927
+ tokenProgram = splToken . TOKEN_PROGRAM_ID
928
+ ) : Promise < PublicKey > {
929
+ if ( configOrMint instanceof PublicKey ) {
930
+ return splToken . getAssociatedTokenAddress (
931
+ configOrMint ,
932
+ this . pdas . tokenAuthority ( ) ,
933
+ true ,
934
+ tokenProgram
935
+ ) ;
936
+ } else {
937
+ return splToken . getAssociatedTokenAddress (
938
+ configOrMint . mint ,
939
+ this . pdas . tokenAuthority ( ) ,
940
+ true ,
941
+ configOrMint . tokenProgram
942
+ ) ;
943
+ }
913
944
}
914
945
915
946
createUnsignedTx (
0 commit comments