@lit-protocol/vincent-ability-uniswap-swap 5.0.0 → 7.0.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 (67) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/CHANGELOG.md +45 -0
  3. package/dist/package.json +1 -1
  4. package/dist/src/generated/lit-action.js +2 -2
  5. package/dist/src/generated/vincent-ability-metadata.json +1 -1
  6. package/dist/src/generated/vincent-bundled-ability.d.ts +67 -10
  7. package/dist/src/generated/vincent-bundled-ability.d.ts.map +1 -1
  8. package/dist/src/generated/vincent-prepare-metadata.json +3 -3
  9. package/dist/src/index.d.ts +2 -0
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/index.js +3 -1
  12. package/dist/src/index.js.map +1 -1
  13. package/dist/src/lib/ability-checks/check-erc20-allowance.d.ts +4 -3
  14. package/dist/src/lib/ability-checks/check-erc20-allowance.d.ts.map +1 -1
  15. package/dist/src/lib/ability-checks/check-erc20-allowance.js +24 -10
  16. package/dist/src/lib/ability-checks/check-erc20-allowance.js.map +1 -1
  17. package/dist/src/lib/ability-checks/check-erc20-balance.d.ts +9 -0
  18. package/dist/src/lib/ability-checks/check-erc20-balance.d.ts.map +1 -0
  19. package/dist/src/lib/ability-checks/check-erc20-balance.js +25 -0
  20. package/dist/src/lib/ability-checks/check-erc20-balance.js.map +1 -0
  21. package/dist/src/lib/ability-checks/check-native-token-balance.d.ts +2 -1
  22. package/dist/src/lib/ability-checks/check-native-token-balance.d.ts.map +1 -1
  23. package/dist/src/lib/ability-checks/check-native-token-balance.js +8 -2
  24. package/dist/src/lib/ability-checks/check-native-token-balance.js.map +1 -1
  25. package/dist/src/lib/ability-checks/index.d.ts +1 -1
  26. package/dist/src/lib/ability-checks/index.d.ts.map +1 -1
  27. package/dist/src/lib/ability-checks/index.js +1 -1
  28. package/dist/src/lib/ability-checks/index.js.map +1 -1
  29. package/dist/src/lib/ability-helpers/get-erc20-allowance.d.ts +8 -0
  30. package/dist/src/lib/ability-helpers/get-erc20-allowance.d.ts.map +1 -0
  31. package/dist/src/lib/ability-helpers/get-erc20-allowance.js +10 -0
  32. package/dist/src/lib/ability-helpers/get-erc20-allowance.js.map +1 -0
  33. package/dist/src/lib/{ability-checks/getErc20Contract.d.ts → ability-helpers/get-erc20-contract.d.ts} +2 -2
  34. package/dist/src/lib/ability-helpers/get-erc20-contract.d.ts.map +1 -0
  35. package/dist/src/lib/{ability-checks/getErc20Contract.js → ability-helpers/get-erc20-contract.js} +1 -1
  36. package/dist/src/lib/ability-helpers/get-erc20-contract.js.map +1 -0
  37. package/dist/src/lib/ability-helpers/index.d.ts +2 -0
  38. package/dist/src/lib/ability-helpers/index.d.ts.map +1 -1
  39. package/dist/src/lib/ability-helpers/index.js +2 -0
  40. package/dist/src/lib/ability-helpers/index.js.map +1 -1
  41. package/dist/src/lib/ability-helpers/send-erc20-approval-tx.d.ts +15 -0
  42. package/dist/src/lib/ability-helpers/send-erc20-approval-tx.d.ts.map +1 -0
  43. package/dist/src/lib/ability-helpers/send-erc20-approval-tx.js +86 -0
  44. package/dist/src/lib/ability-helpers/send-erc20-approval-tx.js.map +1 -0
  45. package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts +4 -1
  46. package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts.map +1 -1
  47. package/dist/src/lib/ability-helpers/send-uniswap-tx.js +16 -1
  48. package/dist/src/lib/ability-helpers/send-uniswap-tx.js.map +1 -1
  49. package/dist/src/lib/schemas.d.ts +67 -9
  50. package/dist/src/lib/schemas.d.ts.map +1 -1
  51. package/dist/src/lib/schemas.js +70 -12
  52. package/dist/src/lib/schemas.js.map +1 -1
  53. package/dist/src/lib/types.d.ts +44 -0
  54. package/dist/src/lib/types.d.ts.map +1 -0
  55. package/dist/src/lib/types.js +10 -0
  56. package/dist/src/lib/types.js.map +1 -0
  57. package/dist/src/lib/vincent-ability.d.ts +67 -10
  58. package/dist/src/lib/vincent-ability.d.ts.map +1 -1
  59. package/dist/src/lib/vincent-ability.js +178 -46
  60. package/dist/src/lib/vincent-ability.js.map +1 -1
  61. package/package.json +4 -4
  62. package/dist/src/lib/ability-checks/check-token-in-balance.d.ts +0 -8
  63. package/dist/src/lib/ability-checks/check-token-in-balance.d.ts.map +0 -1
  64. package/dist/src/lib/ability-checks/check-token-in-balance.js +0 -17
  65. package/dist/src/lib/ability-checks/check-token-in-balance.js.map +0 -1
  66. package/dist/src/lib/ability-checks/getErc20Contract.d.ts.map +0 -1
  67. package/dist/src/lib/ability-checks/getErc20Contract.js.map +0 -1
@@ -1,3 +1,3 @@
1
1
  {
2
- "ipfsCid": "QmTvPwj165nh8ps6Zxfi6yhS4qpb5aQQGV5vj7i4Zfp5cV"
2
+ "ipfsCid": "QmWf9R5ctPJrXXTP5SLuJbcbjQoF8FBwNAiWH2KNHSyRZ7"
3
3
  }
@@ -2,6 +2,7 @@
2
2
  * DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
3
3
  */
4
4
  export declare const bundledVincentAbility: import("@lit-protocol/vincent-ability-sdk").BundledVincentAbility<import("@lit-protocol/vincent-ability-sdk").VincentAbility<import("zod").ZodObject<{
5
+ action: import("zod").ZodEnum<["approve", "swap", "approveAndSwap"]>;
5
6
  rpcUrlForUniswap: import("zod").ZodString;
6
7
  signedUniswapQuote: import("zod").ZodObject<{
7
8
  quote: import("zod").ZodObject<{
@@ -90,7 +91,12 @@ export declare const bundledVincentAbility: import("@lit-protocol/vincent-abilit
90
91
  }>;
91
92
  gasBufferPercentage: import("zod").ZodOptional<import("zod").ZodNumber>;
92
93
  baseFeePerGasBufferPercentage: import("zod").ZodOptional<import("zod").ZodNumber>;
94
+ alchemyGasSponsor: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
95
+ alchemyGasSponsorApiKey: import("zod").ZodOptional<import("zod").ZodString>;
96
+ alchemyGasSponsorPolicyId: import("zod").ZodOptional<import("zod").ZodString>;
93
97
  }, "strip", import("zod").ZodTypeAny, {
98
+ alchemyGasSponsor: boolean;
99
+ action: "swap" | "approve" | "approveAndSwap";
94
100
  rpcUrlForUniswap: string;
95
101
  signedUniswapQuote: {
96
102
  quote: {
@@ -113,7 +119,10 @@ export declare const bundledVincentAbility: import("@lit-protocol/vincent-abilit
113
119
  };
114
120
  gasBufferPercentage?: number | undefined;
115
121
  baseFeePerGasBufferPercentage?: number | undefined;
122
+ alchemyGasSponsorApiKey?: string | undefined;
123
+ alchemyGasSponsorPolicyId?: string | undefined;
116
124
  }, {
125
+ action: "swap" | "approve" | "approveAndSwap";
117
126
  rpcUrlForUniswap: string;
118
127
  signedUniswapQuote: {
119
128
  quote: {
@@ -136,26 +145,74 @@ export declare const bundledVincentAbility: import("@lit-protocol/vincent-abilit
136
145
  };
137
146
  gasBufferPercentage?: number | undefined;
138
147
  baseFeePerGasBufferPercentage?: number | undefined;
148
+ alchemyGasSponsor?: boolean | undefined;
149
+ alchemyGasSponsorApiKey?: string | undefined;
150
+ alchemyGasSponsorPolicyId?: string | undefined;
139
151
  }>, string, import("@lit-protocol/vincent-ability-sdk/internal").AbilityPolicyMap<readonly [], never>, {}, import("zod").ZodObject<{
140
- swapTxHash: import("zod").ZodString;
152
+ swapTxHash: import("zod").ZodOptional<import("zod").ZodString>;
153
+ swapTxUserOperationHash: import("zod").ZodOptional<import("zod").ZodString>;
154
+ approvalTxHash: import("zod").ZodOptional<import("zod").ZodString>;
155
+ approvalTxUserOperationHash: import("zod").ZodOptional<import("zod").ZodString>;
156
+ currentAllowance: import("zod").ZodOptional<import("zod").ZodString>;
141
157
  }, "strip", import("zod").ZodTypeAny, {
142
- swapTxHash: string;
158
+ currentAllowance?: string | undefined;
159
+ swapTxHash?: string | undefined;
160
+ swapTxUserOperationHash?: string | undefined;
161
+ approvalTxHash?: string | undefined;
162
+ approvalTxUserOperationHash?: string | undefined;
143
163
  }, {
144
- swapTxHash: string;
164
+ currentAllowance?: string | undefined;
165
+ swapTxHash?: string | undefined;
166
+ swapTxUserOperationHash?: string | undefined;
167
+ approvalTxHash?: string | undefined;
168
+ approvalTxUserOperationHash?: string | undefined;
145
169
  }>, import("zod").ZodObject<{
146
170
  reason: import("zod").ZodOptional<import("zod").ZodString>;
147
171
  }, "strip", import("zod").ZodTypeAny, {
148
172
  reason?: string | undefined;
149
173
  }, {
150
174
  reason?: string | undefined;
151
- }>, import("zod").ZodUndefined, import("zod").ZodObject<{
152
- reason: import("zod").ZodOptional<import("zod").ZodString>;
153
- erc20SpenderAddress: import("zod").ZodOptional<import("zod").ZodString>;
175
+ }>, import("zod").ZodObject<{
176
+ nativeTokenBalance: import("zod").ZodOptional<import("zod").ZodString>;
177
+ tokenInAddress: import("zod").ZodOptional<import("zod").ZodString>;
178
+ tokenInBalance: import("zod").ZodOptional<import("zod").ZodString>;
179
+ currentTokenInAllowanceForSpender: import("zod").ZodString;
180
+ spenderAddress: import("zod").ZodString;
154
181
  }, "strip", import("zod").ZodTypeAny, {
155
- reason?: string | undefined;
156
- erc20SpenderAddress?: string | undefined;
182
+ spenderAddress: string;
183
+ currentTokenInAllowanceForSpender: string;
184
+ tokenInAddress?: string | undefined;
185
+ nativeTokenBalance?: string | undefined;
186
+ tokenInBalance?: string | undefined;
157
187
  }, {
158
- reason?: string | undefined;
159
- erc20SpenderAddress?: string | undefined;
188
+ spenderAddress: string;
189
+ currentTokenInAllowanceForSpender: string;
190
+ tokenInAddress?: string | undefined;
191
+ nativeTokenBalance?: string | undefined;
192
+ tokenInBalance?: string | undefined;
193
+ }>, import("zod").ZodObject<{
194
+ reason: import("zod").ZodString;
195
+ spenderAddress: import("zod").ZodOptional<import("zod").ZodString>;
196
+ tokenAddress: import("zod").ZodOptional<import("zod").ZodString>;
197
+ requiredTokenAmount: import("zod").ZodOptional<import("zod").ZodString>;
198
+ tokenBalance: import("zod").ZodOptional<import("zod").ZodString>;
199
+ currentAllowance: import("zod").ZodOptional<import("zod").ZodString>;
200
+ requiredAllowance: import("zod").ZodOptional<import("zod").ZodString>;
201
+ }, "strip", import("zod").ZodTypeAny, {
202
+ reason: string;
203
+ tokenAddress?: string | undefined;
204
+ requiredTokenAmount?: string | undefined;
205
+ tokenBalance?: string | undefined;
206
+ requiredAllowance?: string | undefined;
207
+ spenderAddress?: string | undefined;
208
+ currentAllowance?: string | undefined;
209
+ }, {
210
+ reason: string;
211
+ tokenAddress?: string | undefined;
212
+ requiredTokenAmount?: string | undefined;
213
+ tokenBalance?: string | undefined;
214
+ requiredAllowance?: string | undefined;
215
+ spenderAddress?: string | undefined;
216
+ currentAllowance?: string | undefined;
160
217
  }>>, string>;
161
218
  //# sourceMappingURL=vincent-bundled-ability.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vincent-bundled-ability.d.ts","sourceRoot":"","sources":["../../../src/generated/vincent-bundled-ability.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAA4D,CAAC"}
1
+ {"version":3,"file":"vincent-bundled-ability.d.ts","sourceRoot":"","sources":["../../../src/generated/vincent-bundled-ability.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAA4D,CAAC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ipfsCid": "QmTHxA1szqumjfndvB8D59qRPhrhMsJWr6jTq81RFeaf1D",
3
- "pkpTokenId": "44317236434387694874531930309258310489704884861516325543415539434780397033801",
4
- "pkpPublicKey": "0x04c2aed3bbbe57674ec7a0b2e094d8e365415508dd9725bf1b7c8a526e58a75c2e7f2a830a50ac7fc5d26610ba23ad81be1eb8a032f3f813db67d2324df6ecd650",
5
- "pkpEthAddress": "0xa7A476c03a04C1aa86Ad2319594376a124E7f598"
3
+ "pkpTokenId": "76098143227047229486816515135507601076492967288630594604111588574212664320176",
4
+ "pkpPublicKey": "0x0491b71bc50fccc210953141b1f824fae69f7caa8a8f3e77e242f098431ba9b4be971785af76880892c2f963bfa3700aab35bc00b8bede798d0f956d343e11b343",
5
+ "pkpEthAddress": "0x4751ECc8c2918BAbD35ef44eE6759A05Ef110CAE"
6
6
  }
@@ -2,4 +2,6 @@ export { bundledVincentAbility } from './generated/vincent-bundled-ability';
2
2
  export { getSignedUniswapQuote } from './lib/prepare/get-signed-uniswap-quote';
3
3
  export { validateSignedUniswapQuote } from './lib/prepare/validate-signed-uniswap-quote';
4
4
  export type * from './lib/prepare/types';
5
+ export type { CheckNativeTokenBalanceResult, CheckNativeTokenBalanceResultSuccess, CheckNativeTokenBalanceResultFailure, CheckErc20BalanceResult, CheckErc20BalanceResultSuccess, CheckErc20BalanceResultFailure, CheckErc20AllowanceResult, CheckErc20AllowanceResultSuccess, CheckErc20AllowanceResultFailure, } from './lib/types';
6
+ export { AbilityAction } from './lib/types';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,mBAAmB,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,mBAAmB,qBAAqB,CAAC;AACzC,YAAY,EACV,6BAA6B,EAC7B,oCAAoC,EACpC,oCAAoC,EACpC,uBAAuB,EACvB,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,gCAAgC,EAChC,gCAAgC,GACjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSignedUniswapQuote = exports.getSignedUniswapQuote = exports.bundledVincentAbility = void 0;
3
+ exports.AbilityAction = exports.validateSignedUniswapQuote = exports.getSignedUniswapQuote = exports.bundledVincentAbility = void 0;
4
4
  var vincent_bundled_ability_1 = require("./generated/vincent-bundled-ability");
5
5
  Object.defineProperty(exports, "bundledVincentAbility", { enumerable: true, get: function () { return vincent_bundled_ability_1.bundledVincentAbility; } });
6
6
  var get_signed_uniswap_quote_1 = require("./lib/prepare/get-signed-uniswap-quote");
7
7
  Object.defineProperty(exports, "getSignedUniswapQuote", { enumerable: true, get: function () { return get_signed_uniswap_quote_1.getSignedUniswapQuote; } });
8
8
  var validate_signed_uniswap_quote_1 = require("./lib/prepare/validate-signed-uniswap-quote");
9
9
  Object.defineProperty(exports, "validateSignedUniswapQuote", { enumerable: true, get: function () { return validate_signed_uniswap_quote_1.validateSignedUniswapQuote; } });
10
+ var types_1 = require("./lib/types");
11
+ Object.defineProperty(exports, "AbilityAction", { enumerable: true, get: function () { return types_1.AbilityAction; } });
10
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA4E;AAAnE,gIAAA,qBAAqB,OAAA;AAC9B,mFAA+E;AAAtE,iIAAA,qBAAqB,OAAA;AAC9B,6FAAyF;AAAhF,2IAAA,0BAA0B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA4E;AAAnE,gIAAA,qBAAqB,OAAA;AAC9B,mFAA+E;AAAtE,iIAAA,qBAAqB,OAAA;AAC9B,6FAAyF;AAAhF,2IAAA,0BAA0B,OAAA;AAanC,qCAA4C;AAAnC,sGAAA,aAAa,OAAA"}
@@ -1,9 +1,10 @@
1
1
  import { ethers } from 'ethers';
2
- export declare const checkErc20Allowance: ({ provider, tokenAddress, owner, spender, tokenAmount, }: {
2
+ import { CheckErc20AllowanceResult } from '../types';
3
+ export declare const checkErc20Allowance: ({ provider, tokenAddress, owner, spender, requiredAllowance, }: {
3
4
  provider: ethers.providers.StaticJsonRpcProvider;
4
5
  tokenAddress: string;
5
6
  owner: string;
6
7
  spender: string;
7
- tokenAmount: bigint;
8
- }) => Promise<ethers.BigNumber>;
8
+ requiredAllowance: ethers.BigNumber;
9
+ }) => Promise<CheckErc20AllowanceResult>;
9
10
  //# sourceMappingURL=check-erc20-allowance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-erc20-allowance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,mBAAmB,GAAU,0DAMvC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAe3B,CAAC"}
1
+ {"version":3,"file":"check-erc20-allowance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,mBAAmB,GAAU,gEAMvC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC,SAAS,CAAC;CACrC,KAAG,OAAO,CAAC,yBAAyB,CA0BpC,CAAC"}
@@ -1,17 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkErc20Allowance = void 0;
4
- const ethers_1 = require("ethers");
5
- const getErc20Contract_1 = require("./getErc20Contract");
6
- const checkErc20Allowance = async ({ provider, tokenAddress, owner, spender, tokenAmount, }) => {
7
- const contract = (0, getErc20Contract_1.getErc20Contract)(tokenAddress, provider);
8
- const currentAllowance = await contract.allowance(owner, spender);
9
- // Convert bigint to BigNumber for comparison
10
- const tokenAmountBN = ethers_1.ethers.BigNumber.from(tokenAmount.toString());
11
- if (currentAllowance.lt(tokenAmountBN)) {
12
- throw new Error(`Address ${owner} has insufficient ERC20 allowance for spender ${spender} for token ${tokenAddress} (checkErc20Allowance)`);
4
+ const get_erc20_allowance_1 = require("../ability-helpers/get-erc20-allowance");
5
+ const checkErc20Allowance = async ({ provider, tokenAddress, owner, spender, requiredAllowance, }) => {
6
+ const currentAllowance = await (0, get_erc20_allowance_1.getErc20Allowance)({
7
+ provider,
8
+ tokenAddress,
9
+ owner,
10
+ spender,
11
+ });
12
+ if (currentAllowance.lt(requiredAllowance)) {
13
+ return {
14
+ success: false,
15
+ reason: `[checkErc20Allowance] Address ${owner} has insufficient ERC20 allowance for spender ${spender} for token ${tokenAddress}`,
16
+ spenderAddress: spender,
17
+ tokenAddress: tokenAddress,
18
+ requiredAllowance,
19
+ currentAllowance,
20
+ };
13
21
  }
14
- return currentAllowance;
22
+ return {
23
+ success: true,
24
+ spenderAddress: spender,
25
+ tokenAddress: tokenAddress,
26
+ requiredAllowance,
27
+ currentAllowance,
28
+ };
15
29
  };
16
30
  exports.checkErc20Allowance = checkErc20Allowance;
17
31
  //# sourceMappingURL=check-erc20-allowance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-erc20-allowance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-allowance.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,yDAAsD;AAE/C,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,WAAW,GAOZ,EAA6B,EAAE;IAC9B,MAAM,QAAQ,GAAG,IAAA,mCAAgB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAE1D,MAAM,gBAAgB,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAElE,6CAA6C;IAC7C,MAAM,aAAa,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEpE,IAAI,gBAAgB,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,WAAW,KAAK,iDAAiD,OAAO,cAAc,YAAY,wBAAwB,CAC3H,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AA3BW,QAAA,mBAAmB,uBA2B9B"}
1
+ {"version":3,"file":"check-erc20-allowance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-allowance.ts"],"names":[],"mappings":";;;AAEA,gFAA2E;AAGpE,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,iBAAiB,GAOlB,EAAsC,EAAE;IACvC,MAAM,gBAAgB,GAAG,MAAM,IAAA,uCAAiB,EAAC;QAC/C,QAAQ;QACR,YAAY;QACZ,KAAK;QACL,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,gBAAgB,CAAC,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAC3C,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,iCAAiC,KAAK,iDAAiD,OAAO,cAAc,YAAY,EAAE;YAClI,cAAc,EAAE,OAAO;YACvB,YAAY,EAAE,YAAY;YAC1B,iBAAiB;YACjB,gBAAgB;SACjB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,OAAO;QACvB,YAAY,EAAE,YAAY;QAC1B,iBAAiB;QACjB,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC;AAtCW,QAAA,mBAAmB,uBAsC9B"}
@@ -0,0 +1,9 @@
1
+ import { ethers } from 'ethers';
2
+ import { CheckErc20BalanceResult } from '../types';
3
+ export declare const checkErc20Balance: ({ provider, pkpEthAddress, tokenAddress, requiredTokenAmount, }: {
4
+ provider: ethers.providers.StaticJsonRpcProvider;
5
+ pkpEthAddress: string;
6
+ tokenAddress: string;
7
+ requiredTokenAmount: ethers.BigNumber;
8
+ }) => Promise<CheckErc20BalanceResult>;
9
+ //# sourceMappingURL=check-erc20-balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-erc20-balance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAEnD,eAAO,MAAM,iBAAiB,GAAU,iEAKrC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC,SAAS,CAAC;CACvC,KAAG,OAAO,CAAC,uBAAuB,CAqBlC,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkErc20Balance = void 0;
4
+ const get_erc20_contract_1 = require("../ability-helpers/get-erc20-contract");
5
+ const checkErc20Balance = async ({ provider, pkpEthAddress, tokenAddress, requiredTokenAmount, }) => {
6
+ const contract = (0, get_erc20_contract_1.getErc20Contract)(tokenAddress, provider);
7
+ const tokenBalance = await contract.balanceOf(pkpEthAddress);
8
+ if (tokenBalance.lt(requiredTokenAmount)) {
9
+ return {
10
+ success: false,
11
+ reason: `pkpEthAddress (${pkpEthAddress}) has insufficient balance of tokenIn (${tokenAddress}). Wanted ${requiredTokenAmount}, but only have ${tokenBalance}`,
12
+ tokenAddress,
13
+ requiredTokenAmount,
14
+ tokenBalance,
15
+ };
16
+ }
17
+ return {
18
+ success: true,
19
+ tokenAddress,
20
+ requiredTokenAmount,
21
+ tokenBalance,
22
+ };
23
+ };
24
+ exports.checkErc20Balance = checkErc20Balance;
25
+ //# sourceMappingURL=check-erc20-balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-erc20-balance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-erc20-balance.ts"],"names":[],"mappings":";;;AAEA,8EAAyE;AAGlE,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,mBAAmB,GAMpB,EAAoC,EAAE;IACrC,MAAM,QAAQ,GAAG,IAAA,qCAAgB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAE1D,MAAM,YAAY,GAAqB,MAAM,QAAQ,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAE/E,IAAI,YAAY,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACzC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,kBAAkB,aAAa,0CAA0C,YAAY,aAAa,mBAAmB,mBAAmB,YAAY,EAAE;YAC9J,YAAY;YACZ,mBAAmB;YACnB,YAAY;SACb,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,YAAY;QACZ,mBAAmB;QACnB,YAAY;KACb,CAAC;AACJ,CAAC,CAAC;AA/BW,QAAA,iBAAiB,qBA+B5B"}
@@ -1,6 +1,7 @@
1
1
  import { ethers } from 'ethers';
2
+ import { CheckNativeTokenBalanceResult } from '../types';
2
3
  export declare const checkNativeTokenBalance: ({ provider, pkpEthAddress, }: {
3
4
  provider: ethers.providers.Provider;
4
5
  pkpEthAddress: string;
5
- }) => Promise<ethers.BigNumber>;
6
+ }) => Promise<CheckNativeTokenBalanceResult>;
6
7
  //# sourceMappingURL=check-native-token-balance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-native-token-balance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-native-token-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,uBAAuB,GAAU,8BAG3C;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB,8BAUA,CAAC"}
1
+ {"version":3,"file":"check-native-token-balance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-native-token-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAEzD,eAAO,MAAM,uBAAuB,GAAU,8BAG3C;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;CACvB,KAAG,OAAO,CAAC,6BAA6B,CAcxC,CAAC"}
@@ -4,9 +4,15 @@ exports.checkNativeTokenBalance = void 0;
4
4
  const checkNativeTokenBalance = async ({ provider, pkpEthAddress, }) => {
5
5
  const ethBalance = await provider.getBalance(pkpEthAddress);
6
6
  if (ethBalance.isZero()) {
7
- throw new Error(`pkpEthAddress (${pkpEthAddress}) has zero native token balance (UniswapSwapAbilityPrecheck)`);
7
+ return {
8
+ success: false,
9
+ reason: `pkpEthAddress (${pkpEthAddress}) has zero native token balance (UniswapSwapAbilityPrecheck)`,
10
+ };
8
11
  }
9
- return ethBalance;
12
+ return {
13
+ success: true,
14
+ ethBalance,
15
+ };
10
16
  };
11
17
  exports.checkNativeTokenBalance = checkNativeTokenBalance;
12
18
  //# sourceMappingURL=check-native-token-balance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-native-token-balance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-native-token-balance.ts"],"names":[],"mappings":";;;AAEO,MAAM,uBAAuB,GAAG,KAAK,EAAE,EAC5C,QAAQ,EACR,aAAa,GAId,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAE5D,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,kBAAkB,aAAa,8DAA8D,CAC9F,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAhBW,QAAA,uBAAuB,2BAgBlC"}
1
+ {"version":3,"file":"check-native-token-balance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-native-token-balance.ts"],"names":[],"mappings":";;;AAIO,MAAM,uBAAuB,GAAG,KAAK,EAAE,EAC5C,QAAQ,EACR,aAAa,GAId,EAA0C,EAAE;IAC3C,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAE5D,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;QACxB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,kBAAkB,aAAa,8DAA8D;SACtG,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,uBAAuB,2BAoBlC"}
@@ -1,4 +1,4 @@
1
1
  export * from './check-native-token-balance';
2
- export * from './check-token-in-balance';
2
+ export * from './check-erc20-balance';
3
3
  export * from './check-erc20-allowance';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./check-native-token-balance"), exports);
5
- tslib_1.__exportStar(require("./check-token-in-balance"), exports);
5
+ tslib_1.__exportStar(require("./check-erc20-balance"), exports);
6
6
  tslib_1.__exportStar(require("./check-erc20-allowance"), exports);
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,mEAAyC;AACzC,kEAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,gEAAsC;AACtC,kEAAwC"}
@@ -0,0 +1,8 @@
1
+ import { ethers } from 'ethers';
2
+ export declare const getErc20Allowance: ({ provider, tokenAddress, owner, spender, }: {
3
+ provider: ethers.providers.JsonRpcProvider;
4
+ tokenAddress: string;
5
+ owner: string;
6
+ spender: string;
7
+ }) => Promise<ethers.BigNumber>;
8
+ //# sourceMappingURL=get-erc20-allowance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-erc20-allowance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-erc20-allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,iBAAiB,GAAU,6CAKrC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAG3B,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErc20Allowance = void 0;
4
+ const get_erc20_contract_1 = require("./get-erc20-contract");
5
+ const getErc20Allowance = async ({ provider, tokenAddress, owner, spender, }) => {
6
+ const contract = (0, get_erc20_contract_1.getErc20Contract)(tokenAddress, provider);
7
+ return await contract.allowance(owner, spender);
8
+ };
9
+ exports.getErc20Allowance = getErc20Allowance;
10
+ //# sourceMappingURL=get-erc20-allowance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-erc20-allowance.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-erc20-allowance.ts"],"names":[],"mappings":";;;AAEA,6DAAwD;AAEjD,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,GAMR,EAA6B,EAAE;IAC9B,MAAM,QAAQ,GAAG,IAAA,qCAAgB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC1D,OAAO,MAAM,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B"}
@@ -1,4 +1,4 @@
1
1
  import { ethers } from 'ethers';
2
2
  export declare const ERC20_ABI: string[];
3
- export declare function getErc20Contract(tokenAddress: string, provider: ethers.providers.StaticJsonRpcProvider): ethers.Contract;
4
- //# sourceMappingURL=getErc20Contract.d.ts.map
3
+ export declare function getErc20Contract(tokenAddress: string, provider: ethers.providers.JsonRpcProvider): ethers.Contract;
4
+ //# sourceMappingURL=get-erc20-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-erc20-contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-erc20-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,SAAS,UAUrB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,eAAe,mBAEhG"}
@@ -17,4 +17,4 @@ exports.ERC20_ABI = [
17
17
  function getErc20Contract(tokenAddress, provider) {
18
18
  return new ethers_1.ethers.Contract(tokenAddress, exports.ERC20_ABI, provider);
19
19
  }
20
- //# sourceMappingURL=getErc20Contract.js.map
20
+ //# sourceMappingURL=get-erc20-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-erc20-contract.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-erc20-contract.ts"],"names":[],"mappings":";;;AAcA,4CAEC;AAhBD,mCAAgC;AAEnB,QAAA,SAAS,GAAG;IACvB,mEAAmE;IACnE,2EAA2E;IAC3E,oFAAoF;IACpF,0CAA0C;IAC1C,wDAAwD;IACxD,uEAAuE;IACvE,yFAAyF;IACzF,gDAAgD;IAChD,kDAAkD;CACnD,CAAC;AAEF,SAAgB,gBAAgB,CAAC,YAAoB,EAAE,QAA0C;IAC/F,OAAO,IAAI,eAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,iBAAS,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC"}
@@ -2,4 +2,6 @@ export * from './get-pkp-info';
2
2
  export * from './get-uniswap-quote';
3
3
  export * from './send-uniswap-tx';
4
4
  export * from './sign-tx';
5
+ export * from './get-erc20-allowance';
6
+ export * from './get-erc20-contract';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
@@ -5,4 +5,6 @@ tslib_1.__exportStar(require("./get-pkp-info"), exports);
5
5
  tslib_1.__exportStar(require("./get-uniswap-quote"), exports);
6
6
  tslib_1.__exportStar(require("./send-uniswap-tx"), exports);
7
7
  tslib_1.__exportStar(require("./sign-tx"), exports);
8
+ tslib_1.__exportStar(require("./get-erc20-allowance"), exports);
9
+ tslib_1.__exportStar(require("./get-erc20-contract"), exports);
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,8DAAoC;AACpC,4DAAkC;AAClC,oDAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,8DAAoC;AACpC,4DAAkC;AAClC,oDAA0B;AAC1B,gEAAsC;AACtC,+DAAqC"}
@@ -0,0 +1,15 @@
1
+ export declare const sendErc20ApprovalTx: ({ rpcUrl, chainId, pkpPublicKey, pkpEthAddress, erc20TokenAddress, spenderAddress, allowanceAmount, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }: {
2
+ rpcUrl: string;
3
+ chainId: number;
4
+ pkpPublicKey: string;
5
+ pkpEthAddress: string;
6
+ erc20TokenAddress: string;
7
+ spenderAddress: string;
8
+ allowanceAmount: string;
9
+ gasBufferPercentage?: number;
10
+ baseFeePerGasBufferPercentage?: number;
11
+ alchemyGasSponsor: boolean;
12
+ alchemyGasSponsorApiKey?: string;
13
+ alchemyGasSponsorPolicyId?: string;
14
+ }) => Promise<string>;
15
+ //# sourceMappingURL=send-erc20-approval-tx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-erc20-approval-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-erc20-approval-tx.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,mBAAmB,GAAU,kOAavC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC,KAAG,OAAO,CAAC,MAAM,CA+FjB,CAAC"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendErc20ApprovalTx = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
6
+ const get_erc20_contract_1 = require("./get-erc20-contract");
7
+ const sign_tx_1 = require("./sign-tx");
8
+ const sendErc20ApprovalTx = async ({ rpcUrl, chainId, pkpPublicKey, pkpEthAddress, erc20TokenAddress, spenderAddress, allowanceAmount, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }) => {
9
+ if (alchemyGasSponsor) {
10
+ console.log('[sendErc20ApprovalTx] Alchemy gas sponsor is enabled');
11
+ if (!alchemyGasSponsorApiKey || !alchemyGasSponsorPolicyId) {
12
+ throw new Error('[sendErc20ApprovalTx] Alchemy gas sponsor is enabled, but API key or policy ID is not provided.');
13
+ }
14
+ return await (0, vincent_ability_sdk_1.sponsoredGasContractCall)({
15
+ pkpPublicKey,
16
+ abi: get_erc20_contract_1.ERC20_ABI,
17
+ contractAddress: erc20TokenAddress,
18
+ functionName: 'approve',
19
+ args: [spenderAddress, allowanceAmount],
20
+ chainId,
21
+ eip7702AlchemyApiKey: alchemyGasSponsorApiKey,
22
+ eip7702AlchemyPolicyId: alchemyGasSponsorPolicyId,
23
+ });
24
+ }
25
+ console.log('[sendErc20ApprovalTx] Estimating gas for ERC20 Approval transaction');
26
+ const populateTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: '[sendErc20ApprovalTx] ERC20 approval tx gas estimation' }, async () => {
27
+ const erc20Interface = new ethers_1.ethers.utils.Interface(get_erc20_contract_1.ERC20_ABI);
28
+ const approveCalldata = erc20Interface.encodeFunctionData('approve', [
29
+ spenderAddress,
30
+ allowanceAmount,
31
+ ]);
32
+ try {
33
+ return JSON.stringify({
34
+ status: 'success',
35
+ populatedTransaction: await (0, vincent_ability_sdk_1.populateTransaction)({
36
+ to: erc20TokenAddress,
37
+ from: pkpEthAddress,
38
+ value: '0',
39
+ data: approveCalldata,
40
+ rpcUrl,
41
+ chainId,
42
+ gasBufferPercentage,
43
+ baseFeePerGasBufferPercentage,
44
+ }),
45
+ });
46
+ }
47
+ catch (error) {
48
+ return JSON.stringify({
49
+ status: 'error',
50
+ error: error instanceof Error ? error.message : String(error),
51
+ });
52
+ }
53
+ });
54
+ const parsedPopulateTxResponse = JSON.parse(populateTxResponse);
55
+ if (parsedPopulateTxResponse.status === 'error') {
56
+ throw new Error(`[sendErc20ApprovalTx] Error populating transaction for approval: ${parsedPopulateTxResponse.error}`);
57
+ }
58
+ const { populatedTransaction } = parsedPopulateTxResponse;
59
+ const signedApprovalTx = await (0, sign_tx_1.signTx)(pkpPublicKey, populatedTransaction, 'erc20ApprovalSig');
60
+ console.log(`Broadcasting ERC20 approval transaction (sendErc20ApprovalTx)`);
61
+ const swapTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'erc20ApprovalTxSender' }, async () => {
62
+ try {
63
+ const uniswapRpcProvider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
64
+ const receipt = await uniswapRpcProvider.sendTransaction(signedApprovalTx);
65
+ return JSON.stringify({
66
+ status: 'success',
67
+ txHash: receipt.hash,
68
+ });
69
+ }
70
+ catch (error) {
71
+ return JSON.stringify({
72
+ status: 'error',
73
+ error: error instanceof Error ? error.message : String(error),
74
+ });
75
+ }
76
+ });
77
+ const parsedSwapTxResponse = JSON.parse(swapTxResponse);
78
+ if (parsedSwapTxResponse.status === 'error') {
79
+ throw new Error(`[sendErc20ApprovalTx] Error broadcasting ERC20 approval transaction: ${parsedSwapTxResponse.error}`);
80
+ }
81
+ const { txHash } = parsedSwapTxResponse;
82
+ console.log(`[sendErc20ApprovalTx] ERC20 approval transaction broadcasted: ${txHash}`);
83
+ return txHash;
84
+ };
85
+ exports.sendErc20ApprovalTx = sendErc20ApprovalTx;
86
+ //# sourceMappingURL=send-erc20-approval-tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-erc20-approval-tx.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-erc20-approval-tx.ts"],"names":[],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- export declare const sendUniswapTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, }: {
1
+ export declare const sendUniswapTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }: {
2
2
  rpcUrl: string;
3
3
  chainId: number;
4
4
  pkpEthAddress: string;
@@ -8,5 +8,8 @@ export declare const sendUniswapTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublic
8
8
  calldata: string;
9
9
  gasBufferPercentage?: number;
10
10
  baseFeePerGasBufferPercentage?: number;
11
+ alchemyGasSponsor?: boolean;
12
+ alchemyGasSponsorApiKey?: string;
13
+ alchemyGasSponsorPolicyId?: string;
11
14
  }) => Promise<string>;
12
15
  //# sourceMappingURL=send-uniswap-tx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"send-uniswap-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa,GAAU,4HAUjC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,6BAA6B,CAAC,EAAE,MAAM,CAAC;CACxC,KAAG,OAAO,CAAC,MAAM,CAsEjB,CAAC"}
1
+ {"version":3,"file":"send-uniswap-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa,GAAU,mMAajC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC,KAAG,OAAO,CAAC,MAAM,CAyFjB,CAAC"}
@@ -4,7 +4,22 @@ exports.sendUniswapTx = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  const sign_tx_1 = require("./sign-tx");
6
6
  const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
7
- const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, }) => {
7
+ const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, to, value, calldata, gasBufferPercentage, baseFeePerGasBufferPercentage, alchemyGasSponsor, alchemyGasSponsorApiKey, alchemyGasSponsorPolicyId, }) => {
8
+ if (alchemyGasSponsor) {
9
+ console.log('[sendUniswapTx] Alchemy gas sponsor is enabled');
10
+ if (!alchemyGasSponsorApiKey || !alchemyGasSponsorPolicyId) {
11
+ throw new Error('[sendUniswapTx] Alchemy gas sponsor is enabled, but API key or policy ID is not provided.');
12
+ }
13
+ return await (0, vincent_ability_sdk_1.sponsoredGasRawTransaction)({
14
+ pkpPublicKey,
15
+ to,
16
+ value,
17
+ data: calldata,
18
+ chainId,
19
+ eip7702AlchemyApiKey: alchemyGasSponsorApiKey,
20
+ eip7702AlchemyPolicyId: alchemyGasSponsorPolicyId,
21
+ });
22
+ }
8
23
  console.log('Estimating gas for Swap transaction using pre-computed route (sendUniswapTx)');
9
24
  const populateTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'Uniswap swap tx gas estimation with pre-computed route' }, async () => {
10
25
  try {