@mysten/deepbook-v3 1.0.12 → 1.1.1

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.
@@ -5,8 +5,8 @@ import { normalizeSuiAddress } from '@mysten/sui/utils';
5
5
 
6
6
  import { BalanceManagerContract } from '../transactions/balanceManager.js';
7
7
  import type { BalanceManager, MarginManager, Coin, Pool, MarginPool } from '../types/index.js';
8
- import type { CoinMap, PoolMap, MarginPoolMap } from './constants.js';
9
- import { ResourceNotFoundError, ErrorMessages } from './errors.js';
8
+ import type { CoinMap, PoolMap, MarginPoolMap, DeepbookPackageIds } from './constants.js';
9
+ import { ResourceNotFoundError, ConfigurationError, ErrorMessages } from './errors.js';
10
10
  import {
11
11
  mainnetCoins,
12
12
  mainnetPackageIds,
@@ -68,6 +68,8 @@ export class DeepBookConfig {
68
68
  coins,
69
69
  pools,
70
70
  marginPools,
71
+ packageIds,
72
+ pyth,
71
73
  }: {
72
74
  network: SuiClientTypes.Network;
73
75
  address: string;
@@ -79,11 +81,9 @@ export class DeepBookConfig {
79
81
  coins?: CoinMap;
80
82
  pools?: PoolMap;
81
83
  marginPools?: MarginPoolMap;
84
+ packageIds?: DeepbookPackageIds;
85
+ pyth?: { pythStateId: string; wormholeStateId: string };
82
86
  }) {
83
- if (network !== 'mainnet' && network !== 'testnet') {
84
- throw new Error(`DeepBook only supports 'mainnet' and 'testnet' networks, got '${network}'`);
85
- }
86
-
87
87
  this.network = network;
88
88
  this.address = normalizeSuiAddress(address);
89
89
  this.adminCap = adminCap;
@@ -92,7 +92,18 @@ export class DeepBookConfig {
92
92
  this.balanceManagers = balanceManagers || {};
93
93
  this.marginManagers = marginManagers || {};
94
94
 
95
- if (network === 'mainnet') {
95
+ if (packageIds) {
96
+ this.DEEPBOOK_PACKAGE_ID = packageIds.DEEPBOOK_PACKAGE_ID || '';
97
+ this.REGISTRY_ID = packageIds.REGISTRY_ID || '';
98
+ this.DEEP_TREASURY_ID = packageIds.DEEP_TREASURY_ID || '';
99
+ this.MARGIN_PACKAGE_ID = packageIds.MARGIN_PACKAGE_ID || '';
100
+ this.MARGIN_REGISTRY_ID = packageIds.MARGIN_REGISTRY_ID || '';
101
+ this.LIQUIDATION_PACKAGE_ID = packageIds.LIQUIDATION_PACKAGE_ID || '';
102
+ this.#coins = coins || {};
103
+ this.#pools = pools || {};
104
+ this.#marginPools = marginPools || {};
105
+ this.pyth = pyth || { pythStateId: '', wormholeStateId: '' };
106
+ } else if (network === 'mainnet') {
96
107
  this.#coins = coins || mainnetCoins;
97
108
  this.#pools = pools || mainnetPools;
98
109
  this.#marginPools = marginPools || mainnetMarginPools;
@@ -103,7 +114,7 @@ export class DeepBookConfig {
103
114
  this.MARGIN_REGISTRY_ID = mainnetPackageIds.MARGIN_REGISTRY_ID;
104
115
  this.LIQUIDATION_PACKAGE_ID = mainnetPackageIds.LIQUIDATION_PACKAGE_ID;
105
116
  this.pyth = mainnetPythConfigs;
106
- } else {
117
+ } else if (network === 'testnet') {
107
118
  this.#coins = coins || testnetCoins;
108
119
  this.#pools = pools || testnetPools;
109
120
  this.#marginPools = marginPools || testnetMarginPools;
@@ -114,11 +125,23 @@ export class DeepBookConfig {
114
125
  this.MARGIN_REGISTRY_ID = testnetPackageIds.MARGIN_REGISTRY_ID;
115
126
  this.LIQUIDATION_PACKAGE_ID = testnetPackageIds.LIQUIDATION_PACKAGE_ID;
116
127
  this.pyth = testnetPythConfigs;
128
+ } else {
129
+ throw new Error(
130
+ `Network '${network}' is not supported by default. Provide custom 'packageIds' for non-standard networks.`,
131
+ );
117
132
  }
118
133
 
119
134
  this.balanceManager = new BalanceManagerContract(this);
120
135
  }
121
136
 
137
+ requirePyth() {
138
+ if (!this.pyth.pythStateId || !this.pyth.wormholeStateId) {
139
+ throw new ConfigurationError(
140
+ "Pyth configuration is required for price feed operations. Provide 'pyth' when using custom packageIds.",
141
+ );
142
+ }
143
+ }
144
+
122
145
  // Getters
123
146
  getCoin(key: string): Coin {
124
147
  const coin = this.#coins[key];
@@ -7,12 +7,12 @@ export type CoinMap = Record<string, Coin>;
7
7
  export type PoolMap = Record<string, Pool>;
8
8
  export type MarginPoolMap = Record<string, MarginPool>;
9
9
  export interface DeepbookPackageIds {
10
- DEEPBOOK_PACKAGE_ID: string;
11
- REGISTRY_ID: string;
12
- DEEP_TREASURY_ID: string;
13
- MARGIN_PACKAGE_ID: string;
14
- MARGIN_REGISTRY_ID: string;
15
- LIQUIDATION_PACKAGE_ID: string;
10
+ DEEPBOOK_PACKAGE_ID?: string;
11
+ REGISTRY_ID?: string;
12
+ DEEP_TREASURY_ID?: string;
13
+ MARGIN_PACKAGE_ID?: string;
14
+ MARGIN_REGISTRY_ID?: string;
15
+ LIQUIDATION_PACKAGE_ID?: string;
16
16
  }
17
17
 
18
18
  export const testnetPackageIds = {