This server provides backend services for the Vortex application, including:
- Signature services for ephemeral accounts
- On-ramping and off-ramping flows
- Quote generation and management
- Transaction state management
The service now includes a unified API for on-ramping and off-ramping flows, with state persistence in PostgreSQL.
The service requires PostgreSQL. Set up a database and configure the connection in your .env file:
# Create a PostgreSQL database
createdb vortex
# Configure environment variables (see .env.example)
cp .env.example .env
# Edit .env with your database credentialsMake sure you have the required environment variables set, either in a .env file or in the environment.
# Install dependencies
yarn install
# Run migrations
yarn migrate
# Seed phase metadata
yarn seed:phase-metadata
# For production
yarn start
# For development
yarn devPOST /v1/ramp/quotes- Create a new quoteGET /v1/ramp/quotes/:id- Get quote information
POST /v1/ramp/start- Start a new ramping processGET /v1/ramp/:id- Get the status of a ramping processPATCH /v1/ramp/:id/phase- Advance a ramping process to the next phasePATCH /v1/ramp/:id/state- Update the state of a ramping processPATCH /v1/ramp/:id/subsidy- Update subsidy detailsPATCH /v1/ramp/:id/nonce- Update nonce sequencesPOST /v1/ramp/:id/error- Log an errorGET /v1/ramp/:id/history- Get phase historyGET /v1/ramp/:id/errors- Get error logsGET /v1/ramp/phases/:phase/transitions- Get valid transitions for a phase
POST /v1/stellar/create- Get signature for account creationPOST /v1/stellar/payment- Get signatures for payment and merge operations
The service now implements a state machine pattern for ramping flows:
- Phase Transitions: Each phase has defined valid transitions to other phases
- Phase History: All phase transitions are logged with timestamps
- Error Logging: Errors are logged with phase information
- Subsidy Management: Subsidy details are tracked throughout the flow
- Nonce Sequence Management: Transaction nonce sequences are managed
Phase metadata is stored in the database and includes:
- Required transactions for each phase
- Success conditions
- Retry policies
- Valid transitions
To update phase metadata, modify the seeder file and run:
yarn seed:phase-metadataFUNDING_SECRET: Secret key to sign the funding transactions on Stellar.PENDULUM_FUNDING_SEED: Seed phrase to sign the funding transactions on Pendulum.MOONBEAM_EXECUTOR_PRIVATE_KEY: Private key to sign the transactions on Moonbeam.CLIENT_DOMAIN_SECRET: Secret for client domain verification.
DB_HOST: PostgreSQL host (default: localhost)DB_PORT: PostgreSQL port (default: 5432)DB_USERNAME: PostgreSQL username (default: postgres)DB_PASSWORD: PostgreSQL password (default: postgres)DB_NAME: PostgreSQL database name (default: vortex)
NODE_ENV: The environment the application is running in (default: production)PORT: The port the HTTP server will listen on (default: 3000)GOOGLE_SERVICE_ACCOUNT_EMAIL: Google service account email.GOOGLE_PRIVATE_KEY: Google private key.GOOGLE_SPREADSHEET_ID: Google spreadsheet ID for data storage.GOOGLE_EMAIL_SPREADSHEET_ID: Google spreadsheet ID for emails.GOOGLE_RATING_SPREADSHEET_ID: Google spreadsheet ID for ratings.RATE_LIMIT_MAX_REQUESTS: Maximum number of requests per IP address (default: 100)RATE_LIMIT_WINDOW_MINUTES: Time window in minutes for the rate limit (default: 1)RATE_LIMIT_NUMBER_OF_PROXIES: Number of proxies between server and user (default: 1)
There are two test/scripts that can help with testing a flow of interest, by-passing some of the external services and checks, and focusing on the phase executions alone.
These are phase-processor.integration.test.ts and phase-processor.recovery.integration.test.ts
These tests will fetch a quote, and attempt to register and start a ramp by signing and sending the funds from a testing account, which simulates the actions of the UI and the user.
It is important to keep in mind that both BRLA subaccount and ramp interactions are mocked. Similarly, Stellar interactions with anchors is skipped and an account is chosen as the anchor's target, to recover the funds.
To test, please run bun test phase-processor.integration.test.ts --timeuout X where X is a reasonable timeframe for
the phases to complete. Note: all the environment variables used to run the service MUST be provided, with the addition
of BACKEND_TEST_STARTER_ACCOUNT, the account simulates the user.
The state of the ramp is stored in lastRampState.json, which mocks the database. In the event of a failure, copy the
state into failedRampStateRecovery.json and run bun test phase-processor.recovery.integration.test.ts --timeout X to
simply restart the flow from the last phase. This is useful to test fixes or bugs.