@instadapp/interop-x 0.0.0-dev.6ea4ee5 → 0.0.0-dev.733ff78

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 (91) hide show
  1. package/bin/interop-x +1 -1
  2. package/dist/package.json +73 -0
  3. package/dist/{abi → src/abi}/erc20.json +0 -0
  4. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  5. package/dist/{abi → src/abi}/index.js +0 -0
  6. package/dist/{abi → src/abi}/interopBridgeToken.json +21 -9
  7. package/dist/{abi → src/abi}/interopXGateway.json +11 -11
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/{config → src/config}/index.js +11 -1
  10. package/dist/{constants → src/constants}/addresses.js +1 -9
  11. package/dist/{constants → src/constants}/index.js +1 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/{constants → src/constants}/tokens.js +0 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +0 -0
  16. package/dist/{db → src/db}/models/transaction.js +11 -1
  17. package/dist/{db → src/db}/sequelize.js +1 -1
  18. package/dist/src/gnosis/actions/deposit.js +48 -0
  19. package/dist/src/gnosis/actions/index.js +11 -0
  20. package/dist/src/gnosis/actions/withdraw.js +50 -0
  21. package/dist/src/gnosis/index.js +20 -0
  22. package/dist/src/index.js +133 -0
  23. package/dist/{logger → src/logger}/index.js +0 -0
  24. package/dist/{net → src/net}/index.js +0 -0
  25. package/dist/{net → src/net}/peer/index.js +8 -3
  26. package/dist/{net → src/net}/pool/index.js +32 -9
  27. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  28. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -12
  29. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  30. package/dist/{net → src/net}/protocol/index.js +51 -1
  31. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  32. package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
  33. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -0
  34. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
  35. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  36. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +164 -0
  37. package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +18 -23
  38. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  39. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  40. package/dist/src/tasks/index.js +55 -0
  41. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  42. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  43. package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
  44. package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
  45. package/dist/{typechain → src/typechain}/common.js +0 -0
  46. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  47. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  48. package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +23 -11
  49. package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +14 -14
  50. package/dist/{typechain → src/typechain}/factories/index.js +0 -0
  51. package/dist/{typechain → src/typechain}/index.js +0 -0
  52. package/dist/{types.js → src/types.js} +0 -0
  53. package/dist/{utils → src/utils}/index.js +62 -6
  54. package/package.json +12 -5
  55. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  56. package/src/abi/interopBridgeToken.json +21 -9
  57. package/src/abi/interopXGateway.json +11 -11
  58. package/src/api/index.ts +36 -0
  59. package/src/config/index.ts +11 -1
  60. package/src/constants/addresses.ts +1 -9
  61. package/src/constants/index.ts +1 -0
  62. package/src/constants/itokens.ts +10 -0
  63. package/src/db/models/transaction.ts +18 -4
  64. package/src/db/sequelize.ts +1 -1
  65. package/src/gnosis/actions/deposit.ts +63 -0
  66. package/src/gnosis/actions/index.ts +7 -0
  67. package/src/gnosis/actions/withdraw.ts +67 -0
  68. package/src/gnosis/index.ts +19 -0
  69. package/src/index.ts +99 -8
  70. package/src/net/peer/index.ts +9 -7
  71. package/src/net/pool/index.ts +41 -11
  72. package/src/net/protocol/dial/SignatureDialProtocol.ts +19 -13
  73. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  74. package/src/net/protocol/index.ts +67 -1
  75. package/src/tasks/AutoUpdateTask.ts +82 -0
  76. package/src/tasks/BaseTask.ts +14 -4
  77. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
  78. package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
  79. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  80. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
  81. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +25 -15
  82. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  83. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  84. package/src/tasks/index.ts +43 -2
  85. package/src/typechain/InteropBridgeToken.ts +23 -17
  86. package/src/typechain/InteropXGateway.ts +13 -13
  87. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  88. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  89. package/src/utils/index.ts +76 -7
  90. package/dist/index.js +0 -63
  91. package/dist/tasks/index.js +0 -27
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.http = void 0;
6
+ exports.getContract = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
7
7
  /**
8
8
  * @module util
9
9
  */
@@ -13,6 +13,16 @@ const constants_1 = require("@/constants");
13
13
  const ethers_1 = require("ethers");
14
14
  exports.http = axios_1.default.create();
15
15
  (0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
16
+ function shortenHash(hash, length = 4) {
17
+ if (!hash)
18
+ return;
19
+ if (hash.length < 12)
20
+ return hash;
21
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
22
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
23
+ return shortened;
24
+ }
25
+ exports.shortenHash = shortenHash;
16
26
  function short(buffer) {
17
27
  return buffer.toString('hex').slice(0, 8) + '...';
18
28
  }
@@ -56,11 +66,11 @@ exports.signGnosisSafeTx = signGnosisSafeTx;
56
66
  const getRpcProviderUrl = (chainId) => {
57
67
  switch (chainId) {
58
68
  case 1:
59
- return 'https://rpc.instadapp.io/mainnet';
69
+ return 'https://rpc.ankr.com/eth';
60
70
  case 137:
61
- return 'https://rpc.instadapp.io/polygon';
71
+ return 'https://rpc.ankr.com/polygon';
62
72
  case 43114:
63
- return 'https://rpc.instadapp.io/avalanche';
73
+ return 'https://rpc.ankr.com/avalanche';
64
74
  default:
65
75
  throw new Error(`Unknown chainId: ${chainId}`);
66
76
  }
@@ -92,10 +102,56 @@ const asyncCallWithTimeout = async (asyncPromise, timeout) => {
92
102
  exports.asyncCallWithTimeout = asyncCallWithTimeout;
93
103
  const generateInteropTransactionHash = (data) => {
94
104
  return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
95
- String(data.type),
96
- String(data.sourceTransactionHash),
105
+ String(data.action),
106
+ String(data.submitTransactionHash),
97
107
  String(data.sourceChainId),
98
108
  String(data.targetChainId),
99
109
  ]);
100
110
  };
101
111
  exports.generateInteropTransactionHash = generateInteropTransactionHash;
112
+ function getContract(address, contractInterface, signerOrProvider) {
113
+ if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
114
+ throw Error(`Invalid 'address' parameter '${address}'.`);
115
+ }
116
+ const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
117
+ // Make sure the contract properties is writable
118
+ const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
119
+ if (!desc || desc.writable !== true) {
120
+ return contract;
121
+ }
122
+ return new Proxy(contract, {
123
+ get(target, prop, receiver) {
124
+ const value = Reflect.get(target, prop, receiver);
125
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
126
+ return async (...args) => {
127
+ try {
128
+ return await value.bind(contract)(...args);
129
+ }
130
+ catch (error) {
131
+ throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`);
132
+ }
133
+ };
134
+ }
135
+ if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
136
+ const parentProp = String(prop);
137
+ return new Proxy(value, {
138
+ get(target, prop, receiver) {
139
+ const value = Reflect.get(target, prop, receiver);
140
+ if (typeof value === 'function') {
141
+ return async (...args) => {
142
+ try {
143
+ return await value.bind(contract)(...args);
144
+ }
145
+ catch (error) {
146
+ throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`);
147
+ }
148
+ };
149
+ }
150
+ }
151
+ });
152
+ }
153
+ return value;
154
+ },
155
+ });
156
+ }
157
+ exports.getContract = getContract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.6ea4ee5",
3
+ "version": "0.0.0-dev.733ff78",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -12,7 +12,8 @@
12
12
  "build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
13
13
  "dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
14
14
  "generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
15
- "prepublishOnly": "yarn build"
15
+ "prepublishOnly": "yarn build",
16
+ "postinstall": "patch-package"
16
17
  },
17
18
  "nodemonConfig": {
18
19
  "watch": [
@@ -23,15 +24,18 @@
23
24
  },
24
25
  "dependencies": {
25
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
+ "@fastify/cors": "^7.0.0",
28
+ "await-spawn": "^4.0.2",
26
29
  "axios": "^0.27.1",
27
30
  "axios-retry": "^3.2.4",
28
- "bignumber.js": "^9.0.2",
29
31
  "chalk": "4.1.2",
30
32
  "dotenv": "^16.0.0",
31
33
  "ethereumjs-util": "^7.1.4",
32
34
  "ethers": "^5.6.4",
33
35
  "ethers-multisend": "^2.1.1",
34
36
  "expand-home-dir": "^0.0.3",
37
+ "fastify": "^3.28.0",
38
+ "fs-extra": "^10.1.0",
35
39
  "libp2p": "^0.36.2",
36
40
  "libp2p-bootstrap": "^0.14.0",
37
41
  "libp2p-kad-dht": "^0.28.6",
@@ -43,12 +47,15 @@
43
47
  "libp2p-websockets": "^0.16.2",
44
48
  "luxon": "^2.3.2",
45
49
  "module-alias": "^2.2.2",
46
- "sequelize": "^6.19.0",
50
+ "patch-package": "^6.4.7",
51
+ "postinstall-postinstall": "^2.1.0",
52
+ "sequelize": "6.18.0",
47
53
  "sqlite3": "^5.0.5",
48
54
  "waait": "^1.0.5"
49
55
  },
50
56
  "bin": {
51
- "interop-node": "bin/interop-x"
57
+ "interop-x": "bin/interop-x",
58
+ "interopx": "bin/interop-x"
52
59
  },
53
60
  "devDependencies": {
54
61
  "@typechain/ethers-v5": "^10.0.0",
@@ -0,0 +1,13 @@
1
+ diff --git a/node_modules/@ethersproject/properties/lib/index.js b/node_modules/@ethersproject/properties/lib/index.js
2
+ index 41e0b52..4c7a9e3 100644
3
+ --- a/node_modules/@ethersproject/properties/lib/index.js
4
+ +++ b/node_modules/@ethersproject/properties/lib/index.js
5
+ @@ -44,7 +44,7 @@ function defineReadOnly(object, name, value) {
6
+ Object.defineProperty(object, name, {
7
+ enumerable: true,
8
+ value: value,
9
+ - writable: false,
10
+ + writable: true,
11
+ });
12
+ }
13
+ exports.defineReadOnly = defineReadOnly;
@@ -46,11 +46,17 @@
46
46
  "name": "amount",
47
47
  "type": "uint256"
48
48
  },
49
+ {
50
+ "indexed": false,
51
+ "internalType": "uint32",
52
+ "name": "sourceChainId",
53
+ "type": "uint32"
54
+ },
49
55
  {
50
56
  "indexed": true,
51
- "internalType": "uint256",
52
- "name": "chainId",
53
- "type": "uint256"
57
+ "internalType": "uint32",
58
+ "name": "targetChainId",
59
+ "type": "uint32"
54
60
  }
55
61
  ],
56
62
  "name": "Burn",
@@ -73,14 +79,20 @@
73
79
  },
74
80
  {
75
81
  "indexed": true,
76
- "internalType": "uint256",
77
- "name": "chainId",
78
- "type": "uint256"
82
+ "internalType": "uint32",
83
+ "name": "sourceChainId",
84
+ "type": "uint32"
85
+ },
86
+ {
87
+ "indexed": false,
88
+ "internalType": "uint32",
89
+ "name": "targetChainId",
90
+ "type": "uint32"
79
91
  },
80
92
  {
81
93
  "indexed": true,
82
94
  "internalType": "bytes32",
83
- "name": "transactionHash",
95
+ "name": "submitTransactionHash",
84
96
  "type": "bytes32"
85
97
  }
86
98
  ],
@@ -164,7 +176,7 @@
164
176
  "inputs": [
165
177
  { "internalType": "address", "name": "to", "type": "address" },
166
178
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
167
- { "internalType": "uint256", "name": "chainId", "type": "uint256" }
179
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" }
168
180
  ],
169
181
  "name": "burn",
170
182
  "outputs": [],
@@ -206,7 +218,7 @@
206
218
  "inputs": [
207
219
  { "internalType": "address", "name": "to", "type": "address" },
208
220
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
209
- { "internalType": "uint256", "name": "chainId", "type": "uint256" },
221
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" },
210
222
  {
211
223
  "internalType": "bytes32",
212
224
  "name": "transactionHash",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  {
37
37
  "indexed": false,
38
- "internalType": "uint256",
38
+ "internalType": "uint32",
39
39
  "name": "sourceChainId",
40
- "type": "uint256"
40
+ "type": "uint32"
41
41
  },
42
42
  {
43
43
  "indexed": true,
44
- "internalType": "uint256",
44
+ "internalType": "uint32",
45
45
  "name": "targetChainId",
46
- "type": "uint256"
46
+ "type": "uint32"
47
47
  }
48
48
  ],
49
49
  "name": "LogGatewayDeposit",
@@ -72,15 +72,15 @@
72
72
  },
73
73
  {
74
74
  "indexed": true,
75
- "internalType": "uint256",
75
+ "internalType": "uint32",
76
76
  "name": "sourceChainId",
77
- "type": "uint256"
77
+ "type": "uint32"
78
78
  },
79
79
  {
80
80
  "indexed": false,
81
- "internalType": "uint256",
81
+ "internalType": "uint32",
82
82
  "name": "targetChainId",
83
- "type": "uint256"
83
+ "type": "uint32"
84
84
  },
85
85
  {
86
86
  "indexed": true,
@@ -122,7 +122,7 @@
122
122
  "inputs": [
123
123
  { "internalType": "address", "name": "token_", "type": "address" },
124
124
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
125
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
125
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
126
126
  ],
127
127
  "name": "deposit",
128
128
  "outputs": [],
@@ -134,7 +134,7 @@
134
134
  { "internalType": "address", "name": "to_", "type": "address" },
135
135
  { "internalType": "address", "name": "token_", "type": "address" },
136
136
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
137
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
137
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
138
138
  ],
139
139
  "name": "depositFor",
140
140
  "outputs": [],
@@ -160,7 +160,7 @@
160
160
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
161
161
  { "internalType": "address", "name": "user_", "type": "address" },
162
162
  { "internalType": "address", "name": "token_", "type": "address" },
163
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" },
163
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" },
164
164
  {
165
165
  "internalType": "bytes32",
166
166
  "name": "transactionHash_",
@@ -0,0 +1,36 @@
1
+ import fastify from "fastify"
2
+ import cors from '@fastify/cors'
3
+ import Logger from "@/logger"
4
+ import { Transaction } from "@/db";
5
+
6
+ const logger = new Logger("RPC");
7
+
8
+
9
+ const server = fastify({ logger: false })
10
+
11
+ server.register(cors, {})
12
+
13
+ server.get('/', async () => 'Interop X API')
14
+
15
+ export const startApiServer = async () => {
16
+ const HOST = process.env.API_HOST || '0.0.0.0';
17
+ const PORT = process.env.API_PORT || '8080';
18
+ try {
19
+ server.get('/transactions', async (req) => {
20
+ return await Transaction.findAndCountAll({
21
+ limit: 20,
22
+ offset: 0,
23
+ order: [
24
+ ['createdAt', 'DESC']
25
+ ]
26
+ })
27
+ })
28
+
29
+ await server.listen(PORT, HOST)
30
+
31
+ logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
32
+ } catch (err) {
33
+ logger.error(err.message)
34
+ process.exit(1)
35
+ }
36
+ }
@@ -1,5 +1,7 @@
1
1
  import { ethers, Wallet } from "ethers"
2
2
  import { EventBus, EventBusType } from "@/types"
3
+ import fs from 'fs-extra'
4
+ import expandHomeDir from "expand-home-dir";
3
5
 
4
6
  class Config {
5
7
  public readonly events: EventBusType
@@ -8,14 +10,18 @@ class Config {
8
10
  public readonly privateKey: string
9
11
  public readonly wallet: Wallet
10
12
  public readonly staging: boolean
13
+ public readonly autoUpdate: boolean
14
+ public readonly baseConfigPath: string
11
15
 
12
16
  constructor() {
13
17
  this.events = new EventBus() as EventBusType
14
- this.maxPeers = 10
18
+ this.maxPeers = 20
15
19
  this.privateKey = process.env.PRIVATE_KEY as string;
16
20
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
21
+ this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
17
22
  this.wallet = new Wallet(this.privateKey);
18
23
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
24
+ this.baseConfigPath = expandHomeDir(`~/.interop-x`);
19
25
  }
20
26
 
21
27
  get publicAddress(){
@@ -25,6 +31,10 @@ class Config {
25
31
  isLeadNode() {
26
32
  return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
27
33
  }
34
+
35
+ isMaintenanceMode(){
36
+ return fs.existsSync(this.baseConfigPath + '/maintenance')
37
+ }
28
38
  }
29
39
 
30
40
  export default new Config()
@@ -3,23 +3,15 @@ export const addresses = {
3
3
  gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
4
4
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
5
5
  interopXGateway: '',
6
- interopBridgeTokens: [],
7
6
  },
8
7
  137: {
9
8
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
10
9
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
11
10
  interopXGateway: '',
12
- interopBridgeTokens: [
13
- {
14
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
15
- symbol : 'USDC',
16
- }
17
- ],
18
11
  },
19
12
  43114: {
20
13
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
21
14
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
22
- interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
23
- interopBridgeTokens: [],
15
+ interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
24
16
  }
25
17
  }
@@ -1,2 +1,3 @@
1
1
  export * from './addresses';
2
2
  export * from './tokens';
3
+ export * from './itokens';
@@ -0,0 +1,10 @@
1
+ export const itokens = {
2
+ 1: [],
3
+ 137: [
4
+ {
5
+ address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
6
+ symbol: 'USDC',
7
+ }
8
+ ],
9
+ 43114: []
10
+ };
@@ -5,16 +5,19 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
5
5
  declare id: CreationOptional<number>;
6
6
 
7
7
  declare transactionHash: string;
8
- declare type: string;
8
+ declare action: string;
9
9
  declare from: string;
10
10
  declare to: string;
11
11
 
12
+ declare submitTransactionHash: string;
13
+ declare submitBlockNumber: number;
12
14
 
13
15
  declare sourceChainId: number;
14
- declare sourceTransactionHash: string;
15
- declare sourceBlockNumber: number;
16
+ declare sourceTransactionHash: CreationOptional<string>;
17
+ declare sourceBlockNumber: CreationOptional<number>;
16
18
  declare sourceStatus: string;
17
19
  declare sourceErrors: CreationOptional<string[]>;
20
+ declare sourceLogs: CreationOptional<any[]>;
18
21
  declare sourceCreatedAt: CreationOptional<Date>;
19
22
  declare sourceDelayUntil: CreationOptional<Date>;
20
23
 
@@ -23,6 +26,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
23
26
  declare targetBlockNumber: CreationOptional<number>;
24
27
  declare targetStatus: string;
25
28
  declare targetErrors: CreationOptional<string[]>;
29
+ declare targetLogs: CreationOptional<any[]>;
26
30
  declare targetCreatedAt: CreationOptional<Date>;
27
31
  declare targetDelayUntil: CreationOptional<Date>;
28
32
 
@@ -45,9 +49,11 @@ Transaction.init({
45
49
  primaryKey: true
46
50
  },
47
51
 
52
+ submitTransactionHash: DataTypes.NUMBER,
53
+ submitBlockNumber: DataTypes.NUMBER,
48
54
 
49
55
  transactionHash: DataTypes.STRING,
50
- type: DataTypes.STRING,
56
+ action: DataTypes.STRING,
51
57
 
52
58
  from: DataTypes.STRING,
53
59
  to: DataTypes.STRING,
@@ -60,6 +66,10 @@ Transaction.init({
60
66
  type: DataTypes.JSON,
61
67
  // defaultValue: [],
62
68
  },
69
+ sourceLogs: {
70
+ type: DataTypes.JSON,
71
+ // defaultValue: [],
72
+ },
63
73
  sourceCreatedAt: {
64
74
  type: DataTypes.DATE,
65
75
  defaultValue: Date.now()
@@ -74,6 +84,10 @@ Transaction.init({
74
84
  type: DataTypes.JSON,
75
85
  // defaultValue: [],
76
86
  },
87
+ targetLogs: {
88
+ type: DataTypes.JSON,
89
+ // defaultValue: [],
90
+ },
77
91
  targetCreatedAt: DataTypes.DATE,
78
92
  targetDelayUntil: DataTypes.DATE,
79
93
 
@@ -4,7 +4,7 @@ import expandHomeDir from "expand-home-dir";
4
4
 
5
5
  import { Sequelize } from 'sequelize';
6
6
 
7
- const basePath = expandHomeDir(`~/.interop-x/data/${config.publicAddress}`);
7
+ const basePath = expandHomeDir(`~/.interop-x/data/${config.publicAddress}/${config.staging ? 'staging' : ''}`);
8
8
 
9
9
  export const sequelize = new Sequelize({
10
10
  dialect: 'sqlite',
@@ -0,0 +1,63 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropBridgeToken } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.sourceStatus === 'pending') {
16
+ throw Error('Cannot build data for pending deposit transaction');
17
+ }
18
+
19
+ if (!transaction.submitEvent) {
20
+ throw Error('Cannot build data for transaction without submitEvent');
21
+ }
22
+
23
+
24
+ const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
25
+
26
+ if (!token) {
27
+ throw Error(`Unsupported token ${transaction.submitEvent.token}`);
28
+ }
29
+
30
+ const itoken = itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
31
+
32
+ if (!itoken) {
33
+ throw Error(`Unsupported itoken ${token.symbol}`);
34
+ }
35
+
36
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
37
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
38
+ const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
39
+
40
+ const { data } = await interopBridgeContract.populateTransaction.mint(
41
+ transaction.submitEvent.user,
42
+ ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
43
+ ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
44
+ transaction.submitTransactionHash,
45
+ );
46
+
47
+ transactions.push({
48
+ to: itoken.address,
49
+ data: data!,
50
+ value: '0',
51
+ operation: OperationType.Call,
52
+ });
53
+
54
+ logs.push({
55
+ type: 'mint', // mint, approved, burn, transfer, borrow, swap, repay, collected, traded, .....
56
+ message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
57
+ })
58
+
59
+ return {
60
+ transactions,
61
+ logs,
62
+ }
63
+ }
@@ -0,0 +1,7 @@
1
+ import deposit from "./deposit"
2
+ import withdraw from "./withdraw"
3
+
4
+ export default {
5
+ deposit,
6
+ withdraw,
7
+ }
@@ -0,0 +1,67 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropXGateway } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.action !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.action}`)
17
+ }
18
+
19
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
20
+ throw Error('Cannot build data for pending withdraw transaction');
21
+ }
22
+
23
+ if (!transaction.submitEvent) {
24
+ throw Error('Cannot build data for transaction without submitEvent');
25
+ }
26
+
27
+ const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
28
+
29
+ const itoken = itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
30
+
31
+ if (!itoken) {
32
+ throw Error(`Unsupported itoken ${itokenAddress}`);
33
+ }
34
+
35
+ const token = tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
36
+
37
+ if (!token) {
38
+ throw Error(`Unsupported token ${itoken.symbol}`);
39
+ }
40
+
41
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
42
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
43
+ const gatewayAddress = addresses[targetChainId].interopXGateway;
44
+ const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
45
+
46
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
47
+ ethers.BigNumber.from(amount.toString()),
48
+ to,
49
+ token.address,
50
+ ethers.BigNumber.from(sourceChainId.toString()),
51
+ transaction.submitTransactionHash,
52
+ );
53
+
54
+ transactions.push({
55
+ to: gatewayAddress,
56
+ data: data!,
57
+ value: '0',
58
+ operation: OperationType.Call,
59
+ });
60
+
61
+ logs.push({
62
+ type: 'transfer',
63
+ message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
64
+ })
65
+
66
+ return { transactions, logs }
67
+ }
@@ -0,0 +1,19 @@
1
+ import { Transaction } from "@/db";
2
+ import { encodeMulti } from "ethers-multisend";
3
+ import actions from "./actions";
4
+
5
+ export const buildGnosisAction = async (transaction: Transaction, type?: 'source' | 'target') => {
6
+ type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
7
+
8
+ if (actions.hasOwnProperty(transaction.action)) {
9
+
10
+ const { transactions, logs } = await actions[transaction.action](transaction, type);
11
+
12
+ return {
13
+ data: encodeMulti(transactions).data,
14
+ logs
15
+ };
16
+ }
17
+
18
+ throw new Error(`Unknown action: ${transaction.action}`);
19
+ }