perp-cli 0.12.17 → 0.14.0
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/README.md +247 -27
- package/dist/_stderr-filter.js +0 -1
- package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
- package/dist/agent-wallet/lighter-keystore.js +92 -10
- package/dist/agent-wallet/passphrase.d.ts +1 -1
- package/dist/agent-wallet/passphrase.js +16 -3
- package/dist/agent-wallet/store.d.ts +37 -4
- package/dist/agent-wallet/store.js +132 -0
- package/dist/agent-wallet/venue-keystore.d.ts +14 -0
- package/dist/agent-wallet/venue-keystore.js +121 -0
- package/dist/api/public/hyperliquid.js +4 -4
- package/dist/api/public/lighter.js +5 -5
- package/dist/api/public/pacifica.d.ts +0 -1
- package/dist/api/public/pacifica.js +4 -13
- package/dist/api/public/urls.d.ts +9 -1
- package/dist/api/public/urls.js +35 -13
- package/dist/arb/file-lock.d.ts +11 -0
- package/dist/arb/file-lock.js +74 -0
- package/dist/arb/index.d.ts +2 -2
- package/dist/arb/index.js +2 -2
- package/dist/arb/pending-entry.d.ts +32 -0
- package/dist/arb/pending-entry.js +77 -0
- package/dist/arb/sizing.d.ts +6 -13
- package/dist/arb/sizing.js +12 -51
- package/dist/arb/state.d.ts +45 -12
- package/dist/arb/state.js +214 -42
- package/dist/arb/utils.d.ts +20 -6
- package/dist/arb/utils.js +43 -39
- package/dist/bot/conditions.d.ts +4 -4
- package/dist/bot/conditions.js +11 -6
- package/dist/bot/config.d.ts +17 -1
- package/dist/bot/config.js +48 -12
- package/dist/bot/engine.d.ts +61 -2
- package/dist/bot/engine.js +610 -144
- package/dist/bot/fill-size.d.ts +7 -0
- package/dist/bot/fill-size.js +18 -0
- package/dist/bot/index.d.ts +1 -1
- package/dist/bot/index.js +1 -1
- package/dist/bot/perp-order.d.ts +99 -0
- package/dist/bot/perp-order.js +299 -0
- package/dist/bot/presets.d.ts +7 -0
- package/dist/bot/presets.js +17 -0
- package/dist/bot/quarantine.d.ts +75 -0
- package/dist/bot/quarantine.js +190 -0
- package/dist/bot/quote-rules.d.ts +23 -0
- package/dist/bot/quote-rules.js +69 -0
- package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
- package/dist/bot/strategies/avellaneda-mm.js +72 -70
- package/dist/bot/strategies/basis-arb.js +2 -0
- package/dist/bot/strategies/dca-strategy.d.ts +2 -0
- package/dist/bot/strategies/dca-strategy.js +5 -0
- package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
- package/dist/bot/strategies/funding-arb-strategy.js +571 -380
- package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
- package/dist/bot/strategies/funding-arb-utils.js +159 -195
- package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
- package/dist/bot/strategies/funding-arb-v2.js +258 -47
- package/dist/bot/strategies/funding-auto.js +215 -194
- package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
- package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
- package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
- package/dist/bot/strategies/spot-perp-executor.js +319 -120
- package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
- package/dist/bot/strategies/spot-perp-state.js +70 -0
- package/dist/bot/strategy-types.d.ts +6 -0
- package/dist/bot/tui/BotDashboard.d.ts +7 -2
- package/dist/bot/tui/BotDashboard.js +6 -3
- package/dist/bridge-engine.d.ts +120 -19
- package/dist/bridge-engine.js +710 -422
- package/dist/bridge-signers.d.ts +54 -0
- package/dist/bridge-signers.js +161 -0
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +11 -0
- package/dist/cli-flags.d.ts +50 -0
- package/dist/cli-flags.js +104 -0
- package/dist/cli-program.d.ts +35 -0
- package/dist/cli-program.js +286 -0
- package/dist/cli-spec.js +1 -1
- package/dist/client-id-tracker.js +11 -2
- package/dist/commands/account.d.ts +7 -1
- package/dist/commands/account.js +70 -92
- package/dist/commands/agent-import.d.ts +114 -0
- package/dist/commands/agent-import.js +794 -0
- package/dist/commands/agent.d.ts +232 -2
- package/dist/commands/agent.js +1858 -955
- package/dist/commands/alerts.d.ts +1 -0
- package/dist/commands/alerts.js +31 -28
- package/dist/commands/arb/index.d.ts +60 -1
- package/dist/commands/arb/index.js +381 -384
- package/dist/commands/arb-auto.d.ts +132 -4
- package/dist/commands/arb-auto.js +1474 -967
- package/dist/commands/arb.d.ts +3 -1
- package/dist/commands/arb.js +62 -30
- package/dist/commands/bot.js +127 -47
- package/dist/commands/bridge.d.ts +2 -1
- package/dist/commands/bridge.js +339 -192
- package/dist/commands/builder.d.ts +55 -0
- package/dist/commands/builder.js +387 -0
- package/dist/commands/funds-onchain.d.ts +32 -0
- package/dist/commands/funds-onchain.js +286 -0
- package/dist/commands/funds.d.ts +25 -0
- package/dist/commands/funds.js +939 -245
- package/dist/commands/history.js +72 -45
- package/dist/commands/init.d.ts +107 -15
- package/dist/commands/init.js +1116 -249
- package/dist/commands/jobs.d.ts +2 -1
- package/dist/commands/jobs.js +77 -15
- package/dist/commands/manage.js +136 -91
- package/dist/commands/market.d.ts +4 -1
- package/dist/commands/market.js +35 -32
- package/dist/commands/outcome.d.ts +10 -0
- package/dist/commands/outcome.js +396 -0
- package/dist/commands/plan.js +52 -12
- package/dist/commands/portfolio.d.ts +1 -0
- package/dist/commands/portfolio.js +60 -72
- package/dist/commands/rebalance.d.ts +2 -1
- package/dist/commands/rebalance.js +33 -43
- package/dist/commands/risk.js +46 -19
- package/dist/commands/settings.d.ts +1 -0
- package/dist/commands/settings.js +246 -51
- package/dist/commands/trade.d.ts +50 -0
- package/dist/commands/trade.js +1943 -695
- package/dist/commands/wallet.d.ts +30 -1
- package/dist/commands/wallet.js +316 -337
- package/dist/config.d.ts +60 -9
- package/dist/config.js +252 -82
- package/dist/constants.d.ts +29 -4
- package/dist/constants.js +62 -20
- package/dist/dashboard/server.d.ts +2 -0
- package/dist/dashboard/server.js +9 -6
- package/dist/dashboard/ui.js +6 -4
- package/dist/dashboard/ws-feeds.js +20 -8
- package/dist/dex-asset-map.js +5 -3
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +194 -0
- package/dist/event-stream.js +75 -19
- package/dist/evm-master-tx.d.ts +59 -0
- package/dist/evm-master-tx.js +154 -0
- package/dist/exchanges/adapter-network.d.ts +10 -0
- package/dist/exchanges/adapter-network.js +10 -0
- package/dist/exchanges/arcus/adapter.d.ts +196 -0
- package/dist/exchanges/arcus/adapter.js +1092 -0
- package/dist/exchanges/arcus/agent.d.ts +55 -0
- package/dist/exchanges/arcus/agent.js +188 -0
- package/dist/exchanges/arcus/client.d.ts +63 -0
- package/dist/exchanges/arcus/client.js +285 -0
- package/dist/exchanges/arcus/public.d.ts +65 -0
- package/dist/exchanges/arcus/public.js +138 -0
- package/dist/exchanges/arcus/signing.d.ts +176 -0
- package/dist/exchanges/arcus/signing.js +288 -0
- package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
- package/dist/exchanges/arcus/spot-chain.js +241 -0
- package/dist/exchanges/arcus/spot-router.d.ts +177 -0
- package/dist/exchanges/arcus/spot-router.js +183 -0
- package/dist/exchanges/arcus/spot.d.ts +109 -0
- package/dist/exchanges/arcus/spot.js +645 -0
- package/dist/exchanges/aster-funds.d.ts +127 -0
- package/dist/exchanges/aster-funds.js +252 -0
- package/dist/exchanges/aster-nonce.d.ts +2 -0
- package/dist/exchanges/aster-nonce.js +107 -0
- package/dist/exchanges/aster-spot.d.ts +117 -0
- package/dist/exchanges/aster-spot.js +686 -0
- package/dist/exchanges/aster-typed-data.d.ts +133 -7
- package/dist/exchanges/aster-typed-data.js +121 -7
- package/dist/exchanges/aster.d.ts +219 -6
- package/dist/exchanges/aster.js +1023 -153
- package/dist/exchanges/builder-fee.d.ts +254 -0
- package/dist/exchanges/builder-fee.js +421 -0
- package/dist/exchanges/canonical-symbols.d.ts +32 -0
- package/dist/exchanges/canonical-symbols.js +96 -0
- package/dist/exchanges/capabilities.d.ts +7 -1
- package/dist/exchanges/capabilities.js +7 -0
- package/dist/exchanges/hl-signing.d.ts +165 -0
- package/dist/exchanges/hl-signing.js +158 -0
- package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
- package/dist/exchanges/hyperliquid-outcome.js +646 -0
- package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
- package/dist/exchanges/hyperliquid-spot.js +308 -117
- package/dist/exchanges/hyperliquid.d.ts +462 -57
- package/dist/exchanges/hyperliquid.js +1575 -449
- package/dist/exchanges/index.d.ts +6 -0
- package/dist/exchanges/index.js +4 -0
- package/dist/exchanges/interface.d.ts +63 -10
- package/dist/exchanges/interface.js +18 -3
- package/dist/exchanges/ioc-outcome.d.ts +44 -0
- package/dist/exchanges/ioc-outcome.js +57 -0
- package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
- package/dist/exchanges/legacy-trading-v2.js +940 -0
- package/dist/exchanges/lighter-public.d.ts +43 -0
- package/dist/exchanges/lighter-public.js +276 -0
- package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
- package/dist/exchanges/lighter-rh-deposit.js +185 -0
- package/dist/exchanges/lighter-signer.d.ts +123 -0
- package/dist/exchanges/lighter-signer.js +215 -0
- package/dist/exchanges/lighter-spot.d.ts +91 -13
- package/dist/exchanges/lighter-spot.js +595 -233
- package/dist/exchanges/lighter.d.ts +611 -39
- package/dist/exchanges/lighter.js +1890 -649
- package/dist/exchanges/ondo/adapter.d.ts +166 -0
- package/dist/exchanges/ondo/adapter.js +835 -0
- package/dist/exchanges/ondo/agent.d.ts +31 -0
- package/dist/exchanges/ondo/agent.js +101 -0
- package/dist/exchanges/ondo/client.d.ts +60 -0
- package/dist/exchanges/ondo/client.js +297 -0
- package/dist/exchanges/ondo/funds.d.ts +122 -0
- package/dist/exchanges/ondo/funds.js +290 -0
- package/dist/exchanges/ondo/public.d.ts +95 -0
- package/dist/exchanges/ondo/public.js +214 -0
- package/dist/exchanges/ondo/spot.d.ts +127 -0
- package/dist/exchanges/ondo/spot.js +392 -0
- package/dist/exchanges/outcome-interface.d.ts +140 -0
- package/dist/exchanges/outcome-interface.js +16 -0
- package/dist/exchanges/pacifica-spot.d.ts +83 -0
- package/dist/exchanges/pacifica-spot.js +324 -0
- package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
- package/dist/exchanges/pacifica-typed-data.js +57 -9
- package/dist/exchanges/pacifica.d.ts +288 -4
- package/dist/exchanges/pacifica.js +1013 -76
- package/dist/exchanges/precision.d.ts +47 -0
- package/dist/exchanges/precision.js +209 -0
- package/dist/exchanges/qfex/adapter.d.ts +341 -0
- package/dist/exchanges/qfex/adapter.js +1383 -0
- package/dist/exchanges/qfex/agent.d.ts +58 -0
- package/dist/exchanges/qfex/agent.js +188 -0
- package/dist/exchanges/qfex/client.d.ts +54 -0
- package/dist/exchanges/qfex/client.js +138 -0
- package/dist/exchanges/qfex/errors.d.ts +70 -0
- package/dist/exchanges/qfex/errors.js +236 -0
- package/dist/exchanges/qfex/public.d.ts +122 -0
- package/dist/exchanges/qfex/public.js +268 -0
- package/dist/exchanges/qfex/signing.d.ts +160 -0
- package/dist/exchanges/qfex/signing.js +283 -0
- package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
- package/dist/exchanges/qfex/ws-transport.js +798 -0
- package/dist/exchanges/rate-limiter.d.ts +12 -0
- package/dist/exchanges/rate-limiter.js +64 -0
- package/dist/exchanges/registry.d.ts +14 -2
- package/dist/exchanges/registry.js +20 -32
- package/dist/exchanges/slippage.d.ts +37 -0
- package/dist/exchanges/slippage.js +70 -0
- package/dist/exchanges/spot-factory.d.ts +166 -0
- package/dist/exchanges/spot-factory.js +431 -0
- package/dist/exchanges/spot-interface.d.ts +98 -4
- package/dist/exchanges/spot-interface.js +27 -1
- package/dist/exchanges/spot-result.d.ts +79 -0
- package/dist/exchanges/spot-result.js +273 -0
- package/dist/exchanges/trading-v2.d.ts +117 -0
- package/dist/exchanges/trading-v2.js +301 -0
- package/dist/exchanges/venue-types.d.ts +231 -0
- package/dist/exchanges/venue-types.js +87 -0
- package/dist/exchanges/venue.d.ts +211 -0
- package/dist/exchanges/venue.js +132 -0
- package/dist/exchanges/venues/arcus.d.ts +8 -0
- package/dist/exchanges/venues/arcus.js +109 -0
- package/dist/exchanges/venues/aster.d.ts +49 -0
- package/dist/exchanges/venues/aster.js +176 -0
- package/dist/exchanges/venues/create-helpers.d.ts +18 -0
- package/dist/exchanges/venues/create-helpers.js +199 -0
- package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
- package/dist/exchanges/venues/hyperliquid.js +126 -0
- package/dist/exchanges/venues/index.d.ts +16 -0
- package/dist/exchanges/venues/index.js +26 -0
- package/dist/exchanges/venues/lighter-family.d.ts +92 -0
- package/dist/exchanges/venues/lighter-family.js +166 -0
- package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
- package/dist/exchanges/venues/lighter-rh.js +58 -0
- package/dist/exchanges/venues/lighter.d.ts +6 -0
- package/dist/exchanges/venues/lighter.js +55 -0
- package/dist/exchanges/venues/ondo.d.ts +34 -0
- package/dist/exchanges/venues/ondo.js +140 -0
- package/dist/exchanges/venues/pacifica.d.ts +8 -0
- package/dist/exchanges/venues/pacifica.js +95 -0
- package/dist/exchanges/venues/qfex.d.ts +28 -0
- package/dist/exchanges/venues/qfex.js +132 -0
- package/dist/execution-log.js +10 -2
- package/dist/funding/legacy-public.d.ts +31 -0
- package/dist/funding/legacy-public.js +369 -0
- package/dist/funding/normalize.d.ts +28 -16
- package/dist/funding/normalize.js +61 -29
- package/dist/funding/rates.d.ts +46 -11
- package/dist/funding/rates.js +228 -277
- package/dist/guardrail/perp-guardrail.js +0 -0
- package/dist/index.js +156 -684
- package/dist/jobs.d.ts +84 -6
- package/dist/jobs.js +239 -41
- package/dist/landing.d.ts +7 -2
- package/dist/landing.js +19 -3
- package/dist/mcp-server.d.ts +14 -4
- package/dist/mcp-server.js +820 -402
- package/dist/mcp-trade-guard.d.ts +16 -0
- package/dist/mcp-trade-guard.js +59 -0
- package/dist/pacifica/client.d.ts +41 -10
- package/dist/pacifica/client.js +167 -63
- package/dist/pacifica/constants.d.ts +0 -1
- package/dist/pacifica/constants.js +0 -5
- package/dist/pacifica/deposit.d.ts +30 -3
- package/dist/pacifica/deposit.js +119 -2
- package/dist/pacifica/faucet.d.ts +29 -0
- package/dist/pacifica/faucet.js +100 -0
- package/dist/pacifica/sign-tx.d.ts +15 -0
- package/dist/pacifica/sign-tx.js +41 -0
- package/dist/pacifica/types/account.d.ts +28 -4
- package/dist/pacifica/types/lake.d.ts +20 -5
- package/dist/pacifica/types/lake.js +4 -0
- package/dist/pacifica/types/market.d.ts +5 -0
- package/dist/pacifica/types/order.d.ts +4 -1
- package/dist/pacifica/types/position.d.ts +9 -1
- package/dist/plan-executor.d.ts +10 -5
- package/dist/plan-executor.js +165 -54
- package/dist/position-history.js +13 -0
- package/dist/rebalance.d.ts +26 -2
- package/dist/rebalance.js +86 -7
- package/dist/relay-swap.d.ts +232 -0
- package/dist/relay-swap.js +630 -0
- package/dist/risk.js +5 -1
- package/dist/secret-env.d.ts +15 -0
- package/dist/secret-env.js +36 -0
- package/dist/settings.d.ts +169 -6
- package/dist/settings.js +219 -38
- package/dist/signer/ows-evm.d.ts +13 -0
- package/dist/signer/ows-evm.js +22 -0
- package/dist/smart-order.d.ts +9 -0
- package/dist/smart-order.js +53 -8
- package/dist/strategies/dca.d.ts +6 -2
- package/dist/strategies/dca.js +66 -26
- package/dist/strategies/funding-arb.d.ts +11 -1
- package/dist/strategies/funding-arb.js +202 -89
- package/dist/strategies/grid.d.ts +31 -0
- package/dist/strategies/grid.js +89 -11
- package/dist/strategies/pending-stop.d.ts +8 -0
- package/dist/strategies/pending-stop.js +12 -0
- package/dist/strategies/split-order.d.ts +45 -17
- package/dist/strategies/split-order.js +157 -91
- package/dist/strategies/trailing-stop.d.ts +2 -1
- package/dist/strategies/trailing-stop.js +52 -6
- package/dist/strategies/twap.d.ts +6 -1
- package/dist/strategies/twap.js +39 -11
- package/dist/trade-validator.d.ts +22 -0
- package/dist/trade-validator.js +119 -15
- package/dist/utils/numeric.d.ts +46 -0
- package/dist/utils/numeric.js +79 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +96 -19
- package/dist/withdraw-gate.d.ts +49 -0
- package/dist/withdraw-gate.js +131 -0
- package/package.json +15 -6
- package/skills/perp-cli/SKILL.md +142 -55
- package/skills/perp-cli/references/agent-operations.md +110 -56
- package/skills/perp-cli/references/commands.md +266 -71
- package/skills/perp-cli/references/strategies.md +34 -31
- package/skills/perp-cli/scripts/arb-monitor.sh +10 -5
- package/skills/perp-cli/scripts/funding-analysis.sh +14 -9
- package/skills/perp-cli/scripts/preflight.sh +21 -14
- package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
- package/skills/perp-cli/scripts/validate-arb.sh +31 -15
- package/vendor/lighter-signer/SHA256SUMS +2 -0
- package/vendor/lighter-signer/VERSION +8 -0
- package/vendor/lighter-signer/lighter-signer.wasm +0 -0
- package/vendor/lighter-signer/wasm_exec.js +575 -0
- package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
- package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
package/dist/pacifica/deposit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction, Transaction, } from "@solana/web3.js";
|
|
2
2
|
import { getNetworkConfig, USDC_DECIMALS } from "./constants.js";
|
|
3
|
+
import { PerpError } from "../errors.js";
|
|
3
4
|
const TOKEN_PROGRAM = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
4
5
|
const ASSOCIATED_TOKEN_PROGRAM = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
5
6
|
const SYSTEM_PROGRAM = new PublicKey("11111111111111111111111111111111");
|
|
@@ -30,7 +31,8 @@ function getEventAuthority(programId) {
|
|
|
30
31
|
* Build a Pacifica deposit instruction.
|
|
31
32
|
*
|
|
32
33
|
* @param userPubkey - User's wallet public key
|
|
33
|
-
* @param amount - Amount in USDC (e.g
|
|
34
|
+
* @param amount - Amount in USDC as a plain decimal string with at most 6 decimals (e.g. "100", "99.5");
|
|
35
|
+
* scaled exactly (no float math). Anything else → INVALID_PARAMS.
|
|
34
36
|
* @param network - mainnet or testnet
|
|
35
37
|
*/
|
|
36
38
|
export async function buildDepositInstruction(userPubkey, amount, network = "mainnet") {
|
|
@@ -43,7 +45,12 @@ export async function buildDepositInstruction(userPubkey, amount, network = "mai
|
|
|
43
45
|
const eventAuthority = getEventAuthority(programId);
|
|
44
46
|
// Build instruction data: discriminator + amount (u64 LE)
|
|
45
47
|
const discriminator = await getDepositDiscriminator();
|
|
46
|
-
const amountLamports =
|
|
48
|
+
const amountLamports = usdcUnits(amount);
|
|
49
|
+
if (amountLamports === null || amountLamports <= 0n) {
|
|
50
|
+
throw new PerpError("INVALID_PARAMS", `Pacifica deposit amount "${amount}" is not a positive USDC amount with at most ${USDC_DECIMALS} decimals; nothing was built`, {
|
|
51
|
+
exchange: "pacifica", remediation: `Pass a plain decimal with at most ${USDC_DECIMALS} decimals, e.g. 100 or 99.5`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
47
54
|
const amountBytes = new Uint8Array(8);
|
|
48
55
|
const view = new DataView(amountBytes.buffer);
|
|
49
56
|
view.setBigUint64(0, amountLamports, true); // little-endian
|
|
@@ -76,3 +83,113 @@ export async function deposit(connection, userPubkey, amount, signTransaction, n
|
|
|
76
83
|
const signed = await signTransaction(tx);
|
|
77
84
|
return connection.sendRawTransaction(signed.serialize());
|
|
78
85
|
}
|
|
86
|
+
const COMPUTE_BUDGET_PROGRAM = new PublicKey("ComputeBudget111111111111111111111111111111");
|
|
87
|
+
/** Highest relayer fee (USDC) the CLI signs for a relayed deposit. Above it the transaction is refused. */
|
|
88
|
+
export const PACIFICA_RELAY_FEE_CAP_USDC = 1;
|
|
89
|
+
/** Decimal USDC string → integer base units (6 decimals), exact; null when not a plain decimal with ≤ 6 decimals. */
|
|
90
|
+
function usdcUnits(amount) {
|
|
91
|
+
const m = /^(\d+)(?:\.(\d{1,6}))?$/.exec(amount.trim());
|
|
92
|
+
if (m === null)
|
|
93
|
+
return null;
|
|
94
|
+
return BigInt(m[1]) * 10n ** BigInt(USDC_DECIMALS) + BigInt((m[2] ?? "").padEnd(USDC_DECIMALS, "0"));
|
|
95
|
+
}
|
|
96
|
+
function readU64LE(data, offset) {
|
|
97
|
+
if (data.length < offset + 8)
|
|
98
|
+
return null;
|
|
99
|
+
return new DataView(data.buffer, data.byteOffset + offset, 8).getBigUint64(0, true);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Verify a RELAYER-BUILT transaction before the master Solana key signs it. The relayer is an
|
|
103
|
+
* untrusted HTTP service (PERP_RELAYER_URL): whatever it returns is signed only when it is
|
|
104
|
+
* exactly
|
|
105
|
+
* - ONE pinned Pacifica deposit instruction — the program id, every account (user, user USDC
|
|
106
|
+
* ATA, central state, vault, mint, …, in order, same signer / writable flags) and the data
|
|
107
|
+
* `buildDepositInstruction` would produce for `declared.netAmount`;
|
|
108
|
+
* - any number of ComputeBudget instructions (they move no funds);
|
|
109
|
+
* - at most ONE relayer fee transfer: an SPL Token Transfer / TransferChecked of exactly
|
|
110
|
+
* `declared.fee` USDC from the user's USDC account, authority = user, to the token account the
|
|
111
|
+
* build response declared (`feeRecipient`), with fee ≤ PACIFICA_RELAY_FEE_CAP_USDC;
|
|
112
|
+
* and fee + netAmount equals the amount the user asked to deposit, and the fee payer is not the
|
|
113
|
+
* user (the relayer sponsors gas). Anything else → POLICY_DENIED, nothing is signed.
|
|
114
|
+
*/
|
|
115
|
+
export async function assertRelayedDepositTransaction(tx, ctx) {
|
|
116
|
+
const refuse = (why) => new PerpError("POLICY_DENIED", `Refusing to sign the relayer-built Pacifica deposit: ${why}. Nothing was signed`, {
|
|
117
|
+
exchange: "pacifica", remediation: "Drop --relay for a direct deposit (you pay gas, ~0.005 SOL)",
|
|
118
|
+
});
|
|
119
|
+
const { user, declared } = ctx;
|
|
120
|
+
const requested = usdcUnits(ctx.requestedAmount);
|
|
121
|
+
if (requested === null || requested <= 0n)
|
|
122
|
+
throw refuse(`the requested amount "${ctx.requestedAmount}" is not a USDC amount with at most ${USDC_DECIMALS} decimals`);
|
|
123
|
+
if (!Number.isFinite(declared.fee) || !Number.isFinite(declared.netAmount) || declared.fee < 0 || declared.netAmount <= 0) {
|
|
124
|
+
throw refuse(`the build response declares fee ${declared.fee} / netAmount ${declared.netAmount}`);
|
|
125
|
+
}
|
|
126
|
+
const feeUnits = BigInt(Math.round(declared.fee * 10 ** USDC_DECIMALS));
|
|
127
|
+
const netUnits = BigInt(Math.round(declared.netAmount * 10 ** USDC_DECIMALS));
|
|
128
|
+
if (feeUnits + netUnits !== requested)
|
|
129
|
+
throw refuse(`declared fee ${declared.fee} + netAmount ${declared.netAmount} is not the requested ${ctx.requestedAmount} USDC`);
|
|
130
|
+
if (declared.fee > PACIFICA_RELAY_FEE_CAP_USDC)
|
|
131
|
+
throw refuse(`the relayer fee ${declared.fee} USDC is above the cap of ${PACIFICA_RELAY_FEE_CAP_USDC} USDC`);
|
|
132
|
+
if (tx.feePayer === undefined || tx.feePayer === null || tx.feePayer.equals(user))
|
|
133
|
+
throw refuse("the fee payer is not the relayer (a sponsored deposit never makes the user pay gas)");
|
|
134
|
+
const config = getNetworkConfig(ctx.network);
|
|
135
|
+
const usdcMint = new PublicKey(config.usdcMint);
|
|
136
|
+
const userAta = getATA(user, usdcMint);
|
|
137
|
+
const netDecimal = `${netUnits / 10n ** BigInt(USDC_DECIMALS)}.${(netUnits % 10n ** BigInt(USDC_DECIMALS)).toString().padStart(USDC_DECIMALS, "0")}`;
|
|
138
|
+
const expected = await buildDepositInstruction(user, netDecimal, ctx.network);
|
|
139
|
+
let deposits = 0;
|
|
140
|
+
let feeTransfers = 0;
|
|
141
|
+
for (const [i, ix] of tx.instructions.entries()) {
|
|
142
|
+
const at = `instruction ${i} (${ix.programId.toBase58()})`;
|
|
143
|
+
if (ix.programId.equals(COMPUTE_BUDGET_PROGRAM)) {
|
|
144
|
+
if (ix.keys.length !== 0)
|
|
145
|
+
throw refuse(`${at}: a compute-budget instruction with accounts`);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (ix.programId.equals(expected.programId)) {
|
|
149
|
+
const sameKeys = ix.keys.length === expected.keys.length && ix.keys.every((k, j) => k.pubkey.equals(expected.keys[j].pubkey) && k.isSigner === expected.keys[j].isSigner && k.isWritable === expected.keys[j].isWritable);
|
|
150
|
+
if (!sameKeys)
|
|
151
|
+
throw refuse(`${at}: the deposit accounts are not the pinned user / vault / mint accounts`);
|
|
152
|
+
if (!Buffer.from(ix.data).equals(Buffer.from(expected.data)))
|
|
153
|
+
throw refuse(`${at}: the deposit data is not "deposit ${declared.netAmount} USDC"`);
|
|
154
|
+
deposits++;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (ix.programId.equals(TOKEN_PROGRAM)) {
|
|
158
|
+
// SPL Token Transfer (3): [source, destination, authority]; TransferChecked (12): [source, mint, destination, authority].
|
|
159
|
+
const tag = ix.data[0];
|
|
160
|
+
const checked = tag === 12;
|
|
161
|
+
if (tag !== 3 && !checked)
|
|
162
|
+
throw refuse(`${at}: an SPL token instruction that is not a transfer`);
|
|
163
|
+
if (ix.data.length !== (checked ? 10 : 9) || ix.keys.length !== (checked ? 4 : 3))
|
|
164
|
+
throw refuse(`${at}: a malformed token transfer`);
|
|
165
|
+
const [source, dest, authority] = checked ? [ix.keys[0], ix.keys[2], ix.keys[3]] : [ix.keys[0], ix.keys[1], ix.keys[2]];
|
|
166
|
+
if (checked && (!ix.keys[1].pubkey.equals(usdcMint) || ix.data[9] !== USDC_DECIMALS))
|
|
167
|
+
throw refuse(`${at}: the fee transfer is not in the deposit token`);
|
|
168
|
+
if (!source.pubkey.equals(userAta) || !authority.pubkey.equals(user))
|
|
169
|
+
throw refuse(`${at}: the token transfer is not from the user's own USDC account`);
|
|
170
|
+
if (declared.feeRecipient === null)
|
|
171
|
+
throw refuse(`${at}: a fee transfer the build response did not declare (no feeRecipient)`);
|
|
172
|
+
let recipient;
|
|
173
|
+
try {
|
|
174
|
+
recipient = new PublicKey(declared.feeRecipient);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
throw refuse(`the declared feeRecipient "${declared.feeRecipient}" is not a Solana address`);
|
|
178
|
+
}
|
|
179
|
+
if (!dest.pubkey.equals(recipient))
|
|
180
|
+
throw refuse(`${at}: the fee transfer goes to ${dest.pubkey.toBase58()}, not the declared ${recipient.toBase58()}`);
|
|
181
|
+
if (readU64LE(ix.data, 1) !== feeUnits)
|
|
182
|
+
throw refuse(`${at}: the fee transfer amount is not the declared ${declared.fee} USDC`);
|
|
183
|
+
if (++feeTransfers > 1)
|
|
184
|
+
throw refuse("more than one fee transfer");
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
throw refuse(`${at} is not a Pacifica deposit, a compute-budget instruction or the declared fee transfer`);
|
|
188
|
+
}
|
|
189
|
+
if (deposits !== 1)
|
|
190
|
+
throw refuse(`it contains ${deposits} Pacifica deposit instructions (exactly one expected)`);
|
|
191
|
+
if (feeUnits > 0n && feeTransfers !== 1)
|
|
192
|
+
throw refuse(`the declared fee ${declared.fee} USDC is not transferred by the transaction`);
|
|
193
|
+
if (feeUnits === 0n && feeTransfers !== 0)
|
|
194
|
+
throw refuse("a fee transfer although the declared fee is 0");
|
|
195
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import type { SolanaSigner } from "../signer/index.js";
|
|
3
|
+
export declare const PACIFICA_DEVNET_RPC = "https://api.devnet.solana.com";
|
|
4
|
+
export declare const MINT_TEST_USDC_COMPUTE_UNITS = 400000;
|
|
5
|
+
/** sha256("global:mint_test_usdc")[:8]. */
|
|
6
|
+
export declare function mintTestUsdcDiscriminator(): Buffer;
|
|
7
|
+
/** Plain positive decimal with ≤ 6 decimals → base units (u64). */
|
|
8
|
+
export declare function testUsdcBaseUnits(amount: string): bigint;
|
|
9
|
+
export interface MintTestUsdcPlan {
|
|
10
|
+
user: string;
|
|
11
|
+
userAccountPda: string;
|
|
12
|
+
userAta: string;
|
|
13
|
+
mint: string;
|
|
14
|
+
centralState: string;
|
|
15
|
+
programId: string;
|
|
16
|
+
amount: string;
|
|
17
|
+
baseUnits: string;
|
|
18
|
+
}
|
|
19
|
+
/** Accounts + amount the faucet instruction uses (pure; used for --dry-run). */
|
|
20
|
+
export declare function mintTestUsdcPlan(user: PublicKey, amount: string): MintTestUsdcPlan;
|
|
21
|
+
export declare function buildMintTestUsdcInstruction(plan: MintTestUsdcPlan): TransactionInstruction;
|
|
22
|
+
/**
|
|
23
|
+
* Build, sign, SIMULATE, then send + confirm the faucet transaction. A simulation
|
|
24
|
+
* error throws EXCHANGE_ERROR (with the program logs) and nothing is sent.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mintTestUsdc(connection: Connection, signer: SolanaSigner, amount: string): Promise<{
|
|
27
|
+
signature: string;
|
|
28
|
+
plan: MintTestUsdcPlan;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pacifica TESTNET (Solana devnet) test-USDP faucet — Anchor `mint_test_usdc`.
|
|
3
|
+
*
|
|
4
|
+
* Testnet tooling only: the instruction exists on the devnet program
|
|
5
|
+
* (TESTNET_PROGRAM_ID); there is no mainnet equivalent and callers refuse
|
|
6
|
+
* mainnet before building anything.
|
|
7
|
+
*
|
|
8
|
+
* Instruction (verified on devnet 2026-10-02 with a simulated + sent tx):
|
|
9
|
+
* data = sha256("global:mint_test_usdc")[:8] (76904e769bd6b9ba) ‖ u64 LE amount × 1e6
|
|
10
|
+
* accounts = user (signer, writable), PDA(["user_account", user], program) (writable),
|
|
11
|
+
* user USDP ATA (writable), USDP mint (writable), central_state (read-only —
|
|
12
|
+
* the verified tx sent it read-only), ATA program, token program, system program
|
|
13
|
+
* + ComputeBudget setComputeUnitLimit(400_000).
|
|
14
|
+
* The transaction is always simulated before it is sent; a failed simulation sends nothing.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction, TransactionInstruction, } from "@solana/web3.js";
|
|
18
|
+
import { PerpError } from "../errors.js";
|
|
19
|
+
import { getNetworkConfig, USDC_DECIMALS } from "./constants.js";
|
|
20
|
+
import { signSolanaTransaction } from "./sign-tx.js";
|
|
21
|
+
const TOKEN_PROGRAM = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
22
|
+
const ASSOCIATED_TOKEN_PROGRAM = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
23
|
+
export const PACIFICA_DEVNET_RPC = "https://api.devnet.solana.com";
|
|
24
|
+
export const MINT_TEST_USDC_COMPUTE_UNITS = 400_000;
|
|
25
|
+
/** sha256("global:mint_test_usdc")[:8]. */
|
|
26
|
+
export function mintTestUsdcDiscriminator() {
|
|
27
|
+
return createHash("sha256").update("global:mint_test_usdc").digest().subarray(0, 8);
|
|
28
|
+
}
|
|
29
|
+
/** Plain positive decimal with ≤ 6 decimals → base units (u64). */
|
|
30
|
+
export function testUsdcBaseUnits(amount) {
|
|
31
|
+
if (!/^\d+(\.\d{1,6})?$/.test(amount)) {
|
|
32
|
+
throw new PerpError("INVALID_PARAMS", `Faucet amount must be a plain decimal with at most ${USDC_DECIMALS} decimals (got "${amount}")`);
|
|
33
|
+
}
|
|
34
|
+
const [ip, fp = ""] = amount.split(".");
|
|
35
|
+
const units = BigInt(ip) * 10n ** BigInt(USDC_DECIMALS) + BigInt(fp.padEnd(USDC_DECIMALS, "0"));
|
|
36
|
+
if (units <= 0n)
|
|
37
|
+
throw new PerpError("INVALID_PARAMS", `Faucet amount must be positive (got "${amount}")`);
|
|
38
|
+
if (units > 0xffffffffffffffffn)
|
|
39
|
+
throw new PerpError("INVALID_PARAMS", `Faucet amount ${amount} overflows u64`);
|
|
40
|
+
return units;
|
|
41
|
+
}
|
|
42
|
+
/** Accounts + amount the faucet instruction uses (pure; used for --dry-run). */
|
|
43
|
+
export function mintTestUsdcPlan(user, amount) {
|
|
44
|
+
const cfg = getNetworkConfig("testnet");
|
|
45
|
+
const program = new PublicKey(cfg.programId);
|
|
46
|
+
const mint = new PublicKey(cfg.usdcMint);
|
|
47
|
+
const [userAccountPda] = PublicKey.findProgramAddressSync([Buffer.from("user_account"), user.toBuffer()], program);
|
|
48
|
+
const [userAta] = PublicKey.findProgramAddressSync([user.toBuffer(), TOKEN_PROGRAM.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM);
|
|
49
|
+
return {
|
|
50
|
+
user: user.toBase58(),
|
|
51
|
+
userAccountPda: userAccountPda.toBase58(),
|
|
52
|
+
userAta: userAta.toBase58(),
|
|
53
|
+
mint: mint.toBase58(),
|
|
54
|
+
centralState: cfg.centralState,
|
|
55
|
+
programId: cfg.programId,
|
|
56
|
+
amount,
|
|
57
|
+
baseUnits: testUsdcBaseUnits(amount).toString(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function buildMintTestUsdcInstruction(plan) {
|
|
61
|
+
const amt = Buffer.alloc(8);
|
|
62
|
+
amt.writeBigUInt64LE(BigInt(plan.baseUnits));
|
|
63
|
+
return new TransactionInstruction({
|
|
64
|
+
programId: new PublicKey(plan.programId),
|
|
65
|
+
data: Buffer.concat([mintTestUsdcDiscriminator(), amt]),
|
|
66
|
+
keys: [
|
|
67
|
+
{ pubkey: new PublicKey(plan.user), isSigner: true, isWritable: true },
|
|
68
|
+
{ pubkey: new PublicKey(plan.userAccountPda), isSigner: false, isWritable: true },
|
|
69
|
+
{ pubkey: new PublicKey(plan.userAta), isSigner: false, isWritable: true },
|
|
70
|
+
{ pubkey: new PublicKey(plan.mint), isSigner: false, isWritable: true },
|
|
71
|
+
{ pubkey: new PublicKey(plan.centralState), isSigner: false, isWritable: false },
|
|
72
|
+
{ pubkey: ASSOCIATED_TOKEN_PROGRAM, isSigner: false, isWritable: false },
|
|
73
|
+
{ pubkey: TOKEN_PROGRAM, isSigner: false, isWritable: false },
|
|
74
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build, sign, SIMULATE, then send + confirm the faucet transaction. A simulation
|
|
80
|
+
* error throws EXCHANGE_ERROR (with the program logs) and nothing is sent.
|
|
81
|
+
*/
|
|
82
|
+
export async function mintTestUsdc(connection, signer, amount) {
|
|
83
|
+
const user = new PublicKey(signer.getPublicKeyBase58());
|
|
84
|
+
const plan = mintTestUsdcPlan(user, amount);
|
|
85
|
+
const tx = new Transaction().add(ComputeBudgetProgram.setComputeUnitLimit({ units: MINT_TEST_USDC_COMPUTE_UNITS }), buildMintTestUsdcInstruction(plan));
|
|
86
|
+
tx.feePayer = user;
|
|
87
|
+
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
88
|
+
signSolanaTransaction(signer, tx, false);
|
|
89
|
+
const sim = await connection.simulateTransaction(tx);
|
|
90
|
+
if (sim.value.err !== null) {
|
|
91
|
+
throw new PerpError("EXCHANGE_ERROR", `Pacifica testnet faucet simulation failed: ${JSON.stringify(sim.value.err)} — nothing was sent`, {
|
|
92
|
+
exchange: "pacifica",
|
|
93
|
+
logs: (sim.value.logs ?? []).slice(-8),
|
|
94
|
+
remediation: "Check the wallet has devnet SOL for fees (solana airdrop) and retry with a smaller amount",
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const signature = await connection.sendRawTransaction(tx.serialize());
|
|
98
|
+
await connection.confirmTransaction(signature, "confirmed");
|
|
99
|
+
return { signature, plan };
|
|
100
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign a Solana transaction with any SolanaSigner (local keypair or OWS vault).
|
|
3
|
+
*
|
|
4
|
+
* OWS never exposes a raw keypair, so `tx.sign(keypair)` cannot be used for vault
|
|
5
|
+
* wallets: the serialized transaction is signed through OWS and the signature is
|
|
6
|
+
* attached with `addSignature`. The signature is always verified locally before
|
|
7
|
+
* the caller sends anything.
|
|
8
|
+
*/
|
|
9
|
+
import { type Transaction } from "@solana/web3.js";
|
|
10
|
+
import type { SolanaSigner } from "../signer/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Add `signer`'s signature to `tx`. `partial` = other signatures (e.g. a relayer fee
|
|
13
|
+
* payer) are still missing; otherwise every required signature must be present.
|
|
14
|
+
*/
|
|
15
|
+
export declare function signSolanaTransaction(signer: SolanaSigner, tx: Transaction, partial: boolean): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign a Solana transaction with any SolanaSigner (local keypair or OWS vault).
|
|
3
|
+
*
|
|
4
|
+
* OWS never exposes a raw keypair, so `tx.sign(keypair)` cannot be used for vault
|
|
5
|
+
* wallets: the serialized transaction is signed through OWS and the signature is
|
|
6
|
+
* attached with `addSignature`. The signature is always verified locally before
|
|
7
|
+
* the caller sends anything.
|
|
8
|
+
*/
|
|
9
|
+
import { PublicKey } from "@solana/web3.js";
|
|
10
|
+
import { PerpError } from "../errors.js";
|
|
11
|
+
import { LocalSolanaSigner } from "../signer/index.js";
|
|
12
|
+
function hasBytesSigner(s) {
|
|
13
|
+
return typeof s.signTransactionBytes === "function";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Add `signer`'s signature to `tx`. `partial` = other signatures (e.g. a relayer fee
|
|
17
|
+
* payer) are still missing; otherwise every required signature must be present.
|
|
18
|
+
*/
|
|
19
|
+
export function signSolanaTransaction(signer, tx, partial) {
|
|
20
|
+
const pubkey = new PublicKey(signer.getPublicKeyBase58());
|
|
21
|
+
if (signer instanceof LocalSolanaSigner) {
|
|
22
|
+
if (partial)
|
|
23
|
+
signer.partialSignTransaction(tx);
|
|
24
|
+
else
|
|
25
|
+
signer.signTransaction(tx);
|
|
26
|
+
}
|
|
27
|
+
else if (hasBytesSigner(signer)) {
|
|
28
|
+
const bytes = tx.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
29
|
+
tx.addSignature(pubkey, Buffer.from(signer.signTransactionBytes(bytes)));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new PerpError("NO_SIGNER_AVAILABLE", "This Solana signer cannot sign transactions", {
|
|
33
|
+
remediation: "Use an OWS vault wallet or a local key for on-chain Pacifica actions",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!tx.verifySignatures(!partial)) {
|
|
37
|
+
throw new PerpError("SIGNATURE_FAILED", `Solana transaction signature from ${pubkey.toBase58()} did not verify — nothing was sent`, {
|
|
38
|
+
remediation: "Check the wallet; the transaction was not submitted",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -14,19 +14,43 @@ export interface AccountInfo {
|
|
|
14
14
|
orders_count: number;
|
|
15
15
|
stop_orders_count: number;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* One `margin_settings` entry of GET /account/settings (docs.pacifica.fi
|
|
19
|
+
* api-documentation/api/rest-api/account/get-account-settings): `isolated` = "If the account is set
|
|
20
|
+
* to isolated margining for this symbol", `leverage` = "Current leverage set by the user (default to max)".
|
|
21
|
+
*/
|
|
22
|
+
export interface AccountMarginSetting {
|
|
18
23
|
symbol: string;
|
|
19
|
-
|
|
24
|
+
isolated: boolean;
|
|
20
25
|
leverage: number;
|
|
26
|
+
created_at: number;
|
|
27
|
+
updated_at: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* GET /account/settings `data`. Only markets changed from their defaults are listed — docs: "Upon
|
|
31
|
+
* account creation, all markets have margin settings default to cross margin and leverage default
|
|
32
|
+
* to max. When querying this endpoint, all markets with default margin and leverage settings on
|
|
33
|
+
* this account will return blank."
|
|
34
|
+
*/
|
|
35
|
+
export interface AccountSettings {
|
|
36
|
+
auto_lend_disabled: boolean | null;
|
|
37
|
+
margin_settings: AccountMarginSetting[];
|
|
38
|
+
spot_settings?: Array<{
|
|
39
|
+
symbol: string;
|
|
40
|
+
unified_margin_excluded: boolean;
|
|
41
|
+
}>;
|
|
21
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* POST /account/subaccount/transfer. Docs (rest-api/subaccounts/subaccount-fund-transfer): the
|
|
45
|
+
* sender is the signing `account` ("Sender account address"); the signed payload is only
|
|
46
|
+
* `to_account` ("Recipient wallet address") and `amount` ("Transfer amount (in USDC)").
|
|
47
|
+
*/
|
|
22
48
|
export interface TransferFundsParams {
|
|
23
|
-
from_account: string;
|
|
24
49
|
to_account: string;
|
|
25
50
|
amount: string;
|
|
26
51
|
}
|
|
27
52
|
export interface WithdrawParams {
|
|
28
53
|
amount: string;
|
|
29
|
-
dest_address: string;
|
|
30
54
|
}
|
|
31
55
|
export interface UpdateLeverageParams {
|
|
32
56
|
symbol: string;
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault ("lake") request payloads — docs.pacifica.fi api-documentation/api/rest-api/vaults.
|
|
3
|
+
* Fields the docs mark optional are `T | null` here (null = not sent).
|
|
4
|
+
*/
|
|
5
|
+
/** POST /lake/create ("create_lake"): every payload field is optional per the docs. */
|
|
1
6
|
export interface CreateLakeParams {
|
|
2
|
-
|
|
3
|
-
|
|
7
|
+
/** "Manager address. Omit to create a fresh vault with no manager." */
|
|
8
|
+
manager: string | null;
|
|
9
|
+
/** "Display name for the vault" */
|
|
10
|
+
nickname: string | null;
|
|
11
|
+
/** "Seed deposit from the creator in the same request" (decimal string) */
|
|
12
|
+
initial_deposit: string | null;
|
|
4
13
|
}
|
|
14
|
+
/** POST /lake/deposit ("deposit_to_lake"). */
|
|
5
15
|
export interface LakeDepositParams {
|
|
6
|
-
|
|
16
|
+
/** "Vault address" */
|
|
17
|
+
lake: string;
|
|
18
|
+
/** "Deposit amount in USDC" */
|
|
7
19
|
amount: string;
|
|
8
20
|
}
|
|
21
|
+
/** POST /lake/withdraw ("withdraw_from_lake"). */
|
|
9
22
|
export interface LakeWithdrawParams {
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
/** "Vault address" */
|
|
24
|
+
lake: string;
|
|
25
|
+
/** "Number of shares to redeem" */
|
|
26
|
+
shares: string;
|
|
12
27
|
}
|
|
@@ -9,6 +9,11 @@ export interface MarketInfo {
|
|
|
9
9
|
volume_24h: string;
|
|
10
10
|
mark_price: string;
|
|
11
11
|
index_price: string;
|
|
12
|
+
/** "perpetual" | "spot" (live /info rows). */
|
|
13
|
+
instrument_type: string;
|
|
14
|
+
base_asset: string;
|
|
15
|
+
/** USD notional minimum. */
|
|
16
|
+
min_order_size: string;
|
|
12
17
|
}
|
|
13
18
|
export interface PriceInfo {
|
|
14
19
|
symbol: string;
|
|
@@ -26,6 +26,8 @@ export interface StopOrderParams {
|
|
|
26
26
|
amount: string;
|
|
27
27
|
limit_price?: string;
|
|
28
28
|
client_order_id?: string;
|
|
29
|
+
/** Trigger price source: "mark_price" (default) | "last_trade_price" | "mid_price". */
|
|
30
|
+
trigger_price_type?: string;
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
export interface EditOrderParams {
|
|
@@ -52,9 +54,10 @@ export interface TWAPParams {
|
|
|
52
54
|
duration_in_seconds: number;
|
|
53
55
|
client_order_id?: string;
|
|
54
56
|
}
|
|
57
|
+
/** POST /orders/twap/cancel — pacifica-fi/python-sdk rest/cancel_twap_order.py signs {symbol, order_id}. */
|
|
55
58
|
export interface CancelTWAPParams {
|
|
56
59
|
symbol: string;
|
|
57
|
-
|
|
60
|
+
order_id: number;
|
|
58
61
|
}
|
|
59
62
|
export interface TPSLParams {
|
|
60
63
|
symbol: string;
|
|
@@ -7,7 +7,15 @@ export interface Position {
|
|
|
7
7
|
mark_price: string;
|
|
8
8
|
liquidation_price: string;
|
|
9
9
|
unrealized_pnl: string;
|
|
10
|
+
/** Backing margin. The live spec names this `margin`; older payloads used
|
|
11
|
+
* `margin_used`. Both are read defensively. */
|
|
12
|
+
margin?: string;
|
|
10
13
|
margin_used: string;
|
|
11
|
-
leverage
|
|
14
|
+
/** Optional — the live /positions spec omits leverage; treat as possibly absent. */
|
|
15
|
+
leverage?: number;
|
|
16
|
+
/** True when the position is isolated-margin. Gates `margin`, which the spec
|
|
17
|
+
* documents as "only shown when isolated" — so leverage cannot be derived
|
|
18
|
+
* from margin on a cross position. */
|
|
19
|
+
isolated?: boolean;
|
|
12
20
|
created_at: number;
|
|
13
21
|
}
|
package/dist/plan-executor.d.ts
CHANGED
|
@@ -17,7 +17,12 @@ export interface ExecutionPlan {
|
|
|
17
17
|
export interface StepResult {
|
|
18
18
|
stepId: string;
|
|
19
19
|
action: PlanAction;
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* pending = an order step whose outcome is unknown (ORDER_PENDING): the plan stopped, the
|
|
22
|
+
* symbol is quarantined, the step is never rolled back. rollback_failed = a completed step
|
|
23
|
+
* whose reversal was rejected / unconfirmed / partial (symbol quarantined).
|
|
24
|
+
*/
|
|
25
|
+
status: "success" | "failed" | "skipped" | "rolled_back" | "cancelled" | "rollback_failed" | "pending" | "dry_run";
|
|
21
26
|
result?: unknown;
|
|
22
27
|
error?: {
|
|
23
28
|
code: string;
|
|
@@ -27,8 +32,11 @@ export interface StepResult {
|
|
|
27
32
|
}
|
|
28
33
|
export interface PlanResult {
|
|
29
34
|
planId: string;
|
|
30
|
-
|
|
35
|
+
/** pending = an order step's outcome is unknown; quarantined = a rollback left exposure (see `quarantined`). */
|
|
36
|
+
status: "completed" | "partial" | "failed" | "pending" | "quarantined" | "dry_run";
|
|
31
37
|
steps: StepResult[];
|
|
38
|
+
/** Symbols quarantined by this run (unknown order outcome or failed rollback). */
|
|
39
|
+
quarantined: string[];
|
|
32
40
|
totalDurationMs: number;
|
|
33
41
|
timestamp: string;
|
|
34
42
|
}
|
|
@@ -39,9 +47,6 @@ export declare function validatePlan(plan: unknown): {
|
|
|
39
47
|
valid: boolean;
|
|
40
48
|
errors: string[];
|
|
41
49
|
};
|
|
42
|
-
/**
|
|
43
|
-
* Execute a plan step by step.
|
|
44
|
-
*/
|
|
45
50
|
export declare function executePlan(adapter: ExchangeAdapter, plan: ExecutionPlan, opts?: {
|
|
46
51
|
dryRun?: boolean;
|
|
47
52
|
log?: (msg: string) => void;
|