@instadapp/interop-x 0.0.0-dev.ef7acff → 0.0.0-dev.f45bd03
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +8 -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/index.js +6 -0
- package/dist/src/constants/addresses.js +6 -0
- 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 +1 -1
- package/dist/src/errors/index.js +14 -1
- package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
- package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
- 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/ProcessSubmitEvents.js +92 -12
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
- 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/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/index.js +7 -1
- package/dist/src/typechain/index.js +7 -1
- package/dist/src/utils/formatting.js +51 -1
- package/dist/src/utils/gnosis.js +42 -17
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/tokens.js +22 -0
- package/dist/src/utils/validate.js +85 -1
- package/dist/src/utils/web3.js +2 -1
- package/package.json +8 -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/index.ts +6 -0
- package/src/constants/addresses.ts +18 -1
- 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 +1 -1
- package/src/errors/index.ts +13 -0
- package/src/gnosis/actions/aaveV2/source.ts +58 -2
- package/src/gnosis/actions/aaveV2/target.ts +29 -2
- 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/ProcessSubmitEvents.ts +120 -17
- package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -14
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
- package/src/typechain/AaveV2Resolver.ts +1017 -0
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/BalanceResolver.ts +266 -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/index.ts +3 -0
- package/src/typechain/index.ts +6 -0
- package/src/utils/formatting.ts +53 -0
- package/src/utils/gnosis.ts +75 -32
- package/src/utils/index.ts +1 -0
- package/src/utils/tokens.ts +21 -0
- package/src/utils/validate.ts +149 -2
- 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/dist/src/abi/index.js
CHANGED
@@ -8,10 +8,16 @@ const erc20_json_1 = __importDefault(require("./erc20.json"));
|
|
8
8
|
const interopX_json_1 = __importDefault(require("./interopX.json"));
|
9
9
|
const connectors_1 = require("./connectors");
|
10
10
|
const instList_json_1 = __importDefault(require("./instList.json"));
|
11
|
+
const balanceResolver_json_1 = __importDefault(require("./balanceResolver.json"));
|
12
|
+
const aaveV2Resolver_json_1 = __importDefault(require("./aaveV2Resolver.json"));
|
13
|
+
const aaveV3Resolver_json_1 = __importDefault(require("./aaveV3Resolver.json"));
|
11
14
|
exports.default = {
|
12
15
|
gnosisSafe: gnosisSafe_json_1.default,
|
13
16
|
erc20: erc20_json_1.default,
|
14
17
|
interopX: interopX_json_1.default,
|
15
18
|
connectors: connectors_1.connectors,
|
16
19
|
instList: instList_json_1.default,
|
20
|
+
balanceResolver: balanceResolver_json_1.default,
|
21
|
+
aaveV2Resolver: aaveV2Resolver_json_1.default,
|
22
|
+
aaveV3Resolver: aaveV3Resolver_json_1.default,
|
17
23
|
};
|
@@ -8,6 +8,9 @@ exports.addresses = {
|
|
8
8
|
interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
|
9
9
|
dsaAddress: '0x9Fbd453a8e7a158510fBae5D9935958507cf4b19',
|
10
10
|
instList: "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556",
|
11
|
+
aaveV2Resolver: "0x0731c1d0154C2bE74d50e2083Df10aa531AAbb10",
|
12
|
+
aaveV3Resolver: "0x1bD311bd5aD4DCfE18bCb55d42F0a3c714E2bfDe",
|
13
|
+
balanceResolver: "0xecc3991846bB21717B95A593Fd86C5930A491F95",
|
11
14
|
},
|
12
15
|
43114: {
|
13
16
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
@@ -15,5 +18,8 @@ exports.addresses = {
|
|
15
18
|
interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
|
16
19
|
dsaAddress: '0x995e67a652d2be45a8bff438b3dfac66dfff1c46',
|
17
20
|
instList: "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687",
|
21
|
+
aaveV2Resolver: "0x7C5C59944263311a1e350E3B871B0d1d8E9A513E",
|
22
|
+
aaveV3Resolver: "0xB0862d7dB941698A0A92F8dF6672F4B56A5F5b02",
|
23
|
+
balanceResolver: "0xD45dFA34cEeAB567208041331F5ed9916C23b1E8",
|
18
24
|
}
|
19
25
|
};
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./addresses"), exports);
|
18
18
|
__exportStar(require("./tokens"), exports);
|
19
19
|
__exportStar(require("./blockConfirmations"), exports);
|
20
|
+
__exportStar(require("./wrappedNativeToken"), exports);
|
21
|
+
__exportStar(require("./capPerChain"), exports);
|
@@ -2,50 +2,50 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.tokens = void 0;
|
4
4
|
exports.tokens = {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
5
|
+
1: [
|
6
|
+
{
|
7
|
+
aliases: ['eth'],
|
8
|
+
symbol: "ETH",
|
9
|
+
name: "Ethereum",
|
10
|
+
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
11
|
+
decimals: 18,
|
12
|
+
},
|
13
|
+
{
|
14
|
+
aliases: ['weth'],
|
15
|
+
symbol: "WETH",
|
16
|
+
name: "Wrapped Ethereum",
|
17
|
+
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
18
|
+
decimals: 18,
|
19
|
+
},
|
20
|
+
{
|
21
|
+
aliases: ['dai'],
|
22
|
+
symbol: "DAI",
|
23
|
+
name: "DAI Stable",
|
24
|
+
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
25
|
+
decimals: 18,
|
26
|
+
},
|
27
|
+
{
|
28
|
+
aliases: ['usdc'],
|
29
|
+
symbol: "USDC",
|
30
|
+
name: "USD Coin",
|
31
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
32
|
+
decimals: 6,
|
33
|
+
},
|
34
|
+
{
|
35
|
+
aliases: ['usdt'],
|
36
|
+
symbol: "USDT",
|
37
|
+
name: "Tether USD Coin",
|
38
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
39
|
+
decimals: 6,
|
40
|
+
},
|
41
|
+
{
|
42
|
+
aliases: ['wbtc'],
|
43
|
+
symbol: "WBTC",
|
44
|
+
name: "Wrapped BTC",
|
45
|
+
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
46
|
+
decimals: 8,
|
47
|
+
},
|
48
|
+
],
|
49
49
|
137: [
|
50
50
|
{
|
51
51
|
aliases: ['eth', 'weth'],
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.wrappedNativeToken = void 0;
|
4
|
+
exports.wrappedNativeToken = {
|
5
|
+
"1": '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
6
|
+
"137": '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
|
7
|
+
"43114": '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7'
|
8
|
+
};
|
@@ -0,0 +1,16 @@
|
|
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 services_1 = require("@/services");
|
7
|
+
const node_cron_1 = __importDefault(require("node-cron"));
|
8
|
+
services_1.Prices.fetch().catch(console.log);
|
9
|
+
node_cron_1.default.schedule(`* * * * *`, async () => {
|
10
|
+
try {
|
11
|
+
await services_1.Prices.fetch();
|
12
|
+
}
|
13
|
+
catch (error) {
|
14
|
+
console.log("Prices: ", error.message);
|
15
|
+
}
|
16
|
+
});
|
@@ -40,7 +40,7 @@ Transaction.init({
|
|
40
40
|
type: sequelize_2.DataTypes.DATE,
|
41
41
|
defaultValue: Date.now(),
|
42
42
|
},
|
43
|
-
sourceDelayUntil: sequelize_2.DataTypes.
|
43
|
+
sourceDelayUntil: sequelize_2.DataTypes.DATE,
|
44
44
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
45
45
|
targetDsaId: sequelize_2.DataTypes.STRING,
|
46
46
|
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
package/dist/src/errors/index.js
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InvalidChaindIdError = exports.LiquidityError = void 0;
|
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;
|
4
10
|
class LiquidityError extends Error {
|
5
11
|
constructor(message) {
|
6
12
|
super(message || "Not enough liquidity");
|
@@ -15,3 +21,10 @@ class InvalidChaindIdError extends Error {
|
|
15
21
|
}
|
16
22
|
}
|
17
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 sourceAavePosition = await sourceResolverContract.checkAavePosition(sourceUserAddress, position, safeUserRatioGap, false);
|
29
|
+
const userSourceAaveIsOk = sourceAavePosition.isOk;
|
30
|
+
if (!userSourceAaveIsOk) {
|
31
|
+
throw new Error("Source chain aave position is not safe to migrate.");
|
32
|
+
}
|
33
|
+
const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
34
|
+
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
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);
|
18
21
|
const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
19
22
|
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
23
|
+
const targetAavePosition = await targetResolverContract
|
24
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
25
|
+
const userTargetAaveIsOk = targetAavePosition.isOk;
|
26
|
+
if (!userTargetAaveIsOk) {
|
27
|
+
throw new Error("Target chain aave position will not be safe after migration.");
|
28
|
+
}
|
29
|
+
const targetAavePositionWithFee = await targetResolverContract
|
30
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
31
|
+
const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
|
32
|
+
if (!userTargetAaveIsOkWithFee) {
|
33
|
+
throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
|
34
|
+
}
|
20
35
|
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
21
36
|
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
22
37
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
@@ -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;
|