@neutral-trade/sdk 0.1.4 → 0.1.5
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/dist/index.d.mts +15 -11
- package/dist/index.mjs +26 -23
- package/package.json +1 -1
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
|
|
5130
|
+
/** Raw vault entry from registry JSON */
|
|
5131
5131
|
interface VaultRegistryEntry {
|
|
5132
5132
|
vaultId: number;
|
|
5133
5133
|
name: string;
|
|
@@ -5136,13 +5136,17 @@ interface VaultRegistryEntry {
|
|
|
5136
5136
|
vaultAddress: string;
|
|
5137
5137
|
depositToken: SupportedToken;
|
|
5138
5138
|
pfee?: number;
|
|
5139
|
+
/** Optional Drift program ID (only for Drift vaults with non-default program) */
|
|
5140
|
+
driftProgramId?: string;
|
|
5141
|
+
/** Optional Bundle program ID (only for Bundle vaults with non-default V2 program) */
|
|
5142
|
+
bundleProgramId?: string;
|
|
5139
5143
|
}
|
|
5140
|
-
/** Vault config
|
|
5144
|
+
/** Vault config (same as registry entry, program IDs are optional) */
|
|
5141
5145
|
interface VaultConfig extends VaultRegistryEntry {
|
|
5142
5146
|
/** Required for Drift vaults */
|
|
5143
|
-
driftProgramId
|
|
5147
|
+
driftProgramId: string;
|
|
5144
5148
|
/** Required for Bundle vaults */
|
|
5145
|
-
bundleProgramId
|
|
5149
|
+
bundleProgramId: string;
|
|
5146
5150
|
}
|
|
5147
5151
|
/** Vault registry as a record keyed by vaultId */
|
|
5148
5152
|
type VaultConfigRecord = Record<number, VaultConfig>;
|
|
@@ -5172,15 +5176,15 @@ type UserBalanceResult = Record<number, VaultBalanceData | null>;
|
|
|
5172
5176
|
//#endregion
|
|
5173
5177
|
//#region src/constants/vaults.d.ts
|
|
5174
5178
|
/**
|
|
5175
|
-
* Get Bundle Program ID for a vault
|
|
5176
|
-
*
|
|
5179
|
+
* Get Bundle Program ID for a vault config
|
|
5180
|
+
* Uses registry value if present, otherwise defaults to V1
|
|
5177
5181
|
*/
|
|
5178
|
-
declare function getBundleProgramId(
|
|
5182
|
+
declare function getBundleProgramId(vault: VaultRegistryEntry): BundleProgramId;
|
|
5179
5183
|
/**
|
|
5180
|
-
* Get Drift Program ID for a vault
|
|
5181
|
-
*
|
|
5184
|
+
* Get Drift Program ID for a vault config as PublicKey
|
|
5185
|
+
* Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
|
|
5182
5186
|
*/
|
|
5183
|
-
declare function
|
|
5187
|
+
declare function getDriftProgramId(vault: VaultRegistryEntry): string;
|
|
5184
5188
|
declare const vaults: VaultConfigRecord;
|
|
5185
5189
|
declare function isValidVaultAddress(address: string): boolean;
|
|
5186
5190
|
declare function getVaultByAddress(address: string): VaultConfig | undefined;
|
|
@@ -5243,4 +5247,4 @@ declare function deriveUserPDA(userKey: PublicKey, bundlePDA: PublicKey, program
|
|
|
5243
5247
|
*/
|
|
5244
5248
|
declare function getVaultDepositorAddressSync(programId: PublicKey, vault: PublicKey, authority: PublicKey): PublicKey;
|
|
5245
5249
|
//#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,
|
|
5250
|
+
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, 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,23 @@ 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
|
-
*
|
|
8986
|
+
* Get Bundle Program ID for a vault config
|
|
8987
|
+
* Uses registry value if present, otherwise defaults to V1
|
|
8987
8988
|
*/
|
|
8988
|
-
function getBundleProgramId(
|
|
8989
|
-
if (
|
|
8989
|
+
function getBundleProgramId(vault) {
|
|
8990
|
+
if (vault.bundleProgramId) {
|
|
8991
|
+
if (Object.values(BundleProgramId).includes(vault.bundleProgramId)) return vault.bundleProgramId;
|
|
8992
|
+
}
|
|
8990
8993
|
return BundleProgramId.V1;
|
|
8991
8994
|
}
|
|
8992
8995
|
/**
|
|
8993
|
-
* Get Drift Program ID for a vault
|
|
8994
|
-
*
|
|
8996
|
+
* Get Drift Program ID for a vault config as PublicKey
|
|
8997
|
+
* Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
|
|
8995
8998
|
*/
|
|
8996
|
-
function
|
|
8997
|
-
if (
|
|
8998
|
-
return VAULT_PROGRAM_ID;
|
|
8999
|
+
function getDriftProgramId(vault) {
|
|
9000
|
+
if (vault.driftProgramId) return vault.driftProgramId;
|
|
9001
|
+
return VAULT_PROGRAM_ID.toBase58();
|
|
8999
9002
|
}
|
|
9000
9003
|
/**
|
|
9001
9004
|
* Transform a registry entry to VaultConfig with program IDs
|
|
@@ -9005,8 +9008,8 @@ function getDriftProgramPK(vaultId) {
|
|
|
9005
9008
|
function toVaultConfig(entry) {
|
|
9006
9009
|
return {
|
|
9007
9010
|
...entry,
|
|
9008
|
-
driftProgramId:
|
|
9009
|
-
bundleProgramId:
|
|
9011
|
+
driftProgramId: getDriftProgramId(entry),
|
|
9012
|
+
bundleProgramId: getBundleProgramId(entry)
|
|
9010
9013
|
};
|
|
9011
9014
|
}
|
|
9012
9015
|
/**
|
|
@@ -9147,7 +9150,7 @@ async function getBundleBalances({ vaultIds, userAddress, vaults: vaults$1, bund
|
|
|
9147
9150
|
for (const vaultId of vaultIds) {
|
|
9148
9151
|
const config = vaults$1[vaultId];
|
|
9149
9152
|
if (!config) continue;
|
|
9150
|
-
if (
|
|
9153
|
+
if (config.bundleProgramId === BundleProgramId.V2) v2Vaults.push({
|
|
9151
9154
|
vaultId,
|
|
9152
9155
|
config
|
|
9153
9156
|
});
|
|
@@ -9285,9 +9288,9 @@ async function getDriftBalances({ vaultIds, userAddress, vaults: vaults$1, drift
|
|
|
9285
9288
|
})).filter((entry) => entry.config !== void 0);
|
|
9286
9289
|
if (vaultEntries.length === 0) return result;
|
|
9287
9290
|
const vaultAddresses = vaultEntries.map(({ config }) => new PublicKey(config.vaultAddress));
|
|
9288
|
-
const vaultDepositorPDAs = vaultEntries.map(({
|
|
9291
|
+
const vaultDepositorPDAs = vaultEntries.map(({ config }) => {
|
|
9289
9292
|
const vaultPubkey = new PublicKey(config.vaultAddress);
|
|
9290
|
-
return getVaultDepositorAddressSync(
|
|
9293
|
+
return getVaultDepositorAddressSync(new PublicKey(config.driftProgramId), vaultPubkey, userPublicKey);
|
|
9291
9294
|
});
|
|
9292
9295
|
const [vaultsData, vaultDepositors] = await Promise.all([driftVaultClient.program.account.vault.fetchMultiple(vaultAddresses), driftVaultClient.program.account.vaultDepositor.fetchMultiple(vaultDepositorPDAs)]);
|
|
9293
9296
|
for (let i = 0; i < vaultEntries.length; i++) {
|
|
@@ -9488,4 +9491,4 @@ var NeutralTrade = class NeutralTrade {
|
|
|
9488
9491
|
};
|
|
9489
9492
|
|
|
9490
9493
|
//#endregion
|
|
9491
|
-
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId,
|
|
9494
|
+
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultId, VaultType, deriveOraclePDA, deriveUserPDA, getBundleProgramId, getDriftProgramId, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults };
|