@instadapp/interop-x 0.0.0-dev.d05464a → 0.0.0-dev.d71f27e

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.
Files changed (80) hide show
  1. package/dist/package.json +3 -3
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +4 -1
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/db/models/transaction.js +27 -9
  10. package/dist/src/gnosis/actions/index.js +9 -0
  11. package/dist/src/gnosis/actions/withdraw/index.js +41 -0
  12. package/dist/src/gnosis/index.js +20 -0
  13. package/dist/src/index.js +39 -23
  14. package/dist/src/net/peer/index.js +2 -1
  15. package/dist/src/net/pool/index.js +7 -2
  16. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
  17. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  18. package/dist/src/net/protocol/index.js +26 -5
  19. package/dist/src/tasks/AutoUpdateTask.js +33 -11
  20. package/dist/src/tasks/BaseTask.js +11 -3
  21. package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +54 -52
  22. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  23. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  24. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  25. package/dist/src/tasks/index.js +13 -17
  26. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  27. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  28. package/dist/src/typechain/factories/index.js +3 -5
  29. package/dist/src/typechain/index.js +3 -5
  30. package/dist/src/utils/index.js +27 -87
  31. package/package.json +3 -3
  32. package/src/abi/index.ts +2 -4
  33. package/src/abi/interopXContract.json +391 -0
  34. package/src/alias.ts +6 -0
  35. package/src/api/index.ts +4 -1
  36. package/src/config/index.ts +9 -1
  37. package/src/constants/addresses.ts +3 -3
  38. package/src/constants/index.ts +0 -1
  39. package/src/db/models/transaction.ts +66 -21
  40. package/src/gnosis/actions/index.ts +5 -0
  41. package/src/gnosis/actions/withdraw/index.ts +56 -0
  42. package/src/gnosis/index.ts +19 -0
  43. package/src/index.ts +52 -25
  44. package/src/net/peer/index.ts +2 -1
  45. package/src/net/pool/index.ts +7 -3
  46. package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
  47. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  48. package/src/net/protocol/index.ts +28 -6
  49. package/src/tasks/AutoUpdateTask.ts +36 -14
  50. package/src/tasks/BaseTask.ts +13 -3
  51. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +78 -95
  52. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
  53. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  54. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  55. package/src/tasks/index.ts +17 -18
  56. package/src/typechain/InteropXContract.ts +524 -0
  57. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  58. package/src/typechain/factories/index.ts +1 -2
  59. package/src/typechain/index.ts +2 -4
  60. package/src/utils/index.ts +61 -128
  61. package/tsconfig.json +7 -2
  62. package/dist/src/abi/interopBridgeToken.json +0 -286
  63. package/dist/src/abi/interopXGateway.json +0 -184
  64. package/dist/src/constants/itokens.js +0 -13
  65. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -147
  66. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -70
  67. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  68. package/dist/src/typechain/InteropXGateway.js +0 -2
  69. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  70. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  71. package/src/abi/interopBridgeToken.json +0 -286
  72. package/src/abi/interopXGateway.json +0 -184
  73. package/src/constants/itokens.ts +0 -10
  74. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
  75. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -245
  76. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  77. package/src/typechain/InteropBridgeToken.ts +0 -686
  78. package/src/typechain/InteropXGateway.ts +0 -407
  79. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  80. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,3 +1,2 @@
1
1
  export * from './addresses';
2
2
  export * from './tokens';
3
- export * from './itokens';
@@ -1,40 +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;
19
+
8
20
  declare action: string;
9
- declare from: string;
10
- declare to: string;
21
+ declare bridger: string;
22
+ declare requestTransactionHash: string;
11
23
 
12
- declare submitTransactionHash: string;
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 submitEvent: any;
32
- declare sourceEvent: CreationOptional<any>;
33
- declare targetEvent: CreationOptional<any>;
34
-
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;
35
63
  declare metadata: CreationOptional<any>;
36
64
 
37
- declare status: string;
65
+ declare status: CreationOptional<string>;
38
66
 
39
67
  declare createdAt: CreationOptional<Date>;
40
68
  declare updatedAt: CreationOptional<Date>;
@@ -47,23 +75,28 @@ Transaction.init({
47
75
  primaryKey: true
48
76
  },
49
77
 
50
- submitTransactionHash: DataTypes.NUMBER,
51
- submitBlockNumber: DataTypes.NUMBER,
78
+ requestTransactionHash: DataTypes.NUMBER,
79
+ requestBlockNumber: DataTypes.NUMBER,
52
80
 
53
81
  transactionHash: DataTypes.STRING,
54
82
  action: DataTypes.STRING,
55
-
56
- from: DataTypes.STRING,
57
- to: DataTypes.STRING,
83
+ bridger: DataTypes.STRING,
58
84
 
59
85
  sourceChainId: DataTypes.NUMBER,
60
86
  sourceTransactionHash: DataTypes.STRING,
61
87
  sourceBlockNumber: DataTypes.NUMBER,
62
- sourceStatus: DataTypes.STRING,
88
+ sourceStatus: {
89
+ type: DataTypes.STRING,
90
+ defaultValue: 'uninitialised'
91
+ },
63
92
  sourceErrors: {
64
93
  type: DataTypes.JSON,
65
94
  // defaultValue: [],
66
95
  },
96
+ sourceLogs: {
97
+ type: DataTypes.JSON,
98
+ // defaultValue: [],
99
+ },
67
100
  sourceCreatedAt: {
68
101
  type: DataTypes.DATE,
69
102
  defaultValue: Date.now()
@@ -73,18 +106,30 @@ Transaction.init({
73
106
  targetChainId: DataTypes.NUMBER,
74
107
  targetTransactionHash: DataTypes.STRING,
75
108
  targetBlockNumber: DataTypes.NUMBER,
76
- targetStatus: DataTypes.STRING,
109
+ targetStatus: {
110
+ type: DataTypes.STRING,
111
+ defaultValue: 'uninitialised'
112
+ },
77
113
  targetErrors: {
78
114
  type: DataTypes.JSON,
79
115
  // defaultValue: [],
80
116
  },
117
+ targetLogs: {
118
+ type: DataTypes.JSON,
119
+ // defaultValue: [],
120
+ },
81
121
  targetCreatedAt: DataTypes.DATE,
82
122
  targetDelayUntil: DataTypes.DATE,
83
123
 
84
- submitEvent: DataTypes.JSON,
85
- sourceEvent: DataTypes.JSON,
86
- targetEvent: DataTypes.JSON,
124
+ requestEvent: {
125
+ type: DataTypes.JSON,
126
+ allowNull: false
127
+ },
128
+ requestSentEvent: DataTypes.JSON,
129
+ committedEvent: DataTypes.JSON,
130
+ completedEvent: DataTypes.JSON,
87
131
 
132
+ position: DataTypes.JSON,
88
133
  metadata: DataTypes.JSON,
89
134
 
90
135
  status: {
@@ -0,0 +1,5 @@
1
+ import withdraw from "./withdraw"
2
+
3
+ export default {
4
+ withdraw,
5
+ }
@@ -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,21 +1,7 @@
1
- import moduleAlias from 'module-alias';
2
-
3
- moduleAlias.addAliases({
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(' PRIVATE_KEY=abcd1234 interop-x')
31
- console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
32
- console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x')
33
- console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
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 GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
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(! process.env.PRIVATE_KEY) {
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)
@@ -64,6 +81,7 @@ import { Tasks } from "@/tasks";
64
81
  import { startPeer, protocol, peerPool } from "@/net";
65
82
  import { startApiServer } from '@/api';
66
83
  import { Transaction } from './db';
84
+ import { shortenHash } from './utils';
67
85
 
68
86
  async function main() {
69
87
 
@@ -71,14 +89,21 @@ async function main() {
71
89
 
72
90
  const tasks = new Tasks()
73
91
 
74
- tasks.start();
92
+ setTimeout(() => {
93
+ tasks.start();
94
+ }, 10000)
75
95
 
76
96
  startApiServer()
77
97
 
78
98
  protocol.on('TransactionStatus', async (payload) => {
79
99
  if (!peerPool.isLeadNode(payload.peerId)) {
80
100
  const peer = peerPool.getPeer(payload.peerId)
81
- logger.info(`ignored transaction status from ${payload.peerId} ${peer?.publicAddress} `)
101
+
102
+ if (!peer) {
103
+ return;
104
+ }
105
+
106
+ logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
82
107
  return;
83
108
  }
84
109
 
@@ -91,10 +116,12 @@ async function main() {
91
116
  transaction.sourceStatus = payload.data.sourceStatus
92
117
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash
93
118
  transaction.sourceErrors = payload.data.sourceErrors
119
+ transaction.sourceLogs = payload.data.sourceLogs
94
120
 
95
121
  transaction.targetStatus = payload.data.targetStatus
96
122
  transaction.targetTransactionHash = payload.data.targetTransactionHash
97
123
  transaction.targetErrors = payload.data.targetErrors
124
+ transaction.targetLogs = payload.data.targetLogs
98
125
 
99
126
  transaction.status = payload.data.status
100
127
 
@@ -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
 
@@ -2,6 +2,8 @@ import { Event } from "@/types";
2
2
  import config from "@/config";
3
3
  import Logger from "@/logger";
4
4
  import { getAddress } from "ethers/lib/utils";
5
+ import { shortenHash } from "@/utils";
6
+ import chalk from "chalk";
5
7
 
6
8
 
7
9
  const logger = new Logger('PeerPool')
@@ -87,7 +89,7 @@ export class PeerPool {
87
89
 
88
90
  if (newPeer) {
89
91
  config.events.emit(Event.POOL_PEER_ADDED, peer)
90
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`)
92
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
91
93
  }
92
94
  }
93
95
  }
@@ -102,7 +104,7 @@ export class PeerPool {
102
104
  if (this.pool.delete(peer.id)) {
103
105
  peer.pooled = false
104
106
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
105
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`)
107
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
106
108
  }
107
109
  }
108
110
  }
@@ -123,7 +125,6 @@ export class PeerPool {
123
125
  return this.activePeers.map((p) => p.id)
124
126
  }
125
127
 
126
-
127
128
  getPeer(id: string){
128
129
  return this.pool.get(id);
129
130
  }
@@ -138,6 +139,9 @@ export class PeerPool {
138
139
  return getAddress(peer.publicAddress) === getAddress(config.leadNodeAddress)
139
140
  }
140
141
 
142
+ getLeadPeer() {
143
+ return this.peers.find((p) => this.isLeadNode(p.id))
144
+ }
141
145
 
142
146
  cleanup() {
143
147
  // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
@@ -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 { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
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.targetChainId].multisend,
60
- data: await buildDataForTransaction(transaction, data.type),
61
- chainId: transaction.targetChainId as ChainId,
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 });
@@ -0,0 +1,33 @@
1
+ import { BaseDialProtocol } from "./BaseDialProtocol";
2
+ import { Transaction } from "@/db";
3
+
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | '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
+ sourceLogs: transaction.sourceLogs,
24
+
25
+ targetStatus: transaction.targetStatus,
26
+ targetTransactionHash: transaction.targetTransactionHash,
27
+ targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
29
+
30
+ status: transaction.status,
31
+ }
32
+ }
33
+ }
@@ -6,6 +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/TransactionStatusDialProtocol";
9
10
 
10
11
  export interface ProtocolOptions {
11
12
  /* Handshake timeout in ms (default: 8000) */
@@ -35,7 +36,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
35
36
  }
36
37
 
37
38
  interface TransactionStatusEvent extends BaseMessageEvent {
38
- 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'>
39
40
  }
40
41
 
41
42
  declare interface Protocol {
@@ -65,31 +66,42 @@ class Protocol extends EventEmitter {
65
66
  Buffer.from(transaction.transactionHash),
66
67
 
67
68
  Buffer.from(transaction.sourceStatus),
68
- Buffer.from(transaction.sourceTransactionHash),
69
+ Buffer.from(transaction.sourceTransactionHash || ''),
69
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)]) : [],
70
72
 
71
73
  Buffer.from(transaction.targetStatus),
72
- Buffer.from(transaction.targetTransactionHash),
74
+ Buffer.from(transaction.targetTransactionHash || ''),
73
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)]) : [],
74
77
 
75
78
  Buffer.from(transaction.status),
76
79
  ],
77
- 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]) => ({
78
81
  transactionHash: transactionHash.toString(),
79
82
 
80
83
  sourceStatus: sourceStatus.toString(),
81
- sourceTransactionHash: sourceTransactionHash.toString(),
84
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
82
85
  sourceErrors: sourceErrors.map((e) => e.toString()),
86
+ sourceLogs: sourceLogs.map(e => ({
87
+ type: e[0].toString(),
88
+ message: e[1].toString(),
89
+ })),
83
90
 
84
91
  targetStatus: targetStatus.toString(),
85
- targetTransactionHash: targetTransactionHash.toString(),
92
+ targetTransactionHash: targetTransactionHash.toString() || null,
86
93
  targetErrors: targetErrors.map((e) => e.toString()),
94
+ targetLogs: targetLogs.map(e => ({
95
+ type: e[0].toString(),
96
+ message: e[1].toString(),
97
+ })),
87
98
 
88
99
  status: status.toString(),
89
100
  }),
90
101
  },
91
102
  ];
92
103
  private signature: SignatureDialProtocol;
104
+ private transactionStatus: TransactionStatusDialProtocol;
93
105
 
94
106
 
95
107
  start({ libp2p, topic = null, }) {
@@ -109,6 +121,7 @@ class Protocol extends EventEmitter {
109
121
  })
110
122
 
111
123
  this.signature = new SignatureDialProtocol(this.libp2p);
124
+ this.transactionStatus = new TransactionStatusDialProtocol(this.libp2p);
112
125
  }
113
126
 
114
127
 
@@ -177,6 +190,15 @@ class Protocol extends EventEmitter {
177
190
  return []
178
191
  }
179
192
  }
193
+
194
+ async requestTransactionStatus(transactionHash: string, peerId: string) {
195
+ try {
196
+ return await this.transactionStatus.send(transactionHash, peerId);
197
+ } catch (error) {
198
+ console.log(error);
199
+ return null
200
+ }
201
+ }
180
202
  }
181
203
 
182
204
  export const protocol = new Protocol();