@decibeltrade/sdk 0.1.1
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint$colon$check.log +5 -0
- package/.turbo/turbo-lint.log +5 -0
- package/decibel_transactions.md +1049 -0
- package/dist/abi/abi-manager.d.ts +13 -0
- package/dist/abi/abi-manager.d.ts.map +1 -0
- package/dist/abi/abi-manager.js +21 -0
- package/dist/abi/abis.json +1322 -0
- package/dist/abi/bytecode-manager.d.ts +57 -0
- package/dist/abi/bytecode-manager.d.ts.map +1 -0
- package/dist/abi/bytecode-manager.js +62 -0
- package/dist/abi/bytecode.json +24 -0
- package/dist/abi/fetch-abis.d.ts +7 -0
- package/dist/abi/fetch-abis.d.ts.map +1 -0
- package/dist/abi/fetch-abis.js +132 -0
- package/dist/abi/fetch-bytecode.d.ts +24 -0
- package/dist/abi/fetch-bytecode.d.ts.map +1 -0
- package/dist/abi/fetch-bytecode.js +123 -0
- package/dist/abi/generate-abis.d.ts +6 -0
- package/dist/abi/generate-abis.d.ts.map +1 -0
- package/dist/abi/generate-abis.js +170 -0
- package/dist/abi/json/netna.json +1323 -0
- package/dist/abi/json/testnet.json +1315 -0
- package/dist/abi/types.d.ts +22 -0
- package/dist/abi/types.d.ts.map +1 -0
- package/dist/abi/types.js +2 -0
- package/dist/admin.d.ts +29 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +203 -0
- package/dist/base.d.ts +42 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +176 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +78 -0
- package/dist/fee-pay.d.ts +11 -0
- package/dist/fee-pay.d.ts.map +1 -0
- package/dist/fee-pay.js +30 -0
- package/dist/gas/gas-price-manager.d.ts +35 -0
- package/dist/gas/gas-price-manager.d.ts.map +1 -0
- package/dist/gas/gas-price-manager.js +93 -0
- package/dist/gas-price-manager.d.ts +31 -0
- package/dist/gas-price-manager.d.ts.map +1 -0
- package/dist/gas-price-manager.js +84 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/order-event.types.d.ts +55 -0
- package/dist/order-event.types.d.ts.map +1 -0
- package/dist/order-event.types.js +3 -0
- package/dist/order-status.d.ts +43 -0
- package/dist/order-status.d.ts.map +1 -0
- package/dist/order-status.js +86 -0
- package/dist/read/account-overview/account-overview.reader.d.ts +37 -0
- package/dist/read/account-overview/account-overview.reader.d.ts.map +1 -0
- package/dist/read/account-overview/account-overview.reader.js +35 -0
- package/dist/read/account-overview/account-overview.types.d.ts +52 -0
- package/dist/read/account-overview/account-overview.types.d.ts.map +1 -0
- package/dist/read/account-overview/account-overview.types.js +36 -0
- package/dist/read/api-wallets/api-wallets.reader.d.ts +17 -0
- package/dist/read/api-wallets/api-wallets.reader.d.ts.map +1 -0
- package/dist/read/api-wallets/api-wallets.reader.js +27 -0
- package/dist/read/api-wallets/api-wallets.types.d.ts +17 -0
- package/dist/read/api-wallets/api-wallets.types.d.ts.map +1 -0
- package/dist/read/api-wallets/api-wallets.types.js +13 -0
- package/dist/read/base-reader.d.ts +22 -0
- package/dist/read/base-reader.d.ts.map +1 -0
- package/dist/read/base-reader.js +29 -0
- package/dist/read/candlesticks/candlesticks.reader.d.ts +31 -0
- package/dist/read/candlesticks/candlesticks.reader.d.ts.map +1 -0
- package/dist/read/candlesticks/candlesticks.reader.js +43 -0
- package/dist/read/candlesticks/candlesticks.types.d.ts +45 -0
- package/dist/read/candlesticks/candlesticks.types.d.ts.map +1 -0
- package/dist/read/candlesticks/candlesticks.types.js +36 -0
- package/dist/read/delegations/delegations.reader.d.ts +15 -0
- package/dist/read/delegations/delegations.reader.d.ts.map +1 -0
- package/dist/read/delegations/delegations.reader.js +23 -0
- package/dist/read/delegations/delegations.types.d.ts +17 -0
- package/dist/read/delegations/delegations.types.d.ts.map +1 -0
- package/dist/read/delegations/delegations.types.js +13 -0
- package/dist/read/index.d.ts +105 -0
- package/dist/read/index.d.ts.map +1 -0
- package/dist/read/index.js +244 -0
- package/dist/read/leaderboard/leaderboard.reader.d.ts +21 -0
- package/dist/read/leaderboard/leaderboard.reader.d.ts.map +1 -0
- package/dist/read/leaderboard/leaderboard.reader.js +22 -0
- package/dist/read/leaderboard/leaderboard.types.d.ts +27 -0
- package/dist/read/leaderboard/leaderboard.types.d.ts.map +1 -0
- package/dist/read/leaderboard/leaderboard.types.js +14 -0
- package/dist/read/market-contexts/market-contexts.reader.d.ts +22 -0
- package/dist/read/market-contexts/market-contexts.reader.d.ts.map +1 -0
- package/dist/read/market-contexts/market-contexts.reader.js +27 -0
- package/dist/read/market-contexts/market-contexts.types.d.ts +26 -0
- package/dist/read/market-contexts/market-contexts.types.d.ts.map +1 -0
- package/dist/read/market-contexts/market-contexts.types.js +19 -0
- package/dist/read/market-depth/market-depth.reader.d.ts +30 -0
- package/dist/read/market-depth/market-depth.reader.d.ts.map +1 -0
- package/dist/read/market-depth/market-depth.reader.js +46 -0
- package/dist/read/market-depth/market-depth.types.d.ts +20 -0
- package/dist/read/market-depth/market-depth.types.d.ts.map +1 -0
- package/dist/read/market-depth/market-depth.types.js +16 -0
- package/dist/read/market-prices/market-prices.reader.d.ts +44 -0
- package/dist/read/market-prices/market-prices.reader.d.ts.map +1 -0
- package/dist/read/market-prices/market-prices.reader.js +51 -0
- package/dist/read/market-prices/market-prices.types.d.ts +48 -0
- package/dist/read/market-prices/market-prices.types.d.ts.map +1 -0
- package/dist/read/market-prices/market-prices.types.js +26 -0
- package/dist/read/market-trades/market-trades.reader.d.ts +33 -0
- package/dist/read/market-trades/market-trades.reader.d.ts.map +1 -0
- package/dist/read/market-trades/market-trades.reader.js +39 -0
- package/dist/read/market-trades/market-trades.types.d.ts +52 -0
- package/dist/read/market-trades/market-trades.types.d.ts.map +1 -0
- package/dist/read/market-trades/market-trades.types.js +23 -0
- package/dist/read/markets/markets.reader.d.ts +38 -0
- package/dist/read/markets/markets.reader.d.ts.map +1 -0
- package/dist/read/markets/markets.reader.js +80 -0
- package/dist/read/markets/markets.types.d.ts +82 -0
- package/dist/read/markets/markets.types.d.ts.map +1 -0
- package/dist/read/markets/markets.types.js +46 -0
- package/dist/read/pagination.types.d.ts +14 -0
- package/dist/read/pagination.types.d.ts.map +1 -0
- package/dist/read/pagination.types.js +12 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts +14 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts.map +1 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.js +21 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.d.ts +14 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.d.ts.map +1 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.js +12 -0
- package/dist/read/public-vaults/public-vaults.reader.d.ts +38 -0
- package/dist/read/public-vaults/public-vaults.reader.d.ts.map +1 -0
- package/dist/read/public-vaults/public-vaults.reader.js +31 -0
- package/dist/read/public-vaults/public-vaults.types.d.ts +62 -0
- package/dist/read/public-vaults/public-vaults.types.d.ts.map +1 -0
- package/dist/read/public-vaults/public-vaults.types.js +33 -0
- package/dist/read/types.d.ts +178 -0
- package/dist/read/types.d.ts.map +1 -0
- package/dist/read/types.js +87 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts +31 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts.map +1 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.js +31 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.d.ts +49 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.d.ts.map +1 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.js +25 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts +31 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts.map +1 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +32 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts +46 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts.map +1 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.js +24 -0
- package/dist/read/user-funding-history/user-funding-history.reader.d.ts +28 -0
- package/dist/read/user-funding-history/user-funding-history.reader.d.ts.map +1 -0
- package/dist/read/user-funding-history/user-funding-history.reader.js +32 -0
- package/dist/read/user-funding-history/user-funding-history.types.d.ts +37 -0
- package/dist/read/user-funding-history/user-funding-history.types.d.ts.map +1 -0
- package/dist/read/user-funding-history/user-funding-history.types.js +21 -0
- package/dist/read/user-notifications/user-notifications.reader.d.ts +13 -0
- package/dist/read/user-notifications/user-notifications.reader.d.ts.map +1 -0
- package/dist/read/user-notifications/user-notifications.reader.js +19 -0
- package/dist/read/user-notifications/user-notifications.types.d.ts +49 -0
- package/dist/read/user-notifications/user-notifications.types.d.ts.map +1 -0
- package/dist/read/user-notifications/user-notifications.types.js +18 -0
- package/dist/read/user-open-orders/user-open-orders.reader.d.ts +40 -0
- package/dist/read/user-open-orders/user-open-orders.reader.d.ts.map +1 -0
- package/dist/read/user-open-orders/user-open-orders.reader.js +31 -0
- package/dist/read/user-open-orders/user-open-orders.types.d.ts +76 -0
- package/dist/read/user-open-orders/user-open-orders.types.d.ts.map +1 -0
- package/dist/read/user-open-orders/user-open-orders.types.js +34 -0
- package/dist/read/user-order-history/user-order-history.reader.d.ts +40 -0
- package/dist/read/user-order-history/user-order-history.reader.d.ts.map +1 -0
- package/dist/read/user-order-history/user-order-history.reader.js +28 -0
- package/dist/read/user-order-history/user-order-history.types.d.ts +85 -0
- package/dist/read/user-order-history/user-order-history.types.d.ts.map +1 -0
- package/dist/read/user-order-history/user-order-history.types.js +37 -0
- package/dist/read/user-positions/user-positions.reader.d.ts +37 -0
- package/dist/read/user-positions/user-positions.reader.d.ts.map +1 -0
- package/dist/read/user-positions/user-positions.reader.js +41 -0
- package/dist/read/user-positions/user-positions.types.d.ts +2590 -0
- package/dist/read/user-positions/user-positions.types.d.ts.map +1 -0
- package/dist/read/user-positions/user-positions.types.js +31 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts +18 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts.map +1 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.js +28 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.d.ts +21 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.d.ts.map +1 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.js +15 -0
- package/dist/read/user-trade-history/user-trade-history.reader.d.ts +33 -0
- package/dist/read/user-trade-history/user-trade-history.reader.d.ts.map +1 -0
- package/dist/read/user-trade-history/user-trade-history.reader.js +32 -0
- package/dist/read/user-trade-history/user-trade-history.types.d.ts +52 -0
- package/dist/read/user-trade-history/user-trade-history.types.d.ts.map +1 -0
- package/dist/read/user-trade-history/user-trade-history.types.js +26 -0
- package/dist/read/user-vaults/user-vaults.reader.d.ts +26 -0
- package/dist/read/user-vaults/user-vaults.reader.d.ts.map +1 -0
- package/dist/read/user-vaults/user-vaults.reader.js +32 -0
- package/dist/read/user-vaults/user-vaults.types.d.ts +39 -0
- package/dist/read/user-vaults/user-vaults.types.d.ts.map +1 -0
- package/dist/read/user-vaults/user-vaults.types.js +21 -0
- package/dist/read/vault/vault.reader.d.ts +95 -0
- package/dist/read/vault/vault.reader.d.ts.map +1 -0
- package/dist/read/vault/vault.reader.js +168 -0
- package/dist/read/vault/vault.types.d.ts +49 -0
- package/dist/read/vault/vault.types.d.ts.map +1 -0
- package/dist/read/vault/vault.types.js +45 -0
- package/dist/read/vaults/vaults.reader.d.ts +72 -0
- package/dist/read/vaults/vaults.reader.d.ts.map +1 -0
- package/dist/read/vaults/vaults.reader.js +63 -0
- package/dist/read/vaults/vaults.types.d.ts +140 -0
- package/dist/read/vaults/vaults.types.d.ts.map +1 -0
- package/dist/read/vaults/vaults.types.js +71 -0
- package/dist/read/ws-subscription.d.ts +21 -0
- package/dist/read/ws-subscription.d.ts.map +1 -0
- package/dist/read/ws-subscription.js +170 -0
- package/dist/subaccount-types.d.ts +24 -0
- package/dist/subaccount-types.d.ts.map +1 -0
- package/dist/subaccount-types.js +11 -0
- package/dist/transaction-builder.d.ts +14 -0
- package/dist/transaction-builder.d.ts.map +1 -0
- package/dist/transaction-builder.js +40 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils.d.ts +56 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +164 -0
- package/dist/vault-types.d.ts +43 -0
- package/dist/vault-types.d.ts.map +1 -0
- package/dist/vault-types.js +11 -0
- package/dist/write.d.ts +271 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +485 -0
- package/eslint.config.mjs +25 -0
- package/package.json +39 -0
- package/readme.md +257 -0
- package/sdk_reference.md +876 -0
- package/src/abi/generate-abis.ts +164 -0
- package/src/abi/json/netna.json +1323 -0
- package/src/abi/json/testnet.json +1315 -0
- package/src/abi/types.ts +23 -0
- package/src/admin.ts +284 -0
- package/src/base.ts +218 -0
- package/src/constants.ts +118 -0
- package/src/fee-pay.ts +39 -0
- package/src/gas/gas-price-manager.ts +115 -0
- package/src/index.ts +10 -0
- package/src/order-event.types.ts +65 -0
- package/src/order-status.ts +89 -0
- package/src/read/account-overview/account-overview.reader.ts +43 -0
- package/src/read/account-overview/account-overview.types.ts +45 -0
- package/src/read/base-reader.ts +41 -0
- package/src/read/candlesticks/candlesticks.reader.ts +61 -0
- package/src/read/candlesticks/candlesticks.types.ts +46 -0
- package/src/read/delegations/delegations.reader.ts +22 -0
- package/src/read/delegations/delegations.types.ts +19 -0
- package/src/read/index.ts +271 -0
- package/src/read/leaderboard/leaderboard.reader.ts +21 -0
- package/src/read/leaderboard/leaderboard.types.ts +26 -0
- package/src/read/market-contexts/market-contexts.reader.ts +26 -0
- package/src/read/market-contexts/market-contexts.types.ts +18 -0
- package/src/read/market-depth/market-depth.reader.ts +60 -0
- package/src/read/market-depth/market-depth.types.ts +24 -0
- package/src/read/market-prices/market-prices.reader.ts +61 -0
- package/src/read/market-prices/market-prices.types.ts +38 -0
- package/src/read/market-trades/market-trades.reader.ts +46 -0
- package/src/read/market-trades/market-trades.types.ts +34 -0
- package/src/read/markets/markets.reader.ts +82 -0
- package/src/read/markets/markets.types.ts +54 -0
- package/src/read/pagination.types.ts +18 -0
- package/src/read/portfolio-chart/portfolio-chart.reader.ts +20 -0
- package/src/read/portfolio-chart/portfolio-chart.types.ts +21 -0
- package/src/read/types.ts +129 -0
- package/src/read/user-active-twaps/user-active-twaps.reader.ts +36 -0
- package/src/read/user-active-twaps/user-active-twaps.types.ts +33 -0
- package/src/read/user-bulk-orders/user-bulk-orders.reader.ts +37 -0
- package/src/read/user-bulk-orders/user-bulk-orders.types.ts +32 -0
- package/src/read/user-funding-history/user-funding-history.reader.ts +38 -0
- package/src/read/user-funding-history/user-funding-history.types.ts +29 -0
- package/src/read/user-notifications/user-notifications.reader.ts +17 -0
- package/src/read/user-notifications/user-notifications.types.ts +61 -0
- package/src/read/user-open-orders/user-open-orders.reader.ts +36 -0
- package/src/read/user-open-orders/user-open-orders.types.ts +42 -0
- package/src/read/user-order-history/user-order-history.reader.ts +34 -0
- package/src/read/user-order-history/user-order-history.types.ts +44 -0
- package/src/read/user-positions/user-positions.reader.ts +55 -0
- package/src/read/user-positions/user-positions.types.ts +43 -0
- package/src/read/user-subaccounts/user-subaccounts.reader.ts +30 -0
- package/src/read/user-subaccounts/user-subaccounts.types.ts +21 -0
- package/src/read/user-trade-history/user-trade-history.reader.ts +38 -0
- package/src/read/user-trade-history/user-trade-history.types.ts +33 -0
- package/src/read/vaults/vaults.reader.ts +79 -0
- package/src/read/vaults/vaults.types.ts +106 -0
- package/src/read/ws-subscription.ts +200 -0
- package/src/subaccount-types.ts +31 -0
- package/src/transaction-builder.ts +75 -0
- package/src/utils.ts +255 -0
- package/src/write.ts +965 -0
- package/tsconfig.json +8 -0
package/dist/write.js
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DecibelWriteDex = exports.TimeInForce = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
const order_status_1 = require("./order-status");
|
|
6
|
+
const subaccount_types_1 = require("./subaccount-types");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
exports.TimeInForce = {
|
|
9
|
+
GoodTillCanceled: 0,
|
|
10
|
+
PostOnly: 1,
|
|
11
|
+
ImmediateOrCancel: 2,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Rounds price to the nearest tick size multiple
|
|
15
|
+
* @param price The price to round
|
|
16
|
+
* @param tickSize The market's tick size
|
|
17
|
+
* @returns Price rounded to nearest tick size multiple
|
|
18
|
+
*/
|
|
19
|
+
function roundToTickSize(price, tickSize) {
|
|
20
|
+
if (price === 0 || tickSize === 0)
|
|
21
|
+
return 0;
|
|
22
|
+
return Math.round(price / tickSize) * tickSize;
|
|
23
|
+
}
|
|
24
|
+
class DecibelWriteDex extends base_1.BaseSDK {
|
|
25
|
+
cache;
|
|
26
|
+
orderStatusClient;
|
|
27
|
+
constructor(config, account, opts) {
|
|
28
|
+
super(config, account, opts);
|
|
29
|
+
this.cache = {};
|
|
30
|
+
this.orderStatusClient = new order_status_1.OrderStatusClient(config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Extract order_id from OrderEvent in transaction response
|
|
34
|
+
*/
|
|
35
|
+
extractOrderIdFromTransaction(txResponse, subaccountAddr) {
|
|
36
|
+
const orderEvents = ["market_types::OrderEvent", "async_matching_engine::TwapEvent"];
|
|
37
|
+
try {
|
|
38
|
+
// Check if the response is a UserTransactionResponse with events
|
|
39
|
+
if ("events" in txResponse && Array.isArray(txResponse.events)) {
|
|
40
|
+
for (const event of txResponse.events) {
|
|
41
|
+
// Check if this is an OrderEvent from the market module
|
|
42
|
+
for (const orderEvent of orderEvents) {
|
|
43
|
+
if (event.type.includes(orderEvent)) {
|
|
44
|
+
const orderEvent = event.data;
|
|
45
|
+
// Verify the event's user field matches the subaccount placing the order
|
|
46
|
+
const userAddress = subaccountAddr ?? this.account.accountAddress;
|
|
47
|
+
const orderUserAddress = orderEvent.user;
|
|
48
|
+
const twapUserAddress = orderEvent.account;
|
|
49
|
+
if (orderUserAddress === userAddress || twapUserAddress === userAddress) {
|
|
50
|
+
return typeof orderEvent.order_id === "string"
|
|
51
|
+
? orderEvent.order_id
|
|
52
|
+
: orderEvent.order_id.order_id;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error("Error extracting order_id from transaction:", error);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async renameSubaccount({ subaccountAddress, newName }) {
|
|
66
|
+
return await (0, utils_1.postRequest)({
|
|
67
|
+
schema: subaccount_types_1.RenameSubaccountSchema,
|
|
68
|
+
url: `${this.config.tradingHttpUrl}/api/v1/subaccounts/${subaccountAddress}`,
|
|
69
|
+
body: { name: newName },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async createSubaccount() {
|
|
73
|
+
return await this.sendTx({
|
|
74
|
+
function: `${this.config.deployment.package}::dex_accounts::create_new_subaccount`,
|
|
75
|
+
typeArguments: [],
|
|
76
|
+
functionArguments: [],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async sendSubaccountTx(sendTx, subaccountAddr) {
|
|
80
|
+
if (!subaccountAddr) {
|
|
81
|
+
subaccountAddr = (0, utils_1.getPrimarySubaccountAddr)(this.account.accountAddress);
|
|
82
|
+
}
|
|
83
|
+
return await sendTx(subaccountAddr);
|
|
84
|
+
}
|
|
85
|
+
async withSubaccount(fn, subaccountAddr) {
|
|
86
|
+
if (!subaccountAddr) {
|
|
87
|
+
subaccountAddr = (0, utils_1.getPrimarySubaccountAddr)(this.account.accountAddress);
|
|
88
|
+
}
|
|
89
|
+
return await fn(subaccountAddr);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @param amount u64 amount of collateral to deposit
|
|
93
|
+
*/
|
|
94
|
+
async deposit(amount, subaccountAddr) {
|
|
95
|
+
if (!subaccountAddr) {
|
|
96
|
+
return await this.sendTx({
|
|
97
|
+
function: `${this.config.deployment.package}::dex_accounts::deposit_to_subaccount`,
|
|
98
|
+
typeArguments: [],
|
|
99
|
+
functionArguments: [this.config.deployment.usdc, amount],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
104
|
+
function: `${this.config.deployment.package}::dex_accounts::deposit_to_subaccount_at`,
|
|
105
|
+
typeArguments: [],
|
|
106
|
+
functionArguments: [subaccountAddr, this.config.deployment.usdc, amount],
|
|
107
|
+
}), subaccountAddr);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @param amount u64 amount of collateral to withdraw
|
|
112
|
+
*/
|
|
113
|
+
async withdraw(amount, subaccountAddr) {
|
|
114
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
115
|
+
function: `${this.config.deployment.package}::dex_accounts::withdraw_from_subaccount`,
|
|
116
|
+
typeArguments: [],
|
|
117
|
+
functionArguments: [subaccountAddr, this.config.deployment.usdc, amount],
|
|
118
|
+
}), subaccountAddr);
|
|
119
|
+
}
|
|
120
|
+
async configureUserSettingsForMarket({ marketAddr, subaccountAddr, isCross, userLeverage, }) {
|
|
121
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
122
|
+
function: `${this.config.deployment.package}::dex_accounts::configure_user_settings_for_market`,
|
|
123
|
+
typeArguments: [],
|
|
124
|
+
functionArguments: [subaccountAddr, marketAddr, isCross, userLeverage],
|
|
125
|
+
}), subaccountAddr);
|
|
126
|
+
}
|
|
127
|
+
async placeOrder({ marketName, price, size, isBuy, timeInForce, isReduceOnly, clientOrderId, stopPrice, tpTriggerPrice, tpLimitPrice, slTriggerPrice, slLimitPrice, builderAddr, builderFee, subaccountAddr, accountOverride, tickSize, }) {
|
|
128
|
+
try {
|
|
129
|
+
const marketAddr = (0, utils_1.getMarketAddr)(marketName, this.config.deployment.perpEngineGlobal);
|
|
130
|
+
// Apply tick size rounding if tickSize is provided
|
|
131
|
+
const roundedPrice = tickSize ? roundToTickSize(price, tickSize) : price;
|
|
132
|
+
const roundedStopPrice = stopPrice !== undefined && tickSize ? roundToTickSize(stopPrice, tickSize) : stopPrice;
|
|
133
|
+
const roundedTpTriggerPrice = tpTriggerPrice !== undefined && tickSize
|
|
134
|
+
? roundToTickSize(tpTriggerPrice, tickSize)
|
|
135
|
+
: tpTriggerPrice;
|
|
136
|
+
const roundedTpLimitPrice = tpLimitPrice !== undefined && tickSize
|
|
137
|
+
? roundToTickSize(tpLimitPrice, tickSize)
|
|
138
|
+
: tpLimitPrice;
|
|
139
|
+
const roundedSlTriggerPrice = slTriggerPrice !== undefined && tickSize
|
|
140
|
+
? roundToTickSize(slTriggerPrice, tickSize)
|
|
141
|
+
: slTriggerPrice;
|
|
142
|
+
const roundedSlLimitPrice = slLimitPrice !== undefined && tickSize
|
|
143
|
+
? roundToTickSize(slLimitPrice, tickSize)
|
|
144
|
+
: slLimitPrice;
|
|
145
|
+
const txResponse = await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
146
|
+
function: `${this.config.deployment.package}::dex_accounts::place_order_to_subaccount`,
|
|
147
|
+
typeArguments: [],
|
|
148
|
+
functionArguments: [
|
|
149
|
+
subaccountAddr,
|
|
150
|
+
marketAddr.toString(),
|
|
151
|
+
roundedPrice,
|
|
152
|
+
size,
|
|
153
|
+
isBuy,
|
|
154
|
+
timeInForce,
|
|
155
|
+
isReduceOnly,
|
|
156
|
+
clientOrderId,
|
|
157
|
+
roundedStopPrice,
|
|
158
|
+
roundedTpTriggerPrice,
|
|
159
|
+
roundedTpLimitPrice,
|
|
160
|
+
roundedSlTriggerPrice,
|
|
161
|
+
roundedSlLimitPrice,
|
|
162
|
+
builderAddr,
|
|
163
|
+
builderFee,
|
|
164
|
+
],
|
|
165
|
+
}, accountOverride), subaccountAddr);
|
|
166
|
+
// Extract order_id from the transaction events
|
|
167
|
+
const orderId = this.extractOrderIdFromTransaction(txResponse, subaccountAddr);
|
|
168
|
+
return {
|
|
169
|
+
success: true,
|
|
170
|
+
orderId: orderId || undefined,
|
|
171
|
+
transactionHash: txResponse.hash,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error("Error placing order:", error);
|
|
176
|
+
return {
|
|
177
|
+
success: false,
|
|
178
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async triggerMatching({ marketAddr, maxWorkUnit }) {
|
|
183
|
+
const txResponse = await this.sendTx({
|
|
184
|
+
function: `${this.config.deployment.package}::public_apis::trigger_matching`,
|
|
185
|
+
typeArguments: [],
|
|
186
|
+
functionArguments: [marketAddr, maxWorkUnit],
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
success: true,
|
|
190
|
+
transactionHash: txResponse.hash,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async placeTwapOrder({ marketName, size, isBuy, isReduceOnly, twapFrequencySeconds, twapDurationSeconds, builderAddress, builderFees, subaccountAddr, accountOverride, }) {
|
|
194
|
+
const marketAddr = (0, utils_1.getMarketAddr)(marketName, this.config.deployment.perpEngineGlobal);
|
|
195
|
+
const txResponse = await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
196
|
+
function: `${this.config.deployment.package}::dex_accounts::place_twap_order_to_subaccount`,
|
|
197
|
+
typeArguments: [],
|
|
198
|
+
functionArguments: [
|
|
199
|
+
subaccountAddr,
|
|
200
|
+
marketAddr.toString(),
|
|
201
|
+
size,
|
|
202
|
+
isBuy,
|
|
203
|
+
isReduceOnly,
|
|
204
|
+
twapFrequencySeconds,
|
|
205
|
+
twapDurationSeconds,
|
|
206
|
+
builderAddress,
|
|
207
|
+
builderFees,
|
|
208
|
+
],
|
|
209
|
+
}, accountOverride), subaccountAddr);
|
|
210
|
+
const orderId = this.extractOrderIdFromTransaction(txResponse, subaccountAddr);
|
|
211
|
+
return {
|
|
212
|
+
success: true,
|
|
213
|
+
orderId: orderId || undefined,
|
|
214
|
+
transactionHash: txResponse.hash,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Cancel an order on the exchange
|
|
219
|
+
* @param orderId The id of the order to cancel
|
|
220
|
+
* @param marketId The id of the market the order is in
|
|
221
|
+
* @param subaccountAddr Optional subaccount address, will use primary if not provided
|
|
222
|
+
* @returns Transaction response
|
|
223
|
+
*/
|
|
224
|
+
async cancelOrder({ orderId, subaccountAddr, accountOverride, ...args }) {
|
|
225
|
+
// Either marketName or marketAddr must be provided
|
|
226
|
+
const marketAddr = "marketName" in args
|
|
227
|
+
? (0, utils_1.getMarketAddr)(args.marketName, this.config.deployment.perpEngineGlobal)
|
|
228
|
+
: args.marketAddr;
|
|
229
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
230
|
+
function: `${this.config.deployment.package}::dex_accounts::cancel_order_to_subaccount`,
|
|
231
|
+
typeArguments: [],
|
|
232
|
+
functionArguments: [subaccountAddr, BigInt(orderId.toString()), marketAddr.toString()],
|
|
233
|
+
}, accountOverride), subaccountAddr);
|
|
234
|
+
}
|
|
235
|
+
async cancelClientOrder({ clientOrderId, marketName, subaccountAddr, accountOverride, }) {
|
|
236
|
+
const marketAddr = (0, utils_1.getMarketAddr)(marketName, this.config.deployment.perpEngineGlobal);
|
|
237
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
238
|
+
function: `${this.config.deployment.package}::dex_accounts::cancel_client_order_to_subaccount`,
|
|
239
|
+
typeArguments: [],
|
|
240
|
+
functionArguments: [subaccountAddr, clientOrderId, marketAddr.toString()],
|
|
241
|
+
}, accountOverride), subaccountAddr);
|
|
242
|
+
}
|
|
243
|
+
async delegateTradingTo({ subaccountAddr, accountToDelegateTo, }) {
|
|
244
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
245
|
+
function: `${this.config.deployment.package}::dex_accounts::delegate_trading_to`,
|
|
246
|
+
typeArguments: [],
|
|
247
|
+
functionArguments: [subaccountAddr, accountToDelegateTo],
|
|
248
|
+
}), subaccountAddr);
|
|
249
|
+
}
|
|
250
|
+
async revokeDelegation({ subaccountAddr, accountToRevoke, }) {
|
|
251
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
252
|
+
function: `${this.config.deployment.package}::dex_accounts::revoke_delegation`,
|
|
253
|
+
typeArguments: [],
|
|
254
|
+
functionArguments: [subaccountAddr, accountToRevoke],
|
|
255
|
+
}), subaccountAddr);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Place a TP/SL order for a position
|
|
259
|
+
*/
|
|
260
|
+
async placeTpSlOrderForPosition({ marketAddr, tpTriggerPrice, tpLimitPrice, tpSize, slTriggerPrice, slLimitPrice, slSize, subaccountAddr, accountOverride, tickSize, }) {
|
|
261
|
+
const roundedTpTriggerPrice = tpTriggerPrice !== undefined && tickSize
|
|
262
|
+
? roundToTickSize(tpTriggerPrice, tickSize)
|
|
263
|
+
: tpTriggerPrice;
|
|
264
|
+
const roundedTpLimitPrice = tpLimitPrice !== undefined && tickSize
|
|
265
|
+
? roundToTickSize(tpLimitPrice, tickSize)
|
|
266
|
+
: tpLimitPrice;
|
|
267
|
+
const roundedSlTriggerPrice = slTriggerPrice !== undefined && tickSize
|
|
268
|
+
? roundToTickSize(slTriggerPrice, tickSize)
|
|
269
|
+
: slTriggerPrice;
|
|
270
|
+
const roundedSlLimitPrice = slLimitPrice !== undefined && tickSize
|
|
271
|
+
? roundToTickSize(slLimitPrice, tickSize)
|
|
272
|
+
: slLimitPrice;
|
|
273
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
274
|
+
function: `${this.config.deployment.package}::dex_accounts::place_tp_sl_order_for_position`,
|
|
275
|
+
typeArguments: [],
|
|
276
|
+
functionArguments: [
|
|
277
|
+
subaccountAddr,
|
|
278
|
+
marketAddr,
|
|
279
|
+
roundedTpTriggerPrice,
|
|
280
|
+
roundedTpLimitPrice,
|
|
281
|
+
tpSize,
|
|
282
|
+
roundedSlTriggerPrice,
|
|
283
|
+
roundedSlLimitPrice,
|
|
284
|
+
slSize,
|
|
285
|
+
undefined, // builderAddr
|
|
286
|
+
undefined, // builderFees
|
|
287
|
+
],
|
|
288
|
+
}, accountOverride), subaccountAddr);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Update TP for a position
|
|
292
|
+
*/
|
|
293
|
+
async updateTpOrderForPosition({ marketAddr, prevOrderId, tpTriggerPrice, tpLimitPrice, tpSize, subaccountAddr, accountOverride, }) {
|
|
294
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
295
|
+
function: `${this.config.deployment.package}::dex_accounts::update_tp_order_for_position`,
|
|
296
|
+
typeArguments: [],
|
|
297
|
+
functionArguments: [
|
|
298
|
+
subaccountAddr,
|
|
299
|
+
BigInt(prevOrderId.toString()),
|
|
300
|
+
marketAddr,
|
|
301
|
+
tpTriggerPrice,
|
|
302
|
+
tpLimitPrice,
|
|
303
|
+
tpSize,
|
|
304
|
+
],
|
|
305
|
+
}, accountOverride), subaccountAddr);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Update SL for a position
|
|
309
|
+
*/
|
|
310
|
+
async updateSlOrderForPosition({ marketAddr, prevOrderId, slTriggerPrice, slLimitPrice, slSize, subaccountAddr, accountOverride, }) {
|
|
311
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
312
|
+
function: `${this.config.deployment.package}::dex_accounts::update_sl_order_for_position`,
|
|
313
|
+
typeArguments: [],
|
|
314
|
+
functionArguments: [
|
|
315
|
+
subaccountAddr,
|
|
316
|
+
BigInt(prevOrderId.toString()),
|
|
317
|
+
marketAddr,
|
|
318
|
+
slTriggerPrice,
|
|
319
|
+
slLimitPrice,
|
|
320
|
+
slSize,
|
|
321
|
+
],
|
|
322
|
+
}, accountOverride), subaccountAddr);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Cancel a TP/SL order for a position
|
|
326
|
+
*/
|
|
327
|
+
async cancelTpSlOrderForPosition({ marketAddr, orderId, subaccountAddr, accountOverride, }) {
|
|
328
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
329
|
+
function: `${this.config.deployment.package}::dex_accounts::cancel_tp_sl_order_for_position`,
|
|
330
|
+
typeArguments: [],
|
|
331
|
+
functionArguments: [subaccountAddr, marketAddr, BigInt(orderId.toString())],
|
|
332
|
+
}, accountOverride), subaccountAddr);
|
|
333
|
+
}
|
|
334
|
+
async cancelTwapOrder({ orderId, marketAddr, subaccountAddr, accountOverride, }) {
|
|
335
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
336
|
+
function: `${this.config.deployment.package}::dex_accounts::cancel_twap_orders_to_subaccount`,
|
|
337
|
+
typeArguments: [],
|
|
338
|
+
functionArguments: [subaccountAddr, marketAddr, orderId],
|
|
339
|
+
}, accountOverride), subaccountAddr);
|
|
340
|
+
}
|
|
341
|
+
async buildDeactiveSubaccountTx({ subaccountAddr, revokeAllDelegations = true, signerAddress, }) {
|
|
342
|
+
const transaction = await this.buildTx({
|
|
343
|
+
function: `${this.config.deployment.package}::dex_accounts::deactivate_subaccount`,
|
|
344
|
+
typeArguments: [],
|
|
345
|
+
functionArguments: [subaccountAddr, revokeAllDelegations],
|
|
346
|
+
}, signerAddress);
|
|
347
|
+
return transaction;
|
|
348
|
+
}
|
|
349
|
+
// ======= VAULT FUNCTIONS =======
|
|
350
|
+
// @Todo: We can move this to another Class and this doesnt requires subaccount so dont belong in here
|
|
351
|
+
/**
|
|
352
|
+
* Create a new vault with optional initial funding
|
|
353
|
+
*/
|
|
354
|
+
async buildCreateVaultTx({ contributionAssetType, vaultName, vaultShareSymbol, vaultShareIconUri = "", vaultShareProjectUri = "", feeBps, feeIntervalS, contributionLockupDurationS, initialFunding = 0, acceptsContributions = false, delegateToCreator = false, signerAddress, vaultDescription, vaultSocialLinks, }) {
|
|
355
|
+
const transaction = await this.buildTx({
|
|
356
|
+
function: `${this.config.deployment.package}::vault::create_and_fund_vault`,
|
|
357
|
+
typeArguments: [],
|
|
358
|
+
functionArguments: [
|
|
359
|
+
contributionAssetType,
|
|
360
|
+
vaultName,
|
|
361
|
+
vaultDescription,
|
|
362
|
+
vaultSocialLinks,
|
|
363
|
+
vaultShareSymbol,
|
|
364
|
+
vaultShareIconUri,
|
|
365
|
+
vaultShareProjectUri,
|
|
366
|
+
feeBps,
|
|
367
|
+
feeIntervalS,
|
|
368
|
+
contributionLockupDurationS,
|
|
369
|
+
initialFunding,
|
|
370
|
+
acceptsContributions,
|
|
371
|
+
delegateToCreator,
|
|
372
|
+
],
|
|
373
|
+
}, signerAddress);
|
|
374
|
+
return transaction;
|
|
375
|
+
}
|
|
376
|
+
async createVault(args) {
|
|
377
|
+
const txResponse = await this.sendSubaccountTx(() => this.sendTx({
|
|
378
|
+
function: `${this.config.deployment.package}::vault::create_and_fund_vault`,
|
|
379
|
+
typeArguments: [],
|
|
380
|
+
functionArguments: [
|
|
381
|
+
args.contributionAssetType,
|
|
382
|
+
args.vaultName,
|
|
383
|
+
args.vaultDescription,
|
|
384
|
+
args.vaultSocialLinks,
|
|
385
|
+
args.vaultShareSymbol,
|
|
386
|
+
args.vaultShareIconUri,
|
|
387
|
+
args.vaultShareProjectUri,
|
|
388
|
+
args.feeBps,
|
|
389
|
+
args.feeIntervalS,
|
|
390
|
+
args.contributionLockupDurationS,
|
|
391
|
+
args.initialFunding,
|
|
392
|
+
args.acceptsContributions,
|
|
393
|
+
args.delegateToCreator,
|
|
394
|
+
],
|
|
395
|
+
}, args.accountOverride), args.subaccountAddr);
|
|
396
|
+
return txResponse;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Activate a vault to accept contributions
|
|
400
|
+
*/
|
|
401
|
+
async buildActivateVaultTx({ vaultAddress, additionalFunding = 0, signerAddress, }) {
|
|
402
|
+
return await this.buildTx({
|
|
403
|
+
function: `${this.config.deployment.package}::vault::activate_vault`,
|
|
404
|
+
typeArguments: [],
|
|
405
|
+
functionArguments: [vaultAddress, additionalFunding],
|
|
406
|
+
}, signerAddress);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Contribute funds to a vault in exchange for shares
|
|
410
|
+
*/
|
|
411
|
+
async buildDepositToVaultTx({ vaultAddress, amount, signerAddress, }) {
|
|
412
|
+
return await this.buildTx({
|
|
413
|
+
function: `${this.config.deployment.package}::vault::contribute`,
|
|
414
|
+
typeArguments: [],
|
|
415
|
+
functionArguments: [vaultAddress, amount],
|
|
416
|
+
}, signerAddress);
|
|
417
|
+
}
|
|
418
|
+
async depositToVault(args) {
|
|
419
|
+
const txResponse = await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
420
|
+
function: `${this.config.deployment.package}::dex_accounts_vault_extension::contribute_to_vault`,
|
|
421
|
+
typeArguments: [],
|
|
422
|
+
functionArguments: [
|
|
423
|
+
subaccountAddr,
|
|
424
|
+
args.vaultAddress,
|
|
425
|
+
this.config.deployment.usdc,
|
|
426
|
+
args.amount,
|
|
427
|
+
],
|
|
428
|
+
}), args.subaccountAddr);
|
|
429
|
+
return txResponse;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Redeem shares from a vault for underlying assets
|
|
433
|
+
*/
|
|
434
|
+
async buildWithdrawFromVaultTx({ vaultAddress, shares, signerAddress, }) {
|
|
435
|
+
return await this.buildTx({
|
|
436
|
+
function: `${this.config.deployment.package}::vault::redeem`,
|
|
437
|
+
typeArguments: [],
|
|
438
|
+
functionArguments: [vaultAddress, shares],
|
|
439
|
+
}, signerAddress);
|
|
440
|
+
}
|
|
441
|
+
async withdrawFromVault(args) {
|
|
442
|
+
const txResponse = await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
443
|
+
function: `${this.config.deployment.package}::dex_accounts_vault_extension::redeem_from_vault`,
|
|
444
|
+
typeArguments: [],
|
|
445
|
+
functionArguments: [subaccountAddr, args.vaultAddress, args.shares],
|
|
446
|
+
}, args.accountOverride), args.subaccountAddr);
|
|
447
|
+
return txResponse;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Delegate trading to another account for a vault
|
|
451
|
+
*/
|
|
452
|
+
async buildDelegateDexActionsToTx({ vaultAddress, accountToDelegateTo, signerAddress, expirationTimestampSecs, }) {
|
|
453
|
+
return await this.buildTx({
|
|
454
|
+
function: `${this.config.deployment.package}::vault::delegate_dex_actions_to`,
|
|
455
|
+
typeArguments: [],
|
|
456
|
+
functionArguments: [vaultAddress, accountToDelegateTo, expirationTimestampSecs],
|
|
457
|
+
}, signerAddress);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Approve max builder fee for a subaccount
|
|
461
|
+
* @param builderAddr The address of the builder
|
|
462
|
+
* @param maxFee The maximum fee in basis points (e.g., 100 = 0.01%)
|
|
463
|
+
* @param subaccountAddr Optional subaccount address, will use primary if not provided
|
|
464
|
+
*/
|
|
465
|
+
async approveMaxBuilderFee({ builderAddr, maxFee, subaccountAddr, }) {
|
|
466
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
467
|
+
function: `${this.config.deployment.package}::dex_accounts::approve_max_builder_fee_for_subaccount`,
|
|
468
|
+
typeArguments: [],
|
|
469
|
+
functionArguments: [subaccountAddr, builderAddr, maxFee],
|
|
470
|
+
}), subaccountAddr);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Revoke max builder fee for a subaccount
|
|
474
|
+
* @param builderAddr The address of the builder
|
|
475
|
+
* @param subaccountAddr Optional subaccount address, will use primary if not provided
|
|
476
|
+
*/
|
|
477
|
+
async revokeMaxBuilderFee({ builderAddr, subaccountAddr, }) {
|
|
478
|
+
return await this.sendSubaccountTx((subaccountAddr) => this.sendTx({
|
|
479
|
+
function: `${this.config.deployment.package}::dex_accounts::revoke_max_builder_fee_for_subaccount`,
|
|
480
|
+
typeArguments: [],
|
|
481
|
+
functionArguments: [subaccountAddr, builderAddr],
|
|
482
|
+
}), subaccountAddr);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
exports.DecibelWriteDex = DecibelWriteDex;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { baseConfig } from "@decibeltrade/eslint-config/base";
|
|
4
|
+
import { dirname } from "path";
|
|
5
|
+
import tseslint from "typescript-eslint";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
export default tseslint.config(
|
|
12
|
+
{
|
|
13
|
+
languageOptions: {
|
|
14
|
+
parserOptions: {
|
|
15
|
+
ecmaVersion: "latest",
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
projectService: {
|
|
18
|
+
allowDefaultProject: ["*.mjs"],
|
|
19
|
+
},
|
|
20
|
+
tsconfigRootDir: __dirname,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
baseConfig,
|
|
25
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@decibeltrade/sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"test": "vitest run --passWithNoTests",
|
|
16
|
+
"lint": "eslint src --fix --max-warnings 0",
|
|
17
|
+
"lint:check": "eslint src --max-warnings 0",
|
|
18
|
+
"generate:abis": "tsx src/abi/generate-abis.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"isomorphic-ws": "^5.0.0",
|
|
22
|
+
"ws": "^8.18.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@aptos-labs/ts-sdk": "^5.1.2",
|
|
26
|
+
"@types/ws": "^8.18.0",
|
|
27
|
+
"zod": "^3.25.62"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@decibeltrade/eslint-config": "workspace:*",
|
|
31
|
+
"@decibeltrade/tsconfig": "workspace:*",
|
|
32
|
+
"@types/estree": "^1.0.6",
|
|
33
|
+
"eslint": "^9.28.0",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"typescript-eslint": "^8.46.2",
|
|
36
|
+
"tsx": "^4.20.5",
|
|
37
|
+
"vitest": "^3.1.1"
|
|
38
|
+
}
|
|
39
|
+
}
|