@decibeltrade/sdk 0.2.6 → 0.2.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.
Files changed (66) hide show
  1. package/package.json +7 -1
  2. package/.github/workflows/npm_publish.yml +0 -26
  3. package/eslint.config.mjs +0 -25
  4. package/src/abi/generate-abis.ts +0 -164
  5. package/src/abi/json/netna.json +0 -1325
  6. package/src/abi/json/testnet.json +0 -1328
  7. package/src/abi/types.ts +0 -23
  8. package/src/admin.ts +0 -287
  9. package/src/base.ts +0 -226
  10. package/src/constants.ts +0 -131
  11. package/src/fee-pay.ts +0 -39
  12. package/src/gas/gas-price-manager.ts +0 -115
  13. package/src/index.ts +0 -11
  14. package/src/order-event.types.ts +0 -65
  15. package/src/order-status.ts +0 -89
  16. package/src/read/account-overview/account-overview.reader.ts +0 -47
  17. package/src/read/account-overview/account-overview.types.ts +0 -47
  18. package/src/read/base-reader.ts +0 -41
  19. package/src/read/candlesticks/candlesticks.reader.ts +0 -61
  20. package/src/read/candlesticks/candlesticks.types.ts +0 -46
  21. package/src/read/delegations/delegations.reader.ts +0 -22
  22. package/src/read/delegations/delegations.types.ts +0 -19
  23. package/src/read/index.ts +0 -288
  24. package/src/read/leaderboard/leaderboard.reader.ts +0 -21
  25. package/src/read/leaderboard/leaderboard.types.ts +0 -26
  26. package/src/read/market-contexts/market-contexts.reader.ts +0 -26
  27. package/src/read/market-contexts/market-contexts.types.ts +0 -17
  28. package/src/read/market-depth/market-depth.reader.ts +0 -60
  29. package/src/read/market-depth/market-depth.types.ts +0 -24
  30. package/src/read/market-prices/market-prices.reader.ts +0 -74
  31. package/src/read/market-prices/market-prices.types.ts +0 -41
  32. package/src/read/market-trades/market-trades.reader.ts +0 -46
  33. package/src/read/market-trades/market-trades.types.ts +0 -34
  34. package/src/read/markets/markets.reader.ts +0 -82
  35. package/src/read/markets/markets.types.ts +0 -54
  36. package/src/read/pagination.types.ts +0 -18
  37. package/src/read/portfolio-chart/portfolio-chart.reader.ts +0 -20
  38. package/src/read/portfolio-chart/portfolio-chart.types.ts +0 -21
  39. package/src/read/types.ts +0 -130
  40. package/src/read/user-active-twaps/user-active-twaps.reader.ts +0 -36
  41. package/src/read/user-active-twaps/user-active-twaps.types.ts +0 -33
  42. package/src/read/user-bulk-orders/user-bulk-orders.reader.ts +0 -37
  43. package/src/read/user-bulk-orders/user-bulk-orders.types.ts +0 -32
  44. package/src/read/user-funding-history/user-funding-history.reader.ts +0 -38
  45. package/src/read/user-funding-history/user-funding-history.types.ts +0 -29
  46. package/src/read/user-notifications/user-notifications.reader.ts +0 -17
  47. package/src/read/user-notifications/user-notifications.types.ts +0 -61
  48. package/src/read/user-open-orders/user-open-orders.reader.ts +0 -36
  49. package/src/read/user-open-orders/user-open-orders.types.ts +0 -42
  50. package/src/read/user-order-history/user-order-history.reader.ts +0 -34
  51. package/src/read/user-order-history/user-order-history.types.ts +0 -48
  52. package/src/read/user-positions/user-positions.reader.ts +0 -55
  53. package/src/read/user-positions/user-positions.types.ts +0 -42
  54. package/src/read/user-subaccounts/user-subaccounts.reader.ts +0 -30
  55. package/src/read/user-subaccounts/user-subaccounts.types.ts +0 -21
  56. package/src/read/user-trade-history/user-trade-history.reader.ts +0 -38
  57. package/src/read/user-trade-history/user-trade-history.types.ts +0 -33
  58. package/src/read/vaults/vaults.reader.ts +0 -81
  59. package/src/read/vaults/vaults.types.ts +0 -109
  60. package/src/read/ws-subscription.ts +0 -206
  61. package/src/release-config.ts +0 -47
  62. package/src/subaccount-types.ts +0 -31
  63. package/src/transaction-builder.ts +0 -76
  64. package/src/utils.ts +0 -289
  65. package/src/write.ts +0 -979
  66. package/tsconfig.json +0 -8
package/src/abi/types.ts DELETED
@@ -1,23 +0,0 @@
1
- import { MoveFunction, MoveFunctionId } from "@aptos-labs/ts-sdk";
2
-
3
- export type ABIs = Record<MoveFunctionId, MoveFunction>;
4
-
5
- export interface ABIData {
6
- packageAddress: string;
7
- network: string;
8
- fullnodeUrl: string;
9
- fetchedAt: string;
10
- abis: ABIs;
11
- errors: Array<{
12
- module: string;
13
- function: string;
14
- error: string;
15
- }>;
16
- summary: {
17
- totalModules: number;
18
- totalFunctions: number;
19
- successful: number;
20
- failed: number;
21
- };
22
- modules: string[];
23
- }
package/src/admin.ts DELETED
@@ -1,287 +0,0 @@
1
- import { AccountAddress, createObjectAddress } from "@aptos-labs/ts-sdk";
2
-
3
- import { BaseSDK } from "./base";
4
- import { getVaultApiModule } from "./constants";
5
- import { getMarketAddr } from "./utils";
6
-
7
- export class DecibelAdminDex extends BaseSDK {
8
- /**
9
- * Initialize the global vault system. Only callable by the admin account.
10
- */
11
- async initialize(
12
- collateralTokenAddr: string,
13
- collateralBalanceDecimals: number,
14
- backstopLiquidatorAddr: string,
15
- ) {
16
- return await this.sendTx({
17
- function: `${this.config.deployment.package}::admin_apis::initialize`,
18
- typeArguments: [],
19
- functionArguments: [collateralTokenAddr, collateralBalanceDecimals, backstopLiquidatorAddr],
20
- });
21
- }
22
-
23
- getProtocolVaultAddress(): AccountAddress {
24
- const vaultConfigObjectAddr = createObjectAddress(
25
- AccountAddress.fromString(this.config.deployment.package),
26
- "GlobalVaultConfig",
27
- );
28
- const protocolVaultObjectAddr = createObjectAddress(
29
- vaultConfigObjectAddr,
30
- "Decibel Protocol Vault",
31
- );
32
-
33
- return protocolVaultObjectAddr;
34
- }
35
-
36
- async initializeProtocolVault(collateralTokenAddr: string, initialFunding: number) {
37
- const vaultApiModule = getVaultApiModule(this.config.compatVersion);
38
- return await this.sendTx({
39
- function: `${this.config.deployment.package}::${vaultApiModule}::create_and_fund_vault`,
40
- typeArguments: [],
41
- functionArguments: [
42
- null,
43
- collateralTokenAddr,
44
- "Decibel Protocol Vault",
45
- "(description)",
46
- [],
47
- "DPV",
48
- "",
49
- "",
50
- 0, // fee_bps
51
- 0, // fee_interval
52
- 3 * 24 * 60 * 60, // contribution_lockup_duration_s
53
- initialFunding, // initial_funding
54
- true, // accepts_contributions
55
- false, // delegate_to_creator
56
- ],
57
- });
58
- }
59
-
60
- async delegateProtocolVaultTradingTo(vaultAddress: string, accountToDelegateTo: string) {
61
- return await this.sendTx({
62
- function: `${this.config.deployment.package}::vault::delegate_dex_actions_to`,
63
- typeArguments: [],
64
- functionArguments: [vaultAddress, accountToDelegateTo, undefined],
65
- });
66
- }
67
-
68
- async authorizeOracleAndMarkUpdate(internalOracleUpdater: string) {
69
- return await this.sendTx({
70
- function: `${this.config.deployment.package}::admin_apis::add_oracle_and_mark_update_permission`,
71
- typeArguments: [],
72
- functionArguments: [internalOracleUpdater],
73
- });
74
- }
75
-
76
- async registerMarketWithInternalOracle(
77
- name: string,
78
- szDecimals: number,
79
- minSize: number,
80
- lotSize: number,
81
- tickerSize: number,
82
- maxOpenInterest: number,
83
- maxLeverage: number,
84
- taker_in_next_block = true,
85
- initial_oracle_price = 1,
86
- max_staleness_secs = 60,
87
- ) {
88
- return await this.sendTx({
89
- function: `${this.config.deployment.package}::admin_apis::register_market_with_internal_oracle`,
90
- typeArguments: [],
91
- functionArguments: [
92
- name,
93
- szDecimals,
94
- minSize,
95
- lotSize,
96
- tickerSize,
97
- maxOpenInterest,
98
- maxLeverage,
99
- taker_in_next_block,
100
- initial_oracle_price,
101
- max_staleness_secs,
102
- ],
103
- });
104
- }
105
-
106
- async registerMarketWithPythOracle(
107
- name: string,
108
- szDecimals: number,
109
- minSize: number,
110
- lotSize: number,
111
- tickerSize: number,
112
- maxOpenInterest: number,
113
- maxLeverage: number,
114
- taker_in_next_block = true,
115
- pythIdentifierBytes: number[],
116
- pythMaxStalenessSecs: number,
117
- pythConfidenceIntervalThreshold: number,
118
- pythDecimals: number,
119
- ) {
120
- return await this.sendTx({
121
- function: `${this.config.deployment.package}::admin_apis::register_market_with_pyth_oracle`,
122
- typeArguments: [],
123
- functionArguments: [
124
- name,
125
- szDecimals,
126
- minSize,
127
- lotSize,
128
- tickerSize,
129
- maxOpenInterest,
130
- maxLeverage,
131
- taker_in_next_block,
132
- pythIdentifierBytes,
133
- pythMaxStalenessSecs,
134
- pythConfidenceIntervalThreshold,
135
- pythDecimals,
136
- ],
137
- });
138
- }
139
-
140
- async registerMarketWithCompositeOraclePrimaryPyth(
141
- name: string,
142
- szDecimals: number,
143
- minSize: number,
144
- lotSize: number,
145
- tickerSize: number,
146
- maxOpenInterest: number,
147
- maxLeverage: number,
148
- taker_in_next_block = true,
149
- pythIdentifierBytes: number[],
150
- pythMaxStalenessSecs: number,
151
- pythConfidenceIntervalThreshold: number,
152
- pythDecimals: number,
153
- internalInitialPrice: number,
154
- internalMaxStalenessSecs: number,
155
- oraclesDeviationBps: number,
156
- consecutiveDeviationCount: number,
157
- ) {
158
- return await this.sendTx({
159
- function: `${this.config.deployment.package}::admin_apis::register_market_with_composite_oracle_primary_pyth`,
160
- typeArguments: [],
161
- functionArguments: [
162
- name,
163
- szDecimals,
164
- minSize,
165
- lotSize,
166
- tickerSize,
167
- maxOpenInterest,
168
- maxLeverage,
169
- taker_in_next_block,
170
- pythIdentifierBytes,
171
- pythMaxStalenessSecs,
172
- pythConfidenceIntervalThreshold,
173
- pythDecimals,
174
- internalInitialPrice,
175
- internalMaxStalenessSecs,
176
- oraclesDeviationBps,
177
- consecutiveDeviationCount,
178
- ],
179
- });
180
- }
181
-
182
- async registerMarketWithCompositeOraclePrimaryChainlink(
183
- name: string,
184
- szDecimals: number,
185
- minSize: number,
186
- lotSize: number,
187
- tickerSize: number,
188
- maxOpenInterest: number,
189
- maxLeverage: number,
190
- taker_in_next_block = true,
191
- rescaleDecimals: number,
192
- chainlinkFeedIdBytes: number[],
193
- chainlinkMaxStalenessSecs: number,
194
- internalMaxStalenessSecs: number,
195
- internalInitialPrice: number,
196
- oraclesDeviationBps: number,
197
- consecutiveDeviationCount: number,
198
- ) {
199
- return await this.sendTx({
200
- function: `${this.config.deployment.package}::admin_apis::register_market_with_composite_oracle_primary_chainlink`,
201
- typeArguments: [],
202
- functionArguments: [
203
- name,
204
- szDecimals,
205
- minSize,
206
- lotSize,
207
- tickerSize,
208
- maxOpenInterest,
209
- maxLeverage,
210
- taker_in_next_block,
211
- chainlinkFeedIdBytes,
212
- chainlinkMaxStalenessSecs,
213
- rescaleDecimals,
214
- internalInitialPrice,
215
- internalMaxStalenessSecs,
216
- oraclesDeviationBps,
217
- consecutiveDeviationCount,
218
- ],
219
- });
220
- }
221
-
222
- async updateInternalOraclePrice(marketName: string, oraclePrice: number) {
223
- const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
224
- return await this.sendTx({
225
- function: `${this.config.deployment.package}::admin_apis::update_mark_for_internal_oracle`,
226
- typeArguments: [],
227
- functionArguments: [marketAddr, oraclePrice, [], true],
228
- });
229
- }
230
-
231
- async updatePythOraclePrice(marketName: string, vaa: number[]) {
232
- const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
233
- return await this.sendTx({
234
- function: `${this.config.deployment.package}::admin_apis::update_mark_for_pyth_oracle`,
235
- typeArguments: [],
236
- functionArguments: [marketAddr, vaa, [], true],
237
- });
238
- }
239
-
240
- async updatePriceToPythOnly(vaas: number[][]) {
241
- return await this.sendTx({
242
- function: `${this.config.deployment.package}::pyth::update_price_feeds_with_funder`,
243
- typeArguments: [],
244
- functionArguments: [vaas],
245
- });
246
- }
247
-
248
- async updatePriceToChainlinkOnly(signedReport: number[]) {
249
- return await this.sendTx({
250
- function: `${this.config.deployment.package}::chainlink_state::verify_and_store_single_price`,
251
- typeArguments: [],
252
- functionArguments: [signedReport],
253
- });
254
- }
255
-
256
- async mintUsdc(toAddr: AccountAddress, amount: number) {
257
- return await this.sendTx({
258
- function: `${this.config.deployment.package}::usdc::mint`,
259
- typeArguments: [],
260
- functionArguments: [toAddr, amount],
261
- });
262
- }
263
-
264
- async setPublicMinting(allow: boolean) {
265
- return await this.sendTx({
266
- function: `${this.config.deployment.package}::usdc::set_public_minting`,
267
- typeArguments: [],
268
- functionArguments: [allow],
269
- });
270
- }
271
-
272
- /**
273
- * Get the balance of USDC for an account
274
- * @param addr The account address to get the balance for
275
- * @returns The balance of USDC for the account
276
- */
277
- async usdcBalance(addr: AccountAddress) {
278
- const balance = await this.aptos.view<[number]>({
279
- payload: {
280
- function: `0x1::primary_fungible_store::balance`,
281
- typeArguments: [`0x1::fungible_asset::Metadata`],
282
- functionArguments: [addr, this.config.deployment.usdc],
283
- },
284
- });
285
- return balance[0];
286
- }
287
- }
package/src/base.ts DELETED
@@ -1,226 +0,0 @@
1
- import {
2
- Account,
3
- AccountAddress,
4
- AccountAuthenticator,
5
- Aptos,
6
- AptosConfig,
7
- InputEntryFunctionData,
8
- InputGenerateTransactionPayloadData,
9
- MoveFunction,
10
- MoveFunctionId,
11
- PendingTransactionResponse,
12
- SimpleTransaction,
13
- } from "@aptos-labs/ts-sdk";
14
-
15
- import netnaAbis from "./abi/json/netna.json";
16
- import testnetAbis from "./abi/json/testnet.json";
17
- import { ABIData } from "./abi/types";
18
- import { DecibelConfig, NETNA_CONFIG, TESTNET_CONFIG } from "./constants";
19
- import { submitFeePaidTransaction } from "./fee-pay";
20
- import { GasPriceManager } from "./gas/gas-price-manager";
21
- import { buildSimpleTransactionSync } from "./transaction-builder";
22
- import { generateRandomReplayProtectionNonce, getPrimarySubaccountAddr } from "./utils";
23
-
24
- export interface Options {
25
- skipSimulate?: boolean;
26
- noFeePayer?: boolean;
27
- nodeApiKey?: string;
28
- gasPriceManager?: GasPriceManager;
29
- /**
30
- * Time delta in milliseconds to add to Date.now() for expiration timestamps.
31
- * Used to sync with server time when client clock is incorrect.
32
- */
33
- timeDeltaMs?: number;
34
- }
35
-
36
- const chainIdToAbi: Record<number, ABIData> = {};
37
- if (NETNA_CONFIG.chainId) chainIdToAbi[NETNA_CONFIG.chainId] = netnaAbis as ABIData;
38
- if (TESTNET_CONFIG.chainId) chainIdToAbi[TESTNET_CONFIG.chainId] = testnetAbis as ABIData;
39
-
40
- export class BaseSDK {
41
- readonly aptos: Aptos;
42
- readonly skipSimulate: boolean;
43
- readonly noFeePayer: boolean;
44
- private readonly chainId: number | undefined;
45
- private readonly abi = netnaAbis as ABIData;
46
- private readonly gasPriceManager: GasPriceManager | undefined;
47
- /**
48
- * Time delta in milliseconds to add to Date.now() for expiration timestamps.
49
- */
50
- public timeDeltaMs: number;
51
-
52
- constructor(
53
- readonly config: DecibelConfig,
54
- /**
55
- * The main account
56
- */
57
- readonly account: Account,
58
- opts?: Options,
59
- ) {
60
- const abi = config.chainId ? chainIdToAbi[config.chainId] : null;
61
- if (abi) {
62
- this.abi = abi;
63
- } else {
64
- this.abi = netnaAbis as ABIData;
65
- console.warn(
66
- "Using NETNA ABI for unsupported chain id, this might cause issues with the transaction builder",
67
- );
68
- }
69
-
70
- const aptosConfig = new AptosConfig({
71
- network: config.network,
72
- fullnode: config.fullnodeUrl,
73
- clientConfig: { API_KEY: opts?.nodeApiKey },
74
- });
75
- this.aptos = new Aptos(aptosConfig);
76
- this.skipSimulate = opts?.skipSimulate ?? false;
77
- this.noFeePayer = opts?.noFeePayer ?? false;
78
- this.chainId = config.chainId;
79
- this.gasPriceManager = opts?.gasPriceManager;
80
- this.timeDeltaMs = opts?.timeDeltaMs ?? 0;
81
- }
82
-
83
- private getABI(functionId: MoveFunctionId): MoveFunction | null {
84
- return this.abi.abis[functionId] ?? null;
85
- }
86
-
87
- public async submitTx(
88
- transaction: SimpleTransaction,
89
- senderAuthenticator: AccountAuthenticator,
90
- ): Promise<PendingTransactionResponse> {
91
- if (this.noFeePayer) {
92
- return await this.aptos.transaction.submit.simple({
93
- transaction,
94
- senderAuthenticator,
95
- });
96
- } else {
97
- return await submitFeePaidTransaction(this.config, transaction, senderAuthenticator);
98
- }
99
- }
100
-
101
- public async buildTx(
102
- {
103
- maxGasAmount,
104
- gasUnitPrice,
105
- ...payload
106
- }: InputGenerateTransactionPayloadData & { maxGasAmount?: number; gasUnitPrice?: number },
107
- sender: AccountAddress,
108
- ) {
109
- const functionAbi = "function" in payload ? this.getABI(payload.function) : undefined;
110
- const withFeePayer = !this.noFeePayer;
111
-
112
- const replayProtectionNonce = generateRandomReplayProtectionNonce();
113
-
114
- // This should never happen, but just in case
115
- if (!replayProtectionNonce) {
116
- throw new Error("Unable to generate replayProtectionNonce");
117
- }
118
-
119
- let transaction: SimpleTransaction;
120
-
121
- // If we have functionAbi and chainId, we can use the sync function to generate the transaction
122
- // This is faster than the async function
123
- if (functionAbi && this.chainId) {
124
- if (gasUnitPrice === undefined && this.gasPriceManager) {
125
- // 1. Try getting from cache
126
- // 2. If not available, try fetching from gasmanager, this also sets the gas price in the cache for future use
127
- gasUnitPrice =
128
- this.gasPriceManager.getGasPrice() ?? (await this.gasPriceManager.fetchAndSetGasPrice());
129
- } else {
130
- // 1. Fetch from network, this is a fallback, should only happen if gasPriceManager is not set
131
- gasUnitPrice = (await this.aptos.getGasPriceEstimation()).gas_estimate;
132
- }
133
-
134
- transaction = buildSimpleTransactionSync({
135
- aptosConfig: this.aptos.config,
136
- sender,
137
- data: payload as InputEntryFunctionData,
138
- withFeePayer,
139
- replayProtectionNonce,
140
- abi: functionAbi,
141
- chainId: this.chainId,
142
- gasUnitPrice,
143
- timeDeltaMs: this.timeDeltaMs,
144
- maxGasAmount,
145
- });
146
- } else {
147
- // This is a fallback, should not happen, but works if due to any issues, functionAbi or chainId is not present
148
- // @Todo: Pass in Abi ideally, once we update aptos-ts-sdk to not refetch abi if abi is passed in payload
149
- transaction = await this.aptos.transaction.build.simple({
150
- sender,
151
- data: payload,
152
- withFeePayer,
153
- options: {
154
- replayProtectionNonce,
155
- maxGasAmount,
156
- gasUnitPrice,
157
- },
158
- });
159
- }
160
-
161
- return transaction;
162
- }
163
-
164
- protected async sendTx(payload: InputGenerateTransactionPayloadData, accountOverride?: Account) {
165
- const signer = accountOverride ?? this.account;
166
- const sender = signer.accountAddress;
167
-
168
- let transaction = await this.buildTx(payload, sender);
169
-
170
- if (!this.skipSimulate) {
171
- const [sim] = await this.aptos.transaction.simulate.simple({
172
- transaction,
173
- options: {
174
- estimateMaxGasAmount: true,
175
- estimateGasUnitPrice: true,
176
- },
177
- });
178
-
179
- if (typeof sim === "undefined") {
180
- throw new Error("Transaction simulation returned no results");
181
- }
182
-
183
- if (!sim.max_gas_amount || !sim.gas_unit_price) {
184
- throw new Error("Transaction simulation returned no results");
185
- }
186
-
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
- );
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
- });
221
- }
222
-
223
- public getPrimarySubaccountAddress(addr: AccountAddress | string) {
224
- return getPrimarySubaccountAddr(addr, this.config.subaccountVariant);
225
- }
226
- }
package/src/constants.ts DELETED
@@ -1,131 +0,0 @@
1
- import { AccountAddress, Aptos, createObjectAddress, Network } from "@aptos-labs/ts-sdk";
2
-
3
- import { DecibelWsSubscription } from "./read/ws-subscription";
4
- import { CompatVersion, PACKAGE, RELEASE_CONFIGS, ReleaseConfig } from "./release-config";
5
-
6
- export function getUsdcAddress(publisherAddr: string) {
7
- return createObjectAddress(
8
- AccountAddress.fromString(publisherAddr),
9
- new TextEncoder().encode("USDC"),
10
- );
11
- }
12
-
13
- export function getTestcAddress(publisherAddr: string) {
14
- return createObjectAddress(
15
- AccountAddress.fromString(publisherAddr),
16
- new TextEncoder().encode("TESTC"),
17
- );
18
- }
19
-
20
- export function getPerpEngineGlobalAddress(publisherAddr: string) {
21
- return createObjectAddress(
22
- AccountAddress.fromString(publisherAddr),
23
- new TextEncoder().encode("GlobalPerpEngine"),
24
- );
25
- }
26
-
27
- export interface DecibelConfig extends ReleaseConfig {
28
- network: Network;
29
- fullnodeUrl: string;
30
- tradingHttpUrl: string;
31
- tradingWsUrl: string;
32
- gasStationUrl: string;
33
- deployment: Deployment;
34
- chainId?: number;
35
- }
36
-
37
- export interface DecibelReaderDeps {
38
- aptos: Aptos;
39
- ws: DecibelWsSubscription;
40
- config: DecibelConfig;
41
- apiKey?: string;
42
- }
43
-
44
- export interface Deployment {
45
- package: string;
46
- usdc: string;
47
- testc: string;
48
- perpEngineGlobal: string;
49
- }
50
-
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
- };
58
- };
59
-
60
- export const NETNA_CONFIG: DecibelConfig = {
61
- network: Network.CUSTOM,
62
- fullnodeUrl: "https://api.netna.aptoslabs.com/v1",
63
- tradingHttpUrl: "https://api.netna.aptoslabs.com/decibel",
64
- tradingWsUrl: "wss://api.netna.aptoslabs.com/decibel/ws",
65
- gasStationUrl: "https://fee-payer-dev-netna-us-central1-410192433417.us-central1.run.app",
66
- deployment: getDeployment(PACKAGE.NETNA),
67
- chainId: 208,
68
- ...RELEASE_CONFIGS.NETNA,
69
- };
70
-
71
- export const TESTNET_DEPLOYMENT: Deployment = {
72
- package: PACKAGE.TESTNET,
73
- usdc: getUsdcAddress(PACKAGE.TESTNET).toString(),
74
- testc: getTestcAddress(PACKAGE.TESTNET).toString(),
75
- perpEngineGlobal: getPerpEngineGlobalAddress(PACKAGE.TESTNET).toString(),
76
- };
77
-
78
- export const TESTNET_CONFIG: DecibelConfig = {
79
- network: Network.TESTNET,
80
- fullnodeUrl: "https://api.testnet.aptoslabs.com/v1",
81
- tradingHttpUrl: "https://api.testnet.aptoslabs.com/decibel",
82
- tradingWsUrl: "wss://api.testnet.aptoslabs.com/decibel/ws",
83
- gasStationUrl: "https://fee-payer-staging-testnet-us-central1-502735673999.us-central1.run.app",
84
- deployment: getDeployment(PACKAGE.TESTNET),
85
- chainId: 2,
86
- ...RELEASE_CONFIGS.TESTNET,
87
- };
88
-
89
- export const LOCAL_CONFIG: DecibelConfig = {
90
- network: Network.CUSTOM,
91
- fullnodeUrl: "http://localhost:8080/v1",
92
- tradingHttpUrl: "http://localhost:8084",
93
- tradingWsUrl: "ws://localhost:8083",
94
- gasStationUrl: "http://localhost:8085",
95
- deployment: getDeployment(PACKAGE.NETNA),
96
- ...RELEASE_CONFIGS.LOCAL,
97
- };
98
-
99
- export const DOCKER_CONFIG: DecibelConfig = {
100
- network: Network.CUSTOM,
101
- fullnodeUrl: "http://tradenet:8080/v1",
102
- tradingHttpUrl: "http://trading-api-http:8080",
103
- // nosemgrep: javascript.lang.security.detect-insecure-websocket.detect-insecure-websocket
104
- tradingWsUrl: "ws://trading-api-ws:8080",
105
- gasStationUrl: "http://fee-payer:8080",
106
- deployment: getDeployment(PACKAGE.NETNA),
107
- ...RELEASE_CONFIGS.DOCKER,
108
- };
109
-
110
- export const NAMED_CONFIGS: Record<string, DecibelConfig | undefined> = {
111
- netna: NETNA_CONFIG,
112
- local: LOCAL_CONFIG,
113
- docker: DOCKER_CONFIG,
114
- testnet: TESTNET_CONFIG,
115
- };
116
-
117
- export const QUERY_PARAM_KEYS = {
118
- offset: "offset",
119
- limit: "limit",
120
- sortKey: "sort_key",
121
- sortDir: "sort_dir",
122
- searchTerm: "search_term",
123
- };
124
-
125
- export function getVaultApiModule(compatVersion: CompatVersion) {
126
- if (compatVersion === CompatVersion.V0_1) {
127
- return `vault`;
128
- } else {
129
- return `vault_api`;
130
- }
131
- }
package/src/fee-pay.ts DELETED
@@ -1,39 +0,0 @@
1
- import {
2
- AccountAuthenticator,
3
- PendingTransactionResponse,
4
- SimpleTransaction,
5
- } from "@aptos-labs/ts-sdk";
6
-
7
- import { DecibelConfig } from "./constants";
8
-
9
- /**
10
- * Submit a transaction with fee payer support
11
- * @param config The Decibel configuration containing the gas station URL
12
- * @param transaction The transaction to submit
13
- * @param senderAuthenticator The sender's authenticator
14
- * @returns A promise that resolves to the pending transaction response
15
- */
16
- export async function submitFeePaidTransaction(
17
- config: DecibelConfig,
18
- transaction: SimpleTransaction,
19
- senderAuthenticator: AccountAuthenticator,
20
- ): Promise<PendingTransactionResponse> {
21
- const signatureBcs = Array.from(senderAuthenticator.bcsToBytes());
22
- const transactionBcs = Array.from(transaction.rawTransaction.bcsToBytes());
23
- const body = JSON.stringify({
24
- signature: signatureBcs,
25
- transaction: transactionBcs,
26
- });
27
- const response = await fetch(config.gasStationUrl + "/transactions", {
28
- method: "POST",
29
- headers: {
30
- "Content-Type": "application/json",
31
- },
32
- body,
33
- });
34
- if (!response.ok) {
35
- throw new Error(`HTTP error! status: ${response.status}`);
36
- }
37
- // TODO(bl): Error handling
38
- return (await response.json()) as PendingTransactionResponse;
39
- }