@instadapp/interop-x 0.0.0-dev.e916c22 → 0.0.0-dev.ea4acf6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/dist/package.json +9 -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/api/index.js +7 -0
  7. package/dist/src/constants/addresses.js +6 -0
  8. package/dist/src/constants/capPerChain.js +8 -0
  9. package/dist/src/constants/index.js +2 -0
  10. package/dist/src/constants/tokens.js +44 -44
  11. package/dist/src/constants/wrappedNativeToken.js +8 -0
  12. package/dist/src/crons/index.js +3 -0
  13. package/dist/src/crons/prices.js +16 -0
  14. package/dist/src/db/models/transaction.js +1 -1
  15. package/dist/src/errors/index.js +30 -0
  16. package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
  17. package/dist/src/gnosis/actions/aaveV2/target.js +18 -4
  18. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  19. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  20. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  21. package/dist/src/gnosis/actions/index.js +2 -0
  22. package/dist/src/index.js +2 -1
  23. package/dist/src/providers/index.js +17 -0
  24. package/dist/src/providers/retry-provider.js +45 -0
  25. package/dist/src/services/Prices.js +74 -0
  26. package/dist/src/services/index.js +8 -0
  27. package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +108 -14
  28. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +30 -10
  29. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +3 -2
  30. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +3 -2
  31. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +3 -2
  32. package/dist/src/tasks/index.js +3 -4
  33. package/dist/src/typechain/AaveV2Resolver.js +2 -0
  34. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  35. package/dist/src/typechain/BalanceResolver.js +2 -0
  36. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  37. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  38. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  39. package/dist/src/typechain/factories/index.js +7 -1
  40. package/dist/src/typechain/index.js +7 -1
  41. package/dist/src/utils/async.js +18 -0
  42. package/dist/src/utils/dsa.js +36 -0
  43. package/dist/src/utils/formatting.js +67 -0
  44. package/dist/src/utils/gnosis.js +87 -0
  45. package/dist/src/utils/http.js +10 -0
  46. package/dist/src/utils/index.js +22 -220
  47. package/dist/src/utils/interop.js +16 -0
  48. package/dist/src/utils/tokens.js +22 -0
  49. package/dist/src/utils/validate.js +111 -0
  50. package/dist/src/utils/web3.js +93 -0
  51. package/package.json +9 -2
  52. package/src/abi/aaveV2Resolver.json +832 -0
  53. package/src/abi/aaveV3Resolver.json +628 -0
  54. package/src/abi/balanceResolver.json +211 -0
  55. package/src/abi/index.ts +6 -0
  56. package/src/api/index.ts +8 -0
  57. package/src/constants/addresses.ts +18 -1
  58. package/src/constants/capPerChain.ts +5 -0
  59. package/src/constants/index.ts +2 -0
  60. package/src/constants/tokens.ts +44 -44
  61. package/src/constants/wrappedNativeToken.ts +5 -0
  62. package/src/crons/index.ts +1 -0
  63. package/src/crons/prices.ts +12 -0
  64. package/src/db/models/transaction.ts +1 -1
  65. package/src/errors/index.ts +26 -0
  66. package/src/gnosis/actions/aaveV2/source.ts +56 -3
  67. package/src/gnosis/actions/aaveV2/target.ts +30 -11
  68. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  69. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  70. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  71. package/src/gnosis/actions/index.ts +2 -0
  72. package/src/index.ts +1 -0
  73. package/src/providers/index.ts +1 -0
  74. package/src/providers/retry-provider.ts +51 -0
  75. package/src/services/Prices.ts +89 -0
  76. package/src/services/index.ts +1 -0
  77. package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +135 -20
  78. package/src/tasks/InteropX/ProcessValidateEvents.ts +42 -19
  79. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +5 -6
  80. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +6 -7
  81. package/src/tasks/InteropX/SyncLogValidateEvents.ts +6 -7
  82. package/src/tasks/index.ts +3 -4
  83. package/src/typechain/AaveV2Resolver.ts +1017 -0
  84. package/src/typechain/AaveV3Resolver.ts +935 -0
  85. package/src/typechain/BalanceResolver.ts +266 -0
  86. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  87. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  88. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  89. package/src/typechain/factories/index.ts +3 -0
  90. package/src/typechain/index.ts +6 -0
  91. package/src/utils/async.ts +22 -0
  92. package/src/utils/dsa.ts +56 -0
  93. package/src/utils/formatting.ts +68 -0
  94. package/src/utils/gnosis.ts +166 -0
  95. package/src/utils/http.ts +6 -0
  96. package/src/utils/index.ts +9 -365
  97. package/src/utils/interop.ts +28 -0
  98. package/src/utils/tokens.ts +21 -0
  99. package/src/utils/validate.ts +179 -0
  100. package/src/utils/web3.ts +132 -0
@@ -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
  };
package/src/api/index.ts CHANGED
@@ -26,6 +26,14 @@ export const startApiServer = async () => {
26
26
  })
27
27
  })
28
28
 
29
+ server.get('/transactions/:transaction', async (req) => {
30
+ return await Transaction.findOne({
31
+ where: {
32
+ transactionHash: (req.params as any).transaction
33
+ }
34
+ })
35
+ })
36
+
29
37
  await server.listen(PORT, HOST)
30
38
 
31
39
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
@@ -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,
@@ -0,0 +1,26 @@
1
+ export class UnsupportedChaindIdError extends Error {
2
+ constructor(chainId: any) {
3
+ super(`Unsupported chainId: ${chainId}`);
4
+ }
5
+ }
6
+
7
+ export class LiquidityError extends Error {
8
+ constructor(message?: string) {
9
+ super(message || "Not enough liquidity");
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ }
12
+ }
13
+
14
+ export class InvalidChaindIdError extends Error {
15
+ constructor(message?: string) {
16
+ super(message || "Invalid chain id");
17
+ Object.setPrototypeOf(this, new.target.prototype);
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
+ }
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, InteropX } from "@/typechain";
6
7
  import { ChainId } from "@/types";
7
- import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
8
+ import { encodeConnectorMethod, getContract, getDsaAccountAddress, 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,49 @@ 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
+
68
+ const sourceDsaAddress = await getDsaAccountAddress({ dsaId: sourceDsaId, chainId: sourceChainId, provider: sourceChainProvider });
69
+
70
+ const sourceAavePosition = await sourceResolverContract.checkAavePosition(sourceDsaAddress, position, safeUserRatioGap, false)
71
+
72
+ const userSourceAaveIsOk = sourceAavePosition.isOk;
73
+
74
+ if (!userSourceAaveIsOk) {
75
+ throw new Error("Source chain aave position is not safe to migrate.");
76
+ }
77
+
78
+ const targetDsaAddress = await getDsaAccountAddress({ dsaId: targetDsaId, chainId: targetChainId, provider: targetChainProvider });
79
+
80
+ const targetAavePosition = await targetResolverContract
81
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true)
82
+
83
+ const userTargetAaveIsOk = targetAavePosition.isOk;
84
+
85
+ if (!userTargetAaveIsOk) {
86
+ throw new Error("Target chain aave position will not be safe after migration.");
87
+ }
88
+
89
+ const targetAavePositionWithFee = await targetResolverContract
90
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
91
+
92
+ const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
93
+
94
+ if (!userTargetAaveIsOkWithFee) {
95
+ throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
96
+ }
97
+
45
98
  const sourceSpells: any[] = [];
46
99
  const commonSpells: any[] = [];
47
100
 
@@ -2,13 +2,14 @@ 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";
6
- import { InstList } from "@/typechain/InstList";
5
+ import { JsonRpcRetryProvider } from "@/providers";
6
+ import { AaveV2Resolver, InteropX } from "@/typechain";
7
7
  import { ChainId } from "@/types";
8
- import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
8
+ import { encodeConnectorMethod, getContract, getDsaAccountAddress, getRpcProviderUrl } from "@/utils";
9
9
  import { ethers } from "ethers";
10
10
  import { MetaTransaction, OperationType } from "ethers-multisend";
11
11
 
12
+ const safeUserRatioGap = "800000000000000000"
12
13
 
13
14
  export default async function (transaction: Transaction) {
14
15
  const transactions: MetaTransaction[] = [];
@@ -27,7 +28,7 @@ export default async function (transaction: Transaction) {
27
28
  metadata,
28
29
  } = transaction.validateEvent;
29
30
 
30
- const targetChainProvider = new ethers.providers.JsonRpcProvider(
31
+ const targetChainProvider = new JsonRpcRetryProvider(
31
32
  getRpcProviderUrl(targetChainId as ChainId)
32
33
  );
33
34
  const targetWallet = new ethers.Wallet(
@@ -35,14 +36,32 @@ export default async function (transaction: Transaction) {
35
36
  targetChainProvider
36
37
  );
37
38
 
38
-
39
- const targetInstListContract = getContract<InstList>(
40
- addresses[targetChainId].instList,
41
- abi.instList,
42
- targetChainProvider,
39
+ const targetResolverContract = getContract<AaveV2Resolver>(
40
+ addresses[targetChainId].aaveV2Resolver,
41
+ abi.aaveV2Resolver,
42
+ targetWallet
43
43
  );
44
44
 
45
- const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId)
45
+ const targetDsaAddress = await getDsaAccountAddress({ dsaId: targetDsaId, chainId: targetChainId, provider: targetChainProvider });
46
+
47
+ const targetAavePosition = await targetResolverContract
48
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true)
49
+
50
+ const userTargetAaveIsOk = targetAavePosition.isOk;
51
+
52
+ if (!userTargetAaveIsOk) {
53
+ throw new Error("Target chain aave position will not be safe after migration.");
54
+ }
55
+
56
+ const targetAavePositionWithFee = await targetResolverContract
57
+ .checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
58
+
59
+ const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
60
+
61
+ if (!userTargetAaveIsOkWithFee) {
62
+ throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
63
+ }
64
+
46
65
  const dsaAddress = addresses[targetChainId].dsaAddress;
47
66
  const interopAddress = addresses[targetChainId].interopX;
48
67
  const contract = getContract<InteropX>(
@@ -110,7 +129,7 @@ export default async function (transaction: Transaction) {
110
129
  };
111
130
 
112
131
  targetSpells.push({
113
- connector: spellData.connector,
132
+ connector: spellData2.connector,
114
133
  data: encodeConnectorMethod(spellData2),
115
134
  });
116
135
  }
@@ -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
+ }