@neutral-trade/sdk 0.4.5 → 0.4.8
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 +41 -4
- package/dist/index.mjs +34 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as SupportedToken, B as DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, C as VaultRegistryEntry, D as UserBundleAccount, E as OracleData, F as ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, G as getDefaultBundleProgramIdByCluster, H as assertAllowlistedBundleProgramId, I as BUNDLE_PROGRAM_ID_V2_MAINNET, K as isAllowlistedBundleProgramId, L as BundleCluster, M as getSolanaTokenDecimals, N as getSolanaTokenMint, O as UserBundleTempData, P as tokens, R as BundleProgram, S as VaultRegistry, T as BundleAccount, U as createAllowlistedBundleProgram, V as DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, W as createBundleProgramById, _ as vaults, b as VaultBalanceData, d as NeutralTradeConfig, f as getBundleProgramId, g as isValidVaultAddress, h as getVaultRegistry, j as Token, k as SupportedChain, m as getVaultById, p as getVaultByAddress, t as NeutralTradeCoreContext, u as NeutralTrade, v as vaultsDevnet, w as VaultType, x as VaultCategory, y as UserBalanceResult, z as BundleProvider } from "./neutral-trade-core-BGjOiCsY.mjs";
|
|
2
|
-
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
|
|
1
|
+
import { A as SupportedToken, B as DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, C as VaultRegistryEntry, D as UserBundleAccount, E as OracleData, F as ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, G as getDefaultBundleProgramIdByCluster, H as assertAllowlistedBundleProgramId, I as BUNDLE_PROGRAM_ID_V2_MAINNET, K as isAllowlistedBundleProgramId, L as BundleCluster, M as getSolanaTokenDecimals, N as getSolanaTokenMint, O as UserBundleTempData, P as tokens, R as BundleProgram, S as VaultRegistry, T as BundleAccount, U as createAllowlistedBundleProgram, V as DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, W as createBundleProgramById, _ as vaults$1, b as VaultBalanceData, d as NeutralTradeConfig, f as getBundleProgramId, g as isValidVaultAddress, h as getVaultRegistry, j as Token, k as SupportedChain, m as getVaultById, p as getVaultByAddress, t as NeutralTradeCoreContext, u as NeutralTrade, v as vaultsDevnet, w as VaultType, x as VaultCategory, y as UserBalanceResult, z as BundleProvider } from "./neutral-trade-core-BGjOiCsY.mjs";
|
|
2
|
+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
|
|
3
3
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
4
4
|
import BN from "bn.js";
|
|
5
5
|
|
|
@@ -199,6 +199,24 @@ declare function parseAmountRawToBigInt(amountRaw: string): bigint;
|
|
|
199
199
|
*/
|
|
200
200
|
declare function humanFloatToAmountRawString(human: number, decimals: number): string;
|
|
201
201
|
//#endregion
|
|
202
|
+
//#region src/utils/bundle.d.ts
|
|
203
|
+
/**
|
|
204
|
+
* Estimated unpaid bundle fees in deposit token (mgmt + performance), matching on-chain `charge_user_fees`.
|
|
205
|
+
*/
|
|
206
|
+
declare function estimatePendingBundleFeeToken({
|
|
207
|
+
oracleData,
|
|
208
|
+
bundleData,
|
|
209
|
+
userBundle,
|
|
210
|
+
assetDecimals,
|
|
211
|
+
nowUnixSeconds
|
|
212
|
+
}: {
|
|
213
|
+
oracleData: OracleData;
|
|
214
|
+
bundleData: BundleAccount;
|
|
215
|
+
userBundle: UserBundleAccount;
|
|
216
|
+
assetDecimals: number;
|
|
217
|
+
nowUnixSeconds?: number;
|
|
218
|
+
}): number;
|
|
219
|
+
//#endregion
|
|
202
220
|
//#region src/utils/bundle-fee-override.d.ts
|
|
203
221
|
/** Mirrors `bundle-sc` `FEE_OVERRIDE_*` bit flags. */
|
|
204
222
|
declare const FEE_OVERRIDE: {
|
|
@@ -206,6 +224,7 @@ declare const FEE_OVERRIDE: {
|
|
|
206
224
|
readonly WITHDRAWAL: number;
|
|
207
225
|
readonly PERFORMANCE: number;
|
|
208
226
|
readonly MANAGEMENT: number;
|
|
227
|
+
readonly ALL: number;
|
|
209
228
|
};
|
|
210
229
|
interface EffectiveFeeBps {
|
|
211
230
|
depositFeeBps: number;
|
|
@@ -213,6 +232,14 @@ interface EffectiveFeeBps {
|
|
|
213
232
|
performanceFeeBps: number;
|
|
214
233
|
managementFeeBps: number;
|
|
215
234
|
}
|
|
235
|
+
/** Normalized per-user fee override fields (bps + flag mask). */
|
|
236
|
+
interface UserFeeOverrideFields {
|
|
237
|
+
feeOverrideFlags: number;
|
|
238
|
+
customDepositFeeBps: number;
|
|
239
|
+
customWithdrawalFeeBps: number;
|
|
240
|
+
customPerformanceFeeBps: number;
|
|
241
|
+
customManagementFeeBps: number;
|
|
242
|
+
}
|
|
216
243
|
/** Decimal fees matching frontend `VaultConfig` (`0.01` = 1%). */
|
|
217
244
|
interface EffectiveVaultFeeDecimals {
|
|
218
245
|
dfee: number;
|
|
@@ -222,12 +249,22 @@ interface EffectiveVaultFeeDecimals {
|
|
|
222
249
|
}
|
|
223
250
|
declare function bpsToFeeDecimal(bps: number): number;
|
|
224
251
|
declare function feeDecimalToBps(decimal: number): number;
|
|
252
|
+
declare function bpsToPercentLabel(bps: number): string;
|
|
253
|
+
declare function hasFeeOverrideFlag(flags: number, bit: number): boolean;
|
|
254
|
+
declare function buildFeeOverrideMask(flags: {
|
|
255
|
+
deposit?: boolean;
|
|
256
|
+
withdrawal?: boolean;
|
|
257
|
+
performance?: boolean;
|
|
258
|
+
management?: boolean;
|
|
259
|
+
}): number;
|
|
260
|
+
declare function formatFeeOverrideFlags(flags: number): string;
|
|
261
|
+
declare function readUserFeeOverrideFields(account: Record<string, unknown>): UserFeeOverrideFields;
|
|
225
262
|
declare function vaultFeeDecimalsToBps(fees: EffectiveVaultFeeDecimals): EffectiveFeeBps;
|
|
226
263
|
declare function effectiveFeeBpsToDecimals(fees: EffectiveFeeBps): EffectiveVaultFeeDecimals;
|
|
227
264
|
/**
|
|
228
265
|
* Apply per-user fee override flags onto default bps (bundle or vault-config defaults).
|
|
229
266
|
*/
|
|
230
|
-
declare function resolveEffectiveFeeBpsFromDefaults(defaults: EffectiveFeeBps, user:
|
|
267
|
+
declare function resolveEffectiveFeeBpsFromDefaults(defaults: EffectiveFeeBps, user: UserFeeOverrideFields): EffectiveFeeBps;
|
|
231
268
|
/**
|
|
232
269
|
* Mirror on-chain `resolve_effective_fees`. Returns fee rates in bps.
|
|
233
270
|
*/
|
|
@@ -326,4 +363,4 @@ declare function derivePendingAuthPDA(bundlePDA: PublicKey, programId: PublicKey
|
|
|
326
363
|
*/
|
|
327
364
|
declare function getVaultDepositorAddressSync(programId: PublicKey, vault: PublicKey, authority: PublicKey): PublicKey;
|
|
328
365
|
//#endregion
|
|
329
|
-
export { ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, BUNDLE_PROGRAM_ID_V2_MAINNET, type BuildBundleDepositInstructionsParams, type BuildBundleRequestWithdrawInstructionParams, type BundleAccount, type BundleCluster, type BundleProgram, type BundleProvider, DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, DevnetVaultId, type EffectiveFeeBps, type EffectiveVaultFeeDecimals, FEE_OVERRIDE, NeutralTrade, type NeutralTradeConfig, type NeutralTradeCoreContext, type OracleData, SEED_ORACLE, SEED_PENDING_AUTH, SEED_TEMP, SEED_USER, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type VaultBalanceData, VaultCategory, VaultId, type VaultRegistry, type VaultRegistryEntry, VaultType, assertAllowlistedBundleProgramId, bpsToFeeDecimal, buildBundleDepositInstructions, buildBundleRequestWithdrawInstruction, computeDepositFeePreview, computeRequestWithdrawalSharesFromAmountRaw, createAllowlistedBundleProgram, createBundleProgramById, createDummyWallet, deriveOraclePDA, derivePendingAuthPDA, deriveTempDataPDA, deriveUserPDA, effectiveFeeBpsToDecimals, feeDecimalToBps, getBundleProgramId, getDefaultBundleProgramIdByCluster, getSolanaTokenDecimals, getSolanaTokenMint, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, getVaultRegistry, hasAnyFeeOverride, hasCustomFeeRate, humanFloatToAmountRawString, isAllowlistedBundleProgramId, isValidVaultAddress, parseAmountRawToBigInt, resolveEffectiveFeeBps, resolveEffectiveFeeBpsFromDefaults, resolveEffectiveVaultFees, tokens, vaultFeeDecimalsToBps, vaults, vaultsDevnet };
|
|
366
|
+
export { ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, BUNDLE_PROGRAM_ID_V2_MAINNET, type BuildBundleDepositInstructionsParams, type BuildBundleRequestWithdrawInstructionParams, type BundleAccount, type BundleCluster, type BundleProgram, type BundleProvider, DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, DevnetVaultId, type EffectiveFeeBps, type EffectiveVaultFeeDecimals, FEE_OVERRIDE, NeutralTrade, type NeutralTradeConfig, type NeutralTradeCoreContext, type OracleData, SEED_ORACLE, SEED_PENDING_AUTH, SEED_TEMP, SEED_USER, SupportedChain, SupportedToken, type Token, type UserBalanceResult, type UserBundleAccount, type UserBundleTempData, type UserFeeOverrideFields, type VaultBalanceData, VaultCategory, VaultId, type VaultRegistry, type VaultRegistryEntry, VaultType, assertAllowlistedBundleProgramId, bpsToFeeDecimal, bpsToPercentLabel, buildBundleDepositInstructions, buildBundleRequestWithdrawInstruction, buildFeeOverrideMask, computeDepositFeePreview, computeRequestWithdrawalSharesFromAmountRaw, createAllowlistedBundleProgram, createBundleProgramById, createDummyWallet, deriveOraclePDA, derivePendingAuthPDA, deriveTempDataPDA, deriveUserPDA, effectiveFeeBpsToDecimals, estimatePendingBundleFeeToken, feeDecimalToBps, formatFeeOverrideFlags, getBundleProgramId, getDefaultBundleProgramIdByCluster, getSolanaTokenDecimals, getSolanaTokenMint, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, getVaultRegistry, hasAnyFeeOverride, hasCustomFeeRate, hasFeeOverrideFlag, humanFloatToAmountRawString, isAllowlistedBundleProgramId, isValidVaultAddress, parseAmountRawToBigInt, readUserFeeOverrideFields, resolveEffectiveFeeBps, resolveEffectiveFeeBpsFromDefaults, resolveEffectiveVaultFees, tokens, vaultFeeDecimalsToBps, vaults$1 as vaults, vaultsDevnet };
|
package/dist/index.mjs
CHANGED
|
@@ -191,7 +191,8 @@ const FEE_OVERRIDE = {
|
|
|
191
191
|
DEPOSIT: 1,
|
|
192
192
|
WITHDRAWAL: 2,
|
|
193
193
|
PERFORMANCE: 4,
|
|
194
|
-
MANAGEMENT: 8
|
|
194
|
+
MANAGEMENT: 8,
|
|
195
|
+
ALL: 15
|
|
195
196
|
};
|
|
196
197
|
const FEE_EPS = 1e-9;
|
|
197
198
|
function bpsToFeeDecimal(bps) {
|
|
@@ -200,6 +201,37 @@ function bpsToFeeDecimal(bps) {
|
|
|
200
201
|
function feeDecimalToBps(decimal) {
|
|
201
202
|
return Math.round(decimal * 1e4);
|
|
202
203
|
}
|
|
204
|
+
function bpsToPercentLabel(bps) {
|
|
205
|
+
return (bps / 100).toFixed(4).replace(/\.?0+$/, "");
|
|
206
|
+
}
|
|
207
|
+
function hasFeeOverrideFlag(flags, bit) {
|
|
208
|
+
return (flags & bit) !== 0;
|
|
209
|
+
}
|
|
210
|
+
function buildFeeOverrideMask(flags) {
|
|
211
|
+
let mask = 0;
|
|
212
|
+
if (flags.deposit) mask |= FEE_OVERRIDE.DEPOSIT;
|
|
213
|
+
if (flags.withdrawal) mask |= FEE_OVERRIDE.WITHDRAWAL;
|
|
214
|
+
if (flags.performance) mask |= FEE_OVERRIDE.PERFORMANCE;
|
|
215
|
+
if (flags.management) mask |= FEE_OVERRIDE.MANAGEMENT;
|
|
216
|
+
return mask;
|
|
217
|
+
}
|
|
218
|
+
function formatFeeOverrideFlags(flags) {
|
|
219
|
+
const parts = [];
|
|
220
|
+
if (hasFeeOverrideFlag(flags, FEE_OVERRIDE.DEPOSIT)) parts.push("deposit");
|
|
221
|
+
if (hasFeeOverrideFlag(flags, FEE_OVERRIDE.WITHDRAWAL)) parts.push("withdrawal");
|
|
222
|
+
if (hasFeeOverrideFlag(flags, FEE_OVERRIDE.PERFORMANCE)) parts.push("performance");
|
|
223
|
+
if (hasFeeOverrideFlag(flags, FEE_OVERRIDE.MANAGEMENT)) parts.push("management");
|
|
224
|
+
return parts.length > 0 ? parts.join(", ") : "none";
|
|
225
|
+
}
|
|
226
|
+
function readUserFeeOverrideFields(account) {
|
|
227
|
+
return {
|
|
228
|
+
feeOverrideFlags: toNum(account.feeOverrideFlags ?? account.fee_override_flags),
|
|
229
|
+
customDepositFeeBps: toNum(account.customDepositFeeBps ?? account.custom_deposit_fee_bps),
|
|
230
|
+
customWithdrawalFeeBps: toNum(account.customWithdrawalFeeBps ?? account.custom_withdrawal_fee_bps),
|
|
231
|
+
customPerformanceFeeBps: toNum(account.customPerformanceFeeBps ?? account.custom_performance_fee_bps),
|
|
232
|
+
customManagementFeeBps: toNum(account.customManagementFeeBps ?? account.custom_management_fee_bps)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
203
235
|
function toNum(value) {
|
|
204
236
|
if (typeof value === "number") return value;
|
|
205
237
|
if (typeof value === "bigint") return Number(value);
|
|
@@ -500,4 +532,4 @@ var NeutralTrade = class NeutralTrade {
|
|
|
500
532
|
};
|
|
501
533
|
|
|
502
534
|
//#endregion
|
|
503
|
-
export { ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, BUNDLE_PROGRAM_ID_V2_MAINNET, DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, DevnetVaultId, FEE_OVERRIDE, NeutralTrade, SEED_ORACLE, SEED_PENDING_AUTH, SEED_TEMP, SEED_USER, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, assertAllowlistedBundleProgramId, bpsToFeeDecimal, buildBundleDepositInstructions, buildBundleRequestWithdrawInstruction, computeDepositFeePreview, computeRequestWithdrawalSharesFromAmountRaw, createAllowlistedBundleProgram, createBundleProgramById, createDummyWallet, deriveOraclePDA, derivePendingAuthPDA, deriveTempDataPDA, deriveUserPDA, effectiveFeeBpsToDecimals, feeDecimalToBps, getBundleProgramId, getDefaultBundleProgramIdByCluster, getSolanaTokenDecimals, getSolanaTokenMint, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, getVaultRegistry, hasAnyFeeOverride, hasCustomFeeRate, humanFloatToAmountRawString, isAllowlistedBundleProgramId, isValidVaultAddress, parseAmountRawToBigInt, resolveEffectiveFeeBps, resolveEffectiveFeeBpsFromDefaults, resolveEffectiveVaultFees, tokens, vaultFeeDecimalsToBps, vaults, vaultsDevnet };
|
|
535
|
+
export { ALLOWLISTED_BUNDLE_PROGRAM_IDS_BY_CLUSTER, BUNDLE_PROGRAM_ID_V2_MAINNET, DEFAULT_BUNDLE_PROGRAM_ID_DEVNET, DEFAULT_BUNDLE_PROGRAM_ID_MAINNET, DevnetVaultId, FEE_OVERRIDE, NeutralTrade, SEED_ORACLE, SEED_PENDING_AUTH, SEED_TEMP, SEED_USER, SupportedChain, SupportedToken, VaultCategory, VaultId, VaultType, assertAllowlistedBundleProgramId, bpsToFeeDecimal, bpsToPercentLabel, buildBundleDepositInstructions, buildBundleRequestWithdrawInstruction, buildFeeOverrideMask, computeDepositFeePreview, computeRequestWithdrawalSharesFromAmountRaw, createAllowlistedBundleProgram, createBundleProgramById, createDummyWallet, deriveOraclePDA, derivePendingAuthPDA, deriveTempDataPDA, deriveUserPDA, effectiveFeeBpsToDecimals, estimatePendingBundleFeeToken, feeDecimalToBps, formatFeeOverrideFlags, getBundleProgramId, getDefaultBundleProgramIdByCluster, getSolanaTokenDecimals, getSolanaTokenMint, getVaultByAddress, getVaultById, getVaultDepositorAddressSync, getVaultRegistry, hasAnyFeeOverride, hasCustomFeeRate, hasFeeOverrideFlag, humanFloatToAmountRawString, isAllowlistedBundleProgramId, isValidVaultAddress, parseAmountRawToBigInt, readUserFeeOverrideFields, resolveEffectiveFeeBps, resolveEffectiveFeeBpsFromDefaults, resolveEffectiveVaultFees, tokens, vaultFeeDecimalsToBps, vaults, vaultsDevnet };
|