Skip to content

fix(launchpad): dpnm-v2 registration + treeRoot + encodedParams double-selector#164

Open
lnlockly wants to merge 5 commits into
Virtual-Protocol:mainfrom
lnlockly:fix/launchpad-dpnm-v2-bugs
Open

fix(launchpad): dpnm-v2 registration + treeRoot + encodedParams double-selector#164
lnlockly wants to merge 5 commits into
Virtual-Protocol:mainfrom
lnlockly:fix/launchpad-dpnm-v2-bugs

Conversation

@lnlockly
Copy link
Copy Markdown

Summary

  • Bug 1 — dpnm-v2 template not registered: Added DpnmV2Template + 6 sub-impl contracts, the deploy-dpnm-v2-template.ts registration script, and ran it on BSC testnet. The template keccak256("dpnm-v2") is now registered on factory 0x713d03A5… with initSelector 0x3ba009a3 (tx 0x86443124f8d95c65b45d6e1c4cfaa43fccd3b071d35370bbf04aaf2d1ff2569b). Deployment artifact: deployment-dpnm-v2-template-bsc-testnet.json.
  • Bug 2 — treeRoot = deployer causes AlreadyPlaced: DPNMTree.initialize marks treeRoot as placed. When treeRoot == deployer, the deployer's activate() call hits AlreadyPlaced. Fixed both deploy-bsc-testnet.ts and deploy-dpnm-bsc-testnet.ts to default to 0x000000000000000000000000000000000000dEaD instead of deployer.address. Overridable via FLOW_TREE_ROOT / DPNM_TREE_ROOT env vars.
  • Bug 3 — encodedParams double-selector (guard): encodeInitializeParams already correctly uses encodeAbiParameters (raw args, no selector). LaunchpadFactory.launch prepends initSelector via bytes.concat. Added explicit warning comment in the encoder to prevent future regression from switching to encodeFunctionData.

Test plan

  • npx hardhat test test/factory/factory.test.js — factory integration still passes
  • npx hardhat test test/dpnm/template-v2.test.js — DpnmV2Template coverage passes
  • Verify on-chain: factory.templates(keccak256("dpnm-v2"))registered: true on BSC testnet
  • Deploy a tenant via the wizard — no TemplateMissing revert
  • New deployer activate() — no AlreadyPlaced revert (treeRoot is dead address)

Docs: see agentflow-code-docs/subsystems/dpnm-v2-template.mdx (companion PR pending)

🤖 Generated with Claude Code

lnlockly and others added 5 commits April 25, 2026 23:15
Add prep documentation for external audit (Code4rena/Sherlock/Spearbit):
- THREAT_MODEL.md (STRIDE coverage, 23 threats with impact/likelihood)
- INVARIANTS.md (24 invariants across accounting, curve, tree, migration, access)
- ATTACK_SCENARIOS.md (13 step-by-step attacks with mitigations + test refs)
- SCOPE.md (in/out of scope, ~3.7k SLOC, deployment plan, bounty scale)
- REPRODUCE.md (auditor reproduction guide: clone -> test -> deploy testnet)
- CHECKLIST.md (per-contract compliance: ReferralRegistry, Payouts, Bonding, Migrator)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…le closed system)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
$FLOW — closed-system MLM token modeled after dPNM, exclusive to AgentFlow
platform. 100% USDT-backed, no DEX graduation, supply expands on buy and
contracts on sell. Includes:

- contracts/flow/FlowToken.sol         — ERC20Permit, MINTER_ROLE-gated mint/burn
- contracts/flow/FlowGrowToken.sol     — GWT compensation token (1:1 vs USDT fees)
- contracts/flow/PhenomenalTree.sol    — 3-branch x 10-level placement tree
                                          with spillover and 10-level reward walk
- contracts/flow/FlowProtocol.sol      — orchestrator: activate, buy, sell,
                                          extendTree, buyIncomeLimitWithGWT, claimGWT
- contracts/flow/interfaces/*          — interface declarations
- script/deploy-flow-bsc-testnet.ts    — BSC testnet deploy script
- test/flow/flow.js                    — 24-test suite (activation, buy/sell, daily
                                          limit, income limit math, 10-level
                                          marketing payout, spillover, GWT, pause)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…Clonable pattern)

Phase 1 launchpad refactor. Introduces a single LaunchpadFactory that
clones registered templates via EIP-1167 minimal proxies. Both the
existing virtuals-style bonding-curve stack and the new dPNM-style
closed-system stack now deploy through the same entry point.

Architecture:
- LaunchpadFactory (UUPS, AccessControl) — one registry of templates
  keyed by bytes32 id. `launch(id, encodedParams, salt)` clones the
  registered implementation, low-level-calls its initSelector with the
  caller-supplied params, and emits Launched(id, instance, deployer).
- DpnmTemplate — orchestrator. On initialize, clones Flow + GWT + Tree
  + FlowProtocol implementations, wires inter-contract roles, hands
  DEFAULT_ADMIN to the supplied admin and renounces itself.
- VirtualsTemplate — orchestrator. On initialize, clones the
  FFactory + FRouter + Bonding trio, wires CREATOR / EXECUTOR / router
  roles, transfers Bonding ownership to admin.

Sub-contracts converted to Initializable (clonable) with
_disableInitializers in the constructor:
- contracts/flow/FlowToken.sol
- contracts/flow/FlowGrowToken.sol
- contracts/flow/PhenomenalTree.sol
- contracts/flow/FlowProtocol.sol
(Bonding/FFactory/FRouter were already Initializable upstream.)

Deploy script (script/deploy-bsc-testnet.ts) now stands up the factory,
registers both templates, then launches \$FLOW exclusively through
factory.launch("dpnm", ...). Future tokens (agentic memecoins,
AI-generated contracts) just register a new template — no factory or
script changes required.

Tests:
- test/factory/factory.test.js — 11 cases (registration, paused,
  unknown id, dpnm launch + activate/buy/sell, virtuals launch with
  wired roles, predictAddress, salt uniqueness, fee collection +
  underpayment revert).
- test/flow/flow.js — updated to use new Cloner helper for proxy
  deployment; all 24 cases still passing.

Helper:
- contracts/dev/Cloner.sol — exposes Clones.clone for tests / scripts
  that need to bypass the factory pipeline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…e-selector

Bug 1: register keccak256("dpnm-v2") template on factory (BSC testnet).
Added DpnmV2Template + 6 sub-impls + deploy-dpnm-v2-template.ts script.
Artifact: deployment-dpnm-v2-template-bsc-testnet.json (tx 0x8644…569b).

Bug 2: default treeRoot was deployer.address — DPNMTree marks it placed in
initialize(), so deployer's activate() call hit AlreadyPlaced. Changed both
deploy-bsc-testnet.ts and deploy-dpnm-bsc-testnet.ts to default to
0x000000000000000000000000000000000000dEaD. Override via FLOW_TREE_ROOT /
DPNM_TREE_ROOT env vars.

Bug 3 (encoder guard): encodeInitializeParams already uses encodeAbiParameters
(no selector) which is correct — LaunchpadFactory prepends initSelector via
bytes.concat. Added explicit warning comment to prevent future regression.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant