Skip to content

Add Base rebalancer flow#1184

Open
gianfra-t wants to merge 39 commits into
stagingfrom
add-base-rebalancer-flow
Open

Add Base rebalancer flow#1184
gianfra-t wants to merge 39 commits into
stagingfrom
add-base-rebalancer-flow

Conversation

@gianfra-t

@gianfra-t gianfra-t commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

About

Rebalancer now checks by default the Base Nabla instance, for USDC -> BRLA rebalances.

If not specified otherwise, the flow compares between:

  • Swapping with Avenia internally.
  • Rebalancing using Squidrouter's selected pool for USDC -> BRLA on Polygon.
  • Rebalancing using the "main" nabla DEX (Router: 0x58E5Cb2dA15f01CB8FAefef202aa25238efCBdcf).

This PR also adds rebalancing logic for the other direction, BRLA -> USDC. Only with the main nabla DEX path is included for now.

New commands and flags

--route=avenia or --route=squidrouter forces the path to one or the other regardless of the rate comparison.

New env variables

@gianfra-t gianfra-t changed the title Add Base rebalancer flow [Testing] Add Base rebalancer flow Jun 1, 2026
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit 728ec84
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6a3187a3149dae0008c44ad7
😎 Deploy Preview https://deploy-preview-1184--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for vortex-sandbox failed. Why did it fail? →

Name Link
🔨 Latest commit 728ec84
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6a3187a3e33200000a5fa43d

Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Fixed
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Fixed
Comment thread apps/rebalancer/src/utils/config.ts Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “USDC → BRLA → USDC” rebalancing flow targeting the Base Nabla instance by default, with optional routing via Avenia vs SquidRouter and resumable state persisted in Supabase storage.

Changes:

  • Extend BRLA shared quote types/service to support specifying outputPaymentMethod for onchain swap quotes (e.g. Base).
  • Introduce a new Base rebalancing flow (steps + orchestrator) and Base coverage-ratio check used by default (legacy flow preserved behind --legacy).
  • Add shared Supabase-backed state manager abstraction and a simple EVM nonce manager for sequential tx submission.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/shared/src/services/brla/types.ts Extends onchain swap quote params to optionally specify output payment method.
packages/shared/src/services/brla/brlaApiService.ts Uses optional output payment method when building onchain swap quote requests.
apps/rebalancer/src/utils/nonce.ts Adds a nonce manager to issue sequential nonces for EVM transactions.
apps/rebalancer/src/utils/config.ts Consolidates EVM executor secret usage and adds Base EVM client getter.
apps/rebalancer/src/services/stateManager.ts Refactors state persistence into a reusable Supabase storage state manager; adds state for Base flow.
apps/rebalancer/src/services/indexer/index.ts Adds Base Nabla BRLA pool coverage-ratio read via onchain calls.
apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Implements Base rebalance step functions (Nabla swap, Avenia transfer/swap, Squid route swap).
apps/rebalancer/src/rebalance/usdc-brla-usdc-base/index.ts Orchestrates the new Base flow with resumability and optional forced routing.
apps/rebalancer/src/rebalance/brla-to-axlusdc/index.ts Updates legacy flow to use the renamed state manager and phase order constants.
apps/rebalancer/src/index.ts Switches default run path to Base flow; adds --legacy and --route=... flags.
apps/rebalancer/README.md Updates env var documentation for the new consolidated EVM secret and legacy-only Pendulum secret.
apps/rebalancer/.env.example Updates example env vars for the new consolidated EVM secret and legacy-only Pendulum secret.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/rebalancer/src/utils/nonce.ts
Comment thread apps/rebalancer/src/services/stateManager.ts Outdated
Comment thread apps/rebalancer/src/services/indexer/index.ts
Comment thread apps/rebalancer/src/utils/config.ts
Comment thread apps/rebalancer/src/utils/config.ts
Comment thread apps/rebalancer/src/utils/config.ts
Comment thread apps/rebalancer/src/utils/config.ts
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Outdated
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/index.ts Outdated
Comment thread packages/shared/src/services/brla/brlaApiService.ts
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Fixed
gianfra-t and others added 5 commits June 2, 2026 13:41
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…tion or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…tion or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Fixed
@gianfra-t gianfra-t changed the title [Testing] Add Base rebalancer flow Add Base rebalancer flow Jun 2, 2026
@gianfra-t gianfra-t requested a review from a team June 2, 2026 19:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Comment thread apps/rebalancer/src/index.ts Outdated
Comment thread apps/rebalancer/src/services/indexer/index.ts
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Outdated
Comment thread apps/rebalancer/README.md
Comment thread apps/rebalancer/.env.example
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
gianfra-t and others added 5 commits June 3, 2026 13:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/index.ts Fixed
gianfra-t and others added 4 commits June 4, 2026 16:29
…tion or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Comment thread apps/rebalancer/src/index.ts Fixed
Comment thread apps/rebalancer/src/rebalance/brla-to-usdc-base/steps.ts Fixed
Comment thread apps/rebalancer/src/rebalance/usdc-brla-usdc-base/steps.ts Fixed

@ebma ebma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some parts could be cleaner or refactored, like duplicate imports of the USDC token contract, or the ABI functions but it's also fine with me to leave as is since it's just the rebalancer. @gianfra-t what about the code-quality comments from the bot?

return balance.toString();
}

import { checkInitialUsdcBalanceOnBase } from "../usdc-brla-usdc-base/steps.ts";
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.

3 participants