@decibeltrade/sdk 0.1.6 → 0.1.8
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.js +19 -26
- package/dist/constants.js +34 -41
- 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 +20 -91
- package/dist/read/account-overview/account-overview.types.d.ts +7 -7
- package/dist/read/account-overview/account-overview.types.js +23 -26
- package/dist/read/base-reader.js +5 -9
- package/dist/read/candlesticks/candlesticks.reader.js +24 -95
- package/dist/read/candlesticks/candlesticks.types.js +14 -17
- package/dist/read/delegations/delegations.reader.js +14 -84
- package/dist/read/delegations/delegations.types.js +6 -9
- package/dist/read/index.js +50 -68
- package/dist/read/leaderboard/leaderboard.reader.js +13 -94
- package/dist/read/leaderboard/leaderboard.types.js +10 -13
- package/dist/read/market-contexts/market-contexts.reader.js +16 -83
- package/dist/read/market-contexts/market-contexts.types.js +12 -15
- package/dist/read/market-depth/market-depth.reader.js +29 -101
- package/dist/read/market-depth/market-depth.types.js +8 -11
- package/dist/read/market-prices/market-prices.reader.js +30 -111
- package/dist/read/market-prices/market-prices.types.js +21 -24
- package/dist/read/market-trades/market-trades.reader.js +23 -94
- package/dist/read/market-trades/market-trades.types.js +18 -21
- package/dist/read/markets/markets.reader.js +55 -152
- package/dist/read/markets/markets.types.js +32 -35
- package/dist/read/pagination.types.js +5 -11
- package/dist/read/portfolio-chart/portfolio-chart.reader.js +12 -82
- package/dist/read/portfolio-chart/portfolio-chart.types.js +5 -8
- package/dist/read/types.js +58 -75
- package/dist/read/user-active-twaps/user-active-twaps.reader.js +16 -86
- package/dist/read/user-active-twaps/user-active-twaps.types.js +18 -21
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +16 -86
- package/dist/read/user-bulk-orders/user-bulk-orders.types.js +16 -19
- package/dist/read/user-funding-history/user-funding-history.reader.js +16 -86
- package/dist/read/user-funding-history/user-funding-history.types.js +13 -16
- package/dist/read/user-notifications/user-notifications.reader.js +8 -32
- package/dist/read/user-notifications/user-notifications.types.js +19 -22
- package/dist/read/user-open-orders/user-open-orders.reader.js +16 -86
- package/dist/read/user-open-orders/user-open-orders.types.js +27 -30
- package/dist/read/user-order-history/user-order-history.reader.js +18 -88
- package/dist/read/user-order-history/user-order-history.types.js +29 -32
- package/dist/read/user-positions/user-positions.reader.js +24 -95
- package/dist/read/user-positions/user-positions.types.d.ts +15 -15
- package/dist/read/user-positions/user-positions.types.js +22 -25
- package/dist/read/user-subaccounts/user-subaccounts.reader.js +18 -89
- package/dist/read/user-subaccounts/user-subaccounts.types.js +8 -11
- package/dist/read/user-trade-history/user-trade-history.reader.js +16 -86
- package/dist/read/user-trade-history/user-trade-history.types.js +18 -21
- package/dist/read/vaults/vaults.reader.js +45 -150
- package/dist/read/vaults/vaults.types.js +52 -55
- package/dist/read/ws-subscription.js +10 -17
- package/dist/subaccount-types.js +4 -7
- package/dist/transaction-builder.js +15 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.js +28 -42
- package/dist/write.js +20 -24
- package/package.json +4 -3
- package/tsconfig.json +4 -1
|
@@ -1,167 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
54
|
-
var t = {};
|
|
55
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
56
|
-
t[p] = s[p];
|
|
57
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
58
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
60
|
-
t[p[i]] = s[p[i]];
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.VaultsReader = void 0;
|
|
66
|
-
var base_reader_1 = require("../base-reader");
|
|
67
|
-
var vaults_types_1 = require("./vaults.types");
|
|
68
|
-
var VaultsReader = /** @class */ (function (_super) {
|
|
69
|
-
__extends(VaultsReader, _super);
|
|
70
|
-
function VaultsReader() {
|
|
71
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
-
}
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { UserOwnedVaultsResponseSchema, UserPerformancesOnVaultsResponseSchema, VaultsResponseSchema, } from "./vaults.types";
|
|
3
|
+
export class VaultsReader extends BaseReader {
|
|
73
4
|
/**
|
|
74
5
|
* Get all vaults
|
|
75
6
|
* @returns All vaults
|
|
76
7
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (args.offset)
|
|
91
|
-
queryParams.set("offset", args.offset.toString());
|
|
92
|
-
return [4 /*yield*/, this.getRequest({
|
|
93
|
-
schema: vaults_types_1.VaultsResponseSchema,
|
|
94
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/vaults"),
|
|
95
|
-
queryParams: queryParams,
|
|
96
|
-
options: fetchOptions,
|
|
97
|
-
})];
|
|
98
|
-
case 1:
|
|
99
|
-
response = _b.sent();
|
|
100
|
-
return [2 /*return*/, response.data];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
8
|
+
async getVaults({ fetchOptions, ...args } = {}) {
|
|
9
|
+
const queryParams = new URLSearchParams();
|
|
10
|
+
if (args.vaultType)
|
|
11
|
+
queryParams.set("vault_type", args.vaultType);
|
|
12
|
+
if (args.limit)
|
|
13
|
+
queryParams.set("limit", args.limit.toString());
|
|
14
|
+
if (args.offset)
|
|
15
|
+
queryParams.set("offset", args.offset.toString());
|
|
16
|
+
const response = await this.getRequest({
|
|
17
|
+
schema: VaultsResponseSchema,
|
|
18
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/vaults`,
|
|
19
|
+
queryParams,
|
|
20
|
+
options: fetchOptions,
|
|
103
21
|
});
|
|
104
|
-
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
105
24
|
/**
|
|
106
25
|
* Get vaults by owner address
|
|
107
26
|
* @param user The user address to filter vaults by
|
|
108
27
|
* @returns The vaults for the given owner address
|
|
109
28
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
queryParams.set("offset", args.offset.toString());
|
|
124
|
-
return [4 /*yield*/, this.getRequest({
|
|
125
|
-
schema: vaults_types_1.UserOwnedVaultsResponseSchema,
|
|
126
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/user_owned_vaults"),
|
|
127
|
-
queryParams: queryParams,
|
|
128
|
-
options: fetchOptions,
|
|
129
|
-
})];
|
|
130
|
-
case 1:
|
|
131
|
-
response = _b.sent();
|
|
132
|
-
return [2 /*return*/, response.data];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
29
|
+
async getUserOwnedVaults({ fetchOptions, ...args }) {
|
|
30
|
+
const queryParams = new URLSearchParams({
|
|
31
|
+
user: args.ownerAddr,
|
|
32
|
+
});
|
|
33
|
+
if (args.limit)
|
|
34
|
+
queryParams.set("limit", args.limit.toString());
|
|
35
|
+
if (args.offset)
|
|
36
|
+
queryParams.set("offset", args.offset.toString());
|
|
37
|
+
const response = await this.getRequest({
|
|
38
|
+
schema: UserOwnedVaultsResponseSchema,
|
|
39
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/user_owned_vaults`,
|
|
40
|
+
queryParams,
|
|
41
|
+
options: fetchOptions,
|
|
135
42
|
});
|
|
136
|
-
|
|
43
|
+
return response.data;
|
|
44
|
+
}
|
|
137
45
|
/**
|
|
138
46
|
* Get user performance
|
|
139
47
|
* @param args The arguments for the user performance
|
|
140
48
|
* @returns The user performance
|
|
141
49
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
return [4 /*yield*/, this.getRequest({
|
|
153
|
-
schema: vaults_types_1.UserPerformancesOnVaultsResponseSchema,
|
|
154
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/user_vault_performance"),
|
|
155
|
-
queryParams: queryParams,
|
|
156
|
-
options: fetchOptions,
|
|
157
|
-
})];
|
|
158
|
-
case 1:
|
|
159
|
-
response = _b.sent();
|
|
160
|
-
return [2 /*return*/, response.data];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
50
|
+
async getUserPerformancesOnVaults({ fetchOptions, ...args }) {
|
|
51
|
+
const queryParams = new URLSearchParams({
|
|
52
|
+
user_address: args.ownerAddr,
|
|
53
|
+
});
|
|
54
|
+
const response = await this.getRequest({
|
|
55
|
+
schema: UserPerformancesOnVaultsResponseSchema,
|
|
56
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/user_vault_performance`,
|
|
57
|
+
queryParams,
|
|
58
|
+
options: fetchOptions,
|
|
163
59
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
exports.VaultsReader = VaultsReader;
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,71 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.UserPerformancesOnVaultsResponseSchema = exports.UserPerformanceOnVaultSchema = exports.UserOwnedVaultsResponseSchema = exports.UserOwnedVaultSchema = exports.VaultsResponseSchema = exports.VaultSchema = void 0;
|
|
4
|
-
var v4_1 = require("zod/v4");
|
|
5
|
-
var pagination_types_1 = require("../pagination.types");
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
import { PaginatedResponseSchema } from "../pagination.types";
|
|
6
3
|
/**
|
|
7
4
|
* Schema for a vault in the protocol
|
|
8
5
|
* Represents both protocol-wide vaults and user-managed vaults
|
|
9
6
|
*/
|
|
10
|
-
|
|
11
|
-
address:
|
|
12
|
-
name:
|
|
13
|
-
description:
|
|
14
|
-
manager:
|
|
15
|
-
status:
|
|
16
|
-
created_at:
|
|
17
|
-
tvl:
|
|
18
|
-
volume:
|
|
19
|
-
all_time_return:
|
|
20
|
-
past_month_return:
|
|
21
|
-
sharpe_ratio:
|
|
22
|
-
max_drawdown:
|
|
23
|
-
weekly_win_rate_12w:
|
|
24
|
-
profit_share:
|
|
25
|
-
pnl_90d:
|
|
26
|
-
manager_avg_cash:
|
|
27
|
-
average_leverage:
|
|
28
|
-
depositors:
|
|
29
|
-
perp_equity:
|
|
30
|
-
vault_type:
|
|
31
|
-
pnl_history:
|
|
32
|
-
social_links:
|
|
7
|
+
export const VaultSchema = z.object({
|
|
8
|
+
address: z.string(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
description: z.string().nullable(),
|
|
11
|
+
manager: z.string(),
|
|
12
|
+
status: z.string(),
|
|
13
|
+
created_at: z.number(),
|
|
14
|
+
tvl: z.number().nullable(),
|
|
15
|
+
volume: z.number().nullable(),
|
|
16
|
+
all_time_return: z.number().nullable(),
|
|
17
|
+
past_month_return: z.number().nullable(),
|
|
18
|
+
sharpe_ratio: z.number().nullable(),
|
|
19
|
+
max_drawdown: z.number().nullable(),
|
|
20
|
+
weekly_win_rate_12w: z.number().nullable(),
|
|
21
|
+
profit_share: z.number().nullable(),
|
|
22
|
+
pnl_90d: z.number().nullable(),
|
|
23
|
+
manager_avg_cash: z.number().nullable(),
|
|
24
|
+
average_leverage: z.number().nullable(),
|
|
25
|
+
depositors: z.number().nullable(),
|
|
26
|
+
perp_equity: z.number().nullable(),
|
|
27
|
+
vault_type: z.string(),
|
|
28
|
+
pnl_history: z.array(z.string()).nullable(),
|
|
29
|
+
social_links: z.array(z.string()).nullable(),
|
|
33
30
|
});
|
|
34
|
-
|
|
35
|
-
total_value_locked:
|
|
36
|
-
total_volume:
|
|
31
|
+
export const VaultsResponseSchema = PaginatedResponseSchema(VaultSchema).extend({
|
|
32
|
+
total_value_locked: z.number(),
|
|
33
|
+
total_volume: z.number(),
|
|
37
34
|
});
|
|
38
35
|
/**
|
|
39
36
|
* Schema for vaults owned/managed by a specific user
|
|
40
37
|
* Contains summary information about vaults the user manages
|
|
41
38
|
*/
|
|
42
|
-
|
|
43
|
-
vault_address:
|
|
44
|
-
vault_name:
|
|
45
|
-
vault_share_symbol:
|
|
46
|
-
status:
|
|
47
|
-
age_days:
|
|
48
|
-
num_managers:
|
|
49
|
-
tvl:
|
|
50
|
-
apr:
|
|
51
|
-
manager_equity:
|
|
52
|
-
manager_stake:
|
|
39
|
+
export const UserOwnedVaultSchema = z.object({
|
|
40
|
+
vault_address: z.string(),
|
|
41
|
+
vault_name: z.string(),
|
|
42
|
+
vault_share_symbol: z.string(),
|
|
43
|
+
status: z.string(),
|
|
44
|
+
age_days: z.number(),
|
|
45
|
+
num_managers: z.number(),
|
|
46
|
+
tvl: z.number().nullable(),
|
|
47
|
+
apr: z.number().nullable(),
|
|
48
|
+
manager_equity: z.number().nullable(),
|
|
49
|
+
manager_stake: z.number().nullable(),
|
|
53
50
|
});
|
|
54
|
-
|
|
51
|
+
export const UserOwnedVaultsResponseSchema = PaginatedResponseSchema(UserOwnedVaultSchema);
|
|
55
52
|
/**
|
|
56
53
|
* Schema for user performance metrics within a vault
|
|
57
54
|
* Tracks a user's deposits, shares, returns, and PnL for a specific vault
|
|
58
55
|
*/
|
|
59
|
-
|
|
60
|
-
vault_address:
|
|
61
|
-
user_address:
|
|
62
|
-
net_deposits:
|
|
63
|
-
current_num_shares:
|
|
64
|
-
current_value_of_shares:
|
|
65
|
-
all_time_return:
|
|
66
|
-
unrealized_pnl:
|
|
67
|
-
share_price:
|
|
68
|
-
volume:
|
|
69
|
-
weekly_win_rate_12w:
|
|
56
|
+
export const UserPerformanceOnVaultSchema = z.object({
|
|
57
|
+
vault_address: z.string(),
|
|
58
|
+
user_address: z.string(),
|
|
59
|
+
net_deposits: z.number().nullable(),
|
|
60
|
+
current_num_shares: z.number().nullable(),
|
|
61
|
+
current_value_of_shares: z.number().nullable(),
|
|
62
|
+
all_time_return: z.number().nullable(),
|
|
63
|
+
unrealized_pnl: z.number().nullable(),
|
|
64
|
+
share_price: z.number(),
|
|
65
|
+
volume: z.number(),
|
|
66
|
+
weekly_win_rate_12w: z.number().nullable(),
|
|
70
67
|
});
|
|
71
|
-
|
|
68
|
+
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,7 +39,7 @@ 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
45
|
this.#subscriptions.keys().forEach((topic) => {
|
|
@@ -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,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.RenameSubaccountSchema = v4_1.default.object({
|
|
6
|
-
subaccount_address: v4_1.default.string(),
|
|
7
|
-
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(),
|
|
8
5
|
});
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.buildSimpleTransactionSync = buildSimpleTransactionSync;
|
|
5
|
-
var ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
6
|
-
function buildSimpleTransactionSync(args) {
|
|
7
|
-
var 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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
|
|
21
|
+
const numSigners = findFirstNonSignerArg(functionAbi);
|
|
22
|
+
const params = [];
|
|
23
|
+
for (let i = numSigners; i < functionAbi.params.length; i += 1) {
|
|
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,8 +32,4 @@ var parseMoveFnAbiToEntryFnABI = function (functionAbi) {
|
|
|
36
32
|
parameters: params,
|
|
37
33
|
};
|
|
38
34
|
};
|
|
39
|
-
|
|
40
|
-
if (timeDeltaMs === void 0) { timeDeltaMs = 0; }
|
|
41
|
-
return Math.floor((Date.now() + timeDeltaMs) / 1000) + aptosConfig.getDefaultTxnExpirySecFromNow();
|
|
42
|
-
};
|
|
43
|
-
exports.generateExpireTimestamp = generateExpireTimestamp;
|
|
35
|
+
export const generateExpireTimestamp = (aptosConfig, timeDeltaMs = 0) => Math.floor((Date.now() + timeDeltaMs) / 1000) + aptosConfig.getDefaultTxnExpirySecFromNow();
|