@pipeline-sol/sdk 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +209 -2
  2. package/dist/actions.d.ts +87 -0
  3. package/dist/actions.d.ts.map +1 -0
  4. package/dist/actions.js +326 -0
  5. package/dist/actions.js.map +1 -0
  6. package/dist/codecs.d.ts +188 -0
  7. package/dist/codecs.d.ts.map +1 -0
  8. package/dist/codecs.js +296 -0
  9. package/dist/codecs.js.map +1 -0
  10. package/dist/constants.d.ts +97 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +98 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/discovery.d.ts +17 -0
  15. package/dist/discovery.d.ts.map +1 -0
  16. package/dist/discovery.js +47 -0
  17. package/dist/discovery.js.map +1 -0
  18. package/dist/events.d.ts +106 -0
  19. package/dist/events.d.ts.map +1 -0
  20. package/dist/events.js +149 -0
  21. package/dist/events.js.map +1 -0
  22. package/dist/fees.d.ts +16 -0
  23. package/dist/fees.d.ts.map +1 -0
  24. package/dist/fees.js +60 -0
  25. package/dist/fees.js.map +1 -0
  26. package/dist/http.d.ts +23 -0
  27. package/dist/http.d.ts.map +1 -0
  28. package/dist/http.js +99 -0
  29. package/dist/http.js.map +1 -0
  30. package/dist/index.d.ts +14 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +13 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/inspect.d.ts +410 -0
  35. package/dist/inspect.d.ts.map +1 -0
  36. package/dist/inspect.js +828 -0
  37. package/dist/inspect.js.map +1 -0
  38. package/dist/instructions.d.ts +101 -0
  39. package/dist/instructions.d.ts.map +1 -0
  40. package/dist/instructions.js +201 -0
  41. package/dist/instructions.js.map +1 -0
  42. package/dist/listing.d.ts +35 -0
  43. package/dist/listing.d.ts.map +1 -0
  44. package/dist/listing.js +49 -0
  45. package/dist/listing.js.map +1 -0
  46. package/dist/metadata.d.ts +266 -0
  47. package/dist/metadata.d.ts.map +1 -0
  48. package/dist/metadata.js +515 -0
  49. package/dist/metadata.js.map +1 -0
  50. package/dist/pda.d.ts +21 -0
  51. package/dist/pda.d.ts.map +1 -0
  52. package/dist/pda.js +52 -0
  53. package/dist/pda.js.map +1 -0
  54. package/dist/quote.d.ts +63 -0
  55. package/dist/quote.d.ts.map +1 -0
  56. package/dist/quote.js +169 -0
  57. package/dist/quote.js.map +1 -0
  58. package/package.json +56 -5
  59. package/schema/strategy-metadata.v1.json +171 -0
@@ -0,0 +1,63 @@
1
+ import { type AccountMeta, type Address, type Base64EncodedWireTransaction, type Commitment, type Rpc, type SimulateTransactionApi, type Slot } from '@solana/kit';
2
+ import { type Market, type QuoteResult, type TradeRequest } from './codecs.js';
3
+ import type { PipelineInstruction } from './instructions.js';
4
+ /** Default compute cap for a strategy's read-only call, as in `pipeline-quoter`. */
5
+ export declare const DEFAULT_COMPUTE_LIMIT = 200000;
6
+ /** The parts of a Pipeline market a quote needs. Build it with {@link marketViewFromMarket}. */
7
+ export type MarketView = {
8
+ market: Address;
9
+ strategyProgram: Address;
10
+ marketState: Address;
11
+ mints: readonly Address[];
12
+ vaults: readonly Address[];
13
+ /** Each mint's owning token program, in mint order. */
14
+ tokenPrograms: readonly Address[];
15
+ supportsExactOut: boolean;
16
+ };
17
+ /** `tokenPrograms` must give each mint's owning token program, in mint order. */
18
+ export declare function marketViewFromMarket(marketAddress: Address, market: Market, tokenPrograms: readonly Address[]): MarketView;
19
+ /**
20
+ * The strategy's `pipeline_quote` for `trade` (vault-level amounts). Strategy accounts are
21
+ * passed read-only after the fixed accounts.
22
+ */
23
+ export declare function buildQuoteInstruction(market: MarketView, trade: TradeRequest, strategyAccounts: readonly AccountMeta[]): Promise<PipelineInstruction>;
24
+ /**
25
+ * The strategy's `pipeline_resolve_accounts` for one round. `known` are the accounts
26
+ * returned by the previous round, passed read-only after the fixed accounts.
27
+ */
28
+ export declare function buildResolveAccountsInstruction(market: MarketView, trade: TradeRequest, round: number, known: readonly AccountMeta[]): Promise<PipelineInstruction>;
29
+ export type SimulationOptions = {
30
+ /** Compute unit limit for the strategy call. Defaults to {@link DEFAULT_COMPUTE_LIMIT}. */
31
+ computeUnitLimit?: number;
32
+ /** Defaults to `finalized`; with Alpenglow (live on mainnet and devnet) that is ~150 ms behind the tip. */
33
+ commitment?: Commitment;
34
+ minContextSlot?: Slot;
35
+ };
36
+ /** The simulated strategy call failed, or returned no usable data. */
37
+ export declare class SimulationError extends Error {
38
+ readonly err: unknown;
39
+ readonly logs: readonly string[];
40
+ constructor(message: string, err: unknown, logs: readonly string[] | null);
41
+ }
42
+ /**
43
+ * The unsigned, base64-encoded transaction simulated for a read-only strategy call: a
44
+ * compute limit, then `instruction`, paid by `feePayer` (which must exist on chain).
45
+ */
46
+ export declare function buildSimulationTransaction(instruction: PipelineInstruction, feePayer: Address, computeUnitLimit?: number): Base64EncodedWireTransaction;
47
+ /**
48
+ * Runs the strategy's `pipeline_quote` for `trade` by RPC simulation. Amounts are
49
+ * vault-level: Pipeline, integrator and token transfer fees are not applied.
50
+ *
51
+ * `feePayer` must be an existing account with lamports; it does not sign.
52
+ */
53
+ export declare function quoteStrategy(rpc: Rpc<SimulateTransactionApi>, market: MarketView, trade: TradeRequest, strategyAccounts: readonly AccountMeta[], feePayer: Address, options?: SimulationOptions): Promise<{
54
+ quote: QuoteResult;
55
+ unitsConsumed: bigint | null;
56
+ }>;
57
+ /**
58
+ * Asks the strategy which accounts `trade` needs, by RPC simulation, for up to
59
+ * {@link MAX_RESOLVE_ROUNDS} rounds. Each round passes the accounts returned so far.
60
+ * Returns the strategy accounts to pass to `swap` (and to {@link quoteStrategy}).
61
+ */
62
+ export declare function resolveAccounts(rpc: Rpc<SimulateTransactionApi>, market: MarketView, trade: TradeRequest, feePayer: Address, options?: SimulationOptions): Promise<AccountMeta[]>;
63
+ //# sourceMappingURL=quote.d.ts.map
@@ -0,0 +1 @@
1
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quote` and
2
+ // `pipeline_resolve_accounts` through any RPC node. This is the zero-infrastructure
3
+ // fallback; `pipeline-quoter` (Rust) does the same in an embedded VM.
4
+ //
5
+ // The instructions use the same fixed read accounts as `pipeline-quoter`: everything
6
+ // read-only, nothing signs, and the trader's token accounts are its associated token
7
+ // accounts (which need not exist). An anonymous trade uses the all-zero address.
8
+ import { AccountRole, appendTransactionMessageInstructions, compileTransaction, createTransactionMessage, getBase64EncodedWireTransaction, getBase64Encoder, pipe, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, } from '@solana/kit';
9
+ import { decodeReturnData, getQuoteResultCodec, getResolveRequestCodec, getResolveResultCodec, getTradeRequestCodec, instructionData, marketMints, } from './codecs.js';
10
+ import { COMPUTE_BUDGET_PROGRAM_ADDRESS, DEFAULT_ADDRESS, MAX_RESOLVE_ROUNDS, STRATEGY_DISCRIMINATORS, } from './constants.js';
11
+ import { associatedTokenAddress } from './pda.js';
12
+ /** Default compute cap for a strategy's read-only call, as in `pipeline-quoter`. */
13
+ export const DEFAULT_COMPUTE_LIMIT = 200_000;
14
+ /** `tokenPrograms` must give each mint's owning token program, in mint order. */
15
+ export function marketViewFromMarket(marketAddress, market, tokenPrograms) {
16
+ const mints = marketMints(market);
17
+ if (tokenPrograms.length !== mints.length) {
18
+ throw new RangeError(`expected ${mints.length} token programs, got ${tokenPrograms.length}`);
19
+ }
20
+ return {
21
+ market: marketAddress,
22
+ strategyProgram: market.strategyProgram,
23
+ marketState: market.marketState,
24
+ mints,
25
+ vaults: market.vaults.slice(0, mints.length),
26
+ tokenPrograms,
27
+ supportsExactOut: market.supportsExactOut,
28
+ };
29
+ }
30
+ function at(list, index, what) {
31
+ const value = list[index];
32
+ if (value === undefined) {
33
+ throw new RangeError(`${what} index ${index} is out of range`);
34
+ }
35
+ return value;
36
+ }
37
+ function readonly(address) {
38
+ return { address, role: AccountRole.READONLY };
39
+ }
40
+ /** The fixed trade accounts for a read-only strategy call. */
41
+ async function readAccounts(market, trade) {
42
+ const trader = trade.trader ?? DEFAULT_ADDRESS;
43
+ const inputMint = at(market.mints, trade.inputIndex, 'input mint');
44
+ const outputMint = at(market.mints, trade.outputIndex, 'output mint');
45
+ const inputTokenProgram = at(market.tokenPrograms, trade.inputIndex, 'input token program');
46
+ const outputTokenProgram = at(market.tokenPrograms, trade.outputIndex, 'output token program');
47
+ return [
48
+ readonly(market.market),
49
+ readonly(market.marketState),
50
+ readonly(trader),
51
+ readonly(await associatedTokenAddress(trader, inputMint, inputTokenProgram)),
52
+ readonly(await associatedTokenAddress(trader, outputMint, outputTokenProgram)),
53
+ readonly(at(market.vaults, trade.inputIndex, 'input vault')),
54
+ readonly(inputMint),
55
+ readonly(outputMint),
56
+ readonly(inputTokenProgram),
57
+ readonly(outputTokenProgram),
58
+ ];
59
+ }
60
+ /**
61
+ * The strategy's `pipeline_quote` for `trade` (vault-level amounts). Strategy accounts are
62
+ * passed read-only after the fixed accounts.
63
+ */
64
+ export async function buildQuoteInstruction(market, trade, strategyAccounts) {
65
+ return {
66
+ programAddress: market.strategyProgram,
67
+ accounts: [...(await readAccounts(market, trade)), ...strategyAccounts.map((m) => readonly(m.address))],
68
+ data: instructionData(STRATEGY_DISCRIMINATORS.quote, getTradeRequestCodec(), trade),
69
+ };
70
+ }
71
+ /**
72
+ * The strategy's `pipeline_resolve_accounts` for one round. `known` are the accounts
73
+ * returned by the previous round, passed read-only after the fixed accounts.
74
+ */
75
+ export async function buildResolveAccountsInstruction(market, trade, round, known) {
76
+ return {
77
+ programAddress: market.strategyProgram,
78
+ accounts: [...(await readAccounts(market, trade)), ...known.map((m) => readonly(m.address))],
79
+ data: instructionData(STRATEGY_DISCRIMINATORS.resolveAccounts, getResolveRequestCodec(), { trade, round }),
80
+ };
81
+ }
82
+ /** The simulated strategy call failed, or returned no usable data. */
83
+ export class SimulationError extends Error {
84
+ err;
85
+ logs;
86
+ constructor(message, err, logs) {
87
+ super(message);
88
+ this.name = 'SimulationError';
89
+ this.err = err;
90
+ this.logs = logs ?? [];
91
+ }
92
+ }
93
+ function setComputeUnitLimit(units) {
94
+ // Compute budget `SetComputeUnitLimit`: tag 2, then the limit as a little-endian u32.
95
+ const data = new Uint8Array(5);
96
+ data[0] = 2;
97
+ new DataView(data.buffer).setUint32(1, units, true);
98
+ return { programAddress: COMPUTE_BUDGET_PROGRAM_ADDRESS, accounts: [], data };
99
+ }
100
+ // Any 32-byte value; the node replaces it (`replaceRecentBlockhash`).
101
+ const PLACEHOLDER_BLOCKHASH = '11111111111111111111111111111111';
102
+ /**
103
+ * The unsigned, base64-encoded transaction simulated for a read-only strategy call: a
104
+ * compute limit, then `instruction`, paid by `feePayer` (which must exist on chain).
105
+ */
106
+ export function buildSimulationTransaction(instruction, feePayer, computeUnitLimit = DEFAULT_COMPUTE_LIMIT) {
107
+ const message = pipe(createTransactionMessage({ version: 0 }), (m) => setTransactionMessageFeePayer(feePayer, m), (m) => setTransactionMessageLifetimeUsingBlockhash({ blockhash: PLACEHOLDER_BLOCKHASH, lastValidBlockHeight: 0n }, m), (m) => appendTransactionMessageInstructions([setComputeUnitLimit(computeUnitLimit), instruction], m));
108
+ return getBase64EncodedWireTransaction(compileTransaction(message));
109
+ }
110
+ const base64 = getBase64Encoder();
111
+ async function simulate(rpc, instruction, feePayer, decoder, options) {
112
+ const wire = buildSimulationTransaction(instruction, feePayer, options.computeUnitLimit);
113
+ const { value } = await rpc
114
+ .simulateTransaction(wire, {
115
+ encoding: 'base64',
116
+ sigVerify: false,
117
+ replaceRecentBlockhash: true,
118
+ commitment: options.commitment ?? 'finalized',
119
+ minContextSlot: options.minContextSlot,
120
+ })
121
+ .send();
122
+ if (value.err !== null) {
123
+ throw new SimulationError('strategy call failed in simulation', value.err, value.logs);
124
+ }
125
+ // The runtime records no return data when it is empty or all zeros, so a missing
126
+ // value decodes as all zeros. Data set by another program is rejected.
127
+ const returned = value.returnData;
128
+ if (returned !== null && returned.programId !== instruction.programAddress) {
129
+ throw new SimulationError(`return data came from ${returned.programId}`, null, value.logs);
130
+ }
131
+ const bytes = returned === null ? new Uint8Array() : base64.encode(returned.data[0]);
132
+ const decoded = decodeReturnData(decoder, bytes);
133
+ if (decoded === null) {
134
+ throw new SimulationError('malformed return data', null, value.logs);
135
+ }
136
+ return { value: decoded, unitsConsumed: value.unitsConsumed ?? null };
137
+ }
138
+ /**
139
+ * Runs the strategy's `pipeline_quote` for `trade` by RPC simulation. Amounts are
140
+ * vault-level: Pipeline, integrator and token transfer fees are not applied.
141
+ *
142
+ * `feePayer` must be an existing account with lamports; it does not sign.
143
+ */
144
+ export async function quoteStrategy(rpc, market, trade, strategyAccounts, feePayer, options = {}) {
145
+ const instruction = await buildQuoteInstruction(market, trade, strategyAccounts);
146
+ const { value, unitsConsumed } = await simulate(rpc, instruction, feePayer, getQuoteResultCodec(), options);
147
+ return { quote: value, unitsConsumed };
148
+ }
149
+ /**
150
+ * Asks the strategy which accounts `trade` needs, by RPC simulation, for up to
151
+ * {@link MAX_RESOLVE_ROUNDS} rounds. Each round passes the accounts returned so far.
152
+ * Returns the strategy accounts to pass to `swap` (and to {@link quoteStrategy}).
153
+ */
154
+ export async function resolveAccounts(rpc, market, trade, feePayer, options = {}) {
155
+ let known = [];
156
+ for (let round = 0; round < MAX_RESOLVE_ROUNDS; round++) {
157
+ const instruction = await buildResolveAccountsInstruction(market, trade, round, known);
158
+ const { value } = await simulate(rpc, instruction, feePayer, getResolveResultCodec(), options);
159
+ known = value.accounts.map((account) => ({
160
+ address: account.address,
161
+ role: account.writable ? AccountRole.WRITABLE : AccountRole.READONLY,
162
+ }));
163
+ if (value.complete) {
164
+ return known;
165
+ }
166
+ }
167
+ throw new SimulationError(`account resolution did not finish within ${MAX_RESOLVE_ROUNDS} rounds`, null, null);
168
+ }
169
+ //# sourceMappingURL=quote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../src/quote.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,oFAAoF;AACpF,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G,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACrC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ;SACvE,CAAC,CAAC,CAAC;QACJ,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,MAAM,IAAI,eAAe,CAAC,4CAA4C,kBAAkB,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACnH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
- "name": "@pipeline-sol/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@pipeline-sol/sdk",
3
+ "version": "0.1.1",
4
+ "description": "Instruction builders, account and event decoders, fee maths and RPC quoting for the Pipeline router",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/MetalLegBob/pipeline.git",
9
+ "directory": "sdk/ts"
10
+ },
11
+ "homepage": "https://github.com/MetalLegBob/pipeline/tree/main/sdk/ts",
12
+ "bugs": "https://github.com/MetalLegBob/pipeline/issues",
13
+ "keywords": [
14
+ "solana",
15
+ "pipeline",
16
+ "amm",
17
+ "defi",
18
+ "sdk",
19
+ "router"
20
+ ],
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "schema"
33
+ ],
34
+ "engines": {
35
+ "node": ">=20.19"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "test": "npm run typecheck && npm run format:check && vitest run",
41
+ "fixtures": "cargo run -q -p pipeline-client --example ts_fixtures > test/fixtures.json && cargo run -q -p pipeline-client --example ts_facts_fixtures > ../../crates/pipeline-client/tests/fixtures/trust-facts.json",
42
+ "format": "prettier --write .",
43
+ "format:check": "prettier --check ."
44
+ },
45
+ "dependencies": {
46
+ "@solana/kit": "^8.4.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^24.19.2",
50
+ "prettier": "^3.9.10",
51
+ "typescript": "^7.0.2",
52
+ "vitest": "^5.0.4"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ }
57
+ }
@@ -0,0 +1,171 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Pipeline strategy metadata, version 1",
4
+ "description": "The JSON document a registered strategy's metadata_uri points to. Unknown keys are allowed everywhere. Account source strings follow the grammar documented in the SDK's parseAccountSource; parseStrategyMetadata in the TypeScript SDK is the reference validator.",
5
+ "type": "object",
6
+ "required": ["schema", "name"],
7
+ "properties": {
8
+ "schema": { "const": "pipeline-strategy-metadata/1" },
9
+ "name": { "type": "string", "minLength": 1, "maxLength": 64 },
10
+ "description": { "type": "string", "maxLength": 2000 },
11
+ "image": { "$ref": "#/$defs/url", "description": "Icon or logo." },
12
+ "category": {
13
+ "type": "string",
14
+ "description": "One of amm, launchpad, order-book, auction, lbp, other. Readers treat other values as unknown, not invalid.",
15
+ "examples": ["amm", "launchpad", "order-book", "auction", "lbp", "other"]
16
+ },
17
+ "tags": {
18
+ "type": "array",
19
+ "maxItems": 16,
20
+ "items": { "type": "string", "minLength": 1, "maxLength": 32 }
21
+ },
22
+ "links": {
23
+ "type": "object",
24
+ "description": "Links shown to users: website, docs, source, IDL and social accounts. Every value is a URL; other named links are allowed. A social link on an unexpected site is accepted with a warning.",
25
+ "properties": {
26
+ "website": { "$ref": "#/$defs/url" },
27
+ "docs": { "$ref": "#/$defs/url" },
28
+ "source": { "$ref": "#/$defs/url", "description": "Human-facing source link." },
29
+ "idl": { "$ref": "#/$defs/url", "description": "Anchor IDL or Codama document." },
30
+ "twitter": { "$ref": "#/$defs/url", "description": "X (Twitter) profile, on x.com or twitter.com." },
31
+ "github": {
32
+ "$ref": "#/$defs/url",
33
+ "description": "GitHub organisation, user or repository, on github.com."
34
+ },
35
+ "discord": { "$ref": "#/$defs/url", "description": "Discord invite, on discord.gg or discord.com." },
36
+ "telegram": { "$ref": "#/$defs/url", "description": "Telegram group or channel, on t.me." },
37
+ "farcaster": {
38
+ "$ref": "#/$defs/url",
39
+ "description": "Farcaster profile or channel, on farcaster.xyz or warpcast.com."
40
+ }
41
+ },
42
+ "additionalProperties": { "$ref": "#/$defs/url" }
43
+ },
44
+ "source": {
45
+ "type": "object",
46
+ "description": "The code a verified build is made from.",
47
+ "required": ["repository"],
48
+ "properties": {
49
+ "repository": { "$ref": "#/$defs/url" },
50
+ "commit": { "type": "string", "pattern": "^[0-9a-fA-F]{7,64}$" },
51
+ "path": {
52
+ "type": "string",
53
+ "maxLength": 256,
54
+ "description": "The program's directory in the repository."
55
+ }
56
+ }
57
+ },
58
+ "init": {
59
+ "type": "object",
60
+ "description": "How to build create_market: init_data is the args Borsh-encoded in order (no discriminator); accounts are the strategy's own setup accounts after the router's four fixed ones.",
61
+ "properties": {
62
+ "description": { "type": "string", "maxLength": 2000 },
63
+ "idl_type": { "type": "string", "maxLength": 128 },
64
+ "market_state": {
65
+ "type": "string",
66
+ "maxLength": 512,
67
+ "description": "new_keypair (default: a fresh keypair signs) or an account source such as pda:strategy:..."
68
+ },
69
+ "args": { "$ref": "#/$defs/args" },
70
+ "accounts": { "$ref": "#/$defs/accounts" }
71
+ }
72
+ },
73
+ "actions": {
74
+ "type": "array",
75
+ "maxItems": 64,
76
+ "items": { "$ref": "#/$defs/action" }
77
+ },
78
+ "conformance": {
79
+ "type": "object",
80
+ "required": ["report"],
81
+ "properties": {
82
+ "report": { "$ref": "#/$defs/url", "description": "A pipeline-check JSON report." },
83
+ "sha256": { "type": "string", "pattern": "^[0-9a-fA-F]{64}$" }
84
+ }
85
+ },
86
+ "security": {
87
+ "type": "object",
88
+ "required": ["contact"],
89
+ "properties": {
90
+ "contact": { "type": "string", "minLength": 1, "maxLength": 256 },
91
+ "policy": { "$ref": "#/$defs/url" },
92
+ "audits": {
93
+ "type": "array",
94
+ "maxItems": 32,
95
+ "items": {
96
+ "type": "object",
97
+ "required": ["by"],
98
+ "properties": {
99
+ "by": { "type": "string", "minLength": 1, "maxLength": 128 },
100
+ "url": { "$ref": "#/$defs/url" },
101
+ "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ },
108
+ "$defs": {
109
+ "url": {
110
+ "type": "string",
111
+ "maxLength": 512,
112
+ "pattern": "^(https|ipfs|ar)://",
113
+ "description": "https://, ipfs:// or ar:// only."
114
+ },
115
+ "identifier": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$" },
116
+ "source": {
117
+ "type": "string",
118
+ "minLength": 1,
119
+ "maxLength": 512,
120
+ "description": "wallet | market_state | market | strategy_program | system_program | associated_token_program | mint:i | vault:i | token_program:i | wallet_token_account:i | fixed:<address> | input:<name> | pda:<address|strategy>:<seed>,... (seeds str:<text>, hex:<bytes>, key:<source>, arg:<name>) | ata:<owner>,<mint> | token_program_of:<mint>",
121
+ "pattern": "^(wallet|market_state|market|strategy_program|system_program|associated_token_program|(mint|vault|token_program|wallet_token_account):[0-3]|fixed:.+|input:.+|pda:.+|ata:.+,.+|token_program_of:.+)$"
122
+ },
123
+ "arg": {
124
+ "type": "object",
125
+ "required": ["name", "type"],
126
+ "properties": {
127
+ "name": { "$ref": "#/$defs/identifier" },
128
+ "type": { "enum": ["u8", "u16", "u32", "u64", "i64", "bool", "pubkey", "bytes", "string"] },
129
+ "label": { "type": "string", "maxLength": 64 },
130
+ "description": { "type": "string", "maxLength": 1000 },
131
+ "decimals_of": { "$ref": "#/$defs/source" }
132
+ }
133
+ },
134
+ "args": { "type": "array", "maxItems": 32, "items": { "$ref": "#/$defs/arg" } },
135
+ "account": {
136
+ "type": "object",
137
+ "required": ["name", "source"],
138
+ "properties": {
139
+ "name": { "type": "string", "minLength": 1, "maxLength": 64 },
140
+ "source": { "$ref": "#/$defs/source" },
141
+ "signer": { "type": "boolean" },
142
+ "writable": { "type": "boolean" }
143
+ }
144
+ },
145
+ "accounts": { "type": "array", "maxItems": 64, "items": { "$ref": "#/$defs/account" } },
146
+ "action": {
147
+ "type": "object",
148
+ "required": ["name", "label"],
149
+ "properties": {
150
+ "name": {
151
+ "$ref": "#/$defs/identifier",
152
+ "description": "For Anchor programs, the IDL instruction name."
153
+ },
154
+ "label": { "type": "string", "minLength": 1, "maxLength": 64 },
155
+ "kind": {
156
+ "type": "string",
157
+ "description": "add_liquidity, remove_liquidity, claim, create_market or other. Readers treat other values as unknown, not invalid.",
158
+ "examples": ["add_liquidity", "remove_liquidity", "claim", "create_market", "other"]
159
+ },
160
+ "description": { "type": "string", "maxLength": 2000 },
161
+ "discriminator": {
162
+ "type": "string",
163
+ "pattern": "^[0-9a-fA-F]{16}$",
164
+ "description": "Defaults to Anchor's sha256(\"global:<name>\")[..8]."
165
+ },
166
+ "args": { "$ref": "#/$defs/args" },
167
+ "accounts": { "$ref": "#/$defs/accounts" }
168
+ }
169
+ }
170
+ }
171
+ }