@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.
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +6 -6
- package/README.md +1 -1
- package/dist/CHANGELOG.md +22 -0
- package/dist/CONTRIBUTING.md +6 -6
- package/dist/README.md +1 -1
- package/dist/package.json +3 -3
- package/dist/src/generated/lit-action.js +2 -2
- package/dist/src/generated/vincent-bundled-policy.d.ts +183 -144
- package/dist/src/generated/vincent-bundled-policy.d.ts.map +1 -1
- package/dist/src/generated/vincent-policy-metadata.json +1 -1
- package/dist/src/lib/abi/counterSignatures.d.ts +82 -0
- package/dist/src/lib/abi/counterSignatures.d.ts.map +1 -0
- package/dist/src/lib/abi/counterSignatures.js +100 -0
- package/dist/src/lib/abi/counterSignatures.js.map +1 -0
- package/dist/src/lib/helpers/index.d.ts +26 -0
- package/dist/src/lib/helpers/index.d.ts.map +1 -0
- package/dist/src/lib/helpers/index.js +107 -0
- package/dist/src/lib/helpers/index.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +115 -64
- package/dist/src/lib/schemas.d.ts.map +1 -1
- package/dist/src/lib/schemas.js +71 -36
- package/dist/src/lib/schemas.js.map +1 -1
- package/dist/src/lib/vincent-policy.d.ts +183 -144
- package/dist/src/lib/vincent-policy.d.ts.map +1 -1
- package/dist/src/lib/vincent-policy.js +145 -74
- package/dist/src/lib/vincent-policy.js.map +1 -1
- package/package.json +5 -5
- package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts +0 -7
- package/dist/src/lib/policy-helpers/calculate-usd-value.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/calculate-usd-value.js +0 -22
- package/dist/src/lib/policy-helpers/calculate-usd-value.js.map +0 -1
- package/dist/src/lib/policy-helpers/check-spending-limit.d.ts +0 -16
- package/dist/src/lib/policy-helpers/check-spending-limit.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/check-spending-limit.js +0 -29
- package/dist/src/lib/policy-helpers/check-spending-limit.js.map +0 -1
- package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts +0 -6
- package/dist/src/lib/policy-helpers/get-eth-usd-price.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/get-eth-usd-price.js +0 -22
- package/dist/src/lib/policy-helpers/get-eth-usd-price.js.map +0 -1
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts +0 -10
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js +0 -68
- package/dist/src/lib/policy-helpers/get-token-amount-in-usd.js.map +0 -1
- package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts +0 -15
- package/dist/src/lib/policy-helpers/get-uniswap-quote.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/get-uniswap-quote.js +0 -114
- package/dist/src/lib/policy-helpers/get-uniswap-quote.js.map +0 -1
- package/dist/src/lib/policy-helpers/index.d.ts +0 -7
- package/dist/src/lib/policy-helpers/index.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/index.js +0 -10
- package/dist/src/lib/policy-helpers/index.js.map +0 -1
- package/dist/src/lib/policy-helpers/send-spend-tx.d.ts +0 -9
- package/dist/src/lib/policy-helpers/send-spend-tx.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/send-spend-tx.js +0 -144
- package/dist/src/lib/policy-helpers/send-spend-tx.js.map +0 -1
- package/dist/src/lib/policy-helpers/sign-tx.d.ts +0 -3
- package/dist/src/lib/policy-helpers/sign-tx.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/sign-tx.js +0 -28
- package/dist/src/lib/policy-helpers/sign-tx.js.map +0 -1
- package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts +0 -4
- package/dist/src/lib/policy-helpers/spending-limit-contract.d.ts.map +0 -1
- package/dist/src/lib/policy-helpers/spending-limit-contract.js +0 -22
- package/dist/src/lib/policy-helpers/spending-limit-contract.js.map +0 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions for the send-counter-limit policy
|
|
4
|
+
* Integrates with the Counter smart contract to track send limits
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.checkSendLimit = checkSendLimit;
|
|
8
|
+
exports.resetSendCounter = resetSendCounter;
|
|
9
|
+
const la_utils_1 = require("@lit-protocol/vincent-scaffold-sdk/la-utils");
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const counterSignatures_1 = require("../abi/counterSignatures");
|
|
12
|
+
/**
|
|
13
|
+
* Check how many sends a user has made and if they can send again
|
|
14
|
+
* @param userAddress - The user's address (PKP address)
|
|
15
|
+
* @param maxSends - Maximum number of sends allowed
|
|
16
|
+
* @param timeWindowSeconds - Time window in seconds before reset
|
|
17
|
+
* @returns Send limit status and timing information
|
|
18
|
+
*/
|
|
19
|
+
async function checkSendLimit(userAddress, maxSends, timeWindowSeconds) {
|
|
20
|
+
try {
|
|
21
|
+
// Create provider for contract calls
|
|
22
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider('https://yellowstone-rpc.litprotocol.com/');
|
|
23
|
+
// Create contract instance
|
|
24
|
+
const contract = new ethers_1.ethers.Contract(counterSignatures_1.counterSignatures.address, [counterSignatures_1.counterSignatures.methods.counterByAddress, counterSignatures_1.counterSignatures.methods.lastIncrementTime], provider);
|
|
25
|
+
// Get current count and last increment time
|
|
26
|
+
const [currentCount, lastIncrementTime] = await Promise.all([
|
|
27
|
+
contract.counterByAddress(userAddress),
|
|
28
|
+
contract.lastIncrementTime(userAddress),
|
|
29
|
+
]);
|
|
30
|
+
const currentCountNum = currentCount.toNumber();
|
|
31
|
+
const lastIncrementTimeNum = lastIncrementTime.toNumber();
|
|
32
|
+
console.log(`Send limit check for ${userAddress}: ${currentCountNum} sends, last at ${lastIncrementTimeNum}`);
|
|
33
|
+
// If user has never sent before, they're allowed
|
|
34
|
+
if (lastIncrementTimeNum === 0) {
|
|
35
|
+
return {
|
|
36
|
+
allowed: true,
|
|
37
|
+
currentCount: currentCountNum,
|
|
38
|
+
remainingSends: maxSends - currentCountNum,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Check if enough time has passed since last send
|
|
42
|
+
const currentTime = Math.floor(Date.now() / 1000); // Convert to seconds
|
|
43
|
+
const timeSinceLastSend = currentTime - lastIncrementTimeNum;
|
|
44
|
+
const timeWindowElapsed = timeSinceLastSend >= timeWindowSeconds;
|
|
45
|
+
// If time window has elapsed, user can send again (count effectively resets)
|
|
46
|
+
if (timeWindowElapsed) {
|
|
47
|
+
console.log(`Time window elapsed for ${userAddress}, allowing send (count will reset on next commit)`);
|
|
48
|
+
return {
|
|
49
|
+
allowed: true,
|
|
50
|
+
currentCount: 0, // Will be reset on next commit
|
|
51
|
+
remainingSends: maxSends,
|
|
52
|
+
shouldReset: true, // Flag to indicate reset is needed
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Time window hasn't elapsed, check if under limit
|
|
56
|
+
if (currentCountNum < maxSends) {
|
|
57
|
+
return {
|
|
58
|
+
allowed: true,
|
|
59
|
+
currentCount: currentCountNum,
|
|
60
|
+
remainingSends: maxSends - currentCountNum,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// User has hit limit and time window hasn't elapsed
|
|
64
|
+
const secondsUntilReset = timeWindowSeconds - timeSinceLastSend;
|
|
65
|
+
return {
|
|
66
|
+
allowed: false,
|
|
67
|
+
currentCount: currentCountNum,
|
|
68
|
+
remainingSends: 0,
|
|
69
|
+
secondsUntilReset: Math.max(0, secondsUntilReset),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Error checking send limit:', error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reset the send counter for a user by calling reset on the
|
|
79
|
+
contract
|
|
80
|
+
* @param userAddress - The user's address (PKP address)
|
|
81
|
+
* @param pkpPublicKey - The PKP public key for signing
|
|
82
|
+
*/
|
|
83
|
+
async function resetSendCounter(userAddress, pkpPublicKey) {
|
|
84
|
+
console.log(`Resetting send counter for ${userAddress} on contract ${counterSignatures_1.counterSignatures.address}`);
|
|
85
|
+
try {
|
|
86
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider('https://yellowstone-rpc.litprotocol.com/');
|
|
87
|
+
const txHash = await la_utils_1.laUtils.transaction.handler.contractCall({
|
|
88
|
+
provider,
|
|
89
|
+
pkpPublicKey,
|
|
90
|
+
callerAddress: userAddress,
|
|
91
|
+
abi: [counterSignatures_1.counterSignatures.methods.reset],
|
|
92
|
+
contractAddress: counterSignatures_1.counterSignatures.address,
|
|
93
|
+
functionName: 'reset',
|
|
94
|
+
args: [],
|
|
95
|
+
overrides: {
|
|
96
|
+
gasLimit: 100000,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
console.log(`Reset successful - TxHash: ${txHash}`);
|
|
100
|
+
return txHash;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('Error resetting send counter:', error);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/helpers/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAeH,wCAqFC;AAQD,4CA2BC;AArID,0EAAsE;AAEtE,mCAAgC;AAEhC,gEAA6D;AAE7D;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAClC,WAAmB,EACnB,QAAgB,EAChB,iBAAyB;IAQzB,IAAI,CAAC;QACH,qCAAqC;QACrC,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,eAAe,CACn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AAS,EAAE;gBACT,QAAQ,EAAE,MAAM;aACjB;SACF,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACtD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,101 +1,152 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Ability parameters schema - matches the ability this policy works with
|
|
4
|
+
*/
|
|
2
5
|
export declare const abilityParamsSchema: z.ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
chainIdForUniswap: z.ZodNumber;
|
|
6
|
-
tokenAddress: z.ZodString;
|
|
7
|
-
tokenDecimals: z.ZodNumber;
|
|
8
|
-
buyAmount: z.ZodNumber;
|
|
6
|
+
to: z.ZodString;
|
|
7
|
+
amount: z.ZodString;
|
|
9
8
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
chainIdForUniswap: number;
|
|
13
|
-
tokenAddress: string;
|
|
14
|
-
tokenDecimals: number;
|
|
15
|
-
buyAmount: number;
|
|
9
|
+
to: string;
|
|
10
|
+
amount: string;
|
|
16
11
|
}, {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
chainIdForUniswap: number;
|
|
20
|
-
tokenAddress: string;
|
|
21
|
-
tokenDecimals: number;
|
|
22
|
-
buyAmount: number;
|
|
12
|
+
to: string;
|
|
13
|
+
amount: string;
|
|
23
14
|
}>;
|
|
15
|
+
/**
|
|
16
|
+
* User parameters schema - policy configuration set by the user
|
|
17
|
+
*/
|
|
24
18
|
export declare const userParamsSchema: z.ZodObject<{
|
|
25
|
-
|
|
19
|
+
maxSends: z.ZodNumber;
|
|
20
|
+
timeWindowSeconds: z.ZodNumber;
|
|
26
21
|
}, "strip", z.ZodTypeAny, {
|
|
27
|
-
|
|
22
|
+
maxSends: number;
|
|
23
|
+
timeWindowSeconds: number;
|
|
28
24
|
}, {
|
|
29
|
-
|
|
25
|
+
maxSends: number;
|
|
26
|
+
timeWindowSeconds: number;
|
|
30
27
|
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Commit parameters schema - data passed to commit phase
|
|
30
|
+
*/
|
|
31
|
+
export declare const commitParamsSchema: z.ZodObject<{
|
|
32
|
+
currentCount: z.ZodNumber;
|
|
33
|
+
maxSends: z.ZodNumber;
|
|
34
|
+
remainingSends: z.ZodNumber;
|
|
35
|
+
timeWindowSeconds: z.ZodNumber;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
currentCount: number;
|
|
38
|
+
remainingSends: number;
|
|
39
|
+
maxSends: number;
|
|
40
|
+
timeWindowSeconds: number;
|
|
41
|
+
}, {
|
|
42
|
+
currentCount: number;
|
|
43
|
+
remainingSends: number;
|
|
44
|
+
maxSends: number;
|
|
45
|
+
timeWindowSeconds: number;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Precheck allow result schema
|
|
49
|
+
*/
|
|
31
50
|
export declare const precheckAllowResultSchema: z.ZodObject<{
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
currentCount: z.ZodNumber;
|
|
52
|
+
maxSends: z.ZodNumber;
|
|
53
|
+
remainingSends: z.ZodNumber;
|
|
54
|
+
timeWindowSeconds: z.ZodNumber;
|
|
34
55
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
currentCount: number;
|
|
57
|
+
remainingSends: number;
|
|
58
|
+
maxSends: number;
|
|
59
|
+
timeWindowSeconds: number;
|
|
37
60
|
}, {
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
currentCount: number;
|
|
62
|
+
remainingSends: number;
|
|
63
|
+
maxSends: number;
|
|
64
|
+
timeWindowSeconds: number;
|
|
40
65
|
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Precheck deny result schema
|
|
68
|
+
*/
|
|
41
69
|
export declare const precheckDenyResultSchema: z.ZodObject<{
|
|
42
|
-
reason: z.
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
reason: z.ZodString;
|
|
71
|
+
currentCount: z.ZodNumber;
|
|
72
|
+
maxSends: z.ZodNumber;
|
|
73
|
+
secondsUntilReset: z.ZodNumber;
|
|
45
74
|
}, "strip", z.ZodTypeAny, {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
currentCount: number;
|
|
76
|
+
secondsUntilReset: number;
|
|
77
|
+
maxSends: number;
|
|
78
|
+
reason: string;
|
|
49
79
|
}, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
80
|
+
currentCount: number;
|
|
81
|
+
secondsUntilReset: number;
|
|
82
|
+
maxSends: number;
|
|
83
|
+
reason: string;
|
|
53
84
|
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Evaluate allow result schema
|
|
87
|
+
*/
|
|
54
88
|
export declare const evalAllowResultSchema: z.ZodObject<{
|
|
55
|
-
|
|
56
|
-
|
|
89
|
+
currentCount: z.ZodNumber;
|
|
90
|
+
maxSends: z.ZodNumber;
|
|
91
|
+
remainingSends: z.ZodNumber;
|
|
92
|
+
timeWindowSeconds: z.ZodNumber;
|
|
57
93
|
}, "strip", z.ZodTypeAny, {
|
|
58
|
-
|
|
59
|
-
|
|
94
|
+
currentCount: number;
|
|
95
|
+
remainingSends: number;
|
|
96
|
+
maxSends: number;
|
|
97
|
+
timeWindowSeconds: number;
|
|
60
98
|
}, {
|
|
61
|
-
|
|
62
|
-
|
|
99
|
+
currentCount: number;
|
|
100
|
+
remainingSends: number;
|
|
101
|
+
maxSends: number;
|
|
102
|
+
timeWindowSeconds: number;
|
|
63
103
|
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Evaluate deny result schema
|
|
106
|
+
*/
|
|
64
107
|
export declare const evalDenyResultSchema: z.ZodObject<{
|
|
65
108
|
reason: z.ZodString;
|
|
66
|
-
|
|
67
|
-
|
|
109
|
+
currentCount: z.ZodNumber;
|
|
110
|
+
maxSends: z.ZodNumber;
|
|
111
|
+
secondsUntilReset: z.ZodNumber;
|
|
112
|
+
timeWindowSeconds: z.ZodNumber;
|
|
68
113
|
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
currentCount: number;
|
|
115
|
+
secondsUntilReset: number;
|
|
116
|
+
maxSends: number;
|
|
117
|
+
timeWindowSeconds: number;
|
|
69
118
|
reason: string;
|
|
70
|
-
maxSpendingLimitInUsd?: number | undefined;
|
|
71
|
-
buyAmountInUsd?: number | undefined;
|
|
72
119
|
}, {
|
|
120
|
+
currentCount: number;
|
|
121
|
+
secondsUntilReset: number;
|
|
122
|
+
maxSends: number;
|
|
123
|
+
timeWindowSeconds: number;
|
|
73
124
|
reason: string;
|
|
74
|
-
maxSpendingLimitInUsd?: number | undefined;
|
|
75
|
-
buyAmountInUsd?: number | undefined;
|
|
76
|
-
}>;
|
|
77
|
-
export declare const commitParamsSchema: z.ZodObject<{
|
|
78
|
-
amountSpentUsd: z.ZodNumber;
|
|
79
|
-
maxSpendingLimitInUsd: z.ZodNumber;
|
|
80
|
-
}, "strip", z.ZodTypeAny, {
|
|
81
|
-
amountSpentUsd: number;
|
|
82
|
-
maxSpendingLimitInUsd: number;
|
|
83
|
-
}, {
|
|
84
|
-
amountSpentUsd: number;
|
|
85
|
-
maxSpendingLimitInUsd: number;
|
|
86
125
|
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Commit allow result schema
|
|
128
|
+
*/
|
|
87
129
|
export declare const commitAllowResultSchema: z.ZodObject<{
|
|
88
|
-
|
|
130
|
+
recorded: z.ZodBoolean;
|
|
131
|
+
newCount: z.ZodNumber;
|
|
132
|
+
remainingSends: z.ZodNumber;
|
|
89
133
|
}, "strip", z.ZodTypeAny, {
|
|
90
|
-
|
|
134
|
+
remainingSends: number;
|
|
135
|
+
recorded: boolean;
|
|
136
|
+
newCount: number;
|
|
91
137
|
}, {
|
|
92
|
-
|
|
138
|
+
remainingSends: number;
|
|
139
|
+
recorded: boolean;
|
|
140
|
+
newCount: number;
|
|
93
141
|
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Commit deny result schema (though commit rarely denies)
|
|
144
|
+
*/
|
|
94
145
|
export declare const commitDenyResultSchema: z.ZodObject<{
|
|
95
|
-
|
|
146
|
+
reason: z.ZodString;
|
|
96
147
|
}, "strip", z.ZodTypeAny, {
|
|
97
|
-
|
|
148
|
+
reason: string;
|
|
98
149
|
}, {
|
|
99
|
-
|
|
150
|
+
reason: string;
|
|
100
151
|
}>;
|
|
101
152
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/lib/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;EAS9B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;EAS3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;EAO7B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;EAKpC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;EAKnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;EAKhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;EAM/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;EAMlC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;EAEjC,CAAC"}
|
package/dist/src/lib/schemas.js
CHANGED
|
@@ -1,60 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.commitDenyResultSchema = exports.commitAllowResultSchema = exports.
|
|
3
|
+
exports.commitDenyResultSchema = exports.commitAllowResultSchema = exports.evalDenyResultSchema = exports.evalAllowResultSchema = exports.precheckDenyResultSchema = exports.precheckAllowResultSchema = exports.commitParamsSchema = exports.userParamsSchema = exports.abilityParamsSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Ability parameters schema - matches the ability this policy works with
|
|
7
|
+
*/
|
|
5
8
|
exports.abilityParamsSchema = zod_1.z.object({
|
|
6
|
-
|
|
9
|
+
to: zod_1.z
|
|
7
10
|
.string()
|
|
8
|
-
.
|
|
9
|
-
|
|
11
|
+
.min(1, 'Recipient address cannot be empty')
|
|
12
|
+
.describe("The recipient's address the underlying ability will send to."),
|
|
13
|
+
amount: zod_1.z
|
|
10
14
|
.string()
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.min(1, 'Amount cannot be empty')
|
|
16
|
+
.describe('The amount to send as a string (units/format depend on the underlying ability).'),
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* User parameters schema - policy configuration set by the user
|
|
20
|
+
*/
|
|
21
|
+
exports.userParamsSchema = zod_1.z.object({
|
|
22
|
+
maxSends: zod_1.z
|
|
19
23
|
.number()
|
|
20
|
-
.
|
|
21
|
-
|
|
24
|
+
.positive()
|
|
25
|
+
.describe('Maximum number of sends allowed within the configured time window.'),
|
|
26
|
+
timeWindowSeconds: zod_1.z
|
|
22
27
|
.number()
|
|
23
|
-
.
|
|
28
|
+
.positive()
|
|
29
|
+
.describe('Length of the counting window in seconds (e.g., 10 = 10 seconds).'),
|
|
24
30
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Commit parameters schema - data passed to commit phase
|
|
33
|
+
*/
|
|
34
|
+
exports.commitParamsSchema = zod_1.z.object({
|
|
35
|
+
currentCount: zod_1.z
|
|
36
|
+
.number()
|
|
37
|
+
.describe('The number of sends recorded in the current time window at commit time.'),
|
|
38
|
+
maxSends: zod_1.z.number().describe('The maximum number of sends allowed in the time window.'),
|
|
39
|
+
remainingSends: zod_1.z.number().describe('How many sends remain available in the current window.'),
|
|
40
|
+
timeWindowSeconds: zod_1.z.number().describe('The duration of the time window in seconds.'),
|
|
29
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* Precheck allow result schema
|
|
44
|
+
*/
|
|
30
45
|
exports.precheckAllowResultSchema = zod_1.z.object({
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
currentCount: zod_1.z.number().describe('The number of sends already made in the current window.'),
|
|
47
|
+
maxSends: zod_1.z.number().describe('The maximum number of sends allowed in the current window.'),
|
|
48
|
+
remainingSends: zod_1.z.number().describe('How many sends are still allowed before hitting the limit.'),
|
|
49
|
+
timeWindowSeconds: zod_1.z.number().describe('The duration of the time window in seconds.'),
|
|
33
50
|
});
|
|
51
|
+
/**
|
|
52
|
+
* Precheck deny result schema
|
|
53
|
+
*/
|
|
34
54
|
exports.precheckDenyResultSchema = zod_1.z.object({
|
|
35
|
-
reason: zod_1.z
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
buyAmountInUsd: zod_1.z.number().describe('The value of the tokens to be spent, in USD.'),
|
|
55
|
+
reason: zod_1.z.string().describe('The reason for denying the precheck.'),
|
|
56
|
+
currentCount: zod_1.z.number().describe('The number of sends already made in the current window.'),
|
|
57
|
+
maxSends: zod_1.z.number().describe('The maximum number of sends allowed in the current window.'),
|
|
58
|
+
secondsUntilReset: zod_1.z.number().describe('Number of seconds remaining until the counter resets.'),
|
|
40
59
|
});
|
|
60
|
+
/**
|
|
61
|
+
* Evaluate allow result schema
|
|
62
|
+
*/
|
|
41
63
|
exports.evalAllowResultSchema = zod_1.z.object({
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
currentCount: zod_1.z.number().describe('The number of sends already made in the current window.'),
|
|
65
|
+
maxSends: zod_1.z.number().describe('The maximum number of sends allowed in the current window.'),
|
|
66
|
+
remainingSends: zod_1.z.number().describe('How many sends are still allowed before hitting the limit.'),
|
|
67
|
+
timeWindowSeconds: zod_1.z.number().describe('The duration of the time window in seconds.'),
|
|
44
68
|
});
|
|
69
|
+
/**
|
|
70
|
+
* Evaluate deny result schema
|
|
71
|
+
*/
|
|
45
72
|
exports.evalDenyResultSchema = zod_1.z.object({
|
|
46
73
|
reason: zod_1.z.string().describe('The reason for denying the evaluation.'),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
amountSpentUsd: zod_1.z.number().describe('The amount spent for this transaction, in USD.'),
|
|
52
|
-
maxSpendingLimitInUsd: zod_1.z.number().describe("The user's daily spending limit in USD."),
|
|
74
|
+
currentCount: zod_1.z.number().describe('The number of sends already made in the current window.'),
|
|
75
|
+
maxSends: zod_1.z.number().describe('The maximum number of sends allowed in the current window.'),
|
|
76
|
+
secondsUntilReset: zod_1.z.number().describe('Number of seconds remaining until the counter resets.'),
|
|
77
|
+
timeWindowSeconds: zod_1.z.number().describe('The duration of the time window in seconds.'),
|
|
53
78
|
});
|
|
79
|
+
/**
|
|
80
|
+
* Commit allow result schema
|
|
81
|
+
*/
|
|
54
82
|
exports.commitAllowResultSchema = zod_1.z.object({
|
|
55
|
-
|
|
83
|
+
recorded: zod_1.z.boolean().describe('Whether the send was recorded in the policy state.'),
|
|
84
|
+
newCount: zod_1.z.number().describe('The updated number of sends recorded after this commit.'),
|
|
85
|
+
remainingSends: zod_1.z
|
|
86
|
+
.number()
|
|
87
|
+
.describe('How many sends remain available in the current window after commit.'),
|
|
56
88
|
});
|
|
89
|
+
/**
|
|
90
|
+
* Commit deny result schema (though commit rarely denies)
|
|
91
|
+
*/
|
|
57
92
|
exports.commitDenyResultSchema = zod_1.z.object({
|
|
58
|
-
|
|
93
|
+
reason: zod_1.z.string().describe('A string containing the error message if the commit failed.'),
|
|
59
94
|
});
|
|
60
95
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/lib/schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/lib/schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;GAEG;AACU,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,OAAC;SACF,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,mCAAmC,CAAC;SAC3C,QAAQ,CAAC,8DAA8D,CAAC;IAC3E,MAAM,EAAE,OAAC;SACN,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,wBAAwB,CAAC;SAChC,QAAQ,CAAC,iFAAiF,CAAC;CAC/F,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,gBAAgB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,OAAC;SACR,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,oEAAoE,CAAC;IACjF,iBAAiB,EAAE,OAAC;SACjB,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,mEAAmE,CAAC;CACjF,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,YAAY,EAAE,OAAC;SACZ,MAAM,E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