@mysten/deepbook-v3 1.0.1 → 1.0.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/CHANGELOG.md +8 -0
- package/dist/client.d.mts +22 -0
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +61 -0
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/wormhole/bytes32.mjs +16 -0
- package/dist/contracts/wormhole/bytes32.mjs.map +1 -0
- package/dist/contracts/wormhole/consumed_vaas.mjs +16 -0
- package/dist/contracts/wormhole/consumed_vaas.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +16 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
- package/dist/contracts/wormhole/external_address.mjs +16 -0
- package/dist/contracts/wormhole/external_address.mjs.map +1 -0
- package/dist/contracts/wormhole/fee_collector.mjs +20 -0
- package/dist/contracts/wormhole/fee_collector.mjs.map +1 -0
- package/dist/contracts/wormhole/set.mjs +16 -0
- package/dist/contracts/wormhole/set.mjs.map +1 -0
- package/dist/contracts/wormhole/state.mjs +31 -0
- package/dist/contracts/wormhole/state.mjs.map +1 -0
- package/dist/pyth/pyth.d.mts.map +1 -1
- package/dist/pyth/pyth.mjs +14 -17
- package/dist/pyth/pyth.mjs.map +1 -1
- package/package.json +4 -4
- package/src/client.ts +147 -0
- package/src/contracts/wormhole/bytes32.ts +12 -0
- package/src/contracts/wormhole/consumed_vaas.ts +13 -0
- package/src/contracts/{deepbook/deps/sui/object.ts → wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts} +4 -7
- package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
- package/src/contracts/{pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.ts → wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts} +4 -3
- package/src/contracts/wormhole/external_address.ts +13 -0
- package/src/contracts/wormhole/fee_collector.ts +15 -0
- package/src/contracts/wormhole/set.ts +12 -0
- package/src/contracts/wormhole/state.ts +25 -0
- package/src/pyth/pyth.ts +21 -19
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import { MoveStruct } from '../utils/index.js';
|
|
5
|
+
import * as bytes32 from './bytes32.js';
|
|
6
|
+
const $moduleName =
|
|
7
|
+
'0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::external_address';
|
|
8
|
+
export const ExternalAddress = new MoveStruct({
|
|
9
|
+
name: `${$moduleName}::ExternalAddress`,
|
|
10
|
+
fields: {
|
|
11
|
+
value: bytes32.Bytes32,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import { MoveStruct } from '../utils/index.js';
|
|
5
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
6
|
+
import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js';
|
|
7
|
+
const $moduleName =
|
|
8
|
+
'0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::fee_collector';
|
|
9
|
+
export const FeeCollector = new MoveStruct({
|
|
10
|
+
name: `${$moduleName}::FeeCollector`,
|
|
11
|
+
fields: {
|
|
12
|
+
fee_amount: bcs.u64(),
|
|
13
|
+
balance: balance.Balance,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import { MoveStruct } from '../utils/index.js';
|
|
5
|
+
import * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js';
|
|
6
|
+
const $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::set';
|
|
7
|
+
export const Set = new MoveStruct({
|
|
8
|
+
name: `${$moduleName}::Set`,
|
|
9
|
+
fields: {
|
|
10
|
+
items: table.Table,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import { MoveStruct } from '../utils/index.js';
|
|
5
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
6
|
+
import * as external_address from './external_address.js';
|
|
7
|
+
import * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js';
|
|
8
|
+
import * as consumed_vaas from './consumed_vaas.js';
|
|
9
|
+
import * as fee_collector from './fee_collector.js';
|
|
10
|
+
import * as _package from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.js';
|
|
11
|
+
const $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::state';
|
|
12
|
+
export const State = new MoveStruct({
|
|
13
|
+
name: `${$moduleName}::State`,
|
|
14
|
+
fields: {
|
|
15
|
+
id: bcs.Address,
|
|
16
|
+
governance_chain: bcs.u16(),
|
|
17
|
+
governance_contract: external_address.ExternalAddress,
|
|
18
|
+
guardian_set_index: bcs.u32(),
|
|
19
|
+
guardian_sets: table.Table,
|
|
20
|
+
guardian_set_seconds_to_live: bcs.u32(),
|
|
21
|
+
consumed_vaas: consumed_vaas.ConsumedVAAs,
|
|
22
|
+
fee_collector: fee_collector.FeeCollector,
|
|
23
|
+
upgrade_cap: _package.UpgradeCap,
|
|
24
|
+
},
|
|
25
|
+
});
|
package/src/pyth/pyth.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { HexString } from './PriceServiceConnection.js';
|
|
|
11
11
|
import { PriceServiceConnection } from './PriceServiceConnection.js';
|
|
12
12
|
import { extractVaaBytesFromAccumulatorMessage } from './pyth-helpers.js';
|
|
13
13
|
import { State as PythState } from '../contracts/pyth/state.js';
|
|
14
|
+
import { State as WormholeState } from '../contracts/wormhole/state.js';
|
|
14
15
|
|
|
15
16
|
const MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
16
17
|
export type ObjectId = string;
|
|
@@ -195,28 +196,27 @@ export class SuiPythClient {
|
|
|
195
196
|
* @returns Price table object ID and field type
|
|
196
197
|
*/
|
|
197
198
|
async #fetchPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const result = await this.provider.core.getDynamicField({
|
|
199
|
+
const result = await this.provider.core.getDynamicObjectField({
|
|
201
200
|
parentId: this.pythStateId,
|
|
202
201
|
name: {
|
|
203
202
|
type: 'vector<u8>',
|
|
204
|
-
bcs:
|
|
203
|
+
bcs: bcs.string().serialize('price_info').toBytes(),
|
|
205
204
|
},
|
|
206
205
|
});
|
|
207
206
|
|
|
208
|
-
if (!result.
|
|
207
|
+
if (!result.object) {
|
|
209
208
|
throw new Error('Price Table not found, contract may not be initialized');
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
const
|
|
211
|
+
const tableType = parseStructTag(result.object.type);
|
|
212
|
+
const priceIdentifier = tableType.typeParams[0];
|
|
213
213
|
if (
|
|
214
214
|
typeof priceIdentifier === 'object' &&
|
|
215
215
|
priceIdentifier !== null &&
|
|
216
216
|
priceIdentifier.name === 'PriceIdentifier' &&
|
|
217
217
|
'address' in priceIdentifier
|
|
218
218
|
) {
|
|
219
|
-
return { id: result.
|
|
219
|
+
return { id: result.object.objectId, fieldType: priceIdentifier.address };
|
|
220
220
|
} else {
|
|
221
221
|
throw new Error('fieldType not found');
|
|
222
222
|
}
|
|
@@ -235,7 +235,17 @@ export class SuiPythClient {
|
|
|
235
235
|
* Fetches the package ID for the Wormhole contract (no caching).
|
|
236
236
|
*/
|
|
237
237
|
async #fetchWormholePackageId(): Promise<ObjectId> {
|
|
238
|
-
|
|
238
|
+
const result = await this.provider.core.getObject({
|
|
239
|
+
objectId: this.wormholeStateId,
|
|
240
|
+
include: { content: true },
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
if (!result.object?.content) {
|
|
244
|
+
throw new Error('Unable to fetch Wormhole state object');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const state = WormholeState.parse(result.object.content);
|
|
248
|
+
return state.upgrade_cap.package;
|
|
239
249
|
}
|
|
240
250
|
|
|
241
251
|
/**
|
|
@@ -252,28 +262,20 @@ export class SuiPythClient {
|
|
|
252
262
|
* Fetches the package ID for the Pyth contract (no caching).
|
|
253
263
|
*/
|
|
254
264
|
async #fetchPythPackageId(): Promise<ObjectId> {
|
|
255
|
-
return await this.#getPackageId(this.pythStateId);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Fetches the package ID for a given object.
|
|
260
|
-
*
|
|
261
|
-
* @param objectId Object ID to fetch the package ID for.
|
|
262
|
-
*/
|
|
263
|
-
async #getPackageId(objectId: ObjectId): Promise<ObjectId> {
|
|
264
265
|
const result = await this.provider.core.getObject({
|
|
265
|
-
objectId:
|
|
266
|
+
objectId: this.pythStateId,
|
|
266
267
|
include: { content: true },
|
|
267
268
|
});
|
|
268
269
|
|
|
269
270
|
if (!result.object?.content) {
|
|
270
|
-
throw new Error(`Cannot fetch package ID for object ${
|
|
271
|
+
throw new Error(`Cannot fetch Pyth package ID for object ${this.pythStateId}`);
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
// Parse the BCS content to get the upgrade_cap.package field
|
|
274
275
|
const state = PythState.parse(result.object.content);
|
|
275
276
|
return state.upgrade_cap.package;
|
|
276
277
|
}
|
|
278
|
+
|
|
277
279
|
/**
|
|
278
280
|
* Gets the base update fee from the Pyth state object.
|
|
279
281
|
*/
|