From 9dad746fd6a761ae0c9a3da6969c68e60a1535f3 Mon Sep 17 00:00:00 2001 From: Xiaozhou Li Date: Sat, 9 May 2026 19:28:41 -0700 Subject: [PATCH 1/3] rename contracts --- README.md | 20 +- docs/architecture-summary.md | 22 +- docs/contracts.md | 110 ++--- script/.env.example | 2 +- script/DeployCore.s.sol | 16 +- script/DeployLedger.s.sol | 18 +- script/README.md | 32 +- script/example_config.json | 4 +- src/{CelerLedger.sol => AgentPayLedger.sol} | 34 +- ...rLedgerMock.sol => AgentPayLedgerMock.sol} | 26 +- src/{CelerWallet.sol => AgentPayWallet.sol} | 40 +- src/helper/ERC20ExampleToken.sol | 2 +- src/helper/NativeWrapMock.sol | 2 +- src/helper/WalletTestHelper.sol | 10 +- .../{ICelerLedger.sol => IAgentPayLedger.sol} | 18 +- .../{ICelerWallet.sol => IAgentPayWallet.sol} | 16 +- src/interfaces/INativeWrap.sol | 2 +- src/lib/AgentPayErrors.sol | 4 +- src/lib/data/proto/entity.proto | 2 +- src/lib/ledgerlib/LedgerChannel.sol | 12 +- src/lib/ledgerlib/LedgerMigrate.sol | 18 +- src/lib/ledgerlib/LedgerOperation.sol | 80 ++-- src/lib/ledgerlib/LedgerStruct.sol | 18 +- ...ERC20.t.sol => AgentPayLedger.ERC20.t.sol} | 66 +-- ...ger.ETH.t.sol => AgentPayLedger.ETH.t.sol} | 406 +++++++++--------- ...ate.t.sol => AgentPayLedger.Migrate.t.sol} | 73 ++-- ...CelerWallet.t.sol => AgentPayWallet.t.sol} | 12 +- test/GasReport.t.sol | 142 +++--- test/gas_logs/AgentPayLedger-ERC20.txt | 8 + ...rLedger-ETH.txt => AgentPayLedger-ETH.txt} | 18 +- ...Migrate.txt => AgentPayLedger-Migrate.txt} | 2 +- test/gas_logs/CelerLedger-ERC20.txt | 8 - test/invariants/ChannelInvariants.t.sol | 30 +- test/invariants/handlers/ChannelHandler.sol | 14 +- test/utils/Base.t.sol | 18 +- test/utils/LedgerTestBase.t.sol | 20 +- 36 files changed, 662 insertions(+), 663 deletions(-) rename src/{CelerLedger.sol => AgentPayLedger.sol} (94%) rename src/{CelerLedgerMock.sol => AgentPayLedgerMock.sol} (97%) rename src/{CelerWallet.sol => AgentPayWallet.sol} (92%) rename src/interfaces/{ICelerLedger.sol => IAgentPayLedger.sol} (97%) rename src/interfaces/{ICelerWallet.sol => IAgentPayWallet.sol} (94%) rename test/{CelerLedger.ERC20.t.sol => AgentPayLedger.ERC20.t.sol} (71%) rename test/{CelerLedger.ETH.t.sol => AgentPayLedger.ETH.t.sol} (77%) rename test/{CelerLedger.Migrate.t.sol => AgentPayLedger.Migrate.t.sol} (68%) rename test/{CelerWallet.t.sol => AgentPayWallet.t.sol} (98%) create mode 100644 test/gas_logs/AgentPayLedger-ERC20.txt rename test/gas_logs/{CelerLedger-ETH.txt => AgentPayLedger-ETH.txt} (64%) rename test/gas_logs/{CelerLedger-Migrate.txt => AgentPayLedger-Migrate.txt} (75%) delete mode 100644 test/gas_logs/CelerLedger-ERC20.txt diff --git a/README.md b/README.md index 28170b1..6603186 100644 --- a/README.md +++ b/README.md @@ -44,22 +44,22 @@ Six top-level contracts in [`src/`](src/), grouped by role: ### Asset custody (permanent, audited, not versioned) -- **[CelerWallet](src/CelerWallet.sol)** — Multi-owner / multi-token wallet shared by - the whole network; the only contract that holds funds. Operated by a `CelerLedger`. +- **[AgentPayWallet](src/AgentPayWallet.sol)** — Multi-owner / multi-token wallet shared by + the whole network; the only contract that holds funds. Operated by a `AgentPayLedger`. - **[PayRegistry](src/PayRegistry.sol)** — Append-only global record of resolved conditional-payment results, indexed by `payId = keccak256(payHash, setterAddress)`. - **[VirtContractResolver](src/VirtContractResolver.sol)** — On-demand deployer for virtual (off-chain) contracts when disputes need them on-chain. -`CelerLedger` additionally depends on the chain's canonical wrapped-native +`AgentPayLedger` additionally depends on the chain's canonical wrapped-native (WETH9-style) contract for the multi-party-funding path on native channels — wired at deploy time via the `_nativeWrap` constructor argument. Users still deposit and receive native; wrapped-native is internal plumbing only. ### Channel & payment logic (versioned, peer-controlled migration) -- **[CelerLedger](src/CelerLedger.sol)** — Channel state machine and primary user entry - point; operator of `CelerWallet`. Logic split across libraries in +- **[AgentPayLedger](src/AgentPayLedger.sol)** — Channel state machine and primary user entry + point; operator of `AgentPayWallet`. Logic split across libraries in [`src/lib/ledgerlib/`](src/lib/ledgerlib/). - **[PayResolver](src/PayResolver.sol)** — On-chain resolution of conditional payments; evaluates conditions or vouched results and writes outcomes to `PayRegistry`. @@ -78,9 +78,9 @@ For per-contract APIs, constructor args, events, and storage, see ``` src/ -├── CelerLedger.sol # channel state machine; primary entry point (versioned) -├── CelerLedgerMock.sol # test-only ledger variant -├── CelerWallet.sol # multi-owner asset custodian (permanent) +├── AgentPayLedger.sol # channel state machine; primary entry point (versioned) +├── AgentPayLedgerMock.sol # test-only ledger variant +├── AgentPayWallet.sol # multi-owner asset custodian (permanent) ├── PayRegistry.sol # global resolved-payment registry (permanent) ├── PayResolver.sol # conditional-pay resolution (versioned) ├── RouterRegistry.sol # optional relay-router registry @@ -89,10 +89,10 @@ src/ ├── interfaces/ # I*.sol — public ABI surface └── lib/ ├── data/ # auto-generated protobuf decoders + .proto sources - └── ledgerlib/ # CelerLedger logic split into libraries (EIP-170 size-split) + └── ledgerlib/ # AgentPayLedger logic split into libraries (EIP-170 size-split) test/ # Foundry tests -├── invariants/ # property-based / fuzz invariants for CelerLedger +├── invariants/ # property-based / fuzz invariants for AgentPayLedger ├── utils/ # shared test base + fixtures + signing utils └── *.t.sol # per-contract unit tests script/ # Forge deploy scripts diff --git a/docs/architecture-summary.md b/docs/architecture-summary.md index 519a63f..b764ec5 100644 --- a/docs/architecture-summary.md +++ b/docs/architecture-summary.md @@ -21,13 +21,13 @@ conditional payments through routed paths. The blockchain is only touched for de withdrawals, settlement, dispute resolution, and (rarely) deploying virtual contracts. The six contracts split cleanly into two roles. **Asset custody** lives in -permanent, audited contracts that change rarely or never (`CelerWallet`, `PayRegistry`, +permanent, audited contracts that change rarely or never (`AgentPayWallet`, `PayRegistry`, `VirtContractResolver`). **Channel and payment logic** lives in *versioned* -contracts (`CelerLedger`, `PayResolver`) that peers can cooperatively migrate between +contracts (`AgentPayLedger`, `PayResolver`) that peers can cooperatively migrate between without disturbing the assets — see [Decentralized Versioning][versioning] in the full docs. `RouterRegistry` is an optional advertisement registry for relay nodes. -`CelerLedger` additionally depends on the chain's canonical wrapped-native +`AgentPayLedger` additionally depends on the chain's canonical wrapped-native (wrapped-native) contract for the multi-party-funding path on native channels — wired at deploy time, never user-visible. Users still deposit and receive native. @@ -51,8 +51,8 @@ These shape every choice in the codebase. Read the full text in A sixth, structural principle: **decentralized, peer-controlled versioning** — instead of admin-controlled proxy upgrades, channel peers cooperatively migrate to new -`CelerLedger` / `PayResolver` versions. This eliminates trusted upgrade controllers and -keeps asset custody (`CelerWallet`) immutable. +`AgentPayLedger` / `PayResolver` versions. This eliminates trusted upgrade controllers and +keeps asset custody (`AgentPayWallet`) immutable. [system-overview]: https://agentpay-docs.celer.network/agentpay-architecture/system-overview @@ -60,7 +60,7 @@ keeps asset custody (`CelerWallet`) immutable. ## Channel state machine -The status of a payment channel inside `CelerLedger` (see +The status of a payment channel inside `AgentPayLedger` (see [`LedgerStruct.ChannelStatus`](../src/lib/ledgerlib/LedgerStruct.sol)): ``` @@ -79,13 +79,13 @@ The status of a payment channel inside `CelerLedger` (see (on the OLD ledger) ``` -- **Uninitialized** — channel does not yet exist in this `CelerLedger` instance. +- **Uninitialized** — channel does not yet exist in this `AgentPayLedger` instance. - **Operable** — active; deposits, withdrawals, snapshots, off-chain pay forwarding. - **Settling** — `intendSettle` opened a challenge window; counterparty can submit newer simplex states. - **Closed** — terminal; balances paid out, channel finalized. - **Migrated** — terminal *on the old ledger*; the channel continues life on a new - `CelerLedger` version. Migration outranks `intendSettle`: peers can migrate even + `AgentPayLedger` version. Migration outranks `intendSettle`: peers can migrate even while `Settling`, returning the channel to `Operable` on the new ledger. For the full state-transition rules, see @@ -99,8 +99,8 @@ For the full state-transition rules, see | Contract | Role | Versioned? | |---|---|---| -| [`CelerWallet`](../src/CelerWallet.sol) | Multi-owner / multi-token asset custodian. One global instance. | No (permanent) | -| [`CelerLedger`](../src/CelerLedger.sol) | Channel state machine + primary user entry point. Operator of `CelerWallet`. | **Yes** | +| [`AgentPayWallet`](../src/AgentPayWallet.sol) | Multi-owner / multi-token asset custodian. One global instance. | No (permanent) | +| [`AgentPayLedger`](../src/AgentPayLedger.sol) | Channel state machine + primary user entry point. Operator of `AgentPayWallet`. | **Yes** | | [`PayResolver`](../src/PayResolver.sol) | On-chain conditional-pay resolution; writes results to `PayRegistry`. | **Yes** (chosen per-payment) | | [`PayRegistry`](../src/PayRegistry.sol) | Global `payId → (amount, deadline)` map; immutable, public reference. | No (permanent) | | [`VirtContractResolver`](../src/VirtContractResolver.sol) | On-demand deployment of virtual contracts during disputes. | No (permanent) | @@ -124,7 +124,7 @@ not violate them. never lowered. This protects relay nodes from collusive source/dest pairs. - Migration outranks `intendSettle`. Cooperative migration always wins over a unilateral settle in flight. -- `CelerWallet` has exactly one **operator** (a `CelerLedger` instance). Operatorship +- `AgentPayWallet` has exactly one **operator** (a `AgentPayLedger` instance). Operatorship transfer is the migration pivot; only the current operator (or all owners cooperatively, via `voteForOperator`) can transfer it. diff --git a/docs/contracts.md b/docs/contracts.md index a69e926..6dc9355 100644 --- a/docs/contracts.md +++ b/docs/contracts.md @@ -7,8 +7,8 @@ contract file is authoritative. ## Table of Contents -- [CelerWallet](#celerwallet) -- [CelerLedger](#celerledger) +- [AgentPayWallet](#agentpaywallet) +- [AgentPayLedger](#agentpayledger) - [PayResolver](#payresolver) - [PayRegistry](#payregistry) - [VirtContractResolver](#virtcontractresolver) @@ -18,12 +18,12 @@ contract file is authoritative. --- -## CelerWallet +## AgentPayWallet -[Source](../src/CelerWallet.sol) · [Interface](../src/interfaces/ICelerWallet.sol) · **Permanent** (not versioned) +[Source](../src/AgentPayWallet.sol) · [Interface](../src/interfaces/IAgentPayWallet.sol) · **Permanent** (not versioned) Multi-owner, multi-token wallet that holds the funds for every channel in the network. -A single `CelerWallet` instance is shared globally; every `CelerLedger` (current or +A single `AgentPayWallet` instance is shared globally; every `AgentPayLedger` (current or future versions) is an *operator* over individual wallets within it. The contract has deliberately minimal logic — it only knows how to deposit, withdraw, and transfer operatorship — to keep the audit surface small. @@ -45,7 +45,7 @@ can `pause` / `unpause` and (when paused) `drainToken` to recover stuck funds. ### Roles - **Owners** — the channel peers; receive withdrawals and vote on operator candidates. -- **Operator** — exactly one per wallet; the `CelerLedger` instance authorized to move +- **Operator** — exactly one per wallet; the `AgentPayLedger` instance authorized to move funds. Operatorship is the migration pivot point. - **Contract owner** (Ownable) — can pause / unpause and drain when paused. @@ -53,14 +53,14 @@ can `pause` / `unpause` and (when paused) `drainToken` to recover stuck funds. | Function | Caller | Purpose | |---|---|---| -| [`create`](../src/CelerWallet.sol) | anyone (typically a `CelerLedger`) | Create a new wallet for a peer-pair, returning its `walletId`. | -| [`depositNative`](../src/CelerWallet.sol) | anyone (payable) | Deposit native (e.g., ETH) into a wallet. | -| [`depositERC20`](../src/CelerWallet.sol) | anyone | Deposit ERC-20 tokens (requires prior `approve`). | -| [`withdraw`](../src/CelerWallet.sol) | operator only | Withdraw funds to a receiver. | -| [`transferBetweenWallets`](../src/CelerWallet.sol) | operator only | Move funds between two wallets sharing the same operator (channel rebalancing). | -| [`transferOperatorship`](../src/CelerWallet.sol) | current operator | Transfer operatorship to a new operator (the migration path). | -| [`voteForOperator`](../src/CelerWallet.sol) | wallet owner | Vote for a new operator candidate; the change takes effect when *all* owners have voted for the same candidate (manual fallback for stuck migrations). | -| [`drainToken`](../src/CelerWallet.sol) | contract owner, when paused | Emergency token recovery. | +| [`create`](../src/AgentPayWallet.sol) | anyone (typically a `AgentPayLedger`) | Create a new wallet for a peer-pair, returning its `walletId`. | +| [`depositNative`](../src/AgentPayWallet.sol) | anyone (payable) | Deposit native (e.g., ETH) into a wallet. | +| [`depositERC20`](../src/AgentPayWallet.sol) | anyone | Deposit ERC-20 tokens (requires prior `approve`). | +| [`withdraw`](../src/AgentPayWallet.sol) | operator only | Withdraw funds to a receiver. | +| [`transferBetweenWallets`](../src/AgentPayWallet.sol) | operator only | Move funds between two wallets sharing the same operator (channel rebalancing). | +| [`transferOperatorship`](../src/AgentPayWallet.sol) | current operator | Transfer operatorship to a new operator (the migration path). | +| [`voteForOperator`](../src/AgentPayWallet.sol) | wallet owner | Vote for a new operator candidate; the change takes effect when *all* owners have voted for the same candidate (manual fallback for stuck migrations). | +| [`drainToken`](../src/AgentPayWallet.sol) | contract owner, when paused | Emergency token recovery. | | `pause` / `unpause` | contract owner | Pause guard for deposits / withdrawals / operator changes. | | `walletOwners` / `walletOperator` / `balanceOf` / `pendingOperator` / `hasVoted` | view | Wallet introspection. | @@ -68,7 +68,7 @@ can `pause` / `unpause` and (when paused) `drainToken` to recover stuck funds. `WalletCreated`, `Deposited`, `Withdrawn`, `TransferredBetweenWallets`, `OperatorChanged`, `OperatorVoted`, `TokenDrained`. See -[`ICelerWallet.sol`](../src/interfaces/ICelerWallet.sol). +[`IAgentPayWallet.sol`](../src/interfaces/IAgentPayWallet.sol). ### Storage @@ -90,16 +90,16 @@ mapping(bytes32 => Wallet) private wallets; walletId = keccak256(chainid, walletAddr, creatorAddr, nonce) ``` -`creatorAddr` is `msg.sender` at the time `CelerWallet.create` is called — typically -the `CelerLedger` contract, not the end-user operator. The `chainid` prefix prevents +`creatorAddr` is `msg.sender` at the time `AgentPayWallet.create` is called — typically +the `AgentPayLedger` contract, not the end-user operator. The `chainid` prefix prevents cross-chain wallet-id collisions when the same creator and nonce are reused across chains. --- -## CelerLedger +## AgentPayLedger -[Source](../src/CelerLedger.sol) · [Interface](../src/interfaces/ICelerLedger.sol) · **Versioned** +[Source](../src/AgentPayLedger.sol) · [Interface](../src/interfaces/IAgentPayLedger.sol) · **Versioned** The channel state machine and primary user entry point. The contract is a thin facade — the bulk of channel logic is split across three libraries under @@ -108,21 +108,21 @@ with the type-only `LedgerStruct` namespace alongside them. See [Ledger libraries](#ledger-libraries) below. > **Supported tokens:** native (e.g. ETH) and plain ERC-20 only — see the same -> note under [CelerWallet](#celerwallet). Non-standard ERC-20s +> note under [AgentPayWallet](#agentpaywallet). Non-standard ERC-20s > (fee-on-transfer / rebasing / ERC-777 hooks) will desync channel accounting > from the wallet's real token balance. ### Constructor ```solidity -constructor(address _nativeWrap, address _payRegistry, address _celerWallet) Ownable(msg.sender) +constructor(address _nativeWrap, address _payRegistry, address _wallet) Ownable(msg.sender) ``` | Param | Purpose | |---|---| | `_nativeWrap` | Chain's canonical wrapped-native (wrapped-native) address. Used internally as a funding-flow primitive for native channels; never user-visible. Constructor-set; no setter. | | `_payRegistry` | Address of the deployed [`PayRegistry`](#payregistry). | -| `_celerWallet` | Address of the deployed [`CelerWallet`](#celerwallet). | +| `_wallet` | Address of the deployed [`AgentPayWallet`](#agentpaywallet). | Balance limits are **enabled by default** post-deployment. Configure them via `setBalanceLimits` or call `disableBalanceLimits` for unlimited per-channel deposits. @@ -131,35 +131,35 @@ Balance limits are **enabled by default** post-deployment. Configure them via | Function | Purpose | |---|---| -| [`openChannel`](../src/CelerLedger.sol) | Open a fully-funded channel from a co-signed `PaymentChannelInitializer` (single tx). | -| [`deposit`](../src/CelerLedger.sol) | Deposit native (msg.value) and/or pull from pre-approved wrapped-native or ERC-20 into a channel. | -| [`depositInBatch`](../src/CelerLedger.sol) | Batch deposit across multiple channels in one tx. Not payable — native entries fund only via pre-approved wrapped-native (no `msg.value` path). | -| [`snapshotStates`](../src/CelerLedger.sol) | Persist a co-signed simplex state on-chain (lightweight checkpoint). | +| [`openChannel`](../src/AgentPayLedger.sol) | Open a fully-funded channel from a co-signed `PaymentChannelInitializer` (single tx). | +| [`deposit`](../src/AgentPayLedger.sol) | Deposit native (msg.value) and/or pull from pre-approved wrapped-native or ERC-20 into a channel. | +| [`depositInBatch`](../src/AgentPayLedger.sol) | Batch deposit across multiple channels in one tx. Not payable — native entries fund only via pre-approved wrapped-native (no `msg.value` path). | +| [`snapshotStates`](../src/AgentPayLedger.sol) | Persist a co-signed simplex state on-chain (lightweight checkpoint). | ### External functions — withdrawals | Function | Purpose | |---|---| -| [`cooperativeWithdraw`](../src/CelerLedger.sol) | Single-tx withdrawal with a co-signed `CooperativeWithdrawInfo`. | -| [`intendWithdraw`](../src/CelerLedger.sol) | Start a unilateral withdrawal challenge window. | -| [`vetoWithdraw`](../src/CelerLedger.sol) | Counterparty cancels an in-flight unilateral withdrawal. | -| [`confirmWithdraw`](../src/CelerLedger.sol) | Finalize a unilateral withdrawal after the window closes. | +| [`cooperativeWithdraw`](../src/AgentPayLedger.sol) | Single-tx withdrawal with a co-signed `CooperativeWithdrawInfo`. | +| [`intendWithdraw`](../src/AgentPayLedger.sol) | Start a unilateral withdrawal challenge window. | +| [`vetoWithdraw`](../src/AgentPayLedger.sol) | Counterparty cancels an in-flight unilateral withdrawal. | +| [`confirmWithdraw`](../src/AgentPayLedger.sol) | Finalize a unilateral withdrawal after the window closes. | ### External functions — settlement | Function | Purpose | |---|---| -| [`cooperativeSettle`](../src/CelerLedger.sol) | Single-tx close with a co-signed `CooperativeSettleInfo`. | -| [`intendSettle`](../src/CelerLedger.sol) | Start unilateral settlement using the latest co-signed simplex states. | -| [`clearPays`](../src/CelerLedger.sol) | Settle additional pending pays via a `PayIdList` after `intendSettle`. | -| [`confirmSettle`](../src/CelerLedger.sol) | Finalize unilateral settlement after the challenge window. | +| [`cooperativeSettle`](../src/AgentPayLedger.sol) | Single-tx close with a co-signed `CooperativeSettleInfo`. | +| [`intendSettle`](../src/AgentPayLedger.sol) | Start unilateral settlement using the latest co-signed simplex states. | +| [`clearPays`](../src/AgentPayLedger.sol) | Settle additional pending pays via a `PayIdList` after `intendSettle`. | +| [`confirmSettle`](../src/AgentPayLedger.sol) | Finalize unilateral settlement after the challenge window. | ### External functions — migration (decentralized versioning) | Function | Purpose | |---|---| -| [`migrateChannelFrom`](../src/CelerLedger.sol) | Called on the **new** ledger; orchestrates the migration end-to-end. | -| [`migrateChannelTo`](../src/CelerLedger.sol) | Called on the **old** ledger by the new one; transfers operatorship and exposes state. | +| [`migrateChannelFrom`](../src/AgentPayLedger.sol) | Called on the **new** ledger; orchestrates the migration end-to-end. | +| [`migrateChannelTo`](../src/AgentPayLedger.sol) | Called on the **old** ledger by the new one; transfers operatorship and exposes state. | ### External functions — admin @@ -176,8 +176,8 @@ A wide set of getters: `getChannelStatus`, `getTokenContract`, `getTokenType`, `getWithdrawIntent`, `getCooperativeWithdrawSeqNum`, `getSettleFinalizedTime`, `getDisputeTimeout`, `getMigratedTo`, `getChannelMigrationArgs`, `getPeersMigrationInfo`, `getChannelStatusNum`, `getNativeWrap`, `getPayRegistry`, -`getCelerWallet`, `getBalanceLimit`, `getBalanceLimitsEnabled`. See -[`ICelerLedger.sol`](../src/interfaces/ICelerLedger.sol). +`getAgentPayWallet`, `getBalanceLimit`, `getBalanceLimitsEnabled`. See +[`IAgentPayLedger.sol`](../src/interfaces/IAgentPayLedger.sol). ### Events @@ -190,7 +190,7 @@ Settle: `IntendSettle`, `ClearOnePay`, `ConfirmSettle`, `ConfirmSettleFail`, ```solidity LedgerStruct.Ledger private ledger; -// → channelStatusNums, nativeWrap, payRegistry, celerWallet, +// → channelStatusNums, nativeWrap, payRegistry, wallet, // balanceLimits, balanceLimitsEnabled, channelMap (bytes32 → Channel) ``` @@ -331,8 +331,8 @@ refresh. ## Ledger libraries -`CelerLedger.sol` is intentionally thin. The bulk of channel logic lives in three -libraries under [`src/lib/ledgerlib/`](../src/lib/ledgerlib/), attached to `CelerLedger` +`AgentPayLedger.sol` is intentionally thin. The bulk of channel logic lives in three +libraries under [`src/lib/ledgerlib/`](../src/lib/ledgerlib/), attached to `AgentPayLedger` via `using ... for ...`. A fourth file, `LedgerStruct.sol`, holds shared types but compiles to no bytecode (no functions). @@ -344,25 +344,25 @@ compiles to no bytecode (no functions). | [`LedgerMigrate`](../src/lib/ledgerlib/LedgerMigrate.sol) | `migrateChannelFrom` / `migrateChannelTo` — peer-controlled version migration. | **When debugging or extending channel behavior, the implementation almost always lives -in one of these libraries — not in `CelerLedger.sol`.** +in one of these libraries — not in `AgentPayLedger.sol`.** Balance-limit admin (`setBalanceLimits` / `disableBalanceLimits` / `enableBalanceLimits` / `getBalanceLimit` / `getBalanceLimitsEnabled`) and ledger-wide config getters -(`getNativeWrap` / `getPayRegistry` / `getCelerWallet`) live **directly on -`CelerLedger`** rather than in a library. They're pure storage reads / writes — going +(`getNativeWrap` / `getPayRegistry` / `getAgentPayWallet`) live **directly on +`AgentPayLedger`** rather than in a library. They're pure storage reads / writes — going through a library would only add a DELEGATECALL hop with no logic benefit. ### Why split into libraries? The split is **forced by the EIP-170 deployed-bytecode limit (24,576 bytes)**. The hot-path library `LedgerOperation` alone is ~20.5 KB, leaving only ~4.0 KB of -headroom; merging the rest back into a single `CelerLedger` contract would total +headroom; merging the rest back into a single `AgentPayLedger` contract would total ~37.9 KB and fail to deploy. | Component | Deployed size | % of 24,576 budget | |---|---:|---:| | `LedgerOperation` | ~20.5 KB | 84% | -| `CelerLedger` (facade + balance-limit admin + config getters) | ~8.4 KB | 34% | +| `AgentPayLedger` (facade + balance-limit admin + config getters) | ~8.4 KB | 34% | | `LedgerMigrate` | ~5.2 KB | 21% | | `LedgerChannel` | ~3.8 KB | 15% | @@ -371,20 +371,20 @@ path's bytecode budget. ### How the libraries work mechanically -1. **Storage layout** is owned by `CelerLedger` — the `Ledger` and `Channel` structs +1. **Storage layout** is owned by `AgentPayLedger` — the `Ledger` and `Channel` structs defined in [`LedgerStruct`](../src/lib/ledgerlib/LedgerStruct.sol) describe the - slots; `CelerLedger` declares the actual storage variable. + slots; `AgentPayLedger` declares the actual storage variable. 2. **Library functions take a `storage` pointer** as their first parameter (e.g. `function openChannel(LedgerStruct.Ledger storage _self, ...) external`). -3. **`using LedgerOperation for LedgerStruct.Ledger;`** in `CelerLedger` lets the +3. **`using LedgerOperation for LedgerStruct.Ledger;`** in `AgentPayLedger` lets the facade write `ledger.openChannel(...)`; the compiler rewrites that as a `DELEGATECALL` into the deployed library, passing the storage pointer. -4. **DELEGATECALL semantics** mean the library code executes in `CelerLedger`'s - context: storage reads/writes hit `CelerLedger`'s slots; `msg.sender` and - `msg.value` are whatever the user sent to `CelerLedger`. The library is just code +4. **DELEGATECALL semantics** mean the library code executes in `AgentPayLedger`'s + context: storage reads/writes hit `AgentPayLedger`'s slots; `msg.sender` and + `msg.value` are whatever the user sent to `AgentPayLedger`. The library is just code on a separate address. -The libraries are deployed as their own contracts; `CelerLedger`'s bytecode contains +The libraries are deployed as their own contracts; `AgentPayLedger`'s bytecode contains 20-byte placeholders that are patched with each library's address at deployment time. See [`script/README.md`](../script/README.md#how-the-libraries-are-deployed) for the deployment mechanics. @@ -399,10 +399,10 @@ never be deployed to a production network. | File | Purpose | |---|---| -| [`CelerLedgerMock`](../src/CelerLedgerMock.sol) | Test ledger with extra hooks; used in migration tests where two ledger versions must coexist. | +| [`AgentPayLedgerMock`](../src/AgentPayLedgerMock.sol) | Test ledger with extra hooks; used in migration tests where two ledger versions must coexist. | | [`BooleanCondMock`](../src/helper/BooleanCondMock.sol) | Mock condition contract returning a settable boolean outcome. Used in `PayResolver` tests. | | [`NumericCondMock`](../src/helper/NumericCondMock.sol) | Mock condition contract returning a settable numeric outcome. | -| [`WalletTestHelper`](../src/helper/WalletTestHelper.sol) | Helper for direct `CelerWallet` integration tests. | +| [`WalletTestHelper`](../src/helper/WalletTestHelper.sol) | Helper for direct `AgentPayWallet` integration tests. | | [`ERC20ExampleToken`](../src/helper/ERC20ExampleToken.sol) | Sample ERC-20 used in token-channel tests. | The protobuf decoders [`Pb.sol`](../src/lib/data/Pb.sol), diff --git a/script/.env.example b/script/.env.example index 8dfdfe8..41c51f5 100644 --- a/script/.env.example +++ b/script/.env.example @@ -2,7 +2,7 @@ # set -a; source script/.env; set +a # Deployer private key (hex, with 0x prefix). Pays gas and becomes the initial -# Ownable owner of `CelerWallet` and `CelerLedger`. +# Ownable owner of `AgentPayWallet` and `AgentPayLedger`. PRIVATE_KEY=0x... # RPC URL for the target network diff --git a/script/DeployCore.s.sol b/script/DeployCore.s.sol index 571966a..e688784 100644 --- a/script/DeployCore.s.sol +++ b/script/DeployCore.s.sol @@ -4,13 +4,13 @@ pragma solidity ^0.8.20; import {Script, console} from "forge-std/Script.sol"; import {PayRegistry} from "../src/PayRegistry.sol"; import {VirtContractResolver} from "../src/VirtContractResolver.sol"; -import {CelerWallet} from "../src/CelerWallet.sol"; +import {AgentPayWallet} from "../src/AgentPayWallet.sol"; /** * @title DeployCore * @notice Deploys the three permanent (non-versioned) AgentPay contracts on a - * fresh network: `PayRegistry`, `VirtContractResolver`, `CelerWallet`. These - * are deployed once per network and shared by every `CelerLedger` / + * fresh network: `PayRegistry`, `VirtContractResolver`, `AgentPayWallet`. These + * are deployed once per network and shared by every `AgentPayLedger` / * `PayResolver` version that follows. * * @dev Usage: @@ -23,24 +23,24 @@ import {CelerWallet} from "../src/CelerWallet.sol"; * * Environment variables: * PRIVATE_KEY — Deployer private key (required). Deployer becomes the - * `CelerWallet` Ownable owner (pause / drain / unpause). + * `AgentPayWallet` Ownable owner (pause / drain / unpause). */ contract DeployCore is Script { function run() external - returns (PayRegistry payRegistry, VirtContractResolver virtResolver, CelerWallet celerWallet) + returns (PayRegistry payRegistry, VirtContractResolver virtResolver, AgentPayWallet wallet) { uint256 deployerKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerKey); payRegistry = new PayRegistry(); virtResolver = new VirtContractResolver(); - celerWallet = new CelerWallet(); + wallet = new AgentPayWallet(); vm.stopBroadcast(); console.log("PayRegistry: ", address(payRegistry)); console.log("VirtContractResolver:", address(virtResolver)); - console.log("CelerWallet: ", address(celerWallet)); - console.log("CelerWallet owner: ", celerWallet.owner()); + console.log("AgentPayWallet: ", address(wallet)); + console.log("AgentPayWallet owner: ", wallet.owner()); } } diff --git a/script/DeployLedger.s.sol b/script/DeployLedger.s.sol index 40ac801..a70b937 100644 --- a/script/DeployLedger.s.sol +++ b/script/DeployLedger.s.sol @@ -2,11 +2,11 @@ pragma solidity ^0.8.20; import {Script, console} from "forge-std/Script.sol"; -import {CelerLedger} from "../src/CelerLedger.sol"; +import {AgentPayLedger} from "../src/AgentPayLedger.sol"; /** * @title DeployLedger - * @notice Deploys a `CelerLedger` instance wired against the existing core + * @notice Deploys a `AgentPayLedger` instance wired against the existing core * contracts and the chain's canonical wrapped-native (wrapped-native) * contract. Run once per ledger version — peers cooperatively migrate * channels between versions; the wallet / registry / nativeWrap stay shared. @@ -20,30 +20,30 @@ import {CelerLedger} from "../src/CelerLedger.sol"; * * Environment variables: * PRIVATE_KEY — Deployer private key (required). Deployer becomes the - * `CelerLedger` Ownable owner (`setBalanceLimits`, + * `AgentPayLedger` Ownable owner (`setBalanceLimits`, * `enableBalanceLimits`, `disableBalanceLimits`). * DEPLOY_CONFIG — Path to JSON config file (default: `config.json`). */ contract DeployLedger is Script { - function run() external returns (CelerLedger ledger) { + function run() external returns (AgentPayLedger ledger) { uint256 deployerKey = vm.envUint("PRIVATE_KEY"); string memory configPath = vm.envOr("DEPLOY_CONFIG", string("config.json")); string memory config = vm.readFile(configPath); address nativeWrap = abi.decode(vm.parseJson(config, ".core.nativeWrap"), (address)); address payRegistry = abi.decode(vm.parseJson(config, ".core.payRegistry"), (address)); - address celerWallet = abi.decode(vm.parseJson(config, ".core.celerWallet"), (address)); + address wallet = abi.decode(vm.parseJson(config, ".core.wallet"), (address)); require(nativeWrap != address(0), "nativeWrap address required"); require(payRegistry != address(0), "payRegistry address required"); - require(celerWallet != address(0), "celerWallet address required"); + require(wallet != address(0), "wallet address required"); vm.startBroadcast(deployerKey); - ledger = new CelerLedger(nativeWrap, payRegistry, celerWallet); + ledger = new AgentPayLedger(nativeWrap, payRegistry, wallet); vm.stopBroadcast(); - console.log("CelerLedger: ", address(ledger)); - console.log("CelerLedger owner: ", ledger.owner()); + console.log("AgentPayLedger: ", address(ledger)); + console.log("AgentPayLedger owner: ", ledger.owner()); console.log("Balance limits enabled by default. Configure or disable via the post-deploy checklist."); } } diff --git a/script/README.md b/script/README.md index d0c0f82..b25f5a7 100644 --- a/script/README.md +++ b/script/README.md @@ -15,37 +15,37 @@ existing core without touching the asset-custody contracts. | Script | Deploys | Lifecycle | |---|---|---| -| [`DeployCore.s.sol`](DeployCore.s.sol) | `PayRegistry`, `VirtContractResolver`, `CelerWallet` | Once per network. Permanent — never redeployed. | -| [`DeployLedger.s.sol`](DeployLedger.s.sol) | `CelerLedger` (+ 3 ledger libraries; see below) | Versioned. Run again for each new ledger version; peers cooperatively migrate. | +| [`DeployCore.s.sol`](DeployCore.s.sol) | `PayRegistry`, `VirtContractResolver`, `AgentPayWallet` | Once per network. Permanent — never redeployed. | +| [`DeployLedger.s.sol`](DeployLedger.s.sol) | `AgentPayLedger` (+ 3 ledger libraries; see below) | Versioned. Run again for each new ledger version; peers cooperatively migrate. | | [`DeployPayResolver.s.sol`](DeployPayResolver.s.sol) | `PayResolver` | Versioned per-payment. Run when adding a new resolver. | | [`DeployRouterRegistry.s.sol`](DeployRouterRegistry.s.sol) | `RouterRegistry` | Optional. Independent of the channel graph. | ## How the libraries are deployed -`CelerLedger` is split across three Solidity `library` contracts under +`AgentPayLedger` is split across three Solidity `library` contracts under [`src/lib/ledgerlib/`](../src/lib/ledgerlib/) (forced by EIP-170's 24,576-byte deployed-bytecode limit — see [`docs/contracts.md` § Why split into libraries?](../docs/contracts.md#why-split-into-libraries)). The deploy script doesn't mention them by name, but they **are** deployed — Foundry handles it implicitly: -1. The Solidity compiler emits **20-byte zero placeholders** in `CelerLedger`'s +1. The Solidity compiler emits **20-byte zero placeholders** in `AgentPayLedger`'s bytecode wherever a library function is called, recording each placeholder offset - in `out/CelerLedger.sol/CelerLedger.json` under `bytecode.linkReferences`. -2. When `forge script` evaluates `new CelerLedger(...)`, it walks the link references, + in `out/AgentPayLedger.sol/AgentPayLedger.json` under `bytecode.linkReferences`. +2. When `forge script` evaluates `new AgentPayLedger(...)`, it walks the link references, **deploys each library as its own contract** (one transaction each), and **patches - the placeholders** in `CelerLedger`'s bytecode with the freshly-deployed library + the placeholders** in `AgentPayLedger`'s bytecode with the freshly-deployed library addresses. -3. The now-linked `CelerLedger` is deployed last. +3. The now-linked `AgentPayLedger` is deployed last. So a single `forge script script/DeployLedger.s.sol --broadcast` call actually emits **4 deployment transactions** in this order: `LedgerOperation`, `LedgerChannel`, -`LedgerMigrate`, then `CelerLedger`. All four appear in the broadcast log under +`LedgerMigrate`, then `AgentPayLedger`. All four appear in the broadcast log under `broadcast/DeployLedger.s.sol//run-latest.json` (see [Broadcast outputs](#broadcast-outputs) below). -Library calls happen via `DELEGATECALL`, so the libraries execute in `CelerLedger`'s -storage context — they're code on a separate address but operate on `CelerLedger`'s +Library calls happen via `DELEGATECALL`, so the libraries execute in `AgentPayLedger`'s +storage context — they're code on a separate address but operate on `AgentPayLedger`'s state. ### Etherscan verification @@ -56,7 +56,7 @@ to reproduce the linked bytecode. When verification is run as part of the same just deployed automatically. To verify after the fact, supply them explicitly: ```bash -forge verify-contract CelerLedger \ +forge verify-contract AgentPayLedger \ --chain-id \ --libraries src/lib/ledgerlib/LedgerOperation.sol:LedgerOperation: \ --libraries src/lib/ledgerlib/LedgerChannel.sol:LedgerChannel: \ @@ -68,7 +68,7 @@ forge verify-contract CelerLedger \ By default each `DeployLedger` run **redeploys all three libraries** — fine for a clean version cut, wasteful if you're iterating. To pin already-deployed library -addresses and link `CelerLedger` against them at compile time, add to `foundry.toml`: +addresses and link `AgentPayLedger` against them at compile time, add to `foundry.toml`: ```toml [profile.default] @@ -80,7 +80,7 @@ libraries = [ ``` With those set, `forge build` resolves the link references at compile time and -`forge script` emits exactly **one** transaction (`new CelerLedger(...)`) instead of +`forge script` emits exactly **one** transaction (`new AgentPayLedger(...)`) instead of four. Most production deploys won't bother — re-deploying ~29 KB of library bytecode costs a few hundred thousand gas, which is negligible against the audit / coordination cost of pinning shared libraries across ledger versions. @@ -112,7 +112,7 @@ forge script script/DeployRouterRegistry.s.sol --rpc-url $RPC_URL --broadcast -- ## Adding a new ledger or resolver later -Peer-controlled migration means a new `CelerLedger` is just a fresh deploy pointing at +Peer-controlled migration means a new `AgentPayLedger` is just a fresh deploy pointing at the same core contracts. Likewise, a new `PayResolver` is a fresh deploy that future `ConditionalPay` messages can pin via field 8. @@ -132,7 +132,7 @@ migration request (for the ledger) or include the new resolver in their accepted After **`DeployCore`**: -1. Decide whether to keep the deployer as `CelerWallet` owner, or transfer to a +1. Decide whether to keep the deployer as `AgentPayWallet` owner, or transfer to a security multisig: ```bash cast send "transferOwnership(address)" --rpc-url $RPC_URL --private-key $PRIVATE_KEY diff --git a/script/example_config.json b/script/example_config.json index 21a9f84..218db34 100644 --- a/script/example_config.json +++ b/script/example_config.json @@ -1,10 +1,10 @@ { "_comment": "Copy this file to config.json and fill in the values for your target network.", "core": { - "_comment": "Addresses of the three permanent core contracts (set after running DeployCore.s.sol) plus the chain's canonical wrapped-native (wrapped-native) contract. Reused by every CelerLedger / PayResolver version.", + "_comment": "Addresses of the three permanent core contracts (set after running DeployCore.s.sol) plus the chain's canonical wrapped-native (wrapped-native) contract. Reused by every AgentPayLedger / PayResolver version.", "nativeWrap": "0x0000000000000000000000000000000000000000", "payRegistry": "0x0000000000000000000000000000000000000000", "virtResolver": "0x0000000000000000000000000000000000000000", - "celerWallet": "0x0000000000000000000000000000000000000000" + "wallet": "0x0000000000000000000000000000000000000000" } } \ No newline at end of file diff --git a/src/CelerLedger.sol b/src/AgentPayLedger.sol similarity index 94% rename from src/CelerLedger.sol rename to src/AgentPayLedger.sol index e0e95fa..b2f31b1 100644 --- a/src/CelerLedger.sol +++ b/src/AgentPayLedger.sol @@ -6,24 +6,24 @@ import "./lib/ledgerlib/LedgerOperation.sol"; import "./lib/ledgerlib/LedgerMigrate.sol"; import "./lib/ledgerlib/LedgerChannel.sol"; import "./lib/AgentPayErrors.sol"; -import "./interfaces/ICelerWallet.sol"; +import "./interfaces/IAgentPayWallet.sol"; import "./interfaces/INativeWrap.sol"; import "./interfaces/IPayRegistry.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** - * @title CelerLedger + * @title AgentPayLedger * @notice Channel state machine and primary user entry point for AgentPay. The * contract itself is a thin wrapper — the bulk of channel logic lives in the * libraries under `src/lib/ledgerlib/` (LedgerOperation, LedgerChannel, LedgerMigrate) * attached via `using ... for ...`. Balance-limit admin and ledger-wide config * getters live directly on this contract since they are pure storage reads / - * writes that don't justify a separate library hop. CelerLedger acts as the - * operator of a {ICelerWallet}; cooperative migration to a future ledger version + * writes that don't justify a separate library hop. AgentPayLedger acts as the + * operator of a {IAgentPayWallet}; cooperative migration to a future ledger version * is supported via {migrateChannelTo} / {migrateChannelFrom}. - * @dev See {ICelerLedger} for canonical NatSpec on each function. + * @dev See {IAgentPayLedger} for canonical NatSpec on each function. */ -contract CelerLedger is ICelerLedger, Ownable { +contract AgentPayLedger is IAgentPayLedger, Ownable { using LedgerOperation for LedgerStruct.Ledger; using LedgerMigrate for LedgerStruct.Ledger; using LedgerChannel for LedgerStruct.Channel; @@ -40,15 +40,15 @@ contract CelerLedger is ICelerLedger, Ownable { * (wrapped-native) contract. Used internally as a funding-flow * primitive for native-token channels; never user-visible. * @param _payRegistry Address of the deployed {IPayRegistry}. - * @param _celerWallet Address of the deployed {ICelerWallet} — this ledger must + * @param _wallet Address of the deployed {IAgentPayWallet} — this ledger must * later become its operator (during channel opening or via wallet creation). */ - constructor(address _nativeWrap, address _payRegistry, address _celerWallet) Ownable(msg.sender) { + constructor(address _nativeWrap, address _payRegistry, address _wallet) Ownable(msg.sender) { require(_nativeWrap != address(0), AgentPayErrors.ZeroAddress()); require(_nativeWrap.code.length > 0, AgentPayErrors.NativeWrapNotContract()); ledger.nativeWrap = INativeWrap(_nativeWrap); ledger.payRegistry = IPayRegistry(_payRegistry); - ledger.celerWallet = ICelerWallet(_celerWallet); + ledger.wallet = IAgentPayWallet(_wallet); // enable balance limits in default ledger.balanceLimitsEnabled = true; } @@ -231,7 +231,7 @@ contract CelerLedger is ICelerLedger, Ownable { } /** - * @notice Migrate a channel from this CelerLedger to a new CelerLedger + * @notice Migrate a channel from this AgentPayLedger to a new AgentPayLedger * @param _migrationRequest bytes of migration request message * @return migrated channel id */ @@ -240,7 +240,7 @@ contract CelerLedger is ICelerLedger, Ownable { } /** - * @notice Migrate a channel from an old CelerLedger to this CelerLedger + * @notice Migrate a channel from an old AgentPayLedger to this AgentPayLedger * @param _fromLedgerAddr the old ledger address to migrate from * @param _migrationRequest bytes of migration request message */ @@ -462,7 +462,7 @@ contract CelerLedger is ICelerLedger, Ownable { } /** - * @notice Return the wrapped-native contract used by this CelerLedger + * @notice Return the wrapped-native contract used by this AgentPayLedger * @return wrapped-native contract address */ function getNativeWrap() external view returns (address) { @@ -470,7 +470,7 @@ contract CelerLedger is ICelerLedger, Ownable { } /** - * @notice Return PayRegistry used by this CelerLedger contract + * @notice Return PayRegistry used by this AgentPayLedger contract * @return PayRegistry address */ function getPayRegistry() external view returns (address) { @@ -478,11 +478,11 @@ contract CelerLedger is ICelerLedger, Ownable { } /** - * @notice Return CelerWallet used by this CelerLedger contract - * @return CelerWallet address + * @notice Return AgentPayWallet used by this AgentPayLedger contract + * @return AgentPayWallet address */ - function getCelerWallet() external view returns (address) { - return address(ledger.celerWallet); + function getAgentPayWallet() external view returns (address) { + return address(ledger.wallet); } /** diff --git a/src/CelerLedgerMock.sol b/src/AgentPayLedgerMock.sol similarity index 97% rename from src/CelerLedgerMock.sol rename to src/AgentPayLedgerMock.sol index 655aebf..13eda06 100644 --- a/src/CelerLedgerMock.sol +++ b/src/AgentPayLedgerMock.sol @@ -5,19 +5,19 @@ import "./lib/ledgerlib/LedgerStruct.sol"; import "./lib/ledgerlib/LedgerOperation.sol"; import "./lib/ledgerlib/LedgerMigrate.sol"; import "./lib/ledgerlib/LedgerChannel.sol"; -import "./interfaces/ICelerWallet.sol"; +import "./interfaces/IAgentPayWallet.sol"; import "./interfaces/INativeWrap.sol"; import "./interfaces/IPayRegistry.sol"; /** - * @title CelerLedgerMock - * @notice **Test-only.** Mock CelerLedger that exposes raw state-mutating helpers + * @title AgentPayLedgerMock + * @notice **Test-only.** Mock AgentPayLedger that exposes raw state-mutating helpers * (`*MockSet`) and minimal stubs of the production API (`openChannel`, `deposit`, * `intendSettle`, etc.) to set up isolated test scenarios without going through the * full ledger logic. Used primarily by the migration tests, which require two ledger * contracts to coexist. **Do not deploy to a production network.** */ -contract CelerLedgerMock { +contract AgentPayLedgerMock { using LedgerChannel for LedgerStruct.Channel; LedgerStruct.Ledger private ledger; @@ -25,14 +25,14 @@ contract CelerLedgerMock { bytes32[] public tmpChannelIds; /** - * @notice CelerLedger constructor + * @notice AgentPayLedger constructor * @param _nativeWrap address of wrapped-native (wrapped-native) contract * @param _payRegistry address of PayRegistry */ - constructor(address _nativeWrap, address _payRegistry, address _celerWallet) { + constructor(address _nativeWrap, address _payRegistry, address _wallet) { ledger.nativeWrap = INativeWrap(_nativeWrap); ledger.payRegistry = IPayRegistry(_payRegistry); - ledger.celerWallet = ICelerWallet(_celerWallet); + ledger.wallet = IAgentPayWallet(_wallet); // enable balance limits in default ledger.balanceLimitsEnabled = true; } @@ -474,7 +474,7 @@ contract CelerLedgerMock { } /** - * @notice Return wrapped-native (wrapped-native) contract used by this CelerLedger + * @notice Return wrapped-native (wrapped-native) contract used by this AgentPayLedger * @return wrapped-native contract address */ function getNativeWrap() external view returns (address) { @@ -482,7 +482,7 @@ contract CelerLedgerMock { } /** - * @notice Return PayRegistry used by this CelerLedger contract + * @notice Return PayRegistry used by this AgentPayLedger contract * @return PayRegistry address */ function getPayRegistry() external view returns (address) { @@ -490,11 +490,11 @@ contract CelerLedgerMock { } /** - * @notice Return CelerWallet used by this CelerLedger contract - * @return CelerWallet address + * @notice Return AgentPayWallet used by this AgentPayLedger contract + * @return AgentPayWallet address */ - function getCelerWallet() external view returns (address) { - return address(ledger.celerWallet); + function getAgentPayWallet() external view returns (address) { + return address(ledger.wallet); } /** diff --git a/src/CelerWallet.sol b/src/AgentPayWallet.sol similarity index 92% rename from src/CelerWallet.sol rename to src/AgentPayWallet.sol index 607515c..8c0e379 100644 --- a/src/CelerWallet.sol +++ b/src/AgentPayWallet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import "./interfaces/ICelerWallet.sol"; +import "./interfaces/IAgentPayWallet.sol"; import "./lib/AgentPayErrors.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; @@ -9,24 +9,24 @@ import "@openzeppelin/contracts/utils/Pausable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; /** - * @title CelerWallet + * @title AgentPayWallet * @notice Multi-owner, multi-token, operator-centric wallet that holds funds for every * channel in the AgentPay network. Designed as a permanent, audited custodian — it * has no business logic of its own and does not trust any external contract, - * including CelerLedger. A single global instance is shared across ledger versions, + * including AgentPayLedger. A single global instance is shared across ledger versions, * and operatorship can be transferred cooperatively to enable channel migration. - * @dev See {ICelerWallet} for canonical NatSpec on each function. + * @dev See {IAgentPayWallet} for canonical NatSpec on each function. */ -contract CelerWallet is ICelerWallet, Pausable, Ownable { +contract AgentPayWallet is IAgentPayWallet, Pausable, Ownable { using SafeERC20 for IERC20; /// @notice Hard cap on `owners.length` per wallet. uint256 public constant MAX_OWNERS = 10; struct Wallet { - // corresponding to peers in CelerLedger + // corresponding to peers in AgentPayLedger address[] owners; - // corresponding to CelerLedger + // corresponding to AgentPayLedger address operator; // address(0) for native mapping(address => uint256) balances; @@ -69,7 +69,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { // External / state-changing API // ------------------------------------------------------------------------- - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function create(address[] calldata _owners, address _operator, bytes32 _nonce) external whenNotPaused @@ -90,14 +90,14 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { return walletId; } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function depositNative(bytes32 _walletId) external payable whenNotPaused { uint256 amount = msg.value; wallets[_walletId].balances[address(0)] += amount; emit Deposited(_walletId, address(0), amount); } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function depositERC20(bytes32 _walletId, address _tokenAddress, uint256 _amount) external whenNotPaused { wallets[_walletId].balances[_tokenAddress] += _amount; emit Deposited(_walletId, _tokenAddress, _amount); @@ -106,7 +106,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { } /** - * @inheritdoc ICelerWallet + * @inheritdoc IAgentPayWallet * @dev CEI: balance debit precedes the external transfer. Combined with * Solidity 0.8's checked arithmetic, this bounds any reentrant * withdraw chain at the wallet's actual balance — equivalent to N @@ -126,7 +126,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { _withdrawToken(_tokenAddress, _receiver, _amount); } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function transferBetweenWallets( bytes32 _fromWalletId, bytes32 _toWalletId, @@ -145,7 +145,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { emit TransferredBetweenWallets(_fromWalletId, _toWalletId, _tokenAddress, _receiver, _amount); } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function transferOperatorship(bytes32 _walletId, address _newOperator) external whenNotPaused @@ -154,7 +154,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { _changeOperator(_walletId, _newOperator); } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function voteForOperator(bytes32 _walletId, address _candidate) external onlyWalletOwner(_walletId, msg.sender) { require(_candidate != address(0), AgentPayErrors.ZeroAddress()); @@ -175,7 +175,7 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { } } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function drainToken(address _tokenAddress, address _receiver, uint256 _amount) external whenPaused onlyOwner { emit TokenDrained(_tokenAddress, _receiver, _amount); @@ -196,27 +196,27 @@ contract CelerWallet is ICelerWallet, Pausable, Ownable { // External views // ------------------------------------------------------------------------- - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function walletOwners(bytes32 _walletId) external view returns (address[] memory) { return wallets[_walletId].owners; } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function walletOperator(bytes32 _walletId) external view returns (address) { return wallets[_walletId].operator; } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function balanceOf(bytes32 _walletId, address _tokenAddress) external view returns (uint256) { return wallets[_walletId].balances[_tokenAddress]; } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function pendingOperator(bytes32 _walletId) external view returns (address) { return wallets[_walletId].pendingOperator; } - /// @inheritdoc ICelerWallet + /// @inheritdoc IAgentPayWallet function hasVoted(bytes32 _walletId, address _owner) external view returns (bool) { return wallets[_walletId].votes[_owner]; } diff --git a/src/helper/ERC20ExampleToken.sol b/src/helper/ERC20ExampleToken.sol index 8171468..b82c8d2 100644 --- a/src/helper/ERC20ExampleToken.sol +++ b/src/helper/ERC20ExampleToken.sol @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; /** * @title ERC20ExampleToken * @notice **Test-only.** Simple ERC-20 token whose entire supply is minted to the - * deployer. Used to fund ERC-20 channels in CelerLedger tests. **Do not deploy to a + * deployer. Used to fund ERC-20 channels in AgentPayLedger tests. **Do not deploy to a * production network.** */ contract ERC20ExampleToken is ERC20 { diff --git a/src/helper/NativeWrapMock.sol b/src/helper/NativeWrapMock.sol index db1ef65..95c1bf4 100644 --- a/src/helper/NativeWrapMock.sol +++ b/src/helper/NativeWrapMock.sol @@ -8,7 +8,7 @@ import "../interfaces/INativeWrap.sol"; * @notice **Test-only.** Minimal wrapped-native (WETH9-style ABI) * reimplementation for Foundry tests. Covers `deposit` / `withdraw` / * standard ERC-20. Production deploys reference each chain's canonical - * wrapped-native address (e.g., WETH) via `_nativeWrap` in `CelerLedger`'s + * wrapped-native address (e.g., WETH) via `_nativeWrap` in `AgentPayLedger`'s * constructor. **Do not deploy to a production network.** */ contract NativeWrapMock is INativeWrap { diff --git a/src/helper/WalletTestHelper.sol b/src/helper/WalletTestHelper.sol index cb3660d..062a99b 100644 --- a/src/helper/WalletTestHelper.sol +++ b/src/helper/WalletTestHelper.sol @@ -1,21 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import "../interfaces/ICelerWallet.sol"; +import "../interfaces/IAgentPayWallet.sol"; /** * @title WalletTestHelper - * @notice **Test-only.** Thin wrapper used to create CelerWallet wallets from a + * @notice **Test-only.** Thin wrapper used to create AgentPayWallet wallets from a * contract (rather than an EOA) so tests can exercise non-EOA owner / operator * paths and verify event emission. **Do not deploy to a production network.** */ contract WalletTestHelper { event NewWallet(bytes32 walletId); - ICelerWallet wallet; + IAgentPayWallet wallet; - constructor(address _celerWallet) { - wallet = ICelerWallet(_celerWallet); + constructor(address _wallet) { + wallet = IAgentPayWallet(_wallet); } function create(address[] memory _owners, address _operator, uint256 _nonce) public { diff --git a/src/interfaces/ICelerLedger.sol b/src/interfaces/IAgentPayLedger.sol similarity index 97% rename from src/interfaces/ICelerLedger.sol rename to src/interfaces/IAgentPayLedger.sol index 76c1b9b..f4d02ff 100644 --- a/src/interfaces/ICelerLedger.sol +++ b/src/interfaces/IAgentPayLedger.sol @@ -5,25 +5,25 @@ import "../lib/data/PbEntity.sol"; import "../lib/ledgerlib/LedgerStruct.sol"; /** - * @title CelerLedger interface - * @notice Channel state machine and primary user entry point for AgentPay. CelerLedger - * acts as the operator of a {ICelerWallet} and exposes the on-chain APIs for opening, + * @title AgentPayLedger interface + * @notice Channel state machine and primary user entry point for AgentPay. AgentPayLedger + * acts as the operator of a {IAgentPayWallet} and exposes the on-chain APIs for opening, * funding, withdrawing from, settling, and migrating payment channels. * @dev The interface is grouped by the library that implements each section in * `src/lib/ledgerlib/` (LedgerOperation, LedgerChannel, LedgerMigrate). * Balance-limit admin and ledger-wide config getters are implemented directly on - * CelerLedger (no library hop). Any change here must be mirrored in the + * AgentPayLedger (no library hop). Any change here must be mirrored in the * corresponding implementation, and events declared here must match the library * declarations bit-for-bit. */ -interface ICelerLedger { +interface IAgentPayLedger { // ========================================================================= // LedgerOperation — channel lifecycle, deposit, withdraw, settle // ========================================================================= /** * @notice Open a fully-funded channel from a co-signed initializer in one tx. - * @dev Atomically creates a wallet in the underlying CelerWallet, derives + * @dev Atomically creates a wallet in the underlying AgentPayWallet, derives * `channelId = keccak256(chainid, walletAddr, ledgerAddr, keccak256(initializer))`, * and pulls the initial deposits. Native value is allowed via `msg.value`. * The initializer's `chain_id` and `ledger_address` must match this @@ -143,8 +143,8 @@ interface ICelerLedger { /// @notice Address of the configured {IPayRegistry}. function getPayRegistry() external view returns (address); - /// @notice Address of the configured {ICelerWallet}. - function getCelerWallet() external view returns (address); + /// @notice Address of the configured {IAgentPayWallet}. + function getAgentPayWallet() external view returns (address); /// @notice Emitted on successful {openChannel}. event OpenChannel( @@ -293,7 +293,7 @@ interface ICelerLedger { returns (address receiver, uint256 amount, uint256 requestTime, bytes32 recipientChannelId); // ========================================================================= - // Balance limits — per-channel deposit caps (owner-only admin, on CelerLedger) + // Balance limits — per-channel deposit caps (owner-only admin, on AgentPayLedger) // ========================================================================= /** diff --git a/src/interfaces/ICelerWallet.sol b/src/interfaces/IAgentPayWallet.sol similarity index 94% rename from src/interfaces/ICelerWallet.sol rename to src/interfaces/IAgentPayWallet.sol index a79e6e3..c4b9862 100644 --- a/src/interfaces/ICelerWallet.sol +++ b/src/interfaces/IAgentPayWallet.sol @@ -2,15 +2,15 @@ pragma solidity ^0.8.26; /** - * @title CelerWallet interface + * @title AgentPayWallet interface * @notice Multi-owner, multi-token wallet that holds funds for every channel in the - * AgentPay network. A CelerWallet has two distinct roles: a set of *owners* (the + * AgentPay network. A AgentPayWallet has two distinct roles: a set of *owners* (the * channel peers, recipients of withdrawals) and a single *operator* (typically a - * CelerLedger contract version) authorized to move funds. Operatorship is the pivot + * AgentPayLedger contract version) authorized to move funds. Operatorship is the pivot * point for cooperative migration to a new ledger version — see * {transferOperatorship} and {voteForOperator}. */ -interface ICelerWallet { +interface IAgentPayWallet { /** * @notice Create a new wallet. * @dev `walletId = keccak256(chainid, walletContract, msg.sender, _nonce)`. @@ -25,7 +25,7 @@ interface ICelerWallet { /** * @notice Deposit `msg.value` native (e.g. ETH) into a wallet's native balance. - * @dev Public payable; called directly by users or by `CelerLedger` after + * @dev Public payable; called directly by users or by `AgentPayLedger` after * unwrapping wrapped-native internally for the multi-party-funding path. * Credits `balances[walletId][address(0)]`. * @param _walletId Wallet to deposit into. @@ -72,7 +72,7 @@ interface ICelerWallet { /** * @notice Operator transfers operatorship of a wallet to a new operator. - * @dev Migration pivot point: the new operator is typically a newer CelerLedger + * @dev Migration pivot point: the new operator is typically a newer AgentPayLedger * version cooperatively chosen by the peers. Also clears any in-flight * {voteForOperator} candidate + tally — the direct transfer supersedes any * pending vote. @@ -107,7 +107,7 @@ interface ICelerWallet { function walletOwners(bytes32 _walletId) external view returns (address[] memory); /// @notice Current operator of `_walletId`. Distinct from this contract's - /// Ownable owner — the wallet operator is per-wallet (typically a CelerLedger). + /// Ownable owner — the wallet operator is per-wallet (typically a AgentPayLedger). function walletOperator(bytes32 _walletId) external view returns (address); /// @notice Token balance of `_walletId` for `_tokenAddress` (`address(0)` for native). @@ -123,7 +123,7 @@ interface ICelerWallet { /// @notice Emitted on wallet creation. `owners` is indexed — subscribers /// receive a `keccak256(abi.encode(owners))` topic rather than the array /// itself, so per-owner filtering via topic is not directly supported. - /// For AgentPay's channel use case, the parallel `CelerLedger.OpenChannel` + /// For AgentPay's channel use case, the parallel `AgentPayLedger.OpenChannel` /// event emits the two peer addresses unindexed in its data field, which /// is the cheaper place to read them from. event WalletCreated(bytes32 indexed walletId, address[] indexed owners, address indexed operator); diff --git a/src/interfaces/INativeWrap.sol b/src/interfaces/INativeWrap.sol index 426f66d..84557aa 100644 --- a/src/interfaces/INativeWrap.sol +++ b/src/interfaces/INativeWrap.sol @@ -9,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; * target chain (e.g., WETH on Ethereum). AgentPay uses this only internally * as a funding-flow primitive — `LedgerOperation` pulls a peer's pre-approved * wrapped-native via `transferFrom`, then unwraps via `withdraw` to forward - * the resulting native (e.g., ETH) to `CelerWallet`. Users never see + * the resulting native (e.g., ETH) to `AgentPayWallet`. Users never see * wrapped-native through AgentPay's native-channel API. */ interface INativeWrap is IERC20 { diff --git a/src/lib/AgentPayErrors.sol b/src/lib/AgentPayErrors.sol index bd28666..19854ff 100644 --- a/src/lib/AgentPayErrors.sol +++ b/src/lib/AgentPayErrors.sol @@ -81,7 +81,7 @@ library AgentPayErrors { error InvalidSignature(); // ------------------------------------------------------------------------- - // CelerLedger + // AgentPayLedger // ------------------------------------------------------------------------- /// @notice Constructor's `_nativeWrap` argument has no deployed @@ -96,7 +96,7 @@ library AgentPayErrors { error CallerNotNativeWrap(); // ------------------------------------------------------------------------- - // CelerWallet + // AgentPayWallet // ------------------------------------------------------------------------- /// @notice `msg.sender` is not the wallet's operator. diff --git a/src/lib/data/proto/entity.proto b/src/lib/data/proto/entity.proto index 53a0da8..5b2d795 100644 --- a/src/lib/data/proto/entity.proto +++ b/src/lib/data/proto/entity.proto @@ -186,7 +186,7 @@ message PaymentChannelInitializer { // chain id of the intended target chain; binds the signed initializer // against cross-chain replay uint64 chain_id = 5 [(soltype) = "uint"]; - // address of the intended target CelerLedger; binds the signed initializer + // address of the intended target AgentPayLedger; binds the signed initializer // against same-chain wrong-ledger replay bytes ledger_address = 6 [(soltype) = "address"]; } diff --git a/src/lib/ledgerlib/LedgerChannel.sol b/src/lib/ledgerlib/LedgerChannel.sol index c4e7268..fe1d694 100644 --- a/src/lib/ledgerlib/LedgerChannel.sol +++ b/src/lib/ledgerlib/LedgerChannel.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.26; import "./LedgerStruct.sol"; import "../AgentPayErrors.sol"; -import "../../interfaces/ICelerLedger.sol"; +import "../../interfaces/IAgentPayLedger.sol"; import "../data/PbEntity.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; @@ -11,7 +11,7 @@ import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; /** * @title LedgerChannel * @notice Library of `Channel` view helpers and per-channel state derivations used - * by {CelerLedger}'s getters. Also hosts shared signature-verification helpers used + * by {AgentPayLedger}'s getters. Also hosts shared signature-verification helpers used * by other ledger libraries. * @dev Could be folded into LedgerOperation for marginal gas savings; kept separate * for code clarity. @@ -278,7 +278,7 @@ library LedgerChannel { } /** - * @notice Import channel migration arguments from old CelerLedger contract + * @notice Import channel migration arguments from old AgentPayLedger contract * @param _c the channel to be viewed * @param _fromLedgerAddr old ledger address to import channel config from * @param _channelId ID of the channel to be viewed @@ -292,12 +292,12 @@ library LedgerChannel { ) internal { uint256 tokenType; (_c.disputeTimeout, tokenType, _c.token.tokenAddress, _c.cooperativeWithdrawSeqNum) = - ICelerLedger(_fromLedgerAddr).getChannelMigrationArgs(_channelId); + IAgentPayLedger(_fromLedgerAddr).getChannelMigrationArgs(_channelId); _c.token.tokenType = PbEntity.TokenType(tokenType); } /** - * @notice import channel peers' migration info from old CelerLedger contract + * @notice import channel peers' migration info from old AgentPayLedger contract * @param _c the channel to be viewed * @param _fromLedgerAddr old ledger address to import channel config from * @param _channelId ID of the channel to be viewed @@ -315,7 +315,7 @@ library LedgerChannel { uint256[2] memory seqNums, uint256[2] memory transferOuts, uint256[2] memory pendingPayOuts - ) = ICelerLedger(_fromLedgerAddr).getPeersMigrationInfo(_channelId); + ) = IAgentPayLedger(_fromLedgerAddr).getPeersMigrationInfo(_channelId); for (uint256 i = 0; i < 2; i++) { LedgerStruct.PeerProfile storage peerProfile = _c.peerProfiles[i]; diff --git a/src/lib/ledgerlib/LedgerMigrate.sol b/src/lib/ledgerlib/LedgerMigrate.sol index 04cfc0c..2fb9f88 100644 --- a/src/lib/ledgerlib/LedgerMigrate.sol +++ b/src/lib/ledgerlib/LedgerMigrate.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.26; import "./LedgerOperation.sol"; import "./LedgerChannel.sol"; import "./LedgerStruct.sol"; -import "../../interfaces/ICelerLedger.sol"; +import "../../interfaces/IAgentPayLedger.sol"; import "../AgentPayErrors.sol"; import "../data/PbChain.sol"; import "../data/PbEntity.sol"; @@ -23,8 +23,8 @@ library LedgerMigrate { using LedgerOperation for LedgerStruct.Ledger; /** - * @notice Migrate a channel from this CelerLedger to a new CelerLedger - * @param _self storage data of CelerLedger contract + * @notice Migrate a channel from this AgentPayLedger to a new AgentPayLedger + * @param _self storage data of AgentPayLedger contract * @param _migrationRequest bytes of migration request message * @return migrated channel id */ @@ -53,14 +53,14 @@ library LedgerMigrate { c.migratedTo = toLedgerAddr; emit MigrateChannelTo(channelId, toLedgerAddr); - _self.celerWallet.transferOperatorship(channelId, toLedgerAddr); + _self.wallet.transferOperatorship(channelId, toLedgerAddr); return channelId; } /** - * @notice Migrate a channel from an old CelerLedger to this CelerLedger - * @param _self storage data of CelerLedger contract + * @notice Migrate a channel from an old AgentPayLedger to this AgentPayLedger + * @param _self storage data of AgentPayLedger contract * @param _fromLedgerAddr the old ledger address to migrate from * @param _migrationRequest bytes of migration request message */ @@ -72,12 +72,10 @@ library LedgerMigrate { bytes calldata _migrationRequest ) external { address payable fromLedgerAddrPayable = payable(_fromLedgerAddr); - bytes32 channelId = ICelerLedger(fromLedgerAddrPayable).migrateChannelTo(_migrationRequest); + bytes32 channelId = IAgentPayLedger(fromLedgerAddrPayable).migrateChannelTo(_migrationRequest); LedgerStruct.Channel storage c = _self.channelMap[channelId]; require(c.status == LedgerStruct.ChannelStatus.Uninitialized, AgentPayErrors.ChannelAlreadyMigrated()); - require( - _self.celerWallet.walletOperator(channelId) == address(this), AgentPayErrors.OperatorshipNotTransferred() - ); + require(_self.wallet.walletOperator(channelId) == address(this), AgentPayErrors.OperatorshipNotTransferred()); _self._updateChannelStatus(c, LedgerStruct.ChannelStatus.Operable); // Do not migrate WithdrawIntent, in other words, migration will implicitly veto diff --git a/src/lib/ledgerlib/LedgerOperation.sol b/src/lib/ledgerlib/LedgerOperation.sol index 288032b..3170e02 100644 --- a/src/lib/ledgerlib/LedgerOperation.sol +++ b/src/lib/ledgerlib/LedgerOperation.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.26; import "./LedgerStruct.sol"; import "./LedgerChannel.sol"; import "../AgentPayErrors.sol"; -import "../../interfaces/ICelerWallet.sol"; +import "../../interfaces/IAgentPayWallet.sol"; import "../data/PbChain.sol"; import "../data/PbEntity.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -12,10 +12,10 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** * @title LedgerOperation - * @notice Library implementing the channel-lifecycle flows for CelerLedger: open, + * @notice Library implementing the channel-lifecycle flows for AgentPayLedger: open, * deposit, snapshot, withdraw (cooperative + unilateral), and settle (cooperative + * unilateral). Attached to `LedgerStruct.Ledger` via `using ... for ...` in - * {CelerLedger}; do not deploy directly. Library functions cannot be `payable` but + * {AgentPayLedger}; do not deploy directly. Library functions cannot be `payable` but * read `msg.value` from the calling contract's context. */ library LedgerOperation { @@ -25,7 +25,7 @@ library LedgerOperation { /** * @notice Open a state channel through auth withdraw message * @dev library function can't be payable but can read msg.value in caller's context - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _openRequest bytes of open channel request message */ function openChannel(LedgerStruct.Ledger storage _self, bytes calldata _openRequest) external { @@ -54,7 +54,7 @@ library LedgerOperation { require(peerAddrs[0] < peerAddrs[1], AgentPayErrors.PeersNotAscending()); bytes32 h = keccak256(openRequest.channelInitializer); - (bytes32 channelId, LedgerStruct.Channel storage c) = _createWallet(_self, _self.celerWallet, peerAddrs, h); + (bytes32 channelId, LedgerStruct.Channel storage c) = _createWallet(_self, _self.wallet, peerAddrs, h); c.disputeTimeout = channelInitializer.disputeTimeout; _updateChannelStatus(_self, c, LedgerStruct.ChannelStatus.Operable); @@ -89,7 +89,7 @@ library LedgerOperation { /** * @notice Pull peer deposits into the channel's wallet at `openChannel` time. * @dev Purpose: address the EVM 16-slot stack-depth limit. - * @param _self Storage data of CelerLedger contract. + * @param _self Storage data of AgentPayLedger contract. * @param _channelId Id of the channel being opened. * @param _peerAddrs Sorted peer addresses from the initializer. * @param _amounts Per-peer initial deposits, indexed identically to `_peerAddrs`. @@ -119,7 +119,7 @@ library LedgerOperation { } // `_amtSum > 0` is guaranteed by `openChannel`'s early return; // a single combined depositNative covers both peers' contributions. - _self.celerWallet.depositNative{value: _amtSum}(_channelId); + _self.wallet.depositNative{value: _amtSum}(_channelId); } else if (_token.tokenType == PbEntity.TokenType.ERC20) { require(msg.value == 0, AgentPayErrors.MsgValueMustBeZero()); @@ -128,8 +128,8 @@ library LedgerOperation { if (_amounts[i] == 0) continue; erc20Token.safeTransferFrom(_peerAddrs[i], address(this), _amounts[i]); } - erc20Token.forceApprove(address(_self.celerWallet), _amtSum); - _self.celerWallet.depositERC20(_channelId, address(erc20Token), _amtSum); + erc20Token.forceApprove(address(_self.wallet), _amtSum); + _self.wallet.depositERC20(_channelId, address(erc20Token), _amtSum); } else { assert(false); } @@ -139,7 +139,7 @@ library LedgerOperation { * @notice Deposit native or ERC20 tokens into the channel * @dev total deposit amount = msg.value(must be 0 for ERC20) + _transferFromAmount. * library function can't be payable but can read msg.value in caller's context. - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _receiver address of the receiver * @param _transferFromAmount amount of funds to be transferred from `nativeWrap` (wrapped-native) for native channels @@ -158,20 +158,20 @@ library LedgerOperation { LedgerStruct.Channel storage c = _self.channelMap[_channelId]; if (c.token.tokenType == PbEntity.TokenType.NATIVE) { if (msgValue > 0) { - _self.celerWallet.depositNative{value: msgValue}(_channelId); + _self.wallet.depositNative{value: msgValue}(_channelId); } if (_transferFromAmount > 0) { IERC20(address(_self.nativeWrap)).safeTransferFrom(msg.sender, address(this), _transferFromAmount); _self.nativeWrap.withdraw(_transferFromAmount); - _self.celerWallet.depositNative{value: _transferFromAmount}(_channelId); + _self.wallet.depositNative{value: _transferFromAmount}(_channelId); } } else if (c.token.tokenType == PbEntity.TokenType.ERC20) { require(msgValue == 0, AgentPayErrors.MsgValueMustBeZero()); IERC20 erc20Token = IERC20(c.token.tokenAddress); erc20Token.safeTransferFrom(msg.sender, address(this), _transferFromAmount); - erc20Token.forceApprove(address(_self.celerWallet), _transferFromAmount); - _self.celerWallet.depositERC20(_channelId, address(erc20Token), _transferFromAmount); + erc20Token.forceApprove(address(_self.wallet), _transferFromAmount); + _self.wallet.depositERC20(_channelId, address(erc20Token), _transferFromAmount); } else { assert(false); } @@ -184,7 +184,7 @@ library LedgerOperation { * This function only updates seqNum, transferOut, pendingPayOut of each on-chain * simplex state. It can't ensure that the pending pays will be cleared during * settling the channel, which requires users call intendSettle with the same state. - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _signedSimplexStateArray bytes of SignedSimplexStateArray message */ function snapshotStates(LedgerStruct.Ledger storage _self, bytes calldata _signedSimplexStateArray) external { @@ -234,7 +234,7 @@ library LedgerOperation { /** * @notice Intend to withdraw funds from channel * @dev only peers can call intendWithdraw - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _amount amount of funds to withdraw * @param _recipientChannelId withdraw to receiver address if 0, @@ -266,7 +266,7 @@ library LedgerOperation { /** * @notice Confirm channel withdrawal * @dev anyone can confirm a withdrawal intent - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel */ function confirmWithdraw(LedgerStruct.Ledger storage _self, bytes32 _channelId) external { @@ -300,7 +300,7 @@ library LedgerOperation { * @notice Veto current withdrawal intent * @dev only peers can veto a withdrawal intent; * peers can veto a withdrawal intent even after (requestTime + disputeTimeout) - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel */ function vetoWithdraw(LedgerStruct.Ledger storage _self, bytes32 _channelId) external { @@ -316,7 +316,7 @@ library LedgerOperation { /** * @notice Cooperatively withdraw specific amount of balance - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _cooperativeWithdrawRequest bytes of cooperative withdraw request message */ function cooperativeWithdraw(LedgerStruct.Ledger storage _self, bytes calldata _cooperativeWithdrawRequest) @@ -361,7 +361,7 @@ library LedgerOperation { * which means intendSettle natively supports multi-channel batch processing. * A simplex state with non-zero seqNum (non-null state) must be co-signed by both peers, * while a simplex state with seqNum=0 (null state) only needs to be signed by one peer. - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _signedSimplexStateArray bytes of SignedSimplexStateArray message */ function intendSettle(LedgerStruct.Ledger storage _self, bytes calldata _signedSimplexStateArray) external { @@ -455,7 +455,7 @@ library LedgerOperation { /** * @notice Read payment results and add results to corresponding simplex payment channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _peerFrom address of the peer who send out funds * @param _payIdList bytes of a pay id list @@ -482,7 +482,7 @@ library LedgerOperation { /** * @notice Confirm channel settlement * @dev This must be called after settleFinalizedTime - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel */ function confirmSettle(LedgerStruct.Ledger storage _self, bytes32 _channelId) external { @@ -528,7 +528,7 @@ library LedgerOperation { /** * @notice Cooperatively settle the channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _settleRequest bytes of cooperative settle request message */ function cooperativeSettle(LedgerStruct.Ledger storage _self, bytes calldata _settleRequest) external { @@ -573,7 +573,7 @@ library LedgerOperation { /** * @notice Return channel number of given status in this contract - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelStatus query channel status converted to uint * @return channel number of the status */ @@ -587,17 +587,19 @@ library LedgerOperation { /** * @notice create a wallet for a new channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _w celer wallet * @param _peers peers of the new channel * @param _nonce nonce for creating the wallet * @return channel id, which is same as the created wallet id * @return storage pointer of the channel */ - function _createWallet(LedgerStruct.Ledger storage _self, ICelerWallet _w, address[2] memory _peers, bytes32 _nonce) - internal - returns (bytes32, LedgerStruct.Channel storage) - { + function _createWallet( + LedgerStruct.Ledger storage _self, + IAgentPayWallet _w, + address[2] memory _peers, + bytes32 _nonce + ) internal returns (bytes32, LedgerStruct.Channel storage) { address[] memory owners = new address[](2); owners[0] = _peers[0]; owners[1] = _peers[1]; @@ -615,7 +617,7 @@ library LedgerOperation { /** * @notice Internal function to add deposit of a channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _receiver address of the receiver * @param _amount the amount to be deposited @@ -645,7 +647,7 @@ library LedgerOperation { /** * @notice Internal function to transfer funds out in batch - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _tokenAddr address of tokens to be transferred out * @param _receivers the addresses of token receivers @@ -661,13 +663,13 @@ library LedgerOperation { for (uint256 i = 0; i < 2; i++) { if (_amounts[i] == 0) continue; - _self.celerWallet.withdraw(_channelId, _tokenAddr, _receivers[i], _amounts[i]); + _self.wallet.withdraw(_channelId, _tokenAddr, _receivers[i], _amounts[i]); } } /** * @notice Internal function to withdraw funds out of the channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId ID of the channel * @param _receiver address of the receiver of the withdrawn funds * @param _amount the amount of the withdrawn funds @@ -684,7 +686,7 @@ library LedgerOperation { LedgerStruct.Channel storage c = _self.channelMap[_channelId]; if (_recipientChannelId == bytes32(0)) { - _self.celerWallet.withdraw(_channelId, c.token.tokenAddress, _receiver, _amount); + _self.wallet.withdraw(_channelId, c.token.tokenAddress, _receiver, _amount); } else { LedgerStruct.Channel storage recipientChannel = _self.channelMap[_recipientChannelId]; require( @@ -695,14 +697,14 @@ library LedgerOperation { _addDeposit(_self, _recipientChannelId, _receiver, _amount); // move funds from one channel's wallet to another channel's wallet - _self.celerWallet + _self.wallet .transferBetweenWallets(_channelId, _recipientChannelId, c.token.tokenAddress, _receiver, _amount); } } /** * @notice Reset the state of the channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _c the channel */ function _resetDuplexState(LedgerStruct.Ledger storage _self, LedgerStruct.Channel storage _c) internal { @@ -716,7 +718,7 @@ library LedgerOperation { /** * @notice Clear payments by their hash array - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId the channel ID * @param _peerId ID of the peer who sends out funds * @param _payIdList payIdList to clear @@ -755,7 +757,7 @@ library LedgerOperation { /** * @notice Update overall states of a duplex channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _channelId the channel ID */ function _updateOverallStatesByIntendState(LedgerStruct.Ledger storage _self, bytes32 _channelId) internal { @@ -768,7 +770,7 @@ library LedgerOperation { /** * @notice Update status of a channel - * @param _self storage data of CelerLedger contract + * @param _self storage data of AgentPayLedger contract * @param _c the channel * @param _newStatus new channel status */ diff --git a/src/lib/ledgerlib/LedgerStruct.sol b/src/lib/ledgerlib/LedgerStruct.sol index 0347521..ddeef69 100644 --- a/src/lib/ledgerlib/LedgerStruct.sol +++ b/src/lib/ledgerlib/LedgerStruct.sol @@ -1,21 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import "../../interfaces/ICelerWallet.sol"; +import "../../interfaces/IAgentPayWallet.sol"; import "../../interfaces/INativeWrap.sol"; import "../../interfaces/IPayRegistry.sol"; import "../data/PbEntity.sol"; /** * @title LedgerStruct - * @notice Shared struct and enum definitions used across all CelerLedger libraries. + * @notice Shared struct and enum definitions used across all AgentPayLedger libraries. * No logic — types only. Field semantics map onto the protobuf messages defined in * `proto/entity.proto`; field numbers in those `.proto` files are noted alongside the * Solidity counterparts where relevant. */ library LedgerStruct { /** - * @notice Lifecycle status of a channel inside a CelerLedger instance. + * @notice Lifecycle status of a channel inside a AgentPayLedger instance. * @dev `Uninitialized` is the implicit default when a channel id is not present in * `Ledger.channelMap`. State transitions: see `docs/architecture-summary.md`. */ @@ -62,8 +62,8 @@ library LedgerStruct { /** * @notice On-chain representation of a duplex state channel between two peers. - * @dev Funds physically reside in {ICelerWallet}; this struct holds only state - * and metadata. Peers may cooperatively migrate a channel to a new CelerLedger + * @dev Funds physically reside in {IAgentPayWallet}; this struct holds only state + * and metadata. Peers may cooperatively migrate a channel to a new AgentPayLedger * version, in which case `status = Migrated` and `migratedTo` is set on the old * ledger. */ @@ -75,7 +75,7 @@ library LedgerStruct { uint256 disputeTimeout; PbEntity.TokenInfo token; ChannelStatus status; - // Address of the successor CelerLedger after migration, if any. + // Address of the successor AgentPayLedger after migration, if any. address migratedTo; // Two-peer channels only. PeerProfile[2] peerProfiles; @@ -85,8 +85,8 @@ library LedgerStruct { /** * @notice Top-level ledger storage: many channels under one operation logic. - * @dev Held in CelerLedger as a single private state variable. Each Ledger - * binds to one CelerWallet (asset custody), one PayRegistry (resolved-pay + * @dev Held in AgentPayLedger as a single private state variable. Each Ledger + * binds to one AgentPayWallet (asset custody), one PayRegistry (resolved-pay * results), and one wrapped-native contract (used as funding-flow primitive only). */ struct Ledger { @@ -94,7 +94,7 @@ library LedgerStruct { mapping(uint256 => uint256) channelStatusNums; INativeWrap nativeWrap; IPayRegistry payRegistry; - ICelerWallet celerWallet; + IAgentPayWallet wallet; // Per-token per-channel deposit caps. mapping(address => uint256) balanceLimits; // Whether balance-limit enforcement is currently active. diff --git a/test/CelerLedger.ERC20.t.sol b/test/AgentPayLedger.ERC20.t.sol similarity index 71% rename from test/CelerLedger.ERC20.t.sol rename to test/AgentPayLedger.ERC20.t.sol index 1f8c9ca..c843bcd 100644 --- a/test/CelerLedger.ERC20.t.sol +++ b/test/AgentPayLedger.ERC20.t.sol @@ -6,14 +6,14 @@ import {AgentPayErrors} from "../src/lib/AgentPayErrors.sol"; import {LedgerStruct} from "../src/lib/ledgerlib/LedgerStruct.sol"; /** - * @title CelerLedger ERC20-channel tests - * @notice Unit tests for `CelerLedger`'s ERC-20-channel paths. Focuses on + * @title AgentPayLedger ERC20-channel tests + * @notice Unit tests for `AgentPayLedger`'s ERC-20-channel paths. Focuses on * ERC-20-specific behavior — open with / without funds, balance-limit gates, * deposit (including by a non-peer third party), `msg.value` rejection, * cooperative settle, and intend + confirm settle distributing tokens. - * ETH-side flows are validated in `CelerLedger.ETH.t.sol`. + * ETH-side flows are validated in `AgentPayLedger.ETH.t.sol`. */ -contract CelerLedgerErc20Test is LedgerTestBase { +contract AgentPayLedgerErc20Test is LedgerTestBase { function setUp() public override { super.setUp(); @@ -22,63 +22,63 @@ contract CelerLedgerErc20Test is LedgerTestBase { erc20.transfer(peer1, 1_000_000); vm.prank(peer0); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); vm.prank(peer1); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); } function test_openErc20Channel_zeroDeposit_succeeds() public { uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 channelId) = _buildOpenErc20(address(erc20), [uint256(0), 0], deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); - assertEq(celerLedger.getTokenContract(channelId), address(erc20)); - assertEq(celerLedger.getTotalBalance(channelId), 0); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); + assertEq(ledger.getTokenContract(channelId), address(erc20)); + assertEq(ledger.getTotalBalance(channelId), 0); } function test_openErc20Channel_withFunds_revertsBeforeBalanceLimit() public { uint256 deadline = openDeadlineCursor++; (bytes memory request,,) = _buildOpenErc20(address(erc20), [uint256(100), 200], deadline); vm.expectPartialRevert(AgentPayErrors.BalanceLimitExceeded.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openErc20Channel_withFunds_succeedsAfterBalanceLimit() public { _setErc20BalanceLimit(1_000_000); uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 channelId) = _buildOpenErc20(address(erc20), [uint256(100), 200], deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); - assertEq(celerLedger.getTotalBalance(channelId), 300); + assertEq(ledger.getTotalBalance(channelId), 300); // Balances pulled from peer0 and peer1. assertEq(erc20.balanceOf(peer0), 1_000_000 - 100); assertEq(erc20.balanceOf(peer1), 1_000_000 - 200); } function test_deposit_byPeer_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openZeroErc20Channel(); vm.prank(peer0); - celerLedger.deposit(channelId, peer0, 25); + ledger.deposit(channelId, peer0, 25); - assertEq(celerLedger.getTotalBalance(channelId), 25); + assertEq(ledger.getTotalBalance(channelId), 25); } function test_deposit_byNonPeerThirdParty_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openZeroErc20Channel(); // Stranger has no tokens — fund and approve. erc20.transfer(stranger, 1000); vm.prank(stranger); - erc20.approve(address(celerLedger), 1000); + erc20.approve(address(ledger), 1000); vm.prank(stranger); - celerLedger.deposit(channelId, peer0, 25); + ledger.deposit(channelId, peer0, 25); - assertEq(celerLedger.getTotalBalance(channelId), 25); + assertEq(ledger.getTotalBalance(channelId), 25); } function test_deposit_overBalanceLimit_reverts() public { @@ -87,37 +87,37 @@ contract CelerLedgerErc20Test is LedgerTestBase { vm.expectPartialRevert(AgentPayErrors.BalanceLimitExceeded.selector); vm.prank(peer0); - celerLedger.deposit(channelId, peer0, 100); + ledger.deposit(channelId, peer0, 100); } function test_deposit_withMsgValueNonZero_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openZeroErc20Channel(); // ERC20 channel deposit must not have msg.value. vm.deal(peer0, 1 ether); vm.expectRevert(AgentPayErrors.MsgValueMustBeZero.selector); vm.prank(peer0); - celerLedger.deposit{value: 1}(channelId, peer0, 25); + ledger.deposit{value: 1}(channelId, peer0, 25); } function test_cooperativeSettle_distributesErc20() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedErc20Channel([uint256(200), 0]); bytes memory request = _buildCoopSettle(channelId, 1, [uint256(120), 80], block.timestamp + 1000); uint256 peer0Before = erc20.balanceOf(peer0); uint256 peer1Before = erc20.balanceOf(peer1); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); assertEq(erc20.balanceOf(peer0), peer0Before + 120); assertEq(erc20.balanceOf(peer1), peer1Before + 80); } function test_intendSettle_thenConfirmSettle_noPays_distributesErc20() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedErc20Channel([uint256(200), 0]); bytes memory s0 = _buildSignedSimplex(channelId, peer0, 1, 0); @@ -125,13 +125,13 @@ contract CelerLedgerErc20Test is LedgerTestBase { bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer0Before = erc20.balanceOf(peer0); - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); assertEq(erc20.balanceOf(peer0), peer0Before + 200); } @@ -144,20 +144,20 @@ contract CelerLedgerErc20Test is LedgerTestBase { tokens[0] = address(erc20); uint256[] memory limits = new uint256[](1); limits[0] = _limit; - celerLedger.setBalanceLimits(tokens, limits); + ledger.setBalanceLimits(tokens, limits); } function _openZeroErc20Channel() internal returns (bytes32) { uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 channelId) = _buildOpenErc20(address(erc20), [uint256(0), 0], deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); return channelId; } function _openFundedErc20Channel(uint256[2] memory _amounts) internal returns (bytes32) { uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 channelId) = _buildOpenErc20(address(erc20), _amounts, deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); return channelId; } } diff --git a/test/CelerLedger.ETH.t.sol b/test/AgentPayLedger.ETH.t.sol similarity index 77% rename from test/CelerLedger.ETH.t.sol rename to test/AgentPayLedger.ETH.t.sol index b02f21d..e22c439 100644 --- a/test/CelerLedger.ETH.t.sol +++ b/test/AgentPayLedger.ETH.t.sol @@ -4,13 +4,13 @@ pragma solidity ^0.8.20; import {LedgerTestBase} from "./utils/LedgerTestBase.t.sol"; import {AgentPayErrors} from "../src/lib/AgentPayErrors.sol"; import {LedgerStruct} from "../src/lib/ledgerlib/LedgerStruct.sol"; -import {CelerLedger} from "../src/CelerLedger.sol"; +import {AgentPayLedger} from "../src/AgentPayLedger.sol"; import {Fixtures} from "./utils/Fixtures.sol"; import {SignUtil} from "./utils/SignUtil.sol"; /** - * @title CelerLedger ETH-channel tests - * @notice Comprehensive unit tests for `CelerLedger`'s ETH-channel paths. + * @title AgentPayLedger ETH-channel tests + * @notice Comprehensive unit tests for `AgentPayLedger`'s ETH-channel paths. * Covers the channel state machine, balance-limit admin, deposit, cooperative * and unilateral withdraw, snapshot states, intend / confirm / cooperative * settle, `clearPays` segment chaining, the recipient-channel rebalance @@ -30,14 +30,14 @@ import {SignUtil} from "./utils/SignUtil.sol"; * 11. Connection getters * 12. Internal helpers */ -contract CelerLedgerEthTest is LedgerTestBase { +contract AgentPayLedgerEthTest is LedgerTestBase { // ========================================================================= // 1. Channel state machine // ========================================================================= function test_uninitializedChannel_returnsStatusZero() public view { bytes32 unknownId = bytes32(uint256(0x123)); - assertEq(uint256(celerLedger.getChannelStatus(unknownId)), uint256(LedgerStruct.ChannelStatus.Uninitialized)); + assertEq(uint256(ledger.getChannelStatus(unknownId)), uint256(LedgerStruct.ChannelStatus.Uninitialized)); } // ========================================================================= @@ -47,26 +47,26 @@ contract CelerLedgerEthTest is LedgerTestBase { function test_openChannel_zeroDeposit_succeeds() public { bytes32 channelId = _openZeroEthChannel(); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); - assertEq(celerLedger.getTokenContract(channelId), address(0)); - assertEq(celerLedger.getTotalBalance(channelId), 0); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); + assertEq(ledger.getTokenContract(channelId), address(0)); + assertEq(ledger.getTotalBalance(channelId), 0); } function test_openChannel_afterDeadline_reverts() public { (bytes memory request,,) = _buildOpenEth([uint256(0), 0], 0, block.timestamp - 1); vm.expectRevert(AgentPayErrors.DeadlinePassed.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openChannel_sameInitializerTwice_reverts() public { // Build with a fixed deadline so both attempts use the same initializer hash. uint256 deadline = openDeadlineCursor++; (bytes memory request,,) = _buildOpenEth([uint256(0), 0], 0, deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); vm.expectRevert(AgentPayErrors.WalletIdOccupied.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openChannel_withFunds_revertsBeforeBalanceLimit() public { @@ -77,7 +77,7 @@ contract CelerLedgerEthTest is LedgerTestBase { // (sum of both peers' deposits), limit = 0 (unconfigured). vm.expectRevert(abi.encodeWithSelector(AgentPayErrors.BalanceLimitExceeded.selector, uint256(300), uint256(0))); vm.prank(peer0); - celerLedger.openChannel{value: 100}(request); + ledger.openChannel{value: 100}(request); } function test_openChannel_withFunds_succeedsAfterBalanceLimit() public { @@ -85,8 +85,8 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes32 channelId = _openFundedEthChannel([uint256(100), 200]); - assertEq(celerLedger.getTotalBalance(channelId), 300); - (, uint256[2] memory deposits,) = celerLedger.getBalanceMap(channelId); + assertEq(ledger.getTotalBalance(channelId), 300); + (, uint256[2] memory deposits,) = ledger.getBalanceMap(channelId); assertEq(deposits[0], 100); assertEq(deposits[1], 200); } @@ -108,21 +108,21 @@ contract CelerLedgerEthTest is LedgerTestBase { disputeTimeout: DISPUTE_TIMEOUT, msgValueReceiver: 0, chainId: block.chainid + 1, - ledgerAddress: address(celerLedger) + ledgerAddress: address(ledger) }); bytes memory initializer = Fixtures.encPaymentChannelInitializer(init); bytes[] memory sigs = SignUtil.coSign(peer0Pk, peer1Pk, initializer); bytes memory request = Fixtures.encOpenChannelRequest(initializer, sigs); vm.expectPartialRevert(AgentPayErrors.ChainIdMismatch.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openChannel_replayedOnWrongLedger_reverts() public { - // Initializer is bound to a sibling ledger (a fresh CelerLedger sharing + // Initializer is bound to a sibling ledger (a fresh AgentPayLedger sharing // the same wallet+pool+registry). Replaying the same co-signed request - // against the original `celerLedger` must revert. - address otherLedger = address(new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet))); + // against the original `ledger` must revert. + address otherLedger = address(new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet))); Fixtures.PaymentChannelInitializer memory init = Fixtures.PaymentChannelInitializer({ tokenType: 1, @@ -140,7 +140,7 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory request = Fixtures.encOpenChannelRequest(initializer, sigs); vm.expectRevert(AgentPayErrors.LedgerAddressMismatch.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openChannel_signedOnOneChain_replayedOnAnother_reverts() public { @@ -156,7 +156,7 @@ contract CelerLedgerEthTest is LedgerTestBase { disputeTimeout: DISPUTE_TIMEOUT, msgValueReceiver: 0, chainId: block.chainid, - ledgerAddress: address(celerLedger) + ledgerAddress: address(ledger) }); bytes memory initializer = Fixtures.encPaymentChannelInitializer(init); bytes[] memory sigs = SignUtil.coSign(peer0Pk, peer1Pk, initializer); @@ -166,14 +166,14 @@ contract CelerLedgerEthTest is LedgerTestBase { vm.chainId(block.chainid + 1); vm.expectPartialRevert(AgentPayErrors.ChainIdMismatch.selector); - celerLedger.openChannel(request); + ledger.openChannel(request); } function test_openChannel_signedForOneLedger_replayedToSibling_reverts() public { // Direct cross-ledger replay: peers co-sign a *valid* initializer for - // `celerLedger`; the same signed bytes are then submitted to a sibling + // `ledger`; the same signed bytes are then submitted to a sibling // ledger sharing the same wallet+pool+registry. - CelerLedger siblingLedger = new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet)); + AgentPayLedger siblingLedger = new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet)); Fixtures.PaymentChannelInitializer memory init = Fixtures.PaymentChannelInitializer({ tokenType: 1, @@ -184,7 +184,7 @@ contract CelerLedgerEthTest is LedgerTestBase { disputeTimeout: DISPUTE_TIMEOUT, msgValueReceiver: 0, chainId: block.chainid, - ledgerAddress: address(celerLedger) + ledgerAddress: address(ledger) }); bytes memory initializer = Fixtures.encPaymentChannelInitializer(init); bytes[] memory sigs = SignUtil.coSign(peer0Pk, peer1Pk, initializer); @@ -206,37 +206,37 @@ contract CelerLedgerEthTest is LedgerTestBase { vm.expectRevert(); vm.prank(stranger); - celerLedger.setBalanceLimits(tokens, limits); + ledger.setBalanceLimits(tokens, limits); } function test_setBalanceLimits_storesLimit() public { _setEthBalanceLimit(1_000_000); - assertEq(celerLedger.getBalanceLimit(address(0)), 1_000_000); + assertEq(ledger.getBalanceLimit(address(0)), 1_000_000); } function test_disableBalanceLimits_revertsForNonOwner() public { vm.expectRevert(); vm.prank(stranger); - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); } function test_enableBalanceLimits_revertsForNonOwner() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); vm.expectRevert(); vm.prank(stranger); - celerLedger.enableBalanceLimits(); + ledger.enableBalanceLimits(); } function test_disableBalanceLimits_allowsLargeDeposit() public { _setEthBalanceLimit(50); bytes32 channelId = _openZeroEthChannel(); - celerLedger.disableBalanceLimits(); - assertEq(celerLedger.getBalanceLimitsEnabled(), false); + ledger.disableBalanceLimits(); + assertEq(ledger.getBalanceLimitsEnabled(), false); vm.prank(peer0); - celerLedger.deposit{value: 1000}(channelId, peer0, 0); - assertEq(celerLedger.getTotalBalance(channelId), 1000); + ledger.deposit{value: 1000}(channelId, peer0, 0); + assertEq(ledger.getTotalBalance(channelId), 1000); } // ========================================================================= @@ -248,9 +248,9 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes32 channelId = _openZeroEthChannel(); vm.prank(peer0); - celerLedger.deposit{value: 50}(channelId, peer0, 0); + ledger.deposit{value: 50}(channelId, peer0, 0); - assertEq(celerLedger.getTotalBalance(channelId), 50); + assertEq(ledger.getTotalBalance(channelId), 50); } function test_deposit_viaWrappedNative_succeeds() public { @@ -258,9 +258,9 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes32 channelId = _openZeroEthChannel(); vm.prank(peer0); - celerLedger.deposit(channelId, peer0, 100); + ledger.deposit(channelId, peer0, 100); - assertEq(celerLedger.getTotalBalance(channelId), 100); + assertEq(ledger.getTotalBalance(channelId), 100); } function test_deposit_viaWrappedNative_insufficientApproval_reverts() public { @@ -269,19 +269,19 @@ contract CelerLedgerEthTest is LedgerTestBase { // peer0 lowers their nativeWrap allowance below the requested deposit. vm.prank(peer0); - nativeWrap.approve(address(celerLedger), 50); + nativeWrap.approve(address(ledger), 50); vm.expectRevert(); vm.prank(peer0); - celerLedger.deposit(channelId, peer0, 100); + ledger.deposit(channelId, peer0, 100); } - function test_celerLedger_receive_revertsForNonNativeWrap() public { + function test_ledger_receive_revertsForNonNativeWrap() public { // Restricted receive(): only `nativeWrap` can deliver native to the // ledger (during its `withdraw(...)` callback). vm.deal(stranger, 1 ether); vm.prank(stranger); - (bool ok,) = address(celerLedger).call{value: 1}(""); + (bool ok,) = address(ledger).call{value: 1}(""); assertFalse(ok, "direct native send to ledger should revert"); } @@ -291,9 +291,9 @@ contract CelerLedgerEthTest is LedgerTestBase { vm.deal(stranger, 1 ether); vm.prank(stranger); - celerLedger.deposit{value: 25}(channelId, peer0, 0); + ledger.deposit{value: 25}(channelId, peer0, 0); - assertEq(celerLedger.getTotalBalance(channelId), 25); + assertEq(ledger.getTotalBalance(channelId), 25); } function test_deposit_overBalanceLimit_reverts() public { @@ -302,21 +302,21 @@ contract CelerLedgerEthTest is LedgerTestBase { vm.expectPartialRevert(AgentPayErrors.BalanceLimitExceeded.selector); vm.prank(peer0); - celerLedger.deposit{value: 200}(channelId, peer0, 0); + ledger.deposit{value: 200}(channelId, peer0, 0); } function test_deposit_toNonPeer_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openZeroEthChannel(); vm.deal(stranger, 1 ether); vm.expectRevert(AgentPayErrors.NotPeer.selector); vm.prank(stranger); - celerLedger.deposit{value: 25}(channelId, stranger, 0); + ledger.deposit{value: 25}(channelId, stranger, 0); } function test_depositInBatch_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 ch1 = _openZeroEthChannel(); bytes32 ch2 = _openZeroEthChannel(); @@ -331,10 +331,10 @@ contract CelerLedgerEthTest is LedgerTestBase { amounts[1] = 70; vm.prank(peer0); - celerLedger.depositInBatch(ids, receivers, amounts); + ledger.depositInBatch(ids, receivers, amounts); - assertEq(celerLedger.getTotalBalance(ch1), 30); - assertEq(celerLedger.getTotalBalance(ch2), 70); + assertEq(ledger.getTotalBalance(ch1), 30); + assertEq(ledger.getTotalBalance(ch2), 70); } function test_depositInBatch_lengthMismatch_reverts() public { @@ -348,7 +348,7 @@ contract CelerLedgerEthTest is LedgerTestBase { uint256[] memory amounts = new uint256[](2); vm.expectPartialRevert(AgentPayErrors.LengthMismatch.selector); - celerLedger.depositInBatch(ids, receivers, amounts); + ledger.depositInBatch(ids, receivers, amounts); } // ========================================================================= @@ -356,86 +356,86 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_cooperativeWithdraw_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopWithdraw(channelId, 1, peer0, 100, block.timestamp + 1000, bytes32(0)); uint256 peer0BalBefore = peer0.balance; - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); assertEq(peer0.balance, peer0BalBefore + 100); - assertEq(celerLedger.getTotalBalance(channelId), 100); - assertEq(celerLedger.getCooperativeWithdrawSeqNum(channelId), 1); + assertEq(ledger.getTotalBalance(channelId), 100); + assertEq(ledger.getCooperativeWithdrawSeqNum(channelId), 1); } function test_cooperativeWithdraw_toRecipientChannel_movesFundsAcrossChannels() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 srcChannel = _openFundedEthChannel([uint256(200), 0]); bytes32 dstChannel = _openZeroEthChannel(); bytes memory request = _buildCoopWithdraw(srcChannel, 1, peer0, 80, block.timestamp + 1000, dstChannel); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); // Source channel debited 80; destination channel credited 80 to peer0. - assertEq(celerLedger.getTotalBalance(srcChannel), 200 - 80); - assertEq(celerLedger.getTotalBalance(dstChannel), 80); + assertEq(ledger.getTotalBalance(srcChannel), 200 - 80); + assertEq(ledger.getTotalBalance(dstChannel), 80); - (, uint256[2] memory dstDeposits,) = celerLedger.getBalanceMap(dstChannel); + (, uint256[2] memory dstDeposits,) = ledger.getBalanceMap(dstChannel); assertEq(dstDeposits[0], 80); assertEq(dstDeposits[1], 0); } function test_cooperativeWithdraw_expiredDeadline_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopWithdraw(channelId, 1, peer0, 100, block.timestamp - 1, bytes32(0)); vm.expectRevert(AgentPayErrors.DeadlinePassed.selector); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); } function test_cooperativeWithdraw_outOfOrderSeqNum_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // First withdraw at seqNum=1 (must be exactly current+1). bytes memory r1 = _buildCoopWithdraw(channelId, 1, peer0, 50, block.timestamp + 1000, bytes32(0)); - celerLedger.cooperativeWithdraw(r1); + ledger.cooperativeWithdraw(r1); // Try seqNum=1 again (should be 2 next) — reverts. bytes memory r2 = _buildCoopWithdraw(channelId, 1, peer0, 50, block.timestamp + 1000, bytes32(0)); // Full-payload assertion — locks down (onchain, proposed). After the // first withdraw the on-chain seqNum is 1; the test resubmits 1. vm.expectRevert(abi.encodeWithSelector(AgentPayErrors.SeqNumOutOfOrder.selector, uint256(1), uint256(1))); - celerLedger.cooperativeWithdraw(r2); + ledger.cooperativeWithdraw(r2); } function test_cooperativeWithdraw_toMismatchedTokenChannel_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); // Fund an ERC20 channel to use as a (mismatched) recipient. erc20.transfer(peer0, 1_000); erc20.transfer(peer1, 1_000); vm.prank(peer0); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); vm.prank(peer1); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); uint256 deadline = openDeadlineCursor++; (bytes memory openReq,, bytes32 erc20Channel) = _buildOpenErc20(address(erc20), [uint256(0), 0], deadline); - celerLedger.openChannel(openReq); + ledger.openChannel(openReq); bytes32 ethChannel = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopWithdraw(ethChannel, 1, peer0, 50, block.timestamp + 1000, erc20Channel); vm.expectRevert(AgentPayErrors.RecipientChannelTokenMismatch.selector); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); } function test_cooperativeWithdraw_badSignatures_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); Fixtures.CooperativeWithdrawInfo memory w = Fixtures.CooperativeWithdrawInfo({ @@ -456,7 +456,7 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory request = Fixtures.encCooperativeWithdrawRequest(body, sigs); vm.expectRevert(AgentPayErrors.InvalidCoSignatures.selector); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); } // ========================================================================= @@ -464,106 +464,106 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_intendWithdraw_succeeds_emitsEvent() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); - (address receiver, uint256 amount,, bytes32 recipient) = celerLedger.getWithdrawIntent(channelId); + (address receiver, uint256 amount,, bytes32 recipient) = ledger.getWithdrawIntent(channelId); assertEq(receiver, peer0); assertEq(amount, 50); assertEq(recipient, bytes32(0)); } function test_intendWithdraw_byNonPeer_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.expectRevert(); vm.prank(stranger); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); } function test_intendWithdraw_pendingExists_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 30, bytes32(0)); + ledger.intendWithdraw(channelId, 30, bytes32(0)); vm.expectRevert(AgentPayErrors.WithdrawIntentExists.selector); vm.prank(peer1); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); } function test_intendWithdraw_confirmAfterTimeout_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer0BalBefore = peer0.balance; - celerLedger.confirmWithdraw(channelId); + ledger.confirmWithdraw(channelId); assertEq(peer0.balance, peer0BalBefore + 50); - assertEq(celerLedger.getTotalBalance(channelId), 150); + assertEq(ledger.getTotalBalance(channelId), 150); } function test_intendWithdraw_toRecipientChannel_succeeds() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 srcChannel = _openFundedEthChannel([uint256(200), 0]); bytes32 dstChannel = _openZeroEthChannel(); vm.prank(peer0); - celerLedger.intendWithdraw(srcChannel, 60, dstChannel); + ledger.intendWithdraw(srcChannel, 60, dstChannel); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); - celerLedger.confirmWithdraw(srcChannel); + ledger.confirmWithdraw(srcChannel); - assertEq(celerLedger.getTotalBalance(srcChannel), 140); - assertEq(celerLedger.getTotalBalance(dstChannel), 60); + assertEq(ledger.getTotalBalance(srcChannel), 140); + assertEq(ledger.getTotalBalance(dstChannel), 60); } function test_confirmWithdraw_beforeDisputeWindow_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); vm.expectRevert(AgentPayErrors.DisputeNotElapsed.selector); - celerLedger.confirmWithdraw(channelId); + ledger.confirmWithdraw(channelId); } function test_confirmWithdraw_doubleConfirm_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); - celerLedger.confirmWithdraw(channelId); + ledger.confirmWithdraw(channelId); vm.expectRevert(); - celerLedger.confirmWithdraw(channelId); + ledger.confirmWithdraw(channelId); } function test_vetoWithdraw_clearsIntent() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(channelId, 50, bytes32(0)); + ledger.intendWithdraw(channelId, 50, bytes32(0)); vm.prank(peer1); - celerLedger.vetoWithdraw(channelId); + ledger.vetoWithdraw(channelId); - (address receiver,,,) = celerLedger.getWithdrawIntent(channelId); + (address receiver,,,) = ledger.getWithdrawIntent(channelId); assertEq(receiver, address(0)); } @@ -572,21 +572,21 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_snapshotStates_recordsLatest() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory simplex = _buildSignedSimplex(channelId, peer0, 1, 50); bytes memory array = _wrapStateArray(simplex, ""); - celerLedger.snapshotStates(array); + ledger.snapshotStates(array); - (, uint256[2] memory seqs) = celerLedger.getStateSeqNumMap(channelId); + (, uint256[2] memory seqs) = ledger.getStateSeqNumMap(channelId); assertEq(seqs[0], 1); - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); assertEq(transferOuts[0], 50); } function test_snapshotStates_multiChannel_emitsPerChannel() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 ch1 = _openFundedEthChannel([uint256(100), 0]); bytes32 ch2 = _openFundedEthChannel([uint256(150), 0]); bytes32 first = ch1 < ch2 ? ch1 : ch2; @@ -599,16 +599,16 @@ contract CelerLedgerEthTest is LedgerTestBase { states[1] = s1; bytes memory array = Fixtures.encSignedSimplexStateArray(states); - celerLedger.snapshotStates(array); + ledger.snapshotStates(array); - (, uint256[2] memory firstSeqs) = celerLedger.getStateSeqNumMap(first); - (, uint256[2] memory secondSeqs) = celerLedger.getStateSeqNumMap(second); + (, uint256[2] memory firstSeqs) = ledger.getStateSeqNumMap(first); + (, uint256[2] memory secondSeqs) = ledger.getStateSeqNumMap(second); assertEq(firstSeqs[0], 1); assertEq(secondSeqs[0], 1); } function test_snapshotStates_nonAscendingChannelIds_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 ch1 = _openFundedEthChannel([uint256(100), 0]); bytes32 ch2 = _openFundedEthChannel([uint256(150), 0]); bytes32 high = ch1 > ch2 ? ch1 : ch2; @@ -622,11 +622,11 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = Fixtures.encSignedSimplexStateArray(states); vm.expectRevert(AgentPayErrors.NonAscendingChannelIds.selector); - celerLedger.snapshotStates(array); + ledger.snapshotStates(array); } function test_snapshotStates_badSignature_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(100), 0]); Fixtures.SimplexState memory s = Fixtures.SimplexState({ @@ -652,7 +652,7 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = Fixtures.encSignedSimplexStateArray(states); vm.expectRevert(AgentPayErrors.InvalidCoSignatures.selector); - celerLedger.snapshotStates(array); + ledger.snapshotStates(array); } // ========================================================================= @@ -660,58 +660,58 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_cooperativeSettle_closesChannel_distributesBalance() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopSettle(channelId, 1, [uint256(120), 80], block.timestamp + 1000); uint256 peer0Before = peer0.balance; uint256 peer1Before = peer1.balance; - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); assertEq(peer0.balance, peer0Before + 120); assertEq(peer1.balance, peer1Before + 80); } function test_cooperativeSettle_balanceSumMismatch_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Total = 200 but settleBalance = 100 + 50 = 150 → revert. bytes memory request = _buildCoopSettle(channelId, 1, [uint256(100), 50], block.timestamp + 1000); vm.expectRevert(AgentPayErrors.SettleBalanceSumMismatch.selector); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); } function test_cooperativeSettle_expiredDeadline_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Deadline already in the past. bytes memory request = _buildCoopSettle(channelId, 1, [uint256(120), 80], block.timestamp - 1); vm.expectRevert(AgentPayErrors.DeadlinePassed.selector); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); } function test_cooperativeSettle_lowSeqNum_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Bump peer0's seqNum to 1 via snapshot first. bytes memory simplex = _buildSignedSimplex(channelId, peer0, 1, 0); - celerLedger.snapshotStates(_wrapStateArray(simplex, "")); + ledger.snapshotStates(_wrapStateArray(simplex, "")); // settleInfo seqNum must be > both peer seqNums; 1 fails (peer0 already 1). bytes memory request = _buildCoopSettle(channelId, 1, [uint256(120), 80], block.timestamp + 1000); vm.expectPartialRevert(AgentPayErrors.SeqNumOutOfOrder.selector); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); } function test_cooperativeSettle_singleSignature_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); Fixtures.CooperativeSettleInfo memory s = Fixtures.CooperativeSettleInfo({ @@ -727,7 +727,7 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory request = Fixtures.encCooperativeSettleRequest(body, sigs); vm.expectRevert(AgentPayErrors.InvalidCoSignatures.selector); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); } // ========================================================================= @@ -735,7 +735,7 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_intendSettle_thenConfirmSettle_noPays_closesChannel() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory s0 = _buildSignedSimplex(channelId, peer0, 1, 0); @@ -744,20 +744,20 @@ contract CelerLedgerEthTest is LedgerTestBase { // Caller of intendSettle must be a channel peer. vm.prank(peer0); - celerLedger.intendSettle(array); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); + ledger.intendSettle(array); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer0Before = peer0.balance; - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); // peer0 deposited 200; with no transferOut, peer0 keeps everything. assertEq(peer0.balance, peer0Before + 200); } function test_intendSettle_withTransferOut_distributesOnConfirm() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // peer0 transferred 50 to peer1; peer1's simplex is null. @@ -766,12 +766,12 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer0Before = peer0.balance; uint256 peer1Before = peer1.balance; - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); // peer0 keeps 200 - 50 = 150; peer1 receives 50. assertEq(peer0.balance, peer0Before + 150); @@ -779,7 +779,7 @@ contract CelerLedgerEthTest is LedgerTestBase { } function test_intendSettle_multiChannelBatch_putsAllSettling() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 ch1 = _openFundedEthChannel([uint256(100), 0]); bytes32 ch2 = _openFundedEthChannel([uint256(150), 0]); @@ -799,14 +799,14 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = Fixtures.encSignedSimplexStateArray(states); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); - assertEq(uint256(celerLedger.getChannelStatus(firstId)), uint256(LedgerStruct.ChannelStatus.Settling)); - assertEq(uint256(celerLedger.getChannelStatus(secondId)), uint256(LedgerStruct.ChannelStatus.Settling)); + assertEq(uint256(ledger.getChannelStatus(firstId)), uint256(LedgerStruct.ChannelStatus.Settling)); + assertEq(uint256(ledger.getChannelStatus(secondId)), uint256(LedgerStruct.ChannelStatus.Settling)); } function test_intendSettle_nullState_singleSignedByOnePeer() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Both states null (seqNum=0), each signed by exactly one peer. @@ -815,13 +815,13 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); } function test_intendSettle_challengeWithHigherSeqNum_overrides() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // First intendSettle at seqNum=1 (peer0 transferred 30). @@ -829,26 +829,26 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory s1null = _buildSignedSimplex(channelId, peer1, 1, 0); bytes memory array1 = _wrapStateArray(s0v1, s1null); vm.prank(peer0); - celerLedger.intendSettle(array1); + ledger.intendSettle(array1); // Counterparty challenges with seqNum=2 showing peer0 actually transferred 60. bytes memory s0v2 = _buildSignedSimplex(channelId, peer0, 2, 60); bytes memory s1null2 = _buildSignedSimplex(channelId, peer1, 2, 0); bytes memory array2 = _wrapStateArray(s0v2, s1null2); vm.prank(peer1); - celerLedger.intendSettle(array2); + ledger.intendSettle(array2); - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); assertEq(transferOuts[0], 60); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer1Before = peer1.balance; - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); assertEq(peer1.balance, peer1Before + 60); } function test_intendSettle_withPendingPays_clearsAndDistributes() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Resolve a single hash-lock-only pay to max amount on the registry. @@ -863,20 +863,20 @@ contract CelerLedgerEthTest is LedgerTestBase { vm.warp(block.timestamp + 10); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); assertEq(transferOuts[0], 25); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer1Before = peer1.balance; - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); assertEq(peer1.balance, peer1Before + 25); } function test_clearPays_multiSegmentList_processesSecondSegment() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Resolve two pays so we have two distinct pay ids. @@ -903,17 +903,17 @@ contract CelerLedgerEthTest is LedgerTestBase { // intendSettle clears the head list. vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); - (, uint256[2] memory transferOuts1) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts1) = ledger.getTransferOutMap(channelId); assertEq(transferOuts1[0], 15); - (, bytes32[2] memory nextHashes) = celerLedger.getNextPayIdListHashMap(channelId); + (, bytes32[2] memory nextHashes) = ledger.getNextPayIdListHashMap(channelId); assertEq(nextHashes[0], tailHash); // Public clearPays processes the tail. - celerLedger.clearPays(channelId, peer0, tailList); + ledger.clearPays(channelId, peer0, tailList); - (, uint256[2] memory transferOuts2) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts2) = ledger.getTransferOutMap(channelId); assertEq(transferOuts2[0], 35); } @@ -955,7 +955,7 @@ contract CelerLedgerEthTest is LedgerTestBase { // expires, confirmSettle reverts so recipients have time to clearPays // the tail segments. After the deadline, confirmSettle is unconditionally // eligible — uncleared-tail pays are stranded. - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); uint256 clearDeadline = block.timestamp + 500; @@ -968,19 +968,19 @@ contract CelerLedgerEthTest is LedgerTestBase { // implicit head-clear (via getPayAmounts) succeeds. vm.warp(block.timestamp + 1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); // Past dispute timeout but before pay_clear_deadline → reverts. vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); assertTrue(block.timestamp < clearDeadline); vm.expectRevert(AgentPayErrors.PaymentNotFinalized.selector); - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); // Snapshot just before the post-deadline confirmSettle: head was cleared // (transferOut[0] == 15) but the 20-unit tail is still outstanding // (pendingPayOut[0] == 20). This is the stranded-funds setup. - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); - (, uint256[2] memory pendingOuts) = celerLedger.getPendingPayOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); + (, uint256[2] memory pendingOuts) = ledger.getPendingPayOutMap(channelId); assertEq(transferOuts[0], 15, "only head cleared"); assertEq(pendingOuts[0], 20, "tail still pending"); uint256 peer0Before = peer0.balance; @@ -988,8 +988,8 @@ contract CelerLedgerEthTest is LedgerTestBase { // After pay_clear_deadline → succeeds without the tail being cleared. vm.warp(clearDeadline + 1); - celerLedger.confirmSettle(channelId); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); + ledger.confirmSettle(channelId); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Closed)); // Settlement strands the uncleared tail: peer1 only receives the head's 15 // (not the full 35). The 20-unit tail effectively stays with peer0 since @@ -1002,7 +1002,7 @@ contract CelerLedgerEthTest is LedgerTestBase { // Happy path: tail cleared before dispute window closes; confirmSettle // is eligible right after dispute timeout, no need to wait for // pay_clear_deadline because nextPayIdListHash[0] == 0. - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes32 payId1 = _resolveSingleHashLockPay(15, "p1", 1); @@ -1023,19 +1023,19 @@ contract CelerLedgerEthTest is LedgerTestBase { // Advance past the head pays' resolveDeadline so intendSettle's head-clear succeeds. vm.warp(block.timestamp + 1); vm.prank(peer0); - celerLedger.intendSettle(array); - celerLedger.clearPays(channelId, peer0, tailList); + ledger.intendSettle(array); + ledger.clearPays(channelId, peer0, tailList); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 peer1Before = peer1.balance; - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); // peer1 receives both pays = 35. assertEq(peer1.balance, peer1Before + 35); } function test_clearPays_wrongStatus_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openZeroEthChannel(); bytes32[] memory ids = new bytes32[](1); @@ -1044,11 +1044,11 @@ contract CelerLedgerEthTest is LedgerTestBase { // Channel is Operable; clearPays requires Settling. vm.expectRevert(AgentPayErrors.ChannelNotSettling.selector); - celerLedger.clearPays(channelId, peer0, list); + ledger.clearPays(channelId, peer0, list); } function test_clearPays_listHashMismatch_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Put channel in Settling with no pending pays. @@ -1056,7 +1056,7 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory s1 = _buildSignedSimplex(channelId, peer1, 1, 0); bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); // Try to clear an arbitrary list — peer's nextPayIdListHash is bytes32(0). bytes32[] memory ids = new bytes32[](1); @@ -1064,34 +1064,34 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory list = Fixtures.encPayIdList(ids, bytes32(0)); vm.expectRevert(AgentPayErrors.PayListHashMismatch.selector); - celerLedger.clearPays(channelId, peer0, list); + ledger.clearPays(channelId, peer0, list); } function test_confirmSettle_beforeFinalizedTime_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); bytes memory s0 = _buildSignedSimplex(channelId, peer0, 1, 0); bytes memory s1 = _buildSignedSimplex(channelId, peer1, 1, 0); bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); vm.expectRevert(AgentPayErrors.ConfirmSettleTooEarly.selector); - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); } function test_confirmSettle_wrongStatus_reverts() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); // Channel is Operable; confirmSettle requires Settling. vm.expectRevert(AgentPayErrors.ChannelNotSettling.selector); - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); } function test_confirmSettle_invalidBalance_resetsToOperable() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(100), 0]); // Construct a settle scenario where peer0's transferOut > peer0's deposit. @@ -1102,15 +1102,15 @@ contract CelerLedgerEthTest is LedgerTestBase { bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); + ledger.intendSettle(array); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); - celerLedger.confirmSettle(channelId); + ledger.confirmSettle(channelId); // Channel must reset to Operable, not Closed. - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); // Per-peer state should have been wiped. - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); assertEq(transferOuts[0], 0); assertEq(transferOuts[1], 0); } @@ -1120,46 +1120,46 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_getChannelStatusNum_tracksOperableCount() public { - assertEq(celerLedger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 0); + assertEq(ledger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 0); _openZeroEthChannel(); - assertEq(celerLedger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 1); + assertEq(ledger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 1); _openZeroEthChannel(); - assertEq(celerLedger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 2); + assertEq(ledger.getChannelStatusNum(uint256(LedgerStruct.ChannelStatus.Operable)), 2); } function test_getTokenContract_andTokenType_forEthChannel() public { bytes32 channelId = _openZeroEthChannel(); - assertEq(celerLedger.getTokenContract(channelId), address(0)); + assertEq(ledger.getTokenContract(channelId), address(0)); // PbEntity.TokenType.NATIVE = 1 - assertEq(uint256(celerLedger.getTokenType(channelId)), 1); + assertEq(uint256(ledger.getTokenType(channelId)), 1); } function test_getCooperativeWithdrawSeqNum_returnsLatestSeq() public { - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); bytes32 channelId = _openFundedEthChannel([uint256(200), 0]); - assertEq(celerLedger.getCooperativeWithdrawSeqNum(channelId), 0); + assertEq(ledger.getCooperativeWithdrawSeqNum(channelId), 0); bytes memory request = _buildCoopWithdraw(channelId, 1, peer0, 50, block.timestamp + 1000, bytes32(0)); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); - assertEq(celerLedger.getCooperativeWithdrawSeqNum(channelId), 1); + assertEq(ledger.getCooperativeWithdrawSeqNum(channelId), 1); } function test_getMigratedTo_zeroIfNotMigrated() public { bytes32 channelId = _openZeroEthChannel(); - assertEq(celerLedger.getMigratedTo(channelId), address(0)); + assertEq(ledger.getMigratedTo(channelId), address(0)); } function test_getDisputeTimeout_returnsConfigured() public { bytes32 channelId = _openZeroEthChannel(); - assertEq(celerLedger.getDisputeTimeout(channelId), DISPUTE_TIMEOUT); + assertEq(ledger.getDisputeTimeout(channelId), DISPUTE_TIMEOUT); } function test_getStateSeqNumMap_initiallyZero() public { bytes32 channelId = _openZeroEthChannel(); - (address[2] memory addrs, uint256[2] memory seqs) = celerLedger.getStateSeqNumMap(channelId); + (address[2] memory addrs, uint256[2] memory seqs) = ledger.getStateSeqNumMap(channelId); assertEq(addrs[0], peer0); assertEq(addrs[1], peer1); assertEq(seqs[0], 0); @@ -1168,28 +1168,28 @@ contract CelerLedgerEthTest is LedgerTestBase { function test_getTransferOutMap_initiallyZero() public { bytes32 channelId = _openZeroEthChannel(); - (, uint256[2] memory transferOuts) = celerLedger.getTransferOutMap(channelId); + (, uint256[2] memory transferOuts) = ledger.getTransferOutMap(channelId); assertEq(transferOuts[0], 0); assertEq(transferOuts[1], 0); } function test_getNextPayIdListHashMap_initiallyZero() public { bytes32 channelId = _openZeroEthChannel(); - (, bytes32[2] memory hashes) = celerLedger.getNextPayIdListHashMap(channelId); + (, bytes32[2] memory hashes) = ledger.getNextPayIdListHashMap(channelId); assertEq(hashes[0], bytes32(0)); assertEq(hashes[1], bytes32(0)); } function test_getPayClearDeadlineMap_initiallyZero() public { bytes32 channelId = _openZeroEthChannel(); - (, uint256[2] memory deadlines) = celerLedger.getPayClearDeadlineMap(channelId); + (, uint256[2] memory deadlines) = ledger.getPayClearDeadlineMap(channelId); assertEq(deadlines[0], 0); assertEq(deadlines[1], 0); } function test_getPendingPayOutMap_initiallyZero() public { bytes32 channelId = _openZeroEthChannel(); - (, uint256[2] memory pending) = celerLedger.getPendingPayOutMap(channelId); + (, uint256[2] memory pending) = ledger.getPendingPayOutMap(channelId); assertEq(pending[0], 0); assertEq(pending[1], 0); } @@ -1199,19 +1199,19 @@ contract CelerLedgerEthTest is LedgerTestBase { // ========================================================================= function test_getNativeWrap_returnsConfiguredPool() public view { - assertEq(celerLedger.getNativeWrap(), address(nativeWrap)); + assertEq(ledger.getNativeWrap(), address(nativeWrap)); } function test_getPayRegistry_returnsConfiguredRegistry() public view { - assertEq(celerLedger.getPayRegistry(), address(payRegistry)); + assertEq(ledger.getPayRegistry(), address(payRegistry)); } - function test_getCelerWallet_returnsConfiguredWallet() public view { - assertEq(celerLedger.getCelerWallet(), address(celerWallet)); + function test_getAgentPayWallet_returnsConfiguredWallet() public view { + assertEq(ledger.getAgentPayWallet(), address(wallet)); } function test_getBalanceLimit_returnsZeroByDefault() public view { - assertEq(celerLedger.getBalanceLimit(address(0)), 0); + assertEq(ledger.getBalanceLimit(address(0)), 0); } // ========================================================================= @@ -1223,7 +1223,7 @@ contract CelerLedgerEthTest is LedgerTestBase { tokens[0] = address(0); uint256[] memory limits = new uint256[](1); limits[0] = _limit; - celerLedger.setBalanceLimits(tokens, limits); + ledger.setBalanceLimits(tokens, limits); } /// @dev Resolve a single hash-lock-only ConditionalPay (peer0 → peer1) at max diff --git a/test/CelerLedger.Migrate.t.sol b/test/AgentPayLedger.Migrate.t.sol similarity index 68% rename from test/CelerLedger.Migrate.t.sol rename to test/AgentPayLedger.Migrate.t.sol index 2504594..be4df16 100644 --- a/test/CelerLedger.Migrate.t.sol +++ b/test/AgentPayLedger.Migrate.t.sol @@ -4,44 +4,44 @@ pragma solidity ^0.8.20; import {LedgerTestBase} from "./utils/LedgerTestBase.t.sol"; import {AgentPayErrors} from "../src/lib/AgentPayErrors.sol"; import {LedgerStruct} from "../src/lib/ledgerlib/LedgerStruct.sol"; -import {CelerLedger} from "../src/CelerLedger.sol"; +import {AgentPayLedger} from "../src/AgentPayLedger.sol"; import {Fixtures} from "./utils/Fixtures.sol"; import {SignUtil} from "./utils/SignUtil.sol"; /** - * @title CelerLedger migration tests + * @title AgentPayLedger migration tests * @notice Unit tests for peer-controlled cross-version channel migration. - * Deploys two CelerLedger versions sharing the same CelerWallet, opens a + * Deploys two AgentPayLedger versions sharing the same AgentPayWallet, opens a * channel on the old ledger, and migrates it to the new one. Covers both * Operable and Settling source states for ETH and ERC-20 channels, plus the * expired-deadline and wrong-from-ledger revert paths. */ -contract CelerLedgerMigrateTest is LedgerTestBase { - /// @notice The old ledger is `celerLedger` from {LedgerTestBase}; deploy a sibling. - CelerLedger internal celerLedgerNew; +contract AgentPayLedgerMigrateTest is LedgerTestBase { + /// @notice The old ledger is `ledger` from {LedgerTestBase}; deploy a sibling. + AgentPayLedger internal ledgerNew; function setUp() public override { super.setUp(); - celerLedgerNew = new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet)); - vm.label(address(celerLedgerNew), "CelerLedgerNew"); + ledgerNew = new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet)); + vm.label(address(ledgerNew), "AgentPayLedgerNew"); // Disable balance limits on both for simplicity. - celerLedger.disableBalanceLimits(); - celerLedgerNew.disableBalanceLimits(); + ledger.disableBalanceLimits(); + ledgerNew.disableBalanceLimits(); // Approve the new ledger from the wrapped-native too. vm.prank(peer0); - nativeWrap.approve(address(celerLedgerNew), type(uint256).max); + nativeWrap.approve(address(ledgerNew), type(uint256).max); vm.prank(peer1); - nativeWrap.approve(address(celerLedgerNew), type(uint256).max); + nativeWrap.approve(address(ledgerNew), type(uint256).max); // Fund both peers with ERC20 + approve both ledgers. erc20.transfer(peer0, 1_000_000); erc20.transfer(peer1, 1_000_000); vm.prank(peer0); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); vm.prank(peer1); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); } // ------------------------------------------------------------------------- @@ -50,7 +50,7 @@ contract CelerLedgerMigrateTest is LedgerTestBase { function test_migrate_operableEthChannel_succeeds() public { bytes32 channelId = _openFundedEthChannel([uint256(100), 200]); - _assertOperatorOnChannel(channelId, address(celerLedger)); + _assertOperatorOnChannel(channelId, address(ledger)); _migrate(channelId); @@ -59,7 +59,7 @@ contract CelerLedgerMigrateTest is LedgerTestBase { function test_migrate_operableErc20Channel_succeeds() public { bytes32 channelId = _openFundedErc20Channel([uint256(100), 200]); - _assertOperatorOnChannel(channelId, address(celerLedger)); + _assertOperatorOnChannel(channelId, address(ledger)); _migrate(channelId); @@ -78,8 +78,8 @@ contract CelerLedgerMigrateTest is LedgerTestBase { bytes memory s1 = _buildSignedSimplex(channelId, peer1, 1, 0); bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); - celerLedger.intendSettle(array); - assertEq(uint256(celerLedger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); + ledger.intendSettle(array); + assertEq(uint256(ledger.getChannelStatus(channelId)), uint256(LedgerStruct.ChannelStatus.Settling)); _migrate(channelId); @@ -94,20 +94,20 @@ contract CelerLedgerMigrateTest is LedgerTestBase { bytes32 channelId = _openFundedEthChannel([uint256(100), 200]); bytes memory request = - _buildMigrationRequest(channelId, address(celerLedger), address(celerLedgerNew), block.timestamp - 1); + _buildMigrationRequest(channelId, address(ledger), address(ledgerNew), block.timestamp - 1); vm.expectRevert(AgentPayErrors.DeadlinePassed.selector); - celerLedgerNew.migrateChannelFrom(address(celerLedger), request); + ledgerNew.migrateChannelFrom(address(ledger), request); } function test_migrate_wrongFromLedger_reverts() public { bytes32 channelId = _openFundedEthChannel([uint256(100), 200]); - // Migration request claims a different fromLedger (not address(celerLedger)). - bytes memory request = _buildMigrationRequest(channelId, stranger, address(celerLedgerNew), 99_999_999); + // Migration request claims a different fromLedger (not address(ledger)). + bytes memory request = _buildMigrationRequest(channelId, stranger, address(ledgerNew), 99_999_999); vm.expectRevert(AgentPayErrors.FromLedgerAddressMismatch.selector); - celerLedgerNew.migrateChannelFrom(address(celerLedger), request); + ledgerNew.migrateChannelFrom(address(ledger), request); } // ------------------------------------------------------------------------- @@ -117,7 +117,7 @@ contract CelerLedgerMigrateTest is LedgerTestBase { function _openFundedErc20Channel(uint256[2] memory _amounts) internal returns (bytes32) { uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 channelId) = _buildOpenErc20(address(erc20), _amounts, deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); return channelId; } @@ -135,37 +135,36 @@ contract CelerLedgerMigrateTest is LedgerTestBase { } function _migrate(bytes32 _channelId) internal { - bytes memory request = _buildMigrationRequest( - _channelId, address(celerLedger), address(celerLedgerNew), block.timestamp + 100_000 - ); - celerLedgerNew.migrateChannelFrom(address(celerLedger), request); + bytes memory request = + _buildMigrationRequest(_channelId, address(ledger), address(ledgerNew), block.timestamp + 100_000); + ledgerNew.migrateChannelFrom(address(ledger), request); } function _assertOperatorOnChannel(bytes32 _channelId, address _expectedOperator) internal view { - assertEq(celerWallet.walletOperator(_channelId), _expectedOperator); + assertEq(wallet.walletOperator(_channelId), _expectedOperator); } function _assertMigratedFromOldToNew(bytes32 _channelId) internal view { // Wallet operator is now the new ledger. - _assertOperatorOnChannel(_channelId, address(celerLedgerNew)); + _assertOperatorOnChannel(_channelId, address(ledgerNew)); // Old ledger marks the channel Migrated and records migratedTo. - assertEq(uint256(celerLedger.getChannelStatus(_channelId)), uint256(LedgerStruct.ChannelStatus.Migrated)); - assertEq(celerLedger.getMigratedTo(_channelId), address(celerLedgerNew)); + assertEq(uint256(ledger.getChannelStatus(_channelId)), uint256(LedgerStruct.ChannelStatus.Migrated)); + assertEq(ledger.getMigratedTo(_channelId), address(ledgerNew)); // New ledger has the channel as Operable. - assertEq(uint256(celerLedgerNew.getChannelStatus(_channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); + assertEq(uint256(ledgerNew.getChannelStatus(_channelId)), uint256(LedgerStruct.ChannelStatus.Operable)); // Channel-level metadata round-trips. - (uint256 oldDispute, uint256 oldType, address oldToken,) = celerLedger.getChannelMigrationArgs(_channelId); - (uint256 newDispute, uint256 newType, address newToken,) = celerLedgerNew.getChannelMigrationArgs(_channelId); + (uint256 oldDispute, uint256 oldType, address oldToken,) = ledger.getChannelMigrationArgs(_channelId); + (uint256 newDispute, uint256 newType, address newToken,) = ledgerNew.getChannelMigrationArgs(_channelId); assertEq(oldDispute, newDispute); assertEq(oldType, newType); assertEq(oldToken, newToken); // Per-peer balances round-trip. - (, uint256[2] memory oldDeposits, uint256[2] memory oldWithdrawals) = celerLedger.getBalanceMap(_channelId); - (, uint256[2] memory newDeposits, uint256[2] memory newWithdrawals) = celerLedgerNew.getBalanceMap(_channelId); + (, uint256[2] memory oldDeposits, uint256[2] memory oldWithdrawals) = ledger.getBalanceMap(_channelId); + (, uint256[2] memory newDeposits, uint256[2] memory newWithdrawals) = ledgerNew.getBalanceMap(_channelId); assertEq(oldDeposits[0], newDeposits[0]); assertEq(oldDeposits[1], newDeposits[1]); assertEq(oldWithdrawals[0], newWithdrawals[0]); diff --git a/test/CelerWallet.t.sol b/test/AgentPayWallet.t.sol similarity index 98% rename from test/CelerWallet.t.sol rename to test/AgentPayWallet.t.sol index 3e0b1c2..91cb9f7 100644 --- a/test/CelerWallet.t.sol +++ b/test/AgentPayWallet.t.sol @@ -3,12 +3,12 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; import {AgentPayErrors} from "../src/lib/AgentPayErrors.sol"; -import {CelerWallet} from "../src/CelerWallet.sol"; +import {AgentPayWallet} from "../src/AgentPayWallet.sol"; import {WalletTestHelper} from "../src/helper/WalletTestHelper.sol"; import {ERC20ExampleToken} from "../src/helper/ERC20ExampleToken.sol"; /** - * @title CelerWallet tests + * @title AgentPayWallet tests * @notice Unit tests for the multi-owner / multi-token wallet that holds funds * for every channel in the AgentPay network. Covers wallet creation, ETH / * ERC-20 deposits and withdrawals, inter-wallet transfer, operator transfer @@ -16,12 +16,12 @@ import {ERC20ExampleToken} from "../src/helper/ERC20ExampleToken.sol"; * * @dev Pause control runs through `Ownable` — the contract owner is the pauser. */ -contract CelerWalletTest is Test { +contract AgentPayWalletTest is Test { // ========================================================================= // Setup // ========================================================================= - CelerWallet internal wallet; + AgentPayWallet internal wallet; WalletTestHelper internal walletHelper; ERC20ExampleToken internal token; @@ -54,7 +54,7 @@ contract CelerWalletTest is Test { function setUp() public { owner = address(this); token = new ERC20ExampleToken(); - wallet = new CelerWallet(); + wallet = new AgentPayWallet(); walletHelper = new WalletTestHelper(address(wallet)); walletOwners.push(owner0); @@ -80,7 +80,7 @@ contract CelerWalletTest is Test { walletId2 = _walletIdViaHelper(1); } - /// @dev Replicates `WalletTestHelper.create` + `CelerWallet.create` id derivation: + /// @dev Replicates `WalletTestHelper.create` + `AgentPayWallet.create` id derivation: /// helper hashes the user nonce into `bytes32 n`, then the wallet derives /// `id = keccak256(chainid, walletAddr, helperAddr, n)`. function _walletIdViaHelper(uint256 _nonce) internal view returns (bytes32) { diff --git a/test/GasReport.t.sol b/test/GasReport.t.sol index 8f5a458..57e3c84 100644 --- a/test/GasReport.t.sol +++ b/test/GasReport.t.sol @@ -5,8 +5,8 @@ import {VmSafe} from "forge-std/Vm.sol"; import {LedgerTestBase} from "./utils/LedgerTestBase.t.sol"; import {Fixtures} from "./utils/Fixtures.sol"; import {SignUtil} from "./utils/SignUtil.sol"; -import {CelerLedger} from "../src/CelerLedger.sol"; -import {CelerWallet} from "../src/CelerWallet.sol"; +import {AgentPayLedger} from "../src/AgentPayLedger.sol"; +import {AgentPayWallet} from "../src/AgentPayWallet.sol"; import {NativeWrapMock} from "../src/helper/NativeWrapMock.sol"; import {PayRegistry} from "../src/PayRegistry.sol"; import {PayResolver} from "../src/PayResolver.sol"; @@ -22,9 +22,9 @@ import {BooleanCondMock} from "../src/helper/BooleanCondMock.sol"; * size). * * @dev Top-level reports (per-call gas): - * - `test/gas_logs/CelerLedger-ETH.txt` - * - `test/gas_logs/CelerLedger-ERC20.txt` - * - `test/gas_logs/CelerLedger-Migrate.txt` + * - `test/gas_logs/AgentPayLedger-ETH.txt` + * - `test/gas_logs/AgentPayLedger-ERC20.txt` + * - `test/gas_logs/AgentPayLedger-Migrate.txt` * - `test/gas_logs/PayResolver.txt` * - `test/gas_logs/VirtContractResolver.txt` * @@ -43,29 +43,29 @@ import {BooleanCondMock} from "../src/helper/BooleanCondMock.sol"; contract GasReport is LedgerTestBase { function setUp() public override { super.setUp(); - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); erc20.transfer(peer0, 1_000_000_000); erc20.transfer(peer1, 1_000_000_000); vm.prank(peer0); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); vm.prank(peer1); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); } // ========================================================================= - // Top-level report — CelerLedger ETH + // Top-level report — AgentPayLedger ETH // ========================================================================= - function test_writeReport_CelerLedgerEth() public { - string memory s = "********** Gas Measurement: CelerLedger ETH **********\n\n"; + function test_writeReport_AgentPayLedgerEth() public { + string memory s = "********** Gas Measurement: AgentPayLedger ETH **********\n\n"; s = string.concat(s, "***** Deploy Gas Used *****\n"); s = string.concat(s, _deployRow("VirtContractResolver", _measureDeploy_virt())); s = string.concat(s, _deployRow("NativeWrapMock", _measureDeploy_nativeWrap())); s = string.concat(s, _deployRow("PayRegistry", _measureDeploy_payRegistry())); - s = string.concat(s, _deployRow("CelerWallet", _measureDeploy_celerWallet())); + s = string.concat(s, _deployRow("AgentPayWallet", _measureDeploy_wallet())); s = string.concat(s, _deployRow("PayResolver", _measureDeploy_payResolver())); - s = string.concat(s, _deployRow("CelerLedger", _measureDeploy_celerLedger())); + s = string.concat(s, _deployRow("AgentPayLedger", _measureDeploy_ledger())); s = string.concat(s, "\n***** Function Calls Gas Used *****\n"); s = string.concat(s, _row("openChannel() with zero deposit", _measure_openChannel_zeroDeposit())); @@ -89,35 +89,35 @@ contract GasReport is LedgerTestBase { s = string.concat(s, _row("confirmSettle()", _measure_confirmSettle())); s = string.concat(s, _row("cooperativeSettle()", _measure_cooperativeSettle())); - _writeReport("test/gas_logs/CelerLedger-ETH.txt", s); + _writeReport("test/gas_logs/AgentPayLedger-ETH.txt", s); } // ========================================================================= - // Top-level report — CelerLedger ERC20 + // Top-level report — AgentPayLedger ERC20 // ========================================================================= - function test_writeReport_CelerLedgerErc20() public { - string memory s = "********** Gas Measurement: CelerLedger ERC20 **********\n\n"; + function test_writeReport_AgentPayLedgerErc20() public { + string memory s = "********** Gas Measurement: AgentPayLedger ERC20 **********\n\n"; s = string.concat(s, "***** Function Calls Gas Used *****\n"); s = string.concat(s, _row("openChannel() with zero deposit", _measure_openChannel_erc20_zero())); s = string.concat(s, _row("openChannel() with non-zero ERC20 deposits", _measure_openChannel_erc20_funded())); s = string.concat(s, _row("deposit()", _measure_deposit_erc20())); s = string.concat(s, _row("cooperativeWithdraw()", _measure_cooperativeWithdraw_erc20())); s = string.concat(s, _row("cooperativeSettle()", _measure_cooperativeSettle_erc20())); - _writeReport("test/gas_logs/CelerLedger-ERC20.txt", s); + _writeReport("test/gas_logs/AgentPayLedger-ERC20.txt", s); } // ========================================================================= // Top-level report — Migration // ========================================================================= - function test_writeReport_CelerLedgerMigrate() public { - string memory s = "********** Gas Measurement: CelerLedger Migration **********\n\n"; + function test_writeReport_AgentPayLedgerMigrate() public { + string memory s = "********** Gas Measurement: AgentPayLedger Migration **********\n\n"; s = string.concat(s, "***** Function Calls Gas Used *****\n"); s = string.concat(s, _row("migrateChannelFrom() an Operable ETH channel", _measure_migrate_operableEth())); s = string.concat(s, _row("migrateChannelFrom() a Settling ETH channel", _measure_migrate_settlingEth())); s = string.concat(s, _row("migrateChannelFrom() an Operable ERC20 channel", _measure_migrate_operableErc20())); - _writeReport("test/gas_logs/CelerLedger-Migrate.txt", s); + _writeReport("test/gas_logs/AgentPayLedger-Migrate.txt", s); } // ========================================================================= @@ -268,10 +268,10 @@ contract GasReport is LedgerTestBase { vm.revertToState(snap); } - function _measureDeploy_celerWallet() internal returns (uint256 g) { + function _measureDeploy_wallet() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); uint256 g0 = gasleft(); - new CelerWallet(); + new AgentPayWallet(); g = g0 - gasleft(); vm.revertToState(snap); } @@ -284,10 +284,10 @@ contract GasReport is LedgerTestBase { vm.revertToState(snap); } - function _measureDeploy_celerLedger() internal returns (uint256 g) { + function _measureDeploy_ledger() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); uint256 g0 = gasleft(); - new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet)); + new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet)); g = g0 - gasleft(); vm.revertToState(snap); } @@ -296,7 +296,7 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); (bytes memory request,,) = _buildOpenEth([uint256(0), 0], 0, openDeadlineCursor++); uint256 g0 = gasleft(); - celerLedger.openChannel(request); + ledger.openChannel(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -306,7 +306,7 @@ contract GasReport is LedgerTestBase { (bytes memory request,,) = _buildOpenEth([uint256(100), 200], 0, openDeadlineCursor++); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.openChannel{value: 100}(request); + ledger.openChannel{value: 100}(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -315,7 +315,7 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); (bytes memory request,,) = _buildOpenErc20(address(erc20), [uint256(0), 0], openDeadlineCursor++); uint256 g0 = gasleft(); - celerLedger.openChannel(request); + ledger.openChannel(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -324,29 +324,29 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); (bytes memory request,,) = _buildOpenErc20(address(erc20), [uint256(100), 200], openDeadlineCursor++); uint256 g0 = gasleft(); - celerLedger.openChannel(request); + ledger.openChannel(request); g = g0 - gasleft(); vm.revertToState(snap); } function _measure_setBalanceLimits() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); - celerLedger.enableBalanceLimits(); + ledger.enableBalanceLimits(); address[] memory tokens = new address[](1); tokens[0] = address(0); uint256[] memory limits = new uint256[](1); limits[0] = 1_000_000; uint256 g0 = gasleft(); - celerLedger.setBalanceLimits(tokens, limits); + ledger.setBalanceLimits(tokens, limits); g = g0 - gasleft(); vm.revertToState(snap); } function _measure_disableBalanceLimits() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); - celerLedger.enableBalanceLimits(); + ledger.enableBalanceLimits(); uint256 g0 = gasleft(); - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); g = g0 - gasleft(); vm.revertToState(snap); } @@ -355,7 +355,7 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); // Already disabled in setUp. uint256 g0 = gasleft(); - celerLedger.enableBalanceLimits(); + ledger.enableBalanceLimits(); g = g0 - gasleft(); vm.revertToState(snap); } @@ -365,7 +365,7 @@ contract GasReport is LedgerTestBase { bytes32 ch = _openZeroEthChannel(); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.deposit{value: 50}(ch, peer0, 0); + ledger.deposit{value: 50}(ch, peer0, 0); g = g0 - gasleft(); vm.revertToState(snap); } @@ -375,7 +375,7 @@ contract GasReport is LedgerTestBase { bytes32 ch = _openZeroEthChannel(); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.deposit(ch, peer0, 100); + ledger.deposit(ch, peer0, 100); g = g0 - gasleft(); vm.revertToState(snap); } @@ -383,10 +383,10 @@ contract GasReport is LedgerTestBase { function _measure_deposit_erc20() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); (bytes memory request,, bytes32 ch) = _buildOpenErc20(address(erc20), [uint256(0), 0], openDeadlineCursor++); - celerLedger.openChannel(request); + ledger.openChannel(request); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.deposit(ch, peer0, 100); + ledger.deposit(ch, peer0, 100); g = g0 - gasleft(); vm.revertToState(snap); } @@ -407,7 +407,7 @@ contract GasReport is LedgerTestBase { } vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.depositInBatch(ids, receivers, amounts); + ledger.depositInBatch(ids, receivers, amounts); g = g0 - gasleft(); vm.revertToState(snap); } @@ -417,7 +417,7 @@ contract GasReport is LedgerTestBase { bytes32 ch = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.intendWithdraw(ch, 50, bytes32(0)); + ledger.intendWithdraw(ch, 50, bytes32(0)); g = g0 - gasleft(); vm.revertToState(snap); } @@ -426,10 +426,10 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); bytes32 ch = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(ch, 50, bytes32(0)); + ledger.intendWithdraw(ch, 50, bytes32(0)); vm.prank(peer1); uint256 g0 = gasleft(); - celerLedger.vetoWithdraw(ch); + ledger.vetoWithdraw(ch); g = g0 - gasleft(); vm.revertToState(snap); } @@ -438,10 +438,10 @@ contract GasReport is LedgerTestBase { uint256 snap = vm.snapshotState(); bytes32 ch = _openFundedEthChannel([uint256(200), 0]); vm.prank(peer0); - celerLedger.intendWithdraw(ch, 50, bytes32(0)); + ledger.intendWithdraw(ch, 50, bytes32(0)); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 g0 = gasleft(); - celerLedger.confirmWithdraw(ch); + ledger.confirmWithdraw(ch); g = g0 - gasleft(); vm.revertToState(snap); } @@ -451,7 +451,7 @@ contract GasReport is LedgerTestBase { bytes32 ch = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopWithdraw(ch, 1, peer0, 100, block.timestamp + 1000, bytes32(0)); uint256 g0 = gasleft(); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -459,10 +459,10 @@ contract GasReport is LedgerTestBase { function _measure_cooperativeWithdraw_erc20() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); (bytes memory openReq,, bytes32 ch) = _buildOpenErc20(address(erc20), [uint256(200), 0], openDeadlineCursor++); - celerLedger.openChannel(openReq); + ledger.openChannel(openReq); bytes memory request = _buildCoopWithdraw(ch, 1, peer0, 100, block.timestamp + 1000, bytes32(0)); uint256 g0 = gasleft(); - celerLedger.cooperativeWithdraw(request); + ledger.cooperativeWithdraw(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -473,7 +473,7 @@ contract GasReport is LedgerTestBase { bytes memory simplex = _buildSignedSimplex(ch, peer0, 1, 50); bytes memory array = _wrapStateArray(simplex, ""); uint256 g0 = gasleft(); - celerLedger.snapshotStates(array); + ledger.snapshotStates(array); g = g0 - gasleft(); vm.revertToState(snap); } @@ -486,7 +486,7 @@ contract GasReport is LedgerTestBase { bytes memory array = _wrapStateArray(s0, s1); vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.intendSettle(array); + ledger.intendSettle(array); g = g0 - gasleft(); vm.revertToState(snap); } @@ -518,7 +518,7 @@ contract GasReport is LedgerTestBase { vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.intendSettle(array); + ledger.intendSettle(array); g = g0 - gasleft(); vm.revertToState(snap); } @@ -544,7 +544,7 @@ contract GasReport is LedgerTestBase { vm.prank(peer0); uint256 g0 = gasleft(); - celerLedger.intendSettle(array); + ledger.intendSettle(array); g = g0 - gasleft(); vm.revertToState(snap); } @@ -580,10 +580,10 @@ contract GasReport is LedgerTestBase { vm.warp(block.timestamp + 10); vm.prank(peer0); - celerLedger.intendSettle(_wrapStateArray(s0, s1)); + ledger.intendSettle(_wrapStateArray(s0, s1)); uint256 g0 = gasleft(); - celerLedger.clearPays(ch, peer0, tailList); + ledger.clearPays(ch, peer0, tailList); g = g0 - gasleft(); vm.revertToState(snap); } @@ -594,10 +594,10 @@ contract GasReport is LedgerTestBase { bytes memory s0 = _buildSignedSimplex(ch, peer0, 1, 0); bytes memory s1 = _buildSignedSimplex(ch, peer1, 1, 0); vm.prank(peer0); - celerLedger.intendSettle(_wrapStateArray(s0, s1)); + ledger.intendSettle(_wrapStateArray(s0, s1)); vm.warp(block.timestamp + DISPUTE_TIMEOUT + 1); uint256 g0 = gasleft(); - celerLedger.confirmSettle(ch); + ledger.confirmSettle(ch); g = g0 - gasleft(); vm.revertToState(snap); } @@ -607,7 +607,7 @@ contract GasReport is LedgerTestBase { bytes32 ch = _openFundedEthChannel([uint256(200), 0]); bytes memory request = _buildCoopSettle(ch, 1, [uint256(120), 80], block.timestamp + 1000); uint256 g0 = gasleft(); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -615,10 +615,10 @@ contract GasReport is LedgerTestBase { function _measure_cooperativeSettle_erc20() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); (bytes memory openReq,, bytes32 ch) = _buildOpenErc20(address(erc20), [uint256(200), 0], openDeadlineCursor++); - celerLedger.openChannel(openReq); + ledger.openChannel(openReq); bytes memory request = _buildCoopSettle(ch, 1, [uint256(120), 80], block.timestamp + 1000); uint256 g0 = gasleft(); - celerLedger.cooperativeSettle(request); + ledger.cooperativeSettle(request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -691,12 +691,12 @@ contract GasReport is LedgerTestBase { function _measure_migrate_operableEth() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); bytes32 ch = _openFundedEthChannel([uint256(100), 200]); - CelerLedger newLedger = _deployNewLedgerSiblingAndApprove(); + AgentPayLedger newLedger = _deployNewLedgerSiblingAndApprove(); bytes memory request = - _buildMigrationRequest(ch, address(celerLedger), address(newLedger), block.timestamp + 100_000); + _buildMigrationRequest(ch, address(ledger), address(newLedger), block.timestamp + 100_000); uint256 g0 = gasleft(); - newLedger.migrateChannelFrom(address(celerLedger), request); + newLedger.migrateChannelFrom(address(ledger), request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -707,14 +707,14 @@ contract GasReport is LedgerTestBase { bytes memory s0 = _buildSignedSimplex(ch, peer0, 1, 0); bytes memory s1 = _buildSignedSimplex(ch, peer1, 1, 0); vm.prank(peer0); - celerLedger.intendSettle(_wrapStateArray(s0, s1)); + ledger.intendSettle(_wrapStateArray(s0, s1)); - CelerLedger newLedger = _deployNewLedgerSiblingAndApprove(); + AgentPayLedger newLedger = _deployNewLedgerSiblingAndApprove(); bytes memory request = - _buildMigrationRequest(ch, address(celerLedger), address(newLedger), block.timestamp + 100_000); + _buildMigrationRequest(ch, address(ledger), address(newLedger), block.timestamp + 100_000); uint256 g0 = gasleft(); - newLedger.migrateChannelFrom(address(celerLedger), request); + newLedger.migrateChannelFrom(address(ledger), request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -722,14 +722,14 @@ contract GasReport is LedgerTestBase { function _measure_migrate_operableErc20() internal returns (uint256 g) { uint256 snap = vm.snapshotState(); (bytes memory openReq,, bytes32 ch) = _buildOpenErc20(address(erc20), [uint256(100), 200], openDeadlineCursor++); - celerLedger.openChannel(openReq); + ledger.openChannel(openReq); - CelerLedger newLedger = _deployNewLedgerSiblingAndApprove(); + AgentPayLedger newLedger = _deployNewLedgerSiblingAndApprove(); bytes memory request = - _buildMigrationRequest(ch, address(celerLedger), address(newLedger), block.timestamp + 100_000); + _buildMigrationRequest(ch, address(ledger), address(newLedger), block.timestamp + 100_000); uint256 g0 = gasleft(); - newLedger.migrateChannelFrom(address(celerLedger), request); + newLedger.migrateChannelFrom(address(ledger), request); g = g0 - gasleft(); vm.revertToState(snap); } @@ -784,8 +784,8 @@ contract GasReport is LedgerTestBase { return Fixtures.encSignedSimplexState(simplex, sigs); } - function _deployNewLedgerSiblingAndApprove() internal returns (CelerLedger newLedger) { - newLedger = new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet)); + function _deployNewLedgerSiblingAndApprove() internal returns (AgentPayLedger newLedger) { + newLedger = new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet)); newLedger.disableBalanceLimits(); vm.prank(peer0); nativeWrap.approve(address(newLedger), type(uint256).max); diff --git a/test/gas_logs/AgentPayLedger-ERC20.txt b/test/gas_logs/AgentPayLedger-ERC20.txt new file mode 100644 index 0000000..e0e7a6a --- /dev/null +++ b/test/gas_logs/AgentPayLedger-ERC20.txt @@ -0,0 +1,8 @@ +********** Gas Measurement: AgentPayLedger ERC20 ********** + +***** Function Calls Gas Used ***** +openChannel() with zero deposit: 305141 +openChannel() with non-zero ERC20 deposits: 468969 +deposit(): 149771 +cooperativeWithdraw(): 89032 +cooperativeSettle(): 88555 diff --git a/test/gas_logs/CelerLedger-ETH.txt b/test/gas_logs/AgentPayLedger-ETH.txt similarity index 64% rename from test/gas_logs/CelerLedger-ETH.txt rename to test/gas_logs/AgentPayLedger-ETH.txt index 1413831..b525d04 100644 --- a/test/gas_logs/CelerLedger-ETH.txt +++ b/test/gas_logs/AgentPayLedger-ETH.txt @@ -1,17 +1,17 @@ -********** Gas Measurement: CelerLedger ETH ********** +********** Gas Measurement: AgentPayLedger ETH ********** ***** Deploy Gas Used ***** VirtContractResolver Deploy Gas: 176893 NativeWrapMock Deploy Gas: 416605 PayRegistry Deploy Gas: 554814 -CelerWallet Deploy Gas: 1055891 -PayResolver Deploy Gas: 1806985 -CelerLedger Deploy Gas: 1820981 +AgentPayWallet Deploy Gas: 1055895 +PayResolver Deploy Gas: 1806981 +AgentPayLedger Deploy Gas: 1820981 ***** Function Calls Gas Used ***** -openChannel() with zero deposit: 301168 -openChannel() using nativeWrap and msg.value: 432652 -setBalanceLimits(): 24553 +openChannel() with zero deposit: 301173 +openChannel() using nativeWrap and msg.value: 432658 +setBalanceLimits(): 24532 disableBalanceLimits(): 1132 enableBalanceLimits(): 29544 deposit() via msg.value: 77839 @@ -20,10 +20,10 @@ depositInBatch() with 5 deposits: 525900 intendWithdraw(): 72783 vetoWithdraw(): 4017 confirmWithdraw(): 57359 -cooperativeWithdraw(): 92228 +cooperativeWithdraw(): 92210 snapshotStates() with one non-null simplex state: 77707 intendSettle() with a null state: 87577 intendSettle() with two 2-payment-hashList states: 279885 clearPays() with 2 payments: 17012 confirmSettle(): 48519 -cooperativeSettle(): 92734 +cooperativeSettle(): 92777 diff --git a/test/gas_logs/CelerLedger-Migrate.txt b/test/gas_logs/AgentPayLedger-Migrate.txt similarity index 75% rename from test/gas_logs/CelerLedger-Migrate.txt rename to test/gas_logs/AgentPayLedger-Migrate.txt index ee060d1..9db1f78 100644 --- a/test/gas_logs/CelerLedger-Migrate.txt +++ b/test/gas_logs/AgentPayLedger-Migrate.txt @@ -1,4 +1,4 @@ -********** Gas Measurement: CelerLedger Migration ********** +********** Gas Measurement: AgentPayLedger Migration ********** ***** Function Calls Gas Used ***** migrateChannelFrom() an Operable ETH channel: 304259 diff --git a/test/gas_logs/CelerLedger-ERC20.txt b/test/gas_logs/CelerLedger-ERC20.txt deleted file mode 100644 index 00c714e..0000000 --- a/test/gas_logs/CelerLedger-ERC20.txt +++ /dev/null @@ -1,8 +0,0 @@ -********** Gas Measurement: CelerLedger ERC20 ********** - -***** Function Calls Gas Used ***** -openChannel() with zero deposit: 305141 -openChannel() with non-zero ERC20 deposits: 468963 -deposit(): 149771 -cooperativeWithdraw(): 89024 -cooperativeSettle(): 88544 diff --git a/test/invariants/ChannelInvariants.t.sol b/test/invariants/ChannelInvariants.t.sol index 82abb12..e3f4f31 100644 --- a/test/invariants/ChannelInvariants.t.sol +++ b/test/invariants/ChannelInvariants.t.sol @@ -7,7 +7,7 @@ import {ChannelHandler} from "./handlers/ChannelHandler.sol"; /** * @title ChannelInvariants - * @notice Foundry invariant tests for `CelerLedger`. A {ChannelHandler} drives + * @notice Foundry invariant tests for `AgentPayLedger`. A {ChannelHandler} drives * random sequences of channel actions across both native and ERC-20 channels: * open / deposit / cooperative withdraw / cooperative settle / unilateral * withdraw + veto + confirm / snapshotStates / intendSettle / confirmSettle. @@ -26,7 +26,7 @@ import {ChannelHandler} from "./handlers/ChannelHandler.sol"; * `peerProfiles.withdrawal`. * * Cross-version migration is out of scope (covered by direct tests in - * `CelerLedger.Migrate.t.sol`); pending pay lists in simplex states are also + * `AgentPayLedger.Migrate.t.sol`); pending pay lists in simplex states are also * out of scope (handler always passes empty lists). */ contract ChannelInvariants is LedgerTestBase { @@ -49,7 +49,7 @@ contract ChannelInvariants is LedgerTestBase { // Disable per-token deposit caps so fuzzed open / deposit calls aren't // gated by uninitialized limits. - celerLedger.disableBalanceLimits(); + ledger.disableBalanceLimits(); // Seed peer ERC-20 balances + approvals upfront. The handler's // `_ensureErc20Balance` will top up later if a peer drains, but @@ -58,11 +58,11 @@ contract ChannelInvariants is LedgerTestBase { deal(address(erc20), peer0, 100 ether); deal(address(erc20), peer1, 100 ether); vm.prank(peer0); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); vm.prank(peer1); - erc20.approve(address(celerLedger), type(uint256).max); + erc20.approve(address(ledger), type(uint256).max); - handler = new ChannelHandler(celerLedger, celerWallet, nativeWrap, erc20, peer0, peer1, peer0Pk, peer1Pk); + handler = new ChannelHandler(ledger, wallet, nativeWrap, erc20, peer0, peer1, peer0Pk, peer1Pk); // Restrict Foundry's fuzzer to the handler — otherwise it would call // every public function on the inherited test scaffolding. @@ -82,7 +82,7 @@ contract ChannelInvariants is LedgerTestBase { for (uint256 i = 0; i < n; i++) { bytes32 id = handler.channelIds(i); uint256 prev = lastStatusValue[id]; - uint256 curr = uint256(celerLedger.getChannelStatus(id)); + uint256 curr = uint256(ledger.getChannelStatus(id)); if (prev == 0) { lastStatusValue[id] = curr; @@ -112,7 +112,7 @@ contract ChannelInvariants is LedgerTestBase { uint256 n = handler.channelCount(); for (uint256 i = 0; i < n; i++) { bytes32 id = handler.channelIds(i); - (, uint256[2] memory deps, uint256[2] memory wds) = celerLedger.getBalanceMap(id); + (, uint256[2] memory deps, uint256[2] memory wds) = ledger.getBalanceMap(id); assertGe(deps[0], lastDeposit[id][0], "peer0 deposit decreased"); assertGe(deps[1], lastDeposit[id][1], "peer1 deposit decreased"); @@ -134,11 +134,11 @@ contract ChannelInvariants is LedgerTestBase { uint256 n = handler.channelCount(); for (uint256 i = 0; i < n; i++) { bytes32 id = handler.channelIds(i); - uint256 currStatus = uint256(celerLedger.getChannelStatus(id)); + uint256 currStatus = uint256(ledger.getChannelStatus(id)); uint256 prevStatus = lastStatusForSimplex[id]; - (, uint256[2] memory seqs) = celerLedger.getStateSeqNumMap(id); - (, uint256[2] memory tos) = celerLedger.getTransferOutMap(id); + (, uint256[2] memory seqs) = ledger.getStateSeqNumMap(id); + (, uint256[2] memory tos) = ledger.getTransferOutMap(id); bool rebound = prevStatus == uint256(LedgerStruct.ChannelStatus.Settling) && currStatus == uint256(LedgerStruct.ChannelStatus.Operable); @@ -166,11 +166,11 @@ contract ChannelInvariants is LedgerTestBase { uint256 n = handler.channelCount(); for (uint256 i = 0; i < n; i++) { bytes32 id = handler.channelIds(i); - uint256 status = uint256(celerLedger.getChannelStatus(id)); + uint256 status = uint256(ledger.getChannelStatus(id)); address token = handler.channelToken(id); - uint256 walletBal = celerWallet.balanceOf(id, token); + uint256 walletBal = wallet.balanceOf(id, token); - (, uint256[2] memory deps, uint256[2] memory wds) = celerLedger.getBalanceMap(id); + (, uint256[2] memory deps, uint256[2] memory wds) = ledger.getBalanceMap(id); uint256 netLedger = deps[0] + deps[1] - wds[0] - wds[1]; if ( @@ -191,7 +191,7 @@ contract ChannelInvariants is LedgerTestBase { uint256 n = handler.channelCount(); for (uint256 i = 0; i < n; i++) { bytes32 id = handler.channelIds(i); - (, uint256[2] memory deps, uint256[2] memory wds) = celerLedger.getBalanceMap(id); + (, uint256[2] memory deps, uint256[2] memory wds) = ledger.getBalanceMap(id); assertEq(deps[0] + deps[1], handler.ghostDeposits(id), "deposit total mismatch"); assertEq(wds[0] + wds[1], handler.ghostWithdrawals(id), "withdrawal total mismatch"); diff --git a/test/invariants/handlers/ChannelHandler.sol b/test/invariants/handlers/ChannelHandler.sol index 9cf2618..387da5b 100644 --- a/test/invariants/handlers/ChannelHandler.sol +++ b/test/invariants/handlers/ChannelHandler.sol @@ -5,8 +5,8 @@ import {CommonBase} from "forge-std/Base.sol"; import {StdCheats} from "forge-std/StdCheats.sol"; import {StdUtils} from "forge-std/StdUtils.sol"; -import {CelerLedger} from "../../../src/CelerLedger.sol"; -import {CelerWallet} from "../../../src/CelerWallet.sol"; +import {AgentPayLedger} from "../../../src/AgentPayLedger.sol"; +import {AgentPayWallet} from "../../../src/AgentPayWallet.sol"; import {NativeWrapMock} from "../../../src/helper/NativeWrapMock.sol"; import {ERC20ExampleToken} from "../../../src/helper/ERC20ExampleToken.sol"; import {LedgerStruct} from "../../../src/lib/ledgerlib/LedgerStruct.sol"; @@ -15,7 +15,7 @@ import {SignUtil} from "../../utils/SignUtil.sol"; /** * @title ChannelHandler - * @notice Invariant-test driver for `CelerLedger`. Each public function wraps one + * @notice Invariant-test driver for `AgentPayLedger`. Each public function wraps one * user-facing channel action (open / deposit / cooperative withdraw / cooperative * settle / unilateral withdraw + veto + confirm / snapshotStates / intendSettle / * confirmSettle). Foundry selects functions and fuzzes their args; the handler @@ -32,8 +32,8 @@ contract ChannelHandler is CommonBase, StdCheats, StdUtils { // ----------------------------------------------------------------------------- // Wired contracts (deployed by the invariant test, passed in via constructor). // ----------------------------------------------------------------------------- - CelerLedger public immutable ledger; - CelerWallet public immutable wallet; + AgentPayLedger public immutable ledger; + AgentPayWallet public immutable wallet; NativeWrapMock public immutable nativeWrap; ERC20ExampleToken public immutable erc20; @@ -72,8 +72,8 @@ contract ChannelHandler is CommonBase, StdCheats, StdUtils { mapping(bytes32 => uint256) public callsByName; constructor( - CelerLedger _ledger, - CelerWallet _wallet, + AgentPayLedger _ledger, + AgentPayWallet _wallet, NativeWrapMock _nativeWrap, ERC20ExampleToken _erc20, address _peer0, diff --git a/test/utils/Base.t.sol b/test/utils/Base.t.sol index e83035e..5bfaf93 100644 --- a/test/utils/Base.t.sol +++ b/test/utils/Base.t.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; -import {CelerWallet} from "../../src/CelerWallet.sol"; -import {CelerLedger} from "../../src/CelerLedger.sol"; +import {AgentPayWallet} from "../../src/AgentPayWallet.sol"; +import {AgentPayLedger} from "../../src/AgentPayLedger.sol"; import {NativeWrapMock} from "../../src/helper/NativeWrapMock.sol"; import {PayRegistry} from "../../src/PayRegistry.sol"; import {PayResolver} from "../../src/PayResolver.sol"; @@ -14,7 +14,7 @@ import {ERC20ExampleToken} from "../../src/helper/ERC20ExampleToken.sol"; * @title BaseTest * @notice Common deployment + helper utilities for AgentPay Foundry tests. Inherit * this from individual test contracts to get a fully wired contract graph - * (`celerWallet`, `celerLedger`, `nativeWrap`, `payRegistry`, `payResolver`, + * (`wallet`, `ledger`, `nativeWrap`, `payRegistry`, `payResolver`, * `virtResolver`, `erc20`) and a few addressing helpers. * @dev `setUp()` here can be called from a child's own `setUp()` via `super.setUp()`. * Tests that don't need every dependency may reach into the contracts directly @@ -24,8 +24,8 @@ contract BaseTest is Test { // ------------------------------------------------------------------------- // Deployed contracts // ------------------------------------------------------------------------- - CelerWallet internal celerWallet; - CelerLedger internal celerLedger; + AgentPayWallet internal wallet; + AgentPayLedger internal ledger; NativeWrapMock internal nativeWrap; PayRegistry internal payRegistry; PayResolver internal payResolver; @@ -64,12 +64,12 @@ contract BaseTest is Test { payRegistry = new PayRegistry(); virtResolver = new VirtContractResolver(); payResolver = new PayResolver(address(payRegistry), address(virtResolver)); - celerWallet = new CelerWallet(); - celerLedger = new CelerLedger(address(nativeWrap), address(payRegistry), address(celerWallet)); + wallet = new AgentPayWallet(); + ledger = new AgentPayLedger(address(nativeWrap), address(payRegistry), address(wallet)); erc20 = new ERC20ExampleToken(); - vm.label(address(celerWallet), "CelerWallet"); - vm.label(address(celerLedger), "CelerLedger"); + vm.label(address(wallet), "AgentPayWallet"); + vm.label(address(ledger), "AgentPayLedger"); vm.label(address(nativeWrap), "NativeWrap"); vm.label(address(payRegistry), "PayRegistry"); vm.label(address(payResolver), "PayResolver"); diff --git a/test/utils/LedgerTestBase.t.sol b/test/utils/LedgerTestBase.t.sol index 78a3c71..cd1d55e 100644 --- a/test/utils/LedgerTestBase.t.sol +++ b/test/utils/LedgerTestBase.t.sol @@ -7,9 +7,9 @@ import {SignUtil} from "./SignUtil.sol"; /** * @title LedgerTestBase - * @notice CelerLedger-specific helpers layered on top of {BaseTest}: open-channel + * @notice AgentPayLedger-specific helpers layered on top of {BaseTest}: open-channel * fixture builders, channelId derivation, and pre-funded peer pool. Used by - * every CelerLedger test file (ETH, ERC20, Migrate). + * every AgentPayLedger test file (ETH, ERC20, Migrate). */ contract LedgerTestBase is BaseTest { uint256 internal constant DISPUTE_TIMEOUT = 20; @@ -34,9 +34,9 @@ contract LedgerTestBase is BaseTest { // Approve the ledger to draw from each peer's wrapped-native balance. vm.prank(peer0); - nativeWrap.approve(address(celerLedger), type(uint256).max); + nativeWrap.approve(address(ledger), type(uint256).max); vm.prank(peer1); - nativeWrap.approve(address(celerLedger), type(uint256).max); + nativeWrap.approve(address(ledger), type(uint256).max); } // ------------------------------------------------------------------------- @@ -44,11 +44,11 @@ contract LedgerTestBase is BaseTest { // ------------------------------------------------------------------------- /// @dev Derive the channel id that `openChannel` will produce for a given - /// initializer-bytes payload. Mirrors `CelerWallet.create` id derivation: + /// initializer-bytes payload. Mirrors `AgentPayWallet.create` id derivation: /// `keccak256(chainid, wallet, ledger, keccak256(initializer))`. function _deriveChannelId(bytes memory _initializer) internal view returns (bytes32) { bytes32 nonce = keccak256(_initializer); - return keccak256(abi.encodePacked(block.chainid, address(celerWallet), address(celerLedger), nonce)); + return keccak256(abi.encodePacked(block.chainid, address(wallet), address(ledger), nonce)); } // ------------------------------------------------------------------------- @@ -71,7 +71,7 @@ contract LedgerTestBase is BaseTest { disputeTimeout: DISPUTE_TIMEOUT, msgValueReceiver: _msgValueReceiver, chainId: block.chainid, - ledgerAddress: address(celerLedger) + ledgerAddress: address(ledger) }); initializer = Fixtures.encPaymentChannelInitializer(init); @@ -95,7 +95,7 @@ contract LedgerTestBase is BaseTest { disputeTimeout: DISPUTE_TIMEOUT, msgValueReceiver: 0, chainId: block.chainid, - ledgerAddress: address(celerLedger) + ledgerAddress: address(ledger) }); initializer = Fixtures.encPaymentChannelInitializer(init); @@ -108,7 +108,7 @@ contract LedgerTestBase is BaseTest { function _openZeroEthChannel() internal returns (bytes32 channelId) { uint256 deadline = openDeadlineCursor++; (bytes memory request,, bytes32 derivedId) = _buildOpenEth([uint256(0), 0], 0, deadline); - celerLedger.openChannel(request); + ledger.openChannel(request); return derivedId; } @@ -118,7 +118,7 @@ contract LedgerTestBase is BaseTest { (bytes memory request,, bytes32 derivedId) = _buildOpenEth(_amounts, 0, deadline); // peer0 sends msg.value = amounts[0]; remainder pulled from peer1's wrapped-native balance. vm.prank(peer0); - celerLedger.openChannel{value: _amounts[0]}(request); + ledger.openChannel{value: _amounts[0]}(request); return derivedId; } From c4503149325faf87614efbc0ddc2aaba7af5a5fa Mon Sep 17 00:00:00 2001 From: Xiaozhou Li Date: Sat, 9 May 2026 19:52:18 -0700 Subject: [PATCH 2/3] cleanup --- script/README.md | 8 ++++---- src/RouterRegistry.sol | 2 +- src/lib/ledgerlib/LedgerOperation.sol | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/script/README.md b/script/README.md index b25f5a7..3eabff6 100644 --- a/script/README.md +++ b/script/README.md @@ -56,7 +56,7 @@ to reproduce the linked bytecode. When verification is run as part of the same just deployed automatically. To verify after the fact, supply them explicitly: ```bash -forge verify-contract AgentPayLedger \ +forge verify-contract AgentPayLedger \ --chain-id \ --libraries src/lib/ledgerlib/LedgerOperation.sol:LedgerOperation: \ --libraries src/lib/ledgerlib/LedgerChannel.sol:LedgerChannel: \ @@ -135,7 +135,7 @@ After **`DeployCore`**: 1. Decide whether to keep the deployer as `AgentPayWallet` owner, or transfer to a security multisig: ```bash - cast send "transferOwnership(address)" --rpc-url $RPC_URL --private-key $PRIVATE_KEY + cast send "transferOwnership(address)" --rpc-url $RPC_URL --private-key $PRIVATE_KEY ``` The owner can `pause` / `unpause` and (when paused) `drainToken` for emergency recovery — pick the holder accordingly. @@ -147,10 +147,10 @@ After **`DeployLedger`**: revert until you do one of: ```bash # Option A: set caps for the tokens you'll use (address(0) = native) - cast send "setBalanceLimits(address[],uint256[])" "[0x0000000000000000000000000000000000000000]" "[1000000000000000000000]" --rpc-url $RPC_URL --private-key $PRIVATE_KEY + cast send "setBalanceLimits(address[],uint256[])" "[0x0000000000000000000000000000000000000000]" "[1000000000000000000000]" --rpc-url $RPC_URL --private-key $PRIVATE_KEY # Option B: disable limits entirely - cast send "disableBalanceLimits()" --rpc-url $RPC_URL --private-key $PRIVATE_KEY + cast send "disableBalanceLimits()" --rpc-url $RPC_URL --private-key $PRIVATE_KEY ``` 2. Optionally transfer ledger ownership to the same multisig. diff --git a/src/RouterRegistry.sol b/src/RouterRegistry.sol index d2d6581..c7d2385 100644 --- a/src/RouterRegistry.sol +++ b/src/RouterRegistry.sol @@ -17,7 +17,7 @@ contract RouterRegistry is IRouterRegistry { mapping(address => uint256) public routerInfo; /** - * @notice An external router could register to join the Celer Network + * @notice An external router could register to join the AgentPay Network */ function registerRouter() external { require(routerInfo[msg.sender] == 0, AgentPayErrors.RouterAlreadyRegistered()); diff --git a/src/lib/ledgerlib/LedgerOperation.sol b/src/lib/ledgerlib/LedgerOperation.sol index 3170e02..4d2be98 100644 --- a/src/lib/ledgerlib/LedgerOperation.sol +++ b/src/lib/ledgerlib/LedgerOperation.sol @@ -588,7 +588,7 @@ library LedgerOperation { /** * @notice create a wallet for a new channel * @param _self storage data of AgentPayLedger contract - * @param _w celer wallet + * @param _w agent-pay wallet * @param _peers peers of the new channel * @param _nonce nonce for creating the wallet * @return channel id, which is same as the created wallet id From a427c8ff92b2234a5053ceb68add9e0f094ab875 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 10 May 2026 03:04:37 +0000 Subject: [PATCH 3/3] Fix grammar: "a AgentPayLedger" -> "an AgentPayLedger" in NatSpec comments Agent-Logs-Url: https://github.com/celer-network/agent-pay-contracts/sessions/897ed49e-6f97-4175-9cd4-e3d5ba97294e Co-authored-by: hhl42 <708956+hhl42@users.noreply.github.com> --- script/DeployLedger.s.sol | 2 +- src/lib/ledgerlib/LedgerStruct.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/DeployLedger.s.sol b/script/DeployLedger.s.sol index a70b937..2e3a3d0 100644 --- a/script/DeployLedger.s.sol +++ b/script/DeployLedger.s.sol @@ -6,7 +6,7 @@ import {AgentPayLedger} from "../src/AgentPayLedger.sol"; /** * @title DeployLedger - * @notice Deploys a `AgentPayLedger` instance wired against the existing core + * @notice Deploys an `AgentPayLedger` instance wired against the existing core * contracts and the chain's canonical wrapped-native (wrapped-native) * contract. Run once per ledger version — peers cooperatively migrate * channels between versions; the wallet / registry / nativeWrap stay shared. diff --git a/src/lib/ledgerlib/LedgerStruct.sol b/src/lib/ledgerlib/LedgerStruct.sol index ddeef69..b243ca1 100644 --- a/src/lib/ledgerlib/LedgerStruct.sol +++ b/src/lib/ledgerlib/LedgerStruct.sol @@ -15,7 +15,7 @@ import "../data/PbEntity.sol"; */ library LedgerStruct { /** - * @notice Lifecycle status of a channel inside a AgentPayLedger instance. + * @notice Lifecycle status of a channel inside an AgentPayLedger instance. * @dev `Uninitialized` is the implicit default when a channel id is not present in * `Ledger.channelMap`. State transitions: see `docs/architecture-summary.md`. */