@decibeltrade/sdk 0.2.2 → 0.2.4
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/dist/abi/generate-abis.js +9 -44
- package/dist/abi/types.js +1 -2
- package/dist/admin.js +10 -14
- package/dist/base.d.ts +1 -0
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +22 -26
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +37 -43
- package/dist/fee-pay.js +1 -4
- package/dist/gas/gas-price-manager.js +3 -7
- package/dist/index.js +10 -26
- package/dist/order-event.types.js +1 -2
- package/dist/order-status.js +16 -23
- package/dist/read/account-overview/account-overview.reader.js +5 -9
- package/dist/read/account-overview/account-overview.types.d.ts +7 -7
- package/dist/read/account-overview/account-overview.types.js +23 -29
- package/dist/read/base-reader.js +5 -9
- package/dist/read/candlesticks/candlesticks.reader.js +8 -12
- package/dist/read/candlesticks/candlesticks.types.js +14 -20
- package/dist/read/delegations/delegations.reader.js +4 -8
- package/dist/read/delegations/delegations.types.js +6 -12
- package/dist/read/index.js +50 -68
- package/dist/read/leaderboard/leaderboard.reader.js +6 -10
- package/dist/read/leaderboard/leaderboard.types.js +10 -13
- package/dist/read/market-contexts/market-contexts.reader.js +4 -8
- package/dist/read/market-contexts/market-contexts.types.js +11 -17
- package/dist/read/market-depth/market-depth.reader.js +9 -13
- package/dist/read/market-depth/market-depth.types.js +8 -14
- package/dist/read/market-prices/market-prices.reader.js +11 -15
- package/dist/read/market-prices/market-prices.types.js +22 -25
- package/dist/read/market-trades/market-trades.reader.js +8 -12
- package/dist/read/market-trades/market-trades.types.js +18 -21
- package/dist/read/markets/markets.reader.js +7 -11
- package/dist/read/markets/markets.types.js +32 -35
- package/dist/read/pagination.types.js +4 -11
- package/dist/read/portfolio-chart/portfolio-chart.reader.js +4 -8
- package/dist/read/portfolio-chart/portfolio-chart.types.js +5 -11
- package/dist/read/types.js +58 -75
- package/dist/read/user-active-twaps/user-active-twaps.reader.js +5 -9
- package/dist/read/user-active-twaps/user-active-twaps.types.js +18 -24
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +5 -9
- package/dist/read/user-bulk-orders/user-bulk-orders.types.js +16 -22
- package/dist/read/user-funding-history/user-funding-history.reader.js +5 -9
- package/dist/read/user-funding-history/user-funding-history.types.js +13 -19
- package/dist/read/user-notifications/user-notifications.reader.js +4 -8
- package/dist/read/user-notifications/user-notifications.types.js +19 -25
- package/dist/read/user-open-orders/user-open-orders.reader.js +5 -9
- package/dist/read/user-open-orders/user-open-orders.types.js +27 -33
- package/dist/read/user-order-history/user-order-history.reader.js +5 -9
- package/dist/read/user-order-history/user-order-history.types.js +32 -38
- package/dist/read/user-positions/user-positions.reader.js +5 -9
- package/dist/read/user-positions/user-positions.types.d.ts +13 -13
- package/dist/read/user-positions/user-positions.types.js +21 -27
- package/dist/read/user-subaccounts/user-subaccounts.reader.js +4 -8
- package/dist/read/user-subaccounts/user-subaccounts.types.js +8 -14
- package/dist/read/user-trade-history/user-trade-history.reader.js +5 -9
- package/dist/read/user-trade-history/user-trade-history.types.js +18 -24
- package/dist/read/vaults/vaults.reader.js +6 -10
- package/dist/read/vaults/vaults.types.js +53 -59
- package/dist/read/ws-subscription.d.ts +1 -1
- package/dist/read/ws-subscription.js +12 -19
- package/dist/subaccount-types.js +4 -10
- package/dist/transaction-builder.js +11 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.d.ts +4 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +46 -49
- package/dist/write.d.ts +2 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +22 -26
- package/package.json +1 -1
- package/src/read/ws-subscription.ts +2 -2
- package/src/write.ts +3 -3
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_reader_1 = require("../base-reader");
|
|
5
|
-
const user_subaccounts_types_1 = require("./user-subaccounts.types");
|
|
6
|
-
class UserSubaccountsReader extends base_reader_1.BaseReader {
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { UserSubaccountsSchema } from "./user-subaccounts.types";
|
|
3
|
+
export class UserSubaccountsReader extends BaseReader {
|
|
7
4
|
/**
|
|
8
5
|
* Get the subaccounts for a given user
|
|
9
6
|
* @param ownerAddr The address of the owner to get subaccounts for
|
|
@@ -18,7 +15,7 @@ class UserSubaccountsReader extends base_reader_1.BaseReader {
|
|
|
18
15
|
// limit: limit.toString(),
|
|
19
16
|
});
|
|
20
17
|
const response = await this.getRequest({
|
|
21
|
-
schema:
|
|
18
|
+
schema: UserSubaccountsSchema,
|
|
22
19
|
url: `${this.deps.config.tradingHttpUrl}/api/v1/subaccounts`, // TODO: update to /user_subaccounts?
|
|
23
20
|
queryParams,
|
|
24
21
|
options: fetchOptions,
|
|
@@ -26,4 +23,3 @@ class UserSubaccountsReader extends base_reader_1.BaseReader {
|
|
|
26
23
|
return response.data;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.UserSubaccountsReader = UserSubaccountsReader;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.UserSubaccountSchema = v4_1.default.object({
|
|
9
|
-
subaccount_address: v4_1.default.string(),
|
|
10
|
-
primary_account_address: v4_1.default.string(),
|
|
11
|
-
is_primary: v4_1.default.boolean(),
|
|
12
|
-
is_active: v4_1.default.boolean().optional(),
|
|
13
|
-
custom_label: v4_1.default.string().nullable(),
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const UserSubaccountSchema = z.object({
|
|
3
|
+
subaccount_address: z.string(),
|
|
4
|
+
primary_account_address: z.string(),
|
|
5
|
+
is_primary: z.boolean(),
|
|
6
|
+
is_active: z.boolean().optional(),
|
|
7
|
+
custom_label: z.string().nullable(),
|
|
14
8
|
});
|
|
15
|
-
|
|
9
|
+
export const UserSubaccountsSchema = z.array(UserSubaccountSchema);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_reader_1 = require("../base-reader");
|
|
5
|
-
const user_trade_history_types_1 = require("./user-trade-history.types");
|
|
6
|
-
class UserTradeHistoryReader extends base_reader_1.BaseReader {
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { UserTradesSchema, UserTradesWsMessageSchema, } from "./user-trade-history.types";
|
|
3
|
+
export class UserTradeHistoryReader extends BaseReader {
|
|
7
4
|
/**
|
|
8
5
|
* Get the trade history for a given user
|
|
9
6
|
* @param subAddr The subaccount address of the user to get trade history for
|
|
@@ -12,7 +9,7 @@ class UserTradeHistoryReader extends base_reader_1.BaseReader {
|
|
|
12
9
|
*/
|
|
13
10
|
async getByAddr({ subAddr, limit = 10, fetchOptions }) {
|
|
14
11
|
const response = await this.getRequest({
|
|
15
|
-
schema:
|
|
12
|
+
schema: UserTradesSchema,
|
|
16
13
|
url: `${this.deps.config.tradingHttpUrl}/api/v1/trade_history`,
|
|
17
14
|
queryParams: { user: subAddr, limit: limit.toString() },
|
|
18
15
|
options: fetchOptions,
|
|
@@ -27,7 +24,6 @@ class UserTradeHistoryReader extends base_reader_1.BaseReader {
|
|
|
27
24
|
*/
|
|
28
25
|
subscribeByAddr(subAddr, onData) {
|
|
29
26
|
const topic = `user_trades:${subAddr}`;
|
|
30
|
-
return this.deps.ws.subscribe(topic,
|
|
27
|
+
return this.deps.ws.subscribe(topic, UserTradesWsMessageSchema, onData);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.UserTradeHistoryReader = UserTradeHistoryReader;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
is_funding_positive: v4_1.default.boolean(),
|
|
17
|
-
realized_funding_amount: v4_1.default.number(),
|
|
18
|
-
is_rebate: v4_1.default.boolean(),
|
|
19
|
-
fee_amount: v4_1.default.number(),
|
|
20
|
-
transaction_unix_ms: v4_1.default.number(),
|
|
21
|
-
transaction_version: v4_1.default.number(),
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const UserTradeSchema = z.object({
|
|
3
|
+
account: z.string(),
|
|
4
|
+
market: z.string(),
|
|
5
|
+
action: z.string(),
|
|
6
|
+
size: z.number(),
|
|
7
|
+
price: z.number(),
|
|
8
|
+
is_profit: z.boolean(),
|
|
9
|
+
realized_pnl_amount: z.number(),
|
|
10
|
+
is_funding_positive: z.boolean(),
|
|
11
|
+
realized_funding_amount: z.number(),
|
|
12
|
+
is_rebate: z.boolean(),
|
|
13
|
+
fee_amount: z.number(),
|
|
14
|
+
transaction_unix_ms: z.number(),
|
|
15
|
+
transaction_version: z.number(),
|
|
22
16
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
trades:
|
|
17
|
+
export const UserTradesSchema = z.array(UserTradeSchema);
|
|
18
|
+
export const UserTradesWsMessageSchema = z.object({
|
|
19
|
+
trades: z.array(UserTradeSchema),
|
|
26
20
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_reader_1 = require("../base-reader");
|
|
5
|
-
const vaults_types_1 = require("./vaults.types");
|
|
6
|
-
class VaultsReader extends base_reader_1.BaseReader {
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { UserOwnedVaultsResponseSchema, UserPerformancesOnVaultsResponseSchema, VaultsResponseSchema, } from "./vaults.types";
|
|
3
|
+
export class VaultsReader extends BaseReader {
|
|
7
4
|
/**
|
|
8
5
|
* Get all vaults
|
|
9
6
|
* @returns All vaults
|
|
@@ -21,7 +18,7 @@ class VaultsReader extends base_reader_1.BaseReader {
|
|
|
21
18
|
if (args.search)
|
|
22
19
|
queryParams.set("search", args.search);
|
|
23
20
|
const response = await this.getRequest({
|
|
24
|
-
schema:
|
|
21
|
+
schema: VaultsResponseSchema,
|
|
25
22
|
url: `${this.deps.config.tradingHttpUrl}/api/v1/vaults`,
|
|
26
23
|
queryParams,
|
|
27
24
|
options: fetchOptions,
|
|
@@ -42,7 +39,7 @@ class VaultsReader extends base_reader_1.BaseReader {
|
|
|
42
39
|
if (args.offset)
|
|
43
40
|
queryParams.set("offset", args.offset.toString());
|
|
44
41
|
const response = await this.getRequest({
|
|
45
|
-
schema:
|
|
42
|
+
schema: UserOwnedVaultsResponseSchema,
|
|
46
43
|
url: `${this.deps.config.tradingHttpUrl}/api/v1/user_owned_vaults`,
|
|
47
44
|
queryParams,
|
|
48
45
|
options: fetchOptions,
|
|
@@ -59,7 +56,7 @@ class VaultsReader extends base_reader_1.BaseReader {
|
|
|
59
56
|
user_address: args.ownerAddr,
|
|
60
57
|
});
|
|
61
58
|
const response = await this.getRequest({
|
|
62
|
-
schema:
|
|
59
|
+
schema: UserPerformancesOnVaultsResponseSchema,
|
|
63
60
|
url: `${this.deps.config.tradingHttpUrl}/api/v1/user_vault_performance`,
|
|
64
61
|
queryParams,
|
|
65
62
|
options: fetchOptions,
|
|
@@ -67,4 +64,3 @@ class VaultsReader extends base_reader_1.BaseReader {
|
|
|
67
64
|
return response.data;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
exports.VaultsReader = VaultsReader;
|
|
@@ -1,75 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UserPerformancesOnVaultsResponseSchema = exports.UserPerformanceOnVaultSchema = exports.UserOwnedVaultsResponseSchema = exports.UserOwnedVaultSchema = exports.VaultsResponseSchema = exports.VaultSchema = exports.vaultTypeValues = void 0;
|
|
7
|
-
const v4_1 = __importDefault(require("zod/v4"));
|
|
8
|
-
const pagination_types_1 = require("../pagination.types");
|
|
9
|
-
exports.vaultTypeValues = ["user", "protocol"];
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
import { PaginatedResponseSchema } from "../pagination.types";
|
|
3
|
+
export const vaultTypeValues = ["user", "protocol"];
|
|
10
4
|
/**
|
|
11
5
|
* Schema for a vault in the protocol
|
|
12
6
|
* Represents both protocol-wide vaults and user-managed vaults
|
|
13
7
|
*/
|
|
14
|
-
|
|
15
|
-
address:
|
|
16
|
-
name:
|
|
17
|
-
description:
|
|
18
|
-
manager:
|
|
19
|
-
status:
|
|
20
|
-
created_at:
|
|
21
|
-
tvl:
|
|
22
|
-
volume:
|
|
23
|
-
all_time_return:
|
|
24
|
-
past_month_return:
|
|
25
|
-
sharpe_ratio:
|
|
26
|
-
max_drawdown:
|
|
27
|
-
weekly_win_rate_12w:
|
|
28
|
-
profit_share:
|
|
29
|
-
pnl_90d:
|
|
30
|
-
manager_avg_cash:
|
|
31
|
-
average_leverage:
|
|
32
|
-
depositors:
|
|
33
|
-
perp_equity:
|
|
34
|
-
vault_type:
|
|
35
|
-
pnl_history:
|
|
36
|
-
social_links:
|
|
8
|
+
export const VaultSchema = z.object({
|
|
9
|
+
address: z.string(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
description: z.string().nullable(),
|
|
12
|
+
manager: z.string(),
|
|
13
|
+
status: z.string(),
|
|
14
|
+
created_at: z.number(),
|
|
15
|
+
tvl: z.number().nullable(),
|
|
16
|
+
volume: z.number().nullable(),
|
|
17
|
+
all_time_return: z.number().nullable(),
|
|
18
|
+
past_month_return: z.number().nullable(),
|
|
19
|
+
sharpe_ratio: z.number().nullable(),
|
|
20
|
+
max_drawdown: z.number().nullable(),
|
|
21
|
+
weekly_win_rate_12w: z.number().nullable(),
|
|
22
|
+
profit_share: z.number().nullable(),
|
|
23
|
+
pnl_90d: z.number().nullable(),
|
|
24
|
+
manager_avg_cash: z.number().nullable(),
|
|
25
|
+
average_leverage: z.number().nullable(),
|
|
26
|
+
depositors: z.number().nullable(),
|
|
27
|
+
perp_equity: z.number().nullable(),
|
|
28
|
+
vault_type: z.enum(vaultTypeValues),
|
|
29
|
+
pnl_history: z.array(z.string()).nullable(),
|
|
30
|
+
social_links: z.array(z.string()).nullable(),
|
|
37
31
|
});
|
|
38
|
-
|
|
39
|
-
total_value_locked:
|
|
40
|
-
total_volume:
|
|
32
|
+
export const VaultsResponseSchema = PaginatedResponseSchema(VaultSchema).extend({
|
|
33
|
+
total_value_locked: z.number(),
|
|
34
|
+
total_volume: z.number(),
|
|
41
35
|
});
|
|
42
36
|
/**
|
|
43
37
|
* Schema for vaults owned/managed by a specific user
|
|
44
38
|
* Contains summary information about vaults the user manages
|
|
45
39
|
*/
|
|
46
|
-
|
|
47
|
-
vault_address:
|
|
48
|
-
vault_name:
|
|
49
|
-
vault_share_symbol:
|
|
50
|
-
status:
|
|
51
|
-
age_days:
|
|
52
|
-
num_managers:
|
|
53
|
-
tvl:
|
|
54
|
-
apr:
|
|
55
|
-
manager_equity:
|
|
56
|
-
manager_stake:
|
|
40
|
+
export const UserOwnedVaultSchema = z.object({
|
|
41
|
+
vault_address: z.string(),
|
|
42
|
+
vault_name: z.string(),
|
|
43
|
+
vault_share_symbol: z.string(),
|
|
44
|
+
status: z.string(),
|
|
45
|
+
age_days: z.number(),
|
|
46
|
+
num_managers: z.number(),
|
|
47
|
+
tvl: z.number().nullable(),
|
|
48
|
+
apr: z.number().nullable(),
|
|
49
|
+
manager_equity: z.number().nullable(),
|
|
50
|
+
manager_stake: z.number().nullable(),
|
|
57
51
|
});
|
|
58
|
-
|
|
52
|
+
export const UserOwnedVaultsResponseSchema = PaginatedResponseSchema(UserOwnedVaultSchema);
|
|
59
53
|
/**
|
|
60
54
|
* Schema for user performance metrics within a vault
|
|
61
55
|
* Tracks a user's deposits, shares, returns, and PnL for a specific vault
|
|
62
56
|
*/
|
|
63
|
-
|
|
64
|
-
vault_address:
|
|
65
|
-
user_address:
|
|
66
|
-
net_deposits:
|
|
67
|
-
current_num_shares:
|
|
68
|
-
current_value_of_shares:
|
|
69
|
-
all_time_return:
|
|
70
|
-
unrealized_pnl:
|
|
71
|
-
share_price:
|
|
72
|
-
volume:
|
|
73
|
-
weekly_win_rate_12w:
|
|
57
|
+
export const UserPerformanceOnVaultSchema = z.object({
|
|
58
|
+
vault_address: z.string(),
|
|
59
|
+
user_address: z.string(),
|
|
60
|
+
net_deposits: z.number().nullable(),
|
|
61
|
+
current_num_shares: z.number().nullable(),
|
|
62
|
+
current_value_of_shares: z.number().nullable(),
|
|
63
|
+
all_time_return: z.number().nullable(),
|
|
64
|
+
unrealized_pnl: z.number().nullable(),
|
|
65
|
+
share_price: z.number(),
|
|
66
|
+
volume: z.number(),
|
|
67
|
+
weekly_win_rate_12w: z.number().nullable(),
|
|
74
68
|
});
|
|
75
|
-
|
|
69
|
+
export const UserPerformancesOnVaultsResponseSchema = z.array(UserPerformanceOnVaultSchema);
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DecibelWsSubscription = void 0;
|
|
7
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
class DecibelWsSubscription {
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { bigIntReviver, prettifyMaybeZodError } from "../utils";
|
|
3
|
+
export class DecibelWsSubscription {
|
|
10
4
|
config;
|
|
11
5
|
onError;
|
|
12
6
|
constructor(config, onError) {
|
|
@@ -27,7 +21,7 @@ class DecibelWsSubscription {
|
|
|
27
21
|
return null;
|
|
28
22
|
}
|
|
29
23
|
try {
|
|
30
|
-
const jsonData = JSON.parse(data,
|
|
24
|
+
const jsonData = JSON.parse(data, bigIntReviver);
|
|
31
25
|
if (jsonData &&
|
|
32
26
|
typeof jsonData === "object" &&
|
|
33
27
|
"topic" in jsonData &&
|
|
@@ -45,12 +39,12 @@ class DecibelWsSubscription {
|
|
|
45
39
|
if (this.#ws) {
|
|
46
40
|
return;
|
|
47
41
|
}
|
|
48
|
-
const ws = new
|
|
42
|
+
const ws = new WebSocket(this.config.tradingWsUrl);
|
|
49
43
|
ws.addEventListener("open", () => {
|
|
50
44
|
this.#reconnectAttempts = 0;
|
|
51
|
-
this.#subscriptions.keys()
|
|
45
|
+
for (const topic of Array.from(this.#subscriptions.keys())) {
|
|
52
46
|
ws.send(this.#getSubscribeMessage(topic));
|
|
53
|
-
}
|
|
47
|
+
}
|
|
54
48
|
});
|
|
55
49
|
ws.addEventListener("message", (event) => {
|
|
56
50
|
if (typeof event.data === "string" &&
|
|
@@ -94,7 +88,7 @@ class DecibelWsSubscription {
|
|
|
94
88
|
const listeners = this.#subscriptions.get(topic) ?? new Set();
|
|
95
89
|
// If subscription arent found, subscribe to topic first
|
|
96
90
|
if (listeners.size === 0) {
|
|
97
|
-
if (this.#ws?.readyState ===
|
|
91
|
+
if (this.#ws?.readyState === WebSocket.OPEN) {
|
|
98
92
|
this.#ws.send(this.#getSubscribeMessage(topic));
|
|
99
93
|
}
|
|
100
94
|
}
|
|
@@ -104,7 +98,7 @@ class DecibelWsSubscription {
|
|
|
104
98
|
void onData(parsedData);
|
|
105
99
|
}
|
|
106
100
|
catch (e) {
|
|
107
|
-
throw
|
|
101
|
+
throw prettifyMaybeZodError(e);
|
|
108
102
|
}
|
|
109
103
|
};
|
|
110
104
|
listeners.add(listener);
|
|
@@ -119,7 +113,7 @@ class DecibelWsSubscription {
|
|
|
119
113
|
if (!this.#subscriptions.has(topic))
|
|
120
114
|
return;
|
|
121
115
|
this.#subscriptions.delete(topic);
|
|
122
|
-
if (this.#ws?.readyState ===
|
|
116
|
+
if (this.#ws?.readyState === WebSocket.OPEN) {
|
|
123
117
|
this.#ws.send(this.#getUnsubscribeMessage(topic));
|
|
124
118
|
}
|
|
125
119
|
// Close the WebSocket if the last subscription was removed.
|
|
@@ -159,7 +153,7 @@ class DecibelWsSubscription {
|
|
|
159
153
|
if (!this.#subscriptions.has(topic)) {
|
|
160
154
|
return;
|
|
161
155
|
}
|
|
162
|
-
if (this.#ws?.readyState ===
|
|
156
|
+
if (this.#ws?.readyState === WebSocket.OPEN) {
|
|
163
157
|
this.#ws.send(this.#getUnsubscribeMessage(topic));
|
|
164
158
|
this.#ws.send(this.#getSubscribeMessage(topic));
|
|
165
159
|
return;
|
|
@@ -170,7 +164,6 @@ class DecibelWsSubscription {
|
|
|
170
164
|
this.#ws?.close();
|
|
171
165
|
}
|
|
172
166
|
readyState() {
|
|
173
|
-
return this.#ws?.readyState ??
|
|
167
|
+
return this.#ws?.readyState ?? WebSocket.CLOSED;
|
|
174
168
|
}
|
|
175
169
|
}
|
|
176
|
-
exports.DecibelWsSubscription = DecibelWsSubscription;
|
package/dist/subaccount-types.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RenameSubaccountSchema = void 0;
|
|
7
|
-
const v4_1 = __importDefault(require("zod/v4"));
|
|
8
|
-
exports.RenameSubaccountSchema = v4_1.default.object({
|
|
9
|
-
subaccount_address: v4_1.default.string(),
|
|
10
|
-
new_name: v4_1.default.string(),
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const RenameSubaccountSchema = z.object({
|
|
3
|
+
subaccount_address: z.string(),
|
|
4
|
+
new_name: z.string(),
|
|
11
5
|
});
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.buildSimpleTransactionSync = buildSimpleTransactionSync;
|
|
5
|
-
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
6
|
-
function buildSimpleTransactionSync(args) {
|
|
7
|
-
const txnPayload = (0, ts_sdk_1.generateTransactionPayloadWithABI)({
|
|
1
|
+
import { AccountAddress, ChainId, convertPayloadToInnerPayload, findFirstNonSignerArg, generateTransactionPayloadWithABI, parseTypeTag, RawTransaction, SimpleTransaction, } from "@aptos-labs/ts-sdk";
|
|
2
|
+
export function buildSimpleTransactionSync(args) {
|
|
3
|
+
const txnPayload = generateTransactionPayloadWithABI({
|
|
8
4
|
aptosConfig: args.aptosConfig,
|
|
9
5
|
function: args.data.function,
|
|
10
6
|
functionArguments: args.data.functionArguments,
|
|
11
7
|
typeArguments: args.data.typeArguments,
|
|
12
8
|
abi: parseMoveFnAbiToEntryFnABI(args.abi),
|
|
13
9
|
});
|
|
14
|
-
const expireTimestamp =
|
|
15
|
-
const rawTxn = new
|
|
10
|
+
const expireTimestamp = generateExpireTimestamp(args.aptosConfig, args.timeDeltaMs);
|
|
11
|
+
const rawTxn = new RawTransaction(AccountAddress.from(args.sender),
|
|
16
12
|
// If replay nonce is provided, use it as the sequence number
|
|
17
13
|
// This is an unused value, so it's specifically to show that the sequence number is not used
|
|
18
|
-
BigInt("0xdeadbeef"),
|
|
14
|
+
BigInt("0xdeadbeef"), convertPayloadToInnerPayload(txnPayload, args.replayProtectionNonce),
|
|
19
15
|
// @Todo: Use gasPriceManager to get the max gas amount [as defaultMaxGasAmount might be very high number]
|
|
20
|
-
BigInt(args.aptosConfig.getDefaultMaxGasAmount()), BigInt(args.gasUnitPrice), BigInt(expireTimestamp), new
|
|
21
|
-
return new
|
|
16
|
+
BigInt(args.aptosConfig.getDefaultMaxGasAmount()), BigInt(args.gasUnitPrice), BigInt(expireTimestamp), new ChainId(args.chainId));
|
|
17
|
+
return new SimpleTransaction(rawTxn, args.withFeePayer ? AccountAddress.ZERO : undefined);
|
|
22
18
|
}
|
|
23
19
|
const parseMoveFnAbiToEntryFnABI = (functionAbi) => {
|
|
24
20
|
// Remove the signer arguments
|
|
25
|
-
const numSigners =
|
|
21
|
+
const numSigners = findFirstNonSignerArg(functionAbi);
|
|
26
22
|
const params = [];
|
|
27
23
|
for (let i = numSigners; i < functionAbi.params.length; i += 1) {
|
|
28
24
|
const param = functionAbi.params[i];
|
|
29
25
|
if (!param)
|
|
30
26
|
continue;
|
|
31
|
-
params.push(
|
|
27
|
+
params.push(parseTypeTag(param, { allowGenerics: true }));
|
|
32
28
|
}
|
|
33
29
|
return {
|
|
34
30
|
signers: numSigners,
|
|
@@ -36,5 +32,4 @@ const parseMoveFnAbiToEntryFnABI = (functionAbi) => {
|
|
|
36
32
|
parameters: params,
|
|
37
33
|
};
|
|
38
34
|
};
|
|
39
|
-
const generateExpireTimestamp = (aptosConfig, timeDeltaMs = 0) => Math.floor((Date.now() + timeDeltaMs) / 1000) + aptosConfig.getDefaultTxnExpirySecFromNow();
|
|
40
|
-
exports.generateExpireTimestamp = generateExpireTimestamp;
|
|
35
|
+
export const generateExpireTimestamp = (aptosConfig, timeDeltaMs = 0) => Math.floor((Date.now() + timeDeltaMs) / 1000) + aptosConfig.getDefaultTxnExpirySecFromNow();
|