@lit-protocol/vincent-policy-send-counter 0.0.4-mma
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +89 -0
- package/README.md +71 -0
- package/dist/CONTRIBUTING.md +89 -0
- package/dist/README.md +71 -0
- package/dist/package.json +30 -0
- package/dist/src/generated/lit-action.js +9 -0
- package/dist/src/generated/vincent-bundled-policy.d.ts +212 -0
- package/dist/src/generated/vincent-bundled-policy.d.ts.map +1 -0
- package/dist/src/generated/vincent-bundled-policy.js +15 -0
- package/dist/src/generated/vincent-bundled-policy.js.map +1 -0
- package/dist/src/generated/vincent-bundled-policy.ts +13 -0
- package/dist/src/generated/vincent-policy-metadata.json +3 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/lit-action.d.ts +2 -0
- package/dist/src/lib/lit-action.d.ts.map +1 -0
- package/dist/src/lib/lit-action.js +12 -0
- package/dist/src/lib/lit-action.js.map +1 -0
- package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts +7 -0
- package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/calculate-usd-value.js +22 -0
- package/dist/src/lib/policy-helpers/calculate-usd-value.js.map +1 -0
- package/dist/src/lib/policy-helpers/check-spending-limit.d.ts +16 -0
- package/dist/src/lib/policy-helpers/check-spending-limit.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/check-spending-limit.js +29 -0
- package/dist/src/lib/policy-helpers/check-spending-limit.js.map +1 -0
- package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts +6 -0
- package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/get-eth-usd-price.js +22 -0
- package/dist/src/lib/policy-helpers/get-eth-usd-price.js.map +1 -0
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts +10 -0
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js +68 -0
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js.map +1 -0
- package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts +15 -0
- package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/get-uniswap-quote.js +114 -0
- package/dist/src/lib/policy-helpers/get-uniswap-quote.js.map +1 -0
- package/dist/src/lib/policy-helpers/index.d.ts +7 -0
- package/dist/src/lib/policy-helpers/index.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/index.js +10 -0
- package/dist/src/lib/policy-helpers/index.js.map +1 -0
- package/dist/src/lib/policy-helpers/send-spend-tx.d.ts +9 -0
- package/dist/src/lib/policy-helpers/send-spend-tx.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/send-spend-tx.js +144 -0
- package/dist/src/lib/policy-helpers/send-spend-tx.js.map +1 -0
- package/dist/src/lib/policy-helpers/sign-tx.d.ts +3 -0
- package/dist/src/lib/policy-helpers/sign-tx.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/sign-tx.js +28 -0
- package/dist/src/lib/policy-helpers/sign-tx.js.map +1 -0
- package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts +4 -0
- package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts.map +1 -0
- package/dist/src/lib/policy-helpers/spending-limit-contract.js +22 -0
- package/dist/src/lib/policy-helpers/spending-limit-contract.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +101 -0
- package/dist/src/lib/schemas.d.ts.map +1 -0
- package/dist/src/lib/schemas.js +60 -0
- package/dist/src/lib/schemas.js.map +1 -0
- package/dist/src/lib/vincent-policy.d.ts +209 -0
- package/dist/src/lib/vincent-policy.d.ts.map +1 -0
- package/dist/src/lib/vincent-policy.js +117 -0
- package/dist/src/lib/vincent-policy.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
export declare const vincentPolicy: import("node_modules/@lit-protocol/vincent-tool-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;
|
|
8
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
9
|
+
ethRpcUrl: string;
|
|
10
|
+
rpcUrlForUniswap: string;
|
|
11
|
+
chainIdForUniswap: number;
|
|
12
|
+
tokenAddress: string;
|
|
13
|
+
tokenDecimals: number;
|
|
14
|
+
buyAmount: number;
|
|
15
|
+
}, {
|
|
16
|
+
ethRpcUrl: string;
|
|
17
|
+
rpcUrlForUniswap: string;
|
|
18
|
+
chainIdForUniswap: number;
|
|
19
|
+
tokenAddress: string;
|
|
20
|
+
tokenDecimals: number;
|
|
21
|
+
buyAmount: number;
|
|
22
|
+
}>, import("zod").ZodObject<{
|
|
23
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
24
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
25
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
26
|
+
}, {
|
|
27
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
28
|
+
}>, import("zod").ZodObject<{
|
|
29
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
30
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
31
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
32
|
+
maxSpendingLimitInUsd: number;
|
|
33
|
+
buyAmountInUsd: number;
|
|
34
|
+
}, {
|
|
35
|
+
maxSpendingLimitInUsd: number;
|
|
36
|
+
buyAmountInUsd: number;
|
|
37
|
+
}>, import("zod").ZodObject<{
|
|
38
|
+
reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
|
|
39
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
40
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
41
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
42
|
+
maxSpendingLimitInUsd: number;
|
|
43
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
44
|
+
buyAmountInUsd: number;
|
|
45
|
+
}, {
|
|
46
|
+
maxSpendingLimitInUsd: number;
|
|
47
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
48
|
+
buyAmountInUsd: number;
|
|
49
|
+
}>, import("zod").ZodObject<{
|
|
50
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
51
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
52
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
53
|
+
maxSpendingLimitInUsd: number;
|
|
54
|
+
buyAmountInUsd: number;
|
|
55
|
+
}, {
|
|
56
|
+
maxSpendingLimitInUsd: number;
|
|
57
|
+
buyAmountInUsd: number;
|
|
58
|
+
}>, import("zod").ZodObject<{
|
|
59
|
+
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, {
|
|
63
|
+
reason: string;
|
|
64
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
65
|
+
buyAmountInUsd?: number | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
reason: string;
|
|
68
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
69
|
+
buyAmountInUsd?: number | undefined;
|
|
70
|
+
}>, import("zod").ZodObject<{
|
|
71
|
+
amountSpentUsd: import("zod").ZodNumber;
|
|
72
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
73
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
74
|
+
amountSpentUsd: number;
|
|
75
|
+
maxSpendingLimitInUsd: number;
|
|
76
|
+
}, {
|
|
77
|
+
amountSpentUsd: number;
|
|
78
|
+
maxSpendingLimitInUsd: number;
|
|
79
|
+
}>, import("zod").ZodObject<{
|
|
80
|
+
spendTxHash: import("zod").ZodString;
|
|
81
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
82
|
+
spendTxHash: string;
|
|
83
|
+
}, {
|
|
84
|
+
spendTxHash: string;
|
|
85
|
+
}>, import("zod").ZodObject<{
|
|
86
|
+
error: import("zod").ZodString;
|
|
87
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
88
|
+
error: string;
|
|
89
|
+
}, {
|
|
90
|
+
error: string;
|
|
91
|
+
}>, import("node_modules/@lit-protocol/vincent-tool-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;
|
|
98
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
99
|
+
ethRpcUrl: string;
|
|
100
|
+
rpcUrlForUniswap: string;
|
|
101
|
+
chainIdForUniswap: number;
|
|
102
|
+
tokenAddress: string;
|
|
103
|
+
tokenDecimals: number;
|
|
104
|
+
buyAmount: number;
|
|
105
|
+
}, {
|
|
106
|
+
ethRpcUrl: string;
|
|
107
|
+
rpcUrlForUniswap: string;
|
|
108
|
+
chainIdForUniswap: number;
|
|
109
|
+
tokenAddress: string;
|
|
110
|
+
tokenDecimals: number;
|
|
111
|
+
buyAmount: number;
|
|
112
|
+
}>, import("zod").ZodObject<{
|
|
113
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
114
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
115
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
116
|
+
}, {
|
|
117
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
118
|
+
}>, import("zod").ZodObject<{
|
|
119
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
120
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
121
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
122
|
+
maxSpendingLimitInUsd: number;
|
|
123
|
+
buyAmountInUsd: number;
|
|
124
|
+
}, {
|
|
125
|
+
maxSpendingLimitInUsd: number;
|
|
126
|
+
buyAmountInUsd: number;
|
|
127
|
+
}>, import("zod").ZodObject<{
|
|
128
|
+
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, {
|
|
132
|
+
reason: string;
|
|
133
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
134
|
+
buyAmountInUsd?: number | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
reason: string;
|
|
137
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
138
|
+
buyAmountInUsd?: number | undefined;
|
|
139
|
+
}>>, import("node_modules/@lit-protocol/vincent-tool-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;
|
|
146
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
147
|
+
ethRpcUrl: string;
|
|
148
|
+
rpcUrlForUniswap: string;
|
|
149
|
+
chainIdForUniswap: number;
|
|
150
|
+
tokenAddress: string;
|
|
151
|
+
tokenDecimals: number;
|
|
152
|
+
buyAmount: number;
|
|
153
|
+
}, {
|
|
154
|
+
ethRpcUrl: string;
|
|
155
|
+
rpcUrlForUniswap: string;
|
|
156
|
+
chainIdForUniswap: number;
|
|
157
|
+
tokenAddress: string;
|
|
158
|
+
tokenDecimals: number;
|
|
159
|
+
buyAmount: number;
|
|
160
|
+
}>, import("zod").ZodObject<{
|
|
161
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
162
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
163
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
164
|
+
}, {
|
|
165
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
166
|
+
}>, import("zod").ZodObject<{
|
|
167
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
168
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
169
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
170
|
+
maxSpendingLimitInUsd: number;
|
|
171
|
+
buyAmountInUsd: number;
|
|
172
|
+
}, {
|
|
173
|
+
maxSpendingLimitInUsd: number;
|
|
174
|
+
buyAmountInUsd: number;
|
|
175
|
+
}>, import("zod").ZodObject<{
|
|
176
|
+
reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
|
|
177
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
178
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
179
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
180
|
+
maxSpendingLimitInUsd: number;
|
|
181
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
182
|
+
buyAmountInUsd: number;
|
|
183
|
+
}, {
|
|
184
|
+
maxSpendingLimitInUsd: number;
|
|
185
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
186
|
+
buyAmountInUsd: number;
|
|
187
|
+
}>>, import("node_modules/@lit-protocol/vincent-tool-sdk/dist/src/lib/types").CommitLifecycleFunction<import("zod").ZodObject<{
|
|
188
|
+
amountSpentUsd: import("zod").ZodNumber;
|
|
189
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
190
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
191
|
+
amountSpentUsd: number;
|
|
192
|
+
maxSpendingLimitInUsd: number;
|
|
193
|
+
}, {
|
|
194
|
+
amountSpentUsd: number;
|
|
195
|
+
maxSpendingLimitInUsd: number;
|
|
196
|
+
}>, import("zod").ZodObject<{
|
|
197
|
+
spendTxHash: import("zod").ZodString;
|
|
198
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
199
|
+
spendTxHash: string;
|
|
200
|
+
}, {
|
|
201
|
+
spendTxHash: string;
|
|
202
|
+
}>, import("zod").ZodObject<{
|
|
203
|
+
error: import("zod").ZodString;
|
|
204
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
205
|
+
error: string;
|
|
206
|
+
}, {
|
|
207
|
+
error: string;
|
|
208
|
+
}>>>;
|
|
209
|
+
//# sourceMappingURL=vincent-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincent-policy.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-policy.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoJxB,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vincentPolicy = void 0;
|
|
4
|
+
const vincent_tool_sdk_1 = require("@lit-protocol/vincent-tool-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");
|
|
7
|
+
const schemas_1 = require("./schemas");
|
|
8
|
+
exports.vincentPolicy = (0, vincent_tool_sdk_1.createVincentPolicy)({
|
|
9
|
+
packageName: '@lit-protocol/vincent-policy-spending-limit',
|
|
10
|
+
toolParamsSchema: schemas_1.toolParamsSchema,
|
|
11
|
+
userParamsSchema: schemas_1.userParamsSchema,
|
|
12
|
+
commitParamsSchema: schemas_1.commitParamsSchema,
|
|
13
|
+
precheckAllowResultSchema: schemas_1.precheckAllowResultSchema,
|
|
14
|
+
precheckDenyResultSchema: schemas_1.precheckDenyResultSchema,
|
|
15
|
+
evalAllowResultSchema: schemas_1.evalAllowResultSchema,
|
|
16
|
+
evalDenyResultSchema: schemas_1.evalDenyResultSchema,
|
|
17
|
+
commitAllowResultSchema: schemas_1.commitAllowResultSchema,
|
|
18
|
+
commitDenyResultSchema: schemas_1.commitDenyResultSchema,
|
|
19
|
+
precheck: async ({ toolParams, userParams }, { allow, deny, appId, delegation: { delegatorPkpInfo } }) => {
|
|
20
|
+
console.log('Prechecking spending limit policy', { toolParams, userParams });
|
|
21
|
+
const { ethAddress } = delegatorPkpInfo;
|
|
22
|
+
const { buyAmount, ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, } = toolParams;
|
|
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,
|
|
33
|
+
appId,
|
|
34
|
+
});
|
|
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),
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
evaluate: async ({ toolParams, userParams }, { allow, deny, appId, delegation: { delegatorPkpInfo } }) => {
|
|
47
|
+
const { ethAddress } = delegatorPkpInfo;
|
|
48
|
+
console.log('Evaluating spending limit policy', JSON.stringify(toolParams));
|
|
49
|
+
const { buyAmount, ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, } = toolParams;
|
|
50
|
+
const { maxDailySpendingLimitInUsdCents } = userParams;
|
|
51
|
+
const checkBuyAmountResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'checkBuyAmount' }, async () => {
|
|
52
|
+
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
|
+
});
|
|
64
|
+
return JSON.stringify({
|
|
65
|
+
status: 'success',
|
|
66
|
+
buyAmountAllowed,
|
|
67
|
+
buyAmountInUsd: buyAmountInUsd.toString(),
|
|
68
|
+
adjustedMaxDailySpendingLimit: adjustedMaxDailySpendingLimit.toString(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return JSON.stringify({
|
|
73
|
+
status: 'error',
|
|
74
|
+
error: error instanceof Error ? error.message : String(error),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const parsedCheckBuyAmountResponse = JSON.parse(checkBuyAmountResponse);
|
|
79
|
+
if (parsedCheckBuyAmountResponse.status === 'error') {
|
|
80
|
+
return deny({
|
|
81
|
+
reason: `Error checking buy amount: ${parsedCheckBuyAmountResponse.error} (evaluate)`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
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),
|
|
99
|
+
});
|
|
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,
|
|
111
|
+
});
|
|
112
|
+
return allow({
|
|
113
|
+
spendTxHash,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=vincent-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincent-policy.js","sourceRoot":"","sources":["../../../src/lib/vincent-policy.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AAErE,kEAA6D;AAC7D,gFAAgF;AAChF,uCAUmB;AAcN,QAAA,aAAa,GAAG,IAAA,sCAAmB,EAAC;IAC/C,WAAW,EAAE,6CAAsD;IAEnE,gBAAgB,EAAhB,0BAAgB;IAChB,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,UAAU,EAAE,UAAU,EAAE,EAC1B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,EAAE,EACxD,EAAE;QACF,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAC7E,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC;QACxC,MAAM,EACJ,SAAS,EACT,SAAS,EAC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,CAAC,CAAC;QAEH,OAAO,gBAAgB;YACrB,CAAC,CAAC,KAAK,CAAC;gBACJ,qBAAqB,EAAE,MAAM,CAAC,6BAA6B,CAAC;gBAC5D,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC;aACvC,CAAC;YACJ,CAAC,CAAC,IAAI,CAAC;gBACH,MAAM,EAAE,0CAA0C;gBAClD,qBAAqB,EAAE,MAAM,CAAC,6BAA6B,CAAC;gBAC5D,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC;aACvC,CAAC,CAAC;IACT,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE;QAC3E,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC;QACnD,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;QAEzD,MAAM,WAAW,GAAG,MAAM,IAAA,2BAAW,EAAC;YACpC,KAAK;YACL,cAAc;YACd,qBAAqB;YACrB,qBAAqB,EAAE,KAAK,EAAE,6BAA6B;YAC3D,aAAa,EAAE,UAAU;YACzB,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;YACX,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lit-protocol/vincent-policy-send-counter",
|
|
3
|
+
"version": "0.0.4-mma",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@uniswap/sdk-core": "^7.7.2",
|
|
9
|
+
"ethers": "^5.8.0",
|
|
10
|
+
"tslib": "2.8.1",
|
|
11
|
+
"zod": "^3.25.64",
|
|
12
|
+
"@lit-protocol/vincent-tool-sdk": "1.0.2"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@lit-protocol/vincent-app-sdk": "^1.0.2"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"esbuild": "^0.19.12",
|
|
19
|
+
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
20
|
+
"ipfs-only-hash": "^4.0.0"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/src/index.js",
|
|
23
|
+
"module": "./dist/src/index.js",
|
|
24
|
+
"types": "./dist/src/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/**",
|
|
27
|
+
"*.md"
|
|
28
|
+
]
|
|
29
|
+
}
|