@spectratools/tx-shared 0.5.3 → 0.6.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.
@@ -2,6 +2,9 @@ import {
2
2
  TxError
3
3
  } from "./chunk-6T4D5UCR.js";
4
4
 
5
+ // src/execute-tx.ts
6
+ import { sanitizeAttributes, withSpan } from "@spectratools/cli-shared/telemetry";
7
+
5
8
  // src/signers/privy-client.ts
6
9
  import { isAddress } from "viem";
7
10
 
@@ -1000,76 +1003,89 @@ async function executeTx(options) {
1000
1003
  nonce,
1001
1004
  dryRun = false
1002
1005
  } = options;
1003
- let estimatedGas;
1004
- try {
1005
- estimatedGas = await publicClient.estimateContractGas({
1006
- account,
1007
- address,
1008
- abi,
1009
- functionName,
1010
- args,
1011
- value
1012
- });
1013
- } catch (error) {
1014
- throw mapError(error, "estimation");
1015
- }
1016
- let simulationResult;
1017
- try {
1018
- const sim = await publicClient.simulateContract({
1019
- account,
1020
- address,
1021
- abi,
1022
- functionName,
1023
- args,
1024
- value
1025
- });
1026
- simulationResult = sim.result;
1027
- } catch (error) {
1028
- throw mapError(error, "simulation");
1029
- }
1030
- const privyPolicy = await runPrivyPolicyPreflight({
1031
- account,
1032
- address,
1033
- ...value !== void 0 ? { value } : {}
1006
+ const spanAttrs = sanitizeAttributes({
1007
+ "tx.to": address,
1008
+ "tx.function": functionName,
1009
+ "tx.chain_id": chain?.id ?? "unknown",
1010
+ "tx.dry_run": dryRun
1034
1011
  });
1035
- if (dryRun) {
1036
- return {
1037
- status: "dry-run",
1038
- estimatedGas,
1039
- simulationResult,
1040
- ...privyPolicy !== void 0 ? { privyPolicy } : {}
1041
- };
1042
- }
1043
- if (privyPolicy?.status === "blocked") {
1044
- throw toPrivyPolicyViolationError(privyPolicy);
1045
- }
1046
- let hash;
1047
- try {
1048
- hash = await walletClient.writeContract({
1012
+ return withSpan("tx.execute", async (span) => {
1013
+ for (const [k, v] of Object.entries(spanAttrs)) {
1014
+ span.setAttribute(k, v);
1015
+ }
1016
+ let estimatedGas;
1017
+ try {
1018
+ estimatedGas = await publicClient.estimateContractGas({
1019
+ account,
1020
+ address,
1021
+ abi,
1022
+ functionName,
1023
+ args,
1024
+ value
1025
+ });
1026
+ } catch (error) {
1027
+ throw mapError(error, "estimation");
1028
+ }
1029
+ let simulationResult;
1030
+ try {
1031
+ const sim = await publicClient.simulateContract({
1032
+ account,
1033
+ address,
1034
+ abi,
1035
+ functionName,
1036
+ args,
1037
+ value
1038
+ });
1039
+ simulationResult = sim.result;
1040
+ } catch (error) {
1041
+ throw mapError(error, "simulation");
1042
+ }
1043
+ const privyPolicy = await runPrivyPolicyPreflight({
1049
1044
  account,
1050
1045
  address,
1051
- abi,
1052
- functionName,
1053
- args,
1054
- value,
1055
- chain,
1056
- gas: gasLimit ?? estimatedGas,
1057
- maxFeePerGas,
1058
- nonce
1046
+ ...value !== void 0 ? { value } : {}
1059
1047
  });
1060
- } catch (error) {
1061
- throw mapError(error, "submit");
1062
- }
1063
- let receipt;
1064
- try {
1065
- receipt = await publicClient.waitForTransactionReceipt({ hash });
1066
- } catch (error) {
1067
- throw mapError(error, "receipt");
1068
- }
1069
- if (receipt.status === "reverted") {
1070
- throw new TxError("TX_REVERTED", `Transaction ${hash} reverted on-chain`);
1071
- }
1072
- return receiptToTxResult(receipt);
1048
+ if (dryRun) {
1049
+ return {
1050
+ status: "dry-run",
1051
+ estimatedGas,
1052
+ simulationResult,
1053
+ ...privyPolicy !== void 0 ? { privyPolicy } : {}
1054
+ };
1055
+ }
1056
+ if (privyPolicy?.status === "blocked") {
1057
+ throw toPrivyPolicyViolationError(privyPolicy);
1058
+ }
1059
+ let hash;
1060
+ try {
1061
+ hash = await walletClient.writeContract({
1062
+ account,
1063
+ address,
1064
+ abi,
1065
+ functionName,
1066
+ args,
1067
+ value,
1068
+ chain,
1069
+ gas: gasLimit ?? estimatedGas,
1070
+ maxFeePerGas,
1071
+ nonce
1072
+ });
1073
+ } catch (error) {
1074
+ throw mapError(error, "submit");
1075
+ }
1076
+ span.setAttribute("tx.hash", hash);
1077
+ let receipt;
1078
+ try {
1079
+ receipt = await publicClient.waitForTransactionReceipt({ hash });
1080
+ } catch (error) {
1081
+ throw mapError(error, "receipt");
1082
+ }
1083
+ span.setAttribute("tx.status", receipt.status);
1084
+ if (receipt.status === "reverted") {
1085
+ throw new TxError("TX_REVERTED", `Transaction ${hash} reverted on-chain`);
1086
+ }
1087
+ return receiptToTxResult(receipt);
1088
+ });
1073
1089
  }
1074
1090
  function receiptToTxResult(receipt) {
1075
1091
  return {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  executeTx
3
- } from "./chunk-HFRJBEDT.js";
3
+ } from "./chunk-KDM7V64L.js";
4
4
  import "./chunk-6T4D5UCR.js";
5
5
  export {
6
6
  executeTx
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { D as DryRunResult, E as ExecuteTxOptions, a as PrivyNormalizedPolicy, b
7
7
  import { z } from 'incur';
8
8
  import { Address, Hex, Hash, SignableMessage, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable } from 'viem';
9
9
  import { KeyObject } from 'node:crypto';
10
+ export { recordError, sanitizeAttributes, withSpan } from '@spectratools/cli-shared/telemetry';
10
11
 
11
12
  /**
12
13
  * Resolve the active signer provider using deterministic precedence:
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  preflightPrivyTransactionPolicy,
19
19
  serializePrivyAuthorizationPayload,
20
20
  toPrivyPolicyViolationError
21
- } from "./chunk-HFRJBEDT.js";
21
+ } from "./chunk-KDM7V64L.js";
22
22
  import {
23
23
  TxError,
24
24
  toTxError
@@ -138,6 +138,13 @@ function toSignerOptions(flags, env) {
138
138
  ...privyApiUrl !== void 0 ? { privyApiUrl } : {}
139
139
  };
140
140
  }
141
+
142
+ // src/index.ts
143
+ import {
144
+ withSpan,
145
+ recordError,
146
+ sanitizeAttributes
147
+ } from "@spectratools/cli-shared/telemetry";
141
148
  export {
142
149
  TxError,
143
150
  abstractMainnet,
@@ -157,11 +164,14 @@ export {
157
164
  normalizePrivyPolicy,
158
165
  parsePrivyAuthorizationKey,
159
166
  preflightPrivyTransactionPolicy,
167
+ recordError,
160
168
  resolveSigner,
169
+ sanitizeAttributes,
161
170
  serializePrivyAuthorizationPayload,
162
171
  signerEnvSchema,
163
172
  signerFlagSchema,
164
173
  toPrivyPolicyViolationError,
165
174
  toSignerOptions,
166
- toTxError
175
+ toTxError,
176
+ withSpan
167
177
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectratools/tx-shared",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
4
4
  "description": "Shared transaction primitives, signer types, and chain config for spectra tools",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -39,7 +39,8 @@
39
39
  "dependencies": {
40
40
  "incur": "^0.3.0",
41
41
  "ox": "^0.14.0",
42
- "viem": "^2.47.0"
42
+ "viem": "^2.47.0",
43
+ "@spectratools/cli-shared": "0.4.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "typescript": "5.7.3",
@@ -52,7 +53,7 @@
52
53
  "main": "./dist/index.js",
53
54
  "types": "./dist/index.d.ts",
54
55
  "scripts": {
55
- "build": "tsup",
56
+ "build": "pnpm --filter @spectratools/cli-shared run build && tsup",
56
57
  "typecheck": "tsc --noEmit -p tsconfig.json",
57
58
  "test": "vitest run"
58
59
  }