@instadapp/interop-x 0.0.0-dev.0ee2ee3 → 0.0.0-dev.234b8be
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.
- package/.env.example +2 -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 +286 -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 +120 -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 +15 -6
- package/dist/{net → src/net}/pool/index.js +34 -11
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
- package/dist/src/net/protocol/dial/SignatureDialProtocol.1.js +28 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +22 -14
- package/dist/{net → src/net}/protocol/index.js +44 -4
- package/dist/src/tasks/AutoUpdateTask.js +69 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +14 -6
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -0
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +69 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +149 -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 +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/src/utils/index.js +238 -0
- package/package.json +21 -7
- 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 +286 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +18 -2
- package/src/constants/addresses.ts +10 -3
- 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 +112 -6
- package/src/net/peer/index.ts +17 -9
- package/src/net/pool/index.ts +43 -13
- package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
- package/src/net/protocol/dial/SignatureDialProtocol.1.ts +31 -0
- package/src/net/protocol/dial/SignatureDialProtocol.ts +26 -17
- package/src/net/protocol/index.ts +61 -5
- package/src/tasks/AutoUpdateTask.ts +80 -0
- package/src/tasks/BaseTask.ts +16 -7
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +119 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +243 -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 +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 +207 -4
- package/tsconfig.json +3 -0
- 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 -34
- 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/index.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from "./models"
|
1
|
+
export * from "./models"
|
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,14 +1,87 @@
|
|
1
|
-
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();
|
2
20
|
import dotenv from "dotenv";
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
21
|
+
import chalk from 'chalk';
|
22
|
+
import { ethers } from "ethers";
|
23
|
+
import packageJson from '../package.json'
|
6
24
|
dotenv.config();
|
7
25
|
|
8
|
-
|
9
|
-
|
26
|
+
import Logger from "@/logger";
|
10
27
|
const logger = new Logger('Process')
|
11
28
|
|
29
|
+
const printUsage = () => {
|
30
|
+
console.log('Usage:')
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x')
|
32
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
|
33
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x')
|
34
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
|
35
|
+
}
|
36
|
+
|
37
|
+
if (process.argv.at(-1) === 'help') {
|
38
|
+
printUsage()
|
39
|
+
process.exit(0)
|
40
|
+
}
|
41
|
+
|
42
|
+
const basePath = expandHomeDir(`~/.interop-x`);
|
43
|
+
|
44
|
+
if (process.argv.at(-1) === 'down') {
|
45
|
+
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
46
|
+
console.log(chalk.red('Maintenance mode enabled'))
|
47
|
+
process.exit(0)
|
48
|
+
}
|
49
|
+
|
50
|
+
if (process.argv.at(-1) === 'up') {
|
51
|
+
fs.removeSync(basePath + '/maintenance')
|
52
|
+
console.log(chalk.green('Maintenance mode disabled'))
|
53
|
+
process.exit(0)
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
58
|
+
|
59
|
+
if (process.argv.at(-1) === 'version') {
|
60
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
61
|
+
process.exit(0)
|
62
|
+
}
|
63
|
+
|
64
|
+
if (!process.env.PRIVATE_KEY) {
|
65
|
+
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
66
|
+
printUsage()
|
67
|
+
process.exit(1)
|
68
|
+
}
|
69
|
+
try {
|
70
|
+
new ethers.Wallet(process.env.PRIVATE_KEY!)
|
71
|
+
} catch (e) {
|
72
|
+
console.error(chalk.bgRed.white('Invalid private key\n'))
|
73
|
+
printUsage()
|
74
|
+
process.exit(1)
|
75
|
+
}
|
76
|
+
|
77
|
+
logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
78
|
+
|
79
|
+
import { Tasks } from "@/tasks";
|
80
|
+
import { startPeer, protocol, peerPool } from "@/net";
|
81
|
+
import { startApiServer } from '@/api';
|
82
|
+
import { Transaction } from './db';
|
83
|
+
import { shortenHash } from './utils';
|
84
|
+
|
12
85
|
async function main() {
|
13
86
|
|
14
87
|
startPeer({})
|
@@ -16,6 +89,39 @@ async function main() {
|
|
16
89
|
const tasks = new Tasks()
|
17
90
|
|
18
91
|
tasks.start();
|
92
|
+
|
93
|
+
startApiServer()
|
94
|
+
|
95
|
+
protocol.on('TransactionStatus', async (payload) => {
|
96
|
+
if (!peerPool.isLeadNode(payload.peerId)) {
|
97
|
+
const peer = peerPool.getPeer(payload.peerId)
|
98
|
+
|
99
|
+
if (!peer) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
|
103
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
|
107
|
+
const transaction = await Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } })
|
108
|
+
|
109
|
+
if (!transaction) {
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
transaction.sourceStatus = payload.data.sourceStatus
|
114
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash
|
115
|
+
transaction.sourceErrors = payload.data.sourceErrors
|
116
|
+
|
117
|
+
transaction.targetStatus = payload.data.targetStatus
|
118
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash
|
119
|
+
transaction.targetErrors = payload.data.targetErrors
|
120
|
+
|
121
|
+
transaction.status = payload.data.status
|
122
|
+
|
123
|
+
await transaction.save()
|
124
|
+
})
|
19
125
|
}
|
20
126
|
|
21
127
|
main()
|
package/src/net/peer/index.ts
CHANGED
@@ -5,7 +5,7 @@ import WS from "libp2p-websockets";
|
|
5
5
|
//@ts-ignore
|
6
6
|
import Mplex from "libp2p-mplex";
|
7
7
|
import { NOISE } from "libp2p-noise";
|
8
|
-
import Logger from "
|
8
|
+
import Logger from "@/logger";
|
9
9
|
import Bootstrap from "libp2p-bootstrap";
|
10
10
|
import wait from "waait";
|
11
11
|
import Gossipsub from "@achingbrain/libp2p-gossipsub";
|
@@ -15,7 +15,9 @@ import MulticastDNS from "libp2p-mdns";
|
|
15
15
|
import KadDHT from "libp2p-kad-dht";
|
16
16
|
//@ts-ignore
|
17
17
|
import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
|
18
|
-
import { protocol } from "
|
18
|
+
import { protocol } from "@/net";
|
19
|
+
import config from "@/config";
|
20
|
+
import chalk from "chalk";
|
19
21
|
|
20
22
|
const logger = new Logger("Peer");
|
21
23
|
|
@@ -79,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
|
|
79
81
|
},
|
80
82
|
});
|
81
83
|
|
82
|
-
logger.info("Peer ID:", node.peerId.toB58String());
|
84
|
+
logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
|
83
85
|
|
84
86
|
await node.start();
|
85
87
|
|
@@ -87,16 +89,22 @@ export const startPeer = async ({ }: IPeerOptions) => {
|
|
87
89
|
libp2p: node
|
88
90
|
})
|
89
91
|
|
90
|
-
node.on("peer:discovery", (peer) =>
|
91
|
-
logger.log(`Discovered peer ${peer}`)
|
92
|
-
); // peer disc.
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
+
});
|
96
99
|
|
97
100
|
logger.log("Peer discovery started");
|
98
101
|
|
99
102
|
await wait(1000);
|
103
|
+
|
104
|
+
|
105
|
+
setInterval(() => protocol.sendPeerInfo({
|
106
|
+
publicAddress: config.wallet.address,
|
107
|
+
}), 5000)
|
100
108
|
};
|
101
109
|
|
102
110
|
export const stopPeer = async () => {
|
package/src/net/pool/index.ts
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
import { Event } from "
|
2
|
-
import config from "
|
1
|
+
import { Event } from "@/types";
|
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,7 +1,7 @@
|
|
1
1
|
import pipe from 'it-pipe';
|
2
2
|
import Libp2p from 'libp2p';
|
3
3
|
import PeerId from 'peer-id';
|
4
|
-
import { asyncCallWithTimeout } from '
|
4
|
+
import { asyncCallWithTimeout } from '@/utils';
|
5
5
|
import wait from 'waait';
|
6
6
|
|
7
7
|
export class BaseDialProtocol<TRequest extends any, TResponse extends any> {
|
@@ -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
|
+
}
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import { signGnosisSafeTx } from "../../../utils";
|
2
1
|
import { BaseDialProtocol } from "./BaseDialProtocol";
|
3
2
|
import wait from "waait";
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import {
|
7
|
-
import {
|
3
|
+
import config from "@/config";
|
4
|
+
import { Transaction } from "@/db";
|
5
|
+
import { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
|
6
|
+
import { addresses } from "@/constants";
|
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
|
}
|