@neutral-trade/sdk 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -38,7 +38,7 @@ const sdk = await NeutralTrade.create({
38
38
 
39
39
  // Get user balance for specific vaults
40
40
  const balances = await sdk.getUserBalanceByVaultIds({
41
- vaultIds: [VaultId.solnl, VaultId.btcnl],
41
+ vaultIds: [VaultId.sol_super_staking_1, VaultId.btc_super_staking_3],
42
42
  userAddress: 'YOUR_WALLET_ADDRESS'
43
43
  })
44
44
 
@@ -53,17 +53,50 @@ The SDK supports both **Drift** and **Bundle** vault types. Use the `VaultId` en
53
53
  import { VaultId } from '@neutral-trade/sdk'
54
54
 
55
55
  // Drift Vaults
56
- VaultId.solnl // SOL Neutral Long
57
- VaultId.btcnl // BTC Neutral Long
58
- VaultId.jlpdnv1 // JLP DN V1
56
+ VaultId.sol_super_staking_1 // SOL Super Staking
57
+ VaultId.btc_super_staking_3 // BTC Super Staking
58
+ VaultId.jlp_delta_neutral_vault_1_0 // JLP Delta Neutral (vault-1)
59
59
 
60
60
  // Bundle Vaults
61
- VaultId.hlfundingarb // HL Funding Arbitrage
62
- VaultId.alpdn // ALP DN
61
+ VaultId.hyperliquid_funding_arb_48 // Hyperliquid Funding Arb
62
+ VaultId.alp_delta_neutral_49 // ALP Delta Neutral
63
63
  ```
64
64
 
65
65
  See the [documentation](https://sdk.neutral.trade) for the complete list of available vaults.
66
66
 
67
+ ## Configuration Registry
68
+
69
+ The SDK includes built-in vault configurations, but you can also fetch the latest configurations from a remote registry. This is useful if you don't upgrade the SDK package frequently.
70
+
71
+ ### Registry URLs
72
+
73
+ - **GitHub Raw**: `https://raw.githubusercontent.com/neutral-trade/sdk/main/src/registry/vaults.json`
74
+ - **jsDelivr CDN**: `https://cdn.jsdelivr.net/gh/neutral-trade/sdk@main/src/registry/vaults.json`
75
+
76
+ ### Usage
77
+
78
+ **Use the registry URL if you don't upgrade the SDK frequently:**
79
+
80
+ ```typescript
81
+ const sdk = await NeutralTrade.create({
82
+ rpcUrl: 'YOUR_RPC_URL_HERE',
83
+ registryUrl: 'https://cdn.jsdelivr.net/gh/neutral-trade/sdk@main/src/registry/vaults.json'
84
+ })
85
+ ```
86
+
87
+ This ensures you always have the latest vault configurations without needing to update the SDK package.
88
+
89
+ **Use built-in configs if you upgrade the SDK regularly:**
90
+
91
+ ```typescript
92
+ const sdk = await NeutralTrade.create({
93
+ rpcUrl: 'YOUR_RPC_URL_HERE'
94
+ // No registryUrl - uses built-in configurations
95
+ })
96
+ ```
97
+
98
+ This is simpler and doesn't require an additional network request at initialization.
99
+
67
100
  ## Examples
68
101
 
69
102
  Check out the [examples](./examples) directory for more usage examples.
package/dist/index.d.mts CHANGED
@@ -5127,7 +5127,7 @@ declare enum VaultType {
5127
5127
  Hyperliquid = "Hyperliquid",
5128
5128
  Kamino = "Kamino",
5129
5129
  }
5130
- /** Raw vault entry from registry JSON (without program IDs) */
5130
+ /** Raw vault entry from registry JSON */
5131
5131
  interface VaultRegistryEntry {
5132
5132
  vaultId: number;
5133
5133
  name: string;
@@ -5136,16 +5136,13 @@ interface VaultRegistryEntry {
5136
5136
  vaultAddress: string;
5137
5137
  depositToken: SupportedToken;
5138
5138
  pfee?: number;
5139
- }
5140
- /** Vault config with required program IDs (transformed from registry entry) */
5141
- interface VaultConfig extends VaultRegistryEntry {
5142
- /** Required for Drift vaults */
5139
+ /** Optional Drift program ID (only for Drift vaults with non-default program) */
5143
5140
  driftProgramId?: string;
5144
- /** Required for Bundle vaults */
5141
+ /** Optional Bundle program ID (only for Bundle vaults with non-default V2 program) */
5145
5142
  bundleProgramId?: string;
5146
5143
  }
5147
5144
  /** Vault registry as a record keyed by vaultId */
5148
- type VaultConfigRecord = Record<number, VaultConfig>;
5145
+ type VaultRegistry = Record<number, VaultRegistryEntry>;
5149
5146
  //#endregion
5150
5147
  //#region src/types/index.d.ts
5151
5148
  interface VaultBalanceData {
@@ -5172,19 +5169,19 @@ type UserBalanceResult = Record<number, VaultBalanceData | null>;
5172
5169
  //#endregion
5173
5170
  //#region src/constants/vaults.d.ts
5174
5171
  /**
5175
- * Get Bundle Program ID for a vault
5176
- * All bundle vaults use V1 except vaultId 69 and 72 which use V2
5172
+ * Get Bundle Program ID for a vault config
5173
+ * Uses registry value if present, otherwise defaults to V1
5177
5174
  */
5178
- declare function getBundleProgramId(vaultId: number): BundleProgramId;
5175
+ declare function getBundleProgramId(vault: VaultRegistryEntry): BundleProgramId | undefined;
5179
5176
  /**
5180
- * Get Drift Program ID for a vault
5181
- * All drift vaults use default program ID except vaultId 0
5177
+ * Get Drift Program ID for a vault config as PublicKey
5178
+ * Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
5182
5179
  */
5183
- declare function getDriftProgramPK(vaultId: number): PublicKey;
5184
- declare const vaults: VaultConfigRecord;
5180
+ declare function getDriftProgramId(vault: VaultRegistryEntry): string | undefined;
5181
+ declare const vaults: VaultRegistry;
5185
5182
  declare function isValidVaultAddress(address: string): boolean;
5186
- declare function getVaultByAddress(address: string): VaultConfig | undefined;
5187
- declare function getVaultById(vaultId: number): VaultConfig | undefined;
5183
+ declare function getVaultByAddress(address: string): VaultRegistryEntry | undefined;
5184
+ declare function getVaultById(vaultId: number): VaultRegistryEntry | undefined;
5188
5185
  //#endregion
5189
5186
  //#region src/NeutralTrade.d.ts
5190
5187
  interface NeutralTradeConfig {
@@ -5200,7 +5197,7 @@ declare class NeutralTrade {
5200
5197
  readonly bundleProgramV2: Program$1<NtbundleV2>;
5201
5198
  readonly driftVaultClient: VaultClient;
5202
5199
  /** Vault configurations (built-in merged with remote if registryUrl was provided) */
5203
- readonly vaults: VaultConfigRecord;
5200
+ readonly vaults: VaultRegistry;
5204
5201
  /** Price map for deposit tokens */
5205
5202
  readonly priceMap: Map<SupportedToken, number>;
5206
5203
  private constructor();
@@ -5243,4 +5240,4 @@ declare function deriveUserPDA(userKey: PublicKey, bundlePDA: PublicKey, program
5243
5240
  */
5244
5241
  declare function getVaultDepositorAddressSync(programId: PublicKey, vault: PublicKey, authority: PublicKey): PublicKey;
5245
5242
  //#endregion
5246
- export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type OracleData, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type VaultBalanceData, type VaultConfig, type VaultConfigRecord, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramPK, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
5243
+ export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type OracleData, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type VaultBalanceData, type VaultRegistryEntry as VaultConfig, type VaultRegistry as VaultConfigRecord, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramId, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
package/dist/index.mjs CHANGED
@@ -8246,7 +8246,8 @@ var vaults_default = [
8246
8246
  "subname": "Atlas Research",
8247
8247
  "type": "Bundle",
8248
8248
  "vaultAddress": "Eo3m78EQcHnwMyHtxaiz1vw4nwHa85RuGE8jLsrELhxj",
8249
- "depositToken": "USDC"
8249
+ "depositToken": "USDC",
8250
+ "bundleProgramId": "BUNDeH5A4c47bcEoAjBhN3sCjLgYnRsmt9ibMztqVkC9"
8250
8251
  },
8251
8252
  {
8252
8253
  "vaultId": 71,
@@ -8268,7 +8269,8 @@ var vaults_default = [
8268
8269
  "subname": "vault-jupiter",
8269
8270
  "type": "Bundle",
8270
8271
  "vaultAddress": "GiNbTRuRqvVGEEQGZKMjmwX84LrsbqfzVVNtWYbcZPCY",
8271
- "depositToken": "USDC"
8272
+ "depositToken": "USDC",
8273
+ "bundleProgramId": "BUNDeH5A4c47bcEoAjBhN3sCjLgYnRsmt9ibMztqVkC9"
8272
8274
  },
8273
8275
  {
8274
8276
  "vaultId": 68,
@@ -8855,7 +8857,8 @@ var vaults_default = [
8855
8857
  "type": "Drift",
8856
8858
  "vaultAddress": "3Nkctq19AW7gs5hkxixUDjS9UVjmCwcNCo7rqPpub87c",
8857
8859
  "depositToken": "USDC",
8858
- "pfee": .25
8860
+ "pfee": .25,
8861
+ "driftProgramId": "9Fcn3Fd4d5ocrb12xCUtEvezxcjFEAyHBPfrZDiPt9Qj"
8859
8862
  }
8860
8863
  ];
8861
8864
 
@@ -8961,7 +8964,9 @@ const VaultRegistryEntrySchema = z.object({
8961
8964
  type: z.nativeEnum(VaultType),
8962
8965
  vaultAddress: z.string().min(32).max(44),
8963
8966
  depositToken: z.nativeEnum(SupportedToken),
8964
- pfee: z.number().min(0).max(1).optional()
8967
+ pfee: z.number().min(0).max(1).optional(),
8968
+ driftProgramId: z.string().min(32).max(44).optional(),
8969
+ bundleProgramId: z.string().min(32).max(44).optional()
8965
8970
  });
8966
8971
  /** Schema for validating array of registry entries */
8967
8972
  const VaultRegistryArraySchema = z.array(VaultRegistryEntrySchema).superRefine((vaults$1, ctx) => {
@@ -8977,25 +8982,25 @@ const VaultRegistryArraySchema = z.array(VaultRegistryEntrySchema).superRefine((
8977
8982
 
8978
8983
  //#endregion
8979
8984
  //#region src/constants/vaults.ts
8980
- /** Special Drift Program ID for jlpdnv1 (vaultId: 0) */
8981
- const JLPDNV1_DRIFT_PROGRAM_ID = "9Fcn3Fd4d5ocrb12xCUtEvezxcjFEAyHBPfrZDiPt9Qj";
8982
- /** V2 Bundle vault IDs */
8983
- const V2_BUNDLE_VAULT_IDS = [69, 72];
8984
8985
  /**
8985
- * Get Bundle Program ID for a vault
8986
- * All bundle vaults use V1 except vaultId 69 and 72 which use V2
8986
+ * Get Bundle Program ID for a vault config
8987
+ * Uses registry value if present, otherwise defaults to V1
8987
8988
  */
8988
- function getBundleProgramId(vaultId) {
8989
- if (V2_BUNDLE_VAULT_IDS.includes(vaultId)) return BundleProgramId.V2;
8989
+ function getBundleProgramId(vault) {
8990
+ if (vault.type !== VaultType.Bundle) return;
8991
+ if (vault.bundleProgramId) {
8992
+ if (Object.values(BundleProgramId).includes(vault.bundleProgramId)) return vault.bundleProgramId;
8993
+ }
8990
8994
  return BundleProgramId.V1;
8991
8995
  }
8992
8996
  /**
8993
- * Get Drift Program ID for a vault
8994
- * All drift vaults use default program ID except vaultId 0
8997
+ * Get Drift Program ID for a vault config as PublicKey
8998
+ * Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
8995
8999
  */
8996
- function getDriftProgramPK(vaultId) {
8997
- if (vaultId === 0) return new PublicKey(JLPDNV1_DRIFT_PROGRAM_ID);
8998
- return VAULT_PROGRAM_ID;
9000
+ function getDriftProgramId(vault) {
9001
+ if (vault.type !== VaultType.Drift) return;
9002
+ if (vault.driftProgramId) return vault.driftProgramId;
9003
+ return VAULT_PROGRAM_ID.toBase58();
8999
9004
  }
9000
9005
  /**
9001
9006
  * Transform a registry entry to VaultConfig with program IDs
@@ -9005,8 +9010,8 @@ function getDriftProgramPK(vaultId) {
9005
9010
  function toVaultConfig(entry) {
9006
9011
  return {
9007
9012
  ...entry,
9008
- driftProgramId: entry.type === VaultType.Drift ? getDriftProgramPK(entry.vaultId).toBase58() : void 0,
9009
- bundleProgramId: entry.type === VaultType.Bundle ? getBundleProgramId(entry.vaultId) : void 0
9013
+ driftProgramId: getDriftProgramId(entry),
9014
+ bundleProgramId: getBundleProgramId(entry)
9010
9015
  };
9011
9016
  }
9012
9017
  /**
@@ -9147,7 +9152,7 @@ async function getBundleBalances({ vaultIds, userAddress, vaults: vaults$1, bund
9147
9152
  for (const vaultId of vaultIds) {
9148
9153
  const config = vaults$1[vaultId];
9149
9154
  if (!config) continue;
9150
- if (getBundleProgramId(vaultId) === BundleProgramId.V2) v2Vaults.push({
9155
+ if (config.bundleProgramId === BundleProgramId.V2) v2Vaults.push({
9151
9156
  vaultId,
9152
9157
  config
9153
9158
  });
@@ -9285,9 +9290,9 @@ async function getDriftBalances({ vaultIds, userAddress, vaults: vaults$1, drift
9285
9290
  })).filter((entry) => entry.config !== void 0);
9286
9291
  if (vaultEntries.length === 0) return result;
9287
9292
  const vaultAddresses = vaultEntries.map(({ config }) => new PublicKey(config.vaultAddress));
9288
- const vaultDepositorPDAs = vaultEntries.map(({ vaultId, config }) => {
9293
+ const vaultDepositorPDAs = vaultEntries.map(({ config }) => {
9289
9294
  const vaultPubkey = new PublicKey(config.vaultAddress);
9290
- return getVaultDepositorAddressSync(getDriftProgramPK(vaultId), vaultPubkey, userPublicKey);
9295
+ return getVaultDepositorAddressSync(config.driftProgramId ? new PublicKey(config.driftProgramId) : VAULT_PROGRAM_ID, vaultPubkey, userPublicKey);
9291
9296
  });
9292
9297
  const [vaultsData, vaultDepositors] = await Promise.all([driftVaultClient.program.account.vault.fetchMultiple(vaultAddresses), driftVaultClient.program.account.vaultDepositor.fetchMultiple(vaultDepositorPDAs)]);
9293
9298
  for (let i = 0; i < vaultEntries.length; i++) {
@@ -9488,4 +9493,4 @@ var NeutralTrade = class NeutralTrade {
9488
9493
  };
9489
9494
 
9490
9495
  //#endregion
9491
- export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramPK, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
9496
+ export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramId, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neutral-trade/sdk",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "description": "SDK for Neutral Trade vaults",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/neutral-trade/sdk#readme",