@stryke-xyz/premarket-sdk 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/cjs/abi/MarketsRegistry.abi.json +98 -0
- package/dist/cjs/abi/OptionMarketVault.abi.json +78 -5
- package/dist/cjs/api/README.md +296 -0
- package/dist/cjs/config/README.md +112 -0
- package/dist/cjs/config/index.js +7 -3
- package/dist/cjs/exchange/README.md +280 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/registry/README.md +150 -0
- package/dist/cjs/registry/markets-registry-contract.js +4 -1
- package/dist/cjs/registry/types.js +6 -2
- package/dist/cjs/shared/README.md +235 -0
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/sync/README.md +215 -0
- package/dist/cjs/sync/clients/activity-client.js +454 -325
- package/dist/cjs/sync/clients/base-client.js +518 -0
- package/dist/cjs/sync/clients/order-client.js +426 -606
- package/dist/cjs/sync/redis-ws-client.js +235 -0
- package/dist/cjs/utils/README.md +89 -0
- package/dist/cjs/vault/README.md +268 -0
- package/dist/cjs/vault/transactions.js +4 -3
- package/dist/esm/abi/MarketsRegistry.abi.json +98 -0
- package/dist/esm/abi/OptionMarketVault.abi.json +78 -5
- package/dist/esm/api/README.md +296 -0
- package/dist/esm/config/README.md +112 -0
- package/dist/esm/config/index.js +4 -3
- package/dist/esm/exchange/README.md +280 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/registry/README.md +150 -0
- package/dist/esm/registry/markets-registry-contract.js +4 -1
- package/dist/esm/registry/types.js +6 -2
- package/dist/esm/shared/README.md +235 -0
- package/dist/esm/shared/utils.js +0 -0
- package/dist/esm/sync/README.md +215 -0
- package/dist/esm/sync/clients/activity-client.js +454 -325
- package/dist/esm/sync/clients/base-client.js +508 -0
- package/dist/esm/sync/clients/order-client.js +426 -606
- package/dist/esm/sync/redis-ws-client.js +225 -0
- package/dist/esm/utils/README.md +89 -0
- package/dist/esm/vault/README.md +268 -0
- package/dist/esm/vault/transactions.js +4 -3
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/registry/types.d.ts +4 -0
- package/dist/types/shared/utils.d.ts +0 -0
- package/dist/types/sync/clients/activity-client.d.ts +32 -39
- package/dist/types/sync/clients/base-client.d.ts +56 -0
- package/dist/types/sync/clients/order-client.d.ts +58 -79
- package/dist/types/sync/index.d.ts +2 -2
- package/dist/types/sync/redis-ws-client.d.ts +21 -0
- package/dist/types/vault/transactions.d.ts +1 -1
- package/package.json +58 -58
package/README.md
CHANGED
|
@@ -539,7 +539,7 @@ Restricted or role-gated builders:
|
|
|
539
539
|
callable only by RedeemKeeper role.
|
|
540
540
|
- `buildDelegateRolloverTransaction(vaultAddress, oldPrmTokenId, holder)` —
|
|
541
541
|
callable only by RolloverKeeper role.
|
|
542
|
-
- `buildDelegateWithdrawTransaction(vaultAddress, prmTokenId, amount, owner, receiver)` —
|
|
542
|
+
- `buildDelegateWithdrawTransaction(vaultAddress, prmTokenId, amount, owner, receiver?)` —
|
|
543
543
|
callable only by WithdrawKeeper role.
|
|
544
544
|
- `buildFillMarketDeliveryTransaction(vaultAddress, marketId, amount)` —
|
|
545
545
|
physical settlement market funding.
|
|
@@ -753,9 +753,9 @@ Public token maps:
|
|
|
753
753
|
|
|
754
754
|
Important nuance:
|
|
755
755
|
|
|
756
|
-
- `USDM`, `USDT0`, `MARKETS_REGISTRY`, `
|
|
757
|
-
`ERC_TOKENS_RESTRICTION_MODULE` are partial maps because
|
|
758
|
-
not exist on every supported chain
|
|
756
|
+
- `USDM`, `USDT0`, `MARKETS_REGISTRY`, `COMMUNITY_MARKET_MANAGER`,
|
|
757
|
+
`FEE_REGISTRY`, and `ERC_TOKENS_RESTRICTION_MODULE` are partial maps because
|
|
758
|
+
those deployments do not exist on every supported chain
|
|
759
759
|
|
|
760
760
|
### Contract address maps
|
|
761
761
|
|
|
@@ -765,6 +765,7 @@ Public address maps:
|
|
|
765
765
|
- `OPTION_MARKET_VAULT`
|
|
766
766
|
- `EXCHANGE`
|
|
767
767
|
- `MARKETS_REGISTRY`
|
|
768
|
+
- `COMMUNITY_MARKET_MANAGER`
|
|
768
769
|
- `ENTRY_POINT`
|
|
769
770
|
- `SIMPLE_ACCOUNT_FACTORY`
|
|
770
771
|
- `FEE_REGISTRY`
|
|
@@ -549,6 +549,19 @@
|
|
|
549
549
|
"outputs": [],
|
|
550
550
|
"stateMutability": "nonpayable"
|
|
551
551
|
},
|
|
552
|
+
{
|
|
553
|
+
"type": "function",
|
|
554
|
+
"name": "setVault",
|
|
555
|
+
"inputs": [
|
|
556
|
+
{
|
|
557
|
+
"name": "vault_",
|
|
558
|
+
"type": "address",
|
|
559
|
+
"internalType": "address"
|
|
560
|
+
}
|
|
561
|
+
],
|
|
562
|
+
"outputs": [],
|
|
563
|
+
"stateMutability": "nonpayable"
|
|
564
|
+
},
|
|
552
565
|
{
|
|
553
566
|
"type": "function",
|
|
554
567
|
"name": "transferOwnership",
|
|
@@ -562,6 +575,24 @@
|
|
|
562
575
|
"outputs": [],
|
|
563
576
|
"stateMutability": "nonpayable"
|
|
564
577
|
},
|
|
578
|
+
{
|
|
579
|
+
"type": "function",
|
|
580
|
+
"name": "updateFinalTick",
|
|
581
|
+
"inputs": [
|
|
582
|
+
{
|
|
583
|
+
"name": "marketId",
|
|
584
|
+
"type": "uint256",
|
|
585
|
+
"internalType": "uint256"
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
"name": "tick",
|
|
589
|
+
"type": "uint256",
|
|
590
|
+
"internalType": "uint256"
|
|
591
|
+
}
|
|
592
|
+
],
|
|
593
|
+
"outputs": [],
|
|
594
|
+
"stateMutability": "nonpayable"
|
|
595
|
+
},
|
|
565
596
|
{
|
|
566
597
|
"type": "function",
|
|
567
598
|
"name": "updateMarketExpiry",
|
|
@@ -631,6 +662,19 @@
|
|
|
631
662
|
"outputs": [],
|
|
632
663
|
"stateMutability": "nonpayable"
|
|
633
664
|
},
|
|
665
|
+
{
|
|
666
|
+
"type": "function",
|
|
667
|
+
"name": "updateNullOutcome",
|
|
668
|
+
"inputs": [
|
|
669
|
+
{
|
|
670
|
+
"name": "marketId",
|
|
671
|
+
"type": "uint256",
|
|
672
|
+
"internalType": "uint256"
|
|
673
|
+
}
|
|
674
|
+
],
|
|
675
|
+
"outputs": [],
|
|
676
|
+
"stateMutability": "nonpayable"
|
|
677
|
+
},
|
|
634
678
|
{
|
|
635
679
|
"type": "function",
|
|
636
680
|
"name": "updateToken",
|
|
@@ -654,6 +698,19 @@
|
|
|
654
698
|
"outputs": [],
|
|
655
699
|
"stateMutability": "nonpayable"
|
|
656
700
|
},
|
|
701
|
+
{
|
|
702
|
+
"type": "function",
|
|
703
|
+
"name": "vault",
|
|
704
|
+
"inputs": [],
|
|
705
|
+
"outputs": [
|
|
706
|
+
{
|
|
707
|
+
"name": "",
|
|
708
|
+
"type": "address",
|
|
709
|
+
"internalType": "address"
|
|
710
|
+
}
|
|
711
|
+
],
|
|
712
|
+
"stateMutability": "view"
|
|
713
|
+
},
|
|
657
714
|
{
|
|
658
715
|
"type": "event",
|
|
659
716
|
"name": "AddressFeesUpdated",
|
|
@@ -963,6 +1020,31 @@
|
|
|
963
1020
|
],
|
|
964
1021
|
"anonymous": false
|
|
965
1022
|
},
|
|
1023
|
+
{
|
|
1024
|
+
"type": "event",
|
|
1025
|
+
"name": "VaultUpdated",
|
|
1026
|
+
"inputs": [
|
|
1027
|
+
{
|
|
1028
|
+
"name": "previousVault",
|
|
1029
|
+
"type": "address",
|
|
1030
|
+
"indexed": true,
|
|
1031
|
+
"internalType": "address"
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
"name": "newVault",
|
|
1035
|
+
"type": "address",
|
|
1036
|
+
"indexed": true,
|
|
1037
|
+
"internalType": "address"
|
|
1038
|
+
},
|
|
1039
|
+
{
|
|
1040
|
+
"name": "sender",
|
|
1041
|
+
"type": "address",
|
|
1042
|
+
"indexed": true,
|
|
1043
|
+
"internalType": "address"
|
|
1044
|
+
}
|
|
1045
|
+
],
|
|
1046
|
+
"anonymous": false
|
|
1047
|
+
},
|
|
966
1048
|
{
|
|
967
1049
|
"type": "error",
|
|
968
1050
|
"name": "AddressEmptyCode",
|
|
@@ -979,6 +1061,22 @@
|
|
|
979
1061
|
"name": "FailedCall",
|
|
980
1062
|
"inputs": []
|
|
981
1063
|
},
|
|
1064
|
+
{
|
|
1065
|
+
"type": "error",
|
|
1066
|
+
"name": "FinalizedOutcomeRequired",
|
|
1067
|
+
"inputs": [
|
|
1068
|
+
{
|
|
1069
|
+
"name": "marketId",
|
|
1070
|
+
"type": "uint256",
|
|
1071
|
+
"internalType": "uint256"
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
"name": "expiry",
|
|
1075
|
+
"type": "uint256",
|
|
1076
|
+
"internalType": "uint256"
|
|
1077
|
+
}
|
|
1078
|
+
]
|
|
1079
|
+
},
|
|
982
1080
|
{
|
|
983
1081
|
"type": "error",
|
|
984
1082
|
"name": "InvalidFeeRate",
|
|
@@ -217,11 +217,6 @@
|
|
|
217
217
|
"name": "owner",
|
|
218
218
|
"type": "address",
|
|
219
219
|
"internalType": "address"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"name": "rec",
|
|
223
|
-
"type": "address",
|
|
224
|
-
"internalType": "address"
|
|
225
220
|
}
|
|
226
221
|
],
|
|
227
222
|
"outputs": [],
|
|
@@ -574,6 +569,30 @@
|
|
|
574
569
|
],
|
|
575
570
|
"stateMutability": "nonpayable"
|
|
576
571
|
},
|
|
572
|
+
{
|
|
573
|
+
"type": "function",
|
|
574
|
+
"name": "nullOutcomes",
|
|
575
|
+
"inputs": [
|
|
576
|
+
{
|
|
577
|
+
"name": "marketId",
|
|
578
|
+
"type": "uint256",
|
|
579
|
+
"internalType": "uint256"
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
"name": "expiry",
|
|
583
|
+
"type": "uint256",
|
|
584
|
+
"internalType": "uint256"
|
|
585
|
+
}
|
|
586
|
+
],
|
|
587
|
+
"outputs": [
|
|
588
|
+
{
|
|
589
|
+
"name": "isNullOutcome",
|
|
590
|
+
"type": "bool",
|
|
591
|
+
"internalType": "bool"
|
|
592
|
+
}
|
|
593
|
+
],
|
|
594
|
+
"stateMutability": "view"
|
|
595
|
+
},
|
|
577
596
|
{
|
|
578
597
|
"type": "function",
|
|
579
598
|
"name": "optionPrmToPrm",
|
|
@@ -1003,6 +1022,19 @@
|
|
|
1003
1022
|
"outputs": [],
|
|
1004
1023
|
"stateMutability": "nonpayable"
|
|
1005
1024
|
},
|
|
1025
|
+
{
|
|
1026
|
+
"type": "function",
|
|
1027
|
+
"name": "updateNullOutcome",
|
|
1028
|
+
"inputs": [
|
|
1029
|
+
{
|
|
1030
|
+
"name": "marketId",
|
|
1031
|
+
"type": "uint256",
|
|
1032
|
+
"internalType": "uint256"
|
|
1033
|
+
}
|
|
1034
|
+
],
|
|
1035
|
+
"outputs": [],
|
|
1036
|
+
"stateMutability": "nonpayable"
|
|
1037
|
+
},
|
|
1006
1038
|
{
|
|
1007
1039
|
"type": "function",
|
|
1008
1040
|
"name": "withdraw",
|
|
@@ -1278,6 +1310,37 @@
|
|
|
1278
1310
|
],
|
|
1279
1311
|
"anonymous": false
|
|
1280
1312
|
},
|
|
1313
|
+
{
|
|
1314
|
+
"type": "event",
|
|
1315
|
+
"name": "NullOutcomeUpdated",
|
|
1316
|
+
"inputs": [
|
|
1317
|
+
{
|
|
1318
|
+
"name": "marketId",
|
|
1319
|
+
"type": "uint256",
|
|
1320
|
+
"indexed": true,
|
|
1321
|
+
"internalType": "uint256"
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
"name": "previousExpiry",
|
|
1325
|
+
"type": "uint256",
|
|
1326
|
+
"indexed": true,
|
|
1327
|
+
"internalType": "uint256"
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
"name": "expiry",
|
|
1331
|
+
"type": "uint256",
|
|
1332
|
+
"indexed": true,
|
|
1333
|
+
"internalType": "uint256"
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
"name": "updater",
|
|
1337
|
+
"type": "address",
|
|
1338
|
+
"indexed": false,
|
|
1339
|
+
"internalType": "address"
|
|
1340
|
+
}
|
|
1341
|
+
],
|
|
1342
|
+
"anonymous": false
|
|
1343
|
+
},
|
|
1281
1344
|
{
|
|
1282
1345
|
"type": "event",
|
|
1283
1346
|
"name": "OperatorSet",
|
|
@@ -1744,6 +1807,11 @@
|
|
|
1744
1807
|
}
|
|
1745
1808
|
]
|
|
1746
1809
|
},
|
|
1810
|
+
{
|
|
1811
|
+
"type": "error",
|
|
1812
|
+
"name": "DeliveryAlreadyFilled",
|
|
1813
|
+
"inputs": []
|
|
1814
|
+
},
|
|
1747
1815
|
{
|
|
1748
1816
|
"type": "error",
|
|
1749
1817
|
"name": "DeliveryNotFilled",
|
|
@@ -1806,6 +1874,11 @@
|
|
|
1806
1874
|
}
|
|
1807
1875
|
]
|
|
1808
1876
|
},
|
|
1877
|
+
{
|
|
1878
|
+
"type": "error",
|
|
1879
|
+
"name": "InvalidFinalTick",
|
|
1880
|
+
"inputs": []
|
|
1881
|
+
},
|
|
1809
1882
|
{
|
|
1810
1883
|
"type": "error",
|
|
1811
1884
|
"name": "InvalidMarket",
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# API Guide
|
|
2
|
+
|
|
3
|
+
The `api` module gives the SDK two high-level integration surfaces:
|
|
4
|
+
|
|
5
|
+
- `OrderHelper`
|
|
6
|
+
- a workflow helper for building, hashing, serializing, signing, and
|
|
7
|
+
recovering orders
|
|
8
|
+
- `OrderbookApi`
|
|
9
|
+
- the HTTP client for orderbook, market, user, history, and analytics reads
|
|
10
|
+
|
|
11
|
+
This is the module most frontend and backend product teams use directly.
|
|
12
|
+
|
|
13
|
+
## Source map
|
|
14
|
+
|
|
15
|
+
- [`index.ts`](./index.ts) re-exports the public API surface
|
|
16
|
+
- [`order-helper.ts`](./order-helper.ts) wraps exchange helpers into an
|
|
17
|
+
integration-friendly class
|
|
18
|
+
- [`orderbook-api/index.ts`](./orderbook-api/index.ts) implements the HTTP
|
|
19
|
+
client
|
|
20
|
+
- [`orderbook-api/deserializers.ts`](./orderbook-api/deserializers.ts) converts
|
|
21
|
+
string-heavy responses into bigint-friendly client-side objects
|
|
22
|
+
- [`../shared/types.ts`](../shared/types.ts) defines the request and response
|
|
23
|
+
DTOs consumed by `OrderbookApi`
|
|
24
|
+
|
|
25
|
+
## OrderHelper
|
|
26
|
+
|
|
27
|
+
`OrderHelper` exists so most consumers do not need to manually stitch together
|
|
28
|
+
`buildExchangeOrder`, `getExchangeTypedData`, `hashExchangeOrder`, and the
|
|
29
|
+
serialization helpers.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {
|
|
33
|
+
OrderHelper,
|
|
34
|
+
SignatureType,
|
|
35
|
+
TradeType,
|
|
36
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
37
|
+
|
|
38
|
+
const helper = new OrderHelper({
|
|
39
|
+
chainId: 4326,
|
|
40
|
+
exchangeAddress: "0xCf24f40D2dd88084e9C28FE34Ba9E24AFDACb7C2",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const order = helper.buildOrder({
|
|
44
|
+
maker: "0x1111111111111111111111111111111111111111",
|
|
45
|
+
receiver: "0x1111111111111111111111111111111111111111",
|
|
46
|
+
nonce: 0n,
|
|
47
|
+
marketId: 1n,
|
|
48
|
+
makingAmount: 1_000_000n,
|
|
49
|
+
takingAmount: 500_000n,
|
|
50
|
+
deadline: 1_900_000_000n,
|
|
51
|
+
tradeType: TradeType.SELL,
|
|
52
|
+
signatureType: SignatureType.EIP712,
|
|
53
|
+
tokenId: 42n,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Constructor config
|
|
58
|
+
|
|
59
|
+
`OrderHelperConfig`:
|
|
60
|
+
|
|
61
|
+
- `chainId`
|
|
62
|
+
- used for hashing and typed-data generation
|
|
63
|
+
- `exchangeAddress`
|
|
64
|
+
- the verifying contract used in EIP-712 signatures
|
|
65
|
+
|
|
66
|
+
### Public methods
|
|
67
|
+
|
|
68
|
+
- `buildOrder(params)`
|
|
69
|
+
- generic normalized order builder
|
|
70
|
+
- `buildSellOrder(params)`
|
|
71
|
+
- convenience helper that pins `tradeType = SELL`
|
|
72
|
+
- `buildBuyOrder(params)`
|
|
73
|
+
- convenience helper that pins `tradeType = BUY`
|
|
74
|
+
- `serializeOrder(order)`
|
|
75
|
+
- converts `ExchangeOrder` into `SerializedExchangeOrder`
|
|
76
|
+
- `hashOrder(order)`
|
|
77
|
+
- EIP-712 digest for the configured chain and exchange address
|
|
78
|
+
- `getTypedData(order)`
|
|
79
|
+
- typed-data payload suitable for a wallet signer
|
|
80
|
+
- `signEip712Order(order, walletClient)`
|
|
81
|
+
- only valid for `SignatureType.EIP712`
|
|
82
|
+
- `signSimpleAccountOrder(order, ownerWalletClient)`
|
|
83
|
+
- only valid for `SignatureType.ERC1271`
|
|
84
|
+
- intended for `SimpleAccount`-compatible flows where the maker contract
|
|
85
|
+
validates a raw owner signature against the native order hash
|
|
86
|
+
- `signOrder(order, walletClient)`
|
|
87
|
+
- compatibility alias for `signEip712Order`
|
|
88
|
+
- `recoverOrderSigner(order, signature)`
|
|
89
|
+
- recovers the address that signed the order payload
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const signature = await helper.signEip712Order(order, walletClient);
|
|
93
|
+
const payloadOrder = helper.serializeOrder(order);
|
|
94
|
+
const signer = await helper.recoverOrderSigner(order, signature);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## OrderbookApi
|
|
98
|
+
|
|
99
|
+
`OrderbookApi` is a fetch-based client that understands the backend's envelope
|
|
100
|
+
format, normalizes URLs, surfaces clearer errors, and exposes typed return
|
|
101
|
+
values for the main public read and write flows.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { OrderbookApi } from "@stryke-xyz/premarket-sdk";
|
|
105
|
+
|
|
106
|
+
const api = new OrderbookApi({
|
|
107
|
+
baseUrl: "https://example.stryke.xyz",
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Constructor config
|
|
112
|
+
|
|
113
|
+
`OrderbookApiConfig` from [`../shared/types.ts`](../shared/types.ts):
|
|
114
|
+
|
|
115
|
+
- `baseUrl`
|
|
116
|
+
- root URL for the backend
|
|
117
|
+
- `fetchFn?`
|
|
118
|
+
- optional injected `fetch` implementation for tests or custom runtimes
|
|
119
|
+
|
|
120
|
+
## Order endpoints
|
|
121
|
+
|
|
122
|
+
Public order methods:
|
|
123
|
+
|
|
124
|
+
- `createOrder(params, bearerToken)`
|
|
125
|
+
- creates a new order with bearer auth
|
|
126
|
+
- `getOrder(orderHash)`
|
|
127
|
+
- returns `StoredOrder | null`
|
|
128
|
+
- `queryOrders(params)`
|
|
129
|
+
- list endpoint for orderbook snapshots
|
|
130
|
+
- `getUserOrders(maker, marketId)`
|
|
131
|
+
- market-scoped user order lookup
|
|
132
|
+
- `getDepthSnapshot(marketId, tokenId)`
|
|
133
|
+
- point-in-time depth snapshot for a market and token pair
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const api = new OrderbookApi({ baseUrl: "https://example.stryke.xyz" });
|
|
137
|
+
|
|
138
|
+
await api.createOrder(
|
|
139
|
+
{
|
|
140
|
+
marketId: payloadOrder.marketId,
|
|
141
|
+
order: payloadOrder,
|
|
142
|
+
signature,
|
|
143
|
+
timeInForce: "GTC",
|
|
144
|
+
postOnly: false,
|
|
145
|
+
},
|
|
146
|
+
bearerToken,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const snapshot = await api.queryOrders({ marketId: "1", limit: 50 });
|
|
150
|
+
const mine = await api.getUserOrders(
|
|
151
|
+
"0x1111111111111111111111111111111111111111",
|
|
152
|
+
"1",
|
|
153
|
+
);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Important integration note:
|
|
157
|
+
|
|
158
|
+
- `getUserOrders` enforces `marketId` at runtime
|
|
159
|
+
- `queryOrders` accepts an optional `marketId` in its TypeScript type, but the
|
|
160
|
+
documented backend contract expects callers to provide one for reliable
|
|
161
|
+
integration behavior
|
|
162
|
+
|
|
163
|
+
## Market endpoints
|
|
164
|
+
|
|
165
|
+
Public market methods:
|
|
166
|
+
|
|
167
|
+
- `getMarkets()`
|
|
168
|
+
- returns `MarketsResponse["data"]`
|
|
169
|
+
- `getMarketRecentTrades(marketId, limit?)`
|
|
170
|
+
- returns `MarketTradeItem[]`
|
|
171
|
+
- `getMarket(marketId)`
|
|
172
|
+
- returns `MarketResponse["data"] | null`
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const markets = await api.getMarkets();
|
|
176
|
+
const market = await api.getMarket("12");
|
|
177
|
+
const trades = await api.getMarketRecentTrades("12", 25);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## User positions and PnL
|
|
181
|
+
|
|
182
|
+
Public user analytics methods:
|
|
183
|
+
|
|
184
|
+
- `getUserPositions(userAddress)`
|
|
185
|
+
- `getUserTradingPnL(userAddress)`
|
|
186
|
+
- `getUserPnL(userAddress)`
|
|
187
|
+
- `getTokenPnL(userAddress, tokenId)`
|
|
188
|
+
- `getErc20PnL(userAddress, tokenAddress)`
|
|
189
|
+
|
|
190
|
+
These methods return the shared transport DTOs documented in the
|
|
191
|
+
[Shared types guide](../shared/README.md).
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const positions = await api.getUserPositions(userAddress);
|
|
195
|
+
const trading = await api.getUserTradingPnL(userAddress);
|
|
196
|
+
const summary = await api.getUserPnL(userAddress);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Histories
|
|
200
|
+
|
|
201
|
+
Public history methods:
|
|
202
|
+
|
|
203
|
+
- `getUserHistories(userAddress, limit?)`
|
|
204
|
+
- `getMintHistory(userAddress, limit?)`
|
|
205
|
+
- `getRedeemHistory(userAddress, limit?)`
|
|
206
|
+
- `getUnwindHistory(userAddress, limit?)`
|
|
207
|
+
- `getTransferHistory(userAddress, limit?)`
|
|
208
|
+
- `getFillHistory(userAddress, limit?)`
|
|
209
|
+
|
|
210
|
+
These methods are useful when a frontend needs user-facing activity feeds, or
|
|
211
|
+
when a backend wants typed access to grouped historical data without hand-rolled
|
|
212
|
+
endpoint wrappers.
|
|
213
|
+
|
|
214
|
+
## Deserializers
|
|
215
|
+
|
|
216
|
+
The API returns string-heavy DTOs because JSON cannot safely transport `bigint`
|
|
217
|
+
values. [`orderbook-api/deserializers.ts`](./orderbook-api/deserializers.ts)
|
|
218
|
+
provides opt-in conversion helpers for clients that prefer `bigint` values.
|
|
219
|
+
|
|
220
|
+
Public helpers:
|
|
221
|
+
|
|
222
|
+
- `marketInstrumentToBigInt`
|
|
223
|
+
- `marketToBigInt`
|
|
224
|
+
- `marketsToBigInt`
|
|
225
|
+
- `positionToBigInt`
|
|
226
|
+
- `tradingPnLToBigInt`
|
|
227
|
+
- `mintHistoryToBigInt`
|
|
228
|
+
- `redeemHistoryToBigInt`
|
|
229
|
+
- `unwindHistoryToBigInt`
|
|
230
|
+
- `transferHistoryToBigInt`
|
|
231
|
+
- `fillHistoryToBigInt`
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import {
|
|
235
|
+
marketsToBigInt,
|
|
236
|
+
OrderbookApi,
|
|
237
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
238
|
+
|
|
239
|
+
const api = new OrderbookApi({ baseUrl: "https://example.stryke.xyz" });
|
|
240
|
+
const marketData = await api.getMarkets();
|
|
241
|
+
const bigintMarketData = marketsToBigInt(marketData);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Public request and response types
|
|
245
|
+
|
|
246
|
+
The API client relies on the DTOs exported from [`../shared/types.ts`](../shared/types.ts).
|
|
247
|
+
The most important public request and response shapes are:
|
|
248
|
+
|
|
249
|
+
- order write and read types
|
|
250
|
+
- `CreateOrderParams`
|
|
251
|
+
- `CreateOrderRequest`
|
|
252
|
+
- `StoredOrder`
|
|
253
|
+
- `OrderQueryParams`
|
|
254
|
+
- `OrdersSnapshot`
|
|
255
|
+
- `QueryOrdersResponse`
|
|
256
|
+
- `DepthSnapshot`
|
|
257
|
+
- market types
|
|
258
|
+
- `Market`
|
|
259
|
+
- `MarketInstrument`
|
|
260
|
+
- `MarketResponse`
|
|
261
|
+
- `MarketsResponse`
|
|
262
|
+
- `MarketTradeItem`
|
|
263
|
+
- user and analytics types
|
|
264
|
+
- `UserPosition`
|
|
265
|
+
- `TradingPnL`
|
|
266
|
+
- `UserPnL`
|
|
267
|
+
- `TokenPnL`
|
|
268
|
+
- `Erc20PnL`
|
|
269
|
+
- `UserHistories`
|
|
270
|
+
- `MintHistoryItem`
|
|
271
|
+
- `RedeemHistoryItem`
|
|
272
|
+
- `UnwindHistoryItem`
|
|
273
|
+
- `TransferHistoryItem`
|
|
274
|
+
- `OrderFillHistoryItem`
|
|
275
|
+
|
|
276
|
+
Those interfaces are broken down field-by-field in the
|
|
277
|
+
[Shared types guide](../shared/README.md).
|
|
278
|
+
|
|
279
|
+
## Restricted and sensitive surfaces
|
|
280
|
+
|
|
281
|
+
`OrderbookApi` also exposes auth helpers:
|
|
282
|
+
|
|
283
|
+
- `getChallenge({ address, chainId })`
|
|
284
|
+
- `verifyAuth({ account, nonce, signature, chainId, expiresAt })`
|
|
285
|
+
|
|
286
|
+
These methods are part of the public SDK surface, but this document does not
|
|
287
|
+
provide a field-by-field auth payload reference. The goal of the new docs is to
|
|
288
|
+
cover the general integration contract well without turning the repository docs
|
|
289
|
+
into an auth operations manual.
|
|
290
|
+
|
|
291
|
+
## How to choose between exchange and api modules
|
|
292
|
+
|
|
293
|
+
- use the [Exchange guide](../exchange/README.md) when you need low-level order
|
|
294
|
+
math, typed-data primitives, or calldata builders
|
|
295
|
+
- use this module when you want the ergonomics most applications need:
|
|
296
|
+
`OrderHelper`, `OrderbookApi`, and optional bigint deserializers
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Config Guide
|
|
2
|
+
|
|
3
|
+
The `config` module is the SDK's deployment and chain registry. It provides the
|
|
4
|
+
named chain objects, token metadata, and contract addresses that other modules
|
|
5
|
+
expect callers to use instead of hardcoding environment-specific values in each
|
|
6
|
+
app.
|
|
7
|
+
|
|
8
|
+
## Source map
|
|
9
|
+
|
|
10
|
+
- [`index.ts`](./index.ts) exports token metadata, contract addresses, and the
|
|
11
|
+
`CHAIN_ID_TO_CHAIN` lookup
|
|
12
|
+
- [`chains.ts`](./chains.ts) defines custom chain objects and the
|
|
13
|
+
`SUPPORTED_CHAINS` type
|
|
14
|
+
|
|
15
|
+
## What this module is for
|
|
16
|
+
|
|
17
|
+
In plain language:
|
|
18
|
+
|
|
19
|
+
- it centralizes deployed addresses
|
|
20
|
+
- it gives frontend and backend code a common view of supported chains
|
|
21
|
+
- it keeps order builders, API clients, and smart-account helpers pointed at
|
|
22
|
+
the same runtime contracts
|
|
23
|
+
|
|
24
|
+
## Chains
|
|
25
|
+
|
|
26
|
+
[`chains.ts`](./chains.ts) exports:
|
|
27
|
+
|
|
28
|
+
- `megaETH`
|
|
29
|
+
- custom viem chain definition for chain id `4326`
|
|
30
|
+
- `SUPPORTED_CHAINS`
|
|
31
|
+
- TypeScript union of the currently supported chain ids
|
|
32
|
+
|
|
33
|
+
[`index.ts`](./index.ts) then maps those ids into a runtime lookup:
|
|
34
|
+
|
|
35
|
+
- `CHAIN_ID_TO_CHAIN`
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import {
|
|
39
|
+
CHAIN_ID_TO_CHAIN,
|
|
40
|
+
megaETH,
|
|
41
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
42
|
+
|
|
43
|
+
const chain = CHAIN_ID_TO_CHAIN[megaETH.id];
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Token metadata
|
|
47
|
+
|
|
48
|
+
`Token` is the shared metadata shape for config entries:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
export interface Token {
|
|
52
|
+
name: string;
|
|
53
|
+
symbol: string;
|
|
54
|
+
address: `0x${string}`;
|
|
55
|
+
decimals: number;
|
|
56
|
+
logoURI?: string;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Public token maps:
|
|
61
|
+
|
|
62
|
+
- `WETH`
|
|
63
|
+
- `USDC`
|
|
64
|
+
- `USDM`
|
|
65
|
+
- `USDT0`
|
|
66
|
+
|
|
67
|
+
Important nuance:
|
|
68
|
+
|
|
69
|
+
- `USDM`, `USDT0`, `MARKETS_REGISTRY`, `FEE_REGISTRY`, and
|
|
70
|
+
`ERC_TOKENS_RESTRICTION_MODULE` are partial maps because those deployments do
|
|
71
|
+
not exist on every supported chain
|
|
72
|
+
|
|
73
|
+
## Contract address maps
|
|
74
|
+
|
|
75
|
+
Public address maps:
|
|
76
|
+
|
|
77
|
+
- `PERMIT2_ADDRESS`
|
|
78
|
+
- `OPTION_MARKET_VAULT`
|
|
79
|
+
- `EXCHANGE`
|
|
80
|
+
- `MARKETS_REGISTRY`
|
|
81
|
+
- `ENTRY_POINT`
|
|
82
|
+
- `SIMPLE_ACCOUNT_FACTORY`
|
|
83
|
+
- `FEE_REGISTRY`
|
|
84
|
+
- `ERC_TOKENS_RESTRICTION_MODULE`
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import {
|
|
88
|
+
EXCHANGE,
|
|
89
|
+
OPTION_MARKET_VAULT,
|
|
90
|
+
SIMPLE_ACCOUNT_FACTORY,
|
|
91
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
92
|
+
|
|
93
|
+
const chainId = 4326;
|
|
94
|
+
|
|
95
|
+
const exchangeAddress = EXCHANGE[chainId];
|
|
96
|
+
const vaultAddress = OPTION_MARKET_VAULT[chainId];
|
|
97
|
+
const factoryAddress = SIMPLE_ACCOUNT_FACTORY[chainId];
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## How this module fits with the rest of the SDK
|
|
101
|
+
|
|
102
|
+
- the [Exchange guide](../exchange/README.md) uses `EXCHANGE`
|
|
103
|
+
- the [Vault guide](../vault/README.md) uses `OPTION_MARKET_VAULT`
|
|
104
|
+
- the [Registry guide](../registry/README.md) uses `MARKETS_REGISTRY`
|
|
105
|
+
- the root package's smart-account helpers use `SIMPLE_ACCOUNT_FACTORY` and
|
|
106
|
+
`ENTRY_POINT`
|
|
107
|
+
|
|
108
|
+
## Operational guidance
|
|
109
|
+
|
|
110
|
+
If upstream deployments change, this module should be updated before app teams
|
|
111
|
+
scatter new addresses across their own repositories. This is one of the main
|
|
112
|
+
places where the SDK adds value as an integration boundary.
|