@instadapp/interop-x 0.0.0-dev.cb34b2e → 0.0.0-dev.d060c38

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.cb34b2e",
3
+ "version": "0.0.0-dev.d060c38",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -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: spellData.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 = 'cb34b2e';
16
+ const GIT_SHORT_HASH = 'd060c38';
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})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.cb34b2e",
3
+ "version": "0.0.0-dev.d060c38",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -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
+ }
@@ -0,0 +1,119 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { JsonRpcRetryProvider } from "@/providers";
6
+ import { InteropX } from "@/typechain";
7
+ import { ChainId } from "@/types";
8
+ import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
9
+ import { ethers } from "ethers";
10
+ import { MetaTransaction, OperationType } from "ethers-multisend";
11
+
12
+ export default async function (transaction: Transaction) {
13
+ const transactions: MetaTransaction[] = [];
14
+ const logs: any[] = [];
15
+
16
+ const {
17
+ position,
18
+ actionId,
19
+ actionIdHashHash,
20
+ sourceSender,
21
+ sourceDsaId,
22
+ targetDsaId,
23
+ sourceChainId,
24
+ targetChainId,
25
+ vnonce,
26
+ metadata,
27
+ } = transaction.submitEvent;
28
+
29
+ const sourceChainProvider = new JsonRpcRetryProvider(
30
+ getRpcProviderUrl(sourceChainId as ChainId)
31
+ );
32
+ const sourceWallet = new ethers.Wallet(
33
+ config.privateKey,
34
+ sourceChainProvider
35
+ );
36
+ const dsaAddress = addresses[sourceChainId].dsaAddress;
37
+ const sourceUserAddress =
38
+ Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
39
+ const interopAddress = addresses[sourceChainId].interopX;
40
+ const contract = getContract<InteropX>(
41
+ interopAddress,
42
+ abi.interopX,
43
+ sourceWallet
44
+ );
45
+
46
+ const sourceSpells: any[] = [];
47
+ const commonSpells: any[] = [];
48
+
49
+ for (const withdraw of position.withdraw) {
50
+ let spellData = {
51
+ connector: "AAVE-V3-A",
52
+ method: "payback",
53
+ args: [withdraw.sourceToken, withdraw.amount, "2", "0", "0"],
54
+ };
55
+
56
+ sourceSpells.push({
57
+ connector: spellData.connector,
58
+ data: encodeConnectorMethod(spellData),
59
+ });
60
+
61
+ let spellDataBasicWithdraw = {
62
+ connector: "BASIC-A",
63
+ method: "withdraw",
64
+ args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
65
+ };
66
+
67
+ commonSpells.push({
68
+ connector: spellDataBasicWithdraw.connector,
69
+ data: encodeConnectorMethod(spellDataBasicWithdraw),
70
+ });
71
+ }
72
+
73
+ for (const supply of position.supply) {
74
+ let spellDataWithdraw = {
75
+ connector: "AAVE-V3-A",
76
+ method: "withdraw",
77
+ args: [supply.sourceToken, supply.amount, "0", "0"],
78
+ };
79
+
80
+ sourceSpells.push({
81
+ connector: spellDataWithdraw.connector,
82
+ data: encodeConnectorMethod(spellDataWithdraw),
83
+ });
84
+
85
+ let spellDataBasicWithdraw = {
86
+ connector: "BASIC-A",
87
+ method: "withdraw",
88
+ args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
89
+ };
90
+
91
+ sourceSpells.push({
92
+ connector: spellDataBasicWithdraw.connector,
93
+ data: encodeConnectorMethod(spellDataBasicWithdraw),
94
+ });
95
+ }
96
+
97
+ const { data } = await contract.populateTransaction.sourceAction(
98
+ sourceSpells,
99
+ commonSpells,
100
+ position,
101
+ actionId,
102
+ sourceSender,
103
+ sourceDsaId,
104
+ targetDsaId,
105
+ sourceChainId,
106
+ targetChainId,
107
+ vnonce,
108
+ metadata
109
+ );
110
+
111
+ transactions.push({
112
+ to: interopAddress,
113
+ data: data!,
114
+ value: "0",
115
+ operation: OperationType.Call,
116
+ });
117
+
118
+ return { transactions, logs };
119
+ }
@@ -0,0 +1,142 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { JsonRpcRetryProvider } from "@/providers";
6
+ import { InteropX } from "@/typechain";
7
+ import { InstList } from "@/typechain/InstList";
8
+ import { ChainId } from "@/types";
9
+ import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
10
+ import { ethers } from "ethers";
11
+ import { MetaTransaction, OperationType } from "ethers-multisend";
12
+
13
+
14
+ export default async function (transaction: Transaction) {
15
+ const transactions: MetaTransaction[] = [];
16
+ const logs: any[] = [];
17
+
18
+ const {
19
+ sourceSpells,
20
+ position,
21
+ actionId,
22
+ sourceSender,
23
+ sourceDsaId,
24
+ targetDsaId,
25
+ sourceChainId,
26
+ targetChainId,
27
+ vnonce,
28
+ metadata,
29
+ } = transaction.validateEvent;
30
+
31
+ const targetChainProvider = new JsonRpcRetryProvider(
32
+ getRpcProviderUrl(targetChainId as ChainId)
33
+ );
34
+ const targetWallet = new ethers.Wallet(
35
+ config.privateKey,
36
+ targetChainProvider
37
+ );
38
+
39
+
40
+ const targetInstListContract = getContract<InstList>(
41
+ addresses[targetChainId].instList,
42
+ abi.instList,
43
+ targetChainProvider,
44
+ );
45
+
46
+ const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId)
47
+ const dsaAddress = addresses[targetChainId].dsaAddress;
48
+ const interopAddress = addresses[targetChainId].interopX;
49
+ const contract = getContract<InteropX>(
50
+ interopAddress,
51
+ abi.interopX,
52
+ targetWallet
53
+ );
54
+
55
+ const targetSpells: any[] = [];
56
+ const commonSpells: any[] = [];
57
+
58
+ for (const supplyToken of position.supply) {
59
+ let spellData = {
60
+ connector: "AAVE-V3-A",
61
+ method: "deposit",
62
+ args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
63
+ };
64
+
65
+ targetSpells.push({
66
+ connector: spellData.connector,
67
+ data: encodeConnectorMethod(spellData),
68
+ });
69
+
70
+ let spellDataBasicWithdraw = {
71
+ connector: "BASIC-A",
72
+ method: "withdraw",
73
+ args: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
74
+ };
75
+
76
+ commonSpells.push({
77
+ connector: spellDataBasicWithdraw.connector,
78
+ data: encodeConnectorMethod(spellDataBasicWithdraw),
79
+ });
80
+ }
81
+
82
+ for (const withdrawToken of position.withdraw) {
83
+
84
+ let spellData = {
85
+ connector: "AAVE-V3-A",
86
+ method: "borrow",
87
+ args: [
88
+ withdrawToken.targetToken,
89
+ withdrawToken.amount,
90
+ "2",
91
+ "0",
92
+ "0",
93
+ ],
94
+ };
95
+
96
+ targetSpells.push({
97
+ connector: spellData.connector,
98
+ data: encodeConnectorMethod(spellData),
99
+ });
100
+
101
+ let spellData2 = {
102
+ connector: "BASIC-A",
103
+ method: "withdraw",
104
+ args: [
105
+ withdrawToken.targetToken,
106
+ withdrawToken.amount,
107
+ dsaAddress,
108
+ "0",
109
+ "0",
110
+ ],
111
+ };
112
+
113
+ targetSpells.push({
114
+ connector: spellData.connector,
115
+ data: encodeConnectorMethod(spellData2),
116
+ });
117
+ }
118
+
119
+ const { data } = await contract.populateTransaction.targetAction(
120
+ sourceSpells,
121
+ targetSpells,
122
+ commonSpells,
123
+ position,
124
+ actionId,
125
+ sourceSender,
126
+ sourceDsaId,
127
+ targetDsaId,
128
+ sourceChainId,
129
+ targetChainId,
130
+ vnonce,
131
+ metadata
132
+ );
133
+
134
+ transactions.push({
135
+ to: interopAddress,
136
+ data: data!,
137
+ value: "0",
138
+ operation: OperationType.Call,
139
+ });
140
+
141
+ return { transactions, logs }
142
+ }
@@ -1,5 +1,7 @@
1
1
  import aaveV2 from "./aaveV2"
2
+ import aaveV3 from "./aaveV3"
2
3
 
3
4
  export default {
4
5
  'A:AAVE-V2:AAVE-V2': aaveV2,
6
+ 'A:AAVE-V3:AAVE-V3': aaveV3,
5
7
  }