@instadapp/interop-x 0.0.0-dev.f39d622 → 0.0.0-dev.f45bd03

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.
Files changed (49) hide show
  1. package/dist/package.json +4 -2
  2. package/dist/src/abi/aaveV3Resolver.json +628 -0
  3. package/dist/src/abi/index.js +2 -0
  4. package/dist/src/constants/addresses.js +4 -2
  5. package/dist/src/db/models/transaction.js +1 -1
  6. package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
  7. package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
  8. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  9. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  10. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  11. package/dist/src/gnosis/actions/index.js +2 -0
  12. package/dist/src/index.js +1 -1
  13. package/dist/src/providers/index.js +17 -0
  14. package/dist/src/providers/retry-provider.js +45 -0
  15. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +38 -10
  16. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
  17. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
  18. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
  19. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
  20. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  21. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  22. package/dist/src/typechain/factories/index.js +3 -1
  23. package/dist/src/typechain/index.js +3 -1
  24. package/dist/src/utils/gnosis.js +42 -17
  25. package/dist/src/utils/validate.js +10 -14
  26. package/package.json +4 -2
  27. package/src/abi/aaveV3Resolver.json +628 -0
  28. package/src/abi/index.ts +2 -0
  29. package/src/constants/addresses.ts +6 -3
  30. package/src/db/models/transaction.ts +1 -1
  31. package/src/gnosis/actions/aaveV2/source.ts +58 -2
  32. package/src/gnosis/actions/aaveV2/target.ts +29 -2
  33. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  34. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  35. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  36. package/src/gnosis/actions/index.ts +2 -0
  37. package/src/providers/index.ts +1 -0
  38. package/src/providers/retry-provider.ts +51 -0
  39. package/src/tasks/InteropX/ProcessSubmitEvents.ts +52 -13
  40. package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -13
  41. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
  42. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
  43. package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
  44. package/src/typechain/AaveV3Resolver.ts +935 -0
  45. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  46. package/src/typechain/factories/index.ts +1 -0
  47. package/src/typechain/index.ts +2 -0
  48. package/src/utils/gnosis.ts +75 -32
  49. package/src/utils/validate.ts +17 -19
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.BalanceResolver__factory = exports.AaveV2Resolver__factory = void 0;
3
+ exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.BalanceResolver__factory = exports.AaveV3Resolver__factory = exports.AaveV2Resolver__factory = void 0;
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
  /* tslint:disable */
6
6
  /* eslint-disable */
7
7
  var AaveV2Resolver__factory_1 = require("./AaveV2Resolver__factory");
8
8
  Object.defineProperty(exports, "AaveV2Resolver__factory", { enumerable: true, get: function () { return AaveV2Resolver__factory_1.AaveV2Resolver__factory; } });
9
+ var AaveV3Resolver__factory_1 = require("./AaveV3Resolver__factory");
10
+ Object.defineProperty(exports, "AaveV3Resolver__factory", { enumerable: true, get: function () { return AaveV3Resolver__factory_1.AaveV3Resolver__factory; } });
9
11
  var BalanceResolver__factory_1 = require("./BalanceResolver__factory");
10
12
  Object.defineProperty(exports, "BalanceResolver__factory", { enumerable: true, get: function () { return BalanceResolver__factory_1.BalanceResolver__factory; } });
11
13
  var Erc20__factory_1 = require("./Erc20__factory");
@@ -23,10 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.BalanceResolver__factory = exports.AaveV2Resolver__factory = exports.factories = void 0;
26
+ exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.BalanceResolver__factory = exports.AaveV3Resolver__factory = exports.AaveV2Resolver__factory = exports.factories = void 0;
27
27
  exports.factories = __importStar(require("./factories"));
28
28
  var AaveV2Resolver__factory_1 = require("./factories/AaveV2Resolver__factory");
29
29
  Object.defineProperty(exports, "AaveV2Resolver__factory", { enumerable: true, get: function () { return AaveV2Resolver__factory_1.AaveV2Resolver__factory; } });
30
+ var AaveV3Resolver__factory_1 = require("./factories/AaveV3Resolver__factory");
31
+ Object.defineProperty(exports, "AaveV3Resolver__factory", { enumerable: true, get: function () { return AaveV3Resolver__factory_1.AaveV3Resolver__factory; } });
30
32
  var BalanceResolver__factory_1 = require("./factories/BalanceResolver__factory");
31
33
  Object.defineProperty(exports, "BalanceResolver__factory", { enumerable: true, get: function () { return BalanceResolver__factory_1.BalanceResolver__factory; } });
32
34
  var Erc20__factory_1 = require("./factories/Erc20__factory");
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateGnosisTransaction = exports.signGnosisSafeTx = exports.buildSignatureBytes = void 0;
3
+ exports.getGnosisOwnerPeerIds = exports.generateGnosisTransaction = exports.signGnosisSafeTx = exports.generateGnosisSignatureMessage = exports.getGnosisSignatureAddress = exports.buildSignatureBytes = void 0;
4
4
  const constants_1 = require("@/constants");
5
+ const net_1 = require("@/net");
5
6
  const ethers_1 = require("ethers");
6
7
  const buildSignatureBytes = (signatures) => {
7
8
  signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
@@ -12,26 +13,31 @@ const buildSignatureBytes = (signatures) => {
12
13
  return signatureBytes;
13
14
  };
14
15
  exports.buildSignatureBytes = buildSignatureBytes;
15
- const signGnosisSafeTx = async ({ to, data = null, value = "0", operation = "1", baseGas = "0", gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }, { signer }) => {
16
+ const gnosisSignatureTypes = {
17
+ SafeTx: [
18
+ { type: "address", name: "to" },
19
+ { type: "uint256", name: "value" },
20
+ { type: "bytes", name: "data" },
21
+ { type: "uint8", name: "operation" },
22
+ { type: "uint256", name: "safeTxGas" },
23
+ { type: "uint256", name: "baseGas" },
24
+ { type: "uint256", name: "gasPrice" },
25
+ { type: "address", name: "gasToken" },
26
+ { type: "address", name: "refundReceiver" },
27
+ { type: "uint256", name: "nonce" },
28
+ ],
29
+ };
30
+ const getGnosisSignatureAddress = ({ signature, message, chainId }) => {
16
31
  const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
17
32
  const domain = {
18
33
  verifyingContract: gnosisSafe,
19
34
  chainId,
20
35
  };
21
- const types = {
22
- SafeTx: [
23
- { type: "address", name: "to" },
24
- { type: "uint256", name: "value" },
25
- { type: "bytes", name: "data" },
26
- { type: "uint8", name: "operation" },
27
- { type: "uint256", name: "safeTxGas" },
28
- { type: "uint256", name: "baseGas" },
29
- { type: "uint256", name: "gasPrice" },
30
- { type: "address", name: "gasToken" },
31
- { type: "address", name: "refundReceiver" },
32
- { type: "uint256", name: "nonce" },
33
- ],
34
- };
36
+ return ethers_1.ethers.utils.verifyTypedData(domain, gnosisSignatureTypes, message, signature);
37
+ };
38
+ exports.getGnosisSignatureAddress = getGnosisSignatureAddress;
39
+ const generateGnosisSignatureMessage = ({ to, data = null, value = "0", operation = "1", baseGas = "0", gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }) => {
40
+ const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
35
41
  const message = {
36
42
  baseGas,
37
43
  data,
@@ -45,7 +51,17 @@ const signGnosisSafeTx = async ({ to, data = null, value = "0", operation = "1",
45
51
  to,
46
52
  value,
47
53
  };
48
- return await signer._signTypedData(domain, types, message);
54
+ return message;
55
+ };
56
+ exports.generateGnosisSignatureMessage = generateGnosisSignatureMessage;
57
+ const signGnosisSafeTx = async ({ to, data = null, value = "0", operation = "1", baseGas = "0", gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }, { signer }) => {
58
+ const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
59
+ const domain = {
60
+ verifyingContract: gnosisSafe,
61
+ chainId,
62
+ };
63
+ const message = (0, exports.generateGnosisSignatureMessage)({ to, data, value, operation, baseGas, gasPrice, gasToken, refundReceiver, safeTxGas, nonce, chainId });
64
+ return await signer._signTypedData(domain, gnosisSignatureTypes, message);
49
65
  };
50
66
  exports.signGnosisSafeTx = signGnosisSafeTx;
51
67
  const generateGnosisTransaction = async (transactionData, safeContract) => {
@@ -60,3 +76,12 @@ const generateGnosisTransaction = async (transactionData, safeContract) => {
60
76
  return transactionData;
61
77
  };
62
78
  exports.generateGnosisTransaction = generateGnosisTransaction;
79
+ const getGnosisOwnerPeerIds = async ({ gnosisContract = null }) => {
80
+ const owners = await gnosisContract
81
+ .getOwners()
82
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
83
+ return net_1.peerPool.activePeers
84
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
85
+ .map((peer) => peer.id);
86
+ };
87
+ exports.getGnosisOwnerPeerIds = getGnosisOwnerPeerIds;
@@ -7,12 +7,12 @@ exports.validateLiquidityCap = exports.validateTargetLiquidity = exports.validat
7
7
  const abi_1 = __importDefault(require("@/abi"));
8
8
  const constants_1 = require("@/constants");
9
9
  const errors_1 = require("@/errors");
10
- const ethers_1 = require("ethers");
11
10
  const web3_1 = require("./web3");
12
11
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
13
12
  const formatting_1 = require("./formatting");
14
13
  const tokens_1 = require("./tokens");
15
14
  const services_1 = require("@/services");
15
+ const providers_1 = require("@/providers");
16
16
  const validateChains = ({ sourceChainId, targetChainId }) => {
17
17
  if (!sourceChainId) {
18
18
  throw new errors_1.InvalidChaindIdError("Source chain id is required");
@@ -31,12 +31,10 @@ const validateChains = ({ sourceChainId, targetChainId }) => {
31
31
  }
32
32
  };
33
33
  exports.validateChains = validateChains;
34
- const validateSourceLiquidity = async ({ position, sourceChainId, isSupply = false, sourceProvider = null, }) => {
35
- sourceProvider = sourceProvider || new ethers_1.ethers.providers.JsonRpcProvider((0, web3_1.getRpcProviderUrl)(sourceChainId));
34
+ const validateSourceLiquidity = async ({ position = null, sourceChainId, isSupply = false, sourceProvider = null, }) => {
35
+ sourceProvider = sourceProvider || new providers_1.JsonRpcRetryProvider((0, web3_1.getRpcProviderUrl)(sourceChainId));
36
36
  const sourceBalanceResolverContract = (0, web3_1.getContract)(constants_1.addresses[sourceChainId].balanceResolver, abi_1.default.balanceResolver, sourceProvider);
37
- const srcBalance = await sourceBalanceResolverContract.methods
38
- .checkLiquidity(position, constants_1.addresses[sourceChainId].interopX, isSupply, false)
39
- .call();
37
+ const srcBalance = await sourceBalanceResolverContract.checkLiquidity(position, constants_1.addresses[sourceChainId].interopX, isSupply, false);
40
38
  if (!srcBalance.isOk) {
41
39
  let liquidityRequired = "";
42
40
  srcBalance.withdraw.forEach(a => {
@@ -49,12 +47,10 @@ const validateSourceLiquidity = async ({ position, sourceChainId, isSupply = fal
49
47
  }
50
48
  };
51
49
  exports.validateSourceLiquidity = validateSourceLiquidity;
52
- const validateTargetLiquidity = async ({ position, targetChainId, targetProvider = null, }) => {
53
- targetProvider = targetProvider || new ethers_1.ethers.providers.JsonRpcProvider((0, web3_1.getRpcProviderUrl)(targetChainId));
50
+ const validateTargetLiquidity = async ({ position = null, targetChainId, targetProvider = null, }) => {
51
+ targetProvider = targetProvider || new providers_1.JsonRpcRetryProvider((0, web3_1.getRpcProviderUrl)(targetChainId));
54
52
  const sourceBalanceResolverContract = (0, web3_1.getContract)(constants_1.addresses[targetChainId].balanceResolver, abi_1.default.balanceResolver, targetProvider);
55
- const targetBalance = await sourceBalanceResolverContract.methods
56
- .checkLiquidity(position, constants_1.addresses[targetChainId].interopX, true, true)
57
- .call();
53
+ const targetBalance = await sourceBalanceResolverContract.checkLiquidity(position, constants_1.addresses[targetChainId].interopX, true, true);
58
54
  if (!targetBalance.isOk) {
59
55
  let liquidityRequired = "";
60
56
  targetBalance.supply.forEach(a => {
@@ -83,8 +79,8 @@ const validateLiquidityCap = async (position, sourceChainId, targetChainId) => {
83
79
  const mainnetPrices = services_1.Prices.getMainnetPrices();
84
80
  const nativeTokenPrice = services_1.Prices.getNetworkTokenPrices()[targetChainId];
85
81
  let total = new bignumber_js_1.default(0);
86
- const supplyPosition = position[0];
87
- for (const [srcTokenAddress, tokenAddress, amount] of supplyPosition) {
82
+ const supplyPosition = position.supply;
83
+ for (const { sourceToken: srcTokenAddress, targetToken: tokenAddress, amount } of supplyPosition) {
88
84
  let tokenPrice;
89
85
  let token;
90
86
  if ((0, tokens_1.isNativeWrappedToken)(srcTokenAddress, sourceChainId)) {
@@ -102,7 +98,7 @@ const validateLiquidityCap = async (position, sourceChainId, targetChainId) => {
102
98
  }
103
99
  token = mainnetToken;
104
100
  }
105
- total = total.plus((tokenPrice * amount) / 10 ** token.decimals);
101
+ total = total.plus((tokenPrice * Number(amount)) / 10 ** token.decimals);
106
102
  }
107
103
  if (total.isGreaterThan(cap)) {
108
104
  throw new Error(`Total amount of tokens in the transaction is greater than the maximum limit of estimated ${(0, formatting_1.formatUsd)(cap)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.f39d622",
3
+ "version": "0.0.0-dev.f45bd03",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -30,11 +30,12 @@
30
30
  "axios": "^0.27.2",
31
31
  "axios-retry": "^3.2.5",
32
32
  "bignumber.js": "^9.0.2",
33
+ "bluebird": "^3.7.2",
33
34
  "chalk": "4.1.2",
34
35
  "dedent": "^0.7.0",
35
36
  "dotenv": "^16.0.1",
36
37
  "ethereumjs-util": "^7.1.4",
37
- "ethers": "^5.6.5",
38
+ "ethers": "^5.6.8",
38
39
  "ethers-multisend": "^2.1.1",
39
40
  "expand-home-dir": "^0.0.3",
40
41
  "fastify": "^3.29.0",
@@ -66,6 +67,7 @@
66
67
  "devDependencies": {
67
68
  "@typechain/ethers-v5": "^10.0.0",
68
69
  "@types/async-retry": "^1.4.4",
70
+ "@types/bluebird": "^3.5.36",
69
71
  "@types/bn.js": "^5.1.0",
70
72
  "@types/dedent": "^0.7.0",
71
73
  "@types/fs-extra": "^9.0.13",