@instadapp/interop-x 0.0.0-dev.c279cb8 → 0.0.0-dev.c696e38

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