Skip to content

feat(deposit): send USDC on Injective on to dYdX automatically - #2148

Merged
jaredvu merged 1 commit into
mainfrom
kefan/injective-sponsored-deposits
Nov 30, 2026
Merged

jaredvu merged 1 commit into
mainfrom
kefan/injective-sponsored-deposits

Conversation

@Kefancao

Copy link
Copy Markdown
Contributor

Changes

Deposits are bridged to the user's Injective address, and until now the user was prompted ("Complete your deposit") to send them on to dYdX from InjectiveDepositDialog. This adds a lifecycle that does it for them.

  • New lifecycle injectiveBalanceSweepLifecycle: whenever the Injective address holds at least 1 USDC, it sends the whole balance to the dYdX address over IBC. Gas is paid by the sponsor unless the account holds enough INJ. It reuses getInjectiveBalances, requestGasSponsorship and sendInjectiveUsdcToDydx from feat(usdc-migration): re-enable deposits + support gas sponsorship #2132, so it does what the dialog's Continue button does. From the dYdX wallet the funds reach the trading account through the existing USDC rebalance lifecycle.
  • Prompt only when needed: the lifecycle publishes whether it is looking after the account (walletEphemeral.injectiveAutoSweepActive). The notification and the account-menu item are shown only while it is not:
    • Cosmos wallets, which would have to be asked to sign
    • restricted or view-only accounts (same gate as selectTxAuthorizedAccount)
    • after an attempt has failed. It is retried in the background after 30s, 1m, 2m, then every 5m, and the prompt goes away once the balance is gone.
  • Guards:
    • nothing is sent while a withdrawal is passing through the same Injective address (selectHasNonExpiredPendingWithdraws, evaluated on each poll since it depends on the time)
    • nothing is sent while the user has the dialog open to send the balance themselves
    • one transfer at a time, with a short cooldown after one so a lagging node's stale balance is not sent again
  • Faster pickup: the lifecycle shares the balance query with useInjectiveBalances (one poll for both), and the query is invalidated when a tracked deposit reaches Injective.
  • Copy: the deposit status screen and the deposit notification no longer tell auto-handled users to complete the deposit themselves. Hardcoded English, like the strings next to them.

InjectiveDepositDialog is unchanged and remains the manual fallback.

Testing

  • 31 new unit tests in injectiveBalanceSweepLifecycle.spec.ts covering the transfer, who is left to the prompt, the withdrawal and dialog guards, failure/retry, and account switches. tsc, eslint and the full suite (351 tests) pass.
  • The app boots with the lifecycle registered and no runtime errors.
  • Not tested: a real transfer from a signed-in account on Injective. Worth doing on staging before merge.

Known limitations

  • The withdrawal guard only sees withdrawals started in the same tab. A second tab on the same account could send a withdrawal's funds back to dYdX mid-flight: the funds stay with the user, but that withdrawal fails. The removed Noble sweep had the same gap.
  • Polling pauses while the tab is hidden, so a deposit made elsewhere is sent on when the user returns to the tab.

Issue

Related Issues (Optional)

Screenshots/Recordings (Optional)

Deposits are bridged to the user's Injective address, and until now the
user was prompted to send them on to dYdX from a dialog. A new lifecycle
does that for them: whenever the address holds at least 1 USDC, it sends
the balance to the dYdX address over IBC, with gas paid by the sponsor
unless the account holds enough INJ.

The prompt (notification and account menu) is only shown while the
lifecycle is not looking after the account: for Cosmos wallets, which
would have to be asked to sign, for restricted or view-only accounts,
and after an attempt has failed. Failed attempts are retried with a
growing delay.

Withdrawals leave through the same Injective address, so nothing is
sent while one is passing through, nor while the user has the dialog
open to send the balance themselves.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Kefancao
Kefancao requested a review from a team as a code owner November 30, 2026 18:47
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
v4-staging Ready Ready Preview Nov 30, 2026 6:50pm UTC
v4-testnet Ready Ready Preview Nov 30, 2026 6:50pm UTC

Request Review

@jaredvu
jaredvu merged commit 813c410 into main Nov 30, 2026
10 checks passed
@jaredvu
jaredvu deleted the kefan/injective-sponsored-deposits branch November 30, 2026 21:30

This branch was successfully deployed

2 active deployments
Preview – v4-staging — 26bc7d87 Deployed Nov 30, 2026 by vercel[bot]
Preview – v4-testnet — 26bc7d87 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants