Skip to content

test: add end-to-end trading integration script#4

Open
juntao wants to merge 8 commits intomainfrom
test/e2e-trading-script
Open

test: add end-to-end trading integration script#4
juntao wants to merge 8 commits intomainfrom
test/e2e-trading-script

Conversation

@juntao
Copy link
Member

@juntao juntao commented Feb 26, 2026

Summary

  • Add tests/e2e_trading.sh — a bash script that exercises a full real-money trading workflow across Hyperliquid and Coinbase

Test flow

  1. Build fintool locally
  2. Deposit $10 USDC from Base mainnet → Hyperliquid (via Across bridge)
  3. Quote SILVER perp, buy $1 perp position
  4. Monitor SILVER price every 30s for up to 10 minutes
  5. Sell when price rises above entry (or on timeout)
  6. Withdraw USDC proceeds back to Base wallet
  7. Buy $1 ETH spot on Hyperliquid
  8. Withdraw ETH to Ethereum mainnet (via HyperUnit)
  9. Buy $1 TSLA on Coinbase

Prerequisites

  • ~/.fintool/config.toml with Hyperliquid wallet (>= $10 USDC on Base) and Coinbase API keys
  • jq installed

Test plan

  • bash -n tests/e2e_trading.sh — syntax check passes
  • Manual run with funded wallet

🤖 Generated with Claude Code

juntao and others added 8 commits February 25, 2026 18:19
Bash script that exercises a full trading workflow:
- Deposit USDC from Base → Hyperliquid
- Quote and buy SILVER perp, monitor price for up to 10 min
- Sell SILVER perp when price rises above entry (or on timeout)
- Withdraw USDC back to Base
- Buy ETH spot on Hyperliquid, withdraw to Ethereum mainnet
- Buy TSLA on Coinbase

Requires funded wallet with >= $10 USDC on Base and Coinbase keys.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add informative before/after messages for each step showing key JSON
response data — prices, funding rates, position sizes, PnL estimates,
bridge TX hashes, and color-coded price monitoring output.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace run_fintool() || true pattern that silently swallowed all errors.
New approach captures stdout/stderr/exit-code separately via temp files.
check_fail() helper prints the full error output (colored red) and calls
fail() whenever a command returns non-zero. Each step now:

- Gates on prior step success (e.g., skip sell if buy failed)
- Prints fintool's stderr progress messages in gray on success, red on failure
- Shows the exact error text from fintool on failure
- Tracks pass/fail counts accurately in the summary

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deposit is a prerequisite for all subsequent trading steps. Stop
immediately instead of continuing with steps that are guaranteed to fail.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Before executing the USDC bridge, check ETH balances on both the source
chain and Arbitrum. If Arbitrum has insufficient ETH for the final HL
Bridge2 deposit tx, automatically bridge 0.001 ETH from the source chain
via Across Protocol. Bail early with a clear error if the source chain
lacks enough ETH to cover gas + the ETH bridge amount.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use 0x0 as outputToken in the Across API to receive native ETH on
Arbitrum instead of WETH. This avoids the chicken-and-egg problem where
unwrapping WETH requires native ETH for gas but there is none.

Flow: wrap ETH→WETH on Base → Across bridge → native ETH on Arbitrum.

Also removes the WETH balance check and unwrap logic that is no longer
needed.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <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