@andrewkimjoseph/celina-sdk 0.9.5 → 0.9.6

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Browser-safe prepared-step simulation (no Node analytics / wallet product logic).
3
+ */
4
+ export type { PreparedTx } from "../types/prepared.js";
5
+ export { simulatePreparedStep, type SimulatePreparedStepOptions, type SimulatePreparedStepParams, } from "./simulate-prepared-step.js";
@@ -0,0 +1,2 @@
1
+ export { simulatePreparedStep, } from "./simulate-prepared-step.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/simulation/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,GAGrB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type PublicClient, type StateOverride } from "viem";
2
+ import type { PreparedTx } from "../types/prepared.js";
3
+ /** Optional host overrides for Celo fee abstraction or custom state. */
4
+ export type SimulatePreparedStepOptions = {
5
+ /** Celo fee-abstraction currency — host-provided, never auto-resolved by the SDK. */
6
+ feeCurrency?: `0x${string}`;
7
+ stateOverride?: StateOverride;
8
+ };
9
+ export type SimulatePreparedStepParams = {
10
+ account: `0x${string}`;
11
+ step: PreparedTx;
12
+ };
13
+ /**
14
+ * Simulate a prepared transaction step against current chain state.
15
+ * Throws when the transaction would revert — call immediately before send.
16
+ */
17
+ export declare function simulatePreparedStep(publicClient: PublicClient, params: SimulatePreparedStepParams, options?: SimulatePreparedStepOptions): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import { isInsufficientBalanceSimulationError } from "../utils/transaction-errors.js";
2
+ function stepRequest(account, step) {
3
+ return {
4
+ account,
5
+ to: step.to,
6
+ data: (step.data ?? "0x"),
7
+ value: step.value ? BigInt(step.value) : 0n,
8
+ };
9
+ }
10
+ function simulationErrorMessage(step, cause) {
11
+ const base = cause instanceof Error ? cause.message : String(cause);
12
+ if (isInsufficientBalanceSimulationError(cause)) {
13
+ return (`Simulation failed for "${step.description}": insufficient balance. (${base})`);
14
+ }
15
+ return `Simulation failed for "${step.description}": ${base}`;
16
+ }
17
+ /**
18
+ * Simulate a prepared transaction step against current chain state.
19
+ * Throws when the transaction would revert — call immediately before send.
20
+ */
21
+ export async function simulatePreparedStep(publicClient, params, options) {
22
+ const request = stepRequest(params.account, params.step);
23
+ const stateOverride = options?.stateOverride;
24
+ try {
25
+ if (options?.feeCurrency) {
26
+ await publicClient.estimateGas({
27
+ ...request,
28
+ feeCurrency: options.feeCurrency,
29
+ ...(stateOverride ? { stateOverride } : {}),
30
+ });
31
+ return;
32
+ }
33
+ await publicClient.call({
34
+ ...request,
35
+ ...(stateOverride ? { stateOverride } : {}),
36
+ });
37
+ }
38
+ catch (error) {
39
+ throw new Error(simulationErrorMessage(params.step, error));
40
+ }
41
+ }
42
+ //# sourceMappingURL=simulate-prepared-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate-prepared-step.js","sourceRoot":"","sources":["../../src/simulation/simulate-prepared-step.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oCAAoC,EAAE,MAAM,gCAAgC,CAAC;AActF,SAAS,WAAW,CAClB,OAAsB,EACtB,IAAgB;IAOhB,OAAO;QACL,OAAO;QACP,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAQ;QAChC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;KAC5C,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAgB,EAAE,KAAc;IAC9D,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEpE,IAAI,oCAAoC,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,CACL,0BAA0B,IAAI,CAAC,WAAW,6BAA6B,IAAI,GAAG,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO,0BAA0B,IAAI,CAAC,WAAW,MAAM,IAAI,EAAE,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,YAA0B,EAC1B,MAAkC,EAClC,OAAqC;IAErC,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,CAAC;IAE7C,IAAI,CAAC;QACH,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,MAAM,YAAY,CAAC,WAAW,CAAC;gBAC7B,GAAG,OAAO;gBACV,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACE,CAAC,CAAC;YACjD,OAAO;QACT,CAAC;QAED,MAAM,YAAY,CAAC,IAAI,CAAC;YACtB,GAAG,OAAO;YACV,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5C,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewkimjoseph/celina-sdk",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "Celina SDK — Celo mainnet reads and unsigned transaction preparation for frontend apps.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -31,6 +31,11 @@
31
31
  "types": "./build/oasf/index.d.ts",
32
32
  "import": "./build/oasf/index.js",
33
33
  "default": "./build/oasf/index.js"
34
+ },
35
+ "./simulation": {
36
+ "types": "./build/simulation/index.d.ts",
37
+ "import": "./build/simulation/index.js",
38
+ "default": "./build/simulation/index.js"
34
39
  }
35
40
  },
36
41
  "files": [