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>
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
import type { Ledger } from "../ledger/ledger.js";
|
||
import type { ProtocolEconomics } from "../core/economics.js";
|
||
import { cspr } from "../core/units.js";
|
||
import { buildYieldProjection } from "./yield_projection.js";
|
||
|
||
/**
|
||
* LP deposit preview — the lender's counterpart to the borrower's credit simulator.
|
||
* Before committing liquidity, an LP wants to know: what share of the pool would I
|
||
* hold, and what yield should I expect on it? This previews the resulting pool size,
|
||
* the depositor's share, and a forward yield estimate (their pro-rata slice of the
|
||
* book's projected LP interest), without moving any funds.
|
||
*/
|
||
|
||
export interface LpDepositPreview {
|
||
deposit_cspr: number;
|
||
current_liquidity_motes: string;
|
||
resulting_liquidity_motes: string;
|
||
resulting_share: number; // 0..1 of the pool after the deposit
|
||
resulting_utilization: number; // outstanding / new liquidity
|
||
projected_apy: number; // the book's forward LP APY (365d)
|
||
projected_annual_yield_motes: string; // deposit × projected_apy (pro-rata)
|
||
}
|
||
|
||
export function buildLpDepositPreview(ledger: Ledger, economics: ProtocolEconomics, depositCspr: number): LpDepositPreview | { error: string } {
|
||
if (!(depositCspr > 0)) return { error: "deposit must be positive" };
|
||
const deposit = cspr(depositCspr);
|
||
const pool = ledger.pool.poolState();
|
||
const resultingLiquidity = pool.total_liquidity + deposit;
|
||
const share = resultingLiquidity > 0n ? Number(deposit) / Number(resultingLiquidity) : 0;
|
||
const utilization = resultingLiquidity > 0n ? Number(pool.outstanding_credit) / Number(resultingLiquidity) : 0;
|
||
|
||
// Use the book's forward 365-day LP APY as the per-CSPR yield estimate.
|
||
const projection = buildYieldProjection(ledger, economics);
|
||
const annual = projection.horizons.find((h) => h.horizon_days === 365);
|
||
const apy = annual?.projected_apy ?? 0;
|
||
|
||
return {
|
||
deposit_cspr: depositCspr,
|
||
current_liquidity_motes: pool.total_liquidity.toString(),
|
||
resulting_liquidity_motes: resultingLiquidity.toString(),
|
||
resulting_share: Math.round(share * 10000) / 10000,
|
||
resulting_utilization: Math.round(utilization * 10000) / 10000,
|
||
projected_apy: apy,
|
||
projected_annual_yield_motes: BigInt(Math.round(Number(deposit) * apy)).toString(),
|
||
};
|
||
}
|