@newton-xyz/policy-pack-vaultsfyi 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -37,12 +37,14 @@ module.exports = __toCommonJS(index_exports);
37
37
  // src/deployments.ts
38
38
  var deployments = {
39
39
  "11155111": {
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"
40
+ stagef: {
41
+ policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc",
42
+ policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37",
43
+ wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm",
44
+ policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b",
45
+ deployedAt: "2026-06-14",
46
+ notes: "Phase 0 Stream D \u2014 composite namespacing redeploy"
47
+ }
46
48
  }
47
49
  };
48
50
 
@@ -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: \"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;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,IAAM,YAAY;AAClB,IAAM,eAAe;AACrB,IAAM,mBACZ;AACM,IAAM,YAAY;AAClB,IAAM,cAAc;;;ACJ3B,IAAAA,cAAkB;;;ACAlB,iBAAkB;AAEX,IAAM,eAAe,aAC1B,OAAO;AAAA,EACP,WAAW,aACT,OAAO,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,0BAA0B,aAAE,OAAO,EAAE,SAAS,yCAAyC;AAAA,EACvF,yBAAyB,aAAE,OAAO,EAAE,SAAS,wCAAwC;AAAA,EACrF,kBAAkB,aAChB,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,EACL,IAAI,GAAG,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,2BAA2B,a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A;AAAA,IACA;AAAA,EACD,EACC,SAAS;AACZ,CAAC,EACA,SAAS,kFAAkF;;;AJpB7F,IAAM,eAAe;AAYrB,IAAM,0BAA0B,CAAC,MAChC,KAAK,IAAI,IAAI,eAAe,KAAK,MAAM,IAAI,YAAY,CAAC,IAAI,OAAO;AAE7D,IAAM,sBAAuB,aAA8C;AAAA,EACjF,CAAC,QAAQ,QAAQ;AAChB,UAAM,gBAA6C;AAAA,MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,eAAW,SAAS,eAAe;AAClC,YAAM,QAAQ,OAAO,KAAK;AAC1B,UAAI,CAAC,wBAAwB,KAAK,GAAG;AACpC,YAAI,SAAS;AAAA,UACZ,MAAM,cAAE,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":["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, GatewayEnv } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tstagef: {\n\t\t\tpolicy: \"0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc\",\n\t\t\tpolicyData: \"0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37\",\n\t\t\twasmCid: \"bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm\",\n\t\t\tpolicyCodeHash: \"0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b\",\n\t\t\tdeployedAt: \"2026-06-14\",\n\t\t\tnotes: \"Phase 0 Stream D — composite namespacing redeploy\",\n\t\t},\n\t},\n} as const satisfies Readonly<\n\tPartial<Record<ChainId, Readonly<Partial<Record<GatewayEnv, Deployment>>>>>\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).\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc;AAAA,EAC1B,YAAY;AAAA,IACX,QAAQ;AAAA,MACP,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,gBAAgB;AAAA,MAChB,YAAY;AAAA,MACZ,OAAO;AAAA,IACR;AAAA,EACD;AACD;;;ACbO,IAAM,YAAY;AAClB,IAAM,eAAe;AACrB,IAAM,mBACZ;AACM,IAAM,YAAY;AAClB,IAAM,cAAc;;;ACJ3B,IAAAA,cAAkB;;;ACAlB,iBAAkB;AAEX,IAAM,eAAe,aAC1B,OAAO;AAAA,EACP,WAAW,aACT,OAAO,EACP;AAAA,IACA;AAAA,EACD;AAAA,EACD,0BAA0B,aAAE,OAAO,EAAE,SAAS,yCAAyC;AAAA,EACvF,yBAAyB,aAAE,OAAO,EAAE,SAAS,wCAAw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cACvB,MAAM;AAAA,IACN,cACE,OAAO,EACP;AAAA,MACA;AAAA,IACD;AAAA,IACD,cACE,KAAK,EACL;AAAA,MACA;AAAA,IACD;AAAA,EACF,CAAC,EACA;AAAA,IACA;AAAA,EACD,EACC,SAAS;AACZ,CAAC,EACA,SAAS,kFAAkF;;;AJpB7F,IAAM,eAAe;AAYrB,IAAM,0BAA0B,CAAC,MAChC,KAAK,IAAI,IAAI,eAAe,KAAK,MAAM,IAAI,YAAY,CAAC,IAAI,OAAO;AAE7D,IAAM,sBAAuB,aAA8C;AAAA,EACjF,CAAC,QAAQ,QAAQ;AAChB,UAAM,gBAA6C;AAAA,MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,eAAW,SAAS,eAAe;AAClC,YAAM,QAAQ,OAAO,KAAK;AAC1B,UAAI,CAAC,wBAAwB,KAAK,GAAG;AACpC,YAAI,SAAS;AAAA,UACZ,MAAM,cAAE,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":["import_zod","import_zod","import_zod"]}
package/dist/index.d.cts CHANGED
@@ -3,12 +3,14 @@ import { z } from 'zod';
3
3
 
4
4
  declare const deployments: {
5
5
  readonly "11155111": {
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";
6
+ readonly stagef: {
7
+ readonly policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc";
8
+ readonly policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37";
9
+ readonly wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm";
10
+ readonly policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b";
11
+ readonly deployedAt: "2026-06-14";
12
+ readonly notes: "Phase 0 Stream D — composite namespacing redeploy";
13
+ };
12
14
  };
13
15
  };
14
16
 
package/dist/index.d.ts CHANGED
@@ -3,12 +3,14 @@ import { z } from 'zod';
3
3
 
4
4
  declare const deployments: {
5
5
  readonly "11155111": {
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";
6
+ readonly stagef: {
7
+ readonly policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc";
8
+ readonly policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37";
9
+ readonly wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm";
10
+ readonly policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b";
11
+ readonly deployedAt: "2026-06-14";
12
+ readonly notes: "Phase 0 Stream D — composite namespacing redeploy";
13
+ };
12
14
  };
13
15
  };
14
16
 
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  // src/deployments.ts
2
2
  var deployments = {
3
3
  "11155111": {
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"
4
+ stagef: {
5
+ policy: "0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc",
6
+ policyData: "0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37",
7
+ wasmCid: "bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm",
8
+ policyCodeHash: "0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b",
9
+ deployedAt: "2026-06-14",
10
+ notes: "Phase 0 Stream D \u2014 composite namespacing redeploy"
11
+ }
10
12
  }
11
13
  };
12
14
 
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: \"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,U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MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,eAAW,SAAS,eAAe;AAClC,YAAM,QAAQ,OAAO,KAAK;AAC1B,UAAI,CAAC,wBAAwB,KAAK,GAAG;AACpC,YAAI,SAAS;AAAA,UACZ,MAAMC,GAAE,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"]}
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, GatewayEnv } from \"@newton-xyz/policy-pack-shared\";\n\nexport const deployments = {\n\t\"11155111\": {\n\t\tstagef: {\n\t\t\tpolicy: \"0x7eC92AfEdcf2DB90222f04044C47ce0Efd7ccbcc\",\n\t\t\tpolicyData: \"0x9242fc89033C612878e64CcDF6d1Fff8b0d1fC37\",\n\t\t\twasmCid: \"bafybeibiqon7wsceuet2lumtsu6364vnbe6ezwwwtjlnpusclorai3s5nm\",\n\t\t\tpolicyCodeHash: \"0x78067d1329f7cf28fff8728da6f1480a047dde458c04fa8db69407bc7bcb492b\",\n\t\t\tdeployedAt: \"2026-06-14\",\n\t\t\tnotes: \"Phase 0 Stream D — composite namespacing redeploy\",\n\t\t},\n\t},\n} as const satisfies Readonly<\n\tPartial<Record<ChainId, Readonly<Partial<Record<GatewayEnv, Deployment>>>>>\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).\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,MACP,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,gBAAgB;AAAA,MAChB,YAAY;AAAA,MACZ,OAAO;AAAA,IACR;AAAA,EACD;AACD;;;ACbO,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,EAC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,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": "2.0.0",
3
+ "version": "2.0.1",
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,7 +41,7 @@
41
41
  "LICENSE"
42
42
  ],
43
43
  "peerDependencies": {
44
- "@newton-xyz/policy-pack-shared": "^0.3.0",
44
+ "@newton-xyz/policy-pack-shared": "^0.4.0",
45
45
  "viem": "^2.0.0",
46
46
  "zod": "^3.0.0"
47
47
  },
@@ -51,7 +51,7 @@
51
51
  "typescript": "^5.5.0",
52
52
  "viem": "^2.0.0",
53
53
  "zod": "^3.23.0",
54
- "@newton-xyz/policy-pack-shared": "0.3.0"
54
+ "@newton-xyz/policy-pack-shared": "0.4.0"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup",