@drift-labs/sdk 2.86.0-beta.2 → 2.86.0-beta.21
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/accounts/pollingDriftClientAccountSubscriber.js +24 -16
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +25 -32
- package/lib/adminClient.d.ts +6 -0
- package/lib/adminClient.js +55 -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 +125 -101
- package/lib/constants/spotMarkets.js +19 -18
- package/lib/idl/drift.json +331 -4
- 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 +17 -0
- package/lib/user.d.ts +8 -0
- package/lib/user.js +59 -0
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +38 -23
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +55 -38
- package/src/adminClient.ts +159 -0
- package/src/bankrun/bankrunConnection.ts +13 -0
- package/src/constants/numericConstants.ts +4 -0
- package/src/constants/perpMarkets.ts +129 -101
- package/src/constants/spotMarkets.ts +20 -18
- package/src/idl/drift.json +331 -4
- package/src/index.ts +1 -0
- package/src/math/fuel.ts +70 -0
- package/src/types.ts +22 -0
- package/src/user.ts +154 -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
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.86.0-beta.
|
|
1
|
+
2.86.0-beta.21
|
|
@@ -47,7 +47,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
47
47
|
this.oracleInfos = oracleInfos;
|
|
48
48
|
}
|
|
49
49
|
await this.updateAccountsToPoll();
|
|
50
|
-
|
|
50
|
+
this.updateOraclesToPoll();
|
|
51
51
|
await this.addToAccountLoader();
|
|
52
52
|
let subscriptionSucceeded = false;
|
|
53
53
|
let retries = 0;
|
|
@@ -59,8 +59,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
59
59
|
if (subscriptionSucceeded) {
|
|
60
60
|
this.eventEmitter.emit('update');
|
|
61
61
|
}
|
|
62
|
-
await this.setPerpOracleMap();
|
|
63
|
-
await this.setSpotOracleMap();
|
|
62
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
64
63
|
this.isSubscribing = false;
|
|
65
64
|
this.isSubscribed = subscriptionSucceeded;
|
|
66
65
|
this.subscriptionPromiseResolver(subscriptionSucceeded);
|
|
@@ -76,13 +75,15 @@ class PollingDriftClientAccountSubscriber {
|
|
|
76
75
|
publicKey: statePublicKey,
|
|
77
76
|
eventType: 'stateAccountUpdate',
|
|
78
77
|
});
|
|
79
|
-
await
|
|
80
|
-
|
|
78
|
+
await Promise.all([
|
|
79
|
+
this.updatePerpMarketAccountsToPoll(),
|
|
80
|
+
this.updateSpotMarketAccountsToPoll(),
|
|
81
|
+
]);
|
|
81
82
|
}
|
|
82
83
|
async updatePerpMarketAccountsToPoll() {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
84
|
+
await Promise.all(this.perpMarketIndexes.map((marketIndex) => {
|
|
85
|
+
return this.addPerpMarketAccountToPoll(marketIndex);
|
|
86
|
+
}));
|
|
86
87
|
return true;
|
|
87
88
|
}
|
|
88
89
|
async addPerpMarketAccountToPoll(marketIndex) {
|
|
@@ -96,9 +97,9 @@ class PollingDriftClientAccountSubscriber {
|
|
|
96
97
|
return true;
|
|
97
98
|
}
|
|
98
99
|
async updateSpotMarketAccountsToPoll() {
|
|
99
|
-
|
|
100
|
+
await Promise.all(this.spotMarketIndexes.map(async (marketIndex) => {
|
|
100
101
|
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
101
|
-
}
|
|
102
|
+
}));
|
|
102
103
|
return true;
|
|
103
104
|
}
|
|
104
105
|
async addSpotMarketAccountToPoll(marketIndex) {
|
|
@@ -127,12 +128,15 @@ class PollingDriftClientAccountSubscriber {
|
|
|
127
128
|
return true;
|
|
128
129
|
}
|
|
129
130
|
async addToAccountLoader() {
|
|
131
|
+
const accountPromises = [];
|
|
130
132
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
131
|
-
|
|
133
|
+
accountPromises.push(this.addAccountToAccountLoader(accountToPoll));
|
|
132
134
|
}
|
|
135
|
+
const oraclePromises = [];
|
|
133
136
|
for (const [_, oracleToPoll] of this.oraclesToPoll) {
|
|
134
|
-
|
|
137
|
+
oraclePromises.push(this.addOracleToAccountLoader(oracleToPoll));
|
|
135
138
|
}
|
|
139
|
+
await Promise.all([...accountPromises, ...oraclePromises]);
|
|
136
140
|
this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
|
|
137
141
|
this.eventEmitter.emit('error', error);
|
|
138
142
|
});
|
|
@@ -284,33 +288,37 @@ class PollingDriftClientAccountSubscriber {
|
|
|
284
288
|
}
|
|
285
289
|
async setPerpOracleMap() {
|
|
286
290
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
291
|
+
const oraclePromises = [];
|
|
287
292
|
for (const perpMarket of perpMarkets) {
|
|
288
293
|
const perpMarketAccount = perpMarket.data;
|
|
289
294
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
290
295
|
const oracle = perpMarketAccount.amm.oracle;
|
|
291
296
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
292
|
-
|
|
297
|
+
oraclePromises.push(this.addOracle({
|
|
293
298
|
publicKey: oracle,
|
|
294
299
|
source: perpMarketAccount.amm.oracleSource,
|
|
295
|
-
});
|
|
300
|
+
}));
|
|
296
301
|
}
|
|
297
302
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
298
303
|
}
|
|
304
|
+
await Promise.all(oraclePromises);
|
|
299
305
|
}
|
|
300
306
|
async setSpotOracleMap() {
|
|
301
307
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
308
|
+
const oraclePromises = [];
|
|
302
309
|
for (const spotMarket of spotMarkets) {
|
|
303
310
|
const spotMarketAccount = spotMarket.data;
|
|
304
311
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
305
312
|
const oracle = spotMarketAccount.oracle;
|
|
306
313
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
307
|
-
|
|
314
|
+
oraclePromises.push(this.addOracle({
|
|
308
315
|
publicKey: oracle,
|
|
309
316
|
source: spotMarketAccount.oracleSource,
|
|
310
|
-
});
|
|
317
|
+
}));
|
|
311
318
|
}
|
|
312
319
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
313
320
|
}
|
|
321
|
+
await Promise.all(oraclePromises);
|
|
314
322
|
}
|
|
315
323
|
assertIsSubscribed() {
|
|
316
324
|
if (!this.isSubscribed) {
|
|
@@ -52,24 +52,23 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
52
52
|
this.eventEmitter.emit('stateAccountUpdate', data);
|
|
53
53
|
this.eventEmitter.emit('update');
|
|
54
54
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
await Promise.all([
|
|
56
|
+
// subscribe to market accounts
|
|
57
|
+
this.subscribeToPerpMarketAccounts(),
|
|
58
|
+
// subscribe to spot market accounts
|
|
59
|
+
this.subscribeToSpotMarketAccounts(),
|
|
60
|
+
// subscribe to oracles
|
|
61
|
+
this.subscribeToOracles(),
|
|
62
|
+
]);
|
|
61
63
|
this.eventEmitter.emit('update');
|
|
62
|
-
await this.setPerpOracleMap();
|
|
63
|
-
await this.setSpotOracleMap();
|
|
64
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
64
65
|
this.isSubscribing = false;
|
|
65
66
|
this.isSubscribed = true;
|
|
66
67
|
this.subscriptionPromiseResolver(true);
|
|
67
68
|
return true;
|
|
68
69
|
}
|
|
69
70
|
async subscribeToPerpMarketAccounts() {
|
|
70
|
-
|
|
71
|
-
await this.subscribeToPerpMarketAccount(marketIndex);
|
|
72
|
-
}
|
|
71
|
+
await Promise.all(this.perpMarketIndexes.map((marketIndex) => this.subscribeToPerpMarketAccount(marketIndex)));
|
|
73
72
|
return true;
|
|
74
73
|
}
|
|
75
74
|
async subscribeToPerpMarketAccount(marketIndex) {
|
|
@@ -83,9 +82,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
83
82
|
return true;
|
|
84
83
|
}
|
|
85
84
|
async subscribeToSpotMarketAccounts() {
|
|
86
|
-
|
|
87
|
-
await this.subscribeToSpotMarketAccount(marketIndex);
|
|
88
|
-
}
|
|
85
|
+
await Promise.all(this.spotMarketIndexes.map((marketIndex) => this.subscribeToSpotMarketAccount(marketIndex)));
|
|
89
86
|
return true;
|
|
90
87
|
}
|
|
91
88
|
async subscribeToSpotMarketAccount(marketIndex) {
|
|
@@ -99,11 +96,9 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
99
96
|
return true;
|
|
100
97
|
}
|
|
101
98
|
async subscribeToOracles() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
99
|
+
await Promise.all(this.oracleInfos
|
|
100
|
+
.filter((oracleInfo) => !oracleInfo.publicKey.equals(web3_js_1.PublicKey.default))
|
|
101
|
+
.map((oracleInfo) => this.subscribeToOracle(oracleInfo)));
|
|
107
102
|
return true;
|
|
108
103
|
}
|
|
109
104
|
async subscribeToOracle(oracleInfo) {
|
|
@@ -119,19 +114,13 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
119
114
|
return true;
|
|
120
115
|
}
|
|
121
116
|
async unsubscribeFromMarketAccounts() {
|
|
122
|
-
|
|
123
|
-
await accountSubscriber.unsubscribe();
|
|
124
|
-
}
|
|
117
|
+
await Promise.all(Array.from(this.perpMarketAccountSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
125
118
|
}
|
|
126
119
|
async unsubscribeFromSpotMarketAccounts() {
|
|
127
|
-
|
|
128
|
-
await accountSubscriber.unsubscribe();
|
|
129
|
-
}
|
|
120
|
+
await Promise.all(Array.from(this.spotMarketAccountSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
130
121
|
}
|
|
131
122
|
async unsubscribeFromOracles() {
|
|
132
|
-
|
|
133
|
-
await accountSubscriber.unsubscribe();
|
|
134
|
-
}
|
|
123
|
+
await Promise.all(Array.from(this.oracleSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
135
124
|
}
|
|
136
125
|
async fetch() {
|
|
137
126
|
if (!this.isSubscribed) {
|
|
@@ -179,6 +168,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
179
168
|
}
|
|
180
169
|
async setPerpOracleMap() {
|
|
181
170
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
171
|
+
const addOraclePromises = [];
|
|
182
172
|
for (const perpMarket of perpMarkets) {
|
|
183
173
|
if (!perpMarket) {
|
|
184
174
|
continue;
|
|
@@ -187,16 +177,18 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
187
177
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
188
178
|
const oracle = perpMarketAccount.amm.oracle;
|
|
189
179
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
190
|
-
|
|
180
|
+
addOraclePromises.push(this.addOracle({
|
|
191
181
|
publicKey: oracle,
|
|
192
182
|
source: perpMarket.data.amm.oracleSource,
|
|
193
|
-
});
|
|
183
|
+
}));
|
|
194
184
|
}
|
|
195
185
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
196
186
|
}
|
|
187
|
+
await Promise.all(addOraclePromises);
|
|
197
188
|
}
|
|
198
189
|
async setSpotOracleMap() {
|
|
199
190
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
191
|
+
const addOraclePromises = [];
|
|
200
192
|
for (const spotMarket of spotMarkets) {
|
|
201
193
|
if (!spotMarket) {
|
|
202
194
|
continue;
|
|
@@ -205,13 +197,14 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
205
197
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
206
198
|
const oracle = spotMarketAccount.oracle;
|
|
207
199
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
208
|
-
|
|
200
|
+
addOraclePromises.push(this.addOracle({
|
|
209
201
|
publicKey: oracle,
|
|
210
202
|
source: spotMarketAccount.oracleSource,
|
|
211
|
-
});
|
|
203
|
+
}));
|
|
212
204
|
}
|
|
213
205
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
214
206
|
}
|
|
207
|
+
await Promise.all(addOraclePromises);
|
|
215
208
|
}
|
|
216
209
|
assertIsSubscribed() {
|
|
217
210
|
if (!this.isSubscribed) {
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -179,6 +179,12 @@ export declare class AdminClient extends DriftClient {
|
|
|
179
179
|
getUpdatePrelaunchOracleParamsIx(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionInstruction>;
|
|
180
180
|
deletePrelaunchOracle(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
181
181
|
getDeletePrelaunchOracleIx(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionInstruction>;
|
|
182
|
+
updateSpotMarketFuel(spotMarketIndex: number, fuelBoostDeposits?: number, fuelBoostBorrows?: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostInsurance?: number): Promise<TransactionSignature>;
|
|
183
|
+
getUpdateSpotMarketFuelIx(spotMarketIndex: number, fuelBoostDeposits?: number, fuelBoostBorrows?: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostInsurance?: number): Promise<TransactionInstruction>;
|
|
184
|
+
updatePerpMarketFuel(perpMarketIndex: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostPosition?: number): Promise<TransactionSignature>;
|
|
185
|
+
getUpdatePerpMarketFuelIx(perpMarketIndex: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostPosition?: number): Promise<TransactionInstruction>;
|
|
186
|
+
initUserFuel(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionSignature>;
|
|
187
|
+
getInitUserFuelIx(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionInstruction>;
|
|
182
188
|
initializePythPullOracle(feedId: string): Promise<TransactionSignature>;
|
|
183
189
|
getInitializePythPullOracleIx(feedId: string): Promise<TransactionInstruction>;
|
|
184
190
|
}
|
package/lib/adminClient.js
CHANGED
|
@@ -1631,6 +1631,61 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1631
1631
|
},
|
|
1632
1632
|
});
|
|
1633
1633
|
}
|
|
1634
|
+
async updateSpotMarketFuel(spotMarketIndex, fuelBoostDeposits, fuelBoostBorrows, fuelBoostTaker, fuelBoostMaker, fuelBoostInsurance) {
|
|
1635
|
+
const updateSpotMarketFuelIx = await this.getUpdateSpotMarketFuelIx(spotMarketIndex, fuelBoostDeposits || null, fuelBoostBorrows || null, fuelBoostTaker || null, fuelBoostMaker || null, fuelBoostInsurance || null);
|
|
1636
|
+
const tx = await this.buildTransaction(updateSpotMarketFuelIx);
|
|
1637
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1638
|
+
return txSig;
|
|
1639
|
+
}
|
|
1640
|
+
async getUpdateSpotMarketFuelIx(spotMarketIndex, fuelBoostDeposits, fuelBoostBorrows, fuelBoostTaker, fuelBoostMaker, fuelBoostInsurance) {
|
|
1641
|
+
const spotMarketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
1642
|
+
return await this.program.instruction.updateSpotMarketFuel(fuelBoostDeposits || null, fuelBoostBorrows || null, fuelBoostTaker || null, fuelBoostMaker || null, fuelBoostInsurance || null, {
|
|
1643
|
+
accounts: {
|
|
1644
|
+
admin: this.isSubscribed
|
|
1645
|
+
? this.getStateAccount().admin
|
|
1646
|
+
: this.wallet.publicKey,
|
|
1647
|
+
state: await this.getStatePublicKey(),
|
|
1648
|
+
spotMarket: spotMarketPublicKey,
|
|
1649
|
+
},
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
async updatePerpMarketFuel(perpMarketIndex, fuelBoostTaker, fuelBoostMaker, fuelBoostPosition) {
|
|
1653
|
+
const updatePerpMarketFuelIx = await this.getUpdatePerpMarketFuelIx(perpMarketIndex, fuelBoostTaker || null, fuelBoostMaker || null, fuelBoostPosition || null);
|
|
1654
|
+
const tx = await this.buildTransaction(updatePerpMarketFuelIx);
|
|
1655
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1656
|
+
return txSig;
|
|
1657
|
+
}
|
|
1658
|
+
async getUpdatePerpMarketFuelIx(perpMarketIndex, fuelBoostTaker, fuelBoostMaker, fuelBoostPosition) {
|
|
1659
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
1660
|
+
return await this.program.instruction.updatePerpMarketFuel(fuelBoostTaker || null, fuelBoostMaker || null, fuelBoostPosition || null, {
|
|
1661
|
+
accounts: {
|
|
1662
|
+
admin: this.isSubscribed
|
|
1663
|
+
? this.getStateAccount().admin
|
|
1664
|
+
: this.wallet.publicKey,
|
|
1665
|
+
state: await this.getStatePublicKey(),
|
|
1666
|
+
perpMarket: perpMarketPublicKey,
|
|
1667
|
+
},
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
async initUserFuel(user, authority, fuelBonusDeposits, fuelBonusBorrows, fuelBonusTaker, fuelBonusMaker, fuelBonusInsurance) {
|
|
1671
|
+
const updatePerpMarketFuelIx = await this.getInitUserFuelIx(user, authority, fuelBonusDeposits, fuelBonusBorrows, fuelBonusTaker, fuelBonusMaker, fuelBonusInsurance);
|
|
1672
|
+
const tx = await this.buildTransaction(updatePerpMarketFuelIx);
|
|
1673
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1674
|
+
return txSig;
|
|
1675
|
+
}
|
|
1676
|
+
async getInitUserFuelIx(user, authority, fuelBonusDeposits, fuelBonusBorrows, fuelBonusTaker, fuelBonusMaker, fuelBonusInsurance) {
|
|
1677
|
+
const userStats = await (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
|
|
1678
|
+
return await this.program.instruction.initUserFuel(fuelBonusDeposits || null, fuelBonusBorrows || null, fuelBonusTaker || null, fuelBonusMaker || null, fuelBonusInsurance || null, {
|
|
1679
|
+
accounts: {
|
|
1680
|
+
admin: this.isSubscribed
|
|
1681
|
+
? this.getStateAccount().admin
|
|
1682
|
+
: this.wallet.publicKey,
|
|
1683
|
+
state: await this.getStatePublicKey(),
|
|
1684
|
+
user,
|
|
1685
|
+
userStats,
|
|
1686
|
+
},
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1634
1689
|
async initializePythPullOracle(feedId) {
|
|
1635
1690
|
const initializePythPullOracleIx = await this.getInitializePythPullOracleIx(feedId);
|
|
1636
1691
|
const tx = await this.buildTransaction(initializePythPullOracleIx);
|
|
@@ -26,6 +26,7 @@ export declare class BankrunContextWrapper {
|
|
|
26
26
|
getLatestBlockhash(): Promise<Blockhash>;
|
|
27
27
|
printTxLogs(signature: string): void;
|
|
28
28
|
moveTimeForward(increment: number): Promise<void>;
|
|
29
|
+
setTimestamp(unix_timestamp: number): Promise<void>;
|
|
29
30
|
}
|
|
30
31
|
export declare class BankrunConnection {
|
|
31
32
|
private readonly _banksClient;
|
|
@@ -53,6 +53,12 @@ class BankrunContextWrapper {
|
|
|
53
53
|
const newClock = new solana_bankrun_1.Clock(currentClock.slot, currentClock.epochStartTimestamp, currentClock.epoch, currentClock.leaderScheduleEpoch, newUnixTimestamp);
|
|
54
54
|
await this.context.setClock(newClock);
|
|
55
55
|
}
|
|
56
|
+
async setTimestamp(unix_timestamp) {
|
|
57
|
+
const currentClock = await this.context.banksClient.getClock();
|
|
58
|
+
const newUnixTimestamp = BigInt(unix_timestamp);
|
|
59
|
+
const newClock = new solana_bankrun_1.Clock(currentClock.slot, currentClock.epochStartTimestamp, currentClock.epoch, currentClock.leaderScheduleEpoch, newUnixTimestamp);
|
|
60
|
+
await this.context.setClock(newClock);
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
exports.BankrunContextWrapper = BankrunContextWrapper;
|
|
58
64
|
class BankrunConnection {
|
|
@@ -57,6 +57,7 @@ export declare const FIVE_MINUTE: BN;
|
|
|
57
57
|
export declare const ONE_HOUR: BN;
|
|
58
58
|
export declare const ONE_YEAR: BN;
|
|
59
59
|
export declare const QUOTE_SPOT_MARKET_INDEX = 0;
|
|
60
|
+
export declare const GOV_SPOT_MARKET_INDEX = 15;
|
|
60
61
|
export declare const LAMPORTS_PRECISION: BN;
|
|
61
62
|
export declare const LAMPORTS_EXP: BN;
|
|
62
63
|
export declare const OPEN_ORDER_MARGIN_REQUIREMENT: BN;
|
|
@@ -65,3 +66,5 @@ export declare const ACCOUNT_AGE_DELETION_CUTOFF_SECONDS: number;
|
|
|
65
66
|
export declare const IDLE_TIME_SLOTS = 9000;
|
|
66
67
|
export declare const SLOT_TIME_ESTIMATE_MS = 400;
|
|
67
68
|
export declare const DUST_POSITION_SIZE: BN;
|
|
69
|
+
export declare const FUEL_WINDOW: BN;
|
|
70
|
+
export declare const FUEL_START_TS: BN;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.PRICE_DIV_PEG = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_RATE_BUFFER_PRECISION = exports.FUNDING_RATE_PRECISION = exports.PRICE_PRECISION = exports.QUOTE_PRECISION = exports.LIQUIDATION_FEE_PRECISION = exports.SPOT_MARKET_IMF_PRECISION = exports.SPOT_MARKET_IMF_PRECISION_EXP = exports.SPOT_MARKET_BALANCE_PRECISION = exports.SPOT_MARKET_BALANCE_PRECISION_EXP = exports.SPOT_MARKET_WEIGHT_PRECISION = exports.SPOT_MARKET_UTILIZATION_PRECISION = exports.SPOT_MARKET_UTILIZATION_PRECISION_EXP = exports.SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION = exports.SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP = exports.SPOT_MARKET_RATE_PRECISION = exports.SPOT_MARKET_RATE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.PRICE_PRECISION_EXP = exports.FUNDING_RATE_BUFFER_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.CONCENTRATION_PRECISION = exports.PERCENTAGE_PRECISION = exports.PERCENTAGE_PRECISION_EXP = exports.MAX_LEVERAGE_ORDER_SIZE = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.NINE = exports.EIGHT = exports.SEVEN = exports.SIX = exports.FIVE = exports.FOUR = exports.THREE = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
4
|
-
exports.DUST_POSITION_SIZE = exports.SLOT_TIME_ESTIMATE_MS = exports.IDLE_TIME_SLOTS = exports.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS = exports.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.FUNDING_RATE_OFFSET_DENOMINATOR = exports.LIQUIDATION_PCT_PRECISION = exports.BID_ASK_SPREAD_PRECISION = void 0;
|
|
4
|
+
exports.FUEL_START_TS = exports.FUEL_WINDOW = exports.DUST_POSITION_SIZE = exports.SLOT_TIME_ESTIMATE_MS = exports.IDLE_TIME_SLOTS = exports.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS = exports.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT = exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.LAMPORTS_EXP = exports.LAMPORTS_PRECISION = exports.GOV_SPOT_MARKET_INDEX = exports.QUOTE_SPOT_MARKET_INDEX = exports.ONE_YEAR = exports.ONE_HOUR = exports.FIVE_MINUTE = exports.FUNDING_RATE_OFFSET_DENOMINATOR = exports.LIQUIDATION_PCT_PRECISION = exports.BID_ASK_SPREAD_PRECISION = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const __1 = require("../");
|
|
7
7
|
exports.ZERO = new __1.BN(0);
|
|
@@ -61,6 +61,7 @@ exports.FIVE_MINUTE = new __1.BN(60 * 5);
|
|
|
61
61
|
exports.ONE_HOUR = new __1.BN(60 * 60);
|
|
62
62
|
exports.ONE_YEAR = new __1.BN(31536000);
|
|
63
63
|
exports.QUOTE_SPOT_MARKET_INDEX = 0;
|
|
64
|
+
exports.GOV_SPOT_MARKET_INDEX = 15;
|
|
64
65
|
exports.LAMPORTS_PRECISION = new __1.BN(web3_js_1.LAMPORTS_PER_SOL);
|
|
65
66
|
exports.LAMPORTS_EXP = new __1.BN(Math.log10(web3_js_1.LAMPORTS_PER_SOL));
|
|
66
67
|
exports.OPEN_ORDER_MARGIN_REQUIREMENT = exports.QUOTE_PRECISION.div(new __1.BN(100));
|
|
@@ -69,3 +70,5 @@ exports.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS = 60 * 60 * 24 * 13; // 13 days
|
|
|
69
70
|
exports.IDLE_TIME_SLOTS = 9000;
|
|
70
71
|
exports.SLOT_TIME_ESTIMATE_MS = 400;
|
|
71
72
|
exports.DUST_POSITION_SIZE = exports.QUOTE_PRECISION.divn(100); // Dust position is any position smaller than 1c
|
|
73
|
+
exports.FUEL_WINDOW = new __1.BN(60 * 60 * 24 * 28); // 28 days
|
|
74
|
+
exports.FUEL_START_TS = new __1.BN(1722384000); // unix timestamp
|