@drift-labs/sdk 2.41.0-beta.3 → 2.42.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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.41.0-beta.3
1
+ 2.42.0-beta.0
@@ -17,6 +17,9 @@ class BulkAccountLoader {
17
17
  this.pollingFrequency = pollingFrequency;
18
18
  }
19
19
  async addAccount(publicKey, callback) {
20
+ if (!publicKey) {
21
+ console.trace(`Caught adding blank publickey to bulkAccountLoader`);
22
+ }
20
23
  const existingSize = this.accountsToLoad.size;
21
24
  const callbackId = (0, uuid_1.v4)();
22
25
  const existingAccountToLoad = this.accountsToLoad.get(publicKey.toString());
@@ -122,24 +125,22 @@ class BulkAccountLoader {
122
125
  this.log('request to rpc timed out');
123
126
  return;
124
127
  }
125
- for (const i in rpcResponses) {
126
- const rpcResponse = rpcResponses[i];
128
+ rpcResponses.forEach((rpcResponse, i) => {
127
129
  if (!rpcResponse.result) {
128
130
  console.error('rpc response missing result:');
129
131
  console.log(JSON.stringify(rpcResponse));
130
- continue;
132
+ return;
131
133
  }
132
134
  const newSlot = rpcResponse.result.context.slot;
133
135
  if (newSlot > this.mostRecentSlot) {
134
136
  this.mostRecentSlot = newSlot;
135
137
  }
136
138
  const accountsToLoad = accountsToLoadChunks[i];
137
- for (const j in accountsToLoad) {
138
- const accountToLoad = accountsToLoad[j];
139
+ accountsToLoad.forEach((accountToLoad, j) => {
139
140
  const key = accountToLoad.publicKey.toBase58();
140
141
  const oldRPCResponse = this.bufferAndSlotMap.get(key);
141
142
  if (oldRPCResponse && newSlot <= oldRPCResponse.slot) {
142
- continue;
143
+ return;
143
144
  }
144
145
  let newBuffer = undefined;
145
146
  if (rpcResponse.result.value[j]) {
@@ -153,7 +154,7 @@ class BulkAccountLoader {
153
154
  buffer: newBuffer,
154
155
  });
155
156
  this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
156
- continue;
157
+ return;
157
158
  }
158
159
  const oldBuffer = oldRPCResponse.buffer;
159
160
  if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
@@ -163,8 +164,8 @@ class BulkAccountLoader {
163
164
  });
164
165
  this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
165
166
  }
166
- }
167
- }
167
+ });
168
+ });
168
169
  }
169
170
  handleAccountCallbacks(accountToLoad, buffer, slot) {
170
171
  for (const [_, callback] of accountToLoad.callbacks) {
@@ -925,27 +925,29 @@ class DriftClient {
925
925
  * @param reduceOnly
926
926
  */
927
927
  async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false) {
928
- const ixs = [];
928
+ const tx = new web3_js_1.Transaction();
929
+ tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
930
+ units: 600000,
931
+ }));
929
932
  const additionalSigners = [];
930
933
  const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
931
934
  const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
932
935
  const signerAuthority = this.wallet.publicKey;
933
936
  const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signerAuthority);
934
937
  if (createWSOLTokenAccount) {
935
- const { ixs: wrappedSolIxs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
938
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
936
939
  associatedTokenAccount = pubkey;
937
- wrappedSolIxs.forEach((ix) => {
938
- ixs.push(ix);
940
+ ixs.forEach((ix) => {
941
+ tx.add(ix);
939
942
  });
940
943
  }
941
944
  const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, true);
942
- ixs.push(depositCollateralIx);
945
+ tx.add(depositCollateralIx);
943
946
  // Close the wrapped sol account at the end of the transaction
944
947
  if (createWSOLTokenAccount) {
945
- ixs.push((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAccount, signerAuthority, signerAuthority, []));
948
+ tx.add((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAccount, signerAuthority, signerAuthority, []));
946
949
  }
947
- console.log(ixs);
948
- const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, { computeUnits: 600000 }, 0), additionalSigners, this.opts);
950
+ const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
949
951
  this.spotMarketLastSlotCache.set(marketIndex, slot);
950
952
  return txSig;
951
953
  }
@@ -56,8 +56,7 @@ async function fetchTransactionLogs(connection, signatures, finality) {
56
56
  return Promise.reject('RPC request timed out fetching transactions');
57
57
  }
58
58
  const logs = new Array();
59
- for (const i in rpcResponses) {
60
- const rpcResponse = rpcResponses[i];
59
+ for (const rpcResponse of rpcResponses) {
61
60
  if (rpcResponse.result) {
62
61
  logs.push(mapTransactionResponseToLog(rpcResponse.result));
63
62
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.40.0",
2
+ "version": "2.41.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -2396,7 +2396,7 @@
2396
2396
  },
2397
2397
  {
2398
2398
  "name": "spotMarket",
2399
- "isMut": false,
2399
+ "isMut": true,
2400
2400
  "isSigner": false
2401
2401
  },
2402
2402
  {
@@ -4422,6 +4422,32 @@
4422
4422
  }
4423
4423
  ]
4424
4424
  },
4425
+ {
4426
+ "name": "updatePerpMarketFeeAdjustment",
4427
+ "accounts": [
4428
+ {
4429
+ "name": "admin",
4430
+ "isMut": false,
4431
+ "isSigner": true
4432
+ },
4433
+ {
4434
+ "name": "state",
4435
+ "isMut": false,
4436
+ "isSigner": false
4437
+ },
4438
+ {
4439
+ "name": "perpMarket",
4440
+ "isMut": true,
4441
+ "isSigner": false
4442
+ }
4443
+ ],
4444
+ "args": [
4445
+ {
4446
+ "name": "feeAdjustment",
4447
+ "type": "i16"
4448
+ }
4449
+ ]
4450
+ },
4425
4451
  {
4426
4452
  "name": "updateAdmin",
4427
4453
  "accounts": [
@@ -5109,7 +5135,7 @@
5109
5135
  },
5110
5136
  {
5111
5137
  "name": "padding1",
5112
- "type": "bool"
5138
+ "type": "u8"
5113
5139
  },
5114
5140
  {
5115
5141
  "name": "quoteSpotMarketIndex",
@@ -5118,12 +5144,21 @@
5118
5144
  ],
5119
5145
  "type": "u16"
5120
5146
  },
5147
+ {
5148
+ "name": "feeAdjustment",
5149
+ "docs": [
5150
+ "Between -100 and 100, represents what % to increase/decrease the fee by",
5151
+ "E.g. if this is -50 and the fee is 5bps, the new fee will be 2.5bps",
5152
+ "if this is 50 and the fee is 5bps, the new fee will be 7.5bps"
5153
+ ],
5154
+ "type": "i16"
5155
+ },
5121
5156
  {
5122
5157
  "name": "padding",
5123
5158
  "type": {
5124
5159
  "array": [
5125
5160
  "u8",
5126
- 48
5161
+ 46
5127
5162
  ]
5128
5163
  }
5129
5164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.41.0-beta.3",
3
+ "version": "2.42.0-beta.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -40,6 +40,10 @@ export class BulkAccountLoader {
40
40
  publicKey: PublicKey,
41
41
  callback: (buffer: Buffer, slot: number) => void
42
42
  ): Promise<string> {
43
+ if (!publicKey) {
44
+ console.trace(`Caught adding blank publickey to bulkAccountLoader`);
45
+ }
46
+
43
47
  const existingSize = this.accountsToLoad.size;
44
48
 
45
49
  const callbackId = uuidv4();
@@ -172,12 +176,11 @@ export class BulkAccountLoader {
172
176
  return;
173
177
  }
174
178
 
175
- for (const i in rpcResponses) {
176
- const rpcResponse = rpcResponses[i];
179
+ rpcResponses.forEach((rpcResponse, i) => {
177
180
  if (!rpcResponse.result) {
178
181
  console.error('rpc response missing result:');
179
182
  console.log(JSON.stringify(rpcResponse));
180
- continue;
183
+ return;
181
184
  }
182
185
  const newSlot = rpcResponse.result.context.slot;
183
186
 
@@ -186,13 +189,12 @@ export class BulkAccountLoader {
186
189
  }
187
190
 
188
191
  const accountsToLoad = accountsToLoadChunks[i];
189
- for (const j in accountsToLoad) {
190
- const accountToLoad = accountsToLoad[j];
192
+ accountsToLoad.forEach((accountToLoad, j) => {
191
193
  const key = accountToLoad.publicKey.toBase58();
192
194
  const oldRPCResponse = this.bufferAndSlotMap.get(key);
193
195
 
194
196
  if (oldRPCResponse && newSlot <= oldRPCResponse.slot) {
195
- continue;
197
+ return;
196
198
  }
197
199
 
198
200
  let newBuffer: Buffer | undefined = undefined;
@@ -208,7 +210,7 @@ export class BulkAccountLoader {
208
210
  buffer: newBuffer,
209
211
  });
210
212
  this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
211
- continue;
213
+ return;
212
214
  }
213
215
 
214
216
  const oldBuffer = oldRPCResponse.buffer;
@@ -219,8 +221,8 @@ export class BulkAccountLoader {
219
221
  });
220
222
  this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
221
223
  }
222
- }
223
- }
224
+ });
225
+ });
224
226
  }
225
227
 
226
228
  handleAccountCallbacks(
@@ -1557,7 +1557,12 @@ export class DriftClient {
1557
1557
  subAccountId?: number,
1558
1558
  reduceOnly = false
1559
1559
  ): Promise<TransactionSignature> {
1560
- const ixs: Array<TransactionInstruction> = [];
1560
+ const tx = new Transaction();
1561
+ tx.add(
1562
+ ComputeBudgetProgram.setComputeUnitLimit({
1563
+ units: 600_000,
1564
+ })
1565
+ );
1561
1566
 
1562
1567
  const additionalSigners: Array<Signer> = [];
1563
1568
 
@@ -1571,13 +1576,15 @@ export class DriftClient {
1571
1576
  isSolMarket && associatedTokenAccount.equals(signerAuthority);
1572
1577
 
1573
1578
  if (createWSOLTokenAccount) {
1574
- const { ixs: wrappedSolIxs, pubkey } =
1575
- await this.getWrappedSolAccountCreationIxs(amount, true);
1579
+ const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
1580
+ amount,
1581
+ true
1582
+ );
1576
1583
 
1577
1584
  associatedTokenAccount = pubkey;
1578
1585
 
1579
- wrappedSolIxs.forEach((ix) => {
1580
- ixs.push(ix);
1586
+ ixs.forEach((ix) => {
1587
+ tx.add(ix);
1581
1588
  });
1582
1589
  }
1583
1590
 
@@ -1590,11 +1597,11 @@ export class DriftClient {
1590
1597
  true
1591
1598
  );
1592
1599
 
1593
- ixs.push(depositCollateralIx);
1600
+ tx.add(depositCollateralIx);
1594
1601
 
1595
1602
  // Close the wrapped sol account at the end of the transaction
1596
1603
  if (createWSOLTokenAccount) {
1597
- ixs.push(
1604
+ tx.add(
1598
1605
  createCloseAccountInstruction(
1599
1606
  associatedTokenAccount,
1600
1607
  signerAuthority,
@@ -1604,9 +1611,8 @@ export class DriftClient {
1604
1611
  );
1605
1612
  }
1606
1613
 
1607
- console.log(ixs);
1608
1614
  const { txSig, slot } = await this.sendTransaction(
1609
- await this.buildTransaction(ixs, { computeUnits: 600_000 }, 0),
1615
+ tx,
1610
1616
  additionalSigners,
1611
1617
  this.opts
1612
1618
  );
@@ -117,8 +117,7 @@ export async function fetchTransactionLogs(
117
117
  }
118
118
 
119
119
  const logs = new Array<Log>();
120
- for (const i in rpcResponses) {
121
- const rpcResponse = rpcResponses[i];
120
+ for (const rpcResponse of rpcResponses) {
122
121
  if (rpcResponse.result) {
123
122
  logs.push(mapTransactionResponseToLog(rpcResponse.result));
124
123
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.40.0",
2
+ "version": "2.41.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -2396,7 +2396,7 @@
2396
2396
  },
2397
2397
  {
2398
2398
  "name": "spotMarket",
2399
- "isMut": false,
2399
+ "isMut": true,
2400
2400
  "isSigner": false
2401
2401
  },
2402
2402
  {
@@ -4422,6 +4422,32 @@
4422
4422
  }
4423
4423
  ]
4424
4424
  },
4425
+ {
4426
+ "name": "updatePerpMarketFeeAdjustment",
4427
+ "accounts": [
4428
+ {
4429
+ "name": "admin",
4430
+ "isMut": false,
4431
+ "isSigner": true
4432
+ },
4433
+ {
4434
+ "name": "state",
4435
+ "isMut": false,
4436
+ "isSigner": false
4437
+ },
4438
+ {
4439
+ "name": "perpMarket",
4440
+ "isMut": true,
4441
+ "isSigner": false
4442
+ }
4443
+ ],
4444
+ "args": [
4445
+ {
4446
+ "name": "feeAdjustment",
4447
+ "type": "i16"
4448
+ }
4449
+ ]
4450
+ },
4425
4451
  {
4426
4452
  "name": "updateAdmin",
4427
4453
  "accounts": [
@@ -5109,7 +5135,7 @@
5109
5135
  },
5110
5136
  {
5111
5137
  "name": "padding1",
5112
- "type": "bool"
5138
+ "type": "u8"
5113
5139
  },
5114
5140
  {
5115
5141
  "name": "quoteSpotMarketIndex",
@@ -5118,12 +5144,21 @@
5118
5144
  ],
5119
5145
  "type": "u16"
5120
5146
  },
5147
+ {
5148
+ "name": "feeAdjustment",
5149
+ "docs": [
5150
+ "Between -100 and 100, represents what % to increase/decrease the fee by",
5151
+ "E.g. if this is -50 and the fee is 5bps, the new fee will be 2.5bps",
5152
+ "if this is 50 and the fee is 5bps, the new fee will be 7.5bps"
5153
+ ],
5154
+ "type": "i16"
5155
+ },
5121
5156
  {
5122
5157
  "name": "padding",
5123
5158
  "type": {
5124
5159
  "array": [
5125
5160
  "u8",
5126
- 48
5161
+ 46
5127
5162
  ]
5128
5163
  }
5129
5164
  }