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 in client #33

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
26 changes: 22 additions & 4 deletions client/ts/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ import { FIXED_WRAPPER_HEADER_SIZE } from './constants';
import { getVaultAddress } from './utils/market';

export class ManifestClient {
private isBase22: boolean;
private isQuote22: boolean;
private constructor(
public connection: Connection,
public wrapper: Wrapper,
public market: Market,
private payer: PublicKey,
private baseMint: Mint,
private quoteMint: Mint,
) {}
) {
this.isBase22 = baseMint.tlvData.length > 0;
this.isQuote22 = quoteMint.tlvData.length > 0;
}

/**
* Create a new client which creates a wrapper and claims seat if needed.
Expand All @@ -68,7 +73,6 @@ export class ManifestClient {
});
const baseMintPk: PublicKey = marketObject.baseMint();
const quoteMintPk: PublicKey = marketObject.quoteMint();
// TODO: Maybe update for token22.
const baseMint: Mint = await getMint(connection, baseMintPk);
const quoteMint: Mint = await getMint(connection, quoteMintPk);

Expand Down Expand Up @@ -248,6 +252,10 @@ export class ManifestClient {
mint,
payer,
);
const is22: boolean =
(mint == this.baseMint.address && this.isBase22) ||
(mint == this.baseMint.address && this.isBase22);

return createDepositInstruction(
{
payer,
Expand All @@ -258,6 +266,7 @@ export class ManifestClient {
owner: this.payer,
wrapperState: this.wrapper.address,
mint,
tokenProgram: is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
},
{
params: {
Expand Down Expand Up @@ -287,6 +296,10 @@ export class ManifestClient {
mint,
payer,
);
const is22: boolean =
(mint == this.baseMint.address && this.isBase22) ||
(mint == this.baseMint.address && this.isBase22);

return createWithdrawInstruction(
{
payer,
Expand All @@ -297,6 +310,7 @@ export class ManifestClient {
owner: this.payer,
wrapperState: this.wrapper.address,
mint,
tokenProgram: is22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
},
{
params: {
Expand Down Expand Up @@ -377,9 +391,13 @@ export class ManifestClient {
traderQuote,
baseVault,
quoteVault,
tokenProgramBase: TOKEN_PROGRAM_ID,
tokenProgramBase: this.isBase22
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID,
baseMint: this.baseMint.address,
tokenProgramQuote: TOKEN_PROGRAM_ID,
tokenProgramQuote: this.isQuote22
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID,
quoteMint: this.quoteMint.address,
},
{
Expand Down
Loading