@instadapp/interop-x 0.0.0-dev.2c0a756 → 0.0.0-dev.376f394
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/.github/workflows/ci.yml +19 -0
- package/dist/package.json +13 -12
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopX.json +1436 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/constants/addresses.js +2 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +29 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +114 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +7 -18
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
- package/dist/src/net/protocol/index.js +11 -1
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +84 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +7 -2
- package/dist/src/tasks/index.js +8 -30
- package/dist/src/typechain/{InteropBridgeToken.js → InteropX.js} +0 -0
- package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +46 -89
- package/package.json +13 -12
- package/src/abi/index.ts +2 -4
- package/src/abi/interopX.json +1436 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +3 -0
- package/src/constants/addresses.ts +3 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +65 -25
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +6 -17
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
- package/src/net/protocol/index.ts +13 -3
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +136 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +7 -2
- package/src/tasks/index.ts +10 -40
- package/src/typechain/InteropX.ts +1216 -0
- package/src/typechain/factories/InteropX__factory.ts +1932 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +98 -128
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -298
- 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/SyncBurnEvents.js +0 -71
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -66
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -162
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -71
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -298
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -231
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -121
- package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -98
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -257
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -103
- package/src/typechain/InteropBridgeToken.ts +0 -692
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const module_alias_1 = __importDefault(require("module-alias"));
|
7
|
+
module_alias_1.default.addAliases({
|
8
|
+
"@": __dirname,
|
9
|
+
});
|
10
|
+
(0, module_alias_1.default)();
|
package/dist/src/api/index.js
CHANGED
@@ -2,19 +2,14 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.addresses = void 0;
|
4
4
|
exports.addresses = {
|
5
|
-
1: {
|
6
|
-
gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
|
7
|
-
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
8
|
-
interopXGateway: '',
|
9
|
-
},
|
10
5
|
137: {
|
11
6
|
gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
|
12
7
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
13
|
-
|
8
|
+
interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
|
14
9
|
},
|
15
10
|
43114: {
|
16
11
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
17
12
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
18
|
-
|
13
|
+
interopX: '0xd61f55C6d9deD35B9d13243b816c4BcC1d78592b',
|
19
14
|
}
|
20
15
|
};
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./addresses"), exports);
|
18
18
|
__exportStar(require("./tokens"), exports);
|
19
|
-
__exportStar(require("./itokens"), exports);
|
@@ -2,102 +2,125 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.tokens = void 0;
|
4
4
|
exports.tokens = {
|
5
|
-
1: [
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
5
|
+
// 1: [
|
6
|
+
// {
|
7
|
+
// aliases: ['eth'],
|
8
|
+
// symbol: "ETH",
|
9
|
+
// name: "Ethereum",
|
10
|
+
// address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
11
|
+
// decimals: 18,
|
12
|
+
// },
|
13
|
+
// {
|
14
|
+
// aliases: ['weth'],
|
15
|
+
// symbol: "WETH",
|
16
|
+
// name: "Wrapped Ethereum",
|
17
|
+
// address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
18
|
+
// decimals: 18,
|
19
|
+
// },
|
20
|
+
// {
|
21
|
+
// aliases: ['dai'],
|
22
|
+
// symbol: "DAI",
|
23
|
+
// name: "DAI Stable",
|
24
|
+
// address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
25
|
+
// decimals: 18,
|
26
|
+
// },
|
27
|
+
// {
|
28
|
+
// aliases: ['usdc'],
|
29
|
+
// symbol: "USDC",
|
30
|
+
// name: "USD Coin",
|
31
|
+
// address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
32
|
+
// decimals: 6,
|
33
|
+
// },
|
34
|
+
// {
|
35
|
+
// aliases: ['usdt'],
|
36
|
+
// symbol: "USDT",
|
37
|
+
// name: "Tether USD Coin",
|
38
|
+
// address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
39
|
+
// decimals: 6,
|
40
|
+
// },
|
41
|
+
// {
|
42
|
+
// aliases: ['wbtc'],
|
43
|
+
// symbol: "WBTC",
|
44
|
+
// name: "Wrapped BTC",
|
45
|
+
// address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
46
|
+
// decimals: 8,
|
47
|
+
// },
|
48
|
+
// ],
|
37
49
|
137: [
|
38
50
|
{
|
51
|
+
aliases: ['eth', 'weth'],
|
39
52
|
symbol: "ETH",
|
40
53
|
name: "Ethereum",
|
41
54
|
address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
42
55
|
decimals: 18,
|
43
56
|
},
|
44
57
|
{
|
58
|
+
aliases: ['dai'],
|
45
59
|
symbol: "DAI",
|
46
60
|
name: "DAI Stable",
|
47
61
|
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
|
48
62
|
decimals: 18,
|
49
63
|
},
|
50
64
|
{
|
65
|
+
aliases: ['usdc'],
|
51
66
|
symbol: "USDC",
|
52
67
|
name: "USD Coin",
|
53
68
|
address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
54
69
|
decimals: 6,
|
55
70
|
},
|
56
71
|
{
|
72
|
+
aliases: ['usdt'],
|
57
73
|
symbol: "USDT",
|
58
74
|
name: "Tether USD Coin",
|
59
75
|
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
60
76
|
decimals: 6,
|
61
77
|
},
|
62
78
|
{
|
79
|
+
aliases: ['wbtc'],
|
63
80
|
symbol: "WBTC",
|
64
81
|
name: "Wrapped BTC",
|
65
82
|
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
66
83
|
decimals: 8,
|
67
84
|
},
|
68
|
-
{
|
69
|
-
symbol: "AVAX",
|
70
|
-
name: "Avalanche Token",
|
71
|
-
address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
|
72
|
-
decimals: 18,
|
73
|
-
},
|
74
85
|
],
|
75
86
|
43114: [
|
76
87
|
{
|
88
|
+
aliases: ['eth', 'weth'],
|
77
89
|
symbol: "ETH",
|
78
90
|
name: "Ethereum",
|
79
91
|
address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
|
80
92
|
decimals: 18,
|
81
93
|
},
|
82
94
|
{
|
95
|
+
aliases: ['dai'],
|
83
96
|
symbol: "DAI",
|
84
97
|
name: "DAI Stable",
|
85
98
|
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
86
99
|
decimals: 18,
|
87
100
|
},
|
88
101
|
{
|
102
|
+
aliases: ['usdc'],
|
89
103
|
symbol: "USDC",
|
90
104
|
name: "USD Coin",
|
91
105
|
address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
|
92
106
|
decimals: 6,
|
93
107
|
},
|
94
108
|
{
|
95
|
-
|
109
|
+
aliases: ['usdt'],
|
110
|
+
symbol: "USDt",
|
96
111
|
name: "Tether USD Coin",
|
112
|
+
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
113
|
+
decimals: 6,
|
114
|
+
},
|
115
|
+
{
|
116
|
+
aliases: ['usdt'],
|
117
|
+
symbol: "USDT.e",
|
118
|
+
name: "Tether USD",
|
97
119
|
address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
98
120
|
decimals: 6,
|
99
121
|
},
|
100
122
|
{
|
123
|
+
aliases: ["wbtc"],
|
101
124
|
symbol: "WBTC",
|
102
125
|
name: "Wrapped BTC",
|
103
126
|
address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
|
@@ -12,39 +12,57 @@ Transaction.init({
|
|
12
12
|
autoIncrement: true,
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
|
-
submitTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
-
submitBlockNumber: sequelize_2.DataTypes.NUMBER,
|
17
15
|
transactionHash: sequelize_2.DataTypes.STRING,
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
actionId: sequelize_2.DataTypes.STRING,
|
17
|
+
vnonce: sequelize_2.DataTypes.STRING,
|
18
|
+
sourceSender: sequelize_2.DataTypes.STRING,
|
19
|
+
submitChainId: sequelize_2.DataTypes.NUMBER,
|
20
|
+
submitTransactionHash: sequelize_2.DataTypes.STRING,
|
21
|
+
submitBlockNumber: sequelize_2.DataTypes.NUMBER,
|
22
|
+
submitCreatedAt: sequelize_2.DataTypes.DATE,
|
21
23
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
24
|
+
sourceDsaId: sequelize_2.DataTypes.STRING,
|
22
25
|
sourceTransactionHash: sequelize_2.DataTypes.STRING,
|
23
26
|
sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
|
24
|
-
sourceStatus:
|
27
|
+
sourceStatus: {
|
28
|
+
type: sequelize_2.DataTypes.STRING,
|
29
|
+
defaultValue: 'pending'
|
30
|
+
},
|
25
31
|
sourceErrors: {
|
26
32
|
type: sequelize_2.DataTypes.JSON,
|
27
33
|
// defaultValue: [],
|
28
34
|
},
|
35
|
+
sourceLogs: {
|
36
|
+
type: sequelize_2.DataTypes.JSON,
|
37
|
+
// defaultValue: [],
|
38
|
+
},
|
29
39
|
sourceCreatedAt: {
|
30
40
|
type: sequelize_2.DataTypes.DATE,
|
31
41
|
defaultValue: Date.now()
|
32
42
|
},
|
33
43
|
sourceDelayUntil: sequelize_2.DataTypes.STRING,
|
34
44
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
45
|
+
targetDsaId: sequelize_2.DataTypes.STRING,
|
35
46
|
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
36
47
|
targetBlockNumber: sequelize_2.DataTypes.NUMBER,
|
37
|
-
targetStatus:
|
48
|
+
targetStatus: {
|
49
|
+
type: sequelize_2.DataTypes.STRING,
|
50
|
+
defaultValue: 'pending'
|
51
|
+
},
|
38
52
|
targetErrors: {
|
39
53
|
type: sequelize_2.DataTypes.JSON,
|
40
54
|
// defaultValue: [],
|
41
55
|
},
|
56
|
+
targetLogs: {
|
57
|
+
type: sequelize_2.DataTypes.JSON,
|
58
|
+
// defaultValue: [],
|
59
|
+
},
|
42
60
|
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
43
61
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
44
|
-
submitEvent:
|
45
|
-
|
46
|
-
|
47
|
-
|
62
|
+
submitEvent: {
|
63
|
+
type: sequelize_2.DataTypes.JSON,
|
64
|
+
allowNull: false
|
65
|
+
},
|
48
66
|
status: {
|
49
67
|
type: sequelize_2.DataTypes.STRING,
|
50
68
|
defaultValue: 'pending'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const withdraw_1 = __importDefault(require("./withdraw"));
|
7
|
+
exports.default = {
|
8
|
+
withdraw: withdraw_1.default,
|
9
|
+
};
|
@@ -0,0 +1,114 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// const getBridgeAmounts = async (user: string, tokens: string[], chainId: ChainId) => {
|
4
|
+
// const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(chainId));
|
5
|
+
// const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
|
6
|
+
// const contractAddress = addresses[chainId].interopX;
|
7
|
+
// const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
|
8
|
+
// const data = await contract.getBridgeAmounts(user, tokens);
|
9
|
+
// return data.map((item, index) => ({
|
10
|
+
// token: tokens[index],
|
11
|
+
// deposit: item.deposit,
|
12
|
+
// withdraw: item.withdraw,
|
13
|
+
// }))
|
14
|
+
// }
|
15
|
+
async function default_1(transaction, type) {
|
16
|
+
const transactions = [];
|
17
|
+
const logs = [];
|
18
|
+
// if (transaction.actionId !== 'withdraw') {
|
19
|
+
// throw new Error(`Invalid action: ${transaction.actionId}`)
|
20
|
+
// }
|
21
|
+
// if (type !== 'source') {
|
22
|
+
// throw new Error(`[WIP] Type not supported: ${type}`)
|
23
|
+
// }
|
24
|
+
// if (transaction.sourceStatus === 'pending') {
|
25
|
+
// throw Error('Source transaction already processesing')
|
26
|
+
// }
|
27
|
+
// if (transaction.sourceStatus === 'pending') {
|
28
|
+
// throw Error('Source transaction already processed')
|
29
|
+
// }
|
30
|
+
// if (!transaction.requestEvent) {
|
31
|
+
// throw Error('Something went wrong, source transaction has no request event')
|
32
|
+
// }
|
33
|
+
// const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
|
34
|
+
// const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(sourceChainId as ChainId));
|
35
|
+
// const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
|
36
|
+
// const contractAddress = addresses[sourceChainId].interopX;
|
37
|
+
// const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
|
38
|
+
// const sourceToken = tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
|
39
|
+
// if (!sourceToken) {
|
40
|
+
// throw Error('Source token not found')
|
41
|
+
// }
|
42
|
+
// const targetToken = tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
|
43
|
+
// if (!targetToken) {
|
44
|
+
// throw Error('Target token not found')
|
45
|
+
// }
|
46
|
+
// if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
|
47
|
+
// throw Error('Source and target token must be the same')
|
48
|
+
// }
|
49
|
+
// const networks: ChainId[] = [137, 43114];
|
50
|
+
// const networkUserData = {}
|
51
|
+
// for (const network of networks) {
|
52
|
+
// networkUserData[network] = await getBridgeAmounts(bridger, tokens[network].map(t => t.address), network)
|
53
|
+
// }
|
54
|
+
// for (const tokenSymbol of ["dai", "usdc", "usdt", "eth", "wbtc"]) {
|
55
|
+
// let totalDeposit = BigNumber.from(0)
|
56
|
+
// let totalWithdraw = BigNumber.from(0)
|
57
|
+
// for (const network of networks) {
|
58
|
+
// // on avax might we have 2 usdc/usdt tokens
|
59
|
+
// const matchedTokens = tokens[network].filter(t => t.aliases.includes(tokenSymbol));
|
60
|
+
// for (const matchedToken of matchedTokens) {
|
61
|
+
// const data = networkUserData[network].find(t => t.token.toLowerCase() === matchedToken.address.toLowerCase());
|
62
|
+
// if (data) {
|
63
|
+
// totalDeposit = totalDeposit.add(data.deposit)
|
64
|
+
// totalWithdraw = totalWithdraw.add(data.withdraw)
|
65
|
+
// }
|
66
|
+
// }
|
67
|
+
// // on Mainent add weth too
|
68
|
+
// if (tokenSymbol === "eth" && network === 1) {
|
69
|
+
// const weth = tokens[1].find(t => t.symbol === 'WETH');
|
70
|
+
// if (weth) {
|
71
|
+
// const data = networkUserData[1].find(t => t.token.toLowerCase() === weth.address.toLowerCase());
|
72
|
+
// if (data) {
|
73
|
+
// totalDeposit = totalDeposit.add(data.deposit)
|
74
|
+
// totalWithdraw = totalWithdraw.add(data.withdraw)
|
75
|
+
// }
|
76
|
+
// }
|
77
|
+
// }
|
78
|
+
// }
|
79
|
+
// if (totalWithdraw.gt(totalDeposit)) {
|
80
|
+
// throw Error(`if withdraw > deposit, user has debt and we can't process the withdraw and reject it`)
|
81
|
+
// }
|
82
|
+
// if (totalWithdraw.lt(totalDeposit)) {
|
83
|
+
// throw Error('Something went wrong')
|
84
|
+
// }
|
85
|
+
// }
|
86
|
+
// let balance = BigNumber.from(0);
|
87
|
+
// if (position.withdraw[0].sourceToken.toLowerCase() === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'.toLowerCase()) {
|
88
|
+
// balance = await sourceChainProvider.getBalance(bridger);
|
89
|
+
// } else {
|
90
|
+
// const erc20 = getContract<Erc20>(position.withdraw[0].sourceToken, abi.erc20, sourceChainProvider);
|
91
|
+
// balance = await erc20.balanceOf(addresses[sourceChainId].gnosisSafe);
|
92
|
+
// }
|
93
|
+
// if (balance.lt(position.withdraw[0].amount)) {
|
94
|
+
// throw new LiquidityError()
|
95
|
+
// }
|
96
|
+
// const { data } = await contract.populateTransaction.withdrawRequested(
|
97
|
+
// actionId,
|
98
|
+
// bridger,
|
99
|
+
// position.withdraw[0].sourceToken,
|
100
|
+
// position.withdraw[0].targetToken,
|
101
|
+
// position.withdraw[0].amount,
|
102
|
+
// targetChainId,
|
103
|
+
// transaction.requestTransactionHash,
|
104
|
+
// metadata,
|
105
|
+
// );
|
106
|
+
// transactions.push({
|
107
|
+
// to: contractAddress,
|
108
|
+
// data: data!,
|
109
|
+
// value: '0',
|
110
|
+
// operation: OperationType.Call,
|
111
|
+
// });
|
112
|
+
return { transactions, logs };
|
113
|
+
}
|
114
|
+
exports.default = default_1;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.buildGnosisAction = void 0;
|
7
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
8
|
+
const actions_1 = __importDefault(require("./actions"));
|
9
|
+
const buildGnosisAction = async (transaction, type) => {
|
10
|
+
// type = type || (transaction.sourceStatus === 'success' ? 'target' : 'source')
|
11
|
+
if (actions_1.default.hasOwnProperty(transaction.actionId)) {
|
12
|
+
const { transactions, logs } = await actions_1.default[transaction.actionId](transaction, type);
|
13
|
+
return {
|
14
|
+
data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
|
15
|
+
logs
|
16
|
+
};
|
17
|
+
}
|
18
|
+
throw new Error(`Unknown action: ${transaction.actionId}`);
|
19
|
+
};
|
20
|
+
exports.buildGnosisAction = buildGnosisAction;
|
package/dist/src/index.js
CHANGED
@@ -3,24 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
|
6
|
+
require("./alias");
|
7
7
|
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
-
module_alias_1.default.addAliases({
|
10
|
-
"@/": __dirname + "/",
|
11
|
-
"@/logger": __dirname + "/logger",
|
12
|
-
"@/tasks": __dirname + "/tasks",
|
13
|
-
"@/utils": __dirname + "/utils",
|
14
|
-
"@/api": __dirname + "/api",
|
15
|
-
"@/net": __dirname + "/net",
|
16
|
-
"@/db": __dirname + "/db",
|
17
|
-
"@/config": __dirname + "/config",
|
18
|
-
"@/types": __dirname + "/types",
|
19
|
-
"@/abi": __dirname + "/abi",
|
20
|
-
"@/constants": __dirname + "/constants",
|
21
|
-
"@/typechain": __dirname + "/typechain"
|
22
|
-
});
|
23
|
-
(0, module_alias_1.default)();
|
24
9
|
const dotenv_1 = __importDefault(require("dotenv"));
|
25
10
|
const chalk_1 = __importDefault(require("chalk"));
|
26
11
|
const ethers_1 = require("ethers");
|
@@ -28,7 +13,7 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
28
13
|
dotenv_1.default.config();
|
29
14
|
const logger_1 = __importDefault(require("@/logger"));
|
30
15
|
const logger = new logger_1.default('Process');
|
31
|
-
const GIT_SHORT_HASH = '
|
16
|
+
const GIT_SHORT_HASH = '376f394';
|
32
17
|
const printUsage = () => {
|
33
18
|
console.log();
|
34
19
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
@@ -87,7 +72,9 @@ const utils_1 = require("./utils");
|
|
87
72
|
async function main() {
|
88
73
|
(0, net_1.startPeer)({});
|
89
74
|
const tasks = new tasks_1.Tasks();
|
90
|
-
|
75
|
+
setTimeout(() => {
|
76
|
+
tasks.start();
|
77
|
+
}, 10000);
|
91
78
|
(0, api_1.startApiServer)();
|
92
79
|
net_1.protocol.on('TransactionStatus', async (payload) => {
|
93
80
|
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
@@ -105,9 +92,11 @@ async function main() {
|
|
105
92
|
transaction.sourceStatus = payload.data.sourceStatus;
|
106
93
|
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
107
94
|
transaction.sourceErrors = payload.data.sourceErrors;
|
95
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
108
96
|
transaction.targetStatus = payload.data.targetStatus;
|
109
97
|
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
110
98
|
transaction.targetErrors = payload.data.targetErrors;
|
99
|
+
transaction.targetLogs = payload.data.targetLogs;
|
111
100
|
transaction.status = payload.data.status;
|
112
101
|
await transaction.save();
|
113
102
|
});
|
@@ -10,12 +10,17 @@ const config_1 = __importDefault(require("@/config"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
13
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
14
15
|
constructor(libp2p) {
|
15
16
|
super(libp2p, '/interop-x/signatures');
|
16
17
|
this.timeout = 30000;
|
17
18
|
}
|
18
19
|
async response(data) {
|
20
|
+
console.log({
|
21
|
+
tag: 'SignatureDialProtocol',
|
22
|
+
data
|
23
|
+
});
|
19
24
|
const signer = config_1.default.wallet;
|
20
25
|
let transaction;
|
21
26
|
let maxTimeout = 20000;
|
@@ -33,17 +38,11 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
38
|
error: 'Event not found'
|
34
39
|
};
|
35
40
|
}
|
36
|
-
|
37
|
-
to: constants_1.addresses[transaction.targetChainId].multisend,
|
38
|
-
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
39
|
-
chainId: transaction.targetChainId,
|
40
|
-
safeTxGas: data.safeTxGas,
|
41
|
-
nonce: data.safeNonce,
|
42
|
-
});
|
41
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
43
42
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
44
|
-
to: constants_1.addresses[transaction.
|
45
|
-
data:
|
46
|
-
chainId: transaction.
|
43
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
44
|
+
data: gnosisData,
|
45
|
+
chainId: transaction.sourceChainId,
|
47
46
|
safeTxGas: data.safeTxGas,
|
48
47
|
nonce: data.safeNonce,
|
49
48
|
}, { signer });
|
@@ -18,9 +18,11 @@ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol
|
|
18
18
|
sourceStatus: transaction.sourceStatus,
|
19
19
|
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
20
|
sourceErrors: transaction.sourceErrors,
|
21
|
+
sourceLogs: transaction.sourceLogs,
|
21
22
|
targetStatus: transaction.targetStatus,
|
22
23
|
targetTransactionHash: transaction.targetTransactionHash,
|
23
24
|
targetErrors: transaction.targetErrors,
|
25
|
+
targetLogs: transaction.targetLogs,
|
24
26
|
status: transaction.status,
|
25
27
|
};
|
26
28
|
}
|
@@ -33,19 +33,29 @@ class Protocol extends stream_1.EventEmitter {
|
|
33
33
|
Buffer.from(transaction.sourceStatus),
|
34
34
|
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
35
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
36
37
|
Buffer.from(transaction.targetStatus),
|
37
38
|
Buffer.from(transaction.targetTransactionHash || ''),
|
38
39
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
40
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
39
41
|
Buffer.from(transaction.status),
|
40
42
|
],
|
41
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
42
44
|
transactionHash: transactionHash.toString(),
|
43
45
|
sourceStatus: sourceStatus.toString(),
|
44
46
|
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
47
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
49
|
+
type: e[0].toString(),
|
50
|
+
message: e[1].toString(),
|
51
|
+
})),
|
46
52
|
targetStatus: targetStatus.toString(),
|
47
53
|
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
54
|
targetErrors: targetErrors.map((e) => e.toString()),
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
56
|
+
type: e[0].toString(),
|
57
|
+
message: e[1].toString(),
|
58
|
+
})),
|
49
59
|
status: status.toString(),
|
50
60
|
}),
|
51
61
|
},
|
@@ -0,0 +1,84 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropX::SyncLogSubmitEvents"),
|
18
|
+
});
|
19
|
+
this.chainId = chainId;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogSubmit(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
actionId,
|
33
|
+
vnonce: vnonce.toString(),
|
34
|
+
sourceSender: sourceSender.toString(),
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
37
|
+
sourceDsaId: sourceDsaId.toString(),
|
38
|
+
targetDsaId: targetDsaId.toString(),
|
39
|
+
};
|
40
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
41
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
42
|
+
if (transaction) {
|
43
|
+
continue;
|
44
|
+
}
|
45
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { submitChainId: this.chainId, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber, submitCreatedAt: new Date(), submitEvent: {
|
46
|
+
actionId,
|
47
|
+
actionIdHashHash,
|
48
|
+
vnonce: vnonce.toString(),
|
49
|
+
position: {
|
50
|
+
withdraw: position.withdraw.map((v) => ({
|
51
|
+
sourceToken: v.sourceToken,
|
52
|
+
targetToken: v.targetToken,
|
53
|
+
amount: v.amount.toString()
|
54
|
+
})),
|
55
|
+
supply: position.supply.map((v) => ({
|
56
|
+
sourceToken: v.sourceToken,
|
57
|
+
targetToken: v.targetToken,
|
58
|
+
amount: v.amount.toString()
|
59
|
+
})),
|
60
|
+
},
|
61
|
+
sourceChainId: sourceChainId.toNumber(),
|
62
|
+
targetChainId: targetChainId.toNumber(),
|
63
|
+
sourceSender,
|
64
|
+
sourceDsaId: sourceDsaId.toString(),
|
65
|
+
targetDsaId: targetDsaId.toString(),
|
66
|
+
metadata,
|
67
|
+
} }));
|
68
|
+
this.logger.info(`New InteropX tranaction: ${transactionHash} `);
|
69
|
+
}
|
70
|
+
catch (error) {
|
71
|
+
this.logger.error(error);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
if (processedEvents > 0)
|
75
|
+
this.logger.info(`${processedEvents} events processed`);
|
76
|
+
}
|
77
|
+
async start() {
|
78
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopX;
|
79
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
80
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
81
|
+
await super.start();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.default = SyncLogSubmitEvents;
|