@instadapp/interop-x 0.0.0-dev.0b0cc3f → 0.0.0-dev.11d690f
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/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +2 -4
- package/dist/src/abi/interopXContract.json +391 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +36 -0
- package/dist/src/config/index.js +31 -0
- package/dist/{constants → src/constants}/addresses.js +3 -11
- package/dist/{constants → src/constants}/index.js +1 -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 +0 -0
- package/dist/{db → src/db}/models/transaction.js +28 -8
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +41 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +119 -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 +21 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +147 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +87 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +38 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropXContract.js} +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
- package/dist/src/typechain/factories/index.js +12 -0
- package/dist/{typechain → src/typechain}/index.js +3 -5
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +168 -0
- package/package.json +13 -19
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +391 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +17 -1
- package/src/constants/addresses.ts +3 -11
- package/src/constants/index.ts +1 -0
- package/src/constants/tokens.ts +104 -0
- package/src/db/models/transaction.ts +70 -21
- package/src/db/sequelize.ts +2 -1
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +56 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +107 -7
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +211 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +119 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +24 -5
- package/src/typechain/InteropXContract.ts +524 -0
- package/src/typechain/factories/InteropXContract__factory.ts +533 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +119 -8
- package/tsconfig.json +7 -2
- package/dist/abi/interopBridgeToken.json +0 -286
- package/dist/abi/interopXGateway.json +0 -184
- package/dist/config/index.js +0 -17
- package/dist/index.js +0 -43
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
- package/dist/tasks/index.js +0 -27
- package/dist/typechain/InteropXGateway.js +0 -2
- package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
- package/dist/typechain/factories/index.js +0 -14
- package/dist/utils/index.js +0 -101
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
package/src/api/index.ts
ADDED
@@ -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
|
+
}
|
package/src/config/index.ts
CHANGED
@@ -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
|
@@ -7,18 +9,32 @@ class Config {
|
|
7
9
|
public readonly leadNodeAddress: string
|
8
10
|
public readonly privateKey: string
|
9
11
|
public readonly wallet: Wallet
|
12
|
+
public readonly staging: boolean
|
13
|
+
public readonly autoUpdate: boolean
|
14
|
+
public readonly baseConfigPath: string
|
10
15
|
|
11
16
|
constructor() {
|
12
17
|
this.events = new EventBus() as EventBusType
|
13
|
-
this.maxPeers =
|
18
|
+
this.maxPeers = 20
|
14
19
|
this.privateKey = process.env.PRIVATE_KEY as string;
|
20
|
+
this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
|
21
|
+
this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
15
22
|
this.wallet = new Wallet(this.privateKey);
|
16
23
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
|
24
|
+
this.baseConfigPath = expandHomeDir(`~/.interop-x`);
|
25
|
+
}
|
26
|
+
|
27
|
+
get publicAddress(){
|
28
|
+
return this.wallet.address
|
17
29
|
}
|
18
30
|
|
19
31
|
isLeadNode() {
|
20
32
|
return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
|
21
33
|
}
|
34
|
+
|
35
|
+
isMaintenanceMode(){
|
36
|
+
return fs.existsSync(this.baseConfigPath + '/maintenance')
|
37
|
+
}
|
22
38
|
}
|
23
39
|
|
24
40
|
export default new Config()
|
@@ -2,24 +2,16 @@ export const addresses = {
|
|
2
2
|
1: {
|
3
3
|
gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
|
4
4
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
5
|
-
|
6
|
-
interopBridgeTokens: [],
|
5
|
+
interopXContract: '',
|
7
6
|
},
|
8
7
|
137: {
|
9
8
|
gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
|
10
9
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
11
|
-
|
12
|
-
interopBridgeTokens: [
|
13
|
-
{
|
14
|
-
address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
|
15
|
-
symbol : 'USDC',
|
16
|
-
}
|
17
|
-
],
|
10
|
+
interopXContract: '0x2189741c8cAc1cf51570932817A7d6390646C80e',
|
18
11
|
},
|
19
12
|
43114: {
|
20
13
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
21
14
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
22
|
-
|
23
|
-
interopBridgeTokens: [],
|
15
|
+
interopXContract: '0x1867DF97Ec24bb0bbD4AD464F0Be9C6713422EAE',
|
24
16
|
}
|
25
17
|
}
|
package/src/constants/index.ts
CHANGED
@@ -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
|
+
};
|
@@ -1,38 +1,68 @@
|
|
1
1
|
import { sequelize } from '@/db/sequelize'
|
2
2
|
import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
|
3
3
|
|
4
|
+
export interface IPositionTokenInfo{
|
5
|
+
amount: string;
|
6
|
+
sourceToken: string;
|
7
|
+
targetToken: string;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface IPosition {
|
11
|
+
supply: IPositionTokenInfo[];
|
12
|
+
withdraw: IPositionTokenInfo[];
|
13
|
+
}
|
14
|
+
|
4
15
|
export class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
|
5
16
|
declare id: CreationOptional<number>;
|
6
17
|
|
7
18
|
declare transactionHash: string;
|
8
|
-
|
9
|
-
declare
|
10
|
-
declare
|
19
|
+
|
20
|
+
declare action: string;
|
21
|
+
declare bridger: string;
|
22
|
+
declare requestTransactionHash: string;
|
11
23
|
|
24
|
+
declare requestBlockNumber: number;
|
12
25
|
|
13
26
|
declare sourceChainId: number;
|
14
|
-
declare sourceTransactionHash: string
|
15
|
-
declare sourceBlockNumber: number
|
16
|
-
declare sourceStatus: string
|
27
|
+
declare sourceTransactionHash: CreationOptional<string>;
|
28
|
+
declare sourceBlockNumber: CreationOptional<number>;
|
29
|
+
declare sourceStatus: CreationOptional<string>;
|
17
30
|
declare sourceErrors: CreationOptional<string[]>;
|
31
|
+
declare sourceLogs: CreationOptional<any[]>;
|
18
32
|
declare sourceCreatedAt: CreationOptional<Date>;
|
19
33
|
declare sourceDelayUntil: CreationOptional<Date>;
|
20
34
|
|
21
35
|
declare targetChainId: number;
|
22
36
|
declare targetTransactionHash: CreationOptional<string>;
|
23
37
|
declare targetBlockNumber: CreationOptional<number>;
|
24
|
-
declare targetStatus: string
|
38
|
+
declare targetStatus: CreationOptional<string>;
|
25
39
|
declare targetErrors: CreationOptional<string[]>;
|
40
|
+
declare targetLogs: CreationOptional<any[]>;
|
26
41
|
declare targetCreatedAt: CreationOptional<Date>;
|
27
42
|
declare targetDelayUntil: CreationOptional<Date>;
|
28
43
|
|
29
|
-
declare
|
30
|
-
|
31
|
-
|
32
|
-
|
44
|
+
declare requestEvent: {
|
45
|
+
bridger: string;
|
46
|
+
metadata: string;
|
47
|
+
position: IPosition;
|
48
|
+
sourceChainId: number;
|
49
|
+
targetChainId: number;
|
50
|
+
};
|
51
|
+
declare requestSentEvent: CreationOptional<{
|
52
|
+
bridger: string;
|
53
|
+
metadata: string;
|
54
|
+
position: IPosition;
|
55
|
+
sourceChainId: number;
|
56
|
+
targetChainId: number;
|
57
|
+
requestTransactionHash: string;
|
58
|
+
}>;
|
59
|
+
declare committedEvent: CreationOptional<any>;
|
60
|
+
declare completedEvent: CreationOptional<any>;
|
61
|
+
|
62
|
+
declare position: any;
|
33
63
|
declare metadata: CreationOptional<any>;
|
34
64
|
|
35
|
-
declare status: string
|
65
|
+
declare status: CreationOptional<string>;
|
36
66
|
|
37
67
|
declare createdAt: CreationOptional<Date>;
|
38
68
|
declare updatedAt: CreationOptional<Date>;
|
@@ -45,21 +75,28 @@ Transaction.init({
|
|
45
75
|
primaryKey: true
|
46
76
|
},
|
47
77
|
|
78
|
+
requestTransactionHash: DataTypes.NUMBER,
|
79
|
+
requestBlockNumber: DataTypes.NUMBER,
|
48
80
|
|
49
81
|
transactionHash: DataTypes.STRING,
|
50
|
-
|
51
|
-
|
52
|
-
from: DataTypes.STRING,
|
53
|
-
to: DataTypes.STRING,
|
82
|
+
action: DataTypes.STRING,
|
83
|
+
bridger: DataTypes.STRING,
|
54
84
|
|
55
85
|
sourceChainId: DataTypes.NUMBER,
|
56
86
|
sourceTransactionHash: DataTypes.STRING,
|
57
87
|
sourceBlockNumber: DataTypes.NUMBER,
|
58
|
-
sourceStatus:
|
88
|
+
sourceStatus: {
|
89
|
+
type: DataTypes.STRING,
|
90
|
+
defaultValue: 'uninitialised'
|
91
|
+
},
|
59
92
|
sourceErrors: {
|
60
93
|
type: DataTypes.JSON,
|
61
94
|
// defaultValue: [],
|
62
95
|
},
|
96
|
+
sourceLogs: {
|
97
|
+
type: DataTypes.JSON,
|
98
|
+
// defaultValue: [],
|
99
|
+
},
|
63
100
|
sourceCreatedAt: {
|
64
101
|
type: DataTypes.DATE,
|
65
102
|
defaultValue: Date.now()
|
@@ -69,18 +106,30 @@ Transaction.init({
|
|
69
106
|
targetChainId: DataTypes.NUMBER,
|
70
107
|
targetTransactionHash: DataTypes.STRING,
|
71
108
|
targetBlockNumber: DataTypes.NUMBER,
|
72
|
-
targetStatus:
|
109
|
+
targetStatus: {
|
110
|
+
type: DataTypes.STRING,
|
111
|
+
defaultValue: 'uninitialised'
|
112
|
+
},
|
73
113
|
targetErrors: {
|
74
114
|
type: DataTypes.JSON,
|
75
115
|
// defaultValue: [],
|
76
116
|
},
|
117
|
+
targetLogs: {
|
118
|
+
type: DataTypes.JSON,
|
119
|
+
// defaultValue: [],
|
120
|
+
},
|
77
121
|
targetCreatedAt: DataTypes.DATE,
|
78
122
|
targetDelayUntil: DataTypes.DATE,
|
79
123
|
|
80
|
-
|
81
|
-
|
82
|
-
|
124
|
+
requestEvent: {
|
125
|
+
type: DataTypes.JSON,
|
126
|
+
allowNull: false
|
127
|
+
},
|
128
|
+
requestSentEvent: DataTypes.JSON,
|
129
|
+
committedEvent: DataTypes.JSON,
|
130
|
+
completedEvent: DataTypes.JSON,
|
83
131
|
|
132
|
+
position: DataTypes.JSON,
|
84
133
|
metadata: DataTypes.JSON,
|
85
134
|
|
86
135
|
status: {
|
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',
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import abi from "@/abi";
|
2
|
+
import config from "@/config";
|
3
|
+
import { addresses, tokens } from "@/constants";
|
4
|
+
import { Transaction } from "@/db";
|
5
|
+
import { InteropXContract } 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 (type !== 'source') {
|
20
|
+
throw new Error(`Type not supported: ${type}`)
|
21
|
+
}
|
22
|
+
|
23
|
+
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
24
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!transaction.requestEvent) {
|
28
|
+
throw Error('Cannot build data for transaction without requestEvent');
|
29
|
+
}
|
30
|
+
|
31
|
+
const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
|
32
|
+
|
33
|
+
const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
|
34
|
+
const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
|
35
|
+
const contractAddress = addresses[sourceChainId].interopXContract;
|
36
|
+
const contract = getContract<InteropXContract>(contractAddress, abi.interopXContract, sourceWallet);
|
37
|
+
|
38
|
+
const { data } = await contract.populateTransaction.withdrawRequested(
|
39
|
+
bridger,
|
40
|
+
position.withdraw[0].sourceToken,
|
41
|
+
position.withdraw[0].targetToken,
|
42
|
+
position.withdraw[0].amount,
|
43
|
+
targetChainId,
|
44
|
+
transaction.requestTransactionHash,
|
45
|
+
metadata,
|
46
|
+
);
|
47
|
+
|
48
|
+
transactions.push({
|
49
|
+
to: contractAddress,
|
50
|
+
data: data!,
|
51
|
+
value: '0',
|
52
|
+
operation: OperationType.Call,
|
53
|
+
});
|
54
|
+
|
55
|
+
return { transactions, logs }
|
56
|
+
}
|
@@ -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 === 'success' ? 'target' : 'source')
|
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
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,24 +1,87 @@
|
|
1
|
-
import '
|
2
|
-
import
|
1
|
+
import './alias'
|
2
|
+
import expandHomeDir from "expand-home-dir";
|
3
|
+
import fs from 'fs-extra'
|
4
|
+
|
3
5
|
import dotenv from "dotenv";
|
6
|
+
import chalk from 'chalk';
|
4
7
|
import { ethers } from "ethers";
|
8
|
+
import packageJson from '../package.json'
|
5
9
|
dotenv.config();
|
6
10
|
|
7
11
|
import Logger from "@/logger";
|
8
12
|
const logger = new Logger('Process')
|
9
13
|
|
10
|
-
|
14
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
15
|
+
|
16
|
+
const printUsage = () => {
|
17
|
+
console.log()
|
18
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
19
|
+
console.log()
|
20
|
+
|
21
|
+
console.log('Usage:')
|
22
|
+
console.log(' interop-x help Show this message')
|
23
|
+
console.log(' interop-x version Print out the installed version of Interop X')
|
24
|
+
|
25
|
+
console.log()
|
26
|
+
|
27
|
+
console.log(' interop-x down Put the node into maintenance mode')
|
28
|
+
console.log(' interop-x up Take the node out of maintenance mode')
|
29
|
+
|
30
|
+
console.log()
|
31
|
+
|
32
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
|
33
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
|
34
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
|
35
|
+
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')
|
36
|
+
console.log()
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
if (process.argv.at(-1) === 'help') {
|
41
|
+
printUsage()
|
42
|
+
process.exit(0)
|
43
|
+
}
|
44
|
+
|
45
|
+
const basePath = expandHomeDir(`~/.interop-x`);
|
46
|
+
|
47
|
+
if (process.argv.at(-1) === 'down') {
|
48
|
+
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
49
|
+
console.log(chalk.red('Maintenance mode enabled'))
|
50
|
+
process.exit(0)
|
51
|
+
}
|
52
|
+
|
53
|
+
if (process.argv.at(-1) === 'up') {
|
54
|
+
fs.removeSync(basePath + '/maintenance')
|
55
|
+
console.log(chalk.green('Maintenance mode disabled'))
|
56
|
+
process.exit(0)
|
57
|
+
}
|
11
58
|
|
59
|
+
|
60
|
+
if (process.argv.at(-1) === 'version') {
|
61
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
62
|
+
process.exit(0)
|
63
|
+
}
|
64
|
+
|
65
|
+
if (!process.env.PRIVATE_KEY) {
|
66
|
+
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
67
|
+
printUsage()
|
68
|
+
process.exit(1)
|
69
|
+
}
|
12
70
|
try {
|
13
71
|
new ethers.Wallet(process.env.PRIVATE_KEY!)
|
14
72
|
} catch (e) {
|
15
|
-
|
73
|
+
console.error(chalk.bgRed.white('Invalid private key\n'))
|
74
|
+
printUsage()
|
16
75
|
process.exit(1)
|
17
76
|
}
|
18
77
|
|
19
|
-
|
20
|
-
import { startPeer } from "@/net";
|
78
|
+
logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
21
79
|
|
80
|
+
import { Tasks } from "@/tasks";
|
81
|
+
import { startPeer, protocol, peerPool } from "@/net";
|
82
|
+
import { startApiServer } from '@/api';
|
83
|
+
import { Transaction } from './db';
|
84
|
+
import { shortenHash } from './utils';
|
22
85
|
|
23
86
|
async function main() {
|
24
87
|
|
@@ -26,7 +89,44 @@ async function main() {
|
|
26
89
|
|
27
90
|
const tasks = new Tasks()
|
28
91
|
|
29
|
-
|
92
|
+
setTimeout(() => {
|
93
|
+
tasks.start();
|
94
|
+
}, 10000)
|
95
|
+
|
96
|
+
startApiServer()
|
97
|
+
|
98
|
+
protocol.on('TransactionStatus', async (payload) => {
|
99
|
+
if (!peerPool.isLeadNode(payload.peerId)) {
|
100
|
+
const peer = peerPool.getPeer(payload.peerId)
|
101
|
+
|
102
|
+
if (!peer) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
|
106
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
|
110
|
+
const transaction = await Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } })
|
111
|
+
|
112
|
+
if (!transaction) {
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
|
116
|
+
transaction.sourceStatus = payload.data.sourceStatus
|
117
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash
|
118
|
+
transaction.sourceErrors = payload.data.sourceErrors
|
119
|
+
transaction.sourceLogs = payload.data.sourceLogs
|
120
|
+
|
121
|
+
transaction.targetStatus = payload.data.targetStatus
|
122
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash
|
123
|
+
transaction.targetErrors = payload.data.targetErrors
|
124
|
+
transaction.targetLogs = payload.data.targetLogs
|
125
|
+
|
126
|
+
transaction.status = payload.data.status
|
127
|
+
|
128
|
+
await transaction.save()
|
129
|
+
})
|
30
130
|
}
|
31
131
|
|
32
132
|
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
|
|