@decibeltrade/sdk 0.1.6 → 0.1.7
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 +2 -1
- package/tsconfig.json +4 -1
|
@@ -1,50 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* ABI fetcher that gets all ABIs used by the Decibel SDK
|
|
4
3
|
* Based on actual function calls found in the SDK source code
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
const constants_1 = require("../constants");
|
|
5
|
+
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { NETNA_CONFIG, TESTNET_CONFIG } from "../constants";
|
|
44
9
|
// @Todo: There should be a global config that takes care of config across all the packages and apps
|
|
45
10
|
// @Todo: Generate ABIs for all the networks as well, or as per global config depending upon how that will work
|
|
46
11
|
// Remove NETNA_CONFIG and use getSdkConfig() instead once we implement it as a global config
|
|
47
|
-
const CONFIGS = [
|
|
12
|
+
const CONFIGS = [NETNA_CONFIG, TESTNET_CONFIG];
|
|
48
13
|
// All modules used in the SDK (extracted from source code analysis)
|
|
49
14
|
const SDK_MODULES = [
|
|
50
15
|
"admin_apis",
|
|
@@ -60,9 +25,9 @@ const SDK_MODULES = [
|
|
|
60
25
|
*/
|
|
61
26
|
function getAbiFilename(config) {
|
|
62
27
|
// For CUSTOM networks, use a more descriptive name based on the config
|
|
63
|
-
if (config.network ===
|
|
28
|
+
if (config.network === Network.CUSTOM) {
|
|
64
29
|
// Check if it's NETNA by comparing package address or other unique identifier
|
|
65
|
-
if (config.deployment.package ===
|
|
30
|
+
if (config.deployment.package === NETNA_CONFIG.deployment.package) {
|
|
66
31
|
return "json/netna.json";
|
|
67
32
|
}
|
|
68
33
|
return "json/custom.json";
|
|
@@ -80,13 +45,13 @@ async function fetchAllAbis(config) {
|
|
|
80
45
|
console.error("❌ Error: config.package or CONFIG.fullnodeUrl is not set");
|
|
81
46
|
process.exit(1);
|
|
82
47
|
}
|
|
83
|
-
const aptosConfig = new
|
|
48
|
+
const aptosConfig = new AptosConfig({
|
|
84
49
|
network: config.network,
|
|
85
50
|
fullnode: config.fullnodeUrl,
|
|
86
51
|
});
|
|
87
52
|
const abis = {};
|
|
88
53
|
const errors = [];
|
|
89
|
-
const aptos = new
|
|
54
|
+
const aptos = new Aptos(aptosConfig);
|
|
90
55
|
// Fetch entire modules at once (much more efficient!)
|
|
91
56
|
for (const module of SDK_MODULES) {
|
|
92
57
|
try {
|
package/dist/abi/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/admin.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
class DecibelAdminDex extends base_1.BaseSDK {
|
|
1
|
+
import { AccountAddress, createObjectAddress } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { BaseSDK } from "./base";
|
|
3
|
+
import { getVaultApiModule } from "./constants";
|
|
4
|
+
import { getMarketAddr } from "./utils";
|
|
5
|
+
export class DecibelAdminDex extends BaseSDK {
|
|
9
6
|
/**
|
|
10
7
|
* Initialize the global vault system. Only callable by the admin account.
|
|
11
8
|
*/
|
|
@@ -17,12 +14,12 @@ class DecibelAdminDex extends base_1.BaseSDK {
|
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
getProtocolVaultAddress() {
|
|
20
|
-
const vaultConfigObjectAddr =
|
|
21
|
-
const protocolVaultObjectAddr =
|
|
17
|
+
const vaultConfigObjectAddr = createObjectAddress(AccountAddress.fromString(this.config.deployment.package), "GlobalVaultConfig");
|
|
18
|
+
const protocolVaultObjectAddr = createObjectAddress(vaultConfigObjectAddr, "Decibel Protocol Vault");
|
|
22
19
|
return protocolVaultObjectAddr;
|
|
23
20
|
}
|
|
24
21
|
async initializeProtocolVault(collateralTokenAddr, initialFunding) {
|
|
25
|
-
const vaultApiModule =
|
|
22
|
+
const vaultApiModule = getVaultApiModule(this.config.compatVersion);
|
|
26
23
|
return await this.sendTx({
|
|
27
24
|
function: `${this.config.deployment.package}::${vaultApiModule}::create_and_fund_vault`,
|
|
28
25
|
typeArguments: [],
|
|
@@ -143,7 +140,7 @@ class DecibelAdminDex extends base_1.BaseSDK {
|
|
|
143
140
|
});
|
|
144
141
|
}
|
|
145
142
|
async updateInternalOraclePrice(marketName, oraclePrice) {
|
|
146
|
-
const marketAddr =
|
|
143
|
+
const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
|
|
147
144
|
return await this.sendTx({
|
|
148
145
|
function: `${this.config.deployment.package}::admin_apis::update_mark_for_internal_oracle`,
|
|
149
146
|
typeArguments: [],
|
|
@@ -151,7 +148,7 @@ class DecibelAdminDex extends base_1.BaseSDK {
|
|
|
151
148
|
});
|
|
152
149
|
}
|
|
153
150
|
async updatePythOraclePrice(marketName, vaa) {
|
|
154
|
-
const marketAddr =
|
|
151
|
+
const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
|
|
155
152
|
return await this.sendTx({
|
|
156
153
|
function: `${this.config.deployment.package}::admin_apis::update_mark_for_pyth_oracle`,
|
|
157
154
|
typeArguments: [],
|
|
@@ -202,4 +199,3 @@ class DecibelAdminDex extends base_1.BaseSDK {
|
|
|
202
199
|
return balance[0];
|
|
203
200
|
}
|
|
204
201
|
}
|
|
205
|
-
exports.DecibelAdminDex = DecibelAdminDex;
|
package/dist/base.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const netna_json_1 = __importDefault(require("./abi/json/netna.json"));
|
|
9
|
-
const testnet_json_1 = __importDefault(require("./abi/json/testnet.json"));
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
|
-
const fee_pay_1 = require("./fee-pay");
|
|
12
|
-
const transaction_builder_1 = require("./transaction-builder");
|
|
13
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { Aptos, AptosConfig, } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import netnaAbis from "./abi/json/netna.json";
|
|
3
|
+
import testnetAbis from "./abi/json/testnet.json";
|
|
4
|
+
import { NETNA_CONFIG, TESTNET_CONFIG } from "./constants";
|
|
5
|
+
import { submitFeePaidTransaction } from "./fee-pay";
|
|
6
|
+
import { buildSimpleTransactionSync } from "./transaction-builder";
|
|
7
|
+
import { generateRandomReplayProtectionNonce } from "./utils";
|
|
14
8
|
const chainIdToAbi = {};
|
|
15
|
-
if (
|
|
16
|
-
chainIdToAbi[
|
|
17
|
-
if (
|
|
18
|
-
chainIdToAbi[
|
|
19
|
-
class BaseSDK {
|
|
9
|
+
if (NETNA_CONFIG.chainId)
|
|
10
|
+
chainIdToAbi[NETNA_CONFIG.chainId] = netnaAbis;
|
|
11
|
+
if (TESTNET_CONFIG.chainId)
|
|
12
|
+
chainIdToAbi[TESTNET_CONFIG.chainId] = testnetAbis;
|
|
13
|
+
export class BaseSDK {
|
|
20
14
|
config;
|
|
21
15
|
account;
|
|
22
16
|
aptos;
|
|
23
17
|
skipSimulate;
|
|
24
18
|
noFeePayer;
|
|
25
19
|
chainId;
|
|
26
|
-
abi =
|
|
20
|
+
abi = netnaAbis;
|
|
27
21
|
gasPriceManager;
|
|
28
22
|
/**
|
|
29
23
|
* Time delta in milliseconds to add to Date.now() for expiration timestamps.
|
|
@@ -41,15 +35,15 @@ class BaseSDK {
|
|
|
41
35
|
this.abi = abi;
|
|
42
36
|
}
|
|
43
37
|
else {
|
|
44
|
-
this.abi =
|
|
38
|
+
this.abi = netnaAbis;
|
|
45
39
|
console.warn("Using NETNA ABI for unsupported chain id, this might cause issues with the transaction builder");
|
|
46
40
|
}
|
|
47
|
-
const aptosConfig = new
|
|
41
|
+
const aptosConfig = new AptosConfig({
|
|
48
42
|
network: config.network,
|
|
49
43
|
fullnode: config.fullnodeUrl,
|
|
50
44
|
clientConfig: { API_KEY: opts?.nodeApiKey },
|
|
51
45
|
});
|
|
52
|
-
this.aptos = new
|
|
46
|
+
this.aptos = new Aptos(aptosConfig);
|
|
53
47
|
this.skipSimulate = opts?.skipSimulate ?? false;
|
|
54
48
|
this.noFeePayer = opts?.noFeePayer ?? false;
|
|
55
49
|
this.chainId = config.chainId;
|
|
@@ -94,13 +88,13 @@ class BaseSDK {
|
|
|
94
88
|
});
|
|
95
89
|
}
|
|
96
90
|
else {
|
|
97
|
-
return await
|
|
91
|
+
return await submitFeePaidTransaction(this.config, transaction, senderAuthenticator);
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
async buildTx(payload, sender) {
|
|
101
95
|
const functionAbi = "function" in payload ? this.getABI(payload.function) : undefined;
|
|
102
96
|
const withFeePayer = !this.noFeePayer;
|
|
103
|
-
const replayProtectionNonce =
|
|
97
|
+
const replayProtectionNonce = generateRandomReplayProtectionNonce();
|
|
104
98
|
// This should never happen, but just in case
|
|
105
99
|
if (!replayProtectionNonce) {
|
|
106
100
|
throw new Error("Unable to generate replayProtectionNonce");
|
|
@@ -120,7 +114,7 @@ class BaseSDK {
|
|
|
120
114
|
// 1. Fetch from network, this is a fallback, should only happen if gasPriceManager is not set
|
|
121
115
|
gasUnitPrice = (await this.aptos.getGasPriceEstimation()).gas_estimate;
|
|
122
116
|
}
|
|
123
|
-
transaction =
|
|
117
|
+
transaction = buildSimpleTransactionSync({
|
|
124
118
|
aptosConfig: this.aptos.config,
|
|
125
119
|
sender,
|
|
126
120
|
data: payload,
|
|
@@ -173,4 +167,3 @@ class BaseSDK {
|
|
|
173
167
|
}
|
|
174
168
|
}
|
|
175
169
|
}
|
|
176
|
-
exports.BaseSDK = BaseSDK;
|
package/dist/constants.js
CHANGED
|
@@ -1,93 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getUsdcAddress = getUsdcAddress;
|
|
5
|
-
exports.getTestcAddress = getTestcAddress;
|
|
6
|
-
exports.getPerpEngineGlobalAddress = getPerpEngineGlobalAddress;
|
|
7
|
-
exports.getVaultApiModule = getVaultApiModule;
|
|
8
|
-
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
9
|
-
function getUsdcAddress(publisherAddr) {
|
|
10
|
-
return (0, ts_sdk_1.createObjectAddress)(ts_sdk_1.AccountAddress.fromString(publisherAddr), new TextEncoder().encode("USDC"));
|
|
1
|
+
import { AccountAddress, createObjectAddress, Network } from "@aptos-labs/ts-sdk";
|
|
2
|
+
export function getUsdcAddress(publisherAddr) {
|
|
3
|
+
return createObjectAddress(AccountAddress.fromString(publisherAddr), new TextEncoder().encode("USDC"));
|
|
11
4
|
}
|
|
12
|
-
function getTestcAddress(publisherAddr) {
|
|
13
|
-
return
|
|
5
|
+
export function getTestcAddress(publisherAddr) {
|
|
6
|
+
return createObjectAddress(AccountAddress.fromString(publisherAddr), new TextEncoder().encode("TESTC"));
|
|
14
7
|
}
|
|
15
|
-
function getPerpEngineGlobalAddress(publisherAddr) {
|
|
16
|
-
return
|
|
8
|
+
export function getPerpEngineGlobalAddress(publisherAddr) {
|
|
9
|
+
return createObjectAddress(AccountAddress.fromString(publisherAddr), new TextEncoder().encode("GlobalPerpEngine"));
|
|
17
10
|
}
|
|
18
|
-
var CompatVersion;
|
|
11
|
+
export var CompatVersion;
|
|
19
12
|
(function (CompatVersion) {
|
|
20
13
|
CompatVersion["V0_1"] = "v0.1";
|
|
21
14
|
CompatVersion["V0_2"] = "v0.2";
|
|
22
|
-
})(CompatVersion || (
|
|
23
|
-
|
|
15
|
+
})(CompatVersion || (CompatVersion = {}));
|
|
16
|
+
export const DEFAULT_COMPAT_VERSION = CompatVersion.V0_2;
|
|
24
17
|
const NETNA_PACKAGE = "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95";
|
|
25
|
-
|
|
18
|
+
export const NETNA_DEPLOYMENT = {
|
|
26
19
|
package: NETNA_PACKAGE,
|
|
27
20
|
usdc: getUsdcAddress(NETNA_PACKAGE).toString(),
|
|
28
21
|
testc: getTestcAddress(NETNA_PACKAGE).toString(),
|
|
29
22
|
perpEngineGlobal: getPerpEngineGlobalAddress(NETNA_PACKAGE).toString(),
|
|
30
23
|
};
|
|
31
|
-
|
|
32
|
-
network:
|
|
24
|
+
export const NETNA_CONFIG = {
|
|
25
|
+
network: Network.CUSTOM,
|
|
33
26
|
fullnodeUrl: "https://api.netna.aptoslabs.com/v1",
|
|
34
27
|
tradingHttpUrl: "https://api.netna.aptoslabs.com/decibel",
|
|
35
28
|
tradingWsUrl: "wss://api.netna.aptoslabs.com/decibel/ws",
|
|
36
29
|
gasStationUrl: "https://fee-payer-dev-netna-us-central1-410192433417.us-central1.run.app",
|
|
37
|
-
deployment:
|
|
30
|
+
deployment: NETNA_DEPLOYMENT,
|
|
38
31
|
chainId: 206,
|
|
39
|
-
compatVersion:
|
|
32
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
40
33
|
};
|
|
41
34
|
const TESTNET_PACKAGE = "0x1f513904b7568445e3c291a6c58cb272db017d8a72aea563d5664666221d5f75";
|
|
42
|
-
|
|
35
|
+
export const TESTNET_DEPLOYMENT = {
|
|
43
36
|
package: TESTNET_PACKAGE,
|
|
44
37
|
usdc: getUsdcAddress(TESTNET_PACKAGE).toString(),
|
|
45
38
|
testc: getTestcAddress(TESTNET_PACKAGE).toString(),
|
|
46
39
|
perpEngineGlobal: getPerpEngineGlobalAddress(TESTNET_PACKAGE).toString(),
|
|
47
40
|
};
|
|
48
|
-
|
|
49
|
-
network:
|
|
41
|
+
export const TESTNET_CONFIG = {
|
|
42
|
+
network: Network.TESTNET,
|
|
50
43
|
fullnodeUrl: "https://api.testnet.aptoslabs.com/v1",
|
|
51
44
|
tradingHttpUrl: "https://api.testnet.aptoslabs.com/decibel",
|
|
52
45
|
tradingWsUrl: "wss://api.testnet.aptoslabs.com/decibel/ws",
|
|
53
46
|
gasStationUrl: "https://fee-payer-staging-testnet-us-central1-502735673999.us-central1.run.app",
|
|
54
|
-
deployment:
|
|
47
|
+
deployment: TESTNET_DEPLOYMENT,
|
|
55
48
|
chainId: 2,
|
|
56
49
|
compatVersion: CompatVersion.V0_1,
|
|
57
50
|
};
|
|
58
|
-
|
|
59
|
-
network:
|
|
51
|
+
export const LOCAL_CONFIG = {
|
|
52
|
+
network: Network.CUSTOM,
|
|
60
53
|
fullnodeUrl: "http://localhost:8080/v1",
|
|
61
54
|
tradingHttpUrl: "http://localhost:8084",
|
|
62
55
|
tradingWsUrl: "ws://localhost:8083",
|
|
63
56
|
gasStationUrl: "http://localhost:8085",
|
|
64
|
-
deployment:
|
|
65
|
-
compatVersion:
|
|
57
|
+
deployment: NETNA_DEPLOYMENT,
|
|
58
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
66
59
|
};
|
|
67
|
-
|
|
68
|
-
network:
|
|
60
|
+
export const DOCKER_CONFIG = {
|
|
61
|
+
network: Network.CUSTOM,
|
|
69
62
|
fullnodeUrl: "http://tradenet:8080/v1",
|
|
70
63
|
tradingHttpUrl: "http://trading-api-http:8080",
|
|
71
64
|
// nosemgrep: javascript.lang.security.detect-insecure-websocket.detect-insecure-websocket
|
|
72
65
|
tradingWsUrl: "ws://trading-api-ws:8080",
|
|
73
66
|
gasStationUrl: "http://fee-payer:8080",
|
|
74
|
-
deployment:
|
|
75
|
-
compatVersion:
|
|
67
|
+
deployment: NETNA_DEPLOYMENT,
|
|
68
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
76
69
|
};
|
|
77
|
-
|
|
78
|
-
netna:
|
|
79
|
-
local:
|
|
80
|
-
docker:
|
|
81
|
-
testnet:
|
|
70
|
+
export const NAMED_CONFIGS = {
|
|
71
|
+
netna: NETNA_CONFIG,
|
|
72
|
+
local: LOCAL_CONFIG,
|
|
73
|
+
docker: DOCKER_CONFIG,
|
|
74
|
+
testnet: TESTNET_CONFIG,
|
|
82
75
|
};
|
|
83
|
-
|
|
76
|
+
export const QUERY_PARAM_KEYS = {
|
|
84
77
|
offset: "offset",
|
|
85
78
|
limit: "limit",
|
|
86
79
|
sortKey: "sort_key",
|
|
87
80
|
sortDir: "sort_dir",
|
|
88
81
|
searchTerm: "search_term",
|
|
89
82
|
};
|
|
90
|
-
function getVaultApiModule(compatVersion) {
|
|
83
|
+
export function getVaultApiModule(compatVersion) {
|
|
91
84
|
if (compatVersion === CompatVersion.V0_1) {
|
|
92
85
|
return `vault`;
|
|
93
86
|
}
|
package/dist/fee-pay.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.submitFeePaidTransaction = submitFeePaidTransaction;
|
|
4
1
|
/**
|
|
5
2
|
* Submit a transaction with fee payer support
|
|
6
3
|
* @param config The Decibel configuration containing the gas station URL
|
|
@@ -8,7 +5,7 @@ exports.submitFeePaidTransaction = submitFeePaidTransaction;
|
|
|
8
5
|
* @param senderAuthenticator The sender's authenticator
|
|
9
6
|
* @returns A promise that resolves to the pending transaction response
|
|
10
7
|
*/
|
|
11
|
-
async function submitFeePaidTransaction(config, transaction, senderAuthenticator) {
|
|
8
|
+
export async function submitFeePaidTransaction(config, transaction, senderAuthenticator) {
|
|
12
9
|
const signatureBcs = Array.from(senderAuthenticator.bcsToBytes());
|
|
13
10
|
const transactionBcs = Array.from(transaction.rawTransaction.bcsToBytes());
|
|
14
11
|
const body = JSON.stringify({
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.GasPriceManager = void 0;
|
|
4
|
-
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
|
|
5
|
-
class GasPriceManager {
|
|
1
|
+
import { Aptos, AptosConfig } from "@aptos-labs/ts-sdk";
|
|
2
|
+
export class GasPriceManager {
|
|
6
3
|
gasPrice = null;
|
|
7
4
|
intervalId = null;
|
|
8
5
|
aptos;
|
|
@@ -10,7 +7,7 @@ class GasPriceManager {
|
|
|
10
7
|
isInitialized = false;
|
|
11
8
|
multiplier;
|
|
12
9
|
constructor(config, opts) {
|
|
13
|
-
this.aptos = new
|
|
10
|
+
this.aptos = new Aptos(new AptosConfig({
|
|
14
11
|
network: config.network,
|
|
15
12
|
fullnode: config.fullnodeUrl,
|
|
16
13
|
clientConfig: { API_KEY: opts?.nodeApiKey },
|
|
@@ -90,4 +87,3 @@ class GasPriceManager {
|
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
|
-
exports.GasPriceManager = GasPriceManager;
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./admin"), exports);
|
|
18
|
-
__exportStar(require("./constants"), exports);
|
|
19
|
-
__exportStar(require("./fee-pay"), exports);
|
|
20
|
-
__exportStar(require("./gas/gas-price-manager"), exports);
|
|
21
|
-
__exportStar(require("./order-event.types"), exports);
|
|
22
|
-
__exportStar(require("./order-status"), exports);
|
|
23
|
-
__exportStar(require("./read/index"), exports);
|
|
24
|
-
__exportStar(require("./subaccount-types"), exports);
|
|
25
|
-
__exportStar(require("./utils"), exports);
|
|
26
|
-
__exportStar(require("./write"), exports);
|
|
1
|
+
export * from "./admin";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./fee-pay";
|
|
4
|
+
export * from "./gas/gas-price-manager";
|
|
5
|
+
export * from "./order-event.types";
|
|
6
|
+
export * from "./order-status";
|
|
7
|
+
export * from "./read/index";
|
|
8
|
+
export * from "./subaccount-types";
|
|
9
|
+
export * from "./utils";
|
|
10
|
+
export * from "./write";
|
package/dist/order-status.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OrderStatusClient = exports.OrderStatusSchema = void 0;
|
|
7
|
-
const v4_1 = __importDefault(require("zod/v4"));
|
|
1
|
+
import z from "zod/v4";
|
|
8
2
|
// Order status response schema
|
|
9
|
-
|
|
10
|
-
parent:
|
|
11
|
-
market:
|
|
12
|
-
order_id:
|
|
13
|
-
status:
|
|
14
|
-
orig_size:
|
|
15
|
-
remaining_size:
|
|
16
|
-
size_delta:
|
|
17
|
-
price:
|
|
18
|
-
is_buy:
|
|
19
|
-
details:
|
|
20
|
-
transaction_version:
|
|
21
|
-
unix_ms:
|
|
3
|
+
export const OrderStatusSchema = z.object({
|
|
4
|
+
parent: z.string(),
|
|
5
|
+
market: z.string(),
|
|
6
|
+
order_id: z.string(),
|
|
7
|
+
status: z.string(),
|
|
8
|
+
orig_size: z.number(),
|
|
9
|
+
remaining_size: z.number(),
|
|
10
|
+
size_delta: z.number(),
|
|
11
|
+
price: z.number(),
|
|
12
|
+
is_buy: z.boolean(),
|
|
13
|
+
details: z.string(),
|
|
14
|
+
transaction_version: z.number(),
|
|
15
|
+
unix_ms: z.number(),
|
|
22
16
|
});
|
|
23
|
-
class OrderStatusClient {
|
|
17
|
+
export class OrderStatusClient {
|
|
24
18
|
config;
|
|
25
19
|
constructor(config) {
|
|
26
20
|
this.config = config;
|
|
@@ -39,7 +33,7 @@ class OrderStatusClient {
|
|
|
39
33
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
40
34
|
}
|
|
41
35
|
const data = await response.json();
|
|
42
|
-
return
|
|
36
|
+
return OrderStatusSchema.parse(data);
|
|
43
37
|
}
|
|
44
38
|
catch (error) {
|
|
45
39
|
console.error("Error fetching order status:", error);
|
|
@@ -83,4 +77,3 @@ class OrderStatusClient {
|
|
|
83
77
|
return this.isSuccessStatus(status) || this.isFailureStatus(status);
|
|
84
78
|
}
|
|
85
79
|
}
|
|
86
|
-
exports.OrderStatusClient = OrderStatusClient;
|
|
@@ -1,103 +1,32 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.AccountOverviewReader = void 0;
|
|
55
|
-
var base_reader_1 = require("../base-reader");
|
|
56
|
-
var account_overview_types_1 = require("./account-overview.types");
|
|
57
|
-
var AccountOverviewReader = /** @class */ (function (_super) {
|
|
58
|
-
__extends(AccountOverviewReader, _super);
|
|
59
|
-
function AccountOverviewReader() {
|
|
60
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
61
|
-
}
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { AccountOverviewSchema, AccountOverviewWsMessageSchema, } from "./account-overview.types";
|
|
3
|
+
export class AccountOverviewReader extends BaseReader {
|
|
62
4
|
/**
|
|
63
5
|
* Get the account overview for a given user
|
|
64
6
|
* @param subAddr The subaccount address to get the account overview for
|
|
65
7
|
* @returns The account overview for the given subaccount address
|
|
66
8
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
return [4 /*yield*/, this.getRequest({
|
|
79
|
-
schema: account_overview_types_1.AccountOverviewSchema,
|
|
80
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/account_overviews"),
|
|
81
|
-
queryParams: queryParams,
|
|
82
|
-
options: fetchOptions,
|
|
83
|
-
})];
|
|
84
|
-
case 1:
|
|
85
|
-
response = _c.sent();
|
|
86
|
-
return [2 /*return*/, response.data];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
9
|
+
async getByAddr({ subAddr, volumeWindow, fetchOptions }) {
|
|
10
|
+
const queryParams = new URLSearchParams({ user: subAddr });
|
|
11
|
+
if (volumeWindow) {
|
|
12
|
+
queryParams.set("volume_window", volumeWindow);
|
|
13
|
+
}
|
|
14
|
+
const response = await this.getRequest({
|
|
15
|
+
schema: AccountOverviewSchema,
|
|
16
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/account_overviews`,
|
|
17
|
+
queryParams,
|
|
18
|
+
options: fetchOptions,
|
|
89
19
|
});
|
|
90
|
-
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
91
22
|
/**
|
|
92
23
|
* Subscribe to account overview
|
|
93
24
|
* @param subAddr The subaccount address of the user to subscribe to
|
|
94
25
|
* @param onData Callback function for received account overview data
|
|
95
26
|
* @returns A function to unsubscribe from the account overview updates
|
|
96
27
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return this.deps.ws.subscribe(topic,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}(base_reader_1.BaseReader));
|
|
103
|
-
exports.AccountOverviewReader = AccountOverviewReader;
|
|
28
|
+
subscribeByAddr(subAddr, onData) {
|
|
29
|
+
const topic = `account_overview:${subAddr}`;
|
|
30
|
+
return this.deps.ws.subscribe(topic, AccountOverviewWsMessageSchema, onData);
|
|
31
|
+
}
|
|
32
|
+
}
|