@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,209 +1,248 @@
1
- export declare const vincentPolicy: import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/types").VincentPolicy<"@lit-protocol/vincent-policy-spending-limit", import("zod").ZodObject<{
2
- ethRpcUrl: import("zod").ZodString;
3
- rpcUrlForUniswap: import("zod").ZodString;
4
- chainIdForUniswap: import("zod").ZodNumber;
5
- tokenAddress: import("zod").ZodString;
6
- tokenDecimals: import("zod").ZodNumber;
7
- buyAmount: import("zod").ZodNumber;
1
+ export declare const vincentPolicy: import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/types").VincentPolicy<"@lit-protocol/vincent-policy-send-counter-limit", import("zod").ZodObject<{
2
+ to: import("zod").ZodString;
3
+ amount: import("zod").ZodString;
8
4
  }, "strip", import("zod").ZodTypeAny, {
9
- ethRpcUrl: string;
10
- rpcUrlForUniswap: string;
11
- chainIdForUniswap: number;
12
- tokenAddress: string;
13
- tokenDecimals: number;
14
- buyAmount: number;
5
+ to: string;
6
+ amount: string;
15
7
  }, {
16
- ethRpcUrl: string;
17
- rpcUrlForUniswap: string;
18
- chainIdForUniswap: number;
19
- tokenAddress: string;
20
- tokenDecimals: number;
21
- buyAmount: number;
8
+ to: string;
9
+ amount: string;
22
10
  }>, import("zod").ZodObject<{
23
- maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
11
+ maxSends: import("zod").ZodNumber;
12
+ timeWindowSeconds: import("zod").ZodNumber;
24
13
  }, "strip", import("zod").ZodTypeAny, {
25
- maxDailySpendingLimitInUsdCents: bigint;
14
+ maxSends: number;
15
+ timeWindowSeconds: number;
26
16
  }, {
27
- maxDailySpendingLimitInUsdCents: bigint;
17
+ maxSends: number;
18
+ timeWindowSeconds: number;
28
19
  }>, import("zod").ZodObject<{
29
- maxSpendingLimitInUsd: import("zod").ZodNumber;
30
- buyAmountInUsd: import("zod").ZodNumber;
20
+ currentCount: import("zod").ZodNumber;
21
+ maxSends: import("zod").ZodNumber;
22
+ remainingSends: import("zod").ZodNumber;
23
+ timeWindowSeconds: import("zod").ZodNumber;
31
24
  }, "strip", import("zod").ZodTypeAny, {
32
- maxSpendingLimitInUsd: number;
33
- buyAmountInUsd: number;
25
+ currentCount: number;
26
+ remainingSends: number;
27
+ maxSends: number;
28
+ timeWindowSeconds: number;
34
29
  }, {
35
- maxSpendingLimitInUsd: number;
36
- buyAmountInUsd: number;
30
+ currentCount: number;
31
+ remainingSends: number;
32
+ maxSends: number;
33
+ timeWindowSeconds: number;
37
34
  }>, import("zod").ZodObject<{
38
- reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
39
- maxSpendingLimitInUsd: import("zod").ZodNumber;
40
- buyAmountInUsd: import("zod").ZodNumber;
35
+ reason: import("zod").ZodString;
36
+ currentCount: import("zod").ZodNumber;
37
+ maxSends: import("zod").ZodNumber;
38
+ secondsUntilReset: import("zod").ZodNumber;
41
39
  }, "strip", import("zod").ZodTypeAny, {
42
- maxSpendingLimitInUsd: number;
43
- reason: "Attempted buy amount exceeds daily limit";
44
- buyAmountInUsd: number;
40
+ currentCount: number;
41
+ secondsUntilReset: number;
42
+ maxSends: number;
43
+ reason: string;
45
44
  }, {
46
- maxSpendingLimitInUsd: number;
47
- reason: "Attempted buy amount exceeds daily limit";
48
- buyAmountInUsd: number;
45
+ currentCount: number;
46
+ secondsUntilReset: number;
47
+ maxSends: number;
48
+ reason: string;
49
49
  }>, import("zod").ZodObject<{
50
- maxSpendingLimitInUsd: import("zod").ZodNumber;
51
- buyAmountInUsd: import("zod").ZodNumber;
50
+ currentCount: import("zod").ZodNumber;
51
+ maxSends: import("zod").ZodNumber;
52
+ remainingSends: import("zod").ZodNumber;
53
+ timeWindowSeconds: import("zod").ZodNumber;
52
54
  }, "strip", import("zod").ZodTypeAny, {
53
- maxSpendingLimitInUsd: number;
54
- buyAmountInUsd: number;
55
+ currentCount: number;
56
+ remainingSends: number;
57
+ maxSends: number;
58
+ timeWindowSeconds: number;
55
59
  }, {
56
- maxSpendingLimitInUsd: number;
57
- buyAmountInUsd: number;
60
+ currentCount: number;
61
+ remainingSends: number;
62
+ maxSends: number;
63
+ timeWindowSeconds: number;
58
64
  }>, import("zod").ZodObject<{
59
65
  reason: import("zod").ZodString;
60
- maxSpendingLimitInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
61
- buyAmountInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
62
- }, "strip", import("zod").ZodTypeAny, {
66
+ currentCount: import("zod").ZodNumber;
67
+ maxSends: import("zod").ZodNumber;
68
+ secondsUntilReset: import("zod").ZodNumber;
69
+ timeWindowSeconds: import("zod").ZodNumber;
70
+ }, "strip", import("zod").ZodTypeAny, {
71
+ currentCount: number;
72
+ secondsUntilReset: number;
73
+ maxSends: number;
74
+ timeWindowSeconds: number;
63
75
  reason: string;
64
- maxSpendingLimitInUsd?: number | undefined;
65
- buyAmountInUsd?: number | undefined;
66
76
  }, {
77
+ currentCount: number;
78
+ secondsUntilReset: number;
79
+ maxSends: number;
80
+ timeWindowSeconds: number;
67
81
  reason: string;
68
- maxSpendingLimitInUsd?: number | undefined;
69
- buyAmountInUsd?: number | undefined;
70
82
  }>, import("zod").ZodObject<{
71
- amountSpentUsd: import("zod").ZodNumber;
72
- maxSpendingLimitInUsd: import("zod").ZodNumber;
83
+ currentCount: import("zod").ZodNumber;
84
+ maxSends: import("zod").ZodNumber;
85
+ remainingSends: import("zod").ZodNumber;
86
+ timeWindowSeconds: import("zod").ZodNumber;
73
87
  }, "strip", import("zod").ZodTypeAny, {
74
- amountSpentUsd: number;
75
- maxSpendingLimitInUsd: number;
88
+ currentCount: number;
89
+ remainingSends: number;
90
+ maxSends: number;
91
+ timeWindowSeconds: number;
76
92
  }, {
77
- amountSpentUsd: number;
78
- maxSpendingLimitInUsd: number;
93
+ currentCount: number;
94
+ remainingSends: number;
95
+ maxSends: number;
96
+ timeWindowSeconds: number;
79
97
  }>, import("zod").ZodObject<{
80
- spendTxHash: import("zod").ZodString;
98
+ recorded: import("zod").ZodBoolean;
99
+ newCount: import("zod").ZodNumber;
100
+ remainingSends: import("zod").ZodNumber;
81
101
  }, "strip", import("zod").ZodTypeAny, {
82
- spendTxHash: string;
102
+ remainingSends: number;
103
+ recorded: boolean;
104
+ newCount: number;
83
105
  }, {
84
- spendTxHash: string;
106
+ remainingSends: number;
107
+ recorded: boolean;
108
+ newCount: number;
85
109
  }>, import("zod").ZodObject<{
86
- error: import("zod").ZodString;
110
+ reason: import("zod").ZodString;
87
111
  }, "strip", import("zod").ZodTypeAny, {
88
- error: string;
112
+ reason: string;
89
113
  }, {
90
- error: string;
114
+ reason: string;
91
115
  }>, import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/types").PolicyLifecycleFunction<import("zod").ZodObject<{
92
- ethRpcUrl: import("zod").ZodString;
93
- rpcUrlForUniswap: import("zod").ZodString;
94
- chainIdForUniswap: import("zod").ZodNumber;
95
- tokenAddress: import("zod").ZodString;
96
- tokenDecimals: import("zod").ZodNumber;
97
- buyAmount: import("zod").ZodNumber;
116
+ to: import("zod").ZodString;
117
+ amount: import("zod").ZodString;
98
118
  }, "strip", import("zod").ZodTypeAny, {
99
- ethRpcUrl: string;
100
- rpcUrlForUniswap: string;
101
- chainIdForUniswap: number;
102
- tokenAddress: string;
103
- tokenDecimals: number;
104
- buyAmount: number;
119
+ to: string;
120
+ amount: string;
105
121
  }, {
106
- ethRpcUrl: string;
107
- rpcUrlForUniswap: string;
108
- chainIdForUniswap: number;
109
- tokenAddress: string;
110
- tokenDecimals: number;
111
- buyAmount: number;
122
+ to: string;
123
+ amount: string;
112
124
  }>, import("zod").ZodObject<{
113
- maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
125
+ maxSends: import("zod").ZodNumber;
126
+ timeWindowSeconds: import("zod").ZodNumber;
114
127
  }, "strip", import("zod").ZodTypeAny, {
115
- maxDailySpendingLimitInUsdCents: bigint;
128
+ maxSends: number;
129
+ timeWindowSeconds: number;
116
130
  }, {
117
- maxDailySpendingLimitInUsdCents: bigint;
131
+ maxSends: number;
132
+ timeWindowSeconds: number;
118
133
  }>, import("zod").ZodObject<{
119
- maxSpendingLimitInUsd: import("zod").ZodNumber;
120
- buyAmountInUsd: import("zod").ZodNumber;
134
+ currentCount: import("zod").ZodNumber;
135
+ maxSends: import("zod").ZodNumber;
136
+ remainingSends: import("zod").ZodNumber;
137
+ timeWindowSeconds: import("zod").ZodNumber;
121
138
  }, "strip", import("zod").ZodTypeAny, {
122
- maxSpendingLimitInUsd: number;
123
- buyAmountInUsd: number;
139
+ currentCount: number;
140
+ remainingSends: number;
141
+ maxSends: number;
142
+ timeWindowSeconds: number;
124
143
  }, {
125
- maxSpendingLimitInUsd: number;
126
- buyAmountInUsd: number;
144
+ currentCount: number;
145
+ remainingSends: number;
146
+ maxSends: number;
147
+ timeWindowSeconds: number;
127
148
  }>, import("zod").ZodObject<{
128
149
  reason: import("zod").ZodString;
129
- maxSpendingLimitInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
130
- buyAmountInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
131
- }, "strip", import("zod").ZodTypeAny, {
150
+ currentCount: import("zod").ZodNumber;
151
+ maxSends: import("zod").ZodNumber;
152
+ secondsUntilReset: import("zod").ZodNumber;
153
+ timeWindowSeconds: import("zod").ZodNumber;
154
+ }, "strip", import("zod").ZodTypeAny, {
155
+ currentCount: number;
156
+ secondsUntilReset: number;
157
+ maxSends: number;
158
+ timeWindowSeconds: number;
132
159
  reason: string;
133
- maxSpendingLimitInUsd?: number | undefined;
134
- buyAmountInUsd?: number | undefined;
135
160
  }, {
161
+ currentCount: number;
162
+ secondsUntilReset: number;
163
+ maxSends: number;
164
+ timeWindowSeconds: number;
136
165
  reason: string;
137
- maxSpendingLimitInUsd?: number | undefined;
138
- buyAmountInUsd?: number | undefined;
139
166
  }>>, import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/types").PolicyLifecycleFunction<import("zod").ZodObject<{
140
- ethRpcUrl: import("zod").ZodString;
141
- rpcUrlForUniswap: import("zod").ZodString;
142
- chainIdForUniswap: import("zod").ZodNumber;
143
- tokenAddress: import("zod").ZodString;
144
- tokenDecimals: import("zod").ZodNumber;
145
- buyAmount: import("zod").ZodNumber;
167
+ to: import("zod").ZodString;
168
+ amount: import("zod").ZodString;
146
169
  }, "strip", import("zod").ZodTypeAny, {
147
- ethRpcUrl: string;
148
- rpcUrlForUniswap: string;
149
- chainIdForUniswap: number;
150
- tokenAddress: string;
151
- tokenDecimals: number;
152
- buyAmount: number;
170
+ to: string;
171
+ amount: string;
153
172
  }, {
154
- ethRpcUrl: string;
155
- rpcUrlForUniswap: string;
156
- chainIdForUniswap: number;
157
- tokenAddress: string;
158
- tokenDecimals: number;
159
- buyAmount: number;
173
+ to: string;
174
+ amount: string;
160
175
  }>, import("zod").ZodObject<{
161
- maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
176
+ maxSends: import("zod").ZodNumber;
177
+ timeWindowSeconds: import("zod").ZodNumber;
162
178
  }, "strip", import("zod").ZodTypeAny, {
163
- maxDailySpendingLimitInUsdCents: bigint;
179
+ maxSends: number;
180
+ timeWindowSeconds: number;
164
181
  }, {
165
- maxDailySpendingLimitInUsdCents: bigint;
182
+ maxSends: number;
183
+ timeWindowSeconds: number;
166
184
  }>, import("zod").ZodObject<{
167
- maxSpendingLimitInUsd: import("zod").ZodNumber;
168
- buyAmountInUsd: import("zod").ZodNumber;
185
+ currentCount: import("zod").ZodNumber;
186
+ maxSends: import("zod").ZodNumber;
187
+ remainingSends: import("zod").ZodNumber;
188
+ timeWindowSeconds: import("zod").ZodNumber;
169
189
  }, "strip", import("zod").ZodTypeAny, {
170
- maxSpendingLimitInUsd: number;
171
- buyAmountInUsd: number;
190
+ currentCount: number;
191
+ remainingSends: number;
192
+ maxSends: number;
193
+ timeWindowSeconds: number;
172
194
  }, {
173
- maxSpendingLimitInUsd: number;
174
- buyAmountInUsd: number;
195
+ currentCount: number;
196
+ remainingSends: number;
197
+ maxSends: number;
198
+ timeWindowSeconds: number;
175
199
  }>, import("zod").ZodObject<{
176
- reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
177
- maxSpendingLimitInUsd: import("zod").ZodNumber;
178
- buyAmountInUsd: import("zod").ZodNumber;
200
+ reason: import("zod").ZodString;
201
+ currentCount: import("zod").ZodNumber;
202
+ maxSends: import("zod").ZodNumber;
203
+ secondsUntilReset: import("zod").ZodNumber;
179
204
  }, "strip", import("zod").ZodTypeAny, {
180
- maxSpendingLimitInUsd: number;
181
- reason: "Attempted buy amount exceeds daily limit";
182
- buyAmountInUsd: number;
205
+ currentCount: number;
206
+ secondsUntilReset: number;
207
+ maxSends: number;
208
+ reason: string;
183
209
  }, {
184
- maxSpendingLimitInUsd: number;
185
- reason: "Attempted buy amount exceeds daily limit";
186
- buyAmountInUsd: number;
210
+ currentCount: number;
211
+ secondsUntilReset: number;
212
+ maxSends: number;
213
+ reason: string;
187
214
  }>>, import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/types").CommitLifecycleFunction<import("zod").ZodObject<{
188
- amountSpentUsd: import("zod").ZodNumber;
189
- maxSpendingLimitInUsd: import("zod").ZodNumber;
215
+ currentCount: import("zod").ZodNumber;
216
+ maxSends: import("zod").ZodNumber;
217
+ remainingSends: import("zod").ZodNumber;
218
+ timeWindowSeconds: import("zod").ZodNumber;
190
219
  }, "strip", import("zod").ZodTypeAny, {
191
- amountSpentUsd: number;
192
- maxSpendingLimitInUsd: number;
220
+ currentCount: number;
221
+ remainingSends: number;
222
+ maxSends: number;
223
+ timeWindowSeconds: number;
193
224
  }, {
194
- amountSpentUsd: number;
195
- maxSpendingLimitInUsd: number;
225
+ currentCount: number;
226
+ remainingSends: number;
227
+ maxSends: number;
228
+ timeWindowSeconds: number;
196
229
  }>, import("zod").ZodObject<{
197
- spendTxHash: import("zod").ZodString;
230
+ recorded: import("zod").ZodBoolean;
231
+ newCount: import("zod").ZodNumber;
232
+ remainingSends: import("zod").ZodNumber;
198
233
  }, "strip", import("zod").ZodTypeAny, {
199
- spendTxHash: string;
234
+ remainingSends: number;
235
+ recorded: boolean;
236
+ newCount: number;
200
237
  }, {
201
- spendTxHash: string;
238
+ remainingSends: number;
239
+ recorded: boolean;
240
+ newCount: number;
202
241
  }>, import("zod").ZodObject<{
203
- error: import("zod").ZodString;
242
+ reason: import("zod").ZodString;
204
243
  }, "strip", import("zod").ZodTypeAny, {
205
- error: string;
244
+ reason: string;
206
245
  }, {
207
- error: string;
246
+ reason: string;
208
247
  }>>>;
209
248
  //# sourceMappingURL=vincent-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vincent-policy.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-policy.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoJxB,CAAC"}
1
+ {"version":3,"file":"vincent-policy.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-policy.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgRxB,CAAC"}
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vincentPolicy = void 0;
4
4
  const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
5
- const send_spend_tx_1 = require("./policy-helpers/send-spend-tx");
6
- const check_spending_limit_1 = require("./policy-helpers/check-spending-limit");
5
+ const vincent_scaffold_sdk_1 = require("@lit-protocol/vincent-scaffold-sdk");
6
+ const index_1 = require("./helpers/index");
7
7
  const schemas_1 = require("./schemas");
8
+ const counterSignatures_1 = require("./abi/counterSignatures");
8
9
  exports.vincentPolicy = (0, vincent_ability_sdk_1.createVincentPolicy)({
9
- packageName: '@lit-protocol/vincent-policy-spending-limit',
10
+ packageName: '@lit-protocol/vincent-policy-send-counter-limit',
10
11
  abilityParamsSchema: schemas_1.abilityParamsSchema,
11
12
  userParamsSchema: schemas_1.userParamsSchema,
12
13
  commitParamsSchema: schemas_1.commitParamsSchema,
@@ -17,55 +18,75 @@ exports.vincentPolicy = (0, vincent_ability_sdk_1.createVincentPolicy)({
17
18
  commitAllowResultSchema: schemas_1.commitAllowResultSchema,
18
19
  commitDenyResultSchema: schemas_1.commitDenyResultSchema,
19
20
  precheck: async ({ abilityParams, userParams }, { allow, deny, appId, delegation: { delegatorPkpInfo } }) => {
20
- console.log('Prechecking spending limit policy', { abilityParams, userParams });
21
- const { ethAddress } = delegatorPkpInfo;
22
- const { buyAmount, ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, } = abilityParams;
23
- const { maxDailySpendingLimitInUsdCents } = userParams;
24
- const { buyAmountAllowed, buyAmountInUsd, adjustedMaxDailySpendingLimit } = await (0, check_spending_limit_1.checkIfBuyAmountAllowed)({
25
- ethRpcUrl,
26
- rpcUrlForUniswap,
27
- chainIdForUniswap,
28
- tokenAddress: tokenAddress,
29
- tokenDecimals,
30
- buyAmount,
31
- maxDailySpendingLimitInUsdCents,
32
- pkpEthAddress: ethAddress,
21
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🔍 POLICY PRECHECK CALLED');
22
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🔍 Policy precheck params:', {
23
+ abilityParams,
24
+ userParams,
25
+ ethAddress: delegatorPkpInfo.ethAddress,
33
26
  appId,
34
27
  });
35
- return buyAmountAllowed
36
- ? allow({
37
- maxSpendingLimitInUsd: Number(adjustedMaxDailySpendingLimit),
38
- buyAmountInUsd: Number(buyAmountInUsd),
39
- })
40
- : deny({
41
- reason: 'Attempted buy amount exceeds daily limit',
42
- maxSpendingLimitInUsd: Number(adjustedMaxDailySpendingLimit),
43
- buyAmountInUsd: Number(buyAmountInUsd),
28
+ // Only use what we actually need - no defaults in policy logic
29
+ const { maxSends, timeWindowSeconds } = userParams;
30
+ const { ethAddress } = delegatorPkpInfo;
31
+ try {
32
+ // Check current send limit for the user
33
+ const limitCheck = await (0, index_1.checkSendLimit)(ethAddress, maxSends, timeWindowSeconds);
34
+ if (!limitCheck.allowed) {
35
+ const denyResult = {
36
+ reason: `Send limit exceeded. Maximum ${maxSends} sends per ${timeWindowSeconds} seconds. Try again in ${limitCheck.secondsUntilReset} seconds.`,
37
+ currentCount: limitCheck.currentCount,
38
+ maxSends: maxSends,
39
+ secondsUntilReset: limitCheck.secondsUntilReset || 0,
40
+ };
41
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 POLICY PRECHECK DENYING REQUEST:');
42
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 Deny result:', JSON.stringify(denyResult, null, 2));
43
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 Current count:', limitCheck.currentCount);
44
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 Max sends:', maxSends);
45
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 Limit check result:', JSON.stringify(limitCheck, null, 2));
46
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 About to call deny() function...');
47
+ const denyResponse = deny(denyResult);
48
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/precheck] 🚫 POLICY PRECHECK DENY RESPONSE:', JSON.stringify(denyResponse, null, 2));
49
+ return denyResponse;
50
+ }
51
+ const allowResult = {
52
+ maxSends,
53
+ timeWindowSeconds,
54
+ currentCount: limitCheck.currentCount,
55
+ remainingSends: limitCheck.remainingSends,
56
+ };
57
+ console.log('[SendLimitPolicy/precheck] ✅ POLICY PRECHECK ALLOWING REQUEST:');
58
+ console.log('[SendLimitPolicy/precheck] ✅ Allow result:', JSON.stringify(allowResult, null, 2));
59
+ console.log('[SendLimitPolicy/precheck] ✅ Current count:', limitCheck.currentCount);
60
+ console.log('[SendLimitPolicy/precheck] ✅ Max sends:', maxSends);
61
+ console.log('[SendLimitPolicy/precheck] ✅ Remaining sends:', limitCheck.remainingSends);
62
+ const allowResponse = allow(allowResult);
63
+ console.log('[SendLimitPolicy/precheck] ✅ POLICY PRECHECK ALLOW RESPONSE:', JSON.stringify(allowResponse, null, 2));
64
+ return allowResponse;
65
+ }
66
+ catch (error) {
67
+ console.error('[SendLimitPolicy/precheck] Error in precheck:', error);
68
+ return deny({
69
+ maxSends,
70
+ reason: `Policy error: ${error instanceof Error ? error.message : 'Unknown error'}`,
71
+ currentCount: 0,
72
+ secondsUntilReset: 0,
44
73
  });
74
+ }
45
75
  },
46
- evaluate: async ({ abilityParams, userParams }, { allow, deny, appId, delegation: { delegatorPkpInfo } }) => {
76
+ evaluate: async ({ abilityParams, userParams }, { allow, deny, delegation: { delegatorPkpInfo } }) => {
77
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/evaluate] Evaluating send limit policy', {
78
+ abilityParams,
79
+ userParams,
80
+ });
81
+ // Only use what we actually need - no defaults in policy logic
82
+ const { maxSends, timeWindowSeconds } = userParams;
47
83
  const { ethAddress } = delegatorPkpInfo;
48
- console.log('Evaluating spending limit policy', JSON.stringify(abilityParams));
49
- const { buyAmount, ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, } = abilityParams;
50
- const { maxDailySpendingLimitInUsdCents } = userParams;
51
- const checkBuyAmountResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'checkBuyAmount' }, async () => {
84
+ const checkSendResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'checkSendLimit' }, async () => {
52
85
  try {
53
- const { buyAmountAllowed, buyAmountInUsd, adjustedMaxDailySpendingLimit } = await (0, check_spending_limit_1.checkIfBuyAmountAllowed)({
54
- ethRpcUrl,
55
- rpcUrlForUniswap,
56
- chainIdForUniswap,
57
- tokenAddress: tokenAddress,
58
- tokenDecimals,
59
- buyAmount,
60
- maxDailySpendingLimitInUsdCents,
61
- pkpEthAddress: ethAddress,
62
- appId,
63
- });
86
+ const limitCheck = await (0, index_1.checkSendLimit)(ethAddress, maxSends, timeWindowSeconds);
64
87
  return JSON.stringify({
65
88
  status: 'success',
66
- buyAmountAllowed,
67
- buyAmountInUsd: buyAmountInUsd.toString(),
68
- adjustedMaxDailySpendingLimit: adjustedMaxDailySpendingLimit.toString(),
89
+ ...limitCheck,
69
90
  });
70
91
  }
71
92
  catch (error) {
@@ -75,43 +96,93 @@ exports.vincentPolicy = (0, vincent_ability_sdk_1.createVincentPolicy)({
75
96
  });
76
97
  }
77
98
  });
78
- const parsedCheckBuyAmountResponse = JSON.parse(checkBuyAmountResponse);
79
- if (parsedCheckBuyAmountResponse.status === 'error') {
99
+ const parsedResponse = JSON.parse(checkSendResponse);
100
+ if (parsedResponse.status === 'error') {
80
101
  return deny({
81
- reason: `Error checking buy amount: ${parsedCheckBuyAmountResponse.error} (evaluate)`,
102
+ maxSends,
103
+ timeWindowSeconds,
104
+ reason: `Error checking send limit: ${parsedResponse.error} (evaluate)`,
105
+ currentCount: 0,
106
+ secondsUntilReset: 0,
82
107
  });
83
108
  }
84
- const { buyAmountAllowed, buyAmountInUsd, adjustedMaxDailySpendingLimit } = parsedCheckBuyAmountResponse;
85
- console.log('Evaluated spending limit policy', {
86
- buyAmountAllowed,
87
- buyAmountInUsd,
88
- adjustedMaxDailySpendingLimit,
89
- });
90
- return buyAmountAllowed
91
- ? allow({
92
- maxSpendingLimitInUsd: Number(adjustedMaxDailySpendingLimit),
93
- buyAmountInUsd: Number(buyAmountInUsd),
94
- })
95
- : deny({
96
- reason: 'Attempted buy amount exceeds daily limit',
97
- maxSpendingLimitInUsd: Number(adjustedMaxDailySpendingLimit),
98
- buyAmountInUsd: Number(buyAmountInUsd),
109
+ const { allowed, currentCount, remainingSends, secondsUntilReset } = parsedResponse;
110
+ if (!allowed) {
111
+ return deny({
112
+ reason: `Send limit exceeded during evaluation. Maximum ${maxSends} sends per ${timeWindowSeconds} seconds. Try again in ${secondsUntilReset} seconds.`,
113
+ currentCount,
114
+ maxSends,
115
+ timeWindowSeconds,
116
+ secondsUntilReset: secondsUntilReset || 0,
99
117
  });
100
- },
101
- commit: async (params, { allow, appId, delegation: { delegatorPkpInfo } }) => {
102
- const { ethAddress, publicKey } = delegatorPkpInfo;
103
- const { amountSpentUsd, maxSpendingLimitInUsd } = params;
104
- const spendTxHash = await (0, send_spend_tx_1.sendSpendTx)({
105
- appId,
106
- amountSpentUsd,
107
- maxSpendingLimitInUsd,
108
- spendingLimitDuration: 86400, // number of seconds in a day
109
- pkpEthAddress: ethAddress,
110
- pkpPubKey: publicKey,
118
+ }
119
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/evaluate] Evaluated send limit policy', {
120
+ currentCount,
121
+ maxSends,
122
+ remainingSends,
111
123
  });
112
124
  return allow({
113
- spendTxHash,
125
+ currentCount,
126
+ maxSends,
127
+ remainingSends,
128
+ timeWindowSeconds,
114
129
  });
115
130
  },
131
+ commit: async ({ currentCount, maxSends, timeWindowSeconds }, { allow, appId, delegation: { delegatorPkpInfo } }) => {
132
+ const { ethAddress } = delegatorPkpInfo;
133
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/commit] 🚀 IM COMMITING!');
134
+ // Check if we need to reset the counter first
135
+ const checkResponse = await (0, index_1.checkSendLimit)(ethAddress, maxSends, timeWindowSeconds);
136
+ if (checkResponse.shouldReset) {
137
+ console.log(`[@lit-protocol/vincent-policy-send-counter-limit/commit] Resetting counter for ${ethAddress} due to time window expiration`);
138
+ try {
139
+ await (0, index_1.resetSendCounter)(ethAddress, delegatorPkpInfo.publicKey);
140
+ console.log(`[@lit-protocol/vincent-policy-send-counter-limit/commit] Counter reset successful for ${ethAddress}`);
141
+ }
142
+ catch (error) {
143
+ console.warn(`Counter reset failed for ${ethAddress}:`, error);
144
+ // Continue anyway, the counter will still work
145
+ }
146
+ }
147
+ try {
148
+ // Record the send to the smart contract
149
+ console.log(`[@lit-protocol/vincent-policy-send-counter-limit/commit] Recording send to contract for ${ethAddress} (appId: ${appId})`);
150
+ // Execute the contract call to increment the counter directly
151
+ console.log(`[@lit-protocol/vincent-policy-send-counter-limit/commit] Calling incrementByAddress(${ethAddress}) on contract ${counterSignatures_1.counterSignatures.address}`);
152
+ // Call contract directly without Lit.Actions.runOnce wrapper
153
+ const txHash = await vincent_scaffold_sdk_1.laUtils.transaction.handler.contractCall({
154
+ provider: new ethers.providers.JsonRpcProvider(await Lit.Actions.getRpcUrl({ chain: 'yellowstone' })),
155
+ pkpPublicKey: delegatorPkpInfo.publicKey,
156
+ callerAddress: ethAddress,
157
+ abi: [counterSignatures_1.counterSignatures.methods.increment],
158
+ contractAddress: counterSignatures_1.counterSignatures.address,
159
+ functionName: 'increment',
160
+ args: [],
161
+ });
162
+ const newCount = currentCount + 1;
163
+ const remainingSends = maxSends - newCount;
164
+ console.log('[@lit-protocol/vincent-policy-send-counter-limit/commit] Policy commit successful', {
165
+ ethAddress,
166
+ newCount,
167
+ maxSends,
168
+ remainingSends,
169
+ txHash,
170
+ });
171
+ return allow({
172
+ recorded: true,
173
+ newCount,
174
+ remainingSends: Math.max(0, remainingSends),
175
+ });
176
+ }
177
+ catch (error) {
178
+ console.error('[@lit-protocol/vincent-policy-send-counter-limit/commit] Error in commit phase:', error);
179
+ // Still return success since the transaction itself succeeded
180
+ return allow({
181
+ recorded: false,
182
+ newCount: currentCount + 1,
183
+ remainingSends: Math.max(0, maxSends - currentCount - 1),
184
+ });
185
+ }
186
+ },
116
187
  });
117
188
  //# sourceMappingURL=vincent-policy.js.map