Merge branch 'worktree-feat+solisting-sdk'
This commit is contained in:
@@ -1 +1,6 @@
|
|||||||
|
approvedGitRepositories:
|
||||||
|
- "**"
|
||||||
|
|
||||||
|
enableScripts: true
|
||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|||||||
17
package.json
17
package.json
@@ -1,21 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "solisting",
|
"name": "solisting",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
"private": true,
|
||||||
|
"workspaces": [
|
||||||
|
"sdk",
|
||||||
|
"app"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
|
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
|
||||||
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
|
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
|
||||||
"@anchor-lang/core": "^1.0.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bn.js": "^5.2.0",
|
"prettier": "^3.8.3"
|
||||||
"@types/chai": "^5.2.3",
|
|
||||||
"@types/mocha": "^10.0.10",
|
|
||||||
"chai": "^6.2.2",
|
|
||||||
"mocha": "^11.7.6",
|
|
||||||
"prettier": "^3.8.3",
|
|
||||||
"ts-mocha": "^11.1.0",
|
|
||||||
"typescript": "^6.0.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
sdk/codama.solisting.json
Normal file
11
sdk/codama.solisting.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"idl": "./src/idl/solisting.json",
|
||||||
|
"scripts": {
|
||||||
|
"js": [
|
||||||
|
{
|
||||||
|
"from": "@codama/renderers-js",
|
||||||
|
"args": ["./src/generated/solisting"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
23
sdk/package.json
Normal file
23
sdk/package.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "@solisting/sdk",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"main": "./src/index.ts",
|
||||||
|
"types": "./src/index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"generate": "codama run js --config codama.solisting.json",
|
||||||
|
"test": "vitest run",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@solana/kit": "^6.0.0",
|
||||||
|
"@solana/program-client-core": "^6.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@codama/nodes-from-anchor": "^1.4.1",
|
||||||
|
"@codama/renderers-js": "^2.2.0",
|
||||||
|
"codama": "^1.6.0",
|
||||||
|
"typescript": "^6.0.3",
|
||||||
|
"vitest": "^3.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
36
sdk/src/__tests__/pda.test.ts
Normal file
36
sdk/src/__tests__/pda.test.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { address } from '@solana/kit'
|
||||||
|
import { deriveEscrowId, findListingPda } from '../pda.js'
|
||||||
|
|
||||||
|
const SELLER = address('11111111111111111111111111111112')
|
||||||
|
|
||||||
|
describe('deriveEscrowId', () => {
|
||||||
|
it('returns a bigint from the first 8 bytes of the order PDA', () => {
|
||||||
|
const fakeOrderPda = address('So11111111111111111111111111111111111111112')
|
||||||
|
const id1 = deriveEscrowId(fakeOrderPda)
|
||||||
|
const id2 = deriveEscrowId(fakeOrderPda)
|
||||||
|
expect(id1).toBe(id2)
|
||||||
|
expect(typeof id1).toBe('bigint')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns different ids for different PDAs', () => {
|
||||||
|
const pda1 = address('So11111111111111111111111111111111111111112')
|
||||||
|
const pda2 = address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')
|
||||||
|
expect(deriveEscrowId(pda1)).not.toBe(deriveEscrowId(pda2))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('findListingPda', () => {
|
||||||
|
it('derives a deterministic PDA for a given seller + listingId', async () => {
|
||||||
|
const [pda1] = await findListingPda(SELLER, 1001n)
|
||||||
|
const [pda2] = await findListingPda(SELLER, 1001n)
|
||||||
|
expect(pda1).toBe(pda2)
|
||||||
|
expect(pda1).toHaveLength(44) // base58 encoded 32-byte pubkey
|
||||||
|
})
|
||||||
|
|
||||||
|
it('produces different PDAs for different listing ids', async () => {
|
||||||
|
const [pda1] = await findListingPda(SELLER, 1001n)
|
||||||
|
const [pda2] = await findListingPda(SELLER, 1002n)
|
||||||
|
expect(pda1).not.toBe(pda2)
|
||||||
|
})
|
||||||
|
})
|
||||||
22
sdk/src/generated/solisting/package.json
Normal file
22
sdk/src/generated/solisting/package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "js-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "src/index.ts",
|
||||||
|
"files": [
|
||||||
|
"./dist/src",
|
||||||
|
"./dist/types",
|
||||||
|
"./src/"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@solana/kit": "^6.10.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@solana/program-client-core": "^6.10.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
10
sdk/src/generated/solisting/src/generated/accounts/index.ts
Normal file
10
sdk/src/generated/solisting/src/generated/accounts/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./solistingStateListingAccount";
|
||||||
|
export * from "./solistingStateOrderAccount";
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
addDecoderSizePrefix,
|
||||||
|
addEncoderSizePrefix,
|
||||||
|
assertAccountExists,
|
||||||
|
assertAccountsExist,
|
||||||
|
combineCodec,
|
||||||
|
decodeAccount,
|
||||||
|
fetchEncodedAccount,
|
||||||
|
fetchEncodedAccounts,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getArrayDecoder,
|
||||||
|
getArrayEncoder,
|
||||||
|
getBooleanDecoder,
|
||||||
|
getBooleanEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getOptionDecoder,
|
||||||
|
getOptionEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU32Decoder,
|
||||||
|
getU32Encoder,
|
||||||
|
getU64Decoder,
|
||||||
|
getU64Encoder,
|
||||||
|
getU8Decoder,
|
||||||
|
getU8Encoder,
|
||||||
|
getUtf8Decoder,
|
||||||
|
getUtf8Encoder,
|
||||||
|
transformEncoder,
|
||||||
|
type Account,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type EncodedAccount,
|
||||||
|
type Encoder,
|
||||||
|
type FetchAccountConfig,
|
||||||
|
type FetchAccountsConfig,
|
||||||
|
type MaybeAccount,
|
||||||
|
type MaybeEncodedAccount,
|
||||||
|
type Option,
|
||||||
|
type OptionOrNullable,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getSolistingStateAltCurrencyConfigDecoder,
|
||||||
|
getSolistingStateAltCurrencyConfigEncoder,
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateAltCurrencyConfig,
|
||||||
|
type SolistingStateAltCurrencyConfigArgs,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR: ReadonlyUint8Array =
|
||||||
|
new Uint8Array([59, 89, 136, 25, 21, 196, 183, 13]);
|
||||||
|
|
||||||
|
export function getSolistingStateListingAccountDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SolistingStateListingAccount = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
seller: Address;
|
||||||
|
/** Sole source of truth for price. All alt_currencies are derived from this via oracle. */
|
||||||
|
canonicalCurrency: SolistingStateCurrency;
|
||||||
|
/** Price in canonical_currency's smallest unit. */
|
||||||
|
price: bigint;
|
||||||
|
/**
|
||||||
|
* Pyth V2 PriceFeedAccount for the canonical currency priced in USD.
|
||||||
|
* `None` = canonical is a $1.00 USD stablecoin.
|
||||||
|
* For Sol canonical: set to the SOL/USD Pyth feed.
|
||||||
|
*/
|
||||||
|
canonicalOracle: Option<Address>;
|
||||||
|
/**
|
||||||
|
* Alt currencies the seller accepts. Amounts are oracle-computed at create_order time.
|
||||||
|
* Empty = no oracle ever needed.
|
||||||
|
*/
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfig>;
|
||||||
|
/** Resolvers the seller accepts for dispute resolution. Empty = any resolver ok. */
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
/** Total units the seller offers (includes quantity_reserved). */
|
||||||
|
quantity: number;
|
||||||
|
/** Units held by pending orders. available = quantity - quantity_reserved. */
|
||||||
|
quantityReserved: number;
|
||||||
|
metadataUri: string;
|
||||||
|
listingId: bigint;
|
||||||
|
isActive: boolean;
|
||||||
|
bump: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingStateListingAccountArgs = {
|
||||||
|
seller: Address;
|
||||||
|
/** Sole source of truth for price. All alt_currencies are derived from this via oracle. */
|
||||||
|
canonicalCurrency: SolistingStateCurrencyArgs;
|
||||||
|
/** Price in canonical_currency's smallest unit. */
|
||||||
|
price: number | bigint;
|
||||||
|
/**
|
||||||
|
* Pyth V2 PriceFeedAccount for the canonical currency priced in USD.
|
||||||
|
* `None` = canonical is a $1.00 USD stablecoin.
|
||||||
|
* For Sol canonical: set to the SOL/USD Pyth feed.
|
||||||
|
*/
|
||||||
|
canonicalOracle: OptionOrNullable<Address>;
|
||||||
|
/**
|
||||||
|
* Alt currencies the seller accepts. Amounts are oracle-computed at create_order time.
|
||||||
|
* Empty = no oracle ever needed.
|
||||||
|
*/
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfigArgs>;
|
||||||
|
/** Resolvers the seller accepts for dispute resolution. Empty = any resolver ok. */
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
/** Total units the seller offers (includes quantity_reserved). */
|
||||||
|
quantity: number;
|
||||||
|
/** Units held by pending orders. available = quantity - quantity_reserved. */
|
||||||
|
quantityReserved: number;
|
||||||
|
metadataUri: string;
|
||||||
|
listingId: number | bigint;
|
||||||
|
isActive: boolean;
|
||||||
|
bump: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Gets the encoder for {@link SolistingStateListingAccountArgs} account data. */
|
||||||
|
export function getSolistingStateListingAccountEncoder(): Encoder<SolistingStateListingAccountArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["seller", getAddressEncoder()],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["price", getU64Encoder()],
|
||||||
|
["canonicalOracle", getOptionEncoder(getAddressEncoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayEncoder(getAddressEncoder())],
|
||||||
|
["quantity", getU32Encoder()],
|
||||||
|
["quantityReserved", getU32Encoder()],
|
||||||
|
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
|
["listingId", getU64Encoder()],
|
||||||
|
["isActive", getBooleanEncoder()],
|
||||||
|
["bump", getU8Encoder()],
|
||||||
|
]),
|
||||||
|
(value) => ({
|
||||||
|
...value,
|
||||||
|
discriminator: SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the decoder for {@link SolistingStateListingAccount} account data. */
|
||||||
|
export function getSolistingStateListingAccountDecoder(): Decoder<SolistingStateListingAccount> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["seller", getAddressDecoder()],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["price", getU64Decoder()],
|
||||||
|
["canonicalOracle", getOptionDecoder(getAddressDecoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayDecoder(getAddressDecoder())],
|
||||||
|
["quantity", getU32Decoder()],
|
||||||
|
["quantityReserved", getU32Decoder()],
|
||||||
|
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
|
["listingId", getU64Decoder()],
|
||||||
|
["isActive", getBooleanDecoder()],
|
||||||
|
["bump", getU8Decoder()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the codec for {@link SolistingStateListingAccount} account data. */
|
||||||
|
export function getSolistingStateListingAccountCodec(): Codec<
|
||||||
|
SolistingStateListingAccountArgs,
|
||||||
|
SolistingStateListingAccount
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getSolistingStateListingAccountEncoder(),
|
||||||
|
getSolistingStateListingAccountDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function decodeSolistingStateListingAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: EncodedAccount<TAddress>,
|
||||||
|
): Account<SolistingStateListingAccount, TAddress>;
|
||||||
|
export function decodeSolistingStateListingAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
||||||
|
): MaybeAccount<SolistingStateListingAccount, TAddress>;
|
||||||
|
export function decodeSolistingStateListingAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
||||||
|
):
|
||||||
|
| Account<SolistingStateListingAccount, TAddress>
|
||||||
|
| MaybeAccount<SolistingStateListingAccount, TAddress> {
|
||||||
|
return decodeAccount(
|
||||||
|
encodedAccount as MaybeEncodedAccount<TAddress>,
|
||||||
|
getSolistingStateListingAccountDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchSolistingStateListingAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
||||||
|
address: Address<TAddress>,
|
||||||
|
config?: FetchAccountConfig,
|
||||||
|
): Promise<Account<SolistingStateListingAccount, TAddress>> {
|
||||||
|
const maybeAccount = await fetchMaybeSolistingStateListingAccount(
|
||||||
|
rpc,
|
||||||
|
address,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
assertAccountExists(maybeAccount);
|
||||||
|
return maybeAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchMaybeSolistingStateListingAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
||||||
|
address: Address<TAddress>,
|
||||||
|
config?: FetchAccountConfig,
|
||||||
|
): Promise<MaybeAccount<SolistingStateListingAccount, TAddress>> {
|
||||||
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
||||||
|
return decodeSolistingStateListingAccount(maybeAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAllSolistingStateListingAccount(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
||||||
|
addresses: Array<Address>,
|
||||||
|
config?: FetchAccountsConfig,
|
||||||
|
): Promise<Account<SolistingStateListingAccount>[]> {
|
||||||
|
const maybeAccounts = await fetchAllMaybeSolistingStateListingAccount(
|
||||||
|
rpc,
|
||||||
|
addresses,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
assertAccountsExist(maybeAccounts);
|
||||||
|
return maybeAccounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAllMaybeSolistingStateListingAccount(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
||||||
|
addresses: Array<Address>,
|
||||||
|
config?: FetchAccountsConfig,
|
||||||
|
): Promise<MaybeAccount<SolistingStateListingAccount>[]> {
|
||||||
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
||||||
|
return maybeAccounts.map((maybeAccount) =>
|
||||||
|
decodeSolistingStateListingAccount(maybeAccount),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
assertAccountExists,
|
||||||
|
assertAccountsExist,
|
||||||
|
combineCodec,
|
||||||
|
decodeAccount,
|
||||||
|
fetchEncodedAccount,
|
||||||
|
fetchEncodedAccounts,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getI64Decoder,
|
||||||
|
getI64Encoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU64Decoder,
|
||||||
|
getU64Encoder,
|
||||||
|
getU8Decoder,
|
||||||
|
getU8Encoder,
|
||||||
|
transformEncoder,
|
||||||
|
type Account,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type EncodedAccount,
|
||||||
|
type Encoder,
|
||||||
|
type FetchAccountConfig,
|
||||||
|
type FetchAccountsConfig,
|
||||||
|
type MaybeAccount,
|
||||||
|
type MaybeEncodedAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR: ReadonlyUint8Array =
|
||||||
|
new Uint8Array([79, 67, 112, 155, 214, 14, 32, 55]);
|
||||||
|
|
||||||
|
export function getSolistingStateOrderAccountDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SolistingStateOrderAccount = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
listing: Address;
|
||||||
|
buyer: Address;
|
||||||
|
seller: Address;
|
||||||
|
resolver: Address;
|
||||||
|
/** The currency the buyer chose to pay in. */
|
||||||
|
paymentCurrency: SolistingStateCurrency;
|
||||||
|
/** Actual amount paid (may differ from price when oracle-converted). */
|
||||||
|
amount: bigint;
|
||||||
|
/** The descro EscrowAccount PDA for this order. */
|
||||||
|
escrowAccount: Address;
|
||||||
|
/** Derived from order_account PDA bytes[0..8]; used as descro escrow_id seed. */
|
||||||
|
escrowId: bigint;
|
||||||
|
orderId: bigint;
|
||||||
|
createdAt: bigint;
|
||||||
|
bump: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingStateOrderAccountArgs = {
|
||||||
|
listing: Address;
|
||||||
|
buyer: Address;
|
||||||
|
seller: Address;
|
||||||
|
resolver: Address;
|
||||||
|
/** The currency the buyer chose to pay in. */
|
||||||
|
paymentCurrency: SolistingStateCurrencyArgs;
|
||||||
|
/** Actual amount paid (may differ from price when oracle-converted). */
|
||||||
|
amount: number | bigint;
|
||||||
|
/** The descro EscrowAccount PDA for this order. */
|
||||||
|
escrowAccount: Address;
|
||||||
|
/** Derived from order_account PDA bytes[0..8]; used as descro escrow_id seed. */
|
||||||
|
escrowId: number | bigint;
|
||||||
|
orderId: number | bigint;
|
||||||
|
createdAt: number | bigint;
|
||||||
|
bump: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Gets the encoder for {@link SolistingStateOrderAccountArgs} account data. */
|
||||||
|
export function getSolistingStateOrderAccountEncoder(): Encoder<SolistingStateOrderAccountArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["listing", getAddressEncoder()],
|
||||||
|
["buyer", getAddressEncoder()],
|
||||||
|
["seller", getAddressEncoder()],
|
||||||
|
["resolver", getAddressEncoder()],
|
||||||
|
["paymentCurrency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["amount", getU64Encoder()],
|
||||||
|
["escrowAccount", getAddressEncoder()],
|
||||||
|
["escrowId", getU64Encoder()],
|
||||||
|
["orderId", getU64Encoder()],
|
||||||
|
["createdAt", getI64Encoder()],
|
||||||
|
["bump", getU8Encoder()],
|
||||||
|
]),
|
||||||
|
(value) => ({
|
||||||
|
...value,
|
||||||
|
discriminator: SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the decoder for {@link SolistingStateOrderAccount} account data. */
|
||||||
|
export function getSolistingStateOrderAccountDecoder(): Decoder<SolistingStateOrderAccount> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["listing", getAddressDecoder()],
|
||||||
|
["buyer", getAddressDecoder()],
|
||||||
|
["seller", getAddressDecoder()],
|
||||||
|
["resolver", getAddressDecoder()],
|
||||||
|
["paymentCurrency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["amount", getU64Decoder()],
|
||||||
|
["escrowAccount", getAddressDecoder()],
|
||||||
|
["escrowId", getU64Decoder()],
|
||||||
|
["orderId", getU64Decoder()],
|
||||||
|
["createdAt", getI64Decoder()],
|
||||||
|
["bump", getU8Decoder()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the codec for {@link SolistingStateOrderAccount} account data. */
|
||||||
|
export function getSolistingStateOrderAccountCodec(): Codec<
|
||||||
|
SolistingStateOrderAccountArgs,
|
||||||
|
SolistingStateOrderAccount
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getSolistingStateOrderAccountEncoder(),
|
||||||
|
getSolistingStateOrderAccountDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function decodeSolistingStateOrderAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: EncodedAccount<TAddress>,
|
||||||
|
): Account<SolistingStateOrderAccount, TAddress>;
|
||||||
|
export function decodeSolistingStateOrderAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: MaybeEncodedAccount<TAddress>,
|
||||||
|
): MaybeAccount<SolistingStateOrderAccount, TAddress>;
|
||||||
|
export function decodeSolistingStateOrderAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
||||||
|
):
|
||||||
|
| Account<SolistingStateOrderAccount, TAddress>
|
||||||
|
| MaybeAccount<SolistingStateOrderAccount, TAddress> {
|
||||||
|
return decodeAccount(
|
||||||
|
encodedAccount as MaybeEncodedAccount<TAddress>,
|
||||||
|
getSolistingStateOrderAccountDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchSolistingStateOrderAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
||||||
|
address: Address<TAddress>,
|
||||||
|
config?: FetchAccountConfig,
|
||||||
|
): Promise<Account<SolistingStateOrderAccount, TAddress>> {
|
||||||
|
const maybeAccount = await fetchMaybeSolistingStateOrderAccount(
|
||||||
|
rpc,
|
||||||
|
address,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
assertAccountExists(maybeAccount);
|
||||||
|
return maybeAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchMaybeSolistingStateOrderAccount<
|
||||||
|
TAddress extends string = string,
|
||||||
|
>(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
||||||
|
address: Address<TAddress>,
|
||||||
|
config?: FetchAccountConfig,
|
||||||
|
): Promise<MaybeAccount<SolistingStateOrderAccount, TAddress>> {
|
||||||
|
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
||||||
|
return decodeSolistingStateOrderAccount(maybeAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAllSolistingStateOrderAccount(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
||||||
|
addresses: Array<Address>,
|
||||||
|
config?: FetchAccountsConfig,
|
||||||
|
): Promise<Account<SolistingStateOrderAccount>[]> {
|
||||||
|
const maybeAccounts = await fetchAllMaybeSolistingStateOrderAccount(
|
||||||
|
rpc,
|
||||||
|
addresses,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
assertAccountsExist(maybeAccounts);
|
||||||
|
return maybeAccounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAllMaybeSolistingStateOrderAccount(
|
||||||
|
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
||||||
|
addresses: Array<Address>,
|
||||||
|
config?: FetchAccountsConfig,
|
||||||
|
): Promise<MaybeAccount<SolistingStateOrderAccount>[]> {
|
||||||
|
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
||||||
|
return maybeAccounts.map((maybeAccount) =>
|
||||||
|
decodeSolistingStateOrderAccount(maybeAccount),
|
||||||
|
);
|
||||||
|
}
|
||||||
13
sdk/src/generated/solisting/src/generated/index.ts
Normal file
13
sdk/src/generated/solisting/src/generated/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./accounts";
|
||||||
|
export * from "./instructions";
|
||||||
|
export * from "./pdas";
|
||||||
|
export * from "./programs";
|
||||||
|
export * from "./types";
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const ACCEPT_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
118, 157, 62, 39, 239, 234, 231, 193,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getAcceptOrderDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
ACCEPT_ORDER_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AcceptOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolver extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountOrderAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolverEntry extends string | AccountMeta<string> = string,
|
||||||
|
TAccountDescroProgram extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
|
"11111111111111111111111111111111",
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? WritableSignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountResolver extends string
|
||||||
|
? ReadonlyAccount<TAccountResolver>
|
||||||
|
: TAccountResolver,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
TAccountOrderAccount extends string
|
||||||
|
? WritableAccount<TAccountOrderAccount>
|
||||||
|
: TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry extends string
|
||||||
|
? ReadonlyAccount<TAccountResolverEntry>
|
||||||
|
: TAccountResolverEntry,
|
||||||
|
TAccountDescroProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountDescroProgram>
|
||||||
|
: TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type AcceptOrderInstructionData = { discriminator: ReadonlyUint8Array };
|
||||||
|
|
||||||
|
export type AcceptOrderInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getAcceptOrderInstructionDataEncoder(): FixedSizeEncoder<AcceptOrderInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: ACCEPT_ORDER_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAcceptOrderInstructionDataDecoder(): FixedSizeDecoder<AcceptOrderInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAcceptOrderInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
AcceptOrderInstructionDataArgs,
|
||||||
|
AcceptOrderInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getAcceptOrderInstructionDataEncoder(),
|
||||||
|
getAcceptOrderInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AcceptOrderInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountResolver extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountResolverEntry extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
resolver: Address<TAccountResolver>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
resolverEntry: Address<TAccountResolverEntry>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getAcceptOrderInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountResolver extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountResolverEntry extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: AcceptOrderInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): AcceptOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
resolver: { value: input.resolver ?? null, isWritable: false },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
resolverEntry: { value: input.resolverEntry ?? null, isWritable: false },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("resolver", accounts.resolver),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("resolverEntry", accounts.resolverEntry),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getAcceptOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as AcceptOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedAcceptOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
resolver: TAccountMetas[1];
|
||||||
|
listingAccount: TAccountMetas[2];
|
||||||
|
orderAccount: TAccountMetas[3];
|
||||||
|
escrowAccount: TAccountMetas[4];
|
||||||
|
resolverEntry: TAccountMetas[5];
|
||||||
|
descroProgram: TAccountMetas[6];
|
||||||
|
systemProgram: TAccountMetas[7];
|
||||||
|
};
|
||||||
|
data: AcceptOrderInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseAcceptOrderInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedAcceptOrderInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 8) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 8,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
seller: getNextAccount(),
|
||||||
|
resolver: getNextAccount(),
|
||||||
|
listingAccount: getNextAccount(),
|
||||||
|
orderAccount: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
resolverEntry: getNextAccount(),
|
||||||
|
descroProgram: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getAcceptOrderInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,386 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getProgramDerivedAddress,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
getAddressFromResolvedInstructionAccount,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const CANCEL_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
95, 129, 237, 240, 8, 49, 223, 132,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getCancelOrderDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
CANCEL_ORDER_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CancelOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountOrderAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountVault extends string | AccountMeta<string> = string,
|
||||||
|
TAccountDescroProgram extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
|
"11111111111111111111111111111111",
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountBuyer extends string
|
||||||
|
? WritableSignerAccount<TAccountBuyer> &
|
||||||
|
AccountSignerMeta<TAccountBuyer>
|
||||||
|
: TAccountBuyer,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
TAccountOrderAccount extends string
|
||||||
|
? WritableAccount<TAccountOrderAccount>
|
||||||
|
: TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountVault extends string
|
||||||
|
? WritableAccount<TAccountVault>
|
||||||
|
: TAccountVault,
|
||||||
|
TAccountDescroProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountDescroProgram>
|
||||||
|
: TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type CancelOrderInstructionData = { discriminator: ReadonlyUint8Array };
|
||||||
|
|
||||||
|
export type CancelOrderInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getCancelOrderInstructionDataEncoder(): FixedSizeEncoder<CancelOrderInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: CANCEL_ORDER_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCancelOrderInstructionDataDecoder(): FixedSizeDecoder<CancelOrderInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCancelOrderInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
CancelOrderInstructionDataArgs,
|
||||||
|
CancelOrderInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getCancelOrderInstructionDataEncoder(),
|
||||||
|
getCancelOrderInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CancelOrderAsyncInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault?: Address<TAccountVault>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getCancelOrderInstructionAsync<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CancelOrderAsyncInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
CancelOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.vault.value) {
|
||||||
|
accounts.vault.value = await getProgramDerivedAddress({
|
||||||
|
programAddress:
|
||||||
|
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
|
||||||
|
getAddressEncoder().encode(
|
||||||
|
getAddressFromResolvedInstructionAccount(
|
||||||
|
"escrowAccount",
|
||||||
|
accounts.escrowAccount.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCancelOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as CancelOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CancelOrderInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault: Address<TAccountVault>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCancelOrderInstruction<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CancelOrderInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): CancelOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCancelOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as CancelOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedCancelOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
buyer: TAccountMetas[0];
|
||||||
|
listingAccount: TAccountMetas[1];
|
||||||
|
orderAccount: TAccountMetas[2];
|
||||||
|
escrowAccount: TAccountMetas[3];
|
||||||
|
vault: TAccountMetas[4];
|
||||||
|
descroProgram: TAccountMetas[5];
|
||||||
|
systemProgram: TAccountMetas[6];
|
||||||
|
};
|
||||||
|
data: CancelOrderInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseCancelOrderInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedCancelOrderInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 7) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 7,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
buyer: getNextAccount(),
|
||||||
|
listingAccount: getNextAccount(),
|
||||||
|
orderAccount: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
vault: getNextAccount(),
|
||||||
|
descroProgram: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getCancelOrderInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const CLOSE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
33, 15, 192, 81, 78, 175, 159, 97,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getCloseListingDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
CLOSE_LISTING_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CloseListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? WritableSignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type CloseListingInstructionData = { discriminator: ReadonlyUint8Array };
|
||||||
|
|
||||||
|
export type CloseListingInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getCloseListingInstructionDataEncoder(): FixedSizeEncoder<CloseListingInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: CLOSE_LISTING_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCloseListingInstructionDataDecoder(): FixedSizeDecoder<CloseListingInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCloseListingInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
CloseListingInstructionDataArgs,
|
||||||
|
CloseListingInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getCloseListingInstructionDataEncoder(),
|
||||||
|
getCloseListingInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CloseListingInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCloseListingInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CloseListingInput<TAccountSeller, TAccountListingAccount>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): CloseListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
],
|
||||||
|
data: getCloseListingInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as CloseListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedCloseListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
listingAccount: TAccountMetas[1];
|
||||||
|
};
|
||||||
|
data: CloseListingInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseCloseListingInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedCloseListingInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 2) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 2,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: { seller: getNextAccount(), listingAccount: getNextAccount() },
|
||||||
|
data: getCloseListingInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const CLOSE_STALE_ORDER_DISCRIMINATOR: ReadonlyUint8Array =
|
||||||
|
new Uint8Array([167, 12, 32, 252, 132, 106, 131, 250]);
|
||||||
|
|
||||||
|
export function getCloseStaleOrderDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
CLOSE_STALE_ORDER_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CloseStaleOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountCaller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountOrderAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountCaller extends string
|
||||||
|
? WritableSignerAccount<TAccountCaller> &
|
||||||
|
AccountSignerMeta<TAccountCaller>
|
||||||
|
: TAccountCaller,
|
||||||
|
TAccountOrderAccount extends string
|
||||||
|
? WritableAccount<TAccountOrderAccount>
|
||||||
|
: TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? ReadonlyAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type CloseStaleOrderInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CloseStaleOrderInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getCloseStaleOrderInstructionDataEncoder(): FixedSizeEncoder<CloseStaleOrderInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: CLOSE_STALE_ORDER_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCloseStaleOrderInstructionDataDecoder(): FixedSizeDecoder<CloseStaleOrderInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCloseStaleOrderInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
CloseStaleOrderInstructionDataArgs,
|
||||||
|
CloseStaleOrderInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getCloseStaleOrderInstructionDataEncoder(),
|
||||||
|
getCloseStaleOrderInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CloseStaleOrderInput<
|
||||||
|
TAccountCaller extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
> = {
|
||||||
|
caller: TransactionSigner<TAccountCaller>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCloseStaleOrderInstruction<
|
||||||
|
TAccountCaller extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CloseStaleOrderInput<
|
||||||
|
TAccountCaller,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): CloseStaleOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountCaller,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
caller: { value: input.caller ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("caller", accounts.caller),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
],
|
||||||
|
data: getCloseStaleOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as CloseStaleOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountCaller,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedCloseStaleOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
caller: TAccountMetas[0];
|
||||||
|
orderAccount: TAccountMetas[1];
|
||||||
|
escrowAccount: TAccountMetas[2];
|
||||||
|
};
|
||||||
|
data: CloseStaleOrderInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseCloseStaleOrderInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedCloseStaleOrderInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 3) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 3,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
caller: getNextAccount(),
|
||||||
|
orderAccount: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getCloseStaleOrderInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,390 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
addDecoderSizePrefix,
|
||||||
|
addEncoderSizePrefix,
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getArrayDecoder,
|
||||||
|
getArrayEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getOptionDecoder,
|
||||||
|
getOptionEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU32Decoder,
|
||||||
|
getU32Encoder,
|
||||||
|
getU64Decoder,
|
||||||
|
getU64Encoder,
|
||||||
|
getUtf8Decoder,
|
||||||
|
getUtf8Encoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type Encoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type Option,
|
||||||
|
type OptionOrNullable,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
getAddressFromResolvedInstructionAccount,
|
||||||
|
getNonNullResolvedInstructionInput,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { findListingAccountPda } from "../pdas";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
import {
|
||||||
|
getSolistingStateAltCurrencyConfigDecoder,
|
||||||
|
getSolistingStateAltCurrencyConfigEncoder,
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateAltCurrencyConfig,
|
||||||
|
type SolistingStateAltCurrencyConfigArgs,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const CREATE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
18, 168, 45, 24, 191, 31, 117, 54,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getCreateListingDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
CREATE_LISTING_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
|
"11111111111111111111111111111111",
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? WritableSignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type CreateListingInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
listingId: bigint;
|
||||||
|
canonicalCurrency: SolistingStateCurrency;
|
||||||
|
price: bigint;
|
||||||
|
canonicalOracle: Option<Address>;
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfig>;
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
quantity: number;
|
||||||
|
metadataUri: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CreateListingInstructionDataArgs = {
|
||||||
|
listingId: number | bigint;
|
||||||
|
canonicalCurrency: SolistingStateCurrencyArgs;
|
||||||
|
price: number | bigint;
|
||||||
|
canonicalOracle: OptionOrNullable<Address>;
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfigArgs>;
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
quantity: number;
|
||||||
|
metadataUri: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCreateListingInstructionDataEncoder(): Encoder<CreateListingInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["listingId", getU64Encoder()],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["price", getU64Encoder()],
|
||||||
|
["canonicalOracle", getOptionEncoder(getAddressEncoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayEncoder(getAddressEncoder())],
|
||||||
|
["quantity", getU32Encoder()],
|
||||||
|
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
|
]),
|
||||||
|
(value) => ({ ...value, discriminator: CREATE_LISTING_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCreateListingInstructionDataDecoder(): Decoder<CreateListingInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["listingId", getU64Decoder()],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["price", getU64Decoder()],
|
||||||
|
["canonicalOracle", getOptionDecoder(getAddressDecoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayDecoder(getAddressDecoder())],
|
||||||
|
["quantity", getU32Decoder()],
|
||||||
|
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCreateListingInstructionDataCodec(): Codec<
|
||||||
|
CreateListingInstructionDataArgs,
|
||||||
|
CreateListingInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getCreateListingInstructionDataEncoder(),
|
||||||
|
getCreateListingInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateListingAsyncInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
listingAccount?: Address<TAccountListingAccount>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
listingId: CreateListingInstructionDataArgs["listingId"];
|
||||||
|
canonicalCurrency: CreateListingInstructionDataArgs["canonicalCurrency"];
|
||||||
|
price: CreateListingInstructionDataArgs["price"];
|
||||||
|
canonicalOracle: CreateListingInstructionDataArgs["canonicalOracle"];
|
||||||
|
altCurrencies: CreateListingInstructionDataArgs["altCurrencies"];
|
||||||
|
acceptedResolvers: CreateListingInstructionDataArgs["acceptedResolvers"];
|
||||||
|
quantity: CreateListingInstructionDataArgs["quantity"];
|
||||||
|
metadataUri: CreateListingInstructionDataArgs["metadataUri"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getCreateListingInstructionAsync<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CreateListingAsyncInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
CreateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Original args.
|
||||||
|
const args = { ...input };
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.listingAccount.value) {
|
||||||
|
accounts.listingAccount.value = await findListingAccountPda({
|
||||||
|
seller: getAddressFromResolvedInstructionAccount(
|
||||||
|
"seller",
|
||||||
|
accounts.seller.value,
|
||||||
|
),
|
||||||
|
listingId: getNonNullResolvedInstructionInput(
|
||||||
|
"listingId",
|
||||||
|
args.listingId,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCreateListingInstructionDataEncoder().encode(
|
||||||
|
args as CreateListingInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as CreateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateListingInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
listingId: CreateListingInstructionDataArgs["listingId"];
|
||||||
|
canonicalCurrency: CreateListingInstructionDataArgs["canonicalCurrency"];
|
||||||
|
price: CreateListingInstructionDataArgs["price"];
|
||||||
|
canonicalOracle: CreateListingInstructionDataArgs["canonicalOracle"];
|
||||||
|
altCurrencies: CreateListingInstructionDataArgs["altCurrencies"];
|
||||||
|
acceptedResolvers: CreateListingInstructionDataArgs["acceptedResolvers"];
|
||||||
|
quantity: CreateListingInstructionDataArgs["quantity"];
|
||||||
|
metadataUri: CreateListingInstructionDataArgs["metadataUri"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCreateListingInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CreateListingInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): CreateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Original args.
|
||||||
|
const args = { ...input };
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCreateListingInstructionDataEncoder().encode(
|
||||||
|
args as CreateListingInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as CreateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedCreateListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
listingAccount: TAccountMetas[1];
|
||||||
|
systemProgram: TAccountMetas[2];
|
||||||
|
};
|
||||||
|
data: CreateListingInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseCreateListingInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedCreateListingInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 3) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 3,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
seller: getNextAccount(),
|
||||||
|
listingAccount: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getCreateListingInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,559 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getProgramDerivedAddress,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU16Decoder,
|
||||||
|
getU16Encoder,
|
||||||
|
getU64Decoder,
|
||||||
|
getU64Encoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type Encoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
getAddressFromResolvedInstructionAccount,
|
||||||
|
getNonNullResolvedInstructionInput,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { findOrderAccountPda } from "../pdas";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
import {
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const CREATE_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
141, 54, 37, 207, 237, 210, 250, 215,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getCreateOrderDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
CREATE_ORDER_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountOrderAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountDescroVault extends string | AccountMeta<string> = string,
|
||||||
|
TAccountCanonicalOracle extends string | AccountMeta<string> = string,
|
||||||
|
TAccountTargetOracle extends string | AccountMeta<string> = string,
|
||||||
|
TAccountDescroProgram extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
|
"11111111111111111111111111111111",
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountBuyer extends string
|
||||||
|
? WritableSignerAccount<TAccountBuyer> &
|
||||||
|
AccountSignerMeta<TAccountBuyer>
|
||||||
|
: TAccountBuyer,
|
||||||
|
TAccountSeller extends string
|
||||||
|
? ReadonlyAccount<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
TAccountOrderAccount extends string
|
||||||
|
? WritableAccount<TAccountOrderAccount>
|
||||||
|
: TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault extends string
|
||||||
|
? WritableAccount<TAccountDescroVault>
|
||||||
|
: TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle extends string
|
||||||
|
? ReadonlyAccount<TAccountCanonicalOracle>
|
||||||
|
: TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle extends string
|
||||||
|
? ReadonlyAccount<TAccountTargetOracle>
|
||||||
|
: TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountDescroProgram>
|
||||||
|
: TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type CreateOrderInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
orderId: bigint;
|
||||||
|
escrowId: bigint;
|
||||||
|
resolver: Address;
|
||||||
|
paymentCurrency: SolistingStateCurrency;
|
||||||
|
expectedAmount: bigint;
|
||||||
|
maxSlippageBps: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CreateOrderInstructionDataArgs = {
|
||||||
|
orderId: number | bigint;
|
||||||
|
escrowId: number | bigint;
|
||||||
|
resolver: Address;
|
||||||
|
paymentCurrency: SolistingStateCurrencyArgs;
|
||||||
|
expectedAmount: number | bigint;
|
||||||
|
maxSlippageBps: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCreateOrderInstructionDataEncoder(): Encoder<CreateOrderInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["orderId", getU64Encoder()],
|
||||||
|
["escrowId", getU64Encoder()],
|
||||||
|
["resolver", getAddressEncoder()],
|
||||||
|
["paymentCurrency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["expectedAmount", getU64Encoder()],
|
||||||
|
["maxSlippageBps", getU16Encoder()],
|
||||||
|
]),
|
||||||
|
(value) => ({ ...value, discriminator: CREATE_ORDER_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCreateOrderInstructionDataDecoder(): Decoder<CreateOrderInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["orderId", getU64Decoder()],
|
||||||
|
["escrowId", getU64Decoder()],
|
||||||
|
["resolver", getAddressDecoder()],
|
||||||
|
["paymentCurrency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["expectedAmount", getU64Decoder()],
|
||||||
|
["maxSlippageBps", getU16Decoder()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCreateOrderInstructionDataCodec(): Codec<
|
||||||
|
CreateOrderInstructionDataArgs,
|
||||||
|
CreateOrderInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getCreateOrderInstructionDataEncoder(),
|
||||||
|
getCreateOrderInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateOrderAsyncInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountDescroVault extends string = string,
|
||||||
|
TAccountCanonicalOracle extends string = string,
|
||||||
|
TAccountTargetOracle extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
seller: Address<TAccountSeller>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount?: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount?: Address<TAccountEscrowAccount>;
|
||||||
|
descroVault?: Address<TAccountDescroVault>;
|
||||||
|
/** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */
|
||||||
|
canonicalOracle: Address<TAccountCanonicalOracle>;
|
||||||
|
/** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */
|
||||||
|
targetOracle: Address<TAccountTargetOracle>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
orderId: CreateOrderInstructionDataArgs["orderId"];
|
||||||
|
escrowId: CreateOrderInstructionDataArgs["escrowId"];
|
||||||
|
resolver: CreateOrderInstructionDataArgs["resolver"];
|
||||||
|
paymentCurrency: CreateOrderInstructionDataArgs["paymentCurrency"];
|
||||||
|
expectedAmount: CreateOrderInstructionDataArgs["expectedAmount"];
|
||||||
|
maxSlippageBps: CreateOrderInstructionDataArgs["maxSlippageBps"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getCreateOrderInstructionAsync<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountDescroVault extends string,
|
||||||
|
TAccountCanonicalOracle extends string,
|
||||||
|
TAccountTargetOracle extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CreateOrderAsyncInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
CreateOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
seller: { value: input.seller ?? null, isWritable: false },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
descroVault: { value: input.descroVault ?? null, isWritable: true },
|
||||||
|
canonicalOracle: {
|
||||||
|
value: input.canonicalOracle ?? null,
|
||||||
|
isWritable: false,
|
||||||
|
},
|
||||||
|
targetOracle: { value: input.targetOracle ?? null, isWritable: false },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Original args.
|
||||||
|
const args = { ...input };
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.orderAccount.value) {
|
||||||
|
accounts.orderAccount.value = await findOrderAccountPda({
|
||||||
|
listingAccount: getAddressFromResolvedInstructionAccount(
|
||||||
|
"listingAccount",
|
||||||
|
accounts.listingAccount.value,
|
||||||
|
),
|
||||||
|
buyer: getAddressFromResolvedInstructionAccount(
|
||||||
|
"buyer",
|
||||||
|
accounts.buyer.value,
|
||||||
|
),
|
||||||
|
orderId: getNonNullResolvedInstructionInput("orderId", args.orderId),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.escrowAccount.value) {
|
||||||
|
accounts.escrowAccount.value = await getProgramDerivedAddress({
|
||||||
|
programAddress:
|
||||||
|
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(new Uint8Array([101, 115, 99, 114, 111, 119])),
|
||||||
|
getAddressEncoder().encode(
|
||||||
|
getAddressFromResolvedInstructionAccount(
|
||||||
|
"seller",
|
||||||
|
accounts.seller.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
getU64Encoder().encode(
|
||||||
|
getNonNullResolvedInstructionInput("escrowId", args.escrowId),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.descroVault.value) {
|
||||||
|
accounts.descroVault.value = await getProgramDerivedAddress({
|
||||||
|
programAddress:
|
||||||
|
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
|
||||||
|
getAddressEncoder().encode(
|
||||||
|
getAddressFromResolvedInstructionAccount(
|
||||||
|
"escrowAccount",
|
||||||
|
accounts.escrowAccount.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("descroVault", accounts.descroVault),
|
||||||
|
getAccountMeta("canonicalOracle", accounts.canonicalOracle),
|
||||||
|
getAccountMeta("targetOracle", accounts.targetOracle),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCreateOrderInstructionDataEncoder().encode(
|
||||||
|
args as CreateOrderInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as CreateOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateOrderInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountDescroVault extends string = string,
|
||||||
|
TAccountCanonicalOracle extends string = string,
|
||||||
|
TAccountTargetOracle extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
seller: Address<TAccountSeller>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
descroVault: Address<TAccountDescroVault>;
|
||||||
|
/** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */
|
||||||
|
canonicalOracle: Address<TAccountCanonicalOracle>;
|
||||||
|
/** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */
|
||||||
|
targetOracle: Address<TAccountTargetOracle>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
orderId: CreateOrderInstructionDataArgs["orderId"];
|
||||||
|
escrowId: CreateOrderInstructionDataArgs["escrowId"];
|
||||||
|
resolver: CreateOrderInstructionDataArgs["resolver"];
|
||||||
|
paymentCurrency: CreateOrderInstructionDataArgs["paymentCurrency"];
|
||||||
|
expectedAmount: CreateOrderInstructionDataArgs["expectedAmount"];
|
||||||
|
maxSlippageBps: CreateOrderInstructionDataArgs["maxSlippageBps"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getCreateOrderInstruction<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountDescroVault extends string,
|
||||||
|
TAccountCanonicalOracle extends string,
|
||||||
|
TAccountTargetOracle extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CreateOrderInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): CreateOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
seller: { value: input.seller ?? null, isWritable: false },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
descroVault: { value: input.descroVault ?? null, isWritable: true },
|
||||||
|
canonicalOracle: {
|
||||||
|
value: input.canonicalOracle ?? null,
|
||||||
|
isWritable: false,
|
||||||
|
},
|
||||||
|
targetOracle: { value: input.targetOracle ?? null, isWritable: false },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Original args.
|
||||||
|
const args = { ...input };
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("descroVault", accounts.descroVault),
|
||||||
|
getAccountMeta("canonicalOracle", accounts.canonicalOracle),
|
||||||
|
getAccountMeta("targetOracle", accounts.targetOracle),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCreateOrderInstructionDataEncoder().encode(
|
||||||
|
args as CreateOrderInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as CreateOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountDescroVault,
|
||||||
|
TAccountCanonicalOracle,
|
||||||
|
TAccountTargetOracle,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedCreateOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
buyer: TAccountMetas[0];
|
||||||
|
seller: TAccountMetas[1];
|
||||||
|
listingAccount: TAccountMetas[2];
|
||||||
|
orderAccount: TAccountMetas[3];
|
||||||
|
escrowAccount: TAccountMetas[4];
|
||||||
|
descroVault: TAccountMetas[5];
|
||||||
|
/** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */
|
||||||
|
canonicalOracle: TAccountMetas[6];
|
||||||
|
/** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */
|
||||||
|
targetOracle: TAccountMetas[7];
|
||||||
|
descroProgram: TAccountMetas[8];
|
||||||
|
systemProgram: TAccountMetas[9];
|
||||||
|
};
|
||||||
|
data: CreateOrderInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseCreateOrderInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedCreateOrderInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 10) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 10,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
buyer: getNextAccount(),
|
||||||
|
seller: getNextAccount(),
|
||||||
|
listingAccount: getNextAccount(),
|
||||||
|
orderAccount: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
descroVault: getNextAccount(),
|
||||||
|
canonicalOracle: getNextAccount(),
|
||||||
|
targetOracle: getNextAccount(),
|
||||||
|
descroProgram: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getCreateOrderInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./acceptOrder";
|
||||||
|
export * from "./cancelOrder";
|
||||||
|
export * from "./closeListing";
|
||||||
|
export * from "./closeStaleOrder";
|
||||||
|
export * from "./createListing";
|
||||||
|
export * from "./createOrder";
|
||||||
|
export * from "./initialize";
|
||||||
|
export * from "./rejectOrder";
|
||||||
|
export * from "./updateListing";
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const INITIALIZE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
175, 175, 109, 31, 13, 152, 155, 237,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getInitializeDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_DISCRIMINATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InitializeInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<TRemainingAccounts>;
|
||||||
|
|
||||||
|
export type InitializeInstructionData = { discriminator: ReadonlyUint8Array };
|
||||||
|
|
||||||
|
export type InitializeInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getInitializeInstructionDataEncoder(): FixedSizeEncoder<InitializeInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInitializeInstructionDataDecoder(): FixedSizeDecoder<InitializeInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInitializeInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
InitializeInstructionDataArgs,
|
||||||
|
InitializeInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getInitializeInstructionDataEncoder(),
|
||||||
|
getInitializeInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InitializeInput = {};
|
||||||
|
|
||||||
|
export function getInitializeInstruction<
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(config?: {
|
||||||
|
programAddress?: TProgramAddress;
|
||||||
|
}): InitializeInstruction<TProgramAddress> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
return Object.freeze({
|
||||||
|
data: getInitializeInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as InitializeInstruction<TProgramAddress>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedInitializeInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
> = { programAddress: Address<TProgram>; data: InitializeInstructionData };
|
||||||
|
|
||||||
|
export function parseInitializeInstruction<TProgram extends string>(
|
||||||
|
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedInitializeInstruction<TProgram> {
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
data: getInitializeInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getProgramDerivedAddress,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type FixedSizeCodec,
|
||||||
|
type FixedSizeDecoder,
|
||||||
|
type FixedSizeEncoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
type WritableSignerAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
getAddressFromResolvedInstructionAccount,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const REJECT_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
216, 154, 15, 81, 179, 14, 75, 62,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getRejectOrderDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
REJECT_ORDER_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RejectOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountOrderAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountVault extends string | AccountMeta<string> = string,
|
||||||
|
TAccountDescroProgram extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
|
"11111111111111111111111111111111",
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? WritableSignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountBuyer extends string
|
||||||
|
? WritableAccount<TAccountBuyer>
|
||||||
|
: TAccountBuyer,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
TAccountOrderAccount extends string
|
||||||
|
? WritableAccount<TAccountOrderAccount>
|
||||||
|
: TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountVault extends string
|
||||||
|
? WritableAccount<TAccountVault>
|
||||||
|
: TAccountVault,
|
||||||
|
TAccountDescroProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountDescroProgram>
|
||||||
|
: TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type RejectOrderInstructionData = { discriminator: ReadonlyUint8Array };
|
||||||
|
|
||||||
|
export type RejectOrderInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getRejectOrderInstructionDataEncoder(): FixedSizeEncoder<RejectOrderInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: REJECT_ORDER_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRejectOrderInstructionDataDecoder(): FixedSizeDecoder<RejectOrderInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRejectOrderInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
RejectOrderInstructionDataArgs,
|
||||||
|
RejectOrderInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getRejectOrderInstructionDataEncoder(),
|
||||||
|
getRejectOrderInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RejectOrderAsyncInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
buyer: Address<TAccountBuyer>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault?: Address<TAccountVault>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getRejectOrderInstructionAsync<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: RejectOrderAsyncInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
RejectOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.vault.value) {
|
||||||
|
accounts.vault.value = await getProgramDerivedAddress({
|
||||||
|
programAddress:
|
||||||
|
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
|
||||||
|
getAddressEncoder().encode(
|
||||||
|
getAddressFromResolvedInstructionAccount(
|
||||||
|
"escrowAccount",
|
||||||
|
accounts.escrowAccount.value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getRejectOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as RejectOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RejectOrderInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
TAccountOrderAccount extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountDescroProgram extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
buyer: Address<TAccountBuyer>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
orderAccount: Address<TAccountOrderAccount>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault: Address<TAccountVault>;
|
||||||
|
descroProgram: Address<TAccountDescroProgram>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getRejectOrderInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TAccountOrderAccount extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountDescroProgram extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: RejectOrderInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): RejectOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
orderAccount: { value: input.orderAccount ?? null, isWritable: true },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
descroProgram: { value: input.descroProgram ?? null, isWritable: false },
|
||||||
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Resolve default values.
|
||||||
|
if (!accounts.systemProgram.value) {
|
||||||
|
accounts.systemProgram.value =
|
||||||
|
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
getAccountMeta("orderAccount", accounts.orderAccount),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("descroProgram", accounts.descroProgram),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getRejectOrderInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as RejectOrderInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountListingAccount,
|
||||||
|
TAccountOrderAccount,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountDescroProgram,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedRejectOrderInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
buyer: TAccountMetas[1];
|
||||||
|
listingAccount: TAccountMetas[2];
|
||||||
|
orderAccount: TAccountMetas[3];
|
||||||
|
escrowAccount: TAccountMetas[4];
|
||||||
|
vault: TAccountMetas[5];
|
||||||
|
descroProgram: TAccountMetas[6];
|
||||||
|
systemProgram: TAccountMetas[7];
|
||||||
|
};
|
||||||
|
data: RejectOrderInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseRejectOrderInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedRejectOrderInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 8) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 8,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: {
|
||||||
|
seller: getNextAccount(),
|
||||||
|
buyer: getNextAccount(),
|
||||||
|
listingAccount: getNextAccount(),
|
||||||
|
orderAccount: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
vault: getNextAccount(),
|
||||||
|
descroProgram: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getRejectOrderInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
addDecoderSizePrefix,
|
||||||
|
addEncoderSizePrefix,
|
||||||
|
combineCodec,
|
||||||
|
fixDecoderSize,
|
||||||
|
fixEncoderSize,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getArrayDecoder,
|
||||||
|
getArrayEncoder,
|
||||||
|
getBytesDecoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getOptionDecoder,
|
||||||
|
getOptionEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU32Decoder,
|
||||||
|
getU32Encoder,
|
||||||
|
getU64Decoder,
|
||||||
|
getU64Encoder,
|
||||||
|
getUtf8Decoder,
|
||||||
|
getUtf8Encoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
SolanaError,
|
||||||
|
transformEncoder,
|
||||||
|
type AccountMeta,
|
||||||
|
type AccountSignerMeta,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type Encoder,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithAccounts,
|
||||||
|
type InstructionWithData,
|
||||||
|
type Option,
|
||||||
|
type OptionOrNullable,
|
||||||
|
type ReadonlySignerAccount,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
type TransactionSigner,
|
||||||
|
type WritableAccount,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getAccountMetaFactory,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { SOLISTING_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
import {
|
||||||
|
getSolistingStateAltCurrencyConfigDecoder,
|
||||||
|
getSolistingStateAltCurrencyConfigEncoder,
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateAltCurrencyConfig,
|
||||||
|
type SolistingStateAltCurrencyConfigArgs,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const UPDATE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
192, 174, 210, 68, 116, 40, 242, 253,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getUpdateListingDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
UPDATE_LISTING_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountListingAccount extends string | AccountMeta<string> = string,
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? ReadonlySignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountListingAccount extends string
|
||||||
|
? WritableAccount<TAccountListingAccount>
|
||||||
|
: TAccountListingAccount,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type UpdateListingInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
canonicalCurrency: SolistingStateCurrency;
|
||||||
|
price: bigint;
|
||||||
|
canonicalOracle: Option<Address>;
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfig>;
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
quantity: number;
|
||||||
|
metadataUri: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UpdateListingInstructionDataArgs = {
|
||||||
|
canonicalCurrency: SolistingStateCurrencyArgs;
|
||||||
|
price: number | bigint;
|
||||||
|
canonicalOracle: OptionOrNullable<Address>;
|
||||||
|
altCurrencies: Array<SolistingStateAltCurrencyConfigArgs>;
|
||||||
|
acceptedResolvers: Array<Address>;
|
||||||
|
quantity: number;
|
||||||
|
metadataUri: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getUpdateListingInstructionDataEncoder(): Encoder<UpdateListingInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["price", getU64Encoder()],
|
||||||
|
["canonicalOracle", getOptionEncoder(getAddressEncoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayEncoder(getAddressEncoder())],
|
||||||
|
["quantity", getU32Encoder()],
|
||||||
|
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
|
]),
|
||||||
|
(value) => ({ ...value, discriminator: UPDATE_LISTING_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUpdateListingInstructionDataDecoder(): Decoder<UpdateListingInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["canonicalCurrency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["price", getU64Decoder()],
|
||||||
|
["canonicalOracle", getOptionDecoder(getAddressDecoder())],
|
||||||
|
[
|
||||||
|
"altCurrencies",
|
||||||
|
getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()),
|
||||||
|
],
|
||||||
|
["acceptedResolvers", getArrayDecoder(getAddressDecoder())],
|
||||||
|
["quantity", getU32Decoder()],
|
||||||
|
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUpdateListingInstructionDataCodec(): Codec<
|
||||||
|
UpdateListingInstructionDataArgs,
|
||||||
|
UpdateListingInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getUpdateListingInstructionDataEncoder(),
|
||||||
|
getUpdateListingInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateListingInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountListingAccount extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
listingAccount: Address<TAccountListingAccount>;
|
||||||
|
canonicalCurrency: UpdateListingInstructionDataArgs["canonicalCurrency"];
|
||||||
|
price: UpdateListingInstructionDataArgs["price"];
|
||||||
|
canonicalOracle: UpdateListingInstructionDataArgs["canonicalOracle"];
|
||||||
|
altCurrencies: UpdateListingInstructionDataArgs["altCurrencies"];
|
||||||
|
acceptedResolvers: UpdateListingInstructionDataArgs["acceptedResolvers"];
|
||||||
|
quantity: UpdateListingInstructionDataArgs["quantity"];
|
||||||
|
metadataUri: UpdateListingInstructionDataArgs["metadataUri"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getUpdateListingInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountListingAccount extends string,
|
||||||
|
TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: UpdateListingInput<TAccountSeller, TAccountListingAccount>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): UpdateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: false },
|
||||||
|
listingAccount: { value: input.listingAccount ?? null, isWritable: true },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
// Original args.
|
||||||
|
const args = { ...input };
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("listingAccount", accounts.listingAccount),
|
||||||
|
],
|
||||||
|
data: getUpdateListingInstructionDataEncoder().encode(
|
||||||
|
args as UpdateListingInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as UpdateListingInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountListingAccount
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedUpdateListingInstruction<
|
||||||
|
TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
listingAccount: TAccountMetas[1];
|
||||||
|
};
|
||||||
|
data: UpdateListingInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseUpdateListingInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedUpdateListingInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 2) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 2,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let accountIndex = 0;
|
||||||
|
const getNextAccount = () => {
|
||||||
|
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
||||||
|
accountIndex += 1;
|
||||||
|
return accountMeta;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
programAddress: instruction.programAddress,
|
||||||
|
accounts: { seller: getNextAccount(), listingAccount: getNextAccount() },
|
||||||
|
data: getUpdateListingInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
10
sdk/src/generated/solisting/src/generated/pdas/index.ts
Normal file
10
sdk/src/generated/solisting/src/generated/pdas/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./listingAccount";
|
||||||
|
export * from "./orderAccount";
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getProgramDerivedAddress,
|
||||||
|
getU64Encoder,
|
||||||
|
type Address,
|
||||||
|
type ProgramDerivedAddress,
|
||||||
|
} from "@solana/kit";
|
||||||
|
|
||||||
|
export type ListingAccountSeeds = {
|
||||||
|
seller: Address;
|
||||||
|
listingId: number | bigint;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function findListingAccountPda(
|
||||||
|
seeds: ListingAccountSeeds,
|
||||||
|
config: { programAddress?: Address | undefined } = {},
|
||||||
|
): Promise<ProgramDerivedAddress> {
|
||||||
|
const { programAddress = "" as Address<""> } = config;
|
||||||
|
return await getProgramDerivedAddress({
|
||||||
|
programAddress,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(
|
||||||
|
new Uint8Array([108, 105, 115, 116, 105, 110, 103]),
|
||||||
|
),
|
||||||
|
getAddressEncoder().encode(seeds.seller),
|
||||||
|
getU64Encoder().encode(seeds.listingId),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
getAddressEncoder,
|
||||||
|
getBytesEncoder,
|
||||||
|
getProgramDerivedAddress,
|
||||||
|
getU64Encoder,
|
||||||
|
type Address,
|
||||||
|
type ProgramDerivedAddress,
|
||||||
|
} from "@solana/kit";
|
||||||
|
|
||||||
|
export type OrderAccountSeeds = {
|
||||||
|
listingAccount: Address;
|
||||||
|
buyer: Address;
|
||||||
|
orderId: number | bigint;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function findOrderAccountPda(
|
||||||
|
seeds: OrderAccountSeeds,
|
||||||
|
config: { programAddress?: Address | undefined } = {},
|
||||||
|
): Promise<ProgramDerivedAddress> {
|
||||||
|
const { programAddress = "" as Address<""> } = config;
|
||||||
|
return await getProgramDerivedAddress({
|
||||||
|
programAddress,
|
||||||
|
seeds: [
|
||||||
|
getBytesEncoder().encode(new Uint8Array([111, 114, 100, 101, 114])),
|
||||||
|
getAddressEncoder().encode(seeds.listingAccount),
|
||||||
|
getAddressEncoder().encode(seeds.buyer),
|
||||||
|
getU64Encoder().encode(seeds.orderId),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./solisting";
|
||||||
497
sdk/src/generated/solisting/src/generated/programs/solisting.ts
Normal file
497
sdk/src/generated/solisting/src/generated/programs/solisting.ts
Normal file
@@ -0,0 +1,497 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
assertIsInstructionWithAccounts,
|
||||||
|
containsBytes,
|
||||||
|
extendClient,
|
||||||
|
fixEncoderSize,
|
||||||
|
getBytesEncoder,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
|
||||||
|
SolanaError,
|
||||||
|
type Address,
|
||||||
|
type ClientWithRpc,
|
||||||
|
type ClientWithTransactionPlanning,
|
||||||
|
type ClientWithTransactionSending,
|
||||||
|
type ExtendedClient,
|
||||||
|
type GetAccountInfoApi,
|
||||||
|
type GetMultipleAccountsApi,
|
||||||
|
type Instruction,
|
||||||
|
type InstructionWithData,
|
||||||
|
type ReadonlyUint8Array,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
addSelfFetchFunctions,
|
||||||
|
addSelfPlanAndSendFunctions,
|
||||||
|
type SelfFetchFunctions,
|
||||||
|
type SelfPlanAndSendFunctions,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import {
|
||||||
|
getSolistingStateListingAccountCodec,
|
||||||
|
getSolistingStateOrderAccountCodec,
|
||||||
|
type SolistingStateListingAccount,
|
||||||
|
type SolistingStateListingAccountArgs,
|
||||||
|
type SolistingStateOrderAccount,
|
||||||
|
type SolistingStateOrderAccountArgs,
|
||||||
|
} from "../accounts";
|
||||||
|
import {
|
||||||
|
getAcceptOrderInstruction,
|
||||||
|
getCancelOrderInstructionAsync,
|
||||||
|
getCloseListingInstruction,
|
||||||
|
getCloseStaleOrderInstruction,
|
||||||
|
getCreateListingInstructionAsync,
|
||||||
|
getCreateOrderInstructionAsync,
|
||||||
|
getInitializeInstruction,
|
||||||
|
getRejectOrderInstructionAsync,
|
||||||
|
getUpdateListingInstruction,
|
||||||
|
parseAcceptOrderInstruction,
|
||||||
|
parseCancelOrderInstruction,
|
||||||
|
parseCloseListingInstruction,
|
||||||
|
parseCloseStaleOrderInstruction,
|
||||||
|
parseCreateListingInstruction,
|
||||||
|
parseCreateOrderInstruction,
|
||||||
|
parseInitializeInstruction,
|
||||||
|
parseRejectOrderInstruction,
|
||||||
|
parseUpdateListingInstruction,
|
||||||
|
type AcceptOrderInput,
|
||||||
|
type CancelOrderAsyncInput,
|
||||||
|
type CloseListingInput,
|
||||||
|
type CloseStaleOrderInput,
|
||||||
|
type CreateListingAsyncInput,
|
||||||
|
type CreateOrderAsyncInput,
|
||||||
|
type InitializeInput,
|
||||||
|
type ParsedAcceptOrderInstruction,
|
||||||
|
type ParsedCancelOrderInstruction,
|
||||||
|
type ParsedCloseListingInstruction,
|
||||||
|
type ParsedCloseStaleOrderInstruction,
|
||||||
|
type ParsedCreateListingInstruction,
|
||||||
|
type ParsedCreateOrderInstruction,
|
||||||
|
type ParsedInitializeInstruction,
|
||||||
|
type ParsedRejectOrderInstruction,
|
||||||
|
type ParsedUpdateListingInstruction,
|
||||||
|
type RejectOrderAsyncInput,
|
||||||
|
type UpdateListingInput,
|
||||||
|
} from "../instructions";
|
||||||
|
import { findListingAccountPda, findOrderAccountPda } from "../pdas";
|
||||||
|
|
||||||
|
export const SOLISTING_PROGRAM_ADDRESS = "" as Address<"">;
|
||||||
|
|
||||||
|
export enum SolistingAccount {
|
||||||
|
SolistingStateListingAccount,
|
||||||
|
SolistingStateOrderAccount,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function identifySolistingAccount(
|
||||||
|
account: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
|
||||||
|
): SolistingAccount {
|
||||||
|
const data = "data" in account ? account.data : account;
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([59, 89, 136, 25, 21, 196, 183, 13]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingAccount.SolistingStateListingAccount;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([79, 67, 112, 155, 214, 14, 32, 55]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingAccount.SolistingStateOrderAccount;
|
||||||
|
}
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT,
|
||||||
|
{ accountData: data, programName: "solisting" },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum SolistingInstruction {
|
||||||
|
Initialize,
|
||||||
|
CreateListing,
|
||||||
|
UpdateListing,
|
||||||
|
CloseListing,
|
||||||
|
CreateOrder,
|
||||||
|
AcceptOrder,
|
||||||
|
RejectOrder,
|
||||||
|
CancelOrder,
|
||||||
|
CloseStaleOrder,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function identifySolistingInstruction(
|
||||||
|
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
|
||||||
|
): SolistingInstruction {
|
||||||
|
const data = "data" in instruction ? instruction.data : instruction;
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([175, 175, 109, 31, 13, 152, 155, 237]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.Initialize;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([18, 168, 45, 24, 191, 31, 117, 54]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.CreateListing;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([192, 174, 210, 68, 116, 40, 242, 253]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.UpdateListing;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([33, 15, 192, 81, 78, 175, 159, 97]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.CloseListing;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([141, 54, 37, 207, 237, 210, 250, 215]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.CreateOrder;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([118, 157, 62, 39, 239, 234, 231, 193]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.AcceptOrder;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([216, 154, 15, 81, 179, 14, 75, 62]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.RejectOrder;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([95, 129, 237, 240, 8, 49, 223, 132]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.CancelOrder;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([167, 12, 32, 252, 132, 106, 131, 250]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return SolistingInstruction.CloseStaleOrder;
|
||||||
|
}
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
|
||||||
|
{ instructionData: data, programName: "solisting" },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedSolistingInstruction<TProgram extends string = ""> =
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.Initialize;
|
||||||
|
} & ParsedInitializeInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.CreateListing;
|
||||||
|
} & ParsedCreateListingInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.UpdateListing;
|
||||||
|
} & ParsedUpdateListingInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.CloseListing;
|
||||||
|
} & ParsedCloseListingInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.CreateOrder;
|
||||||
|
} & ParsedCreateOrderInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.AcceptOrder;
|
||||||
|
} & ParsedAcceptOrderInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.RejectOrder;
|
||||||
|
} & ParsedRejectOrderInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.CancelOrder;
|
||||||
|
} & ParsedCancelOrderInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: SolistingInstruction.CloseStaleOrder;
|
||||||
|
} & ParsedCloseStaleOrderInstruction<TProgram>);
|
||||||
|
|
||||||
|
export function parseSolistingInstruction<TProgram extends string>(
|
||||||
|
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedSolistingInstruction<TProgram> {
|
||||||
|
const instructionType = identifySolistingInstruction(instruction);
|
||||||
|
switch (instructionType) {
|
||||||
|
case SolistingInstruction.Initialize: {
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.Initialize,
|
||||||
|
...parseInitializeInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.CreateListing: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.CreateListing,
|
||||||
|
...parseCreateListingInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.UpdateListing: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.UpdateListing,
|
||||||
|
...parseUpdateListingInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.CloseListing: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.CloseListing,
|
||||||
|
...parseCloseListingInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.CreateOrder: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.CreateOrder,
|
||||||
|
...parseCreateOrderInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.AcceptOrder: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.AcceptOrder,
|
||||||
|
...parseAcceptOrderInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.RejectOrder: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.RejectOrder,
|
||||||
|
...parseRejectOrderInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.CancelOrder: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.CancelOrder,
|
||||||
|
...parseCancelOrderInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case SolistingInstruction.CloseStaleOrder: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: SolistingInstruction.CloseStaleOrder,
|
||||||
|
...parseCloseStaleOrderInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
|
||||||
|
{
|
||||||
|
instructionType: instructionType as string,
|
||||||
|
programName: "solisting",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SolistingPlugin = {
|
||||||
|
accounts: SolistingPluginAccounts;
|
||||||
|
instructions: SolistingPluginInstructions;
|
||||||
|
pdas: SolistingPluginPdas;
|
||||||
|
identifyAccount: typeof identifySolistingAccount;
|
||||||
|
identifyInstruction: typeof identifySolistingInstruction;
|
||||||
|
parseInstruction: typeof parseSolistingInstruction;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingPluginAccounts = {
|
||||||
|
solistingStateListingAccount: ReturnType<
|
||||||
|
typeof getSolistingStateListingAccountCodec
|
||||||
|
> &
|
||||||
|
SelfFetchFunctions<
|
||||||
|
SolistingStateListingAccountArgs,
|
||||||
|
SolistingStateListingAccount
|
||||||
|
>;
|
||||||
|
solistingStateOrderAccount: ReturnType<
|
||||||
|
typeof getSolistingStateOrderAccountCodec
|
||||||
|
> &
|
||||||
|
SelfFetchFunctions<
|
||||||
|
SolistingStateOrderAccountArgs,
|
||||||
|
SolistingStateOrderAccount
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingPluginInstructions = {
|
||||||
|
initialize: (
|
||||||
|
input: InitializeInput,
|
||||||
|
) => ReturnType<typeof getInitializeInstruction> & SelfPlanAndSendFunctions;
|
||||||
|
createListing: (
|
||||||
|
input: CreateListingAsyncInput,
|
||||||
|
) => ReturnType<typeof getCreateListingInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
updateListing: (
|
||||||
|
input: UpdateListingInput,
|
||||||
|
) => ReturnType<typeof getUpdateListingInstruction> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
closeListing: (
|
||||||
|
input: CloseListingInput,
|
||||||
|
) => ReturnType<typeof getCloseListingInstruction> & SelfPlanAndSendFunctions;
|
||||||
|
createOrder: (
|
||||||
|
input: CreateOrderAsyncInput,
|
||||||
|
) => ReturnType<typeof getCreateOrderInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
acceptOrder: (
|
||||||
|
input: AcceptOrderInput,
|
||||||
|
) => ReturnType<typeof getAcceptOrderInstruction> & SelfPlanAndSendFunctions;
|
||||||
|
rejectOrder: (
|
||||||
|
input: RejectOrderAsyncInput,
|
||||||
|
) => ReturnType<typeof getRejectOrderInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
cancelOrder: (
|
||||||
|
input: CancelOrderAsyncInput,
|
||||||
|
) => ReturnType<typeof getCancelOrderInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
closeStaleOrder: (
|
||||||
|
input: CloseStaleOrderInput,
|
||||||
|
) => ReturnType<typeof getCloseStaleOrderInstruction> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingPluginPdas = {
|
||||||
|
listingAccount: typeof findListingAccountPda;
|
||||||
|
orderAccount: typeof findOrderAccountPda;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingPluginRequirements = ClientWithRpc<
|
||||||
|
GetAccountInfoApi & GetMultipleAccountsApi
|
||||||
|
> &
|
||||||
|
ClientWithTransactionPlanning &
|
||||||
|
ClientWithTransactionSending;
|
||||||
|
|
||||||
|
export function solistingProgram() {
|
||||||
|
return <T extends SolistingPluginRequirements>(
|
||||||
|
client: T,
|
||||||
|
): ExtendedClient<T, { solisting: SolistingPlugin }> => {
|
||||||
|
return extendClient(client, {
|
||||||
|
solisting: <SolistingPlugin>{
|
||||||
|
accounts: {
|
||||||
|
solistingStateListingAccount: addSelfFetchFunctions(
|
||||||
|
client,
|
||||||
|
getSolistingStateListingAccountCodec(),
|
||||||
|
),
|
||||||
|
solistingStateOrderAccount: addSelfFetchFunctions(
|
||||||
|
client,
|
||||||
|
getSolistingStateOrderAccountCodec(),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
instructions: {
|
||||||
|
initialize: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getInitializeInstruction(input),
|
||||||
|
),
|
||||||
|
createListing: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCreateListingInstructionAsync(input),
|
||||||
|
),
|
||||||
|
updateListing: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getUpdateListingInstruction(input),
|
||||||
|
),
|
||||||
|
closeListing: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCloseListingInstruction(input),
|
||||||
|
),
|
||||||
|
createOrder: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCreateOrderInstructionAsync(input),
|
||||||
|
),
|
||||||
|
acceptOrder: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getAcceptOrderInstruction(input),
|
||||||
|
),
|
||||||
|
rejectOrder: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getRejectOrderInstructionAsync(input),
|
||||||
|
),
|
||||||
|
cancelOrder: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCancelOrderInstructionAsync(input),
|
||||||
|
),
|
||||||
|
closeStaleOrder: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCloseStaleOrderInstruction(input),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
pdas: {
|
||||||
|
listingAccount: findListingAccountPda,
|
||||||
|
orderAccount: findOrderAccountPda,
|
||||||
|
},
|
||||||
|
identifyAccount: identifySolistingAccount,
|
||||||
|
identifyInstruction: identifySolistingInstruction,
|
||||||
|
parseInstruction: parseSolistingInstruction,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
10
sdk/src/generated/solisting/src/generated/types/index.ts
Normal file
10
sdk/src/generated/solisting/src/generated/types/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./solistingStateAltCurrencyConfig";
|
||||||
|
export * from "./solistingStateCurrency";
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getOptionDecoder,
|
||||||
|
getOptionEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type Encoder,
|
||||||
|
type Option,
|
||||||
|
type OptionOrNullable,
|
||||||
|
} from "@solana/kit";
|
||||||
|
import {
|
||||||
|
getSolistingStateCurrencyDecoder,
|
||||||
|
getSolistingStateCurrencyEncoder,
|
||||||
|
type SolistingStateCurrency,
|
||||||
|
type SolistingStateCurrencyArgs,
|
||||||
|
} from ".";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-alt-currency oracle configuration. Each alt currency carries its own Pyth feed
|
||||||
|
* because different tokens have different price feeds.
|
||||||
|
*/
|
||||||
|
export type SolistingStateAltCurrencyConfig = {
|
||||||
|
currency: SolistingStateCurrency;
|
||||||
|
/**
|
||||||
|
* Pyth V2 PriceFeedAccount for this token priced in USD (TOKEN/USD).
|
||||||
|
* `None` = treat as a $1.00 USD stablecoin — no oracle account required at order time.
|
||||||
|
*/
|
||||||
|
usdOracle: Option<Address>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolistingStateAltCurrencyConfigArgs = {
|
||||||
|
currency: SolistingStateCurrencyArgs;
|
||||||
|
/**
|
||||||
|
* Pyth V2 PriceFeedAccount for this token priced in USD (TOKEN/USD).
|
||||||
|
* `None` = treat as a $1.00 USD stablecoin — no oracle account required at order time.
|
||||||
|
*/
|
||||||
|
usdOracle: OptionOrNullable<Address>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getSolistingStateAltCurrencyConfigEncoder(): Encoder<SolistingStateAltCurrencyConfigArgs> {
|
||||||
|
return getStructEncoder([
|
||||||
|
["currency", getSolistingStateCurrencyEncoder()],
|
||||||
|
["usdOracle", getOptionEncoder(getAddressEncoder())],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSolistingStateAltCurrencyConfigDecoder(): Decoder<SolistingStateAltCurrencyConfig> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["currency", getSolistingStateCurrencyDecoder()],
|
||||||
|
["usdOracle", getOptionDecoder(getAddressDecoder())],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSolistingStateAltCurrencyConfigCodec(): Codec<
|
||||||
|
SolistingStateAltCurrencyConfigArgs,
|
||||||
|
SolistingStateAltCurrencyConfig
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getSolistingStateAltCurrencyConfigEncoder(),
|
||||||
|
getSolistingStateAltCurrencyConfigDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
combineCodec,
|
||||||
|
getAddressDecoder,
|
||||||
|
getAddressEncoder,
|
||||||
|
getDiscriminatedUnionDecoder,
|
||||||
|
getDiscriminatedUnionEncoder,
|
||||||
|
getStructDecoder,
|
||||||
|
getStructEncoder,
|
||||||
|
getU8Decoder,
|
||||||
|
getU8Encoder,
|
||||||
|
getUnitDecoder,
|
||||||
|
getUnitEncoder,
|
||||||
|
type Address,
|
||||||
|
type Codec,
|
||||||
|
type Decoder,
|
||||||
|
type Encoder,
|
||||||
|
type GetDiscriminatedUnionVariant,
|
||||||
|
type GetDiscriminatedUnionVariantContent,
|
||||||
|
} from "@solana/kit";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment currency identifier. Amounts are always in the currency's smallest unit:
|
||||||
|
* Sol → Lamports (u64), Spl → token units (smallest unit per `decimals`).
|
||||||
|
*/
|
||||||
|
export type SolistingStateCurrency =
|
||||||
|
| { __kind: "Sol" }
|
||||||
|
| { __kind: "Spl"; mint: Address; decimals: number };
|
||||||
|
|
||||||
|
export type SolistingStateCurrencyArgs = SolistingStateCurrency;
|
||||||
|
|
||||||
|
export function getSolistingStateCurrencyEncoder(): Encoder<SolistingStateCurrencyArgs> {
|
||||||
|
return getDiscriminatedUnionEncoder([
|
||||||
|
["Sol", getUnitEncoder()],
|
||||||
|
[
|
||||||
|
"Spl",
|
||||||
|
getStructEncoder([
|
||||||
|
["mint", getAddressEncoder()],
|
||||||
|
["decimals", getU8Encoder()],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSolistingStateCurrencyDecoder(): Decoder<SolistingStateCurrency> {
|
||||||
|
return getDiscriminatedUnionDecoder([
|
||||||
|
["Sol", getUnitDecoder()],
|
||||||
|
[
|
||||||
|
"Spl",
|
||||||
|
getStructDecoder([
|
||||||
|
["mint", getAddressDecoder()],
|
||||||
|
["decimals", getU8Decoder()],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSolistingStateCurrencyCodec(): Codec<
|
||||||
|
SolistingStateCurrencyArgs,
|
||||||
|
SolistingStateCurrency
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getSolistingStateCurrencyEncoder(),
|
||||||
|
getSolistingStateCurrencyDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data Enum Helpers.
|
||||||
|
export function solistingStateCurrency(
|
||||||
|
kind: "Sol",
|
||||||
|
): GetDiscriminatedUnionVariant<SolistingStateCurrencyArgs, "__kind", "Sol">;
|
||||||
|
export function solistingStateCurrency(
|
||||||
|
kind: "Spl",
|
||||||
|
data: GetDiscriminatedUnionVariantContent<
|
||||||
|
SolistingStateCurrencyArgs,
|
||||||
|
"__kind",
|
||||||
|
"Spl"
|
||||||
|
>,
|
||||||
|
): GetDiscriminatedUnionVariant<SolistingStateCurrencyArgs, "__kind", "Spl">;
|
||||||
|
export function solistingStateCurrency<
|
||||||
|
K extends SolistingStateCurrencyArgs["__kind"],
|
||||||
|
Data,
|
||||||
|
>(kind: K, data?: Data) {
|
||||||
|
return Array.isArray(data)
|
||||||
|
? { __kind: kind, fields: data }
|
||||||
|
: { __kind: kind, ...(data ?? {}) };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isSolistingStateCurrency<
|
||||||
|
K extends SolistingStateCurrency["__kind"],
|
||||||
|
>(
|
||||||
|
kind: K,
|
||||||
|
value: SolistingStateCurrency,
|
||||||
|
): value is SolistingStateCurrency & { __kind: K } {
|
||||||
|
return value.__kind === kind;
|
||||||
|
}
|
||||||
1428
sdk/src/idl/solisting.json
Normal file
1428
sdk/src/idl/solisting.json
Normal file
File diff suppressed because it is too large
Load Diff
13
sdk/src/index.ts
Normal file
13
sdk/src/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// Generated bindings — accounts, instructions, pdas, types, errors, program id
|
||||||
|
export * from './generated/solisting/src/generated/index.js'
|
||||||
|
|
||||||
|
// Hand-written helpers
|
||||||
|
export * from './pda.js'
|
||||||
|
export * from './listing.js'
|
||||||
|
// Order exports are imported but we exclude the re-exported deriveEscrowId to avoid duplication
|
||||||
|
// since it's already exported from pda.js
|
||||||
|
export type { OrderAccountWithPda } from './order.js'
|
||||||
|
export { fetchOrdersForListing, fetchOrdersByBuyer, fetchOrder } from './order.js'
|
||||||
|
|
||||||
|
// Re-export Address for consumers
|
||||||
|
export type { Address, Account } from '@solana/kit'
|
||||||
54
sdk/src/listing.ts
Normal file
54
sdk/src/listing.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { address, type Account, type Address, type Rpc } from '@solana/kit'
|
||||||
|
import { type GetProgramAccountsApi } from '@solana/rpc-api'
|
||||||
|
import { type GetAccountInfoApi } from '@solana/rpc-api'
|
||||||
|
import type { Base64EncodedBytes } from '@solana/rpc-types'
|
||||||
|
import {
|
||||||
|
decodeSolistingStateListingAccount,
|
||||||
|
fetchSolistingStateListingAccount,
|
||||||
|
SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR,
|
||||||
|
type SolistingStateListingAccount,
|
||||||
|
} from './generated/solisting/src/generated/index.js'
|
||||||
|
|
||||||
|
const PROGRAM_ADDRESS = address('DzwUAbpRvqcbA8QsEkRbZeXG4TEho5782cMySodrUHBU')
|
||||||
|
|
||||||
|
export type ListingAccountWithPda = Account<SolistingStateListingAccount>
|
||||||
|
export type GpaRpc = Rpc<GetProgramAccountsApi>
|
||||||
|
export type GetRpc = Rpc<GetAccountInfoApi>
|
||||||
|
|
||||||
|
export async function fetchAllListings(rpc: GpaRpc): Promise<ListingAccountWithPda[]> {
|
||||||
|
const disc = SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR
|
||||||
|
const discBase64 = Buffer.from(disc).toString('base64') as Base64EncodedBytes
|
||||||
|
const results = await rpc
|
||||||
|
.getProgramAccounts(PROGRAM_ADDRESS, {
|
||||||
|
encoding: 'base64',
|
||||||
|
filters: [{ memcmp: { offset: 0n, bytes: discBase64, encoding: 'base64' } }],
|
||||||
|
})
|
||||||
|
.send()
|
||||||
|
return (results as Array<{ pubkey: Address; account: { executable: boolean; lamports: bigint; owner: Address; space: bigint; data: [string, 'base64'] } }>).map((r) => {
|
||||||
|
const data = new Uint8Array(Buffer.from(r.account.data[0], 'base64'))
|
||||||
|
return decodeSolistingStateListingAccount({
|
||||||
|
address: r.pubkey,
|
||||||
|
data,
|
||||||
|
executable: r.account.executable,
|
||||||
|
lamports: r.account.lamports as unknown as import('@solana/rpc-types').Lamports,
|
||||||
|
programAddress: r.account.owner,
|
||||||
|
space: r.account.space,
|
||||||
|
exists: true,
|
||||||
|
}) as ListingAccountWithPda
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchListingsBySeller(
|
||||||
|
rpc: GpaRpc,
|
||||||
|
seller: Address,
|
||||||
|
): Promise<ListingAccountWithPda[]> {
|
||||||
|
const all = await fetchAllListings(rpc)
|
||||||
|
return all.filter((l) => l.data.seller === seller)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchListing(
|
||||||
|
rpc: GetRpc,
|
||||||
|
addr: Address,
|
||||||
|
): Promise<ListingAccountWithPda | null> {
|
||||||
|
return fetchSolistingStateListingAccount(rpc, addr).catch(() => null)
|
||||||
|
}
|
||||||
65
sdk/src/order.ts
Normal file
65
sdk/src/order.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { address, type Account, type Address, type Rpc } from '@solana/kit'
|
||||||
|
import { type GetProgramAccountsApi } from '@solana/rpc-api'
|
||||||
|
import { type GetAccountInfoApi } from '@solana/rpc-api'
|
||||||
|
import type { Base64EncodedBytes } from '@solana/rpc-types'
|
||||||
|
import {
|
||||||
|
decodeSolistingStateOrderAccount,
|
||||||
|
fetchSolistingStateOrderAccount,
|
||||||
|
SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR,
|
||||||
|
type SolistingStateOrderAccount,
|
||||||
|
} from './generated/solisting/src/generated/index.js'
|
||||||
|
import { deriveEscrowId } from './pda.js'
|
||||||
|
|
||||||
|
const PROGRAM_ADDRESS = address('DzwUAbpRvqcbA8QsEkRbZeXG4TEho5782cMySodrUHBU')
|
||||||
|
|
||||||
|
export type OrderAccountWithPda = Account<SolistingStateOrderAccount>
|
||||||
|
type GpaRpc = Rpc<GetProgramAccountsApi>
|
||||||
|
type GetRpc = Rpc<GetAccountInfoApi>
|
||||||
|
|
||||||
|
async function fetchAllOrders(rpc: GpaRpc): Promise<OrderAccountWithPda[]> {
|
||||||
|
const disc = SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR
|
||||||
|
const discBase64 = Buffer.from(disc).toString('base64') as Base64EncodedBytes
|
||||||
|
const results = await rpc
|
||||||
|
.getProgramAccounts(PROGRAM_ADDRESS, {
|
||||||
|
encoding: 'base64',
|
||||||
|
filters: [{ memcmp: { offset: 0n, bytes: discBase64, encoding: 'base64' } }],
|
||||||
|
})
|
||||||
|
.send()
|
||||||
|
return (results as Array<{ pubkey: Address; account: { executable: boolean; lamports: bigint; owner: Address; space: bigint; data: [string, 'base64'] } }>).map((r) => {
|
||||||
|
const data = new Uint8Array(Buffer.from(r.account.data[0], 'base64'))
|
||||||
|
return decodeSolistingStateOrderAccount({
|
||||||
|
address: r.pubkey,
|
||||||
|
data,
|
||||||
|
executable: r.account.executable,
|
||||||
|
lamports: r.account.lamports as unknown as import('@solana/rpc-types').Lamports,
|
||||||
|
programAddress: r.account.owner,
|
||||||
|
space: r.account.space,
|
||||||
|
exists: true,
|
||||||
|
}) as OrderAccountWithPda
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchOrdersForListing(
|
||||||
|
rpc: GpaRpc,
|
||||||
|
listingPk: Address,
|
||||||
|
): Promise<OrderAccountWithPda[]> {
|
||||||
|
const all = await fetchAllOrders(rpc)
|
||||||
|
return all.filter((o) => o.data.listing === listingPk)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchOrdersByBuyer(
|
||||||
|
rpc: GpaRpc,
|
||||||
|
buyer: Address,
|
||||||
|
): Promise<OrderAccountWithPda[]> {
|
||||||
|
const all = await fetchAllOrders(rpc)
|
||||||
|
return all.filter((o) => o.data.buyer === buyer)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchOrder(
|
||||||
|
rpc: GetRpc,
|
||||||
|
addr: Address,
|
||||||
|
): Promise<OrderAccountWithPda | null> {
|
||||||
|
return fetchSolistingStateOrderAccount(rpc, addr).catch(() => null)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { deriveEscrowId }
|
||||||
30
sdk/src/pda.ts
Normal file
30
sdk/src/pda.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { address, getAddressEncoder, type Address, type ProgramDerivedAddress } from '@solana/kit'
|
||||||
|
import { findListingAccountPda, findOrderAccountPda } from './generated/solisting/src/generated/index.js'
|
||||||
|
|
||||||
|
const PROGRAM_ADDRESS = address('DzwUAbpRvqcbA8QsEkRbZeXG4TEho5782cMySodrUHBU')
|
||||||
|
|
||||||
|
export async function findListingPda(
|
||||||
|
seller: Address,
|
||||||
|
listingId: bigint,
|
||||||
|
): Promise<ProgramDerivedAddress> {
|
||||||
|
return findListingAccountPda({ seller, listingId }, { programAddress: PROGRAM_ADDRESS })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function findOrderPda(
|
||||||
|
listingAccount: Address,
|
||||||
|
buyer: Address,
|
||||||
|
orderId: bigint,
|
||||||
|
): Promise<ProgramDerivedAddress> {
|
||||||
|
return findOrderAccountPda({ listingAccount, buyer, orderId }, { programAddress: PROGRAM_ADDRESS })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replicates the program's escrow_id derivation:
|
||||||
|
* u64::from_le_bytes(order_pda.to_bytes()[0..8])
|
||||||
|
* Must match exactly — used when building create_order instructions.
|
||||||
|
*/
|
||||||
|
export function deriveEscrowId(orderPda: Address): bigint {
|
||||||
|
const bytes = getAddressEncoder().encode(orderPda) // 32-byte Uint8Array
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
||||||
|
return view.getBigUint64(0, true) // little-endian, first 8 bytes
|
||||||
|
}
|
||||||
12
sdk/tsconfig.json
Normal file
12
sdk/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
1428
target/idl/solisting.json
Normal file
1428
target/idl/solisting.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user