Skip to content

Commit 41cc514

Browse files
committed
push
1 parent cb4375e commit 41cc514

9 files changed

Lines changed: 3864 additions & 273 deletions

File tree

.docs/ChangesTarget.md

Lines changed: 318 additions & 264 deletions
Large diffs are not rendered by default.

.env.example

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1+
# RPC endpoint for deployment chain (e.g. Base Sepolia)
12
RPC_URL="https://sepolia.base.org"
3+
4+
# Deployer private key (used to broadcast deployment tx)
25
PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
6+
7+
# Operator address - signs checkpoints for ChannelSettlement (derive from OPERATOR_PRIVATE_KEY)
38
OPERATOR="0x0000000000000000000000000000000000000000"
9+
10+
# ERC20 settlement token address (e.g. USDC on Base Sepolia: 0x036CbD53842c5426634e7929541eC2318f3dCF7e)
411
SETTLEMENT_TOKEN="0x0000000000000000000000000000000000000000"
12+
13+
# Chainlink CRE Forwarder address - from https://docs.chain.link/cre/guides/workflow/using-evm-client/forwarder-directory
514
CHAINLINK_FORWARDER="0x0000000000000000000000000000000000000000"
615

7-
# Oracle validation
16+
# Oracle validation - min confidence in basis points (8000 = 80%)
817
MIN_CONFIDENCE="8000"
918

10-
# Fee config
11-
PROTOCOL_FEE_BPS="100"
12-
LP_FEE_SHARE_BPS="2000"
19+
# Fee config (basis points)
20+
PROTOCOL_FEE_BPS="250"
21+
LP_FEE_SHARE_BPS="1750"
1322
CREATOR_FEE_SHARE_BPS="1000"
1423

1524
# SettlementRouter controls
1625
USE_RECEIVER_ALLOWLIST="true"
1726
APPROVE_MARKET_REGISTRY_RECEIVER="true"
1827

19-
# Optional ReceiverTemplate metadata checks
28+
# Optional: grant AI_ORACLE_ROLE on MarketDraftBoard for CRE-driven draft proposals (omit to use deployer)
29+
# AI_ORACLE_ADDRESS="0x0000000000000000000000000000000000000000"
30+
31+
# Optional ReceiverTemplate metadata checks - restrict which CRE workflows can call receivers
2032
EXPECTED_WORKFLOW_AUTHOR="0x0000000000000000000000000000000000000000"
2133
EXPECTED_WORKFLOW_ID="0x0000000000000000000000000000000000000000000000000000000000000000"
2234
EXPECTED_WORKFLOW_NAME=""

.env.world-sepolia.tenderly

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Network: Tenderly Virtual TestNet (Worldchain Sepolia)
2+
RPC_URL="https://virtual.worldchain-sepolia.eu.rpc.tenderly.co/11e8d92d-b8ae-4dcd-ae5a-4d82f447dd1a"
3+
CHAIN_ID="4801"
4+
NATIVE_SYMBOL="ETH"
5+
BLOCK_EXPLORER_URL="https://worldchain-sepolia-explorer.alchemy.com/"
6+
7+
# Deployer key (wallet that deploys contracts)
8+
PRIVATE_KEY="redacted"
9+
OPERATOR="0xbeaA395506D02d20749d8E39ddb996ACe1C85Bfc"
10+
# Operator (signs checkpoints / session finalization depending on your relayer design)
11+
# If your relayer needs it (recommended to keep separate from deployer):
12+
OPERATOR_PRIVATE_KEY="redacted"
13+
14+
# Settlement / collateral token
15+
# If you don't have an ERC20 on this VT yet, keep 0x0 only if your contracts allow native ETH settlement.
16+
# Otherwise deploy a MockERC20 and put its address here.
17+
SETTLEMENT_TOKEN="0x3183a80955d6922ec4b3fe0b2db593dfd67bfb2f"
18+
19+
# Chainlink CRE forwarder
20+
# On a Tenderly Virtual TestNet, you usually won't have an official forwarder address unless you deployed/mocked it.
21+
# If your receivers enforce forwarder-only access, this must be a real address you control/deploy.
22+
CHAINLINK_FORWARDER="0xbeaA395506D02d20749d8E39ddb996ACe1C85Bfc"
23+
24+
# Oracle validation
25+
MIN_CONFIDENCE="8000"
26+
27+
# Fee config
28+
PROTOCOL_FEE_BPS="200" # 2%
29+
LP_FEE_SHARE_BPS="2000" # 20%
30+
CREATOR_FEE_SHARE_BPS="2000" # 20%
31+
32+
# SettlementRouter controls
33+
USE_RECEIVER_ALLOWLIST="true"
34+
APPROVE_MARKET_REGISTRY_RECEIVER="true"
35+
36+
# Optional ReceiverTemplate metadata checks
37+
EXPECTED_WORKFLOW_AUTHOR="0x0000000000000000000000000000000000000000"
38+
EXPECTED_WORKFLOW_ID="0x0000000000000000000000000000000000000000000000000000000000000000"
39+
EXPECTED_WORKFLOW_NAME="retropickV1"

DEPLOYMENT.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# RetroPick Testnet Deployment
2+
3+
Deployment guide for the CRE + Nitrolite Yellow checkpoint stack to **Tenderly Virtual TestNet** (Worldchain Sepolia).
4+
5+
## Target Network
6+
7+
| Property | Value |
8+
|----------|-------|
9+
| Network | Tenderly Virtual TestNet (Worldchain Sepolia) |
10+
| RPC URL | `https://virtual.worldchain-sepolia.eu.rpc.tenderly.co/41d3ff02-8fa1-4270-aa65-a652be2c6541` |
11+
| Chain ID | 4801 |
12+
| Native Token | ETH |
13+
| Block Explorer | https://worldchain-sepolia-explorer.alchemy.com/ |
14+
15+
## Configuration (from .env)
16+
17+
| Variable | Value | Description |
18+
|----------|-------|-------------|
19+
| `PRIVATE_KEY` | (deployer key) | Wallet that broadcasts deployment |
20+
| `OPERATOR` | `0xbeaA395506D02d20749d8E39ddb996ACe1C85Bfc` | Checkpoint signer for ChannelSettlement |
21+
| `OPERATOR_PRIVATE_KEY` | (same as deployer) | Used by relayer for signing |
22+
| `SETTLEMENT_TOKEN` | `0x0000000000000000000000000000000000000000` | ERC20 collateral; deploy MockERC20 if needed |
23+
| `CHAINLINK_FORWARDER` | `0x0000000000000000000000000000000000000000` | On VT, deploy/mock if receivers enforce it |
24+
| `MIN_CONFIDENCE` | `8000` | Oracle confidence (80% in bps) |
25+
| `PROTOCOL_FEE_BPS` | `250` | Protocol fee 2.5% |
26+
| `LP_FEE_SHARE_BPS` | `1750` | LP share 17.5% |
27+
| `CREATOR_FEE_SHARE_BPS` | `1000` | Creator share 10% |
28+
| `USE_RECEIVER_ALLOWLIST` | `true` | Enforce receiver allowlist |
29+
| `APPROVE_MARKET_REGISTRY_RECEIVER` | `true` | MarketRegistry approved for settlement |
30+
| `EXPECTED_WORKFLOW_NAME` | `retropickV1` | ReceiverTemplate workflow filter |
31+
32+
## Pre-deploy
33+
34+
1. Ensure `.env` is populated (copy from `.env.example`).
35+
2. **Required:** `SETTLEMENT_TOKEN` and `CHAINLINK_FORWARDER` must be non-zero. Deployment reverts otherwise:
36+
- **SETTLEMENT_TOKEN** – CollateralVault requires a valid ERC20. Deploy a MockERC20 on the VT and mint tokens.
37+
- **CHAINLINK_FORWARDER** – ReceiverTemplate requires a valid forwarder. On VT, deploy a mock (e.g. a simple contract you control) that can call `onReport` for testing.
38+
3. Fund the deployer wallet with native ETH on the VT for gas.
39+
40+
## Deploy
41+
42+
```bash
43+
cd packages/contracts
44+
source .env # or export vars manually
45+
forge script script/DeployTestnet.s.sol:DeployTestnet \
46+
--rpc-url "$RPC_URL" \
47+
--broadcast \
48+
--slow
49+
```
50+
51+
# Export private key ke global
52+
export PRIVATE_KEY=$(cast wallet private-key --account rudeus33)
53+
# Deploy with script
54+
forge script script/DeployTestnet.s.sol \
55+
--rpc-url https://sepolia.base.org/ \
56+
--broadcast \
57+
--account rudeus33
58+
59+
`--slow` waits for each transaction to confirm before sending the next, avoiding "replacement transaction underpriced" errors when deploying many contracts.
60+
61+
For a dry run (no broadcast):
62+
63+
```bash
64+
forge script script/DeployTestnet.s.sol:DeployTestnet --rpc-url "$RPC_URL"
65+
```
66+
67+
**"Replacement transaction underpriced"** – Use `--slow` (included above). If you have pending txs from a failed run, either wait for them to confirm or clear and retry.
68+
69+
**Resume partial deployment:**
70+
71+
```bash
72+
forge script script/DeployTestnet.s.sol:DeployTestnet --rpc-url "$RPC_URL" --broadcast --slow --resume
73+
```
74+
75+
## Deployed Contracts
76+
77+
After deployment, record addresses from the script output:
78+
79+
| Contract | Address |
80+
|----------|---------|
81+
| ExecutionLedger | |
82+
| ChannelSettlement | |
83+
| MultiAssetVault | |
84+
| CollateralVault | |
85+
| MarketRegistry | |
86+
| FeeManager | |
87+
| FeePool | |
88+
| TreasuryPool | |
89+
| ReportValidator | |
90+
| CREReceiver | |
91+
| OracleCoordinator | |
92+
| SettlementRouter | |
93+
| MarketPolicy | |
94+
| MarketDraftBoard | |
95+
| DraftClaimManager | |
96+
| LiquidityVaultFactory | |
97+
| CREPublishReceiver | |
98+
| MarketFactory | |
99+
100+
## Post-deploy
101+
102+
### 1. Relayer (`apps/relayer/.env`)
103+
104+
```
105+
CHANNEL_SETTLEMENT_ADDRESS=<ChannelSettlement address from deploy>
106+
OPERATOR_PRIVATE_KEY=<operator key>
107+
```
108+
109+
### 2. CRE Workflows
110+
111+
Configure workflows to use:
112+
113+
- **CREReceiver** – outcome resolution + checkpoint submit
114+
- **CREPublishReceiver** – publish from draft
115+
- **MarketFactory** – CRE feed market creation
116+
117+
### 3. Draft Proposals
118+
119+
Deployer has `AI_ORACLE_ROLE`. Set `AI_ORACLE_ADDRESS` in `.env` and re-run deploy to grant the role to a CRE workflow for automated draft proposals.
120+
121+
## Tenderly Notes
122+
123+
- Virtual TestNets use ephemeral forked state; deployments are not persistent across sessions unless you use Tenderly persistence features.
124+
- No official Chainlink Forwarder on VT; use a mock or disable forwarder checks for testing.
125+
- Fund the deployer wallet with native ETH on the VT for gas.

broadcast/DeployTestnet.s.sol/84532/run-1771484789778.json

Lines changed: 1112 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployTestnet.s.sol/84532/run-1771487715129.json

Lines changed: 1112 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployTestnet.s.sol/84532/run-latest.json

Lines changed: 1112 additions & 0 deletions
Large diffs are not rendered by default.

foundry.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
[profile.default]
22
src = "src"
33
fuzz = { runs = 10000 }
4-
4+
use_literal_content = true # use source code
55
out = "out"
66
libs = ["lib"]
77
via_ir = true
8+
9+
# Reduce bytecode size for EIP-170 limit (24KB); ChannelSettlement was over limit
10+
optimizer = true
11+
optimizer_runs = 200
812
remappings = [
913
"@openzeppelin/=lib/openzeppelin-contracts/"
1014
]
1115
fs_permissions = [
1216
{ access = "read-write", path = "/home/asyam321/Project/RetroPick/RetroPick/.cursor/debug.log" }
1317
]
18+
19+
eth-rpc-url = "https://sepolia.base.org"
20+
chain_id = 84532

script/DeployTestnet.s.sol

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.24;
33

4+
/// @title DeployTestnet
5+
/// @notice Deploys the CRE + Nitrolite Yellow checkpoint production stack.
6+
/// @dev Uses MarketRegistry + ChannelSettlement. Does NOT deploy PoolMarketLegacy or SessionFinalizer.
7+
/// For relayer: set CHANNEL_SETTLEMENT_ADDRESS and OPERATOR_PRIVATE_KEY in apps/relayer/.env.
8+
49
import {Script, console2} from "forge-std/Script.sol";
510

611
import {ExecutionLedger} from "../src/execution/ExecutionLedger.sol";
@@ -130,6 +135,10 @@ contract DeployTestnet is Script {
130135

131136
d.draftBoard.setDraftClaimManager(address(d.draftClaimManager));
132137
d.draftBoard.grantPublishCaller(address(d.marketFactory));
138+
address aiOracle = vm.envOr("AI_ORACLE_ADDRESS", address(0));
139+
if (aiOracle != address(0)) {
140+
d.draftBoard.grantRole(d.draftBoard.AI_ORACLE_ROLE(), aiOracle);
141+
}
133142
d.draftClaimManager.setLiquidityVaultFactory(address(d.liquidityVaultFactory));
134143

135144
d.marketFactory.setMarketRegistry(address(d.marketRegistry));
@@ -192,8 +201,17 @@ contract DeployTestnet is Script {
192201
console2.log("MarketFactory", address(d.marketFactory));
193202
console2.log("CREPublishReceiver", address(d.crePublishReceiver));
194203
console2.log("");
195-
console2.log("For relayer checkpoint path, set in apps/relayer/.env:");
196-
console2.log(" CHANNEL_SETTLEMENT_ADDRESS=%s", address(d.channelSettlement));
197-
console2.log(" OPERATOR=<same as OPERATOR env used here>");
204+
console2.log("--- Post-deploy checklist ---");
205+
console2.log("");
206+
console2.log("1. Relayer (apps/relayer/.env):");
207+
console2.log(" CHANNEL_SETTLEMENT_ADDRESS=%s", address(d.channelSettlement));
208+
console2.log(" OPERATOR_PRIVATE_KEY=<same operator key as OPERATOR env>");
209+
console2.log("");
210+
console2.log("2. CRE workflows: configure receivers:");
211+
console2.log(" CREReceiver (outcome resolution + checkpoint submit): %s", address(d.creReceiver));
212+
console2.log(" CREPublishReceiver (publish from draft): %s", address(d.crePublishReceiver));
213+
console2.log(" MarketFactory (CRE feed market creation): %s", address(d.marketFactory));
214+
console2.log("");
215+
console2.log("3. Draft proposals: deployer has AI_ORACLE_ROLE. Set AI_ORACLE_ADDRESS to grant to CRE workflow.");
198216
}
199217
}

0 commit comments

Comments
 (0)