@decibeltrade/sdk 0.1.1
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint$colon$check.log +5 -0
- package/.turbo/turbo-lint.log +5 -0
- package/decibel_transactions.md +1049 -0
- package/dist/abi/abi-manager.d.ts +13 -0
- package/dist/abi/abi-manager.d.ts.map +1 -0
- package/dist/abi/abi-manager.js +21 -0
- package/dist/abi/abis.json +1322 -0
- package/dist/abi/bytecode-manager.d.ts +57 -0
- package/dist/abi/bytecode-manager.d.ts.map +1 -0
- package/dist/abi/bytecode-manager.js +62 -0
- package/dist/abi/bytecode.json +24 -0
- package/dist/abi/fetch-abis.d.ts +7 -0
- package/dist/abi/fetch-abis.d.ts.map +1 -0
- package/dist/abi/fetch-abis.js +132 -0
- package/dist/abi/fetch-bytecode.d.ts +24 -0
- package/dist/abi/fetch-bytecode.d.ts.map +1 -0
- package/dist/abi/fetch-bytecode.js +123 -0
- package/dist/abi/generate-abis.d.ts +6 -0
- package/dist/abi/generate-abis.d.ts.map +1 -0
- package/dist/abi/generate-abis.js +170 -0
- package/dist/abi/json/netna.json +1323 -0
- package/dist/abi/json/testnet.json +1315 -0
- package/dist/abi/types.d.ts +22 -0
- package/dist/abi/types.d.ts.map +1 -0
- package/dist/abi/types.js +2 -0
- package/dist/admin.d.ts +29 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +203 -0
- package/dist/base.d.ts +42 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +176 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +78 -0
- package/dist/fee-pay.d.ts +11 -0
- package/dist/fee-pay.d.ts.map +1 -0
- package/dist/fee-pay.js +30 -0
- package/dist/gas/gas-price-manager.d.ts +35 -0
- package/dist/gas/gas-price-manager.d.ts.map +1 -0
- package/dist/gas/gas-price-manager.js +93 -0
- package/dist/gas-price-manager.d.ts +31 -0
- package/dist/gas-price-manager.d.ts.map +1 -0
- package/dist/gas-price-manager.js +84 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/order-event.types.d.ts +55 -0
- package/dist/order-event.types.d.ts.map +1 -0
- package/dist/order-event.types.js +3 -0
- package/dist/order-status.d.ts +43 -0
- package/dist/order-status.d.ts.map +1 -0
- package/dist/order-status.js +86 -0
- package/dist/read/account-overview/account-overview.reader.d.ts +37 -0
- package/dist/read/account-overview/account-overview.reader.d.ts.map +1 -0
- package/dist/read/account-overview/account-overview.reader.js +35 -0
- package/dist/read/account-overview/account-overview.types.d.ts +52 -0
- package/dist/read/account-overview/account-overview.types.d.ts.map +1 -0
- package/dist/read/account-overview/account-overview.types.js +36 -0
- package/dist/read/api-wallets/api-wallets.reader.d.ts +17 -0
- package/dist/read/api-wallets/api-wallets.reader.d.ts.map +1 -0
- package/dist/read/api-wallets/api-wallets.reader.js +27 -0
- package/dist/read/api-wallets/api-wallets.types.d.ts +17 -0
- package/dist/read/api-wallets/api-wallets.types.d.ts.map +1 -0
- package/dist/read/api-wallets/api-wallets.types.js +13 -0
- package/dist/read/base-reader.d.ts +22 -0
- package/dist/read/base-reader.d.ts.map +1 -0
- package/dist/read/base-reader.js +29 -0
- package/dist/read/candlesticks/candlesticks.reader.d.ts +31 -0
- package/dist/read/candlesticks/candlesticks.reader.d.ts.map +1 -0
- package/dist/read/candlesticks/candlesticks.reader.js +43 -0
- package/dist/read/candlesticks/candlesticks.types.d.ts +45 -0
- package/dist/read/candlesticks/candlesticks.types.d.ts.map +1 -0
- package/dist/read/candlesticks/candlesticks.types.js +36 -0
- package/dist/read/delegations/delegations.reader.d.ts +15 -0
- package/dist/read/delegations/delegations.reader.d.ts.map +1 -0
- package/dist/read/delegations/delegations.reader.js +23 -0
- package/dist/read/delegations/delegations.types.d.ts +17 -0
- package/dist/read/delegations/delegations.types.d.ts.map +1 -0
- package/dist/read/delegations/delegations.types.js +13 -0
- package/dist/read/index.d.ts +105 -0
- package/dist/read/index.d.ts.map +1 -0
- package/dist/read/index.js +244 -0
- package/dist/read/leaderboard/leaderboard.reader.d.ts +21 -0
- package/dist/read/leaderboard/leaderboard.reader.d.ts.map +1 -0
- package/dist/read/leaderboard/leaderboard.reader.js +22 -0
- package/dist/read/leaderboard/leaderboard.types.d.ts +27 -0
- package/dist/read/leaderboard/leaderboard.types.d.ts.map +1 -0
- package/dist/read/leaderboard/leaderboard.types.js +14 -0
- package/dist/read/market-contexts/market-contexts.reader.d.ts +22 -0
- package/dist/read/market-contexts/market-contexts.reader.d.ts.map +1 -0
- package/dist/read/market-contexts/market-contexts.reader.js +27 -0
- package/dist/read/market-contexts/market-contexts.types.d.ts +26 -0
- package/dist/read/market-contexts/market-contexts.types.d.ts.map +1 -0
- package/dist/read/market-contexts/market-contexts.types.js +19 -0
- package/dist/read/market-depth/market-depth.reader.d.ts +30 -0
- package/dist/read/market-depth/market-depth.reader.d.ts.map +1 -0
- package/dist/read/market-depth/market-depth.reader.js +46 -0
- package/dist/read/market-depth/market-depth.types.d.ts +20 -0
- package/dist/read/market-depth/market-depth.types.d.ts.map +1 -0
- package/dist/read/market-depth/market-depth.types.js +16 -0
- package/dist/read/market-prices/market-prices.reader.d.ts +44 -0
- package/dist/read/market-prices/market-prices.reader.d.ts.map +1 -0
- package/dist/read/market-prices/market-prices.reader.js +51 -0
- package/dist/read/market-prices/market-prices.types.d.ts +48 -0
- package/dist/read/market-prices/market-prices.types.d.ts.map +1 -0
- package/dist/read/market-prices/market-prices.types.js +26 -0
- package/dist/read/market-trades/market-trades.reader.d.ts +33 -0
- package/dist/read/market-trades/market-trades.reader.d.ts.map +1 -0
- package/dist/read/market-trades/market-trades.reader.js +39 -0
- package/dist/read/market-trades/market-trades.types.d.ts +52 -0
- package/dist/read/market-trades/market-trades.types.d.ts.map +1 -0
- package/dist/read/market-trades/market-trades.types.js +23 -0
- package/dist/read/markets/markets.reader.d.ts +38 -0
- package/dist/read/markets/markets.reader.d.ts.map +1 -0
- package/dist/read/markets/markets.reader.js +80 -0
- package/dist/read/markets/markets.types.d.ts +82 -0
- package/dist/read/markets/markets.types.d.ts.map +1 -0
- package/dist/read/markets/markets.types.js +46 -0
- package/dist/read/pagination.types.d.ts +14 -0
- package/dist/read/pagination.types.d.ts.map +1 -0
- package/dist/read/pagination.types.js +12 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts +14 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts.map +1 -0
- package/dist/read/portfolio-chart/portfolio-chart.reader.js +21 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.d.ts +14 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.d.ts.map +1 -0
- package/dist/read/portfolio-chart/portfolio-chart.types.js +12 -0
- package/dist/read/public-vaults/public-vaults.reader.d.ts +38 -0
- package/dist/read/public-vaults/public-vaults.reader.d.ts.map +1 -0
- package/dist/read/public-vaults/public-vaults.reader.js +31 -0
- package/dist/read/public-vaults/public-vaults.types.d.ts +62 -0
- package/dist/read/public-vaults/public-vaults.types.d.ts.map +1 -0
- package/dist/read/public-vaults/public-vaults.types.js +33 -0
- package/dist/read/types.d.ts +178 -0
- package/dist/read/types.d.ts.map +1 -0
- package/dist/read/types.js +87 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts +31 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts.map +1 -0
- package/dist/read/user-active-twaps/user-active-twaps.reader.js +31 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.d.ts +49 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.d.ts.map +1 -0
- package/dist/read/user-active-twaps/user-active-twaps.types.js +25 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts +31 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts.map +1 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +32 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts +46 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts.map +1 -0
- package/dist/read/user-bulk-orders/user-bulk-orders.types.js +24 -0
- package/dist/read/user-funding-history/user-funding-history.reader.d.ts +28 -0
- package/dist/read/user-funding-history/user-funding-history.reader.d.ts.map +1 -0
- package/dist/read/user-funding-history/user-funding-history.reader.js +32 -0
- package/dist/read/user-funding-history/user-funding-history.types.d.ts +37 -0
- package/dist/read/user-funding-history/user-funding-history.types.d.ts.map +1 -0
- package/dist/read/user-funding-history/user-funding-history.types.js +21 -0
- package/dist/read/user-notifications/user-notifications.reader.d.ts +13 -0
- package/dist/read/user-notifications/user-notifications.reader.d.ts.map +1 -0
- package/dist/read/user-notifications/user-notifications.reader.js +19 -0
- package/dist/read/user-notifications/user-notifications.types.d.ts +49 -0
- package/dist/read/user-notifications/user-notifications.types.d.ts.map +1 -0
- package/dist/read/user-notifications/user-notifications.types.js +18 -0
- package/dist/read/user-open-orders/user-open-orders.reader.d.ts +40 -0
- package/dist/read/user-open-orders/user-open-orders.reader.d.ts.map +1 -0
- package/dist/read/user-open-orders/user-open-orders.reader.js +31 -0
- package/dist/read/user-open-orders/user-open-orders.types.d.ts +76 -0
- package/dist/read/user-open-orders/user-open-orders.types.d.ts.map +1 -0
- package/dist/read/user-open-orders/user-open-orders.types.js +34 -0
- package/dist/read/user-order-history/user-order-history.reader.d.ts +40 -0
- package/dist/read/user-order-history/user-order-history.reader.d.ts.map +1 -0
- package/dist/read/user-order-history/user-order-history.reader.js +28 -0
- package/dist/read/user-order-history/user-order-history.types.d.ts +85 -0
- package/dist/read/user-order-history/user-order-history.types.d.ts.map +1 -0
- package/dist/read/user-order-history/user-order-history.types.js +37 -0
- package/dist/read/user-positions/user-positions.reader.d.ts +37 -0
- package/dist/read/user-positions/user-positions.reader.d.ts.map +1 -0
- package/dist/read/user-positions/user-positions.reader.js +41 -0
- package/dist/read/user-positions/user-positions.types.d.ts +2590 -0
- package/dist/read/user-positions/user-positions.types.d.ts.map +1 -0
- package/dist/read/user-positions/user-positions.types.js +31 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts +18 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts.map +1 -0
- package/dist/read/user-subaccounts/user-subaccounts.reader.js +28 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.d.ts +21 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.d.ts.map +1 -0
- package/dist/read/user-subaccounts/user-subaccounts.types.js +15 -0
- package/dist/read/user-trade-history/user-trade-history.reader.d.ts +33 -0
- package/dist/read/user-trade-history/user-trade-history.reader.d.ts.map +1 -0
- package/dist/read/user-trade-history/user-trade-history.reader.js +32 -0
- package/dist/read/user-trade-history/user-trade-history.types.d.ts +52 -0
- package/dist/read/user-trade-history/user-trade-history.types.d.ts.map +1 -0
- package/dist/read/user-trade-history/user-trade-history.types.js +26 -0
- package/dist/read/user-vaults/user-vaults.reader.d.ts +26 -0
- package/dist/read/user-vaults/user-vaults.reader.d.ts.map +1 -0
- package/dist/read/user-vaults/user-vaults.reader.js +32 -0
- package/dist/read/user-vaults/user-vaults.types.d.ts +39 -0
- package/dist/read/user-vaults/user-vaults.types.d.ts.map +1 -0
- package/dist/read/user-vaults/user-vaults.types.js +21 -0
- package/dist/read/vault/vault.reader.d.ts +95 -0
- package/dist/read/vault/vault.reader.d.ts.map +1 -0
- package/dist/read/vault/vault.reader.js +168 -0
- package/dist/read/vault/vault.types.d.ts +49 -0
- package/dist/read/vault/vault.types.d.ts.map +1 -0
- package/dist/read/vault/vault.types.js +45 -0
- package/dist/read/vaults/vaults.reader.d.ts +72 -0
- package/dist/read/vaults/vaults.reader.d.ts.map +1 -0
- package/dist/read/vaults/vaults.reader.js +63 -0
- package/dist/read/vaults/vaults.types.d.ts +140 -0
- package/dist/read/vaults/vaults.types.d.ts.map +1 -0
- package/dist/read/vaults/vaults.types.js +71 -0
- package/dist/read/ws-subscription.d.ts +21 -0
- package/dist/read/ws-subscription.d.ts.map +1 -0
- package/dist/read/ws-subscription.js +170 -0
- package/dist/subaccount-types.d.ts +24 -0
- package/dist/subaccount-types.d.ts.map +1 -0
- package/dist/subaccount-types.js +11 -0
- package/dist/transaction-builder.d.ts +14 -0
- package/dist/transaction-builder.d.ts.map +1 -0
- package/dist/transaction-builder.js +40 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils.d.ts +56 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +164 -0
- package/dist/vault-types.d.ts +43 -0
- package/dist/vault-types.d.ts.map +1 -0
- package/dist/vault-types.js +11 -0
- package/dist/write.d.ts +271 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +485 -0
- package/eslint.config.mjs +25 -0
- package/package.json +39 -0
- package/readme.md +257 -0
- package/sdk_reference.md +876 -0
- package/src/abi/generate-abis.ts +164 -0
- package/src/abi/json/netna.json +1323 -0
- package/src/abi/json/testnet.json +1315 -0
- package/src/abi/types.ts +23 -0
- package/src/admin.ts +284 -0
- package/src/base.ts +218 -0
- package/src/constants.ts +118 -0
- package/src/fee-pay.ts +39 -0
- package/src/gas/gas-price-manager.ts +115 -0
- package/src/index.ts +10 -0
- package/src/order-event.types.ts +65 -0
- package/src/order-status.ts +89 -0
- package/src/read/account-overview/account-overview.reader.ts +43 -0
- package/src/read/account-overview/account-overview.types.ts +45 -0
- package/src/read/base-reader.ts +41 -0
- package/src/read/candlesticks/candlesticks.reader.ts +61 -0
- package/src/read/candlesticks/candlesticks.types.ts +46 -0
- package/src/read/delegations/delegations.reader.ts +22 -0
- package/src/read/delegations/delegations.types.ts +19 -0
- package/src/read/index.ts +271 -0
- package/src/read/leaderboard/leaderboard.reader.ts +21 -0
- package/src/read/leaderboard/leaderboard.types.ts +26 -0
- package/src/read/market-contexts/market-contexts.reader.ts +26 -0
- package/src/read/market-contexts/market-contexts.types.ts +18 -0
- package/src/read/market-depth/market-depth.reader.ts +60 -0
- package/src/read/market-depth/market-depth.types.ts +24 -0
- package/src/read/market-prices/market-prices.reader.ts +61 -0
- package/src/read/market-prices/market-prices.types.ts +38 -0
- package/src/read/market-trades/market-trades.reader.ts +46 -0
- package/src/read/market-trades/market-trades.types.ts +34 -0
- package/src/read/markets/markets.reader.ts +82 -0
- package/src/read/markets/markets.types.ts +54 -0
- package/src/read/pagination.types.ts +18 -0
- package/src/read/portfolio-chart/portfolio-chart.reader.ts +20 -0
- package/src/read/portfolio-chart/portfolio-chart.types.ts +21 -0
- package/src/read/types.ts +129 -0
- package/src/read/user-active-twaps/user-active-twaps.reader.ts +36 -0
- package/src/read/user-active-twaps/user-active-twaps.types.ts +33 -0
- package/src/read/user-bulk-orders/user-bulk-orders.reader.ts +37 -0
- package/src/read/user-bulk-orders/user-bulk-orders.types.ts +32 -0
- package/src/read/user-funding-history/user-funding-history.reader.ts +38 -0
- package/src/read/user-funding-history/user-funding-history.types.ts +29 -0
- package/src/read/user-notifications/user-notifications.reader.ts +17 -0
- package/src/read/user-notifications/user-notifications.types.ts +61 -0
- package/src/read/user-open-orders/user-open-orders.reader.ts +36 -0
- package/src/read/user-open-orders/user-open-orders.types.ts +42 -0
- package/src/read/user-order-history/user-order-history.reader.ts +34 -0
- package/src/read/user-order-history/user-order-history.types.ts +44 -0
- package/src/read/user-positions/user-positions.reader.ts +55 -0
- package/src/read/user-positions/user-positions.types.ts +43 -0
- package/src/read/user-subaccounts/user-subaccounts.reader.ts +30 -0
- package/src/read/user-subaccounts/user-subaccounts.types.ts +21 -0
- package/src/read/user-trade-history/user-trade-history.reader.ts +38 -0
- package/src/read/user-trade-history/user-trade-history.types.ts +33 -0
- package/src/read/vaults/vaults.reader.ts +79 -0
- package/src/read/vaults/vaults.types.ts +106 -0
- package/src/read/ws-subscription.ts +200 -0
- package/src/subaccount-types.ts +31 -0
- package/src/transaction-builder.ts +75 -0
- package/src/utils.ts +255 -0
- package/src/write.ts +965 -0
- package/tsconfig.json +8 -0
package/src/abi/types.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { AccountAddress, createObjectAddress } from "@aptos-labs/ts-sdk";
|
|
2
|
+
|
|
3
|
+
import { BaseSDK } from "./base";
|
|
4
|
+
import { getMarketAddr } from "./utils";
|
|
5
|
+
|
|
6
|
+
export class DecibelAdminDex extends BaseSDK {
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the global vault system. Only callable by the admin account.
|
|
9
|
+
*/
|
|
10
|
+
async initialize(
|
|
11
|
+
collateralTokenAddr: string,
|
|
12
|
+
collateralBalanceDecimals: number,
|
|
13
|
+
backstopLiquidatorAddr: string,
|
|
14
|
+
) {
|
|
15
|
+
return await this.sendTx({
|
|
16
|
+
function: `${this.config.deployment.package}::admin_apis::initialize`,
|
|
17
|
+
typeArguments: [],
|
|
18
|
+
functionArguments: [collateralTokenAddr, collateralBalanceDecimals, backstopLiquidatorAddr],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getProtocolVaultAddress(): AccountAddress {
|
|
23
|
+
const vaultConfigObjectAddr = createObjectAddress(
|
|
24
|
+
AccountAddress.fromString(this.config.deployment.package),
|
|
25
|
+
"GlobalVaultConfig",
|
|
26
|
+
);
|
|
27
|
+
const protocolVaultObjectAddr = createObjectAddress(
|
|
28
|
+
vaultConfigObjectAddr,
|
|
29
|
+
"Decibel Protocol Vault",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return protocolVaultObjectAddr;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async initializeProtocolVault(collateralTokenAddr: string, initialFunding: number) {
|
|
36
|
+
return await this.sendTx({
|
|
37
|
+
function: `${this.config.deployment.package}::vault::create_and_fund_vault`,
|
|
38
|
+
typeArguments: [],
|
|
39
|
+
functionArguments: [
|
|
40
|
+
collateralTokenAddr,
|
|
41
|
+
"Decibel Protocol Vault",
|
|
42
|
+
"(description)",
|
|
43
|
+
[],
|
|
44
|
+
"DPV",
|
|
45
|
+
"",
|
|
46
|
+
"",
|
|
47
|
+
0, // fee_bps
|
|
48
|
+
0, // fee_interval
|
|
49
|
+
3 * 24 * 60 * 60, // contribution_lockup_duration_s
|
|
50
|
+
initialFunding, // initial_funding
|
|
51
|
+
true, // accepts_contributions
|
|
52
|
+
false, // delegate_to_creator
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async delegateProtocolVaultTradingTo(vaultAddress: string, accountToDelegateTo: string) {
|
|
58
|
+
return await this.sendTx({
|
|
59
|
+
function: `${this.config.deployment.package}::vault::delegate_dex_actions_to`,
|
|
60
|
+
typeArguments: [],
|
|
61
|
+
functionArguments: [vaultAddress, accountToDelegateTo, undefined],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async authorizeOracleAndMarkUpdate(internalOracleUpdater: string) {
|
|
66
|
+
return await this.sendTx({
|
|
67
|
+
function: `${this.config.deployment.package}::admin_apis::add_oracle_and_mark_update_permission`,
|
|
68
|
+
typeArguments: [],
|
|
69
|
+
functionArguments: [internalOracleUpdater],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async registerMarketWithInternalOracle(
|
|
74
|
+
name: string,
|
|
75
|
+
szDecimals: number,
|
|
76
|
+
minSize: number,
|
|
77
|
+
lotSize: number,
|
|
78
|
+
tickerSize: number,
|
|
79
|
+
maxOpenInterest: number,
|
|
80
|
+
maxLeverage: number,
|
|
81
|
+
taker_in_next_block = true,
|
|
82
|
+
initial_oracle_price = 1,
|
|
83
|
+
max_staleness_secs = 60,
|
|
84
|
+
) {
|
|
85
|
+
return await this.sendTx({
|
|
86
|
+
function: `${this.config.deployment.package}::admin_apis::register_market_with_internal_oracle`,
|
|
87
|
+
typeArguments: [],
|
|
88
|
+
functionArguments: [
|
|
89
|
+
name,
|
|
90
|
+
szDecimals,
|
|
91
|
+
minSize,
|
|
92
|
+
lotSize,
|
|
93
|
+
tickerSize,
|
|
94
|
+
maxOpenInterest,
|
|
95
|
+
maxLeverage,
|
|
96
|
+
taker_in_next_block,
|
|
97
|
+
initial_oracle_price,
|
|
98
|
+
max_staleness_secs,
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async registerMarketWithPythOracle(
|
|
104
|
+
name: string,
|
|
105
|
+
szDecimals: number,
|
|
106
|
+
minSize: number,
|
|
107
|
+
lotSize: number,
|
|
108
|
+
tickerSize: number,
|
|
109
|
+
maxOpenInterest: number,
|
|
110
|
+
maxLeverage: number,
|
|
111
|
+
taker_in_next_block = true,
|
|
112
|
+
pythIdentifierBytes: number[],
|
|
113
|
+
pythMaxStalenessSecs: number,
|
|
114
|
+
pythConfidenceIntervalThreshold: number,
|
|
115
|
+
pythDecimals: number,
|
|
116
|
+
) {
|
|
117
|
+
return await this.sendTx({
|
|
118
|
+
function: `${this.config.deployment.package}::admin_apis::register_market_with_pyth_oracle`,
|
|
119
|
+
typeArguments: [],
|
|
120
|
+
functionArguments: [
|
|
121
|
+
name,
|
|
122
|
+
szDecimals,
|
|
123
|
+
minSize,
|
|
124
|
+
lotSize,
|
|
125
|
+
tickerSize,
|
|
126
|
+
maxOpenInterest,
|
|
127
|
+
maxLeverage,
|
|
128
|
+
taker_in_next_block,
|
|
129
|
+
pythIdentifierBytes,
|
|
130
|
+
pythMaxStalenessSecs,
|
|
131
|
+
pythConfidenceIntervalThreshold,
|
|
132
|
+
pythDecimals,
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async registerMarketWithCompositeOraclePrimaryPyth(
|
|
138
|
+
name: string,
|
|
139
|
+
szDecimals: number,
|
|
140
|
+
minSize: number,
|
|
141
|
+
lotSize: number,
|
|
142
|
+
tickerSize: number,
|
|
143
|
+
maxOpenInterest: number,
|
|
144
|
+
maxLeverage: number,
|
|
145
|
+
taker_in_next_block = true,
|
|
146
|
+
pythIdentifierBytes: number[],
|
|
147
|
+
pythMaxStalenessSecs: number,
|
|
148
|
+
pythConfidenceIntervalThreshold: number,
|
|
149
|
+
pythDecimals: number,
|
|
150
|
+
internalInitialPrice: number,
|
|
151
|
+
internalMaxStalenessSecs: number,
|
|
152
|
+
oraclesDeviationBps: number,
|
|
153
|
+
consecutiveDeviationCount: number,
|
|
154
|
+
) {
|
|
155
|
+
return await this.sendTx({
|
|
156
|
+
function: `${this.config.deployment.package}::admin_apis::register_market_with_composite_oracle_primary_pyth`,
|
|
157
|
+
typeArguments: [],
|
|
158
|
+
functionArguments: [
|
|
159
|
+
name,
|
|
160
|
+
szDecimals,
|
|
161
|
+
minSize,
|
|
162
|
+
lotSize,
|
|
163
|
+
tickerSize,
|
|
164
|
+
maxOpenInterest,
|
|
165
|
+
maxLeverage,
|
|
166
|
+
taker_in_next_block,
|
|
167
|
+
pythIdentifierBytes,
|
|
168
|
+
pythMaxStalenessSecs,
|
|
169
|
+
pythConfidenceIntervalThreshold,
|
|
170
|
+
pythDecimals,
|
|
171
|
+
internalInitialPrice,
|
|
172
|
+
internalMaxStalenessSecs,
|
|
173
|
+
oraclesDeviationBps,
|
|
174
|
+
consecutiveDeviationCount,
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async registerMarketWithCompositeOraclePrimaryChainlink(
|
|
180
|
+
name: string,
|
|
181
|
+
szDecimals: number,
|
|
182
|
+
minSize: number,
|
|
183
|
+
lotSize: number,
|
|
184
|
+
tickerSize: number,
|
|
185
|
+
maxOpenInterest: number,
|
|
186
|
+
maxLeverage: number,
|
|
187
|
+
taker_in_next_block = true,
|
|
188
|
+
rescaleDecimals: number,
|
|
189
|
+
chainlinkFeedIdBytes: number[],
|
|
190
|
+
chainlinkMaxStalenessSecs: number,
|
|
191
|
+
internalMaxStalenessSecs: number,
|
|
192
|
+
internalInitialPrice: number,
|
|
193
|
+
oraclesDeviationBps: number,
|
|
194
|
+
consecutiveDeviationCount: number,
|
|
195
|
+
) {
|
|
196
|
+
return await this.sendTx({
|
|
197
|
+
function: `${this.config.deployment.package}::admin_apis::register_market_with_composite_oracle_primary_chainlink`,
|
|
198
|
+
typeArguments: [],
|
|
199
|
+
functionArguments: [
|
|
200
|
+
name,
|
|
201
|
+
szDecimals,
|
|
202
|
+
minSize,
|
|
203
|
+
lotSize,
|
|
204
|
+
tickerSize,
|
|
205
|
+
maxOpenInterest,
|
|
206
|
+
maxLeverage,
|
|
207
|
+
taker_in_next_block,
|
|
208
|
+
chainlinkFeedIdBytes,
|
|
209
|
+
chainlinkMaxStalenessSecs,
|
|
210
|
+
rescaleDecimals,
|
|
211
|
+
internalInitialPrice,
|
|
212
|
+
internalMaxStalenessSecs,
|
|
213
|
+
oraclesDeviationBps,
|
|
214
|
+
consecutiveDeviationCount,
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async updateInternalOraclePrice(marketName: string, oraclePrice: number) {
|
|
220
|
+
const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
|
|
221
|
+
return await this.sendTx({
|
|
222
|
+
function: `${this.config.deployment.package}::admin_apis::update_mark_for_internal_oracle`,
|
|
223
|
+
typeArguments: [],
|
|
224
|
+
functionArguments: [marketAddr, oraclePrice, [], true],
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async updatePythOraclePrice(marketName: string, vaa: number[]) {
|
|
229
|
+
const marketAddr = getMarketAddr(marketName, this.config.deployment.perpEngineGlobal);
|
|
230
|
+
return await this.sendTx({
|
|
231
|
+
function: `${this.config.deployment.package}::admin_apis::update_mark_for_pyth_oracle`,
|
|
232
|
+
typeArguments: [],
|
|
233
|
+
functionArguments: [marketAddr, vaa, [], true],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async updatePriceToPythOnly(vaas: number[][]) {
|
|
238
|
+
return await this.sendTx({
|
|
239
|
+
function: `${this.config.deployment.package}::pyth::update_price_feeds_with_funder`,
|
|
240
|
+
typeArguments: [],
|
|
241
|
+
functionArguments: [vaas],
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async updatePriceToChainlinkOnly(signedReport: number[]) {
|
|
246
|
+
return await this.sendTx({
|
|
247
|
+
function: `${this.config.deployment.package}::chainlink_state::verify_and_store_single_price`,
|
|
248
|
+
typeArguments: [],
|
|
249
|
+
functionArguments: [signedReport],
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async mintUsdc(toAddr: AccountAddress, amount: number) {
|
|
254
|
+
return await this.sendTx({
|
|
255
|
+
function: `${this.config.deployment.package}::usdc::mint`,
|
|
256
|
+
typeArguments: [],
|
|
257
|
+
functionArguments: [toAddr, amount],
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async setPublicMinting(allow: boolean) {
|
|
262
|
+
return await this.sendTx({
|
|
263
|
+
function: `${this.config.deployment.package}::usdc::set_public_minting`,
|
|
264
|
+
typeArguments: [],
|
|
265
|
+
functionArguments: [allow],
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get the balance of USDC for an account
|
|
271
|
+
* @param addr The account address to get the balance for
|
|
272
|
+
* @returns The balance of USDC for the account
|
|
273
|
+
*/
|
|
274
|
+
async usdcBalance(addr: AccountAddress) {
|
|
275
|
+
const balance = await this.aptos.view<[number]>({
|
|
276
|
+
payload: {
|
|
277
|
+
function: `0x1::primary_fungible_store::balance`,
|
|
278
|
+
typeArguments: [`0x1::fungible_asset::Metadata`],
|
|
279
|
+
functionArguments: [addr, this.config.deployment.usdc],
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
return balance[0];
|
|
283
|
+
}
|
|
284
|
+
}
|
package/src/base.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
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 } 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
|
+
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
|
+
public async submitTx(
|
|
122
|
+
transaction: SimpleTransaction,
|
|
123
|
+
senderAuthenticator: AccountAuthenticator,
|
|
124
|
+
): Promise<PendingTransactionResponse> {
|
|
125
|
+
if (this.noFeePayer) {
|
|
126
|
+
return await this.aptos.transaction.submit.simple({
|
|
127
|
+
transaction,
|
|
128
|
+
senderAuthenticator,
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
return await submitFeePaidTransaction(this.config, transaction, senderAuthenticator);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public async buildTx(payload: InputGenerateTransactionPayloadData, sender: AccountAddress) {
|
|
136
|
+
const functionAbi = "function" in payload ? this.getABI(payload.function) : undefined;
|
|
137
|
+
const withFeePayer = !this.noFeePayer;
|
|
138
|
+
|
|
139
|
+
const replayProtectionNonce = generateRandomReplayProtectionNonce();
|
|
140
|
+
|
|
141
|
+
// This should never happen, but just in case
|
|
142
|
+
if (!replayProtectionNonce) {
|
|
143
|
+
throw new Error("Unable to generate replayProtectionNonce");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let transaction: SimpleTransaction;
|
|
147
|
+
|
|
148
|
+
// If we have functionAbi and chainId, we can use the sync function to generate the transaction
|
|
149
|
+
// This is faster than the async function
|
|
150
|
+
if (functionAbi && this.chainId) {
|
|
151
|
+
let gasUnitPrice: number;
|
|
152
|
+
|
|
153
|
+
if (this.gasPriceManager) {
|
|
154
|
+
// 1. Try getting from cache
|
|
155
|
+
// 2. If not available, try fetching from gasmanager, this also sets the gas price in the cache for future use
|
|
156
|
+
gasUnitPrice =
|
|
157
|
+
this.gasPriceManager.getGasPrice() ?? (await this.gasPriceManager.fetchAndSetGasPrice());
|
|
158
|
+
} else {
|
|
159
|
+
// 1. Fetch from network, this is a fallback, should only happen if gasPriceManager is not set
|
|
160
|
+
gasUnitPrice = (await this.aptos.getGasPriceEstimation()).gas_estimate;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
transaction = buildSimpleTransactionSync({
|
|
164
|
+
aptosConfig: this.aptos.config,
|
|
165
|
+
sender,
|
|
166
|
+
data: payload as InputEntryFunctionData,
|
|
167
|
+
withFeePayer,
|
|
168
|
+
replayProtectionNonce,
|
|
169
|
+
abi: functionAbi,
|
|
170
|
+
chainId: this.chainId,
|
|
171
|
+
gasUnitPrice,
|
|
172
|
+
timeDeltaMs: this.timeDeltaMs,
|
|
173
|
+
});
|
|
174
|
+
} else {
|
|
175
|
+
// This is a fallback, should not happen, but works if due to any issues, functionAbi or chainId is not present
|
|
176
|
+
// @Todo: Pass in Abi ideally, once we update aptos-ts-sdk to not refetch abi if abi is passed in payload
|
|
177
|
+
transaction = await this.aptos.transaction.build.simple({
|
|
178
|
+
sender,
|
|
179
|
+
data: payload,
|
|
180
|
+
withFeePayer,
|
|
181
|
+
options: {
|
|
182
|
+
replayProtectionNonce,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return transaction;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
protected async sendTx(payload: InputGenerateTransactionPayloadData, accountOverride?: Account) {
|
|
191
|
+
const signer = accountOverride ?? this.account;
|
|
192
|
+
const sender = signer.accountAddress;
|
|
193
|
+
if (!this.skipSimulate) {
|
|
194
|
+
const transaction = await this.getSimulatedTx(payload, sender);
|
|
195
|
+
const senderAuthenticator = this.aptos.transaction.sign({
|
|
196
|
+
signer,
|
|
197
|
+
transaction,
|
|
198
|
+
});
|
|
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
|
+
|
|
206
|
+
const senderAuthenticator = this.aptos.transaction.sign({
|
|
207
|
+
signer,
|
|
208
|
+
transaction,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const pendingTransaction = await this.submitTx(transaction, senderAuthenticator);
|
|
212
|
+
|
|
213
|
+
return await this.aptos.waitForTransaction({
|
|
214
|
+
transactionHash: pendingTransaction.hash,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AccountAddress, Aptos, createObjectAddress, Network } from "@aptos-labs/ts-sdk";
|
|
2
|
+
|
|
3
|
+
import { DecibelWsSubscription } from "./read/ws-subscription";
|
|
4
|
+
|
|
5
|
+
export function getUsdcAddress(publisherAddr: string) {
|
|
6
|
+
return createObjectAddress(
|
|
7
|
+
AccountAddress.fromString(publisherAddr),
|
|
8
|
+
new TextEncoder().encode("USDC"),
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTestcAddress(publisherAddr: string) {
|
|
13
|
+
return createObjectAddress(
|
|
14
|
+
AccountAddress.fromString(publisherAddr),
|
|
15
|
+
new TextEncoder().encode("TESTC"),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getPerpEngineGlobalAddress(publisherAddr: string) {
|
|
20
|
+
return createObjectAddress(
|
|
21
|
+
AccountAddress.fromString(publisherAddr),
|
|
22
|
+
new TextEncoder().encode("GlobalPerpEngine"),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DecibelConfig {
|
|
27
|
+
network: Network;
|
|
28
|
+
fullnodeUrl: string;
|
|
29
|
+
tradingHttpUrl: string;
|
|
30
|
+
tradingWsUrl: string;
|
|
31
|
+
gasStationUrl: string;
|
|
32
|
+
deployment: Deployment;
|
|
33
|
+
chainId?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DecibelReaderDeps {
|
|
37
|
+
aptos: Aptos;
|
|
38
|
+
ws: DecibelWsSubscription;
|
|
39
|
+
config: DecibelConfig;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Deployment {
|
|
44
|
+
package: string;
|
|
45
|
+
usdc: string;
|
|
46
|
+
testc: string;
|
|
47
|
+
perpEngineGlobal: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const NETNA_PACKAGE = "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95";
|
|
51
|
+
export const NETNA_DEPLOYMENT: Deployment = {
|
|
52
|
+
package: NETNA_PACKAGE,
|
|
53
|
+
usdc: getUsdcAddress(NETNA_PACKAGE).toString(),
|
|
54
|
+
testc: getTestcAddress(NETNA_PACKAGE).toString(),
|
|
55
|
+
perpEngineGlobal: getPerpEngineGlobalAddress(NETNA_PACKAGE).toString(),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const NETNA_CONFIG: DecibelConfig = {
|
|
59
|
+
network: Network.CUSTOM,
|
|
60
|
+
fullnodeUrl: "https://api.netna.aptoslabs.com/v1",
|
|
61
|
+
tradingHttpUrl: "https://api.netna.aptoslabs.com/decibel",
|
|
62
|
+
tradingWsUrl: "wss://api.netna.aptoslabs.com/decibel/ws",
|
|
63
|
+
gasStationUrl: "https://fee-payer-dev-netna-us-central1-410192433417.us-central1.run.app",
|
|
64
|
+
deployment: NETNA_DEPLOYMENT,
|
|
65
|
+
chainId: 205,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const TESTNET_PACKAGE = "0x1f513904b7568445e3c291a6c58cb272db017d8a72aea563d5664666221d5f75";
|
|
69
|
+
export const TESTNET_DEPLOYMENT: Deployment = {
|
|
70
|
+
package: TESTNET_PACKAGE,
|
|
71
|
+
usdc: getUsdcAddress(TESTNET_PACKAGE).toString(),
|
|
72
|
+
testc: getTestcAddress(TESTNET_PACKAGE).toString(),
|
|
73
|
+
perpEngineGlobal: getPerpEngineGlobalAddress(TESTNET_PACKAGE).toString(),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const TESTNET_CONFIG: DecibelConfig = {
|
|
77
|
+
network: Network.TESTNET,
|
|
78
|
+
fullnodeUrl: "https://api.testnet.aptoslabs.com/v1",
|
|
79
|
+
tradingHttpUrl: "https://api.testnet.aptoslabs.com/decibel",
|
|
80
|
+
tradingWsUrl: "wss://api.testnet.aptoslabs.com/decibel/ws",
|
|
81
|
+
gasStationUrl: "https://fee-payer-staging-testnet-us-central1-502735673999.us-central1.run.app",
|
|
82
|
+
deployment: TESTNET_DEPLOYMENT,
|
|
83
|
+
chainId: 2,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const LOCAL_CONFIG: DecibelConfig = {
|
|
87
|
+
network: Network.CUSTOM,
|
|
88
|
+
fullnodeUrl: "http://localhost:8080/v1",
|
|
89
|
+
tradingHttpUrl: "http://localhost:8084",
|
|
90
|
+
tradingWsUrl: "ws://localhost:8083",
|
|
91
|
+
gasStationUrl: "http://localhost:8085",
|
|
92
|
+
deployment: NETNA_DEPLOYMENT,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const DOCKER_CONFIG: DecibelConfig = {
|
|
96
|
+
network: Network.CUSTOM,
|
|
97
|
+
fullnodeUrl: "http://tradenet:8080/v1",
|
|
98
|
+
tradingHttpUrl: "http://trading-api-http:8080",
|
|
99
|
+
// nosemgrep: javascript.lang.security.detect-insecure-websocket.detect-insecure-websocket
|
|
100
|
+
tradingWsUrl: "ws://trading-api-ws:8080",
|
|
101
|
+
gasStationUrl: "http://fee-payer:8080",
|
|
102
|
+
deployment: NETNA_DEPLOYMENT,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const NAMED_CONFIGS: Record<string, DecibelConfig | undefined> = {
|
|
106
|
+
netna: NETNA_CONFIG,
|
|
107
|
+
local: LOCAL_CONFIG,
|
|
108
|
+
docker: DOCKER_CONFIG,
|
|
109
|
+
testnet: TESTNET_CONFIG,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const QUERY_PARAM_KEYS = {
|
|
113
|
+
offset: "offset",
|
|
114
|
+
limit: "limit",
|
|
115
|
+
sortKey: "sort_key",
|
|
116
|
+
sortDir: "sort_dir",
|
|
117
|
+
searchTerm: "search_term",
|
|
118
|
+
};
|
package/src/fee-pay.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|