@instadapp/interop-x 0.0.0-dev.ef7acff → 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 (88) hide show
  1. package/dist/package.json +8 -2
  2. package/dist/src/abi/aaveV2Resolver.json +832 -0
  3. package/dist/src/abi/aaveV3Resolver.json +628 -0
  4. package/dist/src/abi/balanceResolver.json +211 -0
  5. package/dist/src/abi/index.js +6 -0
  6. package/dist/src/constants/addresses.js +6 -0
  7. package/dist/src/constants/capPerChain.js +8 -0
  8. package/dist/src/constants/index.js +2 -0
  9. package/dist/src/constants/tokens.js +44 -44
  10. package/dist/src/constants/wrappedNativeToken.js +8 -0
  11. package/dist/src/crons/index.js +3 -0
  12. package/dist/src/crons/prices.js +16 -0
  13. package/dist/src/db/models/transaction.js +1 -1
  14. package/dist/src/errors/index.js +14 -1
  15. package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
  16. package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
  17. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  18. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  19. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  20. package/dist/src/gnosis/actions/index.js +2 -0
  21. package/dist/src/index.js +2 -1
  22. package/dist/src/providers/index.js +17 -0
  23. package/dist/src/providers/retry-provider.js +45 -0
  24. package/dist/src/services/Prices.js +74 -0
  25. package/dist/src/services/index.js +8 -0
  26. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +92 -12
  27. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
  28. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
  29. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
  30. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
  31. package/dist/src/typechain/AaveV2Resolver.js +2 -0
  32. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  33. package/dist/src/typechain/BalanceResolver.js +2 -0
  34. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  35. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  36. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  37. package/dist/src/typechain/factories/index.js +7 -1
  38. package/dist/src/typechain/index.js +7 -1
  39. package/dist/src/utils/formatting.js +51 -1
  40. package/dist/src/utils/gnosis.js +42 -17
  41. package/dist/src/utils/index.js +1 -0
  42. package/dist/src/utils/tokens.js +22 -0
  43. package/dist/src/utils/validate.js +85 -1
  44. package/dist/src/utils/web3.js +2 -1
  45. package/package.json +8 -2
  46. package/src/abi/aaveV2Resolver.json +832 -0
  47. package/src/abi/aaveV3Resolver.json +628 -0
  48. package/src/abi/balanceResolver.json +211 -0
  49. package/src/abi/index.ts +6 -0
  50. package/src/constants/addresses.ts +18 -1
  51. package/src/constants/capPerChain.ts +5 -0
  52. package/src/constants/index.ts +2 -0
  53. package/src/constants/tokens.ts +44 -44
  54. package/src/constants/wrappedNativeToken.ts +5 -0
  55. package/src/crons/index.ts +1 -0
  56. package/src/crons/prices.ts +12 -0
  57. package/src/db/models/transaction.ts +1 -1
  58. package/src/errors/index.ts +13 -0
  59. package/src/gnosis/actions/aaveV2/source.ts +58 -2
  60. package/src/gnosis/actions/aaveV2/target.ts +29 -2
  61. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  62. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  63. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  64. package/src/gnosis/actions/index.ts +2 -0
  65. package/src/index.ts +1 -0
  66. package/src/providers/index.ts +1 -0
  67. package/src/providers/retry-provider.ts +51 -0
  68. package/src/services/Prices.ts +89 -0
  69. package/src/services/index.ts +1 -0
  70. package/src/tasks/InteropX/ProcessSubmitEvents.ts +120 -17
  71. package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -14
  72. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
  73. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
  74. package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
  75. package/src/typechain/AaveV2Resolver.ts +1017 -0
  76. package/src/typechain/AaveV3Resolver.ts +935 -0
  77. package/src/typechain/BalanceResolver.ts +266 -0
  78. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  79. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  80. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  81. package/src/typechain/factories/index.ts +3 -0
  82. package/src/typechain/index.ts +6 -0
  83. package/src/utils/formatting.ts +53 -0
  84. package/src/utils/gnosis.ts +75 -32
  85. package/src/utils/index.ts +1 -0
  86. package/src/utils/tokens.ts +21 -0
  87. package/src/utils/validate.ts +149 -2
  88. package/src/utils/web3.ts +3 -2
@@ -0,0 +1,211 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "internalType": "address",
6
+ "name": "_wnativeToken",
7
+ "type": "address"
8
+ }
9
+ ],
10
+ "stateMutability": "nonpayable",
11
+ "type": "constructor"
12
+ },
13
+ {
14
+ "inputs": [
15
+ {
16
+ "components": [
17
+ {
18
+ "components": [
19
+ {
20
+ "internalType": "address",
21
+ "name": "sourceToken",
22
+ "type": "address"
23
+ },
24
+ {
25
+ "internalType": "address",
26
+ "name": "targetToken",
27
+ "type": "address"
28
+ },
29
+ {
30
+ "internalType": "uint256",
31
+ "name": "amount",
32
+ "type": "uint256"
33
+ }
34
+ ],
35
+ "internalType": "struct Variables.TokenInfo[]",
36
+ "name": "supply",
37
+ "type": "tuple[]"
38
+ },
39
+ {
40
+ "components": [
41
+ {
42
+ "internalType": "address",
43
+ "name": "sourceToken",
44
+ "type": "address"
45
+ },
46
+ {
47
+ "internalType": "address",
48
+ "name": "targetToken",
49
+ "type": "address"
50
+ },
51
+ {
52
+ "internalType": "uint256",
53
+ "name": "amount",
54
+ "type": "uint256"
55
+ }
56
+ ],
57
+ "internalType": "struct Variables.TokenInfo[]",
58
+ "name": "withdraw",
59
+ "type": "tuple[]"
60
+ }
61
+ ],
62
+ "internalType": "struct Variables.Position",
63
+ "name": "position",
64
+ "type": "tuple"
65
+ },
66
+ {
67
+ "internalType": "address",
68
+ "name": "liquidityContract",
69
+ "type": "address"
70
+ },
71
+ {
72
+ "internalType": "bool",
73
+ "name": "isSupply",
74
+ "type": "bool"
75
+ },
76
+ {
77
+ "internalType": "bool",
78
+ "name": "isTargetToken",
79
+ "type": "bool"
80
+ }
81
+ ],
82
+ "name": "checkLiquidity",
83
+ "outputs": [
84
+ {
85
+ "components": [
86
+ {
87
+ "internalType": "bool",
88
+ "name": "isOk",
89
+ "type": "bool"
90
+ },
91
+ {
92
+ "components": [
93
+ {
94
+ "internalType": "address",
95
+ "name": "token",
96
+ "type": "address"
97
+ },
98
+ {
99
+ "internalType": "uint256",
100
+ "name": "liquidityAvailable",
101
+ "type": "uint256"
102
+ },
103
+ {
104
+ "internalType": "uint256",
105
+ "name": "liquidityShort",
106
+ "type": "uint256"
107
+ }
108
+ ],
109
+ "internalType": "struct Helpers.LiquidityData[]",
110
+ "name": "supply",
111
+ "type": "tuple[]"
112
+ },
113
+ {
114
+ "components": [
115
+ {
116
+ "internalType": "address",
117
+ "name": "token",
118
+ "type": "address"
119
+ },
120
+ {
121
+ "internalType": "uint256",
122
+ "name": "liquidityAvailable",
123
+ "type": "uint256"
124
+ },
125
+ {
126
+ "internalType": "uint256",
127
+ "name": "liquidityShort",
128
+ "type": "uint256"
129
+ }
130
+ ],
131
+ "internalType": "struct Helpers.LiquidityData[]",
132
+ "name": "withdraw",
133
+ "type": "tuple[]"
134
+ }
135
+ ],
136
+ "internalType": "struct Helpers.PositionData",
137
+ "name": "p",
138
+ "type": "tuple"
139
+ }
140
+ ],
141
+ "stateMutability": "view",
142
+ "type": "function"
143
+ },
144
+ {
145
+ "inputs": [
146
+ {
147
+ "internalType": "address[]",
148
+ "name": "tokens",
149
+ "type": "address[]"
150
+ },
151
+ {
152
+ "internalType": "address",
153
+ "name": "liquidityContract",
154
+ "type": "address"
155
+ }
156
+ ],
157
+ "name": "getLiquidity",
158
+ "outputs": [
159
+ {
160
+ "components": [
161
+ {
162
+ "internalType": "address",
163
+ "name": "token",
164
+ "type": "address"
165
+ },
166
+ {
167
+ "internalType": "uint256",
168
+ "name": "liquidityAvailable",
169
+ "type": "uint256"
170
+ },
171
+ {
172
+ "internalType": "uint256",
173
+ "name": "liquidityShort",
174
+ "type": "uint256"
175
+ }
176
+ ],
177
+ "internalType": "struct Helpers.LiquidityData[]",
178
+ "name": "l",
179
+ "type": "tuple[]"
180
+ }
181
+ ],
182
+ "stateMutability": "view",
183
+ "type": "function"
184
+ },
185
+ {
186
+ "inputs": [],
187
+ "name": "nativeToken",
188
+ "outputs": [
189
+ {
190
+ "internalType": "address",
191
+ "name": "",
192
+ "type": "address"
193
+ }
194
+ ],
195
+ "stateMutability": "view",
196
+ "type": "function"
197
+ },
198
+ {
199
+ "inputs": [],
200
+ "name": "wnativeToken",
201
+ "outputs": [
202
+ {
203
+ "internalType": "address",
204
+ "name": "",
205
+ "type": "address"
206
+ }
207
+ ],
208
+ "stateMutability": "view",
209
+ "type": "function"
210
+ }
211
+ ]
package/src/abi/index.ts CHANGED
@@ -3,6 +3,9 @@ import erc20 from "./erc20.json";
3
3
  import interopX from "./interopX.json";
4
4
  import { connectors } from "./connectors";
5
5
  import instList from "./instList.json";
6
+ import balanceResolver from "./balanceResolver.json";
7
+ import aaveV2Resolver from "./aaveV2Resolver.json";
8
+ import aaveV3Resolver from "./aaveV3Resolver.json";
6
9
 
7
10
  export default {
8
11
  gnosisSafe,
@@ -10,4 +13,7 @@ export default {
10
13
  interopX,
11
14
  connectors,
12
15
  instList,
16
+ balanceResolver,
17
+ aaveV2Resolver,
18
+ aaveV3Resolver,
13
19
  };
@@ -1,3 +1,14 @@
1
+ export type NetworkAddresses = {
2
+ gnosisSafe: string
3
+ multisend: string
4
+ interopX: string
5
+ dsaAddress: string
6
+ instList: string
7
+ aaveV2Resolver: string
8
+ aaveV3Resolver: string
9
+ balanceResolver: string
10
+ }
11
+
1
12
  export const addresses = {
2
13
  137: {
3
14
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
@@ -5,6 +16,9 @@ export const addresses = {
5
16
  interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
6
17
  dsaAddress: '0x9Fbd453a8e7a158510fBae5D9935958507cf4b19',
7
18
  instList: "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556",
19
+ aaveV2Resolver: "0x0731c1d0154C2bE74d50e2083Df10aa531AAbb10",
20
+ aaveV3Resolver: "0x1bD311bd5aD4DCfE18bCb55d42F0a3c714E2bfDe",
21
+ balanceResolver: "0xecc3991846bB21717B95A593Fd86C5930A491F95",
8
22
  },
9
23
  43114: {
10
24
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
@@ -12,5 +26,8 @@ export const addresses = {
12
26
  interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
13
27
  dsaAddress: '0x995e67a652d2be45a8bff438b3dfac66dfff1c46',
14
28
  instList: "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687",
29
+ aaveV2Resolver: "0x7C5C59944263311a1e350E3B871B0d1d8E9A513E",
30
+ aaveV3Resolver: "0xB0862d7dB941698A0A92F8dF6672F4B56A5F5b02",
31
+ balanceResolver: "0xD45dFA34cEeAB567208041331F5ed9916C23b1E8",
15
32
  }
16
- } as Record<number, { gnosisSafe: string, multisend: string, interopX: string, dsaAddress: string, instList: string }>
33
+ } as Record<number, NetworkAddresses>
@@ -0,0 +1,5 @@
1
+ export const capPerChain = {
2
+ "1": 100_000_000,
3
+ "137": 100_000_000,
4
+ "43114": 100_000_000,
5
+ };
@@ -1,3 +1,5 @@
1
1
  export * from './addresses';
2
2
  export * from './tokens';
3
3
  export * from './blockConfirmations';
4
+ export * from './wrappedNativeToken';
5
+ export * from './capPerChain';
@@ -1,48 +1,48 @@
1
1
  export const tokens = {
2
- // 1: [
3
- // {
4
- // aliases: ['eth'],
5
- // symbol: "ETH",
6
- // name: "Ethereum",
7
- // address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
8
- // decimals: 18,
9
- // },
10
- // {
11
- // aliases: ['weth'],
12
- // symbol: "WETH",
13
- // name: "Wrapped Ethereum",
14
- // address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
15
- // decimals: 18,
16
- // },
17
- // {
18
- // aliases: ['dai'],
19
- // symbol: "DAI",
20
- // name: "DAI Stable",
21
- // address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
22
- // decimals: 18,
23
- // },
24
- // {
25
- // aliases: ['usdc'],
26
- // symbol: "USDC",
27
- // name: "USD Coin",
28
- // address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
29
- // decimals: 6,
30
- // },
31
- // {
32
- // aliases: ['usdt'],
33
- // symbol: "USDT",
34
- // name: "Tether USD Coin",
35
- // address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
36
- // decimals: 6,
37
- // },
38
- // {
39
- // aliases: ['wbtc'],
40
- // symbol: "WBTC",
41
- // name: "Wrapped BTC",
42
- // address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
43
- // decimals: 8,
44
- // },
45
- // ],
2
+ 1: [
3
+ {
4
+ aliases: ['eth'],
5
+ symbol: "ETH",
6
+ name: "Ethereum",
7
+ address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
8
+ decimals: 18,
9
+ },
10
+ {
11
+ aliases: ['weth'],
12
+ symbol: "WETH",
13
+ name: "Wrapped Ethereum",
14
+ address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
15
+ decimals: 18,
16
+ },
17
+ {
18
+ aliases: ['dai'],
19
+ symbol: "DAI",
20
+ name: "DAI Stable",
21
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
22
+ decimals: 18,
23
+ },
24
+ {
25
+ aliases: ['usdc'],
26
+ symbol: "USDC",
27
+ name: "USD Coin",
28
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
29
+ decimals: 6,
30
+ },
31
+ {
32
+ aliases: ['usdt'],
33
+ symbol: "USDT",
34
+ name: "Tether USD Coin",
35
+ address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
36
+ decimals: 6,
37
+ },
38
+ {
39
+ aliases: ['wbtc'],
40
+ symbol: "WBTC",
41
+ name: "Wrapped BTC",
42
+ address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
43
+ decimals: 8,
44
+ },
45
+ ],
46
46
  137: [
47
47
  {
48
48
  aliases: ['eth', 'weth'],
@@ -0,0 +1,5 @@
1
+ export const wrappedNativeToken = {
2
+ "1": '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
3
+ "137": '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
4
+ "43114": '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7'
5
+ };
@@ -0,0 +1 @@
1
+ import "./prices"
@@ -0,0 +1,12 @@
1
+ import { Prices } from "@/services";
2
+ import cron from "node-cron";
3
+
4
+ Prices.fetch().catch(console.log);
5
+
6
+ cron.schedule(`* * * * *`, async () => {
7
+ try {
8
+ await Prices.fetch();
9
+ } catch (error) {
10
+ console.log("Prices: ", error.message);
11
+ }
12
+ });
@@ -143,7 +143,7 @@ Transaction.init(
143
143
  type: DataTypes.DATE,
144
144
  defaultValue: Date.now(),
145
145
  },
146
- sourceDelayUntil: DataTypes.STRING,
146
+ sourceDelayUntil: DataTypes.DATE,
147
147
 
148
148
  targetChainId: DataTypes.NUMBER,
149
149
  targetDsaId: DataTypes.STRING,
@@ -1,3 +1,9 @@
1
+ export class UnsupportedChaindIdError extends Error {
2
+ constructor(chainId: any) {
3
+ super(`Unsupported chainId: ${chainId}`);
4
+ }
5
+ }
6
+
1
7
  export class LiquidityError extends Error {
2
8
  constructor(message?: string) {
3
9
  super(message || "Not enough liquidity");
@@ -10,4 +16,11 @@ export class InvalidChaindIdError extends Error {
10
16
  super(message || "Invalid chain id");
11
17
  Object.setPrototypeOf(this, new.target.prototype);
12
18
  }
19
+ }
20
+
21
+ export class LowLiquidityError extends Error {
22
+ constructor(message?: string) {
23
+ super(message || "Low liquidity");
24
+ Object.setPrototypeOf(this, new.target.prototype);
25
+ }
13
26
  }
@@ -2,12 +2,15 @@ import abi from "@/abi";
2
2
  import config from "@/config";
3
3
  import { addresses } from "@/constants";
4
4
  import { Transaction } from "@/db";
5
- import { InteropX } from "@/typechain";
5
+ import { JsonRpcRetryProvider } from "@/providers";
6
+ import { AaveV2Resolver, InstList, InteropX } from "@/typechain";
6
7
  import { ChainId } from "@/types";
7
8
  import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
8
9
  import { ethers } from "ethers";
9
10
  import { MetaTransaction, OperationType } from "ethers-multisend";
10
11
 
12
+ const safeUserRatioGap = "800000000000000000"
13
+
11
14
  export default async function (transaction: Transaction) {
12
15
  const transactions: MetaTransaction[] = [];
13
16
  const logs: any[] = [];
@@ -25,13 +28,20 @@ export default async function (transaction: Transaction) {
25
28
  metadata,
26
29
  } = transaction.submitEvent;
27
30
 
28
- const sourceChainProvider = new ethers.providers.JsonRpcProvider(
31
+ const sourceChainProvider = new JsonRpcRetryProvider(
29
32
  getRpcProviderUrl(sourceChainId as ChainId)
30
33
  );
31
34
  const sourceWallet = new ethers.Wallet(
32
35
  config.privateKey,
33
36
  sourceChainProvider
34
37
  );
38
+ const targetChainProvider = new JsonRpcRetryProvider(
39
+ getRpcProviderUrl(targetChainId as ChainId)
40
+ );
41
+ const targetWallet = new ethers.Wallet(
42
+ config.privateKey,
43
+ targetChainProvider
44
+ );
35
45
  const dsaAddress = addresses[sourceChainId].dsaAddress;
36
46
  const sourceUserAddress =
37
47
  Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
@@ -42,6 +52,52 @@ export default async function (transaction: Transaction) {
42
52
  sourceWallet
43
53
  );
44
54
 
55
+ const sourceResolverContract = getContract<AaveV2Resolver>(
56
+ addresses[sourceChainId].aaveV2Resolver,
57
+ abi.aaveV2Resolver,
58
+ sourceWallet
59
+ );
60
+
61
+ const targetResolverContract = getContract<AaveV2Resolver>(
62
+ addresses[targetChainId].aaveV2Resolver,
63
+ abi.aaveV2Resolver,
64
+ targetWallet
65
+ );
66
+
67
+ const sourceAavePosition = await sourceResolverContract.checkAavePosition(sourceUserAddress, position, safeUserRatioGap, false)
68
+
69
+ const userSourceAaveIsOk = sourceAavePosition.isOk;
70
+
71
+ if (!userSourceAaveIsOk) {
72
+ throw new Error("Source chain aave position is not safe to migrate.");
73
+ }
74
+
75
+ const targetInstListContract = getContract<InstList>(
76
+ addresses[targetChainId].instList,
77
+ abi.instList,
78
+ targetChainProvider,
79
+ );
80
+
81
+ const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId)
82
+
83
+ const targetAavePosition = await targetResolverContract
84
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true)
85
+
86
+ const userTargetAaveIsOk = targetAavePosition.isOk;
87
+
88
+ if (!userTargetAaveIsOk) {
89
+ throw new Error("Target chain aave position will not be safe after migration.");
90
+ }
91
+
92
+ const targetAavePositionWithFee = await targetResolverContract
93
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
94
+
95
+ const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
96
+
97
+ if (!userTargetAaveIsOkWithFee) {
98
+ throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
99
+ }
100
+
45
101
  const sourceSpells: any[] = [];
46
102
  const commonSpells: any[] = [];
47
103
 
@@ -2,13 +2,15 @@ import abi from "@/abi";
2
2
  import config from "@/config";
3
3
  import { addresses } from "@/constants";
4
4
  import { Transaction } from "@/db";
5
- import { InteropX } from "@/typechain";
5
+ import { JsonRpcRetryProvider } from "@/providers";
6
+ import { AaveV2Resolver, InteropX } from "@/typechain";
6
7
  import { InstList } from "@/typechain/InstList";
7
8
  import { ChainId } from "@/types";
8
9
  import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
9
10
  import { ethers } from "ethers";
10
11
  import { MetaTransaction, OperationType } from "ethers-multisend";
11
12
 
13
+ const safeUserRatioGap = "800000000000000000"
12
14
 
13
15
  export default async function (transaction: Transaction) {
14
16
  const transactions: MetaTransaction[] = [];
@@ -27,7 +29,7 @@ export default async function (transaction: Transaction) {
27
29
  metadata,
28
30
  } = transaction.validateEvent;
29
31
 
30
- const targetChainProvider = new ethers.providers.JsonRpcProvider(
32
+ const targetChainProvider = new JsonRpcRetryProvider(
31
33
  getRpcProviderUrl(targetChainId as ChainId)
32
34
  );
33
35
  const targetWallet = new ethers.Wallet(
@@ -35,6 +37,11 @@ export default async function (transaction: Transaction) {
35
37
  targetChainProvider
36
38
  );
37
39
 
40
+ const targetResolverContract = getContract<AaveV2Resolver>(
41
+ addresses[targetChainId].aaveV2Resolver,
42
+ abi.aaveV2Resolver,
43
+ targetWallet
44
+ );
38
45
 
39
46
  const targetInstListContract = getContract<InstList>(
40
47
  addresses[targetChainId].instList,
@@ -43,6 +50,26 @@ export default async function (transaction: Transaction) {
43
50
  );
44
51
 
45
52
  const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId)
53
+
54
+
55
+ const targetAavePosition = await targetResolverContract
56
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true)
57
+
58
+ const userTargetAaveIsOk = targetAavePosition.isOk;
59
+
60
+ if (!userTargetAaveIsOk) {
61
+ throw new Error("Target chain aave position will not be safe after migration.");
62
+ }
63
+
64
+ const targetAavePositionWithFee = await targetResolverContract
65
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
66
+
67
+ const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
68
+
69
+ if (!userTargetAaveIsOkWithFee) {
70
+ throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
71
+ }
72
+
46
73
  const dsaAddress = addresses[targetChainId].dsaAddress;
47
74
  const interopAddress = addresses[targetChainId].interopX;
48
75
  const contract = getContract<InteropX>(
@@ -0,0 +1,9 @@
1
+ import { Transaction } from "@/db";
2
+ import source from "./source";
3
+ import target from "./target";
4
+
5
+
6
+
7
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
8
+ return type === 'source' ? source(transaction) : target(transaction);
9
+ }