@instadapp/interop-x 0.0.0-dev.8cb1c22 → 0.0.0-dev.909c44a
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/dist/package.json +9 -2
- package/dist/src/abi/aaveV2Resolver.json +832 -0
- package/dist/src/abi/aaveV3Resolver.json +628 -0
- package/dist/src/abi/balanceResolver.json +211 -0
- package/dist/src/abi/connectors/index.js +2 -2
- package/dist/src/abi/connectors/v2/1INCH-A.js +39 -1
- package/dist/src/abi/connectors/v2/1INCH-V3-A.js +42 -0
- package/dist/src/abi/connectors/v2/1INCH-V4-A.js +42 -0
- package/dist/src/abi/connectors/v2/AAVE-IMPORT-V2-V3-A.js +57 -0
- package/dist/src/abi/connectors/v2/AAVE-V2-A.js +91 -133
- package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-C.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-V3-A.js +322 -0
- package/dist/src/abi/connectors/v2/AAVE-V3-CLAIM-A.js +58 -0
- package/dist/src/abi/connectors/v2/AAVE-V3-IMPORT-A.js +59 -0
- package/dist/src/abi/connectors/v2/AAVE-V3-IMPORT-PERMIT-A.js +81 -0
- package/dist/src/abi/connectors/v2/BASIC-A.js +44 -86
- package/dist/src/abi/connectors/v2/BENQI-A.js +901 -0
- package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-C.js +4 -0
- package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-D.js +27 -0
- package/dist/src/abi/connectors/v2/DSA-SPELL-A.js +60 -0
- package/dist/src/abi/connectors/v2/HOP-A.js +41 -0
- package/dist/src/abi/connectors/v2/HOP-MAINNET-A.js +38 -0
- package/dist/src/abi/connectors/v2/INSTA-DEX-SIMULATION-A.js +40 -0
- package/dist/src/abi/connectors/v2/INSTAPOOL-B.js +4 -0
- package/dist/src/abi/connectors/v2/INSTAPOOL-C.js +4 -0
- package/dist/src/abi/connectors/v2/INTEROP-A.js +4 -0
- package/dist/src/abi/connectors/v2/INTEROP-STAGING-A.js +4 -0
- package/dist/src/abi/connectors/v2/LIDO-STETH-A.js +36 -0
- package/dist/src/abi/connectors/v2/LITE-A.js +4 -0
- package/dist/src/abi/connectors/v2/MSTABLE-A.js +4 -0
- package/dist/src/abi/connectors/v2/NOTIONAL-V2-A.js +484 -0
- package/dist/src/abi/connectors/v2/PANGOLIN-A.js +136 -0
- package/dist/src/abi/connectors/v2/PANGOLIN-STAKE-A.js +227 -0
- package/dist/src/abi/connectors/v2/PARASWAP-A.js +26 -1
- package/dist/src/abi/connectors/v2/PARASWAP-V5-A.js +29 -0
- package/dist/src/abi/connectors/v2/POOLTOGETHER-A.js +4 -0
- package/dist/src/abi/connectors/v2/QI-A.js +4 -0
- package/dist/src/abi/connectors/v2/QUICKSWAP-A.js +136 -0
- package/dist/src/abi/connectors/v2/SUSHISWAP-A.js +136 -0
- package/dist/src/abi/connectors/v2/SWAP-AGGREGATOR-A.js +25 -0
- package/dist/src/abi/connectors/v2/UBIQUITY-A.js +73 -0
- package/dist/src/abi/connectors/v2/UNISWAP-SELL-BETA.js +4 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V3-A.js +1 -1
- package/dist/src/abi/connectors/v2/UNISWAP-V3-ROUTER-A.js +4 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V3-STAKER-B.js +193 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V3-SWAP-A.js +74 -0
- package/dist/src/abi/connectors/v2/UNIVERSE-A.js +4 -0
- package/dist/src/abi/connectors/v2/WAVAX-A.js +4 -0
- package/dist/src/abi/connectors/v2/WFTM-A.js +60 -0
- package/dist/src/abi/connectors/v2/WMATIC-A.js +4 -0
- package/dist/src/abi/connectors/v2/ZEROX-A.js +29 -0
- package/dist/src/abi/connectors/v2/ZEROX-V4-A.js +29 -0
- package/dist/src/abi/connectors/v2/index.js +128 -44
- package/dist/src/abi/index.js +8 -0
- package/dist/src/abi/instList.json +232 -0
- package/dist/src/api/index.js +7 -0
- package/dist/src/constants/addresses.js +9 -1
- package/dist/src/constants/capPerChain.js +8 -0
- package/dist/src/constants/index.js +2 -0
- package/dist/src/constants/tokens.js +44 -44
- package/dist/src/constants/wrappedNativeToken.js +8 -0
- package/dist/src/crons/index.js +3 -0
- package/dist/src/crons/prices.js +16 -0
- package/dist/src/db/models/transaction.js +5 -1
- package/dist/src/errors/index.js +30 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
- package/dist/src/gnosis/actions/aaveV2/target.js +20 -5
- package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
- package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
- package/dist/src/gnosis/actions/index.js +2 -0
- package/dist/src/index.js +2 -1
- package/dist/src/providers/index.js +17 -0
- package/dist/src/providers/retry-provider.js +45 -0
- package/dist/src/services/Prices.js +74 -0
- package/dist/src/services/index.js +8 -0
- package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +110 -16
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +30 -10
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +3 -2
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +6 -5
- package/dist/src/tasks/index.js +7 -5
- package/dist/src/typechain/AaveV2Resolver.js +2 -0
- package/dist/src/typechain/AaveV3Resolver.js +2 -0
- package/dist/src/typechain/BalanceResolver.js +2 -0
- package/dist/src/typechain/InstList.js +2 -0
- package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
- package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
- package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
- package/dist/src/typechain/factories/InstList__factory.js +249 -0
- package/dist/src/typechain/factories/index.js +9 -1
- package/dist/src/typechain/index.js +9 -1
- package/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +36 -0
- package/dist/src/utils/formatting.js +67 -0
- package/dist/src/utils/gnosis.js +87 -0
- package/dist/src/utils/http.js +10 -0
- package/dist/src/utils/index.js +22 -220
- package/dist/src/utils/interop.js +16 -0
- package/dist/src/utils/tokens.js +22 -0
- package/dist/src/utils/validate.js +111 -0
- package/dist/src/utils/web3.js +93 -0
- package/package.json +9 -2
- package/src/abi/aaveV2Resolver.json +832 -0
- package/src/abi/aaveV3Resolver.json +628 -0
- package/src/abi/balanceResolver.json +211 -0
- package/src/abi/connectors/index.ts +5 -5
- package/src/abi/connectors/v2/1INCH-A.ts +39 -1
- package/src/abi/connectors/v2/1INCH-V3-A.ts +41 -0
- package/src/abi/connectors/v2/1INCH-V4-A.ts +41 -0
- package/src/abi/connectors/v2/AAVE-IMPORT-V2-V3-A.ts +56 -0
- package/src/abi/connectors/v2/AAVE-V2-A.ts +93 -135
- package/src/abi/connectors/v2/AAVE-V2-IMPORT-C.ts +3 -0
- package/src/abi/connectors/v2/AAVE-V3-A.ts +321 -0
- package/src/abi/connectors/v2/AAVE-V3-CLAIM-A.ts +57 -0
- package/src/abi/connectors/v2/AAVE-V3-IMPORT-A.ts +58 -0
- package/src/abi/connectors/v2/AAVE-V3-IMPORT-PERMIT-A.ts +80 -0
- package/src/abi/connectors/v2/BASIC-A.ts +44 -86
- package/src/abi/connectors/v2/BENQI-A.ts +900 -0
- package/src/abi/connectors/v2/COMPOUND-IMPORT-C.ts +3 -0
- package/src/abi/connectors/v2/COMPOUND-IMPORT-D.ts +26 -0
- package/src/abi/connectors/v2/DSA-SPELL-A.ts +59 -0
- package/src/abi/connectors/v2/HOP-A.ts +40 -0
- package/src/abi/connectors/v2/HOP-MAINNET-A.ts +37 -0
- package/src/abi/connectors/v2/INSTA-DEX-SIMULATION-A.ts +39 -0
- package/src/abi/connectors/v2/INSTAPOOL-B.ts +3 -0
- package/src/abi/connectors/v2/INSTAPOOL-C.ts +3 -0
- package/src/abi/connectors/v2/INTEROP-A.ts +3 -0
- package/src/abi/connectors/v2/INTEROP-STAGING-A.ts +3 -0
- package/src/abi/connectors/v2/LIDO-STETH-A.ts +35 -0
- package/src/abi/connectors/v2/LITE-A.ts +3 -0
- package/src/abi/connectors/v2/MSTABLE-A.ts +3 -0
- package/src/abi/connectors/v2/NOTIONAL-V2-A.ts +483 -0
- package/src/abi/connectors/v2/PANGOLIN-A.ts +135 -0
- package/src/abi/connectors/v2/PANGOLIN-STAKE-A.ts +226 -0
- package/src/abi/connectors/v2/PARASWAP-A.ts +26 -1
- package/src/abi/connectors/v2/PARASWAP-V5-A.ts +28 -0
- package/src/abi/connectors/v2/POOLTOGETHER-A.ts +3 -0
- package/src/abi/connectors/v2/QI-A.ts +3 -0
- package/src/abi/connectors/v2/QUICKSWAP-A.ts +135 -0
- package/src/abi/connectors/v2/SUSHISWAP-A.ts +135 -0
- package/src/abi/connectors/v2/SWAP-AGGREGATOR-A.ts +24 -0
- package/src/abi/connectors/v2/UBIQUITY-A.ts +72 -0
- package/src/abi/connectors/v2/UNISWAP-SELL-BETA.ts +3 -0
- package/src/abi/connectors/v2/UNISWAP-V3-A.ts +1 -1
- package/src/abi/connectors/v2/UNISWAP-V3-ROUTER-A.ts +3 -0
- package/src/abi/connectors/v2/UNISWAP-V3-STAKER-B.ts +192 -0
- package/src/abi/connectors/v2/UNISWAP-V3-SWAP-A.ts +73 -0
- package/src/abi/connectors/v2/UNIVERSE-A.ts +3 -0
- package/src/abi/connectors/v2/WAVAX-A.ts +3 -0
- package/src/abi/connectors/v2/WFTM-A.ts +59 -0
- package/src/abi/connectors/v2/WMATIC-A.ts +3 -0
- package/src/abi/connectors/v2/ZEROX-A.ts +28 -0
- package/src/abi/connectors/v2/ZEROX-V4-A.ts +28 -0
- package/src/abi/connectors/v2/index.ts +171 -85
- package/src/abi/index.ts +8 -0
- package/src/abi/instList.json +232 -0
- package/src/api/index.ts +8 -0
- package/src/constants/addresses.ts +21 -2
- package/src/constants/capPerChain.ts +5 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/tokens.ts +44 -44
- package/src/constants/wrappedNativeToken.ts +5 -0
- package/src/crons/index.ts +1 -0
- package/src/crons/prices.ts +12 -0
- package/src/db/models/transaction.ts +22 -1
- package/src/errors/index.ts +26 -0
- package/src/gnosis/actions/aaveV2/source.ts +56 -3
- package/src/gnosis/actions/aaveV2/target.ts +35 -7
- package/src/gnosis/actions/aaveV3/index.ts +9 -0
- package/src/gnosis/actions/aaveV3/source.ts +119 -0
- package/src/gnosis/actions/aaveV3/target.ts +142 -0
- package/src/gnosis/actions/index.ts +2 -0
- package/src/index.ts +1 -0
- package/src/providers/index.ts +1 -0
- package/src/providers/retry-provider.ts +51 -0
- package/src/services/Prices.ts +89 -0
- package/src/services/index.ts +1 -0
- package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +139 -22
- package/src/tasks/InteropX/ProcessValidateEvents.ts +42 -19
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +6 -7
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +9 -10
- package/src/tasks/index.ts +8 -5
- package/src/typechain/AaveV2Resolver.ts +1017 -0
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/BalanceResolver.ts +266 -0
- package/src/typechain/InstList.ts +402 -0
- package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
- package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
- package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
- package/src/typechain/factories/InstList__factory.ts +253 -0
- package/src/typechain/factories/index.ts +4 -0
- package/src/typechain/index.ts +8 -0
- package/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +56 -0
- package/src/utils/formatting.ts +68 -0
- package/src/utils/gnosis.ts +166 -0
- package/src/utils/http.ts +6 -0
- package/src/utils/index.ts +9 -365
- package/src/utils/interop.ts +28 -0
- package/src/utils/tokens.ts +21 -0
- package/src/utils/validate.ts +179 -0
- package/src/utils/web3.ts +132 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LowLiquidityError = exports.InvalidChaindIdError = exports.LiquidityError = exports.UnsupportedChaindIdError = void 0;
|
4
|
+
class UnsupportedChaindIdError extends Error {
|
5
|
+
constructor(chainId) {
|
6
|
+
super(`Unsupported chainId: ${chainId}`);
|
7
|
+
}
|
8
|
+
}
|
9
|
+
exports.UnsupportedChaindIdError = UnsupportedChaindIdError;
|
10
|
+
class LiquidityError extends Error {
|
11
|
+
constructor(message) {
|
12
|
+
super(message || "Not enough liquidity");
|
13
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.LiquidityError = LiquidityError;
|
17
|
+
class InvalidChaindIdError extends Error {
|
18
|
+
constructor(message) {
|
19
|
+
super(message || "Invalid chain id");
|
20
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.InvalidChaindIdError = InvalidChaindIdError;
|
24
|
+
class LowLiquidityError extends Error {
|
25
|
+
constructor(message) {
|
26
|
+
super(message || "Low liquidity");
|
27
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
exports.LowLiquidityError = LowLiquidityError;
|
@@ -6,19 +6,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const abi_1 = __importDefault(require("@/abi"));
|
7
7
|
const config_1 = __importDefault(require("@/config"));
|
8
8
|
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
9
10
|
const utils_1 = require("@/utils");
|
10
11
|
const ethers_1 = require("ethers");
|
11
12
|
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
const safeUserRatioGap = "800000000000000000";
|
12
14
|
async function default_1(transaction) {
|
13
15
|
const transactions = [];
|
14
16
|
const logs = [];
|
15
17
|
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.submitEvent;
|
16
|
-
const sourceChainProvider = new
|
18
|
+
const sourceChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
|
17
19
|
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
20
|
+
const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
21
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
18
22
|
const dsaAddress = constants_1.addresses[sourceChainId].dsaAddress;
|
19
23
|
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
20
24
|
const interopAddress = constants_1.addresses[sourceChainId].interopX;
|
21
25
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, sourceWallet);
|
26
|
+
const sourceResolverContract = (0, utils_1.getContract)(constants_1.addresses[sourceChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, sourceWallet);
|
27
|
+
const targetResolverContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, targetWallet);
|
28
|
+
const sourceDsaAddress = await (0, utils_1.getDsaAccountAddress)({ dsaId: sourceDsaId, chainId: sourceChainId, provider: sourceChainProvider });
|
29
|
+
const sourceAavePosition = await sourceResolverContract.checkAavePosition(sourceDsaAddress, position, safeUserRatioGap, false);
|
30
|
+
const userSourceAaveIsOk = sourceAavePosition.isOk;
|
31
|
+
if (!userSourceAaveIsOk) {
|
32
|
+
throw new Error("Source chain aave position is not safe to migrate.");
|
33
|
+
}
|
34
|
+
const targetDsaAddress = await (0, utils_1.getDsaAccountAddress)({ dsaId: targetDsaId, chainId: targetChainId, provider: targetChainProvider });
|
35
|
+
const targetAavePosition = await targetResolverContract
|
36
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
37
|
+
const userTargetAaveIsOk = targetAavePosition.isOk;
|
38
|
+
if (!userTargetAaveIsOk) {
|
39
|
+
throw new Error("Target chain aave position will not be safe after migration.");
|
40
|
+
}
|
41
|
+
const targetAavePositionWithFee = await targetResolverContract
|
42
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
43
|
+
const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
|
44
|
+
if (!userTargetAaveIsOkWithFee) {
|
45
|
+
throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
|
46
|
+
}
|
22
47
|
const sourceSpells = [];
|
23
48
|
const commonSpells = [];
|
24
49
|
for (const withdraw of position.withdraw) {
|
@@ -6,17 +6,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const abi_1 = __importDefault(require("@/abi"));
|
7
7
|
const config_1 = __importDefault(require("@/config"));
|
8
8
|
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
9
10
|
const utils_1 = require("@/utils");
|
10
11
|
const ethers_1 = require("ethers");
|
11
12
|
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
const safeUserRatioGap = "800000000000000000";
|
12
14
|
async function default_1(transaction) {
|
13
15
|
const transactions = [];
|
14
16
|
const logs = [];
|
15
17
|
const { sourceSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.validateEvent;
|
16
|
-
const targetChainProvider = new
|
18
|
+
const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
17
19
|
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
20
|
+
const targetResolverContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, targetWallet);
|
21
|
+
const targetDsaAddress = await (0, utils_1.getDsaAccountAddress)({ dsaId: targetDsaId, chainId: targetChainId, provider: targetChainProvider });
|
22
|
+
const targetAavePosition = await targetResolverContract
|
23
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
24
|
+
const userTargetAaveIsOk = targetAavePosition.isOk;
|
25
|
+
if (!userTargetAaveIsOk) {
|
26
|
+
throw new Error("Target chain aave position will not be safe after migration.");
|
27
|
+
}
|
28
|
+
const targetAavePositionWithFee = await targetResolverContract
|
29
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
30
|
+
const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
|
31
|
+
if (!userTargetAaveIsOkWithFee) {
|
32
|
+
throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
|
33
|
+
}
|
18
34
|
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
19
|
-
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
20
35
|
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
21
36
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
22
37
|
const targetSpells = [];
|
@@ -34,7 +49,7 @@ async function default_1(transaction) {
|
|
34
49
|
let spellDataBasicWithdraw = {
|
35
50
|
connector: "BASIC-A",
|
36
51
|
method: "withdraw",
|
37
|
-
args: [supplyToken.targetToken, supplyToken.amount,
|
52
|
+
args: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
|
38
53
|
};
|
39
54
|
commonSpells.push({
|
40
55
|
connector: spellDataBasicWithdraw.connector,
|
@@ -63,13 +78,13 @@ async function default_1(transaction) {
|
|
63
78
|
args: [
|
64
79
|
withdrawToken.targetToken,
|
65
80
|
withdrawToken.amount,
|
66
|
-
|
81
|
+
dsaAddress,
|
67
82
|
"0",
|
68
83
|
"0",
|
69
84
|
],
|
70
85
|
};
|
71
86
|
targetSpells.push({
|
72
|
-
connector:
|
87
|
+
connector: spellData2.connector,
|
73
88
|
data: (0, utils_1.encodeConnectorMethod)(spellData2),
|
74
89
|
});
|
75
90
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const source_1 = __importDefault(require("./source"));
|
7
|
+
const target_1 = __importDefault(require("./target"));
|
8
|
+
async function default_1(transaction, type) {
|
9
|
+
return type === 'source' ? (0, source_1.default)(transaction) : (0, target_1.default)(transaction);
|
10
|
+
}
|
11
|
+
exports.default = default_1;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const abi_1 = __importDefault(require("@/abi"));
|
7
|
+
const config_1 = __importDefault(require("@/config"));
|
8
|
+
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
10
|
+
const utils_1 = require("@/utils");
|
11
|
+
const ethers_1 = require("ethers");
|
12
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
async function default_1(transaction) {
|
14
|
+
const transactions = [];
|
15
|
+
const logs = [];
|
16
|
+
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.submitEvent;
|
17
|
+
const sourceChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
|
18
|
+
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
19
|
+
const dsaAddress = constants_1.addresses[sourceChainId].dsaAddress;
|
20
|
+
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
21
|
+
const interopAddress = constants_1.addresses[sourceChainId].interopX;
|
22
|
+
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, sourceWallet);
|
23
|
+
const sourceSpells = [];
|
24
|
+
const commonSpells = [];
|
25
|
+
for (const withdraw of position.withdraw) {
|
26
|
+
let spellData = {
|
27
|
+
connector: "AAVE-V3-A",
|
28
|
+
method: "payback",
|
29
|
+
args: [withdraw.sourceToken, withdraw.amount, "2", "0", "0"],
|
30
|
+
};
|
31
|
+
sourceSpells.push({
|
32
|
+
connector: spellData.connector,
|
33
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
34
|
+
});
|
35
|
+
let spellDataBasicWithdraw = {
|
36
|
+
connector: "BASIC-A",
|
37
|
+
method: "withdraw",
|
38
|
+
args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
39
|
+
};
|
40
|
+
commonSpells.push({
|
41
|
+
connector: spellDataBasicWithdraw.connector,
|
42
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
43
|
+
});
|
44
|
+
}
|
45
|
+
for (const supply of position.supply) {
|
46
|
+
let spellDataWithdraw = {
|
47
|
+
connector: "AAVE-V3-A",
|
48
|
+
method: "withdraw",
|
49
|
+
args: [supply.sourceToken, supply.amount, "0", "0"],
|
50
|
+
};
|
51
|
+
sourceSpells.push({
|
52
|
+
connector: spellDataWithdraw.connector,
|
53
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataWithdraw),
|
54
|
+
});
|
55
|
+
let spellDataBasicWithdraw = {
|
56
|
+
connector: "BASIC-A",
|
57
|
+
method: "withdraw",
|
58
|
+
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
59
|
+
};
|
60
|
+
sourceSpells.push({
|
61
|
+
connector: spellDataBasicWithdraw.connector,
|
62
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
63
|
+
});
|
64
|
+
}
|
65
|
+
const { data } = await contract.populateTransaction.sourceAction(sourceSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
|
66
|
+
transactions.push({
|
67
|
+
to: interopAddress,
|
68
|
+
data: data,
|
69
|
+
value: "0",
|
70
|
+
operation: ethers_multisend_1.OperationType.Call,
|
71
|
+
});
|
72
|
+
return { transactions, logs };
|
73
|
+
}
|
74
|
+
exports.default = default_1;
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const abi_1 = __importDefault(require("@/abi"));
|
7
|
+
const config_1 = __importDefault(require("@/config"));
|
8
|
+
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
10
|
+
const utils_1 = require("@/utils");
|
11
|
+
const ethers_1 = require("ethers");
|
12
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
async function default_1(transaction) {
|
14
|
+
const transactions = [];
|
15
|
+
const logs = [];
|
16
|
+
const { sourceSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.validateEvent;
|
17
|
+
const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
18
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
19
|
+
const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
20
|
+
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
21
|
+
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
22
|
+
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
23
|
+
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
24
|
+
const targetSpells = [];
|
25
|
+
const commonSpells = [];
|
26
|
+
for (const supplyToken of position.supply) {
|
27
|
+
let spellData = {
|
28
|
+
connector: "AAVE-V3-A",
|
29
|
+
method: "deposit",
|
30
|
+
args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
|
31
|
+
};
|
32
|
+
targetSpells.push({
|
33
|
+
connector: spellData.connector,
|
34
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
35
|
+
});
|
36
|
+
let spellDataBasicWithdraw = {
|
37
|
+
connector: "BASIC-A",
|
38
|
+
method: "withdraw",
|
39
|
+
args: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
|
40
|
+
};
|
41
|
+
commonSpells.push({
|
42
|
+
connector: spellDataBasicWithdraw.connector,
|
43
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
44
|
+
});
|
45
|
+
}
|
46
|
+
for (const withdrawToken of position.withdraw) {
|
47
|
+
let spellData = {
|
48
|
+
connector: "AAVE-V3-A",
|
49
|
+
method: "borrow",
|
50
|
+
args: [
|
51
|
+
withdrawToken.targetToken,
|
52
|
+
withdrawToken.amount,
|
53
|
+
"2",
|
54
|
+
"0",
|
55
|
+
"0",
|
56
|
+
],
|
57
|
+
};
|
58
|
+
targetSpells.push({
|
59
|
+
connector: spellData.connector,
|
60
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
61
|
+
});
|
62
|
+
let spellData2 = {
|
63
|
+
connector: "BASIC-A",
|
64
|
+
method: "withdraw",
|
65
|
+
args: [
|
66
|
+
withdrawToken.targetToken,
|
67
|
+
withdrawToken.amount,
|
68
|
+
dsaAddress,
|
69
|
+
"0",
|
70
|
+
"0",
|
71
|
+
],
|
72
|
+
};
|
73
|
+
targetSpells.push({
|
74
|
+
connector: spellData2.connector,
|
75
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData2),
|
76
|
+
});
|
77
|
+
}
|
78
|
+
const { data } = await contract.populateTransaction.targetAction(sourceSpells, targetSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
|
79
|
+
transactions.push({
|
80
|
+
to: interopAddress,
|
81
|
+
data: data,
|
82
|
+
value: "0",
|
83
|
+
operation: ethers_multisend_1.OperationType.Call,
|
84
|
+
});
|
85
|
+
return { transactions, logs };
|
86
|
+
}
|
87
|
+
exports.default = default_1;
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const aaveV2_1 = __importDefault(require("./aaveV2"));
|
7
|
+
const aaveV3_1 = __importDefault(require("./aaveV3"));
|
7
8
|
exports.default = {
|
8
9
|
'A:AAVE-V2:AAVE-V2': aaveV2_1.default,
|
10
|
+
'A:AAVE-V3:AAVE-V3': aaveV3_1.default,
|
9
11
|
};
|
package/dist/src/index.js
CHANGED
@@ -13,7 +13,7 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
13
13
|
dotenv_1.default.config();
|
14
14
|
const logger_1 = __importDefault(require("@/logger"));
|
15
15
|
const logger = new logger_1.default('Process');
|
16
|
-
const GIT_SHORT_HASH = '
|
16
|
+
const GIT_SHORT_HASH = '909c44a';
|
17
17
|
const printUsage = () => {
|
18
18
|
console.log();
|
19
19
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
@@ -69,6 +69,7 @@ const net_1 = require("@/net");
|
|
69
69
|
const api_1 = require("@/api");
|
70
70
|
const db_1 = require("./db");
|
71
71
|
const utils_1 = require("./utils");
|
72
|
+
require("./crons");
|
72
73
|
async function main() {
|
73
74
|
(0, net_1.startPeer)({});
|
74
75
|
const tasks = new tasks_1.Tasks();
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./retry-provider"), exports);
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.JsonRpcRetryProvider = exports.retryOperation = exports.promiseTimeout = void 0;
|
7
|
+
const ethers_1 = require("ethers");
|
8
|
+
const waait_1 = __importDefault(require("waait"));
|
9
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
10
|
+
function promiseTimeout(ms, promise) {
|
11
|
+
return bluebird_1.default.resolve(promise).timeout(ms);
|
12
|
+
}
|
13
|
+
exports.promiseTimeout = promiseTimeout;
|
14
|
+
function retryOperation(retriesLeft, operation, options) {
|
15
|
+
return new Promise((resolve, reject) => {
|
16
|
+
const { timeouts } = options;
|
17
|
+
// Find the timeout for this specific iteration
|
18
|
+
const timeout = timeouts[timeouts.length - retriesLeft];
|
19
|
+
// Wrap the original operation in a timeout
|
20
|
+
const execution = promiseTimeout(timeout, operation());
|
21
|
+
// If the promise is successful, resolve it and bubble the result up
|
22
|
+
return execution.then(resolve).catch((reason) => {
|
23
|
+
// If there are any retries left, we call the same retryOperation function again,
|
24
|
+
// but decrementing the number of retries left by 1
|
25
|
+
if (retriesLeft - 1 > 0) {
|
26
|
+
// Delay the new attempt slightly
|
27
|
+
return (0, waait_1.default)(options.delay || 50)
|
28
|
+
.then(retryOperation.bind(null, retriesLeft - 1, operation, options))
|
29
|
+
.then(resolve)
|
30
|
+
.catch(reject);
|
31
|
+
}
|
32
|
+
// Reject (and bubble the result up) if there are no more retries
|
33
|
+
return reject(reason);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
}
|
37
|
+
exports.retryOperation = retryOperation;
|
38
|
+
class JsonRpcRetryProvider extends ethers_1.ethers.providers.JsonRpcProvider {
|
39
|
+
perform(method, params) {
|
40
|
+
const timeouts = [5000, 10000];
|
41
|
+
const operation = () => super.perform(method, params);
|
42
|
+
return retryOperation(2, operation, { timeouts, delay: 50 });
|
43
|
+
}
|
44
|
+
}
|
45
|
+
exports.JsonRpcRetryProvider = JsonRpcRetryProvider;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const web3_utils_1 = __importDefault(require("web3-utils"));
|
7
|
+
const path_1 = __importDefault(require("path"));
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
9
|
+
const constants_1 = require("@/constants");
|
10
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
11
|
+
const config_1 = __importDefault(require("@/config"));
|
12
|
+
const utils_1 = require("@/utils");
|
13
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
|
14
|
+
const mainnetPricesFilePath = path_1.default.resolve(basePath, "./mainnetPrices.json");
|
15
|
+
const networkTokenPricesFilePath = path_1.default.resolve(basePath, "./networkTokenPrices.json");
|
16
|
+
class Prices {
|
17
|
+
static async fetch() {
|
18
|
+
if (!fs_1.default.existsSync(mainnetPricesFilePath)) {
|
19
|
+
fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify({}));
|
20
|
+
}
|
21
|
+
if (!fs_1.default.existsSync(networkTokenPricesFilePath)) {
|
22
|
+
fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify({}));
|
23
|
+
}
|
24
|
+
this.mainnetPrices = JSON.parse(fs_1.default.readFileSync(mainnetPricesFilePath, "utf8"));
|
25
|
+
this.networkTokenPrices = JSON.parse(fs_1.default.readFileSync(networkTokenPricesFilePath, "utf8"));
|
26
|
+
try {
|
27
|
+
const path = constants_1.tokens["1"]
|
28
|
+
.filter((a) => a.symbol !== "ETH")
|
29
|
+
.map((token) => token.address)
|
30
|
+
.join(",");
|
31
|
+
const [response, ethResponse, avaxResponse, polygonResponse] = await Promise.all([
|
32
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum", {
|
33
|
+
params: { contract_addresses: path, vs_currencies: "usd" },
|
34
|
+
}),
|
35
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
36
|
+
params: { ids: "ethereum", vs_currencies: "usd" },
|
37
|
+
}),
|
38
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
39
|
+
params: { ids: "avalanche-2", vs_currencies: "usd" },
|
40
|
+
}),
|
41
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
42
|
+
params: { ids: "matic-network", vs_currencies: "usd" },
|
43
|
+
}),
|
44
|
+
]);
|
45
|
+
this.networkTokenPrices = {
|
46
|
+
"1": ethResponse.data.ethereum.usd.toString(),
|
47
|
+
"137": polygonResponse.data["matic-network"].usd.toString(),
|
48
|
+
"43114": avaxResponse.data["avalanche-2"].usd.toString(),
|
49
|
+
};
|
50
|
+
const data = response.data;
|
51
|
+
for (const key in data) {
|
52
|
+
const _key = web3_utils_1.default.toChecksumAddress(key);
|
53
|
+
if (!data[key].usd)
|
54
|
+
continue;
|
55
|
+
this.mainnetPrices[_key] = data[key].usd.toString();
|
56
|
+
}
|
57
|
+
this.mainnetPrices["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"] =
|
58
|
+
ethResponse.data.ethereum.usd.toString();
|
59
|
+
}
|
60
|
+
catch (error) { }
|
61
|
+
fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify(this.mainnetPrices));
|
62
|
+
fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify(this.networkTokenPrices));
|
63
|
+
return this.mainnetPrices;
|
64
|
+
}
|
65
|
+
static getMainnetPrices() {
|
66
|
+
return this.mainnetPrices;
|
67
|
+
}
|
68
|
+
static getNetworkTokenPrices() {
|
69
|
+
return this.networkTokenPrices;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
Prices.mainnetPrices = {};
|
73
|
+
Prices.networkTokenPrices = {};
|
74
|
+
exports.default = Prices;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Prices = void 0;
|
7
|
+
var Prices_1 = require("./Prices");
|
8
|
+
Object.defineProperty(exports, "Prices", { enumerable: true, get: function () { return __importDefault(Prices_1).default; } });
|