← 3Commas

3Commas · DeCommas

DeFi Crosschain strategies

Client: DeCommas and 3Commas

Deposit one stablecoin on one chain; get exposure to actively-managed DeFi strategies that run across many EVM chains — coordinated over LayerZero, funded over Stargate.

github.com/danielles0xG/defi-evm-cross-chain-strategies-LZ-Stargate ↗

Stack & integrations

  • Solidity ^0.8.12
  • LayerZero
  • Stargate
  • Perpetual Protocol
  • GMX / GLP
  • Aave
  • Uniswap V3
  • ERC-1967 proxies (UUPS)
  • Hardhat
  • Foundry
  • GitLab CI
  • Codecov

Context

3Commas — a crypto trading-tools company — launched DeCommas, a decentralized toolset for on-chain traders. This workstream is its cross-chain DeFi strategy engine. A user deposits a single stablecoin and receives a share in a strategy — a professionally-composed basket of DeFi positions (perps, GLP, lending, swaps) that can span several EVM chains at once (Optimism, Arbitrum, BSC, Polygon, Avalanche). The user sees one deposit and one balance; all the cross-chain plumbing is abstracted away.

What it does — the product

Running a multi-chain DeFi strategy by hand means bridging funds, holding gas on every chain, opening positions on each protocol, rebalancing, then unwinding to exit. The product collapses that into deposit stablecoin → hold a share → withdraw stablecoin. Deposits and withdrawals are queued and settled in batches (fair, gas-efficient pricing); the share is an internal claim on the strategy’s cross-chain value.

Product journey: deposit USDC → shares issued → operator bridges and opens positions → strategy runs across chains → request withdraw → receive USDC
The user-facing journey — everything between “deposit” and “withdraw” is automated

Architecture — two independent planes

The system separates instructions from money. A control plane (LayerZero generic messaging) carries commands — “run this action on that contract, on that chain” — while a value plane (Stargate) moves the stablecoin liquidity. A trusted off-chain relayer orchestrates both through a single command hub (ActionPool); the on-chain contracts are deliberately minimal executors that hold funds and expose actions, but never decide when or how much.

Two-plane architecture: relayer drives the ActionPool command hub; LayerZero carries control to the router, factory, registry and building blocks; Stargate carries USDC from the router to the building blocks
Blue = LayerZero control plane · green = Stargate value plane (data-flow arrows animate)

The control plane — a remote-command pattern

Every contract receives cross-chain messages through one funnel. The delivered payload is ABI-encoded calldata for a function on the receiving contract itself; because the contract calls itself, a cross-chain instruction becomes a local self-call that satisfies the onlySelf guard on every privileged action. Inbound messages are gated by LayerZero’s trusted-remote check, so only the command hub can drive them.

Money flows — queued deposits & withdrawals

Both entry and exit are queued and batch-settled, using monotonic head/tail cursors for ordered, replay-safe processing.

  • Deposit: a user deposits USDC into the router, which enqueues a ticket. The relayer batch-settles — crediting each user’s shares against the strategy’s reported value, bridging the pooled capital to the building blocks over Stargate, then commanding each block to deploy it.
  • Withdrawal: a request is queued; the relayer unwinds the remote position, bridges the proceeds back, and the router pays out in strict FIFO order — burning the user’s shares against the redemption.
Deposit flow: deposit USDC to the router → enqueued → relayer processes deposits over LayerZero → shares credited and USDC bridged via Stargate → building block deploys the capital
Deposit flow — enqueue, batch-settle, bridge, deploy
Withdrawal flow: initiate withdraw registers a request → relayer unwinds the position and bridges proceeds back over Stargate → approveWithdraw burns shares and pays USDC to the user
Withdrawal flow — request, remote unwind, bridge back, FIFO payout

Building blocks — the strategy legs

Each strategy is composed from reusable, upgradeable building blocks — one per protocol: a Perpetuals vault (delta-neutral shorts/longs), a GMX / GLP vault, an Aave lending vault, and a Uniswap v3 swapper. Blocks are deployed as ERC-1967 proxies by a per-chain factory and indexed in a cross-chain registry — so a strategy is assembled by wiring blocks together rather than writing new contracts.

Testing & delivery

Delivered with unit and cross-chain integration test suites (Hardhat + Foundry) — mock LayerZero endpoints and Stargate bridges exercise the full deposit → bridge → deploy → unwind → withdraw path — with CI/CD coverage (GitLab CI, Codecov).

My contribution

Designed and developed the strategy core contracts for cross-chain swaps on Optimism, Arbitrum, and BSC on top of LayerZero (Stargate): the ActionPool command hub, the user-facing router with its deposit/withdrawal queues and share ledger, the per-chain building-block factory and cross-chain registry, and the protocol building blocks integrating Perpetual Protocol, GMX, Aave, and Uniswap v3. Authored the LayerZero “remote command” receive pattern and the two-plane (control / value) design, and delivered the unit + cross-chain integration test suites with CI/CD coverage.