@mysten/deepbook-v3 1.5.8 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/dist/client.d.mts +5 -0
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +7 -0
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/account.d.mts.map +1 -1
- package/dist/contracts/deepbook/balance_manager.mjs +413 -0
- package/dist/contracts/deepbook/balance_manager.mjs.map +1 -0
- package/dist/contracts/deepbook/big_vector.mjs +43 -0
- package/dist/contracts/deepbook/big_vector.mjs.map +1 -0
- package/dist/contracts/deepbook/book.mjs +29 -0
- package/dist/contracts/deepbook/book.mjs.map +1 -0
- 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/deep_price.mjs +1 -1
- package/dist/contracts/deepbook/deps/std/type_name.mjs +17 -0
- package/dist/contracts/deepbook/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/bag.mjs +43 -0
- package/dist/contracts/deepbook/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/balance.mjs +21 -0
- package/dist/contracts/deepbook/deps/sui/balance.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/table.mjs +38 -0
- package/dist/contracts/deepbook/deps/sui/table.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/deepbook/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/versioned.mjs +19 -0
- package/dist/contracts/deepbook/deps/sui/versioned.mjs.map +1 -0
- package/dist/contracts/deepbook/governance.mjs +49 -0
- package/dist/contracts/deepbook/governance.mjs.map +1 -0
- package/dist/contracts/deepbook/history.mjs +56 -0
- package/dist/contracts/deepbook/history.mjs.map +1 -0
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/deepbook/pool.mjs +1739 -0
- package/dist/contracts/deepbook/pool.mjs.map +1 -0
- package/dist/contracts/deepbook/registry.mjs +295 -0
- package/dist/contracts/deepbook/registry.mjs.map +1 -0
- package/dist/contracts/deepbook/state.mjs +89 -0
- package/dist/contracts/deepbook/state.mjs.map +1 -0
- package/dist/contracts/deepbook/trade_params.mjs +21 -0
- package/dist/contracts/deepbook/trade_params.mjs.map +1 -0
- package/dist/contracts/deepbook/vault.mjs +42 -0
- package/dist/contracts/deepbook/vault.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs +53 -0
- package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/std/type_name.mjs +17 -0
- package/dist/contracts/deepbook_margin/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/bag.mjs +43 -0
- package/dist/contracts/deepbook_margin/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/balance.mjs +21 -0
- package/dist/contracts/deepbook_margin/deps/sui/balance.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/table.mjs +38 -0
- package/dist/contracts/deepbook_margin/deps/sui/table.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs +26 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs +19 -0
- package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_manager.mjs +989 -0
- package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_pool.mjs +550 -0
- package/dist/contracts/deepbook_margin/margin_pool.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_registry.mjs +786 -0
- package/dist/contracts/deepbook_margin/margin_registry.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_state.mjs +30 -0
- package/dist/contracts/deepbook_margin/margin_state.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/oracle.mjs +82 -0
- package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/pool_proxy.mjs +644 -0
- package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/position_manager.mjs +32 -0
- package/dist/contracts/deepbook_margin/position_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/protocol_config.mjs +122 -0
- package/dist/contracts/deepbook_margin/protocol_config.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/protocol_fees.mjs +58 -0
- package/dist/contracts/deepbook_margin/protocol_fees.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/rate_limiter.mjs +26 -0
- package/dist/contracts/deepbook_margin/rate_limiter.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/tpsl.mjs +171 -0
- package/dist/contracts/deepbook_margin/tpsl.mjs.map +1 -0
- package/dist/contracts/margin_liquidation/deps/sui/bag.mjs +43 -0
- package/dist/contracts/margin_liquidation/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs +179 -0
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -0
- package/dist/contracts/utils/index.d.mts +1 -1
- package/dist/contracts/utils/index.mjs +92 -3
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/queries/registryQueries.mjs +13 -0
- package/dist/queries/registryQueries.mjs.map +1 -1
- package/dist/transactions/balanceManager.d.mts.map +1 -1
- package/dist/transactions/balanceManager.mjs +119 -100
- package/dist/transactions/balanceManager.mjs.map +1 -1
- package/dist/transactions/deepbook.d.mts.map +1 -1
- package/dist/transactions/deepbook.mjs +464 -439
- package/dist/transactions/deepbook.mjs.map +1 -1
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/deepbookAdmin.mjs +151 -135
- package/dist/transactions/deepbookAdmin.mjs.map +1 -1
- package/dist/transactions/flashLoans.d.mts.map +1 -1
- package/dist/transactions/flashLoans.mjs +29 -22
- package/dist/transactions/flashLoans.mjs.map +1 -1
- package/dist/transactions/governance.d.mts.map +1 -1
- package/dist/transactions/governance.mjs +34 -33
- package/dist/transactions/governance.mjs.map +1 -1
- package/dist/transactions/marginAdmin.d.mts +17 -7
- package/dist/transactions/marginAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.mjs +186 -169
- package/dist/transactions/marginAdmin.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.mjs +53 -54
- package/dist/transactions/marginLiquidations.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginMaintainer.d.mts.map +1 -1
- package/dist/transactions/marginMaintainer.mjs +83 -83
- package/dist/transactions/marginMaintainer.mjs.map +1 -1
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +330 -317
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginPool.d.mts.map +1 -1
- package/dist/transactions/marginPool.mjs +93 -89
- package/dist/transactions/marginPool.mjs.map +1 -1
- package/dist/transactions/marginRegistry.d.mts +22 -15
- package/dist/transactions/marginRegistry.d.mts.map +1 -1
- package/dist/transactions/marginRegistry.mjs +101 -68
- package/dist/transactions/marginRegistry.mjs.map +1 -1
- package/dist/transactions/marginTPSL.d.mts +27 -9
- package/dist/transactions/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/marginTPSL.mjs +108 -82
- package/dist/transactions/marginTPSL.mjs.map +1 -1
- package/dist/transactions/poolProxy.d.mts +37 -5
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/dist/transactions/poolProxy.mjs +269 -189
- package/dist/transactions/poolProxy.mjs.map +1 -1
- package/dist/utils/constants.mjs +4 -4
- package/dist/utils/constants.mjs.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +8 -0
- package/src/contracts/deepbook/balance_manager.ts +46 -5
- package/src/contracts/deepbook/constants.ts +13 -0
- package/src/contracts/deepbook/pool.ts +133 -0
- package/src/contracts/deepbook/registry.ts +136 -1
- package/src/contracts/deepbook_margin/deps/deepbook/balance_manager.ts +49 -0
- package/src/contracts/deepbook_margin/deps/std/type_name.ts +24 -0
- package/src/contracts/deepbook_margin/deps/sui/bag.ts +41 -0
- package/src/contracts/deepbook_margin/deps/sui/balance.ts +19 -0
- package/src/contracts/deepbook_margin/deps/sui/table.ts +36 -0
- package/src/contracts/deepbook_margin/deps/sui/vec_map.ts +33 -0
- package/src/contracts/deepbook_margin/deps/sui/vec_set.ts +22 -0
- package/src/contracts/deepbook_margin/deps/sui/versioned.ts +13 -0
- package/src/contracts/deepbook_margin/margin_constants.ts +329 -0
- package/src/contracts/deepbook_margin/margin_manager.ts +1772 -0
- package/src/contracts/deepbook_margin/margin_pool.ts +1129 -0
- package/src/contracts/deepbook_margin/margin_registry.ts +1207 -0
- package/src/contracts/deepbook_margin/margin_state.ts +26 -0
- package/src/contracts/deepbook_margin/oracle.ts +99 -0
- package/src/contracts/deepbook_margin/pool_proxy.ts +1298 -0
- package/src/contracts/deepbook_margin/position_manager.ts +28 -0
- package/src/contracts/deepbook_margin/protocol_config.ts +163 -0
- package/src/contracts/deepbook_margin/protocol_fees.ts +153 -0
- package/src/contracts/deepbook_margin/rate_limiter.ts +80 -0
- package/src/contracts/deepbook_margin/tpsl.ts +559 -0
- package/src/contracts/margin_liquidation/deps/sui/bag.ts +41 -0
- package/src/contracts/margin_liquidation/liquidation_vault.ts +401 -0
- package/src/queries/registryQueries.ts +15 -0
- package/src/transactions/balanceManager.ts +140 -90
- package/src/transactions/deepbook.ts +586 -494
- package/src/transactions/deepbookAdmin.ts +154 -146
- package/src/transactions/flashLoans.ts +29 -20
- package/src/transactions/governance.ts +50 -37
- package/src/transactions/marginAdmin.ts +247 -188
- package/src/transactions/marginLiquidations.ts +70 -55
- package/src/transactions/marginMaintainer.ts +106 -88
- package/src/transactions/marginManager.ts +414 -348
- package/src/transactions/marginPool.ts +140 -103
- package/src/transactions/marginRegistry.ts +103 -70
- package/src/transactions/marginTPSL.ts +151 -87
- package/src/transactions/poolProxy.ts +384 -205
- package/src/utils/constants.ts +4 -4
|
@@ -9,6 +9,9 @@ import type { PoolConfigParams } from '../types/index.js';
|
|
|
9
9
|
import { FLOAT_SCALAR } from '../utils/config.js';
|
|
10
10
|
import { convertRate } from '../utils/conversion.js';
|
|
11
11
|
import { hexToBytes } from '@noble/hashes/utils.js';
|
|
12
|
+
import * as marginRegistryMoveCalls from '../contracts/deepbook_margin/margin_registry.js';
|
|
13
|
+
import * as marginPoolMoveCalls from '../contracts/deepbook_margin/margin_pool.js';
|
|
14
|
+
import * as oracleMoveCalls from '../contracts/deepbook_margin/oracle.js';
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* MarginAdminContract class for managing admin actions.
|
|
@@ -40,14 +43,12 @@ export class MarginAdminContract {
|
|
|
40
43
|
* @returns A function that takes a Transaction object
|
|
41
44
|
*/
|
|
42
45
|
mintMaintainerCap = () => (tx: Transaction) => {
|
|
43
|
-
return tx.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
],
|
|
50
|
-
});
|
|
46
|
+
return tx.add(
|
|
47
|
+
marginRegistryMoveCalls.mintMaintainerCap({
|
|
48
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
49
|
+
arguments: { self: this.#config.MARGIN_REGISTRY_ID, AdminCap: this.#marginAdminCap() },
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -55,6 +56,10 @@ export class MarginAdminContract {
|
|
|
55
56
|
* @returns A function that takes a Transaction object
|
|
56
57
|
*/
|
|
57
58
|
revokeMaintainerCap = (maintainerCapId: string) => (tx: Transaction) => {
|
|
59
|
+
// NOTE: left as a positional moveCall (not codegen). The original passes
|
|
60
|
+
// `maintainerCapId` as an object reference (`tx.object`), whereas the
|
|
61
|
+
// generated binding encodes it as a pure `ID` value — migrating would change
|
|
62
|
+
// the emitted PTB. Kept verbatim to stay byte-identical.
|
|
58
63
|
tx.moveCall({
|
|
59
64
|
target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_maintainer_cap`,
|
|
60
65
|
arguments: [
|
|
@@ -77,17 +82,18 @@ export class MarginAdminContract {
|
|
|
77
82
|
const pool = this.#config.getPool(poolKey);
|
|
78
83
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
79
84
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
80
|
-
tx.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
tx.add(
|
|
86
|
+
marginRegistryMoveCalls.registerDeepbookPool({
|
|
87
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
88
|
+
arguments: {
|
|
89
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
90
|
+
AdminCap: this.#marginAdminCap(),
|
|
91
|
+
pool: pool.address,
|
|
92
|
+
poolConfig,
|
|
93
|
+
},
|
|
94
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
91
97
|
};
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -99,16 +105,17 @@ export class MarginAdminContract {
|
|
|
99
105
|
const pool = this.#config.getPool(poolKey);
|
|
100
106
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
101
107
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
102
|
-
tx.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
tx.add(
|
|
109
|
+
marginRegistryMoveCalls.enableDeepbookPool({
|
|
110
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
111
|
+
arguments: {
|
|
112
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
113
|
+
AdminCap: this.#marginAdminCap(),
|
|
114
|
+
pool: pool.address,
|
|
115
|
+
},
|
|
116
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
112
119
|
};
|
|
113
120
|
|
|
114
121
|
/**
|
|
@@ -120,16 +127,17 @@ export class MarginAdminContract {
|
|
|
120
127
|
const pool = this.#config.getPool(poolKey);
|
|
121
128
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
122
129
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
123
|
-
tx.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
tx.add(
|
|
131
|
+
marginRegistryMoveCalls.disableDeepbookPool({
|
|
132
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
133
|
+
arguments: {
|
|
134
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
135
|
+
AdminCap: this.#marginAdminCap(),
|
|
136
|
+
pool: pool.address,
|
|
137
|
+
},
|
|
138
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
133
141
|
};
|
|
134
142
|
|
|
135
143
|
/**
|
|
@@ -142,17 +150,18 @@ export class MarginAdminContract {
|
|
|
142
150
|
const pool = this.#config.getPool(poolKey);
|
|
143
151
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
144
152
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
145
|
-
tx.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
tx.add(
|
|
154
|
+
marginRegistryMoveCalls.updateRiskParams({
|
|
155
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
156
|
+
arguments: {
|
|
157
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
158
|
+
AdminCap: this.#marginAdminCap(),
|
|
159
|
+
pool: pool.address,
|
|
160
|
+
poolConfig,
|
|
161
|
+
},
|
|
162
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
156
165
|
};
|
|
157
166
|
|
|
158
167
|
/**
|
|
@@ -169,17 +178,18 @@ export class MarginAdminContract {
|
|
|
169
178
|
const pool = this.#config.getPool(poolKey);
|
|
170
179
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
171
180
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
172
|
-
tx.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
tx.add(
|
|
182
|
+
marginRegistryMoveCalls.setPriceTolerance({
|
|
183
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
184
|
+
arguments: {
|
|
185
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
186
|
+
AdminCap: this.#marginAdminCap(),
|
|
187
|
+
pool: pool.address,
|
|
188
|
+
tolerance: convertRate(tolerance, FLOAT_SCALAR),
|
|
189
|
+
},
|
|
190
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
183
193
|
};
|
|
184
194
|
|
|
185
195
|
/**
|
|
@@ -194,17 +204,18 @@ export class MarginAdminContract {
|
|
|
194
204
|
const pool = this.#config.getPool(poolKey);
|
|
195
205
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
196
206
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
197
|
-
tx.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
tx.add(
|
|
208
|
+
marginRegistryMoveCalls.setMaxPriceAge({
|
|
209
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
210
|
+
arguments: {
|
|
211
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
212
|
+
AdminCap: this.#marginAdminCap(),
|
|
213
|
+
pool: pool.address,
|
|
214
|
+
maxAgeMs,
|
|
215
|
+
},
|
|
216
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
208
219
|
};
|
|
209
220
|
|
|
210
221
|
/**
|
|
@@ -221,19 +232,48 @@ export class MarginAdminContract {
|
|
|
221
232
|
const pool = this.#config.getPool(poolKey);
|
|
222
233
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
223
234
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
224
|
-
tx.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
tx.add(
|
|
236
|
+
marginRegistryMoveCalls.setMaxOrderTtl({
|
|
237
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
238
|
+
arguments: {
|
|
239
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
240
|
+
AdminCap: this.#marginAdminCap(),
|
|
241
|
+
pool: pool.address,
|
|
242
|
+
maxOrderTtlMs,
|
|
243
|
+
},
|
|
244
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
235
247
|
};
|
|
236
248
|
|
|
249
|
+
/**
|
|
250
|
+
* @description Set the minimum risk ratio required to open a new position on
|
|
251
|
+
* a pool. Distinct from the borrow floor: this gates position opening, not
|
|
252
|
+
* borrowing. Stored in 9-decimal float scaling (1.0 = `FLOAT_SCALAR`); the SDK
|
|
253
|
+
* applies the scaling, so callers pass a human-readable ratio (e.g. `1.25`).
|
|
254
|
+
* @param {string} poolKey The key of the pool to update
|
|
255
|
+
* @param {number | bigint} minOpenRiskRatio Minimum open risk ratio (e.g. 1.25)
|
|
256
|
+
* @returns A function that takes a Transaction object
|
|
257
|
+
*/
|
|
258
|
+
setMinOpenRiskRatio =
|
|
259
|
+
(poolKey: string, minOpenRiskRatio: number | bigint) => (tx: Transaction) => {
|
|
260
|
+
const pool = this.#config.getPool(poolKey);
|
|
261
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
262
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
263
|
+
tx.add(
|
|
264
|
+
marginRegistryMoveCalls.setMinOpenRiskRatio({
|
|
265
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
266
|
+
arguments: {
|
|
267
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
268
|
+
AdminCap: this.#marginAdminCap(),
|
|
269
|
+
pool: pool.address,
|
|
270
|
+
minOpenRiskRatio: convertRate(minOpenRiskRatio, FLOAT_SCALAR),
|
|
271
|
+
},
|
|
272
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
237
277
|
/**
|
|
238
278
|
* @description Add the PythConfig to the margin registry
|
|
239
279
|
* @param {Transaction} tx The transaction object
|
|
@@ -241,15 +281,17 @@ export class MarginAdminContract {
|
|
|
241
281
|
* @returns A function that takes a Transaction object
|
|
242
282
|
*/
|
|
243
283
|
addConfig = (config: TransactionArgument) => (tx: Transaction) => {
|
|
244
|
-
tx.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
284
|
+
tx.add(
|
|
285
|
+
marginRegistryMoveCalls.addConfig({
|
|
286
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
287
|
+
arguments: {
|
|
288
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
289
|
+
AdminCap: this.#marginAdminCap(),
|
|
290
|
+
config,
|
|
291
|
+
},
|
|
292
|
+
typeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
253
295
|
};
|
|
254
296
|
|
|
255
297
|
/**
|
|
@@ -258,11 +300,13 @@ export class MarginAdminContract {
|
|
|
258
300
|
* @returns A function that takes a Transaction object
|
|
259
301
|
*/
|
|
260
302
|
removeConfig = () => (tx: Transaction) => {
|
|
261
|
-
tx.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
303
|
+
tx.add(
|
|
304
|
+
marginRegistryMoveCalls.removeConfig({
|
|
305
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
306
|
+
arguments: { self: this.#config.MARGIN_REGISTRY_ID, AdminCap: this.#marginAdminCap() },
|
|
307
|
+
typeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
266
310
|
};
|
|
267
311
|
|
|
268
312
|
/**
|
|
@@ -271,14 +315,16 @@ export class MarginAdminContract {
|
|
|
271
315
|
* @returns A function that takes a Transaction object
|
|
272
316
|
*/
|
|
273
317
|
enableVersion = (version: number) => (tx: Transaction) => {
|
|
274
|
-
tx.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
318
|
+
tx.add(
|
|
319
|
+
marginRegistryMoveCalls.enableVersion({
|
|
320
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
321
|
+
arguments: {
|
|
322
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
323
|
+
version,
|
|
324
|
+
AdminCap: this.#marginAdminCap(),
|
|
325
|
+
},
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
282
328
|
};
|
|
283
329
|
|
|
284
330
|
/**
|
|
@@ -287,14 +333,16 @@ export class MarginAdminContract {
|
|
|
287
333
|
* @returns A function that takes a Transaction object
|
|
288
334
|
*/
|
|
289
335
|
disableVersion = (version: number) => (tx: Transaction) => {
|
|
290
|
-
tx.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
336
|
+
tx.add(
|
|
337
|
+
marginRegistryMoveCalls.disableVersion({
|
|
338
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
339
|
+
arguments: {
|
|
340
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
341
|
+
version,
|
|
342
|
+
AdminCap: this.#marginAdminCap(),
|
|
343
|
+
},
|
|
344
|
+
}),
|
|
345
|
+
);
|
|
298
346
|
};
|
|
299
347
|
|
|
300
348
|
/**
|
|
@@ -315,19 +363,21 @@ export class MarginAdminContract {
|
|
|
315
363
|
userLiquidationReward,
|
|
316
364
|
poolLiquidationReward,
|
|
317
365
|
} = poolConfigParams;
|
|
318
|
-
return tx.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
366
|
+
return tx.add(
|
|
367
|
+
marginRegistryMoveCalls.newPoolConfig({
|
|
368
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
369
|
+
arguments: {
|
|
370
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
371
|
+
minWithdrawRiskRatio: convertRate(minWithdrawRiskRatio, FLOAT_SCALAR),
|
|
372
|
+
minBorrowRiskRatio: convertRate(minBorrowRiskRatio, FLOAT_SCALAR),
|
|
373
|
+
liquidationRiskRatio: convertRate(liquidationRiskRatio, FLOAT_SCALAR),
|
|
374
|
+
targetLiquidationRiskRatio: convertRate(targetLiquidationRiskRatio, FLOAT_SCALAR),
|
|
375
|
+
userLiquidationReward: convertRate(userLiquidationReward, FLOAT_SCALAR),
|
|
376
|
+
poolLiquidationReward: convertRate(poolLiquidationReward, FLOAT_SCALAR),
|
|
377
|
+
},
|
|
378
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
379
|
+
}),
|
|
380
|
+
);
|
|
331
381
|
};
|
|
332
382
|
|
|
333
383
|
/**
|
|
@@ -340,14 +390,16 @@ export class MarginAdminContract {
|
|
|
340
390
|
const pool = this.#config.getPool(poolKey);
|
|
341
391
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
342
392
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
343
|
-
tx.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
393
|
+
tx.add(
|
|
394
|
+
marginRegistryMoveCalls.newPoolConfigWithLeverage({
|
|
395
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
396
|
+
arguments: {
|
|
397
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
398
|
+
leverage: convertRate(leverage, FLOAT_SCALAR),
|
|
399
|
+
},
|
|
400
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
351
403
|
};
|
|
352
404
|
|
|
353
405
|
/**
|
|
@@ -366,16 +418,18 @@ export class MarginAdminContract {
|
|
|
366
418
|
const priceFeedInput = new Uint8Array(
|
|
367
419
|
hexToBytes(coin['feed']!.startsWith('0x') ? coin.feed!.slice(2) : coin['feed']),
|
|
368
420
|
);
|
|
369
|
-
return tx.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
421
|
+
return tx.add(
|
|
422
|
+
oracleMoveCalls.newCoinTypeDataFromCurrency({
|
|
423
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
424
|
+
arguments: {
|
|
425
|
+
currency: coin.currencyId!,
|
|
426
|
+
priceFeedId: Array.from(priceFeedInput),
|
|
427
|
+
maxConfBps,
|
|
428
|
+
maxEwmaDifferenceBps,
|
|
429
|
+
},
|
|
430
|
+
typeArguments: [coin.type],
|
|
431
|
+
}),
|
|
432
|
+
);
|
|
379
433
|
};
|
|
380
434
|
|
|
381
435
|
/**
|
|
@@ -396,16 +450,18 @@ export class MarginAdminContract {
|
|
|
396
450
|
this.newCoinTypeData(setup.coinKey, setup.maxConfBps, setup.maxEwmaDifferenceBps)(tx),
|
|
397
451
|
);
|
|
398
452
|
}
|
|
399
|
-
return tx.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
453
|
+
return tx.add(
|
|
454
|
+
oracleMoveCalls.newPythConfig({
|
|
455
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
456
|
+
arguments: {
|
|
457
|
+
setups: tx.makeMoveVec({
|
|
458
|
+
elements: coinTypeDataList,
|
|
459
|
+
type: `${this.#config.MARGIN_PACKAGE_ID}::oracle::CoinTypeData`,
|
|
460
|
+
}),
|
|
461
|
+
maxAgeSecs: maxAgeSeconds,
|
|
462
|
+
},
|
|
463
|
+
}),
|
|
464
|
+
);
|
|
409
465
|
};
|
|
410
466
|
|
|
411
467
|
/**
|
|
@@ -413,14 +469,12 @@ export class MarginAdminContract {
|
|
|
413
469
|
* @returns A function that takes a Transaction object
|
|
414
470
|
*/
|
|
415
471
|
mintPauseCap = () => (tx: Transaction) => {
|
|
416
|
-
return tx.
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
],
|
|
423
|
-
});
|
|
472
|
+
return tx.add(
|
|
473
|
+
marginRegistryMoveCalls.mintPauseCap({
|
|
474
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
475
|
+
arguments: { self: this.#config.MARGIN_REGISTRY_ID, AdminCap: this.#marginAdminCap() },
|
|
476
|
+
}),
|
|
477
|
+
);
|
|
424
478
|
};
|
|
425
479
|
|
|
426
480
|
/**
|
|
@@ -429,15 +483,16 @@ export class MarginAdminContract {
|
|
|
429
483
|
* @returns A function that takes a Transaction object
|
|
430
484
|
*/
|
|
431
485
|
revokePauseCap = (pauseCapId: string) => (tx: Transaction) => {
|
|
432
|
-
tx.
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
486
|
+
tx.add(
|
|
487
|
+
marginRegistryMoveCalls.revokePauseCap({
|
|
488
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
489
|
+
arguments: {
|
|
490
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
491
|
+
AdminCap: this.#marginAdminCap(),
|
|
492
|
+
pauseCapId,
|
|
493
|
+
},
|
|
494
|
+
}),
|
|
495
|
+
);
|
|
441
496
|
};
|
|
442
497
|
|
|
443
498
|
/**
|
|
@@ -447,14 +502,16 @@ export class MarginAdminContract {
|
|
|
447
502
|
* @returns A function that takes a Transaction object
|
|
448
503
|
*/
|
|
449
504
|
disableVersionPauseCap = (version: number, pauseCapId: string) => (tx: Transaction) => {
|
|
450
|
-
tx.
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
505
|
+
tx.add(
|
|
506
|
+
marginRegistryMoveCalls.disableVersionPauseCap({
|
|
507
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
508
|
+
arguments: {
|
|
509
|
+
self: this.#config.MARGIN_REGISTRY_ID,
|
|
510
|
+
version,
|
|
511
|
+
pauseCap: pauseCapId,
|
|
512
|
+
},
|
|
513
|
+
}),
|
|
514
|
+
);
|
|
458
515
|
};
|
|
459
516
|
|
|
460
517
|
/**
|
|
@@ -466,14 +523,16 @@ export class MarginAdminContract {
|
|
|
466
523
|
adminWithdrawDefaultReferralFees = (coinKey: string) => (tx: Transaction) => {
|
|
467
524
|
const coin = this.#config.getCoin(coinKey);
|
|
468
525
|
const marginPool = this.#config.getMarginPool(coinKey);
|
|
469
|
-
return tx.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
526
|
+
return tx.add(
|
|
527
|
+
marginPoolMoveCalls.adminWithdrawDefaultReferralFees({
|
|
528
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
529
|
+
arguments: {
|
|
530
|
+
self: marginPool.address,
|
|
531
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
532
|
+
AdminCap: this.#marginAdminCap(),
|
|
533
|
+
},
|
|
534
|
+
typeArguments: [coin.type],
|
|
535
|
+
}),
|
|
536
|
+
);
|
|
478
537
|
};
|
|
479
538
|
}
|