@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/lib/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/lib/index.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export * from './config';
|
|
|
53
53
|
export * from './constants/numericConstants';
|
|
54
54
|
export * from './serum/serumSubscriber';
|
|
55
55
|
export * from './serum/serumFulfillmentConfigMap';
|
|
56
|
+
export * from './phoenix/phoenixSubscriber';
|
|
57
|
+
export * from './phoenix/phoenixFulfillmentConfigMap';
|
|
56
58
|
export * from './tx/retryTxSender';
|
|
57
59
|
export * from './util/computeUnits';
|
|
58
60
|
export * from './util/tps';
|
|
@@ -64,6 +66,8 @@ export * from './dlob/DLOB';
|
|
|
64
66
|
export * from './dlob/DLOBNode';
|
|
65
67
|
export * from './dlob/DLOBOrders';
|
|
66
68
|
export * from './dlob/NodeList';
|
|
69
|
+
export * from './dlob/DLOBSubscriber';
|
|
70
|
+
export * from './dlob/types';
|
|
67
71
|
export * from './userMap/userMap';
|
|
68
72
|
export * from './userMap/userStatsMap';
|
|
69
73
|
export * from './math/bankruptcy';
|
package/lib/index.js
CHANGED
|
@@ -77,6 +77,8 @@ __exportStar(require("./config"), exports);
|
|
|
77
77
|
__exportStar(require("./constants/numericConstants"), exports);
|
|
78
78
|
__exportStar(require("./serum/serumSubscriber"), exports);
|
|
79
79
|
__exportStar(require("./serum/serumFulfillmentConfigMap"), exports);
|
|
80
|
+
__exportStar(require("./phoenix/phoenixSubscriber"), exports);
|
|
81
|
+
__exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
|
|
80
82
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
81
83
|
__exportStar(require("./util/computeUnits"), exports);
|
|
82
84
|
__exportStar(require("./util/tps"), exports);
|
|
@@ -88,6 +90,8 @@ __exportStar(require("./dlob/DLOB"), exports);
|
|
|
88
90
|
__exportStar(require("./dlob/DLOBNode"), exports);
|
|
89
91
|
__exportStar(require("./dlob/DLOBOrders"), exports);
|
|
90
92
|
__exportStar(require("./dlob/NodeList"), exports);
|
|
93
|
+
__exportStar(require("./dlob/DLOBSubscriber"), exports);
|
|
94
|
+
__exportStar(require("./dlob/types"), exports);
|
|
91
95
|
__exportStar(require("./userMap/userMap"), exports);
|
|
92
96
|
__exportStar(require("./userMap/userStatsMap"), exports);
|
|
93
97
|
__exportStar(require("./math/bankruptcy"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { PhoenixV1FulfillmentConfigAccount } from '../types';
|
|
3
|
+
import { DriftClient } from '../driftClient';
|
|
4
|
+
export declare class PhoenixFulfillmentConfigMap {
|
|
5
|
+
driftClient: DriftClient;
|
|
6
|
+
map: Map<number, PhoenixV1FulfillmentConfigAccount>;
|
|
7
|
+
constructor(driftClient: DriftClient);
|
|
8
|
+
add(marketIndex: number, phoenixMarketAddress: PublicKey): Promise<void>;
|
|
9
|
+
get(marketIndex: number): PhoenixV1FulfillmentConfigAccount;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhoenixFulfillmentConfigMap = void 0;
|
|
4
|
+
class PhoenixFulfillmentConfigMap {
|
|
5
|
+
constructor(driftClient) {
|
|
6
|
+
this.map = new Map();
|
|
7
|
+
this.driftClient = driftClient;
|
|
8
|
+
}
|
|
9
|
+
async add(marketIndex, phoenixMarketAddress) {
|
|
10
|
+
const account = await this.driftClient.getPhoenixV1FulfillmentConfig(phoenixMarketAddress);
|
|
11
|
+
this.map.set(marketIndex, account);
|
|
12
|
+
}
|
|
13
|
+
get(marketIndex) {
|
|
14
|
+
return this.map.get(marketIndex);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PhoenixFulfillmentConfigMap = PhoenixFulfillmentConfigMap;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
+
import { MarketData, Client } from '@ellipsis-labs/phoenix-sdk';
|
|
4
|
+
import { BN } from '@coral-xyz/anchor';
|
|
5
|
+
export type PhoenixMarketSubscriberConfig = {
|
|
6
|
+
connection: Connection;
|
|
7
|
+
programId: PublicKey;
|
|
8
|
+
marketAddress: PublicKey;
|
|
9
|
+
accountSubscription: {
|
|
10
|
+
type: 'polling';
|
|
11
|
+
accountLoader: BulkAccountLoader;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'websocket';
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare class PhoenixSubscriber {
|
|
17
|
+
connection: Connection;
|
|
18
|
+
client: Client;
|
|
19
|
+
programId: PublicKey;
|
|
20
|
+
marketAddress: PublicKey;
|
|
21
|
+
subscriptionType: 'polling' | 'websocket';
|
|
22
|
+
accountLoader: BulkAccountLoader | undefined;
|
|
23
|
+
market: MarketData;
|
|
24
|
+
marketCallbackId: string | number;
|
|
25
|
+
clockCallbackId: string | number;
|
|
26
|
+
subscribed: boolean;
|
|
27
|
+
lastSlot: number;
|
|
28
|
+
lastUnixTimestamp: number;
|
|
29
|
+
constructor(config: PhoenixMarketSubscriberConfig);
|
|
30
|
+
subscribe(): Promise<void>;
|
|
31
|
+
getBestBid(): BN;
|
|
32
|
+
getBestAsk(): BN;
|
|
33
|
+
unsubscribe(): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhoenixSubscriber = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const phoenix_sdk_1 = require("@ellipsis-labs/phoenix-sdk");
|
|
6
|
+
const numericConstants_1 = require("../constants/numericConstants");
|
|
7
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
class PhoenixSubscriber {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.connection = config.connection;
|
|
11
|
+
this.programId = config.programId;
|
|
12
|
+
this.marketAddress = config.marketAddress;
|
|
13
|
+
if (config.accountSubscription.type === 'polling') {
|
|
14
|
+
this.subscriptionType = 'polling';
|
|
15
|
+
this.accountLoader = config.accountSubscription.accountLoader;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.subscriptionType = 'websocket';
|
|
19
|
+
}
|
|
20
|
+
this.lastSlot = 0;
|
|
21
|
+
this.lastUnixTimestamp = 0;
|
|
22
|
+
}
|
|
23
|
+
async subscribe() {
|
|
24
|
+
if (this.subscribed) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.market = (0, phoenix_sdk_1.deserializeMarketData)((await this.connection.getAccountInfo(this.marketAddress, 'confirmed'))
|
|
28
|
+
.data);
|
|
29
|
+
const clock = (0, phoenix_sdk_1.deserializeClockData)((await this.connection.getAccountInfo(web3_js_1.SYSVAR_CLOCK_PUBKEY, 'confirmed'))
|
|
30
|
+
.data);
|
|
31
|
+
this.lastUnixTimestamp = (0, phoenix_sdk_1.toNum)(clock.unixTimestamp);
|
|
32
|
+
if (this.subscriptionType === 'websocket') {
|
|
33
|
+
this.marketCallbackId = this.connection.onAccountChange(this.marketAddress, (accountInfo, _ctx) => {
|
|
34
|
+
this.market = (0, phoenix_sdk_1.deserializeMarketData)(accountInfo.data);
|
|
35
|
+
});
|
|
36
|
+
this.clockCallbackId = this.connection.onAccountChange(web3_js_1.SYSVAR_CLOCK_PUBKEY, (accountInfo, ctx) => {
|
|
37
|
+
this.lastSlot = ctx.slot;
|
|
38
|
+
const clock = (0, phoenix_sdk_1.deserializeClockData)(accountInfo.data);
|
|
39
|
+
this.lastUnixTimestamp = (0, phoenix_sdk_1.toNum)(clock.unixTimestamp);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.marketCallbackId = await this.accountLoader.addAccount(this.marketAddress, (buffer, slot) => {
|
|
44
|
+
this.lastSlot = slot;
|
|
45
|
+
this.market = (0, phoenix_sdk_1.deserializeMarketData)(buffer);
|
|
46
|
+
});
|
|
47
|
+
this.clockCallbackId = await this.accountLoader.addAccount(web3_js_1.SYSVAR_CLOCK_PUBKEY, (buffer, slot) => {
|
|
48
|
+
this.lastSlot = slot;
|
|
49
|
+
const clock = (0, phoenix_sdk_1.deserializeClockData)(buffer);
|
|
50
|
+
this.lastUnixTimestamp = (0, phoenix_sdk_1.toNum)(clock.unixTimestamp);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.subscribed = true;
|
|
54
|
+
}
|
|
55
|
+
getBestBid() {
|
|
56
|
+
const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
57
|
+
return new anchor_1.BN(Math.floor(ladder.bids[0][0] * numericConstants_1.PRICE_PRECISION.toNumber()));
|
|
58
|
+
}
|
|
59
|
+
getBestAsk() {
|
|
60
|
+
const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
61
|
+
return new anchor_1.BN(Math.floor(ladder.asks[0][0] * numericConstants_1.PRICE_PRECISION.toNumber()));
|
|
62
|
+
}
|
|
63
|
+
async unsubscribe() {
|
|
64
|
+
if (!this.subscribed) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// remove listeners
|
|
68
|
+
if (this.subscriptionType === 'websocket') {
|
|
69
|
+
await this.connection.removeAccountChangeListener(this.marketCallbackId);
|
|
70
|
+
await this.connection.removeAccountChangeListener(this.clockCallbackId);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.accountLoader.removeAccount(this.marketAddress, this.marketCallbackId);
|
|
74
|
+
this.accountLoader.removeAccount(web3_js_1.SYSVAR_CLOCK_PUBKEY, this.clockCallbackId);
|
|
75
|
+
}
|
|
76
|
+
this.subscribed = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.PhoenixSubscriber = PhoenixSubscriber;
|
|
@@ -8,6 +8,9 @@ class SlotSubscriber {
|
|
|
8
8
|
this.eventEmitter = new events_1.EventEmitter();
|
|
9
9
|
}
|
|
10
10
|
async subscribe() {
|
|
11
|
+
if (this.subscriptionId) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
11
14
|
this.currentSlot = await this.connection.getSlot('confirmed');
|
|
12
15
|
this.subscriptionId = this.connection.onSlotChange((slotInfo) => {
|
|
13
16
|
this.currentSlot = slotInfo.slot;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { TxSender, TxSigAndSlot } from './types';
|
|
3
|
-
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
3
|
+
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, VersionedTransaction, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
4
4
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
5
5
|
type ResolveReference = {
|
|
6
6
|
resolve?: () => void;
|
|
@@ -13,6 +13,7 @@ export declare class RetryTxSender implements TxSender {
|
|
|
13
13
|
constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
|
|
14
14
|
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
15
15
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
16
|
+
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
16
17
|
sendVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
17
18
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
18
19
|
confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -39,7 +39,7 @@ class RetryTxSender {
|
|
|
39
39
|
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
40
40
|
return signedTx;
|
|
41
41
|
}
|
|
42
|
-
async
|
|
42
|
+
async getVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts) {
|
|
43
43
|
if (additionalSigners === undefined) {
|
|
44
44
|
additionalSigners = [];
|
|
45
45
|
}
|
|
@@ -52,6 +52,10 @@ class RetryTxSender {
|
|
|
52
52
|
instructions: ixs,
|
|
53
53
|
}).compileToV0Message(lookupTableAccounts);
|
|
54
54
|
const tx = new web3_js_1.VersionedTransaction(message);
|
|
55
|
+
return tx;
|
|
56
|
+
}
|
|
57
|
+
async sendVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts) {
|
|
58
|
+
const tx = await this.getVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts);
|
|
55
59
|
// @ts-ignore
|
|
56
60
|
tx.sign(additionalSigners.concat(this.provider.wallet.payer));
|
|
57
61
|
return this.sendRawTransaction(tx.serialize(), opts);
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Provider } from '@coral-xyz/anchor';
|
|
2
|
-
import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
3
|
+
import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
3
4
|
export type TxSigAndSlot = {
|
|
4
5
|
txSig: TransactionSignature;
|
|
5
6
|
slot: number;
|
|
@@ -8,4 +9,6 @@ export interface TxSender {
|
|
|
8
9
|
provider: Provider;
|
|
9
10
|
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
|
|
10
11
|
sendVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
12
|
+
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
13
|
+
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
11
14
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1021,6 +1021,17 @@ export type SerumV3FulfillmentConfigAccount = {
|
|
|
1021
1021
|
serumOpenOrders: PublicKey;
|
|
1022
1022
|
serumSignerNonce: BN;
|
|
1023
1023
|
};
|
|
1024
|
+
export type PhoenixV1FulfillmentConfigAccount = {
|
|
1025
|
+
pubkey: PublicKey;
|
|
1026
|
+
phoenixProgramId: PublicKey;
|
|
1027
|
+
phoenixLogAuthority: PublicKey;
|
|
1028
|
+
phoenixMarket: PublicKey;
|
|
1029
|
+
phoenixBaseVault: PublicKey;
|
|
1030
|
+
phoenixQuoteVault: PublicKey;
|
|
1031
|
+
marketIndex: number;
|
|
1032
|
+
fulfillmentType: SpotFulfillmentType;
|
|
1033
|
+
status: SpotFulfillmentStatus;
|
|
1034
|
+
};
|
|
1024
1035
|
export type ReferrerNameAccount = {
|
|
1025
1036
|
name: number[];
|
|
1026
1037
|
user: PublicKey;
|