diff --git a/Cargo.lock b/Cargo.lock index f14e0cf..ac67bc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1582,7 +1582,7 @@ dependencies = [ [[package]] name = "drift-gateway" -version = "1.5.1" +version = "1.5.2" dependencies = [ "actix-web", "argh", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "drift-idl-gen" version = "0.2.0" -source = "git+https://github.com/drift-labs/drift-rs?rev=975d81f#975d81f7f6ec693cca0211a2045f0fa1296d4a03" +source = "git+https://github.com/drift-labs/drift-rs?rev=6d2d6e0#6d2d6e077c9dd23365da6e90d0d2ad920992eb1a" dependencies = [ "proc-macro2", "quote", @@ -1618,7 +1618,7 @@ dependencies = [ [[package]] name = "drift-pubsub-client" version = "0.1.1" -source = "git+https://github.com/drift-labs/drift-rs?rev=975d81f#975d81f7f6ec693cca0211a2045f0fa1296d4a03" +source = "git+https://github.com/drift-labs/drift-rs?rev=6d2d6e0#6d2d6e077c9dd23365da6e90d0d2ad920992eb1a" dependencies = [ "futures-util", "gjson", @@ -1638,7 +1638,7 @@ dependencies = [ [[package]] name = "drift-rs" version = "1.0.0-alpha.15" -source = "git+https://github.com/drift-labs/drift-rs?rev=975d81f#975d81f7f6ec693cca0211a2045f0fa1296d4a03" +source = "git+https://github.com/drift-labs/drift-rs?rev=6d2d6e0#6d2d6e077c9dd23365da6e90d0d2ad920992eb1a" dependencies = [ "abi_stable", "ahash 0.8.11", @@ -7489,8 +7489,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-client" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7504e16bd8edc6af4ba11be0b42fba24ffb42b383b1373c5d26dc644a327070a" +source = "git+https://github.com/rpcpool/yellowstone-grpc?rev=bb3a44a#bb3a44a2f723fb1885eb70a1d1efcab44e8ac32f" dependencies = [ "bytes", "futures", @@ -7503,8 +7502,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-proto" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a19211525073ab3811f57f30056633011f836fd61781a1f3b24ed4404a4c214" +source = "git+https://github.com/rpcpool/yellowstone-grpc?rev=bb3a44a#bb3a44a2f723fb1885eb70a1d1efcab44e8ac32f" dependencies = [ "anyhow", "bincode", diff --git a/Cargo.toml b/Cargo.toml index aaed0c0..e80e21e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "*" diff --git a/README.md b/README.md index d565b6e..6d83d5e 100644 --- a/README.md +++ b/README.md @@ -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" \ @@ -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: diff --git a/src/websocket.rs b/src/websocket.rs index d7d0872..1cf95e1 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -212,6 +212,7 @@ pub(crate) enum Channel { Fills, Orders, Funding, + Swap, } #[derive(Deserialize, Debug)] @@ -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 { @@ -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, }), ) @@ -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 { @@ -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, }), ) @@ -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(), + }), + ) + } } }