@lit-protocol/vincent-policy-send-counter 0.1.0 → 0.2.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 (64) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/CONTRIBUTING.md +6 -6
  3. package/README.md +1 -1
  4. package/dist/CHANGELOG.md +22 -0
  5. package/dist/CONTRIBUTING.md +6 -6
  6. package/dist/README.md +1 -1
  7. package/dist/package.json +3 -3
  8. package/dist/src/generated/lit-action.js +2 -2
  9. package/dist/src/generated/vincent-bundled-policy.d.ts +183 -144
  10. package/dist/src/generated/vincent-bundled-policy.d.ts.map +1 -1
  11. package/dist/src/generated/vincent-policy-metadata.json +1 -1
  12. package/dist/src/lib/abi/counterSignatures.d.ts +82 -0
  13. package/dist/src/lib/abi/counterSignatures.d.ts.map +1 -0
  14. package/dist/src/lib/abi/counterSignatures.js +100 -0
  15. package/dist/src/lib/abi/counterSignatures.js.map +1 -0
  16. package/dist/src/lib/helpers/index.d.ts +26 -0
  17. package/dist/src/lib/helpers/index.d.ts.map +1 -0
  18. package/dist/src/lib/helpers/index.js +107 -0
  19. package/dist/src/lib/helpers/index.js.map +1 -0
  20. package/dist/src/lib/schemas.d.ts +115 -64
  21. package/dist/src/lib/schemas.d.ts.map +1 -1
  22. package/dist/src/lib/schemas.js +71 -36
  23. package/dist/src/lib/schemas.js.map +1 -1
  24. package/dist/src/lib/vincent-policy.d.ts +183 -144
  25. package/dist/src/lib/vincent-policy.d.ts.map +1 -1
  26. package/dist/src/lib/vincent-policy.js +145 -74
  27. package/dist/src/lib/vincent-policy.js.map +1 -1
  28. package/package.json +5 -5
  29. package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts +0 -7
  30. package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts.map +0 -1
  31. package/dist/src/lib/policy-helpers/calculate-usd-value.js +0 -22
  32. package/dist/src/lib/policy-helpers/calculate-usd-value.js.map +0 -1
  33. package/dist/src/lib/policy-helpers/check-spending-limit.d.ts +0 -16
  34. package/dist/src/lib/policy-helpers/check-spending-limit.d.ts.map +0 -1
  35. package/dist/src/lib/policy-helpers/check-spending-limit.js +0 -29
  36. package/dist/src/lib/policy-helpers/check-spending-limit.js.map +0 -1
  37. package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts +0 -6
  38. package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts.map +0 -1
  39. package/dist/src/lib/policy-helpers/get-eth-usd-price.js +0 -22
  40. package/dist/src/lib/policy-helpers/get-eth-usd-price.js.map +0 -1
  41. package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts +0 -10
  42. package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts.map +0 -1
  43. package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js +0 -68
  44. package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js.map +0 -1
  45. package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts +0 -15
  46. package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts.map +0 -1
  47. package/dist/src/lib/policy-helpers/get-uniswap-quote.js +0 -114
  48. package/dist/src/lib/policy-helpers/get-uniswap-quote.js.map +0 -1
  49. package/dist/src/lib/policy-helpers/index.d.ts +0 -7
  50. package/dist/src/lib/policy-helpers/index.d.ts.map +0 -1
  51. package/dist/src/lib/policy-helpers/index.js +0 -10
  52. package/dist/src/lib/policy-helpers/index.js.map +0 -1
  53. package/dist/src/lib/policy-helpers/send-spend-tx.d.ts +0 -9
  54. package/dist/src/lib/policy-helpers/send-spend-tx.d.ts.map +0 -1
  55. package/dist/src/lib/policy-helpers/send-spend-tx.js +0 -144
  56. package/dist/src/lib/policy-helpers/send-spend-tx.js.map +0 -1
  57. package/dist/src/lib/policy-helpers/sign-tx.d.ts +0 -3
  58. package/dist/src/lib/policy-helpers/sign-tx.d.ts.map +0 -1
  59. package/dist/src/lib/policy-helpers/sign-tx.js +0 -28
  60. package/dist/src/lib/policy-helpers/sign-tx.js.map +0 -1
  61. package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts +0 -4
  62. package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts.map +0 -1
  63. package/dist/src/lib/policy-helpers/spending-limit-contract.js +0 -22
  64. package/dist/src/lib/policy-helpers/spending-limit-contract.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"vincent-policy.js","sourceRoot":"","sources":["../../../src/lib/vincent-policy.ts"],"names":[],"mappings":";;;AAAA,2EAAwE;AAExE,kEAA6D;AAC7D,gFAAgF;AAChF,uCAUmB;AAcN,QAAA,aAAa,GAAG,IAAA,yCAAmB,EAAC;IAC/C,WAAW,EAAE,6CAAsD;IAEnE,mBAAmB,EAAnB,6BAAmB;IACnB,gBAAgB,EAAhB,0BAAgB;IAChB,kBAAkB,EAAlB,4BAAkB;IAElB,yBAAyB,EAAzB,mCAAyB;IACzB,wBAAwB,EAAxB,kCAAwB;IAExB,qBAAqB,EAArB,+BAAqB;IACrB,oBAAoB,EAApB,8BAAoB;IAEpB,uBAAuB,EAAvB,iCAAuB;IACvB,sBAAsB,EAAtB,gCAAsB;IAEtB,QAAQ,EAAE,KAAK,EACb,EAAE,aAAa,EAAE,UAAU,EAAE,EAC7B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,EAAE,EACxD,EAAE;QACF,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC;QAChF,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC;QACxC,MAAM,EACJ,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,GAAG,aAAa,CAAC;QAClB,MAAM,EAAE,+BAA+B,EAAE,GAAG,UAAU,CAAC;QAEvD,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,6BAA6B,EAAE,GACvE,MAAM,I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ACR,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,iFAAiF,EACjF,KAAK,CACN,CAAC;YACF,8DAA8D;YAC9D,OAAO,KAAK,CAAC;gBACX,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE,YAAY,GAAG,CAAC;gBAC1B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,CAAC,CAAC;aACzD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@lit-protocol/vincent-policy-send-counter",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "dependencies": {
8
- "@uniswap/sdk-core": "^7.7.2",
8
+ "@lit-protocol/vincent-scaffold-sdk": "^1.1.7",
9
9
  "ethers": "^5.8.0",
10
10
  "tslib": "2.8.1",
11
11
  "zod": "^3.25.64",
12
- "@lit-protocol/vincent-ability-sdk": "2.0.0"
12
+ "@lit-protocol/vincent-ability-sdk": "2.1.0"
13
13
  },
14
14
  "peerDependencies": {
15
- "@lit-protocol/vincent-app-sdk": "^2.0.0"
15
+ "@lit-protocol/vincent-app-sdk": "^2.1.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "esbuild": "^0.19.12",
19
- "esbuild-plugin-polyfill-node": "^0.3.0",
19
+ "@lit-protocol/esbuild-plugin-polyfill-node": "^0.3.0",
20
20
  "ipfs-only-hash": "^4.0.0"
21
21
  },
22
22
  "main": "./dist/src/index.js",
@@ -1,7 +0,0 @@
1
- import { ethers } from 'ethers';
2
- export declare const calculateUsdValue: ({ ethRpcUrl, chainlinkPriceFeedAddress, amountInWeth, }: {
3
- ethRpcUrl: string;
4
- chainlinkPriceFeedAddress: string;
5
- amountInWeth: ethers.BigNumber;
6
- }) => Promise<ethers.BigNumber>;
7
- //# sourceMappingURL=calculate-usd-value.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculate-usd-value.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/calculate-usd-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,iBAAiB,GAAU,yDAIrC;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB,EAAE,MAAM,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;CAChC,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAgB3B,CAAC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateUsdValue = void 0;
4
- const ethers_1 = require("ethers");
5
- const get_eth_usd_price_1 = require("./get-eth-usd-price");
6
- const calculateUsdValue = async ({ ethRpcUrl, chainlinkPriceFeedAddress, amountInWeth, }) => {
7
- const ethPriceInUsd = await (0, get_eth_usd_price_1.getEthUsdPriceFromChainlink)({ ethRpcUrl, chainlinkPriceFeedAddress });
8
- // Calculate USD value (8 decimals precision)
9
- const CHAINLINK_DECIMALS = 8;
10
- const WETH_DECIMALS = 18; // WETH decimals
11
- const amountInUsd = amountInWeth
12
- .mul(ethPriceInUsd)
13
- .div(ethers_1.ethers.utils.parseUnits('1', WETH_DECIMALS));
14
- console.log(`Calculate token amount in USDC (calculateUsdValue)`, {
15
- tokenAmountInWeth: ethers_1.ethers.utils.formatUnits(amountInWeth, WETH_DECIMALS),
16
- ethPriceInUsd: ethers_1.ethers.utils.formatUnits(ethPriceInUsd, CHAINLINK_DECIMALS),
17
- tokenAmountInUsd: ethers_1.ethers.utils.formatUnits(amountInUsd, CHAINLINK_DECIMALS),
18
- });
19
- return amountInUsd;
20
- };
21
- exports.calculateUsdValue = calculateUsdValue;
22
- //# sourceMappingURL=calculate-usd-value.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculate-usd-value.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/calculate-usd-value.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,2DAAkE;AAE3D,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,SAAS,EACT,yBAAyB,EACzB,YAAY,GAKb,EAA6B,EAAE;IAC9B,MAAM,aAAa,GAAG,MAAM,IAAA,+CAA2B,EAAC,EAAE,SAAS,EAAE,yBAAyB,EAAE,CAAC,CAAC;IAElG,6CAA6C;IAC7C,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAC7B,MAAM,aAAa,GAAG,EAAE,CAAC,CAAC,gBAAgB;IAC1C,MAAM,WAAW,GAAG,YAAY;SAC7B,GAAG,CAAC,aAAa,CAAC;SAClB,GAAG,CAAC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,oDAAoD,EAAE;QAChE,iBAAiB,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC;QACxE,aAAa,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,kBAAkB,CAAC;QAC1E,gBAAgB,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,kBAAkB,CAAC;KAC5E,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAxBW,QAAA,iBAAiB,qBAwB5B"}
@@ -1,16 +0,0 @@
1
- export declare const checkIfBuyAmountAllowed: ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, buyAmount, maxDailySpendingLimitInUsdCents, pkpEthAddress, appId, }: {
2
- ethRpcUrl: string;
3
- rpcUrlForUniswap: string;
4
- chainIdForUniswap: number;
5
- tokenAddress: `0x${string}`;
6
- tokenDecimals: number;
7
- buyAmount: number;
8
- maxDailySpendingLimitInUsdCents: bigint;
9
- pkpEthAddress: `0x${string}`;
10
- appId: number;
11
- }) => Promise<{
12
- buyAmountAllowed: boolean;
13
- buyAmountInUsd: bigint;
14
- adjustedMaxDailySpendingLimit: bigint;
15
- }>;
16
- //# sourceMappingURL=check-spending-limit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-spending-limit.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/check-spending-limit.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,GAAU,oJAU3C;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B,EAAE,MAAM,CAAC;IACxC,aAAa,EAAE,KAAK,MAAM,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,OAAO,CAAC;IACV,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,6BAA6B,EAAE,MAAM,CAAC;CACvC,CAoCA,CAAC"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkIfBuyAmountAllowed = void 0;
4
- const get_token_amount_in_usd_1 = require("./get-token-amount-in-usd");
5
- const spending_limit_contract_1 = require("./spending-limit-contract");
6
- const checkIfBuyAmountAllowed = async ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, buyAmount, maxDailySpendingLimitInUsdCents, pkpEthAddress, appId, }) => {
7
- const buyAmountInUsd = await (0, get_token_amount_in_usd_1.getTokenAmountInUsd)({
8
- ethRpcUrl,
9
- rpcUrlForUniswap,
10
- chainIdForUniswap,
11
- tokenAddress,
12
- tokenDecimals,
13
- tokenAmount: buyAmount,
14
- });
15
- // maxDailySpendingLimitInUsdCents has 2 decimal precision, but tokenAmountInUsd has 8,
16
- // so we multiply by 10^6 to match the precision
17
- const adjustedMaxDailySpendingLimit = maxDailySpendingLimitInUsdCents * 1000000n;
18
- console.log(`Adjusted maxDailySpendingLimitInUsdCents to 8 decimal precision: ${adjustedMaxDailySpendingLimit.toString()} (spendingLimitPolicyPrecheck)`);
19
- const spendingLimitContract = (0, spending_limit_contract_1.getSpendingLimitContractInstance)();
20
- const buyAmountAllowed = await spendingLimitContract.checkLimit(pkpEthAddress, BigInt(appId), buyAmountInUsd.toBigInt(), adjustedMaxDailySpendingLimit, 86400n);
21
- console.log(`Buy amount allowed: ${JSON.stringify(buyAmountAllowed)} (spendingLimitPolicyPrecheck)`);
22
- return {
23
- buyAmountAllowed,
24
- buyAmountInUsd: buyAmountInUsd.toBigInt(),
25
- adjustedMaxDailySpendingLimit,
26
- };
27
- };
28
- exports.checkIfBuyAmountAllowed = checkIfBuyAmountAllowed;
29
- //# sourceMappingURL=check-spending-limit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-spending-limit.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/check-spending-limit.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAChE,uEAA6E;AAEtE,MAAM,uBAAuB,GAAG,KAAK,EAAE,EAC5C,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,+BAA+B,EAC/B,aAAa,EACb,KAAK,GAWN,EAIE,EAAE;IACH,MAAM,cAAc,GAAG,MAAM,IAAA,6CAAmB,EAAC;QAC/C,SAAS;QACT,gBAAgB;QAChB,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;IAEH,uFAAuF;IACvF,gDAAgD;IAChD,MAAM,6BAA6B,GAAG,+BAA+B,GAAG,QAAU,CAAC;IACnF,OAAO,CAAC,GAAG,CACT,oEAAoE,6BAA6B,CAAC,QAAQ,EAAE,gCAAgC,CAC7I,CAAC;IAEF,MAAM,qBAAqB,GAAG,IAAA,0DAAgC,GAAE,CAAC;IAEjE,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAC7D,aAAa,EACb,MAAM,CAAC,KAAK,CAAC,EACb,cAAc,CAAC,QAAQ,EAAE,EACzB,6BAA6B,EAC7B,MAAM,CACP,CAAC;IAEF,OAAO,CAAC,GAAG,CACT,uBAAuB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,gCAAgC,CACxF,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE;QACzC,6BAA6B;KAC9B,CAAC;AACJ,CAAC,CAAC;AA5DW,QAAA,uBAAuB,2BA4DlC"}
@@ -1,6 +0,0 @@
1
- import { ethers } from 'ethers';
2
- export declare const getEthUsdPriceFromChainlink: ({ chainlinkPriceFeedAddress, ethRpcUrl, }: {
3
- chainlinkPriceFeedAddress: string;
4
- ethRpcUrl: string;
5
- }) => Promise<ethers.BigNumber>;
6
- //# sourceMappingURL=get-eth-usd-price.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-eth-usd-price.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-eth-usd-price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,eAAO,MAAM,2BAA2B,GAAU,2CAG/C;IACD,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAiB3B,CAAC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEthUsdPriceFromChainlink = void 0;
4
- const ethers_1 = require("ethers");
5
- const CHAINLINK_AGGREGATOR_ABI = [
6
- 'function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)',
7
- ];
8
- const getEthUsdPriceFromChainlink = async ({ chainlinkPriceFeedAddress, ethRpcUrl, }) => {
9
- console.log(`Getting ETH price in USD from Chainlink (getEthUsdPriceFromChainlink)`, {
10
- chainlinkPriceFeedAddress,
11
- ethRpcUrl,
12
- });
13
- const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider(ethRpcUrl);
14
- const contract = new ethers_1.ethers.Contract(chainlinkPriceFeedAddress, CHAINLINK_AGGREGATOR_ABI, provider);
15
- const [_, answer] = await contract.latestRoundData();
16
- console.log(`Got ETH price in USD (getEthUsdPriceFromChainlink)`, {
17
- ethPriceInUsd: ethers_1.ethers.utils.formatUnits(answer, 8),
18
- });
19
- return answer;
20
- };
21
- exports.getEthUsdPriceFromChainlink = getEthUsdPriceFromChainlink;
22
- //# sourceMappingURL=get-eth-usd-price.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-eth-usd-price.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-eth-usd-price.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,MAAM,wBAAwB,GAAG;IAC/B,gJAAgJ;CACjJ,CAAC;AAEK,MAAM,2BAA2B,GAAG,KAAK,EAAE,EAChD,yBAAyB,EACzB,SAAS,GAIV,EAA6B,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,uEAAuE,EAAE;QACnF,yBAAyB;QACzB,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,QAAQ,CAClC,yBAAyB,EACzB,wBAAwB,EACxB,QAAQ,CACT,CAAC;IACF,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,oDAAoD,EAAE;QAChE,aAAa,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;KACnD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAvBW,QAAA,2BAA2B,+BAuBtC"}
@@ -1,10 +0,0 @@
1
- import { ethers } from 'ethers';
2
- export declare const getTokenAmountInUsd: ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenAmount, tokenDecimals, }: {
3
- ethRpcUrl: string;
4
- rpcUrlForUniswap: string;
5
- chainIdForUniswap: number;
6
- tokenAddress: string;
7
- tokenDecimals: number;
8
- tokenAmount: number;
9
- }) => Promise<ethers.BigNumber>;
10
- //# sourceMappingURL=get-token-amount-in-usd.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-token-amount-in-usd.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-token-amount-in-usd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAWhC,eAAO,MAAM,mBAAmB,GAAU,+FAOvC;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAiE3B,CAAC"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokenAmountInUsd = void 0;
4
- const ethers_1 = require("ethers");
5
- const calculate_usd_value_1 = require("./calculate-usd-value");
6
- const get_uniswap_quote_1 = require("./get-uniswap-quote");
7
- const ETH_MAINNET_WETH_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
8
- /**
9
- * Source: https://docs.chain.link/data-feeds/price-feeds/addresses/?network=ethereum&page=1&search=ETH%2FUSD
10
- */
11
- const ETH_MAINNET_ETH_USD_CHAINLINK_FEED = '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419';
12
- const getTokenAmountInUsd = async ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenAmount, tokenDecimals, }) => {
13
- console.log(`Getting token amount in USD (getTokenAmountInUsd)`, {
14
- ethRpcUrl,
15
- rpcUrlForUniswap,
16
- chainIdForUniswap,
17
- tokenAddress,
18
- tokenAmount,
19
- tokenDecimals,
20
- ethMainnetWethAddress: ETH_MAINNET_WETH_ADDRESS,
21
- ethMainnetEthUsdChainlinkFeed: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
22
- });
23
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(rpcUrlForUniswap);
24
- const tokenInContract = new ethers_1.ethers.Contract(tokenAddress, ['function symbol() view returns (string)'], provider);
25
- const tokenInSymbol = await tokenInContract.symbol();
26
- console.log(`tokenInSymbol: ${tokenInSymbol} (getTokenAmountInUsd)`);
27
- // Special case for WETH - no need to get a quote since it's already in ETH terms
28
- if (tokenInSymbol.toUpperCase() === 'WETH') {
29
- console.log(`Token is WETH, using amount directly: ${tokenAmount} (getTokenAmountInUsd)`);
30
- const amountInWeth = ethers_1.ethers.utils.parseUnits(tokenAmount.toString(), tokenDecimals);
31
- return (0, calculate_usd_value_1.calculateUsdValue)({
32
- ethRpcUrl,
33
- chainlinkPriceFeedAddress: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
34
- amountInWeth,
35
- });
36
- }
37
- console.log(`Getting price in WETH from Uniswap (getTokenAmountInUsd)`, {
38
- tokenInAddress: tokenAddress,
39
- tokenInDecimals: tokenDecimals,
40
- tokenInAmount: tokenAmount,
41
- tokenOutAddress: ETH_MAINNET_WETH_ADDRESS,
42
- tokenOutDecimals: 18,
43
- rpcUrl: rpcUrlForUniswap,
44
- chainId: chainIdForUniswap,
45
- });
46
- const amountInWeth = await (0, get_uniswap_quote_1.getUniswapQuote)({
47
- tokenInAddress: tokenAddress,
48
- tokenInDecimals: tokenDecimals,
49
- tokenInAmount: tokenAmount,
50
- tokenOutAddress: ETH_MAINNET_WETH_ADDRESS,
51
- tokenOutDecimals: 18,
52
- rpcUrl: rpcUrlForUniswap,
53
- chainId: chainIdForUniswap,
54
- });
55
- // Convert WETH amount to USD
56
- const amountInUsdc = await (0, calculate_usd_value_1.calculateUsdValue)({
57
- ethRpcUrl,
58
- chainlinkPriceFeedAddress: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
59
- amountInWeth: amountInWeth.bestQuote,
60
- });
61
- console.log('Calculated token amount in USDC (getTokenAmountInUsd)', {
62
- amountInWeth: ethers_1.ethers.utils.formatUnits(amountInWeth.bestQuote, 18),
63
- amountInUsdc: ethers_1.ethers.utils.formatUnits(amountInUsdc, 8),
64
- });
65
- return amountInUsdc;
66
- };
67
- exports.getTokenAmountInUsd = getTokenAmountInUsd;
68
- //# sourceMappingURL=get-token-amount-in-usd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-token-amount-in-usd.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-token-amount-in-usd.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,+DAA0D;AAC1D,2DAAsD;AAEtD,MAAM,wBAAwB,GAAG,4CAA4C,CAAC;AAC9E;;GAEG;AACH,MAAM,kCAAkC,GAAG,4CAA4C,CAAC;AAEjF,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,GAQd,EAA6B,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,mDAAmD,EAAE;QAC/D,SAAS;QACT,gBAAgB;QAChB,iBAAiB;QACjB,YAAY;QACZ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;QACxB,OAAO,EAAE,iBAAiB;KAC3B,CAAC,CAAC;IAEH,6BAA6B;IAC7B,MAAM,YAAY,GAAG,MAAM,IAAA,uCAAiB,EAAC;QAC3C,SAAS;QACT,yBAAyB,EAAE,kCAAkC;QAC7D,YAAY,EAAE,YAAY,CAAC,SAAS;KACrC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,uDAAuD,EAAE;QACnE,YAAY,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;QAClE,YAAY,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC;KACxD,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AA/EW,QAAA,mBAAmB,uBA+E9B"}
@@ -1,15 +0,0 @@
1
- import { ethers } from 'ethers';
2
- export declare const getUniswapQuote: ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }: {
3
- rpcUrl: string;
4
- chainId: number;
5
- tokenInAddress: string;
6
- tokenInDecimals: number;
7
- tokenInAmount: number;
8
- tokenOutAddress: string;
9
- tokenOutDecimals: number;
10
- }) => Promise<{
11
- bestQuote: ethers.BigNumber;
12
- bestFee: number;
13
- amountOutMin: ethers.BigNumber;
14
- }>;
15
- //# sourceMappingURL=get-uniswap-quote.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-uniswap-quote.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-uniswap-quote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,eAAO,MAAM,eAAe,GAAU,yGAQnC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,KAAG,OAAO,CAAC;IACV,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;CAChC,CA8HA,CAAC"}
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUniswapQuote = void 0;
4
- const sdk_core_1 = require("@uniswap/sdk-core");
5
- const ethers_1 = require("ethers");
6
- const UNISWAP_V3_QUOTER_INTERFACE = new ethers_1.ethers.utils.Interface([
7
- 'function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96)) external returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)',
8
- ]);
9
- const getUniswapQuote = async ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }) => {
10
- console.log('Getting Uniswap Quote (getUniswapQuote)', {
11
- rpcUrl,
12
- chainId,
13
- tokenInAddress,
14
- tokenInDecimals,
15
- tokenInAmount,
16
- tokenOutAddress,
17
- tokenOutDecimals,
18
- });
19
- const chainAddressMap = sdk_core_1.CHAIN_TO_ADDRESSES_MAP[chainId];
20
- if (chainAddressMap === undefined)
21
- throw new Error(`Unsupported chainId: ${chainId} (getUniswapQuote)`);
22
- if (chainAddressMap.quoterAddress === undefined)
23
- throw new Error(`No Uniswap V3 Quoter Address found for chainId: ${chainId} (getUniswapQuote)`);
24
- const quoterAddress = chainAddressMap.quoterAddress;
25
- console.log(`Using Quoter Address: ${quoterAddress} (getUniswapQuote)`);
26
- const uniswapRpcProvider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
27
- const formattedTokenInAmount = ethers_1.ethers.utils.parseUnits(tokenInAmount.toString(), tokenInDecimals);
28
- console.log('Amount conversion:', {
29
- original: tokenInAmount,
30
- decimals: tokenInDecimals,
31
- wei: formattedTokenInAmount.toString(),
32
- formatted: ethers_1.ethers.utils.formatUnits(formattedTokenInAmount, tokenInDecimals),
33
- });
34
- let bestQuote = null;
35
- let bestFee = null;
36
- const feeTiers = [3000, 500]; // Supported fee tiers (0.3% and 0.05%)
37
- for (const fee of feeTiers) {
38
- try {
39
- const quoteParams = {
40
- tokenIn: tokenInAddress,
41
- tokenOut: tokenOutAddress,
42
- amountIn: formattedTokenInAmount.toString(),
43
- fee,
44
- sqrtPriceLimitX96: 0,
45
- };
46
- console.log(`Attempting quote with fee tier ${fee / 10000}% (getUniswapQuote)`);
47
- console.log('Quote parameters (getUniswapQuote):', quoteParams);
48
- const quote = await uniswapRpcProvider.call({
49
- to: quoterAddress,
50
- data: UNISWAP_V3_QUOTER_INTERFACE.encodeFunctionData('quoteExactInputSingle', [
51
- quoteParams,
52
- ]),
53
- });
54
- console.log('Raw quote response (getUniswapQuote):', quote);
55
- const [amountOut] = UNISWAP_V3_QUOTER_INTERFACE.decodeFunctionResult('quoteExactInputSingle', quote);
56
- const currentQuote = ethers_1.ethers.BigNumber.from(amountOut);
57
- if (currentQuote.isZero()) {
58
- console.log(`Quote is 0 for fee tier ${fee / 10000}% - skipping (getUniswapQuote)`);
59
- continue;
60
- }
61
- const formattedQuote = ethers_1.ethers.utils.formatUnits(currentQuote, tokenOutDecimals);
62
- console.log(`Quote for fee tier ${fee / 10000}% (getUniswapQuote):`, {
63
- raw: currentQuote.toString(),
64
- formatted: formattedQuote,
65
- });
66
- if (!bestQuote || currentQuote.gt(bestQuote)) {
67
- bestQuote = currentQuote;
68
- bestFee = fee;
69
- console.log(`New best quote found with fee tier ${fee / 10000}% (getUniswapQuote): ${formattedQuote}`);
70
- }
71
- }
72
- catch (error) {
73
- const err = error;
74
- // Check if this is an ethers contract error with expected properties
75
- if ('reason' in err && 'message' in err && 'code' in err) {
76
- if (err.reason === 'Unexpected error') {
77
- console.log(`Unexpected error thrown, probably no pool found for fee tier ${fee / 10000}% (getUniswapQuote)`, err);
78
- }
79
- else {
80
- console.log(`Quoter call failed for fee tier ${fee / 10000}% (getUniswapQuote)`, {
81
- message: err.message,
82
- reason: err.reason,
83
- code: err.code,
84
- });
85
- }
86
- continue;
87
- }
88
- else {
89
- throw error;
90
- }
91
- }
92
- }
93
- if (!bestQuote || !bestFee) {
94
- throw new Error('Failed to get quote from Uniswap V3. No valid pool found for this token pair or quote returned 0 (getUniswapQuote)');
95
- }
96
- // Calculate minimum output with 0.5% slippage tolerance
97
- const slippageTolerance = 0.005;
98
- const amountOutMin = bestQuote.mul(1000 - slippageTolerance * 1000).div(1000);
99
- console.log('Final quote details:', {
100
- bestFee: `${bestFee / 10000}%`,
101
- bestQuote: {
102
- raw: bestQuote.toString(),
103
- formatted: ethers_1.ethers.utils.formatUnits(bestQuote, tokenOutDecimals),
104
- },
105
- minimumOutput: {
106
- raw: amountOutMin.toString(),
107
- formatted: ethers_1.ethers.utils.formatUnits(amountOutMin, tokenOutDecimals),
108
- },
109
- slippageTolerance: `${slippageTolerance * 100}%`,
110
- });
111
- return { bestQuote, bestFee, amountOutMin };
112
- };
113
- exports.getUniswapQuote = getUniswapQuote;
114
- //# sourceMappingURL=get-uniswap-quote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-uniswap-quote.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-uniswap-quote.ts"],"names":[],"mappings":";;;AAAA,gDAA2D;AAC3D,mCAAgC;AAEhC,MAAM,2BAA2B,GAAG,IAAI,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC;IAC7D,mPAAmP;CACpP,CAAC,CAAC;AAEI,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,MAAM,EACN,OAAO,EACP,cAAc,EACd,eAAe,EACf,aAAa,EACb,eAAe,EACf,gBAAgB,GASjB,EAIE,EAAE;IACH,OAAO,CAAC,GAAG,CAAC,yCAAyC,E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SAAS,EAAE,gBAAgB,CAAC;SACjE;QACD,aAAa,EAAE;YACb,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE;YAC5B,SAAS,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,gBAAgB,CAAC;SACpE;QACD,iBAAiB,EAAE,GAAG,iBAAiB,GAAG,GAAG,GAAG;KACjD,CAAC,CAAC;IAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAC9C,CAAC,CAAC;AAlJW,QAAA,eAAe,mBAkJ1B"}
@@ -1,7 +0,0 @@
1
- export * from './get-token-amount-in-usd';
2
- export * from './get-uniswap-quote';
3
- export * from './send-spend-tx';
4
- export * from './sign-tx';
5
- export * from './check-spending-limit';
6
- export * from './spending-limit-contract';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./get-token-amount-in-usd"), exports);
5
- tslib_1.__exportStar(require("./get-uniswap-quote"), exports);
6
- tslib_1.__exportStar(require("./send-spend-tx"), exports);
7
- tslib_1.__exportStar(require("./sign-tx"), exports);
8
- tslib_1.__exportStar(require("./check-spending-limit"), exports);
9
- tslib_1.__exportStar(require("./spending-limit-contract"), exports);
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,8DAAoC;AACpC,0DAAgC;AAChC,oDAA0B;AAC1B,iEAAuC;AACvC,oEAA0C"}
@@ -1,9 +0,0 @@
1
- export declare const sendSpendTx: ({ appId, amountSpentUsd, maxSpendingLimitInUsd, spendingLimitDuration, pkpEthAddress, pkpPubKey, }: {
2
- appId: number;
3
- amountSpentUsd: number;
4
- maxSpendingLimitInUsd: number;
5
- spendingLimitDuration: number;
6
- pkpEthAddress: string;
7
- pkpPubKey: string;
8
- }) => Promise<any>;
9
- //# sourceMappingURL=send-spend-tx.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"send-spend-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/send-spend-tx.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW,GAAU,oGAO/B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB,iBAqGA,CAAC"}
@@ -1,144 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendSpendTx = void 0;
4
- const ethers_1 = require("ethers");
5
- const spending_limit_contract_1 = require("./spending-limit-contract");
6
- const sign_tx_1 = require("./sign-tx");
7
- const sendSpendTx = async ({ appId, amountSpentUsd, maxSpendingLimitInUsd, spendingLimitDuration, pkpEthAddress, pkpPubKey, }) => {
8
- const spendingLimitContract = (0, spending_limit_contract_1.getSpendingLimitContractInstance)();
9
- const buildPartialSpendTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'send spend tx gas estimation' }, async () => {
10
- console.log(`Preparing transaction to send to Spending Limit Contract: ${spending_limit_contract_1.SPENDING_LIMIT_CONTRACT_ADDRESS} (sendSpendTx)`);
11
- try {
12
- console.log(`Estimating gas for spending limit transaction...`);
13
- // Get current gas price and nonce
14
- const [feeData, nonce] = await Promise.all([
15
- spendingLimitContract.provider.getFeeData(),
16
- spendingLimitContract.provider.getTransactionCount(pkpEthAddress),
17
- ]);
18
- // Encode function data
19
- const txData = spendingLimitContract.interface.encodeFunctionData('spend', [
20
- BigInt(appId),
21
- BigInt(amountSpentUsd),
22
- BigInt(maxSpendingLimitInUsd),
23
- BigInt(spendingLimitDuration),
24
- ]);
25
- // Estimate gas
26
- const estimatedGas = await spendingLimitContract.estimateGas.spend(BigInt(appId), BigInt(amountSpentUsd), BigInt(maxSpendingLimitInUsd), BigInt(spendingLimitDuration), { from: pkpEthAddress });
27
- console.log('fetching nonce for pkpEthAddress: ', pkpEthAddress, ' (sendSpendTx)');
28
- return JSON.stringify({
29
- status: 'success',
30
- data: txData,
31
- gasLimit: estimatedGas.toString(),
32
- maxFeePerGas: feeData.maxFeePerGas?.toString() || '0',
33
- maxPriorityFeePerGas: feeData.maxPriorityFeePerGas?.toString() || '0',
34
- nonce: nonce.toString(),
35
- });
36
- }
37
- catch (error) {
38
- return attemptToDecodeSpendLimitExceededError(error, spendingLimitContract);
39
- }
40
- });
41
- const parsedBuildPartialSpendTxResponse = JSON.parse(buildPartialSpendTxResponse);
42
- if (parsedBuildPartialSpendTxResponse.status === 'error') {
43
- throw new Error(`Error estimating gas for spending limit transaction: ${parsedBuildPartialSpendTxResponse.error}`);
44
- }
45
- const { gasLimit, maxFeePerGas, maxPriorityFeePerGas, nonce, data } = parsedBuildPartialSpendTxResponse;
46
- // Create ethers Transaction object
47
- const unsignedSpendTx = {
48
- to: spending_limit_contract_1.SPENDING_LIMIT_CONTRACT_ADDRESS,
49
- data: data,
50
- value: ethers_1.ethers.BigNumber.from(0),
51
- gasLimit: ethers_1.ethers.BigNumber.from(gasLimit),
52
- maxFeePerGas: ethers_1.ethers.BigNumber.from(maxFeePerGas),
53
- maxPriorityFeePerGas: ethers_1.ethers.BigNumber.from(maxPriorityFeePerGas),
54
- nonce: Number(nonce),
55
- chainId: 175188,
56
- type: 2, // EIP-1559 transaction type
57
- };
58
- console.log(`Signing spend transaction: ${safeStringify(unsignedSpendTx)} (sendSpendTx)`);
59
- const signedSpendTx = await (0, sign_tx_1.signTx)(pkpPubKey, unsignedSpendTx, 'spendingLimitSig');
60
- console.log(`Broadcasting spend transaction...`);
61
- const spendTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'spendTxSender' }, async () => {
62
- try {
63
- const txResponse = await spendingLimitContract.provider.sendTransaction(signedSpendTx);
64
- return JSON.stringify({
65
- status: 'success',
66
- txHash: txResponse.hash,
67
- });
68
- }
69
- catch (error) {
70
- return attemptToDecodeSpendLimitExceededError(error, spendingLimitContract);
71
- }
72
- });
73
- console.log(`Spend transaction response: ${spendTxResponse} (sendSpendTx)`);
74
- const parsedSpendTxResponse = JSON.parse(spendTxResponse);
75
- if (parsedSpendTxResponse.status === 'error') {
76
- throw new Error(`Error sending spend transaction: ${parsedSpendTxResponse.error}`);
77
- }
78
- return parsedSpendTxResponse.txHash;
79
- };
80
- exports.sendSpendTx = sendSpendTx;
81
- const safeStringify = (obj) => {
82
- return JSON.stringify(obj, (_, value) => {
83
- if (typeof value === 'bigint') {
84
- return value.toString();
85
- }
86
- if (ethers_1.ethers.BigNumber.isBigNumber(value)) {
87
- return value.toString();
88
- }
89
- return value;
90
- });
91
- };
92
- const attemptToDecodeSpendLimitExceededError = (error, contract) => {
93
- try {
94
- // Check if it's an ethers revert error with data
95
- if (error && typeof error === 'object' && 'reason' in error) {
96
- const ethersError = error;
97
- // Try to decode custom error from error data
98
- if (ethersError.data) {
99
- try {
100
- const decoded = contract.interface.parseError(ethersError.data);
101
- if (decoded.name === 'SpendLimitExceeded' && decoded.args) {
102
- const [user, appId, amount, limit] = decoded.args;
103
- return JSON.stringify({
104
- status: 'error',
105
- error: `Spending limit exceeded. User: ${user}, App ID: ${appId.toString()}, Attempted spend amount: ${amount.toString()}, Daily spend limit: ${limit.toString()}`,
106
- });
107
- }
108
- }
109
- catch (parseError) {
110
- // If parsing fails, fall through to generic error handling
111
- }
112
- }
113
- // Handle standard revert with reason string
114
- if (ethersError.reason) {
115
- return JSON.stringify({
116
- status: 'error',
117
- error: `Contract reverted: ${ethersError.reason}`,
118
- });
119
- }
120
- }
121
- // Handle ethers CALL_EXCEPTION errors
122
- if (error && typeof error === 'object' && 'code' in error) {
123
- const ethersError = error;
124
- if (ethersError.code === 'CALL_EXCEPTION' && ethersError.errorArgs) {
125
- const [user, appId, amount, limit] = ethersError.errorArgs;
126
- return JSON.stringify({
127
- status: 'error',
128
- error: `Spending limit exceeded. User: ${user}, App ID: ${appId.toString()}, Attempted spend amount: ${amount.toString()}, Daily spend limit: ${limit.toString()}`,
129
- });
130
- }
131
- }
132
- }
133
- catch (decodingError) {
134
- return JSON.stringify({
135
- status: 'error',
136
- error: `Failed to decode revert reason: ${decodingError}`,
137
- });
138
- }
139
- return JSON.stringify({
140
- status: 'error',
141
- error: error?.toString() || 'Unknown error',
142
- });
143
- };
144
- //# sourceMappingURL=send-spend-tx.js.map