@lit-protocol/vincent-ability-uniswap-swap 2.0.1 → 4.0.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 +15 -0
- package/README.md +94 -83
- package/dist/CHANGELOG.md +15 -0
- package/dist/README.md +94 -83
- package/dist/package.json +6 -4
- package/dist/src/generated/lit-action-prepare.js +9 -0
- package/dist/src/generated/lit-action.js +2 -2
- package/dist/src/generated/vincent-ability-metadata.json +1 -1
- package/dist/src/generated/vincent-bundled-ability.d.ts +139 -946
- package/dist/src/generated/vincent-bundled-ability.d.ts.map +1 -1
- package/dist/src/generated/vincent-prepare-metadata.json +6 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/ability-checks/check-token-in-balance.d.ts +1 -1
- package/dist/src/lib/ability-checks/check-token-in-balance.d.ts.map +1 -1
- package/dist/src/lib/ability-checks/check-token-in-balance.js.map +1 -1
- package/dist/src/lib/ability-checks/index.d.ts +0 -1
- package/dist/src/lib/ability-checks/index.d.ts.map +1 -1
- package/dist/src/lib/ability-checks/index.js +0 -1
- package/dist/src/lib/ability-checks/index.js.map +1 -1
- package/dist/src/lib/ability-helpers/get-gas-params.d.ts +1 -1
- package/dist/src/lib/ability-helpers/get-gas-params.d.ts.map +1 -1
- package/dist/src/lib/ability-helpers/get-gas-params.js +5 -3
- package/dist/src/lib/ability-helpers/get-gas-params.js.map +1 -1
- package/dist/src/lib/ability-helpers/get-uniswap-quote.d.ts +6 -11
- package/dist/src/lib/ability-helpers/get-uniswap-quote.d.ts.map +1 -1
- package/dist/src/lib/ability-helpers/get-uniswap-quote.js +59 -104
- package/dist/src/lib/ability-helpers/get-uniswap-quote.js.map +1 -1
- package/dist/src/lib/ability-helpers/index.d.ts +0 -4
- package/dist/src/lib/ability-helpers/index.d.ts.map +1 -1
- package/dist/src/lib/ability-helpers/index.js +0 -4
- package/dist/src/lib/ability-helpers/index.js.map +1 -1
- package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts +8 -8
- package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts.map +1 -1
- package/dist/src/lib/ability-helpers/send-uniswap-tx.js +25 -53
- package/dist/src/lib/ability-helpers/send-uniswap-tx.js.map +1 -1
- package/dist/src/lib/prepare/get-signed-uniswap-quote.d.ts +9 -0
- package/dist/src/lib/prepare/get-signed-uniswap-quote.d.ts.map +1 -0
- package/dist/src/lib/prepare/get-signed-uniswap-quote.js +57 -0
- package/dist/src/lib/prepare/get-signed-uniswap-quote.js.map +1 -0
- package/dist/src/lib/prepare/lit-action.d.ts +2 -0
- package/dist/src/lib/prepare/lit-action.d.ts.map +1 -0
- package/dist/src/lib/prepare/lit-action.js +88 -0
- package/dist/src/lib/prepare/lit-action.js.map +1 -0
- package/dist/src/lib/prepare/types.d.ts +49 -0
- package/dist/src/lib/prepare/types.d.ts.map +1 -0
- package/dist/src/lib/prepare/types.js +3 -0
- package/dist/src/lib/prepare/types.js.map +1 -0
- package/dist/src/lib/prepare/validate-signed-uniswap-quote.d.ts +7 -0
- package/dist/src/lib/prepare/validate-signed-uniswap-quote.d.ts.map +1 -0
- package/dist/src/lib/prepare/validate-signed-uniswap-quote.js +25 -0
- package/dist/src/lib/prepare/validate-signed-uniswap-quote.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +140 -62
- package/dist/src/lib/schemas.d.ts.map +1 -1
- package/dist/src/lib/schemas.js +27 -41
- package/dist/src/lib/schemas.js.map +1 -1
- package/dist/src/lib/vincent-ability.d.ts +139 -946
- package/dist/src/lib/vincent-ability.d.ts.map +1 -1
- package/dist/src/lib/vincent-ability.js +54 -122
- package/dist/src/lib/vincent-ability.js.map +1 -1
- package/package.json +8 -6
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.d.ts +0 -10
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.d.ts.map +0 -1
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.js +0 -24
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.js.map +0 -1
- package/dist/src/lib/ability-helpers/calculate-usd-value.d.ts +0 -7
- package/dist/src/lib/ability-helpers/calculate-usd-value.d.ts.map +0 -1
- package/dist/src/lib/ability-helpers/calculate-usd-value.js +0 -22
- package/dist/src/lib/ability-helpers/calculate-usd-value.js.map +0 -1
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.d.ts +0 -7
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.d.ts.map +0 -1
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.js +0 -24
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.js.map +0 -1
- package/dist/src/lib/ability-helpers/get-eth-usd-price.d.ts +0 -6
- package/dist/src/lib/ability-helpers/get-eth-usd-price.d.ts.map +0 -1
- package/dist/src/lib/ability-helpers/get-eth-usd-price.js +0 -22
- package/dist/src/lib/ability-helpers/get-eth-usd-price.js.map +0 -1
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.d.ts +0 -10
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.d.ts.map +0 -1
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.js +0 -68
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vincent-ability.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vincent-ability.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,cAAc,GAAI,KAAK,GAAG,EAAE,OAAO,GAAG,QAElD,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHzB,CAAC"}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vincentAbility = exports.bigintReplacer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
5
|
-
const
|
|
6
|
-
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
7
|
const ability_helpers_1 = require("./ability-helpers");
|
|
8
8
|
const ability_checks_1 = require("./ability-checks");
|
|
9
9
|
const schemas_1 = require("./schemas");
|
|
10
|
-
const ethers_1 = require("ethers");
|
|
11
10
|
const check_erc20_allowance_1 = require("./ability-checks/check-erc20-allowance");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
bundledVincentPolicy: vincent_policy_spending_limit_1.bundledVincentPolicy,
|
|
15
|
-
abilityParameterMappings: {
|
|
16
|
-
rpcUrlForUniswap: 'rpcUrlForUniswap',
|
|
17
|
-
chainIdForUniswap: 'chainIdForUniswap',
|
|
18
|
-
ethRpcUrl: 'ethRpcUrl',
|
|
19
|
-
tokenInAddress: 'tokenAddress',
|
|
20
|
-
tokenInDecimals: 'tokenDecimals',
|
|
21
|
-
tokenInAmount: 'buyAmount',
|
|
22
|
-
},
|
|
23
|
-
});
|
|
11
|
+
const validate_signed_uniswap_quote_1 = require("./prepare/validate-signed-uniswap-quote");
|
|
12
|
+
const vincent_prepare_metadata_json_1 = tslib_1.__importDefault(require("../generated/vincent-prepare-metadata.json"));
|
|
24
13
|
const bigintReplacer = (key, value) => {
|
|
25
14
|
return typeof value === 'bigint' ? value.toString() : value;
|
|
26
15
|
};
|
|
@@ -29,55 +18,48 @@ exports.vincentAbility = (0, vincent_ability_sdk_1.createVincentAbility)({
|
|
|
29
18
|
packageName: '@lit-protocol/vincent-ability-uniswap-swap',
|
|
30
19
|
abilityDescription: 'Performs a swap between two ERC20 tokens using Uniswap',
|
|
31
20
|
abilityParamsSchema: schemas_1.abilityParamsSchema,
|
|
32
|
-
supportedPolicies: (0, vincent_ability_sdk_1.supportedPoliciesForAbility)([
|
|
21
|
+
supportedPolicies: (0, vincent_ability_sdk_1.supportedPoliciesForAbility)([]),
|
|
33
22
|
executeSuccessSchema: schemas_1.executeSuccessSchema,
|
|
34
23
|
executeFailSchema: schemas_1.executeFailSchema,
|
|
35
24
|
precheckFailSchema: schemas_1.precheckFailSchema,
|
|
36
25
|
precheck: async ({ abilityParams }, { succeed, fail, delegation: { delegatorPkpInfo } }) => {
|
|
37
|
-
// TODO: Rewrite checks to use `createAllowResult` and `createDenyResult` so we always know when we get a runtime err
|
|
38
|
-
const { rpcUrlForUniswap, chainIdForUniswap, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, } = abilityParams;
|
|
39
26
|
console.log('Prechecking UniswapSwapAbility', JSON.stringify(abilityParams, exports.bigintReplacer, 2));
|
|
40
|
-
|
|
41
|
-
const
|
|
27
|
+
// TODO: Rewrite checks to use `createAllowResult` and `createDenyResult` so we always know when we get a runtime err
|
|
28
|
+
const { rpcUrlForUniswap, signedUniswapQuote } = abilityParams;
|
|
29
|
+
const { quote } = signedUniswapQuote;
|
|
42
30
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
(0, validate_signed_uniswap_quote_1.validateSignedUniswapQuote)({
|
|
32
|
+
prepareSuccessResult: signedUniswapQuote,
|
|
33
|
+
expectedSignerEthAddress: vincent_prepare_metadata_json_1.default.pkpEthAddress,
|
|
34
|
+
expectedRecipientEthAddress: delegatorPkpInfo.ethAddress,
|
|
46
35
|
});
|
|
47
36
|
}
|
|
48
|
-
catch (
|
|
37
|
+
catch (error) {
|
|
49
38
|
return fail({
|
|
50
|
-
reason: `
|
|
39
|
+
reason: `Uniswap quote validation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
51
40
|
});
|
|
52
41
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
return fail({
|
|
56
|
-
reason: `Uniswap router address not found for chainId ${chainIdForUniswap} (UniswapSwapAbilityPrecheck)`,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const requiredAmount = ethers_1.ethers.utils
|
|
60
|
-
.parseUnits(tokenInAmount.toString(), tokenInDecimals)
|
|
61
|
-
.toBigInt();
|
|
42
|
+
const delegatorPkpAddress = delegatorPkpInfo.ethAddress;
|
|
43
|
+
const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrlForUniswap);
|
|
62
44
|
try {
|
|
63
|
-
await (0,
|
|
45
|
+
await (0, ability_checks_1.checkNativeTokenBalance)({
|
|
64
46
|
provider,
|
|
65
|
-
|
|
66
|
-
owner: delegatorPkpAddress,
|
|
67
|
-
spender: uniswapRouterAddress,
|
|
68
|
-
tokenAmount: requiredAmount,
|
|
47
|
+
pkpEthAddress: delegatorPkpAddress,
|
|
69
48
|
});
|
|
70
49
|
}
|
|
71
50
|
catch (err) {
|
|
72
51
|
return fail({
|
|
73
|
-
reason: `
|
|
52
|
+
reason: `Native token balance error: ${err instanceof Error ? err.message : String(err)}`,
|
|
74
53
|
});
|
|
75
54
|
}
|
|
55
|
+
const requiredAmount = ethers_1.ethers.utils
|
|
56
|
+
.parseUnits(quote.amountIn, quote.tokenInDecimals)
|
|
57
|
+
.toBigInt();
|
|
76
58
|
try {
|
|
77
59
|
await (0, ability_checks_1.checkTokenInBalance)({
|
|
78
60
|
provider,
|
|
79
61
|
pkpEthAddress: delegatorPkpAddress,
|
|
80
|
-
tokenInAddress:
|
|
62
|
+
tokenInAddress: quote.tokenIn,
|
|
81
63
|
tokenInAmount: requiredAmount,
|
|
82
64
|
});
|
|
83
65
|
}
|
|
@@ -86,102 +68,52 @@ exports.vincentAbility = (0, vincent_ability_sdk_1.createVincentAbility)({
|
|
|
86
68
|
reason: `tokenIn balance check error: ${err instanceof Error ? err.message : String(err)}`,
|
|
87
69
|
});
|
|
88
70
|
}
|
|
71
|
+
// Check ERC20 allowance for the router specified in the route
|
|
89
72
|
try {
|
|
90
|
-
await (0,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
tokenOutAddress: tokenOutAddress,
|
|
97
|
-
tokenOutDecimals,
|
|
73
|
+
await (0, check_erc20_allowance_1.checkErc20Allowance)({
|
|
74
|
+
provider,
|
|
75
|
+
tokenAddress: quote.tokenIn,
|
|
76
|
+
owner: delegatorPkpAddress,
|
|
77
|
+
spender: quote.to,
|
|
78
|
+
tokenAmount: requiredAmount,
|
|
98
79
|
});
|
|
99
80
|
}
|
|
100
81
|
catch (err) {
|
|
101
82
|
return fail({
|
|
102
|
-
reason: `
|
|
83
|
+
reason: `ERC20 allowance check error: ${err instanceof Error ? err.message : String(err)}`,
|
|
84
|
+
erc20SpenderAddress: quote.to,
|
|
103
85
|
});
|
|
104
86
|
}
|
|
105
87
|
return succeed();
|
|
106
88
|
},
|
|
107
|
-
execute: async ({ abilityParams }, { succeed, fail,
|
|
89
|
+
execute: async ({ abilityParams }, { succeed, fail, delegation: { delegatorPkpInfo } }) => {
|
|
108
90
|
console.log('Executing UniswapSwapAbility', JSON.stringify(abilityParams, exports.bigintReplacer, 2));
|
|
109
|
-
const {
|
|
110
|
-
const {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
tokenAmount: tokenInAmount,
|
|
122
|
-
tokenDecimals: tokenInDecimals,
|
|
91
|
+
const { rpcUrlForUniswap, signedUniswapQuote } = abilityParams;
|
|
92
|
+
const { quote } = signedUniswapQuote;
|
|
93
|
+
try {
|
|
94
|
+
(0, validate_signed_uniswap_quote_1.validateSignedUniswapQuote)({
|
|
95
|
+
prepareSuccessResult: signedUniswapQuote,
|
|
96
|
+
expectedSignerEthAddress: vincent_prepare_metadata_json_1.default.pkpEthAddress,
|
|
97
|
+
expectedRecipientEthAddress: delegatorPkpInfo.ethAddress,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return fail({
|
|
102
|
+
reason: `Uniswap quote validation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
123
103
|
});
|
|
124
|
-
const { maxSpendingLimitInUsd } = spendingLimitPolicyContext.result;
|
|
125
|
-
console.log('Spending limit policy commit', JSON.stringify(spendingLimitPolicyContext, exports.bigintReplacer, 2));
|
|
126
|
-
try {
|
|
127
|
-
const commitResult = await spendingLimitPolicyContext.commit({
|
|
128
|
-
amountSpentUsd: tokenInAmountInUsd.toNumber(),
|
|
129
|
-
maxSpendingLimitInUsd,
|
|
130
|
-
});
|
|
131
|
-
console.log('Spending limit policy commit result', JSON.stringify(commitResult, exports.bigintReplacer, 2));
|
|
132
|
-
if (commitResult.allow) {
|
|
133
|
-
spendLimitCommitTxHash = commitResult.result.spendTxHash;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
if (commitResult.runtimeError) {
|
|
137
|
-
// Handle either an error that was `throw()`n from the commit method and wrapped by the sdk
|
|
138
|
-
// Or an explicit schema validation error on input params or output result
|
|
139
|
-
return fail({
|
|
140
|
-
reason: 'Commit spending limit policy spending limit adjustment due to un-structured error response.',
|
|
141
|
-
spendingLimitCommitFail: {
|
|
142
|
-
runtimeError: commitResult.runtimeError,
|
|
143
|
-
schemaValidationError: commitResult.schemaValidationError,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
// In this case we should have a result that is the shape of the commitDenyResultSchema from the policy to return
|
|
148
|
-
return fail({
|
|
149
|
-
reason: 'Commit spending limit policy spending limit adjustment denied with structured result',
|
|
150
|
-
spendingLimitCommitFail: {
|
|
151
|
-
structuredCommitFailureReason: commitResult.result,
|
|
152
|
-
runtimeError: commitResult.runtimeError,
|
|
153
|
-
schemaValidationError: commitResult.schemaValidationError,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
console.log(`Committed spending limit policy for transaction: ${spendLimitCommitTxHash} (UniswapSwapAbilityExecute)`);
|
|
158
|
-
}
|
|
159
|
-
catch (commitErr) {
|
|
160
|
-
// Commit methods are wrapped in code so that this should only happen if we encounter an error
|
|
161
|
-
// _inside_ the wrapping code in the vincent-ability-sdk -- but let's handle it Just In Case :tm:
|
|
162
|
-
return fail({
|
|
163
|
-
reason: 'Commit spending limit policy spending limit adjustment due to unexpected runtime error.',
|
|
164
|
-
spendingLimitCommitFail: {
|
|
165
|
-
runtimeError: commitErr instanceof Error ? commitErr.message : String(commitErr),
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
104
|
}
|
|
170
105
|
const swapTxHash = await (0, ability_helpers_1.sendUniswapTx)({
|
|
171
106
|
rpcUrl: rpcUrlForUniswap,
|
|
172
|
-
chainId:
|
|
173
|
-
pkpEthAddress:
|
|
174
|
-
pkpPublicKey:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
return succeed({
|
|
182
|
-
swapTxHash,
|
|
183
|
-
spendTxHash: spendLimitCommitTxHash,
|
|
107
|
+
chainId: quote.chainId,
|
|
108
|
+
pkpEthAddress: delegatorPkpInfo.ethAddress,
|
|
109
|
+
pkpPublicKey: delegatorPkpInfo.publicKey,
|
|
110
|
+
uniswapTxData: {
|
|
111
|
+
to: quote.to,
|
|
112
|
+
calldata: quote.calldata,
|
|
113
|
+
estimatedGasUsed: quote.estimatedGasUsed,
|
|
114
|
+
},
|
|
184
115
|
});
|
|
116
|
+
return succeed({ swapTxHash });
|
|
185
117
|
},
|
|
186
118
|
});
|
|
187
119
|
//# sourceMappingURL=vincent-ability.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vincent-ability.js","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vincent-ability.js","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":";;;;AAAA,2EAG2C;AAC3C,mCAAgC;AAEhC,uDAAkD;AAClD,qDAAgF;AAChF,uCAKmB;AACnB,kFAA6E;AAC7E,2FAAqF;AACrF,uHAAgF;AAEzE,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAE,KAAU,EAAE,EAAE;IACrD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEW,QAAA,cAAc,GAAG,IAAA,0CAAoB,EAAC;IACjD,WAAW,EAAE,4CAAqD;IAClE,kBAAkB,EAAE,wDAAiE;IAErF,mBAAmB,EAAnB,6BAAmB;IACnB,iBAAiB,EAAE,IAAA,iDAA2B,EAAC,EAAE,CAAC;IAElD,oBAAoB,EAApB,8BAAoB;IACpB,iBAAiB,EAAjB,2BAAiB;IAEjB,kBAAkB,EAAlB,4BAAkB;IAElB,QAAQ,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE;QACzF,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,sBAAc,EAAE,CAAC,CAAC,CAAC,CAAC;QAEhG,qHAAqH;QACrH,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC;QAC/D,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC;QAErC,IAAI,CAAC;Y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,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;gBACV,MAAM,EAAE,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aACrG,CAAC,CAAC;QACL,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,IAAA,+BAAa,EAAC;YACrC,MAAM,EAAE,gBAAgB;YACxB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,aAAa,EAAE,gBAAgB,CAAC,UAAU;YAC1C,YAAY,EAAE,gBAAgB,CAAC,SAAS;YACxC,aAAa,EAAE;gBACb,EAAE,EAAE,KAAK,CAAC,EAAE;gBACZ,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;aACzC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IACjC,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lit-protocol/vincent-ability-uniswap-swap",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@lit-protocol/lit-node-client": "^7.2.3",
|
|
8
9
|
"@uniswap/sdk-core": "^7.7.2",
|
|
10
|
+
"@uniswap/smart-order-router": "^4.22.9",
|
|
9
11
|
"ethers": "^5.8.0",
|
|
12
|
+
"json-stable-stringify": "^1.3.0",
|
|
10
13
|
"tslib": "2.8.1",
|
|
11
14
|
"zod": "^3.25.64",
|
|
12
|
-
"@lit-protocol/vincent-
|
|
13
|
-
"@lit-protocol/vincent-
|
|
15
|
+
"@lit-protocol/vincent-ability-sdk": "2.1.0",
|
|
16
|
+
"@lit-protocol/vincent-app-sdk": "2.2.0"
|
|
14
17
|
},
|
|
15
18
|
"peerDependencies": {
|
|
16
|
-
"@lit-protocol/vincent-app-sdk": "^2.0
|
|
19
|
+
"@lit-protocol/vincent-app-sdk": "^2.2.0"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
22
|
"@dotenvx/dotenvx": "^1.44.2",
|
|
20
23
|
"@lit-protocol/auth-helpers": "^7.2.3",
|
|
21
24
|
"@lit-protocol/constants": "^7.2.3",
|
|
22
25
|
"@lit-protocol/contracts-sdk": "^7.2.3",
|
|
23
|
-
"@lit-protocol/
|
|
26
|
+
"@lit-protocol/esbuild-plugin-polyfill-node": "^0.3.0",
|
|
24
27
|
"esbuild": "^0.19.12",
|
|
25
|
-
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
26
28
|
"ipfs-only-hash": "^4.0.0",
|
|
27
29
|
"viem": "^2.28.0"
|
|
28
30
|
},
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const checkUniswapPoolExists: ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }: {
|
|
2
|
-
rpcUrl: string;
|
|
3
|
-
chainId: number;
|
|
4
|
-
tokenInAddress: `0x${string}`;
|
|
5
|
-
tokenInDecimals: number;
|
|
6
|
-
tokenInAmount: number;
|
|
7
|
-
tokenOutAddress: `0x${string}`;
|
|
8
|
-
tokenOutDecimals: number;
|
|
9
|
-
}) => Promise<boolean>;
|
|
10
|
-
//# sourceMappingURL=check-uniswap-pool-exists.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-uniswap-pool-exists.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-uniswap-pool-exists.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,GAAU,yGAQ1C;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,KAAK,MAAM,EAAE,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,KAAK,MAAM,EAAE,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;CAC1B,qBAiBA,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { FeeAmount } from '@uniswap/v3-sdk';
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.checkUniswapPoolExists = void 0;
|
|
5
|
-
const get_uniswap_quote_1 = require("../ability-helpers/get-uniswap-quote");
|
|
6
|
-
const checkUniswapPoolExists = async ({ rpcUrl, chainId, tokenInAddress, tokenInDecimals, tokenInAmount, tokenOutAddress, tokenOutDecimals, }) => {
|
|
7
|
-
try {
|
|
8
|
-
await (0, get_uniswap_quote_1.getUniswapQuote)({
|
|
9
|
-
rpcUrl,
|
|
10
|
-
chainId,
|
|
11
|
-
tokenInAddress,
|
|
12
|
-
tokenInDecimals,
|
|
13
|
-
tokenInAmount,
|
|
14
|
-
tokenOutAddress,
|
|
15
|
-
tokenOutDecimals,
|
|
16
|
-
});
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
throw new Error(`No valid Uniswap V3 pool found for token pair tokenInAddress: ${tokenInAddress}, tokenOutAddress: ${tokenOutAddress} with sufficient liquidity for amount tokenInAmount: ${tokenInAmount}: ${error instanceof Error ? error.message : String(error)}`);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.checkUniswapPoolExists = checkUniswapPoolExists;
|
|
24
|
-
//# sourceMappingURL=check-uniswap-pool-exists.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-uniswap-pool-exists.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-uniswap-pool-exists.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;AAE/C,4EAAuE;AAEhE,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,MAAM,EACN,OAAO,EACP,cAAc,EACd,eAAe,EACf,aAAa,EACb,eAAe,EACf,gBAAgB,GASjB,EAAE,EAAE;IACH,IAAI,CAAC;QACH,MAAM,IAAA,mCAAe,EAAC;YACpB,MAAM;YACN,OAAO;YACP,cAAc;YACd,eAAe;YACf,aAAa;YACb,eAAe;YACf,gBAAgB;SACjB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,iEAAiE,cAAc,sBAAsB,eAAe,wDAAwD,aAAa,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACvP,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAjCW,QAAA,sBAAsB,0BAiCjC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-usd-value.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-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"}
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
22
|
-
//# sourceMappingURL=calculate-usd-value.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-usd-value.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/calculate-usd-value.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,2DAAkE;AAE3D,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,SAAS,EACT,yBAAyB,EACzB,YAAY,GAKb,EAA6B,EAAE;IAC9B,MAAM,aAAa,GAAG,MAAM,IAAA,+CAA2B,EAAC,EAAE,SAAS,EAAE,yBAAyB,EAAE,CAAC,CAAC;IAElG,6CAA6C;IAC7C,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAC7B,MAAM,aAAa,GAAG,EAAE,CAAC,CAAC,gBAAgB;IAC1C,MAAM,WAAW,GAAG,YAAY;SAC7B,GAAG,CAAC,aAAa,CAAC;SAClB,GAAG,CAAC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,oDAAoD,EAAE;QAChE,iBAAiB,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC;QACxE,aAAa,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,kBAAkB,CAAC;QAC1E,gBAAgB,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,kBAAkB,CAAC;KAC5E,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAxBW,QAAA,iBAAiB,qBAwB5B"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
export declare const estimateGasForSwap: (uniswapV3RouterContract: ethers.Contract, tokenInAddress: string, tokenOutAddress: string, uniswapV3PoolFee: number, pkpEthAddress: string, amountInSmallestUnit: ethers.BigNumber, amountOutMin: ethers.BigNumber) => Promise<{
|
|
3
|
-
estimatedGas: ethers.BigNumber;
|
|
4
|
-
maxFeePerGas: ethers.BigNumber;
|
|
5
|
-
maxPriorityFeePerGas: ethers.BigNumber;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=estimate-gas-for-swap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"estimate-gas-for-swap.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/estimate-gas-for-swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,eAAO,MAAM,kBAAkB,GAC7B,yBAAyB,MAAM,CAAC,QAAQ,EACxC,gBAAgB,MAAM,EACtB,iBAAiB,MAAM,EACvB,kBAAkB,MAAM,EACxB,eAAe,MAAM,EACrB,sBAAsB,MAAM,CAAC,SAAS,EACtC,cAAc,MAAM,CAAC,SAAS;;;;EAsB/B,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.estimateGasForSwap = void 0;
|
|
4
|
-
const get_gas_params_1 = require("./get-gas-params");
|
|
5
|
-
const estimateGasForSwap = async (uniswapV3RouterContract, tokenInAddress, tokenOutAddress, uniswapV3PoolFee, pkpEthAddress, amountInSmallestUnit, amountOutMin) => {
|
|
6
|
-
const [block, feeData, estimatedGas] = await Promise.all([
|
|
7
|
-
uniswapV3RouterContract.provider.getBlock('latest'),
|
|
8
|
-
uniswapV3RouterContract.provider.getFeeData(),
|
|
9
|
-
uniswapV3RouterContract.estimateGas.exactInputSingle([
|
|
10
|
-
tokenInAddress,
|
|
11
|
-
tokenOutAddress,
|
|
12
|
-
uniswapV3PoolFee,
|
|
13
|
-
pkpEthAddress,
|
|
14
|
-
amountInSmallestUnit,
|
|
15
|
-
amountOutMin,
|
|
16
|
-
0,
|
|
17
|
-
], { from: pkpEthAddress }),
|
|
18
|
-
]);
|
|
19
|
-
return {
|
|
20
|
-
...(await (0, get_gas_params_1.getGasParams)(uniswapV3RouterContract.provider, block, feeData, estimatedGas)),
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
exports.estimateGasForSwap = estimateGasForSwap;
|
|
24
|
-
//# sourceMappingURL=estimate-gas-for-swap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"estimate-gas-for-swap.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/estimate-gas-for-swap.ts"],"names":[],"mappings":";;;AAEA,qDAAgD;AAEzC,MAAM,kBAAkB,GAAG,KAAK,EACrC,uBAAwC,EACxC,cAAsB,EACtB,eAAuB,EACvB,gBAAwB,EACxB,aAAqB,EACrB,oBAAsC,EACtC,YAA8B,EAC9B,EAAE;IACF,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,uBAAuB,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACnD,uBAAuB,CAAC,QAAQ,CAAC,UAAU,EAAE;QAC7C,uBAAuB,CAAC,WAAW,CAAC,gBAAgB,CAClD;YACE,cAAc;YACd,eAAe;YACf,gBAAgB;YAChB,aAAa;YACb,oBAAoB;YACpB,YAAY;YACZ,CAAC;SACF,EACD,EAAE,IAAI,EAAE,aAAa,EAAE,CACxB;KACF,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,CAAC,MAAM,IAAA,6BAAY,EAAC,uBAAuB,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;KACxF,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,kBAAkB,sBA6B7B"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-eth-usd-price.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-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"}
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
22
|
-
//# sourceMappingURL=get-eth-usd-price.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-eth-usd-price.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-eth-usd-price.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,MAAM,wBAAwB,GAAG;IAC/B,gJAAgJ;CACjJ,CAAC;AAEK,MAAM,2BAA2B,GAAG,KAAK,EAAE,EAChD,yBAAyB,EACzB,SAAS,GAIV,EAA6B,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,uEAAuE,EAAE;QACnF,yBAAyB;QACzB,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,QAAQ,CAClC,yBAAyB,EACzB,wBAAwB,EACxB,QAAQ,CACT,CAAC;IACF,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,oDAAoD,EAAE;QAChE,aAAa,EAAE,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;KACnD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAvBW,QAAA,2BAA2B,+BAuBtC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-token-amount-in-usd.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-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,CAgE3B,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
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;
|
|
68
|
-
//# sourceMappingURL=get-token-amount-in-usd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-token-amount-in-usd.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-token-amount-in-usd.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,+DAA0D;AAC1D,2DAAsD;AAEtD,MAAM,wBAAwB,GAAG,4CAA4C,CAAC;AAC9E;;GAEG;AACH,MAAM,kCAAkC,GAAG,4CAA4C,CAAC;AAEjF,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,GAQd,EAA6B,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,mDAAmD,EAAE;QAC/D,SAAS;QAC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