@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.
- package/dist/index.js +145 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -60
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.js +29 -57
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +29 -57
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -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
|
-
|
|
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 (!
|
|
1416
|
-
return jsonResponse({ error: "Missing required parameters (eip712, signature
|
|
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
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
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
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
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
|
|
1471
|
-
|
|
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) {
|