@neutral-trade/sdk 0.1.21 → 0.2.2
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 +12 -13
- package/dist/index.d.mts +19 -12
- package/dist/index.mjs +45 -168
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
5
|
[![License][license-src]][license-href]
|
|
6
6
|
|
|
7
|
-
TypeScript SDK for [Neutral Trade](https://neutral.trade) vaults.
|
|
7
|
+
TypeScript SDK for [Neutral Trade](https://neutral.trade) **Bundle** vaults (on-chain reads, balances, registry).
|
|
8
8
|
|
|
9
9
|
📚 **[Documentation](https://sdk.neutral.trade/)**
|
|
10
10
|
|
|
11
|
+
## Drift vault balances (legacy)
|
|
12
|
+
|
|
13
|
+
This package **does not** depend on `@drift-labs/*`. The public registry may still list historical Drift vault metadata, but **`NeutralTrade.getUserBalanceByVaultIds` only returns Bundle vaults**. Drift depositor balances are outside this package’s scope.
|
|
14
|
+
|
|
11
15
|
## Installation
|
|
12
16
|
|
|
13
17
|
```bash
|
|
@@ -24,7 +28,7 @@ pnpm add @neutral-trade/sdk
|
|
|
24
28
|
bun add @neutral-trade/sdk
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
Runtime dependencies are declared normally (Anchor, Solana web3, etc.); consumers should not need extra setup for Bundle flows.
|
|
28
32
|
|
|
29
33
|
## Quick Start
|
|
30
34
|
|
|
@@ -36,33 +40,28 @@ const sdk = await NeutralTrade.create({
|
|
|
36
40
|
rpcUrl: 'YOUR_RPC_URL_HERE'
|
|
37
41
|
})
|
|
38
42
|
|
|
39
|
-
// Get user balance for
|
|
43
|
+
// Get user balance for Bundle vaults only
|
|
40
44
|
const balances = await sdk.getUserBalanceByVaultIds({
|
|
41
|
-
vaultIds: [VaultId.
|
|
45
|
+
vaultIds: [VaultId.hyperliquid_funding_arb_48, VaultId.alp_delta_neutral_49],
|
|
42
46
|
userAddress: 'YOUR_WALLET_ADDRESS'
|
|
43
47
|
})
|
|
44
48
|
|
|
45
49
|
console.log(balances)
|
|
46
50
|
```
|
|
47
51
|
|
|
48
|
-
##
|
|
52
|
+
## Vault registry
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
Built-in configs include multiple vault **types** in metadata (`VaultType` may still include `Drift` for historical entries). **Balance queries** in this package apply only to **`VaultType.Bundle`** rows.
|
|
51
55
|
|
|
52
56
|
```typescript
|
|
53
57
|
import { VaultId } from '@neutral-trade/sdk'
|
|
54
58
|
|
|
55
|
-
//
|
|
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
|
-
|
|
60
|
-
// Bundle Vaults
|
|
59
|
+
// Examples — Bundle vaults (balances supported here)
|
|
61
60
|
VaultId.hyperliquid_funding_arb_48 // Hyperliquid Funding Arb
|
|
62
61
|
VaultId.alp_delta_neutral_49 // ALP Delta Neutral
|
|
63
62
|
```
|
|
64
63
|
|
|
65
|
-
See the [documentation](https://sdk.neutral.trade) for the complete list of
|
|
64
|
+
See the [documentation](https://sdk.neutral.trade) for the complete list of vault IDs.
|
|
66
65
|
|
|
67
66
|
## Configuration Registry
|
|
68
67
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { AnchorProvider, IdlAccounts, Program } from "@coral-xyz/anchor";
|
|
1
|
+
import { AnchorProvider, IdlAccounts, Program, Wallet } from "@coral-xyz/anchor";
|
|
2
2
|
import { AnchorProvider as AnchorProvider$1, IdlAccounts as IdlAccounts$1, Program as Program$1 } from "@coral-xyz/anchor-32";
|
|
3
3
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
|
-
import { VaultClient } from "@drift-labs/vaults-sdk";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
|
|
6
|
+
//#region src/constants/client.d.ts
|
|
7
|
+
declare function createDummyWallet(): Wallet;
|
|
8
|
+
declare function createConnection(rpcUrl: string): Connection;
|
|
9
|
+
declare function createAnchorProviderV29(connection: Connection, wallet?: Wallet): AnchorProvider;
|
|
10
|
+
declare function createAnchorProviderV32(connection: Connection, wallet?: Wallet): AnchorProvider$1;
|
|
11
|
+
//#endregion
|
|
7
12
|
//#region src/types/tokens.d.ts
|
|
8
13
|
declare enum SupportedChain {
|
|
9
14
|
Solana = "Solana",
|
|
@@ -5232,11 +5237,6 @@ declare enum VaultId {
|
|
|
5232
5237
|
* Uses registry value if present, otherwise defaults to V1
|
|
5233
5238
|
*/
|
|
5234
5239
|
declare function getBundleProgramId(vault: VaultRegistryEntry): BundleProgramId | undefined;
|
|
5235
|
-
/**
|
|
5236
|
-
* Get Drift Program ID for a vault config as PublicKey
|
|
5237
|
-
* Uses registry value if present, otherwise defaults to VAULT_PROGRAM_ID
|
|
5238
|
-
*/
|
|
5239
|
-
declare function getDriftProgramId(vault: VaultRegistryEntry): string | undefined;
|
|
5240
5240
|
declare const vaults$1: VaultRegistry;
|
|
5241
5241
|
declare function isValidVaultAddress(address: string): boolean;
|
|
5242
5242
|
declare function getVaultByAddress(address: string): VaultRegistryEntry | undefined;
|
|
@@ -5250,21 +5250,27 @@ interface NeutralTradeConfig {
|
|
|
5250
5250
|
/** Optional fallback prices map. Prices are fetched from Pyth Network first; fallback is used only if Pyth returns incomplete data */
|
|
5251
5251
|
fallbackPrices?: Partial<Record<SupportedToken, number>>;
|
|
5252
5252
|
}
|
|
5253
|
+
interface NeutralTradeCoreContext {
|
|
5254
|
+
connection: Connection;
|
|
5255
|
+
bundleProgramV1: Program<NtbundleV1>;
|
|
5256
|
+
bundleProgramV2: Program$1<NtbundleV2>;
|
|
5257
|
+
vaults: VaultRegistry;
|
|
5258
|
+
priceMap: Map<SupportedToken, number>;
|
|
5259
|
+
}
|
|
5253
5260
|
declare class NeutralTrade {
|
|
5254
5261
|
readonly connection: Connection;
|
|
5255
5262
|
readonly bundleProgramV1: Program<NtbundleV1>;
|
|
5256
5263
|
readonly bundleProgramV2: Program$1<NtbundleV2>;
|
|
5257
|
-
readonly driftVaultClient: VaultClient;
|
|
5258
5264
|
/** Vault configurations (built-in merged with remote if registryUrl was provided) */
|
|
5259
5265
|
readonly vaults: VaultRegistry;
|
|
5260
5266
|
/** Price map for deposit tokens */
|
|
5261
5267
|
readonly priceMap: Map<SupportedToken, number>;
|
|
5262
|
-
|
|
5268
|
+
protected constructor(connection: Connection, bundleProgramV1: Program<NtbundleV1>, bundleProgramV2: Program$1<NtbundleV2>, vaults: VaultRegistry, priceMap: Map<SupportedToken, number>);
|
|
5263
5269
|
/**
|
|
5264
5270
|
* Create a new NeutralTrade instance
|
|
5265
|
-
* This is async because DriftClient needs to subscribe
|
|
5266
5271
|
* @throws Error if registryUrl is provided but fetch fails or validation fails
|
|
5267
5272
|
*/
|
|
5273
|
+
protected static initCore(config: NeutralTradeConfig): Promise<NeutralTradeCoreContext>;
|
|
5268
5274
|
static create(config: NeutralTradeConfig): Promise<NeutralTrade>;
|
|
5269
5275
|
/**
|
|
5270
5276
|
* Fetch vault configurations from a remote registry URL
|
|
@@ -5273,7 +5279,8 @@ declare class NeutralTrade {
|
|
|
5273
5279
|
*/
|
|
5274
5280
|
private static fetchVaultsFromRegistry;
|
|
5275
5281
|
/**
|
|
5276
|
-
* Get user balance for
|
|
5282
|
+
* Get user balance for Bundle vaults only.
|
|
5283
|
+
* Drift vault IDs are ignored (no keys in the result).
|
|
5277
5284
|
*/
|
|
5278
5285
|
getUserBalanceByVaultIds({
|
|
5279
5286
|
vaultIds,
|
|
@@ -5317,4 +5324,4 @@ declare function deriveUserPDA(userKey: PublicKey, bundlePDA: PublicKey, program
|
|
|
5317
5324
|
*/
|
|
5318
5325
|
declare function getVaultDepositorAddressSync(programId: PublicKey, vault: PublicKey, authority: PublicKey): PublicKey;
|
|
5319
5326
|
//#endregion
|
|
5320
|
-
export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type OracleData, type PointsVaultEntry, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type VaultBalanceData, VaultCategory, type VaultRegistryEntry as VaultConfig, type VaultRegistry as VaultConfigRecord, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId,
|
|
5327
|
+
export { type BundleAccount, BundleProgramId, NeutralTrade, type NeutralTradeConfig, type NeutralTradeCoreContext, type OracleData, type PointsVaultEntry, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type VaultBalanceData, VaultCategory, type VaultRegistryEntry as VaultConfig, type VaultRegistry as VaultConfigRecord, VaultId, VaultType, createAnchorProviderV29, createAnchorProviderV32, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, createConnection, createDummyWallet, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId, getPointsVaults, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, isValidVaultAddress, tokens, vaults$1 as vaults };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import { AnchorProvider, Program } from "@coral-xyz/anchor";
|
|
2
2
|
import { AnchorProvider as AnchorProvider$1, Program as Program$1 } from "@coral-xyz/anchor-32";
|
|
3
3
|
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
4
|
-
import { IDL, VAULT_PROGRAM_ID, VaultClient } from "@drift-labs/vaults-sdk";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
import { BulkAccountLoader, DriftClient, QUOTE_PRECISION, TEN, convertToNumber } from "@drift-labs/sdk";
|
|
7
|
-
import { BN } from "bn.js";
|
|
8
5
|
|
|
6
|
+
//#region src/constants/addr.ts
|
|
7
|
+
const ZERO_ADDRESS = new PublicKey("11111111111111111111111111111111");
|
|
8
|
+
const WSOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/constants/client.ts
|
|
12
|
+
function createDummyWallet() {
|
|
13
|
+
return {
|
|
14
|
+
publicKey: ZERO_ADDRESS,
|
|
15
|
+
signTransaction: async (tx) => tx,
|
|
16
|
+
signAllTransactions: async (txs) => txs,
|
|
17
|
+
payer: Keypair.generate()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createConnection(rpcUrl) {
|
|
21
|
+
return new Connection(rpcUrl, "confirmed");
|
|
22
|
+
}
|
|
23
|
+
function createAnchorProviderV29(connection, wallet) {
|
|
24
|
+
return new AnchorProvider(connection, wallet ?? createDummyWallet(), AnchorProvider.defaultOptions());
|
|
25
|
+
}
|
|
26
|
+
function createAnchorProviderV32(connection, wallet) {
|
|
27
|
+
return new AnchorProvider$1(connection, wallet ?? createDummyWallet(), AnchorProvider$1.defaultOptions());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
9
31
|
//#region src/constants/points-vaults.ts
|
|
10
32
|
/**
|
|
11
33
|
* Get vaults that earn points, filtered by pointsEnabled !== false.
|
|
@@ -8087,31 +8109,6 @@ var bundle_v2_default = {
|
|
|
8087
8109
|
]
|
|
8088
8110
|
};
|
|
8089
8111
|
|
|
8090
|
-
//#endregion
|
|
8091
|
-
//#region src/constants/addr.ts
|
|
8092
|
-
const ZERO_ADDRESS = new PublicKey("11111111111111111111111111111111");
|
|
8093
|
-
const WSOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");
|
|
8094
|
-
|
|
8095
|
-
//#endregion
|
|
8096
|
-
//#region src/constants/client.ts
|
|
8097
|
-
function createDummyWallet() {
|
|
8098
|
-
return {
|
|
8099
|
-
publicKey: ZERO_ADDRESS,
|
|
8100
|
-
signTransaction: async (tx) => tx,
|
|
8101
|
-
signAllTransactions: async (txs) => txs,
|
|
8102
|
-
payer: Keypair.generate()
|
|
8103
|
-
};
|
|
8104
|
-
}
|
|
8105
|
-
function createConnection(rpcUrl) {
|
|
8106
|
-
return new Connection(rpcUrl, "confirmed");
|
|
8107
|
-
}
|
|
8108
|
-
function createAnchorProviderV29(connection, wallet) {
|
|
8109
|
-
return new AnchorProvider(connection, wallet ?? createDummyWallet(), AnchorProvider.defaultOptions());
|
|
8110
|
-
}
|
|
8111
|
-
function createAnchorProviderV32(connection, wallet) {
|
|
8112
|
-
return new AnchorProvider$1(connection, wallet ?? createDummyWallet(), AnchorProvider$1.defaultOptions());
|
|
8113
|
-
}
|
|
8114
|
-
|
|
8115
8112
|
//#endregion
|
|
8116
8113
|
//#region src/constants/programs.ts
|
|
8117
8114
|
let BundleProgramId = /* @__PURE__ */ function(BundleProgramId$1) {
|
|
@@ -9286,6 +9283,7 @@ const VaultRegistryArraySchema = z.array(VaultRegistryEntrySchema).superRefine((
|
|
|
9286
9283
|
|
|
9287
9284
|
//#endregion
|
|
9288
9285
|
//#region src/constants/vaults.ts
|
|
9286
|
+
const VAULT_PROGRAM_ID = new PublicKey("vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR");
|
|
9289
9287
|
/**
|
|
9290
9288
|
* Get Bundle Program ID for a vault config
|
|
9291
9289
|
* Uses registry value if present, otherwise defaults to V1
|
|
@@ -9550,101 +9548,6 @@ async function getBundleBalances({ vaultIds, userAddress, vaults: vaults$1, bund
|
|
|
9550
9548
|
return result;
|
|
9551
9549
|
}
|
|
9552
9550
|
|
|
9553
|
-
//#endregion
|
|
9554
|
-
//#region src/utils/drift.ts
|
|
9555
|
-
/**
|
|
9556
|
-
* Calculate total earnings for Drift vault
|
|
9557
|
-
*/
|
|
9558
|
-
function getDriftVaultTotalEarning({ netDepositToken, requestWithdrawToken, balanceToken }) {
|
|
9559
|
-
const realizedProfit = -Math.min(netDepositToken - requestWithdrawToken, 0);
|
|
9560
|
-
const unrealizedProfit = balanceToken - Math.max(netDepositToken - requestWithdrawToken, 0);
|
|
9561
|
-
return realizedProfit + unrealizedProfit >= -.01 && realizedProfit + unrealizedProfit <= .01 ? 0 : realizedProfit + unrealizedProfit;
|
|
9562
|
-
}
|
|
9563
|
-
/**
|
|
9564
|
-
* Calculate Drift vault balance from vault and vaultDepositor accounts
|
|
9565
|
-
*/
|
|
9566
|
-
async function calculateDriftVaultBalance({ vault, vaultDepositor, driftVaultClient, profitShareFeePercent = 0, asset = SupportedToken.USDC }) {
|
|
9567
|
-
const vaultClient = driftVaultClient;
|
|
9568
|
-
const driftClient = vaultClient.driftClient;
|
|
9569
|
-
const vaultEquity = await vaultClient.calculateVaultEquity({ vault });
|
|
9570
|
-
const spotMarket = driftClient.getSpotMarketAccount(vault.spotMarketIndex);
|
|
9571
|
-
if (!spotMarket) throw new Error("Spot market not found");
|
|
9572
|
-
const spotPrice = convertToNumber(driftClient.getOracleDataForSpotMarket(vault.spotMarketIndex).price, QUOTE_PRECISION);
|
|
9573
|
-
const vaultEquityNum = convertToNumber(vaultEquity, QUOTE_PRECISION);
|
|
9574
|
-
const vaultDepositorShare = vaultDepositor.vaultShares.toNumber();
|
|
9575
|
-
const activeShares = vaultDepositorShare - vaultDepositor.lastWithdrawRequest.shares.toNumber();
|
|
9576
|
-
const balanceUsd = vault.totalShares.toNumber() > 0 ? vaultEquityNum * activeShares / vault.totalShares.toNumber() : 0;
|
|
9577
|
-
const balanceToken = spotPrice > 0 ? balanceUsd / spotPrice : 0;
|
|
9578
|
-
const spotPrecision = TEN.pow(new BN(spotMarket.decimals));
|
|
9579
|
-
const netDeposit = convertToNumber(vaultDepositor.netDeposits, spotPrecision);
|
|
9580
|
-
const requestWithdrawToken = convertToNumber(vaultDepositor.lastWithdrawRequest.value, spotPrecision);
|
|
9581
|
-
const profitShareFeePaid = convertToNumber(vaultDepositor.profitShareFeePaid, spotPrecision);
|
|
9582
|
-
const highWaterMark = netDeposit + convertToNumber(vaultDepositor.cumulativeProfitShareAmount, spotPrecision);
|
|
9583
|
-
let pendingProfitShareFee = 0;
|
|
9584
|
-
if (balanceToken > highWaterMark) pendingProfitShareFee = (balanceToken - highWaterMark) * profitShareFeePercent / 100;
|
|
9585
|
-
const netEarnings = getDriftVaultTotalEarning({
|
|
9586
|
-
netDepositToken: netDeposit,
|
|
9587
|
-
requestWithdrawToken,
|
|
9588
|
-
balanceToken
|
|
9589
|
-
});
|
|
9590
|
-
const totalDeposit = balanceToken + requestWithdrawToken;
|
|
9591
|
-
return {
|
|
9592
|
-
balanceToken,
|
|
9593
|
-
balanceUsd,
|
|
9594
|
-
netEarnings,
|
|
9595
|
-
netEarningsUsd: netEarnings * spotPrice,
|
|
9596
|
-
totalDepositUsd: totalDeposit * spotPrice,
|
|
9597
|
-
totalDeposit,
|
|
9598
|
-
requestWithdrawToken,
|
|
9599
|
-
spotPrice,
|
|
9600
|
-
netDeposit,
|
|
9601
|
-
vaultShares: vaultDepositorShare,
|
|
9602
|
-
feesPaid: profitShareFeePaid,
|
|
9603
|
-
highWaterMark,
|
|
9604
|
-
pendingProfitShareFee,
|
|
9605
|
-
pendingFee: pendingProfitShareFee,
|
|
9606
|
-
pendingFeeUsd: pendingProfitShareFee * spotPrice,
|
|
9607
|
-
asset
|
|
9608
|
-
};
|
|
9609
|
-
}
|
|
9610
|
-
async function getDriftBalances({ vaultIds, userAddress, vaults: vaults$1, driftVaultClient }) {
|
|
9611
|
-
const result = {};
|
|
9612
|
-
const userPublicKey = new PublicKey(userAddress);
|
|
9613
|
-
const vaultEntries = vaultIds.map((id) => ({
|
|
9614
|
-
vaultId: id,
|
|
9615
|
-
config: vaults$1[id]
|
|
9616
|
-
})).filter((entry) => entry.config !== void 0);
|
|
9617
|
-
if (vaultEntries.length === 0) return result;
|
|
9618
|
-
const vaultAddresses = vaultEntries.map(({ config }) => new PublicKey(config.vaultAddress));
|
|
9619
|
-
const vaultDepositorPDAs = vaultEntries.map(({ config }) => {
|
|
9620
|
-
const vaultPubkey = new PublicKey(config.vaultAddress);
|
|
9621
|
-
return getVaultDepositorAddressSync(config.driftProgramId ? new PublicKey(config.driftProgramId) : VAULT_PROGRAM_ID, vaultPubkey, userPublicKey);
|
|
9622
|
-
});
|
|
9623
|
-
const [vaultsData, vaultDepositors] = await Promise.all([driftVaultClient.program.account.vault.fetchMultiple(vaultAddresses), driftVaultClient.program.account.vaultDepositor.fetchMultiple(vaultDepositorPDAs)]);
|
|
9624
|
-
for (let i = 0; i < vaultEntries.length; i++) {
|
|
9625
|
-
const { vaultId, config } = vaultEntries[i];
|
|
9626
|
-
const vault = vaultsData[i];
|
|
9627
|
-
const vaultDepositor = vaultDepositors[i];
|
|
9628
|
-
if (!vault || !vaultDepositor) {
|
|
9629
|
-
result[vaultId] = null;
|
|
9630
|
-
continue;
|
|
9631
|
-
}
|
|
9632
|
-
try {
|
|
9633
|
-
result[vaultId] = await calculateDriftVaultBalance({
|
|
9634
|
-
vault,
|
|
9635
|
-
vaultDepositor,
|
|
9636
|
-
driftVaultClient,
|
|
9637
|
-
profitShareFeePercent: (config.pfee ?? 0) * 100,
|
|
9638
|
-
asset: config.depositToken
|
|
9639
|
-
});
|
|
9640
|
-
} catch (e) {
|
|
9641
|
-
console.error(`Error calculating balance for drift vault ${vaultId}:`, e);
|
|
9642
|
-
result[vaultId] = null;
|
|
9643
|
-
}
|
|
9644
|
-
}
|
|
9645
|
-
return result;
|
|
9646
|
-
}
|
|
9647
|
-
|
|
9648
9551
|
//#endregion
|
|
9649
9552
|
//#region src/utils/price.ts
|
|
9650
9553
|
/**
|
|
@@ -9694,7 +9597,6 @@ async function fetchPricesFromPyth(tokens$1) {
|
|
|
9694
9597
|
}
|
|
9695
9598
|
/**
|
|
9696
9599
|
* Initialize price map by fetching from Pyth Network first, then using fallback prices for any missing
|
|
9697
|
-
* @param vaults - Vault configurations to determine which tokens need prices
|
|
9698
9600
|
* @param fallbackPrices - Optional fallback prices to use if Pyth fetch fails or returns incomplete data
|
|
9699
9601
|
*/
|
|
9700
9602
|
async function initializePrices(fallbackPrices) {
|
|
@@ -9717,51 +9619,27 @@ var NeutralTrade = class NeutralTrade {
|
|
|
9717
9619
|
connection;
|
|
9718
9620
|
bundleProgramV1;
|
|
9719
9621
|
bundleProgramV2;
|
|
9720
|
-
driftVaultClient;
|
|
9721
9622
|
/** Vault configurations (built-in merged with remote if registryUrl was provided) */
|
|
9722
9623
|
vaults;
|
|
9723
9624
|
/** Price map for deposit tokens */
|
|
9724
9625
|
priceMap;
|
|
9725
|
-
constructor(connection, bundleProgramV1, bundleProgramV2,
|
|
9626
|
+
constructor(connection, bundleProgramV1, bundleProgramV2, vaults$1, priceMap) {
|
|
9726
9627
|
this.connection = connection;
|
|
9727
9628
|
this.bundleProgramV1 = bundleProgramV1;
|
|
9728
9629
|
this.bundleProgramV2 = bundleProgramV2;
|
|
9729
|
-
this.driftVaultClient = driftVaultClient;
|
|
9730
9630
|
this.vaults = vaults$1;
|
|
9731
9631
|
this.priceMap = priceMap;
|
|
9732
9632
|
}
|
|
9733
9633
|
/**
|
|
9734
9634
|
* Create a new NeutralTrade instance
|
|
9735
|
-
* This is async because DriftClient needs to subscribe
|
|
9736
9635
|
* @throws Error if registryUrl is provided but fetch fails or validation fails
|
|
9737
9636
|
*/
|
|
9738
|
-
static async
|
|
9637
|
+
static async initCore(config) {
|
|
9739
9638
|
const connection = createConnection(config.rpcUrl);
|
|
9740
|
-
const dummyWallet = createDummyWallet();
|
|
9741
9639
|
const providerV29 = createAnchorProviderV29(connection);
|
|
9742
9640
|
const providerV32 = createAnchorProviderV32(connection);
|
|
9743
9641
|
const bundleProgramV1 = createBundleProgramV1(providerV29);
|
|
9744
9642
|
const bundleProgramV2 = createBundleProgramV2(providerV32);
|
|
9745
|
-
const driftClient = new DriftClient({
|
|
9746
|
-
connection,
|
|
9747
|
-
wallet: dummyWallet,
|
|
9748
|
-
env: "mainnet-beta",
|
|
9749
|
-
opts: {
|
|
9750
|
-
commitment: "confirmed",
|
|
9751
|
-
skipPreflight: false,
|
|
9752
|
-
preflightCommitment: "confirmed"
|
|
9753
|
-
},
|
|
9754
|
-
accountSubscription: {
|
|
9755
|
-
type: "polling",
|
|
9756
|
-
accountLoader: new BulkAccountLoader(connection, "confirmed", 0)
|
|
9757
|
-
}
|
|
9758
|
-
});
|
|
9759
|
-
await driftClient.subscribe();
|
|
9760
|
-
const driftVaultClient = new VaultClient({
|
|
9761
|
-
driftClient,
|
|
9762
|
-
program: new (await (import("@coral-xyz/anchor"))).Program(IDL, VAULT_PROGRAM_ID, providerV29),
|
|
9763
|
-
cliMode: false
|
|
9764
|
-
});
|
|
9765
9643
|
let vaults$1 = { ...vaults };
|
|
9766
9644
|
if (config.registryUrl) {
|
|
9767
9645
|
const remoteVaults = await NeutralTrade.fetchVaultsFromRegistry(config.registryUrl);
|
|
@@ -9771,7 +9649,17 @@ var NeutralTrade = class NeutralTrade {
|
|
|
9771
9649
|
};
|
|
9772
9650
|
}
|
|
9773
9651
|
const priceMap = await initializePrices(config.fallbackPrices);
|
|
9774
|
-
return
|
|
9652
|
+
return {
|
|
9653
|
+
connection,
|
|
9654
|
+
bundleProgramV1,
|
|
9655
|
+
bundleProgramV2,
|
|
9656
|
+
vaults: vaults$1,
|
|
9657
|
+
priceMap
|
|
9658
|
+
};
|
|
9659
|
+
}
|
|
9660
|
+
static async create(config) {
|
|
9661
|
+
const core = await this.initCore(config);
|
|
9662
|
+
return new NeutralTrade(core.connection, core.bundleProgramV1, core.bundleProgramV2, core.vaults, core.priceMap);
|
|
9775
9663
|
}
|
|
9776
9664
|
/**
|
|
9777
9665
|
* Fetch vault configurations from a remote registry URL
|
|
@@ -9787,36 +9675,25 @@ var NeutralTrade = class NeutralTrade {
|
|
|
9787
9675
|
return toVaultRegistry(parseResult.data);
|
|
9788
9676
|
}
|
|
9789
9677
|
/**
|
|
9790
|
-
* Get user balance for
|
|
9678
|
+
* Get user balance for Bundle vaults only.
|
|
9679
|
+
* Drift vault IDs are ignored (no keys in the result).
|
|
9791
9680
|
*/
|
|
9792
9681
|
async getUserBalanceByVaultIds({ vaultIds, userAddress }) {
|
|
9793
|
-
const driftVaultIds = vaultIds.filter((id) => {
|
|
9794
|
-
const config = this.vaults[id];
|
|
9795
|
-
return config && config.type === VaultType.Drift;
|
|
9796
|
-
});
|
|
9797
9682
|
const bundleVaultIds = vaultIds.filter((id) => {
|
|
9798
9683
|
const config = this.vaults[id];
|
|
9799
9684
|
return config && config.type === VaultType.Bundle;
|
|
9800
9685
|
});
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
userAddress,
|
|
9804
|
-
vaults: this.vaults,
|
|
9805
|
-
driftVaultClient: this.driftVaultClient
|
|
9806
|
-
}) : {}, bundleVaultIds.length > 0 ? getBundleBalances({
|
|
9686
|
+
if (bundleVaultIds.length === 0) return {};
|
|
9687
|
+
return await getBundleBalances({
|
|
9807
9688
|
vaultIds: bundleVaultIds,
|
|
9808
9689
|
userAddress,
|
|
9809
9690
|
vaults: this.vaults,
|
|
9810
9691
|
bundleProgramV1: this.bundleProgramV1,
|
|
9811
9692
|
bundleProgramV2: this.bundleProgramV2,
|
|
9812
9693
|
priceMap: this.priceMap
|
|
9813
|
-
})
|
|
9814
|
-
return {
|
|
9815
|
-
...driftResults,
|
|
9816
|
-
...bundleResults
|
|
9817
|
-
};
|
|
9694
|
+
});
|
|
9818
9695
|
}
|
|
9819
9696
|
};
|
|
9820
9697
|
|
|
9821
9698
|
//#endregion
|
|
9822
|
-
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId,
|
|
9699
|
+
export { BundleProgramId, NeutralTrade, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, createAnchorProviderV29, createAnchorProviderV32, createBundleProgramV1, createBundleProgramV2, createBundlePrograms, createConnection, createDummyWallet, deriveOraclePDA, deriveUserPDA, estimatePendingBundleFeeToken, getBundleProgramId, getPointsVaults, 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.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "SDK for Neutral Trade vaults",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/neutral-trade/sdk#readme",
|
|
@@ -25,8 +25,6 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@coral-xyz/anchor": "0.29.0",
|
|
27
27
|
"@coral-xyz/anchor-32": "npm:@coral-xyz/anchor@0.32.0",
|
|
28
|
-
"@drift-labs/sdk": "2.155.0-beta.5",
|
|
29
|
-
"@drift-labs/vaults-sdk": "0.9.264",
|
|
30
28
|
"@solana/web3.js": "^1.98.4",
|
|
31
29
|
"@types/bn.js": "^5.2.0",
|
|
32
30
|
"bn.js": "^5.2.3",
|
|
@@ -38,9 +36,9 @@
|
|
|
38
36
|
"@antfu/utils": "^9.3.0",
|
|
39
37
|
"@coral-xyz/anchor": "0.29.0",
|
|
40
38
|
"@coral-xyz/anchor-32": "npm:@coral-xyz/anchor@0.32.0",
|
|
41
|
-
"@drift-labs/sdk": "2.155.0-beta.5",
|
|
42
39
|
"@solana/web3.js": "^1.98.4",
|
|
43
40
|
"@types/node": "^25.0.1",
|
|
41
|
+
"baseline-browser-mapping": "^2.10.27",
|
|
44
42
|
"bumpp": "^10.3.2",
|
|
45
43
|
"dotenv": "^17.2.3",
|
|
46
44
|
"eslint": "^9.39.2",
|
|
@@ -62,7 +60,7 @@
|
|
|
62
60
|
"pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && npx lint-staged"
|
|
63
61
|
},
|
|
64
62
|
"lint-staged": {
|
|
65
|
-
"
|
|
63
|
+
"*.{js,cjs,mjs,ts,mts,cts,tsx,jsx}": "eslint --fix"
|
|
66
64
|
},
|
|
67
65
|
"scripts": {
|
|
68
66
|
"generate": "tsx scripts/generate-vault-ids.ts",
|