Skip to content

Commit

Permalink
Renaming and comment in sdk (#156)
Browse files Browse the repository at this point in the history
* renaming and comment in sdk

* lint
  • Loading branch information
brittcyr authored Oct 7, 2024
1 parent d8d316a commit de56325
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions client/ts/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ export class ManifestClient {
*
* @param connection Connection
* @param marketPk PublicKey of the market
* @param payerKeypair Keypair of the trader
* @param trader PublicKey of the trader
*
* @returns Promise<SetupData>
*/
public static async getSetupIxs(
connection: Connection,
marketPk: PublicKey,
payerPub: PublicKey,
trader: PublicKey,
): Promise<SetupData> {
const setupData: SetupData = {
setupNeeded: true,
Expand All @@ -274,15 +274,15 @@ export class ManifestClient {
};
const userWrapper = await ManifestClient.fetchFirstUserWrapper(
connection,
payerPub,
trader,
);
if (!userWrapper) {
const wrapperKeypair: Keypair = Keypair.generate();
setupData.wrapperKeypair = wrapperKeypair;

const createAccountIx: TransactionInstruction =
SystemProgram.createAccount({
fromPubkey: payerPub,
fromPubkey: trader,
newAccountPubkey: wrapperKeypair.publicKey,
space: FIXED_WRAPPER_HEADER_SIZE,
lamports: await connection.getMinimumBalanceForRentExemption(
Expand All @@ -294,14 +294,14 @@ export class ManifestClient {

const createWrapperIx: TransactionInstruction =
createCreateWrapperInstruction({
owner: payerPub,
owner: trader,
wrapperState: wrapperKeypair.publicKey,
});
setupData.instructions.push(createWrapperIx);

const claimSeatIx: TransactionInstruction = createClaimSeatInstruction({
manifestProgram: MANIFEST_PROGRAM_ID,
owner: payerPub,
owner: trader,
market: marketPk,
wrapperState: wrapperKeypair.publicKey,
});
Expand All @@ -326,7 +326,7 @@ export class ManifestClient {
// There is a wrapper, but need to claim a seat.
const claimSeatIx: TransactionInstruction = createClaimSeatInstruction({
manifestProgram: MANIFEST_PROGRAM_ID,
owner: payerPub,
owner: trader,
market: marketPk,
wrapperState: userWrapper.pubkey,
});
Expand All @@ -335,25 +335,27 @@ export class ManifestClient {
return setupData;
}

// TODO: Make a version that does not require a trader with a wrapper for use
// in cases where we just want to see the orderbook.
/**
* Create a new client. throws if setup ixs are needed. Call ManifestClient.getSetupIxs to check if ixs are needed.
* This is the way to create a client without directly passing in `Keypair` types (for example when building a UI).
*
* @param connection Connection
* @param marketPk PublicKey of the market
* @param payerKeypair Keypair of the trader
* @param trader PublicKey of the trader
*
* @returns ManifestClient
*/
public static async getClientForMarketNoPrivateKey(
connection: Connection,
marketPk: PublicKey,
payerPub: PublicKey,
trader: PublicKey,
): Promise<ManifestClient> {
const { setupNeeded } = await this.getSetupIxs(
connection,
marketPk,
payerPub,
trader,
);
if (setupNeeded) {
throw new Error('setup ixs need to be executed first');
Expand All @@ -370,7 +372,7 @@ export class ManifestClient {

const userWrapper = await ManifestClient.fetchFirstUserWrapper(
connection,
payerPub,
trader,
);

if (!userWrapper) {
Expand All @@ -388,7 +390,7 @@ export class ManifestClient {
connection,
wrapper,
marketObject,
payerPub,
trader,
baseMint,
quoteMint,
);
Expand Down

0 comments on commit de56325

Please sign in to comment.