Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add endpoint to get AccountEvents from tx sig #36

Merged
merged 7 commits into from
Feb 26, 2024
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
11 changes: 7 additions & 4 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
actix-web = "4.4.0"
argh = "0.1.12"
drift-sdk = { git = "https://github.com/circuit-research/protocol-v2", branch = "cargo-add-sdk" }
drift-sdk = { git = "https://github.com/drift-labs/drift-rs", branch = "main" }
env_logger = "0.10.1"
futures-util = "0.3.29"
log = "0.4.20"
Expand All @@ -16,3 +16,6 @@ serde_json = "*"
tokio = "*"
tokio-tungstenite = "*"
thiserror = "1.0.38"
solana-client = "1.14"
solana-sdk = "1.14"
solana-transaction-status = "1.14"
73 changes: 61 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ Positional Arguments:
rpc_host the solana RPC URL

Options:
--dev run in devnet mode
--host gateway host address
--port gateway port
--ws-port gateway Ws port
--delegate use delegated signing mode, provide the delegators pubkey
--emulate run the gateway in read-only mode for given authority pubkey
--tx-commitment solana commitment level to use for transaction confirmation [processed|confirmed|finalized]
(default: confirmed)
--commitment solana commitment level to use for state updates (default:
confirmed) [processed|confirmed|finalized]
--verbose enable debug logging
--dev run in devnet mode
--host gateway host address
--port gateway port
--ws-port gateway Ws port
--delegate use delegated signing mode, provide the delegators pubkey
--emulate run the gateway in read-only mode for given authority pubkey
--tx-commitment solana commitment level for transaction confirmation [processed|confirmed|finalized] (default: confirmed)
--commitment solana commitment level for state updates [processed|confirmed|finalized] (default: confirmed)
--default-sub-account-id default sub-account ID for account related operations (default: 0)
--verbose enable debug logging
```

## API Examples
Expand Down Expand Up @@ -237,6 +236,56 @@ $ curl localhost:8080/v2/positionInfo/0
}
```

### Get Transaction Events
gets the transaction and parses events relevant to the provided user `subAccountId` (default will be used otherwise). Only events relevant to
the provided user will be returned.


```bash
# get events from tx hash 5JuobpnzPzwgdha4d7FpUHpvkinhyXCJhnPPkwRkdAJ1REnsJPK82q7C3vcMC4BhCQiABR4wfdbaa9StMDkCd9y5 for my subAccountId 0
$ curl localhost:8080/v2/transactionEvent/5JuobpnzPzwgdha4d7FpUHpvkinhyXCJhnPPkwRkdAJ1REnsJPK82q7C3vcMC4BhCQiABR4wfdbaa9StMDkCd9y5?subAccountId=0
```

**Response**

A response with a fill belonging to sub-account 0
```json
{
"events": [
{
"fill": {
"side": "buy",
"fee": "0.129744",
"amount": "5",
"price": "103.7945822",
"oraclePrice": "102.386992",
"orderId": 436,
"marketIndex": 0,
"marketType": "perp",
"ts": 1708684880,
"signature": "5JuobpnzPzwgdha4d7FpUHpvkinhyXCJhnPPkwRkdAJ1REnsJPK82q7C3vcMC4BhCQiABR4wfdbaa9StMDkCd9y5"
}
}
]
}
```

A response for a transaction not found. You should consider this transaction as dropped after around 5 seconds.
```json
{
"code": 404,
"reason": "tx not found: 4Mi32iRCqo2XXPjnV4bywyBpommVmbm5AN4wqbkgGFwDM3bTz6xjNfaomAnGJNFxicoMjX5x3D1b3DGW9xwkY7ms"
}
```

A response for a transaction that was found, but doesn't contain any events for the user
```json
{
"events": []
}
```


### Place Orders

- use sub-zero `amount` to indicate sell/offer order
Expand Down Expand Up @@ -528,7 +577,7 @@ Use the drift UI or Ts/Python SDK to assign a delegator key.
see [Delegated Accounts](https://docs.drift.trade/delegated-accounts) for more information.

## Sub-account Switching
By default the gateway uses the drift sub-account (index 0)
By default the gateway will perform all account operations on sub-account 0, you can overwrite this default by setting the `--default-sub-account-id` flag on startup.

A `subAccountId` URL query parameter may be supplied to switch the sub-account per request basis.

Expand Down
21 changes: 21 additions & 0 deletions development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Rust version

`rustup default 1.73.0-x86_64-apple-darwin` works. Need >=1.73.0 for `bumpalo v3.15.3`


# Tests

Tests expect the `DRIFT_GATEWAY_KEY` environment variable to be set, and that
key must have a valid Drift account on devnet.

Devnet fauct:
* https://faucet.devnet.solana.com/
* `solana airdrop 2 <your_pubkey>`

Initialize an account on https://beta.drift.trade, and set your browser wallet
to point to devnet.

Run tests with:
```
cargo test
```
Loading
Loading