@instadapp/interop-x 0.0.0-dev.5953f3d → 0.0.0-dev.5a90c8d

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 (92) hide show
  1. package/dist/package.json +8 -1
  2. package/dist/src/abi/aaveV2Resolver.json +832 -0
  3. package/dist/src/abi/balanceResolver.json +211 -0
  4. package/dist/src/abi/index.js +6 -0
  5. package/dist/src/abi/instList.json +232 -0
  6. package/dist/src/api/index.js +7 -0
  7. package/dist/src/constants/addresses.js +8 -2
  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 +15 -7
  15. package/dist/src/errors/index.js +30 -0
  16. package/dist/src/gnosis/actions/aaveV2/source.js +17 -5
  17. package/dist/src/gnosis/actions/aaveV2/target.js +79 -0
  18. package/dist/src/index.js +2 -1
  19. package/dist/src/providers/index.js +17 -0
  20. package/dist/src/providers/retry-provider.js +45 -0
  21. package/dist/src/services/Prices.js +74 -0
  22. package/dist/src/services/index.js +8 -0
  23. package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +84 -7
  24. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +185 -0
  25. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
  26. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +3 -1
  27. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +106 -0
  28. package/dist/src/tasks/index.js +13 -5
  29. package/dist/src/typechain/AaveV2Resolver.js +2 -0
  30. package/dist/src/typechain/BalanceResolver.js +2 -0
  31. package/dist/src/typechain/InstList.js +2 -0
  32. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  33. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  34. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  35. package/dist/src/typechain/factories/index.js +7 -1
  36. package/dist/src/typechain/index.js +7 -1
  37. package/dist/src/utils/async.js +18 -0
  38. package/dist/src/utils/dsa.js +24 -0
  39. package/dist/src/utils/formatting.js +67 -0
  40. package/dist/src/utils/gnosis.js +62 -0
  41. package/dist/src/utils/http.js +10 -0
  42. package/dist/src/utils/index.js +22 -220
  43. package/dist/src/utils/interop.js +16 -0
  44. package/dist/src/utils/tokens.js +22 -0
  45. package/dist/src/utils/validate.js +111 -0
  46. package/dist/src/utils/web3.js +93 -0
  47. package/package.json +8 -1
  48. package/src/abi/aaveV2Resolver.json +832 -0
  49. package/src/abi/balanceResolver.json +211 -0
  50. package/src/abi/index.ts +6 -0
  51. package/src/abi/instList.json +232 -0
  52. package/src/api/index.ts +8 -0
  53. package/src/constants/addresses.ts +19 -3
  54. package/src/constants/capPerChain.ts +5 -0
  55. package/src/constants/index.ts +2 -0
  56. package/src/constants/tokens.ts +44 -44
  57. package/src/constants/wrappedNativeToken.ts +5 -0
  58. package/src/crons/index.ts +1 -0
  59. package/src/crons/prices.ts +12 -0
  60. package/src/db/models/transaction.ts +134 -80
  61. package/src/errors/index.ts +26 -0
  62. package/src/gnosis/actions/aaveV2/source.ts +21 -6
  63. package/src/gnosis/actions/aaveV2/target.ts +131 -2
  64. package/src/index.ts +1 -0
  65. package/src/providers/index.ts +1 -0
  66. package/src/providers/retry-provider.ts +51 -0
  67. package/src/services/Prices.ts +89 -0
  68. package/src/services/index.ts +1 -0
  69. package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +104 -11
  70. package/src/tasks/InteropX/ProcessValidateEvents.ts +272 -0
  71. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
  72. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +6 -6
  73. package/src/tasks/InteropX/SyncLogValidateEvents.ts +151 -0
  74. package/src/tasks/index.ts +16 -5
  75. package/src/typechain/AaveV2Resolver.ts +1017 -0
  76. package/src/typechain/BalanceResolver.ts +266 -0
  77. package/src/typechain/InstList.ts +402 -0
  78. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  79. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  80. package/src/typechain/factories/InstList__factory.ts +253 -0
  81. package/src/typechain/factories/index.ts +3 -0
  82. package/src/typechain/index.ts +6 -0
  83. package/src/utils/async.ts +22 -0
  84. package/src/utils/dsa.ts +30 -0
  85. package/src/utils/formatting.ts +68 -0
  86. package/src/utils/gnosis.ts +123 -0
  87. package/src/utils/http.ts +6 -0
  88. package/src/utils/index.ts +9 -365
  89. package/src/utils/interop.ts +28 -0
  90. package/src/utils/tokens.ts +21 -0
  91. package/src/utils/validate.ts +174 -0
  92. package/src/utils/web3.ts +132 -0
@@ -0,0 +1,151 @@
1
+ import { BaseTask } from "../BaseTask";
2
+ import Logger from "@/logger";
3
+ import { ethers } from "ethers";
4
+ import abi from "@/abi";
5
+ import { Transaction } from "@/db";
6
+ import {
7
+ generateInteropTransactionHash,
8
+ getContract,
9
+ getRpcProviderUrl,
10
+ } from "@/utils";
11
+ import { addresses } from "@/constants";
12
+ import { ChainId } from "@/types";
13
+ import config from "@/config";
14
+ import { InteropX } from "@/typechain";
15
+ import { Op } from "sequelize";
16
+ import { JsonRpcRetryProvider } from "@/providers";
17
+
18
+ export default class SyncLogValidateEvents extends BaseTask {
19
+ contractAddress: string;
20
+ provider: JsonRpcRetryProvider;
21
+ contract: InteropX;
22
+ chainId: ChainId;
23
+
24
+ constructor({ chainId }: { chainId: ChainId }) {
25
+ super({
26
+ logger: new Logger("InteropX::SyncLogValidateEvents"),
27
+ });
28
+ this.chainId = chainId;
29
+ }
30
+
31
+ async pollHandler() {
32
+ const currentBlock = await this.provider.getBlockNumber();
33
+
34
+ const events = await this.contract.queryFilter(
35
+ this.contract.filters.LogValidate(),
36
+ currentBlock - 2000,
37
+ currentBlock
38
+ );
39
+
40
+ let processedEvents = 0;
41
+
42
+ for (const event of events) {
43
+ try {
44
+ if (!event.args) {
45
+ continue;
46
+ }
47
+
48
+ const {
49
+ sourceSpells,
50
+ position,
51
+ actionId,
52
+ actionIdHash,
53
+ sourceSender,
54
+ sourceDsaId,
55
+ targetDsaId,
56
+ sourceChainId,
57
+ targetChainId,
58
+ vnonce,
59
+ metadata,
60
+ } = event.args;
61
+
62
+ const uniqueIdentifier = {
63
+ actionId,
64
+ vnonce: vnonce.toString(),
65
+ sourceSender: sourceSender.toString(),
66
+ sourceChainId: sourceChainId.toNumber(),
67
+ targetChainId: targetChainId.toNumber(),
68
+ sourceDsaId: sourceDsaId.toString(),
69
+ targetDsaId: targetDsaId.toString(),
70
+ };
71
+
72
+ let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
73
+
74
+ const transaction = await Transaction.findOne({
75
+ where: {
76
+ transactionHash,
77
+ validateEvent: { [Op.eq]: null },
78
+ },
79
+ });
80
+
81
+ if (!transaction) {
82
+ continue;
83
+ }
84
+
85
+ if (transaction.sourceStatus != "success") {
86
+ transaction.sourceStatus = "success";
87
+ }
88
+
89
+ if (!transaction.sourceCreatedAt) {
90
+ transaction.sourceCreatedAt = new Date();
91
+ }
92
+
93
+ transaction.sourceTransactionHash = event.transactionHash;
94
+ transaction.sourceBlockNumber = event.blockNumber;
95
+ transaction.sourceLogs = [];
96
+ transaction.validateEvent = {
97
+ actionId,
98
+ actionIdHashHash: actionIdHash,
99
+ actionIdHash,
100
+ vnonce: vnonce.toString(),
101
+ sourceSpells: sourceSpells.map(({ connector, data }) => ({
102
+ connector,
103
+ data,
104
+ })),
105
+ position: {
106
+ withdraw: position.withdraw.map((v) => ({
107
+ sourceToken: v.sourceToken,
108
+ targetToken: v.targetToken,
109
+ amount: v.amount.toString(),
110
+ })),
111
+ supply: position.supply.map((v) => ({
112
+ sourceToken: v.sourceToken,
113
+ targetToken: v.targetToken,
114
+ amount: v.amount.toString(),
115
+ })),
116
+ },
117
+ sourceChainId: sourceChainId.toNumber(),
118
+ targetChainId: targetChainId.toNumber(),
119
+ sourceSender,
120
+ sourceDsaId: sourceDsaId.toString(),
121
+ targetDsaId: targetDsaId.toString(),
122
+ metadata,
123
+ }
124
+ await transaction.save();
125
+
126
+ this.logger.info(`New InteropX tranaction: ${transactionHash} `);
127
+ } catch (error) {
128
+ this.logger.error(error);
129
+ }
130
+ }
131
+
132
+ if (processedEvents > 0)
133
+ this.logger.info(`${processedEvents} events processed`);
134
+ }
135
+
136
+ async start(): Promise<void> {
137
+ this.contractAddress = addresses[this.chainId].interopX;
138
+
139
+ this.provider = new JsonRpcRetryProvider(
140
+ getRpcProviderUrl(this.chainId)
141
+ );
142
+
143
+ this.contract = getContract<InteropX>(
144
+ this.contractAddress,
145
+ abi.interopX,
146
+ new ethers.Wallet(config.privateKey!, this.provider)
147
+ );
148
+
149
+ await super.start();
150
+ }
151
+ }
@@ -6,20 +6,31 @@ import SyncTransactionStatusTask from "./Transactions/SyncTransactionStatusTask"
6
6
  import AutoUpdateTask from "./AutoUpdateTask";
7
7
 
8
8
  import SyncLogSubmitEvents from "./InteropX/SyncLogSubmitEvents";
9
- import ProcessSubmitSubmitEvents from "./InteropX/ProcessSubmitSubmitEvents";
9
+ import ProcessSubmitEvents from "./InteropX/ProcessSubmitEvents";
10
+ import SyncLogValidateEvents from "./InteropX/SyncLogValidateEvents";
11
+ import ProcessValidateEvents from "./InteropX/ProcessValidateEvents";
12
+ import SyncLogExecuteEvents from "./InteropX/SyncLogExecuteEvents";
10
13
 
11
14
  export class Tasks {
12
15
 
13
16
  tasks: BaseTask[] = [
14
- // new SyncTransactionStatusTask(),
15
17
  new AutoUpdateTask(),
16
18
 
17
19
  // InteropX
18
20
  new SyncLogSubmitEvents({ chainId: 137 }),
19
21
  new SyncLogSubmitEvents({ chainId: 43114 }),
20
22
 
21
- new ProcessSubmitSubmitEvents({ chainId: 137 }),
22
- new ProcessSubmitSubmitEvents({ chainId: 43114 }),
23
+ new ProcessSubmitEvents({ chainId: 137 }),
24
+ new ProcessSubmitEvents({ chainId: 43114 }),
25
+
26
+ new SyncLogValidateEvents({ chainId: 137 }),
27
+ new SyncLogValidateEvents({ chainId: 43114 }),
28
+
29
+ new ProcessValidateEvents({ chainId: 137 }),
30
+ new ProcessValidateEvents({ chainId: 43114 }),
31
+
32
+ new SyncLogExecuteEvents({ targetChainId: 137 }),
33
+ new SyncLogExecuteEvents({ targetChainId: 43114 }),
23
34
 
24
35
  new SyncTransactionStatusTask(),
25
36
  ];
@@ -28,7 +39,7 @@ export class Tasks {
28
39
  for (const task of this.tasks) {
29
40
  try {
30
41
  task.start();
31
- await wait(1000)
42
+ await wait(300)
32
43
  } catch (error) {
33
44
  console.error(`Error starting task: ${task.constructor.name}`);
34
45
  }