@oobe-protocol-labs/synapse-sap-sdk 0.15.0 → 0.15.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.
- package/dist/cjs/client.js +1 -1
- package/dist/cjs/client.js.map +1 -1
- package/dist/esm/client.js +1 -1
- package/dist/esm/client.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/instructions/memory.d.ts +0 -8
- package/dist/esm/instructions/memory.d.ts.map +0 -1
- package/dist/esm/instructions/memory.js +0 -234
- package/dist/esm/instructions/memory.js.map +0 -1
- package/dist/types/constants/addresses.d.ts +0 -117
- package/dist/types/constants/addresses.d.ts.map +0 -1
- package/dist/types/constants/index.d.ts +0 -31
- package/dist/types/constants/index.d.ts.map +0 -1
- package/dist/types/constants/limits.d.ts +0 -149
- package/dist/types/constants/limits.d.ts.map +0 -1
- package/dist/types/constants/network.d.ts +0 -81
- package/dist/types/constants/network.d.ts.map +0 -1
- package/dist/types/constants/payments.d.ts +0 -121
- package/dist/types/constants/payments.d.ts.map +0 -1
- package/dist/types/constants/programs.d.ts +0 -69
- package/dist/types/constants/programs.d.ts.map +0 -1
- package/dist/types/constants/seeds.d.ts +0 -82
- package/dist/types/constants/seeds.d.ts.map +0 -1
- package/dist/types/core/client.d.ts +0 -467
- package/dist/types/core/client.d.ts.map +0 -1
- package/dist/types/core/connection.d.ts +0 -305
- package/dist/types/core/connection.d.ts.map +0 -1
- package/dist/types/core/index.d.ts +0 -20
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/errors/index.d.ts +0 -335
- package/dist/types/errors/index.d.ts.map +0 -1
- package/dist/types/events/geyser.d.ts +0 -150
- package/dist/types/events/geyser.d.ts.map +0 -1
- package/dist/types/events/index.d.ts +0 -248
- package/dist/types/events/index.d.ts.map +0 -1
- package/dist/types/idl/index.d.ts +0 -70
- package/dist/types/idl/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -86
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/modules/agent.d.ts +0 -156
- package/dist/types/modules/agent.d.ts.map +0 -1
- package/dist/types/modules/attestation.d.ts +0 -96
- package/dist/types/modules/attestation.d.ts.map +0 -1
- package/dist/types/modules/base.d.ts +0 -215
- package/dist/types/modules/base.d.ts.map +0 -1
- package/dist/types/modules/escrow-v2.d.ts +0 -285
- package/dist/types/modules/escrow-v2.d.ts.map +0 -1
- package/dist/types/modules/feedback.d.ts +0 -105
- package/dist/types/modules/feedback.d.ts.map +0 -1
- package/dist/types/modules/index.d.ts +0 -27
- package/dist/types/modules/index.d.ts.map +0 -1
- package/dist/types/modules/indexing.d.ts +0 -200
- package/dist/types/modules/indexing.d.ts.map +0 -1
- package/dist/types/modules/ledger.d.ts +0 -150
- package/dist/types/modules/ledger.d.ts.map +0 -1
- package/dist/types/modules/receipt.d.ts +0 -91
- package/dist/types/modules/receipt.d.ts.map +0 -1
- package/dist/types/modules/staking.d.ts +0 -51
- package/dist/types/modules/staking.d.ts.map +0 -1
- package/dist/types/modules/subscription.d.ts +0 -33
- package/dist/types/modules/subscription.d.ts.map +0 -1
- package/dist/types/modules/tools.d.ts +0 -172
- package/dist/types/modules/tools.d.ts.map +0 -1
- package/dist/types/modules/vault.d.ts +0 -240
- package/dist/types/modules/vault.d.ts.map +0 -1
- package/dist/types/parser/client.d.ts +0 -123
- package/dist/types/parser/client.d.ts.map +0 -1
- package/dist/types/parser/complete.d.ts +0 -90
- package/dist/types/parser/complete.d.ts.map +0 -1
- package/dist/types/parser/index.d.ts +0 -40
- package/dist/types/parser/index.d.ts.map +0 -1
- package/dist/types/parser/inner.d.ts +0 -114
- package/dist/types/parser/inner.d.ts.map +0 -1
- package/dist/types/parser/instructions.d.ts +0 -76
- package/dist/types/parser/instructions.d.ts.map +0 -1
- package/dist/types/parser/transaction.d.ts +0 -77
- package/dist/types/parser/transaction.d.ts.map +0 -1
- package/dist/types/parser/types.d.ts +0 -154
- package/dist/types/parser/types.d.ts.map +0 -1
- package/dist/types/pda/index.d.ts +0 -527
- package/dist/types/pda/index.d.ts.map +0 -1
- package/dist/types/plugin/index.d.ts +0 -171
- package/dist/types/plugin/index.d.ts.map +0 -1
- package/dist/types/plugin/protocols.d.ts +0 -152
- package/dist/types/plugin/protocols.d.ts.map +0 -1
- package/dist/types/plugin/schemas.d.ts +0 -829
- package/dist/types/plugin/schemas.d.ts.map +0 -1
- package/dist/types/postgres/adapter.d.ts +0 -355
- package/dist/types/postgres/adapter.d.ts.map +0 -1
- package/dist/types/postgres/index.d.ts +0 -24
- package/dist/types/postgres/index.d.ts.map +0 -1
- package/dist/types/postgres/serializers.d.ts +0 -30
- package/dist/types/postgres/serializers.d.ts.map +0 -1
- package/dist/types/postgres/sync.d.ts +0 -156
- package/dist/types/postgres/sync.d.ts.map +0 -1
- package/dist/types/postgres/types.d.ts +0 -167
- package/dist/types/postgres/types.d.ts.map +0 -1
- package/dist/types/registries/builder.d.ts +0 -333
- package/dist/types/registries/builder.d.ts.map +0 -1
- package/dist/types/registries/discovery.d.ts +0 -333
- package/dist/types/registries/discovery.d.ts.map +0 -1
- package/dist/types/registries/fairscale.d.ts +0 -680
- package/dist/types/registries/fairscale.d.ts.map +0 -1
- package/dist/types/registries/index.d.ts +0 -52
- package/dist/types/registries/index.d.ts.map +0 -1
- package/dist/types/registries/metaplex-bridge.d.ts +0 -488
- package/dist/types/registries/metaplex-bridge.d.ts.map +0 -1
- package/dist/types/registries/session.d.ts +0 -317
- package/dist/types/registries/session.d.ts.map +0 -1
- package/dist/types/registries/x402.d.ts +0 -523
- package/dist/types/registries/x402.d.ts.map +0 -1
- package/dist/types/types/accounts.d.ts +0 -817
- package/dist/types/types/accounts.d.ts.map +0 -1
- package/dist/types/types/common.d.ts +0 -166
- package/dist/types/types/common.d.ts.map +0 -1
- package/dist/types/types/endpoint.d.ts +0 -161
- package/dist/types/types/endpoint.d.ts.map +0 -1
- package/dist/types/types/enums.d.ts +0 -353
- package/dist/types/types/enums.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -29
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/types/instructions.d.ts +0 -400
- package/dist/types/types/instructions.d.ts.map +0 -1
- package/dist/types/utils/anchor-errors.d.ts +0 -61
- package/dist/types/utils/anchor-errors.d.ts.map +0 -1
- package/dist/types/utils/endpoint-validator.d.ts +0 -110
- package/dist/types/utils/endpoint-validator.d.ts.map +0 -1
- package/dist/types/utils/escrow-validation.d.ts +0 -145
- package/dist/types/utils/escrow-validation.d.ts.map +0 -1
- package/dist/types/utils/hash.d.ts +0 -75
- package/dist/types/utils/hash.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts +0 -36
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/merchant-validator.d.ts +0 -176
- package/dist/types/utils/merchant-validator.d.ts.map +0 -1
- package/dist/types/utils/network-normalizer.d.ts +0 -120
- package/dist/types/utils/network-normalizer.d.ts.map +0 -1
- package/dist/types/utils/priority-fee.d.ts +0 -205
- package/dist/types/utils/priority-fee.d.ts.map +0 -1
- package/dist/types/utils/rpc-strategy.d.ts +0 -179
- package/dist/types/utils/rpc-strategy.d.ts.map +0 -1
- package/dist/types/utils/schemas.d.ts +0 -351
- package/dist/types/utils/schemas.d.ts.map +0 -1
- package/dist/types/utils/serialization.d.ts +0 -69
- package/dist/types/utils/serialization.d.ts.map +0 -1
- package/dist/types/utils/validation.d.ts +0 -29
- package/dist/types/utils/validation.d.ts.map +0 -1
- package/dist/types/utils/volume-curve.d.ts +0 -60
- package/dist/types/utils/volume-curve.d.ts.map +0 -1
- package/dist/types/utils/x402-direct.d.ts +0 -114
- package/dist/types/utils/x402-direct.d.ts.map +0 -1
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module utils/escrow-validation
|
|
3
|
-
* @description Server-side escrow validation pipeline.
|
|
4
|
-
*
|
|
5
|
-
* Provides typed helpers to validate escrow state before settlement
|
|
6
|
-
* and to build the correct SPL `AccountMeta[]` for token escrows.
|
|
7
|
-
*
|
|
8
|
-
* @category Utils
|
|
9
|
-
* @since v0.6.4
|
|
10
|
-
*/
|
|
11
|
-
import { PublicKey, type Connection, type AccountMeta } from "@solana/web3.js";
|
|
12
|
-
import { SapError } from "../errors";
|
|
13
|
-
import type { EscrowAccountData } from "../types";
|
|
14
|
-
/**
|
|
15
|
-
* @interface SplAccountMeta
|
|
16
|
-
* @description Typed SPL account metadata for escrow operations.
|
|
17
|
-
* @category Utils
|
|
18
|
-
* @since v0.6.4
|
|
19
|
-
*/
|
|
20
|
-
export interface SplAccountMeta {
|
|
21
|
-
/** Account role in the escrow pipeline. */
|
|
22
|
-
readonly kind: "escrowAta" | "depositorAta" | "tokenMint" | "tokenProgram";
|
|
23
|
-
/** Account public key. */
|
|
24
|
-
readonly pubkey: PublicKey;
|
|
25
|
-
/** Whether this account is writable. */
|
|
26
|
-
readonly writable: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @interface EscrowValidationResult
|
|
30
|
-
* @description Result of server-side escrow state validation.
|
|
31
|
-
* @category Utils
|
|
32
|
-
* @since v0.6.4
|
|
33
|
-
*/
|
|
34
|
-
export interface EscrowValidationResult {
|
|
35
|
-
/** Whether the escrow is valid for settlement. */
|
|
36
|
-
readonly valid: boolean;
|
|
37
|
-
/** Escrow account data (if found). */
|
|
38
|
-
readonly escrow: EscrowAccountData | null;
|
|
39
|
-
/** Escrow PDA address. */
|
|
40
|
-
readonly escrowPda: PublicKey;
|
|
41
|
-
/** Agent PDA address. */
|
|
42
|
-
readonly agentPda: PublicKey;
|
|
43
|
-
/** Whether this is an SPL token escrow (vs SOL). */
|
|
44
|
-
readonly isSplEscrow: boolean;
|
|
45
|
-
/** Generated SPL account metas (empty for SOL escrows). */
|
|
46
|
-
readonly splAccounts: SplAccountMeta[];
|
|
47
|
-
/** Validation errors (empty when valid). */
|
|
48
|
-
readonly errors: string[];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @name MissingEscrowAtaError
|
|
52
|
-
* @description Thrown when an SPL escrow operation is missing required
|
|
53
|
-
* Associated Token Accounts.
|
|
54
|
-
* @category Errors
|
|
55
|
-
* @since v0.6.4
|
|
56
|
-
*/
|
|
57
|
-
export declare class MissingEscrowAtaError extends SapError {
|
|
58
|
-
/** The ATA address that is missing. */
|
|
59
|
-
readonly ataAddress: string;
|
|
60
|
-
/** Which side is missing: depositor or escrow. */
|
|
61
|
-
readonly side: "depositor" | "escrow";
|
|
62
|
-
constructor(ataAddress: string, side: "depositor" | "escrow");
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @name validateEscrowState
|
|
66
|
-
* @description Validates that an escrow is in a correct state for settlement.
|
|
67
|
-
*
|
|
68
|
-
* Checks:
|
|
69
|
-
* - Escrow PDA exists on-chain
|
|
70
|
-
* - If SPL: depositor ATA exists, escrow ATA exists, token mint matches
|
|
71
|
-
* - Balance >= requested settlement amount
|
|
72
|
-
* - Escrow is not expired
|
|
73
|
-
* - Max calls not exceeded
|
|
74
|
-
*
|
|
75
|
-
* @param connection - Solana RPC connection.
|
|
76
|
-
* @param agentWallet - The agent's wallet public key.
|
|
77
|
-
* @param depositorWallet - The depositor's wallet public key.
|
|
78
|
-
* @param fetchEscrow - Callback to fetch escrow data (avoids coupling to SapProgram).
|
|
79
|
-
* @param opts
|
|
80
|
-
* @param opts.callsToSettle - Number of calls to validate affordability for.
|
|
81
|
-
*
|
|
82
|
-
* @returns A detailed {@link EscrowValidationResult}.
|
|
83
|
-
*
|
|
84
|
-
* @category Utils
|
|
85
|
-
* @since v0.6.4
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```ts
|
|
89
|
-
* const result = await validateEscrowState(
|
|
90
|
-
* connection,
|
|
91
|
-
* agentWallet,
|
|
92
|
-
* depositorWallet,
|
|
93
|
-
* (pda) => client.escrow.fetchByPda(pda),
|
|
94
|
-
* { callsToSettle: 5 },
|
|
95
|
-
* );
|
|
96
|
-
*
|
|
97
|
-
* if (!result.valid) {
|
|
98
|
-
* console.error("Escrow validation failed:", result.errors);
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare function validateEscrowState(connection: Connection, agentWallet: PublicKey, depositorWallet: PublicKey, fetchEscrow: (escrowPda: PublicKey) => Promise<EscrowAccountData | null>, opts?: {
|
|
103
|
-
callsToSettle?: number;
|
|
104
|
-
}): Promise<EscrowValidationResult>;
|
|
105
|
-
/**
|
|
106
|
-
* @name attachSplAccounts
|
|
107
|
-
* @description Build the typed `SplAccountMeta[]` for an SPL token escrow operation.
|
|
108
|
-
* Does NOT validate existence — use {@link validateEscrowState} for full validation.
|
|
109
|
-
*
|
|
110
|
-
* @param escrowPda - The escrow PDA address.
|
|
111
|
-
* @param depositorWallet - The depositor's wallet public key.
|
|
112
|
-
* @param tokenMint - The SPL token mint.
|
|
113
|
-
* @returns An array of typed {@link SplAccountMeta} for SPL escrow operations.
|
|
114
|
-
*
|
|
115
|
-
* @category Utils
|
|
116
|
-
* @since v0.6.4
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* const splMetas = attachSplAccounts(escrowPda, depositorWallet, usdcMint);
|
|
121
|
-
*
|
|
122
|
-
* // Convert to Anchor-compatible AccountMeta[]
|
|
123
|
-
* const accountMetas = splMetas.map(m => ({
|
|
124
|
-
* pubkey: m.pubkey,
|
|
125
|
-
* isWritable: m.writable,
|
|
126
|
-
* isSigner: false,
|
|
127
|
-
* }));
|
|
128
|
-
*
|
|
129
|
-
* await client.escrow.settle(depositor, calls, hash, accountMetas);
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export declare function attachSplAccounts(escrowPda: PublicKey, depositorWallet: PublicKey, tokenMint: PublicKey): SplAccountMeta[];
|
|
133
|
-
/**
|
|
134
|
-
* @name toAccountMetas
|
|
135
|
-
* @description Convert typed {@link SplAccountMeta} to Anchor-compatible
|
|
136
|
-
* `AccountMeta[]` for use with `.remainingAccounts()`.
|
|
137
|
-
*
|
|
138
|
-
* @param splMetas - Array of typed SPL account metas.
|
|
139
|
-
* @returns `AccountMeta[]` compatible with Anchor's `remainingAccounts`.
|
|
140
|
-
*
|
|
141
|
-
* @category Utils
|
|
142
|
-
* @since v0.6.4
|
|
143
|
-
*/
|
|
144
|
-
export declare function toAccountMetas(splMetas: SplAccountMeta[]): AccountMeta[];
|
|
145
|
-
//# sourceMappingURL=escrow-validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"escrow-validation.d.ts","sourceRoot":"","sources":["../../../src/utils/escrow-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMlD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,WAAW,GAAG,cAAc,CAAC;IAC3E,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,kDAAkD;IAClD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC1C,0BAA0B;IAC1B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAA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buffer.
|
|
10
|
-
*
|
|
11
|
-
* Returns a 32-byte `Uint8Array` suitable for PDA seeds
|
|
12
|
-
* and Anchor instruction arguments.
|
|
13
|
-
*
|
|
14
|
-
* @name sha256
|
|
15
|
-
* @description Hashes the input using Node’s `crypto.createHash("sha256")`.
|
|
16
|
-
* @param input - A UTF-8 string, `Buffer`, or `Uint8Array` to hash.
|
|
17
|
-
* @returns {Uint8Array} 32-byte SHA-256 digest.
|
|
18
|
-
* @category Utils
|
|
19
|
-
* @since v0.1.0
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { sha256 } from "@synapse-sap/sdk/utils";
|
|
23
|
-
*
|
|
24
|
-
* const hash = sha256("jupiter:swap"); // Uint8Array (32 bytes)
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare const sha256: (input: string | Buffer | Uint8Array) => Uint8Array;
|
|
28
|
-
/**
|
|
29
|
-
* Convert a `Uint8Array` hash to a plain `number[]`.
|
|
30
|
-
*
|
|
31
|
-
* Anchor instruction argument types expect `number[]` for hash fields
|
|
32
|
-
* rather than typed arrays.
|
|
33
|
-
*
|
|
34
|
-
* @name hashToArray
|
|
35
|
-
* @description Converts a byte array (typically 32 bytes) to a plain JavaScript `number[]`.
|
|
36
|
-
* @param hash - The byte array to convert.
|
|
37
|
-
* @returns {number[]} Shallow copy as a plain array of numbers.
|
|
38
|
-
* @category Utils
|
|
39
|
-
* @since v0.1.0
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { sha256, hashToArray } from "@synapse-sap/sdk/utils";
|
|
43
|
-
*
|
|
44
|
-
* const arr = hashToArray(sha256("jupiter:swap")); // number[]
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare const hashToArray: (hash: Uint8Array) => number[];
|
|
48
|
-
/**
|
|
49
|
-
* Compute the deterministic batch root used by `settle_batch` (v0.10.0).
|
|
50
|
-
*
|
|
51
|
-
* The on-chain program enforces:
|
|
52
|
-
* `batch_root == sha256(s_0 || s_1 || ... || s_{N-1})`
|
|
53
|
-
* where each `s_i` is a 32-byte service hash, in the same order as the
|
|
54
|
-
* `settlements: Settlement[]` array passed to the instruction.
|
|
55
|
-
*
|
|
56
|
-
* Use this helper to derive the seed for the {@link deriveSettlementReceipt}
|
|
57
|
-
* PDA when batching settlements.
|
|
58
|
-
*
|
|
59
|
-
* @name computeBatchRoot
|
|
60
|
-
* @param serviceHashes - Array of 32-byte service hashes (Buffer/Uint8Array/number[]).
|
|
61
|
-
* @returns {Uint8Array} 32-byte batch root.
|
|
62
|
-
* @throws If any `serviceHashes[i]` is not exactly 32 bytes long.
|
|
63
|
-
* @category Utils
|
|
64
|
-
* @since v0.10.0
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { computeBatchRoot, hashToArray } from "@synapse-sap/sdk/utils";
|
|
69
|
-
*
|
|
70
|
-
* const root = computeBatchRoot([h1, h2, h3]);
|
|
71
|
-
* await client.escrow.settleBatch(depositor, settlements, root);
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare const computeBatchRoot: (serviceHashes: ReadonlyArray<Uint8Array | Buffer | number[]>) => Uint8Array;
|
|
75
|
-
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,UAAU,KAAG,UAM5D,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,UAAU,KAAG,MAAM,EAAsB,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,eAAe,aAAa,CAAC,UAAU,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,KAC3D,UAyBF,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module utils
|
|
3
|
-
* @description Shared utilities used across SDK modules.
|
|
4
|
-
*
|
|
5
|
-
* @category Utils
|
|
6
|
-
* @since v0.1.0
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { sha256, hashToArray, assert } from "@synapse-sap/sdk/utils";
|
|
11
|
-
*
|
|
12
|
-
* const hash = sha256("jupiter:swap");
|
|
13
|
-
* const arr = hashToArray(hash); // number[] for Anchor args
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export { sha256, hashToArray, computeBatchRoot } from "./hash";
|
|
17
|
-
export { assert } from "./validation";
|
|
18
|
-
export { serializeAccount, serializeValue } from "./serialization";
|
|
19
|
-
export { normalizeNetworkId, isNetworkEquivalent, getNetworkGenesisHash, getNetworkClusterName, isKnownNetwork, } from "./network-normalizer";
|
|
20
|
-
export { validateEndpoint, validateEndpointDescriptor, validateHealthCheck, validateAgentEndpoints, } from "./endpoint-validator";
|
|
21
|
-
export type { ValidateEndpointOptions } from "./endpoint-validator";
|
|
22
|
-
export { getRpcUrl, getFallbackRpcUrl, createDualConnection, findATA, classifyAnchorError, extractAnchorErrorCode, } from "./rpc-strategy";
|
|
23
|
-
export type { RpcConfig, DualConnection, AtaResult } from "./rpc-strategy";
|
|
24
|
-
export { createEnvSchema, createEndpointDescriptorSchema, createHealthCheckSchema, createToolManifestEntrySchema, createAgentManifestSchema, createPreparePaymentSchema, createRegisterAgentSchema, createCallArgsSchema, validateOrThrow, } from "./schemas";
|
|
25
|
-
export { buildPriorityFeeIxs, buildRpcOptions, FAST_SETTLE_OPTIONS, FAST_BATCH_SETTLE_OPTIONS, DEFAULT_SETTLE_PRIORITY_FEE, DEFAULT_SETTLE_COMPUTE_UNITS, DEFAULT_BATCH_SETTLE_COMPUTE_UNITS, computeBatchSettleCu, } from "./priority-fee";
|
|
26
|
-
export type { PriorityFeeConfig, SettleOptions, } from "./priority-fee";
|
|
27
|
-
export { validateEscrowState, attachSplAccounts, toAccountMetas, MissingEscrowAtaError, } from "./escrow-validation";
|
|
28
|
-
export type { SplAccountMeta, EscrowValidationResult, } from "./escrow-validation";
|
|
29
|
-
export { SapMerchantValidator, parseX402Headers, } from "./merchant-validator";
|
|
30
|
-
export type { ParsedX402Headers, MerchantValidationResult, } from "./merchant-validator";
|
|
31
|
-
export { getX402DirectPayments } from "./x402-direct";
|
|
32
|
-
export type { X402DirectPayment, SettlementPayload, GetX402DirectOptions, } from "./x402-direct";
|
|
33
|
-
export { SAP_ERRORS, SAP_ERROR_BY_NAME, decodeAnchorError, SapPreflightError, throwPredicted, } from "./anchor-errors";
|
|
34
|
-
export type { SapErrorEntry, DecodedAnchorError, } from "./anchor-errors";
|
|
35
|
-
export { calculateSettleAmount } from "./volume-curve";
|
|
36
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGnE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEp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@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module utils/merchant-validator
|
|
3
|
-
* @description Standard Synapse merchant middleware for x402 settlement.
|
|
4
|
-
*
|
|
5
|
-
* Reads `X-Payment-*` headers from incoming HTTP requests, validates
|
|
6
|
-
* the escrow on-chain, auto-generates the correct `AccountMeta[]`,
|
|
7
|
-
* and throws explicit errors (e.g. {@link MissingEscrowAtaError})
|
|
8
|
-
* instead of letting the program return a generic crash.
|
|
9
|
-
*
|
|
10
|
-
* Designed for agents like Syra/Invoica that receive x402 payments.
|
|
11
|
-
*
|
|
12
|
-
* @category Utils
|
|
13
|
-
* @since v0.6.4
|
|
14
|
-
*/
|
|
15
|
-
import { type PublicKey, type Connection, type AccountMeta } from "@solana/web3.js";
|
|
16
|
-
import { BN } from "@coral-xyz/anchor";
|
|
17
|
-
import type { EscrowValidationResult } from "./escrow-validation";
|
|
18
|
-
import type { EscrowAccountData } from "../types";
|
|
19
|
-
/**
|
|
20
|
-
* @interface ParsedX402Headers
|
|
21
|
-
* @description Parsed and typed x402 payment headers from incoming HTTP request.
|
|
22
|
-
* @category Utils
|
|
23
|
-
* @since v0.6.4
|
|
24
|
-
*/
|
|
25
|
-
export interface ParsedX402Headers {
|
|
26
|
-
/** x402 protocol identifier — must be "SAP-x402". */
|
|
27
|
-
readonly protocol: string;
|
|
28
|
-
/** Escrow PDA address. */
|
|
29
|
-
readonly escrowPda: PublicKey;
|
|
30
|
-
/** Agent PDA address. */
|
|
31
|
-
readonly agentPda: PublicKey;
|
|
32
|
-
/** Depositor wallet address. */
|
|
33
|
-
readonly depositorWallet: PublicKey;
|
|
34
|
-
/** Max calls allowed. */
|
|
35
|
-
readonly maxCalls: BN;
|
|
36
|
-
/** Price per call. */
|
|
37
|
-
readonly pricePerCall: BN;
|
|
38
|
-
/** SAP program ID. */
|
|
39
|
-
readonly programId: PublicKey;
|
|
40
|
-
/** Network identifier. */
|
|
41
|
-
readonly network: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @interface MerchantValidationResult
|
|
45
|
-
* @description Complete validation result for merchant-side x402 processing.
|
|
46
|
-
* @category Utils
|
|
47
|
-
* @since v0.6.4
|
|
48
|
-
*/
|
|
49
|
-
export interface MerchantValidationResult {
|
|
50
|
-
/** Whether the escrow is valid and ready for settlement. */
|
|
51
|
-
readonly valid: boolean;
|
|
52
|
-
/** Parsed x402 headers. */
|
|
53
|
-
readonly headers: ParsedX402Headers;
|
|
54
|
-
/** Full escrow validation result. */
|
|
55
|
-
readonly escrowValidation: EscrowValidationResult;
|
|
56
|
-
/** Pre-built AccountMeta[] for settlement TX (empty for SOL escrows). */
|
|
57
|
-
readonly accountMetas: AccountMeta[];
|
|
58
|
-
/** All validation errors. */
|
|
59
|
-
readonly errors: string[];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @name parseX402Headers
|
|
63
|
-
* @description Parse and validate x402 headers from an HTTP request.
|
|
64
|
-
*
|
|
65
|
-
* @param headers - HTTP headers object (case-insensitive key lookup).
|
|
66
|
-
* @returns Parsed x402 headers.
|
|
67
|
-
* @throws {SapValidationError} If required headers are missing or malformed.
|
|
68
|
-
*
|
|
69
|
-
* @category Utils
|
|
70
|
-
* @since v0.6.4
|
|
71
|
-
*/
|
|
72
|
-
export declare function parseX402Headers(headers: Record<string, string | string[] | undefined>): ParsedX402Headers;
|
|
73
|
-
/**
|
|
74
|
-
* @name SapMerchantValidator
|
|
75
|
-
* @description Standard Synapse merchant middleware for x402 payment validation.
|
|
76
|
-
*
|
|
77
|
-
* Reads `X-Payment-*` headers, validates escrow state on-chain, generates
|
|
78
|
-
* correct `AccountMeta[]` for SPL token escrows, and throws explicit errors
|
|
79
|
-
* (e.g. {@link MissingEscrowAtaError}) when ATA accounts are missing.
|
|
80
|
-
*
|
|
81
|
-
* @category Utils
|
|
82
|
-
* @since v0.6.4
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const validator = new SapMerchantValidator(connection, fetchEscrow);
|
|
87
|
-
*
|
|
88
|
-
* // Express.js integration
|
|
89
|
-
* app.post("/api/v1/chat", async (req, res) => {
|
|
90
|
-
* try {
|
|
91
|
-
* const validation = await validator.validateRequest(req.headers, {
|
|
92
|
-
* callsToSettle: 1,
|
|
93
|
-
* });
|
|
94
|
-
*
|
|
95
|
-
* if (!validation.valid) {
|
|
96
|
-
* return res.status(402).json({ errors: validation.errors });
|
|
97
|
-
* }
|
|
98
|
-
*
|
|
99
|
-
* // Process request...
|
|
100
|
-
*
|
|
101
|
-
* // Settle payment using pre-built account metas
|
|
102
|
-
* await client.escrow.settle(
|
|
103
|
-
* validation.headers.depositorWallet,
|
|
104
|
-
* 1,
|
|
105
|
-
* serviceHash,
|
|
106
|
-
* validation.accountMetas,
|
|
107
|
-
* );
|
|
108
|
-
*
|
|
109
|
-
* res.json({ result: "..." });
|
|
110
|
-
* } catch (err) {
|
|
111
|
-
* if (err instanceof MissingEscrowAtaError) {
|
|
112
|
-
* return res.status(402).json({
|
|
113
|
-
* error: err.message,
|
|
114
|
-
* side: err.side,
|
|
115
|
-
* ata: err.ataAddress,
|
|
116
|
-
* });
|
|
117
|
-
* }
|
|
118
|
-
* throw err;
|
|
119
|
-
* }
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export declare class SapMerchantValidator {
|
|
124
|
-
private readonly connection;
|
|
125
|
-
private readonly fetchEscrow;
|
|
126
|
-
/**
|
|
127
|
-
* @param connection - Solana RPC connection.
|
|
128
|
-
* @param fetchEscrow - Callback to fetch escrow account data by PDA.
|
|
129
|
-
* Typically `(pda) => client.escrow.fetchByPda(pda).catch(() => null)`.
|
|
130
|
-
*/
|
|
131
|
-
constructor(connection: Connection, fetchEscrow: (escrowPda: PublicKey) => Promise<EscrowAccountData | null>);
|
|
132
|
-
/**
|
|
133
|
-
* @name validateRequest
|
|
134
|
-
* @description Full validation pipeline for an incoming x402 request.
|
|
135
|
-
*
|
|
136
|
-
* Steps:
|
|
137
|
-
* 1. Parse `X-Payment-*` headers
|
|
138
|
-
* 2. Fetch escrow on-chain
|
|
139
|
-
* 3. Validate escrow state (balance, expiry, max calls)
|
|
140
|
-
* 4. If SPL escrow: validate ATAs exist and mint matches
|
|
141
|
-
* 5. Build `AccountMeta[]` for settlement TX
|
|
142
|
-
*
|
|
143
|
-
* @param headers - HTTP headers from the incoming request.
|
|
144
|
-
* @param opts
|
|
145
|
-
* @param opts.callsToSettle - Number of calls to validate affordability for (default: 1).
|
|
146
|
-
* @param opts.throwOnMissingAta - Throw {@link MissingEscrowAtaError} instead of returning errors (default: true).
|
|
147
|
-
*
|
|
148
|
-
* @returns A complete {@link MerchantValidationResult}.
|
|
149
|
-
*
|
|
150
|
-
* @throws {SapValidationError} If headers are missing or malformed.
|
|
151
|
-
* @throws {MissingEscrowAtaError} If SPL ATAs are missing and `throwOnMissingAta` is true.
|
|
152
|
-
*
|
|
153
|
-
* @category Utils
|
|
154
|
-
* @since v0.6.4
|
|
155
|
-
*/
|
|
156
|
-
validateRequest(headers: Record<string, string | string[] | undefined>, opts?: {
|
|
157
|
-
callsToSettle?: number;
|
|
158
|
-
throwOnMissingAta?: boolean;
|
|
159
|
-
}): Promise<MerchantValidationResult>;
|
|
160
|
-
/**
|
|
161
|
-
* @name validateEscrow
|
|
162
|
-
* @description Validate escrow from pre-parsed headers (convenience method).
|
|
163
|
-
* Call this when you've already parsed the headers yourself.
|
|
164
|
-
*
|
|
165
|
-
* @param headers - Pre-parsed x402 headers.
|
|
166
|
-
* @param opts
|
|
167
|
-
* @returns The escrow validation result with pre-built account metas.
|
|
168
|
-
*
|
|
169
|
-
* @category Utils
|
|
170
|
-
* @since v0.6.4
|
|
171
|
-
*/
|
|
172
|
-
validateEscrow(headers: ParsedX402Headers, opts?: {
|
|
173
|
-
callsToSettle?: number;
|
|
174
|
-
}): Promise<EscrowValidationResult>;
|
|
175
|
-
}
|
|
176
|
-
//# sourceMappingURL=merchant-validator.d.ts.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B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAC3B;AAkBD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD,iBAAiB,CA6EnB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAEW;IAEvC;;;;OAIG;gBAED,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,CACX,SAAS,EAAE,SAAS,KACjB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAMxC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,eAAe,CACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,EACtD,IAAI,CAAC,EAAE;QACL,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GACA,OAAO,CAAC,wBAAwB,CAAC;IAwCpC;;;;;;;;;;;OAWG;IACG,cAAc,CAClB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAChC,OAAO,CAAC,sBAAsB,CAAC;CASnC"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module utils/network-normalizer
|
|
3
|
-
* @description Network identifier normalization for x402 payment headers.
|
|
4
|
-
*
|
|
5
|
-
* Solves the canonical-string mismatch between SAP clients and servers:
|
|
6
|
-
* some providers accept `solana:mainnet-beta` while others require
|
|
7
|
-
* the genesis-hash form `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
8
|
-
*
|
|
9
|
-
* This module provides a single source of truth for normalizing
|
|
10
|
-
* network identifiers so that both clients and agents canonicalize
|
|
11
|
-
* before comparing. Catches the Kamiyo "sap network mismatch" error
|
|
12
|
-
* at the SDK level.
|
|
13
|
-
*
|
|
14
|
-
* @category Utils
|
|
15
|
-
* @since v0.6.0
|
|
16
|
-
*/
|
|
17
|
-
import { type SapNetworkId } from "../constants/network";
|
|
18
|
-
/**
|
|
19
|
-
* @name normalizeNetworkId
|
|
20
|
-
* @description Normalize a raw network identifier string to its canonical
|
|
21
|
-
* {@link SapNetworkId} form.
|
|
22
|
-
*
|
|
23
|
-
* Handles:
|
|
24
|
-
* - Case-insensitive matching
|
|
25
|
-
* - Stripping whitespace
|
|
26
|
-
* - Resolving genesis-hash vs. cluster-name aliases
|
|
27
|
-
* - Unknown strings are returned as-is (passthrough)
|
|
28
|
-
*
|
|
29
|
-
* @param raw - Raw network identifier string from headers, env vars, or config.
|
|
30
|
-
* @returns The canonical {@link SapNetworkId}, or the trimmed input if unknown.
|
|
31
|
-
*
|
|
32
|
-
* @category Utils
|
|
33
|
-
* @since v0.6.0
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { normalizeNetworkId } from "@synapse-sap/sdk";
|
|
38
|
-
*
|
|
39
|
-
* normalizeNetworkId("solana:mainnet-beta");
|
|
40
|
-
* // → "solana:mainnet-beta"
|
|
41
|
-
*
|
|
42
|
-
* normalizeNetworkId("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp");
|
|
43
|
-
* // → "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
44
|
-
*
|
|
45
|
-
* normalizeNetworkId(" MAINNET ");
|
|
46
|
-
* // → "solana:mainnet-beta"
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function normalizeNetworkId(raw: string): SapNetworkId | string;
|
|
50
|
-
/**
|
|
51
|
-
* @name isNetworkEquivalent
|
|
52
|
-
* @description Check if two network identifier strings refer to the same network,
|
|
53
|
-
* even if they use different formats (cluster-name vs. genesis-hash).
|
|
54
|
-
*
|
|
55
|
-
* This is the key function that prevents the Kamiyo "sap network mismatch"
|
|
56
|
-
* error — instead of comparing strings literally, we compare their
|
|
57
|
-
* canonical equivalence class.
|
|
58
|
-
*
|
|
59
|
-
* @param a - First network identifier.
|
|
60
|
-
* @param b - Second network identifier.
|
|
61
|
-
* @returns `true` if both identifiers refer to the same Solana network.
|
|
62
|
-
*
|
|
63
|
-
* @category Utils
|
|
64
|
-
* @since v0.6.0
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { isNetworkEquivalent } from "@synapse-sap/sdk";
|
|
69
|
-
*
|
|
70
|
-
* isNetworkEquivalent("solana:mainnet-beta", "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp");
|
|
71
|
-
* // → true
|
|
72
|
-
*
|
|
73
|
-
* isNetworkEquivalent("solana:devnet", "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1");
|
|
74
|
-
* // → true
|
|
75
|
-
*
|
|
76
|
-
* isNetworkEquivalent("solana:mainnet-beta", "solana:devnet");
|
|
77
|
-
* // → false
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export declare function isNetworkEquivalent(a: string, b: string): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* @name getNetworkGenesisHash
|
|
83
|
-
* @description Get the genesis-hash form of a network identifier.
|
|
84
|
-
* Returns the genesis-hash variant for known networks, or the input as-is.
|
|
85
|
-
*
|
|
86
|
-
* Useful for agents that require the genesis-hash form (Kamiyo, Helius x402).
|
|
87
|
-
*
|
|
88
|
-
* @param networkId - Any network identifier.
|
|
89
|
-
* @returns The genesis-hash form, or the input if unknown.
|
|
90
|
-
*
|
|
91
|
-
* @category Utils
|
|
92
|
-
* @since v0.6.0
|
|
93
|
-
*/
|
|
94
|
-
export declare function getNetworkGenesisHash(networkId: string): string;
|
|
95
|
-
/**
|
|
96
|
-
* @name getNetworkClusterName
|
|
97
|
-
* @description Get the cluster-name form of a network identifier.
|
|
98
|
-
* Returns the human-readable cluster name for known networks.
|
|
99
|
-
*
|
|
100
|
-
* Useful for providers that accept cluster names (Coinbase, Phantom).
|
|
101
|
-
*
|
|
102
|
-
* @param networkId - Any network identifier.
|
|
103
|
-
* @returns The cluster-name form, or the input if unknown.
|
|
104
|
-
*
|
|
105
|
-
* @category Utils
|
|
106
|
-
* @since v0.6.0
|
|
107
|
-
*/
|
|
108
|
-
export declare function getNetworkClusterName(networkId: string): string;
|
|
109
|
-
/**
|
|
110
|
-
* @name isKnownNetwork
|
|
111
|
-
* @description Check if a network identifier is recognized by the SDK.
|
|
112
|
-
*
|
|
113
|
-
* @param networkId - The network identifier to check.
|
|
114
|
-
* @returns `true` if the identifier maps to a known Solana network.
|
|
115
|
-
*
|
|
116
|
-
* @category Utils
|
|
117
|
-
* @since v0.6.0
|
|
118
|
-
*/
|
|
119
|
-
export declare function isKnownNetwork(networkId: string): boolean;
|
|
120
|
-
//# sourceMappingURL=network-normalizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-normalizer.d.ts","sourceRoot":"","sources":["../../../src/utils/network-normalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAsDrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,MAAM,CAcrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CA2BjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAIzD"}
|