@instadapp/interop-x 0.0.0-dev.ef78459 → 0.0.0-dev.f0a6281
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -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 +298 -0
- package/dist/src/abi/interopXGateway.json +184 -0
- package/dist/src/api/index.js +33 -0
- package/dist/src/config/index.js +31 -0
- 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/src/index.js +130 -0
- 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 +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +20 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/{net → src/net}/protocol/index.js +44 -4
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +13 -5
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -0
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +71 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +161 -0
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +74 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +44 -0
- 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 +471 -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/src/utils/index.js +238 -0
- package/package.json +18 -10
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- 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 +298 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +17 -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/models/index.ts +1 -1
- package/src/db/models/transaction.ts +96 -0
- package/src/db/sequelize.ts +2 -1
- package/src/index.ts +119 -7
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +24 -15
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +60 -4
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +15 -6
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +256 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +124 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +26 -1
- package/src/typechain/Erc20.ts +491 -0
- package/src/typechain/GnosisSafe.ts +1728 -0
- package/src/typechain/InteropBridgeToken.ts +692 -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 +478 -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 +1 -1
- package/src/utils/index.ts +206 -3
- package/dist/config/index.js +0 -17
- package/dist/constants/addresses.js +0 -13
- package/dist/db/models/execution.js +0 -38
- package/dist/index.js +0 -43
- package/dist/tasks/index.js +0 -19
- package/dist/utils/index.js +0 -89
- package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,104 @@
|
|
1
|
+
export const tokens = {
|
2
|
+
1: [
|
3
|
+
{
|
4
|
+
symbol: "ETH",
|
5
|
+
name: "Ethereum",
|
6
|
+
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
7
|
+
decimals: 18,
|
8
|
+
},
|
9
|
+
{
|
10
|
+
symbol: "DAI",
|
11
|
+
name: "DAI Stable",
|
12
|
+
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
13
|
+
decimals: 18,
|
14
|
+
},
|
15
|
+
{
|
16
|
+
symbol: "USDC",
|
17
|
+
name: "USD Coin",
|
18
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
19
|
+
decimals: 6,
|
20
|
+
},
|
21
|
+
{
|
22
|
+
symbol: "USDT",
|
23
|
+
name: "Tether USD Coin",
|
24
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
25
|
+
decimals: 6,
|
26
|
+
},
|
27
|
+
{
|
28
|
+
symbol: "WBTC",
|
29
|
+
name: "Wrapped BTC",
|
30
|
+
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
31
|
+
decimals: 8,
|
32
|
+
},
|
33
|
+
],
|
34
|
+
137: [
|
35
|
+
{
|
36
|
+
symbol: "ETH",
|
37
|
+
name: "Ethereum",
|
38
|
+
address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
39
|
+
decimals: 18,
|
40
|
+
},
|
41
|
+
{
|
42
|
+
symbol: "DAI",
|
43
|
+
name: "DAI Stable",
|
44
|
+
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
|
45
|
+
decimals: 18,
|
46
|
+
},
|
47
|
+
{
|
48
|
+
symbol: "USDC",
|
49
|
+
name: "USD Coin",
|
50
|
+
address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
51
|
+
decimals: 6,
|
52
|
+
},
|
53
|
+
{
|
54
|
+
symbol: "USDT",
|
55
|
+
name: "Tether USD Coin",
|
56
|
+
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
57
|
+
decimals: 6,
|
58
|
+
},
|
59
|
+
{
|
60
|
+
symbol: "WBTC",
|
61
|
+
name: "Wrapped BTC",
|
62
|
+
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
63
|
+
decimals: 8,
|
64
|
+
},
|
65
|
+
{
|
66
|
+
symbol: "AVAX",
|
67
|
+
name: "Avalanche Token",
|
68
|
+
address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
|
69
|
+
decimals: 18,
|
70
|
+
},
|
71
|
+
],
|
72
|
+
43114: [
|
73
|
+
{
|
74
|
+
symbol: "ETH",
|
75
|
+
name: "Ethereum",
|
76
|
+
address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
|
77
|
+
decimals: 18,
|
78
|
+
},
|
79
|
+
{
|
80
|
+
symbol: "DAI",
|
81
|
+
name: "DAI Stable",
|
82
|
+
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
83
|
+
decimals: 18,
|
84
|
+
},
|
85
|
+
{
|
86
|
+
symbol: "USDC",
|
87
|
+
name: "USD Coin",
|
88
|
+
address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
|
89
|
+
decimals: 6,
|
90
|
+
},
|
91
|
+
{
|
92
|
+
symbol: "USDT",
|
93
|
+
name: "Tether USD Coin",
|
94
|
+
address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
95
|
+
decimals: 6,
|
96
|
+
},
|
97
|
+
{
|
98
|
+
symbol: "WBTC",
|
99
|
+
name: "Wrapped BTC",
|
100
|
+
address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
|
101
|
+
decimals: 8,
|
102
|
+
},
|
103
|
+
],
|
104
|
+
};
|
package/src/db/models/index.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from './
|
1
|
+
export * from './transaction';
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import { sequelize } from '@/db/sequelize'
|
2
|
+
import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
|
3
|
+
|
4
|
+
export class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
|
5
|
+
declare id: CreationOptional<number>;
|
6
|
+
|
7
|
+
declare transactionHash: string;
|
8
|
+
declare action: string;
|
9
|
+
declare from: string;
|
10
|
+
declare to: string;
|
11
|
+
|
12
|
+
declare submitTransactionHash: string;
|
13
|
+
declare submitBlockNumber: number;
|
14
|
+
|
15
|
+
declare sourceChainId: number;
|
16
|
+
declare sourceTransactionHash: CreationOptional<string>;
|
17
|
+
declare sourceBlockNumber: CreationOptional<number>;
|
18
|
+
declare sourceStatus: string;
|
19
|
+
declare sourceErrors: CreationOptional<string[]>;
|
20
|
+
declare sourceCreatedAt: CreationOptional<Date>;
|
21
|
+
declare sourceDelayUntil: CreationOptional<Date>;
|
22
|
+
|
23
|
+
declare targetChainId: number;
|
24
|
+
declare targetTransactionHash: CreationOptional<string>;
|
25
|
+
declare targetBlockNumber: CreationOptional<number>;
|
26
|
+
declare targetStatus: string;
|
27
|
+
declare targetErrors: CreationOptional<string[]>;
|
28
|
+
declare targetCreatedAt: CreationOptional<Date>;
|
29
|
+
declare targetDelayUntil: CreationOptional<Date>;
|
30
|
+
|
31
|
+
declare submitEvent: any;
|
32
|
+
declare sourceEvent: CreationOptional<any>;
|
33
|
+
declare targetEvent: CreationOptional<any>;
|
34
|
+
|
35
|
+
declare metadata: CreationOptional<any>;
|
36
|
+
|
37
|
+
declare status: string;
|
38
|
+
|
39
|
+
declare createdAt: CreationOptional<Date>;
|
40
|
+
declare updatedAt: CreationOptional<Date>;
|
41
|
+
}
|
42
|
+
|
43
|
+
Transaction.init({
|
44
|
+
id: {
|
45
|
+
type: DataTypes.INTEGER,
|
46
|
+
autoIncrement: true,
|
47
|
+
primaryKey: true
|
48
|
+
},
|
49
|
+
|
50
|
+
submitTransactionHash: DataTypes.NUMBER,
|
51
|
+
submitBlockNumber: DataTypes.NUMBER,
|
52
|
+
|
53
|
+
transactionHash: DataTypes.STRING,
|
54
|
+
action: DataTypes.STRING,
|
55
|
+
|
56
|
+
from: DataTypes.STRING,
|
57
|
+
to: DataTypes.STRING,
|
58
|
+
|
59
|
+
sourceChainId: DataTypes.NUMBER,
|
60
|
+
sourceTransactionHash: DataTypes.STRING,
|
61
|
+
sourceBlockNumber: DataTypes.NUMBER,
|
62
|
+
sourceStatus: DataTypes.STRING,
|
63
|
+
sourceErrors: {
|
64
|
+
type: DataTypes.JSON,
|
65
|
+
// defaultValue: [],
|
66
|
+
},
|
67
|
+
sourceCreatedAt: {
|
68
|
+
type: DataTypes.DATE,
|
69
|
+
defaultValue: Date.now()
|
70
|
+
},
|
71
|
+
sourceDelayUntil: DataTypes.STRING,
|
72
|
+
|
73
|
+
targetChainId: DataTypes.NUMBER,
|
74
|
+
targetTransactionHash: DataTypes.STRING,
|
75
|
+
targetBlockNumber: DataTypes.NUMBER,
|
76
|
+
targetStatus: DataTypes.STRING,
|
77
|
+
targetErrors: {
|
78
|
+
type: DataTypes.JSON,
|
79
|
+
// defaultValue: [],
|
80
|
+
},
|
81
|
+
targetCreatedAt: DataTypes.DATE,
|
82
|
+
targetDelayUntil: DataTypes.DATE,
|
83
|
+
|
84
|
+
submitEvent: DataTypes.JSON,
|
85
|
+
sourceEvent: DataTypes.JSON,
|
86
|
+
targetEvent: DataTypes.JSON,
|
87
|
+
|
88
|
+
metadata: DataTypes.JSON,
|
89
|
+
|
90
|
+
status: {
|
91
|
+
type: DataTypes.STRING,
|
92
|
+
defaultValue: 'pending'
|
93
|
+
},
|
94
|
+
createdAt: DataTypes.DATE,
|
95
|
+
updatedAt: DataTypes.DATE,
|
96
|
+
}, { sequelize, tableName: 'transactions' });
|
package/src/db/sequelize.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
//@ts-ignore
|
2
|
+
import config from "@/config";
|
2
3
|
import expandHomeDir from "expand-home-dir";
|
3
4
|
|
4
5
|
import { Sequelize } from 'sequelize';
|
5
6
|
|
6
|
-
const basePath = expandHomeDir(
|
7
|
+
const basePath = expandHomeDir(`~/.interop-x/data/${config.publicAddress}/${config.staging ? 'staging' : ''}`);
|
7
8
|
|
8
9
|
export const sequelize = new Sequelize({
|
9
10
|
dialect: 'sqlite',
|
package/src/index.ts
CHANGED
@@ -1,23 +1,102 @@
|
|
1
|
-
import 'module-alias
|
2
|
-
import
|
1
|
+
import moduleAlias from 'module-alias';
|
2
|
+
import expandHomeDir from "expand-home-dir";
|
3
|
+
import fs from 'fs-extra'
|
4
|
+
moduleAlias.addAliases({
|
5
|
+
"@/": __dirname + "/",
|
6
|
+
"@/logger": __dirname + "/logger",
|
7
|
+
"@/tasks": __dirname + "/tasks",
|
8
|
+
"@/utils": __dirname + "/utils",
|
9
|
+
"@/api": __dirname + "/api",
|
10
|
+
"@/net": __dirname + "/net",
|
11
|
+
"@/db": __dirname + "/db",
|
12
|
+
"@/config": __dirname + "/config",
|
13
|
+
"@/types": __dirname + "/types",
|
14
|
+
"@/abi": __dirname + "/abi",
|
15
|
+
"@/constants": __dirname + "/constants",
|
16
|
+
"@/typechain": __dirname + "/typechain"
|
17
|
+
})
|
18
|
+
|
19
|
+
moduleAlias();
|
3
20
|
import dotenv from "dotenv";
|
4
|
-
import
|
21
|
+
import chalk from 'chalk';
|
5
22
|
import { ethers } from "ethers";
|
23
|
+
import packageJson from '../package.json'
|
6
24
|
dotenv.config();
|
25
|
+
|
26
|
+
import Logger from "@/logger";
|
7
27
|
const logger = new Logger('Process')
|
8
28
|
|
9
|
-
|
29
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
30
|
+
|
31
|
+
const printUsage = () => {
|
32
|
+
console.log()
|
33
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
34
|
+
console.log()
|
35
|
+
|
36
|
+
console.log('Usage:')
|
37
|
+
console.log(' interop-x help Show this message')
|
38
|
+
console.log(' interop-x version Print out the installed version of Interop X')
|
39
|
+
|
40
|
+
console.log()
|
41
|
+
|
42
|
+
console.log(' interop-x down Put the node into maintenance mode')
|
43
|
+
console.log(' interop-x up Take the node out of maintenance mode')
|
44
|
+
|
45
|
+
console.log()
|
46
|
+
|
47
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
|
48
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
|
49
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
|
50
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port')
|
51
|
+
console.log()
|
10
52
|
|
53
|
+
}
|
54
|
+
|
55
|
+
if (process.argv.at(-1) === 'help') {
|
56
|
+
printUsage()
|
57
|
+
process.exit(0)
|
58
|
+
}
|
59
|
+
|
60
|
+
const basePath = expandHomeDir(`~/.interop-x`);
|
61
|
+
|
62
|
+
if (process.argv.at(-1) === 'down') {
|
63
|
+
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
64
|
+
console.log(chalk.red('Maintenance mode enabled'))
|
65
|
+
process.exit(0)
|
66
|
+
}
|
67
|
+
|
68
|
+
if (process.argv.at(-1) === 'up') {
|
69
|
+
fs.removeSync(basePath + '/maintenance')
|
70
|
+
console.log(chalk.green('Maintenance mode disabled'))
|
71
|
+
process.exit(0)
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
if (process.argv.at(-1) === 'version') {
|
76
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
77
|
+
process.exit(0)
|
78
|
+
}
|
79
|
+
|
80
|
+
if (!process.env.PRIVATE_KEY) {
|
81
|
+
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
82
|
+
printUsage()
|
83
|
+
process.exit(1)
|
84
|
+
}
|
11
85
|
try {
|
12
86
|
new ethers.Wallet(process.env.PRIVATE_KEY!)
|
13
87
|
} catch (e) {
|
14
|
-
|
88
|
+
console.error(chalk.bgRed.white('Invalid private key\n'))
|
89
|
+
printUsage()
|
15
90
|
process.exit(1)
|
16
91
|
}
|
17
92
|
|
18
|
-
|
19
|
-
import { startPeer } from "@/net";
|
93
|
+
logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
20
94
|
|
95
|
+
import { Tasks } from "@/tasks";
|
96
|
+
import { startPeer, protocol, peerPool } from "@/net";
|
97
|
+
import { startApiServer } from '@/api';
|
98
|
+
import { Transaction } from './db';
|
99
|
+
import { shortenHash } from './utils';
|
21
100
|
|
22
101
|
async function main() {
|
23
102
|
|
@@ -26,6 +105,39 @@ async function main() {
|
|
26
105
|
const tasks = new Tasks()
|
27
106
|
|
28
107
|
tasks.start();
|
108
|
+
|
109
|
+
startApiServer()
|
110
|
+
|
111
|
+
protocol.on('TransactionStatus', async (payload) => {
|
112
|
+
if (!peerPool.isLeadNode(payload.peerId)) {
|
113
|
+
const peer = peerPool.getPeer(payload.peerId)
|
114
|
+
|
115
|
+
if (!peer) {
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
|
119
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
|
123
|
+
const transaction = await Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } })
|
124
|
+
|
125
|
+
if (!transaction) {
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
|
129
|
+
transaction.sourceStatus = payload.data.sourceStatus
|
130
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash
|
131
|
+
transaction.sourceErrors = payload.data.sourceErrors
|
132
|
+
|
133
|
+
transaction.targetStatus = payload.data.targetStatus
|
134
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash
|
135
|
+
transaction.targetErrors = payload.data.targetErrors
|
136
|
+
|
137
|
+
transaction.status = payload.data.status
|
138
|
+
|
139
|
+
await transaction.save()
|
140
|
+
})
|
29
141
|
}
|
30
142
|
|
31
143
|
main()
|
package/src/net/peer/index.ts
CHANGED
@@ -17,6 +17,7 @@ import KadDHT from "libp2p-kad-dht";
|
|
17
17
|
import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
|
18
18
|
import { protocol } from "@/net";
|
19
19
|
import config from "@/config";
|
20
|
+
import chalk from "chalk";
|
20
21
|
|
21
22
|
const logger = new Logger("Peer");
|
22
23
|
|
@@ -80,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
|
|
80
81
|
},
|
81
82
|
});
|
82
83
|
|
83
|
-
logger.info("Peer ID:", node.peerId.toB58String());
|
84
|
+
logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
|
84
85
|
|
85
86
|
await node.start();
|
86
87
|
|
@@ -88,12 +89,13 @@ export const startPeer = async ({ }: IPeerOptions) => {
|
|
88
89
|
libp2p: node
|
89
90
|
})
|
90
91
|
|
91
|
-
node.on("peer:discovery", (peer) =>
|
92
|
-
logger.log(`Discovered peer ${peer}`)
|
93
|
-
); // peer disc.
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
node.on("peer:discovery", (peer) => {
|
93
|
+
// logger.log(`Discovered peer ${peer}`)
|
94
|
+
}); // peer disc.
|
95
|
+
|
96
|
+
node.connectionManager.on("peer:connect", (connection) => {
|
97
|
+
// logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
|
98
|
+
});
|
97
99
|
|
98
100
|
logger.log("Peer discovery started");
|
99
101
|
|
package/src/net/pool/index.ts
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
import { Event } from "@/types";
|
2
2
|
import config from "@/config";
|
3
|
+
import Logger from "@/logger";
|
4
|
+
import { getAddress } from "ethers/lib/utils";
|
5
|
+
import { shortenHash } from "@/utils";
|
6
|
+
import chalk from "chalk";
|
7
|
+
|
8
|
+
|
9
|
+
const logger = new Logger('PeerPool')
|
3
10
|
|
4
11
|
export interface IPeerInfo {
|
5
12
|
id: string;
|
@@ -75,10 +82,15 @@ export class PeerPool {
|
|
75
82
|
* @emits {@link Event.POOL_PEER_ADDED}
|
76
83
|
*/
|
77
84
|
add(peer?: IPeerInfo) {
|
78
|
-
if (peer && peer.id
|
85
|
+
if (peer && peer.id) {
|
86
|
+
const newPeer = !this.pool.get(peer.id);
|
79
87
|
this.pool.set(peer.id, peer)
|
80
88
|
peer.pooled = true
|
81
|
-
|
89
|
+
|
90
|
+
if (newPeer) {
|
91
|
+
config.events.emit(Event.POOL_PEER_ADDED, peer)
|
92
|
+
logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
|
93
|
+
}
|
82
94
|
}
|
83
95
|
}
|
84
96
|
|
@@ -92,6 +104,7 @@ export class PeerPool {
|
|
92
104
|
if (this.pool.delete(peer.id)) {
|
93
105
|
peer.pooled = false
|
94
106
|
config.events.emit(Event.POOL_PEER_REMOVED, peer)
|
107
|
+
logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
|
95
108
|
}
|
96
109
|
}
|
97
110
|
}
|
@@ -100,7 +113,7 @@ export class PeerPool {
|
|
100
113
|
this.cleanup()
|
101
114
|
|
102
115
|
return this.peers.filter((p) => {
|
103
|
-
if(!p.pooled) return false;
|
116
|
+
if (!p.pooled) return false;
|
104
117
|
|
105
118
|
const now = new Date()
|
106
119
|
|
@@ -112,16 +125,33 @@ export class PeerPool {
|
|
112
125
|
return this.activePeers.map((p) => p.id)
|
113
126
|
}
|
114
127
|
|
128
|
+
getPeer(id: string){
|
129
|
+
return this.pool.get(id);
|
130
|
+
}
|
115
131
|
|
116
|
-
|
117
|
-
|
132
|
+
isLeadNode(id: string) {
|
133
|
+
const peer = this.pool.get(id);
|
118
134
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
135
|
+
if (!peer) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
|
139
|
+
return getAddress(peer.publicAddress) === getAddress(config.leadNodeAddress)
|
140
|
+
}
|
141
|
+
|
142
|
+
getLeadPeer() {
|
143
|
+
return this.peers.find((p) => this.isLeadNode(p.id))
|
144
|
+
}
|
145
|
+
|
146
|
+
cleanup() {
|
147
|
+
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
148
|
+
|
149
|
+
// this.peers.forEach((peerInfo) => {
|
150
|
+
// if (peerInfo.updated.getTime() < compDate) {
|
151
|
+
// console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
|
152
|
+
// this.remove(peerInfo)
|
153
|
+
// }
|
154
|
+
// })
|
125
155
|
}
|
126
156
|
}
|
127
157
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import { signGnosisSafeTx } from "@/utils";
|
2
1
|
import { BaseDialProtocol } from "./BaseDialProtocol";
|
3
2
|
import wait from "waait";
|
4
|
-
import { ChainId } from "@/types";
|
5
3
|
import config from "@/config";
|
4
|
+
import { Transaction } from "@/db";
|
5
|
+
import { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
|
6
6
|
import { addresses } from "@/constants";
|
7
|
-
import {
|
7
|
+
import { ChainId } from "@/types";
|
8
8
|
|
9
9
|
export interface ISignatureRequest {
|
10
|
-
type:
|
11
|
-
|
10
|
+
type: 'source' | 'target' ,
|
11
|
+
transactionHash: string
|
12
12
|
safeTxGas: string
|
13
13
|
safeNonce: string
|
14
14
|
}
|
@@ -21,25 +21,25 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
21
21
|
protected timeout = 30000;
|
22
22
|
|
23
23
|
constructor(libp2p) {
|
24
|
-
super(libp2p, '/signatures')
|
24
|
+
super(libp2p, '/interop-x/signatures')
|
25
25
|
}
|
26
26
|
|
27
27
|
async response(data: ISignatureRequest): Promise<ISignatureResponse> {
|
28
28
|
const signer = config.wallet;
|
29
29
|
|
30
|
-
let
|
30
|
+
let transaction: Transaction | null;
|
31
31
|
let maxTimeout = 20000;
|
32
32
|
|
33
33
|
do {
|
34
|
-
|
34
|
+
transaction = await Transaction.findOne({ where: { transactionHash: data.transactionHash } })
|
35
35
|
|
36
|
-
if (!
|
36
|
+
if (!transaction) {
|
37
37
|
await wait(1000);
|
38
38
|
maxTimeout -= 1000;
|
39
39
|
}
|
40
|
-
} while (!
|
40
|
+
} while (!transaction && maxTimeout > 0)
|
41
41
|
|
42
|
-
if (!
|
42
|
+
if (!transaction) {
|
43
43
|
return {
|
44
44
|
signer: signer.address,
|
45
45
|
data: null,
|
@@ -47,16 +47,25 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
47
47
|
};
|
48
48
|
}
|
49
49
|
|
50
|
+
console.log("signing:", {
|
51
|
+
to: addresses[transaction.targetChainId].multisend,
|
52
|
+
data: await buildDataForTransaction(transaction, data.type),
|
53
|
+
chainId: transaction.targetChainId as ChainId,
|
54
|
+
safeTxGas: data.safeTxGas,
|
55
|
+
nonce: data.safeNonce,
|
56
|
+
});
|
57
|
+
|
50
58
|
const signedData = await signGnosisSafeTx({
|
51
|
-
to: addresses[
|
52
|
-
data:
|
53
|
-
chainId:
|
59
|
+
to: addresses[transaction.targetChainId].multisend,
|
60
|
+
data: await buildDataForTransaction(transaction, data.type),
|
61
|
+
chainId: transaction.targetChainId as ChainId,
|
54
62
|
safeTxGas: data.safeTxGas,
|
63
|
+
nonce: data.safeNonce,
|
55
64
|
}, { signer });
|
56
65
|
|
57
66
|
return {
|
58
67
|
signer: signer.address,
|
59
|
-
data: signedData
|
68
|
+
data: signedData
|
60
69
|
}
|
61
70
|
}
|
62
71
|
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { BaseDialProtocol } from "./BaseDialProtocol";
|
2
|
+
import { Transaction } from "@/db";
|
3
|
+
|
4
|
+
export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
|
5
|
+
protected timeout = 30000;
|
6
|
+
|
7
|
+
constructor(libp2p) {
|
8
|
+
super(libp2p, '/interop-x/transaction-status')
|
9
|
+
}
|
10
|
+
|
11
|
+
async response(transactionHash: string){
|
12
|
+
const transaction = await Transaction.findOne({ where: { transactionHash } })
|
13
|
+
|
14
|
+
if(! transaction){
|
15
|
+
return null
|
16
|
+
}
|
17
|
+
return {
|
18
|
+
transactionHash: transaction.transactionHash,
|
19
|
+
|
20
|
+
sourceStatus: transaction.sourceStatus,
|
21
|
+
sourceTransactionHash: transaction.sourceTransactionHash,
|
22
|
+
sourceErrors: transaction.sourceErrors,
|
23
|
+
|
24
|
+
targetStatus: transaction.targetStatus,
|
25
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
26
|
+
targetErrors: transaction.targetErrors,
|
27
|
+
|
28
|
+
status: transaction.status,
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|