@candledottv/agent-sdk 0.4.11 → 0.6.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/dist/client.d.ts CHANGED
@@ -26,7 +26,19 @@
26
26
  * validation error), and it never retries a launch whose stage is `executed` or `unconfirmed`
27
27
  * or whose error already names a mint. Backoff is 250ms * 2^n, jittered to 50-100% of that,
28
28
  * capped at 8s, bounded by `maxRetries` (default 3 retries after the initial attempt).
29
+ * - The id on every outcome. The six one-call write methods (`trade()`, `launch()`,
30
+ * `launchAsync()`, `selfLaunch()`, `buildAtomicLaunch()`, `launchAtomic()`) send one idempotency
31
+ * id per call, the caller's or a generated one, and once the first request carrying it has been
32
+ * sent, every exit exposes that id: on the returned value, and on the thrown error
33
+ * (`operationIds(error)`). A `CandleApiError` or `JsonRpcError` keeps its class and gains the id;
34
+ * anything else (a rejected fetch, a 2xx body that is not JSON, a plain Error from one of the
35
+ * method's own steps) is wrapped once, at the outermost method, in a `CandleOperationError` with
36
+ * the original as `cause`. An error raised before anything was sent (no API key) carries no id
37
+ * and is not wrapped. The SDK never reuses an id between calls and adds no retry of its own: a
38
+ * call that passes no id is a new operation. The retry is the caller's, with the id passed back.
39
+ * The README's "Retrying a write that failed or timed out" is the caller-facing procedure.
29
40
  */
41
+ import { type SignedTradeLeg } from "./errors";
30
42
  import { type HyperliquidNetwork, type HyperliquidTypedData } from "./hyperliquid";
31
43
  import type { HyperliquidPnlSection } from "./hyperliquid-pnl";
32
44
  import type { AgentPlansResult, PlanPrice, PlanTable } from "./plans";
@@ -278,9 +290,15 @@ export interface SelfLaunchDryRunResult extends Omit<DryRunResult, "launchWallet
278
290
  launchWallet: string;
279
291
  launchWalletId: string;
280
292
  }
281
- /** POST /api/v1/launch/headless blocking (or replayed) success response. */
293
+ /**
294
+ * POST /api/v1/launch/headless blocking (or replayed) success response, plus `clientLaunchId`.
295
+ * The server's body does not carry the id: `launch()`, `selfLaunch()` and `confirmSelfLaunch()`
296
+ * set it from the request they sent, so a caller who let the SDK generate it still has it.
297
+ */
282
298
  export interface LaunchResult {
283
299
  success: true;
300
+ /** The idempotency id this launch was sent under, the caller's or the generated one. */
301
+ clientLaunchId: string;
284
302
  chain: Chain;
285
303
  mint: string;
286
304
  pool: string | null;
@@ -455,6 +473,79 @@ export type VerifyResult = {
455
473
  signer?: string;
456
474
  };
457
475
  };
476
+ /** Fields an eligible agent key may edit. Name, slug and visibility stay owner-only. */
477
+ export interface OwnAgentProfilePatch {
478
+ publicAvatar?: string | null;
479
+ publicBanner?: string | null;
480
+ publicThesis?: string | null;
481
+ publicStrategy?: string | null;
482
+ publicStrategyNote?: string | null;
483
+ publicModel?: string | null;
484
+ publicModels?: string[] | null;
485
+ publicLinks?: {
486
+ website?: string | null;
487
+ x?: string | null;
488
+ } | null;
489
+ }
490
+ export interface OwnAgentProfile {
491
+ success: true;
492
+ profileId: string;
493
+ keyPrefix: string;
494
+ profileSelfEdit: "allowed" | "denied";
495
+ canEdit: boolean;
496
+ agentEditsLocked: boolean;
497
+ display: {
498
+ name: string | null;
499
+ avatarUrl: string | null;
500
+ bannerUrl: string | null;
501
+ thesis: string | null;
502
+ strategy: string | null;
503
+ strategyNote: string | null;
504
+ model: string | null;
505
+ models: string[];
506
+ links: {
507
+ website: string | null;
508
+ x: string | null;
509
+ };
510
+ };
511
+ }
512
+ /** The token a post names: a token Candle shows publicly. The agent need not have traded or launched it. */
513
+ export interface AgentPostTokenRef {
514
+ chain: "solana" | "hood";
515
+ mint: string;
516
+ }
517
+ /** The chip beside a post, linking to the token's Candle page. */
518
+ export interface AgentPostToken extends AgentPostTokenRef {
519
+ symbol: string;
520
+ name: string;
521
+ image: string;
522
+ }
523
+ /** One post on an agent's own page. Tied to no trade or launch. */
524
+ export interface AgentPost {
525
+ id: string;
526
+ /** Plain text, 1 to 500 characters, line breaks kept. Render it as text: never as HTML, and a URL in it is not a link. */
527
+ text: string;
528
+ /** Server time, unix ms. */
529
+ createdAt: number;
530
+ /** Null when the post named no token, or when Candle no longer shows the one it named. */
531
+ token: AgentPostToken | null;
532
+ }
533
+ export interface CreateAgentPostRequest {
534
+ /** 1 to 500 characters. Line breaks are kept; any other control character and bidi characters are refused. */
535
+ text: string;
536
+ token?: AgentPostTokenRef;
537
+ }
538
+ /** One page of an agent's posts, newest first. `cursor` is null on the last page. */
539
+ export interface AgentPostsPage {
540
+ posts: AgentPost[];
541
+ cursor: string | null;
542
+ }
543
+ export interface ListAgentPostsOptions {
544
+ /** 1 to 50. Default 20. */
545
+ limit?: number;
546
+ /** The previous page's `cursor`. */
547
+ cursor?: string;
548
+ }
458
549
  /** GET /api/v1/users/:idOrWallet/agent, unwrapped from `{ success, agent }`. */
459
550
  export interface AgentProfile {
460
551
  enabled: boolean;
@@ -463,6 +554,103 @@ export interface AgentProfile {
463
554
  launches: number;
464
555
  launchesViaApi: number;
465
556
  }
557
+ /** Claimed fee income on public board entries and records. Older snapshots omit these fields. */
558
+ export interface AgentFeeIncome {
559
+ /** Fees earned, valued when claimed, credited to the profile that launched the token. */
560
+ creatorFeesUsd?: number;
561
+ /** Claims without a USD value; excluded from creatorFeesUsd, never valued at zero. */
562
+ feeClaimsUnvalued?: number;
563
+ /** The capped claim read does not cover the whole window; the fee income is a floor. */
564
+ feeClaimsPartial?: boolean;
565
+ }
566
+ /**
567
+ * The optional board object beside private ledger P&L, also on /keys/pnl rows with a profileId.
568
+ * Rows without a profileId and combined stay ledger-only.
569
+ */
570
+ export interface ProfileBoardPnl {
571
+ profileId: string;
572
+ creatorFeesUsd: number;
573
+ feeClaimsUnvalued: number;
574
+ feeClaimsPartial: boolean;
575
+ /** All-time public board total, including claimed fees; absent before a board entry exists. */
576
+ totalPnlUsd?: number;
577
+ }
578
+ /** One profile row of GET /api/v1/agent/keys/pnl; ledger fields stay separate from board income. */
579
+ export interface ProfilePnlSummaryRow {
580
+ profileId: string | null;
581
+ board?: ProfileBoardPnl;
582
+ [key: string]: unknown;
583
+ }
584
+ /** Public realized figures. feesUsd is fees paid; creatorFeesUsd is separate income. */
585
+ export interface AgentRecordTotals extends AgentFeeIncome {
586
+ realizedNetUsd: number;
587
+ feesUsd: number;
588
+ wins: number;
589
+ losses: number;
590
+ counted: number;
591
+ unvalued: number;
592
+ bestUsd?: number;
593
+ worstUsd?: number;
594
+ unrealizedUsd?: number;
595
+ /** Realized net plus unrealized plus creatorFeesUsd, already including moved-in shares. */
596
+ totalPnlUsd?: number;
597
+ realizedFromTransfersUsd?: number;
598
+ unrealizedFromTransfersUsd?: number;
599
+ }
600
+ /** A public leaderboard entry, including additive fee income beside its trade totals. */
601
+ export interface AgentLeaderboardEntry extends AgentFeeIncome {
602
+ profileId: string;
603
+ name: string;
604
+ wallet: string;
605
+ rank: number;
606
+ totals: AgentRecordTotals;
607
+ winRatePct: number | null;
608
+ unrealizedUsd?: number;
609
+ totalPnlUsd?: number;
610
+ totalRank?: number;
611
+ markedAt?: number;
612
+ unrealizedPartial?: boolean;
613
+ windowComplete?: boolean;
614
+ openWins?: number;
615
+ openLosses?: number;
616
+ /** Other identity and coverage fields are preserved by the API. */
617
+ [key: string]: unknown;
618
+ }
619
+ /** A settled Solana staking claim, newest first; its claim value is not added to P&L again. */
620
+ export interface AgentRewardClaim {
621
+ mint: string;
622
+ tokenSymbol: string;
623
+ amount: number;
624
+ usdValue?: number;
625
+ timestampMs: number;
626
+ signature: string;
627
+ }
628
+ /** GET /api/v1/agent/records/:profileId record, with optional claim projections. */
629
+ export interface AgentPublicRecord extends AgentFeeIncome {
630
+ profileId: string;
631
+ name: string;
632
+ wallet: string;
633
+ totals: AgentRecordTotals;
634
+ unrealizedUsd?: number;
635
+ totalPnlUsd?: number;
636
+ rewardClaims?: AgentRewardClaim[];
637
+ /** Newest 13 claims are retained; true means older claims were omitted. */
638
+ rewardClaimsPartial?: boolean;
639
+ /** Existing row, series, identity and coverage fields. */
640
+ [key: string]: unknown;
641
+ }
642
+ export type AgentHoldingOrigin = "bought" | "movedIn" | "mixed" | "reward";
643
+ /** One of the public top ten holdings, returned separately from the public record. */
644
+ export interface AgentPublicHolding {
645
+ mint: string;
646
+ chain: Chain;
647
+ symbol?: string;
648
+ valueUsd: number;
649
+ unrealizedUsd?: number;
650
+ origin?: AgentHoldingOrigin;
651
+ /** Bought only with positive cost; reward and mixed holdings omit this. */
652
+ unrealizedPct?: number;
653
+ }
466
654
  /** How `listAgents` orders the directory, each largest first. */
467
655
  export type AgentDirectorySort = "newest" | "active" | "pnl";
468
656
  /** One published agent, as `listAgents` returns it. Identity and three aggregates: no wallet, no position. */
@@ -482,9 +670,9 @@ export interface AgentDirectoryEntry {
482
670
  models: string[];
483
671
  /** Unix ms. */
484
672
  publishedAt: number;
485
- /** The newest trade or launch, unix ms. Null for an agent that has done neither. */
673
+ /** The newest trade, launch or post, unix ms. Null for an agent that has none. */
486
674
  lastActiveAt: number | null;
487
- /** All-time realized plus unrealized, USD, refreshed about every ten minutes. Null until first computed. */
675
+ /** All-time realized plus unrealized plus claimed creator fees, USD, refreshed about every ten minutes. Null until first computed. */
488
676
  totalPnlUsd: number | null;
489
677
  tradeCount: number;
490
678
  launchCount: number;
@@ -842,6 +1030,8 @@ export interface ProfileChainPnl extends ProfilePnlEngineFields {
842
1030
  * Every account's realized figure can move on the day a server ships this.
843
1031
  */
844
1032
  export interface ProfilePnlResult {
1033
+ /** Public board figures including fee income; independent of pnl.totalUsd and its coverage. */
1034
+ board?: ProfileBoardPnl;
845
1035
  /** Optional while Hyperliquid is enabled; separate from spot totals. */
846
1036
  hyperliquid?: HyperliquidPnlSection;
847
1037
  success: true;
@@ -1448,6 +1638,43 @@ export type ConfirmTradeRequest = {
1448
1638
  };
1449
1639
  /** POST /api/v1/trade/agent/confirm response. Always "executed": confirm only ever verifies and records a trade that already happened on-chain. */
1450
1640
  export type ConfirmTradeResult = ExecutedTradeResult;
1641
+ /**
1642
+ * One trade from the idempotency ledger, from GET /api/v1/trade/agent/jobs/:clientTradeId
1643
+ * (`getTradeJob()`). `amountRaw` is raw units: the quote asset's on a buy, the token's on a sell.
1644
+ * `status` is `built` (in flight, or built and never confirmed), `confirmed` (landed; `signature`
1645
+ * is set) or `failed` (`errorCode` says why; `TRADE_REVERTED` means it landed and reverted).
1646
+ */
1647
+ export interface TradeJob {
1648
+ signedLegs?: SignedTradeLeg[];
1649
+ clientTradeId: string;
1650
+ chain: Chain;
1651
+ side: TradeSide;
1652
+ mint: string;
1653
+ quoteAsset: string;
1654
+ amountRaw: string;
1655
+ status: "built" | "confirmed" | "failed";
1656
+ signature?: string;
1657
+ errorCode?: string;
1658
+ createdAt: number;
1659
+ updatedAt: number;
1660
+ /** A Hood TEE trade only: its sequenced operation, leg by leg. `kind` and `status` are open strings. */
1661
+ operation?: {
1662
+ operationId: string;
1663
+ kind: string;
1664
+ status: string;
1665
+ plannedLegCount: number;
1666
+ currentLegIndex: number;
1667
+ legs: Array<{
1668
+ kind: string;
1669
+ status: string;
1670
+ hash?: string;
1671
+ nonce?: number;
1672
+ }>;
1673
+ expiresAt: number;
1674
+ /** The fee a trade that landed after its lock expired still owes, once the read has recorded it. */
1675
+ feeOwed?: Record<string, unknown>;
1676
+ };
1677
+ }
1451
1678
  /**
1452
1679
  * POST /api/v1/trade/agent/submit request body. `signedTransactions` is the ordered signed legs:
1453
1680
  * one for Solana; one to four for Hood in the fixed approval, permit2Approval, trade, feeTransfer
@@ -2139,7 +2366,10 @@ export interface TradeRequest {
2139
2366
  * The server defaults it when omitted, which is `sol` on Solana and ETH settlement on Hood.
2140
2367
  */
2141
2368
  quoteAsset?: "sol" | "usdc" | "cndl" | "eth" | "usdg";
2142
- /** Idempotency key shared by the build and confirm calls; generated ("sdk-" + UUID) when omitted. */
2369
+ /**
2370
+ * Idempotency key shared by the build and confirm calls; generated ("sdk-" + UUID) when omitted.
2371
+ * Pass your own for anything that moves funds and store it before the call: see `trade()`.
2372
+ */
2143
2373
  clientTradeId?: string;
2144
2374
  }
2145
2375
  /** selfLaunch()'s one-call request: BuildSelfLaunchRequest plus the linked wallet's Privy wallet id. */
@@ -2191,8 +2421,14 @@ export interface AtomicBundleResponseLeg {
2191
2421
  amountOutRaw: string;
2192
2422
  };
2193
2423
  }
2194
- /** POST /api/v1/launch/atomic/build response. */
2424
+ /**
2425
+ * POST /api/v1/launch/atomic/build response, plus `clientLaunchId`. The server's body does not
2426
+ * carry the id: `buildAtomicLaunch()` sets it from the request it sent. It is the launch's
2427
+ * identity (`bundleId` is single-use), so a caller driving build and submit by hand keeps it.
2428
+ */
2195
2429
  export interface BuildAtomicLaunchResult {
2430
+ /** The idempotency id this build was sent under, the caller's or the generated one. */
2431
+ clientLaunchId: string;
2196
2432
  bundleId: string;
2197
2433
  legs: AtomicBundleResponseLeg[];
2198
2434
  expiresAt: number;
@@ -2211,14 +2447,21 @@ export interface SubmitAtomicLaunchRequest {
2211
2447
  * are the 502 body -- all three are NORMAL, expected outcomes of submitting a Jito bundle that
2212
2448
  * this route documents as part of its own response surface, so `submitAtomicLaunch()`/
2213
2449
  * `launchAtomic()` return them here rather than throwing `CandleApiError` (every OTHER non-2xx
2214
- * status still throws, same as every other method). `retryable` is always `false` for `"failed"`;
2215
- * for `"timeout"` it is `true` only when the bundle's shared blockhash was proven to have expired
2216
- * with no confirmation -- `false` means the resolution window simply ran out with no definitive
2217
- * answer and the bundle MIGHT STILL LAND, so the caller should wait rather than immediately
2218
- * rebuild under a fresh `clientLaunchId`. In every case, `bundleId` itself is dead once this
2219
- * response arrives: it is consumed on the first `/submit` call regardless of outcome, so recovery
2220
- * is always a fresh `buildAtomicLaunch()`/`launchAtomic()` call, never a retried `submit` with the
2221
- * same id. See "Atomic launch with first buys" in docs/headless-launch.md for the full model.
2450
+ * status still throws, same as every other method).
2451
+ *
2452
+ * `retryable` is `false` on every `"failed"` and on every `"timeout"` the server returns today.
2453
+ * It is not permission to relaunch, whatever its value: a `"timeout"` means the resolution window
2454
+ * ran out with no definitive answer and the bundle MIGHT STILL LAND. Treat every `"timeout"` as
2455
+ * unresolved and never rebuild under a new `clientLaunchId` because of one: that is a second
2456
+ * token. (This comment used to describe a `true` case meaning "the blockhash expired, relaunch".
2457
+ * No server path returns it.)
2458
+ *
2459
+ * `bundleId` itself is dead once this response arrives: it is consumed on the first `/submit`
2460
+ * call regardless of outcome and is never resubmitted. The launch's identity is the
2461
+ * `clientLaunchId` the build was sent under, and recovery goes through it: read
2462
+ * `getLaunchJob(clientLaunchId)`, then call `launchAtomic()` again with the SAME id when the job
2463
+ * says to (the steps are on `launchAtomic()`). See "Atomic launch with first buys" in
2464
+ * docs/headless-launch.md for the full model.
2222
2465
  */
2223
2466
  export type SubmitAtomicLaunchResult = {
2224
2467
  status: "landed";
@@ -2234,6 +2477,14 @@ export type SubmitAtomicLaunchResult = {
2234
2477
  bundleId: string;
2235
2478
  retryable: boolean;
2236
2479
  };
2480
+ /**
2481
+ * What `launchAtomic()` returns: `submitAtomicLaunch()`'s outcome plus the `clientLaunchId` the
2482
+ * launch was sent under, on all three of `landed`, `failed` and `timeout`. `submitAtomicLaunch()`
2483
+ * itself is given only a `bundleId` and cannot know the launch id.
2484
+ */
2485
+ export type LaunchAtomicResult = SubmitAtomicLaunchResult & {
2486
+ clientLaunchId: string;
2487
+ };
2237
2488
  /** Who pays for one leg of launchAtomic()'s one-call request. Mirrors AtomicLaunchPayer, but a "linked" payer also carries the privyWalletId signLinkedTransaction() needs to sign that leg -- mirrors TradeRequest's `from` field. */
2238
2489
  export type LaunchAtomicPayer = {
2239
2490
  type: "main";
@@ -2287,6 +2538,44 @@ export declare class CandleClient {
2287
2538
  }): Promise<QuoteResult>;
2288
2539
  getFeed(bucket: FeedBucket, chain?: Chain): Promise<FeedResult>;
2289
2540
  verify(chain: Chain, mint: string): Promise<VerifyResult>;
2541
+ getOwnProfile(): Promise<OwnAgentProfile>;
2542
+ updateOwnProfile(patch: OwnAgentProfilePatch): Promise<{
2543
+ success: true;
2544
+ profileId: string;
2545
+ }>;
2546
+ /** The server counts, audits and saves this image without a subsequent PATCH. */
2547
+ uploadProfileImage(kind: "avatar" | "banner", bytes: Uint8Array, contentType: string): Promise<{
2548
+ imageUrl: string;
2549
+ profileId: string;
2550
+ }>;
2551
+ /**
2552
+ * Publish one post on this agent's own page (`POST /api/v1/agent/posts`). Needs an acting key
2553
+ * with `profileSelfEdit` allowed and no admin lock: a Read key is refused with `SCOPE_MISSING`,
2554
+ * a denied or locked one with `PROFILE_SELF_EDIT_DENIED`. 30 posts per UTC day per profile,
2555
+ * shared by all its keys and the owner; the 31st is `RATE_LIMITED`. A post is tied to no trade
2556
+ * or launch and is shown only on the agent's page.
2557
+ */
2558
+ createPost(req: CreateAgentPostRequest): Promise<{
2559
+ success: true;
2560
+ profileId: string;
2561
+ post: AgentPost;
2562
+ }>;
2563
+ /**
2564
+ * Delete one post of this agent's own profile, whoever wrote it (`DELETE /api/v1/agent/posts/:id`).
2565
+ * The same key requirements as `createPost()`. Deleting does not give the day's place back. An
2566
+ * unknown id, another profile's post and a post already deleted are `RECORD_NOT_FOUND`.
2567
+ */
2568
+ deletePost(postId: string): Promise<{
2569
+ success: true;
2570
+ profileId: string;
2571
+ postId: string;
2572
+ }>;
2573
+ /**
2574
+ * One published agent's posts, newest first (`GET /api/v1/agent/records/:profileId/posts`, no
2575
+ * credential). Pass the returned `cursor` to read the next older page. An agent that is not
2576
+ * published answers 404 `RECORD_NOT_FOUND` (`CandleApiError`), as its record does.
2577
+ */
2578
+ listAgentPosts(profileId: string, options?: ListAgentPostsOptions): Promise<AgentPostsPage>;
2290
2579
  getAgentProfile(idOrWallet: string): Promise<AgentProfile>;
2291
2580
  /**
2292
2581
  * The agent directory (`GET /api/v1/agent/directory`, no credential): every agent its owner
@@ -2315,12 +2604,27 @@ export declare class CandleClient {
2315
2604
  /**
2316
2605
  * Blocking launch with idempotent retries. Generates `clientLaunchId` when absent and
2317
2606
  * re-sends the SAME id on retryable failures; see the module doc for the exact policy.
2607
+ *
2608
+ * The id this call sent, yours or the generated one, is on the result
2609
+ * (`result.clientLaunchId`) and on every error thrown after the first request was sent
2610
+ * (`operationIds(error).clientLaunchId`), including the one thrown when the retries run out.
2611
+ * The built-in retries are safe only inside this one call. To retry after it throws, call
2612
+ * `launch()` again with that SAME id and the same body, or read `getLaunchJob(id)`. Never retry
2613
+ * without the id: a call with no id, or a new one, is a second launch. Pass your own id and
2614
+ * store it before the call when you can: an error can carry the id only if the process is
2615
+ * still running to catch it.
2318
2616
  */
2319
2617
  launch(req: LaunchRequest): Promise<LaunchResult>;
2320
2618
  /**
2321
2619
  * Fire-and-poll launch: sends `async: true`, returns the 202 body. Single attempt (poll
2322
2620
  * `waitForLaunch` instead of retrying the POST). Generates `clientLaunchId` like `launch()`
2323
2621
  * so the returned body always carries the id to poll.
2622
+ *
2623
+ * An error thrown after the request was sent carries that id too
2624
+ * (`operationIds(error).clientLaunchId`): the launch may have been accepted. Poll
2625
+ * `getLaunchJob(id)` / `waitForLaunch(id)`, or call again with the SAME id and body. Never
2626
+ * retry without the id: a call with no id, or a new one, is a second launch. Pass your own id
2627
+ * and store it before the call when you can.
2324
2628
  */
2325
2629
  launchAsync(req: LaunchRequest): Promise<AcceptedJob>;
2326
2630
  getLaunchJob(clientLaunchId: string): Promise<LaunchJob>;
@@ -2521,11 +2825,14 @@ export declare class CandleClient {
2521
2825
  * docs/headless-launch.md.
2522
2826
  */
2523
2827
  buildSelfLaunch(req: BuildSelfLaunchRequest): Promise<BuildSelfLaunchResult>;
2828
+ /** buildSelfLaunch()'s request; selfLaunch() passes its `op` so its exits can expose the id. */
2829
+ private postSelfLaunchBuild;
2524
2830
  /**
2525
2831
  * Self-signed launch confirm: verifies the agent's own broadcast on-chain, then records the
2526
2832
  * launch identically to the headless path. Signature is the transaction hash from the agent's
2527
2833
  * own broadcast. devBuySignature (Hood only) is the optional follow-up dev-buy transaction. See
2528
- * selfLaunch() below for the one-call version of this whole flow (Solana).
2834
+ * selfLaunch() below for the one-call version of this whole flow (Solana). The result carries
2835
+ * the `clientLaunchId` from the request (the server's body does not).
2529
2836
  */
2530
2837
  confirmSelfLaunch(req: ConfirmSelfLaunchRequest): Promise<ConfirmSelfLaunchResult>;
2531
2838
  /**
@@ -2577,6 +2884,35 @@ export declare class CandleClient {
2577
2884
  * `built | confirmed | failed`.
2578
2885
  */
2579
2886
  buildTrade(req: BuildTradeRequest): Promise<BuildTradeResult>;
2887
+ /** buildTrade()'s request; trade() passes its `op` so its exits can expose the id. */
2888
+ private postTradeBuild;
2889
+ /**
2890
+ * Reads one trade from the idempotency ledger by its `clientTradeId`, without sending
2891
+ * anything: the read to make after a `trade()` that threw or timed out, before deciding whether
2892
+ * to send again. Needs `swap:write` (the scope the trade itself needed) and answers during a
2893
+ * kill switch.
2894
+ *
2895
+ * - 404 `JOB_NOT_FOUND` (a thrown `CandleApiError`): the write never began. Call again with the
2896
+ * same id.
2897
+ * - `confirmed`: the trade landed; `signature` is on the job. A same-id `trade()` replays it.
2898
+ * - `failed` with `errorCode: "TRADE_REVERTED"`: it landed and reverted. A new trade needs a
2899
+ * new id.
2900
+ * - `failed`, other: not confirmed. A row with broadcast evidence may still be on chain; a
2901
+ * same-id `trade()` is the check, and answers `IDEMPOTENCY_CONFLICT` with
2902
+ * `stage: "unconfirmed"` for it.
2903
+ * - `built`: in flight or unresolved. A same-id `trade()` answers `IDEMPOTENCY_CONFLICT`; if it
2904
+ * carries `stage: "unconfirmed"` and `retryable: false`, check its `signature` on chain and
2905
+ * do not retry.
2906
+ *
2907
+ * Non-TEE Hood linked jobs include signedLegs and resolve receipts on read. A landed trade
2908
+ * on a built row can be recorded with confirmTrade using the trade and fee hashes; on a failed
2909
+ * row it cannot: do not retry or rebuild. A reverted leg beside an unsettled one is not a
2910
+ * settled id. Approval-only new-id advice is obtained on build only, after claim retirement.
2911
+ *
2912
+ * For a linked payer, also check the wallet's recent transactions before sending again: see
2913
+ * `trade()`.
2914
+ */
2915
+ getTradeJob(clientTradeId: string): Promise<TradeJob>;
2580
2916
  /**
2581
2917
  * Confirm a LINKED payer's own broadcast trade: Candle verifies it landed on-chain, that it was
2582
2918
  * actually signed/sent by the declared linked wallet, that it moved this trade's own mint in
@@ -2676,8 +3012,35 @@ export declare class CandleClient {
2676
3012
  * opt-in, but only for a caller that has already confirmed the build carries neither an
2677
3013
  * `approval` nor a `permit2Approval` leg. Requires `evmRpcUrl`; throws a clear error
2678
3014
  * naming it when unset, before any RPC read or signing.
3015
+ *
3016
+ * ## The id, and retrying
3017
+ *
3018
+ * The `clientTradeId` this call sent, yours or the generated one, is on the result and on every
3019
+ * error thrown after the build request was sent (`operationIds(error).clientTradeId`): a
3020
+ * `CandleApiError` or `JsonRpcError` gains it, and a lost response or any other failure is a
3021
+ * `CandleOperationError` carrying it, with the original as `cause`. Pass your own id for
3022
+ * anything that moves funds and store it before the call: an error can carry the id only if
3023
+ * the process is still running to catch it. Never retry without the id: a call with no id, or a
3024
+ * new one, is a second, independent trade. This method does not retry on its own.
3025
+ *
3026
+ * - **Main payer** (`from: "main"`): the trade executes inside the build call, so a lost
3027
+ * response can sit on a trade that already moved funds. With the id, read `getTradeJob(id)`
3028
+ * or call `trade()` again with the same id and body. Both are safe: the same-id call is a
3029
+ * replay, not a second trade. `getTradeJob()`'s jsdoc says what each job state means.
3030
+ * - **Linked Hood payer**: once any leg is signed, the server refuses a same-id build.
3031
+ * TradeLegOutcomeError keeps the failing leg's txHash and earlier landedLegs. Inspect those
3032
+ * hashes, then read getTradeJob(id) or call trade() with the same id and body for Candle's
3033
+ * view. Never retry a retryable:false answer. A built prior_attempt_on_chain can be recorded
3034
+ * with confirmTrade using signature as tradeTxHash and the fee hash from legs (pay a missing
3035
+ * fee first, following TradeLandedFeeLegError). A failed row cannot be recorded with /confirm:
3036
+ * retain the hashes and do not retry or rebuild. Approval-only new-id advice follows committed
3037
+ * retirement and repeats unchanged. Reverted beside an unsettled leg never advises a new id.
3038
+ * TradeLandedUnconfirmedError means all legs landed but booking failed: read the job first.
3039
+ * - **Linked Solana payer**: read getTradeJob(id) and check the wallet before sending again.
2679
3040
  */
2680
3041
  trade(req: TradeRequest): Promise<ExecutedTradeResult>;
3042
+ /** trade()'s steps. Every error leaves through trade()'s runOperation(), which adds the id. */
3043
+ private tradeSteps;
2681
3044
  /**
2682
3045
  * One-call self-signed launch. Solana: `buildSelfLaunch` -> `signLinkedTransaction` ->
2683
3046
  * `broadcastSignedTransaction` -> `confirmSelfLaunch` (`built.transaction` is a base64 unsigned
@@ -2690,8 +3053,36 @@ export declare class CandleClient {
2690
3053
  * send a dev buy: a Hood self-launch's dev buy is a separate transaction the caller sends itself
2691
3054
  * and reports to `confirmSelfLaunch` as `devBuySignature`. The build response never includes a
2692
3055
  * dev-buy leg, and this method does not assemble one.
3056
+ *
3057
+ * ## The id, and retrying
3058
+ *
3059
+ * The `clientLaunchId` this call sent, yours or the generated one, is on the result and on every
3060
+ * error thrown after the build request was sent (`operationIds(error).clientLaunchId`). Pass
3061
+ * your own id and store it before the call when you can. Never retry without the id: a call
3062
+ * with no id, or a new one, is a second, independent launch.
3063
+ *
3064
+ * This method signs and broadcasts on the caller's side, so an error after the broadcast may
3065
+ * sit on a launch transaction that landed. Read `getLaunchJob(id)` first.
3066
+ *
3067
+ * On Solana the id is enough to keep a second launch from being built. One id has one build
3068
+ * at a time: `buildSelfLaunch()` under the same id returns the SAME transaction while the
3069
+ * earlier one can still land, refuses with `IDEMPOTENCY_CONFLICT` and
3070
+ * `reason: "prior_attempt_on_chain"` once it has landed, and builds a new transaction only
3071
+ * after the chain proves the earlier one expired. A launch that landed is recorded with
3072
+ * `confirmSelfLaunch({ clientLaunchId, signature })`, which keeps working after the build's
3073
+ * 30-minute `expiresAt`. Inside this call, a blockhash error from your Solana RPC is retried
3074
+ * with the bytes already signed: they are signed once, and signed again only when the server
3075
+ * returns a different transaction. Calling `selfLaunch()` again under the same id while the
3076
+ * earlier build is still live is refused by the sign relay, because that transaction's sign
3077
+ * claim is already spent: broadcast what was signed, or wait for it to expire.
3078
+ *
3079
+ * On Hood the id is necessary and NOT sufficient: a rebuild under the same id builds a new
3080
+ * curve, so calling `selfLaunch()` again can create and broadcast a second one. If the job is
3081
+ * not `confirmed`, check the wallet's recent transactions before sending again.
2693
3082
  */
2694
3083
  selfLaunch(req: SelfLaunchRequest): Promise<ConfirmSelfLaunchResult>;
3084
+ /** selfLaunch()'s steps. Every error leaves through selfLaunch()'s runOperation(), which adds the id. */
3085
+ private selfLaunchSteps;
2695
3086
  /**
2696
3087
  * Builds an atomic launch bundle: a Solana launch transaction plus 1-4 first-buy transactions,
2697
3088
  * all sharing one recent blockhash so Jito lands them together or not at all. Returns the
@@ -2702,8 +3093,22 @@ export declare class CandleClient {
2702
3093
  * the full model: Pro/Max tier, `launch:write` + `swap:write` scopes, Solana only, the 1-4 buy
2703
3094
  * cap (Jito's 5-transaction bundle limit), and why every buy leg's own on-chain `minAmountOut` is
2704
3095
  * "0" inside the bundle (`expectedFill` on the returned legs is the real consent surface).
3096
+ *
3097
+ * The result carries the `clientLaunchId` the build was sent under (the server's body does
3098
+ * not), and so does every error thrown after the request was sent
3099
+ * (`operationIds(error).clientLaunchId`). Keep it: `bundleId` is single-use, and the launch's
3100
+ * identity for any later read or retry is the `clientLaunchId`. Retry a failed build with the
3101
+ * SAME id and body, or read `getLaunchJob(id)`; a call with no id, or a new one, is a second
3102
+ * launch. After a submit, follow the steps on `launchAtomic()`. Pass your own id and store it
3103
+ * before the call when you can.
2705
3104
  */
2706
3105
  buildAtomicLaunch(req: BuildAtomicLaunchRequest): Promise<BuildAtomicLaunchResult>;
3106
+ /**
3107
+ * The atomic build request itself. Sets `clientLaunchId` on the result from the request, since
3108
+ * the server's body omits it. Shared by buildAtomicLaunch() and launchAtomic(), each of which
3109
+ * runs it inside its OWN runOperation(), so an error is wrapped once, by the outermost method.
3110
+ */
3111
+ private postAtomicBuild;
2707
3112
  /**
2708
3113
  * Submits an already-built bundle's client-signer legs (EXACTLY the ones
2709
3114
  * `BuildAtomicLaunchResult.legs` named `signer: "client"`, in leg order -- omit every "server"
@@ -2723,7 +3128,15 @@ export declare class CandleClient {
2723
3128
  * roughly 150-160s in the worst case (Jito's own ~60s poll budget plus a further ~90s resolution
2724
3129
  * phase), since Candle checks the launch signature's own on-chain status before answering. Set a
2725
3130
  * client-side timeout no shorter than ~160s (or none) for this call, or you risk abandoning a
2726
- * request that was about to return a normal, if late, response.
3131
+ * request that was about to return a normal, if late, response. A same-id
3132
+ * `buildAtomicLaunch()`/`launchAtomic()` after a send can itself take up to about 95 seconds to
3133
+ * answer, because the server resolves the first attempt against the chain before doing anything
3134
+ * new: allow for that too.
3135
+ *
3136
+ * This method is given only a `bundleId`, so its result cannot carry the launch's
3137
+ * `clientLaunchId`. Keep the one `buildAtomicLaunch()` returned: after a `"failed"` or
3138
+ * `"timeout"`, recovery goes through it (the steps are on `launchAtomic()`), never through
3139
+ * this `bundleId` and never through a new id.
2727
3140
  */
2728
3141
  submitAtomicLaunch(req: SubmitAtomicLaunchRequest): Promise<SubmitAtomicLaunchResult>;
2729
3142
  /**
@@ -2737,11 +3150,44 @@ export declare class CandleClient {
2737
3150
  * bundle with no linked payer at all (every leg "main") skips the signing round entirely and
2738
3151
  * goes straight from build to submit.
2739
3152
  *
2740
- * Returns `submitAtomicLaunch()`'s own result untouched -- see that method's jsdoc for why
2741
- * `"failed"`/`"timeout"` are returned here rather than thrown, and for the recommended
2742
- * client-side timeout.
2743
- */
2744
- launchAtomic(req: LaunchAtomicRequest): Promise<SubmitAtomicLaunchResult>;
3153
+ * Returns `submitAtomicLaunch()`'s outcome plus the `clientLaunchId` the launch was sent under
3154
+ * (`LaunchAtomicResult`), on `"landed"`, `"failed"` and `"timeout"` alike -- see that method's
3155
+ * jsdoc for why `"failed"`/`"timeout"` are returned here rather than thrown, and for the
3156
+ * recommended client-side timeout. A thrown error carries `clientLaunchId` too, and `bundleId`
3157
+ * once the build has answered (`operationIds(error)`). Pass your own id and store it before the
3158
+ * call when you can: an error can carry the id only if the process is still running to catch it.
3159
+ *
3160
+ * ## After a `timeout`, a `failed`, or an error that carries `clientLaunchId`
3161
+ *
3162
+ * `bundleId` is dead once `/submit` has been called and is never resubmitted; it is for log
3163
+ * correlation only. The launch's identity is `clientLaunchId`:
3164
+ *
3165
+ * 1. Read `getLaunchJob(clientLaunchId)`. It needs `launch:read` on the key; a key whose scopes
3166
+ * were named by hand holds it only if it was named. A scope refusal is not "not found".
3167
+ * 2. `confirmed`: the bundle landed. The mint is on the job. Stop.
3168
+ * 3. 404 `JOB_NOT_FOUND`: the build never began. Call `launchAtomic()` again with the same id.
3169
+ * 4. `failed`: the bundle did not land. Call `launchAtomic()` again with the SAME id; the server
3170
+ * starts a clean attempt under it.
3171
+ * 5. Any other status: the bundle may still land. Wait, then read the job again or call
3172
+ * `launchAtomic()` again with the SAME id and the same body. The server resolves the first
3173
+ * attempt before doing anything new. It answers 409 `IDEMPOTENCY_CONFLICT` while the first
3174
+ * attempt is unresolved or has just been found landed, so on that 409 read the job again. It
3175
+ * builds a fresh bundle only when the first is proven reverted. This same-id call can take
3176
+ * about 95 seconds to answer, because the server waits on the chain.
3177
+ * 6. Never send a new id while the job is not `failed`: that is a second token. This includes
3178
+ * the 409 whose message says "use a new clientLaunchId to launch again": read the job first,
3179
+ * because that message is also what a caller sees for a launch it does not yet know landed.
3180
+ * 7. One state has no terminal answer today. The same-id call keeps answering 409 "This launch
3181
+ * was sent; its original attempt must be resolved" and the job is neither `confirmed` nor
3182
+ * `failed`, still, a few minutes after the submit (a blockhash lives about 90 seconds and the
3183
+ * rebuild itself can take about 95). Stop: do not send a new id on a timer, and report the
3184
+ * `clientLaunchId` and `bundleId` to whoever operates the key.
3185
+ * 8. Treat every `timeout` as unresolved. `retryable` is `false` on every one the server returns
3186
+ * today, and it is never permission to relaunch under a new id.
3187
+ */
3188
+ launchAtomic(req: LaunchAtomicRequest): Promise<LaunchAtomicResult>;
3189
+ /** launchAtomic()'s steps. Every error leaves through launchAtomic()'s runOperation(), which adds the ids. */
3190
+ private launchAtomicSteps;
2745
3191
  /**
2746
3192
  * The `EvmRpc` seam packages/sdk/src/evm-tx.ts's helpers are built against, built from this
2747
3193
  * client's own `jsonRpcCall`/`jsonRpcCallRaw` closed over `evmRpcUrl`. Callers must have already
@@ -2825,6 +3271,17 @@ export declare class CandleClient {
2825
3271
  private signLinkedTypedData;
2826
3272
  private requireKey;
2827
3273
  private headers;
3274
+ /**
3275
+ * Runs a one-call write method's steps so that every exit exposes the idempotency id it sent
3276
+ * (see the module doc, "The id on every outcome"). The steps pass `op` to the request that
3277
+ * carries the id. Until that request is handed to fetch, an error leaves unchanged: nothing
3278
+ * reached the server, so there is nothing to replay. After it, `withOperationIds()` puts the
3279
+ * ids on a `CandleApiError`/`JsonRpcError` and wraps anything else in a `CandleOperationError`.
3280
+ *
3281
+ * Called once per public method, never nested: an inner step that is itself a one-call method
3282
+ * (launchAtomic()'s build) runs its plain request, so the error is wrapped once, here.
3283
+ */
3284
+ private runOperation;
2828
3285
  private requestJson;
2829
3286
  private parseResponse;
2830
3287
  /**
@@ -2855,7 +3312,7 @@ export declare function __setEvmReceiptWaitForTest(opts: {
2855
3312
  pollMs?: number;
2856
3313
  } | null): void;
2857
3314
  /** This build's own version. Kept in lockstep with package.json by the release-bump CI guard. */
2858
- export declare const SDK_VERSION = "0.4.11";
3315
+ export declare const SDK_VERSION = "0.6.0";
2859
3316
  /** Test seam: the once-per-process latch would otherwise weld the suite's first case to the rest. */
2860
3317
  export declare function __resetSdkUpdateNoticeForTest(): void;
2861
3318
  //# sourceMappingURL=client.d.ts.map