@drift-labs/vaults-sdk 0.1.569 → 0.1.571

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.
@@ -1,4 +1,4 @@
1
- import { BN, DriftClient, UserMap } from '@drift-labs/sdk';
1
+ import { BN, DriftClient, UserMap, OracleSource } from '@drift-labs/sdk';
2
2
  import { Program, ProgramAccount } from '@coral-xyz/anchor';
3
3
  import { DriftVaults } from './types/drift_vaults';
4
4
  import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
@@ -10,6 +10,10 @@ export type TxParams = {
10
10
  cuPriceMicroLamports?: number;
11
11
  simulateTransaction?: boolean;
12
12
  lookupTables?: AddressLookupTableAccount[];
13
+ oracleFeedsToCrank?: {
14
+ feed: PublicKey;
15
+ oracleSource: OracleSource;
16
+ }[];
13
17
  };
14
18
  export declare class VaultClient {
15
19
  driftClient: DriftClient;
@@ -294,4 +298,5 @@ export declare class VaultClient {
294
298
  protocolRequestWithdraw(vault: PublicKey, amount: BN, withdrawUnit: WithdrawUnit): Promise<TransactionSignature>;
295
299
  protocolCancelWithdrawRequest(vault: PublicKey): Promise<TransactionSignature>;
296
300
  protocolWithdraw(vault: PublicKey): Promise<TransactionSignature>;
301
+ private getOracleFeedsToCrank;
297
302
  }
@@ -963,6 +963,7 @@ class VaultClient {
963
963
  .rpc();
964
964
  }
965
965
  else {
966
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(txParams === null || txParams === void 0 ? void 0 : txParams.oracleFeedsToCrank);
966
967
  const requestWithdrawIx = this.program.instruction.requestWithdraw(
967
968
  // @ts-ignore
968
969
  amount, withdrawUnit, {
@@ -972,7 +973,7 @@ class VaultClient {
972
973
  },
973
974
  remainingAccounts,
974
975
  });
975
- return await this.createAndSendTxn([requestWithdrawIx], txParams);
976
+ return await this.createAndSendTxn([...oracleFeedsToCrankIxs, requestWithdrawIx], txParams);
976
977
  }
977
978
  }
978
979
  async withdraw(vaultDepositor, txParams) {
@@ -1035,7 +1036,9 @@ class VaultClient {
1035
1036
  }
1036
1037
  }
1037
1038
  else {
1039
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(txParams === null || txParams === void 0 ? void 0 : txParams.oracleFeedsToCrank);
1038
1040
  const ixs = [
1041
+ ...oracleFeedsToCrankIxs,
1039
1042
  await this.program.methods
1040
1043
  .withdraw()
1041
1044
  .accounts({
@@ -1141,6 +1144,7 @@ class VaultClient {
1141
1144
  .rpc();
1142
1145
  }
1143
1146
  else {
1147
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(txParams === null || txParams === void 0 ? void 0 : txParams.oracleFeedsToCrank);
1144
1148
  const cancelRequestWithdrawIx = this.program.instruction.cancelRequestWithdraw({
1145
1149
  accounts: {
1146
1150
  authority: this.driftClient.wallet.publicKey,
@@ -1148,7 +1152,7 @@ class VaultClient {
1148
1152
  },
1149
1153
  remainingAccounts,
1150
1154
  });
1151
- return await this.createAndSendTxn([cancelRequestWithdrawIx], txParams);
1155
+ return await this.createAndSendTxn([...oracleFeedsToCrankIxs, cancelRequestWithdrawIx], txParams);
1152
1156
  }
1153
1157
  }
1154
1158
  /**
@@ -1521,5 +1525,17 @@ class VaultClient {
1521
1525
  cuLimit: 1000000,
1522
1526
  });
1523
1527
  }
1528
+ async getOracleFeedsToCrank(oracleFeedsToCrank) {
1529
+ const oracleFeedsToCrankIxs = oracleFeedsToCrank
1530
+ ? (await Promise.all(oracleFeedsToCrank.map(async (feedConfig) => {
1531
+ if (JSON.stringify(feedConfig.oracleSource) !==
1532
+ JSON.stringify(sdk_1.OracleSource.SWITCHBOARD_ON_DEMAND)) {
1533
+ throw new Error('Only SWITCHBOARD_ON_DEMAND oracle feeds are supported for cranking');
1534
+ }
1535
+ return this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx(feedConfig.feed);
1536
+ })))
1537
+ : [];
1538
+ return oracleFeedsToCrankIxs;
1539
+ }
1524
1540
  }
1525
1541
  exports.VaultClient = VaultClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.1.569",
3
+ "version": "0.1.571",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@coral-xyz/anchor": "0.28.0",
11
- "@drift-labs/sdk": "2.102.0-beta.1",
11
+ "@drift-labs/sdk": "2.102.0-beta.2",
12
12
  "@ledgerhq/hw-app-solana": "^7.1.1",
13
13
  "@ledgerhq/hw-transport": "^6.30.1",
14
14
  "@ledgerhq/hw-transport-node-hid": "^6.28.1",
@@ -10,6 +10,7 @@ import {
10
10
  unstakeSharesToAmount as depositSharesToVaultAmount,
11
11
  ZERO,
12
12
  getInsuranceFundVaultPublicKey,
13
+ OracleSource,
13
14
  } from '@drift-labs/sdk';
14
15
  import { BorshAccountsCoder, Program, ProgramAccount } from '@coral-xyz/anchor';
15
16
  import { DriftVaults } from './types/drift_vaults';
@@ -58,6 +59,7 @@ export type TxParams = {
58
59
  cuPriceMicroLamports?: number;
59
60
  simulateTransaction?: boolean;
60
61
  lookupTables?: AddressLookupTableAccount[];
62
+ oracleFeedsToCrank?: { feed: PublicKey; oracleSource: OracleSource }[];
61
63
  };
62
64
 
63
65
  export class VaultClient {
@@ -1553,6 +1555,10 @@ export class VaultClient {
1553
1555
  .remainingAccounts(remainingAccounts)
1554
1556
  .rpc();
1555
1557
  } else {
1558
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
1559
+ txParams?.oracleFeedsToCrank
1560
+ );
1561
+
1556
1562
  const requestWithdrawIx = this.program.instruction.requestWithdraw(
1557
1563
  // @ts-ignore
1558
1564
  amount,
@@ -1566,7 +1572,10 @@ export class VaultClient {
1566
1572
  }
1567
1573
  );
1568
1574
 
1569
- return await this.createAndSendTxn([requestWithdrawIx], txParams);
1575
+ return await this.createAndSendTxn(
1576
+ [...oracleFeedsToCrankIxs, requestWithdrawIx],
1577
+ txParams
1578
+ );
1570
1579
  }
1571
1580
  }
1572
1581
 
@@ -1661,7 +1670,12 @@ export class VaultClient {
1661
1670
  .rpc();
1662
1671
  }
1663
1672
  } else {
1673
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
1674
+ txParams?.oracleFeedsToCrank
1675
+ );
1676
+
1664
1677
  const ixs = [
1678
+ ...oracleFeedsToCrankIxs,
1665
1679
  await this.program.methods
1666
1680
  .withdraw()
1667
1681
  .accounts({
@@ -1823,6 +1837,10 @@ export class VaultClient {
1823
1837
  .remainingAccounts(remainingAccounts)
1824
1838
  .rpc();
1825
1839
  } else {
1840
+ const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
1841
+ txParams?.oracleFeedsToCrank
1842
+ );
1843
+
1826
1844
  const cancelRequestWithdrawIx =
1827
1845
  this.program.instruction.cancelRequestWithdraw({
1828
1846
  accounts: {
@@ -1832,7 +1850,10 @@ export class VaultClient {
1832
1850
  remainingAccounts,
1833
1851
  });
1834
1852
 
1835
- return await this.createAndSendTxn([cancelRequestWithdrawIx], txParams);
1853
+ return await this.createAndSendTxn(
1854
+ [...oracleFeedsToCrankIxs, cancelRequestWithdrawIx],
1855
+ txParams
1856
+ );
1836
1857
  }
1837
1858
  }
1838
1859
 
@@ -2398,4 +2419,29 @@ export class VaultClient {
2398
2419
  cuLimit: 1_000_000,
2399
2420
  });
2400
2421
  }
2422
+
2423
+ private async getOracleFeedsToCrank(
2424
+ oracleFeedsToCrank: TxParams['oracleFeedsToCrank']
2425
+ ) {
2426
+ const oracleFeedsToCrankIxs: TransactionInstruction[] = oracleFeedsToCrank
2427
+ ? ((await Promise.all(
2428
+ oracleFeedsToCrank.map(async (feedConfig) => {
2429
+ if (
2430
+ JSON.stringify(feedConfig.oracleSource) !==
2431
+ JSON.stringify(OracleSource.SWITCHBOARD_ON_DEMAND)
2432
+ ) {
2433
+ throw new Error(
2434
+ 'Only SWITCHBOARD_ON_DEMAND oracle feeds are supported for cranking'
2435
+ );
2436
+ }
2437
+
2438
+ return this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx(
2439
+ feedConfig.feed
2440
+ );
2441
+ })
2442
+ )) as TransactionInstruction[])
2443
+ : [];
2444
+
2445
+ return oracleFeedsToCrankIxs;
2446
+ }
2401
2447
  }