@crediolabs/policy-synth 0.2.0 → 0.3.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/README.md +4 -4
- package/dist/adapters/interpreter/adapter.d.ts +19 -25
- package/dist/adapters/interpreter/adapter.js +54 -487
- package/dist/adapters/interpreter/index.d.ts +1 -1
- package/dist/adapters/interpreter/index.js +1 -1
- package/dist/adapters/oz/adapter.js +1 -15
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/install/build-add-context-rule.d.ts +3 -19
- package/dist/install/build-add-context-rule.js +3 -98
- package/dist/install/build-install-policy.d.ts +4 -53
- package/dist/install/build-install-policy.js +44 -123
- package/dist/install/index.d.ts +0 -2
- package/dist/install/index.js +0 -7
- package/dist/ir/index.d.ts +1 -1
- package/dist/ir/types.d.ts +7 -76
- package/dist/ir/types.js +0 -2
- package/dist/predicate/decode.d.ts +1 -1
- package/dist/predicate/decode.js +2 -70
- package/dist/predicate/encode.js +45 -229
- package/dist/predicate/from-json.js +1 -42
- package/dist/record/decode.js +3 -8
- package/dist/review-card/builder.d.ts +4 -3
- package/dist/review-card/builder.js +18 -162
- package/dist/review-card/cross-check.js +2 -105
- package/dist/review-card/render-leaf.d.ts +4 -0
- package/dist/review-card/render-leaf.js +47 -0
- package/dist/run/index.d.ts +36 -139
- package/dist/run/index.js +125 -437
- package/dist/run/schemas.d.ts +168 -1929
- package/dist/run/schemas.js +40 -269
- package/dist/seams/types.d.ts +0 -2
- package/dist/simulate/deny-cases.d.ts +26 -0
- package/dist/simulate/deny-cases.js +282 -0
- package/dist/simulate/evaluate.d.ts +18 -0
- package/dist/simulate/evaluate.js +271 -0
- package/dist/simulate/index.d.ts +4 -0
- package/dist/simulate/index.js +8 -0
- package/dist/synth/compose-from-recording.d.ts +24 -51
- package/dist/synth/compose-from-recording.js +120 -282
- package/dist/synth/deny-cases.d.ts +5 -7
- package/dist/synth/deny-cases.js +23 -373
- package/dist/synth/evaluate.d.ts +0 -21
- package/dist/synth/evaluate.js +56 -336
- package/dist/synth/index.d.ts +0 -5
- package/dist/synth/index.js +0 -5
- package/dist/synth/permit-context.d.ts +2 -9
- package/dist/synth/permit-context.js +1 -82
- package/dist/synth/synthesize-from-recording.d.ts +1 -29
- package/dist/synth/synthesize-from-recording.js +41 -356
- package/dist/types.d.ts +8 -60
- package/dist/types.js +5 -2
- package/dist/verify/simulate.d.ts +1 -14
- package/dist/verify/simulate.js +2 -88
- package/dist/verify/verify.d.ts +1 -7
- package/dist/verify/verify.js +0 -8
- package/dist-cjs/adapters/interpreter/adapter.d.ts +19 -25
- package/dist-cjs/adapters/interpreter/adapter.js +56 -489
- package/dist-cjs/adapters/interpreter/index.d.ts +1 -1
- package/dist-cjs/adapters/interpreter/index.js +1 -2
- package/dist-cjs/adapters/oz/adapter.js +1 -15
- package/dist-cjs/errors.d.ts +1 -1
- package/dist-cjs/index.d.ts +1 -4
- package/dist-cjs/index.js +1 -4
- package/dist-cjs/install/build-add-context-rule.d.ts +3 -19
- package/dist-cjs/install/build-add-context-rule.js +1 -97
- package/dist-cjs/install/build-install-policy.d.ts +4 -53
- package/dist-cjs/install/build-install-policy.js +44 -122
- package/dist-cjs/install/index.d.ts +0 -2
- package/dist-cjs/install/index.js +2 -23
- package/dist-cjs/ir/index.d.ts +1 -1
- package/dist-cjs/ir/types.d.ts +7 -76
- package/dist-cjs/ir/types.js +0 -2
- package/dist-cjs/predicate/decode.d.ts +1 -1
- package/dist-cjs/predicate/decode.js +2 -70
- package/dist-cjs/predicate/encode.js +45 -229
- package/dist-cjs/predicate/from-json.js +1 -42
- package/dist-cjs/record/decode.js +3 -8
- package/dist-cjs/review-card/builder.d.ts +4 -3
- package/dist-cjs/review-card/builder.js +23 -167
- package/dist-cjs/review-card/cross-check.js +7 -110
- package/dist-cjs/review-card/render-leaf.d.ts +4 -0
- package/dist-cjs/review-card/render-leaf.js +52 -0
- package/dist-cjs/run/index.d.ts +36 -139
- package/dist-cjs/run/index.js +125 -444
- package/dist-cjs/run/schemas.d.ts +168 -1929
- package/dist-cjs/run/schemas.js +41 -270
- package/dist-cjs/seams/types.d.ts +0 -2
- package/dist-cjs/simulate/deny-cases.d.ts +26 -0
- package/dist-cjs/simulate/deny-cases.js +286 -0
- package/dist-cjs/simulate/evaluate.d.ts +18 -0
- package/dist-cjs/simulate/evaluate.js +274 -0
- package/dist-cjs/simulate/index.d.ts +4 -0
- package/dist-cjs/simulate/index.js +13 -0
- package/dist-cjs/synth/compose-from-recording.d.ts +24 -51
- package/dist-cjs/synth/compose-from-recording.js +120 -282
- package/dist-cjs/synth/deny-cases.d.ts +5 -7
- package/dist-cjs/synth/deny-cases.js +23 -374
- package/dist-cjs/synth/evaluate.d.ts +0 -21
- package/dist-cjs/synth/evaluate.js +57 -337
- package/dist-cjs/synth/index.d.ts +0 -5
- package/dist-cjs/synth/index.js +1 -11
- package/dist-cjs/synth/permit-context.d.ts +2 -9
- package/dist-cjs/synth/permit-context.js +1 -82
- package/dist-cjs/synth/synthesize-from-recording.d.ts +1 -29
- package/dist-cjs/synth/synthesize-from-recording.js +39 -354
- package/dist-cjs/types.d.ts +8 -60
- package/dist-cjs/types.js +6 -3
- package/dist-cjs/verify/simulate.d.ts +1 -14
- package/dist-cjs/verify/simulate.js +2 -88
- package/dist-cjs/verify/verify.d.ts +1 -7
- package/dist-cjs/verify/verify.js +0 -8
- package/package.json +4 -4
- package/src/adapters/interpreter/adapter.ts +76 -572
- package/src/errors.ts +0 -19
- package/src/index.ts +1 -4
- package/src/install/build-add-context-rule.ts +5 -139
- package/src/install/build-install-policy.ts +93 -214
- package/src/install/index.ts +0 -34
- package/src/predicate/decode.ts +2 -70
- package/src/predicate/encode.ts +49 -261
- package/src/predicate/from-json.ts +1 -43
- package/src/record/decode.ts +3 -8
- package/src/review-card/builder.ts +19 -168
- package/src/review-card/cross-check.ts +3 -105
- package/src/review-card/render-leaf.ts +48 -0
- package/src/run/index.ts +144 -572
- package/src/run/schemas.ts +42 -291
- package/src/simulate/deny-cases.ts +334 -0
- package/src/simulate/evaluate.ts +284 -0
- package/src/simulate/index.ts +11 -0
- package/src/synth/compose-from-recording.ts +148 -347
- package/src/synth/index.ts +0 -13
- package/src/synth/synthesize-from-recording.ts +43 -456
- package/src/types.ts +13 -49
- package/dist/install/authority-overlap.d.ts +0 -134
- package/dist/install/authority-overlap.js +0 -0
- package/dist/install/build-install-predicate.d.ts +0 -96
- package/dist/install/build-install-predicate.js +0 -444
- package/dist/install/build-merge-policy.d.ts +0 -70
- package/dist/install/build-merge-policy.js +0 -130
- package/dist/install/plan-merge-policy.d.ts +0 -49
- package/dist/install/plan-merge-policy.js +0 -86
- package/dist/install/read-account-rules.d.ts +0 -100
- package/dist/install/read-account-rules.js +0 -283
- package/dist-cjs/install/authority-overlap.d.ts +0 -134
- package/dist-cjs/install/authority-overlap.js +0 -0
- package/dist-cjs/install/build-install-predicate.d.ts +0 -96
- package/dist-cjs/install/build-install-predicate.js +0 -479
- package/dist-cjs/install/build-merge-policy.d.ts +0 -70
- package/dist-cjs/install/build-merge-policy.js +0 -134
- package/dist-cjs/install/plan-merge-policy.d.ts +0 -49
- package/dist-cjs/install/plan-merge-policy.js +0 -90
- package/dist-cjs/install/read-account-rules.d.ts +0 -100
- package/dist-cjs/install/read-account-rules.js +0 -296
- package/src/adapters/interpreter/index.ts +0 -8
- package/src/adapters/oz/adapter.ts +0 -376
- package/src/adapters/oz/index.ts +0 -9
- package/src/codegen/compile-gate.ts +0 -167
- package/src/codegen/index.ts +0 -17
- package/src/codegen/template.ts +0 -165
- package/src/install/authority-overlap.ts +0 -0
- package/src/install/build-merge-policy.ts +0 -219
- package/src/install/plan-merge-policy.ts +0 -133
- package/src/install/read-account-rules.ts +0 -376
- package/src/ir/index.ts +0 -13
- package/src/ir/types.ts +0 -132
- package/src/mandate/index.ts +0 -4
- package/src/mandate/to-ir.ts +0 -71
- package/src/mandate/types.ts +0 -21
- package/src/seams/index.ts +0 -11
- package/src/seams/types.ts +0 -81
- package/src/synth/deny-cases.ts +0 -663
- package/src/synth/evaluate.ts +0 -613
- package/src/synth/harness.ts +0 -68
- package/src/synth/minimize.ts +0 -48
- package/src/synth/permit-context.ts +0 -136
- package/src/synth/predicate-literals.ts +0 -27
- package/src/synth/synthesize-from-mandate.ts +0 -82
- package/src/verify/envelope.ts +0 -28
- package/src/verify/index.ts +0 -5
- package/src/verify/simulate.ts +0 -311
- package/src/verify/verify.ts +0 -243
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AmbiguityPrompt, ContractInvocation, Network } from '../types.ts';
|
|
1
|
+
import type { AmbiguityPrompt, ContractInvocation, Network, PredicateNode } from '../types.ts';
|
|
3
2
|
import type { IntentFacts } from './lower.ts';
|
|
4
|
-
/** Per-asset oracle-price bound supplied by the caller (e.g. swap allowed only
|
|
5
|
-
* if oracle_price(XLM) < 5.00 USDC). One entry per asset; the recorder never
|
|
6
|
-
* fabricates a price bound from a slippage value (different units). */
|
|
7
|
-
export interface OraclePriceBound {
|
|
8
|
-
asset: string;
|
|
9
|
-
operator: IRCompOp;
|
|
10
|
-
value: string;
|
|
11
|
-
/** Decimal basis `value` is written on. REQUIRED: oracle prices normalise to
|
|
12
|
-
* 9 dp, and a threshold silently assumed to share that basis is what let a
|
|
13
|
-
* raw 14-dp bound permit everything. The author states it; we convert. */
|
|
14
|
-
decimals: number;
|
|
15
|
-
}
|
|
16
3
|
/** Caller-supplied answers to the ambiguity prompts. Every numeric bound the
|
|
17
4
|
* synth might apply must come from here - the recording supplies observed
|
|
18
5
|
* amounts (offered only as suggestions), never authorised ceilings. */
|
|
19
6
|
export interface ComposeUserResponses {
|
|
20
|
-
/** Rolling window (seconds) for a spending_limit / invocation_count. */
|
|
21
|
-
windowSeconds?: number;
|
|
22
7
|
/** OZ context-rule expiry (ledger sequence). */
|
|
23
8
|
validUntilLedger?: number;
|
|
24
|
-
/** Per-
|
|
25
|
-
*
|
|
9
|
+
/** Per-call ceiling on the amount the call carries (i128 decimal string).
|
|
10
|
+
* Required to bound the amount argument; absent -> AMOUNT_BOUND_MISSING. */
|
|
26
11
|
limitAmount?: string;
|
|
27
|
-
/** Max invocations per window for an incoming-only flow. Required to emit an
|
|
28
|
-
* invocation_count bound; absent -> FREQUENCY_BOUND_MISSING. */
|
|
29
|
-
invocationLimit?: number;
|
|
30
|
-
/** Per-asset oracle-price bound(s). Each entry lowers to a single
|
|
31
|
-
* `oracle_price(asset) OP value` compare in the interpreter IR. */
|
|
32
|
-
oraclePriceBound?: OraclePriceBound[];
|
|
33
|
-
/** Minimum acceptable swap output per unit of input, as `num/den` (e.g.
|
|
34
|
-
* `{num:'95',den:'100'}` = accept losing at most 5%). REQUIRED to be
|
|
35
|
-
* supplied by the caller: never derived from the recording (the recorded
|
|
36
|
-
* in/out pair is a price at one moment, and freezing it as policy would
|
|
37
|
-
* deny ordinary trades as soon as the rate moves). Absent, no floor is
|
|
38
|
-
* emitted and the existing unbounded-output warning stands. */
|
|
39
|
-
swapMinOutRatio?: {
|
|
40
|
-
num: string;
|
|
41
|
-
den: string;
|
|
42
|
-
};
|
|
43
12
|
/** Recipient allowlist for a swap (call_arg[3] on SoroSwap's
|
|
44
13
|
* swap_exact_tokens_for_tokens). When supplied, REPLACES the default pin.
|
|
45
14
|
* Absent -> recipient is pinned to the recorded value (mirroring SEP-41)
|
|
@@ -51,28 +20,32 @@ export interface ComposeUserResponses {
|
|
|
51
20
|
export interface ComposeOptions {
|
|
52
21
|
network: Network;
|
|
53
22
|
userResponses?: ComposeUserResponses;
|
|
54
|
-
/** When true, constraints the OZ adapter cannot lower are routed to
|
|
55
|
-
* `interpreterIr` (the predicate-shape IR) so the orchestrator can compile
|
|
56
|
-
* them via the interpreter adapter. When false (the default for callers
|
|
57
|
-
* who have not opted in), every constraint goes to `ir` and the OZ
|
|
58
|
-
* adapter's `uncovered` machinery generates the descriptive warnings -
|
|
59
|
-
* today's behaviour. The orchestrator passes this flag through based on
|
|
60
|
-
* whether `opts.interpreter` was supplied. */
|
|
61
|
-
interpreterEnabled?: boolean;
|
|
62
23
|
}
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
24
|
+
/** One composed rule: what the call must be scoped to, the constraints on it,
|
|
25
|
+
* and how long the resulting context rule lives. The constraints are already
|
|
26
|
+
* predicate nodes - there is one enforcement backend, so there is nothing to
|
|
27
|
+
* translate between. */
|
|
28
|
+
export interface ComposedRule {
|
|
29
|
+
scope: {
|
|
30
|
+
contract?: string;
|
|
31
|
+
method?: string;
|
|
32
|
+
};
|
|
33
|
+
constraints: PredicateNode[];
|
|
34
|
+
expiry?: {
|
|
35
|
+
validUntilLedger?: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Result of composition: the composed rule the interpreter compiler
|
|
39
|
+
* compiles, the ambiguities the caller must answer, and descriptive warnings
|
|
40
|
+
* for needs that are NOT expressed as an IR node (so no fabricated constraint
|
|
41
|
+
* is emitted). The orchestrator carries ambiguities into
|
|
42
|
+
* `ProposedPolicy.ambiguities` and merges warnings into
|
|
69
43
|
* `ProposedPolicy.warnings`. */
|
|
70
44
|
export interface ComposeResult {
|
|
71
|
-
|
|
72
|
-
interpreterIr: PolicyIR;
|
|
45
|
+
interpreterRule: ComposedRule;
|
|
73
46
|
ambiguities: AmbiguityPrompt[];
|
|
74
47
|
warnings: string[];
|
|
75
48
|
}
|
|
76
|
-
/** Compose a
|
|
49
|
+
/** Compose a rule from the lowered facts + the resolved scope.
|
|
77
50
|
* Pure (no randomness, no clock); same inputs -> byte-identical result. */
|
|
78
51
|
export declare function composeFromRecording(facts: IntentFacts, scopeContract: string, topLevel: ContractInvocation | null, opts: ComposeOptions): ComposeResult;
|