|
| 1 | +--- |
| 2 | +id: use-stash |
| 3 | +title: Stash API quick start |
| 4 | +sidebar_position: 1 |
| 5 | +--- |
| 6 | + |
| 7 | +:::tip |
| 8 | +Request your Stash API key via [Sprinter Stash Request ](https://forms.gle/kgpcQK722Ley2gke7) or contacting [email protected] |
| 9 | +::: |
| 10 | + |
| 11 | +## As a Solver |
| 12 | + |
| 13 | +Sprinter Stash enables solvers to **borrow crosschain credit on-demand** to execute user intents without needing pre-funded inventory. |
| 14 | + |
| 15 | +This guide covers: |
| 16 | + |
| 17 | +1. Recap of the [Stash Fill Lifecycle](use-stash#1-stash-solver-fill-lifecycle) |
| 18 | +2. Requesting a [Credit Borrow Cost Estimate](use-stash#2-request-a-borrow-cost-estimate-optional) |
| 19 | +3. Requesting a [Final Borrow Quote and Credit Authorization](use-stash#3-request-a-final-borrow-quote) |
| 20 | +4. Check out the [Fill Optimization Tips](use-stash#4-fill-optimization-tips) |
| 21 | + |
| 22 | +### 1. Stash Fill Lifecycle |
| 23 | + |
| 24 | +<div style={{ display: "flex", justifyContent: "center" }}> |
| 25 | + |
| 26 | +```mermaid |
| 27 | +flowchart TD |
| 28 | + A[Solver Detects User Intent] --> B[2 - Solver Previews estimated borrowing cost of credit /request] |
| 29 | + B --> C[Receive Borrow Cost Estimate] |
| 30 | + C --> D{Fill using Stash Credit?} |
| 31 | + D -- Yes --> E[3 - Solver Reserves credit and authorize the fill] |
| 32 | + D -- No --> F[Abort Fill] |
| 33 | + E --> G[Solver Borrow Liquidity from Sprinter Stash] |
| 34 | + G --> H[Stash Executes Cross-Chain Swap/Bridge Execution /quote] |
| 35 | + H --> I[Intent Protocol Repays Borrowed Credit + Costs] |
| 36 | + I --> J[Fill Complete] |
| 37 | +
|
| 38 | +click B "use-stash#2-request-a-borrow-cost-estimate-optional" "Borrow Cost" |
| 39 | +style B fill:#FF9B43,stroke:#333,stroke-width:2px,color:#000,font-weight:bold |
| 40 | +
|
| 41 | +click E "use-stash#3-request-a-final-borrow-quote" "Borrow Quote" |
| 42 | +style E fill:#FF9B43,stroke:#333,stroke-width:2px,color:#000,font-weight:bold |
| 43 | +
|
| 44 | +``` |
| 45 | + |
| 46 | +</div> |
| 47 | + |
| 48 | +### 2. Request a Credit Borrow Cost Estimate (Optional) |
| 49 | + |
| 50 | +Call the [**Borrow Cost API**](borrow-cost-api) to preview an estimated borrowing cost for a potential fill before requesting credit. |
| 51 | + |
| 52 | +```ts title="Fetch Borrow Cost Estimate Example Payload" |
| 53 | +const baseUrl = "https://api.sprinter.tech"; |
| 54 | +const destChainId = "eip155:8453"; // eip155:8453(Base), eip155:10 (Optimism), eip155:42161 (Arbitrum) destChainId must use capid format from our configuration |
| 55 | +const protocol = "across"; // "across" or "mayan" |
| 56 | +const txHash = "string"; // Source chain deposit TX |
| 57 | +const response = await fetch( |
| 58 | + `${baseUrl}/liquidity/chain/${destChainId}/protocol/${protocol}/deposit/${txHash}/requests`, |
| 59 | + { |
| 60 | + method: "GET", |
| 61 | + headers: { |
| 62 | + "X-Auth-Token": "<your_api_key>", |
| 63 | + }, |
| 64 | + body: { |
| 65 | + input: callData, // encoded callData of deposit |
| 66 | + caller: "address", // the address that will execute the borrow and fill ond destChainId |
| 67 | + }, |
| 68 | + }, |
| 69 | +); |
| 70 | +``` |
| 71 | + |
| 72 | +### 3. Request a Final Borrow Quote |
| 73 | + |
| 74 | +If proceeding to fill with Sprinter Stash, call the [**Borrow Quote API**](borrow-quote-api) to request a borrow quote to reserve credit and authorize the fill. This can be based on input or output amount. |
| 75 | + |
| 76 | +```ts title="Request Final Borrow Quote with type ExactInput (input amount - borrow costs)" |
| 77 | +const baseUrl = "https://api.sprinter.tech"; |
| 78 | +const sourceChainId = "eip155:8453"; // eip155:8453(Base), eip155:10 (Optimism), eip155:42161 (Arbitrum). ChainId must use capid format from our configuration |
| 79 | +const protocol = "across"; // "across" or "mayan" |
| 80 | +const type = "ExactInput"; // Request will consider the amount as (input amount - borrow costs) |
| 81 | +const amount = 10000000; // This is the ExactInput eg 1 USDC (6 decimals) |
| 82 | +const response = await fetch( |
| 83 | + `${baseUrl}/liquidity/chain/${sourceChainId}/protocol/${protocol}/type/${type}/quote`, |
| 84 | + { |
| 85 | + method: "GET", |
| 86 | + headers: { |
| 87 | + "X-Auth-Token": "<your_api_key>", |
| 88 | + }, |
| 89 | + body: { |
| 90 | + amount: amount, |
| 91 | + token: "destination_token_address", // Token address |
| 92 | + network: "eip155:10", // Destination_Chain_ID |
| 93 | + }, |
| 94 | + }, |
| 95 | +); |
| 96 | + |
| 97 | +const borrowQuote = await response.json(); |
| 98 | +console.log("Expected amount:", borrowQuote.expectedOutput); |
| 99 | +console.log("Borrow Cost:", borrowQuote.borrowCost); |
| 100 | +``` |
| 101 | + |
| 102 | +```ts title="Request Final Borrow Quote with type ExactOutput (output amount + borrow costs)" |
| 103 | +const baseUrl = "https://api.sprinter.tech"; |
| 104 | +const sourceChainId = "eip155:8453"; // eip155:8453(Base), eip155:10 (Optimism), eip155:42161 (Arbitrum). ChainId must use capid format from our configuration |
| 105 | +const protocol = "across"; // "across" or "mayan" |
| 106 | +const type = "ExactOutput"; // Request will consider the amount as (output amount + borrow costs) |
| 107 | +const amount = 10000000; // This is the ExactInput eg 1 USDC (6 decimals) |
| 108 | +const response = await fetch( |
| 109 | + `${baseUrl}/liquidity/chain/${sourceChainId}/protocol/${protocol}/type/${type}/quote`, |
| 110 | + { |
| 111 | + method: "GET", |
| 112 | + headers: { |
| 113 | + "X-Auth-Token": "<your_api_key>", |
| 114 | + }, |
| 115 | + body: { |
| 116 | + amount: amount, |
| 117 | + token: "destination_token_address", // Token address |
| 118 | + network: "eip155:10", // Destination_Chiain_ID |
| 119 | + }, |
| 120 | + }, |
| 121 | +); |
| 122 | + |
| 123 | +const borrowQuote = await response.json(); |
| 124 | +console.log("Expected Input:", borrowQuote.requiredInput); |
| 125 | +console.log("Borrow Cost:", borrowQuote.borrowCost); |
| 126 | +``` |
| 127 | + |
| 128 | +### 4. Fill Optimization Tips |
| 129 | + |
| 130 | +Here are some tips on getting the best performance and profit from your Sprinter Stash integration: |
| 131 | + |
| 132 | +1. **Pre-fetch Borrow Cost** - Call `GET /type/{type}/quote` as early as possible (when detecting intents) to evaluate solver profitability. |
| 133 | + |
| 134 | +2. **Batch Gas Where Possible** - Bundle execution and repayment transactions to reduce gas costs. |
| 135 | + |
| 136 | +3. **Optimize for Slippage** - Query quotes close to execution time to reduce stale pricing or slippage-induced fills. |
| 137 | + |
| 138 | +4. **Handling Rate Limits ** - If you hit 429s, give it a moment and retry using retry_after value. You can request higher limits via [email protected]. |
| 139 | + |
| 140 | +5. **Validate Transaction Hash Early** - Ensure the user intent transaction is final and not reverted before calling `/deposit/{txHash}/request`. |
0 commit comments