@mysten/deepbook-v3 0.0.0-experimental-20240730220552
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/cjs/client.d.ts +177 -0
- package/dist/cjs/client.js +387 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/transactions/balanceManager.d.ts +80 -0
- package/dist/cjs/transactions/balanceManager.js +185 -0
- package/dist/cjs/transactions/balanceManager.js.map +7 -0
- package/dist/cjs/transactions/deepbook.d.ts +183 -0
- package/dist/cjs/transactions/deepbook.js +545 -0
- package/dist/cjs/transactions/deepbook.js.map +7 -0
- package/dist/cjs/transactions/deepbookAdmin.d.ts +43 -0
- package/dist/cjs/transactions/deepbookAdmin.js +159 -0
- package/dist/cjs/transactions/deepbookAdmin.js.map +7 -0
- package/dist/cjs/transactions/flashLoans.d.ts +56 -0
- package/dist/cjs/transactions/flashLoans.js +122 -0
- package/dist/cjs/transactions/flashLoans.js.map +7 -0
- package/dist/cjs/transactions/governance.d.ts +42 -0
- package/dist/cjs/transactions/governance.js +131 -0
- package/dist/cjs/transactions/governance.js.map +7 -0
- package/dist/cjs/types/index.d.ts +80 -0
- package/dist/cjs/types/index.js +38 -0
- package/dist/cjs/types/index.js.map +7 -0
- package/dist/cjs/utils/config.d.ts +38 -0
- package/dist/cjs/utils/config.js +103 -0
- package/dist/cjs/utils/config.js.map +7 -0
- package/dist/cjs/utils/constants.d.ts +22 -0
- package/dist/cjs/utils/constants.js +117 -0
- package/dist/cjs/utils/constants.js.map +7 -0
- package/dist/esm/client.d.ts +177 -0
- package/dist/esm/client.js +367 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/transactions/balanceManager.d.ts +80 -0
- package/dist/esm/transactions/balanceManager.js +165 -0
- package/dist/esm/transactions/balanceManager.js.map +7 -0
- package/dist/esm/transactions/deepbook.d.ts +183 -0
- package/dist/esm/transactions/deepbook.js +525 -0
- package/dist/esm/transactions/deepbook.js.map +7 -0
- package/dist/esm/transactions/deepbookAdmin.d.ts +43 -0
- package/dist/esm/transactions/deepbookAdmin.js +139 -0
- package/dist/esm/transactions/deepbookAdmin.js.map +7 -0
- package/dist/esm/transactions/flashLoans.d.ts +56 -0
- package/dist/esm/transactions/flashLoans.js +102 -0
- package/dist/esm/transactions/flashLoans.js.map +7 -0
- package/dist/esm/transactions/governance.d.ts +42 -0
- package/dist/esm/transactions/governance.js +111 -0
- package/dist/esm/transactions/governance.js.map +7 -0
- package/dist/esm/types/index.d.ts +80 -0
- package/dist/esm/types/index.js +18 -0
- package/dist/esm/types/index.js.map +7 -0
- package/dist/esm/utils/config.d.ts +38 -0
- package/dist/esm/utils/config.js +90 -0
- package/dist/esm/utils/config.js.map +7 -0
- package/dist/esm/utils/constants.d.ts +22 -0
- package/dist/esm/utils/constants.js +97 -0
- package/dist/esm/utils/constants.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +52 -0
- package/src/client.ts +429 -0
- package/src/index.ts +10 -0
- package/src/transactions/balanceManager.ts +182 -0
- package/src/transactions/deepbook.ts +587 -0
- package/src/transactions/deepbookAdmin.ts +140 -0
- package/src/transactions/flashLoans.ts +121 -0
- package/src/transactions/governance.ts +119 -0
- package/src/types/index.ts +98 -0
- package/src/utils/config.ts +103 -0
- package/src/utils/constants.ts +106 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _config, _DeepBookAdminContract_instances, adminCap_fn;
|
|
10
|
+
import { coinWithBalance } from "@mysten/sui/transactions";
|
|
11
|
+
import { FLOAT_SCALAR, POOL_CREATION_FEE } from "../utils/config.js";
|
|
12
|
+
class DeepBookAdminContract {
|
|
13
|
+
/**
|
|
14
|
+
* @param {DeepBookConfig} config Configuration for DeepBookAdminContract
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
__privateAdd(this, _DeepBookAdminContract_instances);
|
|
18
|
+
__privateAdd(this, _config);
|
|
19
|
+
/**
|
|
20
|
+
* @description Create a new pool as admin
|
|
21
|
+
* @param {CreatePoolAdminParams} params Parameters for creating pool as admin
|
|
22
|
+
* @returns A function that takes a Transaction object
|
|
23
|
+
*/
|
|
24
|
+
this.createPoolAdmin = (params) => (tx) => {
|
|
25
|
+
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
26
|
+
const { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, whitelisted, stablePool } = params;
|
|
27
|
+
const baseCoin = __privateGet(this, _config).getCoin(baseCoinKey);
|
|
28
|
+
const quoteCoin = __privateGet(this, _config).getCoin(quoteCoinKey);
|
|
29
|
+
const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
30
|
+
const creationFee = coinWithBalance({ type: deepCoinType, balance: POOL_CREATION_FEE });
|
|
31
|
+
const baseScalar = baseCoin.scalar;
|
|
32
|
+
const quoteScalar = quoteCoin.scalar;
|
|
33
|
+
const adjustedTickSize = tickSize * FLOAT_SCALAR * quoteScalar / baseScalar;
|
|
34
|
+
const adjustedLotSize = lotSize * baseScalar;
|
|
35
|
+
const adjustedMinSize = minSize * baseScalar;
|
|
36
|
+
tx.moveCall({
|
|
37
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::create_pool_admin`,
|
|
38
|
+
arguments: [
|
|
39
|
+
tx.object(__privateGet(this, _config).REGISTRY_ID),
|
|
40
|
+
// registry_id
|
|
41
|
+
tx.pure.u64(adjustedTickSize),
|
|
42
|
+
// adjusted tick_size
|
|
43
|
+
tx.pure.u64(adjustedLotSize),
|
|
44
|
+
// adjusted lot_size
|
|
45
|
+
tx.pure.u64(adjustedMinSize),
|
|
46
|
+
// adjusted min_size
|
|
47
|
+
creationFee,
|
|
48
|
+
// 0x2::balance::Balance<0x2::sui::SUI>
|
|
49
|
+
tx.pure.bool(whitelisted),
|
|
50
|
+
tx.pure.bool(stablePool),
|
|
51
|
+
tx.object(__privateMethod(this, _DeepBookAdminContract_instances, adminCap_fn).call(this))
|
|
52
|
+
],
|
|
53
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* @description Unregister a pool as admin
|
|
58
|
+
* @param {string} poolKey The key of the pool to be unregistered by admin
|
|
59
|
+
* @returns A function that takes a Transaction object
|
|
60
|
+
*/
|
|
61
|
+
this.unregisterPoolAdmin = (poolKey) => (tx) => {
|
|
62
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
63
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
64
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
65
|
+
tx.moveCall({
|
|
66
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::unregister_pool_admin`,
|
|
67
|
+
arguments: [tx.object(__privateGet(this, _config).REGISTRY_ID), tx.object(__privateMethod(this, _DeepBookAdminContract_instances, adminCap_fn).call(this))],
|
|
68
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* @description Update the allowed versions for a pool
|
|
73
|
+
* @param {string} poolKey The key of the pool to be updated
|
|
74
|
+
* @returns A function that takes a Transaction object
|
|
75
|
+
*/
|
|
76
|
+
this.updateAllowedVersions = (poolKey) => (tx) => {
|
|
77
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
78
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
79
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
80
|
+
tx.moveCall({
|
|
81
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::update_allowed_versions`,
|
|
82
|
+
arguments: [
|
|
83
|
+
tx.object(pool.address),
|
|
84
|
+
tx.object(__privateGet(this, _config).REGISTRY_ID),
|
|
85
|
+
tx.object(__privateMethod(this, _DeepBookAdminContract_instances, adminCap_fn).call(this))
|
|
86
|
+
],
|
|
87
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @description Enable a specific version
|
|
92
|
+
* @param {number} version The version to be enabled
|
|
93
|
+
* @returns A function that takes a Transaction object
|
|
94
|
+
*/
|
|
95
|
+
this.enableVersion = (version) => (tx) => {
|
|
96
|
+
tx.moveCall({
|
|
97
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::registry::enable_version`,
|
|
98
|
+
arguments: [
|
|
99
|
+
tx.object(__privateGet(this, _config).REGISTRY_ID),
|
|
100
|
+
tx.pure.u64(version),
|
|
101
|
+
tx.object(__privateMethod(this, _DeepBookAdminContract_instances, adminCap_fn).call(this))
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* @description Disable a specific version
|
|
107
|
+
* @param {number} version The version to be disabled
|
|
108
|
+
* @returns A function that takes a Transaction object
|
|
109
|
+
*/
|
|
110
|
+
this.disableVersion = (version) => (tx) => {
|
|
111
|
+
tx.moveCall({
|
|
112
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::registry::disable_version`,
|
|
113
|
+
arguments: [
|
|
114
|
+
tx.object(__privateGet(this, _config).REGISTRY_ID),
|
|
115
|
+
tx.pure.u64(version),
|
|
116
|
+
tx.object(__privateMethod(this, _DeepBookAdminContract_instances, adminCap_fn).call(this))
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
__privateSet(this, _config, config);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_config = new WeakMap();
|
|
124
|
+
_DeepBookAdminContract_instances = new WeakSet();
|
|
125
|
+
/**
|
|
126
|
+
* @returns The admin capability required for admin operations
|
|
127
|
+
* @throws Error if the admin capability is not set
|
|
128
|
+
*/
|
|
129
|
+
adminCap_fn = function() {
|
|
130
|
+
const adminCap = __privateGet(this, _config).adminCap;
|
|
131
|
+
if (!adminCap) {
|
|
132
|
+
throw new Error("ADMIN_CAP environment variable not set");
|
|
133
|
+
}
|
|
134
|
+
return adminCap;
|
|
135
|
+
};
|
|
136
|
+
export {
|
|
137
|
+
DeepBookAdminContract
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=deepbookAdmin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/transactions/deepbookAdmin.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { CreatePoolAdminParams } from '../types/index.js';\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { FLOAT_SCALAR, POOL_CREATION_FEE } from '../utils/config.js';\n\n/**\n * DeepBookAdminContract class for managing admin actions.\n */\nexport class DeepBookAdminContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for DeepBookAdminContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#adminCap() {\n\t\tconst adminCap = this.#config.adminCap;\n\t\tif (!adminCap) {\n\t\t\tthrow new Error('ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn adminCap;\n\t}\n\n\t/**\n\t * @description Create a new pool as admin\n\t * @param {CreatePoolAdminParams} params Parameters for creating pool as admin\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreatePoolAdmin = (params: CreatePoolAdminParams) => (tx: Transaction) => {\n\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\tconst { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, whitelisted, stablePool } =\n\t\t\tparams;\n\t\tconst baseCoin = this.#config.getCoin(baseCoinKey);\n\t\tconst quoteCoin = this.#config.getCoin(quoteCoinKey);\n\t\tconst deepCoinType = this.#config.getCoin('DEEP').type;\n\n\t\tconst creationFee = coinWithBalance({ type: deepCoinType, balance: POOL_CREATION_FEE });\n\t\tconst baseScalar = baseCoin.scalar;\n\t\tconst quoteScalar = quoteCoin.scalar;\n\n\t\tconst adjustedTickSize = (tickSize * FLOAT_SCALAR * quoteScalar) / baseScalar;\n\t\tconst adjustedLotSize = lotSize * baseScalar;\n\t\tconst adjustedMinSize = minSize * baseScalar;\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::create_pool_admin`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.REGISTRY_ID), // registry_id\n\t\t\t\ttx.pure.u64(adjustedTickSize), // adjusted tick_size\n\t\t\t\ttx.pure.u64(adjustedLotSize), // adjusted lot_size\n\t\t\t\ttx.pure.u64(adjustedMinSize), // adjusted min_size\n\t\t\t\tcreationFee, // 0x2::balance::Balance<0x2::sui::SUI>\n\t\t\t\ttx.pure.bool(whitelisted),\n\t\t\t\ttx.pure.bool(stablePool),\n\t\t\t\ttx.object(this.#adminCap()),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Unregister a pool as admin\n\t * @param {string} poolKey The key of the pool to be unregistered by admin\n\t * @returns A function that takes a Transaction object\n\t */\n\tunregisterPoolAdmin = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unregister_pool_admin`,\n\t\t\targuments: [tx.object(this.#config.REGISTRY_ID), tx.object(this.#adminCap())],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Update the allowed versions for a pool\n\t * @param {string} poolKey The key of the pool to be updated\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateAllowedVersions = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::update_allowed_versions`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(this.#config.REGISTRY_ID),\n\t\t\t\ttx.object(this.#adminCap()),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a specific version\n\t * @param {number} version The version to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::enable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#adminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a specific version\n\t * @param {number} version The version to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::registry::disable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#adminCap()),\n\t\t\t],\n\t\t});\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;AAGA,SAAS,uBAAuB;AAKhC,SAAS,cAAc,yBAAyB;AAKzC,MAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAMlC,YAAY,QAAwB;AAN9B;AACN;AA0BA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkB,CAAC,WAAkC,CAAC,OAAoB;AACzE,SAAG,kBAAkB,mBAAK,SAAQ,OAAO;AACzC,YAAM,EAAE,aAAa,cAAc,UAAU,SAAS,SAAS,aAAa,WAAW,IACtF;AACD,YAAM,WAAW,mBAAK,SAAQ,QAAQ,WAAW;AACjD,YAAM,YAAY,mBAAK,SAAQ,QAAQ,YAAY;AACnD,YAAM,eAAe,mBAAK,SAAQ,QAAQ,MAAM,EAAE;AAElD,YAAM,cAAc,gBAAgB,EAAE,MAAM,cAAc,SAAS,kBAAkB,CAAC;AACtF,YAAM,aAAa,SAAS;AAC5B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": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* FlashLoanContract class for managing flash loans.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FlashLoanContract {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param {DeepBookConfig} config Configuration object for DeepBook
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: DeepBookConfig);
|
|
12
|
+
/**
|
|
13
|
+
* @description Borrow base asset from the pool
|
|
14
|
+
* @param {string} poolKey The key to identify the pool
|
|
15
|
+
* @param {number} borrowAmount The amount to borrow
|
|
16
|
+
* @returns A function that takes a Transaction object
|
|
17
|
+
*/
|
|
18
|
+
borrowBaseAsset: (poolKey: string, borrowAmount: number) => (tx: Transaction) => readonly [{
|
|
19
|
+
$kind: "NestedResult";
|
|
20
|
+
NestedResult: [number, number];
|
|
21
|
+
}, {
|
|
22
|
+
$kind: "NestedResult";
|
|
23
|
+
NestedResult: [number, number];
|
|
24
|
+
}];
|
|
25
|
+
/**
|
|
26
|
+
* @description Return base asset to the pool after a flash loan.
|
|
27
|
+
* @param {string} poolKey The key to identify the pool
|
|
28
|
+
* @param {number} borrowAmount The amount of the base asset to return
|
|
29
|
+
* @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned
|
|
30
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
31
|
+
* @returns A function that takes a Transaction object
|
|
32
|
+
*/
|
|
33
|
+
returnBaseAsset: (poolKey: string, borrowAmount: number, baseCoinInput: TransactionObjectArgument, flashLoan: TransactionObjectArgument) => (tx: Transaction) => TransactionObjectArgument;
|
|
34
|
+
/**
|
|
35
|
+
* @description Borrow quote asset from the pool
|
|
36
|
+
* @param {string} poolKey The key to identify the pool
|
|
37
|
+
* @param {number} borrowAmount The amount to borrow
|
|
38
|
+
* @returns A function that takes a Transaction object
|
|
39
|
+
*/
|
|
40
|
+
borrowQuoteAsset: (poolKey: string, borrowAmount: number) => (tx: Transaction) => readonly [{
|
|
41
|
+
$kind: "NestedResult";
|
|
42
|
+
NestedResult: [number, number];
|
|
43
|
+
}, {
|
|
44
|
+
$kind: "NestedResult";
|
|
45
|
+
NestedResult: [number, number];
|
|
46
|
+
}];
|
|
47
|
+
/**
|
|
48
|
+
* @description Return quote asset to the pool after a flash loan.
|
|
49
|
+
* @param {string} poolKey The key to identify the pool
|
|
50
|
+
* @param {number} borrowAmount The amount of the quote asset to return
|
|
51
|
+
* @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned
|
|
52
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
53
|
+
* @returns A function that takes a Transaction object
|
|
54
|
+
*/
|
|
55
|
+
returnQuoteAsset: (poolKey: string, borrowAmount: number, quoteCoinInput: TransactionObjectArgument, flashLoan: TransactionObjectArgument) => (tx: Transaction) => TransactionObjectArgument;
|
|
56
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _config;
|
|
9
|
+
class FlashLoanContract {
|
|
10
|
+
/**
|
|
11
|
+
* @param {DeepBookConfig} config Configuration object for DeepBook
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
__privateAdd(this, _config);
|
|
15
|
+
/**
|
|
16
|
+
* @description Borrow base asset from the pool
|
|
17
|
+
* @param {string} poolKey The key to identify the pool
|
|
18
|
+
* @param {number} borrowAmount The amount to borrow
|
|
19
|
+
* @returns A function that takes a Transaction object
|
|
20
|
+
*/
|
|
21
|
+
this.borrowBaseAsset = (poolKey, borrowAmount) => (tx) => {
|
|
22
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
23
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
24
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
25
|
+
const [baseCoinResult, flashLoan] = tx.moveCall({
|
|
26
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,
|
|
27
|
+
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * baseCoin.scalar)],
|
|
28
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
29
|
+
});
|
|
30
|
+
return [baseCoinResult, flashLoan];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @description Return base asset to the pool after a flash loan.
|
|
34
|
+
* @param {string} poolKey The key to identify the pool
|
|
35
|
+
* @param {number} borrowAmount The amount of the base asset to return
|
|
36
|
+
* @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned
|
|
37
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
38
|
+
* @returns A function that takes a Transaction object
|
|
39
|
+
*/
|
|
40
|
+
this.returnBaseAsset = (poolKey, borrowAmount, baseCoinInput, flashLoan) => (tx) => {
|
|
41
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
42
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
43
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
44
|
+
const borrowScalar = baseCoin.scalar;
|
|
45
|
+
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [
|
|
46
|
+
tx.pure.u64(borrowAmount * borrowScalar)
|
|
47
|
+
]);
|
|
48
|
+
tx.moveCall({
|
|
49
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,
|
|
50
|
+
arguments: [tx.object(pool.address), baseCoinReturn, flashLoan],
|
|
51
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
52
|
+
});
|
|
53
|
+
return baseCoinInput;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* @description Borrow quote asset from the pool
|
|
57
|
+
* @param {string} poolKey The key to identify the pool
|
|
58
|
+
* @param {number} borrowAmount The amount to borrow
|
|
59
|
+
* @returns A function that takes a Transaction object
|
|
60
|
+
*/
|
|
61
|
+
this.borrowQuoteAsset = (poolKey, borrowAmount) => (tx) => {
|
|
62
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
63
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
64
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
65
|
+
const [quoteCoinResult, flashLoan] = tx.moveCall({
|
|
66
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,
|
|
67
|
+
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * quoteCoin.scalar)],
|
|
68
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
69
|
+
});
|
|
70
|
+
return [quoteCoinResult, flashLoan];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* @description Return quote asset to the pool after a flash loan.
|
|
74
|
+
* @param {string} poolKey The key to identify the pool
|
|
75
|
+
* @param {number} borrowAmount The amount of the quote asset to return
|
|
76
|
+
* @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned
|
|
77
|
+
* @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled
|
|
78
|
+
* @returns A function that takes a Transaction object
|
|
79
|
+
*/
|
|
80
|
+
this.returnQuoteAsset = (poolKey, borrowAmount, quoteCoinInput, flashLoan) => (tx) => {
|
|
81
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
82
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
83
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
84
|
+
const borrowScalar = quoteCoin.scalar;
|
|
85
|
+
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [
|
|
86
|
+
tx.pure.u64(borrowAmount * borrowScalar)
|
|
87
|
+
]);
|
|
88
|
+
tx.moveCall({
|
|
89
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,
|
|
90
|
+
arguments: [tx.object(pool.address), quoteCoinReturn, flashLoan],
|
|
91
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
92
|
+
});
|
|
93
|
+
return quoteCoinInput;
|
|
94
|
+
};
|
|
95
|
+
__privateSet(this, _config, config);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
_config = new WeakMap();
|
|
99
|
+
export {
|
|
100
|
+
FlashLoanContract
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=flashLoans.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/transactions/flashLoans.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * FlashLoanContract class for managing flash loans.\n */\nexport class FlashLoanContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration object for DeepBook\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Borrow base asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowBaseAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst [baseCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(borrowAmount * baseCoin.scalar)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [baseCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return base asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the base asset to return\n\t * @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnBaseAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tbaseCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst borrowScalar = baseCoin.scalar;\n\n\t\t\tconst [baseCoinReturn] = tx.splitCoins(baseCoinInput, [\n\t\t\t\ttx.pure.u64(borrowAmount * borrowScalar),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,\n\t\t\t\targuments: [tx.object(pool.address), baseCoinReturn, flashLoan],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\n\t\t\treturn baseCoinInput;\n\t\t};\n\n\t/**\n\t * @description Borrow quote asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowQuoteAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst [quoteCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(borrowAmount * quoteCoin.scalar)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [quoteCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return quote asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the quote asset to return\n\t * @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnQuoteAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tquoteCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst borrowScalar = quoteCoin.scalar;\n\n\t\t\tconst [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [\n\t\t\t\ttx.pure.u64(borrowAmount * borrowScalar),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,\n\t\t\t\targuments: [tx.object(pool.address), quoteCoinReturn, flashLoan],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\n\t\t\treturn quoteCoinInput;\n\t\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AASO,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAM9B,YAAY,QAAwB;AALpC;AAeA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkB,CAAC,SAAiB,iBAAyB,CAAC,OAAoB;AACjF,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,WAAW,mBAAK,SAAQ,QAAQ,KAAK,QAAQ;AACnD,YAAM,YAAY,mBAAK,SAAQ,QAAQ,KAAK,SAAS;AACrD,YAAM,CAAC,gBAAgB,SAAS,IAAI,GAAG,SAAS;AAAA,QAC/C,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,QAC3C,WAAW,CAAC,GAAG,OAAO,KAAK,OAAO,GAAG,GAAG,KAAK,IAAI,eAAe,SAAS,MAAM,CAAC;AAAA,QAChF,eAAe,CAAC,SAAS,MAAM,UAAU,IAAI;AAAA,MAC9C,CAAC;AACD,aAAO,CAAC,gBAAgB,SAAS;AAAA,IAClC;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BACC,CACC,SACA,cACA,eACA,cAED,CAAC,OAAoB;AACpB,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,WAAW,mBAAK,SAAQ,QAAQ,KAAK,QAAQ;AACnD,YAAM,YAAY,mBAAK,SAAQ,QAAQ,KAAK,S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AA,QACvD,GAAG,KAAK,IAAI,eAAe,YAAY;AAAA,MACxC,CAAC;AACD,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,QAC3C,WAAW,CAAC,GAAG,OAAO,KAAK,OAAO,GAAG,iBAAiB,SAAS;AAAA,QAC/D,eAAe,CAAC,SAAS,MAAM,UAAU,IAAI;AAAA,MAC9C,CAAC;AAED,aAAO;AAAA,IACR;AAvGA,uBAAK,SAAU;AAAA,EAChB;AAuGD;AA9GC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import type { ProposalParams } from '../types/index.js';
|
|
3
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
4
|
+
/**
|
|
5
|
+
* GovernanceContract class for managing governance operations in DeepBook.
|
|
6
|
+
*/
|
|
7
|
+
export declare class GovernanceContract {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* @param {DeepBookConfig} config Configuration for GovernanceContract
|
|
11
|
+
*/
|
|
12
|
+
constructor(config: DeepBookConfig);
|
|
13
|
+
/**
|
|
14
|
+
* @description Stake a specified amount in the pool
|
|
15
|
+
* @param {string} poolKey The key to identify the pool
|
|
16
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
17
|
+
* @param {number} stakeAmount The amount to stake
|
|
18
|
+
* @returns A function that takes a Transaction object
|
|
19
|
+
*/
|
|
20
|
+
stake: (poolKey: string, balanceManagerKey: string, stakeAmount: number) => (tx: Transaction) => void;
|
|
21
|
+
/**
|
|
22
|
+
* @description Unstake from the pool
|
|
23
|
+
* @param {string} poolKey The key to identify the pool
|
|
24
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
25
|
+
* @returns A function that takes a Transaction object
|
|
26
|
+
*/
|
|
27
|
+
unstake: (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => void;
|
|
28
|
+
/**
|
|
29
|
+
* @description Submit a governance proposal
|
|
30
|
+
* @param {ProposalParams} params Parameters for the proposal
|
|
31
|
+
* @returns A function that takes a Transaction object
|
|
32
|
+
*/
|
|
33
|
+
submitProposal: (params: ProposalParams) => (tx: Transaction) => void;
|
|
34
|
+
/**
|
|
35
|
+
* @description Vote on a proposal
|
|
36
|
+
* @param {string} poolKey The key to identify the pool
|
|
37
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
38
|
+
* @param {string} proposal_id The ID of the proposal to vote on
|
|
39
|
+
* @returns A function that takes a Transaction object
|
|
40
|
+
*/
|
|
41
|
+
vote: (poolKey: string, balanceManagerKey: string, proposal_id: string) => (tx: Transaction) => void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _config;
|
|
9
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from "../utils/config.js";
|
|
10
|
+
class GovernanceContract {
|
|
11
|
+
/**
|
|
12
|
+
* @param {DeepBookConfig} config Configuration for GovernanceContract
|
|
13
|
+
*/
|
|
14
|
+
constructor(config) {
|
|
15
|
+
__privateAdd(this, _config);
|
|
16
|
+
/**
|
|
17
|
+
* @description Stake a specified amount in the pool
|
|
18
|
+
* @param {string} poolKey The key to identify the pool
|
|
19
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
20
|
+
* @param {number} stakeAmount The amount to stake
|
|
21
|
+
* @returns A function that takes a Transaction object
|
|
22
|
+
*/
|
|
23
|
+
this.stake = (poolKey, balanceManagerKey, stakeAmount) => (tx) => {
|
|
24
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
25
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
26
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
27
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
28
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
29
|
+
tx.moveCall({
|
|
30
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stake`,
|
|
31
|
+
arguments: [
|
|
32
|
+
tx.object(pool.address),
|
|
33
|
+
tx.object(balanceManager.address),
|
|
34
|
+
tradeProof,
|
|
35
|
+
tx.pure.u64(stakeAmount * DEEP_SCALAR)
|
|
36
|
+
],
|
|
37
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @description Unstake from the pool
|
|
42
|
+
* @param {string} poolKey The key to identify the pool
|
|
43
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
44
|
+
* @returns A function that takes a Transaction object
|
|
45
|
+
*/
|
|
46
|
+
this.unstake = (poolKey, balanceManagerKey) => (tx) => {
|
|
47
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
48
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
49
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
50
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
51
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
52
|
+
tx.moveCall({
|
|
53
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::unstake`,
|
|
54
|
+
arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
|
|
55
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @description Submit a governance proposal
|
|
60
|
+
* @param {ProposalParams} params Parameters for the proposal
|
|
61
|
+
* @returns A function that takes a Transaction object
|
|
62
|
+
*/
|
|
63
|
+
this.submitProposal = (params) => (tx) => {
|
|
64
|
+
const { poolKey, balanceManagerKey, takerFee, makerFee, stakeRequired } = params;
|
|
65
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
66
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
67
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
68
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
69
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
70
|
+
tx.moveCall({
|
|
71
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::submit_proposal`,
|
|
72
|
+
arguments: [
|
|
73
|
+
tx.object(pool.address),
|
|
74
|
+
tx.object(balanceManager.address),
|
|
75
|
+
tradeProof,
|
|
76
|
+
tx.pure.u64(takerFee * FLOAT_SCALAR),
|
|
77
|
+
tx.pure.u64(makerFee * FLOAT_SCALAR),
|
|
78
|
+
tx.pure.u64(stakeRequired * DEEP_SCALAR)
|
|
79
|
+
],
|
|
80
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* @description Vote on a proposal
|
|
85
|
+
* @param {string} poolKey The key to identify the pool
|
|
86
|
+
* @param {string} balanceManagerKey The key to identify the BalanceManager
|
|
87
|
+
* @param {string} proposal_id The ID of the proposal to vote on
|
|
88
|
+
* @returns A function that takes a Transaction object
|
|
89
|
+
*/
|
|
90
|
+
this.vote = (poolKey, balanceManagerKey, proposal_id) => (tx) => {
|
|
91
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
92
|
+
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
93
|
+
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
94
|
+
tx.moveCall({
|
|
95
|
+
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::vote`,
|
|
96
|
+
arguments: [
|
|
97
|
+
tx.object(pool.address),
|
|
98
|
+
tx.object(balanceManager.address),
|
|
99
|
+
tradeProof,
|
|
100
|
+
tx.pure.id(proposal_id)
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
__privateSet(this, _config, config);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_config = new WeakMap();
|
|
108
|
+
export {
|
|
109
|
+
GovernanceContract
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=governance.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/transactions/governance.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { ProposalParams } from '../types/index.js';\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * GovernanceContract class for managing governance operations in DeepBook.\n */\nexport class GovernanceContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for GovernanceContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Stake a specified amount in the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {number} stakeAmount The amount to stake\n\t * @returns A function that takes a Transaction object\n\t */\n\tstake =\n\t\t(poolKey: string, balanceManagerKey: string, stakeAmount: number) => (tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\t\ttradeProof,\n\t\t\t\t\ttx.pure.u64(stakeAmount * DEEP_SCALAR),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Unstake from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tunstake = (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unstake`,\n\t\t\targuments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Submit a governance proposal\n\t * @param {ProposalParams} params Parameters for the proposal\n\t * @returns A function that takes a Transaction object\n\t */\n\tsubmitProposal = (params: ProposalParams) => (tx: Transaction) => {\n\t\tconst { poolKey, balanceManagerKey, takerFee, makerFee, stakeRequired } = params;\n\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::submit_proposal`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\ttradeProof,\n\t\t\t\ttx.pure.u64(takerFee * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(makerFee * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(stakeRequired * DEEP_SCALAR),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Vote on a proposal\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {string} proposal_id The ID of the proposal to vote on\n\t * @returns A function that takes a Transaction object\n\t */\n\tvote = (poolKey: string, balanceManagerKey: string, proposal_id: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::vote`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\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AAM,aAAa,GAAG,IAAI,mBAAK,SAAQ,eAAe,cAAc,iBAAiB,CAAC;AAEtF,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,QAC3C,WAAW;AAAA,UACV,GAAG,OAAO,KAAK,OAAO;AAAA,UACtB,GAAG,OAAO,eAAe,OAAO;AAAA,UAChC;AAAA,UACA,GAAG,KAAK,GAAG,WAAW;AAAA,QACvB;AAAA,MACD,CAAC;AAAA,IACF;AAnGC,uBAAK,SAAU;AAAA,EAChB;AAmGD;AA1GC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
|
+
export interface BalanceManager {
|
|
3
|
+
address: string;
|
|
4
|
+
tradeCap: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface Coin {
|
|
7
|
+
address: string;
|
|
8
|
+
type: string;
|
|
9
|
+
scalar: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Pool {
|
|
12
|
+
address: string;
|
|
13
|
+
baseCoin: string;
|
|
14
|
+
quoteCoin: string;
|
|
15
|
+
}
|
|
16
|
+
export declare enum OrderType {
|
|
17
|
+
NO_RESTRICTION = 0,
|
|
18
|
+
IMMEDIATE_OR_CANCEL = 1,
|
|
19
|
+
FILL_OR_KILL = 2,
|
|
20
|
+
POST_ONLY = 3
|
|
21
|
+
}
|
|
22
|
+
export declare enum SelfMatchingOptions {
|
|
23
|
+
SELF_MATCHING_ALLOWED = 0,
|
|
24
|
+
CANCEL_TAKER = 1,
|
|
25
|
+
CANCEL_MAKER = 2
|
|
26
|
+
}
|
|
27
|
+
export interface PlaceLimitOrderParams {
|
|
28
|
+
poolKey: string;
|
|
29
|
+
balanceManagerKey: string;
|
|
30
|
+
clientOrderId: string;
|
|
31
|
+
price: number;
|
|
32
|
+
quantity: number;
|
|
33
|
+
isBid: boolean;
|
|
34
|
+
expiration?: number | bigint;
|
|
35
|
+
orderType?: OrderType;
|
|
36
|
+
selfMatchingOption?: SelfMatchingOptions;
|
|
37
|
+
payWithDeep?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface PlaceMarketOrderParams {
|
|
40
|
+
poolKey: string;
|
|
41
|
+
balanceManagerKey: string;
|
|
42
|
+
clientOrderId: string;
|
|
43
|
+
quantity: number;
|
|
44
|
+
isBid: boolean;
|
|
45
|
+
selfMatchingOption?: SelfMatchingOptions;
|
|
46
|
+
payWithDeep?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface ProposalParams {
|
|
49
|
+
poolKey: string;
|
|
50
|
+
balanceManagerKey: string;
|
|
51
|
+
takerFee: number;
|
|
52
|
+
makerFee: number;
|
|
53
|
+
stakeRequired: number;
|
|
54
|
+
}
|
|
55
|
+
export interface SwapParams {
|
|
56
|
+
poolKey: string;
|
|
57
|
+
amount: number;
|
|
58
|
+
deepAmount: number;
|
|
59
|
+
minOut: number;
|
|
60
|
+
deepCoin?: TransactionObjectArgument;
|
|
61
|
+
baseCoin?: TransactionObjectArgument;
|
|
62
|
+
quoteCoin?: TransactionObjectArgument;
|
|
63
|
+
}
|
|
64
|
+
export interface CreatePoolAdminParams {
|
|
65
|
+
baseCoinKey: string;
|
|
66
|
+
quoteCoinKey: string;
|
|
67
|
+
tickSize: number;
|
|
68
|
+
lotSize: number;
|
|
69
|
+
minSize: number;
|
|
70
|
+
whitelisted: boolean;
|
|
71
|
+
stablePool: boolean;
|
|
72
|
+
deepCoin?: TransactionObjectArgument;
|
|
73
|
+
baseCoin?: TransactionObjectArgument;
|
|
74
|
+
}
|
|
75
|
+
export interface Config {
|
|
76
|
+
DEEPBOOK_PACKAGE_ID: string;
|
|
77
|
+
REGISTRY_ID: string;
|
|
78
|
+
DEEP_TREASURY_ID: string;
|
|
79
|
+
}
|
|
80
|
+
export type Environment = 'mainnet' | 'testnet';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var OrderType = /* @__PURE__ */ ((OrderType2) => {
|
|
2
|
+
OrderType2[OrderType2["NO_RESTRICTION"] = 0] = "NO_RESTRICTION";
|
|
3
|
+
OrderType2[OrderType2["IMMEDIATE_OR_CANCEL"] = 1] = "IMMEDIATE_OR_CANCEL";
|
|
4
|
+
OrderType2[OrderType2["FILL_OR_KILL"] = 2] = "FILL_OR_KILL";
|
|
5
|
+
OrderType2[OrderType2["POST_ONLY"] = 3] = "POST_ONLY";
|
|
6
|
+
return OrderType2;
|
|
7
|
+
})(OrderType || {});
|
|
8
|
+
var SelfMatchingOptions = /* @__PURE__ */ ((SelfMatchingOptions2) => {
|
|
9
|
+
SelfMatchingOptions2[SelfMatchingOptions2["SELF_MATCHING_ALLOWED"] = 0] = "SELF_MATCHING_ALLOWED";
|
|
10
|
+
SelfMatchingOptions2[SelfMatchingOptions2["CANCEL_TAKER"] = 1] = "CANCEL_TAKER";
|
|
11
|
+
SelfMatchingOptions2[SelfMatchingOptions2["CANCEL_MAKER"] = 2] = "CANCEL_MAKER";
|
|
12
|
+
return SelfMatchingOptions2;
|
|
13
|
+
})(SelfMatchingOptions || {});
|
|
14
|
+
export {
|
|
15
|
+
OrderType,
|
|
16
|
+
SelfMatchingOptions
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap: string | undefined;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number;\n\tdeepAmount: number;\n\tminOut: number;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\nexport type Environment = 'mainnet' | 'testnet';\n"],
|
|
5
|
+
"mappings": "AAwBO,IAAK,YAAL,kBAAKA,eAAL;AACN,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAJW,SAAAA;AAAA,GAAA;AAQL,IAAK,sBAAL,kBAAKC,yBAAL;AACN,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAHW,SAAAA;AAAA,GAAA;",
|
|
6
|
+
"names": ["OrderType", "SelfMatchingOptions"]
|
|
7
|
+
}
|