@oobe-protocol-labs/synapse-sap-sdk 0.12.9 → 0.13.0
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/modules/base.js +61 -0
- package/dist/cjs/modules/base.js.map +1 -1
- package/dist/cjs/modules/escrow-v2.js +153 -0
- package/dist/cjs/modules/escrow-v2.js.map +1 -1
- package/dist/cjs/modules/escrow.js +36 -0
- package/dist/cjs/modules/escrow.js.map +1 -1
- package/dist/cjs/modules/staking.js +35 -0
- package/dist/cjs/modules/staking.js.map +1 -1
- package/dist/cjs/modules/tools.js +26 -0
- package/dist/cjs/modules/tools.js.map +1 -1
- package/dist/cjs/modules/vault.js +17 -0
- package/dist/cjs/modules/vault.js.map +1 -1
- package/dist/cjs/utils/anchor-errors.js +453 -0
- package/dist/cjs/utils/anchor-errors.js.map +1 -0
- package/dist/cjs/utils/index.js +12 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/volume-curve.js +117 -0
- package/dist/cjs/utils/volume-curve.js.map +1 -0
- package/dist/esm/modules/base.js +61 -0
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/escrow-v2.js +153 -0
- package/dist/esm/modules/escrow-v2.js.map +1 -1
- package/dist/esm/modules/escrow.js +36 -0
- package/dist/esm/modules/escrow.js.map +1 -1
- package/dist/esm/modules/staking.js +35 -0
- package/dist/esm/modules/staking.js.map +1 -1
- package/dist/esm/modules/tools.js +26 -0
- package/dist/esm/modules/tools.js.map +1 -1
- package/dist/esm/modules/vault.js +17 -0
- package/dist/esm/modules/vault.js.map +1 -1
- package/dist/esm/utils/anchor-errors.js +447 -0
- package/dist/esm/utils/anchor-errors.js.map +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/volume-curve.js +114 -0
- package/dist/esm/utils/volume-curve.js.map +1 -0
- package/dist/types/modules/base.d.ts +35 -0
- package/dist/types/modules/base.d.ts.map +1 -1
- package/dist/types/modules/escrow-v2.d.ts +70 -1
- package/dist/types/modules/escrow-v2.d.ts.map +1 -1
- package/dist/types/modules/escrow.d.ts.map +1 -1
- package/dist/types/modules/staking.d.ts.map +1 -1
- package/dist/types/modules/tools.d.ts.map +1 -1
- package/dist/types/modules/vault.d.ts.map +1 -1
- package/dist/types/utils/anchor-errors.d.ts +61 -0
- package/dist/types/utils/anchor-errors.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/volume-curve.d.ts +60 -0
- package/dist/types/utils/volume-curve.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/modules/base.ts +89 -0
- package/src/modules/escrow-v2.ts +214 -1
- package/src/modules/escrow.ts +56 -0
- package/src/modules/staking.ts +66 -0
- package/src/modules/tools.ts +43 -0
- package/src/modules/vault.ts +25 -0
- package/src/utils/anchor-errors.ts +461 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/volume-curve.ts +131 -0
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type AnchorProvider, type Program, BN } from "@coral-xyz/anchor";
|
|
13
13
|
import type { PublicKey, TransactionSignature } from "@solana/web3.js";
|
|
14
|
+
import { SAP_ERROR_BY_NAME } from "../utils/anchor-errors";
|
|
14
15
|
/**
|
|
15
16
|
* Anchor `Program` instance typed for the Synapse Agent SAP IDL.
|
|
16
17
|
*
|
|
@@ -122,5 +123,39 @@ export declare abstract class BaseModule {
|
|
|
122
123
|
* @since v0.1.0
|
|
123
124
|
*/
|
|
124
125
|
protected bn(value: number | bigint | BN): BN;
|
|
126
|
+
/**
|
|
127
|
+
* @name requireAccountExists
|
|
128
|
+
* @description Fetch a required account; throw a {@link SapPreflightError}
|
|
129
|
+
* with an actionable message if it does not exist.
|
|
130
|
+
* @typeParam T - Expected account type.
|
|
131
|
+
* @param accountName - Anchor account discriminator name.
|
|
132
|
+
* @param address - PDA to fetch.
|
|
133
|
+
* @param onMissing - `{ predicted, hint }` describing the on-chain rejection
|
|
134
|
+
* that would otherwise occur.
|
|
135
|
+
* @protected
|
|
136
|
+
* @since v0.13.0
|
|
137
|
+
*/
|
|
138
|
+
protected requireAccountExists<T>(accountName: string, address: PublicKey, onMissing: {
|
|
139
|
+
predicted: keyof typeof SAP_ERROR_BY_NAME;
|
|
140
|
+
hint?: string;
|
|
141
|
+
}): Promise<T>;
|
|
142
|
+
/**
|
|
143
|
+
* @name requireAccountAbsent
|
|
144
|
+
* @description Verify a PDA does not yet exist on-chain. Used before any
|
|
145
|
+
* `init` instruction to catch `account already in use` early.
|
|
146
|
+
* @protected
|
|
147
|
+
* @since v0.13.0
|
|
148
|
+
*/
|
|
149
|
+
protected requireAccountAbsent(accountName: string, address: PublicKey, hint: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* @name simulateOrThrow
|
|
152
|
+
* @description Run `simulate()` on a method builder. If the simulation
|
|
153
|
+
* reports a SAP program error, throw it as a {@link SapPreflightError}
|
|
154
|
+
* with the decoded name + friendly hint *before* the user pays fees.
|
|
155
|
+
* Returns the simulation logs on success for inspection.
|
|
156
|
+
* @protected
|
|
157
|
+
* @since v0.13.0
|
|
158
|
+
*/
|
|
159
|
+
protected simulateOrThrow(builder: any, label: string): Promise<readonly string[]>;
|
|
125
160
|
}
|
|
126
161
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"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EAClB,SAAS,EAAE;QAAE,SAAS,EAAE,MAAM,OAAO,iBAAiB,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACtE,OAAO,CAAC,CAAC,CAAC;IAQb;;;;;;OAMG;cACa,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;;OAQG;cACa,eAAe,CAE7B,OAAO,EAAE,GAAG,EACZ,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;CAoB9B"}
|
|
@@ -30,7 +30,58 @@ export declare class EscrowV2Module extends BaseModule {
|
|
|
30
30
|
deriveDispute(pendingSettlementPda: PublicKey): readonly [PublicKey, number];
|
|
31
31
|
create(agentWallet: PublicKey, args: CreateEscrowV2Args, splAccounts?: AccountMeta[]): Promise<TransactionSignature>;
|
|
32
32
|
deposit(agentWallet: PublicKey, nonce: BN | number | bigint, amount: BN | number | bigint, splAccounts?: AccountMeta[]): Promise<TransactionSignature>;
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Settle a batch of calls against a V2 escrow.
|
|
35
|
+
*
|
|
36
|
+
* **v0.13.0 — Auto-bundle DisputeWindow:** when the escrow's
|
|
37
|
+
* `settlementSecurity` is `DisputeWindow`, this method now bundles
|
|
38
|
+
* **`settleCallsV2` + `createPendingSettlement`** into the SAME
|
|
39
|
+
* transaction. This eliminates the foot-gun where a caller would call
|
|
40
|
+
* `createPendingSettlement` directly without a preceding `settleCallsV2`,
|
|
41
|
+
* leaving `escrow.pending_amount = 0` and causing `finalizeSettlement`
|
|
42
|
+
* to abort with `ArithmeticOverflow` (6075).
|
|
43
|
+
*
|
|
44
|
+
* Flow per security mode:
|
|
45
|
+
* - **CoSigned** — single IX (`settleCallsV2`) with co-signer in
|
|
46
|
+
* remaining accounts; funds move immediately.
|
|
47
|
+
* - **DisputeWindow** — two IXs in one tx:
|
|
48
|
+
* 1. `settleCallsV2` — bumps `pending_amount` and `settlement_index`
|
|
49
|
+
* 2. `createPendingSettlement(idx)` — locks the dispute tracker PDA
|
|
50
|
+
*
|
|
51
|
+
* After this tx confirms, wait `escrow.disputeWindowSlots` slots and
|
|
52
|
+
* call {@link finalizeSettlement} with the index returned via
|
|
53
|
+
* `SettlementPendingEvent` or readable from `escrow.settlement_index - 1`.
|
|
54
|
+
*
|
|
55
|
+
* Pass `opts.skipAutoPending = true` to opt out of the auto-bundle (e.g.
|
|
56
|
+
* if you want to drive `createPendingSettlement` separately for advanced
|
|
57
|
+
* flows like batched off-chain receipt aggregation).
|
|
58
|
+
*
|
|
59
|
+
* @param depositorWallet - Depositor of the escrow being settled.
|
|
60
|
+
* @param nonce - Escrow nonce (default 0 for the canonical escrow).
|
|
61
|
+
* @param callsToSettle - Number of calls to settle in this batch.
|
|
62
|
+
* @param serviceHash - 32-byte sha256 of the service payload.
|
|
63
|
+
* @param splAccounts - Optional remaining accounts (SPL transfer + co-signer).
|
|
64
|
+
* @param opts - Priority-fee + auto-pending options.
|
|
65
|
+
* @param coSigner - Required for CoSigned escrows.
|
|
66
|
+
* @returns The transaction signature.
|
|
67
|
+
* @since v0.7.0 — initial release
|
|
68
|
+
* @since v0.13.0 — auto-bundles `createPendingSettlement` for DisputeWindow
|
|
69
|
+
*/
|
|
70
|
+
settle(depositorWallet: PublicKey, nonce: BN | number | bigint, callsToSettle: BN | number | bigint, serviceHash: number[], splAccounts?: AccountMeta[], opts?: SettleOptions & {
|
|
71
|
+
/**
|
|
72
|
+
* v0.13.0 — Opt out of the DisputeWindow auto-bundle. When `true`,
|
|
73
|
+
* `settle()` only emits `settleCallsV2` and the caller is responsible
|
|
74
|
+
* for sending `createPendingSettlement` afterwards (legacy 2-tx flow).
|
|
75
|
+
* Default: `false` (auto-bundle is on).
|
|
76
|
+
*/
|
|
77
|
+
skipAutoPending?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* v0.13.0 — `receiptMerkleRoot` to inscribe in the auto-bundled
|
|
80
|
+
* `createPendingSettlement`. Defaults to 32 zero bytes (no receipt
|
|
81
|
+
* batch). Ignored when `skipAutoPending = true`.
|
|
82
|
+
*/
|
|
83
|
+
receiptMerkleRoot?: number[];
|
|
84
|
+
}, coSigner?: Signer): Promise<TransactionSignature>;
|
|
34
85
|
/**
|
|
35
86
|
* Read the current `escrow.settlement_index` from chain.
|
|
36
87
|
*
|
|
@@ -45,6 +96,24 @@ export declare class EscrowV2Module extends BaseModule {
|
|
|
45
96
|
* @since v0.12.8
|
|
46
97
|
*/
|
|
47
98
|
nextSettlementIndex(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint): Promise<bigint>;
|
|
99
|
+
/**
|
|
100
|
+
* Create the PendingSettlement PDA for a DisputeWindow batch.
|
|
101
|
+
*
|
|
102
|
+
* **v0.13.0 NOTE:** in almost all cases you should call
|
|
103
|
+
* {@link settle} instead — it auto-bundles `settleCallsV2 +
|
|
104
|
+
* createPendingSettlement` in a single transaction so the two
|
|
105
|
+
* cannot drift out of sync. Use this method standalone ONLY when
|
|
106
|
+
* you intentionally pass `skipAutoPending: true` to `settle()`
|
|
107
|
+
* (e.g. batched receipt-merkle aggregation across multiple
|
|
108
|
+
* `settleCallsV2` runs).
|
|
109
|
+
*
|
|
110
|
+
* Calling this without a preceding `settleCallsV2` (which bumps
|
|
111
|
+
* `escrow.pending_amount`) creates an orphan PDA whose
|
|
112
|
+
* `pending.amount > escrow.pending_amount` — `finalizeSettlement`
|
|
113
|
+
* will then abort with `ArithmeticOverflow` (6075) forever.
|
|
114
|
+
*
|
|
115
|
+
* @since v0.7.0
|
|
116
|
+
*/
|
|
48
117
|
createPendingSettlement(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint, callsToSettle: BN | number | bigint, amount: BN | number | bigint, serviceHash: number[], receiptMerkleRoot?: number[]): Promise<TransactionSignature>;
|
|
49
118
|
finalizeSettlement(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint): Promise<TransactionSignature>;
|
|
50
119
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow-v2.d.ts","sourceRoot":"","sources":["../../../src/modules/escrow-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAUpC,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAKlB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"escrow-v2.d.ts","sourceRoot":"","sources":["../../../src/modules/escrow-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAUpC,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAKlB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK3D;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAG5C,oEAAoE;IACpE,OAAO,CAAC,KAAK;IAMb,YAAY,CACV,QAAQ,EAAE,SAAS,EACnB,SA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AAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAI9D,sBAAsB,CAC1B,UAAU,EAAE,SAAS,GACpB,OAAO,CAAC,qBAAqB,CAAC;IAI3B,8BAA8B,CAClC,UAAU,EAAE,SAAS,GACpB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAIlC,YAAY,CAChB,UAAU,EAAE,SAAS,GACpB,OAAO,CAAC,iBAAiB,CAAC;IAIvB,oBAAoB,CACxB,UAAU,EAAE,SAAS,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAGrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/modules/escrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAQpC,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACX,MAAM,UAAU,CAAC;AAMlB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/modules/escrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAQpC,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACX,MAAM,UAAU,CAAC;AAMlB,OA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ACxC,WAAW,GAAE,WAAW,EAAO,EAC/B,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,oBAAoB,CAAC;IAgDhC;;;;;;;;OAQG;IACG,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAKnF;;;;;;;;OAQG;IACG,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAKlG;;;;;;;;OAQG;IACG,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../../src/modules/staking.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../../src/modules/staking.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAO/C;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAG3C,WAAW,CAAC,QAAQ,EAAE,SAAS,GAAG,S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S,EACnB,WAAW,EAAE,UAAU,GACtB,OAAO,CAAC,iBAAiB,CAAC;IAK7B;;;;;;;;OAQG;IACG,iBAAiB,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI1E;;;;;;;;OAQG;IACG,cAAc,CAClB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAKzB;;;;;;;;OAQG;IACG,aAAa,CACjB,QAAQ,EAAE,SAAS,EACnB,cAAc,EAAE,SAAS,GACxB,OAAO,CAAC,iBAAiB,CAAC;CAI9B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils/anchor-errors
|
|
3
|
+
* @description Full SAP program error table (147 entries, codes 6000-6146)
|
|
4
|
+
* plus decoder utilities. Mirrors `programs/synapse-agent-sap/src/errors.rs`.
|
|
5
|
+
*
|
|
6
|
+
* Use {@link decodeAnchorError} to extract a structured error from any
|
|
7
|
+
* thrown RPC / simulation error. Use {@link SAP_ERRORS} for direct lookups.
|
|
8
|
+
*
|
|
9
|
+
* @category Utils
|
|
10
|
+
* @since v0.13.0
|
|
11
|
+
*/
|
|
12
|
+
export interface SapErrorEntry {
|
|
13
|
+
readonly code: number;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly msg: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const SAP_ERRORS: Readonly<Record<number, SapErrorEntry>>;
|
|
18
|
+
export declare const SAP_ERROR_BY_NAME: Readonly<Record<string, number>>;
|
|
19
|
+
/**
|
|
20
|
+
* @name DecodedAnchorError
|
|
21
|
+
* @description Structured error extracted from a thrown RPC/simulation error.
|
|
22
|
+
* @since v0.13.0
|
|
23
|
+
*/
|
|
24
|
+
export interface DecodedAnchorError {
|
|
25
|
+
readonly code: number;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly msg: string;
|
|
28
|
+
readonly friendly: string;
|
|
29
|
+
readonly logs?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @name decodeAnchorError
|
|
33
|
+
* @description Pull an Anchor / SAP error out of any caught value.
|
|
34
|
+
* Handles: AnchorError, raw RPC SimulateError, `0x...` hex codes,
|
|
35
|
+
* nested `error.errorCode.number`, and direct `code` numbers.
|
|
36
|
+
* @returns Structured {@link DecodedAnchorError} or `null` if not a SAP error.
|
|
37
|
+
* @since v0.13.0
|
|
38
|
+
*/
|
|
39
|
+
export declare function decodeAnchorError(err: unknown): DecodedAnchorError | null;
|
|
40
|
+
/**
|
|
41
|
+
* @name SapPreflightError
|
|
42
|
+
* @description Thrown by SDK preflights when an on-chain check is guaranteed
|
|
43
|
+
* to fail. Carries the predicted error code/name so callers can branch
|
|
44
|
+
* without parsing strings.
|
|
45
|
+
* @since v0.13.0
|
|
46
|
+
*/
|
|
47
|
+
export declare class SapPreflightError extends Error {
|
|
48
|
+
readonly predictedCode: number;
|
|
49
|
+
readonly predictedName: string;
|
|
50
|
+
readonly hint?: string | undefined;
|
|
51
|
+
readonly preflight: true;
|
|
52
|
+
constructor(message: string, predictedCode: number, predictedName: string, hint?: string | undefined);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @name throwPredicted
|
|
56
|
+
* @description Helper for SDK preflights. Throws a {@link SapPreflightError}
|
|
57
|
+
* carrying the on-chain error name + friendly message.
|
|
58
|
+
* @since v0.13.0
|
|
59
|
+
*/
|
|
60
|
+
export declare function throwPredicted(name: keyof typeof SAP_ERROR_BY_NAME, hint?: string): never;
|
|
61
|
+
//# sourceMappingURL=anchor-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor-errors.d.ts","sourceRoot":"","sources":["../../../src/utils/anchor-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,aAAa;IAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CAAE;AACtG,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAoJ7D,CAAC;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoJ7D,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAmCD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAwBzE;AAsCD;;;;;;GAMG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAIxC,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IALxB,QAAQ,CAAC,SAAS,EAAG,IAAI,CAAU;gBAEjC,OAAO,EAAE,MAAM,EACN,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,MAAM,YAAA;CAKzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,OAAO,iBAAiB,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAMzF"}
|
|
@@ -30,4 +30,7 @@ export { SapMerchantValidator, parseX402Headers, } from "./merchant-validator";
|
|
|
30
30
|
export type { ParsedX402Headers, MerchantValidationResult, } from "./merchant-validator";
|
|
31
31
|
export { getX402DirectPayments } from "./x402-direct";
|
|
32
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";
|
|
33
36
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;AAEpE,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,OAAO,EACP,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,GAChB,MAAM,WAAW,C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
+
* @module volume-curve
|
|
3
|
+
* @description Client-side mirror of the on-chain `calculate_settle_amount`
|
|
4
|
+
* function from `programs/synapse-agent-sap/src/instructions/escrow_v2.rs`.
|
|
5
|
+
*
|
|
6
|
+
* Used by {@link EscrowV2Module.settle} to pre-compute the settlement
|
|
7
|
+
* `amount` so it can chain `createPendingSettlement` in the same transaction
|
|
8
|
+
* as `settleCallsV2` (DisputeWindow flow). Keeping the math in one place
|
|
9
|
+
* here ensures the SDK stays byte-for-byte aligned with the program; if the
|
|
10
|
+
* on-chain curve algorithm ever changes, this file is the single source of
|
|
11
|
+
* truth on the client.
|
|
12
|
+
*
|
|
13
|
+
* @category Utilities
|
|
14
|
+
* @since v0.13.0
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import { BN } from "@coral-xyz/anchor";
|
|
18
|
+
import type { VolumeCurveBreakpoint } from "../types/common";
|
|
19
|
+
/**
|
|
20
|
+
* @function calculateSettleAmount
|
|
21
|
+
* @description Compute the lamport (or token base-unit) amount the on-chain
|
|
22
|
+
* `settle_calls_v2` handler will charge for `calls` calls, given the escrow's
|
|
23
|
+
* `pricePerCall`, `volumeCurve`, and the current settled+pending counter.
|
|
24
|
+
*
|
|
25
|
+
* Mirrors the exact algorithm of `calculate_settle_amount` in
|
|
26
|
+
* `escrow_v2.rs` (v0.7+):
|
|
27
|
+
*
|
|
28
|
+
* ```rust
|
|
29
|
+
* if curve.is_empty() { calls * base_price } else { walk-the-curve }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Walks the curve from `cursor = totalCallsBefore` and at each cursor
|
|
33
|
+
* position picks the breakpoint price whose `afterCalls` threshold the
|
|
34
|
+
* cursor has passed. Calls are charged at the active price up to the next
|
|
35
|
+
* threshold, then the cursor advances and the loop repeats until all
|
|
36
|
+
* `calls` are accounted for.
|
|
37
|
+
*
|
|
38
|
+
* @param basePrice - Escrow's `pricePerCall` (BN, u64 lamports/base-units).
|
|
39
|
+
* @param curve - The escrow's `volumeCurve` array (may be empty).
|
|
40
|
+
* @param totalCallsBefore - `escrow.totalCallsSettled + escrow.pendingCalls`
|
|
41
|
+
* AT THE MOMENT `settleCallsV2` runs on-chain.
|
|
42
|
+
* @param calls - Number of calls being settled in this batch.
|
|
43
|
+
* @returns The amount the on-chain handler will compute (BN, u64).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { calculateSettleAmount } from "@oobe-protocol-labs/synapse-sap-sdk";
|
|
48
|
+
*
|
|
49
|
+
* const amount = calculateSettleAmount(
|
|
50
|
+
* escrow.pricePerCall,
|
|
51
|
+
* escrow.volumeCurve,
|
|
52
|
+
* escrow.totalCallsSettled.add(escrow.pendingCalls),
|
|
53
|
+
* new BN(5),
|
|
54
|
+
* );
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @since v0.13.0
|
|
58
|
+
*/
|
|
59
|
+
export declare function calculateSettleAmount(basePrice: BN, curve: VolumeCurveBreakpoint[], totalCallsBefore: BN, calls: BN): BN;
|
|
60
|
+
//# sourceMappingURL=volume-curve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-curve.d.ts","sourceRoot":"","sources":["../../../src/utils/volume-curve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAwB7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,EAAE,EACb,KAAK,EAAE,qBAAqB,EAAE,EAC9B,gBAAgB,EAAE,EAAE,EACpB,KAAK,EAAE,EAAE,GACR,EAAE,CA2CJ"}
|
package/package.json
CHANGED
package/src/modules/base.ts
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
|
|
13
13
|
import { type AnchorProvider, type Program, BN } from "@coral-xyz/anchor";
|
|
14
14
|
import type { PublicKey, TransactionSignature } from "@solana/web3.js";
|
|
15
|
+
import {
|
|
16
|
+
decodeAnchorError,
|
|
17
|
+
SapPreflightError,
|
|
18
|
+
throwPredicted,
|
|
19
|
+
SAP_ERROR_BY_NAME,
|
|
20
|
+
} from "../utils/anchor-errors";
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Anchor `Program` instance typed for the Synapse Agent SAP IDL.
|
|
@@ -155,4 +161,87 @@ export abstract class BaseModule {
|
|
|
155
161
|
if (BN.isBN(value)) return value;
|
|
156
162
|
return new BN(value.toString());
|
|
157
163
|
}
|
|
164
|
+
|
|
165
|
+
// ── v0.13.0 preflight helpers ─────────────────────────
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @name requireAccountExists
|
|
169
|
+
* @description Fetch a required account; throw a {@link SapPreflightError}
|
|
170
|
+
* with an actionable message if it does not exist.
|
|
171
|
+
* @typeParam T - Expected account type.
|
|
172
|
+
* @param accountName - Anchor account discriminator name.
|
|
173
|
+
* @param address - PDA to fetch.
|
|
174
|
+
* @param onMissing - `{ predicted, hint }` describing the on-chain rejection
|
|
175
|
+
* that would otherwise occur.
|
|
176
|
+
* @protected
|
|
177
|
+
* @since v0.13.0
|
|
178
|
+
*/
|
|
179
|
+
protected async requireAccountExists<T>(
|
|
180
|
+
accountName: string,
|
|
181
|
+
address: PublicKey,
|
|
182
|
+
onMissing: { predicted: keyof typeof SAP_ERROR_BY_NAME; hint?: string },
|
|
183
|
+
): Promise<T> {
|
|
184
|
+
const acc = await this.fetchAccountNullable<T>(accountName, address);
|
|
185
|
+
if (acc == null) {
|
|
186
|
+
throwPredicted(onMissing.predicted, onMissing.hint ?? `${accountName} ${address.toBase58()} not found`);
|
|
187
|
+
}
|
|
188
|
+
return acc as T;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @name requireAccountAbsent
|
|
193
|
+
* @description Verify a PDA does not yet exist on-chain. Used before any
|
|
194
|
+
* `init` instruction to catch `account already in use` early.
|
|
195
|
+
* @protected
|
|
196
|
+
* @since v0.13.0
|
|
197
|
+
*/
|
|
198
|
+
protected async requireAccountAbsent(
|
|
199
|
+
accountName: string,
|
|
200
|
+
address: PublicKey,
|
|
201
|
+
hint: string,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
const acc = await this.provider.connection.getAccountInfo(address);
|
|
204
|
+
if (acc !== null) {
|
|
205
|
+
throw new SapPreflightError(
|
|
206
|
+
`${accountName} ${address.toBase58()} already exists. ${hint}`,
|
|
207
|
+
0,
|
|
208
|
+
"AccountAlreadyInUse",
|
|
209
|
+
hint,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @name simulateOrThrow
|
|
216
|
+
* @description Run `simulate()` on a method builder. If the simulation
|
|
217
|
+
* reports a SAP program error, throw it as a {@link SapPreflightError}
|
|
218
|
+
* with the decoded name + friendly hint *before* the user pays fees.
|
|
219
|
+
* Returns the simulation logs on success for inspection.
|
|
220
|
+
* @protected
|
|
221
|
+
* @since v0.13.0
|
|
222
|
+
*/
|
|
223
|
+
protected async simulateOrThrow(
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
builder: any,
|
|
226
|
+
label: string,
|
|
227
|
+
): Promise<readonly string[]> {
|
|
228
|
+
try {
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
230
|
+
const sim = await builder.simulate();
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
232
|
+
const logs = (sim?.raw ?? sim?.logs ?? []) as readonly string[];
|
|
233
|
+
return logs;
|
|
234
|
+
} catch (err) {
|
|
235
|
+
const decoded = decodeAnchorError(err);
|
|
236
|
+
if (decoded) {
|
|
237
|
+
throw new SapPreflightError(
|
|
238
|
+
`[${label}] simulation failed: ${decoded.friendly}`,
|
|
239
|
+
decoded.code,
|
|
240
|
+
decoded.name,
|
|
241
|
+
decoded.logs?.slice(0, 6).join(" | "),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
158
247
|
}
|