Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "drift-gateway"
version = "1.5.1"
version = "1.5.2"
edition = "2021"

[dependencies]
actix-web = "*"
argh = "*"
drift-rs = { git = "https://github.com/drift-labs/drift-rs", rev = "975d81f" }
drift-rs = { git = "https://github.com/drift-labs/drift-rs", rev = "6d2d6e0" }
env_logger = "*"
futures-util = "*"
log = "*"
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ Error (400/500):
```

**Example**:
USDC to
USDC to SOL
```bash
curl -X POST "http://localhost:8080/v2/swap" \
-H "Content-Type: application/json" \
Expand Down Expand Up @@ -934,6 +934,32 @@ settled funding payment event for open perp positions
}
```

**jupiter swap**
denotes a subaccount swapped some amount of token (in) for another token (out)

- `amountIn`: token amount sent at swap start
- `marketIn`: market index of token sent
- `amountOut`: token amount received at swap end
- `marketOut`: market index of token received

```json
{
"data": {
"swap": {
"amountIn": "2.000000",
"amountOut": "0.013732454",
"marketIn": 0,
"marketOut": 1,
"ts": 1746418907,
"txIdx": 104,
"signature": "2mwW6gbPNWzgUWqVCJKCM55HWCTDG5iZUwjU1wVLdKgBzQz7yQj4ZsePQEpsECdcXJ1mJCGVHEvzCVf9mbhHnN7u"
}
},
"channel": "swap",
"subAccountId": 0
}
```

### Errors

error responses have the following JSON structure:
Expand Down
45 changes: 41 additions & 4 deletions src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub(crate) enum Channel {
Fills,
Orders,
Funding,
Swap,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -294,6 +295,16 @@ pub(crate) enum AccountEvent {
signature: String,
tx_idx: usize,
},
#[serde(rename_all = "camelCase")]
Swap {
amount_in: Decimal,
amount_out: Decimal,
market_in: u16,
market_out: u16,
ts: u64,
tx_idx: usize,
signature: String,
},
}

impl AccountEvent {
Expand Down Expand Up @@ -582,7 +593,7 @@ pub(crate) fn map_drift_event_for_account(
Some(AccountEvent::OrderCancel {
order_id: *order_id,
ts: *ts,
signature: signature.to_string(),
signature: signature.clone(),
tx_idx: *tx_idx,
}),
)
Expand All @@ -596,7 +607,7 @@ pub(crate) fn map_drift_event_for_account(
Some(AccountEvent::OrderCancelMissing {
user_order_id: *user_order_id,
order_id: *order_id,
signature: signature.to_string(),
signature: signature.clone(),
}),
),
DriftEvent::OrderExpire {
Expand Down Expand Up @@ -630,7 +641,7 @@ pub(crate) fn map_drift_event_for_account(
Some(AccountEvent::OrderCreate {
order: OrderWithDecimals::from_order(*order, decimals),
ts: *ts,
signature: signature.to_string(),
signature: signature.clone(),
tx_idx: *tx_idx,
}),
)
Expand All @@ -648,9 +659,35 @@ pub(crate) fn map_drift_event_for_account(
amount: Decimal::new(*amount, PRICE_DECIMALS).normalize(),
market_index: *market_index,
ts: *ts,
signature: signature.to_string(),
signature: signature.clone(),
tx_idx: *tx_idx,
}),
),
DriftEvent::Swap {
user,
amount_in,
amount_out,
market_in,
market_out,
fee,
ts,
signature,
tx_idx,
} => {
let decimals_in = get_market_decimals(program_data, Market::spot(*market_in));
let decimals_out = get_market_decimals(program_data, Market::spot(*market_out));
(
Channel::Swap,
Some(AccountEvent::Swap {
amount_in: Decimal::new(*amount_in as i64, decimals_in),
amount_out: Decimal::new(*amount_out as i64, decimals_out),
market_in: *market_in,
market_out: *market_out,
ts: *ts,
tx_idx: *tx_idx,
signature: signature.clone(),
}),
)
}
}
}
Loading