@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/client.d.mts +22 -0
  3. package/dist/client.d.mts.map +1 -1
  4. package/dist/client.mjs +61 -0
  5. package/dist/client.mjs.map +1 -1
  6. package/dist/contracts/wormhole/bytes32.mjs +16 -0
  7. package/dist/contracts/wormhole/bytes32.mjs.map +1 -0
  8. package/dist/contracts/wormhole/consumed_vaas.mjs +16 -0
  9. package/dist/contracts/wormhole/consumed_vaas.mjs.map +1 -0
  10. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +16 -0
  11. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
  12. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
  13. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
  14. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
  15. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
  16. package/dist/contracts/wormhole/external_address.mjs +16 -0
  17. package/dist/contracts/wormhole/external_address.mjs.map +1 -0
  18. package/dist/contracts/wormhole/fee_collector.mjs +20 -0
  19. package/dist/contracts/wormhole/fee_collector.mjs.map +1 -0
  20. package/dist/contracts/wormhole/set.mjs +16 -0
  21. package/dist/contracts/wormhole/set.mjs.map +1 -0
  22. package/dist/contracts/wormhole/state.mjs +31 -0
  23. package/dist/contracts/wormhole/state.mjs.map +1 -0
  24. package/dist/pyth/pyth.d.mts.map +1 -1
  25. package/dist/pyth/pyth.mjs +14 -17
  26. package/dist/pyth/pyth.mjs.map +1 -1
  27. package/package.json +4 -4
  28. package/src/client.ts +147 -0
  29. package/src/contracts/wormhole/bytes32.ts +12 -0
  30. package/src/contracts/wormhole/consumed_vaas.ts +13 -0
  31. package/src/contracts/{deepbook/deps/sui/object.ts → wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts} +4 -7
  32. package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
  33. package/src/contracts/{pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.ts → wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts} +4 -3
  34. package/src/contracts/wormhole/external_address.ts +13 -0
  35. package/src/contracts/wormhole/fee_collector.ts +15 -0
  36. package/src/contracts/wormhole/set.ts +12 -0
  37. package/src/contracts/wormhole/state.ts +25 -0
  38. package/src/pyth/pyth.ts +21 -19
@@ -0,0 +1,16 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+
4
+ //#region src/contracts/wormhole/bytes32.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::bytes32";
9
+ const Bytes32 = new MoveStruct({
10
+ name: `${$moduleName}::Bytes32`,
11
+ fields: { data: bcs.vector(bcs.u8()) }
12
+ });
13
+
14
+ //#endregion
15
+ export { Bytes32 };
16
+ //# sourceMappingURL=bytes32.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes32.mjs","names":[],"sources":["../../../src/contracts/wormhole/bytes32.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nconst $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::bytes32';\nexport const Bytes32 = new MoveStruct({\n\tname: `${$moduleName}::Bytes32`,\n\tfields: {\n\t\tdata: bcs.vector(bcs.u8()),\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cAAc;AACpB,MAAa,UAAU,IAAI,WAAW;CACrC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,MAAM,IAAI,OAAO,IAAI,IAAI,CAAC,EAC1B;CACD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { Set } from "./set.mjs";
3
+
4
+ //#region src/contracts/wormhole/consumed_vaas.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::consumed_vaas";
9
+ const ConsumedVAAs = new MoveStruct({
10
+ name: `${$moduleName}::ConsumedVAAs`,
11
+ fields: { hashes: Set }
12
+ });
13
+
14
+ //#endregion
15
+ export { ConsumedVAAs };
16
+ //# sourceMappingURL=consumed_vaas.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumed_vaas.mjs","names":["set.Set"],"sources":["../../../src/contracts/wormhole/consumed_vaas.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport * as set from './set.js';\nconst $moduleName =\n\t'0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::consumed_vaas';\nexport const ConsumedVAAs = new MoveStruct({\n\tname: `${$moduleName}::ConsumedVAAs`,\n\tfields: {\n\t\thashes: set.Set,\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cACL;AACD,MAAa,eAAe,IAAI,WAAW;CAC1C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,QAAQA,KACR;CACD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { MoveStruct } from "../../../utils/index.mjs";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+
4
+ //#region src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0x2::balance";
9
+ const Balance = new MoveStruct({
10
+ name: `${$moduleName}::Balance`,
11
+ fields: { value: bcs.u64() }
12
+ });
13
+
14
+ //#endregion
15
+ export { Balance };
16
+ //# sourceMappingURL=balance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.mjs","names":[],"sources":["../../../../../src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../../../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nconst $moduleName = '0x2::balance';\nexport const Balance = new MoveStruct({\n\tname: `${$moduleName}::Balance`,\n\tfields: {\n\t\tvalue: bcs.u64(),\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cAAc;AACpB,MAAa,UAAU,IAAI,WAAW;CACrC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,OAAO,IAAI,KAAK,EAChB;CACD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { MoveStruct } from "../../../utils/index.mjs";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+
4
+ //#region src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0x2::package";
9
+ const UpgradeCap = new MoveStruct({
10
+ name: `${$moduleName}::UpgradeCap`,
11
+ fields: {
12
+ id: bcs.Address,
13
+ package: bcs.Address,
14
+ version: bcs.u64(),
15
+ policy: bcs.u8()
16
+ }
17
+ });
18
+
19
+ //#endregion
20
+ export { UpgradeCap };
21
+ //# sourceMappingURL=package.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.mjs","names":[],"sources":["../../../../../src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../../../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nconst $moduleName = '0x2::package';\nexport const UpgradeCap = new MoveStruct({\n\tname: `${$moduleName}::UpgradeCap`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\tpackage: bcs.Address,\n\t\tversion: bcs.u64(),\n\t\tpolicy: bcs.u8(),\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cAAc;AACpB,MAAa,aAAa,IAAI,WAAW;CACxC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EACR,SAAS,IAAI;EACb,SAAS,IAAI,KAAK;EAClB,QAAQ,IAAI,IAAI;EAChB;CACD,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { MoveStruct } from "../../../utils/index.mjs";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+
4
+ //#region src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0x2::table";
9
+ const Table = new MoveStruct({
10
+ name: `${$moduleName}::Table`,
11
+ fields: {
12
+ id: bcs.Address,
13
+ size: bcs.u64()
14
+ }
15
+ });
16
+
17
+ //#endregion
18
+ export { Table };
19
+ //# sourceMappingURL=table.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.mjs","names":[],"sources":["../../../../../src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../../../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nconst $moduleName = '0x2::table';\nexport const Table = new MoveStruct({\n\tname: `${$moduleName}::Table`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\tsize: bcs.u64(),\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cAAc;AACpB,MAAa,QAAQ,IAAI,WAAW;CACnC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EACR,MAAM,IAAI,KAAK;EACf;CACD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { Bytes32 } from "./bytes32.mjs";
3
+
4
+ //#region src/contracts/wormhole/external_address.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::external_address";
9
+ const ExternalAddress = new MoveStruct({
10
+ name: `${$moduleName}::ExternalAddress`,
11
+ fields: { value: Bytes32 }
12
+ });
13
+
14
+ //#endregion
15
+ export { ExternalAddress };
16
+ //# sourceMappingURL=external_address.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external_address.mjs","names":["bytes32.Bytes32"],"sources":["../../../src/contracts/wormhole/external_address.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport * as bytes32 from './bytes32.js';\nconst $moduleName =\n\t'0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::external_address';\nexport const ExternalAddress = new MoveStruct({\n\tname: `${$moduleName}::ExternalAddress`,\n\tfields: {\n\t\tvalue: bytes32.Bytes32,\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cACL;AACD,MAAa,kBAAkB,IAAI,WAAW;CAC7C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,OAAOA,SACP;CACD,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { Balance } from "./deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs";
3
+ import { bcs } from "@mysten/sui/bcs";
4
+
5
+ //#region src/contracts/wormhole/fee_collector.ts
6
+ /**************************************************************
7
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
8
+ **************************************************************/
9
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::fee_collector";
10
+ const FeeCollector = new MoveStruct({
11
+ name: `${$moduleName}::FeeCollector`,
12
+ fields: {
13
+ fee_amount: bcs.u64(),
14
+ balance: Balance
15
+ }
16
+ });
17
+
18
+ //#endregion
19
+ export { FeeCollector };
20
+ //# sourceMappingURL=fee_collector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fee_collector.mjs","names":["balance.Balance"],"sources":["../../../src/contracts/wormhole/fee_collector.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nimport * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js';\nconst $moduleName =\n\t'0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::fee_collector';\nexport const FeeCollector = new MoveStruct({\n\tname: `${$moduleName}::FeeCollector`,\n\tfields: {\n\t\tfee_amount: bcs.u64(),\n\t\tbalance: balance.Balance,\n\t},\n});\n"],"mappings":";;;;;;;;AAMA,MAAM,cACL;AACD,MAAa,eAAe,IAAI,WAAW;CAC1C,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,YAAY,IAAI,KAAK;EACrB,SAASA;EACT;CACD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { Table } from "./deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs";
3
+
4
+ //#region src/contracts/wormhole/set.ts
5
+ /**************************************************************
6
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
7
+ **************************************************************/
8
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::set";
9
+ const Set = new MoveStruct({
10
+ name: `${$moduleName}::Set`,
11
+ fields: { items: Table }
12
+ });
13
+
14
+ //#endregion
15
+ export { Set };
16
+ //# sourceMappingURL=set.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.mjs","names":["table.Table"],"sources":["../../../src/contracts/wormhole/set.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js';\nconst $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::set';\nexport const Set = new MoveStruct({\n\tname: `${$moduleName}::Set`,\n\tfields: {\n\t\titems: table.Table,\n\t},\n});\n"],"mappings":";;;;;;;AAKA,MAAM,cAAc;AACpB,MAAa,MAAM,IAAI,WAAW;CACjC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,OAAOA,OACP;CACD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { MoveStruct } from "../utils/index.mjs";
2
+ import { ExternalAddress } from "./external_address.mjs";
3
+ import { Table } from "./deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs";
4
+ import { ConsumedVAAs } from "./consumed_vaas.mjs";
5
+ import { FeeCollector } from "./fee_collector.mjs";
6
+ import { UpgradeCap } from "./deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs";
7
+ import { bcs } from "@mysten/sui/bcs";
8
+
9
+ //#region src/contracts/wormhole/state.ts
10
+ /**************************************************************
11
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
12
+ **************************************************************/
13
+ const $moduleName = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::state";
14
+ const State = new MoveStruct({
15
+ name: `${$moduleName}::State`,
16
+ fields: {
17
+ id: bcs.Address,
18
+ governance_chain: bcs.u16(),
19
+ governance_contract: ExternalAddress,
20
+ guardian_set_index: bcs.u32(),
21
+ guardian_sets: Table,
22
+ guardian_set_seconds_to_live: bcs.u32(),
23
+ consumed_vaas: ConsumedVAAs,
24
+ fee_collector: FeeCollector,
25
+ upgrade_cap: UpgradeCap
26
+ }
27
+ });
28
+
29
+ //#endregion
30
+ export { State };
31
+ //# sourceMappingURL=state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.mjs","names":["external_address.ExternalAddress","table.Table","consumed_vaas.ConsumedVAAs","fee_collector.FeeCollector","_package.UpgradeCap"],"sources":["../../../src/contracts/wormhole/state.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { MoveStruct } from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nimport * as external_address from './external_address.js';\nimport * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js';\nimport * as consumed_vaas from './consumed_vaas.js';\nimport * as fee_collector from './fee_collector.js';\nimport * as _package from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.js';\nconst $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::state';\nexport const State = new MoveStruct({\n\tname: `${$moduleName}::State`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\tgovernance_chain: bcs.u16(),\n\t\tgovernance_contract: external_address.ExternalAddress,\n\t\tguardian_set_index: bcs.u32(),\n\t\tguardian_sets: table.Table,\n\t\tguardian_set_seconds_to_live: bcs.u32(),\n\t\tconsumed_vaas: consumed_vaas.ConsumedVAAs,\n\t\tfee_collector: fee_collector.FeeCollector,\n\t\tupgrade_cap: _package.UpgradeCap,\n\t},\n});\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,cAAc;AACpB,MAAa,QAAQ,IAAI,WAAW;CACnC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EACR,kBAAkB,IAAI,KAAK;EAC3B,qBAAqBA;EACrB,oBAAoB,IAAI,KAAK;EAC7B,eAAeC;EACf,8BAA8B,IAAI,KAAK;EACvC,eAAeC;EACf,eAAeC;EACf,aAAaC;EACb;CACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pyth.d.mts","names":[],"sources":["../../src/pyth/pyth.ts"],"sourcesContent":[],"mappings":";;;;;KAeY,QAAA;AAAA,cACC,yBAAA,SAAkC,sBAAA,CAD3B;EACP;;;;;;EAYA,uBAAa,CAAA,QAAA,EALe,SAKf,EAAA,CAAA,EAL6B,OAK7B,CALqC,UAKrC,EAAA,CAAA;;AAOZ,cAPD,aAAA,CAOC;EACI,CAAA,OAAA;EAEK,QAAA,EAJZ,iBAIY;EAAgC,WAAA,EAHzC,QAGyC;EAA2B,eAAA,EAFhE,QAEgE;EAY1D,WAAA,CAAA,QAAA,EAZD,iBAYC,EAAA,WAAA,EAZ+B,QAY/B,EAAA,eAAA,EAZ0D,QAY1D;EAAkB;;;;;;;EA+EZ,UAAA,CAAA,IAAA,EA/EN,UA+EM,EAAA,EAAA,EAAA,EA/EY,WA+EZ,CAAA,EA/EuB,OA+EvB,CAAA;IAAoB,YAAA,EAAA,CAAA,MAAA,EAAA,MAAA,CAAA;IAAR,KAAA,EAAA,cAAA;EAiDN,CAAA,EAAA,CAAA;EAAqB;;;;;;;EAuH7B,gBAAA,CAAA,EAAA,EAnOtB,WAm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nection } from "./PriceServiceConnection.mjs";
2
2
  import { extractVaaBytesFromAccumulatorMessage } from "./pyth-helpers.mjs";
3
3
  import { State } from "../contracts/pyth/state.mjs";
4
+ import { State as State$1 } from "../contracts/wormhole/state.mjs";
4
5
  import { bcs } from "@mysten/sui/bcs";
5
6
  import { fromBase64, fromHex, parseStructTag } from "@mysten/sui/utils";
6
7
  import { coinWithBalance } from "@mysten/sui/transactions";
@@ -142,18 +143,17 @@ var SuiPythClient = class {
142
143
  * @returns Price table object ID and field type
143
144
  */
144
145
  async #fetchPriceTableInfo() {
145
- const nameBytes = bcs.string().serialize("price_info").toBytes();
146
- const result = await this.provider.core.getDynamicField({
146
+ const result = await this.provider.core.getDynamicObjectField({
147
147
  parentId: this.pythStateId,
148
148
  name: {
149
149
  type: "vector<u8>",
150
- bcs: nameBytes
150
+ bcs: bcs.string().serialize("price_info").toBytes()
151
151
  }
152
152
  });
153
- if (!result.dynamicField || !result.dynamicField.type) throw new Error("Price Table not found, contract may not be initialized");
154
- const priceIdentifier = parseStructTag(result.dynamicField.type).typeParams[0];
153
+ if (!result.object) throw new Error("Price Table not found, contract may not be initialized");
154
+ const priceIdentifier = parseStructTag(result.object.type).typeParams[0];
155
155
  if (typeof priceIdentifier === "object" && priceIdentifier !== null && priceIdentifier.name === "PriceIdentifier" && "address" in priceIdentifier) return {
156
- id: result.dynamicField.fieldId,
156
+ id: result.object.objectId,
157
157
  fieldType: priceIdentifier.address
158
158
  };
159
159
  else throw new Error("fieldType not found");
@@ -169,7 +169,12 @@ var SuiPythClient = class {
169
169
  * Fetches the package ID for the Wormhole contract (no caching).
170
170
  */
171
171
  async #fetchWormholePackageId() {
172
- return await this.#getPackageId(this.wormholeStateId);
172
+ const result = await this.provider.core.getObject({
173
+ objectId: this.wormholeStateId,
174
+ include: { content: true }
175
+ });
176
+ if (!result.object?.content) throw new Error("Unable to fetch Wormhole state object");
177
+ return State$1.parse(result.object.content).upgrade_cap.package;
173
178
  }
174
179
  /**
175
180
  * Fetches the package ID for the Pyth contract, with caching.
@@ -182,19 +187,11 @@ var SuiPythClient = class {
182
187
  * Fetches the package ID for the Pyth contract (no caching).
183
188
  */
184
189
  async #fetchPythPackageId() {
185
- return await this.#getPackageId(this.pythStateId);
186
- }
187
- /**
188
- * Fetches the package ID for a given object.
189
- *
190
- * @param objectId Object ID to fetch the package ID for.
191
- */
192
- async #getPackageId(objectId) {
193
190
  const result = await this.provider.core.getObject({
194
- objectId,
191
+ objectId: this.pythStateId,
195
192
  include: { content: true }
196
193
  });
197
- if (!result.object?.content) throw new Error(`Cannot fetch package ID for object ${objectId}`);
194
+ if (!result.object?.content) throw new Error(`Cannot fetch Pyth package ID for object ${this.pythStateId}`);
198
195
  return State.parse(result.object.content).upgrade_cap.package;
199
196
  }
200
197
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"pyth.mjs","names":["#priceFeedObjectIdCache","#fetchPriceFeedObjectId","#priceTableInfo","#fetchPriceTableInfo","#wormholePackageId","#fetchWormholePackageId","#getPackageId","#pythPackageId","#fetchPythPackageId","PythState","#fetchBaseUpdateFee","#baseUpdateFee"],"sources":["../../src/pyth/pyth.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport type { ClientWithCoreApi } from '@mysten/sui/client';\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport { fromBase64, fromHex, parseStructTag } from '@mysten/sui/utils';\n\nimport type { HexString } from './PriceServiceConnection.js';\nimport { PriceServiceConnection } from './PriceServiceConnection.js';\nimport { extractVaaBytesFromAccumulatorMessage } from './pyth-helpers.js';\nimport { State as PythState } from '../contracts/pyth/state.js';\n\nconst MAX_ARGUMENT_SIZE = 16 * 1024;\nexport type ObjectId = string;\nexport class SuiPriceServiceConnection extends PriceServiceConnection {\n\t/**\n\t * Fetch price feed update data.\n\t *\n\t * @param priceIds Array of hex-encoded price IDs.\n\t * @returns Array of buffers containing the price update data.\n\t */\n\tasync getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Uint8Array[]> {\n\t\tconst latestVaas = await this.getLatestVaas(priceIds);\n\t\treturn latestVaas.map((vaa) => fromBase64(vaa));\n\t}\n}\nexport class SuiPythClient {\n\t#pythPackageId?: Promise<ObjectId>;\n\t#wormholePackageId?: Promise<ObjectId>;\n\t#priceFeedObjectIdCache: Map<HexString, Promise<ObjectId>> = new Map();\n\t#priceTableInfo?: Promise<{ id: ObjectId; fieldType: ObjectId }>;\n\t#baseUpdateFee?: Promise<number>;\n\tprovider: ClientWithCoreApi;\n\tpythStateId: ObjectId;\n\twormholeStateId: ObjectId;\n\n\tconstructor(provider: ClientWithCoreApi, pythStateId: ObjectId, wormholeStateId: ObjectId) {\n\t\tthis.provider = provider;\n\t\tthis.pythStateId = pythStateId;\n\t\tthis.wormholeStateId = wormholeStateId;\n\t}\n\t/**\n\t * Verifies the VAAs using the Wormhole contract.\n\t *\n\t * @param vaas Array of VAA buffers to verify.\n\t * @param tx Transaction block to add commands to.\n\t * @returns Array of verified VAAs.\n\t */\n\tasync verifyVaas(vaas: Uint8Array[], tx: Transaction) {\n\t\tconst wormholePackageId = await this.getWormholePackageId();\n\t\tconst verifiedVaas = [];\n\t\tfor (const vaa of vaas) {\n\t\t\tconst [verifiedVaa] = tx.moveCall({\n\t\t\t\ttarget: `${wormholePackageId}::vaa::parse_and_verify`,\n\t\t\t\targuments: [tx.object(this.wormholeStateId), tx.pure.vector('u8', vaa), tx.object.clock()],\n\t\t\t});\n\t\t\tverifiedVaas.push(verifiedVaa);\n\t\t}\n\t\treturn verifiedVaas;\n\t}\n\t/**\n\t * Adds the necessary commands for updating the Pyth price feeds to the transaction block.\n\t *\n\t * @param tx Transaction block to add commands to.\n\t * @param updates Array of price feed updates received from the price service.\n\t * @param feedIds Array of feed IDs to update (in hex format).\n\t */\n\tasync updatePriceFeeds(\n\t\ttx: Transaction,\n\t\tupdates: Uint8Array[],\n\t\tfeedIds: HexString[],\n\t): Promise<ObjectId[]> {\n\t\tconst packageId = await this.getPythPackageId();\n\t\tlet priceUpdatesHotPotato;\n\t\tif (updates.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t'SDK does not support sending multiple accumulator messages in a single transaction',\n\t\t\t);\n\t\t}\n\t\tconst vaa = extractVaaBytesFromAccumulatorMessage(updates[0]);\n\t\tconst verifiedVaas = await this.verifyVaas([vaa], tx);\n\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\ttarget: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\ttx.pure(\n\t\t\t\t\tbcs\n\t\t\t\t\t\t.vector(bcs.U8)\n\t\t\t\t\t\t.serialize(Array.from(updates[0]), {\n\t\t\t\t\t\t\tmaxSize: MAX_ARGUMENT_SIZE,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.toBytes(),\n\t\t\t\t),\n\t\t\t\tverifiedVaas[0],\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t\tconst priceInfoObjects: ObjectId[] = [];\n\t\tconst baseUpdateFee = await this.getBaseUpdateFee();\n\t\tfor (const feedId of feedIds) {\n\t\t\tconst priceInfoObjectId = await this.getPriceFeedObjectId(feedId);\n\t\t\tif (!priceInfoObjectId) {\n\t\t\t\tthrow new Error(`Price feed ${feedId} not found, please create it first`);\n\t\t\t}\n\t\t\tpriceInfoObjects.push(priceInfoObjectId);\n\t\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\t\ttarget: `${packageId}::pyth::update_single_price_feed`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\t\tpriceUpdatesHotPotato,\n\t\t\t\t\ttx.object(priceInfoObjectId),\n\t\t\t\t\tcoinWithBalance({ balance: baseUpdateFee }),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t\ttx.moveCall({\n\t\t\ttarget: `${packageId}::hot_potato_vector::destroy`,\n\t\t\targuments: [priceUpdatesHotPotato],\n\t\t\ttypeArguments: [`${packageId}::price_info::PriceInfo`],\n\t\t});\n\t\treturn priceInfoObjects;\n\t}\n\t/**\n\t * Get the price feed object ID for a given feed ID, caching the promise.\n\t * @param feedId\n\t */\n\tgetPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined> {\n\t\tif (!this.#priceFeedObjectIdCache.has(feedId)) {\n\t\t\tthis.#priceFeedObjectIdCache.set(\n\t\t\t\tfeedId,\n\t\t\t\tthis.#fetchPriceFeedObjectId(feedId).catch((err) => {\n\t\t\t\t\t// Remove failed promises from the cache to allow retries\n\t\t\t\t\tthis.#priceFeedObjectIdCache.delete(feedId);\n\t\t\t\t\tthrow err;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn this.#priceFeedObjectIdCache.get(feedId)!;\n\t}\n\n\t/**\n\t * Fetches the price feed object ID for a given feed ID (no caching).\n\t * Throws an error if the object is not found.\n\t */\n\tasync #fetchPriceFeedObjectId(feedId: HexString): Promise<ObjectId> {\n\t\tconst { id: tableId, fieldType } = await this.getPriceTableInfo();\n\n\t\t// Serialize the PriceIdentifier name using BCS (vector of bytes)\n\t\tconst nameBytes = bcs\n\t\t\t.byteVector()\n\t\t\t.serialize(Array.from(fromHex(feedId)))\n\t\t\t.toBytes();\n\n\t\tconst result = await this.provider.core.getDynamicField({\n\t\t\tparentId: tableId,\n\t\t\tname: {\n\t\t\t\ttype: `${fieldType}::price_identifier::PriceIdentifier`,\n\t\t\t\tbcs: nameBytes,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.dynamicField) {\n\t\t\tthrow new Error(`Price feed object ID for feed ID ${feedId} not found.`);\n\t\t}\n\n\t\t// The value in the table is just the object ID (address)\n\t\tconst objectId = bcs.Address.parse(result.dynamicField.value.bcs);\n\t\treturn objectId;\n\t}\n\n\t/**\n\t * Fetches the price table object ID for the current state ID, caching the promise.\n\t * @returns Price table object ID and field type\n\t */\n\tgetPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tif (!this.#priceTableInfo) {\n\t\t\tconst promise = this.#fetchPriceTableInfo().catch((err) => {\n\t\t\t\t// Clear the cached promise on error\n\t\t\t\tthis.#priceTableInfo = undefined;\n\t\t\t\tthrow err;\n\t\t\t});\n\n\t\t\tthis.#priceTableInfo = promise;\n\t\t}\n\n\t\treturn this.#priceTableInfo;\n\t}\n\n\t/**\n\t * Fetches the price table object ID and field type (no caching).\n\t * @returns Price table object ID and field type\n\t */\n\tasync #fetchPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tconst nameBytes = bcs.string().serialize('price_info').toBytes();\n\n\t\tconst result = await this.provider.core.getDynamicField({\n\t\t\tparentId: this.pythStateId,\n\t\t\tname: {\n\t\t\t\ttype: 'vector<u8>',\n\t\t\t\tbcs: nameBytes,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.dynamicField || !result.dynamicField.type) {\n\t\t\tthrow new Error('Price Table not found, contract may not be initialized');\n\t\t}\n\n\t\tconst priceIdentifier = parseStructTag(result.dynamicField.type).typeParams[0];\n\t\tif (\n\t\t\ttypeof priceIdentifier === 'object' &&\n\t\t\tpriceIdentifier !== null &&\n\t\t\tpriceIdentifier.name === 'PriceIdentifier' &&\n\t\t\t'address' in priceIdentifier\n\t\t) {\n\t\t\treturn { id: result.dynamicField.fieldId, fieldType: priceIdentifier.address };\n\t\t} else {\n\t\t\tthrow new Error('fieldType not found');\n\t\t}\n\t}\n\t/**\n\t * Fetches the package ID for the Wormhole contract, with caching.\n\t */\n\tgetWormholePackageId(): Promise<ObjectId> {\n\t\tif (!this.#wormholePackageId) {\n\t\t\tthis.#wormholePackageId = this.#fetchWormholePackageId();\n\t\t}\n\t\treturn this.#wormholePackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Wormhole contract (no caching).\n\t */\n\tasync #fetchWormholePackageId(): Promise<ObjectId> {\n\t\treturn await this.#getPackageId(this.wormholeStateId);\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract, with caching.\n\t */\n\tgetPythPackageId(): Promise<ObjectId> {\n\t\tif (!this.#pythPackageId) {\n\t\t\tthis.#pythPackageId = this.#fetchPythPackageId();\n\t\t}\n\t\treturn this.#pythPackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract (no caching).\n\t */\n\tasync #fetchPythPackageId(): Promise<ObjectId> {\n\t\treturn await this.#getPackageId(this.pythStateId);\n\t}\n\n\t/**\n\t * Fetches the package ID for a given object.\n\t *\n\t * @param objectId Object ID to fetch the package ID for.\n\t */\n\tasync #getPackageId(objectId: ObjectId): Promise<ObjectId> {\n\t\tconst result = await this.provider.core.getObject({\n\t\t\tobjectId: objectId,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (!result.object?.content) {\n\t\t\tthrow new Error(`Cannot fetch package ID for object ${objectId}`);\n\t\t}\n\n\t\t// Parse the BCS content to get the upgrade_cap.package field\n\t\tconst state = PythState.parse(result.object.content);\n\t\treturn state.upgrade_cap.package;\n\t}\n\t/**\n\t * Gets the base update fee from the Pyth state object.\n\t */\n\tasync #fetchBaseUpdateFee(): Promise<number> {\n\t\tconst result = await this.provider.core.getObject({\n\t\t\tobjectId: this.pythStateId,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (!result.object?.content) {\n\t\t\tthrow new Error('Unable to fetch Pyth state object');\n\t\t}\n\n\t\t// Parse the BCS content to get the base_update_fee field\n\t\tconst state = PythState.parse(result.object.content);\n\t\treturn Number(state.base_update_fee);\n\t}\n\n\t/**\n\t * Returns the cached base update fee, fetching it if necessary.\n\t */\n\tgetBaseUpdateFee(): Promise<number> {\n\t\tif (!this.#baseUpdateFee) {\n\t\t\tthis.#baseUpdateFee = this.#fetchBaseUpdateFee();\n\t\t}\n\t\treturn this.#baseUpdateFee;\n\t}\n}\n"],"mappings":";;;;;;;;A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M,IAAI,MAAM,sCAAsC,WAAW;AAKlE,SADcG,MAAU,MAAM,OAAO,OAAO,QAAQ,CACvC,YAAY;;;;;CAK1B,OAAMC,qBAAuC;EAC5C,MAAM,SAAS,MAAM,KAAK,SAAS,KAAK,UAAU;GACjD,UAAU,KAAK;GACf,SAAS,EAAE,SAAS,MAAM;GAC1B,CAAC;AAEF,MAAI,CAAC,OAAO,QAAQ,QACnB,OAAM,IAAI,MAAM,oCAAoC;EAIrD,MAAM,QAAQD,MAAU,MAAM,OAAO,OAAO,QAAQ;AACpD,SAAO,OAAO,MAAM,gBAAgB;;;;;CAMrC,mBAAoC;AACnC,MAAI,CAAC,MAAKE,cACT,OAAKA,gBAAiB,MAAKD,oBAAqB;AAEjD,SAAO,MAAKC"}
1
+ {"version":3,"file":"pyth.mjs","names":["#priceFeedObjectIdCache","#fetchPriceFeedObjectId","#priceTableInfo","#fetchPriceTableInfo","#wormholePackageId","#fetchWormholePackageId","WormholeState","#pythPackageId","#fetchPythPackageId","PythState","#fetchBaseUpdateFee","#baseUpdateFee"],"sources":["../../src/pyth/pyth.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport type { ClientWithCoreApi } from '@mysten/sui/client';\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport { fromBase64, fromHex, parseStructTag } from '@mysten/sui/utils';\n\nimport type { HexString } from './PriceServiceConnection.js';\nimport { PriceServiceConnection } from './PriceServiceConnection.js';\nimport { extractVaaBytesFromAccumulatorMessage } from './pyth-helpers.js';\nimport { State as PythState } from '../contracts/pyth/state.js';\nimport { State as WormholeState } from '../contracts/wormhole/state.js';\n\nconst MAX_ARGUMENT_SIZE = 16 * 1024;\nexport type ObjectId = string;\nexport class SuiPriceServiceConnection extends PriceServiceConnection {\n\t/**\n\t * Fetch price feed update data.\n\t *\n\t * @param priceIds Array of hex-encoded price IDs.\n\t * @returns Array of buffers containing the price update data.\n\t */\n\tasync getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Uint8Array[]> {\n\t\tconst latestVaas = await this.getLatestVaas(priceIds);\n\t\treturn latestVaas.map((vaa) => fromBase64(vaa));\n\t}\n}\nexport class SuiPythClient {\n\t#pythPackageId?: Promise<ObjectId>;\n\t#wormholePackageId?: Promise<ObjectId>;\n\t#priceFeedObjectIdCache: Map<HexString, Promise<ObjectId>> = new Map();\n\t#priceTableInfo?: Promise<{ id: ObjectId; fieldType: ObjectId }>;\n\t#baseUpdateFee?: Promise<number>;\n\tprovider: ClientWithCoreApi;\n\tpythStateId: ObjectId;\n\twormholeStateId: ObjectId;\n\n\tconstructor(provider: ClientWithCoreApi, pythStateId: ObjectId, wormholeStateId: ObjectId) {\n\t\tthis.provider = provider;\n\t\tthis.pythStateId = pythStateId;\n\t\tthis.wormholeStateId = wormholeStateId;\n\t}\n\t/**\n\t * Verifies the VAAs using the Wormhole contract.\n\t *\n\t * @param vaas Array of VAA buffers to verify.\n\t * @param tx Transaction block to add commands to.\n\t * @returns Array of verified VAAs.\n\t */\n\tasync verifyVaas(vaas: Uint8Array[], tx: Transaction) {\n\t\tconst wormholePackageId = await this.getWormholePackageId();\n\t\tconst verifiedVaas = [];\n\t\tfor (const vaa of vaas) {\n\t\t\tconst [verifiedVaa] = tx.moveCall({\n\t\t\t\ttarget: `${wormholePackageId}::vaa::parse_and_verify`,\n\t\t\t\targuments: [tx.object(this.wormholeStateId), tx.pure.vector('u8', vaa), tx.object.clock()],\n\t\t\t});\n\t\t\tverifiedVaas.push(verifiedVaa);\n\t\t}\n\t\treturn verifiedVaas;\n\t}\n\t/**\n\t * Adds the necessary commands for updating the Pyth price feeds to the transaction block.\n\t *\n\t * @param tx Transaction block to add commands to.\n\t * @param updates Array of price feed updates received from the price service.\n\t * @param feedIds Array of feed IDs to update (in hex format).\n\t */\n\tasync updatePriceFeeds(\n\t\ttx: Transaction,\n\t\tupdates: Uint8Array[],\n\t\tfeedIds: HexString[],\n\t): Promise<ObjectId[]> {\n\t\tconst packageId = await this.getPythPackageId();\n\t\tlet priceUpdatesHotPotato;\n\t\tif (updates.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t'SDK does not support sending multiple accumulator messages in a single transaction',\n\t\t\t);\n\t\t}\n\t\tconst vaa = extractVaaBytesFromAccumulatorMessage(updates[0]);\n\t\tconst verifiedVaas = await this.verifyVaas([vaa], tx);\n\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\ttarget: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\ttx.pure(\n\t\t\t\t\tbcs\n\t\t\t\t\t\t.vector(bcs.U8)\n\t\t\t\t\t\t.serialize(Array.from(updates[0]), {\n\t\t\t\t\t\t\tmaxSize: MAX_ARGUMENT_SIZE,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.toBytes(),\n\t\t\t\t),\n\t\t\t\tverifiedVaas[0],\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t\tconst priceInfoObjects: ObjectId[] = [];\n\t\tconst baseUpdateFee = await this.getBaseUpdateFee();\n\t\tfor (const feedId of feedIds) {\n\t\t\tconst priceInfoObjectId = await this.getPriceFeedObjectId(feedId);\n\t\t\tif (!priceInfoObjectId) {\n\t\t\t\tthrow new Error(`Price feed ${feedId} not found, please create it first`);\n\t\t\t}\n\t\t\tpriceInfoObjects.push(priceInfoObjectId);\n\t\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\t\ttarget: `${packageId}::pyth::update_single_price_feed`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\t\tpriceUpdatesHotPotato,\n\t\t\t\t\ttx.object(priceInfoObjectId),\n\t\t\t\t\tcoinWithBalance({ balance: baseUpdateFee }),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t\ttx.moveCall({\n\t\t\ttarget: `${packageId}::hot_potato_vector::destroy`,\n\t\t\targuments: [priceUpdatesHotPotato],\n\t\t\ttypeArguments: [`${packageId}::price_info::PriceInfo`],\n\t\t});\n\t\treturn priceInfoObjects;\n\t}\n\t/**\n\t * Get the price feed object ID for a given feed ID, caching the promise.\n\t * @param feedId\n\t */\n\tgetPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined> {\n\t\tif (!this.#priceFeedObjectIdCache.has(feedId)) {\n\t\t\tthis.#priceFeedObjectIdCache.set(\n\t\t\t\tfeedId,\n\t\t\t\tthis.#fetchPriceFeedObjectId(feedId).catch((err) => {\n\t\t\t\t\t// Remove failed promises from the cache to allow retries\n\t\t\t\t\tthis.#priceFeedObjectIdCache.delete(feedId);\n\t\t\t\t\tthrow err;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn this.#priceFeedObjectIdCache.get(feedId)!;\n\t}\n\n\t/**\n\t * Fetches the price feed object ID for a given feed ID (no caching).\n\t * Throws an error if the object is not found.\n\t */\n\tasync #fetchPriceFeedObjectId(feedId: HexString): Promise<ObjectId> {\n\t\tconst { id: tableId, fieldType } = await this.getPriceTableInfo();\n\n\t\t// Serialize the PriceIdentifier name using BCS (vector of bytes)\n\t\tconst nameBytes = bcs\n\t\t\t.byteVector()\n\t\t\t.serialize(Array.from(fromHex(feedId)))\n\t\t\t.toBytes();\n\n\t\tconst result = await this.provider.core.getDynamicField({\n\t\t\tparentId: tableId,\n\t\t\tname: {\n\t\t\t\ttype: `${fieldType}::price_identifier::PriceIdentifier`,\n\t\t\t\tbcs: nameBytes,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.dynamicField) {\n\t\t\tthrow new Error(`Price feed object ID for feed ID ${feedId} not found.`);\n\t\t}\n\n\t\t// The value in the table is just the object ID (address)\n\t\tconst objectId = bcs.Address.parse(result.dynamicField.value.bcs);\n\t\treturn objectId;\n\t}\n\n\t/**\n\t * Fetches the price table object ID for the current state ID, caching the promise.\n\t * @returns Price table object ID and field type\n\t */\n\tgetPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tif (!this.#priceTableInfo) {\n\t\t\tconst promise = this.#fetchPriceTableInfo().catch((err) => {\n\t\t\t\t// Clear the cached promise on error\n\t\t\t\tthis.#priceTableInfo = undefined;\n\t\t\t\tthrow err;\n\t\t\t});\n\n\t\t\tthis.#priceTableInfo = promise;\n\t\t}\n\n\t\treturn this.#priceTableInfo;\n\t}\n\n\t/**\n\t * Fetches the price table object ID and field type (no caching).\n\t * @returns Price table object ID and field type\n\t */\n\tasync #fetchPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tconst result = await this.provider.core.getDynamicObjectField({\n\t\t\tparentId: this.pythStateId,\n\t\t\tname: {\n\t\t\t\ttype: 'vector<u8>',\n\t\t\t\tbcs: bcs.string().serialize('price_info').toBytes(),\n\t\t\t},\n\t\t});\n\n\t\tif (!result.object) {\n\t\t\tthrow new Error('Price Table not found, contract may not be initialized');\n\t\t}\n\n\t\tconst tableType = parseStructTag(result.object.type);\n\t\tconst priceIdentifier = tableType.typeParams[0];\n\t\tif (\n\t\t\ttypeof priceIdentifier === 'object' &&\n\t\t\tpriceIdentifier !== null &&\n\t\t\tpriceIdentifier.name === 'PriceIdentifier' &&\n\t\t\t'address' in priceIdentifier\n\t\t) {\n\t\t\treturn { id: result.object.objectId, fieldType: priceIdentifier.address };\n\t\t} else {\n\t\t\tthrow new Error('fieldType not found');\n\t\t}\n\t}\n\t/**\n\t * Fetches the package ID for the Wormhole contract, with caching.\n\t */\n\tgetWormholePackageId(): Promise<ObjectId> {\n\t\tif (!this.#wormholePackageId) {\n\t\t\tthis.#wormholePackageId = this.#fetchWormholePackageId();\n\t\t}\n\t\treturn this.#wormholePackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Wormhole contract (no caching).\n\t */\n\tasync #fetchWormholePackageId(): Promise<ObjectId> {\n\t\tconst result = await this.provider.core.getObject({\n\t\t\tobjectId: this.wormholeStateId,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (!result.object?.content) {\n\t\t\tthrow new Error('Unable to fetch Wormhole state object');\n\t\t}\n\n\t\tconst state = WormholeState.parse(result.object.content);\n\t\treturn state.upgrade_cap.package;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract, with caching.\n\t */\n\tgetPythPackageId(): Promise<ObjectId> {\n\t\tif (!this.#pythPackageId) {\n\t\t\tthis.#pythPackageId = this.#fetchPythPackageId();\n\t\t}\n\t\treturn this.#pythPackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract (no caching).\n\t */\n\tasync #fetchPythPackageId(): Promise<ObjectId> {\n\t\tconst result = await this.provider.core.getObject({\n\t\t\tobjectId: this.pythStateId,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (!result.object?.content) {\n\t\t\tthrow new Error(`Cannot fetch Pyth package ID for object ${this.pythStateId}`);\n\t\t}\n\n\t\t// Parse the BCS content to get the upgrade_cap.package field\n\t\tconst state = PythState.parse(result.object.content);\n\t\treturn state.upgrade_cap.package;\n\t}\n\n\t/**\n\t * Gets the base update fee from the Pyth state object.\n\t */\n\tasync #fetchBaseUpdateFee(): Promise<number> {\n\t\tconst result = await this.provider.core.getObject({\n\t\t\tobjectId: this.pythStateId,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tif (!result.object?.content) {\n\t\t\tthrow new Error('Unable to fetch Pyth state object');\n\t\t}\n\n\t\t// Parse the BCS content to get the base_update_fee field\n\t\tconst state = PythState.parse(result.object.content);\n\t\treturn Number(state.base_update_fee);\n\t}\n\n\t/**\n\t * Returns the cached base update fee, fetching it if necessary.\n\t */\n\tgetBaseUpdateFee(): Promise<number> {\n\t\tif (!this.#baseUpdateFee) {\n\t\t\tthis.#baseUpdateFee = this.#fetchBaseUpdateFee();\n\t\t}\n\t\treturn this.#baseUpdateFee;\n\t}\n}\n"],"m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K;GACf,SAAS,EAAE,SAAS,MAAM;GAC1B,CAAC;AAEF,MAAI,CAAC,OAAO,QAAQ,QACnB,OAAM,IAAI,MAAM,2CAA2C,KAAK,cAAc;AAK/E,SADcC,MAAU,MAAM,OAAO,OAAO,QAAQ,CACvC,YAAY;;;;;CAM1B,OAAMC,qBAAuC;EAC5C,MAAM,SAAS,MAAM,KAAK,SAAS,KAAK,UAAU;GACjD,UAAU,KAAK;GACf,SAAS,EAAE,SAAS,MAAM;GAC1B,CAAC;AAEF,MAAI,CAAC,OAAO,QAAQ,QACnB,OAAM,IAAI,MAAM,oCAAoC;EAIrD,MAAM,QAAQD,MAAU,MAAM,OAAO,OAAO,QAAQ;AACpD,SAAO,OAAO,MAAM,gBAAgB;;;;;CAMrC,mBAAoC;AACnC,MAAI,CAAC,MAAKE,cACT,OAAKA,gBAAiB,MAAKD,oBAAqB;AAEjD,SAAO,MAAKC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@mysten/deepbook-v3",
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui Deepbook SDK",
5
- "version": "1.0.1",
5
+ "version": "1.0.2",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
8
8
  "main": "./dist/index.mjs",
@@ -45,11 +45,11 @@
45
45
  "vite": "^7.3.1",
46
46
  "vitest": "^4.0.17",
47
47
  "wait-on": "^9.0.3",
48
- "@mysten/codegen": "^0.6.0",
49
- "@mysten/sui": "^2.1.0"
48
+ "@mysten/codegen": "^0.7.0",
49
+ "@mysten/sui": "^2.2.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@mysten/sui": "^2.1.0"
52
+ "@mysten/sui": "^2.2.0"
53
53
  },
54
54
  "scripts": {
55
55
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
package/src/client.ts CHANGED
@@ -1606,6 +1606,153 @@ export class DeepBookClient {
1606
1606
  };
1607
1607
  }
1608
1608
 
1609
+ /**
1610
+ * @description Get comprehensive state information for multiple margin managers.
1611
+ * @param {Record<string, string>} marginManagers Map of marginManagerId -> poolKey
1612
+ * @param {number} decimals Number of decimal places for formatting (default: 6)
1613
+ * @returns {Promise<Record<string, {...}>>} Object keyed by managerId with state data
1614
+ */
1615
+ async getMarginManagerStates(
1616
+ marginManagers: Record<string, string>,
1617
+ decimals: number = 6,
1618
+ ): Promise<
1619
+ Record<
1620
+ string,
1621
+ {
1622
+ managerId: string;
1623
+ deepbookPoolId: string;
1624
+ riskRatio: number;
1625
+ baseAsset: string;
1626
+ quoteAsset: string;
1627
+ baseDebt: string;
1628
+ quoteDebt: string;
1629
+ basePythPrice: string;
1630
+ basePythDecimals: number;
1631
+ quotePythPrice: string;
1632
+ quotePythDecimals: number;
1633
+ currentPrice: bigint;
1634
+ lowestTriggerAbovePrice: bigint;
1635
+ highestTriggerBelowPrice: bigint;
1636
+ }
1637
+ >
1638
+ > {
1639
+ const entries = Object.entries(marginManagers);
1640
+ if (entries.length === 0) {
1641
+ return {};
1642
+ }
1643
+
1644
+ const tx = new Transaction();
1645
+
1646
+ // Add a managerState call for each margin manager
1647
+ for (const [managerId, poolKey] of entries) {
1648
+ tx.add(this.marginManager.managerState(poolKey, managerId));
1649
+ }
1650
+
1651
+ const res = await this.#client.core.simulateTransaction({
1652
+ transaction: tx,
1653
+ include: { commandResults: true, effects: true },
1654
+ });
1655
+
1656
+ if (res.FailedTransaction) {
1657
+ throw new Error(
1658
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1659
+ );
1660
+ }
1661
+
1662
+ if (!res.commandResults) {
1663
+ throw new Error(`Failed to get margin manager states: Unknown error`);
1664
+ }
1665
+
1666
+ const results: Record<
1667
+ string,
1668
+ {
1669
+ managerId: string;
1670
+ deepbookPoolId: string;
1671
+ riskRatio: number;
1672
+ baseAsset: string;
1673
+ quoteAsset: string;
1674
+ baseDebt: string;
1675
+ quoteDebt: string;
1676
+ basePythPrice: string;
1677
+ basePythDecimals: number;
1678
+ quotePythPrice: string;
1679
+ quotePythDecimals: number;
1680
+ currentPrice: bigint;
1681
+ lowestTriggerAbovePrice: bigint;
1682
+ highestTriggerBelowPrice: bigint;
1683
+ }
1684
+ > = {};
1685
+
1686
+ // Parse each command result
1687
+ for (let i = 0; i < entries.length; i++) {
1688
+ const commandResult = res.commandResults[i];
1689
+ if (!commandResult || !commandResult.returnValues) {
1690
+ throw new Error(`Failed to get margin manager state for index ${i}: No return values`);
1691
+ }
1692
+
1693
+ const [, poolKey] = entries[i];
1694
+ const pool = this.#config.getPool(poolKey);
1695
+ const baseCoin = this.#config.getCoin(pool.baseCoin);
1696
+ const quoteCoin = this.#config.getCoin(pool.quoteCoin);
1697
+
1698
+ const managerId = normalizeSuiAddress(bcs.Address.parse(commandResult.returnValues[0].bcs));
1699
+ const deepbookPoolId = normalizeSuiAddress(
1700
+ bcs.Address.parse(commandResult.returnValues[1].bcs),
1701
+ );
1702
+ const riskRatio = Number(bcs.U64.parse(commandResult.returnValues[2].bcs)) / FLOAT_SCALAR;
1703
+ const baseAsset = this.#formatTokenAmount(
1704
+ BigInt(bcs.U64.parse(commandResult.returnValues[3].bcs)),
1705
+ baseCoin.scalar,
1706
+ decimals,
1707
+ );
1708
+ const quoteAsset = this.#formatTokenAmount(
1709
+ BigInt(bcs.U64.parse(commandResult.returnValues[4].bcs)),
1710
+ quoteCoin.scalar,
1711
+ decimals,
1712
+ );
1713
+ const baseDebt = this.#formatTokenAmount(
1714
+ BigInt(bcs.U64.parse(commandResult.returnValues[5].bcs)),
1715
+ baseCoin.scalar,
1716
+ decimals,
1717
+ );
1718
+ const quoteDebt = this.#formatTokenAmount(
1719
+ BigInt(bcs.U64.parse(commandResult.returnValues[6].bcs)),
1720
+ quoteCoin.scalar,
1721
+ decimals,
1722
+ );
1723
+ const basePythPrice = bcs.U64.parse(commandResult.returnValues[7].bcs);
1724
+ const basePythDecimals = Number(
1725
+ bcs.u8().parse(new Uint8Array(commandResult.returnValues[8].bcs)),
1726
+ );
1727
+ const quotePythPrice = bcs.U64.parse(commandResult.returnValues[9].bcs);
1728
+ const quotePythDecimals = Number(
1729
+ bcs.u8().parse(new Uint8Array(commandResult.returnValues[10].bcs)),
1730
+ );
1731
+ const currentPrice = BigInt(bcs.U64.parse(commandResult.returnValues[11].bcs));
1732
+ const lowestTriggerAbovePrice = BigInt(bcs.U64.parse(commandResult.returnValues[12].bcs));
1733
+ const highestTriggerBelowPrice = BigInt(bcs.U64.parse(commandResult.returnValues[13].bcs));
1734
+
1735
+ results[managerId] = {
1736
+ managerId,
1737
+ deepbookPoolId,
1738
+ riskRatio,
1739
+ baseAsset,
1740
+ quoteAsset,
1741
+ baseDebt,
1742
+ quoteDebt,
1743
+ basePythPrice: basePythPrice.toString(),
1744
+ basePythDecimals,
1745
+ quotePythPrice: quotePythPrice.toString(),
1746
+ quotePythDecimals,
1747
+ currentPrice,
1748
+ lowestTriggerAbovePrice,
1749
+ highestTriggerBelowPrice,
1750
+ };
1751
+ }
1752
+
1753
+ return results;
1754
+ }
1755
+
1609
1756
  /**
1610
1757
  * @description Get the base asset balance of a margin manager
1611
1758
  * @param {string} marginManagerKey The key to identify the margin manager
@@ -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 { bcs } from '@mysten/sui/bcs';
6
+ const $moduleName = '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::bytes32';
7
+ export const Bytes32 = new MoveStruct({
8
+ name: `${$moduleName}::Bytes32`,
9
+ fields: {
10
+ data: bcs.vector(bcs.u8()),
11
+ },
12
+ });
@@ -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 set from './set.js';
6
+ const $moduleName =
7
+ '0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94::consumed_vaas';
8
+ export const ConsumedVAAs = new MoveStruct({
9
+ name: `${$moduleName}::ConsumedVAAs`,
10
+ fields: {
11
+ hashes: set.Set,
12
+ },
13
+ });
@@ -1,15 +1,12 @@
1
1
  /**************************************************************
2
2
  * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
3
  **************************************************************/
4
-
5
- /** Sui object identifiers */
6
-
7
4
  import { MoveStruct } from '../../../utils/index.js';
8
5
  import { bcs } from '@mysten/sui/bcs';
9
- const $moduleName = '0x2::object';
10
- export const UID = new MoveStruct({
11
- name: `${$moduleName}::UID`,
6
+ const $moduleName = '0x2::balance';
7
+ export const Balance = new MoveStruct({
8
+ name: `${$moduleName}::Balance`,
12
9
  fields: {
13
- id: bcs.Address,
10
+ value: bcs.u64(),
14
11
  },
15
12
  });
@@ -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
+ const $moduleName = '0x2::package';
7
+ export const UpgradeCap = new MoveStruct({
8
+ name: `${$moduleName}::UpgradeCap`,
9
+ fields: {
10
+ id: bcs.Address,
11
+ package: bcs.Address,
12
+ version: bcs.u64(),
13
+ policy: bcs.u8(),
14
+ },
15
+ });
@@ -3,10 +3,11 @@
3
3
  **************************************************************/
4
4
  import { MoveStruct } from '../../../utils/index.js';
5
5
  import { bcs } from '@mysten/sui/bcs';
6
- const $moduleName = '0x2::object';
7
- export const UID = new MoveStruct({
8
- name: `${$moduleName}::UID`,
6
+ const $moduleName = '0x2::table';
7
+ export const Table = new MoveStruct({
8
+ name: `${$moduleName}::Table`,
9
9
  fields: {
10
10
  id: bcs.Address,
11
+ size: bcs.u64(),
11
12
  },
12
13
  });