@instadapp/interop-x 0.0.0-dev.b70f25f → 0.0.0-dev.bfeca30
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/dist/package.json +14 -13
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +31 -1
- package/dist/src/db/models/transaction.js +27 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +55 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +34 -22
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
- package/dist/src/net/protocol/index.js +17 -7
- package/dist/src/tasks/AutoUpdateTask.js +34 -12
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +54 -51
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +92 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
- package/dist/src/tasks/index.js +16 -19
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +37 -89
- package/package.json +14 -13
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +3 -0
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +32 -2
- package/src/db/models/transaction.ts +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +77 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +47 -26
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
- package/src/net/protocol/index.ts +17 -7
- package/src/tasks/AutoUpdateTask.ts +36 -15
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +79 -94
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +124 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +21 -20
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +75 -126
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -69
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -119
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -243
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- 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
@@ -1,40 +1,75 @@
|
|
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 actionId: string;
|
21
|
+
declare bridger: string;
|
22
|
+
declare requestTransactionHash: string;
|
11
23
|
|
12
|
-
declare
|
13
|
-
declare submitBlockNumber: number;
|
24
|
+
declare requestBlockNumber: number;
|
14
25
|
|
15
26
|
declare sourceChainId: number;
|
16
27
|
declare sourceTransactionHash: CreationOptional<string>;
|
17
28
|
declare sourceBlockNumber: CreationOptional<number>;
|
18
|
-
declare sourceStatus: string
|
29
|
+
declare sourceStatus: CreationOptional<string>;
|
19
30
|
declare sourceErrors: CreationOptional<string[]>;
|
31
|
+
declare sourceLogs: CreationOptional<any[]>;
|
20
32
|
declare sourceCreatedAt: CreationOptional<Date>;
|
21
33
|
declare sourceDelayUntil: CreationOptional<Date>;
|
22
34
|
|
23
35
|
declare targetChainId: number;
|
24
36
|
declare targetTransactionHash: CreationOptional<string>;
|
25
37
|
declare targetBlockNumber: CreationOptional<number>;
|
26
|
-
declare targetStatus: string
|
38
|
+
declare targetStatus: CreationOptional<string>;
|
27
39
|
declare targetErrors: CreationOptional<string[]>;
|
40
|
+
declare targetLogs: CreationOptional<any[]>;
|
28
41
|
declare targetCreatedAt: CreationOptional<Date>;
|
29
42
|
declare targetDelayUntil: CreationOptional<Date>;
|
30
43
|
|
31
|
-
declare
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
declare requestEvent: {
|
45
|
+
actionId: string;
|
46
|
+
bridger: string;
|
47
|
+
metadata: string;
|
48
|
+
position: IPosition;
|
49
|
+
sourceChainId: number;
|
50
|
+
targetChainId: number;
|
51
|
+
};
|
52
|
+
declare requestSentEvent: CreationOptional<{
|
53
|
+
actionId: string;
|
54
|
+
bridger: string;
|
55
|
+
metadata: string;
|
56
|
+
position: IPosition;
|
57
|
+
sourceChainId: number;
|
58
|
+
targetChainId: number;
|
59
|
+
requestTransactionHash: string;
|
60
|
+
}>;
|
61
|
+
declare committedEvent: CreationOptional<{
|
62
|
+
actionId: string;
|
63
|
+
bridger: string;
|
64
|
+
metadata: string;
|
65
|
+
position: IPosition;
|
66
|
+
sourceChainId: number;
|
67
|
+
targetChainId: number;
|
68
|
+
requestTransactionHash: string;
|
69
|
+
}>;
|
70
|
+
declare completedEvent: CreationOptional<any>;
|
71
|
+
|
72
|
+
declare status: CreationOptional<string>;
|
38
73
|
|
39
74
|
declare createdAt: CreationOptional<Date>;
|
40
75
|
declare updatedAt: CreationOptional<Date>;
|
@@ -47,23 +82,28 @@ Transaction.init({
|
|
47
82
|
primaryKey: true
|
48
83
|
},
|
49
84
|
|
50
|
-
|
51
|
-
|
85
|
+
requestTransactionHash: DataTypes.NUMBER,
|
86
|
+
requestBlockNumber: DataTypes.NUMBER,
|
52
87
|
|
53
88
|
transactionHash: DataTypes.STRING,
|
54
|
-
|
55
|
-
|
56
|
-
from: DataTypes.STRING,
|
57
|
-
to: DataTypes.STRING,
|
89
|
+
actionId: DataTypes.STRING,
|
90
|
+
bridger: DataTypes.STRING,
|
58
91
|
|
59
92
|
sourceChainId: DataTypes.NUMBER,
|
60
93
|
sourceTransactionHash: DataTypes.STRING,
|
61
94
|
sourceBlockNumber: DataTypes.NUMBER,
|
62
|
-
sourceStatus:
|
95
|
+
sourceStatus: {
|
96
|
+
type: DataTypes.STRING,
|
97
|
+
defaultValue: 'uninitialised'
|
98
|
+
},
|
63
99
|
sourceErrors: {
|
64
100
|
type: DataTypes.JSON,
|
65
101
|
// defaultValue: [],
|
66
102
|
},
|
103
|
+
sourceLogs: {
|
104
|
+
type: DataTypes.JSON,
|
105
|
+
// defaultValue: [],
|
106
|
+
},
|
67
107
|
sourceCreatedAt: {
|
68
108
|
type: DataTypes.DATE,
|
69
109
|
defaultValue: Date.now()
|
@@ -73,19 +113,28 @@ Transaction.init({
|
|
73
113
|
targetChainId: DataTypes.NUMBER,
|
74
114
|
targetTransactionHash: DataTypes.STRING,
|
75
115
|
targetBlockNumber: DataTypes.NUMBER,
|
76
|
-
targetStatus:
|
116
|
+
targetStatus: {
|
117
|
+
type: DataTypes.STRING,
|
118
|
+
defaultValue: 'uninitialised'
|
119
|
+
},
|
77
120
|
targetErrors: {
|
78
121
|
type: DataTypes.JSON,
|
79
122
|
// defaultValue: [],
|
80
123
|
},
|
124
|
+
targetLogs: {
|
125
|
+
type: DataTypes.JSON,
|
126
|
+
// defaultValue: [],
|
127
|
+
},
|
81
128
|
targetCreatedAt: DataTypes.DATE,
|
82
129
|
targetDelayUntil: DataTypes.DATE,
|
83
130
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
131
|
+
requestEvent: {
|
132
|
+
type: DataTypes.JSON,
|
133
|
+
allowNull: false
|
134
|
+
},
|
135
|
+
requestSentEvent: DataTypes.JSON,
|
136
|
+
committedEvent: DataTypes.JSON,
|
137
|
+
completedEvent: DataTypes.JSON,
|
89
138
|
|
90
139
|
status: {
|
91
140
|
type: DataTypes.STRING,
|
@@ -0,0 +1,77 @@
|
|
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.actionId !== 'withdraw') {
|
16
|
+
throw new Error(`Invalid action: ${transaction.actionId}`)
|
17
|
+
}
|
18
|
+
|
19
|
+
if (type !== 'source') {
|
20
|
+
throw new Error(`[WIP] Type not supported: ${type}`)
|
21
|
+
}
|
22
|
+
|
23
|
+
if (transaction.sourceStatus === 'pending') {
|
24
|
+
throw Error('Source transaction already processesing')
|
25
|
+
}
|
26
|
+
|
27
|
+
if (transaction.sourceStatus === 'pending') {
|
28
|
+
throw Error('Source transaction already processed')
|
29
|
+
}
|
30
|
+
|
31
|
+
if (!transaction.requestEvent) {
|
32
|
+
throw Error('Something went wrong, source transaction has no request event')
|
33
|
+
}
|
34
|
+
|
35
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, metadata} = transaction.requestEvent;
|
36
|
+
|
37
|
+
const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
|
38
|
+
const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
|
39
|
+
const contractAddress = addresses[sourceChainId].interopXContract;
|
40
|
+
const contract = getContract<InteropXContract>(contractAddress, abi.interopXContract, sourceWallet);
|
41
|
+
|
42
|
+
const sourceToken = tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
|
43
|
+
|
44
|
+
if (!sourceToken) {
|
45
|
+
throw Error('Source token not found')
|
46
|
+
}
|
47
|
+
|
48
|
+
const targetToken = tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
|
49
|
+
|
50
|
+
if (!targetToken) {
|
51
|
+
throw Error('Target token not found')
|
52
|
+
}
|
53
|
+
|
54
|
+
if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
|
55
|
+
throw Error('Source and target token must be the same')
|
56
|
+
}
|
57
|
+
|
58
|
+
const { data } = await contract.populateTransaction.withdrawRequested(
|
59
|
+
actionId,
|
60
|
+
bridger,
|
61
|
+
position.withdraw[0].sourceToken,
|
62
|
+
position.withdraw[0].targetToken,
|
63
|
+
position.withdraw[0].amount,
|
64
|
+
targetChainId,
|
65
|
+
transaction.requestTransactionHash,
|
66
|
+
metadata,
|
67
|
+
);
|
68
|
+
|
69
|
+
transactions.push({
|
70
|
+
to: contractAddress,
|
71
|
+
data: data!,
|
72
|
+
value: '0',
|
73
|
+
operation: OperationType.Call,
|
74
|
+
});
|
75
|
+
|
76
|
+
return { transactions, logs }
|
77
|
+
}
|
@@ -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.actionId)) {
|
9
|
+
|
10
|
+
const { transactions, logs } = await actions[transaction.actionId](transaction, type);
|
11
|
+
|
12
|
+
return {
|
13
|
+
data: encodeMulti(transactions).data,
|
14
|
+
logs
|
15
|
+
};
|
16
|
+
}
|
17
|
+
|
18
|
+
throw new Error(`Unknown action: ${transaction.actionId}`);
|
19
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
"@/": __dirname + "/",
|
5
|
-
"@/logger": __dirname + "/logger",
|
6
|
-
"@/tasks": __dirname + "/tasks",
|
7
|
-
"@/utils": __dirname + "/utils",
|
8
|
-
"@/api": __dirname + "/api",
|
9
|
-
"@/net": __dirname + "/net",
|
10
|
-
"@/db": __dirname + "/db",
|
11
|
-
"@/config": __dirname + "/config",
|
12
|
-
"@/types": __dirname + "/types",
|
13
|
-
"@/abi": __dirname + "/abi",
|
14
|
-
"@/constants": __dirname + "/constants",
|
15
|
-
"@/typechain": __dirname + "/typechain"
|
16
|
-
})
|
1
|
+
import './alias'
|
2
|
+
import expandHomeDir from "expand-home-dir";
|
3
|
+
import fs from 'fs-extra'
|
17
4
|
|
18
|
-
moduleAlias();
|
19
5
|
import dotenv from "dotenv";
|
20
6
|
import chalk from 'chalk';
|
21
7
|
import { ethers } from "ethers";
|
@@ -25,12 +11,30 @@ dotenv.config();
|
|
25
11
|
import Logger from "@/logger";
|
26
12
|
const logger = new Logger('Process')
|
27
13
|
|
14
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
15
|
+
|
28
16
|
const printUsage = () => {
|
17
|
+
console.log()
|
18
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
19
|
+
console.log()
|
20
|
+
|
29
21
|
console.log('Usage:')
|
30
|
-
console.log('
|
31
|
-
console.log('
|
32
|
-
|
33
|
-
console.log(
|
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
|
+
|
34
38
|
}
|
35
39
|
|
36
40
|
if (process.argv.at(-1) === 'help') {
|
@@ -38,14 +42,27 @@ if (process.argv.at(-1) === 'help') {
|
|
38
42
|
process.exit(0)
|
39
43
|
}
|
40
44
|
|
41
|
-
const
|
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
|
+
}
|
58
|
+
|
42
59
|
|
43
60
|
if (process.argv.at(-1) === 'version') {
|
44
61
|
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
45
62
|
process.exit(0)
|
46
63
|
}
|
47
64
|
|
48
|
-
if(!
|
65
|
+
if (!process.env.PRIVATE_KEY) {
|
49
66
|
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
50
67
|
printUsage()
|
51
68
|
process.exit(1)
|
@@ -72,7 +89,9 @@ async function main() {
|
|
72
89
|
|
73
90
|
const tasks = new Tasks()
|
74
91
|
|
75
|
-
|
92
|
+
setTimeout(() => {
|
93
|
+
tasks.start();
|
94
|
+
}, 10000)
|
76
95
|
|
77
96
|
startApiServer()
|
78
97
|
|
@@ -80,10 +99,10 @@ async function main() {
|
|
80
99
|
if (!peerPool.isLeadNode(payload.peerId)) {
|
81
100
|
const peer = peerPool.getPeer(payload.peerId)
|
82
101
|
|
83
|
-
if(!
|
102
|
+
if (!peer) {
|
84
103
|
return;
|
85
104
|
}
|
86
|
-
|
105
|
+
|
87
106
|
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
88
107
|
return;
|
89
108
|
}
|
@@ -97,10 +116,12 @@ async function main() {
|
|
97
116
|
transaction.sourceStatus = payload.data.sourceStatus
|
98
117
|
transaction.sourceTransactionHash = payload.data.sourceTransactionHash
|
99
118
|
transaction.sourceErrors = payload.data.sourceErrors
|
119
|
+
transaction.sourceLogs = payload.data.sourceLogs
|
100
120
|
|
101
121
|
transaction.targetStatus = payload.data.targetStatus
|
102
122
|
transaction.targetTransactionHash = payload.data.targetTransactionHash
|
103
123
|
transaction.targetErrors = payload.data.targetErrors
|
124
|
+
transaction.targetLogs = payload.data.targetLogs
|
104
125
|
|
105
126
|
transaction.status = payload.data.status
|
106
127
|
|
@@ -2,12 +2,13 @@ import { BaseDialProtocol } from "./BaseDialProtocol";
|
|
2
2
|
import wait from "waait";
|
3
3
|
import config from "@/config";
|
4
4
|
import { Transaction } from "@/db";
|
5
|
-
import {
|
5
|
+
import { signGnosisSafeTx } from "@/utils";
|
6
6
|
import { addresses } from "@/constants";
|
7
7
|
import { ChainId } from "@/types";
|
8
|
+
import { buildGnosisAction } from "@/gnosis";
|
8
9
|
|
9
10
|
export interface ISignatureRequest {
|
10
|
-
type: 'source' | 'target'
|
11
|
+
type: 'source' | 'target',
|
11
12
|
transactionHash: string
|
12
13
|
safeTxGas: string
|
13
14
|
safeNonce: string
|
@@ -25,6 +26,10 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
25
26
|
}
|
26
27
|
|
27
28
|
async response(data: ISignatureRequest): Promise<ISignatureResponse> {
|
29
|
+
console.log({
|
30
|
+
tag: 'SignatureDialProtocol',
|
31
|
+
data
|
32
|
+
})
|
28
33
|
const signer = config.wallet;
|
29
34
|
|
30
35
|
let transaction: Transaction | null;
|
@@ -46,19 +51,12 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
46
51
|
error: 'Event not found'
|
47
52
|
};
|
48
53
|
}
|
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
|
-
});
|
54
|
+
const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
|
57
55
|
|
58
56
|
const signedData = await signGnosisSafeTx({
|
59
|
-
to: addresses[transaction.
|
60
|
-
data:
|
61
|
-
chainId: transaction.
|
57
|
+
to: addresses[transaction.sourceChainId].multisend,
|
58
|
+
data: gnosisData,
|
59
|
+
chainId: transaction.sourceChainId as ChainId,
|
62
60
|
safeTxGas: data.safeTxGas,
|
63
61
|
nonce: data.safeNonce,
|
64
62
|
}, { signer });
|
package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts}
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { BaseDialProtocol } from "./BaseDialProtocol";
|
2
2
|
import { Transaction } from "@/db";
|
3
3
|
|
4
|
-
export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
|
4
|
+
export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
|
5
5
|
protected timeout = 30000;
|
6
6
|
|
7
7
|
constructor(libp2p) {
|
@@ -20,10 +20,12 @@ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick
|
|
20
20
|
sourceStatus: transaction.sourceStatus,
|
21
21
|
sourceTransactionHash: transaction.sourceTransactionHash,
|
22
22
|
sourceErrors: transaction.sourceErrors,
|
23
|
+
sourceLogs: transaction.sourceLogs,
|
23
24
|
|
24
25
|
targetStatus: transaction.targetStatus,
|
25
26
|
targetTransactionHash: transaction.targetTransactionHash,
|
26
27
|
targetErrors: transaction.targetErrors,
|
28
|
+
targetLogs: transaction.targetLogs,
|
27
29
|
|
28
30
|
status: transaction.status,
|
29
31
|
}
|
@@ -6,7 +6,7 @@ import { IPeerInfo, peerPool } from "..";
|
|
6
6
|
import config from "@/config";
|
7
7
|
import { Event } from "@/types";
|
8
8
|
import { Transaction } from "@/db";
|
9
|
-
import { TransactionStatusDialProtocol } from "./dial/
|
9
|
+
import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
|
10
10
|
|
11
11
|
export interface ProtocolOptions {
|
12
12
|
/* Handshake timeout in ms (default: 8000) */
|
@@ -36,7 +36,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
interface TransactionStatusEvent extends BaseMessageEvent {
|
39
|
-
data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
|
39
|
+
data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'>
|
40
40
|
}
|
41
41
|
|
42
42
|
declare interface Protocol {
|
@@ -66,25 +66,35 @@ class Protocol extends EventEmitter {
|
|
66
66
|
Buffer.from(transaction.transactionHash),
|
67
67
|
|
68
68
|
Buffer.from(transaction.sourceStatus),
|
69
|
-
Buffer.from(transaction.sourceTransactionHash),
|
69
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
70
70
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
71
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
71
72
|
|
72
73
|
Buffer.from(transaction.targetStatus),
|
73
|
-
Buffer.from(transaction.targetTransactionHash),
|
74
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
74
75
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
76
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
75
77
|
|
76
78
|
Buffer.from(transaction.status),
|
77
79
|
],
|
78
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]: [Buffer, Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer[], Buffer]) => ({
|
80
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]: [Buffer, Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer]) => ({
|
79
81
|
transactionHash: transactionHash.toString(),
|
80
82
|
|
81
83
|
sourceStatus: sourceStatus.toString(),
|
82
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
84
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
83
85
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
86
|
+
sourceLogs: sourceLogs.map(e => ({
|
87
|
+
type: e[0].toString(),
|
88
|
+
message: e[1].toString(),
|
89
|
+
})),
|
84
90
|
|
85
91
|
targetStatus: targetStatus.toString(),
|
86
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
92
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
87
93
|
targetErrors: targetErrors.map((e) => e.toString()),
|
94
|
+
targetLogs: targetLogs.map(e => ({
|
95
|
+
type: e[0].toString(),
|
96
|
+
message: e[1].toString(),
|
97
|
+
})),
|
88
98
|
|
89
99
|
status: status.toString(),
|
90
100
|
}),
|
@@ -1,16 +1,16 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
2
|
import Logger from '@/logger';
|
3
|
-
import
|
4
|
-
import spawn from '
|
3
|
+
import spawnAsync from 'await-spawn';
|
4
|
+
import { spawn } from 'child_process'
|
5
5
|
import config from "@/config";
|
6
6
|
import wait from "waait";
|
7
7
|
import packageJson from "../../package.json";
|
8
8
|
|
9
9
|
const currentVersion = packageJson.version;
|
10
|
-
const
|
10
|
+
const tag = config.staging ? 'dev' : 'latest';
|
11
11
|
|
12
12
|
class AutoUpdateTask extends BaseTask {
|
13
|
-
pollIntervalMs: number = 60 *
|
13
|
+
pollIntervalMs: number = 60 * 10 * 1000
|
14
14
|
|
15
15
|
constructor() {
|
16
16
|
super({
|
@@ -22,11 +22,28 @@ class AutoUpdateTask extends BaseTask {
|
|
22
22
|
return config.autoUpdate && !config.isLeadNode();
|
23
23
|
}
|
24
24
|
|
25
|
-
async
|
25
|
+
async getInstalledVersion() {
|
26
|
+
try {
|
27
|
+
const stdout = await spawnAsync('npm', ['-g', 'ls', '--depth=0', '--json'])
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
|
29
|
+
} catch (error) {
|
30
|
+
this.logger.error(error)
|
31
|
+
return currentVersion
|
32
|
+
}
|
33
|
+
}
|
26
34
|
|
27
|
-
|
35
|
+
async getLatestVersion() {
|
36
|
+
try {
|
37
|
+
const stdout = await spawnAsync('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
|
38
|
+
return stdout.toString().trim()
|
39
|
+
} catch (error) {
|
40
|
+
this.logger.error(error)
|
41
|
+
return currentVersion
|
42
|
+
}
|
43
|
+
}
|
28
44
|
|
29
|
-
|
45
|
+
async pollHandler() {
|
46
|
+
const version = await this.getLatestVersion()
|
30
47
|
|
31
48
|
if (version === currentVersion) {
|
32
49
|
return;
|
@@ -34,26 +51,30 @@ class AutoUpdateTask extends BaseTask {
|
|
34
51
|
|
35
52
|
this.logger.warn(`New version ${version} available.`)
|
36
53
|
|
37
|
-
|
38
54
|
this.logger.info('Updating...')
|
39
55
|
|
40
|
-
await
|
56
|
+
await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
41
57
|
|
42
58
|
await wait(5000)
|
43
59
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
60
|
+
if (version !== await this.getInstalledVersion()) {
|
61
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
|
62
|
+
return;
|
63
|
+
}
|
48
64
|
|
49
65
|
this.logger.warn(`Installed version ${version}`)
|
50
66
|
this.logger.warn(`Restarting...`)
|
51
67
|
|
52
|
-
|
68
|
+
|
69
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
70
|
+
const subprocess = spawn(process.argv[0], process.argv.slice(1), {
|
53
71
|
cwd: process.cwd(),
|
54
|
-
stdio: "inherit"
|
72
|
+
stdio: "inherit",
|
73
|
+
// shell: process.env.SHELL,
|
55
74
|
});
|
56
75
|
|
76
|
+
subprocess.unref();
|
77
|
+
|
57
78
|
process.exit()
|
58
79
|
}
|
59
80
|
}
|
package/src/tasks/BaseTask.ts
CHANGED
@@ -46,6 +46,11 @@ export class BaseTask extends EventEmitter implements IBaseTask {
|
|
46
46
|
}
|
47
47
|
|
48
48
|
prePollHandler(): boolean {
|
49
|
+
if(config.isMaintenanceMode()){
|
50
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.')
|
51
|
+
return false
|
52
|
+
}
|
53
|
+
|
49
54
|
if (this.exceptLeadNode) {
|
50
55
|
return !config.isLeadNode();
|
51
56
|
}
|