@decibeltrade/sdk 0.2.5 → 0.2.6
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/.github/workflows/npm_publish.yml +26 -0
- package/dist/base.d.ts +4 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +40 -49
- package/dist/constants.d.ts +2 -11
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +21 -29
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/read/account-overview/account-overview.reader.d.ts +2 -1
- package/dist/read/account-overview/account-overview.reader.d.ts.map +1 -1
- package/dist/read/account-overview/account-overview.reader.js +4 -3
- package/dist/read/account-overview/account-overview.types.d.ts +10 -7
- package/dist/read/account-overview/account-overview.types.d.ts.map +1 -1
- package/dist/read/account-overview/account-overview.types.js +1 -0
- package/dist/read/index.d.ts +9 -2
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +18 -2
- package/dist/read/types.d.ts +1 -0
- package/dist/read/types.d.ts.map +1 -1
- package/dist/read/user-positions/user-positions.types.d.ts +14 -14
- package/dist/read/ws-subscription.js +1 -1
- package/dist/release-config.d.ts +23 -0
- package/dist/release-config.d.ts.map +1 -0
- package/dist/release-config.js +34 -0
- package/dist/transaction-builder.d.ts +1 -0
- package/dist/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.d.ts +2 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +5 -15
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +3 -3
- package/package.json +33 -25
- package/readme.md +1 -1
- package/src/base.ts +60 -56
- package/src/constants.ts +22 -32
- package/src/index.ts +1 -0
- package/src/read/account-overview/account-overview.reader.ts +8 -4
- package/src/read/account-overview/account-overview.types.ts +2 -0
- package/src/read/index.ts +19 -2
- package/src/read/types.ts +1 -0
- package/src/read/ws-subscription.ts +1 -1
- package/src/release-config.ts +47 -0
- package/src/transaction-builder.ts +2 -1
- package/src/utils.ts +8 -20
- package/src/write.ts +9 -3
- package/.env +0 -2
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-lint$colon$check.log +0 -5
- package/.turbo/turbo-lint.log +0 -5
package/package.json
CHANGED
|
@@ -1,39 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@decibeltrade/sdk",
|
|
3
|
-
"version": "0.2.5",
|
|
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
2
|
"dependencies": {
|
|
21
3
|
"isomorphic-ws": "^5.0.0",
|
|
22
4
|
"ws": "^8.18.1"
|
|
23
5
|
},
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"@aptos-labs/ts-sdk": "^5.1.2",
|
|
26
|
-
"@types/ws": "^8.18.0",
|
|
27
|
-
"zod": "^3.25.62"
|
|
28
|
-
},
|
|
29
6
|
"devDependencies": {
|
|
30
7
|
"@decibeltrade/eslint-config": "1.0.0",
|
|
31
8
|
"@decibeltrade/tsconfig": "1.0.1",
|
|
32
9
|
"@types/estree": "^1.0.6",
|
|
33
10
|
"eslint": "^9.28.0",
|
|
11
|
+
"tsx": "^4.20.5",
|
|
34
12
|
"typescript": "^5.8.3",
|
|
35
13
|
"typescript-eslint": "^8.46.2",
|
|
36
|
-
"tsx": "^4.20.5",
|
|
37
14
|
"vitest": "^3.1.1"
|
|
38
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"default": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"name": "@decibeltrade/sdk",
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@aptos-labs/ts-sdk": "^5.1.2",
|
|
26
|
+
"@types/ws": "^8.18.0",
|
|
27
|
+
"zod": "^3.25.62"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/decibeltrade/sdk.git"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc --watch",
|
|
39
|
+
"generate:abis": "tsx src/abi/generate-abis.ts",
|
|
40
|
+
"lint": "eslint src --fix --max-warnings 0",
|
|
41
|
+
"lint:check": "eslint src --max-warnings 0",
|
|
42
|
+
"test": "vitest run --passWithNoTests"
|
|
43
|
+
},
|
|
44
|
+
"type": "module",
|
|
45
|
+
"types": "dist/index.d.ts",
|
|
46
|
+
"version": "0.2.6"
|
|
39
47
|
}
|
package/readme.md
CHANGED
|
@@ -730,7 +730,7 @@ export enum CandlestickInterval {
|
|
|
730
730
|
import { getPrimarySubaccountAddr, getMarketAddr } from "@decibeltrade/sdk";
|
|
731
731
|
|
|
732
732
|
// Get primary subaccount address for an account
|
|
733
|
-
const subaccountAddr = getPrimarySubaccountAddr("account_address", sdkConfig);
|
|
733
|
+
const subaccountAddr = getPrimarySubaccountAddr("account_address", sdkConfig.subaccountVariant);
|
|
734
734
|
|
|
735
735
|
// Get market address from name
|
|
736
736
|
const marketAddr = getMarketAddr("BTC-USD", "perp_engine_global_address");
|
package/src/base.ts
CHANGED
|
@@ -84,40 +84,6 @@ export class BaseSDK {
|
|
|
84
84
|
return this.abi.abis[functionId] ?? null;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
private async getSimulatedTx(
|
|
88
|
-
payload: InputGenerateTransactionPayloadData,
|
|
89
|
-
sender: AccountAddress,
|
|
90
|
-
) {
|
|
91
|
-
const transaction = await this.aptos.transaction.build.simple({
|
|
92
|
-
sender,
|
|
93
|
-
data: payload,
|
|
94
|
-
});
|
|
95
|
-
const [sim] = await this.aptos.transaction.simulate.simple({
|
|
96
|
-
transaction,
|
|
97
|
-
options: {
|
|
98
|
-
estimateMaxGasAmount: true,
|
|
99
|
-
estimateGasUnitPrice: true,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (typeof sim === "undefined") {
|
|
104
|
-
throw new Error("Transaction simulation returned no results");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!sim.max_gas_amount || !sim.gas_unit_price) {
|
|
108
|
-
throw new Error("Transaction simulation returned no results");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return await this.aptos.transaction.build.simple({
|
|
112
|
-
sender,
|
|
113
|
-
data: payload,
|
|
114
|
-
options: {
|
|
115
|
-
maxGasAmount: Number(sim.max_gas_amount),
|
|
116
|
-
gasUnitPrice: Number(sim.gas_unit_price),
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
87
|
public async submitTx(
|
|
122
88
|
transaction: SimpleTransaction,
|
|
123
89
|
senderAuthenticator: AccountAuthenticator,
|
|
@@ -132,7 +98,14 @@ export class BaseSDK {
|
|
|
132
98
|
}
|
|
133
99
|
}
|
|
134
100
|
|
|
135
|
-
public async buildTx(
|
|
101
|
+
public async buildTx(
|
|
102
|
+
{
|
|
103
|
+
maxGasAmount,
|
|
104
|
+
gasUnitPrice,
|
|
105
|
+
...payload
|
|
106
|
+
}: InputGenerateTransactionPayloadData & { maxGasAmount?: number; gasUnitPrice?: number },
|
|
107
|
+
sender: AccountAddress,
|
|
108
|
+
) {
|
|
136
109
|
const functionAbi = "function" in payload ? this.getABI(payload.function) : undefined;
|
|
137
110
|
const withFeePayer = !this.noFeePayer;
|
|
138
111
|
|
|
@@ -148,9 +121,7 @@ export class BaseSDK {
|
|
|
148
121
|
// If we have functionAbi and chainId, we can use the sync function to generate the transaction
|
|
149
122
|
// This is faster than the async function
|
|
150
123
|
if (functionAbi && this.chainId) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (this.gasPriceManager) {
|
|
124
|
+
if (gasUnitPrice === undefined && this.gasPriceManager) {
|
|
154
125
|
// 1. Try getting from cache
|
|
155
126
|
// 2. If not available, try fetching from gasmanager, this also sets the gas price in the cache for future use
|
|
156
127
|
gasUnitPrice =
|
|
@@ -170,6 +141,7 @@ export class BaseSDK {
|
|
|
170
141
|
chainId: this.chainId,
|
|
171
142
|
gasUnitPrice,
|
|
172
143
|
timeDeltaMs: this.timeDeltaMs,
|
|
144
|
+
maxGasAmount,
|
|
173
145
|
});
|
|
174
146
|
} else {
|
|
175
147
|
// This is a fallback, should not happen, but works if due to any issues, functionAbi or chainId is not present
|
|
@@ -180,6 +152,8 @@ export class BaseSDK {
|
|
|
180
152
|
withFeePayer,
|
|
181
153
|
options: {
|
|
182
154
|
replayProtectionNonce,
|
|
155
|
+
maxGasAmount,
|
|
156
|
+
gasUnitPrice,
|
|
183
157
|
},
|
|
184
158
|
});
|
|
185
159
|
}
|
|
@@ -190,33 +164,63 @@ export class BaseSDK {
|
|
|
190
164
|
protected async sendTx(payload: InputGenerateTransactionPayloadData, accountOverride?: Account) {
|
|
191
165
|
const signer = accountOverride ?? this.account;
|
|
192
166
|
const sender = signer.accountAddress;
|
|
167
|
+
|
|
168
|
+
let transaction = await this.buildTx(payload, sender);
|
|
169
|
+
|
|
193
170
|
if (!this.skipSimulate) {
|
|
194
|
-
const
|
|
195
|
-
const senderAuthenticator = this.aptos.transaction.sign({
|
|
196
|
-
signer,
|
|
171
|
+
const [sim] = await this.aptos.transaction.simulate.simple({
|
|
197
172
|
transaction,
|
|
173
|
+
options: {
|
|
174
|
+
estimateMaxGasAmount: true,
|
|
175
|
+
estimateGasUnitPrice: true,
|
|
176
|
+
},
|
|
198
177
|
});
|
|
199
|
-
const pendingTransaction = await this.submitTx(transaction, senderAuthenticator);
|
|
200
|
-
return await this.aptos.waitForTransaction({
|
|
201
|
-
transactionHash: pendingTransaction.hash,
|
|
202
|
-
});
|
|
203
|
-
} else {
|
|
204
|
-
const transaction = await this.buildTx(payload, sender);
|
|
205
178
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
179
|
+
if (typeof sim === "undefined") {
|
|
180
|
+
throw new Error("Transaction simulation returned no results");
|
|
181
|
+
}
|
|
210
182
|
|
|
211
|
-
|
|
183
|
+
if (!sim.max_gas_amount || !sim.gas_unit_price) {
|
|
184
|
+
throw new Error("Transaction simulation returned no results");
|
|
185
|
+
}
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
187
|
+
const simulatedMaxGas = Number(sim.max_gas_amount);
|
|
188
|
+
const simulatedGasPrice = Number(sim.gas_unit_price);
|
|
189
|
+
const defaultMaxGasAmount = this.aptos.config.getDefaultMaxGasAmount();
|
|
190
|
+
|
|
191
|
+
// @Todo: Look into this more, maybe we can use the simulation results directly
|
|
192
|
+
// Ensure maxGasAmount is at least the default and add a 2x buffer
|
|
193
|
+
// The simulation might return very low values, so we need to ensure minimums
|
|
194
|
+
const maxGasAmount = Math.max(
|
|
195
|
+
Math.ceil(simulatedMaxGas * 2), // 2x buffer from simulation
|
|
196
|
+
defaultMaxGasAmount, // At least the default minimum
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const gasUnitPrice = Math.max(simulatedGasPrice, 1);
|
|
200
|
+
|
|
201
|
+
transaction = await this.buildTx(
|
|
202
|
+
{
|
|
203
|
+
...payload,
|
|
204
|
+
maxGasAmount,
|
|
205
|
+
gasUnitPrice,
|
|
206
|
+
},
|
|
207
|
+
sender,
|
|
208
|
+
);
|
|
216
209
|
}
|
|
210
|
+
|
|
211
|
+
const senderAuthenticator = this.aptos.transaction.sign({
|
|
212
|
+
signer,
|
|
213
|
+
transaction,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const pendingTransaction = await this.submitTx(transaction, senderAuthenticator);
|
|
217
|
+
|
|
218
|
+
return await this.aptos.waitForTransaction({
|
|
219
|
+
transactionHash: pendingTransaction.hash,
|
|
220
|
+
});
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
public getPrimarySubaccountAddress(addr: AccountAddress | string) {
|
|
220
|
-
return getPrimarySubaccountAddr(addr, this.config);
|
|
224
|
+
return getPrimarySubaccountAddr(addr, this.config.subaccountVariant);
|
|
221
225
|
}
|
|
222
226
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountAddress, Aptos, createObjectAddress, Network } from "@aptos-labs/ts-sdk";
|
|
2
2
|
|
|
3
3
|
import { DecibelWsSubscription } from "./read/ws-subscription";
|
|
4
|
+
import { CompatVersion, PACKAGE, RELEASE_CONFIGS, ReleaseConfig } from "./release-config";
|
|
4
5
|
|
|
5
6
|
export function getUsdcAddress(publisherAddr: string) {
|
|
6
7
|
return createObjectAddress(
|
|
@@ -23,17 +24,7 @@ export function getPerpEngineGlobalAddress(publisherAddr: string) {
|
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export
|
|
27
|
-
V0_0 = "v0.0", // decibel-testnet-release-v0.0
|
|
28
|
-
V0_1 = "v0.1", // decibel-testnet-release-v0.1
|
|
29
|
-
V0_2 = "v0.2", // decibel-testnet-release-v0.2
|
|
30
|
-
V0_3 = "v0.3", // Current main branch (bumped when new branch is created)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const TESTNET_COMPAT_VERSION = CompatVersion.V0_2;
|
|
34
|
-
export const DEFAULT_COMPAT_VERSION = CompatVersion.V0_3;
|
|
35
|
-
|
|
36
|
-
export interface DecibelConfig {
|
|
27
|
+
export interface DecibelConfig extends ReleaseConfig {
|
|
37
28
|
network: Network;
|
|
38
29
|
fullnodeUrl: string;
|
|
39
30
|
tradingHttpUrl: string;
|
|
@@ -41,7 +32,6 @@ export interface DecibelConfig {
|
|
|
41
32
|
gasStationUrl: string;
|
|
42
33
|
deployment: Deployment;
|
|
43
34
|
chainId?: number;
|
|
44
|
-
compatVersion: CompatVersion;
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
export interface DecibelReaderDeps {
|
|
@@ -58,12 +48,13 @@ export interface Deployment {
|
|
|
58
48
|
perpEngineGlobal: string;
|
|
59
49
|
}
|
|
60
50
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
const getDeployment = (pkg: string): Deployment => {
|
|
52
|
+
return {
|
|
53
|
+
package: pkg,
|
|
54
|
+
usdc: getUsdcAddress(pkg).toString(),
|
|
55
|
+
testc: getTestcAddress(pkg).toString(),
|
|
56
|
+
perpEngineGlobal: getPerpEngineGlobalAddress(pkg).toString(),
|
|
57
|
+
};
|
|
67
58
|
};
|
|
68
59
|
|
|
69
60
|
export const NETNA_CONFIG: DecibelConfig = {
|
|
@@ -72,17 +63,16 @@ export const NETNA_CONFIG: DecibelConfig = {
|
|
|
72
63
|
tradingHttpUrl: "https://api.netna.aptoslabs.com/decibel",
|
|
73
64
|
tradingWsUrl: "wss://api.netna.aptoslabs.com/decibel/ws",
|
|
74
65
|
gasStationUrl: "https://fee-payer-dev-netna-us-central1-410192433417.us-central1.run.app",
|
|
75
|
-
deployment:
|
|
76
|
-
chainId:
|
|
77
|
-
|
|
66
|
+
deployment: getDeployment(PACKAGE.NETNA),
|
|
67
|
+
chainId: 208,
|
|
68
|
+
...RELEASE_CONFIGS.NETNA,
|
|
78
69
|
};
|
|
79
70
|
|
|
80
|
-
const TESTNET_PACKAGE = "0x9f830083a19fb8b87395983ca9edaea2b0379c97be6dfe234bb914e6c6672844";
|
|
81
71
|
export const TESTNET_DEPLOYMENT: Deployment = {
|
|
82
|
-
package:
|
|
83
|
-
usdc: getUsdcAddress(
|
|
84
|
-
testc: getTestcAddress(
|
|
85
|
-
perpEngineGlobal: getPerpEngineGlobalAddress(
|
|
72
|
+
package: PACKAGE.TESTNET,
|
|
73
|
+
usdc: getUsdcAddress(PACKAGE.TESTNET).toString(),
|
|
74
|
+
testc: getTestcAddress(PACKAGE.TESTNET).toString(),
|
|
75
|
+
perpEngineGlobal: getPerpEngineGlobalAddress(PACKAGE.TESTNET).toString(),
|
|
86
76
|
};
|
|
87
77
|
|
|
88
78
|
export const TESTNET_CONFIG: DecibelConfig = {
|
|
@@ -91,9 +81,9 @@ export const TESTNET_CONFIG: DecibelConfig = {
|
|
|
91
81
|
tradingHttpUrl: "https://api.testnet.aptoslabs.com/decibel",
|
|
92
82
|
tradingWsUrl: "wss://api.testnet.aptoslabs.com/decibel/ws",
|
|
93
83
|
gasStationUrl: "https://fee-payer-staging-testnet-us-central1-502735673999.us-central1.run.app",
|
|
94
|
-
deployment:
|
|
84
|
+
deployment: getDeployment(PACKAGE.TESTNET),
|
|
95
85
|
chainId: 2,
|
|
96
|
-
|
|
86
|
+
...RELEASE_CONFIGS.TESTNET,
|
|
97
87
|
};
|
|
98
88
|
|
|
99
89
|
export const LOCAL_CONFIG: DecibelConfig = {
|
|
@@ -102,8 +92,8 @@ export const LOCAL_CONFIG: DecibelConfig = {
|
|
|
102
92
|
tradingHttpUrl: "http://localhost:8084",
|
|
103
93
|
tradingWsUrl: "ws://localhost:8083",
|
|
104
94
|
gasStationUrl: "http://localhost:8085",
|
|
105
|
-
deployment:
|
|
106
|
-
|
|
95
|
+
deployment: getDeployment(PACKAGE.NETNA),
|
|
96
|
+
...RELEASE_CONFIGS.LOCAL,
|
|
107
97
|
};
|
|
108
98
|
|
|
109
99
|
export const DOCKER_CONFIG: DecibelConfig = {
|
|
@@ -113,8 +103,8 @@ export const DOCKER_CONFIG: DecibelConfig = {
|
|
|
113
103
|
// nosemgrep: javascript.lang.security.detect-insecure-websocket.detect-insecure-websocket
|
|
114
104
|
tradingWsUrl: "ws://trading-api-ws:8080",
|
|
115
105
|
gasStationUrl: "http://fee-payer:8080",
|
|
116
|
-
deployment:
|
|
117
|
-
|
|
106
|
+
deployment: getDeployment(PACKAGE.NETNA),
|
|
107
|
+
...RELEASE_CONFIGS.DOCKER,
|
|
118
108
|
};
|
|
119
109
|
|
|
120
110
|
export const NAMED_CONFIGS: Record<string, DecibelConfig | undefined> = {
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./gas/gas-price-manager";
|
|
|
5
5
|
export * from "./order-event.types";
|
|
6
6
|
export * from "./order-status";
|
|
7
7
|
export * from "./read/index";
|
|
8
|
+
export * from "./release-config";
|
|
8
9
|
export * from "./subaccount-types";
|
|
9
10
|
export * from "./utils";
|
|
10
11
|
export * from "./write";
|
|
@@ -12,12 +12,16 @@ export class AccountOverviewReader extends BaseReader {
|
|
|
12
12
|
* @param subAddr The subaccount address to get the account overview for
|
|
13
13
|
* @returns The account overview for the given subaccount address
|
|
14
14
|
*/
|
|
15
|
-
async getByAddr({
|
|
15
|
+
async getByAddr({
|
|
16
|
+
subAddr,
|
|
17
|
+
volumeWindow,
|
|
18
|
+
fetchOptions,
|
|
19
|
+
includePerformance,
|
|
20
|
+
}: AccountOverviewRequestArgs) {
|
|
16
21
|
const queryParams = new URLSearchParams({ user: subAddr });
|
|
17
22
|
|
|
18
|
-
if (volumeWindow)
|
|
19
|
-
|
|
20
|
-
}
|
|
23
|
+
if (volumeWindow) queryParams.set("volume_window", volumeWindow);
|
|
24
|
+
if (includePerformance) queryParams.set("include_performance", "true");
|
|
21
25
|
|
|
22
26
|
const response = await this.getRequest({
|
|
23
27
|
schema: AccountOverviewSchema,
|
|
@@ -5,6 +5,7 @@ import { BaseRequestArgs } from "../base-reader";
|
|
|
5
5
|
export interface AccountOverviewRequestArgs extends BaseRequestArgs {
|
|
6
6
|
subAddr: string;
|
|
7
7
|
volumeWindow?: VolumeWindow;
|
|
8
|
+
includePerformance?: boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const VolumeWindow = {
|
|
@@ -35,6 +36,7 @@ export const AccountOverviewSchema = z.object({
|
|
|
35
36
|
total_margin: z.number(),
|
|
36
37
|
usdc_cross_withdrawable_balance: z.number(),
|
|
37
38
|
usdc_isolated_withdrawable_balance: z.number(),
|
|
39
|
+
realized_pnl: z.number().nullable(),
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
export const AccountOverviewWsMessageSchema = z.object({
|
package/src/read/index.ts
CHANGED
|
@@ -186,12 +186,29 @@ export class DecibelReadDex {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
|
-
* Get the timestamp when the restricted mint limits reset (in seconds).
|
|
189
|
+
* Get the timestamp when the global restricted mint limits for NEW accounts reset (in seconds).
|
|
190
190
|
*
|
|
191
191
|
* @remarks This method is temporary and only for use in testnet. The restricted_mint_daily_reset_timestamp
|
|
192
192
|
* view function is a testnet-only feature and should be removed before mainnet deployment.
|
|
193
193
|
*/
|
|
194
|
-
async getTriggerResetMintTs(
|
|
194
|
+
async getTriggerResetMintTs(): Promise<number> {
|
|
195
|
+
const result = await this.deps.aptos.view<[string]>({
|
|
196
|
+
payload: {
|
|
197
|
+
function: `${this.config.deployment.package}::usdc::restricted_mint_daily_reset_timestamp`,
|
|
198
|
+
typeArguments: [],
|
|
199
|
+
functionArguments: [],
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
return Number(result[0]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get the timestamp when the account-specific restricted mint limits reset (in seconds).
|
|
207
|
+
*
|
|
208
|
+
* @remarks This method is temporary and only for use in testnet. The restricted_mint_daily_reset_timestamp_for
|
|
209
|
+
* view function is a testnet-only feature and should be removed before mainnet deployment.
|
|
210
|
+
*/
|
|
211
|
+
async getAccountTriggerResetMintTs(addr: string | AccountAddress): Promise<number> {
|
|
195
212
|
const result = await this.deps.aptos.view<[string]>({
|
|
196
213
|
payload: {
|
|
197
214
|
function: `${this.config.deployment.package}::usdc::restricted_mint_daily_reset_timestamp_for`,
|
package/src/read/types.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class DecibelWsSubscription {
|
|
|
52
52
|
|
|
53
53
|
ws.addEventListener("open", () => {
|
|
54
54
|
this.#reconnectAttempts = 0;
|
|
55
|
-
for (const topic of
|
|
55
|
+
for (const topic of this.#subscriptions.keys()) {
|
|
56
56
|
ws.send(this.#getSubscribeMessage(topic));
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export enum CompatVersion {
|
|
2
|
+
V0_0 = "v0.0", // decibel-testnet-release-v0.0
|
|
3
|
+
V0_1 = "v0.1", // decibel-testnet-release-v0.1
|
|
4
|
+
V0_2 = "v0.2", // decibel-testnet-release-v0.2
|
|
5
|
+
V0_3 = "v0.3", // Current main branch (bumped when new branch is created)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type SubaccountVariant = "v0" | "v1" | "v2";
|
|
9
|
+
|
|
10
|
+
export interface ReleaseConfig {
|
|
11
|
+
compatVersion: CompatVersion;
|
|
12
|
+
subaccountVariant: SubaccountVariant;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PACKAGE = {
|
|
16
|
+
NETNA: "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95",
|
|
17
|
+
TESTNET: "0x9f830083a19fb8b87395983ca9edaea2b0379c97be6dfe234bb914e6c6672844",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_COMPAT_VERSION = CompatVersion.V0_3;
|
|
21
|
+
|
|
22
|
+
const NETNA_RELEASE_CONFIG: ReleaseConfig = {
|
|
23
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
24
|
+
subaccountVariant: "v2",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const TESTNET_RELEASE_CONFIG: ReleaseConfig = {
|
|
28
|
+
compatVersion: CompatVersion.V0_2,
|
|
29
|
+
subaccountVariant: "v2",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const LOCAL_RELEASE_CONFIG: ReleaseConfig = {
|
|
33
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
34
|
+
subaccountVariant: "v1",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const DOCKER_RELEASE_CONFIG: ReleaseConfig = {
|
|
38
|
+
compatVersion: DEFAULT_COMPAT_VERSION,
|
|
39
|
+
subaccountVariant: "v1",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const RELEASE_CONFIGS = {
|
|
43
|
+
NETNA: NETNA_RELEASE_CONFIG,
|
|
44
|
+
TESTNET: TESTNET_RELEASE_CONFIG,
|
|
45
|
+
LOCAL: LOCAL_RELEASE_CONFIG,
|
|
46
|
+
DOCKER: DOCKER_RELEASE_CONFIG,
|
|
47
|
+
};
|
|
@@ -26,6 +26,7 @@ export function buildSimpleTransactionSync(args: {
|
|
|
26
26
|
withFeePayer: boolean;
|
|
27
27
|
replayProtectionNonce: bigint;
|
|
28
28
|
timeDeltaMs?: number;
|
|
29
|
+
maxGasAmount?: number;
|
|
29
30
|
}) {
|
|
30
31
|
const txnPayload = generateTransactionPayloadWithABI({
|
|
31
32
|
aptosConfig: args.aptosConfig,
|
|
@@ -44,7 +45,7 @@ export function buildSimpleTransactionSync(args: {
|
|
|
44
45
|
BigInt("0xdeadbeef"),
|
|
45
46
|
convertPayloadToInnerPayload(txnPayload, args.replayProtectionNonce),
|
|
46
47
|
// @Todo: Use gasPriceManager to get the max gas amount [as defaultMaxGasAmount might be very high number]
|
|
47
|
-
BigInt(args.aptosConfig.getDefaultMaxGasAmount()),
|
|
48
|
+
BigInt(args.maxGasAmount ?? args.aptosConfig.getDefaultMaxGasAmount()),
|
|
48
49
|
BigInt(args.gasUnitPrice),
|
|
49
50
|
BigInt(expireTimestamp),
|
|
50
51
|
new ChainId(args.chainId),
|
package/src/utils.ts
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
} from "@aptos-labs/ts-sdk";
|
|
7
7
|
import { z, ZodError } from "zod/v4";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { QUERY_PARAM_KEYS } from "./constants";
|
|
10
10
|
import { PageParams, SearchTermParams, SortParams } from "./read";
|
|
11
|
+
import { SubaccountVariant } from "./release-config";
|
|
11
12
|
|
|
12
13
|
export function getMarketAddr(name: string, perpEngineGlobalAddr: string) {
|
|
13
14
|
const marketNameBytes = new MoveString(name).bcsToBytes();
|
|
@@ -175,31 +176,18 @@ export function bigIntReviver(key: string, value: unknown) {
|
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
const baseSeed = "decibel_dex_primary";
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
181
|
-
const createSeed = (compatVersion: CompatVersion) => {
|
|
182
|
-
return new TextEncoder().encode(
|
|
183
|
-
compatVersion === CompatVersion.V0_0
|
|
184
|
-
? baseSeed
|
|
185
|
-
: `${baseSeed}_v${getCompatVersionAsNumber(compatVersion)}`,
|
|
186
|
-
);
|
|
179
|
+
|
|
180
|
+
const createSeed = (variant: SubaccountVariant) => {
|
|
181
|
+
return new TextEncoder().encode(variant === "v0" ? baseSeed : `${baseSeed}_${variant}`);
|
|
187
182
|
};
|
|
188
183
|
|
|
189
184
|
export function getPrimarySubaccountAddr(
|
|
190
185
|
addr: AccountAddress | string,
|
|
191
|
-
|
|
192
|
-
options?: { overrideCompatVersion?: CompatVersion },
|
|
186
|
+
variant: SubaccountVariant,
|
|
193
187
|
) {
|
|
194
188
|
const account = typeof addr === "string" ? AccountAddress.fromString(addr) : addr;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
getCompatVersionAsNumber(options.overrideCompatVersion) <=
|
|
198
|
-
getCompatVersionAsNumber(config.compatVersion)
|
|
199
|
-
) {
|
|
200
|
-
return createObjectAddress(account, createSeed(options.overrideCompatVersion)).toString();
|
|
201
|
-
}
|
|
202
|
-
return createObjectAddress(account, createSeed(config.compatVersion)).toString();
|
|
189
|
+
|
|
190
|
+
return createObjectAddress(account, createSeed(variant)).toString();
|
|
203
191
|
}
|
|
204
192
|
|
|
205
193
|
export function getTradingCompetitionSubaccountAddr(addr: AccountAddress | string) {
|
package/src/write.ts
CHANGED
|
@@ -106,14 +106,20 @@ export class DecibelWriteDex extends BaseSDK {
|
|
|
106
106
|
subaccountAddr?: string,
|
|
107
107
|
) {
|
|
108
108
|
if (!subaccountAddr) {
|
|
109
|
-
subaccountAddr = getPrimarySubaccountAddr(
|
|
109
|
+
subaccountAddr = getPrimarySubaccountAddr(
|
|
110
|
+
this.account.accountAddress,
|
|
111
|
+
this.config.subaccountVariant,
|
|
112
|
+
);
|
|
110
113
|
}
|
|
111
114
|
return await sendTx(subaccountAddr);
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
async withSubaccount<T>(fn: (subaccountAddr: string) => Promise<T>, subaccountAddr?: string) {
|
|
115
118
|
if (!subaccountAddr) {
|
|
116
|
-
subaccountAddr = getPrimarySubaccountAddr(
|
|
119
|
+
subaccountAddr = getPrimarySubaccountAddr(
|
|
120
|
+
this.account.accountAddress,
|
|
121
|
+
this.config.subaccountVariant,
|
|
122
|
+
);
|
|
117
123
|
}
|
|
118
124
|
return await fn(subaccountAddr);
|
|
119
125
|
}
|
|
@@ -771,7 +777,7 @@ export class DecibelWriteDex extends BaseSDK {
|
|
|
771
777
|
function: `${this.config.deployment.package}::${vaultApiModule}::create_and_fund_vault`,
|
|
772
778
|
typeArguments: [],
|
|
773
779
|
functionArguments: [
|
|
774
|
-
null,
|
|
780
|
+
args.subaccountAddr ?? null,
|
|
775
781
|
args.contributionAssetType,
|
|
776
782
|
args.vaultName,
|
|
777
783
|
args.vaultDescription,
|
package/.env
DELETED
package/.turbo/turbo-build.log
DELETED