@mysten/deepbook-v3 1.0.0 → 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 +14 -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/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginRegistry.d.mts +15 -15
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +5 -0
- package/dist/utils/constants.mjs.map +1 -1
- package/package.json +5 -5
- 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
- package/src/utils/constants.ts +5 -0
|
@@ -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"}
|
package/dist/pyth/pyth.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyth.d.mts","names":[],"sources":["../../src/pyth/pyth.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"pyth.d.mts","names":[],"sources":["../../src/pyth/pyth.ts"],"sourcesContent":[],"mappings":";;;;;KAgBY,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;;;;;;;EAwH7B,gBAAA,CAAA,EAAA,EApOtB,WAoOsB,EAAA,OAAA,EAnOjB,UAmOiB,EAAA,EAAA,OAAA,EAlOjB,SAkOiB,EAAA,CAAA,EAjOxB,OAiOwB,CAjOhB,QAiOgB,EAAA,CAAA;;;;;+BAzKE,YAAY,QAAQ;;;;;uBAiD5B;QAAc;eAAqB;;;;;0BA+ChC,QAAQ;;;;sBA2BZ,QAAQ;;;;sBA8CR"}
|
package/dist/pyth/pyth.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PriceServiceConnection } 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
|
|
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:
|
|
150
|
+
bcs: bcs.string().serialize("price_info").toBytes()
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
-
if (!result.
|
|
154
|
-
const priceIdentifier = parseStructTag(result.
|
|
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.
|
|
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
|
-
|
|
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 ${
|
|
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
|
/**
|
package/dist/pyth/pyth.mjs.map
CHANGED
|
@@ -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":";;;;;;;;AAcA,MAAM,oBAAoB,KAAK;AAE/B,IAAa,4BAAb,cAA+C,uBAAuB;;;;;;;CAOrE,MAAM,wBAAwB,UAA8C;AAE3E,UADmB,MAAM,KAAK,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AM,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"],"mappings":";;;;;;;;;AAeA,MAAM,oBAAoB,KAAK;AAE/B,IAAa,4BAAb,cAA+C,uBAAuB;;;;;;;CAOrE,MAAM,wBAAwB,UAA8C;AA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AAc;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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_transactions92 from "@mysten/sui/transactions";
|
|
3
3
|
import { Transaction } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/transactions/marginLiquidations.d.ts
|
|
@@ -35,7 +35,7 @@ declare class MarginLiquidationsContract {
|
|
|
35
35
|
* @param {number} amount The amount to withdraw
|
|
36
36
|
* @returns A function that takes a Transaction object and returns the withdrawn coin
|
|
37
37
|
*/
|
|
38
|
-
withdraw: (vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) => (tx: Transaction) =>
|
|
38
|
+
withdraw: (vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions92.TransactionResult;
|
|
39
39
|
/**
|
|
40
40
|
* @description Liquidate a margin manager by repaying base debt
|
|
41
41
|
* @param {string} vaultId The liquidation vault object ID
|
|
@@ -60,7 +60,7 @@ declare class MarginLiquidationsContract {
|
|
|
60
60
|
* @param {string} coinKey The key to identify the coin type
|
|
61
61
|
* @returns A function that takes a Transaction object
|
|
62
62
|
*/
|
|
63
|
-
balance: (vaultId: string, coinKey: string) => (tx: Transaction) =>
|
|
63
|
+
balance: (vaultId: string, coinKey: string) => (tx: Transaction) => _mysten_sui_transactions92.TransactionResult;
|
|
64
64
|
}
|
|
65
65
|
//#endregion
|
|
66
66
|
export { MarginLiquidationsContract };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginLiquidations.d.mts","names":[],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUa,cAAA,0BAAA,CAA0B;EAMlB,CAAA,OAAA;EAS2C;;;EAwC9C,WAAA,CAAA,MAAA,EAjDG,cAiDH;EAuBX;;;;;gEA/DyD;;;;;;;;;mGAiBzD;;;;;;;;;oGAuBA,gBAAW,
|
|
1
|
+
{"version":3,"file":"marginLiquidations.d.mts","names":[],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUa,cAAA,0BAAA,CAA0B;EAMlB,CAAA,OAAA;EAS2C;;;EAwC9C,WAAA,CAAA,MAAA,EAjDG,cAiDH;EAuBX;;;;;gEA/DyD;;;;;;;;;mGAiBzD;;;;;;;;;oGAuBA,gBAAW,0BAAA,CAAA;;;;;;;;;0GAuBX;;;;;;;;;2GAwCA;;;;;;;sDAsC+C,gBAAW,0BAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_transactions94 from "@mysten/sui/transactions";
|
|
3
3
|
import { Transaction } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/transactions/marginRegistry.d.ts
|
|
@@ -17,83 +17,83 @@ declare class MarginRegistryContract {
|
|
|
17
17
|
* @param {string} poolKey The key to identify the pool
|
|
18
18
|
* @returns A function that takes a Transaction object
|
|
19
19
|
*/
|
|
20
|
-
poolEnabled: (poolKey: string) => (tx: Transaction) =>
|
|
20
|
+
poolEnabled: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
21
21
|
/**
|
|
22
22
|
* @description Get the margin pool ID for a given asset
|
|
23
23
|
* @param {string} coinKey The key to identify the coin
|
|
24
24
|
* @returns A function that takes a Transaction object
|
|
25
25
|
*/
|
|
26
|
-
getMarginPoolId: (coinKey: string) => (tx: Transaction) =>
|
|
26
|
+
getMarginPoolId: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
27
27
|
/**
|
|
28
28
|
* @description Get the margin pool IDs (base and quote) for a deepbook pool
|
|
29
29
|
* @param {string} poolKey The key to identify the pool
|
|
30
30
|
* @returns A function that takes a Transaction object
|
|
31
31
|
*/
|
|
32
|
-
getDeepbookPoolMarginPoolIds: (poolKey: string) => (tx: Transaction) =>
|
|
32
|
+
getDeepbookPoolMarginPoolIds: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
33
33
|
/**
|
|
34
34
|
* @description Get the margin manager IDs for a given owner
|
|
35
35
|
* @param {string} owner The owner address
|
|
36
36
|
* @returns A function that takes a Transaction object
|
|
37
37
|
*/
|
|
38
|
-
getMarginManagerIds: (owner: string) => (tx: Transaction) =>
|
|
38
|
+
getMarginManagerIds: (owner: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
39
39
|
/**
|
|
40
40
|
* @description Get the base margin pool ID for a deepbook pool
|
|
41
41
|
* @param {string} poolKey The key to identify the pool
|
|
42
42
|
* @returns A function that takes a Transaction object
|
|
43
43
|
*/
|
|
44
|
-
baseMarginPoolId: (poolKey: string) => (tx: Transaction) =>
|
|
44
|
+
baseMarginPoolId: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
45
45
|
/**
|
|
46
46
|
* @description Get the quote margin pool ID for a deepbook pool
|
|
47
47
|
* @param {string} poolKey The key to identify the pool
|
|
48
48
|
* @returns A function that takes a Transaction object
|
|
49
49
|
*/
|
|
50
|
-
quoteMarginPoolId: (poolKey: string) => (tx: Transaction) =>
|
|
50
|
+
quoteMarginPoolId: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
51
51
|
/**
|
|
52
52
|
* @description Get the minimum withdraw risk ratio for a deepbook pool
|
|
53
53
|
* @param {string} poolKey The key to identify the pool
|
|
54
54
|
* @returns A function that takes a Transaction object
|
|
55
55
|
*/
|
|
56
|
-
minWithdrawRiskRatio: (poolKey: string) => (tx: Transaction) =>
|
|
56
|
+
minWithdrawRiskRatio: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
57
57
|
/**
|
|
58
58
|
* @description Get the minimum borrow risk ratio for a deepbook pool
|
|
59
59
|
* @param {string} poolKey The key to identify the pool
|
|
60
60
|
* @returns A function that takes a Transaction object
|
|
61
61
|
*/
|
|
62
|
-
minBorrowRiskRatio: (poolKey: string) => (tx: Transaction) =>
|
|
62
|
+
minBorrowRiskRatio: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
63
63
|
/**
|
|
64
64
|
* @description Get the liquidation risk ratio for a deepbook pool
|
|
65
65
|
* @param {string} poolKey The key to identify the pool
|
|
66
66
|
* @returns A function that takes a Transaction object
|
|
67
67
|
*/
|
|
68
|
-
liquidationRiskRatio: (poolKey: string) => (tx: Transaction) =>
|
|
68
|
+
liquidationRiskRatio: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
69
69
|
/**
|
|
70
70
|
* @description Get the target liquidation risk ratio for a deepbook pool
|
|
71
71
|
* @param {string} poolKey The key to identify the pool
|
|
72
72
|
* @returns A function that takes a Transaction object
|
|
73
73
|
*/
|
|
74
|
-
targetLiquidationRiskRatio: (poolKey: string) => (tx: Transaction) =>
|
|
74
|
+
targetLiquidationRiskRatio: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
75
75
|
/**
|
|
76
76
|
* @description Get the user liquidation reward for a deepbook pool
|
|
77
77
|
* @param {string} poolKey The key to identify the pool
|
|
78
78
|
* @returns A function that takes a Transaction object
|
|
79
79
|
*/
|
|
80
|
-
userLiquidationReward: (poolKey: string) => (tx: Transaction) =>
|
|
80
|
+
userLiquidationReward: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
81
81
|
/**
|
|
82
82
|
* @description Get the pool liquidation reward for a deepbook pool
|
|
83
83
|
* @param {string} poolKey The key to identify the pool
|
|
84
84
|
* @returns A function that takes a Transaction object
|
|
85
85
|
*/
|
|
86
|
-
poolLiquidationReward: (poolKey: string) => (tx: Transaction) =>
|
|
86
|
+
poolLiquidationReward: (poolKey: string) => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
87
87
|
/**
|
|
88
88
|
* @description Get all allowed maintainer cap IDs
|
|
89
89
|
* @returns A function that takes a Transaction object
|
|
90
90
|
*/
|
|
91
|
-
allowedMaintainers: () => (tx: Transaction) =>
|
|
91
|
+
allowedMaintainers: () => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
92
92
|
/**
|
|
93
93
|
* @description Get all allowed pause cap IDs
|
|
94
94
|
* @returns A function that takes a Transaction object
|
|
95
95
|
*/
|
|
96
|
-
allowedPauseCaps: () => (tx: Transaction) =>
|
|
96
|
+
allowedPauseCaps: () => (tx: Transaction) => _mysten_sui_transactions94.TransactionResult;
|
|
97
97
|
}
|
|
98
98
|
//#endregion
|
|
99
99
|
export { MarginRegistryContract };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":[],"mappings":";;;KAKY,OAAA,GAAU,eAAe;KACzB,OAAA,GAAU,eAAe;AADzB,KAEA,aAAA,GAAgB,MAFN,CAAA,MAAM,EAEe,UAFf,CAAA;AAChB,UAEK,kBAAA,CAFK;EACV,mBAAa,EAAA,MAAA;EACR,WAAA,EAAA,MAAA;EASJ,gBAAA,EAAA,MAOiB;EAEjB,iBAAA,EAAA,MAOiB;EAEjB,kBA2CZ,EAAA,MAAA;EAEY,
|
|
1
|
+
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":[],"mappings":";;;KAKY,OAAA,GAAU,eAAe;KACzB,OAAA,GAAU,eAAe;AADzB,KAEA,aAAA,GAAgB,MAFN,CAAA,MAAM,EAEe,UAFf,CAAA;AAChB,UAEK,kBAAA,CAFK;EACV,mBAAa,EAAA,MAAA;EACR,WAAA,EAAA,MAAA;EASJ,gBAAA,EAAA,MAOiB;EAEjB,iBAAA,EAAA,MAOiB;EAEjB,kBA2CZ,EAAA,MAAA;EAEY,sBAuHZ,EAAA,MAvH0B;AAyH3B;AAsCa,cA9NA,iBA8Nc,EAqG1B;EAEY,mBAAA,EAiBZ,MAAA;EAEY,WAAA,EAAA,MAAA;EAmBA,gBAAA,EAAA,MAGZ;EAEY,iBAAA,EAAA,MAGZ;;;;cA1WY;;;;;;;;cASA,cAAc;cA6Cd,cAAc;cAyHd,cAAc;cAsCd,cAAc;cAuGd;;;;;;;;;;;;;;;;;;cAmBA;;;;;;;;;;;;;;;;;;cAmBA;;;;cAKA"}
|
package/dist/utils/constants.mjs
CHANGED
|
@@ -167,6 +167,11 @@ const mainnetCoins = {
|
|
|
167
167
|
type: `0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT`,
|
|
168
168
|
scalar: 1e6
|
|
169
169
|
},
|
|
170
|
+
USDE: {
|
|
171
|
+
address: `0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402`,
|
|
172
|
+
type: `0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE`,
|
|
173
|
+
scalar: 1e6
|
|
174
|
+
},
|
|
170
175
|
WGIGA: {
|
|
171
176
|
address: `0xec32640add6d02a1d5f0425d72705eb76d9de7edfd4f34e0dba68e62ecceb05b`,
|
|
172
177
|
type: `0xec32640add6d02a1d5f0425d72705eb76d9de7edfd4f34e0dba68e62ecceb05b::coin::COIN`,
|