@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.
Files changed (53) hide show
  1. package/.github/workflows/npm_publish.yml +26 -0
  2. package/dist/base.d.ts +4 -2
  3. package/dist/base.d.ts.map +1 -1
  4. package/dist/base.js +40 -49
  5. package/dist/constants.d.ts +2 -11
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +21 -29
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/read/account-overview/account-overview.reader.d.ts +2 -1
  12. package/dist/read/account-overview/account-overview.reader.d.ts.map +1 -1
  13. package/dist/read/account-overview/account-overview.reader.js +4 -3
  14. package/dist/read/account-overview/account-overview.types.d.ts +10 -7
  15. package/dist/read/account-overview/account-overview.types.d.ts.map +1 -1
  16. package/dist/read/account-overview/account-overview.types.js +1 -0
  17. package/dist/read/index.d.ts +9 -2
  18. package/dist/read/index.d.ts.map +1 -1
  19. package/dist/read/index.js +18 -2
  20. package/dist/read/types.d.ts +1 -0
  21. package/dist/read/types.d.ts.map +1 -1
  22. package/dist/read/user-positions/user-positions.types.d.ts +14 -14
  23. package/dist/read/ws-subscription.js +1 -1
  24. package/dist/release-config.d.ts +23 -0
  25. package/dist/release-config.d.ts.map +1 -0
  26. package/dist/release-config.js +34 -0
  27. package/dist/transaction-builder.d.ts +1 -0
  28. package/dist/transaction-builder.d.ts.map +1 -1
  29. package/dist/transaction-builder.js +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/dist/utils.d.ts +2 -4
  32. package/dist/utils.d.ts.map +1 -1
  33. package/dist/utils.js +5 -15
  34. package/dist/write.d.ts.map +1 -1
  35. package/dist/write.js +3 -3
  36. package/package.json +33 -25
  37. package/readme.md +1 -1
  38. package/src/base.ts +60 -56
  39. package/src/constants.ts +22 -32
  40. package/src/index.ts +1 -0
  41. package/src/read/account-overview/account-overview.reader.ts +8 -4
  42. package/src/read/account-overview/account-overview.types.ts +2 -0
  43. package/src/read/index.ts +19 -2
  44. package/src/read/types.ts +1 -0
  45. package/src/read/ws-subscription.ts +1 -1
  46. package/src/release-config.ts +47 -0
  47. package/src/transaction-builder.ts +2 -1
  48. package/src/utils.ts +8 -20
  49. package/src/write.ts +9 -3
  50. package/.env +0 -2
  51. package/.turbo/turbo-build.log +0 -4
  52. package/.turbo/turbo-lint$colon$check.log +0 -5
  53. 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(payload: InputGenerateTransactionPayloadData, sender: AccountAddress) {
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
- let gasUnitPrice: number;
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 transaction = await this.getSimulatedTx(payload, sender);
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
- const senderAuthenticator = this.aptos.transaction.sign({
207
- signer,
208
- transaction,
209
- });
179
+ if (typeof sim === "undefined") {
180
+ throw new Error("Transaction simulation returned no results");
181
+ }
210
182
 
211
- const pendingTransaction = await this.submitTx(transaction, senderAuthenticator);
183
+ if (!sim.max_gas_amount || !sim.gas_unit_price) {
184
+ throw new Error("Transaction simulation returned no results");
185
+ }
212
186
 
213
- return await this.aptos.waitForTransaction({
214
- transactionHash: pendingTransaction.hash,
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 enum CompatVersion {
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 NETNA_PACKAGE = "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95";
62
- export const NETNA_DEPLOYMENT: Deployment = {
63
- package: NETNA_PACKAGE,
64
- usdc: getUsdcAddress(NETNA_PACKAGE).toString(),
65
- testc: getTestcAddress(NETNA_PACKAGE).toString(),
66
- perpEngineGlobal: getPerpEngineGlobalAddress(NETNA_PACKAGE).toString(),
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: NETNA_DEPLOYMENT,
76
- chainId: 207,
77
- compatVersion: DEFAULT_COMPAT_VERSION,
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: TESTNET_PACKAGE,
83
- usdc: getUsdcAddress(TESTNET_PACKAGE).toString(),
84
- testc: getTestcAddress(TESTNET_PACKAGE).toString(),
85
- perpEngineGlobal: getPerpEngineGlobalAddress(TESTNET_PACKAGE).toString(),
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: TESTNET_DEPLOYMENT,
84
+ deployment: getDeployment(PACKAGE.TESTNET),
95
85
  chainId: 2,
96
- compatVersion: TESTNET_COMPAT_VERSION,
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: NETNA_DEPLOYMENT,
106
- compatVersion: DEFAULT_COMPAT_VERSION,
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: NETNA_DEPLOYMENT,
117
- compatVersion: DEFAULT_COMPAT_VERSION,
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({ subAddr, volumeWindow, fetchOptions }: AccountOverviewRequestArgs) {
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
- queryParams.set("volume_window", volumeWindow);
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(addr: string | AccountAddress): Promise<number> {
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
@@ -98,6 +98,7 @@ export interface SortParams<T extends string> {
98
98
 
99
99
  // Vaults
100
100
  export interface CreateVaultArgs {
101
+ subaccountAddr?: string | null;
101
102
  contributionAssetType?: string;
102
103
  vaultName: string;
103
104
  vaultDescription: string;
@@ -52,7 +52,7 @@ export class DecibelWsSubscription {
52
52
 
53
53
  ws.addEventListener("open", () => {
54
54
  this.#reconnectAttempts = 0;
55
- for (const topic of Array.from(this.#subscriptions.keys())) {
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 { CompatVersion, DecibelConfig, QUERY_PARAM_KEYS } from "./constants";
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
- const getCompatVersionAsNumber = (compatVersion: CompatVersion) => {
179
- return Number(compatVersion.split(".")[1]);
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
- config: DecibelConfig,
192
- options?: { overrideCompatVersion?: CompatVersion },
186
+ variant: SubaccountVariant,
193
187
  ) {
194
188
  const account = typeof addr === "string" ? AccountAddress.fromString(addr) : addr;
195
- if (
196
- options?.overrideCompatVersion &&
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(this.account.accountAddress, this.config);
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(this.account.accountAddress, this.config);
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
@@ -1,2 +0,0 @@
1
- PRIVATE_KEY=0xd4921c3d737e43777c14e97c01982f450f9697ba2b39b3ae1091722a1f6f1f2d
2
- APTOS_NODE_API_KEY=AG-4HPTSMWKF56ECP7YVTFK67RQNMMRRDKIO
@@ -1,4 +0,0 @@
1
-
2
- > @decibeltrade/sdk@0.1.4 build /Users/sid/Desktop/Decibel/etna/typescript/packages/sdk
3
- > tsc
4
-
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > @perpdex/sdk@0.1.0 lint:check /Users/sid/Desktop/Decibel/etna/typescript/packages/sdk
4
- > eslint src --max-warnings 0
5
-
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > @decibeltrade/sdk@0.1.4 lint /Users/sid/Desktop/Decibel/etna/typescript/packages/sdk
4
- > eslint src --fix --max-warnings 0
5
-