@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,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
|
|
3
|
+
*/
|
|
4
|
+
export declare const bundledVincentPolicy: import("@lit-protocol/vincent-tool-sdk").BundledVincentPolicy<import("node_modules/@lit-protocol/vincent-tool-sdk/dist/src/lib/types").VincentPolicy<"@lit-protocol/vincent-policy-spending-limit", import("zod").ZodObject<{
|
|
5
|
+
ethRpcUrl: import("zod").ZodString;
|
|
6
|
+
rpcUrlForUniswap: import("zod").ZodString;
|
|
7
|
+
chainIdForUniswap: import("zod").ZodNumber;
|
|
8
|
+
tokenAddress: import("zod").ZodString;
|
|
9
|
+
tokenDecimals: import("zod").ZodNumber;
|
|
10
|
+
buyAmount: import("zod").ZodNumber;
|
|
11
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
+
ethRpcUrl: string;
|
|
13
|
+
rpcUrlForUniswap: string;
|
|
14
|
+
chainIdForUniswap: number;
|
|
15
|
+
tokenAddress: string;
|
|
16
|
+
tokenDecimals: number;
|
|
17
|
+
buyAmount: number;
|
|
18
|
+
}, {
|
|
19
|
+
ethRpcUrl: string;
|
|
20
|
+
rpcUrlForUniswap: string;
|
|
21
|
+
chainIdForUniswap: number;
|
|
22
|
+
tokenAddress: string;
|
|
23
|
+
tokenDecimals: number;
|
|
24
|
+
buyAmount: number;
|
|
25
|
+
}>, import("zod").ZodObject<{
|
|
26
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
27
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
28
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
29
|
+
}, {
|
|
30
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
31
|
+
}>, import("zod").ZodObject<{
|
|
32
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
33
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
34
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
35
|
+
maxSpendingLimitInUsd: number;
|
|
36
|
+
buyAmountInUsd: number;
|
|
37
|
+
}, {
|
|
38
|
+
maxSpendingLimitInUsd: number;
|
|
39
|
+
buyAmountInUsd: number;
|
|
40
|
+
}>, import("zod").ZodObject<{
|
|
41
|
+
reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
|
|
42
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
43
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
44
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
45
|
+
maxSpendingLimitInUsd: number;
|
|
46
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
47
|
+
buyAmountInUsd: number;
|
|
48
|
+
}, {
|
|
49
|
+
maxSpendingLimitInUsd: number;
|
|
50
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
51
|
+
buyAmountInUsd: number;
|
|
52
|
+
}>, import("zod").ZodObject<{
|
|
53
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
54
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
55
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
56
|
+
maxSpendingLimitInUsd: number;
|
|
57
|
+
buyAmountInUsd: number;
|
|
58
|
+
}, {
|
|
59
|
+
maxSpendingLimitInUsd: number;
|
|
60
|
+
buyAmountInUsd: number;
|
|
61
|
+
}>, import("zod").ZodObject<{
|
|
62
|
+
reason: import("zod").ZodString;
|
|
63
|
+
maxSpendingLimitInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
64
|
+
buyAmountInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
65
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
66
|
+
reason: string;
|
|
67
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
68
|
+
buyAmountInUsd?: number | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
reason: string;
|
|
71
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
72
|
+
buyAmountInUsd?: number | undefined;
|
|
73
|
+
}>, import("zod").ZodObject<{
|
|
74
|
+
amountSpentUsd: import("zod").ZodNumber;
|
|
75
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
76
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
77
|
+
amountSpentUsd: number;
|
|
78
|
+
maxSpendingLimitInUsd: number;
|
|
79
|
+
}, {
|
|
80
|
+
amountSpentUsd: number;
|
|
81
|
+
maxSpendingLimitInUsd: number;
|
|
82
|
+
}>, import("zod").ZodObject<{
|
|
83
|
+
spendTxHash: import("zod").ZodString;
|
|
84
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
85
|
+
spendTxHash: string;
|
|
86
|
+
}, {
|
|
87
|
+
spendTxHash: string;
|
|
88
|
+
}>, import("zod").ZodObject<{
|
|
89
|
+
error: import("zod").ZodString;
|
|
90
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
91
|
+
error: string;
|
|
92
|
+
}, {
|
|
93
|
+
error: string;
|
|
94
|
+
}>, import("node_modules/@lit-protocol/vincent-tool-sdk/dist/src/lib/types").PolicyLifecycleFunction<import("zod").ZodObject<{
|
|
95
|
+
ethRpcUrl: import("zod").ZodString;
|
|
96
|
+
rpcUrlForUniswap: import("zod").ZodString;
|
|
97
|
+
chainIdForUniswap: import("zod").ZodNumber;
|
|
98
|
+
tokenAddress: import("zod").ZodString;
|
|
99
|
+
tokenDecimals: import("zod").ZodNumber;
|
|
100
|
+
buyAmount: import("zod").ZodNumber;
|
|
101
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
102
|
+
ethRpcUrl: string;
|
|
103
|
+
rpcUrlForUniswap: string;
|
|
104
|
+
chainIdForUniswap: number;
|
|
105
|
+
tokenAddress: string;
|
|
106
|
+
tokenDecimals: number;
|
|
107
|
+
buyAmount: number;
|
|
108
|
+
}, {
|
|
109
|
+
ethRpcUrl: string;
|
|
110
|
+
rpcUrlForUniswap: string;
|
|
111
|
+
chainIdForUniswap: number;
|
|
112
|
+
tokenAddress: string;
|
|
113
|
+
tokenDecimals: number;
|
|
114
|
+
buyAmount: number;
|
|
115
|
+
}>, import("zod").ZodObject<{
|
|
116
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
117
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
118
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
119
|
+
}, {
|
|
120
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
121
|
+
}>, import("zod").ZodObject<{
|
|
122
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
123
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
124
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
125
|
+
maxSpendingLimitInUsd: number;
|
|
126
|
+
buyAmountInUsd: number;
|
|
127
|
+
}, {
|
|
128
|
+
maxSpendingLimitInUsd: number;
|
|
129
|
+
buyAmountInUsd: number;
|
|
130
|
+
}>, import("zod").ZodObject<{
|
|
131
|
+
reason: import("zod").ZodString;
|
|
132
|
+
maxSpendingLimitInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
133
|
+
buyAmountInUsd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
134
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
135
|
+
reason: string;
|
|
136
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
137
|
+
buyAmountInUsd?: number | undefined;
|
|
138
|
+
}, {
|
|
139
|
+
reason: string;
|
|
140
|
+
maxSpendingLimitInUsd?: number | undefined;
|
|
141
|
+
buyAmountInUsd?: number | undefined;
|
|
142
|
+
}>>, import("node_modules/@lit-protocol/vincent-tool-sdk/dist/src/lib/types").PolicyLifecycleFunction<import("zod").ZodObject<{
|
|
143
|
+
ethRpcUrl: import("zod").ZodString;
|
|
144
|
+
rpcUrlForUniswap: import("zod").ZodString;
|
|
145
|
+
chainIdForUniswap: import("zod").ZodNumber;
|
|
146
|
+
tokenAddress: import("zod").ZodString;
|
|
147
|
+
tokenDecimals: import("zod").ZodNumber;
|
|
148
|
+
buyAmount: import("zod").ZodNumber;
|
|
149
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
150
|
+
ethRpcUrl: string;
|
|
151
|
+
rpcUrlForUniswap: string;
|
|
152
|
+
chainIdForUniswap: number;
|
|
153
|
+
tokenAddress: string;
|
|
154
|
+
tokenDecimals: number;
|
|
155
|
+
buyAmount: number;
|
|
156
|
+
}, {
|
|
157
|
+
ethRpcUrl: string;
|
|
158
|
+
rpcUrlForUniswap: string;
|
|
159
|
+
chainIdForUniswap: number;
|
|
160
|
+
tokenAddress: string;
|
|
161
|
+
tokenDecimals: number;
|
|
162
|
+
buyAmount: number;
|
|
163
|
+
}>, import("zod").ZodObject<{
|
|
164
|
+
maxDailySpendingLimitInUsdCents: import("zod").ZodBigInt;
|
|
165
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
166
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
167
|
+
}, {
|
|
168
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
169
|
+
}>, import("zod").ZodObject<{
|
|
170
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
171
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
172
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
173
|
+
maxSpendingLimitInUsd: number;
|
|
174
|
+
buyAmountInUsd: number;
|
|
175
|
+
}, {
|
|
176
|
+
maxSpendingLimitInUsd: number;
|
|
177
|
+
buyAmountInUsd: number;
|
|
178
|
+
}>, import("zod").ZodObject<{
|
|
179
|
+
reason: import("zod").ZodLiteral<"Attempted buy amount exceeds daily limit">;
|
|
180
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
181
|
+
buyAmountInUsd: import("zod").ZodNumber;
|
|
182
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
183
|
+
maxSpendingLimitInUsd: number;
|
|
184
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
185
|
+
buyAmountInUsd: number;
|
|
186
|
+
}, {
|
|
187
|
+
maxSpendingLimitInUsd: number;
|
|
188
|
+
reason: "Attempted buy amount exceeds daily limit";
|
|
189
|
+
buyAmountInUsd: number;
|
|
190
|
+
}>>, import("node_modules/@lit-protocol/vincent-tool-sdk/dist/src/lib/types").CommitLifecycleFunction<import("zod").ZodObject<{
|
|
191
|
+
amountSpentUsd: import("zod").ZodNumber;
|
|
192
|
+
maxSpendingLimitInUsd: import("zod").ZodNumber;
|
|
193
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
194
|
+
amountSpentUsd: number;
|
|
195
|
+
maxSpendingLimitInUsd: number;
|
|
196
|
+
}, {
|
|
197
|
+
amountSpentUsd: number;
|
|
198
|
+
maxSpendingLimitInUsd: number;
|
|
199
|
+
}>, import("zod").ZodObject<{
|
|
200
|
+
spendTxHash: import("zod").ZodString;
|
|
201
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
202
|
+
spendTxHash: string;
|
|
203
|
+
}, {
|
|
204
|
+
spendTxHash: string;
|
|
205
|
+
}>, import("zod").ZodObject<{
|
|
206
|
+
error: import("zod").ZodString;
|
|
207
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
208
|
+
error: string;
|
|
209
|
+
}, {
|
|
210
|
+
error: string;
|
|
211
|
+
}>>>, string>;
|
|
212
|
+
//# sourceMappingURL=vincent-bundled-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincent-bundled-policy.d.ts","sourceRoot":"","sources":["../../../src/generated/vincent-bundled-policy.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAA0D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bundledVincentPolicy = void 0;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const vincent_tool_sdk_1 = require("@lit-protocol/vincent-tool-sdk");
|
|
9
|
+
const vincent_policy_1 = require("../lib/vincent-policy");
|
|
10
|
+
const vincent_policy_metadata_json_1 = tslib_1.__importDefault(require("./vincent-policy-metadata.json"));
|
|
11
|
+
if (!vincent_policy_metadata_json_1.default.ipfsCid) {
|
|
12
|
+
throw new Error('ipfsCid is not defined in metadata JSON file');
|
|
13
|
+
}
|
|
14
|
+
exports.bundledVincentPolicy = (0, vincent_tool_sdk_1.asBundledVincentPolicy)(vincent_policy_1.vincentPolicy, vincent_policy_metadata_json_1.default.ipfsCid);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { asBundledVincentPolicy } from '@lit-protocol/vincent-tool-sdk';
|
|
6
|
+
import { vincentPolicy } from '../lib/vincent-policy';
|
|
7
|
+
import metadata from './vincent-policy-metadata.json';
|
|
8
|
+
|
|
9
|
+
if(!metadata.ipfsCid) {
|
|
10
|
+
throw new Error('ipfsCid is not defined in metadata JSON file');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const bundledVincentPolicy = asBundledVincentPolicy(vincentPolicy, metadata.ipfsCid);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,qBAAqB,MAAM,0CAA0C,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vincentPolicyMetadata = exports.bundledVincentPolicy = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var vincent_bundled_policy_1 = require("./generated/vincent-bundled-policy");
|
|
6
|
+
Object.defineProperty(exports, "bundledVincentPolicy", { enumerable: true, get: function () { return vincent_bundled_policy_1.bundledVincentPolicy; } });
|
|
7
|
+
const vincentPolicyMetadata = tslib_1.__importStar(require("./generated/vincent-policy-metadata.json"));
|
|
8
|
+
exports.vincentPolicyMetadata = vincentPolicyMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit-action.d.ts","sourceRoot":"","sources":["../../../src/lib/lit-action.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vincent_tool_sdk_1 = require("@lit-protocol/vincent-tool-sdk");
|
|
4
|
+
const vincent_policy_1 = require("./vincent-policy");
|
|
5
|
+
(async () => {
|
|
6
|
+
return await (0, vincent_tool_sdk_1.vincentPolicyHandler)({
|
|
7
|
+
vincentPolicy: vincent_policy_1.vincentPolicy,
|
|
8
|
+
context,
|
|
9
|
+
toolParams,
|
|
10
|
+
});
|
|
11
|
+
})();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export declare const calculateUsdValue: ({ ethRpcUrl, chainlinkPriceFeedAddress, amountInWeth, }: {
|
|
3
|
+
ethRpcUrl: string;
|
|
4
|
+
chainlinkPriceFeedAddress: string;
|
|
5
|
+
amountInWeth: ethers.BigNumber;
|
|
6
|
+
}) => Promise<ethers.BigNumber>;
|
|
7
|
+
//# sourceMappingURL=calculate-usd-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-usd-value.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/calculate-usd-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,iBAAiB,GAAU,yDAIrC;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB,EAAE,MAAM,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;CAChC,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAgB3B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateUsdValue = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const get_eth_usd_price_1 = require("./get-eth-usd-price");
|
|
6
|
+
const calculateUsdValue = async ({ ethRpcUrl, chainlinkPriceFeedAddress, amountInWeth, }) => {
|
|
7
|
+
const ethPriceInUsd = await (0, get_eth_usd_price_1.getEthUsdPriceFromChainlink)({ ethRpcUrl, chainlinkPriceFeedAddress });
|
|
8
|
+
// Calculate USD value (8 decimals precision)
|
|
9
|
+
const CHAINLINK_DECIMALS = 8;
|
|
10
|
+
const WETH_DECIMALS = 18; // WETH decimals
|
|
11
|
+
const amountInUsd = amountInWeth
|
|
12
|
+
.mul(ethPriceInUsd)
|
|
13
|
+
.div(ethers_1.ethers.utils.parseUnits('1', WETH_DECIMALS));
|
|
14
|
+
console.log(`Calculate token amount in USDC (calculateUsdValue)`, {
|
|
15
|
+
tokenAmountInWeth: ethers_1.ethers.utils.formatUnits(amountInWeth, WETH_DECIMALS),
|
|
16
|
+
ethPriceInUsd: ethers_1.ethers.utils.formatUnits(ethPriceInUsd, CHAINLINK_DECIMALS),
|
|
17
|
+
tokenAmountInUsd: ethers_1.ethers.utils.formatUnits(amountInUsd, CHAINLINK_DECIMALS),
|
|
18
|
+
});
|
|
19
|
+
return amountInUsd;
|
|
20
|
+
};
|
|
21
|
+
exports.calculateUsdValue = calculateUsdValue;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const checkIfBuyAmountAllowed: ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, buyAmount, maxDailySpendingLimitInUsdCents, pkpEthAddress, appId, }: {
|
|
2
|
+
ethRpcUrl: string;
|
|
3
|
+
rpcUrlForUniswap: string;
|
|
4
|
+
chainIdForUniswap: number;
|
|
5
|
+
tokenAddress: `0x${string}`;
|
|
6
|
+
tokenDecimals: number;
|
|
7
|
+
buyAmount: number;
|
|
8
|
+
maxDailySpendingLimitInUsdCents: bigint;
|
|
9
|
+
pkpEthAddress: `0x${string}`;
|
|
10
|
+
appId: number;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
buyAmountAllowed: boolean;
|
|
13
|
+
buyAmountInUsd: bigint;
|
|
14
|
+
adjustedMaxDailySpendingLimit: bigint;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=check-spending-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-spending-limit.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/check-spending-limit.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,GAAU,oJAU3C;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B,EAAE,MAAM,CAAC;IACxC,aAAa,EAAE,KAAK,MAAM,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,OAAO,CAAC;IACV,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,6BAA6B,EAAE,MAAM,CAAC;CACvC,CAoCA,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIfBuyAmountAllowed = void 0;
|
|
4
|
+
const get_token_amount_in_usd_1 = require("./get-token-amount-in-usd");
|
|
5
|
+
const spending_limit_contract_1 = require("./spending-limit-contract");
|
|
6
|
+
const checkIfBuyAmountAllowed = async ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenDecimals, buyAmount, maxDailySpendingLimitInUsdCents, pkpEthAddress, appId, }) => {
|
|
7
|
+
const buyAmountInUsd = await (0, get_token_amount_in_usd_1.getTokenAmountInUsd)({
|
|
8
|
+
ethRpcUrl,
|
|
9
|
+
rpcUrlForUniswap,
|
|
10
|
+
chainIdForUniswap,
|
|
11
|
+
tokenAddress,
|
|
12
|
+
tokenDecimals,
|
|
13
|
+
tokenAmount: buyAmount,
|
|
14
|
+
});
|
|
15
|
+
// maxDailySpendingLimitInUsdCents has 2 decimal precision, but tokenAmountInUsd has 8,
|
|
16
|
+
// so we multiply by 10^6 to match the precision
|
|
17
|
+
const adjustedMaxDailySpendingLimit = maxDailySpendingLimitInUsdCents * 1000000n;
|
|
18
|
+
console.log(`Adjusted maxDailySpendingLimitInUsdCents to 8 decimal precision: ${adjustedMaxDailySpendingLimit.toString()} (spendingLimitPolicyPrecheck)`);
|
|
19
|
+
const spendingLimitContract = (0, spending_limit_contract_1.getSpendingLimitContractInstance)();
|
|
20
|
+
const buyAmountAllowed = await spendingLimitContract.checkLimit(pkpEthAddress, BigInt(appId), buyAmountInUsd.toBigInt(), adjustedMaxDailySpendingLimit, 86400n);
|
|
21
|
+
console.log(`Buy amount allowed: ${JSON.stringify(buyAmountAllowed)} (spendingLimitPolicyPrecheck)`);
|
|
22
|
+
return {
|
|
23
|
+
buyAmountAllowed,
|
|
24
|
+
buyAmountInUsd: buyAmountInUsd.toBigInt(),
|
|
25
|
+
adjustedMaxDailySpendingLimit,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.checkIfBuyAmountAllowed = checkIfBuyAmountAllowed;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export declare const getEthUsdPriceFromChainlink: ({ chainlinkPriceFeedAddress, ethRpcUrl, }: {
|
|
3
|
+
chainlinkPriceFeedAddress: string;
|
|
4
|
+
ethRpcUrl: string;
|
|
5
|
+
}) => Promise<ethers.BigNumber>;
|
|
6
|
+
//# sourceMappingURL=get-eth-usd-price.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-eth-usd-price.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-eth-usd-price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,eAAO,MAAM,2BAA2B,GAAU,2CAG/C;IACD,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAiB3B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEthUsdPriceFromChainlink = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const CHAINLINK_AGGREGATOR_ABI = [
|
|
6
|
+
'function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)',
|
|
7
|
+
];
|
|
8
|
+
const getEthUsdPriceFromChainlink = async ({ chainlinkPriceFeedAddress, ethRpcUrl, }) => {
|
|
9
|
+
console.log(`Getting ETH price in USD from Chainlink (getEthUsdPriceFromChainlink)`, {
|
|
10
|
+
chainlinkPriceFeedAddress,
|
|
11
|
+
ethRpcUrl,
|
|
12
|
+
});
|
|
13
|
+
const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider(ethRpcUrl);
|
|
14
|
+
const contract = new ethers_1.ethers.Contract(chainlinkPriceFeedAddress, CHAINLINK_AGGREGATOR_ABI, provider);
|
|
15
|
+
const [_, answer] = await contract.latestRoundData();
|
|
16
|
+
console.log(`Got ETH price in USD (getEthUsdPriceFromChainlink)`, {
|
|
17
|
+
ethPriceInUsd: ethers_1.ethers.utils.formatUnits(answer, 8),
|
|
18
|
+
});
|
|
19
|
+
return answer;
|
|
20
|
+
};
|
|
21
|
+
exports.getEthUsdPriceFromChainlink = getEthUsdPriceFromChainlink;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export declare const getTokenAmountInUsd: ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenAmount, tokenDecimals, }: {
|
|
3
|
+
ethRpcUrl: string;
|
|
4
|
+
rpcUrlForUniswap: string;
|
|
5
|
+
chainIdForUniswap: number;
|
|
6
|
+
tokenAddress: string;
|
|
7
|
+
tokenDecimals: number;
|
|
8
|
+
tokenAmount: number;
|
|
9
|
+
}) => Promise<ethers.BigNumber>;
|
|
10
|
+
//# sourceMappingURL=get-token-amount-in-usd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-token-amount-in-usd.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-token-amount-in-usd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAWhC,eAAO,MAAM,mBAAmB,GAAU,+FAOvC;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,KAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAiE3B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenAmountInUsd = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const calculate_usd_value_1 = require("./calculate-usd-value");
|
|
6
|
+
const get_uniswap_quote_1 = require("./get-uniswap-quote");
|
|
7
|
+
const ETH_MAINNET_WETH_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
8
|
+
/**
|
|
9
|
+
* Source: https://docs.chain.link/data-feeds/price-feeds/addresses/?network=ethereum&page=1&search=ETH%2FUSD
|
|
10
|
+
*/
|
|
11
|
+
const ETH_MAINNET_ETH_USD_CHAINLINK_FEED = '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419';
|
|
12
|
+
const getTokenAmountInUsd = async ({ ethRpcUrl, rpcUrlForUniswap, chainIdForUniswap, tokenAddress, tokenAmount, tokenDecimals, }) => {
|
|
13
|
+
console.log(`Getting token amount in USD (getTokenAmountInUsd)`, {
|
|
14
|
+
ethRpcUrl,
|
|
15
|
+
rpcUrlForUniswap,
|
|
16
|
+
chainIdForUniswap,
|
|
17
|
+
tokenAddress,
|
|
18
|
+
tokenAmount,
|
|
19
|
+
tokenDecimals,
|
|
20
|
+
ethMainnetWethAddress: ETH_MAINNET_WETH_ADDRESS,
|
|
21
|
+
ethMainnetEthUsdChainlinkFeed: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
|
|
22
|
+
});
|
|
23
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(rpcUrlForUniswap);
|
|
24
|
+
const tokenInContract = new ethers_1.ethers.Contract(tokenAddress, ['function symbol() view returns (string)'], provider);
|
|
25
|
+
const tokenInSymbol = await tokenInContract.symbol();
|
|
26
|
+
console.log(`tokenInSymbol: ${tokenInSymbol} (getTokenAmountInUsd)`);
|
|
27
|
+
// Special case for WETH - no need to get a quote since it's already in ETH terms
|
|
28
|
+
if (tokenInSymbol.toUpperCase() === 'WETH') {
|
|
29
|
+
console.log(`Token is WETH, using amount directly: ${tokenAmount} (getTokenAmountInUsd)`);
|
|
30
|
+
const amountInWeth = ethers_1.ethers.utils.parseUnits(tokenAmount.toString(), tokenDecimals);
|
|
31
|
+
return (0, calculate_usd_value_1.calculateUsdValue)({
|
|
32
|
+
ethRpcUrl,
|
|
33
|
+
chainlinkPriceFeedAddress: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
|
|
34
|
+
amountInWeth,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
console.log(`Getting price in WETH from Uniswap (getTokenAmountInUsd)`, {
|
|
38
|
+
tokenInAddress: tokenAddress,
|
|
39
|
+
tokenInDecimals: tokenDecimals,
|
|
40
|
+
tokenInAmount: tokenAmount,
|
|
41
|
+
tokenOutAddress: ETH_MAINNET_WETH_ADDRESS,
|
|
42
|
+
tokenOutDecimals: 18,
|
|
43
|
+
rpcUrl: rpcUrlForUniswap,
|
|
44
|
+
chainId: chainIdForUniswap,
|
|
45
|
+
});
|
|
46
|
+
const amountInWeth = await (0, get_uniswap_quote_1.getUniswapQuote)({
|
|
47
|
+
tokenInAddress: tokenAddress,
|
|
48
|
+
tokenInDecimals: tokenDecimals,
|
|
49
|
+
tokenInAmount: tokenAmount,
|
|
50
|
+
tokenOutAddress: ETH_MAINNET_WETH_ADDRESS,
|
|
51
|
+
tokenOutDecimals: 18,
|
|
52
|
+
rpcUrl: rpcUrlForUniswap,
|
|
53
|
+
chainId: chainIdForUniswap,
|
|
54
|
+
});
|
|
55
|
+
// Convert WETH amount to USD
|
|
56
|
+
const amountInUsdc = await (0, calculate_usd_value_1.calculateUsdValue)({
|
|
57
|
+
ethRpcUrl,
|
|
58
|
+
chainlinkPriceFeedAddress: ETH_MAINNET_ETH_USD_CHAINLINK_FEED,
|
|
59
|
+
amountInWeth: amountInWeth.bestQuote,
|
|
60
|
+
});
|
|
61
|
+
console.log('Calculated token amount in USDC (getTokenAmountInUsd)', {
|
|
62
|
+
amountInWeth: ethers_1.ethers.utils.formatUnits(amountInWeth.bestQuote, 18),
|
|
63
|
+
amountInUsdc: ethers_1.ethers.utils.formatUnits(amountInUsdc, 8),
|
|
64
|
+
});
|
|
65
|
+
return amountInUsdc;
|
|
66
|
+
};
|
|
67
|
+
exports.getTokenAmountInUsd = getTokenAmountInUsd;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export declare const getUniswapQuote: ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }: {
|
|
3
|
+
rpcUrl: string;
|
|
4
|
+
chainId: number;
|
|
5
|
+
tokenInAddress: string;
|
|
6
|
+
tokenInDecimals: number;
|
|
7
|
+
tokenInAmount: number;
|
|
8
|
+
tokenOutAddress: string;
|
|
9
|
+
tokenOutDecimals: number;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
bestQuote: ethers.BigNumber;
|
|
12
|
+
bestFee: number;
|
|
13
|
+
amountOutMin: ethers.BigNumber;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=get-uniswap-quote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-uniswap-quote.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/get-uniswap-quote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,eAAO,MAAM,eAAe,GAAU,yGAQnC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,KAAG,OAAO,CAAC;IACV,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;CAChC,CA8HA,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUniswapQuote = void 0;
|
|
4
|
+
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const UNISWAP_V3_QUOTER_INTERFACE = new ethers_1.ethers.utils.Interface([
|
|
7
|
+
'function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96)) external returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)',
|
|
8
|
+
]);
|
|
9
|
+
const getUniswapQuote = async ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }) => {
|
|
10
|
+
console.log('Getting Uniswap Quote (getUniswapQuote)', {
|
|
11
|
+
rpcUrl,
|
|
12
|
+
chainId,
|
|
13
|
+
tokenInAddress,
|
|
14
|
+
tokenInDecimals,
|
|
15
|
+
tokenInAmount,
|
|
16
|
+
tokenOutAddress,
|
|
17
|
+
tokenOutDecimals,
|
|
18
|
+
});
|
|
19
|
+
const chainAddressMap = sdk_core_1.CHAIN_TO_ADDRESSES_MAP[chainId];
|
|
20
|
+
if (chainAddressMap === undefined)
|
|
21
|
+
throw new Error(`Unsupported chainId: ${chainId} (getUniswapQuote)`);
|
|
22
|
+
if (chainAddressMap.quoterAddress === undefined)
|
|
23
|
+
throw new Error(`No Uniswap V3 Quoter Address found for chainId: ${chainId} (getUniswapQuote)`);
|
|
24
|
+
const quoterAddress = chainAddressMap.quoterAddress;
|
|
25
|
+
console.log(`Using Quoter Address: ${quoterAddress} (getUniswapQuote)`);
|
|
26
|
+
const uniswapRpcProvider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
|
|
27
|
+
const formattedTokenInAmount = ethers_1.ethers.utils.parseUnits(tokenInAmount.toString(), tokenInDecimals);
|
|
28
|
+
console.log('Amount conversion:', {
|
|
29
|
+
original: tokenInAmount,
|
|
30
|
+
decimals: tokenInDecimals,
|
|
31
|
+
wei: formattedTokenInAmount.toString(),
|
|
32
|
+
formatted: ethers_1.ethers.utils.formatUnits(formattedTokenInAmount, tokenInDecimals),
|
|
33
|
+
});
|
|
34
|
+
let bestQuote = null;
|
|
35
|
+
let bestFee = null;
|
|
36
|
+
const feeTiers = [3000, 500]; // Supported fee tiers (0.3% and 0.05%)
|
|
37
|
+
for (const fee of feeTiers) {
|
|
38
|
+
try {
|
|
39
|
+
const quoteParams = {
|
|
40
|
+
tokenIn: tokenInAddress,
|
|
41
|
+
tokenOut: tokenOutAddress,
|
|
42
|
+
amountIn: formattedTokenInAmount.toString(),
|
|
43
|
+
fee,
|
|
44
|
+
sqrtPriceLimitX96: 0,
|
|
45
|
+
};
|
|
46
|
+
console.log(`Attempting quote with fee tier ${fee / 10000}% (getUniswapQuote)`);
|
|
47
|
+
console.log('Quote parameters (getUniswapQuote):', quoteParams);
|
|
48
|
+
const quote = await uniswapRpcProvider.call({
|
|
49
|
+
to: quoterAddress,
|
|
50
|
+
data: UNISWAP_V3_QUOTER_INTERFACE.encodeFunctionData('quoteExactInputSingle', [
|
|
51
|
+
quoteParams,
|
|
52
|
+
]),
|
|
53
|
+
});
|
|
54
|
+
console.log('Raw quote response (getUniswapQuote):', quote);
|
|
55
|
+
const [amountOut] = UNISWAP_V3_QUOTER_INTERFACE.decodeFunctionResult('quoteExactInputSingle', quote);
|
|
56
|
+
const currentQuote = ethers_1.ethers.BigNumber.from(amountOut);
|
|
57
|
+
if (currentQuote.isZero()) {
|
|
58
|
+
console.log(`Quote is 0 for fee tier ${fee / 10000}% - skipping (getUniswapQuote)`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const formattedQuote = ethers_1.ethers.utils.formatUnits(currentQuote, tokenOutDecimals);
|
|
62
|
+
console.log(`Quote for fee tier ${fee / 10000}% (getUniswapQuote):`, {
|
|
63
|
+
raw: currentQuote.toString(),
|
|
64
|
+
formatted: formattedQuote,
|
|
65
|
+
});
|
|
66
|
+
if (!bestQuote || currentQuote.gt(bestQuote)) {
|
|
67
|
+
bestQuote = currentQuote;
|
|
68
|
+
bestFee = fee;
|
|
69
|
+
console.log(`New best quote found with fee tier ${fee / 10000}% (getUniswapQuote): ${formattedQuote}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const err = error;
|
|
74
|
+
// Check if this is an ethers contract error with expected properties
|
|
75
|
+
if ('reason' in err && 'message' in err && 'code' in err) {
|
|
76
|
+
if (err.reason === 'Unexpected error') {
|
|
77
|
+
console.log(`Unexpected error thrown, probably no pool found for fee tier ${fee / 10000}% (getUniswapQuote)`, err);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(`Quoter call failed for fee tier ${fee / 10000}% (getUniswapQuote)`, {
|
|
81
|
+
message: err.message,
|
|
82
|
+
reason: err.reason,
|
|
83
|
+
code: err.code,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!bestQuote || !bestFee) {
|
|
94
|
+
throw new Error('Failed to get quote from Uniswap V3. No valid pool found for this token pair or quote returned 0 (getUniswapQuote)');
|
|
95
|
+
}
|
|
96
|
+
// Calculate minimum output with 0.5% slippage tolerance
|
|
97
|
+
const slippageTolerance = 0.005;
|
|
98
|
+
const amountOutMin = bestQuote.mul(1000 - slippageTolerance * 1000).div(1000);
|
|
99
|
+
console.log('Final quote details:', {
|
|
100
|
+
bestFee: `${bestFee / 10000}%`,
|
|
101
|
+
bestQuote: {
|
|
102
|
+
raw: bestQuote.toString(),
|
|
103
|
+
formatted: ethers_1.ethers.utils.formatUnits(bestQuote, tokenOutDecimals),
|
|
104
|
+
},
|
|
105
|
+
minimumOutput: {
|
|
106
|
+
raw: amountOutMin.toString(),
|
|
107
|
+
formatted: ethers_1.ethers.utils.formatUnits(amountOutMin, tokenOutDecimals),
|
|
108
|
+
},
|
|
109
|
+
slippageTolerance: `${slippageTolerance * 100}%`,
|
|
110
|
+
});
|
|
111
|
+
return { bestQuote, bestFee, amountOutMin };
|
|
112
|
+
};
|
|
113
|
+
exports.getUniswapQuote = getUniswapQuote;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './get-token-amount-in-usd';
|
|
2
|
+
export * from './get-uniswap-quote';
|
|
3
|
+
export * from './send-spend-tx';
|
|
4
|
+
export * from './sign-tx';
|
|
5
|
+
export * from './check-spending-limit';
|
|
6
|
+
export * from './spending-limit-contract';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/policy-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./get-token-amount-in-usd"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./get-uniswap-quote"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./send-spend-tx"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./sign-tx"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./check-spending-limit"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./spending-limit-contract"), exports);
|