Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit da27180

Browse files
committed
Fixup client bindings and otherwise
1 parent 25556ce commit da27180

File tree

3 files changed

+124
-46
lines changed

3 files changed

+124
-46
lines changed

token-swap/js/src/index.ts

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const TokenSwapLayout = BufferLayout.struct([
6666
BufferLayout.u8('version'),
6767
BufferLayout.u8('isInitialized'),
6868
BufferLayout.u8('bumpSeed'),
69-
Layout.publicKey('tokenProgramId'),
69+
Layout.publicKey('poolTokenProgramId'),
7070
Layout.publicKey('tokenAccountA'),
7171
Layout.publicKey('tokenAccountB'),
7272
Layout.publicKey('tokenPool'),
@@ -101,7 +101,7 @@ export class TokenSwap {
101101
* @param connection The connection to use
102102
* @param tokenSwap The token swap account
103103
* @param swapProgramId The program ID of the token-swap program
104-
* @param tokenProgramId The program ID of the token program
104+
* @param poolTokenProgramId The program ID of the token program for the pool tokens
105105
* @param poolToken The pool token
106106
* @param authority The authority over the swap and accounts
107107
* @param tokenAccountA The token swap's Token A account
@@ -123,7 +123,7 @@ export class TokenSwap {
123123
private connection: Connection,
124124
public tokenSwap: PublicKey,
125125
public swapProgramId: PublicKey,
126-
public tokenProgramId: PublicKey,
126+
public poolTokenProgramId: PublicKey,
127127
public poolToken: PublicKey,
128128
public feeAccount: PublicKey,
129129
public authority: PublicKey,
@@ -145,7 +145,7 @@ export class TokenSwap {
145145
this.connection = connection;
146146
this.tokenSwap = tokenSwap;
147147
this.swapProgramId = swapProgramId;
148-
this.tokenProgramId = tokenProgramId;
148+
this.poolTokenProgramId = poolTokenProgramId;
149149
this.poolToken = poolToken;
150150
this.feeAccount = feeAccount;
151151
this.authority = authority;
@@ -186,7 +186,7 @@ export class TokenSwap {
186186
tokenPool: PublicKey,
187187
feeAccount: PublicKey,
188188
tokenAccountPool: PublicKey,
189-
tokenProgramId: PublicKey,
189+
poolTokenProgramId: PublicKey,
190190
swapProgramId: PublicKey,
191191
tradeFeeNumerator: number,
192192
tradeFeeDenominator: number,
@@ -207,7 +207,7 @@ export class TokenSwap {
207207
{pubkey: tokenPool, isSigner: false, isWritable: true},
208208
{pubkey: feeAccount, isSigner: false, isWritable: false},
209209
{pubkey: tokenAccountPool, isSigner: false, isWritable: true},
210-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
210+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
211211
];
212212
const commandDataLayout = BufferLayout.struct([
213213
BufferLayout.u8('instruction'),
@@ -279,7 +279,7 @@ export class TokenSwap {
279279
const tokenAccountB = new PublicKey(tokenSwapData.tokenAccountB);
280280
const mintA = new PublicKey(tokenSwapData.mintA);
281281
const mintB = new PublicKey(tokenSwapData.mintB);
282-
const tokenProgramId = new PublicKey(tokenSwapData.tokenProgramId);
282+
const poolTokenProgramId = new PublicKey(tokenSwapData.poolTokenProgramId);
283283

284284
const tradeFeeNumerator = Numberu64.fromBuffer(
285285
tokenSwapData.tradeFeeNumerator,
@@ -311,7 +311,7 @@ export class TokenSwap {
311311
connection,
312312
address,
313313
programId,
314-
tokenProgramId,
314+
poolTokenProgramId,
315315
poolToken,
316316
feeAccount,
317317
authority,
@@ -343,7 +343,7 @@ export class TokenSwap {
343343
* @param tokenAccountB: The token swap's Token B account
344344
* @param poolToken The pool token
345345
* @param tokenAccountPool The token swap's pool token account
346-
* @param tokenProgramId The program ID of the token program
346+
* @param poolTokenProgramId The program ID of the token program for pool tokens
347347
* @param swapProgramId The program ID of the token-swap program
348348
* @param feeNumerator Numerator of the fee ratio
349349
* @param feeDenominator Denominator of the fee ratio
@@ -362,7 +362,7 @@ export class TokenSwap {
362362
feeAccount: PublicKey,
363363
tokenAccountPool: PublicKey,
364364
swapProgramId: PublicKey,
365-
tokenProgramId: PublicKey,
365+
poolTokenProgramId: PublicKey,
366366
tradeFeeNumerator: number,
367367
tradeFeeDenominator: number,
368368
ownerTradeFeeNumerator: number,
@@ -380,7 +380,7 @@ export class TokenSwap {
380380
connection,
381381
tokenSwapAccount.publicKey,
382382
swapProgramId,
383-
tokenProgramId,
383+
poolTokenProgramId,
384384
poolToken,
385385
feeAccount,
386386
authority,
@@ -423,7 +423,7 @@ export class TokenSwap {
423423
poolToken,
424424
feeAccount,
425425
tokenAccountPool,
426-
tokenProgramId,
426+
poolTokenProgramId,
427427
swapProgramId,
428428
tradeFeeNumerator,
429429
tradeFeeDenominator,
@@ -455,6 +455,8 @@ export class TokenSwap {
455455
* @param poolSource Pool's source token account
456456
* @param poolDestination Pool's destination token account
457457
* @param userDestination User's destination token account
458+
* @param sourceTokenProgramId Program id for the source token
459+
* @param destinationTokenProgramId Program id for the destination token
458460
* @param hostFeeAccount Host account to gather fees
459461
* @param userTransferAuthority Account delegated to transfer user's tokens
460462
* @param amountIn Amount to transfer from source account
@@ -465,6 +467,8 @@ export class TokenSwap {
465467
poolSource: PublicKey,
466468
poolDestination: PublicKey,
467469
userDestination: PublicKey,
470+
sourceTokenProgramId: PublicKey,
471+
destinationTokenProgramId: PublicKey,
468472
hostFeeAccount: PublicKey | null,
469473
userTransferAuthority: Account,
470474
amountIn: number | Numberu64,
@@ -486,7 +490,9 @@ export class TokenSwap {
486490
this.feeAccount,
487491
hostFeeAccount,
488492
this.swapProgramId,
489-
this.tokenProgramId,
493+
sourceTokenProgramId,
494+
destinationTokenProgramId,
495+
this.poolTokenProgramId,
490496
amountIn,
491497
minimumAmountOut,
492498
),
@@ -508,7 +514,9 @@ export class TokenSwap {
508514
feeAccount: PublicKey,
509515
hostFeeAccount: PublicKey | null,
510516
swapProgramId: PublicKey,
511-
tokenProgramId: PublicKey,
517+
sourceTokenProgramId: PublicKey,
518+
destinationTokenProgramId: PublicKey,
519+
poolTokenProgramId: PublicKey,
512520
amountIn: number | Numberu64,
513521
minimumAmountOut: number | Numberu64,
514522
): TransactionInstruction {
@@ -538,7 +546,9 @@ export class TokenSwap {
538546
{pubkey: userDestination, isSigner: false, isWritable: true},
539547
{pubkey: poolMint, isSigner: false, isWritable: true},
540548
{pubkey: feeAccount, isSigner: false, isWritable: true},
541-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
549+
{pubkey: sourceTokenProgramId, isSigner: false, isWritable: false},
550+
{pubkey: destinationTokenProgramId, isSigner: false, isWritable: false},
551+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
542552
];
543553
if (hostFeeAccount !== null) {
544554
keys.push({pubkey: hostFeeAccount, isSigner: false, isWritable: true});
@@ -555,6 +565,8 @@ export class TokenSwap {
555565
* @param userAccountA User account for token A
556566
* @param userAccountB User account for token B
557567
* @param poolAccount User account for pool token
568+
* @param tokenProgramIdA Program id for token A
569+
* @param tokenProgramIdB Program id for token B
558570
* @param userTransferAuthority Account delegated to transfer user's tokens
559571
* @param poolTokenAmount Amount of pool tokens to mint
560572
* @param maximumTokenA The maximum amount of token A to deposit
@@ -564,6 +576,8 @@ export class TokenSwap {
564576
userAccountA: PublicKey,
565577
userAccountB: PublicKey,
566578
poolAccount: PublicKey,
579+
tokenProgramIdA: PublicKey,
580+
tokenProgramIdB: PublicKey,
567581
userTransferAuthority: Account,
568582
poolTokenAmount: number | Numberu64,
569583
maximumTokenA: number | Numberu64,
@@ -584,7 +598,9 @@ export class TokenSwap {
584598
this.poolToken,
585599
poolAccount,
586600
this.swapProgramId,
587-
this.tokenProgramId,
601+
tokenProgramIdA,
602+
tokenProgramIdB,
603+
this.poolTokenProgramId,
588604
poolTokenAmount,
589605
maximumTokenA,
590606
maximumTokenB,
@@ -606,7 +622,9 @@ export class TokenSwap {
606622
poolToken: PublicKey,
607623
poolAccount: PublicKey,
608624
swapProgramId: PublicKey,
609-
tokenProgramId: PublicKey,
625+
tokenProgramIdA: PublicKey,
626+
tokenProgramIdB: PublicKey,
627+
poolTokenProgramId: PublicKey,
610628
poolTokenAmount: number | Numberu64,
611629
maximumTokenA: number | Numberu64,
612630
maximumTokenB: number | Numberu64,
@@ -639,7 +657,9 @@ export class TokenSwap {
639657
{pubkey: intoB, isSigner: false, isWritable: true},
640658
{pubkey: poolToken, isSigner: false, isWritable: true},
641659
{pubkey: poolAccount, isSigner: false, isWritable: true},
642-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
660+
{pubkey: tokenProgramIdA, isSigner: false, isWritable: false},
661+
{pubkey: tokenProgramIdB, isSigner: false, isWritable: false},
662+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
643663
];
644664
return new TransactionInstruction({
645665
keys,
@@ -654,6 +674,8 @@ export class TokenSwap {
654674
* @param userAccountA User account for token A
655675
* @param userAccountB User account for token B
656676
* @param poolAccount User account for pool token
677+
* @param tokenProgramIdA Program id for token A
678+
* @param tokenProgramIdB Program id for token B
657679
* @param userTransferAuthority Account delegated to transfer user's tokens
658680
* @param poolTokenAmount Amount of pool tokens to burn
659681
* @param minimumTokenA The minimum amount of token A to withdraw
@@ -663,6 +685,8 @@ export class TokenSwap {
663685
userAccountA: PublicKey,
664686
userAccountB: PublicKey,
665687
poolAccount: PublicKey,
688+
tokenProgramIdA: PublicKey,
689+
tokenProgramIdB: PublicKey,
666690
userTransferAuthority: Account,
667691
poolTokenAmount: number | Numberu64,
668692
minimumTokenA: number | Numberu64,
@@ -684,7 +708,9 @@ export class TokenSwap {
684708
userAccountA,
685709
userAccountB,
686710
this.swapProgramId,
687-
this.tokenProgramId,
711+
this.poolTokenProgramId,
712+
tokenProgramIdA,
713+
tokenProgramIdB,
688714
poolTokenAmount,
689715
minimumTokenA,
690716
minimumTokenB,
@@ -707,7 +733,9 @@ export class TokenSwap {
707733
userAccountA: PublicKey,
708734
userAccountB: PublicKey,
709735
swapProgramId: PublicKey,
710-
tokenProgramId: PublicKey,
736+
poolTokenProgramId: PublicKey,
737+
tokenProgramIdA: PublicKey,
738+
tokenProgramIdB: PublicKey,
711739
poolTokenAmount: number | Numberu64,
712740
minimumTokenA: number | Numberu64,
713741
minimumTokenB: number | Numberu64,
@@ -741,7 +769,9 @@ export class TokenSwap {
741769
{pubkey: userAccountA, isSigner: false, isWritable: true},
742770
{pubkey: userAccountB, isSigner: false, isWritable: true},
743771
{pubkey: feeAccount, isSigner: false, isWritable: true},
744-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
772+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
773+
{pubkey: tokenProgramIdA, isSigner: false, isWritable: false},
774+
{pubkey: tokenProgramIdB, isSigner: false, isWritable: false},
745775
];
746776
return new TransactionInstruction({
747777
keys,
@@ -754,13 +784,15 @@ export class TokenSwap {
754784
* Deposit one side of tokens into the pool
755785
* @param userAccount User account to deposit token A or B
756786
* @param poolAccount User account to receive pool tokens
787+
* @param sourceTokenProgramId Program id for the source token
757788
* @param userTransferAuthority Account delegated to transfer user's tokens
758789
* @param sourceTokenAmount The amount of token A or B to deposit
759790
* @param minimumPoolTokenAmount Minimum amount of pool tokens to mint
760791
*/
761792
async depositSingleTokenTypeExactAmountIn(
762793
userAccount: PublicKey,
763794
poolAccount: PublicKey,
795+
sourceTokenProgramId: PublicKey,
764796
userTransferAuthority: Account,
765797
sourceTokenAmount: number | Numberu64,
766798
minimumPoolTokenAmount: number | Numberu64,
@@ -779,7 +811,8 @@ export class TokenSwap {
779811
this.poolToken,
780812
poolAccount,
781813
this.swapProgramId,
782-
this.tokenProgramId,
814+
sourceTokenProgramId,
815+
this.poolTokenProgramId,
783816
sourceTokenAmount,
784817
minimumPoolTokenAmount,
785818
),
@@ -799,7 +832,8 @@ export class TokenSwap {
799832
poolToken: PublicKey,
800833
poolAccount: PublicKey,
801834
swapProgramId: PublicKey,
802-
tokenProgramId: PublicKey,
835+
sourceTokenProgramId: PublicKey,
836+
poolTokenProgramId: PublicKey,
803837
sourceTokenAmount: number | Numberu64,
804838
minimumPoolTokenAmount: number | Numberu64,
805839
): TransactionInstruction {
@@ -830,7 +864,8 @@ export class TokenSwap {
830864
{pubkey: intoB, isSigner: false, isWritable: true},
831865
{pubkey: poolToken, isSigner: false, isWritable: true},
832866
{pubkey: poolAccount, isSigner: false, isWritable: true},
833-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
867+
{pubkey: sourceTokenProgramId, isSigner: false, isWritable: false},
868+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
834869
];
835870
return new TransactionInstruction({
836871
keys,
@@ -844,13 +879,15 @@ export class TokenSwap {
844879
*
845880
* @param userAccount User account to receive token A or B
846881
* @param poolAccount User account to burn pool token
882+
* @param destinationTokenProgramId Program id for the destination token
847883
* @param userTransferAuthority Account delegated to transfer user's tokens
848884
* @param destinationTokenAmount The amount of token A or B to withdraw
849885
* @param maximumPoolTokenAmount Maximum amount of pool tokens to burn
850886
*/
851887
async withdrawSingleTokenTypeExactAmountOut(
852888
userAccount: PublicKey,
853889
poolAccount: PublicKey,
890+
destinationTokenProgramId: PublicKey,
854891
userTransferAuthority: Account,
855892
destinationTokenAmount: number | Numberu64,
856893
maximumPoolTokenAmount: number | Numberu64,
@@ -870,7 +907,8 @@ export class TokenSwap {
870907
this.tokenAccountB,
871908
userAccount,
872909
this.swapProgramId,
873-
this.tokenProgramId,
910+
this.poolTokenProgramId,
911+
destinationTokenProgramId,
874912
destinationTokenAmount,
875913
maximumPoolTokenAmount,
876914
),
@@ -891,7 +929,8 @@ export class TokenSwap {
891929
fromB: PublicKey,
892930
userAccount: PublicKey,
893931
swapProgramId: PublicKey,
894-
tokenProgramId: PublicKey,
932+
poolTokenProgramId: PublicKey,
933+
destinationTokenProgramId: PublicKey,
895934
destinationTokenAmount: number | Numberu64,
896935
maximumPoolTokenAmount: number | Numberu64,
897936
): TransactionInstruction {
@@ -925,7 +964,8 @@ export class TokenSwap {
925964
{pubkey: fromB, isSigner: false, isWritable: true},
926965
{pubkey: userAccount, isSigner: false, isWritable: true},
927966
{pubkey: feeAccount, isSigner: false, isWritable: true},
928-
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
967+
{pubkey: poolTokenProgramId, isSigner: false, isWritable: false},
968+
{pubkey: destinationTokenProgramId, isSigner: false, isWritable: false},
929969
];
930970
return new TransactionInstruction({
931971
keys,

0 commit comments

Comments
 (0)