# Backend

### ​[Supabase](https://supabase.com/)​ <a href="#supabase" id="supabase"></a>

**Trade Condition Storage:**&#x20;

* **Process:** When traders set up their trade conditions for automation, Splurge stores these details in a Supabase-managed database.
* **Security Measures:** For added security, traders sign off on the trade details with a unique, randomly generated salt to prevent replay attacks. Splurge saves this signature in Supabase, enabling us to execute trades on the trader's behalf.
* **Token Approval:** Traders must authorize their tokens for trading via the [Splurge Contract](https://arbiscan.io/address/0xe3345d0cca4c478cf16cdd0b7d7363ba223c87af#code).

**Access Security:**&#x20;

* **RLS Policy:** We implement a robust Row-Level Security (RLS) policy, ensuring traders can only access their own automation jobs.
* **JWT Validation:** This security is enforced by verifying a unique JWT (JSON Web Token) for each wallet, generated by Dynamic.
* **Privacy Assurance:** The only entities with access to your automation jobs are you, the trader, and Splurge.

### Automation Infrastructure <a href="#automation-infrastructure" id="automation-infrastructure"></a>

* **Functionality:** Splurge currently sources the best prices from various liquidity pools using GeckoTerminal. It then performs necessary calculations to determine if a trade's conditions are met.
* **Technology:** These processes are containerized using Docker and operate continuously on Google Cloud for prompt trade execution.
* **Future Improvements:** We aim to decentralize our Automation Infrastructure using ZK-Proofs. This will allow the evaluation of automation jobs to be distributed among various validators/nodes, enhancing security and reducing future costs.

### Automation Execution <a href="#automation-execution" id="automation-execution"></a>

* **Triggering Trades:** When trade conditions are met, our keeper bot is notified by the Automation Infrastructure.
* **Pre-Execution Check:** Tenderly simulates the trade to confirm its security and the expected outcome.
* **Execution:** The trade is executed through the [Splurge Smart Contract's](https://arbiscan.io/address/0xe3345d0cca4c478cf16cdd0b7d7363ba223c87af#code) `verifyExecuteTrade()` function.
* **Settlement and Delivery:** We utilize the [0x Protocol](https://0x.org/docs/developer-resources/contract-addresses) to settle trades at optimal rates across all liquidity pools. Post-settlement, the proceeds are directly sent to the trader.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://splurge-1.gitbook.io/splurgefi/system-architecture/backend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
