perp-cli 0.3.3
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/LICENSE +21 -0
- package/README.md +293 -0
- package/dist/__tests__/alert-logic.test.d.ts +1 -0
- package/dist/__tests__/alert-logic.test.js +107 -0
- package/dist/__tests__/arb-auto-3dex.test.d.ts +1 -0
- package/dist/__tests__/arb-auto-3dex.test.js +397 -0
- package/dist/__tests__/arb-history-stats.test.d.ts +1 -0
- package/dist/__tests__/arb-history-stats.test.js +176 -0
- package/dist/__tests__/arb-logic.test.d.ts +1 -0
- package/dist/__tests__/arb-logic.test.js +84 -0
- package/dist/__tests__/arb-manage.test.d.ts +1 -0
- package/dist/__tests__/arb-manage.test.js +253 -0
- package/dist/__tests__/arb-new-features.test.d.ts +1 -0
- package/dist/__tests__/arb-new-features.test.js +457 -0
- package/dist/__tests__/arb-sizing.test.d.ts +1 -0
- package/dist/__tests__/arb-sizing.test.js +48 -0
- package/dist/__tests__/arb-state.test.d.ts +1 -0
- package/dist/__tests__/arb-state.test.js +284 -0
- package/dist/__tests__/arb-userflow.test.d.ts +1 -0
- package/dist/__tests__/arb-userflow.test.js +945 -0
- package/dist/__tests__/arb-utils.test.d.ts +1 -0
- package/dist/__tests__/arb-utils.test.js +264 -0
- package/dist/__tests__/bot-conditions.test.d.ts +1 -0
- package/dist/__tests__/bot-conditions.test.js +341 -0
- package/dist/__tests__/client-id-tracker.test.d.ts +1 -0
- package/dist/__tests__/client-id-tracker.test.js +137 -0
- package/dist/__tests__/commands/new-atomic-commands.test.d.ts +1 -0
- package/dist/__tests__/commands/new-atomic-commands.test.js +502 -0
- package/dist/__tests__/commands/order-intent.test.d.ts +1 -0
- package/dist/__tests__/commands/order-intent.test.js +600 -0
- package/dist/__tests__/commands/trade-commands.test.d.ts +1 -0
- package/dist/__tests__/commands/trade-commands.test.js +821 -0
- package/dist/__tests__/config.test.d.ts +1 -0
- package/dist/__tests__/config.test.js +86 -0
- package/dist/__tests__/cross-chain-margin.test.d.ts +1 -0
- package/dist/__tests__/cross-chain-margin.test.js +287 -0
- package/dist/__tests__/dex-asset-map.test.d.ts +1 -0
- package/dist/__tests__/dex-asset-map.test.js +191 -0
- package/dist/__tests__/errors.test.d.ts +1 -0
- package/dist/__tests__/errors.test.js +110 -0
- package/dist/__tests__/event-stream.test.d.ts +1 -0
- package/dist/__tests__/event-stream.test.js +276 -0
- package/dist/__tests__/exchanges/interface.test.d.ts +1 -0
- package/dist/__tests__/exchanges/interface.test.js +132 -0
- package/dist/__tests__/exchanges/mock-adapter.d.ts +69 -0
- package/dist/__tests__/exchanges/mock-adapter.js +137 -0
- package/dist/__tests__/execution-log.test.d.ts +1 -0
- package/dist/__tests__/execution-log.test.js +106 -0
- package/dist/__tests__/funding-calc.test.d.ts +1 -0
- package/dist/__tests__/funding-calc.test.js +71 -0
- package/dist/__tests__/funding-history.test.d.ts +1 -0
- package/dist/__tests__/funding-history.test.js +343 -0
- package/dist/__tests__/funding-rates.test.d.ts +1 -0
- package/dist/__tests__/funding-rates.test.js +342 -0
- package/dist/__tests__/funding.test.d.ts +1 -0
- package/dist/__tests__/funding.test.js +173 -0
- package/dist/__tests__/gap-logic.test.d.ts +1 -0
- package/dist/__tests__/gap-logic.test.js +43 -0
- package/dist/__tests__/hip3-dex.test.d.ts +1 -0
- package/dist/__tests__/hip3-dex.test.js +234 -0
- package/dist/__tests__/integration/agent-features.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/agent-features.integration.test.js +553 -0
- package/dist/__tests__/integration/atomic-commands.integration.test.d.ts +13 -0
- package/dist/__tests__/integration/atomic-commands.integration.test.js +246 -0
- package/dist/__tests__/integration/bridge-simulation.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/bridge-simulation.integration.test.js +453 -0
- package/dist/__tests__/integration/bridge-strict.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/bridge-strict.integration.test.js +812 -0
- package/dist/__tests__/integration/bridge.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/bridge.integration.test.js +309 -0
- package/dist/__tests__/integration/cli-e2e.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/cli-e2e.integration.test.js +202 -0
- package/dist/__tests__/integration/dex-arb.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/dex-arb.integration.test.js +116 -0
- package/dist/__tests__/integration/envelope-consistency.integration.test.d.ts +13 -0
- package/dist/__tests__/integration/envelope-consistency.integration.test.js +205 -0
- package/dist/__tests__/integration/hip3-dex.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/hip3-dex.integration.test.js +147 -0
- package/dist/__tests__/integration/hyperliquid.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/hyperliquid.integration.test.js +79 -0
- package/dist/__tests__/integration/lighter.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/lighter.integration.test.js +53 -0
- package/dist/__tests__/integration/new-commands-e2e.integration.test.d.ts +9 -0
- package/dist/__tests__/integration/new-commands-e2e.integration.test.js +236 -0
- package/dist/__tests__/integration/order-verification.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/order-verification.integration.test.js +321 -0
- package/dist/__tests__/integration/pacifica.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/pacifica.integration.test.js +75 -0
- package/dist/__tests__/integration/response-shapes.integration.test.d.ts +1 -0
- package/dist/__tests__/integration/response-shapes.integration.test.js +278 -0
- package/dist/__tests__/liquidity.test.d.ts +1 -0
- package/dist/__tests__/liquidity.test.js +225 -0
- package/dist/__tests__/plan-executor.test.d.ts +1 -0
- package/dist/__tests__/plan-executor.test.js +314 -0
- package/dist/__tests__/position-history.test.d.ts +1 -0
- package/dist/__tests__/position-history.test.js +367 -0
- package/dist/__tests__/retry.test.d.ts +1 -0
- package/dist/__tests__/retry.test.js +310 -0
- package/dist/__tests__/risk-assessment.test.d.ts +1 -0
- package/dist/__tests__/risk-assessment.test.js +145 -0
- package/dist/__tests__/security-adversarial.test.d.ts +1 -0
- package/dist/__tests__/security-adversarial.test.js +574 -0
- package/dist/__tests__/strategies.test.d.ts +1 -0
- package/dist/__tests__/strategies.test.js +539 -0
- package/dist/__tests__/trade-execution.test.d.ts +1 -0
- package/dist/__tests__/trade-execution.test.js +129 -0
- package/dist/__tests__/trade-validator.test.d.ts +1 -0
- package/dist/__tests__/trade-validator.test.js +655 -0
- package/dist/__tests__/utils.test.d.ts +1 -0
- package/dist/__tests__/utils.test.js +76 -0
- package/dist/api/public/hyperliquid.d.ts +18 -0
- package/dist/api/public/hyperliquid.js +82 -0
- package/dist/api/public/index.d.ts +8 -0
- package/dist/api/public/index.js +8 -0
- package/dist/api/public/lighter.d.ts +24 -0
- package/dist/api/public/lighter.js +100 -0
- package/dist/api/public/pacifica.d.ts +17 -0
- package/dist/api/public/pacifica.js +54 -0
- package/dist/api/public/urls.d.ts +12 -0
- package/dist/api/public/urls.js +33 -0
- package/dist/arb/history-stats.d.ts +44 -0
- package/dist/arb/history-stats.js +135 -0
- package/dist/arb/index.d.ts +4 -0
- package/dist/arb/index.js +4 -0
- package/dist/arb/sizing.d.ts +23 -0
- package/dist/arb/sizing.js +96 -0
- package/dist/arb/state.d.ts +51 -0
- package/dist/arb/state.js +112 -0
- package/dist/arb/utils.d.ts +81 -0
- package/dist/arb/utils.js +267 -0
- package/dist/arb-history-stats.d.ts +5 -0
- package/dist/arb-history-stats.js +5 -0
- package/dist/arb-sizing.d.ts +5 -0
- package/dist/arb-sizing.js +5 -0
- package/dist/arb-state.d.ts +5 -0
- package/dist/arb-state.js +5 -0
- package/dist/arb-utils.d.ts +5 -0
- package/dist/arb-utils.js +5 -0
- package/dist/bot/conditions.d.ts +32 -0
- package/dist/bot/conditions.js +141 -0
- package/dist/bot/config.d.ts +76 -0
- package/dist/bot/config.js +160 -0
- package/dist/bot/engine.d.ts +8 -0
- package/dist/bot/engine.js +519 -0
- package/dist/bot/presets.d.ts +11 -0
- package/dist/bot/presets.js +296 -0
- package/dist/bridge-engine.d.ts +133 -0
- package/dist/bridge-engine.js +1487 -0
- package/dist/cache.d.ts +25 -0
- package/dist/cache.js +99 -0
- package/dist/cli-spec.d.ts +50 -0
- package/dist/cli-spec.js +75 -0
- package/dist/client-id-tracker.d.ts +25 -0
- package/dist/client-id-tracker.js +76 -0
- package/dist/commands/account.d.ts +3 -0
- package/dist/commands/account.js +425 -0
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.js +386 -0
- package/dist/commands/alert.d.ts +2 -0
- package/dist/commands/alert.js +421 -0
- package/dist/commands/analytics.d.ts +3 -0
- package/dist/commands/analytics.js +311 -0
- package/dist/commands/arb/index.d.ts +3 -0
- package/dist/commands/arb/index.js +921 -0
- package/dist/commands/arb-auto.d.ts +54 -0
- package/dist/commands/arb-auto.js +1328 -0
- package/dist/commands/arb-manage.d.ts +5 -0
- package/dist/commands/arb-manage.js +5 -0
- package/dist/commands/arb.d.ts +2 -0
- package/dist/commands/arb.js +347 -0
- package/dist/commands/backtest.d.ts +2 -0
- package/dist/commands/backtest.js +327 -0
- package/dist/commands/bot.d.ts +3 -0
- package/dist/commands/bot.js +412 -0
- package/dist/commands/bridge.d.ts +2 -0
- package/dist/commands/bridge.js +396 -0
- package/dist/commands/dashboard.d.ts +3 -0
- package/dist/commands/dashboard.js +176 -0
- package/dist/commands/deposit.d.ts +4 -0
- package/dist/commands/deposit.js +573 -0
- package/dist/commands/dex.d.ts +3 -0
- package/dist/commands/dex.js +114 -0
- package/dist/commands/env.d.ts +2 -0
- package/dist/commands/env.js +136 -0
- package/dist/commands/funding.d.ts +2 -0
- package/dist/commands/funding.js +347 -0
- package/dist/commands/gap.d.ts +2 -0
- package/dist/commands/gap.js +305 -0
- package/dist/commands/health.d.ts +2 -0
- package/dist/commands/health.js +67 -0
- package/dist/commands/history.d.ts +2 -0
- package/dist/commands/history.js +235 -0
- package/dist/commands/init.d.ts +15 -0
- package/dist/commands/init.js +266 -0
- package/dist/commands/jobs.d.ts +2 -0
- package/dist/commands/jobs.js +133 -0
- package/dist/commands/manage.d.ts +4 -0
- package/dist/commands/manage.js +309 -0
- package/dist/commands/market.d.ts +3 -0
- package/dist/commands/market.js +225 -0
- package/dist/commands/plan.d.ts +3 -0
- package/dist/commands/plan.js +95 -0
- package/dist/commands/portfolio.d.ts +3 -0
- package/dist/commands/portfolio.js +169 -0
- package/dist/commands/rebalance.d.ts +3 -0
- package/dist/commands/rebalance.js +293 -0
- package/dist/commands/risk.d.ts +3 -0
- package/dist/commands/risk.js +169 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.js +202 -0
- package/dist/commands/settings.d.ts +2 -0
- package/dist/commands/settings.js +102 -0
- package/dist/commands/stream.d.ts +5 -0
- package/dist/commands/stream.js +123 -0
- package/dist/commands/trade.d.ts +3 -0
- package/dist/commands/trade.js +1273 -0
- package/dist/commands/wallet.d.ts +14 -0
- package/dist/commands/wallet.js +602 -0
- package/dist/commands/withdraw.d.ts +3 -0
- package/dist/commands/withdraw.js +187 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +68 -0
- package/dist/cross-chain-margin.d.ts +46 -0
- package/dist/cross-chain-margin.js +107 -0
- package/dist/dashboard/server.d.ts +80 -0
- package/dist/dashboard/server.js +340 -0
- package/dist/dashboard/ui.d.ts +4 -0
- package/dist/dashboard/ui.js +538 -0
- package/dist/dashboard/ws-feeds.d.ts +29 -0
- package/dist/dashboard/ws-feeds.js +660 -0
- package/dist/dex-asset-map.d.ts +80 -0
- package/dist/dex-asset-map.js +201 -0
- package/dist/errors.d.ts +109 -0
- package/dist/errors.js +84 -0
- package/dist/event-stream.d.ts +25 -0
- package/dist/event-stream.js +168 -0
- package/dist/exchanges/hyperliquid.d.ts +212 -0
- package/dist/exchanges/hyperliquid.js +931 -0
- package/dist/exchanges/interface.d.ts +95 -0
- package/dist/exchanges/interface.js +5 -0
- package/dist/exchanges/lighter.d.ts +159 -0
- package/dist/exchanges/lighter.js +793 -0
- package/dist/exchanges/pacifica.d.ts +51 -0
- package/dist/exchanges/pacifica.js +248 -0
- package/dist/execution-log.d.ts +36 -0
- package/dist/execution-log.js +102 -0
- package/dist/funding/history.d.ts +63 -0
- package/dist/funding/history.js +266 -0
- package/dist/funding/index.d.ts +3 -0
- package/dist/funding/index.js +3 -0
- package/dist/funding/normalize.d.ts +39 -0
- package/dist/funding/normalize.js +66 -0
- package/dist/funding/rates.d.ts +45 -0
- package/dist/funding/rates.js +172 -0
- package/dist/funding-history.d.ts +5 -0
- package/dist/funding-history.js +5 -0
- package/dist/funding-rates.d.ts +5 -0
- package/dist/funding-rates.js +5 -0
- package/dist/funding.d.ts +5 -0
- package/dist/funding.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +458 -0
- package/dist/jobs.d.ts +37 -0
- package/dist/jobs.js +152 -0
- package/dist/liquidity.d.ts +34 -0
- package/dist/liquidity.js +100 -0
- package/dist/mcp-server.d.ts +9 -0
- package/dist/mcp-server.js +1206 -0
- package/dist/pacifica/client.d.ts +111 -0
- package/dist/pacifica/client.js +310 -0
- package/dist/pacifica/constants.d.ts +27 -0
- package/dist/pacifica/constants.js +47 -0
- package/dist/pacifica/deposit.d.ts +14 -0
- package/dist/pacifica/deposit.js +78 -0
- package/dist/pacifica/index.d.ts +6 -0
- package/dist/pacifica/index.js +11 -0
- package/dist/pacifica/signing.d.ts +49 -0
- package/dist/pacifica/signing.js +97 -0
- package/dist/pacifica/types/account.d.ts +42 -0
- package/dist/pacifica/types/account.js +1 -0
- package/dist/pacifica/types/index.d.ts +6 -0
- package/dist/pacifica/types/index.js +6 -0
- package/dist/pacifica/types/lake.d.ts +18 -0
- package/dist/pacifica/types/lake.js +1 -0
- package/dist/pacifica/types/market.d.ts +64 -0
- package/dist/pacifica/types/market.js +1 -0
- package/dist/pacifica/types/order.d.ts +92 -0
- package/dist/pacifica/types/order.js +1 -0
- package/dist/pacifica/types/position.d.ts +25 -0
- package/dist/pacifica/types/position.js +1 -0
- package/dist/pacifica/types/ws.d.ts +34 -0
- package/dist/pacifica/types/ws.js +41 -0
- package/dist/pacifica/ws-client.d.ts +42 -0
- package/dist/pacifica/ws-client.js +180 -0
- package/dist/plan-executor.d.ts +48 -0
- package/dist/plan-executor.js +280 -0
- package/dist/position-history.d.ts +68 -0
- package/dist/position-history.js +222 -0
- package/dist/rebalance.d.ts +64 -0
- package/dist/rebalance.js +142 -0
- package/dist/retry.d.ts +74 -0
- package/dist/retry.js +129 -0
- package/dist/risk.d.ts +48 -0
- package/dist/risk.js +156 -0
- package/dist/settings.d.ts +19 -0
- package/dist/settings.js +45 -0
- package/dist/shared-api.d.ts +5 -0
- package/dist/shared-api.js +5 -0
- package/dist/strategies/dca.d.ts +25 -0
- package/dist/strategies/dca.js +114 -0
- package/dist/strategies/funding-arb.d.ts +15 -0
- package/dist/strategies/funding-arb.js +281 -0
- package/dist/strategies/grid.d.ts +34 -0
- package/dist/strategies/grid.js +185 -0
- package/dist/strategies/trailing-stop.d.ts +17 -0
- package/dist/strategies/trailing-stop.js +121 -0
- package/dist/strategies/twap.d.ts +20 -0
- package/dist/strategies/twap.js +78 -0
- package/dist/trade-validator.d.ts +39 -0
- package/dist/trade-validator.js +154 -0
- package/dist/utils.d.ts +38 -0
- package/dist/utils.js +110 -0
- package/package.json +63 -0
- package/skills/perp-cli/SKILL.md +149 -0
- package/skills/perp-cli/references/commands.md +143 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type Network } from "./constants.js";
|
|
2
|
+
import type { MarketInfo, PriceInfo, Orderbook, Trade, Kline, KlineInterval, AggLevel, AccountInfo, AccountSettings, Position, OrderInfo, MarketOrderParams, LimitOrderParams, StopOrderParams, EditOrderParams, CancelOrderParams, CancelAllOrdersParams, TWAPParams, CancelTWAPParams, TPSLParams, UpdateLeverageParams, WithdrawParams, TransferFundsParams, BatchAction, CreateLakeParams, LakeDepositParams, LakeWithdrawParams } from "./types/index.js";
|
|
3
|
+
type SignMessageFn = (message: Uint8Array) => Promise<Uint8Array>;
|
|
4
|
+
export interface PacificaClientConfig {
|
|
5
|
+
network?: Network;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
builderCode?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class PacificaClient {
|
|
11
|
+
private baseUrl;
|
|
12
|
+
private apiKey?;
|
|
13
|
+
private builderCode;
|
|
14
|
+
constructor(config?: PacificaClientConfig);
|
|
15
|
+
private headers;
|
|
16
|
+
private get;
|
|
17
|
+
private post;
|
|
18
|
+
private addBuilderCode;
|
|
19
|
+
getInfo(): Promise<MarketInfo[]>;
|
|
20
|
+
getPrices(): Promise<PriceInfo[]>;
|
|
21
|
+
getBook(symbol: string, aggLevel?: AggLevel): Promise<Orderbook>;
|
|
22
|
+
getTrades(symbol: string): Promise<Trade[]>;
|
|
23
|
+
getKline(symbol: string, interval: KlineInterval, startTime: number, endTime?: number): Promise<Kline[]>;
|
|
24
|
+
getFundingHistory(symbol: string, opts?: {
|
|
25
|
+
limit?: number;
|
|
26
|
+
cursor?: string;
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
getAccount(account: string): Promise<AccountInfo>;
|
|
29
|
+
getAccountSettings(account: string): Promise<AccountSettings[]>;
|
|
30
|
+
getPositions(account: string): Promise<Position[]>;
|
|
31
|
+
getOrders(account: string): Promise<OrderInfo[]>;
|
|
32
|
+
getOrderHistory(account: string, opts?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
cursor?: string;
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
getTradeHistory(account: string, opts?: {
|
|
37
|
+
symbol?: string;
|
|
38
|
+
start_time?: number;
|
|
39
|
+
end_time?: number;
|
|
40
|
+
limit?: number;
|
|
41
|
+
cursor?: number;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
getFundingAccountHistory(account: string, opts?: {
|
|
44
|
+
limit?: number;
|
|
45
|
+
cursor?: string;
|
|
46
|
+
}): Promise<unknown>;
|
|
47
|
+
getPortfolio(account: string, opts?: {
|
|
48
|
+
time_range?: string;
|
|
49
|
+
start_time?: number;
|
|
50
|
+
end_time?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
}): Promise<unknown>;
|
|
53
|
+
getBalanceHistory(account: string, opts?: {
|
|
54
|
+
limit?: number;
|
|
55
|
+
cursor?: string;
|
|
56
|
+
}): Promise<unknown>;
|
|
57
|
+
getOrderHistoryById(orderId: number): Promise<unknown>;
|
|
58
|
+
getTWAPOrders(account: string): Promise<unknown[]>;
|
|
59
|
+
createMarketOrder(params: MarketOrderParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
60
|
+
createLimitOrder(params: LimitOrderParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
61
|
+
createStopOrder(params: StopOrderParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
62
|
+
editOrder(params: EditOrderParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
63
|
+
cancelOrder(params: CancelOrderParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
64
|
+
cancelAllOrders(params: CancelAllOrdersParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
65
|
+
cancelStopOrder(params: {
|
|
66
|
+
symbol: string;
|
|
67
|
+
order_id: number;
|
|
68
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
69
|
+
createTWAP(params: TWAPParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
70
|
+
cancelTWAP(params: CancelTWAPParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
71
|
+
setTPSL(params: TPSLParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
72
|
+
updateLeverage(params: UpdateLeverageParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
73
|
+
updateMarginMode(params: {
|
|
74
|
+
symbol: string;
|
|
75
|
+
is_isolated: boolean;
|
|
76
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
77
|
+
withdraw(params: WithdrawParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
78
|
+
createSubaccount(subaccountName: string, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
79
|
+
listSubaccounts(account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
80
|
+
transferFunds(params: TransferFundsParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
81
|
+
bindAgentWallet(agentWallet: string, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
82
|
+
listAgentWallets(account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
83
|
+
revokeAgentWallet(agentWallet: string, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
84
|
+
revokeAllAgentWallets(account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
85
|
+
createApiKey(name: string, maxFeeRate: string, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
86
|
+
listApiKeys(account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
87
|
+
revokeApiKey(apiKey: string, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
88
|
+
createLake(params: CreateLakeParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
89
|
+
depositToLake(params: LakeDepositParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
90
|
+
withdrawFromLake(params: LakeWithdrawParams, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
91
|
+
approveBuilderCode(params: {
|
|
92
|
+
builder_code: string;
|
|
93
|
+
max_fee_rate: string;
|
|
94
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
95
|
+
revokeBuilderCode(params: {
|
|
96
|
+
builder_code: string;
|
|
97
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
98
|
+
getBuilderApprovals(account: string): Promise<unknown>;
|
|
99
|
+
updateBuilderFeeRate(params: {
|
|
100
|
+
builder_code: string;
|
|
101
|
+
fee_rate: string;
|
|
102
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
103
|
+
getBuilderOverview(account: string): Promise<unknown>;
|
|
104
|
+
getBuilderTrades(builderCode: string): Promise<unknown>;
|
|
105
|
+
getBuilderLeaderboard(builderCode: string): Promise<unknown>;
|
|
106
|
+
claimReferralCode(params: {
|
|
107
|
+
code: string;
|
|
108
|
+
}, account: string, signMessage: SignMessageFn): Promise<unknown>;
|
|
109
|
+
batchOrders(actions: BatchAction[]): Promise<unknown>;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { BUILDER_CODE, getNetworkConfig } from "./constants.js";
|
|
2
|
+
import { buildSignedRequest } from "./signing.js";
|
|
3
|
+
export class PacificaClient {
|
|
4
|
+
baseUrl;
|
|
5
|
+
apiKey;
|
|
6
|
+
builderCode;
|
|
7
|
+
constructor(config = {}) {
|
|
8
|
+
this.baseUrl =
|
|
9
|
+
config.baseUrl || getNetworkConfig(config.network).restUrl;
|
|
10
|
+
this.apiKey = config.apiKey;
|
|
11
|
+
this.builderCode = config.builderCode || BUILDER_CODE;
|
|
12
|
+
}
|
|
13
|
+
headers() {
|
|
14
|
+
const h = { "Content-Type": "application/json" };
|
|
15
|
+
if (this.apiKey)
|
|
16
|
+
h["PF-API-KEY"] = this.apiKey;
|
|
17
|
+
return h;
|
|
18
|
+
}
|
|
19
|
+
async get(path, params) {
|
|
20
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
21
|
+
if (params) {
|
|
22
|
+
Object.entries(params).forEach(([k, v]) => {
|
|
23
|
+
if (v !== undefined && v !== null)
|
|
24
|
+
url.searchParams.set(k, v);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const res = await fetch(url.toString(), { headers: this.headers() });
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
const text = await res.text();
|
|
30
|
+
throw new Error(`GET ${path} failed (${res.status}): ${text}`);
|
|
31
|
+
}
|
|
32
|
+
const json = await res.json();
|
|
33
|
+
// Unwrap Pacifica API response envelope: {success, data, error, code}
|
|
34
|
+
if (json && typeof json === "object" && "data" in json && "success" in json) {
|
|
35
|
+
return json.data;
|
|
36
|
+
}
|
|
37
|
+
return json;
|
|
38
|
+
}
|
|
39
|
+
async post(path, body) {
|
|
40
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: this.headers(),
|
|
43
|
+
body: JSON.stringify(body),
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const text = await res.text();
|
|
47
|
+
throw new Error(`POST ${path} failed (${res.status}): ${text}`);
|
|
48
|
+
}
|
|
49
|
+
return res.json();
|
|
50
|
+
}
|
|
51
|
+
addBuilderCode(payload) {
|
|
52
|
+
if (this.builderCode) {
|
|
53
|
+
return { ...payload, builder_code: this.builderCode };
|
|
54
|
+
}
|
|
55
|
+
return payload;
|
|
56
|
+
}
|
|
57
|
+
// ==================== PUBLIC ENDPOINTS ====================
|
|
58
|
+
async getInfo() {
|
|
59
|
+
return this.get("/info");
|
|
60
|
+
}
|
|
61
|
+
async getPrices() {
|
|
62
|
+
return this.get("/info/prices");
|
|
63
|
+
}
|
|
64
|
+
async getBook(symbol, aggLevel) {
|
|
65
|
+
const params = { symbol };
|
|
66
|
+
if (aggLevel)
|
|
67
|
+
params.agg_level = String(aggLevel);
|
|
68
|
+
return this.get("/book", params);
|
|
69
|
+
}
|
|
70
|
+
async getTrades(symbol) {
|
|
71
|
+
return this.get("/trades", { symbol });
|
|
72
|
+
}
|
|
73
|
+
async getKline(symbol, interval, startTime, endTime) {
|
|
74
|
+
const params = {
|
|
75
|
+
symbol,
|
|
76
|
+
interval,
|
|
77
|
+
start_time: String(startTime),
|
|
78
|
+
};
|
|
79
|
+
if (endTime)
|
|
80
|
+
params.end_time = String(endTime);
|
|
81
|
+
return this.get("/kline", params);
|
|
82
|
+
}
|
|
83
|
+
async getFundingHistory(symbol, opts) {
|
|
84
|
+
const params = { symbol };
|
|
85
|
+
if (opts?.limit)
|
|
86
|
+
params.limit = String(opts.limit);
|
|
87
|
+
if (opts?.cursor)
|
|
88
|
+
params.cursor = opts.cursor;
|
|
89
|
+
return this.get("/funding_rate/history", params);
|
|
90
|
+
}
|
|
91
|
+
// ==================== AUTHENTICATED GET ENDPOINTS ====================
|
|
92
|
+
async getAccount(account) {
|
|
93
|
+
return this.get("/account", { account });
|
|
94
|
+
}
|
|
95
|
+
async getAccountSettings(account) {
|
|
96
|
+
return this.get("/account/settings", { account });
|
|
97
|
+
}
|
|
98
|
+
async getPositions(account) {
|
|
99
|
+
return this.get("/positions", { account });
|
|
100
|
+
}
|
|
101
|
+
async getOrders(account) {
|
|
102
|
+
return this.get("/orders", { account });
|
|
103
|
+
}
|
|
104
|
+
async getOrderHistory(account, opts) {
|
|
105
|
+
const params = { account };
|
|
106
|
+
if (opts?.limit)
|
|
107
|
+
params.limit = String(opts.limit);
|
|
108
|
+
if (opts?.cursor)
|
|
109
|
+
params.cursor = opts.cursor;
|
|
110
|
+
return this.get("/orders/history", params);
|
|
111
|
+
}
|
|
112
|
+
async getTradeHistory(account, opts) {
|
|
113
|
+
const params = { account };
|
|
114
|
+
if (opts?.symbol)
|
|
115
|
+
params.symbol = opts.symbol;
|
|
116
|
+
if (opts?.start_time)
|
|
117
|
+
params.start_time = String(opts.start_time);
|
|
118
|
+
if (opts?.end_time)
|
|
119
|
+
params.end_time = String(opts.end_time);
|
|
120
|
+
if (opts?.limit)
|
|
121
|
+
params.limit = String(opts.limit);
|
|
122
|
+
if (opts?.cursor)
|
|
123
|
+
params.cursor = String(opts.cursor);
|
|
124
|
+
return this.get("/trades/history", params);
|
|
125
|
+
}
|
|
126
|
+
async getFundingAccountHistory(account, opts) {
|
|
127
|
+
const params = { account };
|
|
128
|
+
if (opts?.limit)
|
|
129
|
+
params.limit = String(opts.limit);
|
|
130
|
+
if (opts?.cursor)
|
|
131
|
+
params.cursor = opts.cursor;
|
|
132
|
+
return this.get("/funding/history", params);
|
|
133
|
+
}
|
|
134
|
+
async getPortfolio(account, opts) {
|
|
135
|
+
const params = { account };
|
|
136
|
+
if (opts?.time_range)
|
|
137
|
+
params.time_range = opts.time_range;
|
|
138
|
+
if (opts?.start_time)
|
|
139
|
+
params.start_time = String(opts.start_time);
|
|
140
|
+
if (opts?.end_time)
|
|
141
|
+
params.end_time = String(opts.end_time);
|
|
142
|
+
if (opts?.limit)
|
|
143
|
+
params.limit = String(opts.limit);
|
|
144
|
+
return this.get("/portfolio", params);
|
|
145
|
+
}
|
|
146
|
+
async getBalanceHistory(account, opts) {
|
|
147
|
+
const params = { account };
|
|
148
|
+
if (opts?.limit)
|
|
149
|
+
params.limit = String(opts.limit);
|
|
150
|
+
if (opts?.cursor)
|
|
151
|
+
params.cursor = opts.cursor;
|
|
152
|
+
return this.get("/account/balance/history", params);
|
|
153
|
+
}
|
|
154
|
+
async getOrderHistoryById(orderId) {
|
|
155
|
+
return this.get("/orders/history_by_id", { order_id: String(orderId) });
|
|
156
|
+
}
|
|
157
|
+
async getTWAPOrders(account) {
|
|
158
|
+
return this.get("/orders/twap", { account });
|
|
159
|
+
}
|
|
160
|
+
// ==================== AUTHENTICATED POST ENDPOINTS ====================
|
|
161
|
+
async createMarketOrder(params, account, signMessage) {
|
|
162
|
+
const payload = this.addBuilderCode({ ...params });
|
|
163
|
+
const body = await buildSignedRequest("create_market_order", payload, account, signMessage);
|
|
164
|
+
return this.post("/orders/create_market", body);
|
|
165
|
+
}
|
|
166
|
+
async createLimitOrder(params, account, signMessage) {
|
|
167
|
+
const payload = this.addBuilderCode({ ...params });
|
|
168
|
+
const body = await buildSignedRequest("create_order", payload, account, signMessage);
|
|
169
|
+
return this.post("/orders/create", body);
|
|
170
|
+
}
|
|
171
|
+
async createStopOrder(params, account, signMessage) {
|
|
172
|
+
const body = await buildSignedRequest("create_stop_order", params, account, signMessage);
|
|
173
|
+
return this.post("/orders/stop/create", body);
|
|
174
|
+
}
|
|
175
|
+
async editOrder(params, account, signMessage) {
|
|
176
|
+
const body = await buildSignedRequest("edit_order", params, account, signMessage);
|
|
177
|
+
return this.post("/orders/edit", body);
|
|
178
|
+
}
|
|
179
|
+
async cancelOrder(params, account, signMessage) {
|
|
180
|
+
const body = await buildSignedRequest("cancel_order", params, account, signMessage);
|
|
181
|
+
return this.post("/orders/cancel", body);
|
|
182
|
+
}
|
|
183
|
+
async cancelAllOrders(params, account, signMessage) {
|
|
184
|
+
const body = await buildSignedRequest("cancel_all_orders", params, account, signMessage);
|
|
185
|
+
return this.post("/orders/cancel_all", body);
|
|
186
|
+
}
|
|
187
|
+
async cancelStopOrder(params, account, signMessage) {
|
|
188
|
+
const body = await buildSignedRequest("cancel_stop_order", params, account, signMessage);
|
|
189
|
+
return this.post("/orders/stop/cancel", body);
|
|
190
|
+
}
|
|
191
|
+
async createTWAP(params, account, signMessage) {
|
|
192
|
+
const payload = this.addBuilderCode({ ...params });
|
|
193
|
+
const body = await buildSignedRequest("create_twap_order", payload, account, signMessage);
|
|
194
|
+
return this.post("/orders/twap/create", body);
|
|
195
|
+
}
|
|
196
|
+
async cancelTWAP(params, account, signMessage) {
|
|
197
|
+
const body = await buildSignedRequest("cancel_twap_order", params, account, signMessage);
|
|
198
|
+
return this.post("/orders/twap/cancel", body);
|
|
199
|
+
}
|
|
200
|
+
async setTPSL(params, account, signMessage) {
|
|
201
|
+
const body = await buildSignedRequest("set_position_tpsl", params, account, signMessage);
|
|
202
|
+
return this.post("/positions/tpsl", body);
|
|
203
|
+
}
|
|
204
|
+
async updateLeverage(params, account, signMessage) {
|
|
205
|
+
const body = await buildSignedRequest("update_leverage", params, account, signMessage);
|
|
206
|
+
return this.post("/account/leverage", body);
|
|
207
|
+
}
|
|
208
|
+
async updateMarginMode(params, account, signMessage) {
|
|
209
|
+
const body = await buildSignedRequest("update_margin_mode", params, account, signMessage);
|
|
210
|
+
return this.post("/account/margin", body);
|
|
211
|
+
}
|
|
212
|
+
async withdraw(params, account, signMessage) {
|
|
213
|
+
const body = await buildSignedRequest("withdraw", params, account, signMessage);
|
|
214
|
+
return this.post("/account/withdraw", body);
|
|
215
|
+
}
|
|
216
|
+
// ==================== SUBACCOUNT ====================
|
|
217
|
+
async createSubaccount(subaccountName, account, signMessage) {
|
|
218
|
+
// Step 1: Initiate
|
|
219
|
+
const initiateBody = await buildSignedRequest("subaccount_initiate", { subaccount_name: subaccountName }, account, signMessage);
|
|
220
|
+
await this.post("/account/subaccount/create", initiateBody);
|
|
221
|
+
// Step 2: Confirm
|
|
222
|
+
const confirmBody = await buildSignedRequest("subaccount_confirm", { subaccount_name: subaccountName }, account, signMessage);
|
|
223
|
+
return this.post("/account/subaccount/create", confirmBody);
|
|
224
|
+
}
|
|
225
|
+
async listSubaccounts(account, signMessage) {
|
|
226
|
+
const body = await buildSignedRequest("list_subaccounts", {}, account, signMessage);
|
|
227
|
+
return this.post("/account/subaccount/list", body);
|
|
228
|
+
}
|
|
229
|
+
async transferFunds(params, account, signMessage) {
|
|
230
|
+
const body = await buildSignedRequest("transfer_funds", params, account, signMessage);
|
|
231
|
+
return this.post("/account/subaccount/transfer", body);
|
|
232
|
+
}
|
|
233
|
+
// ==================== AGENT WALLET ====================
|
|
234
|
+
async bindAgentWallet(agentWallet, account, signMessage) {
|
|
235
|
+
const body = await buildSignedRequest("bind_agent_wallet", { agent_wallet: agentWallet }, account, signMessage);
|
|
236
|
+
return this.post("/agent/bind", body);
|
|
237
|
+
}
|
|
238
|
+
async listAgentWallets(account, signMessage) {
|
|
239
|
+
const body = await buildSignedRequest("list_agent_wallets", {}, account, signMessage);
|
|
240
|
+
return this.post("/agent/list", body);
|
|
241
|
+
}
|
|
242
|
+
async revokeAgentWallet(agentWallet, account, signMessage) {
|
|
243
|
+
const body = await buildSignedRequest("revoke_agent_wallet", { agent_wallet: agentWallet }, account, signMessage);
|
|
244
|
+
return this.post("/agent/revoke", body);
|
|
245
|
+
}
|
|
246
|
+
async revokeAllAgentWallets(account, signMessage) {
|
|
247
|
+
const body = await buildSignedRequest("revoke_all_agent_wallets", {}, account, signMessage);
|
|
248
|
+
return this.post("/agent/revoke_all", body);
|
|
249
|
+
}
|
|
250
|
+
// ==================== API KEYS ====================
|
|
251
|
+
async createApiKey(name, maxFeeRate, account, signMessage) {
|
|
252
|
+
const body = await buildSignedRequest("create_api_key", { name, max_fee_rate: maxFeeRate }, account, signMessage);
|
|
253
|
+
return this.post("/account/api_keys/create", body);
|
|
254
|
+
}
|
|
255
|
+
async listApiKeys(account, signMessage) {
|
|
256
|
+
const body = await buildSignedRequest("list_api_keys", {}, account, signMessage);
|
|
257
|
+
return this.post("/account/api_keys", body);
|
|
258
|
+
}
|
|
259
|
+
async revokeApiKey(apiKey, account, signMessage) {
|
|
260
|
+
const body = await buildSignedRequest("revoke_api_key", { api_key: apiKey }, account, signMessage);
|
|
261
|
+
return this.post("/account/api_keys/revoke", body);
|
|
262
|
+
}
|
|
263
|
+
// ==================== LAKE ====================
|
|
264
|
+
async createLake(params, account, signMessage) {
|
|
265
|
+
const body = await buildSignedRequest("create_lake", params, account, signMessage);
|
|
266
|
+
return this.post("/lake/create", body);
|
|
267
|
+
}
|
|
268
|
+
async depositToLake(params, account, signMessage) {
|
|
269
|
+
const body = await buildSignedRequest("deposit_to_lake", params, account, signMessage);
|
|
270
|
+
return this.post("/lake/deposit", body);
|
|
271
|
+
}
|
|
272
|
+
async withdrawFromLake(params, account, signMessage) {
|
|
273
|
+
const body = await buildSignedRequest("withdraw_from_lake", params, account, signMessage);
|
|
274
|
+
return this.post("/lake/withdraw", body);
|
|
275
|
+
}
|
|
276
|
+
// ==================== BUILDER CODE ====================
|
|
277
|
+
async approveBuilderCode(params, account, signMessage) {
|
|
278
|
+
const body = await buildSignedRequest("approve_builder_code", params, account, signMessage);
|
|
279
|
+
return this.post("/account/builder_codes/approve", body);
|
|
280
|
+
}
|
|
281
|
+
async revokeBuilderCode(params, account, signMessage) {
|
|
282
|
+
const body = await buildSignedRequest("revoke_builder_code", params, account, signMessage);
|
|
283
|
+
return this.post("/account/builder_codes/revoke", body);
|
|
284
|
+
}
|
|
285
|
+
async getBuilderApprovals(account) {
|
|
286
|
+
return this.get("/account/builder_codes/approvals", { account });
|
|
287
|
+
}
|
|
288
|
+
async updateBuilderFeeRate(params, account, signMessage) {
|
|
289
|
+
const body = await buildSignedRequest("update_builder_code_fee_rate", params, account, signMessage);
|
|
290
|
+
return this.post("/builder/update_fee_rate", body);
|
|
291
|
+
}
|
|
292
|
+
async getBuilderOverview(account) {
|
|
293
|
+
return this.get("/builder/overview", { account });
|
|
294
|
+
}
|
|
295
|
+
async getBuilderTrades(builderCode) {
|
|
296
|
+
return this.get("/builder/trades", { builder_code: builderCode });
|
|
297
|
+
}
|
|
298
|
+
async getBuilderLeaderboard(builderCode) {
|
|
299
|
+
return this.get("/leaderboard/builder_code", { builder_code: builderCode });
|
|
300
|
+
}
|
|
301
|
+
// ==================== REFERRAL ====================
|
|
302
|
+
async claimReferralCode(params, account, signMessage) {
|
|
303
|
+
const body = await buildSignedRequest("claim_referral_code", params, account, signMessage);
|
|
304
|
+
return this.post("/referral/user/code/claim", body);
|
|
305
|
+
}
|
|
306
|
+
// ==================== BATCH ====================
|
|
307
|
+
async batchOrders(actions) {
|
|
308
|
+
return this.post("/orders/batch", { actions });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const MAINNET_REST = "https://api.pacifica.fi/api/v1";
|
|
2
|
+
export declare const TESTNET_REST = "https://test-api.pacifica.fi/api/v1";
|
|
3
|
+
export declare const MAINNET_WS = "wss://ws.pacifica.fi/ws";
|
|
4
|
+
export declare const TESTNET_WS = "wss://test-ws.pacifica.fi/ws";
|
|
5
|
+
export declare const MAINNET_PROGRAM_ID = "PCFA5iYgmqK6MqPhWNKg7Yv7auX7VZ4Cx7T1eJyrAMH";
|
|
6
|
+
export declare const MAINNET_CENTRAL_STATE = "9Gdmhq4Gv1LnNMp7aiS1HSVd7pNnXNMsbuXALCQRmGjY";
|
|
7
|
+
export declare const MAINNET_PACIFICA_VAULT = "72R843XwZxqWhsJceARQQTTbYtWy6Zw9et2YV4FpRHTa";
|
|
8
|
+
export declare const MAINNET_USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
9
|
+
export declare const TESTNET_PROGRAM_ID = "peRPsYCcB1J9jvrs29jiGdjkytxs8uHLmSPLKKP9ptm";
|
|
10
|
+
export declare const TESTNET_CENTRAL_STATE = "2zPRq1Qvdq5A4Ld6WsH7usgCge4ApZRYfhhf5VAjfXxv";
|
|
11
|
+
export declare const TESTNET_PACIFICA_VAULT = "5SDFdHZGTZbyRYu54CgmRkCGnPHC5pYaN27p7XGLqnBs";
|
|
12
|
+
export declare const TESTNET_USDC_MINT = "USDPqRbLidFGufty2s3oizmDEKdqx7ePTqzDMbf5ZKM";
|
|
13
|
+
export declare const SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
14
|
+
export declare const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
15
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
16
|
+
export declare const DEFAULT_EXPIRY_WINDOW = 5000;
|
|
17
|
+
export declare const USDC_DECIMALS = 6;
|
|
18
|
+
export declare const BUILDER_CODE: string;
|
|
19
|
+
export type Network = "mainnet" | "testnet";
|
|
20
|
+
export declare function getNetworkConfig(network?: Network): {
|
|
21
|
+
restUrl: string;
|
|
22
|
+
wsUrl: string;
|
|
23
|
+
programId: string;
|
|
24
|
+
centralState: string;
|
|
25
|
+
pacificaVault: string;
|
|
26
|
+
usdcMint: string;
|
|
27
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Pacifica Protocol Constants
|
|
2
|
+
// REST API URLs
|
|
3
|
+
export const MAINNET_REST = "https://api.pacifica.fi/api/v1";
|
|
4
|
+
export const TESTNET_REST = "https://test-api.pacifica.fi/api/v1";
|
|
5
|
+
// WebSocket URLs
|
|
6
|
+
export const MAINNET_WS = "wss://ws.pacifica.fi/ws";
|
|
7
|
+
export const TESTNET_WS = "wss://test-ws.pacifica.fi/ws";
|
|
8
|
+
// Mainnet Program IDs
|
|
9
|
+
export const MAINNET_PROGRAM_ID = "PCFA5iYgmqK6MqPhWNKg7Yv7auX7VZ4Cx7T1eJyrAMH";
|
|
10
|
+
export const MAINNET_CENTRAL_STATE = "9Gdmhq4Gv1LnNMp7aiS1HSVd7pNnXNMsbuXALCQRmGjY";
|
|
11
|
+
export const MAINNET_PACIFICA_VAULT = "72R843XwZxqWhsJceARQQTTbYtWy6Zw9et2YV4FpRHTa";
|
|
12
|
+
export const MAINNET_USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
13
|
+
// Testnet (Devnet) Program IDs
|
|
14
|
+
export const TESTNET_PROGRAM_ID = "peRPsYCcB1J9jvrs29jiGdjkytxs8uHLmSPLKKP9ptm";
|
|
15
|
+
export const TESTNET_CENTRAL_STATE = "2zPRq1Qvdq5A4Ld6WsH7usgCge4ApZRYfhhf5VAjfXxv";
|
|
16
|
+
export const TESTNET_PACIFICA_VAULT = "5SDFdHZGTZbyRYu54CgmRkCGnPHC5pYaN27p7XGLqnBs";
|
|
17
|
+
export const TESTNET_USDC_MINT = "USDPqRbLidFGufty2s3oizmDEKdqx7ePTqzDMbf5ZKM";
|
|
18
|
+
// Standard Solana Program IDs
|
|
19
|
+
export const SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
20
|
+
export const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
21
|
+
export const ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
22
|
+
// Signing defaults
|
|
23
|
+
export const DEFAULT_EXPIRY_WINDOW = 5000; // 5 seconds
|
|
24
|
+
// USDC decimals
|
|
25
|
+
export const USDC_DECIMALS = 6;
|
|
26
|
+
// Builder code — 0% fee, used for Pacifica hackathon tracking
|
|
27
|
+
export const BUILDER_CODE = process.env.PACIFICA_BUILDER_CODE || "PERPCLI";
|
|
28
|
+
export function getNetworkConfig(network = "mainnet") {
|
|
29
|
+
if (network === "testnet") {
|
|
30
|
+
return {
|
|
31
|
+
restUrl: TESTNET_REST,
|
|
32
|
+
wsUrl: TESTNET_WS,
|
|
33
|
+
programId: TESTNET_PROGRAM_ID,
|
|
34
|
+
centralState: TESTNET_CENTRAL_STATE,
|
|
35
|
+
pacificaVault: TESTNET_PACIFICA_VAULT,
|
|
36
|
+
usdcMint: TESTNET_USDC_MINT,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
restUrl: MAINNET_REST,
|
|
41
|
+
wsUrl: MAINNET_WS,
|
|
42
|
+
programId: MAINNET_PROGRAM_ID,
|
|
43
|
+
centralState: MAINNET_CENTRAL_STATE,
|
|
44
|
+
pacificaVault: MAINNET_PACIFICA_VAULT,
|
|
45
|
+
usdcMint: MAINNET_USDC_MINT,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction, Transaction, type TransactionSignature } from "@solana/web3.js";
|
|
2
|
+
import { type Network } from "./constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a Pacifica deposit instruction.
|
|
5
|
+
*
|
|
6
|
+
* @param userPubkey - User's wallet public key
|
|
7
|
+
* @param amount - Amount in USDC (e.g., 100 for $100)
|
|
8
|
+
* @param network - mainnet or testnet
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildDepositInstruction(userPubkey: PublicKey, amount: number, network?: Network): Promise<TransactionInstruction>;
|
|
11
|
+
/**
|
|
12
|
+
* Build and send a deposit transaction.
|
|
13
|
+
*/
|
|
14
|
+
export declare function deposit(connection: Connection, userPubkey: PublicKey, amount: number, signTransaction: (tx: Transaction) => Promise<Transaction>, network?: Network): Promise<TransactionSignature>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction, Transaction, } from "@solana/web3.js";
|
|
2
|
+
import { getNetworkConfig, USDC_DECIMALS } from "./constants.js";
|
|
3
|
+
const TOKEN_PROGRAM = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
4
|
+
const ASSOCIATED_TOKEN_PROGRAM = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
5
|
+
const SYSTEM_PROGRAM = new PublicKey("11111111111111111111111111111111");
|
|
6
|
+
/**
|
|
7
|
+
* Build the Anchor "global:deposit" discriminator.
|
|
8
|
+
* sha256("global:deposit")[:8]
|
|
9
|
+
*/
|
|
10
|
+
async function getDepositDiscriminator() {
|
|
11
|
+
const data = new TextEncoder().encode("global:deposit");
|
|
12
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
13
|
+
return new Uint8Array(hash).slice(0, 8);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Derive the Associated Token Account for a user.
|
|
17
|
+
*/
|
|
18
|
+
function getATA(owner, mint) {
|
|
19
|
+
const [ata] = PublicKey.findProgramAddressSync([owner.toBytes(), TOKEN_PROGRAM.toBytes(), mint.toBytes()], ASSOCIATED_TOKEN_PROGRAM);
|
|
20
|
+
return ata;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Derive the event authority PDA.
|
|
24
|
+
*/
|
|
25
|
+
function getEventAuthority(programId) {
|
|
26
|
+
const [pda] = PublicKey.findProgramAddressSync([Buffer.from("__event_authority")], programId);
|
|
27
|
+
return pda;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a Pacifica deposit instruction.
|
|
31
|
+
*
|
|
32
|
+
* @param userPubkey - User's wallet public key
|
|
33
|
+
* @param amount - Amount in USDC (e.g., 100 for $100)
|
|
34
|
+
* @param network - mainnet or testnet
|
|
35
|
+
*/
|
|
36
|
+
export async function buildDepositInstruction(userPubkey, amount, network = "mainnet") {
|
|
37
|
+
const config = getNetworkConfig(network);
|
|
38
|
+
const programId = new PublicKey(config.programId);
|
|
39
|
+
const centralState = new PublicKey(config.centralState);
|
|
40
|
+
const pacificaVault = new PublicKey(config.pacificaVault);
|
|
41
|
+
const usdcMint = new PublicKey(config.usdcMint);
|
|
42
|
+
const userATA = getATA(userPubkey, usdcMint);
|
|
43
|
+
const eventAuthority = getEventAuthority(programId);
|
|
44
|
+
// Build instruction data: discriminator + amount (u64 LE)
|
|
45
|
+
const discriminator = await getDepositDiscriminator();
|
|
46
|
+
const amountLamports = BigInt(Math.round(amount * 10 ** USDC_DECIMALS));
|
|
47
|
+
const amountBytes = new Uint8Array(8);
|
|
48
|
+
const view = new DataView(amountBytes.buffer);
|
|
49
|
+
view.setBigUint64(0, amountLamports, true); // little-endian
|
|
50
|
+
const data = new Uint8Array(discriminator.length + amountBytes.length);
|
|
51
|
+
data.set(discriminator, 0);
|
|
52
|
+
data.set(amountBytes, discriminator.length);
|
|
53
|
+
// Account metas (ORDER IS CRITICAL)
|
|
54
|
+
const keys = [
|
|
55
|
+
{ pubkey: userPubkey, isSigner: true, isWritable: true },
|
|
56
|
+
{ pubkey: userATA, isSigner: false, isWritable: true },
|
|
57
|
+
{ pubkey: centralState, isSigner: false, isWritable: true },
|
|
58
|
+
{ pubkey: pacificaVault, isSigner: false, isWritable: true },
|
|
59
|
+
{ pubkey: TOKEN_PROGRAM, isSigner: false, isWritable: false },
|
|
60
|
+
{ pubkey: ASSOCIATED_TOKEN_PROGRAM, isSigner: false, isWritable: false },
|
|
61
|
+
{ pubkey: usdcMint, isSigner: false, isWritable: false },
|
|
62
|
+
{ pubkey: SYSTEM_PROGRAM, isSigner: false, isWritable: false },
|
|
63
|
+
{ pubkey: eventAuthority, isSigner: false, isWritable: false },
|
|
64
|
+
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
65
|
+
];
|
|
66
|
+
return new TransactionInstruction({ keys, programId, data: Buffer.from(data) });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build and send a deposit transaction.
|
|
70
|
+
*/
|
|
71
|
+
export async function deposit(connection, userPubkey, amount, signTransaction, network = "mainnet") {
|
|
72
|
+
const instruction = await buildDepositInstruction(userPubkey, amount, network);
|
|
73
|
+
const tx = new Transaction().add(instruction);
|
|
74
|
+
tx.feePayer = userPubkey;
|
|
75
|
+
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
76
|
+
const signed = await signTransaction(tx);
|
|
77
|
+
return connection.sendRawTransaction(signed.serialize());
|
|
78
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PacificaClient, type PacificaClientConfig } from "./client.js";
|
|
2
|
+
export { PacificaWSClient, type PacificaWSConfig } from "./ws-client.js";
|
|
3
|
+
export { sortJsonKeys, prepareMessage, createHeader, signWithWallet, buildSignedRequest, buildAgentSignedRequest, } from "./signing.js";
|
|
4
|
+
export { buildDepositInstruction, deposit } from "./deposit.js";
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./types/index.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Core
|
|
2
|
+
export { PacificaClient } from "./client.js";
|
|
3
|
+
export { PacificaWSClient } from "./ws-client.js";
|
|
4
|
+
// Signing
|
|
5
|
+
export { sortJsonKeys, prepareMessage, createHeader, signWithWallet, buildSignedRequest, buildAgentSignedRequest, } from "./signing.js";
|
|
6
|
+
// Deposit
|
|
7
|
+
export { buildDepositInstruction, deposit } from "./deposit.js";
|
|
8
|
+
// Constants
|
|
9
|
+
export * from "./constants.js";
|
|
10
|
+
// Types
|
|
11
|
+
export * from "./types/index.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively sort all object keys alphabetically.
|
|
3
|
+
* Exact port of Python SDK's sort_json_keys().
|
|
4
|
+
*/
|
|
5
|
+
export declare function sortJsonKeys(value: unknown): unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Prepare the message string for signing.
|
|
8
|
+
* Exact port of Python SDK's prepare_message().
|
|
9
|
+
*
|
|
10
|
+
* Header must contain: type, timestamp, expiry_window
|
|
11
|
+
* Returns compact JSON with sorted keys and payload nested under "data".
|
|
12
|
+
*/
|
|
13
|
+
export declare function prepareMessage(header: {
|
|
14
|
+
type: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
expiry_window: number;
|
|
17
|
+
}, payload: object): string;
|
|
18
|
+
/**
|
|
19
|
+
* Create a signing header with current timestamp.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createHeader(type: string, expiryWindow?: number): {
|
|
22
|
+
type: string;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
expiry_window: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Sign a message using a wallet adapter's signMessage function.
|
|
28
|
+
* Used in browser context with Phantom/Solflare/etc.
|
|
29
|
+
*
|
|
30
|
+
* @param header - Operation header (type, timestamp, expiry_window)
|
|
31
|
+
* @param payload - Operation payload
|
|
32
|
+
* @param signMessage - Wallet adapter's signMessage function
|
|
33
|
+
* @returns [message, base58EncodedSignature]
|
|
34
|
+
*/
|
|
35
|
+
export declare function signWithWallet(header: {
|
|
36
|
+
type: string;
|
|
37
|
+
timestamp: number;
|
|
38
|
+
expiry_window: number;
|
|
39
|
+
}, payload: object, signMessage: (message: Uint8Array) => Promise<Uint8Array>): Promise<[string, string]>;
|
|
40
|
+
/**
|
|
41
|
+
* Build a signed request body for REST API POST.
|
|
42
|
+
* Flattens payload to top level and adds account, signature, timestamp, expiry_window.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildSignedRequest(operationType: string, payload: object, account: string, signMessage: (message: Uint8Array) => Promise<Uint8Array>, expiryWindow?: number): Promise<Record<string, unknown>>;
|
|
45
|
+
/**
|
|
46
|
+
* Build a signed request with agent wallet.
|
|
47
|
+
* Used when an agent wallet is trading on behalf of a main account.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildAgentSignedRequest(operationType: string, payload: object, mainAccount: string, agentWallet: string, signMessage: (message: Uint8Array) => Promise<Uint8Array>, expiryWindow?: number): Promise<Record<string, unknown>>;
|