perp-cli 0.12.17 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/README.md +247 -27
  2. package/dist/_stderr-filter.js +0 -1
  3. package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
  4. package/dist/agent-wallet/lighter-keystore.js +92 -10
  5. package/dist/agent-wallet/passphrase.d.ts +1 -1
  6. package/dist/agent-wallet/passphrase.js +16 -3
  7. package/dist/agent-wallet/store.d.ts +37 -4
  8. package/dist/agent-wallet/store.js +132 -0
  9. package/dist/agent-wallet/venue-keystore.d.ts +14 -0
  10. package/dist/agent-wallet/venue-keystore.js +121 -0
  11. package/dist/api/public/hyperliquid.js +4 -4
  12. package/dist/api/public/lighter.js +5 -5
  13. package/dist/api/public/pacifica.d.ts +0 -1
  14. package/dist/api/public/pacifica.js +4 -13
  15. package/dist/api/public/urls.d.ts +9 -1
  16. package/dist/api/public/urls.js +35 -13
  17. package/dist/arb/file-lock.d.ts +11 -0
  18. package/dist/arb/file-lock.js +74 -0
  19. package/dist/arb/index.d.ts +2 -2
  20. package/dist/arb/index.js +2 -2
  21. package/dist/arb/pending-entry.d.ts +32 -0
  22. package/dist/arb/pending-entry.js +77 -0
  23. package/dist/arb/sizing.d.ts +6 -13
  24. package/dist/arb/sizing.js +12 -51
  25. package/dist/arb/state.d.ts +45 -12
  26. package/dist/arb/state.js +214 -42
  27. package/dist/arb/utils.d.ts +20 -6
  28. package/dist/arb/utils.js +43 -39
  29. package/dist/bot/conditions.d.ts +4 -4
  30. package/dist/bot/conditions.js +11 -6
  31. package/dist/bot/config.d.ts +17 -1
  32. package/dist/bot/config.js +48 -12
  33. package/dist/bot/engine.d.ts +61 -2
  34. package/dist/bot/engine.js +610 -144
  35. package/dist/bot/fill-size.d.ts +7 -0
  36. package/dist/bot/fill-size.js +18 -0
  37. package/dist/bot/index.d.ts +1 -1
  38. package/dist/bot/index.js +1 -1
  39. package/dist/bot/perp-order.d.ts +99 -0
  40. package/dist/bot/perp-order.js +299 -0
  41. package/dist/bot/presets.d.ts +7 -0
  42. package/dist/bot/presets.js +17 -0
  43. package/dist/bot/quarantine.d.ts +75 -0
  44. package/dist/bot/quarantine.js +190 -0
  45. package/dist/bot/quote-rules.d.ts +23 -0
  46. package/dist/bot/quote-rules.js +69 -0
  47. package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
  48. package/dist/bot/strategies/avellaneda-mm.js +72 -70
  49. package/dist/bot/strategies/basis-arb.js +2 -0
  50. package/dist/bot/strategies/dca-strategy.d.ts +2 -0
  51. package/dist/bot/strategies/dca-strategy.js +5 -0
  52. package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
  53. package/dist/bot/strategies/funding-arb-strategy.js +571 -380
  54. package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
  55. package/dist/bot/strategies/funding-arb-utils.js +159 -195
  56. package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
  57. package/dist/bot/strategies/funding-arb-v2.js +258 -47
  58. package/dist/bot/strategies/funding-auto.js +215 -194
  59. package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
  60. package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
  61. package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
  62. package/dist/bot/strategies/spot-perp-executor.js +319 -120
  63. package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
  64. package/dist/bot/strategies/spot-perp-state.js +70 -0
  65. package/dist/bot/strategy-types.d.ts +6 -0
  66. package/dist/bot/tui/BotDashboard.d.ts +7 -2
  67. package/dist/bot/tui/BotDashboard.js +6 -3
  68. package/dist/bridge-engine.d.ts +120 -19
  69. package/dist/bridge-engine.js +710 -422
  70. package/dist/bridge-signers.d.ts +54 -0
  71. package/dist/bridge-signers.js +161 -0
  72. package/dist/cache.d.ts +4 -1
  73. package/dist/cache.js +11 -0
  74. package/dist/cli-flags.d.ts +50 -0
  75. package/dist/cli-flags.js +104 -0
  76. package/dist/cli-program.d.ts +35 -0
  77. package/dist/cli-program.js +303 -0
  78. package/dist/cli-spec.js +1 -1
  79. package/dist/client-id-tracker.js +11 -2
  80. package/dist/commands/account.d.ts +7 -1
  81. package/dist/commands/account.js +70 -92
  82. package/dist/commands/agent-import.d.ts +114 -0
  83. package/dist/commands/agent-import.js +794 -0
  84. package/dist/commands/agent.d.ts +232 -2
  85. package/dist/commands/agent.js +1858 -955
  86. package/dist/commands/alerts.d.ts +1 -0
  87. package/dist/commands/alerts.js +31 -28
  88. package/dist/commands/arb/index.d.ts +60 -1
  89. package/dist/commands/arb/index.js +381 -384
  90. package/dist/commands/arb-auto.d.ts +132 -4
  91. package/dist/commands/arb-auto.js +1474 -967
  92. package/dist/commands/arb.d.ts +3 -1
  93. package/dist/commands/arb.js +62 -30
  94. package/dist/commands/bot.js +127 -47
  95. package/dist/commands/bridge.d.ts +2 -1
  96. package/dist/commands/bridge.js +339 -192
  97. package/dist/commands/builder.d.ts +55 -0
  98. package/dist/commands/builder.js +387 -0
  99. package/dist/commands/funds-onchain.d.ts +32 -0
  100. package/dist/commands/funds-onchain.js +248 -0
  101. package/dist/commands/funds.d.ts +25 -0
  102. package/dist/commands/funds.js +925 -245
  103. package/dist/commands/history.js +102 -54
  104. package/dist/commands/init.d.ts +107 -15
  105. package/dist/commands/init.js +1116 -249
  106. package/dist/commands/jobs.d.ts +2 -1
  107. package/dist/commands/jobs.js +77 -15
  108. package/dist/commands/manage.js +136 -91
  109. package/dist/commands/market.d.ts +4 -1
  110. package/dist/commands/market.js +35 -32
  111. package/dist/commands/outcome.d.ts +10 -0
  112. package/dist/commands/outcome.js +396 -0
  113. package/dist/commands/plan.js +52 -12
  114. package/dist/commands/portfolio.d.ts +1 -0
  115. package/dist/commands/portfolio.js +60 -72
  116. package/dist/commands/rebalance.d.ts +2 -1
  117. package/dist/commands/rebalance.js +33 -43
  118. package/dist/commands/risk.js +46 -19
  119. package/dist/commands/settings.d.ts +1 -0
  120. package/dist/commands/settings.js +246 -51
  121. package/dist/commands/trade.d.ts +50 -0
  122. package/dist/commands/trade.js +1943 -695
  123. package/dist/commands/wallet.d.ts +30 -1
  124. package/dist/commands/wallet.js +357 -459
  125. package/dist/config.d.ts +60 -9
  126. package/dist/config.js +252 -82
  127. package/dist/constants.d.ts +29 -4
  128. package/dist/constants.js +62 -20
  129. package/dist/dashboard/server.d.ts +2 -0
  130. package/dist/dashboard/server.js +9 -6
  131. package/dist/dashboard/ui.js +6 -4
  132. package/dist/dashboard/ws-feeds.js +20 -8
  133. package/dist/dex-asset-map.js +5 -3
  134. package/dist/errors.d.ts +122 -0
  135. package/dist/errors.js +194 -0
  136. package/dist/event-stream.js +75 -19
  137. package/dist/evm-master-tx.d.ts +59 -0
  138. package/dist/evm-master-tx.js +154 -0
  139. package/dist/exchanges/adapter-network.d.ts +10 -0
  140. package/dist/exchanges/adapter-network.js +10 -0
  141. package/dist/exchanges/arcus/adapter.d.ts +196 -0
  142. package/dist/exchanges/arcus/adapter.js +1092 -0
  143. package/dist/exchanges/arcus/agent.d.ts +55 -0
  144. package/dist/exchanges/arcus/agent.js +188 -0
  145. package/dist/exchanges/arcus/client.d.ts +63 -0
  146. package/dist/exchanges/arcus/client.js +285 -0
  147. package/dist/exchanges/arcus/public.d.ts +65 -0
  148. package/dist/exchanges/arcus/public.js +138 -0
  149. package/dist/exchanges/arcus/signing.d.ts +176 -0
  150. package/dist/exchanges/arcus/signing.js +288 -0
  151. package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
  152. package/dist/exchanges/arcus/spot-chain.js +241 -0
  153. package/dist/exchanges/arcus/spot-router.d.ts +177 -0
  154. package/dist/exchanges/arcus/spot-router.js +183 -0
  155. package/dist/exchanges/arcus/spot.d.ts +109 -0
  156. package/dist/exchanges/arcus/spot.js +645 -0
  157. package/dist/exchanges/aster-funds.d.ts +127 -0
  158. package/dist/exchanges/aster-funds.js +252 -0
  159. package/dist/exchanges/aster-nonce.d.ts +2 -0
  160. package/dist/exchanges/aster-nonce.js +107 -0
  161. package/dist/exchanges/aster-spot.d.ts +117 -0
  162. package/dist/exchanges/aster-spot.js +686 -0
  163. package/dist/exchanges/aster-typed-data.d.ts +133 -7
  164. package/dist/exchanges/aster-typed-data.js +121 -7
  165. package/dist/exchanges/aster.d.ts +240 -6
  166. package/dist/exchanges/aster.js +1139 -195
  167. package/dist/exchanges/builder-fee.d.ts +254 -0
  168. package/dist/exchanges/builder-fee.js +421 -0
  169. package/dist/exchanges/canonical-symbols.d.ts +32 -0
  170. package/dist/exchanges/canonical-symbols.js +96 -0
  171. package/dist/exchanges/capabilities.d.ts +7 -1
  172. package/dist/exchanges/capabilities.js +7 -0
  173. package/dist/exchanges/hl-signing.d.ts +165 -0
  174. package/dist/exchanges/hl-signing.js +158 -0
  175. package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
  176. package/dist/exchanges/hyperliquid-outcome.js +646 -0
  177. package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
  178. package/dist/exchanges/hyperliquid-spot.js +308 -117
  179. package/dist/exchanges/hyperliquid.d.ts +462 -57
  180. package/dist/exchanges/hyperliquid.js +1575 -449
  181. package/dist/exchanges/index.d.ts +6 -0
  182. package/dist/exchanges/index.js +4 -0
  183. package/dist/exchanges/interface.d.ts +63 -10
  184. package/dist/exchanges/interface.js +18 -3
  185. package/dist/exchanges/ioc-outcome.d.ts +44 -0
  186. package/dist/exchanges/ioc-outcome.js +57 -0
  187. package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
  188. package/dist/exchanges/legacy-trading-v2.js +940 -0
  189. package/dist/exchanges/lighter-public.d.ts +43 -0
  190. package/dist/exchanges/lighter-public.js +276 -0
  191. package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
  192. package/dist/exchanges/lighter-rh-deposit.js +185 -0
  193. package/dist/exchanges/lighter-signer.d.ts +123 -0
  194. package/dist/exchanges/lighter-signer.js +215 -0
  195. package/dist/exchanges/lighter-spot.d.ts +91 -13
  196. package/dist/exchanges/lighter-spot.js +595 -233
  197. package/dist/exchanges/lighter.d.ts +611 -39
  198. package/dist/exchanges/lighter.js +1890 -649
  199. package/dist/exchanges/ondo/adapter.d.ts +152 -0
  200. package/dist/exchanges/ondo/adapter.js +811 -0
  201. package/dist/exchanges/ondo/agent.d.ts +31 -0
  202. package/dist/exchanges/ondo/agent.js +101 -0
  203. package/dist/exchanges/ondo/client.d.ts +60 -0
  204. package/dist/exchanges/ondo/client.js +297 -0
  205. package/dist/exchanges/ondo/funds.d.ts +95 -0
  206. package/dist/exchanges/ondo/funds.js +198 -0
  207. package/dist/exchanges/ondo/public.d.ts +95 -0
  208. package/dist/exchanges/ondo/public.js +214 -0
  209. package/dist/exchanges/ondo/spot.d.ts +127 -0
  210. package/dist/exchanges/ondo/spot.js +392 -0
  211. package/dist/exchanges/outcome-interface.d.ts +140 -0
  212. package/dist/exchanges/outcome-interface.js +16 -0
  213. package/dist/exchanges/pacifica-spot.d.ts +83 -0
  214. package/dist/exchanges/pacifica-spot.js +324 -0
  215. package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
  216. package/dist/exchanges/pacifica-typed-data.js +57 -9
  217. package/dist/exchanges/pacifica.d.ts +293 -4
  218. package/dist/exchanges/pacifica.js +1044 -90
  219. package/dist/exchanges/precision.d.ts +47 -0
  220. package/dist/exchanges/precision.js +209 -0
  221. package/dist/exchanges/qfex/adapter.d.ts +341 -0
  222. package/dist/exchanges/qfex/adapter.js +1386 -0
  223. package/dist/exchanges/qfex/agent.d.ts +58 -0
  224. package/dist/exchanges/qfex/agent.js +188 -0
  225. package/dist/exchanges/qfex/client.d.ts +54 -0
  226. package/dist/exchanges/qfex/client.js +138 -0
  227. package/dist/exchanges/qfex/errors.d.ts +70 -0
  228. package/dist/exchanges/qfex/errors.js +236 -0
  229. package/dist/exchanges/qfex/public.d.ts +122 -0
  230. package/dist/exchanges/qfex/public.js +268 -0
  231. package/dist/exchanges/qfex/signing.d.ts +160 -0
  232. package/dist/exchanges/qfex/signing.js +283 -0
  233. package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
  234. package/dist/exchanges/qfex/ws-transport.js +798 -0
  235. package/dist/exchanges/rate-limiter.d.ts +12 -0
  236. package/dist/exchanges/rate-limiter.js +64 -0
  237. package/dist/exchanges/registry.d.ts +14 -2
  238. package/dist/exchanges/registry.js +20 -32
  239. package/dist/exchanges/slippage.d.ts +37 -0
  240. package/dist/exchanges/slippage.js +70 -0
  241. package/dist/exchanges/spot-factory.d.ts +166 -0
  242. package/dist/exchanges/spot-factory.js +431 -0
  243. package/dist/exchanges/spot-interface.d.ts +98 -4
  244. package/dist/exchanges/spot-interface.js +27 -1
  245. package/dist/exchanges/spot-result.d.ts +79 -0
  246. package/dist/exchanges/spot-result.js +273 -0
  247. package/dist/exchanges/trading-v2.d.ts +117 -0
  248. package/dist/exchanges/trading-v2.js +301 -0
  249. package/dist/exchanges/venue-types.d.ts +231 -0
  250. package/dist/exchanges/venue-types.js +87 -0
  251. package/dist/exchanges/venue.d.ts +211 -0
  252. package/dist/exchanges/venue.js +132 -0
  253. package/dist/exchanges/venues/arcus.d.ts +8 -0
  254. package/dist/exchanges/venues/arcus.js +109 -0
  255. package/dist/exchanges/venues/aster.d.ts +49 -0
  256. package/dist/exchanges/venues/aster.js +176 -0
  257. package/dist/exchanges/venues/create-helpers.d.ts +18 -0
  258. package/dist/exchanges/venues/create-helpers.js +199 -0
  259. package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
  260. package/dist/exchanges/venues/hyperliquid.js +126 -0
  261. package/dist/exchanges/venues/index.d.ts +16 -0
  262. package/dist/exchanges/venues/index.js +26 -0
  263. package/dist/exchanges/venues/lighter-family.d.ts +92 -0
  264. package/dist/exchanges/venues/lighter-family.js +166 -0
  265. package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
  266. package/dist/exchanges/venues/lighter-rh.js +58 -0
  267. package/dist/exchanges/venues/lighter.d.ts +6 -0
  268. package/dist/exchanges/venues/lighter.js +55 -0
  269. package/dist/exchanges/venues/ondo.d.ts +29 -0
  270. package/dist/exchanges/venues/ondo.js +136 -0
  271. package/dist/exchanges/venues/pacifica.d.ts +8 -0
  272. package/dist/exchanges/venues/pacifica.js +95 -0
  273. package/dist/exchanges/venues/qfex.d.ts +39 -0
  274. package/dist/exchanges/venues/qfex.js +140 -0
  275. package/dist/execution-log.js +10 -2
  276. package/dist/funding/legacy-public.d.ts +31 -0
  277. package/dist/funding/legacy-public.js +369 -0
  278. package/dist/funding/normalize.d.ts +28 -16
  279. package/dist/funding/normalize.js +61 -29
  280. package/dist/funding/rates.d.ts +46 -11
  281. package/dist/funding/rates.js +228 -277
  282. package/dist/guardrail/perp-guardrail.js +0 -0
  283. package/dist/index.js +156 -684
  284. package/dist/jobs.d.ts +84 -6
  285. package/dist/jobs.js +239 -41
  286. package/dist/landing.d.ts +7 -2
  287. package/dist/landing.js +19 -3
  288. package/dist/mcp-server.d.ts +14 -4
  289. package/dist/mcp-server.js +821 -403
  290. package/dist/mcp-trade-guard.d.ts +16 -0
  291. package/dist/mcp-trade-guard.js +59 -0
  292. package/dist/onchain-balances.d.ts +40 -0
  293. package/dist/onchain-balances.js +173 -0
  294. package/dist/pacifica/client.d.ts +41 -10
  295. package/dist/pacifica/client.js +167 -63
  296. package/dist/pacifica/constants.d.ts +0 -1
  297. package/dist/pacifica/constants.js +0 -5
  298. package/dist/pacifica/deposit.d.ts +30 -3
  299. package/dist/pacifica/deposit.js +119 -2
  300. package/dist/pacifica/faucet.d.ts +29 -0
  301. package/dist/pacifica/faucet.js +100 -0
  302. package/dist/pacifica/sign-tx.d.ts +15 -0
  303. package/dist/pacifica/sign-tx.js +41 -0
  304. package/dist/pacifica/types/account.d.ts +28 -4
  305. package/dist/pacifica/types/lake.d.ts +20 -5
  306. package/dist/pacifica/types/lake.js +4 -0
  307. package/dist/pacifica/types/market.d.ts +5 -0
  308. package/dist/pacifica/types/order.d.ts +4 -1
  309. package/dist/pacifica/types/position.d.ts +9 -1
  310. package/dist/plan-executor.d.ts +10 -5
  311. package/dist/plan-executor.js +165 -54
  312. package/dist/position-history.js +13 -0
  313. package/dist/rebalance.d.ts +26 -2
  314. package/dist/rebalance.js +86 -7
  315. package/dist/relay-swap.d.ts +232 -0
  316. package/dist/relay-swap.js +630 -0
  317. package/dist/risk.js +5 -1
  318. package/dist/secret-env.d.ts +15 -0
  319. package/dist/secret-env.js +36 -0
  320. package/dist/settings.d.ts +169 -6
  321. package/dist/settings.js +219 -38
  322. package/dist/signer/ows-evm.d.ts +13 -0
  323. package/dist/signer/ows-evm.js +22 -0
  324. package/dist/smart-order.d.ts +9 -0
  325. package/dist/smart-order.js +53 -8
  326. package/dist/strategies/dca.d.ts +6 -2
  327. package/dist/strategies/dca.js +66 -26
  328. package/dist/strategies/funding-arb.d.ts +11 -1
  329. package/dist/strategies/funding-arb.js +202 -89
  330. package/dist/strategies/grid.d.ts +31 -0
  331. package/dist/strategies/grid.js +89 -11
  332. package/dist/strategies/pending-stop.d.ts +8 -0
  333. package/dist/strategies/pending-stop.js +12 -0
  334. package/dist/strategies/split-order.d.ts +45 -17
  335. package/dist/strategies/split-order.js +157 -91
  336. package/dist/strategies/trailing-stop.d.ts +2 -1
  337. package/dist/strategies/trailing-stop.js +52 -6
  338. package/dist/strategies/twap.d.ts +6 -1
  339. package/dist/strategies/twap.js +39 -11
  340. package/dist/trade-validator.d.ts +22 -0
  341. package/dist/trade-validator.js +119 -15
  342. package/dist/utils/numeric.d.ts +46 -0
  343. package/dist/utils/numeric.js +79 -0
  344. package/dist/utils.d.ts +19 -0
  345. package/dist/utils.js +96 -19
  346. package/dist/withdraw-gate.d.ts +49 -0
  347. package/dist/withdraw-gate.js +131 -0
  348. package/package.json +15 -6
  349. package/skills/perp-cli/SKILL.md +159 -55
  350. package/skills/perp-cli/references/agent-operations.md +112 -58
  351. package/skills/perp-cli/references/commands.md +269 -73
  352. package/skills/perp-cli/references/strategies.md +34 -31
  353. package/skills/perp-cli/scripts/arb-monitor.sh +10 -5
  354. package/skills/perp-cli/scripts/funding-analysis.sh +14 -9
  355. package/skills/perp-cli/scripts/preflight.sh +21 -14
  356. package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
  357. package/skills/perp-cli/scripts/validate-arb.sh +31 -15
  358. package/vendor/lighter-signer/SHA256SUMS +2 -0
  359. package/vendor/lighter-signer/VERSION +8 -0
  360. package/vendor/lighter-signer/lighter-signer.wasm +0 -0
  361. package/vendor/lighter-signer/wasm_exec.js +575 -0
  362. package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
  363. package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
@@ -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
- export interface AccountSettings {
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
- margin_mode: "cross" | "isolated";
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
- symbol: string;
3
- amount: string;
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
- lake_id: string;
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
- lake_id: string;
11
- amount: string;
23
+ /** "Vault address" */
24
+ lake: string;
25
+ /** "Number of shares to redeem" */
26
+ shares: string;
12
27
  }
@@ -1 +1,5 @@
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
+ */
1
5
  export {};
@@ -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
- twap_order_id: number;
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: number;
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
  }
@@ -17,7 +17,12 @@ export interface ExecutionPlan {
17
17
  export interface StepResult {
18
18
  stepId: string;
19
19
  action: PlanAction;
20
- status: "success" | "failed" | "skipped" | "rolled_back" | "dry_run";
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
- status: "completed" | "partial" | "failed" | "dry_run";
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;