@lit-protocol/vincent-policy-spending-limit 1.0.0-1
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 +64 -0
- package/dist/CONTRIBUTING.md +89 -0
- package/dist/README.md +64 -0
- package/dist/package.json +27 -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 +14 -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 +8 -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 +11 -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 +21 -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 +28 -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 +21 -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 +67 -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 +113 -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 +9 -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 +143 -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 +27 -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 +21 -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 +43 -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 +116 -0
- package/package.json +26 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const sendSpendTx: ({ appId, amountSpentUsd, maxSpendingLimitInUsd, spendingLimitDuration, pkpEthAddress, pkpPubKey, }: {
|
|
2
|
+
appId: number;
|
|
3
|
+
amountSpentUsd: number;
|
|
4
|
+
maxSpendingLimitInUsd: number;
|
|
5
|
+
spendingLimitDuration: number;
|
|
6
|
+
pkpEthAddress: string;
|
|
7
|
+
pkpPubKey: string;
|
|
8
|
+
}) => Promise<any>;
|
|
9
|
+
//# sourceMappingURL=send-spend-tx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-spend-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/send-spend-tx.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,WAAW,GAAU,oGAO/B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB,iBAqGA,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendSpendTx = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const spending_limit_contract_1 = require("./spending-limit-contract");
|
|
6
|
+
const sign_tx_1 = require("./sign-tx");
|
|
7
|
+
const sendSpendTx = async ({ appId, amountSpentUsd, maxSpendingLimitInUsd, spendingLimitDuration, pkpEthAddress, pkpPubKey, }) => {
|
|
8
|
+
const spendingLimitContract = (0, spending_limit_contract_1.getSpendingLimitContractInstance)();
|
|
9
|
+
const buildPartialSpendTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'send spend tx gas estimation' }, async () => {
|
|
10
|
+
console.log(`Preparing transaction to send to Spending Limit Contract: ${spending_limit_contract_1.SPENDING_LIMIT_CONTRACT_ADDRESS} (sendSpendTx)`);
|
|
11
|
+
try {
|
|
12
|
+
console.log(`Estimating gas for spending limit transaction...`);
|
|
13
|
+
// Get current gas price and nonce
|
|
14
|
+
const [feeData, nonce] = await Promise.all([
|
|
15
|
+
spendingLimitContract.provider.getFeeData(),
|
|
16
|
+
spendingLimitContract.provider.getTransactionCount(pkpEthAddress),
|
|
17
|
+
]);
|
|
18
|
+
// Encode function data
|
|
19
|
+
const txData = spendingLimitContract.interface.encodeFunctionData('spend', [
|
|
20
|
+
BigInt(appId),
|
|
21
|
+
BigInt(amountSpentUsd),
|
|
22
|
+
BigInt(maxSpendingLimitInUsd),
|
|
23
|
+
BigInt(spendingLimitDuration),
|
|
24
|
+
]);
|
|
25
|
+
// Estimate gas
|
|
26
|
+
const estimatedGas = await spendingLimitContract.estimateGas.spend(BigInt(appId), BigInt(amountSpentUsd), BigInt(maxSpendingLimitInUsd), BigInt(spendingLimitDuration), { from: pkpEthAddress });
|
|
27
|
+
console.log('fetching nonce for pkpEthAddress: ', pkpEthAddress, ' (sendSpendTx)');
|
|
28
|
+
return JSON.stringify({
|
|
29
|
+
status: 'success',
|
|
30
|
+
data: txData,
|
|
31
|
+
gasLimit: estimatedGas.toString(),
|
|
32
|
+
maxFeePerGas: feeData.maxFeePerGas?.toString() || '0',
|
|
33
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas?.toString() || '0',
|
|
34
|
+
nonce: nonce.toString(),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return attemptToDecodeSpendLimitExceededError(error, spendingLimitContract);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const parsedBuildPartialSpendTxResponse = JSON.parse(buildPartialSpendTxResponse);
|
|
42
|
+
if (parsedBuildPartialSpendTxResponse.status === 'error') {
|
|
43
|
+
throw new Error(`Error estimating gas for spending limit transaction: ${parsedBuildPartialSpendTxResponse.error}`);
|
|
44
|
+
}
|
|
45
|
+
const { gasLimit, maxFeePerGas, maxPriorityFeePerGas, nonce, data } = parsedBuildPartialSpendTxResponse;
|
|
46
|
+
// Create ethers Transaction object
|
|
47
|
+
const unsignedSpendTx = {
|
|
48
|
+
to: spending_limit_contract_1.SPENDING_LIMIT_CONTRACT_ADDRESS,
|
|
49
|
+
data: data,
|
|
50
|
+
value: ethers_1.ethers.BigNumber.from(0),
|
|
51
|
+
gasLimit: ethers_1.ethers.BigNumber.from(gasLimit),
|
|
52
|
+
maxFeePerGas: ethers_1.ethers.BigNumber.from(maxFeePerGas),
|
|
53
|
+
maxPriorityFeePerGas: ethers_1.ethers.BigNumber.from(maxPriorityFeePerGas),
|
|
54
|
+
nonce: Number(nonce),
|
|
55
|
+
chainId: 175188,
|
|
56
|
+
type: 2, // EIP-1559 transaction type
|
|
57
|
+
};
|
|
58
|
+
console.log(`Signing spend transaction: ${safeStringify(unsignedSpendTx)} (sendSpendTx)`);
|
|
59
|
+
const signedSpendTx = await (0, sign_tx_1.signTx)(pkpPubKey, unsignedSpendTx, 'spendingLimitSig');
|
|
60
|
+
console.log(`Broadcasting spend transaction...`);
|
|
61
|
+
const spendTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'spendTxSender' }, async () => {
|
|
62
|
+
try {
|
|
63
|
+
const txResponse = await spendingLimitContract.provider.sendTransaction(signedSpendTx);
|
|
64
|
+
return JSON.stringify({
|
|
65
|
+
status: 'success',
|
|
66
|
+
txHash: txResponse.hash,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return attemptToDecodeSpendLimitExceededError(error, spendingLimitContract);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
console.log(`Spend transaction response: ${spendTxResponse} (sendSpendTx)`);
|
|
74
|
+
const parsedSpendTxResponse = JSON.parse(spendTxResponse);
|
|
75
|
+
if (parsedSpendTxResponse.status === 'error') {
|
|
76
|
+
throw new Error(`Error sending spend transaction: ${parsedSpendTxResponse.error}`);
|
|
77
|
+
}
|
|
78
|
+
return parsedSpendTxResponse.txHash;
|
|
79
|
+
};
|
|
80
|
+
exports.sendSpendTx = sendSpendTx;
|
|
81
|
+
const safeStringify = (obj) => {
|
|
82
|
+
return JSON.stringify(obj, (_, value) => {
|
|
83
|
+
if (typeof value === 'bigint') {
|
|
84
|
+
return value.toString();
|
|
85
|
+
}
|
|
86
|
+
if (ethers_1.ethers.BigNumber.isBigNumber(value)) {
|
|
87
|
+
return value.toString();
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const attemptToDecodeSpendLimitExceededError = (error, contract) => {
|
|
93
|
+
try {
|
|
94
|
+
// Check if it's an ethers revert error with data
|
|
95
|
+
if (error && typeof error === 'object' && 'reason' in error) {
|
|
96
|
+
const ethersError = error;
|
|
97
|
+
// Try to decode custom error from error data
|
|
98
|
+
if (ethersError.data) {
|
|
99
|
+
try {
|
|
100
|
+
const decoded = contract.interface.parseError(ethersError.data);
|
|
101
|
+
if (decoded.name === 'SpendLimitExceeded' && decoded.args) {
|
|
102
|
+
const [user, appId, amount, limit] = decoded.args;
|
|
103
|
+
return JSON.stringify({
|
|
104
|
+
status: 'error',
|
|
105
|
+
error: `Spending limit exceeded. User: ${user}, App ID: ${appId.toString()}, Attempted spend amount: ${amount.toString()}, Daily spend limit: ${limit.toString()}`,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (parseError) {
|
|
110
|
+
// If parsing fails, fall through to generic error handling
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Handle standard revert with reason string
|
|
114
|
+
if (ethersError.reason) {
|
|
115
|
+
return JSON.stringify({
|
|
116
|
+
status: 'error',
|
|
117
|
+
error: `Contract reverted: ${ethersError.reason}`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Handle ethers CALL_EXCEPTION errors
|
|
122
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
123
|
+
const ethersError = error;
|
|
124
|
+
if (ethersError.code === 'CALL_EXCEPTION' && ethersError.errorArgs) {
|
|
125
|
+
const [user, appId, amount, limit] = ethersError.errorArgs;
|
|
126
|
+
return JSON.stringify({
|
|
127
|
+
status: 'error',
|
|
128
|
+
error: `Spending limit exceeded. User: ${user}, App ID: ${appId.toString()}, Attempted spend amount: ${amount.toString()}, Daily spend limit: ${limit.toString()}`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (decodingError) {
|
|
134
|
+
return JSON.stringify({
|
|
135
|
+
status: 'error',
|
|
136
|
+
error: `Failed to decode revert reason: ${decodingError}`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return JSON.stringify({
|
|
140
|
+
status: 'error',
|
|
141
|
+
error: error?.toString() || 'Unknown error',
|
|
142
|
+
});
|
|
143
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/sign-tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAYhC,eAAO,MAAM,MAAM,GAAU,cAAc,MAAM,EAAE,IAAI,MAAM,CAAC,WAAW,EAAE,SAAS,MAAM,oBA2BzF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signTx = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const signTx = async (pkpPublicKey, tx, sigName) => {
|
|
6
|
+
// Remove 0x prefix if it exists, Lit expects a hex string without 0x prefix
|
|
7
|
+
const publicKeyForLit = pkpPublicKey.replace(/^0x/, '');
|
|
8
|
+
console.log(`Signing using PKP Public Key: ${publicKeyForLit} (signTx)`);
|
|
9
|
+
const unsignedSerializedTx = ethers_1.ethers.utils.serializeTransaction(tx);
|
|
10
|
+
const txHash = ethers_1.ethers.utils.keccak256(unsignedSerializedTx);
|
|
11
|
+
console.log('Tx hash (signTx)', txHash);
|
|
12
|
+
const signatureResponse = await Lit.Actions.signAndCombineEcdsa({
|
|
13
|
+
toSign: ethers_1.ethers.utils.arrayify(txHash),
|
|
14
|
+
publicKey: publicKeyForLit,
|
|
15
|
+
sigName,
|
|
16
|
+
});
|
|
17
|
+
const { r, s, v } = JSON.parse(signatureResponse);
|
|
18
|
+
const ethersJoinedSignature = ethers_1.ethers.utils.joinSignature({
|
|
19
|
+
r: '0x' + r.substring(2),
|
|
20
|
+
s: '0x' + s,
|
|
21
|
+
v: v,
|
|
22
|
+
});
|
|
23
|
+
const signedSerializedTx = ethers_1.ethers.utils.serializeTransaction(tx, ethersJoinedSignature);
|
|
24
|
+
console.log('Signed serialized tx (signTx)', signedSerializedTx);
|
|
25
|
+
return signedSerializedTx;
|
|
26
|
+
};
|
|
27
|
+
exports.signTx = signTx;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-limit-contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/spending-limit-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkBhC,eAAO,MAAM,+BAA+B,+CAA+C,CAAC;AAE5F,eAAO,MAAM,gCAAgC,uBAM5C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSpendingLimitContractInstance = exports.SPENDING_LIMIT_CONTRACT_ADDRESS = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const SPENDING_LIMIT_CONTRACT_ABI = [
|
|
6
|
+
'event Spent(address indexed spender, uint256 indexed appId, uint256 amount, uint256 timestamp)',
|
|
7
|
+
'error EmptyAppIdsArray(address user)',
|
|
8
|
+
'error SpendLimitExceeded(address user, uint256 appId, uint256 amount, uint256 limit)',
|
|
9
|
+
'error ZeroAppIdNotAllowed(address user)',
|
|
10
|
+
'error ZeroDurationQuery(address user)',
|
|
11
|
+
'function checkLimit(address user, uint256 appId, uint256 amountToSpend, uint256 userMaxSpendLimit, uint256 duration) view returns (bool)',
|
|
12
|
+
'function getAppSpendHistory(address user, uint256 appId, uint256 duration) view returns ((uint256 timestamp, uint256 runningSpend)[] history)',
|
|
13
|
+
'function getAppsSpentInDuration(address user, uint256[] appIds, uint256 duration) view returns (uint256)',
|
|
14
|
+
'function getTotalSpent(address user, uint256 duration) view returns (uint256)',
|
|
15
|
+
'function spend(uint256 appId, uint256 amount, uint256 userMaxSpendLimit, uint256 duration)',
|
|
16
|
+
];
|
|
17
|
+
exports.SPENDING_LIMIT_CONTRACT_ADDRESS = '0x756fa449de893446b26e10c6c66e62ccabee908c';
|
|
18
|
+
const getSpendingLimitContractInstance = () => {
|
|
19
|
+
return new ethers_1.ethers.Contract(exports.SPENDING_LIMIT_CONTRACT_ADDRESS, SPENDING_LIMIT_CONTRACT_ABI, new ethers_1.ethers.providers.StaticJsonRpcProvider('https://yellowstone-rpc.litprotocol.com/'));
|
|
20
|
+
};
|
|
21
|
+
exports.getSpendingLimitContractInstance = getSpendingLimitContractInstance;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const toolParamsSchema: z.ZodObject<{
|
|
3
|
+
ethRpcUrl: z.ZodString;
|
|
4
|
+
rpcUrlForUniswap: z.ZodString;
|
|
5
|
+
chainIdForUniswap: z.ZodNumber;
|
|
6
|
+
tokenAddress: z.ZodString;
|
|
7
|
+
tokenDecimals: z.ZodNumber;
|
|
8
|
+
buyAmount: z.ZodNumber;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
ethRpcUrl: string;
|
|
11
|
+
rpcUrlForUniswap: string;
|
|
12
|
+
chainIdForUniswap: number;
|
|
13
|
+
tokenAddress: string;
|
|
14
|
+
tokenDecimals: number;
|
|
15
|
+
buyAmount: number;
|
|
16
|
+
}, {
|
|
17
|
+
ethRpcUrl: string;
|
|
18
|
+
rpcUrlForUniswap: string;
|
|
19
|
+
chainIdForUniswap: number;
|
|
20
|
+
tokenAddress: string;
|
|
21
|
+
tokenDecimals: number;
|
|
22
|
+
buyAmount: number;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const userParamsSchema: z.ZodObject<{
|
|
25
|
+
maxDailySpendingLimitInUsdCents: z.ZodBigInt;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
28
|
+
}, {
|
|
29
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const precheckAllowResultSchema: z.ZodObject<{
|
|
32
|
+
maxSpendingLimitInUsd: z.ZodNumber;
|
|
33
|
+
buyAmountInUsd: z.ZodNumber;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
maxSpendingLimitInUsd: number;
|
|
36
|
+
buyAmountInUsd: number;
|
|
37
|
+
}, {
|
|
38
|
+
maxSpendingLimitInUsd: number;
|
|
39
|
+
buyAmountInUsd: number;
|
|
40
|
+
}>;
|
|
41
|
+
export declare const precheckDenyResultSchema: z.ZodObject<{
|
|
42
|
+
reason: z.ZodLiteral<"Attempted buy amount exceeds daily limit">;
|
|
43
|
+
maxSpendingLimitInUsd: z.ZodNumber;
|
|
44
|
+
buyAmountInUsd: z.ZodNumber;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
maxSpendingLimitInUsd: number;
|
|
47
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
48
|
+
buyAmountInUsd: number;
|
|
49
|
+
}, {
|
|
50
|
+
maxSpendingLimitInUsd: number;
|
|
51
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
52
|
+
buyAmountInUsd: number;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const evalAllowResultSchema: z.ZodObject<{
|
|
55
|
+
maxSpendingLimitInUsd: z.ZodNumber;
|
|
56
|
+
buyAmountInUsd: z.ZodNumber;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
maxSpendingLimitInUsd: number;
|
|
59
|
+
buyAmountInUsd: number;
|
|
60
|
+
}, {
|
|
61
|
+
maxSpendingLimitInUsd: number;
|
|
62
|
+
buyAmountInUsd: number;
|
|
63
|
+
}>;
|
|
64
|
+
export declare const evalDenyResultSchema: z.ZodObject<{
|
|
65
|
+
reason: z.ZodString;
|
|
66
|
+
maxSpendingLimitInUsd: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
buyAmountInUsd: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
reason: string;
|
|
70
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
71
|
+
buyAmountInUsd?: number | undefined;
|
|
72
|
+
}, {
|
|
73
|
+
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
|
+
}>;
|
|
87
|
+
export declare const commitAllowResultSchema: z.ZodObject<{
|
|
88
|
+
spendTxHash: z.ZodString;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
spendTxHash: string;
|
|
91
|
+
}, {
|
|
92
|
+
spendTxHash: string;
|
|
93
|
+
}>;
|
|
94
|
+
export declare const commitDenyResultSchema: z.ZodObject<{
|
|
95
|
+
error: z.ZodString;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
error: string;
|
|
98
|
+
}, {
|
|
99
|
+
error: string;
|
|
100
|
+
}>;
|
|
101
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +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,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAO3B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;EAE3B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;EAGpC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAInC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;EAGhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAI/B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;EAG7B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;EAEjC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commitDenyResultSchema = exports.commitAllowResultSchema = exports.commitParamsSchema = exports.evalDenyResultSchema = exports.evalAllowResultSchema = exports.precheckDenyResultSchema = exports.precheckAllowResultSchema = exports.userParamsSchema = exports.toolParamsSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.toolParamsSchema = zod_1.z.object({
|
|
6
|
+
ethRpcUrl: zod_1.z.string(),
|
|
7
|
+
rpcUrlForUniswap: zod_1.z.string(),
|
|
8
|
+
chainIdForUniswap: zod_1.z.number(),
|
|
9
|
+
tokenAddress: zod_1.z.string(),
|
|
10
|
+
tokenDecimals: zod_1.z.number(),
|
|
11
|
+
buyAmount: zod_1.z.number(),
|
|
12
|
+
});
|
|
13
|
+
exports.userParamsSchema = zod_1.z.object({
|
|
14
|
+
maxDailySpendingLimitInUsdCents: zod_1.z.bigint(),
|
|
15
|
+
});
|
|
16
|
+
exports.precheckAllowResultSchema = zod_1.z.object({
|
|
17
|
+
maxSpendingLimitInUsd: zod_1.z.number(),
|
|
18
|
+
buyAmountInUsd: zod_1.z.number(),
|
|
19
|
+
});
|
|
20
|
+
exports.precheckDenyResultSchema = zod_1.z.object({
|
|
21
|
+
reason: zod_1.z.literal('Attempted buy amount exceeds daily limit'),
|
|
22
|
+
maxSpendingLimitInUsd: zod_1.z.number(),
|
|
23
|
+
buyAmountInUsd: zod_1.z.number(),
|
|
24
|
+
});
|
|
25
|
+
exports.evalAllowResultSchema = zod_1.z.object({
|
|
26
|
+
maxSpendingLimitInUsd: zod_1.z.number(),
|
|
27
|
+
buyAmountInUsd: zod_1.z.number(),
|
|
28
|
+
});
|
|
29
|
+
exports.evalDenyResultSchema = zod_1.z.object({
|
|
30
|
+
reason: zod_1.z.string(),
|
|
31
|
+
maxSpendingLimitInUsd: zod_1.z.number().optional(),
|
|
32
|
+
buyAmountInUsd: zod_1.z.number().optional(),
|
|
33
|
+
});
|
|
34
|
+
exports.commitParamsSchema = zod_1.z.object({
|
|
35
|
+
amountSpentUsd: zod_1.z.number(),
|
|
36
|
+
maxSpendingLimitInUsd: zod_1.z.number(),
|
|
37
|
+
});
|
|
38
|
+
exports.commitAllowResultSchema = zod_1.z.object({
|
|
39
|
+
spendTxHash: zod_1.z.string(),
|
|
40
|
+
});
|
|
41
|
+
exports.commitDenyResultSchema = zod_1.z.object({
|
|
42
|
+
error: zod_1.z.string(),
|
|
43
|
+
});
|
|
@@ -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"}
|