@drift-labs/sdk 2.86.0-beta.8 → 2.87.0-beta.0

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.
Files changed (39) hide show
  1. package/VERSION +1 -1
  2. package/lib/addresses/pda.d.ts +1 -0
  3. package/lib/addresses/pda.js +8 -1
  4. package/lib/adminClient.d.ts +8 -4
  5. package/lib/adminClient.js +51 -8
  6. package/lib/bankrun/bankrunConnection.d.ts +1 -0
  7. package/lib/bankrun/bankrunConnection.js +6 -0
  8. package/lib/constants/numericConstants.d.ts +2 -0
  9. package/lib/constants/numericConstants.js +3 -1
  10. package/lib/constants/perpMarkets.js +144 -120
  11. package/lib/constants/spotMarkets.js +50 -38
  12. package/lib/driftClient.d.ts +12 -14
  13. package/lib/driftClient.js +147 -9
  14. package/lib/idl/drift.json +344 -10
  15. package/lib/idl/pyth_solana_receiver.json +628 -0
  16. package/lib/math/fuel.d.ts +1 -0
  17. package/lib/math/fuel.js +12 -2
  18. package/lib/types.d.ts +25 -6
  19. package/lib/types.js +3 -2
  20. package/lib/user.d.ts +6 -5
  21. package/lib/user.js +36 -18
  22. package/package.json +1 -1
  23. package/src/addresses/pda.ts +15 -0
  24. package/src/adminClient.ts +119 -7
  25. package/src/bankrun/bankrunConnection.ts +13 -0
  26. package/src/constants/numericConstants.ts +2 -0
  27. package/src/constants/perpMarkets.ts +148 -120
  28. package/src/constants/spotMarkets.ts +52 -38
  29. package/src/driftClient.ts +203 -16
  30. package/src/idl/drift.json +344 -10
  31. package/src/idl/openbook.json +3854 -0
  32. package/src/idl/pyth_solana_receiver.json +628 -0
  33. package/src/math/fuel.ts +15 -1
  34. package/src/types.ts +28 -7
  35. package/src/user.ts +119 -55
  36. package/tests/ci/verifyConstants.ts +214 -0
  37. package/tests/dlob/helpers.ts +30 -0
  38. package/tests/user/helpers.ts +1 -0
  39. package/tests/user/test.ts +2 -0
@@ -0,0 +1,628 @@
1
+ {
2
+ "version": "0.1.0",
3
+ "name": "pyth_solana_receiver",
4
+ "instructions": [
5
+ {
6
+ "name": "initialize",
7
+ "accounts": [
8
+ {
9
+ "name": "payer",
10
+ "isMut": true,
11
+ "isSigner": true
12
+ },
13
+ {
14
+ "name": "config",
15
+ "isMut": true,
16
+ "isSigner": false
17
+ },
18
+ {
19
+ "name": "systemProgram",
20
+ "isMut": false,
21
+ "isSigner": false
22
+ }
23
+ ],
24
+ "args": [
25
+ {
26
+ "name": "initialConfig",
27
+ "type": {
28
+ "defined": "Config"
29
+ }
30
+ }
31
+ ]
32
+ },
33
+ {
34
+ "name": "requestGovernanceAuthorityTransfer",
35
+ "accounts": [
36
+ {
37
+ "name": "payer",
38
+ "isMut": false,
39
+ "isSigner": true
40
+ },
41
+ {
42
+ "name": "config",
43
+ "isMut": true,
44
+ "isSigner": false
45
+ }
46
+ ],
47
+ "args": [
48
+ {
49
+ "name": "targetGovernanceAuthority",
50
+ "type": "publicKey"
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "name": "acceptGovernanceAuthorityTransfer",
56
+ "accounts": [
57
+ {
58
+ "name": "payer",
59
+ "isMut": false,
60
+ "isSigner": true
61
+ },
62
+ {
63
+ "name": "config",
64
+ "isMut": true,
65
+ "isSigner": false
66
+ }
67
+ ],
68
+ "args": []
69
+ },
70
+ {
71
+ "name": "setDataSources",
72
+ "accounts": [
73
+ {
74
+ "name": "payer",
75
+ "isMut": false,
76
+ "isSigner": true
77
+ },
78
+ {
79
+ "name": "config",
80
+ "isMut": true,
81
+ "isSigner": false
82
+ }
83
+ ],
84
+ "args": [
85
+ {
86
+ "name": "validDataSources",
87
+ "type": {
88
+ "vec": {
89
+ "defined": "DataSource"
90
+ }
91
+ }
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "name": "setFee",
97
+ "accounts": [
98
+ {
99
+ "name": "payer",
100
+ "isMut": false,
101
+ "isSigner": true
102
+ },
103
+ {
104
+ "name": "config",
105
+ "isMut": true,
106
+ "isSigner": false
107
+ }
108
+ ],
109
+ "args": [
110
+ {
111
+ "name": "singleUpdateFeeInLamports",
112
+ "type": "u64"
113
+ }
114
+ ]
115
+ },
116
+ {
117
+ "name": "setWormholeAddress",
118
+ "accounts": [
119
+ {
120
+ "name": "payer",
121
+ "isMut": false,
122
+ "isSigner": true
123
+ },
124
+ {
125
+ "name": "config",
126
+ "isMut": true,
127
+ "isSigner": false
128
+ }
129
+ ],
130
+ "args": [
131
+ {
132
+ "name": "wormhole",
133
+ "type": "publicKey"
134
+ }
135
+ ]
136
+ },
137
+ {
138
+ "name": "setMinimumSignatures",
139
+ "accounts": [
140
+ {
141
+ "name": "payer",
142
+ "isMut": false,
143
+ "isSigner": true
144
+ },
145
+ {
146
+ "name": "config",
147
+ "isMut": true,
148
+ "isSigner": false
149
+ }
150
+ ],
151
+ "args": [
152
+ {
153
+ "name": "minimumSignatures",
154
+ "type": "u8"
155
+ }
156
+ ]
157
+ },
158
+ {
159
+ "name": "postUpdateAtomic",
160
+ "docs": [
161
+ "Post a price update using a VAA and a MerklePriceUpdate.",
162
+ "This function allows you to post a price update in a single transaction.",
163
+ "Compared to post_update, it is less secure since you won't be able to verify all guardian signatures if you use this function because of transaction size limitations.",
164
+ "Typically, you can fit 5 guardian signatures in a transaction that uses this."
165
+ ],
166
+ "accounts": [
167
+ {
168
+ "name": "payer",
169
+ "isMut": true,
170
+ "isSigner": true
171
+ },
172
+ {
173
+ "name": "guardianSet",
174
+ "isMut": false,
175
+ "isSigner": false,
176
+ "docs": [
177
+ "Instead we do the same steps in deserialize_guardian_set_checked."
178
+ ]
179
+ },
180
+ {
181
+ "name": "config",
182
+ "isMut": false,
183
+ "isSigner": false
184
+ },
185
+ {
186
+ "name": "treasury",
187
+ "isMut": true,
188
+ "isSigner": false
189
+ },
190
+ {
191
+ "name": "priceUpdateAccount",
192
+ "isMut": true,
193
+ "isSigner": true,
194
+ "docs": [
195
+ "The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.",
196
+ "Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized"
197
+ ]
198
+ },
199
+ {
200
+ "name": "systemProgram",
201
+ "isMut": false,
202
+ "isSigner": false
203
+ },
204
+ {
205
+ "name": "writeAuthority",
206
+ "isMut": false,
207
+ "isSigner": true
208
+ }
209
+ ],
210
+ "args": [
211
+ {
212
+ "name": "params",
213
+ "type": {
214
+ "defined": "PostUpdateAtomicParams"
215
+ }
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ "name": "postUpdate",
221
+ "docs": [
222
+ "Post a price update using an encoded_vaa account and a MerklePriceUpdate calldata.",
223
+ "This should be called after the client has already verified the Vaa via the Wormhole contract.",
224
+ "Check out target_chains/solana/cli/src/main.rs for an example of how to do this."
225
+ ],
226
+ "accounts": [
227
+ {
228
+ "name": "payer",
229
+ "isMut": true,
230
+ "isSigner": true
231
+ },
232
+ {
233
+ "name": "encodedVaa",
234
+ "isMut": false,
235
+ "isSigner": false
236
+ },
237
+ {
238
+ "name": "config",
239
+ "isMut": false,
240
+ "isSigner": false
241
+ },
242
+ {
243
+ "name": "treasury",
244
+ "isMut": true,
245
+ "isSigner": false
246
+ },
247
+ {
248
+ "name": "priceUpdateAccount",
249
+ "isMut": true,
250
+ "isSigner": true,
251
+ "docs": [
252
+ "The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.",
253
+ "Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized"
254
+ ]
255
+ },
256
+ {
257
+ "name": "systemProgram",
258
+ "isMut": false,
259
+ "isSigner": false
260
+ },
261
+ {
262
+ "name": "writeAuthority",
263
+ "isMut": false,
264
+ "isSigner": true
265
+ }
266
+ ],
267
+ "args": [
268
+ {
269
+ "name": "params",
270
+ "type": {
271
+ "defined": "PostUpdateParams"
272
+ }
273
+ }
274
+ ]
275
+ },
276
+ {
277
+ "name": "reclaimRent",
278
+ "accounts": [
279
+ {
280
+ "name": "payer",
281
+ "isMut": true,
282
+ "isSigner": true
283
+ },
284
+ {
285
+ "name": "priceUpdateAccount",
286
+ "isMut": true,
287
+ "isSigner": false
288
+ }
289
+ ],
290
+ "args": []
291
+ }
292
+ ],
293
+ "accounts": [
294
+ {
295
+ "name": "Config",
296
+ "type": {
297
+ "kind": "struct",
298
+ "fields": [
299
+ {
300
+ "name": "governanceAuthority",
301
+ "type": "publicKey"
302
+ },
303
+ {
304
+ "name": "targetGovernanceAuthority",
305
+ "type": {
306
+ "option": "publicKey"
307
+ }
308
+ },
309
+ {
310
+ "name": "wormhole",
311
+ "type": "publicKey"
312
+ },
313
+ {
314
+ "name": "validDataSources",
315
+ "type": {
316
+ "vec": {
317
+ "defined": "DataSource"
318
+ }
319
+ }
320
+ },
321
+ {
322
+ "name": "singleUpdateFeeInLamports",
323
+ "type": "u64"
324
+ },
325
+ {
326
+ "name": "minimumSignatures",
327
+ "type": "u8"
328
+ }
329
+ ]
330
+ }
331
+ },
332
+ {
333
+ "name": "priceUpdateV2",
334
+ "type": {
335
+ "kind": "struct",
336
+ "fields": [
337
+ {
338
+ "name": "writeAuthority",
339
+ "type": "publicKey"
340
+ },
341
+ {
342
+ "name": "verificationLevel",
343
+ "type": {
344
+ "defined": "VerificationLevel"
345
+ }
346
+ },
347
+ {
348
+ "name": "priceMessage",
349
+ "type": {
350
+ "defined": "PriceFeedMessage"
351
+ }
352
+ },
353
+ {
354
+ "name": "postedSlot",
355
+ "type": "u64"
356
+ }
357
+ ]
358
+ }
359
+ }
360
+ ],
361
+ "types": [
362
+ {
363
+ "name": "PriceFeedMessage",
364
+ "type": {
365
+ "kind": "struct",
366
+ "fields": [
367
+ {
368
+ "name": "feedId",
369
+ "type": {
370
+ "array": ["u8", 32]
371
+ }
372
+ },
373
+ {
374
+ "name": "price",
375
+ "type": "i64"
376
+ },
377
+ {
378
+ "name": "conf",
379
+ "type": "u64"
380
+ },
381
+ {
382
+ "name": "exponent",
383
+ "type": "i32"
384
+ },
385
+ {
386
+ "name": "publishTime",
387
+ "type": "i64"
388
+ },
389
+ {
390
+ "name": "prevPublishTime",
391
+ "type": "i64"
392
+ },
393
+ {
394
+ "name": "emaPrice",
395
+ "type": "i64"
396
+ },
397
+ {
398
+ "name": "emaConf",
399
+ "type": "u64"
400
+ }
401
+ ]
402
+ }
403
+ },
404
+ {
405
+ "name": "MerklePriceUpdate",
406
+ "type": {
407
+ "kind": "struct",
408
+ "fields": [
409
+ {
410
+ "name": "message",
411
+ "type": "bytes"
412
+ },
413
+ {
414
+ "name": "proof",
415
+ "type": {
416
+ "vec": {
417
+ "array": ["u8", 20]
418
+ }
419
+ }
420
+ }
421
+ ]
422
+ }
423
+ },
424
+ {
425
+ "name": "DataSource",
426
+ "type": {
427
+ "kind": "struct",
428
+ "fields": [
429
+ {
430
+ "name": "chain",
431
+ "type": "u16"
432
+ },
433
+ {
434
+ "name": "emitter",
435
+ "type": "publicKey"
436
+ }
437
+ ]
438
+ }
439
+ },
440
+ {
441
+ "name": "PostMultiUpdatesAtomicParams",
442
+ "type": {
443
+ "kind": "struct",
444
+ "fields": [
445
+ {
446
+ "name": "vaa",
447
+ "type": "bytes"
448
+ },
449
+ {
450
+ "name": "merklePriceUpdates",
451
+ "type": {
452
+ "vec": {
453
+ "defined": "MerklePriceUpdate"
454
+ }
455
+ }
456
+ }
457
+ ]
458
+ }
459
+ },
460
+ {
461
+ "name": "PostUpdateAtomicParams",
462
+ "type": {
463
+ "kind": "struct",
464
+ "fields": [
465
+ {
466
+ "name": "vaa",
467
+ "type": "bytes"
468
+ },
469
+ {
470
+ "name": "merklePriceUpdate",
471
+ "type": {
472
+ "defined": "MerklePriceUpdate"
473
+ }
474
+ }
475
+ ]
476
+ }
477
+ },
478
+ {
479
+ "name": "PostUpdateParams",
480
+ "type": {
481
+ "kind": "struct",
482
+ "fields": [
483
+ {
484
+ "name": "merklePriceUpdate",
485
+ "type": {
486
+ "defined": "MerklePriceUpdate"
487
+ }
488
+ }
489
+ ]
490
+ }
491
+ },
492
+ {
493
+ "name": "VerificationLevel",
494
+ "docs": [
495
+ "* This enum represents how many guardian signatures were checked for a Pythnet price update\n * If full, guardian quorum has been attained\n * If partial, at least config.minimum signatures have been verified, but in the case config.minimum_signatures changes in the future we also include the number of signatures that were checked"
496
+ ],
497
+ "type": {
498
+ "kind": "enum",
499
+ "variants": [
500
+ {
501
+ "name": "Partial",
502
+ "fields": [
503
+ {
504
+ "name": "numSignatures",
505
+ "type": "u8"
506
+ }
507
+ ]
508
+ },
509
+ {
510
+ "name": "Full"
511
+ }
512
+ ]
513
+ }
514
+ }
515
+ ],
516
+ "errors": [
517
+ {
518
+ "code": 6000,
519
+ "name": "InvalidWormholeMessage",
520
+ "msg": "Received an invalid wormhole message"
521
+ },
522
+ {
523
+ "code": 6001,
524
+ "name": "DeserializeMessageFailed",
525
+ "msg": "An error occurred when deserializing the message"
526
+ },
527
+ {
528
+ "code": 6002,
529
+ "name": "InvalidPriceUpdate",
530
+ "msg": "Received an invalid price update"
531
+ },
532
+ {
533
+ "code": 6003,
534
+ "name": "UnsupportedMessageType",
535
+ "msg": "This type of message is not supported currently"
536
+ },
537
+ {
538
+ "code": 6004,
539
+ "name": "InvalidDataSource",
540
+ "msg": "The tuple emitter chain, emitter doesn't match one of the valid data sources."
541
+ },
542
+ {
543
+ "code": 6005,
544
+ "name": "InsufficientFunds",
545
+ "msg": "Funds are insufficient to pay the receiving fee"
546
+ },
547
+ {
548
+ "code": 6006,
549
+ "name": "WrongWriteAuthority",
550
+ "msg": "This signer can't write to price update account"
551
+ },
552
+ {
553
+ "code": 6007,
554
+ "name": "WrongVaaOwner",
555
+ "msg": "The posted VAA account has the wrong owner."
556
+ },
557
+ {
558
+ "code": 6008,
559
+ "name": "DeserializeVaaFailed",
560
+ "msg": "An error occurred when deserializing the VAA."
561
+ },
562
+ {
563
+ "code": 6009,
564
+ "name": "InsufficientGuardianSignatures",
565
+ "msg": "The number of guardian signatures is below the minimum"
566
+ },
567
+ {
568
+ "code": 6010,
569
+ "name": "InvalidVaaVersion",
570
+ "msg": "Invalid VAA version"
571
+ },
572
+ {
573
+ "code": 6011,
574
+ "name": "GuardianSetMismatch",
575
+ "msg": "Guardian set version in the VAA doesn't match the guardian set passed"
576
+ },
577
+ {
578
+ "code": 6012,
579
+ "name": "InvalidGuardianOrder",
580
+ "msg": "Guardian signature indices must be increasing"
581
+ },
582
+ {
583
+ "code": 6013,
584
+ "name": "InvalidGuardianIndex",
585
+ "msg": "Guardian index exceeds the number of guardians in the set"
586
+ },
587
+ {
588
+ "code": 6014,
589
+ "name": "InvalidSignature",
590
+ "msg": "A VAA signature is invalid"
591
+ },
592
+ {
593
+ "code": 6015,
594
+ "name": "InvalidGuardianKeyRecovery",
595
+ "msg": "The recovered guardian public key doesn't match the guardian set"
596
+ },
597
+ {
598
+ "code": 6016,
599
+ "name": "WrongGuardianSetOwner",
600
+ "msg": "The guardian set account is owned by the wrong program"
601
+ },
602
+ {
603
+ "code": 6017,
604
+ "name": "InvalidGuardianSetPda",
605
+ "msg": "The Guardian Set account doesn't match the PDA derivation"
606
+ },
607
+ {
608
+ "code": 6018,
609
+ "name": "GuardianSetExpired",
610
+ "msg": "The Guardian Set is expired"
611
+ },
612
+ {
613
+ "code": 6019,
614
+ "name": "GovernanceAuthorityMismatch",
615
+ "msg": "The signer is not authorized to perform this governance action"
616
+ },
617
+ {
618
+ "code": 6020,
619
+ "name": "TargetGovernanceAuthorityMismatch",
620
+ "msg": "The signer is not authorized to accept the governance authority"
621
+ },
622
+ {
623
+ "code": 6021,
624
+ "name": "NonexistentGovernanceAuthorityTransferRequest",
625
+ "msg": "The governance authority needs to request a transfer first"
626
+ }
627
+ ]
628
+ }
@@ -1,5 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { BN } from '@coral-xyz/anchor';
3
3
  import { SpotMarketAccount, PerpMarketAccount } from '..';
4
+ export declare function calculateInsuranceFuelBonus(spotMarket: SpotMarketAccount, tokenStakeAmount: BN, fuelBonusNumerator: BN): BN;
4
5
  export declare function calculateSpotFuelBonus(spotMarket: SpotMarketAccount, signedTokenValue: BN, fuelBonusNumerator: BN): BN;
5
6
  export declare function calculatePerpFuelBonus(perpMarket: PerpMarketAccount, baseAssetValue: BN, fuelBonusNumerator: BN): BN;
package/lib/math/fuel.js CHANGED
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculatePerpFuelBonus = exports.calculateSpotFuelBonus = void 0;
3
+ exports.calculatePerpFuelBonus = exports.calculateSpotFuelBonus = exports.calculateInsuranceFuelBonus = void 0;
4
4
  const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
+ function calculateInsuranceFuelBonus(spotMarket, tokenStakeAmount, fuelBonusNumerator) {
7
+ const result = tokenStakeAmount
8
+ .abs()
9
+ .mul(fuelBonusNumerator)
10
+ .mul(new anchor_1.BN(spotMarket.fuelBoostInsurance))
11
+ .div(numericConstants_1.FUEL_WINDOW)
12
+ .div(numericConstants_1.QUOTE_PRECISION.div(new anchor_1.BN(10)));
13
+ return result;
14
+ }
15
+ exports.calculateInsuranceFuelBonus = calculateInsuranceFuelBonus;
6
16
  function calculateSpotFuelBonus(spotMarket, signedTokenValue, fuelBonusNumerator) {
7
17
  let result;
8
- if (signedTokenValue.abs().lt(new anchor_1.BN(1))) {
18
+ if (signedTokenValue.abs().lte(numericConstants_1.QUOTE_PRECISION)) {
9
19
  result = numericConstants_1.ZERO;
10
20
  }
11
21
  else if (signedTokenValue.gt(new anchor_1.BN(0))) {