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