cred402/test/lp_deposit_preview.test.ts
caelum0x 5cf86893e3 feat(contracts): deploy Cred402 Odra contracts to Casper Testnet (Casper 2.0)
Migrate the contract suite to Odra 2.x (builds on the Casper 2.0 ABI; fixes the
1.x nightly/edition2024 toolchain deadlock) and deploy 9 contracts live to
casper-test via the Odra livenet deployer:

  AgentRegistry · X402ReceiptRegistry · RWAEvidenceRegistry · RWAAssetRegistry
  ReputationEngine · AgentCreditPool · RiskPolicyManager · AgentPassport · DisputeCourt

- contracts: odra "2", no_std headers, build.rs (odra-build), per-crate Odra.toml +
  build_contract/livenet bins; pinned nightly-2025-01-15 for reproducible wasm.
- tooling: scaffold_livenet.py, deploy_all_testnet.sh, deploy_one.mjs.
- deploys.testnet.json: live manifest; README: on-chain contract hashes.
- Deployer key kept out of git (.secrets/ gitignored); wasm artifacts gitignored.

Verified on-chain: AgentRegistry ContractPackage present in global state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 02:34:49 +03:00

42 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test } from "node:test";
import assert from "node:assert/strict";
import { Ledger } from "../lib/ledger/index.js";
import { ProtocolEconomics } from "../lib/core/economics.js";
import { cspr } from "../lib/core/units.js";
import { buildLpDepositPreview } from "../lib/services/lp_deposit_preview.js";
test("lp preview: share reflects the deposit relative to the resulting pool", () => {
const l = new Ledger();
l.pool.deposit_liquidity(cspr(1000), "existing");
const p = buildLpDepositPreview(l, new ProtocolEconomics(), 1000);
assert.ok(!("error" in p));
if ("error" in p) return;
// 1000 into a 1000 pool → 2000 total, 50% share
assert.equal(p.resulting_liquidity_motes, cspr(2000).toString());
assert.equal(p.resulting_share, 0.5);
});
test("lp preview: a deposit into an empty pool is 100% share", () => {
const l = new Ledger();
const p = buildLpDepositPreview(l, new ProtocolEconomics(), 500);
if ("error" in p) return assert.fail("expected preview");
assert.equal(p.resulting_share, 1);
});
test("lp preview: projected annual yield = deposit × projected APY", () => {
const l = new Ledger();
l.pool.deposit_liquidity(cspr(1000), "lp");
const econ = new ProtocolEconomics();
const p = buildLpDepositPreview(l, econ, 1000);
if ("error" in p) return assert.fail("expected preview");
const expected = Math.round(Number(cspr(1000)) * p.projected_apy);
assert.equal(p.projected_annual_yield_motes, String(expected));
});
test("lp preview: non-positive deposit → error", () => {
const l = new Ledger();
assert.ok("error" in buildLpDepositPreview(l, new ProtocolEconomics(), 0));
assert.ok("error" in buildLpDepositPreview(l, new ProtocolEconomics(), -5));
});