@newton-xyz/policy-pack-vaultsfyi 0.2.0 → 2.0.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/index.cjs CHANGED
@@ -37,12 +37,12 @@ module.exports = __toCommonJS(index_exports);
37
37
  // src/deployments.ts
38
38
  var deployments = {
39
39
  "11155111": {
40
- policy: "0x14685C1769Eb6f449FeC42A48d086746F470CE4a",
41
- policyData: "0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8",
42
- wasmCid: "bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe",
43
- policyCodeHash: "0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54",
44
- deployedAt: "2026-06-09",
45
- notes: "host-secrets fix; current"
40
+ policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc",
41
+ policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37",
42
+ wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm",
43
+ policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b",
44
+ deployedAt: "2026-06-14",
45
+ notes: "Phase 0 Stream D \u2014 composite namespacing redeploy"
46
46
  }
47
47
  };
48
48
 
@@ -54,7 +54,6 @@ var PACK_LINK = "https://vaults.fyi";
54
54
  var PACK_AUTHOR = "";
55
55
 
56
56
  // src/pack.ts
57
- var import_viem = require("viem");
58
57
  var import_zod4 = require("zod");
59
58
 
60
59
  // src/params.ts
@@ -73,7 +72,7 @@ var ParamsSchema = import_zod.z.object({
73
72
  ),
74
73
  deny_on_critical_flag: import_zod.z.boolean().describe("Whether to deny if the vault has a flag with severity 'critical' or 'high'"),
75
74
  deny_on_corrupted: import_zod.z.boolean().describe("Whether to deny if the vault is reported as corrupted by the data source")
76
- }).describe("Risk envelope thresholds for vault deposit gating");
75
+ }).describe("Risk envelope thresholds for vault deposit gating").strict();
77
76
 
78
77
  // src/prepare-query.ts
79
78
  var NETWORK_BY_CHAIN_ID = {
@@ -134,12 +133,6 @@ var WasmArgsSchema = import_zod3.z.object({
134
133
 
135
134
  // src/pack.ts
136
135
  var BASIS_POINTS = 1e4;
137
- function toBp(n) {
138
- return BigInt(Math.round(n * BASIS_POINTS));
139
- }
140
- function fromBp(n) {
141
- return Number(n) / BASIS_POINTS;
142
- }
143
136
  var isAtBasisPointPrecision = (n) => Math.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;
144
137
  var RefinedParamsSchema = ParamsSchema.superRefine(
145
138
  (params, ctx) => {
@@ -160,60 +153,11 @@ var RefinedParamsSchema = ParamsSchema.superRefine(
160
153
  }
161
154
  }
162
155
  );
163
- var POLICY_PARAMS_ABI = [
164
- {
165
- type: "tuple",
166
- components: [
167
- { name: "apyZMax", type: "uint256" },
168
- { name: "tvlDrawdown24hMaxPct", type: "uint256" },
169
- { name: "tvlDrawdown7dMaxPct", type: "uint256" },
170
- { name: "riskScoreFloor", type: "uint16" },
171
- { name: "denyOnAllocationChange", type: "bool" },
172
- { name: "denyOnCriticalFlag", type: "bool" },
173
- { name: "denyOnCorrupted", type: "bool" }
174
- ]
175
- }
176
- ];
177
- function encodeRiskScore(n) {
178
- if (!Number.isInteger(n) || n < 0 || n > 100) {
179
- throw new RangeError(
180
- `risk_score_floor must be an integer in [0, 100]; received ${n}. The AVS-side floor compares against \`vault.scores.netScore\` which is an integer 0-100.`
181
- );
182
- }
183
- return n;
184
- }
185
- function encodeParams(params) {
186
- return (0, import_viem.encodeAbiParameters)(POLICY_PARAMS_ABI, [
187
- {
188
- apyZMax: toBp(params.apy_z_max),
189
- tvlDrawdown24hMaxPct: toBp(params.tvl_drawdown_24h_max_pct),
190
- tvlDrawdown7dMaxPct: toBp(params.tvl_drawdown_7d_max_pct),
191
- riskScoreFloor: encodeRiskScore(params.risk_score_floor),
192
- denyOnAllocationChange: params.deny_on_allocation_change,
193
- denyOnCriticalFlag: params.deny_on_critical_flag,
194
- denyOnCorrupted: params.deny_on_corrupted
195
- }
196
- ]);
197
- }
198
- function decodeParams(encoded) {
199
- const [decoded] = (0, import_viem.decodeAbiParameters)(POLICY_PARAMS_ABI, encoded);
200
- return ParamsSchema.parse({
201
- apy_z_max: fromBp(decoded.apyZMax),
202
- tvl_drawdown_24h_max_pct: fromBp(decoded.tvlDrawdown24hMaxPct),
203
- tvl_drawdown_7d_max_pct: fromBp(decoded.tvlDrawdown7dMaxPct),
204
- risk_score_floor: decoded.riskScoreFloor,
205
- deny_on_allocation_change: decoded.denyOnAllocationChange,
206
- deny_on_critical_flag: decoded.denyOnCriticalFlag,
207
- deny_on_corrupted: decoded.denyOnCorrupted
208
- });
209
- }
210
156
  var vaultsfyi = {
211
157
  id: `${PACK_NAME}/risk-envelope/v1`,
212
158
  paramsSchema: RefinedParamsSchema,
213
159
  wasmArgsSchema: WasmArgsSchema,
214
160
  secretsSchema: SecretsSchema,
215
- encodeParams,
216
- decodeParams,
217
161
  prepareQuery,
218
162
  deployments,
219
163
  metadata: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/deployments.ts","../src/metadata.ts","../src/pack.ts","../src/params.ts","../src/prepare-query.ts","../src/secrets.ts","../src/wasm-args.ts"],"sourcesContent":["// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n\nexport * from \"./deployments\";\nexport * from \"./metadata\";\nexport * from \"./pack\";\nexport * from \"./params\";\nexport * from \"./secrets\";\nexport * from \"./wasm-args\";\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nimport type { ChainId, Deployment } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tpolicy: \"0x14685C1769Eb6f449FeC42A48d086746F470CE4a\",\n\t\tpolicyData: \"0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8\",\n\t\twasmCid: \"bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe\",\n\t\tpolicyCodeHash: \"0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54\",\n\t\tdeployedAt: \"2026-06-09\",\n\t\tnotes: \"host-secrets fix; current\",\n\t},\n} as const satisfies Readonly<Partial<Record<ChainId, Deployment>>>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nexport const PACK_NAME = \"vaultsfyi\" as const;\nexport const PACK_VERSION = \"0.0.1\" as const;\nexport const PACK_DESCRIPTION =\n\t\"Gates vault deposits based on real-time risk signals: APY anomalies, TVL drawdowns, risk score floors, and allocation changes\" as const;\nexport const PACK_LINK = \"https://vaults.fyi\" as const;\nexport const PACK_AUTHOR = \"\" as const;\n","// Hand-written canonical export — survives `pnpm gen:bindings` regen.\n// The generated `index.ts` re-exports `pack.ts` when present.\nimport type { PolicyPack } from \"@newton-xyz/policy-pack-shared\";\nimport { decodeAbiParameters, encodeAbiParameters, type Hex } from \"viem\";\nimport { z } from \"zod\";\nimport { deployments } from \"./deployments\";\nimport { PACK_AUTHOR, PACK_DESCRIPTION, PACK_LINK, PACK_NAME, PACK_VERSION } from \"./metadata\";\nimport { type Params, ParamsSchema } from \"./params\";\nimport { prepareQuery } from \"./prepare-query\";\nimport { type Secrets, SecretsSchema } from \"./secrets\";\nimport { type WasmArgs, WasmArgsSchema } from \"./wasm-args\";\n\n/**\n * The fractional thresholds (`apy_z_max`, `tvl_drawdown_*_max_pct`) are stored\n * in basis points so the on-chain bytes carry only `uint256`. `apy_z_max: 1.5`\n * becomes `15000` (1.5e4 bp); `tvl_drawdown_24h_max_pct: 0.05` becomes `500`.\n * `risk_score_floor` is *not* basis-point-encoded — it's a 0-100 integer scale\n * that matches the AVS-side `vault.scores.netScore` field directly, so it\n * round-trips through `uint16` as-is.\n */\nconst BASIS_POINTS = 10_000;\n\nfunction toBp(n: number): bigint {\n\treturn BigInt(Math.round(n * BASIS_POINTS));\n}\n\nfunction fromBp(n: bigint): number {\n\treturn Number(n) / BASIS_POINTS;\n}\n\n/**\n * Refined params schema with sub-basis-point precision rejection on every\n * fractional threshold so a curator typing `tvl_drawdown_24h_max_pct: 0.00005`\n * can't silently encode as `0n` and disable the cap. The generated\n * `ParamsSchema` from `./params` is the canonical zod derived from\n * `params_schema.json`; this version sits on top of it for stricter SDK-side\n * input validation. `risk_score_floor` is excluded — it's an integer 0-100\n * scale, not a basis-point fraction. Exported with a distinct name to avoid\n * clashing with the generated star re-export in `index.ts`.\n */\nconst isAtBasisPointPrecision = (n: number) =>\n\tMath.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;\n\nexport const RefinedParamsSchema = (ParamsSchema as unknown as z.ZodType<Params>).superRefine(\n\t(params, ctx) => {\n\t\tconst numericFields: ReadonlyArray<keyof Params> = [\n\t\t\t\"apy_z_max\",\n\t\t\t\"tvl_drawdown_24h_max_pct\",\n\t\t\t\"tvl_drawdown_7d_max_pct\",\n\t\t];\n\t\tfor (const field of numericFields) {\n\t\t\tconst value = params[field] as number;\n\t\t\tif (!isAtBasisPointPrecision(value)) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tpath: [field],\n\t\t\t\t\tmessage: `Sub-basis-point precision is not supported. \\`${field}: ${value}\\` would silently encode as ${\n\t\t\t\t\t\tMath.round(value * BASIS_POINTS) / BASIS_POINTS\n\t\t\t\t\t}. Round to 4 decimal places (1bp) before passing.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t},\n);\n\n/**\n * On-chain layout of `policyParams` for the vaults.fyi risk-envelope policy.\n *\n * This is the ABI tuple that round-trips through `NewtonPolicyData.policyParams`.\n * Keys are sorted to match `ParamsSchema`'s key order so generated zod and\n * encoded bytes stay in sync. If the schema adds a field, add it here in the\n * same position and bump the policy contract.\n */\nconst POLICY_PARAMS_ABI = [\n\t{\n\t\ttype: \"tuple\",\n\t\tcomponents: [\n\t\t\t{ name: \"apyZMax\", type: \"uint256\" },\n\t\t\t{ name: \"tvlDrawdown24hMaxPct\", type: \"uint256\" },\n\t\t\t{ name: \"tvlDrawdown7dMaxPct\", type: \"uint256\" },\n\t\t\t{ name: \"riskScoreFloor\", type: \"uint16\" },\n\t\t\t{ name: \"denyOnAllocationChange\", type: \"bool\" },\n\t\t\t{ name: \"denyOnCriticalFlag\", type: \"bool\" },\n\t\t\t{ name: \"denyOnCorrupted\", type: \"bool\" },\n\t\t],\n\t},\n] as const;\n\nfunction encodeRiskScore(n: number): number {\n\tif (!Number.isInteger(n) || n < 0 || n > 100) {\n\t\tthrow new RangeError(\n\t\t\t`risk_score_floor must be an integer in [0, 100]; received ${n}. The AVS-side floor compares against \\`vault.scores.netScore\\` which is an integer 0-100.`,\n\t\t);\n\t}\n\treturn n;\n}\n\nfunction encodeParams(params: Params): Hex {\n\treturn encodeAbiParameters(POLICY_PARAMS_ABI, [\n\t\t{\n\t\t\tapyZMax: toBp(params.apy_z_max),\n\t\t\ttvlDrawdown24hMaxPct: toBp(params.tvl_drawdown_24h_max_pct),\n\t\t\ttvlDrawdown7dMaxPct: toBp(params.tvl_drawdown_7d_max_pct),\n\t\t\triskScoreFloor: encodeRiskScore(params.risk_score_floor),\n\t\t\tdenyOnAllocationChange: params.deny_on_allocation_change,\n\t\t\tdenyOnCriticalFlag: params.deny_on_critical_flag,\n\t\t\tdenyOnCorrupted: params.deny_on_corrupted,\n\t\t},\n\t]);\n}\n\nfunction decodeParams(encoded: Hex): Params {\n\tconst [decoded] = decodeAbiParameters(POLICY_PARAMS_ABI, encoded);\n\treturn ParamsSchema.parse({\n\t\tapy_z_max: fromBp(decoded.apyZMax),\n\t\ttvl_drawdown_24h_max_pct: fromBp(decoded.tvlDrawdown24hMaxPct),\n\t\ttvl_drawdown_7d_max_pct: fromBp(decoded.tvlDrawdown7dMaxPct),\n\t\trisk_score_floor: decoded.riskScoreFloor,\n\t\tdeny_on_allocation_change: decoded.denyOnAllocationChange,\n\t\tdeny_on_critical_flag: decoded.denyOnCriticalFlag,\n\t\tdeny_on_corrupted: decoded.denyOnCorrupted,\n\t});\n}\n\n/**\n * The vaults.fyi risk-envelope `PolicyPack`.\n *\n * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`:\n *\n * ```ts\n * import { vaultsfyi } from \"@newton-xyz/policy-pack-vaultsfyi\";\n *\n * const shield = await createShield({\n * walletClient,\n * vault,\n * pack: vaultsfyi,\n * params: {\n * apy_z_max: 3,\n * tvl_drawdown_24h_max_pct: 0.05,\n * tvl_drawdown_7d_max_pct: 0.20,\n * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`\n * deny_on_allocation_change: true,\n * deny_on_critical_flag: true,\n * deny_on_corrupted: true,\n * },\n * });\n * ```\n */\nexport const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets> = {\n\tid: `${PACK_NAME}/risk-envelope/v1`,\n\tparamsSchema: RefinedParamsSchema,\n\twasmArgsSchema: WasmArgsSchema,\n\tsecretsSchema: SecretsSchema,\n\tencodeParams,\n\tdecodeParams,\n\tprepareQuery,\n\tdeployments,\n\tmetadata: {\n\t\tname: PACK_NAME,\n\t\tversion: PACK_VERSION,\n\t\tdescription: PACK_DESCRIPTION,\n\t\tauthor: PACK_AUTHOR || undefined,\n\t\tlink: PACK_LINK || undefined,\n\t},\n};\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/params_schema.json\nimport { z } from \"zod\";\n\nexport const ParamsSchema = z\n\t.object({\n\t\tapy_z_max: z\n\t\t\t.number()\n\t\t\t.describe(\n\t\t\t\t\"Max APY z-score (current vs 30d median). Exceeding this indicates an APY anomaly.\",\n\t\t\t),\n\t\ttvl_drawdown_24h_max_pct: z.number().describe(\"Max allowed 24h TVL drawdown percentage\"),\n\t\ttvl_drawdown_7d_max_pct: z.number().describe(\"Max allowed 7d TVL drawdown percentage\"),\n\t\trisk_score_floor: z\n\t\t\t.number()\n\t\t\t.int()\n\t\t\t.gte(0)\n\t\t\t.lte(100)\n\t\t\t.describe(\n\t\t\t\t\"Minimum acceptable risk score (0-100 integer scale; matches the AVS-side `vault.scores.netScore`). Set to 0 to effectively disable the floor.\",\n\t\t\t),\n\t\tdeny_on_allocation_change: z\n\t\t\t.boolean()\n\t\t\t.describe(\n\t\t\t\t\"Whether to deny if vault allocation/strategy metadata has changed since last evaluation\",\n\t\t\t),\n\t\tdeny_on_critical_flag: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault has a flag with severity 'critical' or 'high'\"),\n\t\tdeny_on_corrupted: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault is reported as corrupted by the data source\"),\n\t})\n\t.describe(\"Risk envelope thresholds for vault deposit gating\");\n\nexport type Params = z.infer<typeof ParamsSchema>;\n","import type { PrepareQueryArgs, PrepareQueryResult } from \"@newton-xyz/policy-pack-shared\";\nimport type { WasmArgs } from \"./wasm-args\";\n\n/**\n * vaults.fyi network slugs. Keyed by viem chain id. The AVS-side `policy.js`\n * fetches `https://api.vaults.fyi/v2/historical/<network>/<vaultAddress>`\n * with this slug, so the SDK has to use the same map.\n */\nconst NETWORK_BY_CHAIN_ID: Readonly<Record<number, string>> = {\n\t1: \"mainnet\",\n\t8453: \"base\",\n\t42161: \"arbitrum\",\n\t10: \"optimism\",\n\t11155111: \"sepolia\",\n\t84532: \"base-sepolia\",\n};\n\nfunction networkForChain(chainId: number): string {\n\tconst name = NETWORK_BY_CHAIN_ID[chainId];\n\tif (!name) {\n\t\tthrow new Error(\n\t\t\t`policy-pack-vaultsfyi: chain id ${chainId} is not in the vaults.fyi network map. Add it to NETWORK_BY_CHAIN_ID before using this pack on this chain.`,\n\t\t);\n\t}\n\treturn name;\n}\n\n/**\n * Build the WASM args the vaults.fyi policy expects.\n *\n * The AVS-side `policy.js` computes the canonical allocation hash itself\n * (FNV-1a over `JSON.stringify({ protocol?.name, tags, fees, childrenVaults })`\n * fetched from the vaults.fyi API). The SDK has nothing to add — the AVS is\n * the source of truth for both the data and the hash. The SDK's only job is\n * to thread the *previous* hash through so the AVS can compare:\n *\n * - First call: pass `previousAllocationHash: undefined` (defaults to\n * `null` in wasmArgs). The AVS-side `allocation_changed_since_last`\n * branch returns `false`, so `deny_on_allocation_change` doesn't fire\n * on a clean first observation.\n * - Subsequent calls: pass the hash the AVS returned on the prior call\n * (typically read from `policyData` storage or a curator-side cache).\n * The AVS compares against its freshly-computed hash and flips\n * `allocation_changed_since_last` if they diverge.\n *\n * Earlier revisions of this function read MetaMorpho's `supplyQueue` and\n * computed `keccak256(abi.encode(bytes32[]))` — that hash never matched the\n * AVS's FNV-1a-over-API-metadata, so `deny_on_allocation_change: true` was\n * effectively a coin flip. Removed.\n */\nexport async function prepareQuery(\n\t{ publicClient, vault }: PrepareQueryArgs,\n\toptions: { previousAllocationHash?: string } = {},\n): Promise<PrepareQueryResult<WasmArgs>> {\n\tconst chainId = publicClient.chain?.id;\n\tif (chainId === undefined) {\n\t\tthrow new Error(\n\t\t\t\"policy-pack-vaultsfyi: publicClient.chain is undefined. Pass a chain to viem's createPublicClient.\",\n\t\t);\n\t}\n\n\treturn {\n\t\twasmArgs: {\n\t\t\tnetwork: networkForChain(chainId),\n\t\t\tvaultAddress: vault,\n\t\t\tlastKnownAllocationHash: options.previousAllocationHash ?? null,\n\t\t},\n\t};\n}\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/secrets_schema.json\nimport { z } from \"zod\";\n\nexport const SecretsSchema = z.object({ VAULTS_FYI_API_KEY: z.string().min(1) }).strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/wasm_args_schema.json\nimport { z } from \"zod\";\n\nexport const WasmArgsSchema = z\n\t.object({\n\t\tnetwork: z\n\t\t\t.string()\n\t\t\t.describe(\n\t\t\t\t\"Blockchain network name as accepted by the vaults.fyi API (e.g. 'mainnet', 'base', 'arbitrum').\",\n\t\t\t),\n\t\tvaultAddress: z.string().describe(\"Vault contract address (0x-prefixed) to inspect.\"),\n\t\tlastKnownAllocationHash: z\n\t\t\t.union([\n\t\t\t\tz\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t\tz\n\t\t\t\t\t.null()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t])\n\t\t\t.describe(\n\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t)\n\t\t\t.optional(),\n\t})\n\t.describe(\"Inputs passed to the vaults.fyi allocation-change policy WASM at evaluation time\");\n\nexport type WasmArgs = z.infer<typeof WasmArgsSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc;AAAA,EAC1B,YAAY;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,OAAO;AAAA,EACR;AACD;;;ACXO,IAA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/B,mBAAmB,QAAQ;AAAA,EAC5B,CAAC;AACF;AA0BO,IAAM,YAAmD;AAAA,EAC/D,IAAI,GAAG,SAAS;AAAA,EAChB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,QAAQ,eAAe;AAAA,IACvB,MAAM,aAAa;AAAA,EACpB;AACD;","names":["import_zod","import_zod","import_zod"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/deployments.ts","../src/metadata.ts","../src/pack.ts","../src/params.ts","../src/prepare-query.ts","../src/secrets.ts","../src/wasm-args.ts"],"sourcesContent":["// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n\nexport * from \"./deployments\";\nexport * from \"./metadata\";\nexport * from \"./pack\";\nexport * from \"./params\";\nexport * from \"./secrets\";\nexport * from \"./wasm-args\";\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nimport type { ChainId, Deployment } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tpolicy: \"0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc\",\n\t\tpolicyData: \"0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37\",\n\t\twasmCid: \"bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm\",\n\t\tpolicyCodeHash: \"0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b\",\n\t\tdeployedAt: \"2026-06-14\",\n\t\tnotes: \"Phase 0 Stream D — composite namespacing redeploy\",\n\t},\n} as const satisfies Readonly<Partial<Record<ChainId, Deployment>>>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nexport const PACK_NAME = \"vaultsfyi\" as const;\nexport const PACK_VERSION = \"0.0.1\" as const;\nexport const PACK_DESCRIPTION =\n\t\"Gates vault deposits based on real-time risk signals: APY anomalies, TVL drawdowns, risk score floors, and allocation changes\" as const;\nexport const PACK_LINK = \"https://vaults.fyi\" as const;\nexport const PACK_AUTHOR = \"\" as const;\n","// Hand-written canonical export — survives `pnpm gen:bindings` regen.\n// The generated `index.ts` re-exports `pack.ts` when present.\nimport type { PolicyPack } from \"@newton-xyz/policy-pack-shared\";\nimport { z } from \"zod\";\nimport { deployments } from \"./deployments\";\nimport { PACK_AUTHOR, PACK_DESCRIPTION, PACK_LINK, PACK_NAME, PACK_VERSION } from \"./metadata\";\nimport { type Params, ParamsSchema } from \"./params\";\nimport { prepareQuery } from \"./prepare-query\";\nimport { type Secrets, SecretsSchema } from \"./secrets\";\nimport { type WasmArgs, WasmArgsSchema } from \"./wasm-args\";\n\nconst BASIS_POINTS = 10_000;\n\n/**\n * Curator-side input refinement: reject sub-basis-point precision on the\n * fractional thresholds. A curator typing `tvl_drawdown_24h_max_pct: 0.00005`\n * almost certainly means 5bp (`0.0005`); the previous ABI encoder would have\n * silently rounded to `0n` and disabled the cap. Kept as defensive validation\n * even though the JSON encoder no longer rounds — the policy semantics are\n * still defined to basis-point granularity. `risk_score_floor` is excluded;\n * it's an integer 0-100 scale that matches the AVS-side `vault.scores.netScore`\n * field directly.\n */\nconst isAtBasisPointPrecision = (n: number) =>\n\tMath.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;\n\nexport const RefinedParamsSchema = (ParamsSchema as unknown as z.ZodType<Params>).superRefine(\n\t(params, ctx) => {\n\t\tconst numericFields: ReadonlyArray<keyof Params> = [\n\t\t\t\"apy_z_max\",\n\t\t\t\"tvl_drawdown_24h_max_pct\",\n\t\t\t\"tvl_drawdown_7d_max_pct\",\n\t\t];\n\t\tfor (const field of numericFields) {\n\t\t\tconst value = params[field] as number;\n\t\t\tif (!isAtBasisPointPrecision(value)) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tpath: [field],\n\t\t\t\t\tmessage: `Sub-basis-point precision is not supported. \\`${field}: ${value}\\` would silently encode as ${\n\t\t\t\t\t\tMath.round(value * BASIS_POINTS) / BASIS_POINTS\n\t\t\t\t\t}. Round to 4 decimal places (1bp) before passing.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t},\n);\n\n/**\n * The vaults.fyi risk-envelope `PolicyPack`.\n *\n * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`. The\n * on-chain `policyParams` byte format is handled by the canonical\n * `encodePolicyParams` / `decodePolicyParams` utilities in\n * `@newton-xyz/policy-pack-shared` (UTF-8 JSON, sorted keys) — not per-pack.\n *\n * ```ts\n * import { vaultsfyi } from \"@newton-xyz/policy-pack-vaultsfyi\";\n * import { encodePolicyParams } from \"@newton-xyz/policy-pack-shared\";\n *\n * const params = {\n * apy_z_max: 3,\n * tvl_drawdown_24h_max_pct: 0.05,\n * tvl_drawdown_7d_max_pct: 0.20,\n * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`\n * deny_on_allocation_change: true,\n * deny_on_critical_flag: true,\n * deny_on_corrupted: true,\n * };\n * const policyParams = encodePolicyParams(vaultsfyi, params);\n * ```\n */\nexport const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets> = {\n\tid: `${PACK_NAME}/risk-envelope/v1`,\n\tparamsSchema: RefinedParamsSchema,\n\twasmArgsSchema: WasmArgsSchema,\n\tsecretsSchema: SecretsSchema,\n\tprepareQuery,\n\tdeployments,\n\tmetadata: {\n\t\tname: PACK_NAME,\n\t\tversion: PACK_VERSION,\n\t\tdescription: PACK_DESCRIPTION,\n\t\tauthor: PACK_AUTHOR || undefined,\n\t\tlink: PACK_LINK || undefined,\n\t},\n};\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/params_schema.json\nimport { z } from \"zod\";\n\nexport const ParamsSchema = z\n\t.object({\n\t\tapy_z_max: z\n\t\t\t.number()\n\t\t\t.describe(\n\t\t\t\t\"Max APY z-score (current vs 30d median). Exceeding this indicates an APY anomaly.\",\n\t\t\t),\n\t\ttvl_drawdown_24h_max_pct: z.number().describe(\"Max allowed 24h TVL drawdown percentage\"),\n\t\ttvl_drawdown_7d_max_pct: z.number().describe(\"Max allowed 7d TVL drawdown percentage\"),\n\t\trisk_score_floor: z\n\t\t\t.number()\n\t\t\t.int()\n\t\t\t.gte(0)\n\t\t\t.lte(100)\n\t\t\t.describe(\n\t\t\t\t\"Minimum acceptable risk score (0-100 integer scale; matches the AVS-side `vault.scores.netScore`). Set to 0 to effectively disable the floor.\",\n\t\t\t),\n\t\tdeny_on_allocation_change: z\n\t\t\t.boolean()\n\t\t\t.describe(\n\t\t\t\t\"Whether to deny if vault allocation/strategy metadata has changed since last evaluation\",\n\t\t\t),\n\t\tdeny_on_critical_flag: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault has a flag with severity 'critical' or 'high'\"),\n\t\tdeny_on_corrupted: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault is reported as corrupted by the data source\"),\n\t})\n\t.describe(\"Risk envelope thresholds for vault deposit gating\")\n\t.strict();\n\nexport type Params = z.infer<typeof ParamsSchema>;\n","import type { PrepareQueryArgs, PrepareQueryResult } from \"@newton-xyz/policy-pack-shared\";\nimport type { WasmArgs } from \"./wasm-args\";\n\n/**\n * vaults.fyi network slugs. Keyed by viem chain id. The AVS-side `policy.js`\n * fetches `https://api.vaults.fyi/v2/historical/<network>/<vaultAddress>`\n * with this slug, so the SDK has to use the same map.\n */\nconst NETWORK_BY_CHAIN_ID: Readonly<Record<number, string>> = {\n\t1: \"mainnet\",\n\t8453: \"base\",\n\t42161: \"arbitrum\",\n\t10: \"optimism\",\n\t11155111: \"sepolia\",\n\t84532: \"base-sepolia\",\n};\n\nfunction networkForChain(chainId: number): string {\n\tconst name = NETWORK_BY_CHAIN_ID[chainId];\n\tif (!name) {\n\t\tthrow new Error(\n\t\t\t`policy-pack-vaultsfyi: chain id ${chainId} is not in the vaults.fyi network map. Add it to NETWORK_BY_CHAIN_ID before using this pack on this chain.`,\n\t\t);\n\t}\n\treturn name;\n}\n\n/**\n * Build the WASM args the vaults.fyi policy expects.\n *\n * The AVS-side `policy.js` computes the canonical allocation hash itself\n * (FNV-1a over `JSON.stringify({ protocol?.name, tags, fees, childrenVaults })`\n * fetched from the vaults.fyi API). The SDK has nothing to add — the AVS is\n * the source of truth for both the data and the hash. The SDK's only job is\n * to thread the *previous* hash through so the AVS can compare:\n *\n * - First call: pass `previousAllocationHash: undefined` (defaults to\n * `null` in wasmArgs). The AVS-side `allocation_changed_since_last`\n * branch returns `false`, so `deny_on_allocation_change` doesn't fire\n * on a clean first observation.\n * - Subsequent calls: pass the hash the AVS returned on the prior call\n * (typically read from `policyData` storage or a curator-side cache).\n * The AVS compares against its freshly-computed hash and flips\n * `allocation_changed_since_last` if they diverge.\n *\n * Earlier revisions of this function read MetaMorpho's `supplyQueue` and\n * computed `keccak256(abi.encode(bytes32[]))` — that hash never matched the\n * AVS's FNV-1a-over-API-metadata, so `deny_on_allocation_change: true` was\n * effectively a coin flip. Removed.\n */\nexport async function prepareQuery(\n\t{ publicClient, vault }: PrepareQueryArgs,\n\toptions: { previousAllocationHash?: string } = {},\n): Promise<PrepareQueryResult<WasmArgs>> {\n\tconst chainId = publicClient.chain?.id;\n\tif (chainId === undefined) {\n\t\tthrow new Error(\n\t\t\t\"policy-pack-vaultsfyi: publicClient.chain is undefined. Pass a chain to viem's createPublicClient.\",\n\t\t);\n\t}\n\n\treturn {\n\t\twasmArgs: {\n\t\t\tnetwork: networkForChain(chainId),\n\t\t\tvaultAddress: vault,\n\t\t\tlastKnownAllocationHash: options.previousAllocationHash ?? null,\n\t\t},\n\t};\n}\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/secrets_schema.json\nimport { z } from \"zod\";\n\nexport const SecretsSchema = z.object({ VAULTS_FYI_API_KEY: z.string().min(1) }).strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/wasm_args_schema.json\nimport { z } from \"zod\";\n\nexport const WasmArgsSchema = z\n\t.object({\n\t\tnetwork: z\n\t\t\t.string()\n\t\t\t.describe(\n\t\t\t\t\"Blockchain network name as accepted by the vaults.fyi API (e.g. 'mainnet', 'base', 'arbitrum').\",\n\t\t\t),\n\t\tvaultAddress: z.string().describe(\"Vault contract address (0x-prefixed) to inspect.\"),\n\t\tlastKnownAllocationHash: z\n\t\t\t.union([\n\t\t\t\tz\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t\tz\n\t\t\t\t\t.null()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t])\n\t\t\t.describe(\n\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t)\n\t\t\t.optional(),\n\t})\n\t.describe(\"Inputs passed to the vaults.fyi allocation-change policy WASM at evaluation time\");\n\nexport type WasmArgs = z.infer<typeof WasmArgsSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AA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AM,QAAQ,YAAY,IAAI,YACpC;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;AA0BO,IAAM,YAAmD;AAAA,EAC/D,IAAI,GAAG,SAAS;AAAA,EAChB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA,UAAU;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,QAAQ,eAAe;AAAA,IACvB,MAAM,aAAa;AAAA,EACpB;AACD;","names":["import_zod","import_zod","import_zod"]}
package/dist/index.d.cts CHANGED
@@ -3,12 +3,12 @@ import { z } from 'zod';
3
3
 
4
4
  declare const deployments: {
5
5
  readonly "11155111": {
6
- readonly policy: "0x14685C1769Eb6f449FeC42A48d086746F470CE4a";
7
- readonly policyData: "0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8";
8
- readonly wasmCid: "bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe";
9
- readonly policyCodeHash: "0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54";
10
- readonly deployedAt: "2026-06-09";
11
- readonly notes: "host-secrets fix; current";
6
+ readonly policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc";
7
+ readonly policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37";
8
+ readonly wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm";
9
+ readonly policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b";
10
+ readonly deployedAt: "2026-06-14";
11
+ readonly notes: "Phase 0 Stream D — composite namespacing redeploy";
12
12
  };
13
13
  };
14
14
 
@@ -26,7 +26,7 @@ declare const ParamsSchema: z.ZodObject<{
26
26
  deny_on_allocation_change: z.ZodBoolean;
27
27
  deny_on_critical_flag: z.ZodBoolean;
28
28
  deny_on_corrupted: z.ZodBoolean;
29
- }, "strip", z.ZodTypeAny, {
29
+ }, "strict", z.ZodTypeAny, {
30
30
  apy_z_max: number;
31
31
  tvl_drawdown_24h_max_pct: number;
32
32
  tvl_drawdown_7d_max_pct: number;
@@ -105,25 +105,25 @@ declare const RefinedParamsSchema: z.ZodEffects<z.ZodType<{
105
105
  /**
106
106
  * The vaults.fyi risk-envelope `PolicyPack`.
107
107
  *
108
- * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`:
108
+ * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`. The
109
+ * on-chain `policyParams` byte format is handled by the canonical
110
+ * `encodePolicyParams` / `decodePolicyParams` utilities in
111
+ * `@newton-xyz/policy-pack-shared` (UTF-8 JSON, sorted keys) — not per-pack.
109
112
  *
110
113
  * ```ts
111
114
  * import { vaultsfyi } from "@newton-xyz/policy-pack-vaultsfyi";
115
+ * import { encodePolicyParams } from "@newton-xyz/policy-pack-shared";
112
116
  *
113
- * const shield = await createShield({
114
- * walletClient,
115
- * vault,
116
- * pack: vaultsfyi,
117
- * params: {
118
- * apy_z_max: 3,
119
- * tvl_drawdown_24h_max_pct: 0.05,
120
- * tvl_drawdown_7d_max_pct: 0.20,
121
- * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`
122
- * deny_on_allocation_change: true,
123
- * deny_on_critical_flag: true,
124
- * deny_on_corrupted: true,
125
- * },
126
- * });
117
+ * const params = {
118
+ * apy_z_max: 3,
119
+ * tvl_drawdown_24h_max_pct: 0.05,
120
+ * tvl_drawdown_7d_max_pct: 0.20,
121
+ * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`
122
+ * deny_on_allocation_change: true,
123
+ * deny_on_critical_flag: true,
124
+ * deny_on_corrupted: true,
125
+ * };
126
+ * const policyParams = encodePolicyParams(vaultsfyi, params);
127
127
  * ```
128
128
  */
129
129
  declare const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets>;
package/dist/index.d.ts CHANGED
@@ -3,12 +3,12 @@ import { z } from 'zod';
3
3
 
4
4
  declare const deployments: {
5
5
  readonly "11155111": {
6
- readonly policy: "0x14685C1769Eb6f449FeC42A48d086746F470CE4a";
7
- readonly policyData: "0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8";
8
- readonly wasmCid: "bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe";
9
- readonly policyCodeHash: "0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54";
10
- readonly deployedAt: "2026-06-09";
11
- readonly notes: "host-secrets fix; current";
6
+ readonly policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc";
7
+ readonly policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37";
8
+ readonly wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm";
9
+ readonly policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b";
10
+ readonly deployedAt: "2026-06-14";
11
+ readonly notes: "Phase 0 Stream D — composite namespacing redeploy";
12
12
  };
13
13
  };
14
14
 
@@ -26,7 +26,7 @@ declare const ParamsSchema: z.ZodObject<{
26
26
  deny_on_allocation_change: z.ZodBoolean;
27
27
  deny_on_critical_flag: z.ZodBoolean;
28
28
  deny_on_corrupted: z.ZodBoolean;
29
- }, "strip", z.ZodTypeAny, {
29
+ }, "strict", z.ZodTypeAny, {
30
30
  apy_z_max: number;
31
31
  tvl_drawdown_24h_max_pct: number;
32
32
  tvl_drawdown_7d_max_pct: number;
@@ -105,25 +105,25 @@ declare const RefinedParamsSchema: z.ZodEffects<z.ZodType<{
105
105
  /**
106
106
  * The vaults.fyi risk-envelope `PolicyPack`.
107
107
  *
108
- * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`:
108
+ * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`. The
109
+ * on-chain `policyParams` byte format is handled by the canonical
110
+ * `encodePolicyParams` / `decodePolicyParams` utilities in
111
+ * `@newton-xyz/policy-pack-shared` (UTF-8 JSON, sorted keys) — not per-pack.
109
112
  *
110
113
  * ```ts
111
114
  * import { vaultsfyi } from "@newton-xyz/policy-pack-vaultsfyi";
115
+ * import { encodePolicyParams } from "@newton-xyz/policy-pack-shared";
112
116
  *
113
- * const shield = await createShield({
114
- * walletClient,
115
- * vault,
116
- * pack: vaultsfyi,
117
- * params: {
118
- * apy_z_max: 3,
119
- * tvl_drawdown_24h_max_pct: 0.05,
120
- * tvl_drawdown_7d_max_pct: 0.20,
121
- * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`
122
- * deny_on_allocation_change: true,
123
- * deny_on_critical_flag: true,
124
- * deny_on_corrupted: true,
125
- * },
126
- * });
117
+ * const params = {
118
+ * apy_z_max: 3,
119
+ * tvl_drawdown_24h_max_pct: 0.05,
120
+ * tvl_drawdown_7d_max_pct: 0.20,
121
+ * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`
122
+ * deny_on_allocation_change: true,
123
+ * deny_on_critical_flag: true,
124
+ * deny_on_corrupted: true,
125
+ * };
126
+ * const policyParams = encodePolicyParams(vaultsfyi, params);
127
127
  * ```
128
128
  */
129
129
  declare const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets>;
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // src/deployments.ts
2
2
  var deployments = {
3
3
  "11155111": {
4
- policy: "0x14685C1769Eb6f449FeC42A48d086746F470CE4a",
5
- policyData: "0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8",
6
- wasmCid: "bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe",
7
- policyCodeHash: "0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54",
8
- deployedAt: "2026-06-09",
9
- notes: "host-secrets fix; current"
4
+ policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc",
5
+ policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37",
6
+ wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm",
7
+ policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b",
8
+ deployedAt: "2026-06-14",
9
+ notes: "Phase 0 Stream D \u2014 composite namespacing redeploy"
10
10
  }
11
11
  };
12
12
 
@@ -18,7 +18,6 @@ var PACK_LINK = "https://vaults.fyi";
18
18
  var PACK_AUTHOR = "";
19
19
 
20
20
  // src/pack.ts
21
- import { decodeAbiParameters, encodeAbiParameters } from "viem";
22
21
  import { z as z4 } from "zod";
23
22
 
24
23
  // src/params.ts
@@ -37,7 +36,7 @@ var ParamsSchema = z.object({
37
36
  ),
38
37
  deny_on_critical_flag: z.boolean().describe("Whether to deny if the vault has a flag with severity 'critical' or 'high'"),
39
38
  deny_on_corrupted: z.boolean().describe("Whether to deny if the vault is reported as corrupted by the data source")
40
- }).describe("Risk envelope thresholds for vault deposit gating");
39
+ }).describe("Risk envelope thresholds for vault deposit gating").strict();
41
40
 
42
41
  // src/prepare-query.ts
43
42
  var NETWORK_BY_CHAIN_ID = {
@@ -98,12 +97,6 @@ var WasmArgsSchema = z3.object({
98
97
 
99
98
  // src/pack.ts
100
99
  var BASIS_POINTS = 1e4;
101
- function toBp(n) {
102
- return BigInt(Math.round(n * BASIS_POINTS));
103
- }
104
- function fromBp(n) {
105
- return Number(n) / BASIS_POINTS;
106
- }
107
100
  var isAtBasisPointPrecision = (n) => Math.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;
108
101
  var RefinedParamsSchema = ParamsSchema.superRefine(
109
102
  (params, ctx) => {
@@ -124,60 +117,11 @@ var RefinedParamsSchema = ParamsSchema.superRefine(
124
117
  }
125
118
  }
126
119
  );
127
- var POLICY_PARAMS_ABI = [
128
- {
129
- type: "tuple",
130
- components: [
131
- { name: "apyZMax", type: "uint256" },
132
- { name: "tvlDrawdown24hMaxPct", type: "uint256" },
133
- { name: "tvlDrawdown7dMaxPct", type: "uint256" },
134
- { name: "riskScoreFloor", type: "uint16" },
135
- { name: "denyOnAllocationChange", type: "bool" },
136
- { name: "denyOnCriticalFlag", type: "bool" },
137
- { name: "denyOnCorrupted", type: "bool" }
138
- ]
139
- }
140
- ];
141
- function encodeRiskScore(n) {
142
- if (!Number.isInteger(n) || n < 0 || n > 100) {
143
- throw new RangeError(
144
- `risk_score_floor must be an integer in [0, 100]; received ${n}. The AVS-side floor compares against \`vault.scores.netScore\` which is an integer 0-100.`
145
- );
146
- }
147
- return n;
148
- }
149
- function encodeParams(params) {
150
- return encodeAbiParameters(POLICY_PARAMS_ABI, [
151
- {
152
- apyZMax: toBp(params.apy_z_max),
153
- tvlDrawdown24hMaxPct: toBp(params.tvl_drawdown_24h_max_pct),
154
- tvlDrawdown7dMaxPct: toBp(params.tvl_drawdown_7d_max_pct),
155
- riskScoreFloor: encodeRiskScore(params.risk_score_floor),
156
- denyOnAllocationChange: params.deny_on_allocation_change,
157
- denyOnCriticalFlag: params.deny_on_critical_flag,
158
- denyOnCorrupted: params.deny_on_corrupted
159
- }
160
- ]);
161
- }
162
- function decodeParams(encoded) {
163
- const [decoded] = decodeAbiParameters(POLICY_PARAMS_ABI, encoded);
164
- return ParamsSchema.parse({
165
- apy_z_max: fromBp(decoded.apyZMax),
166
- tvl_drawdown_24h_max_pct: fromBp(decoded.tvlDrawdown24hMaxPct),
167
- tvl_drawdown_7d_max_pct: fromBp(decoded.tvlDrawdown7dMaxPct),
168
- risk_score_floor: decoded.riskScoreFloor,
169
- deny_on_allocation_change: decoded.denyOnAllocationChange,
170
- deny_on_critical_flag: decoded.denyOnCriticalFlag,
171
- deny_on_corrupted: decoded.denyOnCorrupted
172
- });
173
- }
174
120
  var vaultsfyi = {
175
121
  id: `${PACK_NAME}/risk-envelope/v1`,
176
122
  paramsSchema: RefinedParamsSchema,
177
123
  wasmArgsSchema: WasmArgsSchema,
178
124
  secretsSchema: SecretsSchema,
179
- encodeParams,
180
- decodeParams,
181
125
  prepareQuery,
182
126
  deployments,
183
127
  metadata: {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deployments.ts","../src/metadata.ts","../src/pack.ts","../src/params.ts","../src/prepare-query.ts","../src/secrets.ts","../src/wasm-args.ts"],"sourcesContent":["// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nimport type { ChainId, Deployment } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tpolicy: \"0x14685C1769Eb6f449FeC42A48d086746F470CE4a\",\n\t\tpolicyData: \"0x5F8B0FC2c22c039f97D2c806B48307B9A9C288C8\",\n\t\twasmCid: \"bafybeig6oielnnf4zorcmqkets6v26ov7t2o6ikipx6vupuzsjrxvbpkpe\",\n\t\tpolicyCodeHash: \"0x09be97b5636da7b6e231914f47e2bfbc32fddfd3647e771d7624cea8fa2bdc54\",\n\t\tdeployedAt: \"2026-06-09\",\n\t\tnotes: \"host-secrets fix; current\",\n\t},\n} as const satisfies Readonly<Partial<Record<ChainId, Deployment>>>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nexport const PACK_NAME = \"vaultsfyi\" as const;\nexport const PACK_VERSION = \"0.0.1\" as const;\nexport const PACK_DESCRIPTION =\n\t\"Gates vault deposits based on real-time risk signals: APY anomalies, TVL drawdowns, risk score floors, and allocation changes\" as const;\nexport const PACK_LINK = \"https://vaults.fyi\" as const;\nexport const PACK_AUTHOR = \"\" as const;\n","// Hand-written canonical export — survives `pnpm gen:bindings` regen.\n// The generated `index.ts` re-exports `pack.ts` when present.\nimport type { PolicyPack } from \"@newton-xyz/policy-pack-shared\";\nimport { decodeAbiParameters, encodeAbiParameters, type Hex } from \"viem\";\nimport { z } from \"zod\";\nimport { deployments } from \"./deployments\";\nimport { PACK_AUTHOR, PACK_DESCRIPTION, PACK_LINK, PACK_NAME, PACK_VERSION } from \"./metadata\";\nimport { type Params, ParamsSchema } from \"./params\";\nimport { prepareQuery } from \"./prepare-query\";\nimport { type Secrets, SecretsSchema } from \"./secrets\";\nimport { type WasmArgs, WasmArgsSchema } from \"./wasm-args\";\n\n/**\n * The fractional thresholds (`apy_z_max`, `tvl_drawdown_*_max_pct`) are stored\n * in basis points so the on-chain bytes carry only `uint256`. `apy_z_max: 1.5`\n * becomes `15000` (1.5e4 bp); `tvl_drawdown_24h_max_pct: 0.05` becomes `500`.\n * `risk_score_floor` is *not* basis-point-encoded — it's a 0-100 integer scale\n * that matches the AVS-side `vault.scores.netScore` field directly, so it\n * round-trips through `uint16` as-is.\n */\nconst BASIS_POINTS = 10_000;\n\nfunction toBp(n: number): bigint {\n\treturn BigInt(Math.round(n * BASIS_POINTS));\n}\n\nfunction fromBp(n: bigint): number {\n\treturn Number(n) / BASIS_POINTS;\n}\n\n/**\n * Refined params schema with sub-basis-point precision rejection on every\n * fractional threshold so a curator typing `tvl_drawdown_24h_max_pct: 0.00005`\n * can't silently encode as `0n` and disable the cap. The generated\n * `ParamsSchema` from `./params` is the canonical zod derived from\n * `params_schema.json`; this version sits on top of it for stricter SDK-side\n * input validation. `risk_score_floor` is excluded — it's an integer 0-100\n * scale, not a basis-point fraction. Exported with a distinct name to avoid\n * clashing with the generated star re-export in `index.ts`.\n */\nconst isAtBasisPointPrecision = (n: number) =>\n\tMath.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;\n\nexport const RefinedParamsSchema = (ParamsSchema as unknown as z.ZodType<Params>).superRefine(\n\t(params, ctx) => {\n\t\tconst numericFields: ReadonlyArray<keyof Params> = [\n\t\t\t\"apy_z_max\",\n\t\t\t\"tvl_drawdown_24h_max_pct\",\n\t\t\t\"tvl_drawdown_7d_max_pct\",\n\t\t];\n\t\tfor (const field of numericFields) {\n\t\t\tconst value = params[field] as number;\n\t\t\tif (!isAtBasisPointPrecision(value)) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tpath: [field],\n\t\t\t\t\tmessage: `Sub-basis-point precision is not supported. \\`${field}: ${value}\\` would silently encode as ${\n\t\t\t\t\t\tMath.round(value * BASIS_POINTS) / BASIS_POINTS\n\t\t\t\t\t}. Round to 4 decimal places (1bp) before passing.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t},\n);\n\n/**\n * On-chain layout of `policyParams` for the vaults.fyi risk-envelope policy.\n *\n * This is the ABI tuple that round-trips through `NewtonPolicyData.policyParams`.\n * Keys are sorted to match `ParamsSchema`'s key order so generated zod and\n * encoded bytes stay in sync. If the schema adds a field, add it here in the\n * same position and bump the policy contract.\n */\nconst POLICY_PARAMS_ABI = [\n\t{\n\t\ttype: \"tuple\",\n\t\tcomponents: [\n\t\t\t{ name: \"apyZMax\", type: \"uint256\" },\n\t\t\t{ name: \"tvlDrawdown24hMaxPct\", type: \"uint256\" },\n\t\t\t{ name: \"tvlDrawdown7dMaxPct\", type: \"uint256\" },\n\t\t\t{ name: \"riskScoreFloor\", type: \"uint16\" },\n\t\t\t{ name: \"denyOnAllocationChange\", type: \"bool\" },\n\t\t\t{ name: \"denyOnCriticalFlag\", type: \"bool\" },\n\t\t\t{ name: \"denyOnCorrupted\", type: \"bool\" },\n\t\t],\n\t},\n] as const;\n\nfunction encodeRiskScore(n: number): number {\n\tif (!Number.isInteger(n) || n < 0 || n > 100) {\n\t\tthrow new RangeError(\n\t\t\t`risk_score_floor must be an integer in [0, 100]; received ${n}. The AVS-side floor compares against \\`vault.scores.netScore\\` which is an integer 0-100.`,\n\t\t);\n\t}\n\treturn n;\n}\n\nfunction encodeParams(params: Params): Hex {\n\treturn encodeAbiParameters(POLICY_PARAMS_ABI, [\n\t\t{\n\t\t\tapyZMax: toBp(params.apy_z_max),\n\t\t\ttvlDrawdown24hMaxPct: toBp(params.tvl_drawdown_24h_max_pct),\n\t\t\ttvlDrawdown7dMaxPct: toBp(params.tvl_drawdown_7d_max_pct),\n\t\t\triskScoreFloor: encodeRiskScore(params.risk_score_floor),\n\t\t\tdenyOnAllocationChange: params.deny_on_allocation_change,\n\t\t\tdenyOnCriticalFlag: params.deny_on_critical_flag,\n\t\t\tdenyOnCorrupted: params.deny_on_corrupted,\n\t\t},\n\t]);\n}\n\nfunction decodeParams(encoded: Hex): Params {\n\tconst [decoded] = decodeAbiParameters(POLICY_PARAMS_ABI, encoded);\n\treturn ParamsSchema.parse({\n\t\tapy_z_max: fromBp(decoded.apyZMax),\n\t\ttvl_drawdown_24h_max_pct: fromBp(decoded.tvlDrawdown24hMaxPct),\n\t\ttvl_drawdown_7d_max_pct: fromBp(decoded.tvlDrawdown7dMaxPct),\n\t\trisk_score_floor: decoded.riskScoreFloor,\n\t\tdeny_on_allocation_change: decoded.denyOnAllocationChange,\n\t\tdeny_on_critical_flag: decoded.denyOnCriticalFlag,\n\t\tdeny_on_corrupted: decoded.denyOnCorrupted,\n\t});\n}\n\n/**\n * The vaults.fyi risk-envelope `PolicyPack`.\n *\n * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`:\n *\n * ```ts\n * import { vaultsfyi } from \"@newton-xyz/policy-pack-vaultsfyi\";\n *\n * const shield = await createShield({\n * walletClient,\n * vault,\n * pack: vaultsfyi,\n * params: {\n * apy_z_max: 3,\n * tvl_drawdown_24h_max_pct: 0.05,\n * tvl_drawdown_7d_max_pct: 0.20,\n * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`\n * deny_on_allocation_change: true,\n * deny_on_critical_flag: true,\n * deny_on_corrupted: true,\n * },\n * });\n * ```\n */\nexport const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets> = {\n\tid: `${PACK_NAME}/risk-envelope/v1`,\n\tparamsSchema: RefinedParamsSchema,\n\twasmArgsSchema: WasmArgsSchema,\n\tsecretsSchema: SecretsSchema,\n\tencodeParams,\n\tdecodeParams,\n\tprepareQuery,\n\tdeployments,\n\tmetadata: {\n\t\tname: PACK_NAME,\n\t\tversion: PACK_VERSION,\n\t\tdescription: PACK_DESCRIPTION,\n\t\tauthor: PACK_AUTHOR || undefined,\n\t\tlink: PACK_LINK || undefined,\n\t},\n};\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/params_schema.json\nimport { z } from \"zod\";\n\nexport const ParamsSchema = z\n\t.object({\n\t\tapy_z_max: z\n\t\t\t.number()\n\t\t\t.describe(\n\t\t\t\t\"Max APY z-score (current vs 30d median). Exceeding this indicates an APY anomaly.\",\n\t\t\t),\n\t\ttvl_drawdown_24h_max_pct: z.number().describe(\"Max allowed 24h TVL drawdown percentage\"),\n\t\ttvl_drawdown_7d_max_pct: z.number().describe(\"Max allowed 7d TVL drawdown percentage\"),\n\t\trisk_score_floor: z\n\t\t\t.number()\n\t\t\t.int()\n\t\t\t.gte(0)\n\t\t\t.lte(100)\n\t\t\t.describe(\n\t\t\t\t\"Minimum acceptable risk score (0-100 integer scale; matches the AVS-side `vault.scores.netScore`). Set to 0 to effectively disable the floor.\",\n\t\t\t),\n\t\tdeny_on_allocation_change: z\n\t\t\t.boolean()\n\t\t\t.describe(\n\t\t\t\t\"Whether to deny if vault allocation/strategy metadata has changed since last evaluation\",\n\t\t\t),\n\t\tdeny_on_critical_flag: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault has a flag with severity 'critical' or 'high'\"),\n\t\tdeny_on_corrupted: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault is reported as corrupted by the data source\"),\n\t})\n\t.describe(\"Risk envelope thresholds for vault deposit gating\");\n\nexport type Params = z.infer<typeof ParamsSchema>;\n","import type { PrepareQueryArgs, PrepareQueryResult } from \"@newton-xyz/policy-pack-shared\";\nimport type { WasmArgs } from \"./wasm-args\";\n\n/**\n * vaults.fyi network slugs. Keyed by viem chain id. The AVS-side `policy.js`\n * fetches `https://api.vaults.fyi/v2/historical/<network>/<vaultAddress>`\n * with this slug, so the SDK has to use the same map.\n */\nconst NETWORK_BY_CHAIN_ID: Readonly<Record<number, string>> = {\n\t1: \"mainnet\",\n\t8453: \"base\",\n\t42161: \"arbitrum\",\n\t10: \"optimism\",\n\t11155111: \"sepolia\",\n\t84532: \"base-sepolia\",\n};\n\nfunction networkForChain(chainId: number): string {\n\tconst name = NETWORK_BY_CHAIN_ID[chainId];\n\tif (!name) {\n\t\tthrow new Error(\n\t\t\t`policy-pack-vaultsfyi: chain id ${chainId} is not in the vaults.fyi network map. Add it to NETWORK_BY_CHAIN_ID before using this pack on this chain.`,\n\t\t);\n\t}\n\treturn name;\n}\n\n/**\n * Build the WASM args the vaults.fyi policy expects.\n *\n * The AVS-side `policy.js` computes the canonical allocation hash itself\n * (FNV-1a over `JSON.stringify({ protocol?.name, tags, fees, childrenVaults })`\n * fetched from the vaults.fyi API). The SDK has nothing to add — the AVS is\n * the source of truth for both the data and the hash. The SDK's only job is\n * to thread the *previous* hash through so the AVS can compare:\n *\n * - First call: pass `previousAllocationHash: undefined` (defaults to\n * `null` in wasmArgs). The AVS-side `allocation_changed_since_last`\n * branch returns `false`, so `deny_on_allocation_change` doesn't fire\n * on a clean first observation.\n * - Subsequent calls: pass the hash the AVS returned on the prior call\n * (typically read from `policyData` storage or a curator-side cache).\n * The AVS compares against its freshly-computed hash and flips\n * `allocation_changed_since_last` if they diverge.\n *\n * Earlier revisions of this function read MetaMorpho's `supplyQueue` and\n * computed `keccak256(abi.encode(bytes32[]))` — that hash never matched the\n * AVS's FNV-1a-over-API-metadata, so `deny_on_allocation_change: true` was\n * effectively a coin flip. Removed.\n */\nexport async function prepareQuery(\n\t{ publicClient, vault }: PrepareQueryArgs,\n\toptions: { previousAllocationHash?: string } = {},\n): Promise<PrepareQueryResult<WasmArgs>> {\n\tconst chainId = publicClient.chain?.id;\n\tif (chainId === undefined) {\n\t\tthrow new Error(\n\t\t\t\"policy-pack-vaultsfyi: publicClient.chain is undefined. Pass a chain to viem's createPublicClient.\",\n\t\t);\n\t}\n\n\treturn {\n\t\twasmArgs: {\n\t\t\tnetwork: networkForChain(chainId),\n\t\t\tvaultAddress: vault,\n\t\t\tlastKnownAllocationHash: options.previousAllocationHash ?? null,\n\t\t},\n\t};\n}\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/secrets_schema.json\nimport { z } from \"zod\";\n\nexport const SecretsSchema = z.object({ VAULTS_FYI_API_KEY: z.string().min(1) }).strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/wasm_args_schema.json\nimport { z } from \"zod\";\n\nexport const WasmArgsSchema = z\n\t.object({\n\t\tnetwork: z\n\t\t\t.string()\n\t\t\t.describe(\n\t\t\t\t\"Blockchain network name as accepted by the vaults.fyi API (e.g. 'mainnet', 'base', 'arbitrum').\",\n\t\t\t),\n\t\tvaultAddress: z.string().describe(\"Vault contract address (0x-prefixed) to inspect.\"),\n\t\tlastKnownAllocationHash: z\n\t\t\t.union([\n\t\t\t\tz\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t\tz\n\t\t\t\t\t.null()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t])\n\t\t\t.describe(\n\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t)\n\t\t\t.optional(),\n\t})\n\t.describe(\"Inputs passed to the vaults.fyi allocation-change policy WASM at evaluation time\");\n\nexport type WasmArgs = z.infer<typeof WasmArgsSchema>;\n"],"mappings":";AAIO,IAAM,cAAc;AAAA,EAC1B,YAAY;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,OAAO;AAAA,EACR;AACD;;;ACXO,IAAM,YAAY;AAClB,IAAM,eAAe;AACrB,IAAM,mBACZ;AACM,IAAM,YAAY;AAClB,IAAM,cAAc;;;ACJ3B,SAAS,qBAAqB,2BAAqC;AACnE,SAAS,KAAAA,UAAS;;;ACDlB,SAAS,SAAS;AAEX,IAAM,eAAe,EAC1B,OAAO;AAAA,EACP,WAAW,EACT,OAAO,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,0BAA0B,EAAE,OAAO,EAAE,SAAS,yCAAyC;AAAA,EACvF,yBAAyB,EAAE,OAAO,EAAE,SAAS,wCAAwC;AAAA,EACrF,kBAAkB,EAChB,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,EACL,IAAI,GAAG,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,2BAA2B,EACzB,QAAQ,EACR;AAAA,IACA;AAAA,EACD;AAAA,EACD,uBAAuB,EACrB,QAAQ,EACR,SAAS,4EAA4E;AAAA,EACvF,mBAAmB,EACjB,QAAQ,EACR,SAAS,0EAA0E;AACtF,CAAC,EACA,SAAS,mDAAmD;;;AC1B9D,IAAM,sBAAwD;AAAA,EAC7D,GAAG;AAAA,EACH,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,OAAO;AACR;AAEA,SAAS,gBAAgB,SAAyB;AACjD,QAAM,OAAO,oBAAoB,OAAO;AACxC,MAAI,CAAC,MAAM;AAC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C/B,oBAAoB,OAAO;AAAA,MAC3B,iBAAiB,OAAO;AAAA,IACzB;AAAA,EACD,CAAC;AACF;AAEA,SAAS,aAAa,SAAsB;AAC3C,QAAM,CAAC,OAAO,IAAI,oBAAoB,mBAAmB,OAAO;AAChE,SAAO,aAAa,MAAM;AAAA,IACzB,WAAW,OAAO,QAAQ,OAAO;AAAA,IACjC,0BAA0B,OAAO,QAAQ,oBAAoB;AAAA,IAC7D,yBAAyB,OAAO,QAAQ,mBAAmB;AAAA,IAC3D,kBAAkB,QAAQ;AAAA,IAC1B,2BAA2B,QAAQ;AAAA,IACnC,uBAAuB,QAAQ;AAAA,IAC/B,mBAAmB,QAAQ;AAAA,EAC5B,CAAC;AACF;AA0BO,IAAM,YAAmD;AAAA,EAC/D,IAAI,GAAG,SAAS;AAAA,EAChB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,QAAQ,eAAe;AAAA,IACvB,MAAM,aAAa;AAAA,EACpB;AACD;","names":["z","z","z","z"]}
1
+ {"version":3,"sources":["../src/deployments.ts","../src/metadata.ts","../src/pack.ts","../src/params.ts","../src/prepare-query.ts","../src/secrets.ts","../src/wasm-args.ts"],"sourcesContent":["// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nimport type { ChainId, Deployment } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tpolicy: \"0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc\",\n\t\tpolicyData: \"0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37\",\n\t\twasmCid: \"bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm\",\n\t\tpolicyCodeHash: \"0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b\",\n\t\tdeployedAt: \"2026-06-14\",\n\t\tnotes: \"Phase 0 Stream D — composite namespacing redeploy\",\n\t},\n} as const satisfies Readonly<Partial<Record<ChainId, Deployment>>>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\nexport const PACK_NAME = \"vaultsfyi\" as const;\nexport const PACK_VERSION = \"0.0.1\" as const;\nexport const PACK_DESCRIPTION =\n\t\"Gates vault deposits based on real-time risk signals: APY anomalies, TVL drawdowns, risk score floors, and allocation changes\" as const;\nexport const PACK_LINK = \"https://vaults.fyi\" as const;\nexport const PACK_AUTHOR = \"\" as const;\n","// Hand-written canonical export — survives `pnpm gen:bindings` regen.\n// The generated `index.ts` re-exports `pack.ts` when present.\nimport type { PolicyPack } from \"@newton-xyz/policy-pack-shared\";\nimport { z } from \"zod\";\nimport { deployments } from \"./deployments\";\nimport { PACK_AUTHOR, PACK_DESCRIPTION, PACK_LINK, PACK_NAME, PACK_VERSION } from \"./metadata\";\nimport { type Params, ParamsSchema } from \"./params\";\nimport { prepareQuery } from \"./prepare-query\";\nimport { type Secrets, SecretsSchema } from \"./secrets\";\nimport { type WasmArgs, WasmArgsSchema } from \"./wasm-args\";\n\nconst BASIS_POINTS = 10_000;\n\n/**\n * Curator-side input refinement: reject sub-basis-point precision on the\n * fractional thresholds. A curator typing `tvl_drawdown_24h_max_pct: 0.00005`\n * almost certainly means 5bp (`0.0005`); the previous ABI encoder would have\n * silently rounded to `0n` and disabled the cap. Kept as defensive validation\n * even though the JSON encoder no longer rounds — the policy semantics are\n * still defined to basis-point granularity. `risk_score_floor` is excluded;\n * it's an integer 0-100 scale that matches the AVS-side `vault.scores.netScore`\n * field directly.\n */\nconst isAtBasisPointPrecision = (n: number) =>\n\tMath.abs(n * BASIS_POINTS - Math.round(n * BASIS_POINTS)) < Number.EPSILON;\n\nexport const RefinedParamsSchema = (ParamsSchema as unknown as z.ZodType<Params>).superRefine(\n\t(params, ctx) => {\n\t\tconst numericFields: ReadonlyArray<keyof Params> = [\n\t\t\t\"apy_z_max\",\n\t\t\t\"tvl_drawdown_24h_max_pct\",\n\t\t\t\"tvl_drawdown_7d_max_pct\",\n\t\t];\n\t\tfor (const field of numericFields) {\n\t\t\tconst value = params[field] as number;\n\t\t\tif (!isAtBasisPointPrecision(value)) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tpath: [field],\n\t\t\t\t\tmessage: `Sub-basis-point precision is not supported. \\`${field}: ${value}\\` would silently encode as ${\n\t\t\t\t\t\tMath.round(value * BASIS_POINTS) / BASIS_POINTS\n\t\t\t\t\t}. Round to 4 decimal places (1bp) before passing.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t},\n);\n\n/**\n * The vaults.fyi risk-envelope `PolicyPack`.\n *\n * Pass to `createShield(...)` from `@newton-xyz/newton-shield-sdk`. The\n * on-chain `policyParams` byte format is handled by the canonical\n * `encodePolicyParams` / `decodePolicyParams` utilities in\n * `@newton-xyz/policy-pack-shared` (UTF-8 JSON, sorted keys) — not per-pack.\n *\n * ```ts\n * import { vaultsfyi } from \"@newton-xyz/policy-pack-vaultsfyi\";\n * import { encodePolicyParams } from \"@newton-xyz/policy-pack-shared\";\n *\n * const params = {\n * apy_z_max: 3,\n * tvl_drawdown_24h_max_pct: 0.05,\n * tvl_drawdown_7d_max_pct: 0.20,\n * risk_score_floor: 85, // 0-100 integer; matches AVS `vault.scores.netScore`\n * deny_on_allocation_change: true,\n * deny_on_critical_flag: true,\n * deny_on_corrupted: true,\n * };\n * const policyParams = encodePolicyParams(vaultsfyi, params);\n * ```\n */\nexport const vaultsfyi: PolicyPack<Params, WasmArgs, Secrets> = {\n\tid: `${PACK_NAME}/risk-envelope/v1`,\n\tparamsSchema: RefinedParamsSchema,\n\twasmArgsSchema: WasmArgsSchema,\n\tsecretsSchema: SecretsSchema,\n\tprepareQuery,\n\tdeployments,\n\tmetadata: {\n\t\tname: PACK_NAME,\n\t\tversion: PACK_VERSION,\n\t\tdescription: PACK_DESCRIPTION,\n\t\tauthor: PACK_AUTHOR || undefined,\n\t\tlink: PACK_LINK || undefined,\n\t},\n};\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/params_schema.json\nimport { z } from \"zod\";\n\nexport const ParamsSchema = z\n\t.object({\n\t\tapy_z_max: z\n\t\t\t.number()\n\t\t\t.describe(\n\t\t\t\t\"Max APY z-score (current vs 30d median). Exceeding this indicates an APY anomaly.\",\n\t\t\t),\n\t\ttvl_drawdown_24h_max_pct: z.number().describe(\"Max allowed 24h TVL drawdown percentage\"),\n\t\ttvl_drawdown_7d_max_pct: z.number().describe(\"Max allowed 7d TVL drawdown percentage\"),\n\t\trisk_score_floor: z\n\t\t\t.number()\n\t\t\t.int()\n\t\t\t.gte(0)\n\t\t\t.lte(100)\n\t\t\t.describe(\n\t\t\t\t\"Minimum acceptable risk score (0-100 integer scale; matches the AVS-side `vault.scores.netScore`). Set to 0 to effectively disable the floor.\",\n\t\t\t),\n\t\tdeny_on_allocation_change: z\n\t\t\t.boolean()\n\t\t\t.describe(\n\t\t\t\t\"Whether to deny if vault allocation/strategy metadata has changed since last evaluation\",\n\t\t\t),\n\t\tdeny_on_critical_flag: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault has a flag with severity 'critical' or 'high'\"),\n\t\tdeny_on_corrupted: z\n\t\t\t.boolean()\n\t\t\t.describe(\"Whether to deny if the vault is reported as corrupted by the data source\"),\n\t})\n\t.describe(\"Risk envelope thresholds for vault deposit gating\")\n\t.strict();\n\nexport type Params = z.infer<typeof ParamsSchema>;\n","import type { PrepareQueryArgs, PrepareQueryResult } from \"@newton-xyz/policy-pack-shared\";\nimport type { WasmArgs } from \"./wasm-args\";\n\n/**\n * vaults.fyi network slugs. Keyed by viem chain id. The AVS-side `policy.js`\n * fetches `https://api.vaults.fyi/v2/historical/<network>/<vaultAddress>`\n * with this slug, so the SDK has to use the same map.\n */\nconst NETWORK_BY_CHAIN_ID: Readonly<Record<number, string>> = {\n\t1: \"mainnet\",\n\t8453: \"base\",\n\t42161: \"arbitrum\",\n\t10: \"optimism\",\n\t11155111: \"sepolia\",\n\t84532: \"base-sepolia\",\n};\n\nfunction networkForChain(chainId: number): string {\n\tconst name = NETWORK_BY_CHAIN_ID[chainId];\n\tif (!name) {\n\t\tthrow new Error(\n\t\t\t`policy-pack-vaultsfyi: chain id ${chainId} is not in the vaults.fyi network map. Add it to NETWORK_BY_CHAIN_ID before using this pack on this chain.`,\n\t\t);\n\t}\n\treturn name;\n}\n\n/**\n * Build the WASM args the vaults.fyi policy expects.\n *\n * The AVS-side `policy.js` computes the canonical allocation hash itself\n * (FNV-1a over `JSON.stringify({ protocol?.name, tags, fees, childrenVaults })`\n * fetched from the vaults.fyi API). The SDK has nothing to add — the AVS is\n * the source of truth for both the data and the hash. The SDK's only job is\n * to thread the *previous* hash through so the AVS can compare:\n *\n * - First call: pass `previousAllocationHash: undefined` (defaults to\n * `null` in wasmArgs). The AVS-side `allocation_changed_since_last`\n * branch returns `false`, so `deny_on_allocation_change` doesn't fire\n * on a clean first observation.\n * - Subsequent calls: pass the hash the AVS returned on the prior call\n * (typically read from `policyData` storage or a curator-side cache).\n * The AVS compares against its freshly-computed hash and flips\n * `allocation_changed_since_last` if they diverge.\n *\n * Earlier revisions of this function read MetaMorpho's `supplyQueue` and\n * computed `keccak256(abi.encode(bytes32[]))` — that hash never matched the\n * AVS's FNV-1a-over-API-metadata, so `deny_on_allocation_change: true` was\n * effectively a coin flip. Removed.\n */\nexport async function prepareQuery(\n\t{ publicClient, vault }: PrepareQueryArgs,\n\toptions: { previousAllocationHash?: string } = {},\n): Promise<PrepareQueryResult<WasmArgs>> {\n\tconst chainId = publicClient.chain?.id;\n\tif (chainId === undefined) {\n\t\tthrow new Error(\n\t\t\t\"policy-pack-vaultsfyi: publicClient.chain is undefined. Pass a chain to viem's createPublicClient.\",\n\t\t);\n\t}\n\n\treturn {\n\t\twasmArgs: {\n\t\t\tnetwork: networkForChain(chainId),\n\t\t\tvaultAddress: vault,\n\t\t\tlastKnownAllocationHash: options.previousAllocationHash ?? null,\n\t\t},\n\t};\n}\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/secrets_schema.json\nimport { z } from \"zod\";\n\nexport const SecretsSchema = z.object({ VAULTS_FYI_API_KEY: z.string().min(1) }).strict();\n\nexport type Secrets = z.infer<typeof SecretsSchema>;\n","// AUTO-GENERATED by scripts/generate-bindings.ts — DO NOT EDIT.\n// Source: AVS-side artifacts in this repo (run `pnpm gen:bindings` to regenerate).\n// Source schema: vaultsfyi/wasm_args_schema.json\nimport { z } from \"zod\";\n\nexport const WasmArgsSchema = z\n\t.object({\n\t\tnetwork: z\n\t\t\t.string()\n\t\t\t.describe(\n\t\t\t\t\"Blockchain network name as accepted by the vaults.fyi API (e.g. 'mainnet', 'base', 'arbitrum').\",\n\t\t\t),\n\t\tvaultAddress: z.string().describe(\"Vault contract address (0x-prefixed) to inspect.\"),\n\t\tlastKnownAllocationHash: z\n\t\t\t.union([\n\t\t\t\tz\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t\tz\n\t\t\t\t\t.null()\n\t\t\t\t\t.describe(\n\t\t\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t\t\t),\n\t\t\t])\n\t\t\t.describe(\n\t\t\t\t\"Hash of the previously observed allocation. Used to detect changes between evaluations. Null on the first evaluation.\",\n\t\t\t)\n\t\t\t.optional(),\n\t})\n\t.describe(\"Inputs passed to the vaults.fyi allocation-change policy WASM at evaluation time\");\n\nexport type WasmArgs = z.infer<typeof WasmArgsSchema>;\n"],"mappings":";AAIO,IAAM,cAAc;AAAA,EAC1B,YAAY;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,OAAO;AAAA,EACR;AACD;;;ACXO,IAAM,YAAY;AAClB,IAAM,eAAe;AACrB,IAAM,mBACZ;AACM,IAAM,YAAY;AAClB,IAAM,cAAc;;;ACJ3B,SAAS,KAAAA,UAAS;;;ACAlB,SAAS,SAAS;AAEX,IAAM,eAAe,EAC1B,OAAO;AAAA,EACP,WAAW,EACT,OAAO,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,0BAA0B,EAAE,OAAO,EAAE,SAAS,yCAAyC;AAAA,EACvF,yBAAyB,EAAE,OAAO,EAAE,SAAS,wCAAwC;AAAA,EACrF,kBAAkB,EAChB,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,EACL,IAAI,GAAG,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,2BAA2B,EACzB,QAAQ,EACR;AAAA,IACA;AAAA,EACD;AAAA,EACD,uBAAuB,EACrB,QAAQ,EACR,SAAS,4EAA4E;AAAA,EACvF,mBAAmB,EACjB,QAAQ,EACR,SAAS,0EAA0E;AACtF,CAAC,EACA,SAAS,mDAAmD,EAC5D,OAAO;;;AC3BT,IAAM,sBAAwD;AAAA,EAC7D,GAAG;AAAA,EACH,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,OAAO;AACR;AAEA,SAAS,gBAAgB,SAAyB;AACjD,QAAM,OAAO,oBAAoB,OAAO;AACxC,MAAI,CAAC,MAAM;AACV,UAAM,IAAI;AAAA,MACT,mCAAmC,OAAO;AAAA,IAC3C;AAAA,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AE,aAAa;AAAA,UACrB,MAAM,CAAC,KAAK;AAAA,UACZ,SAAS,iDAAiD,KAAK,KAAK,KAAK,+BACxE,KAAK,MAAM,QAAQ,YAAY,IAAI,YACpC;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;AA0BO,IAAM,YAAmD;AAAA,EAC/D,IAAI,GAAG,SAAS;AAAA,EAChB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA,UAAU;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,QAAQ,eAAe;AAAA,IACvB,MAAM,aAAa;AAAA,EACpB;AACD;","names":["z","z","z","z"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newton-xyz/policy-pack-vaultsfyi",
3
- "version": "0.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "Typed TypeScript bindings for the Newton vaultsfyi policy pack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Newton Protocol <https://x.com/newton_xyz> (https://newton.xyz)",
@@ -41,21 +41,22 @@
41
41
  "LICENSE"
42
42
  ],
43
43
  "peerDependencies": {
44
- "@newton-xyz/policy-pack-shared": "^0.1.0",
44
+ "@newton-xyz/policy-pack-shared": "^0.3.0",
45
45
  "viem": "^2.0.0",
46
46
  "zod": "^3.0.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.5.1",
50
+ "tsx": "^4.19.0",
50
51
  "typescript": "^5.5.0",
51
52
  "viem": "^2.0.0",
52
53
  "zod": "^3.23.0",
53
- "@newton-xyz/policy-pack-shared": "0.1.0"
54
+ "@newton-xyz/policy-pack-shared": "0.3.0"
54
55
  },
55
56
  "scripts": {
56
57
  "build": "tsup",
57
58
  "dev": "tsup --watch",
58
59
  "typecheck": "tsc --noEmit",
59
- "test": "echo 'no tests yet'"
60
+ "test": "node --import tsx --test src/*.test.ts"
60
61
  }
61
62
  }