Skip to content

Commit c6bb67d

Browse files
committed
Production-grade rewrite: fix settlement, add safety, CI, multi-chain, SDK
## Contracts (BREAKING) - Fix broken settlement logic: proper market resolution + winner/loser payouts - Add ReentrancyGuard on withdraw/settlement, Pausable on deposit/orders - Add order cancellation (cancelOrder), market resolution (resolveMarket) - Add MIN_ORDER_SIZE (0.001 ETH) to prevent DoS via dust orders - Losers get unmatched refund, winners get original + pro-rata of losing pool - FlashGridFactory now accepts resolver address for each market ## Tests (800+ LOC) - 45+ test cases including market resolution, payout correctness, edge cases - Fuzz tests: settlement conservation, deposit/withdraw, balance consistency - Reentrancy attack test with malicious contract - Pause/unpause, min order size, order cancellation tests - Stress test: 50 orders per tick settlement ## CI/CD - GitHub Actions workflow: contracts (build, test, fuzz, fmt) + dashboard (typecheck, build) + SDK ## Multi-Chain - New chains.ts config supporting Monad Testnet, Sepolia, Base Sepolia - Refactored wallet.ts, indexer.ts, contract.ts to use dynamic chain config - foundry.toml updated with Sepolia + Base Sepolia RPC endpoints ## SDK (@flashgrid/sdk) - Standalone npm package with types, ABIs, chain config, and FlashGridClient class - Full TypeScript SDK for deploying and interacting with FlashGrid markets https://claude.ai/code/session_01AYqngFhM9R9jAN8zGzLGqk
1 parent e483cf6 commit c6bb67d

38 files changed

Lines changed: 2872 additions & 229 deletions

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, "feature/**"]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
contracts:
11+
name: Contracts (Build + Test + Fmt)
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: contracts
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: recursive
21+
22+
- name: Install Foundry
23+
uses: foundry-rs/foundry-toolchain@v1
24+
25+
- name: Install dependencies
26+
run: forge install
27+
28+
- name: Build contracts
29+
run: forge build --sizes
30+
31+
- name: Run tests
32+
run: forge test -vvv
33+
34+
- name: Run fuzz tests (extended)
35+
run: forge test --match-test "testFuzz" -vvv --fuzz-runs 500
36+
37+
- name: Check formatting
38+
run: forge fmt --check
39+
40+
dashboard:
41+
name: Dashboard (Lint + Typecheck + Build)
42+
runs-on: ubuntu-latest
43+
defaults:
44+
run:
45+
working-directory: dashboard
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: "20"
54+
cache: npm
55+
cache-dependency-path: dashboard/package-lock.json
56+
57+
- name: Install dependencies
58+
run: npm ci
59+
60+
- name: TypeScript typecheck
61+
run: npx tsc --noEmit
62+
63+
- name: Build
64+
run: npm run build
65+
66+
sdk:
67+
name: SDK (Typecheck + Build)
68+
runs-on: ubuntu-latest
69+
defaults:
70+
run:
71+
working-directory: sdk
72+
73+
steps:
74+
- uses: actions/checkout@v4
75+
76+
- name: Setup Node.js
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: "20"
80+
cache: npm
81+
cache-dependency-path: sdk/package-lock.json
82+
83+
- name: Install dependencies
84+
run: npm ci
85+
86+
- name: TypeScript typecheck
87+
run: npx tsc --noEmit
88+
89+
- name: Build
90+
run: npm run build

contracts/foundry.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ optimizer_runs = 200
1010
line_length = 120
1111
tab_width = 4
1212

13+
[profile.default.fuzz]
14+
runs = 256
15+
1316
[rpc_endpoints]
1417
monad_testnet = "https://testnet-rpc.monad.xyz"
18+
sepolia = "${SEPOLIA_RPC_URL}"
19+
base_sepolia = "${BASE_SEPOLIA_RPC_URL}"
1520

1621
[etherscan]
1722
monad_testnet = { key = "", url = "https://testnet.monadvision.com/api" }
23+
sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api-sepolia.etherscan.io/api" }
24+
base_sepolia = { key = "${BASESCAN_API_KEY}", url = "https://api-sepolia.basescan.org/api" }

contracts/script/Deploy.s.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {ParallelBenchmark} from "../src/ParallelBenchmark.sol";
88
contract DeployScript is Script {
99
function run() external {
1010
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
11+
address deployer = vm.addr(deployerPrivateKey);
1112
vm.startBroadcast(deployerPrivateKey);
1213

1314
// 1. Deploy Factory
1415
FlashGridFactory factory = new FlashGridFactory();
1516
console2.log("FlashGridFactory deployed at:", address(factory));
1617

17-
// 2. Create default market via factory
18+
// 2. Create default market (deployer is resolver)
1819
address market = factory.createMarket("Will MON reach $10 by Q2 2025?");
1920
console2.log("FlashGrid market deployed at:", market);
2021

@@ -24,10 +25,10 @@ contract DeployScript is Script {
2425

2526
vm.stopBroadcast();
2627

27-
// Output addresses for scripts
2828
console2.log("\n=== Deployment Summary ===");
2929
console2.log("Factory: ", address(factory));
3030
console2.log("Market: ", market);
31+
console2.log("Resolver: ", deployer);
3132
console2.log("Benchmark: ", address(benchmark));
3233
console2.log("Chain ID: ", block.chainid);
3334
}

0 commit comments

Comments
 (0)