near-safe 0.8.8 → 0.9.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.
Files changed (42) hide show
  1. package/dist/cjs/decode/explain.d.ts +38 -0
  2. package/dist/cjs/decode/explain.js +97 -0
  3. package/dist/cjs/decode/index.d.ts +2 -8
  4. package/dist/cjs/decode/index.js +16 -50
  5. package/dist/cjs/decode/sign-request.d.ts +8 -0
  6. package/dist/cjs/decode/sign-request.js +44 -0
  7. package/dist/cjs/decode/util.d.ts +0 -10
  8. package/dist/cjs/index.d.ts +1 -1
  9. package/dist/cjs/index.js +2 -3
  10. package/dist/cjs/lib/bundler.d.ts +7 -2
  11. package/dist/cjs/lib/bundler.js +8 -12
  12. package/dist/cjs/lib/safe-message.d.ts +1 -3
  13. package/dist/cjs/lib/safe-message.js +0 -30
  14. package/dist/cjs/near-safe.js +2 -2
  15. package/dist/cjs/types/guards.d.ts +6 -0
  16. package/dist/cjs/types/guards.js +90 -0
  17. package/dist/cjs/{types.d.ts → types/index.d.ts} +5 -9
  18. package/dist/cjs/types/index.js +28 -0
  19. package/dist/cjs/util.d.ts +2 -1
  20. package/dist/cjs/util.js +23 -2
  21. package/dist/esm/decode/explain.d.ts +38 -0
  22. package/dist/esm/decode/explain.js +91 -0
  23. package/dist/esm/decode/index.d.ts +2 -8
  24. package/dist/esm/decode/index.js +2 -49
  25. package/dist/esm/decode/sign-request.d.ts +8 -0
  26. package/dist/esm/decode/sign-request.js +41 -0
  27. package/dist/esm/decode/util.d.ts +0 -10
  28. package/dist/esm/index.d.ts +1 -1
  29. package/dist/esm/index.js +1 -1
  30. package/dist/esm/lib/bundler.d.ts +7 -2
  31. package/dist/esm/lib/bundler.js +9 -13
  32. package/dist/esm/lib/safe-message.d.ts +1 -3
  33. package/dist/esm/lib/safe-message.js +1 -29
  34. package/dist/esm/near-safe.js +2 -2
  35. package/dist/esm/types/guards.d.ts +6 -0
  36. package/dist/esm/types/guards.js +83 -0
  37. package/dist/esm/{types.d.ts → types/index.d.ts} +5 -9
  38. package/dist/esm/{types.js → types/index.js} +1 -0
  39. package/dist/esm/util.d.ts +2 -1
  40. package/dist/esm/util.js +22 -2
  41. package/package.json +2 -2
  42. package/dist/cjs/types.js +0 -13
package/dist/esm/util.js CHANGED
@@ -17,13 +17,13 @@ export function packPaymasterData(data) {
17
17
  : "0x");
18
18
  }
19
19
  export function containsValue(transactions) {
20
- return transactions.some((tx) => tx.value !== "0");
20
+ return transactions.some((tx) => BigInt(tx.value) !== 0n);
21
21
  }
22
22
  export async function isContract(address, chainId) {
23
23
  return (await getClient(chainId).getCode({ address })) !== undefined;
24
24
  }
25
25
  export function getClient(chainId) {
26
- // TODO(bh2smith)
26
+ // TODO(bh2smith): Update defailt client URL in viem for sepolia.
27
27
  if (chainId === 11155111) {
28
28
  return createPublicClient({ transport: http(DEFAULT_SETUP_RPC) });
29
29
  }
@@ -130,3 +130,23 @@ export function assertUnique(iterable, errorMessage = "The collection contains m
130
130
  throw new Error(errorMessage);
131
131
  }
132
132
  }
133
+ export function userOpTransactionCost(userOp) {
134
+ // Convert values from hex to decimal
135
+ const preVerificationGas = BigInt(userOp.preVerificationGas);
136
+ const verificationGasLimit = BigInt(userOp.verificationGasLimit);
137
+ const callGasLimit = BigInt(userOp.callGasLimit);
138
+ const paymasterVerificationGasLimit = BigInt(userOp.paymasterVerificationGasLimit || "0x0");
139
+ const paymasterPostOpGasLimit = BigInt(userOp.paymasterPostOpGasLimit || "0x0");
140
+ // Sum total gas
141
+ const totalGasUsed = preVerificationGas +
142
+ verificationGasLimit +
143
+ callGasLimit +
144
+ paymasterVerificationGasLimit +
145
+ paymasterPostOpGasLimit;
146
+ // Convert maxFeePerGas from hex to decimal
147
+ const maxFeePerGas = BigInt(userOp.maxFeePerGas);
148
+ // Calculate total cost in wei
149
+ const totalCostInWei = totalGasUsed * maxFeePerGas;
150
+ // Convert to Ether for a human-readable value
151
+ return totalCostInWei;
152
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.8.8",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "@safe-global/safe-gateway-typescript-sdk": "^3.22.2",
45
45
  "near-api-js": "^5.0.1",
46
- "near-ca": "^0.7.0",
46
+ "near-ca": "^0.7.2",
47
47
  "semver": "^7.6.3",
48
48
  "viem": "^2.21.41"
49
49
  },
package/dist/cjs/types.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OperationType = void 0;
4
- /**
5
- * Enum representing the type of operation in a meta-transaction.
6
- */
7
- var OperationType;
8
- (function (OperationType) {
9
- /** Standard call operation (0). */
10
- OperationType[OperationType["Call"] = 0] = "Call";
11
- /** Delegate call operation (1). */
12
- OperationType[OperationType["DelegateCall"] = 1] = "DelegateCall";
13
- })(OperationType || (exports.OperationType = OperationType = {}));