@instadapp/interop-x 0.0.0-dev.9387bd9 → 0.0.0-dev.a168c79
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/dist/package.json +69 -0
- package/dist/src/abi/erc20.json +350 -0
- package/dist/src/abi/gnosisSafe.json +747 -0
- package/dist/src/abi/index.js +15 -0
- package/dist/src/abi/interopBridgeToken.json +286 -0
- package/dist/src/abi/interopXGateway.json +184 -0
- package/dist/src/api/index.js +33 -0
- package/dist/{config → src/config}/index.js +5 -1
- package/dist/src/constants/addresses.js +20 -0
- package/dist/{constants → src/constants}/index.js +2 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/src/constants/tokens.js +107 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +1 -1
- package/dist/src/db/models/transaction.js +54 -0
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/{index.js → src/index.js} +29 -3
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +5 -5
- package/dist/{net → src/net}/pool/index.js +2 -2
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +15 -14
- package/dist/{net → src/net}/protocol/index.js +3 -3
- package/dist/{tasks → src/tasks}/BaseTask.js +2 -2
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +140 -0
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +75 -0
- package/dist/{tasks → src/tasks}/index.js +9 -1
- package/dist/src/typechain/Erc20.js +2 -0
- package/dist/src/typechain/GnosisSafe.js +2 -0
- package/dist/src/typechain/InteropBridgeToken.js +2 -0
- package/dist/src/typechain/InteropXGateway.js +2 -0
- package/dist/src/typechain/common.js +2 -0
- package/dist/src/typechain/factories/Erc20__factory.js +367 -0
- package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +459 -0
- package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
- package/dist/src/typechain/factories/index.js +14 -0
- package/dist/src/typechain/index.js +35 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/{utils → src/utils}/index.js +50 -2
- package/package.json +14 -4
- package/src/abi/erc20.json +350 -0
- package/src/abi/gnosisSafe.json +747 -0
- package/src/abi/index.ts +11 -0
- package/src/abi/interopBridgeToken.json +286 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +7 -1
- package/src/constants/addresses.ts +9 -2
- package/src/constants/index.ts +2 -0
- package/src/constants/itokens.ts +10 -0
- package/src/constants/tokens.ts +104 -0
- package/src/db/index.ts +1 -1
- package/src/db/models/index.ts +1 -1
- package/src/db/models/transaction.ts +96 -0
- package/src/db/sequelize.ts +2 -1
- package/src/index.ts +35 -3
- package/src/net/peer/index.ts +3 -3
- package/src/net/pool/index.ts +2 -2
- package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
- package/src/net/protocol/dial/SignatureDialProtocol.ts +18 -17
- package/src/net/protocol/index.ts +3 -3
- package/src/tasks/BaseTask.ts +2 -3
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +232 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +126 -0
- package/src/tasks/index.ts +4 -1
- package/src/typechain/Erc20.ts +491 -0
- package/src/typechain/GnosisSafe.ts +1728 -0
- package/src/typechain/InteropBridgeToken.ts +686 -0
- package/src/typechain/InteropXGateway.ts +407 -0
- package/src/typechain/common.ts +44 -0
- package/src/typechain/factories/Erc20__factory.ts +368 -0
- package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
- package/src/typechain/factories/InteropBridgeToken__factory.ts +466 -0
- package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
- package/src/typechain/factories/index.ts +7 -0
- package/src/typechain/index.ts +12 -0
- package/src/types.ts +2 -2
- package/src/utils/index.ts +72 -3
- package/tsconfig.json +3 -0
- package/dist/constants/addresses.js +0 -13
- package/dist/db/models/execution.js +0 -38
- package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,7 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
export { Erc20__factory } from "./Erc20__factory";
|
5
|
+
export { GnosisSafe__factory } from "./GnosisSafe__factory";
|
6
|
+
export { InteropBridgeToken__factory } from "./InteropBridgeToken__factory";
|
7
|
+
export { InteropXGateway__factory } from "./InteropXGateway__factory";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
export type { Erc20 } from "./Erc20";
|
5
|
+
export type { GnosisSafe } from "./GnosisSafe";
|
6
|
+
export type { InteropBridgeToken } from "./InteropBridgeToken";
|
7
|
+
export type { InteropXGateway } from "./InteropXGateway";
|
8
|
+
export * as factories from "./factories";
|
9
|
+
export { Erc20__factory } from "./factories/Erc20__factory";
|
10
|
+
export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
|
11
|
+
export { InteropBridgeToken__factory } from "./factories/InteropBridgeToken__factory";
|
12
|
+
export { InteropXGateway__factory } from "./factories/InteropXGateway__factory";
|
package/src/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { EventEmitter } from 'events'
|
2
|
-
import { IPeerInfo } from '
|
2
|
+
import { IPeerInfo } from '@/net'
|
3
3
|
|
4
4
|
/**
|
5
5
|
* Types for the central event bus, emitted
|
@@ -36,4 +36,4 @@ export type EventBusType = EventBus<Event.PEER_CONNECTED> &
|
|
36
36
|
EventBus<Event.POOL_PEER_BANNED>
|
37
37
|
|
38
38
|
|
39
|
-
export type ChainId = 1 | 137;
|
39
|
+
export type ChainId = 1 | 137 | 43114;
|
package/src/utils/index.ts
CHANGED
@@ -3,8 +3,14 @@
|
|
3
3
|
*/
|
4
4
|
import axios from 'axios'
|
5
5
|
import axiosRetry from "axios-retry";
|
6
|
-
import { addresses } from '
|
7
|
-
import { ChainId } from '
|
6
|
+
import { addresses, itokens, tokens } from '@/constants';
|
7
|
+
import { ChainId } from '@/types'
|
8
|
+
import { ethers } from 'ethers';
|
9
|
+
import { encodeMulti, MetaTransaction, OperationType } from 'ethers-multisend';
|
10
|
+
import { Transaction } from '@/db';
|
11
|
+
import config from '@/config';
|
12
|
+
import abi from '@/abi';
|
13
|
+
import { InteropBridgeToken } from '@/typechain';
|
8
14
|
|
9
15
|
export const http = axios.create();
|
10
16
|
|
@@ -73,6 +79,8 @@ export const getRpcProviderUrl = (chainId: ChainId) => {
|
|
73
79
|
return 'https://rpc.instadapp.io/mainnet';
|
74
80
|
case 137:
|
75
81
|
return 'https://rpc.instadapp.io/polygon';
|
82
|
+
case 43114:
|
83
|
+
return 'https://rpc.instadapp.io/avalanche';
|
76
84
|
default:
|
77
85
|
throw new Error(`Unknown chainId: ${chainId}`);
|
78
86
|
}
|
@@ -113,4 +121,65 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
|
|
113
121
|
clearTimeout(timeoutHandle);
|
114
122
|
return result;
|
115
123
|
}) as Promise<T>
|
116
|
-
}
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
export const generateInteropTransactionHash = (data: { action: string, submitTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
|
128
|
+
return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
129
|
+
String(data.action),
|
130
|
+
String(data.submitTransactionHash),
|
131
|
+
String(data.sourceChainId),
|
132
|
+
String(data.targetChainId),
|
133
|
+
]);
|
134
|
+
}
|
135
|
+
|
136
|
+
export const buildDataForTransaction = async (transaction: Transaction, type?: 'source' | 'target') => {
|
137
|
+
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
138
|
+
|
139
|
+
const transactions: MetaTransaction[] = [];
|
140
|
+
|
141
|
+
if(transaction.action != 'deposit') {
|
142
|
+
throw new Error('Invalid action');
|
143
|
+
}
|
144
|
+
|
145
|
+
if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
|
146
|
+
throw Error('Cannot build data for pending deposit transaction');
|
147
|
+
}
|
148
|
+
|
149
|
+
if (!transaction.submitEvent) {
|
150
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
155
|
+
|
156
|
+
if (!token) {
|
157
|
+
throw Error('Cannot build data for transaction without token');
|
158
|
+
}
|
159
|
+
|
160
|
+
const itoken = itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
|
161
|
+
|
162
|
+
if (!itoken) {
|
163
|
+
throw Error('Cannot build data for transaction without itoken');
|
164
|
+
}
|
165
|
+
|
166
|
+
const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
|
167
|
+
const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
|
168
|
+
const interopBridgeContract = new ethers.Contract(itoken.address, abi.interopBridgeToken, targetWallet) as InteropBridgeToken;
|
169
|
+
|
170
|
+
const { data } = await interopBridgeContract.populateTransaction.mint(
|
171
|
+
transaction.submitEvent.to,
|
172
|
+
transaction.submitEvent.amount,
|
173
|
+
transaction.sourceChainId,
|
174
|
+
transaction.sourceTransactionHash,
|
175
|
+
);
|
176
|
+
|
177
|
+
transactions.push({
|
178
|
+
to: itoken.address,
|
179
|
+
data: data!,
|
180
|
+
value: '0',
|
181
|
+
operation: OperationType.Call,
|
182
|
+
});
|
183
|
+
|
184
|
+
return encodeMulti(transactions).data
|
185
|
+
}
|
package/tsconfig.json
CHANGED
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.addresses = void 0;
|
4
|
-
exports.addresses = {
|
5
|
-
1: {
|
6
|
-
gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
|
7
|
-
multisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
|
8
|
-
},
|
9
|
-
137: {
|
10
|
-
gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
|
11
|
-
multisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
|
12
|
-
},
|
13
|
-
};
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Execution = void 0;
|
4
|
-
const sequelize_1 = require("../sequelize");
|
5
|
-
const sequelize_2 = require("sequelize");
|
6
|
-
class Execution extends sequelize_2.Model {
|
7
|
-
}
|
8
|
-
exports.Execution = Execution;
|
9
|
-
Execution.init({
|
10
|
-
id: {
|
11
|
-
type: sequelize_2.DataTypes.INTEGER,
|
12
|
-
autoIncrement: true,
|
13
|
-
primaryKey: true
|
14
|
-
},
|
15
|
-
transactionHash: sequelize_2.DataTypes.STRING,
|
16
|
-
from: sequelize_2.DataTypes.STRING,
|
17
|
-
executions: sequelize_2.DataTypes.JSON,
|
18
|
-
chainId: sequelize_2.DataTypes.NUMBER,
|
19
|
-
gas: sequelize_2.DataTypes.STRING,
|
20
|
-
maxGasPrice: sequelize_2.DataTypes.STRING,
|
21
|
-
assets: sequelize_2.DataTypes.JSON,
|
22
|
-
metadata: sequelize_2.DataTypes.STRING,
|
23
|
-
vnonce: sequelize_2.DataTypes.STRING,
|
24
|
-
txHash: sequelize_2.DataTypes.STRING,
|
25
|
-
blockNumber: sequelize_2.DataTypes.STRING,
|
26
|
-
status: {
|
27
|
-
type: sequelize_2.DataTypes.STRING,
|
28
|
-
defaultValue: 'pending'
|
29
|
-
},
|
30
|
-
delayUntil: sequelize_2.DataTypes.DATE,
|
31
|
-
delayedCount: {
|
32
|
-
type: sequelize_2.DataTypes.INTEGER,
|
33
|
-
defaultValue: 0
|
34
|
-
},
|
35
|
-
error: sequelize_2.DataTypes.STRING,
|
36
|
-
createdAt: sequelize_2.DataTypes.DATE,
|
37
|
-
updatedAt: sequelize_2.DataTypes.DATE,
|
38
|
-
}, { sequelize: sequelize_1.sequelize, tableName: 'executions' });
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import { sequelize } from '../sequelize'
|
2
|
-
import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
|
3
|
-
|
4
|
-
export class Execution extends Model<InferAttributes<Execution>, InferCreationAttributes<Execution>> {
|
5
|
-
declare id: CreationOptional<number>;
|
6
|
-
|
7
|
-
declare transactionHash: string;
|
8
|
-
declare from: string;
|
9
|
-
declare executions: any[];
|
10
|
-
declare chainId: number;
|
11
|
-
declare gas: string;
|
12
|
-
declare maxGasPrice: string;
|
13
|
-
declare assets: any[];
|
14
|
-
declare metadata: string;
|
15
|
-
declare vnonce: string;
|
16
|
-
declare txHash: string;
|
17
|
-
|
18
|
-
declare blockNumber: string;
|
19
|
-
declare status: CreationOptional<string>;
|
20
|
-
declare delayUntil: CreationOptional<Date>;
|
21
|
-
declare delayedCount: CreationOptional<number>;
|
22
|
-
|
23
|
-
declare error: CreationOptional<string>;
|
24
|
-
declare createdAt: CreationOptional<Date>;
|
25
|
-
declare updatedAt: CreationOptional<Date>;
|
26
|
-
}
|
27
|
-
|
28
|
-
Execution.init({
|
29
|
-
id: {
|
30
|
-
type: DataTypes.INTEGER,
|
31
|
-
autoIncrement: true,
|
32
|
-
primaryKey: true
|
33
|
-
},
|
34
|
-
transactionHash: DataTypes.STRING,
|
35
|
-
from: DataTypes.STRING,
|
36
|
-
executions: DataTypes.JSON,
|
37
|
-
chainId: DataTypes.NUMBER,
|
38
|
-
gas: DataTypes.STRING,
|
39
|
-
maxGasPrice: DataTypes.STRING,
|
40
|
-
assets: DataTypes.JSON,
|
41
|
-
metadata: DataTypes.STRING,
|
42
|
-
vnonce: DataTypes.STRING,
|
43
|
-
txHash: DataTypes.STRING,
|
44
|
-
blockNumber: DataTypes.STRING,
|
45
|
-
status: {
|
46
|
-
type: DataTypes.STRING,
|
47
|
-
defaultValue: 'pending'
|
48
|
-
},
|
49
|
-
delayUntil: DataTypes.DATE,
|
50
|
-
delayedCount: {
|
51
|
-
type: DataTypes.INTEGER,
|
52
|
-
defaultValue: 0
|
53
|
-
},
|
54
|
-
error: DataTypes.STRING,
|
55
|
-
createdAt: DataTypes.DATE,
|
56
|
-
updatedAt: DataTypes.DATE,
|
57
|
-
}, { sequelize, tableName: 'executions' });
|