@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-bundled-ability.d.ts","sourceRoot":"","sources":["../../../src/generated/vincent-bundled-ability.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"vincent-bundled-ability.d.ts","sourceRoot":"","sources":["../../../src/generated/vincent-bundled-ability.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAA4D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ipfsCid": "QmbtR43zWDsZE8qTNkzhvzqpjFJXXqKNUsF9eXeUoPPwYA",
|
|
3
|
+
"pkpTokenId": "86450843426119340434279394299822687344874406133424458401092716139440841317417",
|
|
4
|
+
"pkpPublicKey": "0x04b08feb4b296fc4b47c763b9e4bc4dee5c48ab1fcf2f906402b0f0092dc9684e1a9c6830e5df2560698bc069bf8bebd99db9044cecf4a5810cc46fa734dd6fc48",
|
|
5
|
+
"pkpEthAddress": "0xf418A48b602023B4d0b6fe8668b4E12982B82563"
|
|
6
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { bundledVincentAbility } from './generated/vincent-bundled-ability';
|
|
2
|
+
export { getSignedUniswapQuote } from './lib/prepare/get-signed-uniswap-quote';
|
|
3
|
+
export { validateSignedUniswapQuote } from './lib/prepare/validate-signed-uniswap-quote';
|
|
4
|
+
export type * from './lib/prepare/types';
|
|
2
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,mBAAmB,qBAAqB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bundledVincentAbility = void 0;
|
|
3
|
+
exports.validateSignedUniswapQuote = exports.getSignedUniswapQuote = exports.bundledVincentAbility = void 0;
|
|
4
4
|
var vincent_bundled_ability_1 = require("./generated/vincent-bundled-ability");
|
|
5
5
|
Object.defineProperty(exports, "bundledVincentAbility", { enumerable: true, get: function () { return vincent_bundled_ability_1.bundledVincentAbility; } });
|
|
6
|
+
var get_signed_uniswap_quote_1 = require("./lib/prepare/get-signed-uniswap-quote");
|
|
7
|
+
Object.defineProperty(exports, "getSignedUniswapQuote", { enumerable: true, get: function () { return get_signed_uniswap_quote_1.getSignedUniswapQuote; } });
|
|
8
|
+
var validate_signed_uniswap_quote_1 = require("./lib/prepare/validate-signed-uniswap-quote");
|
|
9
|
+
Object.defineProperty(exports, "validateSignedUniswapQuote", { enumerable: true, get: function () { return validate_signed_uniswap_quote_1.validateSignedUniswapQuote; } });
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA4E;AAAnE,gIAAA,qBAAqB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAA4E;AAAnE,gIAAA,qBAAqB,OAAA;AAC9B,mFAA+E;AAAtE,iIAAA,qBAAqB,OAAA;AAC9B,6FAAyF;AAAhF,2IAAA,0BAA0B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-token-in-balance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-token-in-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,mBAAmB,GAAU,6DAKvC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,
|
|
1
|
+
{"version":3,"file":"check-token-in-balance.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-token-in-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,mBAAmB,GAAU,6DAKvC;IACD,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,8BAeA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-token-in-balance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-token-in-balance.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,yDAAsD;AAE/C,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,GAMd,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,IAAA,mCAAgB,EAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAE5D,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"check-token-in-balance.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/check-token-in-balance.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,yDAAsD;AAE/C,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,GAMd,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,IAAA,mCAAgB,EAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAE5D,MAAM,cAAc,GAAqB,MAAM,QAAQ,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAEjF,6CAA6C;IAC7C,MAAM,eAAe,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;IAExE,IAAI,cAAc,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,kBAAkB,aAAa,0CAA0C,cAAc,aAAa,aAAa,mBAAmB,cAAc,wBAAwB,CAC3K,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAzBW,QAAA,mBAAmB,uBAyB9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
|
|
@@ -3,6 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./check-native-token-balance"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./check-token-in-balance"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./check-uniswap-pool-exists"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./check-erc20-allowance"), exports);
|
|
8
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,mEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-checks/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,mEAAyC;AACzC,kEAAwC"}
|
|
@@ -4,5 +4,5 @@ export interface GasParams {
|
|
|
4
4
|
maxFeePerGas: ethers.BigNumber;
|
|
5
5
|
maxPriorityFeePerGas: ethers.BigNumber;
|
|
6
6
|
}
|
|
7
|
-
export declare const getGasParams: (provider: ethers.providers.Provider,
|
|
7
|
+
export declare const getGasParams: (provider: ethers.providers.Provider, estimatedGas: ethers.BigNumber) => Promise<GasParams>;
|
|
8
8
|
//# sourceMappingURL=get-gas-params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-gas-params.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-gas-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC,SAAS,CAAC;CACxC;AAED,eAAO,MAAM,YAAY,GACvB,UAAU,MAAM,CAAC,SAAS,CAAC,QAAQ,EACnC,
|
|
1
|
+
{"version":3,"file":"get-gas-params.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-gas-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC,SAAS,CAAC;CACxC;AAED,eAAO,MAAM,YAAY,GACvB,UAAU,MAAM,CAAC,SAAS,CAAC,QAAQ,EACnC,cAAc,MAAM,CAAC,SAAS,KAC7B,OAAO,CAAC,SAAS,CA+BnB,CAAC"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGasParams = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
|
-
const getGasParams = async (provider,
|
|
5
|
+
const getGasParams = async (provider, estimatedGas) => {
|
|
6
|
+
// Fetch block and fee data
|
|
7
|
+
const [block, feeData] = await Promise.all([provider.getBlock('latest'), provider.getFeeData()]);
|
|
6
8
|
// Determine baseFeePerGas, with multiple fallbacks
|
|
7
9
|
let baseFeePerGas = block.baseFeePerGas;
|
|
8
10
|
if (baseFeePerGas == null) {
|
|
@@ -19,8 +21,8 @@ const getGasParams = async (provider, block, feeData, estimatedGas) => {
|
|
|
19
21
|
: ethers_1.ethers.utils.parseUnits('1.5', 'gwei');
|
|
20
22
|
// Calculate maxFeePerGas as the sum of baseFee and priority fee
|
|
21
23
|
const maxFeePerGas = baseFeePerGas.add(maxPriorityFeePerGas);
|
|
22
|
-
// Add a
|
|
23
|
-
const estimatedGasWithBuffer = estimatedGas.mul(
|
|
24
|
+
// Add a 50% buffer to the estimated gas limit for complex swaps
|
|
25
|
+
const estimatedGasWithBuffer = estimatedGas.mul(150).div(100);
|
|
24
26
|
return {
|
|
25
27
|
estimatedGas: estimatedGasWithBuffer,
|
|
26
28
|
maxFeePerGas,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-gas-params.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-gas-params.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAQzB,MAAM,YAAY,GAAG,KAAK,EAC/B,QAAmC,EACnC,
|
|
1
|
+
{"version":3,"file":"get-gas-params.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-gas-params.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAQzB,MAAM,YAAY,GAAG,KAAK,EAC/B,QAAmC,EACnC,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wapRoute } from '@uniswap/smart-order-router';
|
|
2
|
+
export declare function getUniswapQuote({ rpcUrl, tokenInAddress, tokenInAmount, tokenOutAddress, recipient, slippageTolerance, }: {
|
|
3
3
|
rpcUrl: string;
|
|
4
|
-
chainId: number;
|
|
5
4
|
tokenInAddress: string;
|
|
6
|
-
|
|
7
|
-
tokenInAmount: number;
|
|
5
|
+
tokenInAmount: string;
|
|
8
6
|
tokenOutAddress: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
bestFee: number;
|
|
13
|
-
amountOutMin: ethers.BigNumber;
|
|
14
|
-
}>;
|
|
7
|
+
recipient: string;
|
|
8
|
+
slippageTolerance?: number;
|
|
9
|
+
}): Promise<SwapRoute>;
|
|
15
10
|
//# sourceMappingURL=get-uniswap-quote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-uniswap-quote.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-uniswap-quote.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"get-uniswap-quote.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-uniswap-quote.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAG/E,wBAAsB,eAAe,CAAC,EACpC,MAAM,EACN,cAAc,EACd,aAAa,EACb,eAAe,EACf,SAAS,EACT,iBAAiB,GAClB,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,OAAO,CAAC,SAAS,CAAC,CAkFrB"}
|
|
@@ -1,114 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUniswapQuote =
|
|
3
|
+
exports.getUniswapQuote = getUniswapQuote;
|
|
4
4
|
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
5
|
+
const smart_order_router_1 = require("@uniswap/smart-order-router");
|
|
5
6
|
const ethers_1 = require("ethers");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
tokenInDecimals,
|
|
15
|
-
tokenInAmount,
|
|
16
|
-
tokenOutAddress,
|
|
17
|
-
tokenOutDecimals,
|
|
7
|
+
async function getUniswapQuote({ rpcUrl, tokenInAddress, tokenInAmount, tokenOutAddress, recipient, slippageTolerance, }) {
|
|
8
|
+
const activeTimeouts = new Set();
|
|
9
|
+
const realSetTimeout = global.setTimeout;
|
|
10
|
+
const realClearTimeout = global.clearTimeout;
|
|
11
|
+
global.setTimeout = ((fn, ms, ...args) => {
|
|
12
|
+
const id = realSetTimeout(fn, ms, ...args);
|
|
13
|
+
activeTimeouts.add(id);
|
|
14
|
+
return id;
|
|
18
15
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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),
|
|
16
|
+
global.clearTimeout = ((id) => {
|
|
17
|
+
activeTimeouts.delete(id);
|
|
18
|
+
return realClearTimeout(id);
|
|
33
19
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
20
|
+
const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
|
|
21
|
+
const [network, tokenInDecimals, tokenOutDecimals] = await Promise.all([
|
|
22
|
+
provider.getNetwork(),
|
|
23
|
+
new ethers_1.ethers.Contract(tokenInAddress, ['function decimals() view returns (uint8)'], provider).decimals(),
|
|
24
|
+
new ethers_1.ethers.Contract(tokenOutAddress, ['function decimals() view returns (uint8)'], provider).decimals(),
|
|
25
|
+
]);
|
|
26
|
+
const chainId = network.chainId;
|
|
27
|
+
const router = new smart_order_router_1.AlphaRouter({ chainId, provider });
|
|
28
|
+
try {
|
|
29
|
+
const tokenIn = new sdk_core_1.Token(chainId, tokenInAddress, tokenInDecimals);
|
|
30
|
+
const tokenOut = new sdk_core_1.Token(chainId, tokenOutAddress, tokenOutDecimals);
|
|
31
|
+
const amountIn = sdk_core_1.CurrencyAmount.fromRawAmount(tokenIn, ethers_1.ethers.utils.parseUnits(tokenInAmount.toString(), tokenInDecimals).toString());
|
|
32
|
+
// User provides slippage in basis points (e.g., 50 for 0.5%, 100 for 1%)
|
|
33
|
+
// Default to 50 basis points (0.5%) if not provided
|
|
34
|
+
const slippage = new sdk_core_1.Percent(slippageTolerance ?? 50, 10_000);
|
|
35
|
+
console.log('Amount conversion:', {
|
|
36
|
+
original: tokenInAmount,
|
|
37
|
+
decimals: tokenInDecimals,
|
|
38
|
+
wei: amountIn.quotient.toString(),
|
|
39
|
+
formatted: amountIn.toExact(),
|
|
40
|
+
});
|
|
41
|
+
console.log('Getting route from AlphaRouter...');
|
|
42
|
+
const routeResult = await router.route(amountIn, tokenOut, sdk_core_1.TradeType.EXACT_INPUT, {
|
|
43
|
+
recipient,
|
|
44
|
+
slippageTolerance: slippage,
|
|
45
|
+
deadline: Math.floor(Date.now() / 1000 + 1800),
|
|
46
|
+
type: smart_order_router_1.SwapType.SWAP_ROUTER_02,
|
|
47
|
+
});
|
|
48
|
+
if (!routeResult || !routeResult.quote) {
|
|
49
|
+
throw new Error('Failed to get quote from Uniswap (no route)');
|
|
91
50
|
}
|
|
51
|
+
console.log('AlphaRouter completed successfully');
|
|
52
|
+
return routeResult;
|
|
92
53
|
}
|
|
93
|
-
|
|
94
|
-
|
|
54
|
+
finally {
|
|
55
|
+
console.log('Performing cleanup of AlphaRouter resources...');
|
|
56
|
+
provider.removeAllListeners();
|
|
57
|
+
// Clear any timers created during this call
|
|
58
|
+
console.log(`Clearing ${activeTimeouts.size} timeouts`);
|
|
59
|
+
for (const id of Array.from(activeTimeouts)) {
|
|
60
|
+
realClearTimeout(id);
|
|
61
|
+
}
|
|
62
|
+
activeTimeouts.clear();
|
|
63
|
+
// Restore globals to avoid side effects
|
|
64
|
+
global.setTimeout = realSetTimeout;
|
|
65
|
+
global.clearTimeout = realClearTimeout;
|
|
66
|
+
console.log('AlphaRouter cleanup completed');
|
|
95
67
|
}
|
|
96
|
-
|
|
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;
|
|
68
|
+
}
|
|
114
69
|
//# sourceMappingURL=get-uniswap-quote.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-uniswap-quote.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-uniswap-quote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-uniswap-quote.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/get-uniswap-quote.ts"],"names":[],"mappings":";;AAIA,0CAgGC;AApGD,gDAA8E;AAC9E,oEAA+E;AAC/E,mCAAgC;AAEzB,KAAK,UAAU,eAAe,CAAC,EACpC,MAAM,EACN,cAAc,EACd,aAAa,EACb,eAAe,EACf,SAAS,EACT,iBAAiB,GAQlB;IACC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IACjD,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC;IACzC,MAAM,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC;IAE7C,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,EAAgC,EAAE,EAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACzF,MAAM,EAAE,GAAG,cAAc,CAAC,EAAE,EAAE,EAAY,EAAE,GAAG,IAAI,CAAC,CAAC;QACrD,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAsB,CAAC;IAExB,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,EAAkB,EAAE,EAAE;QAC5C,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1B,OAAO,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAwB,CAAC;IAE1B,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACpE,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,gBAAgB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACrE,QAAQ,CAAC,UAAU,EAAE;QACrB,IAAI,eAAM,CAAC,QAAQ,CACjB,cAAc,EACd,CAAC,0CAA0C,CAAC,EAC5C,QAAQ,CACT,CAAC,QAAQ,EAAE;Q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GAAG,IAAI,CAAC;YAC9C,IAAI,EAAE,6BAAQ,CAAC,cAAc;SAC9B,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAClD,OAAO,WAAW,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAE9D,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAE9B,4CAA4C;QAC5C,OAAO,CAAC,GAAG,CAAC,YAAY,cAAc,CAAC,IAAI,WAAW,CAAC,CAAC;QACxD,KAAK,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,gBAAgB,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;QACD,cAAc,CAAC,KAAK,EAAE,CAAC;QAEvB,wCAAwC;QACxC,MAAM,CAAC,UAAU,GAAG,cAAc,CAAC;QACnC,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAC;QAEvC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export * from './get-pkp-info';
|
|
2
2
|
export * from './get-uniswap-quote';
|
|
3
3
|
export * from './send-uniswap-tx';
|
|
4
|
-
export * from './get-token-amount-in-usd';
|
|
5
4
|
export * from './get-gas-params';
|
|
6
5
|
export * from './sign-tx';
|
|
7
|
-
export * from './estimate-gas-for-swap';
|
|
8
|
-
export * from './calculate-usd-value';
|
|
9
|
-
export * from './get-eth-usd-price';
|
|
10
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
|
@@ -4,10 +4,6 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./get-pkp-info"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./get-uniswap-quote"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./send-uniswap-tx"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./get-token-amount-in-usd"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./get-gas-params"), exports);
|
|
9
8
|
tslib_1.__exportStar(require("./sign-tx"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./estimate-gas-for-swap"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./calculate-usd-value"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./get-eth-usd-price"), exports);
|
|
13
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,8DAAoC;AACpC,4DAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,8DAAoC;AACpC,4DAAkC;AAClC,2DAAiC;AACjC,oDAA0B"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const sendUniswapTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey,
|
|
1
|
+
export declare const sendUniswapTx: ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, uniswapTxData, }: {
|
|
2
2
|
rpcUrl: string;
|
|
3
3
|
chainId: number;
|
|
4
|
-
pkpEthAddress:
|
|
4
|
+
pkpEthAddress: string;
|
|
5
5
|
pkpPublicKey: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}) => Promise
|
|
6
|
+
uniswapTxData: {
|
|
7
|
+
to: string;
|
|
8
|
+
calldata: string;
|
|
9
|
+
estimatedGasUsed: string;
|
|
10
|
+
};
|
|
11
|
+
}) => Promise<string>;
|
|
12
12
|
//# sourceMappingURL=send-uniswap-tx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-uniswap-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa,GAAU,
|
|
1
|
+
{"version":3,"file":"send-uniswap-tx.d.ts","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa,GAAU,kEAMjC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE;QACb,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,KAAG,OAAO,CAAC,MAAM,CAwGjB,CAAC"}
|
|
@@ -1,61 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendUniswapTx = void 0;
|
|
4
|
-
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
5
4
|
const ethers_1 = require("ethers");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
throw new Error(`Unsupported chainId: ${chainId} (sendUniswapTx)`);
|
|
11
|
-
}
|
|
12
|
-
const uniswapRouterAddress = sdk_core_1.CHAIN_TO_ADDRESSES_MAP[chainId].swapRouter02Address;
|
|
5
|
+
const sign_tx_1 = require("./sign-tx");
|
|
6
|
+
const get_gas_params_1 = require("./get-gas-params");
|
|
7
|
+
const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, uniswapTxData, }) => {
|
|
8
|
+
console.log('Estimating gas for Swap transaction using pre-computed route (sendUniswapTx)');
|
|
13
9
|
const uniswapRpcProvider = new ethers_1.ethers.providers.StaticJsonRpcProvider(rpcUrl);
|
|
14
|
-
const partialSwapTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'Uniswap swap tx gas estimation' }, async () => {
|
|
10
|
+
const partialSwapTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'Uniswap swap tx gas estimation with pre-computed route' }, async () => {
|
|
15
11
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tokenInAmount,
|
|
27
|
-
tokenOutAddress,
|
|
28
|
-
tokenOutDecimals,
|
|
29
|
-
});
|
|
30
|
-
const { bestFee, amountOutMin } = uniswapQuoteResponse;
|
|
31
|
-
const { estimatedGas, maxFeePerGas, maxPriorityFeePerGas } = await (0, _1.estimateGasForSwap)(uniswapV3RouterContract, tokenInAddress, tokenOutAddress, bestFee, pkpEthAddress, formattedTokenInAmount, amountOutMin);
|
|
32
|
-
console.log('Encoding swap transaction data (sendUniswapTx)', {
|
|
33
|
-
tokenInAddress,
|
|
34
|
-
tokenOutAddress,
|
|
35
|
-
bestFee,
|
|
36
|
-
pkpEthAddress,
|
|
37
|
-
formattedTokenInAmount,
|
|
38
|
-
amountOutMin,
|
|
39
|
-
sqrtPriceLimitX96: 0,
|
|
12
|
+
console.log('Using pre-computed Uniswap route for swap (sendUniswapTx)');
|
|
13
|
+
// Use getGasParams helper which handles block/feeData fetching and applies 50% buffer
|
|
14
|
+
const { estimatedGas, maxFeePerGas, maxPriorityFeePerGas } = await (0, get_gas_params_1.getGasParams)(uniswapRpcProvider, ethers_1.ethers.BigNumber.from(uniswapTxData.estimatedGasUsed));
|
|
15
|
+
console.log('Swap transaction details with pre-computed route (sendUniswapTx)', {
|
|
16
|
+
to: uniswapTxData.to,
|
|
17
|
+
calldata: uniswapTxData.calldata,
|
|
18
|
+
routeEstimatedGas: uniswapTxData.estimatedGasUsed,
|
|
19
|
+
adjustedGasLimit: estimatedGas.toString(),
|
|
20
|
+
maxPriorityFeePerGas: `${ethers_1.ethers.utils.formatUnits(maxPriorityFeePerGas, 'gwei')} gwei`,
|
|
21
|
+
maxFeePerGas: `${ethers_1.ethers.utils.formatUnits(maxFeePerGas, 'gwei')} gwei`,
|
|
40
22
|
});
|
|
41
|
-
const swapTxData = uniswapV3RouterContract.interface.encodeFunctionData('exactInputSingle', [
|
|
42
|
-
[
|
|
43
|
-
tokenInAddress,
|
|
44
|
-
tokenOutAddress,
|
|
45
|
-
bestFee,
|
|
46
|
-
pkpEthAddress,
|
|
47
|
-
formattedTokenInAmount,
|
|
48
|
-
amountOutMin,
|
|
49
|
-
0,
|
|
50
|
-
],
|
|
51
|
-
]);
|
|
52
23
|
return JSON.stringify({
|
|
53
24
|
status: 'success',
|
|
54
25
|
partialSwapTx: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
26
|
+
to: uniswapTxData.to,
|
|
27
|
+
data: uniswapTxData.calldata,
|
|
28
|
+
gasLimit: estimatedGas.toString(),
|
|
29
|
+
maxFeePerGas: maxFeePerGas.toString(),
|
|
30
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas.toString(),
|
|
59
31
|
nonce: await uniswapRpcProvider.getTransactionCount(pkpEthAddress),
|
|
60
32
|
},
|
|
61
33
|
});
|
|
@@ -73,7 +45,7 @@ const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, tok
|
|
|
73
45
|
}
|
|
74
46
|
const { partialSwapTx } = parsedPartialSwapTxResponse;
|
|
75
47
|
const unsignedSwapTx = {
|
|
76
|
-
to:
|
|
48
|
+
to: partialSwapTx.to,
|
|
77
49
|
data: partialSwapTx.data,
|
|
78
50
|
value: ethers_1.ethers.BigNumber.from(0),
|
|
79
51
|
gasLimit: ethers_1.ethers.BigNumber.from(partialSwapTx.gasLimit),
|
|
@@ -83,15 +55,15 @@ const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, tok
|
|
|
83
55
|
chainId,
|
|
84
56
|
type: 2,
|
|
85
57
|
};
|
|
86
|
-
console.log('Unsigned swap transaction object (sendUniswapTx)', {
|
|
58
|
+
console.log('Unsigned swap transaction object with pre-computed route (sendUniswapTx)', {
|
|
87
59
|
...unsignedSwapTx,
|
|
88
60
|
value: unsignedSwapTx.value.toString(),
|
|
89
61
|
gasLimit: unsignedSwapTx.gasLimit.toString(),
|
|
90
62
|
maxFeePerGas: unsignedSwapTx.maxFeePerGas.toString(),
|
|
91
63
|
maxPriorityFeePerGas: unsignedSwapTx.maxPriorityFeePerGas.toString(),
|
|
92
64
|
});
|
|
93
|
-
const signedSwapTx = await (0,
|
|
94
|
-
console.log(`Broadcasting swap transaction (sendUniswapTx)`);
|
|
65
|
+
const signedSwapTx = await (0, sign_tx_1.signTx)(pkpPublicKey, unsignedSwapTx, 'uniswapSwapSig');
|
|
66
|
+
console.log(`Broadcasting swap transaction with pre-computed route (sendUniswapTx)`);
|
|
95
67
|
const swapTxResponse = await Lit.Actions.runOnce({ waitForResponse: true, name: 'swapTxSender' }, async () => {
|
|
96
68
|
try {
|
|
97
69
|
const receipt = await uniswapRpcProvider.sendTransaction(signedSwapTx);
|
|
@@ -112,7 +84,7 @@ const sendUniswapTx = async ({ rpcUrl, chainId, pkpEthAddress, pkpPublicKey, tok
|
|
|
112
84
|
throw new Error(`Error broadcasting swap transaction: ${parsedSwapTxResponse.error} (sendUniswapTx)`);
|
|
113
85
|
}
|
|
114
86
|
const { txHash } = parsedSwapTxResponse;
|
|
115
|
-
console.log(`Swap transaction broadcasted (sendUniswapTx): ${txHash}`);
|
|
87
|
+
console.log(`Swap transaction broadcasted with pre-computed route (sendUniswapTx): ${txHash}`);
|
|
116
88
|
return txHash;
|
|
117
89
|
};
|
|
118
90
|
exports.sendUniswapTx = sendUniswapTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-uniswap-tx.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"send-uniswap-tx.js","sourceRoot":"","sources":["../../../../src/lib/ability-helpers/send-uniswap-tx.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,uCAAmC;AACnC,qDAAgD;AAczC,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,MAAM,EACN,OAAO,EACP,aAAa,EACb,YAAY,EACZ,aAAa,GAWd,EAAmB,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,8EAA8E,CAAC,CAAC;IAE5F,MAAM,kBAAkB,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9E,MAAM,qBAAqB,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CACrD,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,wDAAwD,EAAE,EACzF,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;YAEzE,sFAAsF;YACtF,MAAM,EAAE,YAAY,EAAE,YA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,CAAC,OAAO,CAAC,OAAO,CAC9C,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,EAC/C,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACvE,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,OAAO,CAAC,IAAI;aACrB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IACxD,IAAI,oBAAoB,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACb,wCAAwC,oBAAoB,CAAC,KAAK,kBAAkB,CACrF,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAoB,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,yEAAyE,MAAM,EAAE,CAAC,CAAC;IAE/F,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAxHW,QAAA,aAAa,iBAwHxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
3
|
+
import type { PrepareSignedUniswapQuote, QuoteParams } from './types';
|
|
4
|
+
export declare const getSignedUniswapQuote: ({ quoteParams, ethersSigner, litNodeClient, }: {
|
|
5
|
+
quoteParams: QuoteParams;
|
|
6
|
+
ethersSigner: ethers.Signer;
|
|
7
|
+
litNodeClient: LitNodeClient;
|
|
8
|
+
}) => Promise<PrepareSignedUniswapQuote>;
|
|
9
|
+
//# sourceMappingURL=get-signed-uniswap-quote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-signed-uniswap-quote.d.ts","sourceRoot":"","sources":["../../../../src/lib/prepare/get-signed-uniswap-quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,KAAK,EAEV,yBAAyB,EAEzB,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB,eAAO,MAAM,qBAAqB,GAAU,+CAIzC;IACD,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC;IAC5B,aAAa,EAAE,aAAa,CAAC;CAC9B,KAAG,OAAO,CAAC,yBAAyB,CAwDpC,CAAC"}
|