Skip to content

cli: auto-swap USDC → TOKEN bond during decdn setup via the live DEX pool (Uniswap V3 / Balancer V3) #991

Closed

Description

@alpergundogdu

Summary

Let node operators onboard holding only USDC: have decdn setup auto-swap USDC → TOKEN for exactly the capacity bond via the live TOKEN/USDC DEX pool, then bond. Today an operator must independently source TOKEN before setup can bond — a real friction wall, since TOKEN is an illiquid project token while USDC is trivially acquirable.

Feasible: yes. Most of the machinery already exists. The cleanest version needs no new on-chain contract.

Venue note (see #1000). The original plan assumed the protocol's Balancer V3 80/20 TOKEN/USDC pool. But Balancer V3 is not deployed on Arbitrum Sepolia (the initial testnet target per CLAUDE.md) — only Uniswap V3 is live there (factory 0x248AB79…, QuoterV2 0x2779a0…). So the swap step must be venue-neutral: route through Uniswap V3 on the testnet now, and switch to the Balancer V3 pool later once it lands on Arb Sepolia — exactly the rollout #1000 takes for the buyback burner. The shared dependency is the pool/venue, not any one router.

Why this is mostly already built

  • decdn setup --mbps N already computes the exact TOKEN needed. It reads the bond from the on-chain bondRequired(mbps) curve (bond = k × Mbps^α, defaults k=12.6, α=1.2) and bonds it — see crates/common/src/cli/setup.rs and crates/cli/src/commands/setup.rs, per ADR 019 Phase 2. So the "--declareMbps to know how much token people need" ask is already satisfied by --mbps — the swap target (bondRequired(mbps), plus a slippage buffer) is known before any tx is sent.
  • A TOKEN/USDC pool exists on whichever venue is live. The protocol's intended venue is a Balancer V3 80/20 TOKEN/USDC weighted pool (1% fee, Treasury-custodied) operated by BuybackBurnerBalancerV3 (ADR 018 liquidity strategy, contracts/src/BuybackBurnerBalancerV3.sol). On the Arb Sepolia testnet that pool does not yet exist; the live venue there is Uniswap V3 (see Make BuybackBurner venue-neutral and add BuybackBurnerUniswapV3 #1000). The CLI must target the venue that is actually deployed for the configured chain.

Proposed approach (recommended: CLI-orchestrated, no new contract)

Add an opt-in flag, e.g. decdn setup --mbps N --pay-bond-with usdc (name TBD). The CLI then, before bonding:

  1. Compute target = bondRequired(mbps) (already done) + a slippage buffer.
  2. Resolve the swap venue from chain config (Uniswap V3 on Arb Sepolia today; Balancer V3 where deployed). The venue selection should live in chain context (crates/cli/src/commands/chain_ctx.rs) alongside the existing token/router addresses, not be hard-coded to Balancer.
  3. USDC.approve(<router>, maxUsdcIn) (for Uniswap V3 SwapRouter02; the Balancer V3 Router path approves via Permit2, as BuybackBurnerBalancerV3 already does).
  4. Execute an exact-out swap so the operator receives precisely the bond amount and leftover USDC is refunded:
    • Uniswap V3: SwapRouter02.exactOutputSingle({tokenIn: USDC, tokenOut: TOKEN, fee, recipient, amountOut: target, amountInMaximum: maxUsdcIn, sqrtPriceLimitX96: 0}).
    • Balancer V3: Router.swapSingleTokenExactOut(pool, USDC→TOKEN, exactAmountOut=target, maxAmountIn, deadline, …).
  5. Proceed with the existing approve(CapacityBond) → bond → declareMbps → register flow.

This is fully self-custodial (operator signs every tx; no protocol funds at risk), reuses the live pool, and adds no governance/admin surface.

Why not reuse BuybackBurner: it's exact-in, keeper/governance-gated, and burns the TOKEN it buys — it can't deliver TOKEN to an operator's bond. The shared asset is the pool/venue, not the contract. (The venue-neutral burner refactor in #1000 is the on-chain analogue of the same "abstract the venue" move this CLI flow needs.)

Open design questions (call these out before implementation)

  • Venue abstraction. The swap step needs a small venue trait (exact_out(token_in, token_out, amount_out, max_in, …)) with Uniswap V3 and Balancer V3 implementations, selected by chain config. Keep parity with how Make BuybackBurner venue-neutral and add BuybackBurnerUniswapV3 #1000 abstracts the burner so both surfaces share one mental model. [your call] on whether to land Uniswap-only first and add Balancer behind the same trait later.
  • Slippage / MEV. Operator swaps need amountInMaximum (exact-out) + deadline, and should route through private RPC (Flashbots Protect / MEV-Share), consistent with the ADR 018 buyback policy. How is the slippage bound surfaced — preset, --max-slippage-bps, or governance-tunable band? [your call]
  • Pool depth at large tiers. Depth depends on the live venue (the Balancer seed is ~100M TOKEN / ~$250K USDC; the Uniswap V3 testnet pool seed is a separate operational parameter). Small tiers are negligible (10 Mbps ≈ 200 TOKEN), but big tiers move price hard against a thin pool: 1 Gbps ≈ 50K TOKEN, 10 Gbps ≈ 795K TOKEN. Auto-swap should likely be gated to small/entry tiers (or hard-fail above a price-impact threshold) and point larger operators at OTC/CEX. This also interacts with concurrent onboarding draining the pool. [your call]
  • ADR posture. ADR 019 frames setup as "thin orchestration … submits no transaction the primitives don't." A swap is a new primitive, so this needs an ADR 019 amendment (or a small new ADR) recording the swap step, the venue-neutral selection, slippage policy, and tier gating. Pairs with the existing operator-onboarding/bootstrap programs in ADR 026 § Bootstrap mechanism.
  • Failure atomicity. Swap and bond are separate txs; if bond fails after a successful swap the operator simply holds TOKEN — acceptable, but document it and make setup resumable.

Scope

  • In: opt-in decdn setup flag, venue-neutral CLI swap orchestration (Uniswap V3 SwapRouter02 on Arb Sepolia now, Balancer V3 Router where live), slippage/deadline/private-RPC handling, tier gating, ADR note.
  • Out: any new on-chain contract; production/testnet pool deployment + seeding (tracked under ADR 018 and Make BuybackBurner venue-neutral and add BuybackBurnerUniswapV3 #1000); changing the bond curve.

Pointers

Activity

  1. added
    kind:feature
    design:economics
    design:missing-decision
    prio:medium
    area:cli
    on Jun 25, 2026
  2. github-actions commented on Jun 25, 2026

    @github-actions

    🎯 Triage report

    A COLLABORATOR-authored UX enhancement to eliminate the TOKEN acquisition barrier during node onboarding by adding an opt-in --pay-bond-with usdc flag to decdn setup. The CLI would orchestrate a USDC→TOKEN swapSingleTokenExactOut on the protocol's live Balancer V3 80/20 pool before bonding — no new on-chain contracts, self-custodial, fully reversible. The proposal is well-scoped and references all existing machinery. Three open design decisions are explicitly flagged and must be resolved before implementation can safely begin.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature (unchanged) Opt-in extension to the decdn setup onboarding flow
    Labels unchanged enhancement, economics, technical, missing-decision, medium, cli already accurately applied; missing-decision is correct since the ADR amendment is explicitly unresolved
    Coding agent Needs more info Three explicit design decisions outstanding (slippage policy, tier-gate threshold, ADR posture) block a safe implementation start; requirements are clear once those are resolved

    🔗 Similar issues

    💡 Notes and suggestions

    Design decisions to resolve before assigning for implementation:

    1. Slippage / MEV parameter form. Three options:

      • --max-slippage-bps CLI flag with a hardcoded default (e.g., 150 bps = 1.5%) — simplest and consistent with self-custodial posture; recommended starting point
      • Read a governance-tunable on-chain param — adds upgrade path but needs a contract surface not currently planned
      • Fully preset (hardcoded constant) — simplest but inflexible for thin-pool conditions

      Private-RPC (Flashbots Protect / MEV-Share) should be opt-in via config, mirroring ADR 018 buyback policy.

    2. Tier-gate threshold. Based on issue's own numbers (pool seed ~100M TOKEN / ~$250K USDC):

      • 10 Mbps ≈ 200 TOKEN — negligible price impact, safe
      • 100 Mbps ≈ 2,600 TOKEN — low impact, likely safe
      • 1 Gbps ≈ 50K TOKEN — ~20% of pool USDC side, large impact
      • 10 Gbps ≈ 795K TOKEN — pool-draining, must hard-fail

      Suggested policy: simulate price impact before submitting (query pool reserves via Balancer V3 querySwapSingleTokenExactOut); fail with a clear message ("price impact X% exceeds threshold; use OTC/CEX for this tier") if above a configurable limit (e.g., 5%).

    3. ADR posture. ADR 019 is now implemented (Implement decdn setup — guided node onboarding wizard (ADR 019 Phases 1–2) #933 closed). A swap step is a new primitive beyond ADR 019's "thin orchestration over existing primitives" charter. A new ADR (next available: 040) recording swap step, slippage policy, tier-gate, and failure-atomicity posture is cleaner than amending 019, and avoids reopening a completed ADR.

    Implementation sub-tasks (post design-decision sign-off):

    • Write ADR 040 (swap-on-onboarding: slippage policy, tier gate, failure atomicity)
    • Add --pay-bond-with usdc flag + USDC balance preflight to crates/cli/src/commands/setup.rs
    • Implement swapSingleTokenExactOut call in crates/incentive/ or a new swap.rs module in cli
    • Add tier-gate: query querySwapSingleTokenExactOut for price-impact simulation before submitting
    • Add maxAmountIn + deadline calculation; plumb optional private-RPC config
    • Make setup resumable: on retry, if TOKEN balance ≥ bondRequired(mbps), skip swap and go straight to bond
    • Integration tests (testnet fork or mocked Balancer Router)

    Failure atomicity (already called out in issue): "swap done, bond reverted" leaves the operator holding TOKEN — acceptable. The resume path (detect sufficient TOKEN on retry, skip swap) is the correct fix; no rollback mechanism needed.

    Relevant reference: [Balancer V3 Router swapSingleTokenExactOut API]((docsv3.balancer.fi/redacted) — exact-out variant guarantees the operator receives precisely bondRequired(mbps) tokens, with leftover USDC refunded.

    Generated by Agentic Triage for issue #991 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. changed the title [-]cli: auto-swap USDC → TOKEN bond during `decdn setup` via the protocol's Balancer pool[/-] [+]cli: auto-swap USDC → TOKEN bond during `decdn setup` via the live DEX pool (Uniswap V3 / Balancer V3)[/+] on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:clidesign:economicsdesign:missing-decisionkind:featureprio:medium

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions