Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22 associated token accounts in client #250

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions client/ts/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,15 @@ export class ManifestClient {
throw new Error('Read only');
}
const vault: PublicKey = getVaultAddress(this.market.address, mint);
const is22: boolean =
(mint.equals(this.baseMint.address) && this.isBase22) ||
(mint.equals(this.quoteMint.address) && this.isQuote22);
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
mint,
payer,
true,
is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const is22: boolean =
(mint.equals(this.baseMint.address) && this.isBase22) ||
(mint.equals(this.quoteMint.address) && this.isQuote22);
const mintDecimals =
this.market.quoteMint().toBase58() === mint.toBase58()
? this.market.quoteDecimals()
Expand Down Expand Up @@ -664,13 +666,15 @@ export class ManifestClient {
throw new Error('Read only');
}
const vault: PublicKey = getVaultAddress(this.market.address, mint);
const is22: boolean =
(mint.equals(this.baseMint.address) && this.isBase22) ||
(mint.equals(this.quoteMint.address) && this.isQuote22);
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
mint,
payer,
true,
is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const is22: boolean =
(mint.equals(this.baseMint.address) && this.isBase22) ||
(mint.equals(this.quoteMint.address) && this.isQuote22);
const mintDecimals =
this.market.quoteMint().toBase58() === mint.toBase58()
? this.market.quoteDecimals()
Expand Down Expand Up @@ -924,10 +928,14 @@ export class ManifestClient {
const traderBase: PublicKey = getAssociatedTokenAddressSync(
this.baseMint.address,
payer,
true,
this.isBase22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const traderQuote: PublicKey = getAssociatedTokenAddressSync(
this.quoteMint.address,
payer,
true,
this.isQuote22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const baseVault: PublicKey = getVaultAddress(
this.market.address,
Expand Down Expand Up @@ -1313,10 +1321,6 @@ export class ManifestClient {
): Promise<TransactionInstruction> {
const globalAddress: PublicKey = getGlobalAddress(globalMint);
const globalVault: PublicKey = getGlobalVaultAddress(globalMint);
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
globalMint,
payer,
);
const globalMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(globalMint))!;
const mint: Mint = unpackMint(
Expand All @@ -1325,6 +1329,12 @@ export class ManifestClient {
globalMintAccountInfo.owner,
);
const is22: boolean = mint.tlvData.length > 0;
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
globalMint,
payer,
true,
is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const mintDecimals = mint.decimals;
const amountAtoms = Math.ceil(amountTokens * 10 ** mintDecimals);

Expand Down Expand Up @@ -1363,10 +1373,6 @@ export class ManifestClient {
): Promise<TransactionInstruction> {
const globalAddress: PublicKey = getGlobalAddress(globalMint);
const globalVault: PublicKey = getGlobalVaultAddress(globalMint);
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
globalMint,
payer,
);
const globalMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(globalMint))!;
const mint: Mint = unpackMint(
Expand All @@ -1375,6 +1381,12 @@ export class ManifestClient {
globalMintAccountInfo.owner,
);
const is22: boolean = mint.tlvData.length > 0;
const traderTokenAccount: PublicKey = getAssociatedTokenAddressSync(
globalMint,
payer,
true,
is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
);
const mintDecimals = mint.decimals;
const amountAtoms = Math.ceil(amountTokens * 10 ** mintDecimals);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cks-systems/manifest-sdk",
"version": "0.1.63",
"version": "0.1.64",
"files": [
"dist/",
"README.md",
Expand Down
Loading