@compass-labs/widgets 0.1.35 → 0.1.36

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.
@@ -88,7 +88,7 @@ function createCompassHandler(config) {
88
88
  case "credit/bundle/prepare":
89
89
  return await handleCreditBundlePrepare(client, body);
90
90
  case "credit/bundle/execute":
91
- return await handleCreditExecute(body, config);
91
+ return await handleCreditExecute(client, body, config);
92
92
  case "credit/transfer":
93
93
  return await handleCreditTransfer(client, body);
94
94
  default:
@@ -1387,31 +1387,11 @@ async function handleCreditTransfer(client, body) {
1387
1387
  primaryType: eip712.primaryType
1388
1388
  });
1389
1389
  }
1390
- var SAFE_EXEC_ABI = [
1391
- {
1392
- name: "execTransaction",
1393
- type: "function",
1394
- inputs: [
1395
- { name: "to", type: "address" },
1396
- { name: "value", type: "uint256" },
1397
- { name: "data", type: "bytes" },
1398
- { name: "operation", type: "uint8" },
1399
- { name: "safeTxGas", type: "uint256" },
1400
- { name: "baseGas", type: "uint256" },
1401
- { name: "gasPrice", type: "uint256" },
1402
- { name: "gasToken", type: "address" },
1403
- { name: "refundReceiver", type: "address" },
1404
- { name: "signatures", type: "bytes" }
1405
- ],
1406
- outputs: [{ name: "success", type: "bool" }],
1407
- stateMutability: "payable"
1408
- }
1409
- ];
1410
- async function handleCreditExecute(body, config) {
1411
- const { eip712, signature, chain = "base", creditAccountAddress } = body;
1390
+ async function handleCreditExecute(client, body, config) {
1391
+ const { owner, eip712, signature, chain = "base" } = body;
1412
1392
  const { gasSponsorPrivateKey, rpcUrls } = config;
1413
- if (!eip712 || !signature || !creditAccountAddress) {
1414
- return jsonResponse({ error: "Missing required parameters (eip712, signature, creditAccountAddress)" }, 400);
1393
+ if (!owner || !eip712 || !signature) {
1394
+ return jsonResponse({ error: "Missing required parameters (owner, eip712, signature)" }, 400);
1415
1395
  }
1416
1396
  if (!gasSponsorPrivateKey) {
1417
1397
  return jsonResponse(
@@ -1437,41 +1417,33 @@ async function handleCreditExecute(body, config) {
1437
1417
  chain: viemChain,
1438
1418
  transport: http(rpcUrl)
1439
1419
  });
1440
- const msg = eip712.message;
1441
- const sigBytes = signature.startsWith("0x") ? signature : `0x${signature}`;
1442
- const execArgs = [
1443
- msg.to,
1444
- BigInt(msg.value),
1445
- msg.data,
1446
- Number(msg.operation),
1447
- BigInt(msg.safeTxGas),
1448
- BigInt(msg.baseGas),
1449
- BigInt(msg.gasPrice),
1450
- msg.gasToken,
1451
- msg.refundReceiver,
1452
- sigBytes
1453
- ];
1454
- await publicClient.simulateContract({
1455
- address: creditAccountAddress,
1456
- abi: SAFE_EXEC_ABI,
1457
- functionName: "execTransaction",
1458
- args: execArgs,
1459
- account: sponsorAccount
1420
+ const response = await client.gasSponsorship.gasSponsorshipPrepare({
1421
+ chain,
1422
+ owner,
1423
+ sender: sponsorAccount.address,
1424
+ eip712,
1425
+ signature,
1426
+ product: "credit"
1460
1427
  });
1461
- const gasEstimate = await publicClient.estimateContractGas({
1462
- address: creditAccountAddress,
1463
- abi: SAFE_EXEC_ABI,
1464
- functionName: "execTransaction",
1465
- args: execArgs,
1466
- account: sponsorAccount
1428
+ const transaction = response.transaction;
1429
+ if (!transaction) {
1430
+ return jsonResponse(
1431
+ { error: "No transaction returned from gas sponsorship prepare" },
1432
+ 500
1433
+ );
1434
+ }
1435
+ const txHash = await walletClient.sendTransaction({
1436
+ to: transaction.to,
1437
+ data: transaction.data,
1438
+ value: transaction.value ? BigInt(transaction.value) : 0n,
1439
+ gas: transaction.gas ? BigInt(transaction.gas) : void 0
1467
1440
  });
1468
- const txHash = await walletClient.writeContract({
1469
- address: creditAccountAddress,
1470
- abi: SAFE_EXEC_ABI,
1471
- functionName: "execTransaction",
1472
- args: execArgs,
1473
- gas: gasEstimate * 130n / 100n
1441
+ const receipt = await publicClient.waitForTransactionReceipt({
1442
+ hash: txHash
1474
1443
  });
1444
+ if (receipt.status === "reverted") {
1445
+ return jsonResponse({ error: "Transaction reverted" }, 500);
1446
+ }
1475
1447
  return jsonResponse({ txHash, success: true });
1476
1448
  }
1477
1449
  async function handleTxReceipt(params, config) {