@instadapp/interop-x 0.0.0-dev.32db40c → 0.0.0-dev.373a918

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 (33) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/abi/index.js +2 -0
  3. package/dist/src/abi/instList.json +232 -0
  4. package/dist/src/constants/addresses.js +4 -2
  5. package/dist/src/db/models/transaction.js +11 -7
  6. package/dist/src/gnosis/actions/aaveV2/source.js +4 -4
  7. package/dist/src/gnosis/actions/aaveV2/target.js +78 -0
  8. package/dist/src/index.js +1 -1
  9. package/dist/src/tasks/InteropX/ProcessSubmitSubmitEvents.js +1 -2
  10. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +183 -0
  11. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +1 -0
  12. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
  13. package/dist/src/tasks/index.js +6 -0
  14. package/dist/src/typechain/InstList.js +2 -0
  15. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  16. package/dist/src/typechain/factories/index.js +3 -1
  17. package/dist/src/typechain/index.js +3 -1
  18. package/package.json +1 -1
  19. package/src/abi/index.ts +2 -0
  20. package/src/abi/instList.json +232 -0
  21. package/src/constants/addresses.ts +5 -3
  22. package/src/db/models/transaction.ts +113 -80
  23. package/src/gnosis/actions/aaveV2/source.ts +4 -4
  24. package/src/gnosis/actions/aaveV2/target.ts +130 -2
  25. package/src/tasks/InteropX/ProcessSubmitSubmitEvents.ts +1 -2
  26. package/src/tasks/InteropX/ProcessValidateEvents.ts +274 -0
  27. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +1 -0
  28. package/src/tasks/InteropX/SyncLogValidateEvents.ts +152 -0
  29. package/src/tasks/index.ts +8 -0
  30. package/src/typechain/InstList.ts +402 -0
  31. package/src/typechain/factories/InstList__factory.ts +253 -0
  32. package/src/typechain/factories/index.ts +1 -0
  33. package/src/typechain/index.ts +2 -0
@@ -1,74 +1,100 @@
1
- import { sequelize } from '@/db/sequelize'
2
- import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
1
+ import { sequelize } from "@/db/sequelize";
2
+ import {
3
+ CreationOptional,
4
+ InferAttributes,
5
+ InferCreationAttributes,
6
+ Model,
7
+ DataTypes,
8
+ } from "sequelize";
3
9
 
4
10
  export interface IPositionTokenInfo {
5
- amount: string;
6
- sourceToken: string;
7
- targetToken: string;
11
+ amount: string;
12
+ sourceToken: string;
13
+ targetToken: string;
8
14
  }
9
15
 
10
16
  export interface IPosition {
11
- supply: IPositionTokenInfo[];
12
- withdraw: IPositionTokenInfo[];
17
+ supply: IPositionTokenInfo[];
18
+ withdraw: IPositionTokenInfo[];
13
19
  }
14
20
 
15
- export class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
16
- declare id: CreationOptional<number>;
17
-
18
- declare transactionHash: string;
19
- declare vnonce: string;
20
- declare actionId: string;
21
- declare sourceSender: string;
22
-
23
- declare submitChainId: number;
24
- declare submitTransactionHash: string;
25
- declare submitBlockNumber: number;
26
- declare submitCreatedAt: Date;
27
-
28
- declare sourceChainId: number;
29
- declare sourceDsaId: string;
30
- declare sourceTransactionHash: CreationOptional<string>;
31
- declare sourceBlockNumber: CreationOptional<number>;
32
- declare sourceStatus: CreationOptional<string>;
33
- declare sourceErrors: CreationOptional<string[]>;
34
- declare sourceLogs: CreationOptional<any[]>;
35
- declare sourceCreatedAt: CreationOptional<Date>;
36
- declare sourceDelayUntil: CreationOptional<Date>;
37
-
38
- declare targetChainId: number;
39
- declare targetDsaId: string;
40
- declare targetTransactionHash: CreationOptional<string>;
41
- declare targetBlockNumber: CreationOptional<number>;
42
- declare targetStatus: CreationOptional<string>;
43
- declare targetErrors: CreationOptional<string[]>;
44
- declare targetLogs: CreationOptional<any[]>;
45
- declare targetCreatedAt: CreationOptional<Date>;
46
- declare targetDelayUntil: CreationOptional<Date>;
47
-
48
- declare submitEvent: {
49
- position: IPosition;
50
- actionId: string;
51
- actionIdHashHash: string;
52
- sourceSender: string;
53
- sourceDsaId: string;
54
- targetDsaId: string;
55
- sourceChainId: number;
56
- targetChainId: number;
57
- vnonce: string;
58
- metadata: string;
59
- };
60
-
61
- declare status: CreationOptional<string>;
62
-
63
- declare createdAt: CreationOptional<Date>;
64
- declare updatedAt: CreationOptional<Date>;
21
+ export class Transaction extends Model<
22
+ InferAttributes<Transaction>,
23
+ InferCreationAttributes<Transaction>
24
+ > {
25
+ declare id: CreationOptional<number>;
26
+
27
+ declare transactionHash: string;
28
+ declare vnonce: string;
29
+ declare actionId: string;
30
+ declare sourceSender: string;
31
+
32
+ declare submitChainId: number;
33
+ declare submitTransactionHash: string;
34
+ declare submitBlockNumber: number;
35
+ declare submitCreatedAt: Date;
36
+
37
+ declare sourceChainId: number;
38
+ declare sourceDsaId: string;
39
+ declare sourceTransactionHash: CreationOptional<string>;
40
+ declare sourceBlockNumber: CreationOptional<number>;
41
+ declare sourceStatus: CreationOptional<string>;
42
+ declare sourceErrors: CreationOptional<string[]>;
43
+ declare sourceLogs: CreationOptional<any[]>;
44
+ declare sourceCreatedAt: CreationOptional<Date>;
45
+ declare sourceDelayUntil: CreationOptional<Date>;
46
+
47
+ declare targetChainId: number;
48
+ declare targetDsaId: string;
49
+ declare targetTransactionHash: CreationOptional<string>;
50
+ declare targetBlockNumber: CreationOptional<number>;
51
+ declare targetStatus: CreationOptional<string>;
52
+ declare targetErrors: CreationOptional<string[]>;
53
+ declare targetLogs: CreationOptional<any[]>;
54
+ declare targetCreatedAt: CreationOptional<Date>;
55
+ declare targetDelayUntil: CreationOptional<Date>;
56
+
57
+ declare submitEvent: {
58
+ position: IPosition;
59
+ actionId: string;
60
+ actionIdHashHash: string;
61
+ actionIdHash: string;
62
+ sourceSender: string;
63
+ sourceDsaId: string;
64
+ targetDsaId: string;
65
+ sourceChainId: number;
66
+ targetChainId: number;
67
+ vnonce: string;
68
+ metadata: string;
69
+ };
70
+
71
+ declare validateEvent: CreationOptional<{
72
+ sourceSpells: Array<{ connector: string; data: string }>;
73
+ position: IPosition;
74
+ actionId: string;
75
+ actionIdHashHash: string;
76
+ actionIdHash: string;
77
+ sourceSender: string;
78
+ sourceDsaId: string;
79
+ targetDsaId: string;
80
+ sourceChainId: number;
81
+ targetChainId: number;
82
+ vnonce: string;
83
+ metadata: string;
84
+ }>;
85
+
86
+ declare status: CreationOptional<string>;
87
+
88
+ declare createdAt: CreationOptional<Date>;
89
+ declare updatedAt: CreationOptional<Date>;
65
90
  }
66
91
 
67
- Transaction.init({
92
+ Transaction.init(
93
+ {
68
94
  id: {
69
- type: DataTypes.INTEGER,
70
- autoIncrement: true,
71
- primaryKey: true
95
+ type: DataTypes.INTEGER,
96
+ autoIncrement: true,
97
+ primaryKey: true,
72
98
  },
73
99
 
74
100
  transactionHash: DataTypes.STRING,
@@ -86,20 +112,20 @@ Transaction.init({
86
112
  sourceTransactionHash: DataTypes.STRING,
87
113
  sourceBlockNumber: DataTypes.NUMBER,
88
114
  sourceStatus: {
89
- type: DataTypes.STRING,
90
- defaultValue: 'pending'
115
+ type: DataTypes.STRING,
116
+ defaultValue: "pending",
91
117
  },
92
118
  sourceErrors: {
93
- type: DataTypes.JSON,
94
- // defaultValue: [],
119
+ type: DataTypes.JSON,
120
+ // defaultValue: [],
95
121
  },
96
122
  sourceLogs: {
97
- type: DataTypes.JSON,
98
- // defaultValue: [],
123
+ type: DataTypes.JSON,
124
+ // defaultValue: [],
99
125
  },
100
126
  sourceCreatedAt: {
101
- type: DataTypes.DATE,
102
- defaultValue: Date.now()
127
+ type: DataTypes.DATE,
128
+ defaultValue: Date.now(),
103
129
  },
104
130
  sourceDelayUntil: DataTypes.STRING,
105
131
 
@@ -108,29 +134,36 @@ Transaction.init({
108
134
  targetTransactionHash: DataTypes.STRING,
109
135
  targetBlockNumber: DataTypes.NUMBER,
110
136
  targetStatus: {
111
- type: DataTypes.STRING,
112
- defaultValue: 'pending'
137
+ type: DataTypes.STRING,
138
+ defaultValue: "pending",
113
139
  },
114
140
  targetErrors: {
115
- type: DataTypes.JSON,
116
- // defaultValue: [],
141
+ type: DataTypes.JSON,
142
+ // defaultValue: [],
117
143
  },
118
144
  targetLogs: {
119
- type: DataTypes.JSON,
120
- // defaultValue: [],
145
+ type: DataTypes.JSON,
146
+ // defaultValue: [],
121
147
  },
122
148
  targetCreatedAt: DataTypes.DATE,
123
149
  targetDelayUntil: DataTypes.DATE,
124
150
 
125
151
  submitEvent: {
126
- type: DataTypes.JSON,
127
- allowNull: false
152
+ type: DataTypes.JSON,
153
+ allowNull: false,
154
+ },
155
+
156
+ validateEvent: {
157
+ type: DataTypes.JSON,
158
+ allowNull: true,
128
159
  },
129
160
 
130
161
  status: {
131
- type: DataTypes.STRING,
132
- defaultValue: 'pending'
162
+ type: DataTypes.STRING,
163
+ defaultValue: "pending",
133
164
  },
134
165
  createdAt: DataTypes.DATE,
135
166
  updatedAt: DataTypes.DATE,
136
- }, { sequelize, tableName: 'transactions' });
167
+ },
168
+ { sequelize, tableName: "transactions" }
169
+ );
@@ -53,7 +53,7 @@ export default async function (transaction: Transaction) {
53
53
  };
54
54
 
55
55
  sourceSpells.push({
56
- connector: spellData.method,
56
+ connector: spellData.connector,
57
57
  data: encodeConnectorMethod(spellData),
58
58
  });
59
59
 
@@ -64,7 +64,7 @@ export default async function (transaction: Transaction) {
64
64
  };
65
65
 
66
66
  commonSpells.push({
67
- connector: spellDataBasicWithdraw.method,
67
+ connector: spellDataBasicWithdraw.connector,
68
68
  data: encodeConnectorMethod(spellDataBasicWithdraw),
69
69
  });
70
70
  }
@@ -77,7 +77,7 @@ export default async function (transaction: Transaction) {
77
77
  };
78
78
 
79
79
  sourceSpells.push({
80
- connector: spellDataWithdraw.method,
80
+ connector: spellDataWithdraw.connector,
81
81
  data: encodeConnectorMethod(spellDataWithdraw),
82
82
  });
83
83
 
@@ -88,7 +88,7 @@ export default async function (transaction: Transaction) {
88
88
  };
89
89
 
90
90
  sourceSpells.push({
91
- connector: spellDataBasicWithdraw.method,
91
+ connector: spellDataBasicWithdraw.connector,
92
92
  data: encodeConnectorMethod(spellDataBasicWithdraw),
93
93
  });
94
94
  }
@@ -1,6 +1,12 @@
1
-
2
-
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses } from "@/constants";
3
4
  import { Transaction } from "@/db";
5
+ import { InteropX } from "@/typechain";
6
+ import { InstList } from "@/typechain/InstList";
7
+ import { ChainId } from "@/types";
8
+ import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
9
+ import { ethers } from "ethers";
4
10
  import { MetaTransaction, OperationType } from "ethers-multisend";
5
11
 
6
12
 
@@ -8,6 +14,128 @@ export default async function (transaction: Transaction) {
8
14
  const transactions: MetaTransaction[] = [];
9
15
  const logs: any[] = [];
10
16
 
17
+ const {
18
+ sourceSpells,
19
+ position,
20
+ actionId,
21
+ sourceSender,
22
+ sourceDsaId,
23
+ targetDsaId,
24
+ sourceChainId,
25
+ targetChainId,
26
+ vnonce,
27
+ metadata,
28
+ } = transaction.validateEvent;
29
+
30
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(
31
+ getRpcProviderUrl(targetChainId as ChainId)
32
+ );
33
+ const targetWallet = new ethers.Wallet(
34
+ config.privateKey,
35
+ targetChainProvider
36
+ );
37
+
38
+
39
+ const targetInstListContract = getContract<InstList>(
40
+ addresses[targetChainId].instList,
41
+ abi.instList,
42
+ targetChainProvider,
43
+ );
44
+
45
+ const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId)
46
+ const dsaAddress = addresses[targetChainId].dsaAddress;
47
+ const interopAddress = addresses[targetChainId].interopX;
48
+ const contract = getContract<InteropX>(
49
+ interopAddress,
50
+ abi.interopX,
51
+ targetWallet
52
+ );
53
+
54
+ const targetSpells: any[] = [];
55
+ const commonSpells: any[] = [];
56
+
57
+ for (const supplyToken of position.supply) {
58
+ let spellData = {
59
+ connector: "AAVE-V2-A",
60
+ method: "deposit",
61
+ args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
62
+ };
63
+
64
+ targetSpells.push({
65
+ connector: spellData.connector,
66
+ data: encodeConnectorMethod(spellData),
67
+ });
68
+
69
+ let spellDataBasicWithdraw = {
70
+ connector: "BASIC-A",
71
+ method: "withdraw",
72
+ args: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
73
+ };
74
+
75
+ commonSpells.push({
76
+ connector: spellDataBasicWithdraw.connector,
77
+ data: encodeConnectorMethod(spellDataBasicWithdraw),
78
+ });
79
+ }
80
+
81
+ for (const withdrawToken of position.withdraw) {
82
+
83
+ let spellData = {
84
+ connector: "AAVE-V2-A",
85
+ method: "borrow",
86
+ args: [
87
+ withdrawToken.targetToken,
88
+ withdrawToken.amount,
89
+ "2",
90
+ "0",
91
+ "0",
92
+ ],
93
+ };
94
+
95
+ targetSpells.push({
96
+ connector: spellData.connector,
97
+ data: encodeConnectorMethod(spellData),
98
+ });
99
+
100
+ let spellData2 = {
101
+ connector: "BASIC-A",
102
+ method: "withdraw",
103
+ args: [
104
+ withdrawToken.targetToken,
105
+ withdrawToken.amount,
106
+ dsaAddress,
107
+ "0",
108
+ "0",
109
+ ],
110
+ };
111
+
112
+ targetSpells.push({
113
+ connector: spellData.connector,
114
+ data: encodeConnectorMethod(spellData2),
115
+ });
116
+ }
117
+
118
+ const { data } = await contract.populateTransaction.targetAction(
119
+ sourceSpells,
120
+ targetSpells,
121
+ commonSpells,
122
+ position,
123
+ actionId,
124
+ sourceSender,
125
+ sourceDsaId,
126
+ targetDsaId,
127
+ sourceChainId,
128
+ targetChainId,
129
+ vnonce,
130
+ metadata
131
+ );
132
+
133
+ transactions.push({
134
+ to: interopAddress,
135
+ data: data!,
136
+ value: "0",
137
+ operation: OperationType.Call,
138
+ });
11
139
 
12
140
  return { transactions, logs }
13
141
  }
@@ -207,7 +207,7 @@ class ProcessSubmitSubmitEvents extends BaseTask {
207
207
  from: this.sourceWallet.address,
208
208
  to: this.sourceGnosisContract.address,
209
209
  gasPrice: gasPrice.mul(120).div(100),
210
- gasLimit: gasLimit.mul(120).div(100),
210
+ gasLimit: 5_000_000,//gasLimit.mul(120).div(100),
211
211
  data: txData,
212
212
  });
213
213
 
@@ -237,7 +237,6 @@ class ProcessSubmitSubmitEvents extends BaseTask {
237
237
  if (txSent.blockNumber)
238
238
  transaction.sourceBlockNumber = txSent.blockNumber;
239
239
  transaction.sourceTransactionHash = txSent.hash;
240
- transaction.sourceTransactionHash = txSent.hash;
241
240
  transaction.status = "failed";
242
241
  await transaction.save();
243
242
  }