@instadapp/interop-x 0.0.0-dev.0b0cc3f
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 +1 -0
- package/.github/workflows/publish-dev.yml +30 -0
- package/README.md +21 -0
- package/bin/interop-x +2 -0
- package/dist/abi/erc20.json +350 -0
- package/dist/abi/gnosisSafe.json +747 -0
- package/dist/abi/index.js +15 -0
- package/dist/abi/interopBridgeToken.json +286 -0
- package/dist/abi/interopXGateway.json +184 -0
- package/dist/config/index.js +17 -0
- package/dist/constants/addresses.js +28 -0
- package/dist/constants/index.js +17 -0
- package/dist/db/index.js +17 -0
- package/dist/db/models/index.js +17 -0
- package/dist/db/models/transaction.js +52 -0
- package/dist/db/sequelize.js +22 -0
- package/dist/index.js +43 -0
- package/dist/logger/index.js +138 -0
- package/dist/net/index.js +19 -0
- package/dist/net/peer/index.js +104 -0
- package/dist/net/pool/index.js +107 -0
- package/dist/net/protocol/dial/BaseDialProtocol.js +106 -0
- package/dist/net/protocol/dial/SignatureDialProtocol.js +46 -0
- package/dist/net/protocol/index.js +92 -0
- package/dist/tasks/BaseTask.js +61 -0
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +79 -0
- package/dist/tasks/index.js +27 -0
- package/dist/typechain/Erc20.js +2 -0
- package/dist/typechain/GnosisSafe.js +2 -0
- package/dist/typechain/InteropBridgeToken.js +2 -0
- package/dist/typechain/InteropXGateway.js +2 -0
- package/dist/typechain/common.js +2 -0
- package/dist/typechain/factories/Erc20__factory.js +367 -0
- package/dist/typechain/factories/GnosisSafe__factory.js +1174 -0
- package/dist/typechain/factories/InteropBridgeToken__factory.js +459 -0
- package/dist/typechain/factories/InteropXGateway__factory.js +265 -0
- package/dist/typechain/factories/index.js +14 -0
- package/dist/typechain/index.js +35 -0
- package/dist/types.js +21 -0
- package/dist/utils/index.js +101 -0
- package/package.json +79 -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/config/index.ts +24 -0
- package/src/constants/addresses.ts +25 -0
- package/src/constants/index.ts +1 -0
- package/src/db/index.ts +1 -0
- package/src/db/models/index.ts +1 -0
- package/src/db/models/transaction.ts +92 -0
- package/src/db/sequelize.ts +21 -0
- package/src/index.ts +50 -0
- package/src/logger/index.ts +157 -0
- package/src/net/index.ts +3 -0
- package/src/net/peer/index.ts +119 -0
- package/src/net/pool/index.ts +128 -0
- package/src/net/protocol/dial/BaseDialProtocol.ts +104 -0
- package/src/net/protocol/dial/SignatureDialProtocol.ts +59 -0
- package/src/net/protocol/index.ts +138 -0
- package/src/tasks/BaseTask.ts +75 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +114 -0
- package/src/tasks/index.ts +21 -0
- 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 +39 -0
- package/src/utils/index.ts +129 -0
- package/tsconfig.json +30 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
export { Erc20__factory } from "./Erc20__factory";
|
5
|
+
export { GnosisSafe__factory } from "./GnosisSafe__factory";
|
6
|
+
export { InteropBridgeToken__factory } from "./InteropBridgeToken__factory";
|
7
|
+
export { InteropXGateway__factory } from "./InteropXGateway__factory";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
export type { Erc20 } from "./Erc20";
|
5
|
+
export type { GnosisSafe } from "./GnosisSafe";
|
6
|
+
export type { InteropBridgeToken } from "./InteropBridgeToken";
|
7
|
+
export type { InteropXGateway } from "./InteropXGateway";
|
8
|
+
export * as factories from "./factories";
|
9
|
+
export { Erc20__factory } from "./factories/Erc20__factory";
|
10
|
+
export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
|
11
|
+
export { InteropBridgeToken__factory } from "./factories/InteropBridgeToken__factory";
|
12
|
+
export { InteropXGateway__factory } from "./factories/InteropXGateway__factory";
|
package/src/types.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import { EventEmitter } from 'events'
|
2
|
+
import { IPeerInfo } from '@/net'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Types for the central event bus, emitted
|
6
|
+
* by different components of the client.
|
7
|
+
*/
|
8
|
+
export enum Event {
|
9
|
+
PEER_CONNECTED = 'peer:connected',
|
10
|
+
PEER_DISCONNECTED = 'peer:disconnected',
|
11
|
+
PEER_ERROR = 'peer:error',
|
12
|
+
POOL_PEER_ADDED = 'pool:peer:added',
|
13
|
+
POOL_PEER_REMOVED = 'pool:peer:removed',
|
14
|
+
POOL_PEER_BANNED = 'pool:peer:banned',
|
15
|
+
}
|
16
|
+
export interface EventParams {
|
17
|
+
[Event.PEER_CONNECTED]: [connectedPeer: IPeerInfo]
|
18
|
+
[Event.PEER_DISCONNECTED]: [disconnectedPeer: IPeerInfo]
|
19
|
+
[Event.PEER_ERROR]: [error: Error, peerCausingError: IPeerInfo]
|
20
|
+
[Event.POOL_PEER_ADDED]: [addedPeer: IPeerInfo]
|
21
|
+
[Event.POOL_PEER_REMOVED]: [removedPeer: IPeerInfo]
|
22
|
+
[Event.POOL_PEER_BANNED]: [bannedPeer: IPeerInfo]
|
23
|
+
}
|
24
|
+
|
25
|
+
export declare interface EventBus<T extends Event> {
|
26
|
+
emit(event: T, ...args: EventParams[T]): boolean
|
27
|
+
on(event: T, listener: (...args: EventParams[T]) => void): this
|
28
|
+
}
|
29
|
+
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
31
|
+
export class EventBus<T extends Event> extends EventEmitter { }
|
32
|
+
export type EventBusType = EventBus<Event.PEER_CONNECTED> &
|
33
|
+
EventBus<Event.PEER_DISCONNECTED> &
|
34
|
+
EventBus<Event.POOL_PEER_ADDED> &
|
35
|
+
EventBus<Event.POOL_PEER_REMOVED> &
|
36
|
+
EventBus<Event.POOL_PEER_BANNED>
|
37
|
+
|
38
|
+
|
39
|
+
export type ChainId = 1 | 137 | 43114;
|
@@ -0,0 +1,129 @@
|
|
1
|
+
/**
|
2
|
+
* @module util
|
3
|
+
*/
|
4
|
+
import axios from 'axios'
|
5
|
+
import axiosRetry from "axios-retry";
|
6
|
+
import { addresses } from '@/constants';
|
7
|
+
import { ChainId } from '@/types'
|
8
|
+
import { ethers } from 'ethers';
|
9
|
+
|
10
|
+
export const http = axios.create();
|
11
|
+
|
12
|
+
axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
|
13
|
+
|
14
|
+
|
15
|
+
export function short(buffer: Buffer): string {
|
16
|
+
return buffer.toString('hex').slice(0, 8) + '...'
|
17
|
+
}
|
18
|
+
|
19
|
+
export const signGnosisSafeTx = async ({
|
20
|
+
to,
|
21
|
+
data = null as any,
|
22
|
+
value = '0',
|
23
|
+
operation = '1',
|
24
|
+
baseGas = '0',
|
25
|
+
gasPrice = "0",
|
26
|
+
gasToken = "0x0000000000000000000000000000000000000000",
|
27
|
+
refundReceiver = "0x0000000000000000000000000000000000000000",
|
28
|
+
safeTxGas = "79668" as string | number,
|
29
|
+
nonce = "0",
|
30
|
+
chainId = 137 as ChainId,
|
31
|
+
}, { signer }) => {
|
32
|
+
const gnosisSafe = addresses[chainId].gnosisSafe;
|
33
|
+
|
34
|
+
const domain = {
|
35
|
+
verifyingContract: gnosisSafe,
|
36
|
+
chainId,
|
37
|
+
};
|
38
|
+
|
39
|
+
const types = {
|
40
|
+
SafeTx: [
|
41
|
+
{ type: 'address', name: 'to' },
|
42
|
+
{ type: 'uint256', name: 'value' },
|
43
|
+
{ type: 'bytes', name: 'data' },
|
44
|
+
{ type: 'uint8', name: 'operation' },
|
45
|
+
{ type: 'uint256', name: 'safeTxGas' },
|
46
|
+
{ type: 'uint256', name: 'baseGas' },
|
47
|
+
{ type: 'uint256', name: 'gasPrice' },
|
48
|
+
{ type: 'address', name: 'gasToken' },
|
49
|
+
{ type: 'address', name: 'refundReceiver' },
|
50
|
+
{ type: 'uint256', name: 'nonce' },
|
51
|
+
],
|
52
|
+
};
|
53
|
+
|
54
|
+
const message = {
|
55
|
+
baseGas,
|
56
|
+
data,
|
57
|
+
gasPrice,
|
58
|
+
gasToken,
|
59
|
+
nonce: Number(nonce),
|
60
|
+
operation,
|
61
|
+
refundReceiver,
|
62
|
+
safeAddress: gnosisSafe,
|
63
|
+
safeTxGas: String(safeTxGas),
|
64
|
+
to,
|
65
|
+
value,
|
66
|
+
};
|
67
|
+
|
68
|
+
return await signer._signTypedData(domain, types, message)
|
69
|
+
};
|
70
|
+
|
71
|
+
export const getRpcProviderUrl = (chainId: ChainId) => {
|
72
|
+
switch (chainId) {
|
73
|
+
case 1:
|
74
|
+
return 'https://rpc.instadapp.io/mainnet';
|
75
|
+
case 137:
|
76
|
+
return 'https://rpc.instadapp.io/polygon';
|
77
|
+
case 43114:
|
78
|
+
return 'https://rpc.instadapp.io/avalanche';
|
79
|
+
default:
|
80
|
+
throw new Error(`Unknown chainId: ${chainId}`);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
export interface Signature {
|
85
|
+
signer: string;
|
86
|
+
hash?: string;
|
87
|
+
data: string;
|
88
|
+
}
|
89
|
+
|
90
|
+
export const buildSignatureBytes = (signatures: Signature[]): string => {
|
91
|
+
signatures.sort((left, right) =>
|
92
|
+
left.signer.toLowerCase().localeCompare(right.signer.toLowerCase())
|
93
|
+
);
|
94
|
+
let signatureBytes = "0x";
|
95
|
+
for (const sig of signatures) {
|
96
|
+
signatureBytes += sig.data.slice(2);
|
97
|
+
}
|
98
|
+
return signatureBytes;
|
99
|
+
};
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Call an async function with a maximum time limit (in milliseconds) for the timeout
|
103
|
+
* Resolved promise for async function call, or an error if time limit reached
|
104
|
+
*/
|
105
|
+
export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout: number) => {
|
106
|
+
let timeoutHandle;
|
107
|
+
|
108
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
109
|
+
timeoutHandle = setTimeout(
|
110
|
+
() => reject(new Error('Async call timeout limit reached')),
|
111
|
+
timeout
|
112
|
+
);
|
113
|
+
});
|
114
|
+
|
115
|
+
return Promise.race([asyncPromise, timeoutPromise]).then(result => {
|
116
|
+
clearTimeout(timeoutHandle);
|
117
|
+
return result;
|
118
|
+
}) as Promise<T>
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
export const generateInteropTransactionHash = (data: { type: string, sourceTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
|
123
|
+
return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
124
|
+
String(data.type),
|
125
|
+
String(data.sourceTransactionHash),
|
126
|
+
String(data.sourceChainId),
|
127
|
+
String(data.targetChainId),
|
128
|
+
]);
|
129
|
+
}
|
package/tsconfig.json
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"module": "commonjs",
|
4
|
+
"esModuleInterop": true,
|
5
|
+
"resolveJsonModule": true,
|
6
|
+
"allowSyntheticDefaultImports": true,
|
7
|
+
"emitDecoratorMetadata": true,
|
8
|
+
"experimentalDecorators": true,
|
9
|
+
"target": "ES2017",
|
10
|
+
"noImplicitAny": false,
|
11
|
+
"noUnusedLocals": false,
|
12
|
+
"strictNullChecks": true,
|
13
|
+
"moduleResolution": "node",
|
14
|
+
"skipLibCheck": true,
|
15
|
+
"sourceMap": false,
|
16
|
+
"noEmit": false,
|
17
|
+
"outDir": "dist",
|
18
|
+
"baseUrl": "src",
|
19
|
+
"paths": {
|
20
|
+
"@/*" : ["./*" ]
|
21
|
+
},
|
22
|
+
"typeRoots": [
|
23
|
+
"./node_modules/@types",
|
24
|
+
"./@types"
|
25
|
+
]
|
26
|
+
},
|
27
|
+
"include": [
|
28
|
+
"src/**/*",
|
29
|
+
]
|
30
|
+
}
|