@drift-labs/sdk 2.86.0-beta.3 → 2.86.0-beta.31
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/VERSION +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +8 -0
- package/lib/adminClient.js +79 -0
- package/lib/bankrun/bankrunConnection.d.ts +1 -0
- package/lib/bankrun/bankrunConnection.js +6 -0
- package/lib/constants/numericConstants.d.ts +3 -0
- package/lib/constants/numericConstants.js +4 -1
- package/lib/constants/perpMarkets.js +142 -118
- package/lib/constants/spotMarkets.js +50 -38
- package/lib/driftClient.d.ts +12 -14
- package/lib/driftClient.js +144 -9
- package/lib/idl/drift.json +551 -4
- package/lib/idl/pyth_solana_receiver.json +628 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/fuel.d.ts +6 -0
- package/lib/math/fuel.js +55 -0
- package/lib/types.d.ts +35 -2
- package/lib/types.js +3 -2
- package/lib/user.d.ts +8 -0
- package/lib/user.js +64 -0
- package/package.json +1 -1
- package/src/addresses/pda.ts +15 -0
- package/src/adminClient.ts +208 -0
- package/src/bankrun/bankrunConnection.ts +13 -0
- package/src/constants/numericConstants.ts +4 -0
- package/src/constants/perpMarkets.ts +146 -118
- package/src/constants/spotMarkets.ts +52 -38
- package/src/driftClient.ts +197 -16
- package/src/idl/drift.json +551 -4
- package/src/idl/openbook.json +3854 -0
- package/src/idl/pyth_solana_receiver.json +628 -0
- package/src/index.ts +1 -0
- package/src/math/fuel.ts +70 -0
- package/src/types.ts +42 -2
- package/src/user.ts +177 -0
- package/tests/ci/verifyConstants.ts +214 -0
- package/tests/dlob/helpers.ts +30 -0
- package/tests/user/helpers.ts +1 -0
- package/tests/user/test.ts +2 -0
|
@@ -44,8 +44,8 @@ exports.MainnetSpotMarkets = [
|
|
|
44
44
|
{
|
|
45
45
|
symbol: 'USDC',
|
|
46
46
|
marketIndex: 0,
|
|
47
|
-
oracle: new web3_js_1.PublicKey('
|
|
48
|
-
oracleSource: __1.OracleSource.
|
|
47
|
+
oracle: new web3_js_1.PublicKey('En8hkHLkRe9d9DraYmBTrus518BvmVH448YcvmrFM6Ce'),
|
|
48
|
+
oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
|
|
49
49
|
mint: new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
|
|
50
50
|
precision: numericConstants_1.QUOTE_PRECISION,
|
|
51
51
|
precisionExp: numericConstants_1.QUOTE_PRECISION_EXP,
|
|
@@ -54,8 +54,8 @@ exports.MainnetSpotMarkets = [
|
|
|
54
54
|
{
|
|
55
55
|
symbol: 'SOL',
|
|
56
56
|
marketIndex: 1,
|
|
57
|
-
oracle: new web3_js_1.PublicKey('
|
|
58
|
-
oracleSource: __1.OracleSource.
|
|
57
|
+
oracle: new web3_js_1.PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
|
|
58
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
59
59
|
mint: new web3_js_1.PublicKey(exports.WRAPPED_SOL_MINT),
|
|
60
60
|
precision: numericConstants_1.LAMPORTS_PRECISION,
|
|
61
61
|
precisionExp: numericConstants_1.LAMPORTS_EXP,
|
|
@@ -66,8 +66,8 @@ exports.MainnetSpotMarkets = [
|
|
|
66
66
|
{
|
|
67
67
|
symbol: 'mSOL',
|
|
68
68
|
marketIndex: 2,
|
|
69
|
-
oracle: new web3_js_1.PublicKey('
|
|
70
|
-
oracleSource: __1.OracleSource.
|
|
69
|
+
oracle: new web3_js_1.PublicKey('FAq7hqjn7FWGXKDwJHzsXGgBcydGTcK4kziJpAGWXjDb'),
|
|
70
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
71
71
|
mint: new web3_js_1.PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'),
|
|
72
72
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
73
73
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -77,8 +77,8 @@ exports.MainnetSpotMarkets = [
|
|
|
77
77
|
{
|
|
78
78
|
symbol: 'wBTC',
|
|
79
79
|
marketIndex: 3,
|
|
80
|
-
oracle: new web3_js_1.PublicKey('
|
|
81
|
-
oracleSource: __1.OracleSource.
|
|
80
|
+
oracle: new web3_js_1.PublicKey('486kr3pmFPfTsS4aZgcsQ7kS4i9rjMsYYZup6HQNSTT4'),
|
|
81
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
82
82
|
mint: new web3_js_1.PublicKey('3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh'),
|
|
83
83
|
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
84
84
|
precisionExp: numericConstants_1.EIGHT,
|
|
@@ -88,8 +88,8 @@ exports.MainnetSpotMarkets = [
|
|
|
88
88
|
{
|
|
89
89
|
symbol: 'wETH',
|
|
90
90
|
marketIndex: 4,
|
|
91
|
-
oracle: new web3_js_1.PublicKey('
|
|
92
|
-
oracleSource: __1.OracleSource.
|
|
91
|
+
oracle: new web3_js_1.PublicKey('6bEp2MiyoiiiDxcVqE8rUHQWwHirXUXtKfAEATTVqNzT'),
|
|
92
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
93
93
|
mint: new web3_js_1.PublicKey('7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs'),
|
|
94
94
|
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
95
95
|
precisionExp: numericConstants_1.EIGHT,
|
|
@@ -100,8 +100,8 @@ exports.MainnetSpotMarkets = [
|
|
|
100
100
|
{
|
|
101
101
|
symbol: 'USDT',
|
|
102
102
|
marketIndex: 5,
|
|
103
|
-
oracle: new web3_js_1.PublicKey('
|
|
104
|
-
oracleSource: __1.OracleSource.
|
|
103
|
+
oracle: new web3_js_1.PublicKey('BekJ3P5G3iFeC97sXHuKnUHofCFj9Sbo7uyF2fkKwvit'),
|
|
104
|
+
oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
|
|
105
105
|
mint: new web3_js_1.PublicKey('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'),
|
|
106
106
|
precision: numericConstants_1.QUOTE_PRECISION,
|
|
107
107
|
precisionExp: numericConstants_1.QUOTE_PRECISION_EXP,
|
|
@@ -111,8 +111,8 @@ exports.MainnetSpotMarkets = [
|
|
|
111
111
|
{
|
|
112
112
|
symbol: 'jitoSOL',
|
|
113
113
|
marketIndex: 6,
|
|
114
|
-
oracle: new web3_js_1.PublicKey('
|
|
115
|
-
oracleSource: __1.OracleSource.
|
|
114
|
+
oracle: new web3_js_1.PublicKey('9QE1P5EfzthYDgoQ9oPeTByCEKaRJeZbVVqKJfgU9iau'),
|
|
115
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
116
116
|
mint: new web3_js_1.PublicKey('J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn'),
|
|
117
117
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
118
118
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -123,8 +123,8 @@ exports.MainnetSpotMarkets = [
|
|
|
123
123
|
{
|
|
124
124
|
symbol: 'PYTH',
|
|
125
125
|
marketIndex: 7,
|
|
126
|
-
oracle: new web3_js_1.PublicKey('
|
|
127
|
-
oracleSource: __1.OracleSource.
|
|
126
|
+
oracle: new web3_js_1.PublicKey('GqkCu7CbsPVz1H6W6AAHuReqbJckYG59TXz7Y5HDV7hr'),
|
|
127
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
128
128
|
mint: new web3_js_1.PublicKey('HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3'),
|
|
129
129
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
130
130
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -135,8 +135,8 @@ exports.MainnetSpotMarkets = [
|
|
|
135
135
|
{
|
|
136
136
|
symbol: 'bSOL',
|
|
137
137
|
marketIndex: 8,
|
|
138
|
-
oracle: new web3_js_1.PublicKey('
|
|
139
|
-
oracleSource: __1.OracleSource.
|
|
138
|
+
oracle: new web3_js_1.PublicKey('BmDWPMsytWmYkh9n6o7m79eVshVYf2B5GVaqQ2EWKnGH'),
|
|
139
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
140
140
|
mint: new web3_js_1.PublicKey('bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1'),
|
|
141
141
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
142
142
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -146,8 +146,8 @@ exports.MainnetSpotMarkets = [
|
|
|
146
146
|
{
|
|
147
147
|
symbol: 'JTO',
|
|
148
148
|
marketIndex: 9,
|
|
149
|
-
oracle: new web3_js_1.PublicKey('
|
|
150
|
-
oracleSource: __1.OracleSource.
|
|
149
|
+
oracle: new web3_js_1.PublicKey('Ffq6ACJ17NAgaxC6ocfMzVXL3K61qxB2xHg6WUawWPfP'),
|
|
150
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
151
151
|
mint: new web3_js_1.PublicKey('jtojtomepa8beP8AuQc6eXt5FriJwfFMwQx2v2f9mCL'),
|
|
152
152
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
153
153
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -158,8 +158,8 @@ exports.MainnetSpotMarkets = [
|
|
|
158
158
|
{
|
|
159
159
|
symbol: 'WIF',
|
|
160
160
|
marketIndex: 10,
|
|
161
|
-
oracle: new web3_js_1.PublicKey('
|
|
162
|
-
oracleSource: __1.OracleSource.
|
|
161
|
+
oracle: new web3_js_1.PublicKey('6x6KfE7nY2xoLCRSMPT1u83wQ5fpGXoKNBqFjrCwzsCQ'),
|
|
162
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
163
163
|
mint: new web3_js_1.PublicKey('EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm'),
|
|
164
164
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
165
165
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -170,8 +170,8 @@ exports.MainnetSpotMarkets = [
|
|
|
170
170
|
{
|
|
171
171
|
symbol: 'JUP',
|
|
172
172
|
marketIndex: 11,
|
|
173
|
-
oracle: new web3_js_1.PublicKey('
|
|
174
|
-
oracleSource: __1.OracleSource.
|
|
173
|
+
oracle: new web3_js_1.PublicKey('AwqRpfJ36jnSZQykyL1jYY35mhMteeEAjh7o8LveRQin'),
|
|
174
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
175
175
|
mint: new web3_js_1.PublicKey('JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN'),
|
|
176
176
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
177
177
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -182,8 +182,8 @@ exports.MainnetSpotMarkets = [
|
|
|
182
182
|
{
|
|
183
183
|
symbol: 'RNDR',
|
|
184
184
|
marketIndex: 12,
|
|
185
|
-
oracle: new web3_js_1.PublicKey('
|
|
186
|
-
oracleSource: __1.OracleSource.
|
|
185
|
+
oracle: new web3_js_1.PublicKey('F3mPHRtJqqq57JPDBmUwUVhpyPLmjE5dAzDfpVgpFkug'),
|
|
186
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
187
187
|
mint: new web3_js_1.PublicKey('rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof'),
|
|
188
188
|
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
189
189
|
precisionExp: numericConstants_1.EIGHT,
|
|
@@ -194,8 +194,8 @@ exports.MainnetSpotMarkets = [
|
|
|
194
194
|
{
|
|
195
195
|
symbol: 'W',
|
|
196
196
|
marketIndex: 13,
|
|
197
|
-
oracle: new web3_js_1.PublicKey('
|
|
198
|
-
oracleSource: __1.OracleSource.
|
|
197
|
+
oracle: new web3_js_1.PublicKey('4HbitGsdcFbtFotmYscikQFAAKJ3nYx4t7sV7fTvsk8U'),
|
|
198
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
199
199
|
mint: new web3_js_1.PublicKey('85VBFQZC9TZkfaptBWjvUw7YbZjy52A6mjtPGjstQAmQ'),
|
|
200
200
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
201
201
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -206,8 +206,8 @@ exports.MainnetSpotMarkets = [
|
|
|
206
206
|
{
|
|
207
207
|
symbol: 'TNSR',
|
|
208
208
|
marketIndex: 14,
|
|
209
|
-
oracle: new web3_js_1.PublicKey('
|
|
210
|
-
oracleSource: __1.OracleSource.
|
|
209
|
+
oracle: new web3_js_1.PublicKey('13jpjpVyU5hGpjsZ4HzCcmBo85wze4N8Au7U6cC3GMip'),
|
|
210
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
211
211
|
mint: new web3_js_1.PublicKey('TNSRxcUxoT9xBG3de7PiJyTDYu7kskLqcpddxnEJAS6'),
|
|
212
212
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
213
213
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -218,8 +218,8 @@ exports.MainnetSpotMarkets = [
|
|
|
218
218
|
{
|
|
219
219
|
symbol: 'DRIFT',
|
|
220
220
|
marketIndex: 15,
|
|
221
|
-
oracle: new web3_js_1.PublicKey('
|
|
222
|
-
oracleSource: __1.OracleSource.
|
|
221
|
+
oracle: new web3_js_1.PublicKey('23KmX7SNikmUr2axSCy6Zer7XPBnvmVcASALnDGqBVRR'),
|
|
222
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
223
223
|
mint: new web3_js_1.PublicKey('DriFtupJYLTosbwoN8koMbEYSx54aFAVLddWsbksjwg7'),
|
|
224
224
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
225
225
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -230,8 +230,8 @@ exports.MainnetSpotMarkets = [
|
|
|
230
230
|
{
|
|
231
231
|
symbol: 'INF',
|
|
232
232
|
marketIndex: 16,
|
|
233
|
-
oracle: new web3_js_1.PublicKey('
|
|
234
|
-
oracleSource: __1.OracleSource.
|
|
233
|
+
oracle: new web3_js_1.PublicKey('B7RUYg2zF6UdUSHv2RmpnriPVJccYWojgFydNS1NY5F8'),
|
|
234
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
235
235
|
mint: new web3_js_1.PublicKey('5oVNBeEEQvYi1cX3ir8Dx5n1P7pdxydbGF2X4TxVusJm'),
|
|
236
236
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
237
237
|
precisionExp: numericConstants_1.NINE,
|
|
@@ -251,12 +251,13 @@ exports.MainnetSpotMarkets = [
|
|
|
251
251
|
{
|
|
252
252
|
symbol: 'USDY',
|
|
253
253
|
marketIndex: 18,
|
|
254
|
-
oracle: new web3_js_1.PublicKey('
|
|
255
|
-
oracleSource: __1.OracleSource.
|
|
254
|
+
oracle: new web3_js_1.PublicKey('BPTQgHV4y2x4jvKPPkkd9aS8jY7L3DGZBwjEZC8Vm27o'),
|
|
255
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
256
256
|
mint: new web3_js_1.PublicKey('A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6'),
|
|
257
257
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
258
258
|
precisionExp: numericConstants_1.SIX,
|
|
259
259
|
launchTs: 1718811089000,
|
|
260
|
+
pythFeedId: '0xe393449f6aff8a4b6d3e1165a7c9ebec103685f3b41e60db4277b5b6d10e7326',
|
|
260
261
|
},
|
|
261
262
|
{
|
|
262
263
|
symbol: 'JLP',
|
|
@@ -271,13 +272,24 @@ exports.MainnetSpotMarkets = [
|
|
|
271
272
|
{
|
|
272
273
|
symbol: 'POPCAT',
|
|
273
274
|
marketIndex: 20,
|
|
274
|
-
oracle: new web3_js_1.PublicKey('
|
|
275
|
-
oracleSource: __1.OracleSource.
|
|
275
|
+
oracle: new web3_js_1.PublicKey('H3pn43tkNvsG5z3qzmERguSvKoyHZvvY6VPmNrJqiW5X'),
|
|
276
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
276
277
|
mint: new web3_js_1.PublicKey('7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr'),
|
|
277
278
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
278
279
|
precisionExp: numericConstants_1.NINE,
|
|
279
280
|
launchTs: 1720013054000,
|
|
280
281
|
phoenixMarket: new web3_js_1.PublicKey('31XgvAQ1HgFQEk31KdszbPkVXKaQqB1bgYZPoDrFpSR2'),
|
|
282
|
+
pythFeedId: '0xb9312a7ee50e189ef045aa3c7842e099b061bd9bdc99ac645956c3b660dc8cce',
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
symbol: 'CLOUD',
|
|
286
|
+
marketIndex: 21,
|
|
287
|
+
oracle: new web3_js_1.PublicKey('4FG7UyPkszGvcSVCCKaLSZsArGjyxitwhJeQhYu2bFTS'),
|
|
288
|
+
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
289
|
+
mint: new web3_js_1.PublicKey('CLoUDKc4Ane7HeQcPpE3YHnznRxhMimJ4MyaUqyHFzAu'),
|
|
290
|
+
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
291
|
+
precisionExp: numericConstants_1.NINE,
|
|
292
|
+
launchTs: 1721316817000,
|
|
281
293
|
},
|
|
282
294
|
];
|
|
283
295
|
exports.SpotMarkets = {
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
5
|
-
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord } from './types';
|
|
5
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord, OpenbookV2FulfillmentConfigAccount } from './types';
|
|
6
6
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
|
-
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta,
|
|
7
|
+
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
8
8
|
import { TokenFaucet } from './tokenFaucet';
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
10
10
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -107,6 +107,8 @@ export declare class DriftClient {
|
|
|
107
107
|
getSerumV3FulfillmentConfigs(): Promise<SerumV3FulfillmentConfigAccount[]>;
|
|
108
108
|
getPhoenixV1FulfillmentConfig(phoenixMarket: PublicKey): Promise<PhoenixV1FulfillmentConfigAccount>;
|
|
109
109
|
getPhoenixV1FulfillmentConfigs(): Promise<PhoenixV1FulfillmentConfigAccount[]>;
|
|
110
|
+
getOpenbookV2FulfillmentConfig(openbookMarket: PublicKey): Promise<OpenbookV2FulfillmentConfigAccount>;
|
|
111
|
+
getOpenbookV2FulfillmentConfigs(): Promise<OpenbookV2FulfillmentConfigAccount[]>;
|
|
110
112
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
111
113
|
/**
|
|
112
114
|
* Update the wallet to use for drift transactions and linked user account
|
|
@@ -357,11 +359,12 @@ export declare class DriftClient {
|
|
|
357
359
|
placeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
|
|
358
360
|
}>;
|
|
359
361
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
|
|
360
|
-
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
361
|
-
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
362
|
-
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
|
|
362
|
+
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
363
|
+
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
364
|
+
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount): void;
|
|
363
365
|
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
364
366
|
addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
|
|
367
|
+
addOpenbookRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: OpenbookV2FulfillmentConfigAccount): void;
|
|
365
368
|
/**
|
|
366
369
|
* Swap tokens in drift account using jupiter
|
|
367
370
|
* @param jupiterClient jupiter client to find routes and jupiter instructions
|
|
@@ -712,14 +715,9 @@ export declare class DriftClient {
|
|
|
712
715
|
} | undefined;
|
|
713
716
|
getReceiverProgram(): Program<PythSolanaReceiver>;
|
|
714
717
|
postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
merklePriceUpdate: {
|
|
719
|
-
message: Buffer;
|
|
720
|
-
proof: number[][];
|
|
721
|
-
};
|
|
722
|
-
}, feedId: string, guardianSet: PublicKey): Promise<TransactionInstruction>;
|
|
718
|
+
postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
|
|
719
|
+
getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
|
|
720
|
+
private getSinglePostPythPullOracleAtomicIx;
|
|
723
721
|
updatePythPullOracle(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
724
722
|
getUpdatePythPullOracleIxs(params: {
|
|
725
723
|
merklePriceUpdate: {
|
|
@@ -727,7 +725,7 @@ export declare class DriftClient {
|
|
|
727
725
|
proof: number[][];
|
|
728
726
|
};
|
|
729
727
|
}, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
|
|
730
|
-
getBuildEncodedVaaIxs
|
|
728
|
+
private getBuildEncodedVaaIxs;
|
|
731
729
|
private handleSignedTransaction;
|
|
732
730
|
private handlePreSignedTransaction;
|
|
733
731
|
private isVersionedTransaction;
|
package/lib/driftClient.js
CHANGED
|
@@ -64,6 +64,7 @@ const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
|
|
|
64
64
|
const config_2 = require("./config");
|
|
65
65
|
const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
|
|
66
66
|
const utils_2 = require("./tx/utils");
|
|
67
|
+
const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
|
|
67
68
|
/**
|
|
68
69
|
* # DriftClient
|
|
69
70
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -323,6 +324,14 @@ class DriftClient {
|
|
|
323
324
|
const accounts = await this.program.account.phoenixV1FulfillmentConfig.all();
|
|
324
325
|
return accounts.map((account) => account.account);
|
|
325
326
|
}
|
|
327
|
+
async getOpenbookV2FulfillmentConfig(openbookMarket) {
|
|
328
|
+
const address = (0, pda_1.getOpenbookV2FulfillmentConfigPublicKey)(this.program.programId, openbookMarket);
|
|
329
|
+
return (await this.program.account.openbookV2FulfillmentConfig.fetch(address));
|
|
330
|
+
}
|
|
331
|
+
async getOpenbookV2FulfillmentConfigs() {
|
|
332
|
+
const accounts = await this.program.account.openbookV2FulfillmentConfig.all();
|
|
333
|
+
return accounts.map((account) => account.account);
|
|
334
|
+
}
|
|
326
335
|
async fetchMarketLookupTableAccount() {
|
|
327
336
|
if (this.lookupTableAccount)
|
|
328
337
|
return this.lookupTableAccount;
|
|
@@ -2009,6 +2018,9 @@ class DriftClient {
|
|
|
2009
2018
|
else if ('phoenixProgramId' in fulfillmentConfig) {
|
|
2010
2019
|
this.addPhoenixRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
|
|
2011
2020
|
}
|
|
2021
|
+
else if ('openbookV2ProgramId' in fulfillmentConfig) {
|
|
2022
|
+
this.addOpenbookRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
|
|
2023
|
+
}
|
|
2012
2024
|
else {
|
|
2013
2025
|
throw Error('Invalid fulfillment config type');
|
|
2014
2026
|
}
|
|
@@ -2160,6 +2172,97 @@ class DriftClient {
|
|
|
2160
2172
|
isSigner: false,
|
|
2161
2173
|
});
|
|
2162
2174
|
}
|
|
2175
|
+
addOpenbookRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig) {
|
|
2176
|
+
remainingAccounts.push({
|
|
2177
|
+
pubkey: fulfillmentConfig.pubkey,
|
|
2178
|
+
isWritable: false,
|
|
2179
|
+
isSigner: false,
|
|
2180
|
+
});
|
|
2181
|
+
remainingAccounts.push({
|
|
2182
|
+
pubkey: this.getSignerPublicKey(),
|
|
2183
|
+
isWritable: true,
|
|
2184
|
+
isSigner: false,
|
|
2185
|
+
});
|
|
2186
|
+
remainingAccounts.push({
|
|
2187
|
+
pubkey: fulfillmentConfig.openbookV2ProgramId,
|
|
2188
|
+
isWritable: false,
|
|
2189
|
+
isSigner: false,
|
|
2190
|
+
});
|
|
2191
|
+
remainingAccounts.push({
|
|
2192
|
+
pubkey: fulfillmentConfig.openbookV2Market,
|
|
2193
|
+
isWritable: true,
|
|
2194
|
+
isSigner: false,
|
|
2195
|
+
});
|
|
2196
|
+
remainingAccounts.push({
|
|
2197
|
+
pubkey: fulfillmentConfig.openbookV2MarketAuthority,
|
|
2198
|
+
isWritable: false,
|
|
2199
|
+
isSigner: false,
|
|
2200
|
+
});
|
|
2201
|
+
remainingAccounts.push({
|
|
2202
|
+
pubkey: fulfillmentConfig.openbookV2EventHeap,
|
|
2203
|
+
isWritable: true,
|
|
2204
|
+
isSigner: false,
|
|
2205
|
+
});
|
|
2206
|
+
remainingAccounts.push({
|
|
2207
|
+
pubkey: fulfillmentConfig.openbookV2Bids,
|
|
2208
|
+
isWritable: true,
|
|
2209
|
+
isSigner: false,
|
|
2210
|
+
});
|
|
2211
|
+
remainingAccounts.push({
|
|
2212
|
+
pubkey: fulfillmentConfig.openbookV2Asks,
|
|
2213
|
+
isWritable: true,
|
|
2214
|
+
isSigner: false,
|
|
2215
|
+
});
|
|
2216
|
+
remainingAccounts.push({
|
|
2217
|
+
pubkey: fulfillmentConfig.openbookV2BaseVault,
|
|
2218
|
+
isWritable: true,
|
|
2219
|
+
isSigner: false,
|
|
2220
|
+
});
|
|
2221
|
+
remainingAccounts.push({
|
|
2222
|
+
pubkey: fulfillmentConfig.openbookV2QuoteVault,
|
|
2223
|
+
isWritable: true,
|
|
2224
|
+
isSigner: false,
|
|
2225
|
+
});
|
|
2226
|
+
remainingAccounts.push({
|
|
2227
|
+
pubkey: this.getSpotMarketAccount(marketIndex).vault,
|
|
2228
|
+
isWritable: true,
|
|
2229
|
+
isSigner: false,
|
|
2230
|
+
});
|
|
2231
|
+
remainingAccounts.push({
|
|
2232
|
+
pubkey: this.getQuoteSpotMarketAccount().vault,
|
|
2233
|
+
isWritable: true,
|
|
2234
|
+
isSigner: false,
|
|
2235
|
+
});
|
|
2236
|
+
remainingAccounts.push({
|
|
2237
|
+
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2238
|
+
isWritable: false,
|
|
2239
|
+
isSigner: false,
|
|
2240
|
+
});
|
|
2241
|
+
remainingAccounts.push({
|
|
2242
|
+
pubkey: web3_js_1.SystemProgram.programId,
|
|
2243
|
+
isWritable: false,
|
|
2244
|
+
isSigner: false,
|
|
2245
|
+
});
|
|
2246
|
+
remainingAccounts.push({
|
|
2247
|
+
pubkey: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
2248
|
+
isWritable: true,
|
|
2249
|
+
isSigner: false,
|
|
2250
|
+
});
|
|
2251
|
+
remainingAccounts.push({
|
|
2252
|
+
pubkey: this.getQuoteSpotMarketAccount().pubkey,
|
|
2253
|
+
isWritable: true,
|
|
2254
|
+
isSigner: false,
|
|
2255
|
+
});
|
|
2256
|
+
if (fulfillmentConfig.remainingAccounts) {
|
|
2257
|
+
for (const remainingAccount of fulfillmentConfig.remainingAccounts) {
|
|
2258
|
+
remainingAccounts.push({
|
|
2259
|
+
pubkey: remainingAccount,
|
|
2260
|
+
isWritable: true,
|
|
2261
|
+
isSigner: false,
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2163
2266
|
/**
|
|
2164
2267
|
* Swap tokens in drift account using jupiter
|
|
2165
2268
|
* @param jupiterClient jupiter client to find routes and jupiter instructions
|
|
@@ -2281,9 +2384,6 @@ class DriftClient {
|
|
|
2281
2384
|
async getJupiterSwapIxV6({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }) {
|
|
2282
2385
|
const outMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
2283
2386
|
const inMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
2284
|
-
const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
|
|
2285
|
-
const amountIn = new anchor_1.BN(quote.inAmount);
|
|
2286
|
-
const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer
|
|
2287
2387
|
if (!quote) {
|
|
2288
2388
|
const fetchedQuote = await jupiterClient.getQuote({
|
|
2289
2389
|
inputMint: inMarket.mint,
|
|
@@ -2298,6 +2398,9 @@ class DriftClient {
|
|
|
2298
2398
|
if (!quote) {
|
|
2299
2399
|
throw new Error("Could not fetch Jupiter's quote. Please try again.");
|
|
2300
2400
|
}
|
|
2401
|
+
const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
|
|
2402
|
+
const amountIn = new anchor_1.BN(quote.inAmount);
|
|
2403
|
+
const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer
|
|
2301
2404
|
const transaction = await jupiterClient.getSwap({
|
|
2302
2405
|
quote,
|
|
2303
2406
|
userPublicKey: this.provider.wallet.publicKey,
|
|
@@ -3641,7 +3744,7 @@ class DriftClient {
|
|
|
3641
3744
|
}
|
|
3642
3745
|
getReceiverProgram() {
|
|
3643
3746
|
if (this.receiverProgram === undefined) {
|
|
3644
|
-
this.receiverProgram = new anchor_1.Program(
|
|
3747
|
+
this.receiverProgram = new anchor_1.Program(pyth_solana_receiver_json_1.default, pyth_solana_receiver_1.DEFAULT_RECEIVER_PROGRAM_ID, this.provider);
|
|
3645
3748
|
}
|
|
3646
3749
|
return this.receiverProgram;
|
|
3647
3750
|
}
|
|
@@ -3651,18 +3754,50 @@ class DriftClient {
|
|
|
3651
3754
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3652
3755
|
return txSig;
|
|
3653
3756
|
}
|
|
3654
|
-
async
|
|
3655
|
-
|
|
3757
|
+
async postMultiPythPullOracleUpdatesAtomic(vaaString, feedIds) {
|
|
3758
|
+
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(vaaString, feedIds);
|
|
3759
|
+
const tx = await this.buildTransaction(postIxs);
|
|
3760
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3761
|
+
return txSig;
|
|
3762
|
+
}
|
|
3763
|
+
async getPostPythPullOracleUpdateAtomicIxs(vaaString, feedIds, numSignatures = 2) {
|
|
3656
3764
|
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(vaaString, 'base64'));
|
|
3657
3765
|
const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
|
|
3658
3766
|
const guardianSet = (0, address_1.getGuardianSetPda)(guardianSetIndex, address_1.DEFAULT_WORMHOLE_PROGRAM_ID);
|
|
3659
3767
|
const trimmedVaa = (0, oracles_1.trimVaaSignatures)(accumulatorUpdateData.vaa, numSignatures);
|
|
3660
3768
|
const postIxs = [];
|
|
3661
|
-
|
|
3769
|
+
if (accumulatorUpdateData.updates.length > 1) {
|
|
3770
|
+
const encodedParams = this.getReceiverProgram().coder.types.encode('PostMultiUpdatesAtomicParams', {
|
|
3771
|
+
vaa: trimmedVaa,
|
|
3772
|
+
merklePriceUpdates: accumulatorUpdateData.updates,
|
|
3773
|
+
});
|
|
3774
|
+
const feedIdsToUse = typeof feedIds === 'string' ? [feedIds] : feedIds;
|
|
3775
|
+
const pubkeys = feedIdsToUse.map((feedId) => {
|
|
3776
|
+
return (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, (0, pythPullOracleUtils_1.getFeedIdUint8Array)(feedId));
|
|
3777
|
+
});
|
|
3778
|
+
const remainingAccounts = pubkeys.map((pubkey) => {
|
|
3779
|
+
return {
|
|
3780
|
+
pubkey,
|
|
3781
|
+
isSigner: false,
|
|
3782
|
+
isWritable: true,
|
|
3783
|
+
};
|
|
3784
|
+
});
|
|
3785
|
+
postIxs.push(this.program.instruction.postMultiPythPullOracleUpdatesAtomic(encodedParams, {
|
|
3786
|
+
accounts: {
|
|
3787
|
+
keeper: this.wallet.publicKey,
|
|
3788
|
+
pythSolanaReceiver: config_2.DRIFT_ORACLE_RECEIVER_ID,
|
|
3789
|
+
guardianSet,
|
|
3790
|
+
},
|
|
3791
|
+
remainingAccounts,
|
|
3792
|
+
}));
|
|
3793
|
+
}
|
|
3794
|
+
else {
|
|
3795
|
+
let feedIdToUse = typeof feedIds === 'string' ? feedIds : feedIds[0];
|
|
3796
|
+
feedIdToUse = (0, pythPullOracleUtils_1.trimFeedId)(feedIdToUse);
|
|
3662
3797
|
postIxs.push(await this.getSinglePostPythPullOracleAtomicIx({
|
|
3663
3798
|
vaa: trimmedVaa,
|
|
3664
|
-
merklePriceUpdate:
|
|
3665
|
-
},
|
|
3799
|
+
merklePriceUpdate: accumulatorUpdateData.updates[0],
|
|
3800
|
+
}, feedIdToUse, guardianSet));
|
|
3666
3801
|
}
|
|
3667
3802
|
return postIxs;
|
|
3668
3803
|
}
|