@masterpeach/market-sdk 0.2.0-beta.20260930.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/README.md +109 -0
- package/README.zh-CN.md +155 -0
- package/THIRD_PARTY_NOTICES.md +14 -0
- package/dist/abi/index.cjs +14051 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +10882 -0
- package/dist/abi/index.d.ts +10882 -0
- package/dist/abi/index.js +27 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/chunk-TMU4HSZR.js +231 -0
- package/dist/chunk-TMU4HSZR.js.map +1 -0
- package/dist/chunk-TTVBOGKZ.js +14015 -0
- package/dist/chunk-TTVBOGKZ.js.map +1 -0
- package/dist/core.cjs +271 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +99 -0
- package/dist/core.d.ts +99 -0
- package/dist/core.js +35 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +13327 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +840 -0
- package/dist/index.d.ts +840 -0
- package/dist/index.js +2705 -0
- package/dist/index.js.map +1 -0
- package/docs/earnings.md +71 -0
- package/docs/frontend.md +153 -0
- package/docs/latest-contract.md +38 -0
- package/docs/liquidity.md +87 -0
- package/docs/management.md +73 -0
- package/docs/pool-state.md +30 -0
- package/docs/pools.md +118 -0
- package/docs/positions.md +94 -0
- package/docs/variants.md +24 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# MasterPeach Market SDK
|
|
2
|
+
|
|
3
|
+
[简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Frontend guides (Chinese): [integration](docs/frontend.md), [pool discovery and fields](docs/pools.md), [positions and withdrawals](docs/positions.md).
|
|
6
|
+
|
|
7
|
+
Standalone TypeScript SDK for Peach v4 Crypto and RWA markets: verified deployment configuration, pool discovery, fees/sessions, ERC-20 and native liquidity, net earnings, share/claim authorization and permission-aware management. P1–P7 local implementation and package acceptance are complete. No target-chain deployment is certified automatically; this package has not been published as part of this work.
|
|
8
|
+
|
|
9
|
+
Workspace consumers use `@masterpeach/market-sdk: workspace:*` and the existing `viem` catalog. Entry points are the root (client, configuration, types and errors), `/abi` (Market-prefixed ABIs and source commit), and `/core` (bundled shared primitives). The only runtime peer is viem.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createMarketClient, type MarketChainConfig } from "@masterpeach/market-sdk";
|
|
13
|
+
import type { PublicClient } from "viem";
|
|
14
|
+
|
|
15
|
+
export async function verify(publicClient: PublicClient, chain: MarketChainConfig) {
|
|
16
|
+
return createMarketClient({ publicClient, chain }).verifyDeployment();
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Supply an explicit chain ID, confirmation count and deployment. Each contract reference requires a reviewed address and full runtime code hash. Deployment identity includes deploymentId, PoolManager, Registry, authority, optional Reader and supported Hooks. This version models a shared authority for Registry, Reader and Hooks. No unverified Arc preset is provided.
|
|
21
|
+
|
|
22
|
+
Supported Hook kinds are `ramp`, `ramp-eth` and `rwa-ramp`, with implementation `ramp-v1`. Every Hook includes its ClaimFeePolicy; only RWA includes a Calendar. Declare liquidity, nativeLiquidity, claimOperator and management acceptance as disabled, unverified or verified. Native liquidity must be disabled outside RampETH. These values are caller-supplied acceptance records, never automatically promoted by verification.
|
|
23
|
+
|
|
24
|
+
Client construction is offline. `verifyDeployment({ blockNumber? })` checks RPC chain ID, pinned code hashes, wiring, Reader Hook kinds and RWA calendar control at one block, then rejects a changed block hash. A configured StateView is also checked against its expected code and PoolManager. Its report covers code and wiring at that block only, not contract safety or acceptance of money-moving operations. Configuration errors use `InvalidMarketConfigError`; identity failures use `MarketDeploymentVerificationError`; RPC failures use `MarketReadError` with their cause.
|
|
25
|
+
|
|
26
|
+
## Read-only API
|
|
27
|
+
|
|
28
|
+
All reads return `{ block, data }`, with chain/deployment identity, block number/hash and timestamp. Pass the returned block into subsequent calls to keep pages and related data consistent. A changed hash rejects the read. Ordinary queries check RPC chain identity but do not implicitly repeat full deployment verification or start polling.
|
|
29
|
+
|
|
30
|
+
- `listPools({ offset?, limit?, activeOnly?, blockNumber?, blockHash? })`: scan 20 registry entries by default, maximum 100 and eight concurrent calls, without requiring Multicall3. Filtering may produce an empty page with a non-null nextOffset; continue using that offset and the same block.
|
|
31
|
+
- `getPool(poolId, options?)`: full key, active status and supported Hook kind (null for an unrecognized Hook). Unregistered pools revert rather than appearing as empty records.
|
|
32
|
+
- `getCurrentFees(poolId, options?)`: both current direction fees in pips, and global/combined pool pause status. Reader is optional for this method.
|
|
33
|
+
- `getFeeBreakdown(poolId, zeroForOne, options?)`: Reader detail at the selected block's timestamp. Non-RWA sessions are null. Fees are explicitly suffixed Pips.
|
|
34
|
+
- `previewFeeAt(poolId, zeroForOne, timestamp, options?)`: hypothetical time preview using the read block's configuration. Zero is literal, not now; this neither restores historical configuration nor guarantees future execution fees.
|
|
35
|
+
- `getSession(poolId, { timestamp?, ...block }?)`: RWA Hook calendar evaluation; other Hook kinds return null. CLOSED is a fee session, not a trading prohibition.
|
|
36
|
+
- `getRange({ hook, rangeId, ...block })` and `getPosition({ hook, rangeId, owner, ...block })`: range coordinates, net accumulators/resetSeq, pause status, claim fee in bps, shares, settled net owed/checkpoints and Q128 remainders. No historical position enumeration. Unset ranges differ from established ranges with zero shares; historical owed may survive a full exit. Settling ledgers reject snapshots.
|
|
37
|
+
- `getPoolState(poolId, options?)`: requires an explicit reviewed StateView or opted-in Uniswap v4 storage layout; see [pool-state boundaries](./docs/pool-state.md). No implicit address, layout or fallback is chosen.
|
|
38
|
+
|
|
39
|
+
Inactive registry entries remain readable. Pause status does not mean swaps stop or principal withdrawals are blocked. `settledOwed0/1` is not total live claimable earnings; the SDK does not mix gross growth with net checkpoints. Reader failures remain available through `MarketReadError.cause` (use viem `BaseError.walk` to inspect `ContractFunctionRevertedError`), without zero-fee fallback.
|
|
40
|
+
|
|
41
|
+
The root exports corresponding `Market`-prefixed standalone actions plus `defineMarketPoolKey`, `getMarketPoolId`, `getMarketRangeId` and `getMarketSwapDirection`. Keys must already be sorted and carry the dynamic-fee flag. Range hashing uses standard ABI encoding with tick bounds/spacing validation; buy/sell uses explicit base/quote assets.
|
|
42
|
+
|
|
43
|
+
A wallet-free executable example accepts a reviewed public chain JSON config and RPC URL:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pnpm --filter @masterpeach/market-sdk build
|
|
47
|
+
node examples/consumer/scripts/read-market.mjs /path/to/reviewed-chain.json https://rpc.arc-scan.org
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For Arc mainnet (5042), the example defaults to Launchpad's `https://rpc.arc-scan.org` when the URL argument is omitted. Other chains require an explicit URL; the SDK itself continues to use the injected publicClient only. The example verifies deployment identity, then reads one page and a supported pool's fees/optional reader data at the same block. The initial Launchpad RPC attempt returned HTTP 530 / error 1033. Subsequent read-only and local-fork checks passed for the documented Arc test pool with an explicit Blockdaemon RPC override, and for both BSC test pools. The default URL is unchanged; no mainnet funds were moved and production write capabilities are not enabled automatically.
|
|
51
|
+
|
|
52
|
+
## ERC-20 liquidity transactions (P3)
|
|
53
|
+
|
|
54
|
+
Pass an optional `walletClient` to `createMarketClient`. Keep that same instance through `previewDeposit` / `previewWithdraw`, `prepareApproval` / `prepareDeposit` / `prepareWithdraw` / `prepareClaim` / `prepareWithdrawAndClaim`, explicit `send`, and `waitForTransaction`. Preparation only simulates exact calldata using `eth_call`; it never broadcasts. Writes require a reviewed Hook with `liquidity: "verified"`; P5 adds native support under the additional capability and gas requirements below.
|
|
55
|
+
|
|
56
|
+
`getSpendStatus` reads token balances and allowances to the Hook. Approval amounts replace the entire allowance; approve the full required maximum, not a shortfall. Explicit zero approval supports tokens requiring reset before a nonzero amount. Refresh the preview after approvals and recheck the new limits.
|
|
57
|
+
|
|
58
|
+
Previews use bigint math, deposit rounding up and withdrawal rounding down, explicit amount slippage and an on-chain deadline. Local freshness defaults to 60 seconds (maximum 300). Claims and approvals have no on-chain deadline; their local expiry only restricts submission. Paused or deregistered pools still allow principal withdrawal. Claim and combined withdrawal/claim remain subject to pause and the user-provided effective fee cap.
|
|
59
|
+
|
|
60
|
+
Canonical requests are immutable and bound to the creating client, live account and chain. Submission rechecks freshness, deployment identity and simulation. Receipts expose confirmed/reverted status and matching liquidity events; cancelled/replaced transactions and timeouts remain explicit errors. `settledOwed` remains settled net accounting only, not a live claimable estimate.
|
|
61
|
+
|
|
62
|
+
See [API and precision details](./docs/liquidity.md), [consumer examples](../../examples/consumer/src/market.ts) and [third-party math notices](./THIRD_PARTY_NOTICES.md).
|
|
63
|
+
|
|
64
|
+
## Net earnings and delegated claims (P4)
|
|
65
|
+
|
|
66
|
+
`getFeeSnapshot` and `estimateClaimableFees` combine the pinned Hook net ledger with the actual v4 position gross-growth baseline and effective historical fee. Results distinguish settled, synchronized, pending and total claimable base units, retaining Q128 remainders. They refuse unavailable or inconsistent state instead of mixing gross and net growth.
|
|
67
|
+
|
|
68
|
+
Use `getShareAuthorization` / `getClaimOperator` to inspect separate permissions. `prepareTransferShares`, `prepareTransferSharesFrom`, `prepareApproveShares` and `prepareSetShareOperator` handle ERC-6909 shares; `prepareSetClaimOperator` and `prepareClaimFeesFor` handle independent range fee delegation. A share operator controls all ranges on that Hook, whereas a claim operator controls one range's payouts and can choose the recipient. Claim delegation survives transfers, exits and rebuilds until explicitly revoked.
|
|
69
|
+
|
|
70
|
+
All writes retain the P3 preparation/send/receipt protections. Receipts additionally return `shareEvents`; delegated fee events match the beneficiary separately from the signer. See [P4 accounting and API details](./docs/earnings.md). Real local Ramp tests match estimates, actual payouts and remainders exactly under unchanged state; this does not certify Arc deployments.
|
|
71
|
+
|
|
72
|
+
## Reproduce the ABIs
|
|
73
|
+
|
|
74
|
+
Source commit: `cf16bd9376c12ea50de04658b279176d8d56e4f5` in univ4hook. The generated surface includes Ramp, RampETH, RwaRamp, PoolRegistry, RampReader, MarketCalendar, ClaimFeePolicy and AccessManager.
|
|
75
|
+
|
|
76
|
+
Preferred path: build fresh Foundry artifacts in the contract checkout, then run the SDK's `pnpm abi:generate` using `tooling/abi-codegen/market-artifacts.json`, that checkout's `out` directory, `packages/market/src/abi/generated` as output and the full source SHA.
|
|
77
|
+
|
|
78
|
+
For environments without Foundry, import the committed compiler snapshot:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
pnpm --filter @peach-ts-sdk/abi-codegen build
|
|
82
|
+
node tooling/abi-codegen/scripts/import-market.mjs /path/to/univ4hook \
|
|
83
|
+
cf16bd9376c12ea50de04658b279176d8d56e4f5
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The importer reads the exact commit, validates source and ABI SHA-256 fingerprints, and feeds temporary artifact wrappers to the existing generator. It never executes upstream code. `src/abi/provenance.json` records compiler settings and fingerprints; update it alongside generated ABIs when changing versions. Snapshot consistency is not a fresh compilation or a deployed-chain attestation.
|
|
87
|
+
|
|
88
|
+
Run package `typecheck`, `test` and `test:release`, followed by workspace `test:consumer` and `pnpm --filter @peach-ts-sdk/consumer test`. Ordinary tests use deterministic RPC fixtures. The separate `test:integration` command executes real Ramp / v4 PoolManager transactions on a dedicated local Anvil chain; see [local EVM setup](../../tooling/market-integration/README.md). Local evidence does not certify an Arc deployment. See the [implementation plan](../../docs/plans/market-sdk-implementation-plan.md).
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## P5 native and variant acceptance
|
|
92
|
+
|
|
93
|
+
RampETH supports native currency0 with `value = amount0Max`, explicit native capability acceptance and a bound EIP-1559 gas budget checked before preparation completes and before signing. Native spend status has `kind: "native"`, `allowance: null` and no approval; ERC-20 pools always send zero value. Previews expose `nativeValue` and `estimatedNativeRefund`. Local EVM tests cover RampETH native/ERC-20 and RwaRamp ERC-20 funds, rejecting native recipients, gas/refund reconciliation and calendar/override boundaries. See [LP API](./docs/liquidity.md) and [implementation vs deployment acceptance](./docs/variants.md). No target-chain capability is automatically enabled.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## P6 management and delayed permissions
|
|
97
|
+
|
|
98
|
+
`getManagementAuthorization(action, account)` exposes fixed-block immediate/delayed/denied permission, operation ID, schedule and execute calldata. `prepareManagement(action, { execution })` supports fees, Crypto/RWA configuration, Hook-forwarded calendars, pauses, explicit recipient rotation/settlement, protocol fee sweeps, Registry and reviewed Reader registration. Management capability is independent of LP capability. Delayed operations require separate schedule and execute transactions; preparation never broadcasts. Results include `managementEvents`. See [management API and settlement semantics](./docs/management.md).
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## Package acceptance and examples
|
|
102
|
+
|
|
103
|
+
The package includes both language READMEs, the LP/earnings/management guides under `docs`, and third-party notices. Files under `examples` and `tooling` referenced by these guides are available in the source repository. See [LP workflow](./docs/liquidity.md), [net earnings and authorizations](./docs/earnings.md), [variant acceptance](./docs/variants.md), and [management](./docs/management.md).
|
|
104
|
+
|
|
105
|
+
In the repository, run `pnpm --filter @peach-ts-sdk/market-regression regression` for a deterministic offline public consumer, or `node tooling/market-release/verify-packed.mjs` after building for isolated tarball installation and ESM/CJS/NodeNext checks. The working version is 0.1.0; the pending minor changeset proposes 0.2.0 when explicitly applied. Neither verification command versions or publishes the package.
|
|
106
|
+
|
|
107
|
+
TypeScript compatibility: Bundler resolution is verified with TypeScript 5.7.3; NodeNext ESM/CJS declarations require TypeScript 5.9+ (verified with 5.9.3). TypeScript 5.7 NodeNext rejects ESM declaration imports in viem's dependency graph. Isolated checks keep `skipLibCheck: false`; no dependency declarations are patched.
|
|
108
|
+
|
|
109
|
+
Latest contract/deployment changes and explicit test-pool selection: [integration notes](docs/latest-contract.md).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# MasterPeach Market SDK
|
|
2
|
+
|
|
3
|
+
[English](./README.md)
|
|
4
|
+
|
|
5
|
+
Peach v4 Crypto / RWA 市场的独立 TypeScript SDK。P1–P7 本地实现和包验收已完成,覆盖部署核验、池和费率、ERC-20 / 原生币 LP、净收益、份额 / 代领授权及管理权限。目标链部署仍需单独审核,本次没有发布 npm 包。
|
|
6
|
+
|
|
7
|
+
本包尚未发布。workspace 消费方声明 `@masterpeach/market-sdk: workspace:*`,并按仓库 catalog 安装 `viem`。公开入口:
|
|
8
|
+
|
|
9
|
+
| 入口 | 内容 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `@masterpeach/market-sdk` | `createMarketClient`、配置工厂、部署核验、Market 类型和错误 |
|
|
12
|
+
| `@masterpeach/market-sdk/abi` | 八份带 Market 前缀的 ABI、`marketAbiArtifactCommit` |
|
|
13
|
+
| `@masterpeach/market-sdk/core` | 内联的公共金额、链和交易基础能力 |
|
|
14
|
+
|
|
15
|
+
## 前端功能文档
|
|
16
|
+
|
|
17
|
+
- [前端接入指南](docs/frontend.md):安装、Arc/BSC 配置、客户端生命周期、授权与存入、回执和错误处理。
|
|
18
|
+
- [池子列表与详情](docs/pools.md):listPools 参数、完整字段、分页、缺失展示数据及测试资产识别。
|
|
19
|
+
- [我的仓位与提取](docs/positions.md):索引边界、仓位字段、收益、部分/全部退出和领取。
|
|
20
|
+
|
|
21
|
+
## 配置与核验
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createMarketClient, type MarketChainConfig } from "@masterpeach/market-sdk";
|
|
25
|
+
import type { PublicClient } from "viem";
|
|
26
|
+
|
|
27
|
+
export async function verify(publicClient: PublicClient, chain: MarketChainConfig) {
|
|
28
|
+
const client = createMarketClient({ publicClient, chain });
|
|
29
|
+
return client.verifyDeployment();
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`MarketChainConfig` 显式提供 chainId、confirmations 和 deployment。部署包含独立的 deploymentId、PoolManager、Registry、authority、可选 Reader 及 Hook 列表;每个合约引用必须提供非零地址和经审核的完整 runtime code hash。当前模型要求 Registry、Reader 和 Hook 使用同一 authority。不提供尚未核验的 Arc 默认配置,也不自动从实时 RPC 的代码生成“可信”预期值。
|
|
34
|
+
|
|
35
|
+
Hook kind 为 `ramp` / `ramp-eth` / `rwa-ramp`,implementation 当前仅接受 `ramp-v1`。配置必须说明 ClaimFeePolicy;RWA 还必须说明 Calendar。每个 Hook 的 liquidity / nativeLiquidity / claimOperator / management 状态显式设置为 disabled / unverified / verified,描述调用方提供的部署验收记录;非 RampETH 的 nativeLiquidity 必须 disabled。
|
|
36
|
+
|
|
37
|
+
构造 client 不发起网络请求。`verifyDeployment({ blockNumber? })` 会检查实际 RPC chainId、所有合约代码指纹、绑定关系、Reader Hook 类型及 RWA calendar controller;配置 StateView 时也检查其代码与 PoolManager 绑定。组合读固定区块,返回前再次核对区块哈希。报告只证明该区块的代码和绑定符合调用方提供的配置,不证明合约安全、未来配置不变或资金路径已验收,也不会提升 capability 状态。钱包仅在准备和发送资金操作时需要。
|
|
38
|
+
|
|
39
|
+
配置错误抛 `InvalidMarketConfigError`;代码 / 绑定 / 链不匹配抛 `MarketDeploymentVerificationError`,包含 field / expected / actual;RPC 失败抛 `MarketReadError` 并保留 cause。
|
|
40
|
+
|
|
41
|
+
## P2 只读接口
|
|
42
|
+
|
|
43
|
+
所有接口返回 `{ block, data }`。block 包含 chainId、deploymentId、blockNumber、blockHash、timestamp;组合读取固定该区块,并在返回前检查区块哈希。方法不会自动轮询,也不会每次隐式执行完整部署核验;调用方先核验自己的配置。可通过 `{ blockNumber, blockHash }` 延续分页或组合多次查询,哈希不符即报错。
|
|
44
|
+
|
|
45
|
+
| client 方法 | 内容与边界 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `listPools({ offset?, limit?, activeOnly?, ...block })` | 默认扫描 20 条,最多 100 条,最多 8 个并发读取;无 Multicall3 部署依赖 |
|
|
48
|
+
| `getPool(poolId, options?)` | 完整 PoolKey、active、受支持 Hook 类型;未知 Hook 返回 hookKind=null,未知池透传合约回滚 |
|
|
49
|
+
| `getCurrentFees(poolId, options?)` | 两方向当前 pips、全局与池暂停状态;不依赖 Reader |
|
|
50
|
+
| `getFeeBreakdown(poolId, zeroForOne, options?)` | Reader 明细,时间使用目标区块 timestamp,费率字段显式以 Pips 命名 |
|
|
51
|
+
| `previewFeeAt(poolId, zeroForOne, timestamp, options?)` | 使用读区块的配置做指定时间预览;0 按原值传入,不代表现在,不还原历史配置或保证未来成交 |
|
|
52
|
+
| `getSession(poolId, { timestamp?, ...block }?)` | RWA Hook 链上日历结果;非 RWA 返回 null,不复制 DST / 节假日算法 |
|
|
53
|
+
| `getRange({ hook, rangeId, ...block })` | 区间坐标、净累计器、resetSeq、暂停及有效 claim 分账 bps;未建立区间返回 status=unset |
|
|
54
|
+
| `getPosition({ hook, rangeId, owner, ...block })` | LP shares、已结算净 owed、checkpoint 与 Q128 余数;不枚举用户历史区间 |
|
|
55
|
+
| `getPoolState(poolId, options?)` | 显式 StateView / extsload 的价格、tick 和活动流动性,详见 [读取边界](./docs/pool-state.md) |
|
|
56
|
+
|
|
57
|
+
分页的 limit 是扫描量;activeOnly 过滤后可能返回空数组但仍有 nextOffset,不能据此判定遍历结束。将上一页 block 原样传入下一页可避免分页间状态漂移。
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const page = await client.listPools({ limit: 20, activeOnly: true });
|
|
61
|
+
if (page.data.nextOffset !== null) {
|
|
62
|
+
const next = await client.listPools({
|
|
63
|
+
offset: page.data.nextOffset, limit: 20, activeOnly: true, ...page.block,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const pool = page.data.pools.find((entry) => entry.hookKind !== null);
|
|
67
|
+
if (pool) {
|
|
68
|
+
const fees = await client.getCurrentFees(pool.poolId, page.block);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Registry 停用不会阻止读取,也不意味着本金不能退出;poolPaused 包含全局暂停影响,不表示 swap 停止。RWA closed 表示费率时段,不表示禁止交易。Reader 回滚(包括 FeeMismatch、UnsupportedHook)保留在 `MarketReadError.cause`,可用 viem `BaseError.walk` 查找 `ContractFunctionRevertedError`;不会降级为零费率或偷偷改用其他来源。
|
|
73
|
+
|
|
74
|
+
`settledOwed0/1` 仅是 userPosition 已记账的净欠款,不能作为完整实时 claimable。零份额仍可有历史 owed;status=set 且 totalShares=0 表示已建立后清空的区间,区别于 status=unset。不会将实时 gross rangeGrowth 与净 checkpoint 混算。isSettling=true 时拒绝仓位快照并抛 MarketSettlingError。
|
|
75
|
+
|
|
76
|
+
根入口同时提供有 `Market` 前缀的独立 actions,以及 `defineMarketPoolKey`、`getMarketPoolId`、`getMarketRangeId`、`getMarketSwapDirection`。PoolKey 必须已按地址升序排列且使用动态费率;工具不会悄悄交换币种。区间 ID 使用 ABI 标准编码,校验 v4 tick 范围与 spacing。买卖方向按显式 base / quote 定义。
|
|
77
|
+
|
|
78
|
+
配置经审核后,可执行无私钥示例:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
pnpm --filter @masterpeach/market-sdk build
|
|
82
|
+
node examples/consumer/scripts/read-market.mjs /path/to/reviewed-chain.json https://rpc.arc-scan.org
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Arc 主网配置可省略 RPC 参数,示例默认复用 Launchpad 的 `https://rpc.arc-scan.org`;其他链必须显式传 RPC。SDK 核心仍完全使用注入的 publicClient。示例先核验部署,再在同一区块读取一页市场、一个受支持池的费率,以及已配置的 Reader / poolStateReader。早期该 Launchpad 节点返回 HTTP 530;后续使用显式 Blockdaemon RPC 已完成 Arc 测试池线上只读及本地 fork 对账,BSC 两测试池也已通过。默认节点未改变,未进行主网资金广播,详见[前端指南的验证范围](docs/frontend.md#验证范围)。
|
|
86
|
+
|
|
87
|
+
## P3 ERC-20 LP
|
|
88
|
+
|
|
89
|
+
客户端可传入 walletClient;读操作不需要钱包。资金路径必须使用审核后的部署、`liquidity: "verified"` capability 和同一个客户端实例。
|
|
90
|
+
|
|
91
|
+
`previewDeposit` / `previewWithdraw` → 检查 `getSpendStatus`、按需 `prepareApproval` → `prepareDeposit` / `prepareWithdraw` / `prepareClaim` / `prepareWithdrawAndClaim` → 用户显式 `send` → `waitForTransaction`。准备阶段只模拟,不广播;授权覆盖完整所需额度,不是缺口。
|
|
92
|
+
|
|
93
|
+
数学、取整、滑点、deadline、过期、收款人、暂停退出、分账费上限及替换回执行为见 [P3 接入说明](./docs/liquidity.md)。[消费端示例](../../examples/consumer/src/market.ts) 可直接参与类型检查。P5 已增加原生币及 RampETH / RWA 本地资金验收,见下文。
|
|
94
|
+
|
|
95
|
+
## P4 收益、份额与代领
|
|
96
|
+
|
|
97
|
+
`getFeeSnapshot` / `estimateClaimableFees` 按同一区块读取净账本、PoolManager 毛增长基线及有效历史费率,分别返回 settled / synchronized / pending / claimable 和 Q128 余数。`getShareAuthorization` / `getClaimOperator` 明确区分两套授权。份额转移、份额授权及区间代领均复用显式准备和发送流程。
|
|
98
|
+
|
|
99
|
+
完整 API、整数算法、生命周期与授权作用域见 [P4 接入说明](./docs/earnings.md)。真实本地 EVM 已验证估算与实际领取、余数一致;目标链部署资金验收仍须单独完成。
|
|
100
|
+
|
|
101
|
+
## ABI 来源与生成
|
|
102
|
+
|
|
103
|
+
基线:univ4hook `cf16bd9376c12ea50de04658b279176d8d56e4f5`。覆盖 Ramp、RampETH、RwaRamp、PoolRegistry、RampReader、MarketCalendar、ClaimFeePolicy 和 AccessManager。
|
|
104
|
+
|
|
105
|
+
优先在合约仓库执行 `forge build`、`python3 script/export_artifacts.py`,再在 SDK 根目录运行:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
pnpm abi:generate --config tooling/abi-codegen/market-artifacts.json \
|
|
109
|
+
--artifacts-root /path/to/univ4hook/out \
|
|
110
|
+
--output-dir packages/market/src/abi/generated \
|
|
111
|
+
--artifact-commit cf16bd9376c12ea50de04658b279176d8d56e4f5
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
P1 生成 ABI 时没有 Foundry / out,因此采用合约仓库已提交的编译 ABI 快照。P3 已在临时隔离目录另行编译合约用于本地 EVM 验证,没有更换这些生成 ABI。可重现导入:
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
pnpm --filter @peach-ts-sdk/abi-codegen build
|
|
118
|
+
node tooling/abi-codegen/scripts/import-market.mjs /path/to/univ4hook \
|
|
119
|
+
cf16bd9376c12ea50de04658b279176d8d56e4f5
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
导入器从指定 Git commit 读取数据,验证 manifest 中源码及八份 ABI 的 SHA-256,再包装为 artifact 调用已有生成器;不会执行合约仓库脚本。`src/abi/provenance.json` 保存版本、编译参数和指纹。它证明快照一致性,不替代本地重编译或链上代码核验。切换合约版本时同时刷新 provenance 和 ABI;release 测试拒绝二者不一致。
|
|
123
|
+
|
|
124
|
+
## 验证
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
pnpm --filter @masterpeach/market-sdk typecheck
|
|
128
|
+
pnpm --filter @masterpeach/market-sdk test
|
|
129
|
+
pnpm --filter @masterpeach/market-sdk test:release
|
|
130
|
+
pnpm test:consumer
|
|
131
|
+
pnpm --filter @peach-ts-sdk/consumer test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
普通测试使用确定性 RPC fixture,不使用主网账户。`test:integration` 已提供独立的真实本地 EVM 验收,复现方式见 [本地 EVM](../../tooling/market-integration/README.md)。本地通过不等同于 Arc 主网部署验收。完整任务见 [实施方案](../../docs/plans/market-sdk-implementation-plan.md)。
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## P5 原生币与变体资金验收
|
|
138
|
+
|
|
139
|
+
RampETH 已支持 currency0 原生币,存入 value 等于 amount0Max,预览提供 nativeValue / estimatedNativeRefund。原生币无需授权,allowance 返回 null;准备和发送检查预付款加绑定的 EIP-1559 gas 预算。RampETH 原生币 / 双 ERC-20、RwaRamp 双 ERC-20 真实本地资金闭环、拒收回滚和日历边界均已验证。见 [LP 接入](./docs/liquidity.md) 与 [实现和部署验收矩阵](./docs/variants.md)。这不会自动开放 Arc 主网能力。
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## P6 Keeper 与管理接口
|
|
143
|
+
|
|
144
|
+
已提供 `getManagementAuthorization` / `prepareManagement`,覆盖费率、Crypto / RWA 配置、Hook 日历转发、暂停、显式费用收款人轮换 / settleFirst / sweep、Registry 和审核哈希约束的 Reader 管理。management capability 独立于 LP;延迟权限分为 schedule 与 execute,不自动广播或执行。回执新增 managementEvents。详见 [管理接口与债务归属](./docs/management.md)。
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## 包与消费端验收
|
|
148
|
+
|
|
149
|
+
发布白名单包括 dist、中英文 README、docs 接入指南和第三方许可;文档中的 examples / tooling 路径对应源码仓库。`pnpm --filter @peach-ts-sdk/market-regression regression` 默认离线;构建后 `node tooling/market-release/verify-packed.mjs` 在仓库外安装 tarball,验证 ESM / CJS 三入口及 NodeNext .mts / .cts 声明。
|
|
150
|
+
|
|
151
|
+
工作版本仍为0.1.0。待应用的 minor changeset 按仓库惯例建议0.2.0;本次不运行 version 或 publish。独立安装、源码 / ABI / 产物哈希与部署能力边界见仓库 `docs/releases/market-sdk-acceptance.md`。
|
|
152
|
+
|
|
153
|
+
TypeScript 支持边界:Bundler 模式以5.7.3验证;NodeNext ESM / CJS 声明使用5.9+(验证版本5.9.3)。5.7 的 NodeNext 会拒绝 viem 依赖链的 ESM 声明导入。独立验收保持 skipLibCheck=false,不修改依赖声明。
|
|
154
|
+
|
|
155
|
+
最新合约提交、测试资产识别与新池接入见[重新对接说明](docs/latest-contract.md)。
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Uniswap integer math
|
|
2
|
+
|
|
3
|
+
`src/math/liquidity.ts` ports TickMath constants and applies the integer rounding formulas from the MIT-licensed TickMath, SqrtPriceMath and LiquidityAmounts libraries. Position fee-growth and StateLibrary storage calculations in the earnings implementation follow the same MIT-licensed v4 sources.
|
|
4
|
+
|
|
5
|
+
- v4-core: `46c6834698c48bc4a463a86d8420f4eb1d7f3b75`
|
|
6
|
+
- v4-periphery: `9969eec44cfdf07e24b41de47f40276a58401976`
|
|
7
|
+
|
|
8
|
+
Copyright 2023 Universal Navigation Inc.
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|