@mysten/deepbook-v3 1.4.1 → 1.5.0
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 +22 -0
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/account.d.mts.map +1 -1
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- package/dist/contracts/deepbook/deep_price.d.mts +3 -3
- package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/utils/index.d.mts +35 -0
- package/dist/contracts/utils/index.d.mts.map +1 -1
- package/dist/contracts/utils/index.mjs +73 -2
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginTPSL.d.mts +9 -9
- package/dist/transactions/poolProxy.d.mts +5 -5
- package/package.json +13 -13
- package/src/contracts/utils/index.ts +165 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mysten/deepbook-v3
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bbf63cb: Add `typeTag` and `resolveTypeTag` methods to the generated `MoveStruct`, `MoveEnum`, and
|
|
8
|
+
`MoveTuple` classes.
|
|
9
|
+
|
|
10
|
+
- `typeTag(options?)` builds the type tag string for a generated type. `typeArguments` is the full
|
|
11
|
+
positional list of type arguments in Move declaration order; each entry is a type tag string,
|
|
12
|
+
another `typeTag()` result, or a BCS type (its name is used). Types with unfilled phantom
|
|
13
|
+
parameters require `typeArguments` at compile time, and argument arity is validated at runtime.
|
|
14
|
+
- `resolveTypeTag({ client, ... })` builds the tag, resolves MVR names through
|
|
15
|
+
`client.core.mvr.resolveType`, and returns the normalized address-only form suitable for queries
|
|
16
|
+
and comparisons against on-chain data.
|
|
17
|
+
|
|
18
|
+
- bbf63cb: Updated dependencies
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [bbf63cb]
|
|
23
|
+
- @mysten/bcs@2.1.0
|
|
24
|
+
|
|
3
25
|
## 1.4.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_bcs0 from "@mysten/sui/bcs";
|
|
3
3
|
import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/deepbook/account.d.ts
|
|
6
6
|
declare const Account: MoveStruct<{
|
|
7
|
-
epoch:
|
|
7
|
+
epoch: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
8
8
|
open_orders: MoveStruct<{
|
|
9
|
-
contents:
|
|
9
|
+
contents: _mysten_sui_bcs0.BcsType<string[], Iterable<string | number | bigint> & {
|
|
10
10
|
length: number;
|
|
11
11
|
}, string>;
|
|
12
12
|
}, "0x2::vec_set::VecSet<u128>">;
|
|
13
|
-
taker_volume:
|
|
14
|
-
maker_volume:
|
|
15
|
-
active_stake:
|
|
16
|
-
inactive_stake:
|
|
17
|
-
created_proposal:
|
|
18
|
-
voted_proposal:
|
|
13
|
+
taker_volume: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u128">;
|
|
14
|
+
maker_volume: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u128">;
|
|
15
|
+
active_stake: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
16
|
+
inactive_stake: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
17
|
+
created_proposal: _mysten_sui_bcs0.BcsType<boolean, boolean, "bool">;
|
|
18
|
+
voted_proposal: _mysten_sui_bcs0.BcsType<string | null, string | Uint8Array<ArrayBufferLike> | null | undefined, "Option<bytes[32]>">;
|
|
19
19
|
unclaimed_rebates: MoveStruct<{
|
|
20
|
-
base:
|
|
21
|
-
quote:
|
|
22
|
-
deep:
|
|
20
|
+
base: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
21
|
+
quote: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
22
|
+
deep: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
23
23
|
}, "@deepbook/core::balances::Balances">;
|
|
24
24
|
settled_balances: MoveStruct<{
|
|
25
|
-
base:
|
|
26
|
-
quote:
|
|
27
|
-
deep:
|
|
25
|
+
base: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
26
|
+
quote: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
27
|
+
deep: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
28
28
|
}, "@deepbook/core::balances::Balances">;
|
|
29
29
|
owed_balances: MoveStruct<{
|
|
30
|
-
base:
|
|
31
|
-
quote:
|
|
32
|
-
deep:
|
|
30
|
+
base: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
31
|
+
quote: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
32
|
+
deep: _mysten_sui_bcs0.BcsType<string, string | number | bigint, "u64">;
|
|
33
33
|
}, "@deepbook/core::balances::Balances">;
|
|
34
34
|
}, "@deepbook/core::account::Account">;
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.mts","names":[],"sources":["../../../src/contracts/deepbook/account.ts"],"mappings":";;;;;cAYa,OAAA,EAAO,UAAA;SAelB,
|
|
1
|
+
{"version":3,"file":"account.d.mts","names":[],"sources":["../../../src/contracts/deepbook/account.ts"],"mappings":";;;;;cAYa,OAAA,EAAO,UAAA;SAelB,gBAAA,CAAA,OAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_bcs16 from "@mysten/sui/bcs";
|
|
3
3
|
|
|
4
4
|
//#region src/contracts/deepbook/balances.d.ts
|
|
5
5
|
declare const Balances: MoveStruct<{
|
|
6
|
-
base:
|
|
7
|
-
quote:
|
|
8
|
-
deep:
|
|
6
|
+
base: _mysten_sui_bcs16.BcsType<string, string | number | bigint, "u64">;
|
|
7
|
+
quote: _mysten_sui_bcs16.BcsType<string, string | number | bigint, "u64">;
|
|
8
|
+
deep: _mysten_sui_bcs16.BcsType<string, string | number | bigint, "u64">;
|
|
9
9
|
}, "@deepbook/core::balances::Balances">;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { Balances };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_bcs19 from "@mysten/sui/bcs";
|
|
3
3
|
import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/deepbook/deep_price.d.ts
|
|
6
6
|
declare const OrderDeepPrice: MoveStruct<{
|
|
7
|
-
asset_is_base:
|
|
8
|
-
deep_per_asset:
|
|
7
|
+
asset_is_base: _mysten_sui_bcs19.BcsType<boolean, boolean, "bool">;
|
|
8
|
+
deep_per_asset: _mysten_sui_bcs19.BcsType<string, string | number | bigint, "u64">;
|
|
9
9
|
}, "@deepbook/core::deep_price::OrderDeepPrice">;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { OrderDeepPrice };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep_price.d.mts","names":[],"sources":["../../../src/contracts/deepbook/deep_price.ts"],"mappings":";;;;;cAuCa,cAAA,EAAc,UAAA;iBAMzB,
|
|
1
|
+
{"version":3,"file":"deep_price.d.mts","names":[],"sources":["../../../src/contracts/deepbook/deep_price.ts"],"mappings":";;;;;cAuCa,cAAA,EAAc,UAAA;iBAMzB,iBAAA,CAAA,OAAA"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { MoveStruct } from "../utils/index.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_bcs32 from "@mysten/sui/bcs";
|
|
3
3
|
import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/deepbook/order.d.ts
|
|
6
6
|
declare const Order: MoveStruct<{
|
|
7
|
-
balance_manager_id:
|
|
8
|
-
order_id:
|
|
9
|
-
client_order_id:
|
|
10
|
-
quantity:
|
|
11
|
-
filled_quantity:
|
|
12
|
-
fee_is_deep:
|
|
7
|
+
balance_manager_id: _mysten_sui_bcs32.BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
8
|
+
order_id: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u128">;
|
|
9
|
+
client_order_id: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
10
|
+
quantity: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
11
|
+
filled_quantity: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
12
|
+
fee_is_deep: _mysten_sui_bcs32.BcsType<boolean, boolean, "bool">;
|
|
13
13
|
order_deep_price: MoveStruct<{
|
|
14
|
-
asset_is_base:
|
|
15
|
-
deep_per_asset:
|
|
14
|
+
asset_is_base: _mysten_sui_bcs32.BcsType<boolean, boolean, "bool">;
|
|
15
|
+
deep_per_asset: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
16
16
|
}, "@deepbook/core::deep_price::OrderDeepPrice">;
|
|
17
|
-
epoch:
|
|
18
|
-
status:
|
|
19
|
-
expire_timestamp:
|
|
17
|
+
epoch: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
18
|
+
status: _mysten_sui_bcs32.BcsType<number, number, "u8">;
|
|
19
|
+
expire_timestamp: _mysten_sui_bcs32.BcsType<string, string | number | bigint, "u64">;
|
|
20
20
|
}, "@deepbook/core::order::Order">;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { Order };
|
|
@@ -9,7 +9,42 @@ type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> =
|
|
|
9
9
|
type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> = SuiClientTypes.GetObjectsOptions<Include> & {
|
|
10
10
|
client: ClientWithCoreApi;
|
|
11
11
|
};
|
|
12
|
+
/** A type argument: a type tag string, or a BCS type whose name is a Move type. */
|
|
13
|
+
type TypeArgument = string | BcsType<any>;
|
|
14
|
+
interface TypeTagOptions {
|
|
15
|
+
package?: string;
|
|
16
|
+
typeArguments?: readonly TypeArgument[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `typeArguments` is required when the type's name contains unfilled
|
|
20
|
+
* `phantom X` parameters (at any depth). Everything else — argument arity,
|
|
21
|
+
* position contents, and tag validity — is validated at runtime.
|
|
22
|
+
*/
|
|
23
|
+
type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}` ? [options: TypeTagOptions & {
|
|
24
|
+
typeArguments: readonly TypeArgument[];
|
|
25
|
+
}] : [options?: TypeTagOptions];
|
|
26
|
+
type ResolveTypeTagOptions<Name extends string> = {
|
|
27
|
+
client: ClientWithCoreApi;
|
|
28
|
+
} & (Name extends `${string}phantom ${string}` ? TypeTagOptions & {
|
|
29
|
+
typeArguments: readonly TypeArgument[];
|
|
30
|
+
} : TypeTagOptions);
|
|
12
31
|
declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
32
|
+
/**
|
|
33
|
+
* Build the type tag for this struct.
|
|
34
|
+
*
|
|
35
|
+
* `typeArguments` is the full positional list, in Move declaration order, and
|
|
36
|
+
* is required when the struct has unfilled phantom parameters. The result may
|
|
37
|
+
* contain MVR names: those are valid in transaction `typeArguments`, but for
|
|
38
|
+
* queries or comparisons against on-chain data use `resolveTypeTag` instead.
|
|
39
|
+
*/
|
|
40
|
+
typeTag(...args: TypeTagParams<Name>): string;
|
|
41
|
+
/**
|
|
42
|
+
* Build the type tag for this struct, then resolve any MVR names through the
|
|
43
|
+
* client (using its configured overrides and the MVR API) and return the
|
|
44
|
+
* normalized, address-only form suitable for queries and comparisons against
|
|
45
|
+
* on-chain data.
|
|
46
|
+
*/
|
|
47
|
+
resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string>;
|
|
13
48
|
get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
14
49
|
objectId,
|
|
15
50
|
...options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/contracts/utils/index.ts"],"mappings":";;;;;KAkBY,UAAA,iBAA2B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC1D,cAAA,CAAe,gBAAA,CAAiB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAE1C,cAAA,iBAA+B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC9D,cAAA,CAAe,iBAAA,CAAkB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/contracts/utils/index.ts"],"mappings":";;;;;KAkBY,UAAA,iBAA2B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC1D,cAAA,CAAe,gBAAA,CAAiB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAE1C,cAAA,iBAA+B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC9D,cAAA,CAAe,iBAAA,CAAkB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;;KA4I3C,YAAA,YAAwB,OAAA;AAAA,UAEnB,cAAA;EAChB,OAAA;EACA,aAAA,YAAyB,YAAA;AAAA;;;;;;KAQrB,aAAA,wBAAqC,IAAA,yCACtC,OAAA,EAAS,cAAA;EAAmB,aAAA,WAAwB,YAAA;AAAA,MACpD,OAAA,GAAU,cAAA;AAAA,KAET,qBAAA;EACJ,MAAA,EAAQ,iBAAA;AAAA,KACJ,IAAA,wCACF,cAAA;EAAmB,aAAA,WAAwB,YAAA;AAAA,IAC3C,cAAA;AAAA,cAqFU,UAAA,WACF,MAAA,SAAe,OAAA,oDAEhB,SAAA,CAAU,CAAA,EAAG,IAAA;EAxPtB;;;;;;;;EAiQA,OAAA,CAAA,GAAW,IAAA,EAAM,aAAA,CAAc,IAAA;EAjQhB;;;;;;EA2QT,cAAA,CAAe,OAAA,EAAS,qBAAA,CAAsB,IAAA,IAAQ,OAAA;EAOtD,GAAA,iBAAoB,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IAC7C,QAAA;IAAA,GACG;EAAA,GACD,UAAA,CAAW,OAAA,IAAW,OAAA,CACxB,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;EAeZ,OAAA,iBAAwB,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IACjD,MAAA;IAAA,GACG;EAAA,GACD,cAAA,CAAe,OAAA,IAAW,OAAA,CAC5B,KAAA,CACC,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;AAAA"}
|
|
@@ -1,11 +1,77 @@
|
|
|
1
|
-
import { BcsStruct, bcs } from "@mysten/sui/bcs";
|
|
1
|
+
import { BcsStruct, TypeTagSerializer, bcs } from "@mysten/sui/bcs";
|
|
2
2
|
import "@mysten/sui/transactions";
|
|
3
|
-
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
3
|
+
import { normalizeStructTag, normalizeSuiAddress } from "@mysten/sui/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/utils/index.ts
|
|
6
6
|
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
|
|
7
7
|
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
|
|
8
|
+
const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
|
|
9
|
+
function splitTopLevelTypeArgs(inner) {
|
|
10
|
+
const parts = [];
|
|
11
|
+
let depth = 0;
|
|
12
|
+
let current = "";
|
|
13
|
+
for (const char of inner) {
|
|
14
|
+
if (char === "," && depth === 0) {
|
|
15
|
+
parts.push(current.trim());
|
|
16
|
+
current = "";
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (char === "<") depth++;
|
|
20
|
+
if (char === ">") depth--;
|
|
21
|
+
current += char;
|
|
22
|
+
}
|
|
23
|
+
if (current) parts.push(current.trim());
|
|
24
|
+
return parts;
|
|
25
|
+
}
|
|
26
|
+
function buildTypeTag(name, options) {
|
|
27
|
+
const lt = name.indexOf("<");
|
|
28
|
+
const base = lt === -1 ? name : name.slice(0, lt);
|
|
29
|
+
if (base.split("::").length !== 3) throw new Error(`${name} is not a top-level Move type`);
|
|
30
|
+
let result = name;
|
|
31
|
+
if (options?.typeArguments) {
|
|
32
|
+
const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
|
|
33
|
+
const supplied = options.typeArguments.map((arg) => {
|
|
34
|
+
if (typeof arg === "string") return arg;
|
|
35
|
+
if (arg && typeof arg.serialize === "function" && typeof arg.name === "string") return arg.name;
|
|
36
|
+
throw new Error(`Invalid type argument ${stringify(arg)}`);
|
|
37
|
+
});
|
|
38
|
+
if (supplied.length !== baked.length) throw new Error(`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`);
|
|
39
|
+
result = supplied.length === 0 ? base : `${base}<${supplied.join(", ")}>`;
|
|
40
|
+
}
|
|
41
|
+
if (HAS_PHANTOM_REGEX.test(result)) throw new Error(options?.typeArguments ? `A type argument contains an unfilled phantom parameter in ${result}` : `Missing type arguments for ${result}`);
|
|
42
|
+
if (options?.package) {
|
|
43
|
+
const [, ...rest] = result.split("::");
|
|
44
|
+
result = [options.package, ...rest].join("::");
|
|
45
|
+
}
|
|
46
|
+
if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) TypeTagSerializer.parseFromStr(result);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async function resolveBuiltTypeTag(name, options) {
|
|
50
|
+
const { client, ...rest } = options;
|
|
51
|
+
const { type } = await client.core.mvr.resolveType({ type: buildTypeTag(name, rest) });
|
|
52
|
+
return normalizeStructTag(type);
|
|
53
|
+
}
|
|
8
54
|
var MoveStruct = class extends BcsStruct {
|
|
55
|
+
/**
|
|
56
|
+
* Build the type tag for this struct.
|
|
57
|
+
*
|
|
58
|
+
* `typeArguments` is the full positional list, in Move declaration order, and
|
|
59
|
+
* is required when the struct has unfilled phantom parameters. The result may
|
|
60
|
+
* contain MVR names: those are valid in transaction `typeArguments`, but for
|
|
61
|
+
* queries or comparisons against on-chain data use `resolveTypeTag` instead.
|
|
62
|
+
*/
|
|
63
|
+
typeTag(...args) {
|
|
64
|
+
return buildTypeTag(this.name, args[0]);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build the type tag for this struct, then resolve any MVR names through the
|
|
68
|
+
* client (using its configured overrides and the MVR API) and return the
|
|
69
|
+
* normalized, address-only form suitable for queries and comparisons against
|
|
70
|
+
* on-chain data.
|
|
71
|
+
*/
|
|
72
|
+
async resolveTypeTag(options) {
|
|
73
|
+
return resolveBuiltTypeTag(this.name, options);
|
|
74
|
+
}
|
|
9
75
|
async get({ objectId, ...options }) {
|
|
10
76
|
const [res] = await this.getMany({
|
|
11
77
|
...options,
|
|
@@ -30,6 +96,11 @@ var MoveStruct = class extends BcsStruct {
|
|
|
30
96
|
});
|
|
31
97
|
}
|
|
32
98
|
};
|
|
99
|
+
function stringify(val) {
|
|
100
|
+
if (typeof val === "object") return JSON.stringify(val, (_key, value) => typeof value === "bigint" ? value.toString() : value);
|
|
101
|
+
if (typeof val === "bigint") return val.toString();
|
|
102
|
+
return val;
|
|
103
|
+
}
|
|
33
104
|
|
|
34
105
|
//#endregion
|
|
35
106
|
export { MoveStruct };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":";;;;;AAaA,MAAM,sBAAsB,oBAAoB,MAAM;AACtD,MAAM,wBAAwB,oBAAoB,MAAM;AAiJxD,IAAa,aAAb,cAGU,UAAmB;CAC5B,MAAM,IAAiF,EACtF,UACA,GAAG,WAKF;EACD,MAAM,CAAC,OAAO,MAAM,KAAK,QAAiB;GACzC,GAAG;GACH,WAAW,CAAC,SAAS;GACrB,CAAC;AAEF,MAAI,CAAC,IACJ,OAAM,IAAI,MAAM,0BAA0B,WAAW;AAGtD,SAAO;;CAGR,MAAM,QAAqF,EAC1F,QACA,GAAG,WAOF;AASD,UARkB,MAAM,OAAO,KAAK,WAAW;GAC9C,GAAG;GACH,SAAS;IACR,GAAG,QAAQ;IACX,SAAS;IACT;GACD,CAAC,EAEc,QAAQ,KAAK,QAAQ;AACpC,OAAI,eAAe,MAClB,OAAM;AAGP,UAAO;IACN,GAAG;IACH,MAAM,KAAK,MAAM,IAAI,QAAQ;IAC7B;IACA"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\n/* -------------------------- Move type tags -------------------------- */\n\n/** A type argument: a type tag string, or a BCS type whose name is a Move type. */\nexport type TypeArgument = string | BcsType<any>;\n\nexport interface TypeTagOptions {\n\tpackage?: string;\n\ttypeArguments?: readonly TypeArgument[];\n}\n\n/**\n * `typeArguments` is required when the type's name contains unfilled\n * `phantom X` parameters (at any depth). Everything else — argument arity,\n * position contents, and tag validity — is validated at runtime.\n */\ntype TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`\n\t? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]\n\t: [options?: TypeTagOptions];\n\ntype ResolveTypeTagOptions<Name extends string> = {\n\tclient: ClientWithCoreApi;\n} & (Name extends `${string}phantom ${string}`\n\t? TypeTagOptions & { typeArguments: readonly TypeArgument[] }\n\t: TypeTagOptions);\n\nconst HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;\n\nfunction splitTopLevelTypeArgs(inner: string): string[] {\n\tconst parts: string[] = [];\n\tlet depth = 0;\n\tlet current = '';\n\tfor (const char of inner) {\n\t\tif (char === ',' && depth === 0) {\n\t\t\tparts.push(current.trim());\n\t\t\tcurrent = '';\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '<') depth++;\n\t\tif (char === '>') depth--;\n\t\tcurrent += char;\n\t}\n\tif (current) parts.push(current.trim());\n\treturn parts;\n}\n\nfunction buildTypeTag(name: string, options: TypeTagOptions | undefined): string {\n\tconst lt = name.indexOf('<');\n\tconst base = lt === -1 ? name : name.slice(0, lt);\n\n\tif (base.split('::').length !== 3) {\n\t\tthrow new Error(`${name} is not a top-level Move type`);\n\t}\n\n\tlet result = name;\n\n\tif (options?.typeArguments) {\n\t\tconst baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));\n\t\tconst supplied = options.typeArguments.map((arg) => {\n\t\t\tif (typeof arg === 'string') {\n\t\t\t\treturn arg;\n\t\t\t}\n\t\t\tif (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {\n\t\t\t\treturn arg.name;\n\t\t\t}\n\t\t\tthrow new Error(`Invalid type argument ${stringify(arg)}`);\n\t\t});\n\n\t\tif (supplied.length !== baked.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,\n\t\t\t);\n\t\t}\n\n\t\tresult = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;\n\t}\n\n\tif (HAS_PHANTOM_REGEX.test(result)) {\n\t\tthrow new Error(\n\t\t\toptions?.typeArguments\n\t\t\t\t? `A type argument contains an unfilled phantom parameter in ${result}`\n\t\t\t\t: `Missing type arguments for ${result}`,\n\t\t);\n\t}\n\n\tif (options?.package) {\n\t\tconst [, ...rest] = result.split('::');\n\t\tresult = [options.package, ...rest].join('::');\n\t}\n\n\t// fully validate address-only tags (MVR names can't be parsed as type tags)\n\tif (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {\n\t\tTypeTagSerializer.parseFromStr(result);\n\t}\n\n\treturn result;\n}\n\nasync function resolveBuiltTypeTag(\n\tname: string,\n\toptions: { client: ClientWithCoreApi } & TypeTagOptions,\n): Promise<string> {\n\tconst { client, ...rest } = options;\n\tconst { type } = await client.core.mvr.resolveType({\n\t\ttype: buildTypeTag(name, rest),\n\t});\n\treturn normalizeStructTag(type);\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\t/**\n\t * Build the type tag for this struct.\n\t *\n\t * `typeArguments` is the full positional list, in Move declaration order, and\n\t * is required when the struct has unfilled phantom parameters. The result may\n\t * contain MVR names: those are valid in transaction `typeArguments`, but for\n\t * queries or comparisons against on-chain data use `resolveTypeTag` instead.\n\t */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/**\n\t * Build the type tag for this struct, then resolve any MVR names through the\n\t * client (using its configured overrides and the MVR API) and return the\n\t * normalized, address-only form suitable for queries and comparisons against\n\t * on-chain data.\n\t */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {\n\t/** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {\n\t/** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */\n\ttypeTag(...args: TypeTagParams<Name>): string {\n\t\treturn buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);\n\t}\n\n\t/** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */\n\tasync resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {\n\t\treturn resolveBuiltTypeTag(\n\t\t\tthis.name,\n\t\t\toptions as { client: ClientWithCoreApi } & TypeTagOptions,\n\t\t);\n\t}\n}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (_key, value) =>\n\t\t\ttypeof value === 'bigint' ? value.toString() : value,\n\t\t);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":";;;;;AAaA,MAAM,sBAAsB,oBAAoB,MAAM;AACtD,MAAM,wBAAwB,oBAAoB,MAAM;AA0KxD,MAAM,oBAAoB;AAE1B,SAAS,sBAAsB,OAAyB;CACvD,MAAM,QAAkB,EAAE;CAC1B,IAAI,QAAQ;CACZ,IAAI,UAAU;AACd,MAAK,MAAM,QAAQ,OAAO;AACzB,MAAI,SAAS,OAAO,UAAU,GAAG;AAChC,SAAM,KAAK,QAAQ,MAAM,CAAC;AAC1B,aAAU;AACV;;AAED,MAAI,SAAS,IAAK;AAClB,MAAI,SAAS,IAAK;AAClB,aAAW;;AAEZ,KAAI,QAAS,OAAM,KAAK,QAAQ,MAAM,CAAC;AACvC,QAAO;;AAGR,SAAS,aAAa,MAAc,SAA6C;CAChF,MAAM,KAAK,KAAK,QAAQ,IAAI;CAC5B,MAAM,OAAO,OAAO,KAAK,OAAO,KAAK,MAAM,GAAG,GAAG;AAEjD,KAAI,KAAK,MAAM,KAAK,CAAC,WAAW,EAC/B,OAAM,IAAI,MAAM,GAAG,KAAK,+BAA+B;CAGxD,IAAI,SAAS;AAEb,KAAI,SAAS,eAAe;EAC3B,MAAM,QAAQ,OAAO,KAAK,EAAE,GAAG,sBAAsB,KAAK,MAAM,KAAK,GAAG,GAAG,CAAC;EAC5E,MAAM,WAAW,QAAQ,cAAc,KAAK,QAAQ;AACnD,OAAI,OAAO,QAAQ,SAClB,QAAO;AAER,OAAI,OAAO,OAAO,IAAI,cAAc,cAAc,OAAO,IAAI,SAAS,SACrE,QAAO,IAAI;AAEZ,SAAM,IAAI,MAAM,yBAAyB,UAAU,IAAI,GAAG;IACzD;AAEF,MAAI,SAAS,WAAW,MAAM,OAC7B,OAAM,IAAI,MACT,YAAY,MAAM,OAAO,sBAAsB,KAAK,QAAQ,SAAS,SACrE;AAGF,WAAS,SAAS,WAAW,IAAI,OAAO,GAAG,KAAK,GAAG,SAAS,KAAK,KAAK,CAAC;;AAGxE,KAAI,kBAAkB,KAAK,OAAO,CACjC,OAAM,IAAI,MACT,SAAS,gBACN,6DAA6D,WAC7D,8BAA8B,SACjC;AAGF,KAAI,SAAS,SAAS;EACrB,MAAM,GAAG,GAAG,QAAQ,OAAO,MAAM,KAAK;AACtC,WAAS,CAAC,QAAQ,SAAS,GAAG,KAAK,CAAC,KAAK,KAAK;;AAI/C,KAAI,CAAC,kBAAkB,KAAK,OAAO,IAAI,CAAC,OAAO,KAAK,OAAO,CAC1D,mBAAkB,aAAa,OAAO;AAGvC,QAAO;;AAGR,eAAe,oBACd,MACA,SACkB;CAClB,MAAM,EAAE,QAAQ,GAAG,SAAS;CAC5B,MAAM,EAAE,SAAS,MAAM,OAAO,KAAK,IAAI,YAAY,EAClD,MAAM,aAAa,MAAM,KAAK,EAC9B,CAAC;AACF,QAAO,mBAAmB,KAAK;;AAGhC,IAAa,aAAb,cAGU,UAAmB;;;;;;;;;CAS5B,QAAQ,GAAG,MAAmC;AAC7C,SAAO,aAAa,KAAK,MAAM,KAAK,GAAiC;;;;;;;;CAStE,MAAM,eAAe,SAAuD;AAC3E,SAAO,oBACN,KAAK,MACL,QACA;;CAGF,MAAM,IAAiF,EACtF,UACA,GAAG,WAKF;EACD,MAAM,CAAC,OAAO,MAAM,KAAK,QAAiB;GACzC,GAAG;GACH,WAAW,CAAC,SAAS;GACrB,CAAC;AAEF,MAAI,CAAC,IACJ,OAAM,IAAI,MAAM,0BAA0B,WAAW;AAGtD,SAAO;;CAGR,MAAM,QAAqF,EAC1F,QACA,GAAG,WAOF;AASD,UARkB,MAAM,OAAO,KAAK,WAAW;GAC9C,GAAG;GACH,SAAS;IACR,GAAG,QAAQ;IACX,SAAS;IACT;GACD,CAAC,EAEc,QAAQ,KAAK,QAAQ;AACpC,OAAI,eAAe,MAClB,OAAM;AAGP,UAAO;IACN,GAAG;IACH,MAAM,KAAK,MAAM,IAAI,QAAQ;IAC7B;IACA;;;AAwCJ,SAAS,UAAU,KAAc;AAChC,KAAI,OAAO,QAAQ,SAClB,QAAO,KAAK,UAAU,MAAM,MAAM,UACjC,OAAO,UAAU,WAAW,MAAM,UAAU,GAAG,MAC/C;AAEF,KAAI,OAAO,QAAQ,SAClB,QAAO,IAAI,UAAU;AAGtB,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InterestConfigParams, MarginPoolConfigParams } from "../types/index.mjs";
|
|
2
2
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_transactions46 from "@mysten/sui/transactions";
|
|
4
4
|
import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
5
5
|
|
|
6
6
|
//#region src/transactions/marginMaintainer.d.ts
|
|
@@ -27,27 +27,27 @@ declare class MarginMaintainerContract {
|
|
|
27
27
|
* @param {InterestConfigParams} interestConfig The configuration for the interest
|
|
28
28
|
* @returns A function that takes a Transaction object
|
|
29
29
|
*/
|
|
30
|
-
newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) =>
|
|
30
|
+
newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
|
|
31
31
|
/**
|
|
32
32
|
* @description Create a new margin pool config
|
|
33
33
|
* @param {string} coinKey The key to identify the coin
|
|
34
34
|
* @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
|
|
35
35
|
* @returns A function that takes a Transaction object
|
|
36
36
|
*/
|
|
37
|
-
newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) =>
|
|
37
|
+
newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
|
|
38
38
|
/**
|
|
39
39
|
* @description Create a new margin pool config with rate limit
|
|
40
40
|
* @param {string} coinKey The key to identify the coin
|
|
41
41
|
* @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
|
|
42
42
|
* @returns A function that takes a Transaction object
|
|
43
43
|
*/
|
|
44
|
-
newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) =>
|
|
44
|
+
newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
|
|
45
45
|
/**
|
|
46
46
|
* @description Create a new interest config
|
|
47
47
|
* @param {InterestConfigParams} interestConfig The configuration for the interest
|
|
48
48
|
* @returns A function that takes a Transaction object
|
|
49
49
|
*/
|
|
50
|
-
newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) =>
|
|
50
|
+
newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
|
|
51
51
|
/**
|
|
52
52
|
* @description Enable a deepbook pool for loan
|
|
53
53
|
* @param {string} deepbookPoolKey The key to identify the deepbook pool
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DepositDuringInitParams, DepositParams } from "../types/index.mjs";
|
|
2
2
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_transactions50 from "@mysten/sui/transactions";
|
|
4
4
|
import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
5
5
|
|
|
6
6
|
//#region src/transactions/marginManager.d.ts
|
|
@@ -88,49 +88,49 @@ declare class MarginManagerContract {
|
|
|
88
88
|
* @param {number} amount The amount to withdraw
|
|
89
89
|
* @returns A function that takes a Transaction object
|
|
90
90
|
*/
|
|
91
|
-
withdrawBase: (managerKey: string, amount: number) => (tx: Transaction) =>
|
|
91
|
+
withdrawBase: (managerKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
92
92
|
/**
|
|
93
93
|
* @description Withdraw quote from a margin manager
|
|
94
94
|
* @param {string} managerKey The key to identify the manager
|
|
95
95
|
* @param {number} amount The amount to withdraw
|
|
96
96
|
* @returns A function that takes a Transaction object
|
|
97
97
|
*/
|
|
98
|
-
withdrawQuote: (managerKey: string, amount: number) => (tx: Transaction) =>
|
|
98
|
+
withdrawQuote: (managerKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
99
99
|
/**
|
|
100
100
|
* @description Withdraw deep from a margin manager
|
|
101
101
|
* @param {string} managerKey The key to identify the manager
|
|
102
102
|
* @param {number} amount The amount to withdraw
|
|
103
103
|
* @returns A function that takes a Transaction object
|
|
104
104
|
*/
|
|
105
|
-
withdrawDeep: (managerKey: string, amount: number) => (tx: Transaction) =>
|
|
105
|
+
withdrawDeep: (managerKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
106
106
|
/**
|
|
107
107
|
* @description Borrow base from a margin manager
|
|
108
108
|
* @param {string} managerKey The key to identify the manager
|
|
109
109
|
* @param {number} amount The amount to borrow
|
|
110
110
|
* @returns A function that takes a Transaction object
|
|
111
111
|
*/
|
|
112
|
-
borrowBase: (managerKey: string, amount: number) => (tx: Transaction) =>
|
|
112
|
+
borrowBase: (managerKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
113
113
|
/**
|
|
114
114
|
* @description Borrow quote from a margin manager
|
|
115
115
|
* @param {string} managerKey The key to identify the manager
|
|
116
116
|
* @param {number} amount The amount to borrow
|
|
117
117
|
* @returns A function that takes a Transaction object
|
|
118
118
|
*/
|
|
119
|
-
borrowQuote: (managerKey: string, amount: number) => (tx: Transaction) =>
|
|
119
|
+
borrowQuote: (managerKey: string, amount: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
120
120
|
/**
|
|
121
121
|
* @description Repay base from a margin manager
|
|
122
122
|
* @param {string} managerKey The key to identify the manager
|
|
123
123
|
* @param {number} amount The amount to repay
|
|
124
124
|
* @returns A function that takes a Transaction object
|
|
125
125
|
*/
|
|
126
|
-
repayBase: (managerKey: string, amount?: number) => (tx: Transaction) =>
|
|
126
|
+
repayBase: (managerKey: string, amount?: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
127
127
|
/**
|
|
128
128
|
* @description Repay quote from a margin manager
|
|
129
129
|
* @param {string} managerKey The key to identify the manager
|
|
130
130
|
* @param {number} amount The amount to repay
|
|
131
131
|
* @returns A function that takes a Transaction object
|
|
132
132
|
*/
|
|
133
|
-
repayQuote: (managerKey: string, amount?: number) => (tx: Transaction) =>
|
|
133
|
+
repayQuote: (managerKey: string, amount?: number) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
134
134
|
/**
|
|
135
135
|
* @description Liquidate a margin manager
|
|
136
136
|
* @param {string} managerAddress The address of the manager to liquidate
|
|
@@ -139,7 +139,7 @@ declare class MarginManagerContract {
|
|
|
139
139
|
* @param {TransactionArgument} repayCoin The coin to repay
|
|
140
140
|
* @returns A function that takes a Transaction object
|
|
141
141
|
*/
|
|
142
|
-
liquidate: (managerAddress: string, poolKey: string, debtIsBase: boolean, repayCoin: TransactionArgument) => (tx: Transaction) =>
|
|
142
|
+
liquidate: (managerAddress: string, poolKey: string, debtIsBase: boolean, repayCoin: TransactionArgument) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
143
143
|
/**
|
|
144
144
|
* @description Set the referral for a margin manager (DeepBookPoolReferral)
|
|
145
145
|
* @param {string} managerKey The key to identify the margin manager
|
|
@@ -160,63 +160,63 @@ declare class MarginManagerContract {
|
|
|
160
160
|
* @param {string} marginManagerId The ID of the margin manager
|
|
161
161
|
* @returns A function that takes a Transaction object
|
|
162
162
|
*/
|
|
163
|
-
ownerByPoolKey: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
163
|
+
ownerByPoolKey: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
164
164
|
/**
|
|
165
165
|
* @description Get the DeepBook pool ID associated with a margin manager
|
|
166
166
|
* @param {string} poolKey The key to identify the pool
|
|
167
167
|
* @param {string} marginManagerId The ID of the margin manager
|
|
168
168
|
* @returns A function that takes a Transaction object
|
|
169
169
|
*/
|
|
170
|
-
deepbookPool: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
170
|
+
deepbookPool: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
171
171
|
/**
|
|
172
172
|
* @description Get the margin pool ID (if any) associated with a margin manager
|
|
173
173
|
* @param {string} poolKey The key to identify the pool
|
|
174
174
|
* @param {string} marginManagerId The ID of the margin manager
|
|
175
175
|
* @returns A function that takes a Transaction object
|
|
176
176
|
*/
|
|
177
|
-
marginPoolId: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
177
|
+
marginPoolId: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
178
178
|
/**
|
|
179
179
|
* @description Get borrowed shares for both base and quote assets
|
|
180
180
|
* @param {string} poolKey The key to identify the pool
|
|
181
181
|
* @param {string} marginManagerId The ID of the margin manager
|
|
182
182
|
* @returns A function that takes a Transaction object
|
|
183
183
|
*/
|
|
184
|
-
borrowedShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
184
|
+
borrowedShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
185
185
|
/**
|
|
186
186
|
* @description Get borrowed base shares
|
|
187
187
|
* @param {string} poolKey The key to identify the pool
|
|
188
188
|
* @param {string} marginManagerId The ID of the margin manager
|
|
189
189
|
* @returns A function that takes a Transaction object
|
|
190
190
|
*/
|
|
191
|
-
borrowedBaseShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
191
|
+
borrowedBaseShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
192
192
|
/**
|
|
193
193
|
* @description Get borrowed quote shares
|
|
194
194
|
* @param {string} poolKey The key to identify the pool
|
|
195
195
|
* @param {string} marginManagerId The ID of the margin manager
|
|
196
196
|
* @returns A function that takes a Transaction object
|
|
197
197
|
*/
|
|
198
|
-
borrowedQuoteShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
198
|
+
borrowedQuoteShares: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
199
199
|
/**
|
|
200
200
|
* @description Check if margin manager has base asset debt
|
|
201
201
|
* @param {string} poolKey The key to identify the pool
|
|
202
202
|
* @param {string} marginManagerId The ID of the margin manager
|
|
203
203
|
* @returns A function that takes a Transaction object
|
|
204
204
|
*/
|
|
205
|
-
hasBaseDebt: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
205
|
+
hasBaseDebt: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
206
206
|
/**
|
|
207
207
|
* @description Get the balance manager ID for a margin manager
|
|
208
208
|
* @param {string} poolKey The key to identify the pool
|
|
209
209
|
* @param {string} marginManagerId The ID of the margin manager
|
|
210
210
|
* @returns A function that takes a Transaction object
|
|
211
211
|
*/
|
|
212
|
-
balanceManager: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
212
|
+
balanceManager: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
213
213
|
/**
|
|
214
214
|
* @description Calculate assets (base and quote) for a margin manager
|
|
215
215
|
* @param {string} poolKey The key to identify the pool
|
|
216
216
|
* @param {string} marginManagerId The ID of the margin manager
|
|
217
217
|
* @returns A function that takes a Transaction object
|
|
218
218
|
*/
|
|
219
|
-
calculateAssets: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
219
|
+
calculateAssets: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
220
220
|
/**
|
|
221
221
|
* @description Calculate debts (base and quote) for a margin manager
|
|
222
222
|
* @param {string} poolKey The key to identify the pool
|
|
@@ -224,7 +224,7 @@ declare class MarginManagerContract {
|
|
|
224
224
|
* @param {string} marginManagerId The ID of the margin manager
|
|
225
225
|
* @returns A function that takes a Transaction object
|
|
226
226
|
*/
|
|
227
|
-
calculateDebts: (poolKey: string, coinKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
227
|
+
calculateDebts: (poolKey: string, coinKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
228
228
|
/**
|
|
229
229
|
* @description Get comprehensive state information for a margin manager
|
|
230
230
|
* @param {string} poolKey The key to identify the pool
|
|
@@ -234,28 +234,28 @@ declare class MarginManagerContract {
|
|
|
234
234
|
* base_debt, quote_debt, base_pyth_price, base_pyth_decimals,
|
|
235
235
|
* quote_pyth_price, quote_pyth_decimals)
|
|
236
236
|
*/
|
|
237
|
-
managerState: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
237
|
+
managerState: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
238
238
|
/**
|
|
239
239
|
* @description Get the base asset balance of a margin manager
|
|
240
240
|
* @param {string} poolKey The key to identify the pool
|
|
241
241
|
* @param {string} marginManagerId The ID of the margin manager
|
|
242
242
|
* @returns A function that takes a Transaction object
|
|
243
243
|
*/
|
|
244
|
-
baseBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
244
|
+
baseBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
245
245
|
/**
|
|
246
246
|
* @description Get the quote asset balance of a margin manager
|
|
247
247
|
* @param {string} poolKey The key to identify the pool
|
|
248
248
|
* @param {string} marginManagerId The ID of the margin manager
|
|
249
249
|
* @returns A function that takes a Transaction object
|
|
250
250
|
*/
|
|
251
|
-
quoteBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
251
|
+
quoteBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
252
252
|
/**
|
|
253
253
|
* @description Get the DEEP token balance of a margin manager
|
|
254
254
|
* @param {string} poolKey The key to identify the pool
|
|
255
255
|
* @param {string} marginManagerId The ID of the margin manager
|
|
256
256
|
* @returns A function that takes a Transaction object
|
|
257
257
|
*/
|
|
258
|
-
deepBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
258
|
+
deepBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
259
259
|
/**
|
|
260
260
|
* @description Get the underlying BalanceManager ID for a margin manager.
|
|
261
261
|
* Returns an ID (not a `&BalanceManager`), so it composes in PTBs unlike
|
|
@@ -264,28 +264,28 @@ declare class MarginManagerContract {
|
|
|
264
264
|
* @param {string} marginManagerId The ID of the margin manager
|
|
265
265
|
* @returns A function that takes a Transaction object
|
|
266
266
|
*/
|
|
267
|
-
balanceManagerId: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
267
|
+
balanceManagerId: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
268
268
|
/**
|
|
269
269
|
* @description Get the BalanceManager referral ID for a pool (Option<ID>).
|
|
270
270
|
* @param {string} poolKey The key to identify the pool
|
|
271
271
|
* @param {string} marginManagerId The ID of the margin manager
|
|
272
272
|
* @returns A function that takes a Transaction object
|
|
273
273
|
*/
|
|
274
|
-
getBalanceManagerReferralId: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
274
|
+
getBalanceManagerReferralId: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
275
275
|
/**
|
|
276
276
|
* @description Check if the margin manager's account exists in the pool.
|
|
277
277
|
* @param {string} poolKey The key to identify the pool
|
|
278
278
|
* @param {string} marginManagerId The ID of the margin manager
|
|
279
279
|
* @returns A function that takes a Transaction object
|
|
280
280
|
*/
|
|
281
|
-
accountExists: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
281
|
+
accountExists: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
282
282
|
/**
|
|
283
283
|
* @description Get the pool account data for the margin manager.
|
|
284
284
|
* @param {string} poolKey The key to identify the pool
|
|
285
285
|
* @param {string} marginManagerId The ID of the margin manager
|
|
286
286
|
* @returns A function that takes a Transaction object
|
|
287
287
|
*/
|
|
288
|
-
account: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
288
|
+
account: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
289
289
|
/**
|
|
290
290
|
* @description Get the open order IDs for the margin manager's account in
|
|
291
291
|
* the pool.
|
|
@@ -293,7 +293,7 @@ declare class MarginManagerContract {
|
|
|
293
293
|
* @param {string} marginManagerId The ID of the margin manager
|
|
294
294
|
* @returns A function that takes a Transaction object
|
|
295
295
|
*/
|
|
296
|
-
accountOpenOrders: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
296
|
+
accountOpenOrders: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
297
297
|
/**
|
|
298
298
|
* @description Get full order details for the margin manager's account in
|
|
299
299
|
* the pool.
|
|
@@ -301,7 +301,7 @@ declare class MarginManagerContract {
|
|
|
301
301
|
* @param {string} marginManagerId The ID of the margin manager
|
|
302
302
|
* @returns A function that takes a Transaction object
|
|
303
303
|
*/
|
|
304
|
-
getAccountOrderDetails: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
304
|
+
getAccountOrderDetails: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
305
305
|
/**
|
|
306
306
|
* @description Get locked balances (base, quote, deep) for the margin
|
|
307
307
|
* manager's account in the pool.
|
|
@@ -309,7 +309,7 @@ declare class MarginManagerContract {
|
|
|
309
309
|
* @param {string} marginManagerId The ID of the margin manager
|
|
310
310
|
* @returns A function that takes a Transaction object
|
|
311
311
|
*/
|
|
312
|
-
lockedBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
312
|
+
lockedBalance: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
313
313
|
/**
|
|
314
314
|
* @description Check whether a limit order can be placed given the
|
|
315
315
|
* manager's current state.
|
|
@@ -322,7 +322,7 @@ declare class MarginManagerContract {
|
|
|
322
322
|
* @param {number | bigint} expireTimestamp Order expiration timestamp (ms)
|
|
323
323
|
* @returns A function that takes a Transaction object
|
|
324
324
|
*/
|
|
325
|
-
canPlaceLimitOrder: (poolKey: string, marginManagerId: string, price: number | bigint, quantity: number | bigint, isBid: boolean, payWithDeep: boolean, expireTimestamp: number | bigint) => (tx: Transaction) =>
|
|
325
|
+
canPlaceLimitOrder: (poolKey: string, marginManagerId: string, price: number | bigint, quantity: number | bigint, isBid: boolean, payWithDeep: boolean, expireTimestamp: number | bigint) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
326
326
|
/**
|
|
327
327
|
* @description Check whether a market order can be placed given the
|
|
328
328
|
* manager's current state.
|
|
@@ -333,7 +333,7 @@ declare class MarginManagerContract {
|
|
|
333
333
|
* @param {boolean} payWithDeep Whether to pay fees in DEEP
|
|
334
334
|
* @returns A function that takes a Transaction object
|
|
335
335
|
*/
|
|
336
|
-
canPlaceMarketOrder: (poolKey: string, marginManagerId: string, quantity: number | bigint, isBid: boolean, payWithDeep: boolean) => (tx: Transaction) =>
|
|
336
|
+
canPlaceMarketOrder: (poolKey: string, marginManagerId: string, quantity: number | bigint, isBid: boolean, payWithDeep: boolean) => (tx: Transaction) => _mysten_sui_transactions50.TransactionResult;
|
|
337
337
|
}
|
|
338
338
|
//#endregion
|
|
339
339
|
export { MarginManagerContract };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _mysten_sui_transactions81 from "@mysten/sui/transactions";
|
|
3
3
|
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
4
4
|
|
|
5
5
|
//#region src/transactions/marginPool.d.ts
|
|
@@ -16,7 +16,7 @@ declare class MarginPoolContract {
|
|
|
16
16
|
* @description Mint a supplier cap for margin pool
|
|
17
17
|
* @returns A function that takes a Transaction object
|
|
18
18
|
*/
|
|
19
|
-
mintSupplierCap: () => (tx: Transaction) =>
|
|
19
|
+
mintSupplierCap: () => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
20
20
|
/**
|
|
21
21
|
* @description Supply to a margin pool
|
|
22
22
|
* @param {string} coinKey The key to identify the pool
|
|
@@ -33,7 +33,7 @@ declare class MarginPoolContract {
|
|
|
33
33
|
* @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.
|
|
34
34
|
* @returns A function that takes a Transaction object
|
|
35
35
|
*/
|
|
36
|
-
withdrawFromMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) => (tx: Transaction) =>
|
|
36
|
+
withdrawFromMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
37
37
|
/**
|
|
38
38
|
* @description Mint a referral for a margin pool
|
|
39
39
|
* @param {string} coinKey The key to identify the pool
|
|
@@ -46,94 +46,94 @@ declare class MarginPoolContract {
|
|
|
46
46
|
* @param {string} referralId The ID of the referral
|
|
47
47
|
* @returns A function that takes a Transaction object
|
|
48
48
|
*/
|
|
49
|
-
withdrawReferralFees: (coinKey: string, referralId: string) => (tx: Transaction) =>
|
|
49
|
+
withdrawReferralFees: (coinKey: string, referralId: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
50
50
|
/**
|
|
51
51
|
* @description Get the margin pool ID
|
|
52
52
|
* @param {string} coinKey The key to identify the pool
|
|
53
53
|
* @returns A function that takes a Transaction object
|
|
54
54
|
*/
|
|
55
|
-
getId: (coinKey: string) => (tx: Transaction) =>
|
|
55
|
+
getId: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
56
56
|
/**
|
|
57
57
|
* @description Check if a deepbook pool is allowed for borrowing
|
|
58
58
|
* @param {string} coinKey The key to identify the margin pool
|
|
59
59
|
* @param {string} deepbookPoolId The ID of the deepbook pool
|
|
60
60
|
* @returns A function that takes a Transaction object
|
|
61
61
|
*/
|
|
62
|
-
deepbookPoolAllowed: (coinKey: string, deepbookPoolId: string) => (tx: Transaction) =>
|
|
62
|
+
deepbookPoolAllowed: (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
63
63
|
/**
|
|
64
64
|
* @description Get the total supply amount
|
|
65
65
|
* @param {string} coinKey The key to identify the pool
|
|
66
66
|
* @returns A function that takes a Transaction object
|
|
67
67
|
*/
|
|
68
|
-
totalSupply: (coinKey: string) => (tx: Transaction) =>
|
|
68
|
+
totalSupply: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
69
69
|
/**
|
|
70
70
|
* @description Get the total supply shares
|
|
71
71
|
* @param {string} coinKey The key to identify the pool
|
|
72
72
|
* @returns A function that takes a Transaction object
|
|
73
73
|
*/
|
|
74
|
-
supplyShares: (coinKey: string) => (tx: Transaction) =>
|
|
74
|
+
supplyShares: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
75
75
|
/**
|
|
76
76
|
* @description Get the total borrow amount
|
|
77
77
|
* @param {string} coinKey The key to identify the pool
|
|
78
78
|
* @returns A function that takes a Transaction object
|
|
79
79
|
*/
|
|
80
|
-
totalBorrow: (coinKey: string) => (tx: Transaction) =>
|
|
80
|
+
totalBorrow: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
81
81
|
/**
|
|
82
82
|
* @description Get the total borrow shares
|
|
83
83
|
* @param {string} coinKey The key to identify the pool
|
|
84
84
|
* @returns A function that takes a Transaction object
|
|
85
85
|
*/
|
|
86
|
-
borrowShares: (coinKey: string) => (tx: Transaction) =>
|
|
86
|
+
borrowShares: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
87
87
|
/**
|
|
88
88
|
* @description Get the last update timestamp
|
|
89
89
|
* @param {string} coinKey The key to identify the pool
|
|
90
90
|
* @returns A function that takes a Transaction object
|
|
91
91
|
*/
|
|
92
|
-
lastUpdateTimestamp: (coinKey: string) => (tx: Transaction) =>
|
|
92
|
+
lastUpdateTimestamp: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
93
93
|
/**
|
|
94
94
|
* @description Get the supply cap
|
|
95
95
|
* @param {string} coinKey The key to identify the pool
|
|
96
96
|
* @returns A function that takes a Transaction object
|
|
97
97
|
*/
|
|
98
|
-
supplyCap: (coinKey: string) => (tx: Transaction) =>
|
|
98
|
+
supplyCap: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
99
99
|
/**
|
|
100
100
|
* @description Get the max utilization rate
|
|
101
101
|
* @param {string} coinKey The key to identify the pool
|
|
102
102
|
* @returns A function that takes a Transaction object
|
|
103
103
|
*/
|
|
104
|
-
maxUtilizationRate: (coinKey: string) => (tx: Transaction) =>
|
|
104
|
+
maxUtilizationRate: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
105
105
|
/**
|
|
106
106
|
* @description Get the protocol spread
|
|
107
107
|
* @param {string} coinKey The key to identify the pool
|
|
108
108
|
* @returns A function that takes a Transaction object
|
|
109
109
|
*/
|
|
110
|
-
protocolSpread: (coinKey: string) => (tx: Transaction) =>
|
|
110
|
+
protocolSpread: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
111
111
|
/**
|
|
112
112
|
* @description Get the minimum borrow amount
|
|
113
113
|
* @param {string} coinKey The key to identify the pool
|
|
114
114
|
* @returns A function that takes a Transaction object
|
|
115
115
|
*/
|
|
116
|
-
minBorrow: (coinKey: string) => (tx: Transaction) =>
|
|
116
|
+
minBorrow: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
117
117
|
/**
|
|
118
118
|
* @description Get the current interest rate
|
|
119
119
|
* @param {string} coinKey The key to identify the pool
|
|
120
120
|
* @returns A function that takes a Transaction object
|
|
121
121
|
*/
|
|
122
|
-
interestRate: (coinKey: string) => (tx: Transaction) =>
|
|
122
|
+
interestRate: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
123
123
|
/**
|
|
124
124
|
* @description Get user supply shares for a supplier cap
|
|
125
125
|
* @param {string} coinKey The key to identify the pool
|
|
126
126
|
* @param {string} supplierCapId The ID of the supplier cap
|
|
127
127
|
* @returns A function that takes a Transaction object
|
|
128
128
|
*/
|
|
129
|
-
userSupplyShares: (coinKey: string, supplierCapId: string) => (tx: Transaction) =>
|
|
129
|
+
userSupplyShares: (coinKey: string, supplierCapId: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
130
130
|
/**
|
|
131
131
|
* @description Get user supply amount for a supplier cap
|
|
132
132
|
* @param {string} coinKey The key to identify the pool
|
|
133
133
|
* @param {string} supplierCapId The ID of the supplier cap
|
|
134
134
|
* @returns A function that takes a Transaction object
|
|
135
135
|
*/
|
|
136
|
-
userSupplyAmount: (coinKey: string, supplierCapId: string) => (tx: Transaction) =>
|
|
136
|
+
userSupplyAmount: (coinKey: string, supplierCapId: string) => (tx: Transaction) => _mysten_sui_transactions81.TransactionResult;
|
|
137
137
|
}
|
|
138
138
|
//#endregion
|
|
139
139
|
export { MarginPoolContract };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddConditionalOrderParams, PendingLimitOrderParams, PendingMarketOrderParams } from "../types/index.mjs";
|
|
2
2
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_transactions38 from "@mysten/sui/transactions";
|
|
4
4
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
5
|
|
|
6
6
|
//#region src/transactions/marginTPSL.d.ts
|
|
@@ -20,21 +20,21 @@ declare class MarginTPSLContract {
|
|
|
20
20
|
* @param {number} triggerPrice The price at which to trigger the order
|
|
21
21
|
* @returns A function that takes a Transaction object
|
|
22
22
|
*/
|
|
23
|
-
newCondition: (poolKey: string, triggerBelowPrice: boolean, triggerPrice: number | bigint) => (tx: Transaction) =>
|
|
23
|
+
newCondition: (poolKey: string, triggerBelowPrice: boolean, triggerPrice: number | bigint) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
24
24
|
/**
|
|
25
25
|
* @description Create a new pending limit order for use in conditional orders
|
|
26
26
|
* @param {string} poolKey The key to identify the pool
|
|
27
27
|
* @param {PendingLimitOrderParams} params Parameters for the pending limit order
|
|
28
28
|
* @returns A function that takes a Transaction object
|
|
29
29
|
*/
|
|
30
|
-
newPendingLimitOrder: (poolKey: string, params: PendingLimitOrderParams) => (tx: Transaction) =>
|
|
30
|
+
newPendingLimitOrder: (poolKey: string, params: PendingLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
31
31
|
/**
|
|
32
32
|
* @description Create a new pending market order for use in conditional orders
|
|
33
33
|
* @param {string} poolKey The key to identify the pool
|
|
34
34
|
* @param {PendingMarketOrderParams} params Parameters for the pending market order
|
|
35
35
|
* @returns A function that takes a Transaction object
|
|
36
36
|
*/
|
|
37
|
-
newPendingMarketOrder: (poolKey: string, params: PendingMarketOrderParams) => (tx: Transaction) =>
|
|
37
|
+
newPendingMarketOrder: (poolKey: string, params: PendingMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
38
38
|
/**
|
|
39
39
|
* @description Add a conditional order (take profit or stop loss)
|
|
40
40
|
* @param {AddConditionalOrderParams} params Parameters for adding the conditional order
|
|
@@ -65,14 +65,14 @@ declare class MarginTPSLContract {
|
|
|
65
65
|
* @param {number} maxOrdersToExecute Maximum number of orders to execute in this call
|
|
66
66
|
* @returns A function that takes a Transaction object
|
|
67
67
|
*/
|
|
68
|
-
executeConditionalOrders: (managerAddress: string, poolKey: string, maxOrdersToExecute: number) => (tx: Transaction) =>
|
|
68
|
+
executeConditionalOrders: (managerAddress: string, poolKey: string, maxOrdersToExecute: number) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
69
69
|
/**
|
|
70
70
|
* @description Get all conditional order IDs for a margin manager
|
|
71
71
|
* @param {string} poolKey The key to identify the pool
|
|
72
72
|
* @param {string} marginManagerId The ID of the margin manager
|
|
73
73
|
* @returns A function that takes a Transaction object
|
|
74
74
|
*/
|
|
75
|
-
conditionalOrderIds: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
75
|
+
conditionalOrderIds: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
76
76
|
/**
|
|
77
77
|
* @description Get a specific conditional order by ID
|
|
78
78
|
* @param {string} poolKey The key to identify the pool
|
|
@@ -80,7 +80,7 @@ declare class MarginTPSLContract {
|
|
|
80
80
|
* @param {string} conditionalOrderId The ID of the conditional order
|
|
81
81
|
* @returns A function that takes a Transaction object
|
|
82
82
|
*/
|
|
83
|
-
conditionalOrder: (poolKey: string, marginManagerId: string, conditionalOrderId: string) => (tx: Transaction) =>
|
|
83
|
+
conditionalOrder: (poolKey: string, marginManagerId: string, conditionalOrderId: string) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
84
84
|
/**
|
|
85
85
|
* @description Get the lowest trigger price for trigger_above orders
|
|
86
86
|
* Returns constants::max_u64() if there are no trigger_above orders
|
|
@@ -88,7 +88,7 @@ declare class MarginTPSLContract {
|
|
|
88
88
|
* @param {string} marginManagerId The ID of the margin manager
|
|
89
89
|
* @returns A function that takes a Transaction object
|
|
90
90
|
*/
|
|
91
|
-
lowestTriggerAbovePrice: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
91
|
+
lowestTriggerAbovePrice: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
92
92
|
/**
|
|
93
93
|
* @description Get the highest trigger price for trigger_below orders
|
|
94
94
|
* Returns 0 if there are no trigger_below orders
|
|
@@ -96,7 +96,7 @@ declare class MarginTPSLContract {
|
|
|
96
96
|
* @param {string} marginManagerId The ID of the margin manager
|
|
97
97
|
* @returns A function that takes a Transaction object
|
|
98
98
|
*/
|
|
99
|
-
highestTriggerBelowPrice: (poolKey: string, marginManagerId: string) => (tx: Transaction) =>
|
|
99
|
+
highestTriggerBelowPrice: (poolKey: string, marginManagerId: string) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
|
|
100
100
|
}
|
|
101
101
|
//#endregion
|
|
102
102
|
export { MarginTPSLContract };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarginProposalParams, PlaceMarginLimitOrderParams, PlaceMarginMarketOrderParams } from "../types/index.mjs";
|
|
2
2
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_transactions98 from "@mysten/sui/transactions";
|
|
4
4
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
5
|
|
|
6
6
|
//#region src/transactions/poolProxy.d.ts
|
|
@@ -20,7 +20,7 @@ declare class PoolProxyContract {
|
|
|
20
20
|
* @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order
|
|
21
21
|
* @returns A function that takes a Transaction object
|
|
22
22
|
*/
|
|
23
|
-
placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) =>
|
|
23
|
+
placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions98.TransactionResult;
|
|
24
24
|
/**
|
|
25
25
|
* @description Place a market order. Enforces a post-trade `risk_ratio >=
|
|
26
26
|
* min_borrow_risk_ratio` invariant on the manager (skipped when the manager
|
|
@@ -28,7 +28,7 @@ declare class PoolProxyContract {
|
|
|
28
28
|
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order
|
|
29
29
|
* @returns A function that takes a Transaction object
|
|
30
30
|
*/
|
|
31
|
-
placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) =>
|
|
31
|
+
placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions98.TransactionResult;
|
|
32
32
|
/**
|
|
33
33
|
* @description Place a reduce only limit order. Requires the manager to have
|
|
34
34
|
* debt on the relevant side; enforces a monotonic `risk_ratio_after >=
|
|
@@ -37,7 +37,7 @@ declare class PoolProxyContract {
|
|
|
37
37
|
* @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order
|
|
38
38
|
* @returns A function that takes a Transaction object
|
|
39
39
|
*/
|
|
40
|
-
placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) =>
|
|
40
|
+
placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions98.TransactionResult;
|
|
41
41
|
/**
|
|
42
42
|
* @description Place a reduce only market order. Requires the manager to
|
|
43
43
|
* have debt on the relevant side; enforces a monotonic `risk_ratio_after >=
|
|
@@ -46,7 +46,7 @@ declare class PoolProxyContract {
|
|
|
46
46
|
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order
|
|
47
47
|
* @returns A function that takes a Transaction object
|
|
48
48
|
*/
|
|
49
|
-
placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) =>
|
|
49
|
+
placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions98.TransactionResult;
|
|
50
50
|
/**
|
|
51
51
|
* @description Modify an existing order
|
|
52
52
|
* @param {string} marginManagerKey The key to identify the MarginManager
|
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.
|
|
5
|
+
"version": "1.5.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/index.mjs",
|
|
@@ -30,25 +30,25 @@
|
|
|
30
30
|
"url": "https://github.com/MystenLabs/ts-sdks/issues/new"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@noble/hashes": "^2.0
|
|
34
|
-
"axios": "^1.
|
|
33
|
+
"@noble/hashes": "^2.2.0",
|
|
34
|
+
"axios": "^1.17.0",
|
|
35
35
|
"axios-retry": "^4.5.0",
|
|
36
|
-
"@mysten/bcs": "^2.0
|
|
36
|
+
"@mysten/bcs": "^2.1.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@iarna/toml": "^2.2.5",
|
|
40
|
-
"@types/node": "^25.
|
|
41
|
-
"dotenv": "^17.2
|
|
42
|
-
"tmp": "^0.2.
|
|
40
|
+
"@types/node": "^25.9.3",
|
|
41
|
+
"dotenv": "^17.4.2",
|
|
42
|
+
"tmp": "^0.2.7",
|
|
43
43
|
"ts-node": "^10.9.2",
|
|
44
44
|
"ts-retry-promise": "^0.8.1",
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"vite": "^8.0.
|
|
47
|
-
"vitest": "^4.
|
|
48
|
-
"wait-on": "^9.0.
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
|
+
"vite": "^8.0.16",
|
|
47
|
+
"vitest": "^4.1.8",
|
|
48
|
+
"wait-on": "^9.0.10"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@mysten/sui": "^2.
|
|
51
|
+
"@mysten/sui": "^2.18.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
59
59
|
"oxlint:check": "oxlint .",
|
|
60
60
|
"oxlint:fix": "oxlint --fix",
|
|
61
|
-
"test": "vitest",
|
|
61
|
+
"test": "vitest run",
|
|
62
62
|
"lint": "pnpm run oxlint:check && pnpm run prettier:check",
|
|
63
63
|
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
|
|
64
64
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
BcsEnum,
|
|
8
8
|
BcsTuple,
|
|
9
9
|
} from '@mysten/sui/bcs';
|
|
10
|
-
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
10
|
+
import { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';
|
|
11
11
|
import { type TransactionArgument, isArgument } from '@mysten/sui/transactions';
|
|
12
12
|
import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
|
|
13
13
|
|
|
@@ -157,10 +157,143 @@ export function normalizeMoveArguments(
|
|
|
157
157
|
return normalizedArgs;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
/* -------------------------- Move type tags -------------------------- */
|
|
161
|
+
|
|
162
|
+
/** A type argument: a type tag string, or a BCS type whose name is a Move type. */
|
|
163
|
+
export type TypeArgument = string | BcsType<any>;
|
|
164
|
+
|
|
165
|
+
export interface TypeTagOptions {
|
|
166
|
+
package?: string;
|
|
167
|
+
typeArguments?: readonly TypeArgument[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* `typeArguments` is required when the type's name contains unfilled
|
|
172
|
+
* `phantom X` parameters (at any depth). Everything else — argument arity,
|
|
173
|
+
* position contents, and tag validity — is validated at runtime.
|
|
174
|
+
*/
|
|
175
|
+
type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`
|
|
176
|
+
? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]
|
|
177
|
+
: [options?: TypeTagOptions];
|
|
178
|
+
|
|
179
|
+
type ResolveTypeTagOptions<Name extends string> = {
|
|
180
|
+
client: ClientWithCoreApi;
|
|
181
|
+
} & (Name extends `${string}phantom ${string}`
|
|
182
|
+
? TypeTagOptions & { typeArguments: readonly TypeArgument[] }
|
|
183
|
+
: TypeTagOptions);
|
|
184
|
+
|
|
185
|
+
const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
|
|
186
|
+
|
|
187
|
+
function splitTopLevelTypeArgs(inner: string): string[] {
|
|
188
|
+
const parts: string[] = [];
|
|
189
|
+
let depth = 0;
|
|
190
|
+
let current = '';
|
|
191
|
+
for (const char of inner) {
|
|
192
|
+
if (char === ',' && depth === 0) {
|
|
193
|
+
parts.push(current.trim());
|
|
194
|
+
current = '';
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (char === '<') depth++;
|
|
198
|
+
if (char === '>') depth--;
|
|
199
|
+
current += char;
|
|
200
|
+
}
|
|
201
|
+
if (current) parts.push(current.trim());
|
|
202
|
+
return parts;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function buildTypeTag(name: string, options: TypeTagOptions | undefined): string {
|
|
206
|
+
const lt = name.indexOf('<');
|
|
207
|
+
const base = lt === -1 ? name : name.slice(0, lt);
|
|
208
|
+
|
|
209
|
+
if (base.split('::').length !== 3) {
|
|
210
|
+
throw new Error(`${name} is not a top-level Move type`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let result = name;
|
|
214
|
+
|
|
215
|
+
if (options?.typeArguments) {
|
|
216
|
+
const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
|
|
217
|
+
const supplied = options.typeArguments.map((arg) => {
|
|
218
|
+
if (typeof arg === 'string') {
|
|
219
|
+
return arg;
|
|
220
|
+
}
|
|
221
|
+
if (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {
|
|
222
|
+
return arg.name;
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`Invalid type argument ${stringify(arg)}`);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (supplied.length !== baked.length) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
result = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (HAS_PHANTOM_REGEX.test(result)) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
options?.typeArguments
|
|
239
|
+
? `A type argument contains an unfilled phantom parameter in ${result}`
|
|
240
|
+
: `Missing type arguments for ${result}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (options?.package) {
|
|
245
|
+
const [, ...rest] = result.split('::');
|
|
246
|
+
result = [options.package, ...rest].join('::');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// fully validate address-only tags (MVR names can't be parsed as type tags)
|
|
250
|
+
if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {
|
|
251
|
+
TypeTagSerializer.parseFromStr(result);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function resolveBuiltTypeTag(
|
|
258
|
+
name: string,
|
|
259
|
+
options: { client: ClientWithCoreApi } & TypeTagOptions,
|
|
260
|
+
): Promise<string> {
|
|
261
|
+
const { client, ...rest } = options;
|
|
262
|
+
const { type } = await client.core.mvr.resolveType({
|
|
263
|
+
type: buildTypeTag(name, rest),
|
|
264
|
+
});
|
|
265
|
+
return normalizeStructTag(type);
|
|
266
|
+
}
|
|
267
|
+
|
|
160
268
|
export class MoveStruct<
|
|
161
269
|
T extends Record<string, BcsType<any>>,
|
|
162
270
|
const Name extends string = string,
|
|
163
271
|
> extends BcsStruct<T, Name> {
|
|
272
|
+
/**
|
|
273
|
+
* Build the type tag for this struct.
|
|
274
|
+
*
|
|
275
|
+
* `typeArguments` is the full positional list, in Move declaration order, and
|
|
276
|
+
* is required when the struct has unfilled phantom parameters. The result may
|
|
277
|
+
* contain MVR names: those are valid in transaction `typeArguments`, but for
|
|
278
|
+
* queries or comparisons against on-chain data use `resolveTypeTag` instead.
|
|
279
|
+
*/
|
|
280
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
281
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Build the type tag for this struct, then resolve any MVR names through the
|
|
286
|
+
* client (using its configured overrides and the MVR API) and return the
|
|
287
|
+
* normalized, address-only form suitable for queries and comparisons against
|
|
288
|
+
* on-chain data.
|
|
289
|
+
*/
|
|
290
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
291
|
+
return resolveBuiltTypeTag(
|
|
292
|
+
this.name,
|
|
293
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
164
297
|
async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
165
298
|
objectId,
|
|
166
299
|
...options
|
|
@@ -215,16 +348,44 @@ export class MoveStruct<
|
|
|
215
348
|
export class MoveEnum<
|
|
216
349
|
T extends Record<string, BcsType<any> | null>,
|
|
217
350
|
const Name extends string,
|
|
218
|
-
> extends BcsEnum<T, Name> {
|
|
351
|
+
> extends BcsEnum<T, Name> {
|
|
352
|
+
/** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */
|
|
353
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
354
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */
|
|
358
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
359
|
+
return resolveBuiltTypeTag(
|
|
360
|
+
this.name,
|
|
361
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
219
365
|
|
|
220
366
|
export class MoveTuple<
|
|
221
367
|
const T extends readonly BcsType<any>[],
|
|
222
368
|
const Name extends string,
|
|
223
|
-
> extends BcsTuple<T, Name> {
|
|
369
|
+
> extends BcsTuple<T, Name> {
|
|
370
|
+
/** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */
|
|
371
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
372
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */
|
|
376
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
377
|
+
return resolveBuiltTypeTag(
|
|
378
|
+
this.name,
|
|
379
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
224
383
|
|
|
225
384
|
function stringify(val: unknown) {
|
|
226
385
|
if (typeof val === 'object') {
|
|
227
|
-
return JSON.stringify(val, (
|
|
386
|
+
return JSON.stringify(val, (_key, value) =>
|
|
387
|
+
typeof value === 'bigint' ? value.toString() : value,
|
|
388
|
+
);
|
|
228
389
|
}
|
|
229
390
|
if (typeof val === 'bigint') {
|
|
230
391
|
return val.toString();
|