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

missing tswap pdas + pda resolvers #58

Merged
merged 2 commits into from
Sep 30, 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
2 changes: 1 addition & 1 deletion resolvers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tensor-foundation/resolvers",
"version": "0.2.1",
"version": "0.2.2",
"description": "Kinobi resolvers for Tensor protocols",
"sideEffects": false,
"module": "./dist/src/index.mjs",
Expand Down
84 changes: 84 additions & 0 deletions resolvers/src/pdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,87 @@ export async function findTreeAuthorityPda(
seeds: [getAddressEncoder().encode(seeds.merkleTree)],
});
}

export type TswapNftEscrowSeeds = {
/** The address of the mint account */
mint: Address;
};

export async function findTswapNftEscrowPda(
seeds: TswapNftEscrowSeeds,
config: { programAddress?: Address | undefined } = {}
): Promise<ProgramDerivedAddress> {
const {
programAddress = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' as Address<'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN'>,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getUtf8Encoder().encode('nft_escrow'),
getAddressEncoder().encode(seeds.mint)
],
});
}

export type TswapNftDepositReceiptSeeds = {
/** The address of the mint account */
mint: Address;
};

export async function findTswapNftDepositReceiptPda(
seeds: TswapNftDepositReceiptSeeds,
config: { programAddress?: Address | undefined } = {}
): Promise<ProgramDerivedAddress> {
const {
programAddress = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' as Address<'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN'>,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getUtf8Encoder().encode('nft_receipt'),
getAddressEncoder().encode(seeds.mint)
],
});
}

export type TswapSolEscrowSeeds = {
/** The address of the pool account */
pool: Address;
};

export async function findTswapSolEscrowPda(
seeds: TswapSolEscrowSeeds,
config: { programAddress?: Address | undefined } = {}
): Promise<ProgramDerivedAddress> {
const {
programAddress = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' as Address<'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN'>,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getUtf8Encoder().encode('sol_escrow'),
getAddressEncoder().encode(seeds.pool)
],
});
}

export type TswapSingleListingSeeds = {
/** The address of the mint account */
mint: Address;
};

export async function findTswapSingleListingPda(
seeds: TswapSingleListingSeeds,
config: { programAddress?: Address | undefined } = {}
): Promise<ProgramDerivedAddress> {
const {
programAddress = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' as Address<'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN'>,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getUtf8Encoder().encode('single_listing'),
getAddressEncoder().encode(seeds.mint)
],
});
}
52 changes: 52 additions & 0 deletions resolvers/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
findNftReceiptPda,
findTokenRecordPda,
findTreeAuthorityPda,
findTswapNftDepositReceiptPda,
findTswapNftEscrowPda,
findTswapSingleListingPda,
findTswapSolEscrowPda,
findWnsApprovePda,
findWnsDistributionPda,
} from './index';
Expand Down Expand Up @@ -554,3 +558,51 @@ export const resolveOrderTokenRecordFromTokenStandard = async ({
}
: { value: null };
};

export const resolveTswapNftEscrowPda = async ({
args,
}: {
args: { mint: Address; };
}): Promise<Partial<{ value: ProgramDerivedAddress | null }>> => {
return {
value: await findTswapNftEscrowPda({
mint: expectAddress(args.mint),
}),
};
};

export const resolveTswapNftDepositReceiptPda = async ({
args,
}: {
args: { mint: Address; };
}): Promise<Partial<{ value: ProgramDerivedAddress | null }>> => {
return {
value: await findTswapNftDepositReceiptPda({
mint: expectAddress(args.mint),
}),
};
};

export const resolveTswapSolEscrowPda = async ({
args,
}: {
args: { pool: Address; };
}): Promise<Partial<{ value: ProgramDerivedAddress | null }>> => {
return {
value: await findTswapSolEscrowPda({
pool: expectAddress(args.pool),
}),
};
};

export const resolveTswapSingleListingPda = async ({
args,
}: {
args: { mint: Address; };
}): Promise<Partial<{ value: ProgramDerivedAddress | null }>> => {
return {
value: await findTswapSingleListingPda({
mint: expectAddress(args.mint),
}),
};
};
Loading