@drift-labs/sdk 2.25.4 → 2.26.0-beta.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/examples/phoenix.ts +40 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +5 -4
- package/lib/accounts/pollingUserAccountSubscriber.js +35 -48
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -4
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +30 -47
- package/lib/accounts/types.d.ts +2 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.js +4 -3
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +20 -0
- package/lib/dlob/DLOBApiClient.d.ts +14 -0
- package/lib/dlob/DLOBApiClient.js +34 -0
- package/lib/dlob/DLOBSubscriber.d.ts +19 -0
- package/lib/dlob/DLOBSubscriber.js +42 -0
- package/lib/dlob/types.d.ts +16 -0
- package/lib/dlob/types.js +2 -0
- package/lib/driftClient.d.ts +13 -10
- package/lib/driftClient.js +124 -28
- package/lib/examples/loadDlob.js +2 -4
- package/lib/idl/drift.json +264 -82
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/phoenix/phoenixSubscriber.d.ts +34 -0
- package/lib/phoenix/phoenixSubscriber.js +79 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/tx/retryTxSender.d.ts +2 -1
- package/lib/tx/retryTxSender.js +5 -1
- package/lib/tx/types.d.ts +4 -1
- package/lib/types.d.ts +11 -0
- package/lib/userMap/userMap.d.ts +17 -6
- package/lib/userMap/userMap.js +74 -46
- package/lib/userMap/userStatsMap.d.ts +6 -3
- package/lib/userMap/userStatsMap.js +30 -30
- package/package.json +2 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +51 -63
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +46 -62
- package/src/accounts/types.ts +2 -1
- package/src/accounts/webSocketAccountSubscriber.ts +4 -3
- package/src/accounts/webSocketUserAccountSubscriber.ts +10 -0
- package/src/addresses/pda.ts +13 -0
- package/src/adminClient.ts +34 -0
- package/src/dlob/DLOBApiClient.ts +37 -0
- package/src/dlob/DLOBSubscriber.ts +57 -0
- package/src/dlob/types.ts +20 -0
- package/src/driftClient.ts +216 -59
- package/src/examples/loadDlob.ts +2 -4
- package/src/idl/drift.json +264 -82
- package/src/index.ts +4 -0
- package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
- package/src/phoenix/phoenixSubscriber.ts +156 -0
- package/src/slot/SlotSubscriber.ts +4 -0
- package/src/tx/retryTxSender.ts +19 -2
- package/src/tx/types.ts +13 -0
- package/src/types.ts +12 -0
- package/src/userMap/userMap.ts +111 -60
- package/src/userMap/userStatsMap.ts +43 -44
- package/tests/dlob/helpers.ts +3 -1
- package/src/assert/assert.js +0 -9
- package/src/token/index.js +0 -38
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.26.0-beta.1",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -2293,6 +2293,95 @@
|
|
|
2293
2293
|
}
|
|
2294
2294
|
]
|
|
2295
2295
|
},
|
|
2296
|
+
{
|
|
2297
|
+
"name": "initializePhoenixFulfillmentConfig",
|
|
2298
|
+
"accounts": [
|
|
2299
|
+
{
|
|
2300
|
+
"name": "baseSpotMarket",
|
|
2301
|
+
"isMut": false,
|
|
2302
|
+
"isSigner": false
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
"name": "quoteSpotMarket",
|
|
2306
|
+
"isMut": false,
|
|
2307
|
+
"isSigner": false
|
|
2308
|
+
},
|
|
2309
|
+
{
|
|
2310
|
+
"name": "state",
|
|
2311
|
+
"isMut": true,
|
|
2312
|
+
"isSigner": false
|
|
2313
|
+
},
|
|
2314
|
+
{
|
|
2315
|
+
"name": "phoenixProgram",
|
|
2316
|
+
"isMut": false,
|
|
2317
|
+
"isSigner": false
|
|
2318
|
+
},
|
|
2319
|
+
{
|
|
2320
|
+
"name": "phoenixMarket",
|
|
2321
|
+
"isMut": false,
|
|
2322
|
+
"isSigner": false
|
|
2323
|
+
},
|
|
2324
|
+
{
|
|
2325
|
+
"name": "driftSigner",
|
|
2326
|
+
"isMut": false,
|
|
2327
|
+
"isSigner": false
|
|
2328
|
+
},
|
|
2329
|
+
{
|
|
2330
|
+
"name": "phoenixFulfillmentConfig",
|
|
2331
|
+
"isMut": true,
|
|
2332
|
+
"isSigner": false
|
|
2333
|
+
},
|
|
2334
|
+
{
|
|
2335
|
+
"name": "admin",
|
|
2336
|
+
"isMut": true,
|
|
2337
|
+
"isSigner": true
|
|
2338
|
+
},
|
|
2339
|
+
{
|
|
2340
|
+
"name": "rent",
|
|
2341
|
+
"isMut": false,
|
|
2342
|
+
"isSigner": false
|
|
2343
|
+
},
|
|
2344
|
+
{
|
|
2345
|
+
"name": "systemProgram",
|
|
2346
|
+
"isMut": false,
|
|
2347
|
+
"isSigner": false
|
|
2348
|
+
}
|
|
2349
|
+
],
|
|
2350
|
+
"args": [
|
|
2351
|
+
{
|
|
2352
|
+
"name": "marketIndex",
|
|
2353
|
+
"type": "u16"
|
|
2354
|
+
}
|
|
2355
|
+
]
|
|
2356
|
+
},
|
|
2357
|
+
{
|
|
2358
|
+
"name": "phoenixFulfillmentConfigStatus",
|
|
2359
|
+
"accounts": [
|
|
2360
|
+
{
|
|
2361
|
+
"name": "state",
|
|
2362
|
+
"isMut": false,
|
|
2363
|
+
"isSigner": false
|
|
2364
|
+
},
|
|
2365
|
+
{
|
|
2366
|
+
"name": "phoenixFulfillmentConfig",
|
|
2367
|
+
"isMut": true,
|
|
2368
|
+
"isSigner": false
|
|
2369
|
+
},
|
|
2370
|
+
{
|
|
2371
|
+
"name": "admin",
|
|
2372
|
+
"isMut": true,
|
|
2373
|
+
"isSigner": true
|
|
2374
|
+
}
|
|
2375
|
+
],
|
|
2376
|
+
"args": [
|
|
2377
|
+
{
|
|
2378
|
+
"name": "status",
|
|
2379
|
+
"type": {
|
|
2380
|
+
"defined": "SpotFulfillmentConfigStatus"
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
]
|
|
2384
|
+
},
|
|
2296
2385
|
{
|
|
2297
2386
|
"name": "updateSerumVault",
|
|
2298
2387
|
"accounts": [
|
|
@@ -4002,6 +4091,140 @@
|
|
|
4002
4091
|
}
|
|
4003
4092
|
],
|
|
4004
4093
|
"accounts": [
|
|
4094
|
+
{
|
|
4095
|
+
"name": "PhoenixV1FulfillmentConfig",
|
|
4096
|
+
"type": {
|
|
4097
|
+
"kind": "struct",
|
|
4098
|
+
"fields": [
|
|
4099
|
+
{
|
|
4100
|
+
"name": "pubkey",
|
|
4101
|
+
"type": "publicKey"
|
|
4102
|
+
},
|
|
4103
|
+
{
|
|
4104
|
+
"name": "phoenixProgramId",
|
|
4105
|
+
"type": "publicKey"
|
|
4106
|
+
},
|
|
4107
|
+
{
|
|
4108
|
+
"name": "phoenixLogAuthority",
|
|
4109
|
+
"type": "publicKey"
|
|
4110
|
+
},
|
|
4111
|
+
{
|
|
4112
|
+
"name": "phoenixMarket",
|
|
4113
|
+
"type": "publicKey"
|
|
4114
|
+
},
|
|
4115
|
+
{
|
|
4116
|
+
"name": "phoenixBaseVault",
|
|
4117
|
+
"type": "publicKey"
|
|
4118
|
+
},
|
|
4119
|
+
{
|
|
4120
|
+
"name": "phoenixQuoteVault",
|
|
4121
|
+
"type": "publicKey"
|
|
4122
|
+
},
|
|
4123
|
+
{
|
|
4124
|
+
"name": "marketIndex",
|
|
4125
|
+
"type": "u16"
|
|
4126
|
+
},
|
|
4127
|
+
{
|
|
4128
|
+
"name": "fulfillmentType",
|
|
4129
|
+
"type": {
|
|
4130
|
+
"defined": "SpotFulfillmentType"
|
|
4131
|
+
}
|
|
4132
|
+
},
|
|
4133
|
+
{
|
|
4134
|
+
"name": "status",
|
|
4135
|
+
"type": {
|
|
4136
|
+
"defined": "SpotFulfillmentConfigStatus"
|
|
4137
|
+
}
|
|
4138
|
+
},
|
|
4139
|
+
{
|
|
4140
|
+
"name": "padding",
|
|
4141
|
+
"type": {
|
|
4142
|
+
"array": [
|
|
4143
|
+
"u8",
|
|
4144
|
+
4
|
|
4145
|
+
]
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
]
|
|
4149
|
+
}
|
|
4150
|
+
},
|
|
4151
|
+
{
|
|
4152
|
+
"name": "SerumV3FulfillmentConfig",
|
|
4153
|
+
"type": {
|
|
4154
|
+
"kind": "struct",
|
|
4155
|
+
"fields": [
|
|
4156
|
+
{
|
|
4157
|
+
"name": "pubkey",
|
|
4158
|
+
"type": "publicKey"
|
|
4159
|
+
},
|
|
4160
|
+
{
|
|
4161
|
+
"name": "serumProgramId",
|
|
4162
|
+
"type": "publicKey"
|
|
4163
|
+
},
|
|
4164
|
+
{
|
|
4165
|
+
"name": "serumMarket",
|
|
4166
|
+
"type": "publicKey"
|
|
4167
|
+
},
|
|
4168
|
+
{
|
|
4169
|
+
"name": "serumRequestQueue",
|
|
4170
|
+
"type": "publicKey"
|
|
4171
|
+
},
|
|
4172
|
+
{
|
|
4173
|
+
"name": "serumEventQueue",
|
|
4174
|
+
"type": "publicKey"
|
|
4175
|
+
},
|
|
4176
|
+
{
|
|
4177
|
+
"name": "serumBids",
|
|
4178
|
+
"type": "publicKey"
|
|
4179
|
+
},
|
|
4180
|
+
{
|
|
4181
|
+
"name": "serumAsks",
|
|
4182
|
+
"type": "publicKey"
|
|
4183
|
+
},
|
|
4184
|
+
{
|
|
4185
|
+
"name": "serumBaseVault",
|
|
4186
|
+
"type": "publicKey"
|
|
4187
|
+
},
|
|
4188
|
+
{
|
|
4189
|
+
"name": "serumQuoteVault",
|
|
4190
|
+
"type": "publicKey"
|
|
4191
|
+
},
|
|
4192
|
+
{
|
|
4193
|
+
"name": "serumOpenOrders",
|
|
4194
|
+
"type": "publicKey"
|
|
4195
|
+
},
|
|
4196
|
+
{
|
|
4197
|
+
"name": "serumSignerNonce",
|
|
4198
|
+
"type": "u64"
|
|
4199
|
+
},
|
|
4200
|
+
{
|
|
4201
|
+
"name": "marketIndex",
|
|
4202
|
+
"type": "u16"
|
|
4203
|
+
},
|
|
4204
|
+
{
|
|
4205
|
+
"name": "fulfillmentType",
|
|
4206
|
+
"type": {
|
|
4207
|
+
"defined": "SpotFulfillmentType"
|
|
4208
|
+
}
|
|
4209
|
+
},
|
|
4210
|
+
{
|
|
4211
|
+
"name": "status",
|
|
4212
|
+
"type": {
|
|
4213
|
+
"defined": "SpotFulfillmentConfigStatus"
|
|
4214
|
+
}
|
|
4215
|
+
},
|
|
4216
|
+
{
|
|
4217
|
+
"name": "padding",
|
|
4218
|
+
"type": {
|
|
4219
|
+
"array": [
|
|
4220
|
+
"u8",
|
|
4221
|
+
4
|
|
4222
|
+
]
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
]
|
|
4226
|
+
}
|
|
4227
|
+
},
|
|
4005
4228
|
{
|
|
4006
4229
|
"name": "InsuranceFundStake",
|
|
4007
4230
|
"type": {
|
|
@@ -4423,83 +4646,6 @@
|
|
|
4423
4646
|
]
|
|
4424
4647
|
}
|
|
4425
4648
|
},
|
|
4426
|
-
{
|
|
4427
|
-
"name": "SerumV3FulfillmentConfig",
|
|
4428
|
-
"type": {
|
|
4429
|
-
"kind": "struct",
|
|
4430
|
-
"fields": [
|
|
4431
|
-
{
|
|
4432
|
-
"name": "pubkey",
|
|
4433
|
-
"type": "publicKey"
|
|
4434
|
-
},
|
|
4435
|
-
{
|
|
4436
|
-
"name": "serumProgramId",
|
|
4437
|
-
"type": "publicKey"
|
|
4438
|
-
},
|
|
4439
|
-
{
|
|
4440
|
-
"name": "serumMarket",
|
|
4441
|
-
"type": "publicKey"
|
|
4442
|
-
},
|
|
4443
|
-
{
|
|
4444
|
-
"name": "serumRequestQueue",
|
|
4445
|
-
"type": "publicKey"
|
|
4446
|
-
},
|
|
4447
|
-
{
|
|
4448
|
-
"name": "serumEventQueue",
|
|
4449
|
-
"type": "publicKey"
|
|
4450
|
-
},
|
|
4451
|
-
{
|
|
4452
|
-
"name": "serumBids",
|
|
4453
|
-
"type": "publicKey"
|
|
4454
|
-
},
|
|
4455
|
-
{
|
|
4456
|
-
"name": "serumAsks",
|
|
4457
|
-
"type": "publicKey"
|
|
4458
|
-
},
|
|
4459
|
-
{
|
|
4460
|
-
"name": "serumBaseVault",
|
|
4461
|
-
"type": "publicKey"
|
|
4462
|
-
},
|
|
4463
|
-
{
|
|
4464
|
-
"name": "serumQuoteVault",
|
|
4465
|
-
"type": "publicKey"
|
|
4466
|
-
},
|
|
4467
|
-
{
|
|
4468
|
-
"name": "serumOpenOrders",
|
|
4469
|
-
"type": "publicKey"
|
|
4470
|
-
},
|
|
4471
|
-
{
|
|
4472
|
-
"name": "serumSignerNonce",
|
|
4473
|
-
"type": "u64"
|
|
4474
|
-
},
|
|
4475
|
-
{
|
|
4476
|
-
"name": "marketIndex",
|
|
4477
|
-
"type": "u16"
|
|
4478
|
-
},
|
|
4479
|
-
{
|
|
4480
|
-
"name": "fulfillmentType",
|
|
4481
|
-
"type": {
|
|
4482
|
-
"defined": "SpotFulfillmentType"
|
|
4483
|
-
}
|
|
4484
|
-
},
|
|
4485
|
-
{
|
|
4486
|
-
"name": "status",
|
|
4487
|
-
"type": {
|
|
4488
|
-
"defined": "SpotFulfillmentConfigStatus"
|
|
4489
|
-
}
|
|
4490
|
-
},
|
|
4491
|
-
{
|
|
4492
|
-
"name": "padding",
|
|
4493
|
-
"type": {
|
|
4494
|
-
"array": [
|
|
4495
|
-
"u8",
|
|
4496
|
-
4
|
|
4497
|
-
]
|
|
4498
|
-
}
|
|
4499
|
-
}
|
|
4500
|
-
]
|
|
4501
|
-
}
|
|
4502
|
-
},
|
|
4503
4649
|
{
|
|
4504
4650
|
"name": "State",
|
|
4505
4651
|
"type": {
|
|
@@ -6212,6 +6358,9 @@
|
|
|
6212
6358
|
},
|
|
6213
6359
|
{
|
|
6214
6360
|
"name": "Match"
|
|
6361
|
+
},
|
|
6362
|
+
{
|
|
6363
|
+
"name": "PhoenixV1"
|
|
6215
6364
|
}
|
|
6216
6365
|
]
|
|
6217
6366
|
}
|
|
@@ -6462,6 +6611,9 @@
|
|
|
6462
6611
|
},
|
|
6463
6612
|
{
|
|
6464
6613
|
"name": "NoBorrowLiquidity"
|
|
6614
|
+
},
|
|
6615
|
+
{
|
|
6616
|
+
"name": "OrderFillWithPhoenix"
|
|
6465
6617
|
}
|
|
6466
6618
|
]
|
|
6467
6619
|
}
|
|
@@ -8531,13 +8683,13 @@
|
|
|
8531
8683
|
},
|
|
8532
8684
|
{
|
|
8533
8685
|
"code": 6142,
|
|
8534
|
-
"name": "
|
|
8535
|
-
"msg": "
|
|
8686
|
+
"name": "FailedToFillOnExternalMarket",
|
|
8687
|
+
"msg": "FailedToFillOnExternalMarket"
|
|
8536
8688
|
},
|
|
8537
8689
|
{
|
|
8538
8690
|
"code": 6143,
|
|
8539
|
-
"name": "
|
|
8540
|
-
"msg": "
|
|
8691
|
+
"name": "InvalidFulfillmentConfig",
|
|
8692
|
+
"msg": "InvalidFulfillmentConfig"
|
|
8541
8693
|
},
|
|
8542
8694
|
{
|
|
8543
8695
|
"code": 6144,
|
|
@@ -9028,6 +9180,36 @@
|
|
|
9028
9180
|
"code": 6241,
|
|
9029
9181
|
"name": "InvalidSpotFulfillmentParams",
|
|
9030
9182
|
"msg": "Invalid Spot Fulfillment Params"
|
|
9183
|
+
},
|
|
9184
|
+
{
|
|
9185
|
+
"code": 6242,
|
|
9186
|
+
"name": "FailedToGetMint",
|
|
9187
|
+
"msg": "Failed to Get Mint"
|
|
9188
|
+
},
|
|
9189
|
+
{
|
|
9190
|
+
"code": 6243,
|
|
9191
|
+
"name": "FailedPhoenixCPI",
|
|
9192
|
+
"msg": "FailedPhoenixCPI"
|
|
9193
|
+
},
|
|
9194
|
+
{
|
|
9195
|
+
"code": 6244,
|
|
9196
|
+
"name": "FailedToDeserializePhoenixMarket",
|
|
9197
|
+
"msg": "FailedToDeserializePhoenixMarket"
|
|
9198
|
+
},
|
|
9199
|
+
{
|
|
9200
|
+
"code": 6245,
|
|
9201
|
+
"name": "InvalidPricePrecision",
|
|
9202
|
+
"msg": "InvalidPricePrecision"
|
|
9203
|
+
},
|
|
9204
|
+
{
|
|
9205
|
+
"code": 6246,
|
|
9206
|
+
"name": "InvalidPhoenixProgram",
|
|
9207
|
+
"msg": "InvalidPhoenixProgram"
|
|
9208
|
+
},
|
|
9209
|
+
{
|
|
9210
|
+
"code": 6247,
|
|
9211
|
+
"name": "InvalidPhoenixMarket",
|
|
9212
|
+
"msg": "InvalidPhoenixMarket"
|
|
9031
9213
|
}
|
|
9032
9214
|
]
|
|
9033
9215
|
}
|
package/src/index.ts
CHANGED
|
@@ -55,6 +55,8 @@ export * from './config';
|
|
|
55
55
|
export * from './constants/numericConstants';
|
|
56
56
|
export * from './serum/serumSubscriber';
|
|
57
57
|
export * from './serum/serumFulfillmentConfigMap';
|
|
58
|
+
export * from './phoenix/phoenixSubscriber';
|
|
59
|
+
export * from './phoenix/phoenixFulfillmentConfigMap';
|
|
58
60
|
export * from './tx/retryTxSender';
|
|
59
61
|
export * from './util/computeUnits';
|
|
60
62
|
export * from './util/tps';
|
|
@@ -66,6 +68,8 @@ export * from './dlob/DLOB';
|
|
|
66
68
|
export * from './dlob/DLOBNode';
|
|
67
69
|
export * from './dlob/DLOBOrders';
|
|
68
70
|
export * from './dlob/NodeList';
|
|
71
|
+
export * from './dlob/DLOBSubscriber';
|
|
72
|
+
export * from './dlob/types';
|
|
69
73
|
export * from './userMap/userMap';
|
|
70
74
|
export * from './userMap/userStatsMap';
|
|
71
75
|
export * from './math/bankruptcy';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { PhoenixV1FulfillmentConfigAccount } from '../types';
|
|
3
|
+
import { DriftClient } from '../driftClient';
|
|
4
|
+
|
|
5
|
+
export class PhoenixFulfillmentConfigMap {
|
|
6
|
+
driftClient: DriftClient;
|
|
7
|
+
map = new Map<number, PhoenixV1FulfillmentConfigAccount>();
|
|
8
|
+
|
|
9
|
+
public constructor(driftClient: DriftClient) {
|
|
10
|
+
this.driftClient = driftClient;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public async add(
|
|
14
|
+
marketIndex: number,
|
|
15
|
+
phoenixMarketAddress: PublicKey
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
const account = await this.driftClient.getPhoenixV1FulfillmentConfig(
|
|
18
|
+
phoenixMarketAddress
|
|
19
|
+
);
|
|
20
|
+
this.map.set(marketIndex, account);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get(marketIndex: number): PhoenixV1FulfillmentConfigAccount {
|
|
24
|
+
return this.map.get(marketIndex);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Connection, PublicKey, SYSVAR_CLOCK_PUBKEY } from '@solana/web3.js';
|
|
2
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
+
import {
|
|
4
|
+
MarketData,
|
|
5
|
+
Client,
|
|
6
|
+
deserializeMarketData,
|
|
7
|
+
deserializeClockData,
|
|
8
|
+
toNum,
|
|
9
|
+
getMarketUiLadder,
|
|
10
|
+
} from '@ellipsis-labs/phoenix-sdk';
|
|
11
|
+
import { PRICE_PRECISION } from '../constants/numericConstants';
|
|
12
|
+
import { BN } from '@coral-xyz/anchor';
|
|
13
|
+
|
|
14
|
+
export type PhoenixMarketSubscriberConfig = {
|
|
15
|
+
connection: Connection;
|
|
16
|
+
programId: PublicKey;
|
|
17
|
+
marketAddress: PublicKey;
|
|
18
|
+
accountSubscription:
|
|
19
|
+
| {
|
|
20
|
+
// enables use to add web sockets in the future
|
|
21
|
+
type: 'polling';
|
|
22
|
+
accountLoader: BulkAccountLoader;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: 'websocket';
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class PhoenixSubscriber {
|
|
30
|
+
connection: Connection;
|
|
31
|
+
client: Client;
|
|
32
|
+
programId: PublicKey;
|
|
33
|
+
marketAddress: PublicKey;
|
|
34
|
+
subscriptionType: 'polling' | 'websocket';
|
|
35
|
+
accountLoader: BulkAccountLoader | undefined;
|
|
36
|
+
market: MarketData;
|
|
37
|
+
marketCallbackId: string | number;
|
|
38
|
+
clockCallbackId: string | number;
|
|
39
|
+
|
|
40
|
+
subscribed: boolean;
|
|
41
|
+
lastSlot: number;
|
|
42
|
+
lastUnixTimestamp: number;
|
|
43
|
+
|
|
44
|
+
public constructor(config: PhoenixMarketSubscriberConfig) {
|
|
45
|
+
this.connection = config.connection;
|
|
46
|
+
this.programId = config.programId;
|
|
47
|
+
this.marketAddress = config.marketAddress;
|
|
48
|
+
if (config.accountSubscription.type === 'polling') {
|
|
49
|
+
this.subscriptionType = 'polling';
|
|
50
|
+
this.accountLoader = config.accountSubscription.accountLoader;
|
|
51
|
+
} else {
|
|
52
|
+
this.subscriptionType = 'websocket';
|
|
53
|
+
}
|
|
54
|
+
this.lastSlot = 0;
|
|
55
|
+
this.lastUnixTimestamp = 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async subscribe(): Promise<void> {
|
|
59
|
+
if (this.subscribed) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.market = deserializeMarketData(
|
|
64
|
+
(await this.connection.getAccountInfo(this.marketAddress, 'confirmed'))
|
|
65
|
+
.data
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const clock = deserializeClockData(
|
|
69
|
+
(await this.connection.getAccountInfo(SYSVAR_CLOCK_PUBKEY, 'confirmed'))
|
|
70
|
+
.data
|
|
71
|
+
);
|
|
72
|
+
this.lastUnixTimestamp = toNum(clock.unixTimestamp);
|
|
73
|
+
|
|
74
|
+
if (this.subscriptionType === 'websocket') {
|
|
75
|
+
this.marketCallbackId = this.connection.onAccountChange(
|
|
76
|
+
this.marketAddress,
|
|
77
|
+
(accountInfo, _ctx) => {
|
|
78
|
+
this.market = deserializeMarketData(accountInfo.data);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
this.clockCallbackId = this.connection.onAccountChange(
|
|
82
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
83
|
+
(accountInfo, ctx) => {
|
|
84
|
+
this.lastSlot = ctx.slot;
|
|
85
|
+
const clock = deserializeClockData(accountInfo.data);
|
|
86
|
+
this.lastUnixTimestamp = toNum(clock.unixTimestamp);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
this.marketCallbackId = await this.accountLoader.addAccount(
|
|
91
|
+
this.marketAddress,
|
|
92
|
+
(buffer, slot) => {
|
|
93
|
+
this.lastSlot = slot;
|
|
94
|
+
this.market = deserializeMarketData(buffer);
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
this.clockCallbackId = await this.accountLoader.addAccount(
|
|
98
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
99
|
+
(buffer, slot) => {
|
|
100
|
+
this.lastSlot = slot;
|
|
101
|
+
const clock = deserializeClockData(buffer);
|
|
102
|
+
this.lastUnixTimestamp = toNum(clock.unixTimestamp);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.subscribed = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getBestBid(): BN {
|
|
111
|
+
const ladder = getMarketUiLadder(
|
|
112
|
+
this.market,
|
|
113
|
+
this.lastSlot,
|
|
114
|
+
this.lastUnixTimestamp,
|
|
115
|
+
1
|
|
116
|
+
);
|
|
117
|
+
return new BN(Math.floor(ladder.bids[0][0] * PRICE_PRECISION.toNumber()));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public getBestAsk(): BN {
|
|
121
|
+
const ladder = getMarketUiLadder(
|
|
122
|
+
this.market,
|
|
123
|
+
this.lastSlot,
|
|
124
|
+
this.lastUnixTimestamp,
|
|
125
|
+
1
|
|
126
|
+
);
|
|
127
|
+
return new BN(Math.floor(ladder.asks[0][0] * PRICE_PRECISION.toNumber()));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public async unsubscribe(): Promise<void> {
|
|
131
|
+
if (!this.subscribed) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// remove listeners
|
|
136
|
+
if (this.subscriptionType === 'websocket') {
|
|
137
|
+
await this.connection.removeAccountChangeListener(
|
|
138
|
+
this.marketCallbackId as number
|
|
139
|
+
);
|
|
140
|
+
await this.connection.removeAccountChangeListener(
|
|
141
|
+
this.clockCallbackId as number
|
|
142
|
+
);
|
|
143
|
+
} else {
|
|
144
|
+
this.accountLoader.removeAccount(
|
|
145
|
+
this.marketAddress,
|
|
146
|
+
this.marketCallbackId as string
|
|
147
|
+
);
|
|
148
|
+
this.accountLoader.removeAccount(
|
|
149
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
150
|
+
this.clockCallbackId as string
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.subscribed = false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -22,6 +22,10 @@ export class SlotSubscriber {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
public async subscribe(): Promise<void> {
|
|
25
|
+
if (this.subscriptionId) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
this.currentSlot = await this.connection.getSlot('confirmed');
|
|
26
30
|
|
|
27
31
|
this.subscriptionId = this.connection.onSlotChange((slotInfo) => {
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -86,12 +86,12 @@ export class RetryTxSender implements TxSender {
|
|
|
86
86
|
return signedTx;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
async
|
|
89
|
+
async getVersionedTransaction(
|
|
90
90
|
ixs: TransactionInstruction[],
|
|
91
91
|
lookupTableAccounts: AddressLookupTableAccount[],
|
|
92
92
|
additionalSigners?: Array<Signer>,
|
|
93
93
|
opts?: ConfirmOptions
|
|
94
|
-
): Promise<
|
|
94
|
+
): Promise<VersionedTransaction> {
|
|
95
95
|
if (additionalSigners === undefined) {
|
|
96
96
|
additionalSigners = [];
|
|
97
97
|
}
|
|
@@ -110,6 +110,23 @@ export class RetryTxSender implements TxSender {
|
|
|
110
110
|
}).compileToV0Message(lookupTableAccounts);
|
|
111
111
|
|
|
112
112
|
const tx = new VersionedTransaction(message);
|
|
113
|
+
|
|
114
|
+
return tx;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async sendVersionedTransaction(
|
|
118
|
+
ixs: TransactionInstruction[],
|
|
119
|
+
lookupTableAccounts: AddressLookupTableAccount[],
|
|
120
|
+
additionalSigners?: Array<Signer>,
|
|
121
|
+
opts?: ConfirmOptions
|
|
122
|
+
): Promise<TxSigAndSlot> {
|
|
123
|
+
const tx = await this.getVersionedTransaction(
|
|
124
|
+
ixs,
|
|
125
|
+
lookupTableAccounts,
|
|
126
|
+
additionalSigners,
|
|
127
|
+
opts
|
|
128
|
+
);
|
|
129
|
+
|
|
113
130
|
// @ts-ignore
|
|
114
131
|
tx.sign(additionalSigners.concat(this.provider.wallet.payer));
|
|
115
132
|
|
package/src/tx/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Transaction,
|
|
7
7
|
TransactionInstruction,
|
|
8
8
|
TransactionSignature,
|
|
9
|
+
VersionedTransaction,
|
|
9
10
|
} from '@solana/web3.js';
|
|
10
11
|
|
|
11
12
|
export type TxSigAndSlot = {
|
|
@@ -29,4 +30,16 @@ export interface TxSender {
|
|
|
29
30
|
additionalSigners?: Array<Signer>,
|
|
30
31
|
opts?: ConfirmOptions
|
|
31
32
|
): Promise<TxSigAndSlot>;
|
|
33
|
+
|
|
34
|
+
getVersionedTransaction(
|
|
35
|
+
ixs: TransactionInstruction[],
|
|
36
|
+
lookupTableAccounts: AddressLookupTableAccount[],
|
|
37
|
+
additionalSigners?: Array<Signer>,
|
|
38
|
+
opts?: ConfirmOptions
|
|
39
|
+
): Promise<VersionedTransaction>;
|
|
40
|
+
|
|
41
|
+
sendRawTransaction(
|
|
42
|
+
rawTransaction: Buffer | Uint8Array,
|
|
43
|
+
opts: ConfirmOptions
|
|
44
|
+
): Promise<TxSigAndSlot>;
|
|
32
45
|
}
|
package/src/types.ts
CHANGED
|
@@ -1009,6 +1009,18 @@ export type SerumV3FulfillmentConfigAccount = {
|
|
|
1009
1009
|
serumSignerNonce: BN;
|
|
1010
1010
|
};
|
|
1011
1011
|
|
|
1012
|
+
export type PhoenixV1FulfillmentConfigAccount = {
|
|
1013
|
+
pubkey: PublicKey;
|
|
1014
|
+
phoenixProgramId: PublicKey;
|
|
1015
|
+
phoenixLogAuthority: PublicKey;
|
|
1016
|
+
phoenixMarket: PublicKey;
|
|
1017
|
+
phoenixBaseVault: PublicKey;
|
|
1018
|
+
phoenixQuoteVault: PublicKey;
|
|
1019
|
+
marketIndex: number;
|
|
1020
|
+
fulfillmentType: SpotFulfillmentType;
|
|
1021
|
+
status: SpotFulfillmentStatus;
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1012
1024
|
export type ReferrerNameAccount = {
|
|
1013
1025
|
name: number[];
|
|
1014
1026
|
user: PublicKey;
|