@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
1 lines • 3.15 kB
Source Map (JSON)
{"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results carry a `transactionRequest`, so either is\n * valid input — the helper does not discriminate on `status`.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AACF,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}