UNPKG

@lifi/composer-sdk

Version:

Public Composer SDK for building and submitting flows

40 lines (39 loc) • 1.51 kB
//#region src/run/simulate.ts /** * Assembles a {@link SimulateRequest} from a compile result and the * caller-supplied chain, signer, and tracked balances. Pure: performs no * network I/O, does not mutate its input, and returns a fresh object. * * Bridges the common case — simulate the transaction you just compiled — * without coupling raw-transaction simulation to the flow builder. The * `value` defaults to the compiled transaction's value unless overridden. * * @example * ```ts * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' }); * const req = buildSimulateRequest({ * result: compiled, * chainId: 1, * signer: '0x1111111111111111111111111111111111111111', * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }], * }); * const sim = await sdk.client.simulate(req); * ``` */ const buildSimulateRequest = (input) => { const { result, chainId, signer, trackedBalances, requirements, block } = input; if (result.transactionRequest === void 0) throw new Error("buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating"); return { chainId, from: signer, to: result.transactionRequest.to, data: result.transactionRequest.data, value: input.value ?? result.transactionRequest.value, block, requirements, trackedBalances }; }; //#endregion export { buildSimulateRequest }; //# sourceMappingURL=simulate.js.map