@instadapp/interop-x 0.0.0-dev.14afa72 → 0.0.0-dev.1dc43c9
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 +1 -1
- 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 +21 -11
- package/dist/src/gnosis/actions/index.js +0 -2
- package/dist/src/gnosis/actions/withdraw/index.js +114 -0
- package/dist/src/gnosis/index.js +4 -4
- package/dist/src/index.js +7 -19
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
- 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 +6 -2
- package/dist/src/tasks/index.js +8 -29
- 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 -8
- 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 +1 -1
- 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 +55 -25
- package/src/gnosis/actions/index.ts +0 -2
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +5 -5
- package/src/index.ts +6 -18
- package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
- 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 +6 -2
- package/src/tasks/index.ts +10 -39
- 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 +102 -11
- 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/gnosis/actions/deposit.js +0 -48
- package/dist/src/gnosis/actions/withdraw.js +0 -50
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -162
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
- 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/gnosis/actions/deposit.ts +0 -63
- package/src/gnosis/actions/withdraw.ts +0 -67
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -249
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
- package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
- 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
@@ -1,184 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"inputs": [
|
4
|
-
{ "internalType": "address", "name": "__owner", "type": "address" }
|
5
|
-
],
|
6
|
-
"stateMutability": "nonpayable",
|
7
|
-
"type": "constructor"
|
8
|
-
},
|
9
|
-
{
|
10
|
-
"anonymous": false,
|
11
|
-
"inputs": [
|
12
|
-
{
|
13
|
-
"indexed": false,
|
14
|
-
"internalType": "address",
|
15
|
-
"name": "user",
|
16
|
-
"type": "address"
|
17
|
-
},
|
18
|
-
{
|
19
|
-
"indexed": true,
|
20
|
-
"internalType": "address",
|
21
|
-
"name": "token",
|
22
|
-
"type": "address"
|
23
|
-
},
|
24
|
-
{
|
25
|
-
"indexed": false,
|
26
|
-
"internalType": "uint256",
|
27
|
-
"name": "amount",
|
28
|
-
"type": "uint256"
|
29
|
-
},
|
30
|
-
{
|
31
|
-
"indexed": true,
|
32
|
-
"internalType": "uint256",
|
33
|
-
"name": "vnonce",
|
34
|
-
"type": "uint256"
|
35
|
-
},
|
36
|
-
{
|
37
|
-
"indexed": false,
|
38
|
-
"internalType": "uint32",
|
39
|
-
"name": "sourceChainId",
|
40
|
-
"type": "uint32"
|
41
|
-
},
|
42
|
-
{
|
43
|
-
"indexed": true,
|
44
|
-
"internalType": "uint32",
|
45
|
-
"name": "targetChainId",
|
46
|
-
"type": "uint32"
|
47
|
-
}
|
48
|
-
],
|
49
|
-
"name": "LogGatewayDeposit",
|
50
|
-
"type": "event"
|
51
|
-
},
|
52
|
-
{
|
53
|
-
"anonymous": false,
|
54
|
-
"inputs": [
|
55
|
-
{
|
56
|
-
"indexed": false,
|
57
|
-
"internalType": "address",
|
58
|
-
"name": "user",
|
59
|
-
"type": "address"
|
60
|
-
},
|
61
|
-
{
|
62
|
-
"indexed": true,
|
63
|
-
"internalType": "address",
|
64
|
-
"name": "token",
|
65
|
-
"type": "address"
|
66
|
-
},
|
67
|
-
{
|
68
|
-
"indexed": false,
|
69
|
-
"internalType": "uint256",
|
70
|
-
"name": "amount",
|
71
|
-
"type": "uint256"
|
72
|
-
},
|
73
|
-
{
|
74
|
-
"indexed": true,
|
75
|
-
"internalType": "uint32",
|
76
|
-
"name": "sourceChainId",
|
77
|
-
"type": "uint32"
|
78
|
-
},
|
79
|
-
{
|
80
|
-
"indexed": false,
|
81
|
-
"internalType": "uint32",
|
82
|
-
"name": "targetChainId",
|
83
|
-
"type": "uint32"
|
84
|
-
},
|
85
|
-
{
|
86
|
-
"indexed": true,
|
87
|
-
"internalType": "bytes32",
|
88
|
-
"name": "transactionHash",
|
89
|
-
"type": "bytes32"
|
90
|
-
}
|
91
|
-
],
|
92
|
-
"name": "LogGatewayWithdraw",
|
93
|
-
"type": "event"
|
94
|
-
},
|
95
|
-
{
|
96
|
-
"anonymous": false,
|
97
|
-
"inputs": [
|
98
|
-
{
|
99
|
-
"indexed": true,
|
100
|
-
"internalType": "address",
|
101
|
-
"name": "previousOwner",
|
102
|
-
"type": "address"
|
103
|
-
},
|
104
|
-
{
|
105
|
-
"indexed": true,
|
106
|
-
"internalType": "address",
|
107
|
-
"name": "newOwner",
|
108
|
-
"type": "address"
|
109
|
-
}
|
110
|
-
],
|
111
|
-
"name": "OwnershipTransferred",
|
112
|
-
"type": "event"
|
113
|
-
},
|
114
|
-
{
|
115
|
-
"inputs": [],
|
116
|
-
"name": "_vnonce",
|
117
|
-
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
118
|
-
"stateMutability": "view",
|
119
|
-
"type": "function"
|
120
|
-
},
|
121
|
-
{
|
122
|
-
"inputs": [
|
123
|
-
{ "internalType": "address", "name": "token_", "type": "address" },
|
124
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
125
|
-
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
126
|
-
],
|
127
|
-
"name": "deposit",
|
128
|
-
"outputs": [],
|
129
|
-
"stateMutability": "nonpayable",
|
130
|
-
"type": "function"
|
131
|
-
},
|
132
|
-
{
|
133
|
-
"inputs": [
|
134
|
-
{ "internalType": "address", "name": "to_", "type": "address" },
|
135
|
-
{ "internalType": "address", "name": "token_", "type": "address" },
|
136
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
137
|
-
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
138
|
-
],
|
139
|
-
"name": "depositFor",
|
140
|
-
"outputs": [],
|
141
|
-
"stateMutability": "nonpayable",
|
142
|
-
"type": "function"
|
143
|
-
},
|
144
|
-
{
|
145
|
-
"inputs": [],
|
146
|
-
"name": "owner",
|
147
|
-
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
148
|
-
"stateMutability": "view",
|
149
|
-
"type": "function"
|
150
|
-
},
|
151
|
-
{
|
152
|
-
"inputs": [],
|
153
|
-
"name": "renounceOwnership",
|
154
|
-
"outputs": [],
|
155
|
-
"stateMutability": "nonpayable",
|
156
|
-
"type": "function"
|
157
|
-
},
|
158
|
-
{
|
159
|
-
"inputs": [
|
160
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
161
|
-
{ "internalType": "address", "name": "user_", "type": "address" },
|
162
|
-
{ "internalType": "address", "name": "token_", "type": "address" },
|
163
|
-
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" },
|
164
|
-
{
|
165
|
-
"internalType": "bytes32",
|
166
|
-
"name": "transactionHash_",
|
167
|
-
"type": "bytes32"
|
168
|
-
}
|
169
|
-
],
|
170
|
-
"name": "systemWithdraw",
|
171
|
-
"outputs": [],
|
172
|
-
"stateMutability": "nonpayable",
|
173
|
-
"type": "function"
|
174
|
-
},
|
175
|
-
{
|
176
|
-
"inputs": [
|
177
|
-
{ "internalType": "address", "name": "newOwner", "type": "address" }
|
178
|
-
],
|
179
|
-
"name": "transferOwnership",
|
180
|
-
"outputs": [],
|
181
|
-
"stateMutability": "nonpayable",
|
182
|
-
"type": "function"
|
183
|
-
}
|
184
|
-
]
|
package/src/constants/itokens.ts
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
import abi from "@/abi";
|
2
|
-
import config from "@/config";
|
3
|
-
import { itokens, tokens } from "@/constants";
|
4
|
-
import { Transaction } from "@/db";
|
5
|
-
import { InteropBridgeToken } 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.sourceStatus === 'pending') {
|
16
|
-
throw Error('Cannot build data for pending deposit transaction');
|
17
|
-
}
|
18
|
-
|
19
|
-
if (!transaction.submitEvent) {
|
20
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
25
|
-
|
26
|
-
if (!token) {
|
27
|
-
throw Error(`Unsupported token ${transaction.submitEvent.token}`);
|
28
|
-
}
|
29
|
-
|
30
|
-
const itoken = itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
|
31
|
-
|
32
|
-
if (!itoken) {
|
33
|
-
throw Error(`Unsupported itoken ${token.symbol}`);
|
34
|
-
}
|
35
|
-
|
36
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
|
37
|
-
const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
|
38
|
-
const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
|
39
|
-
|
40
|
-
const { data } = await interopBridgeContract.populateTransaction.mint(
|
41
|
-
transaction.submitEvent.user,
|
42
|
-
ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
|
43
|
-
ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
|
44
|
-
transaction.submitTransactionHash,
|
45
|
-
);
|
46
|
-
|
47
|
-
transactions.push({
|
48
|
-
to: itoken.address,
|
49
|
-
data: data!,
|
50
|
-
value: '0',
|
51
|
-
operation: OperationType.Call,
|
52
|
-
});
|
53
|
-
|
54
|
-
logs.push({
|
55
|
-
type: 'mint', // mint, approved, burn, transfer, borrow, swap, repay, collected, traded, .....
|
56
|
-
message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
|
57
|
-
})
|
58
|
-
|
59
|
-
return {
|
60
|
-
transactions,
|
61
|
-
logs,
|
62
|
-
}
|
63
|
-
}
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import abi from "@/abi";
|
2
|
-
import config from "@/config";
|
3
|
-
import { addresses, itokens, tokens } from "@/constants";
|
4
|
-
import { Transaction } from "@/db";
|
5
|
-
import { InteropXGateway } 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 (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
20
|
-
throw Error('Cannot build data for pending withdraw transaction');
|
21
|
-
}
|
22
|
-
|
23
|
-
if (!transaction.submitEvent) {
|
24
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
25
|
-
}
|
26
|
-
|
27
|
-
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
28
|
-
|
29
|
-
const itoken = itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
30
|
-
|
31
|
-
if (!itoken) {
|
32
|
-
throw Error(`Unsupported itoken ${itokenAddress}`);
|
33
|
-
}
|
34
|
-
|
35
|
-
const token = tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
36
|
-
|
37
|
-
if (!token) {
|
38
|
-
throw Error(`Unsupported token ${itoken.symbol}`);
|
39
|
-
}
|
40
|
-
|
41
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
|
42
|
-
const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
|
43
|
-
const gatewayAddress = addresses[targetChainId].interopXGateway;
|
44
|
-
const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
|
45
|
-
|
46
|
-
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
|
47
|
-
ethers.BigNumber.from(amount.toString()),
|
48
|
-
to,
|
49
|
-
token.address,
|
50
|
-
ethers.BigNumber.from(sourceChainId.toString()),
|
51
|
-
transaction.submitTransactionHash,
|
52
|
-
);
|
53
|
-
|
54
|
-
transactions.push({
|
55
|
-
to: gatewayAddress,
|
56
|
-
data: data!,
|
57
|
-
value: '0',
|
58
|
-
operation: OperationType.Call,
|
59
|
-
});
|
60
|
-
|
61
|
-
logs.push({
|
62
|
-
type: 'transfer',
|
63
|
-
message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
|
64
|
-
})
|
65
|
-
|
66
|
-
return { transactions, logs }
|
67
|
-
}
|
@@ -1,249 +0,0 @@
|
|
1
|
-
import { BaseTask } from "../BaseTask";
|
2
|
-
import Logger from '@/logger';
|
3
|
-
import { BigNumber, ethers } from "ethers";
|
4
|
-
import abi from "@/abi";
|
5
|
-
import { Transaction } from "@/db";
|
6
|
-
import { buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
7
|
-
import { addresses } from "@/constants";
|
8
|
-
import { ChainId } from "@/types";
|
9
|
-
import config from "@/config";
|
10
|
-
import { GnosisSafe } from "@/typechain";
|
11
|
-
import { Op } from "sequelize";
|
12
|
-
import wait from "waait";
|
13
|
-
import { peerPool, protocol } from "@/net";
|
14
|
-
import { LogDescription } from "ethers/lib/utils";
|
15
|
-
import { buildGnosisAction } from "@/gnosis";
|
16
|
-
|
17
|
-
const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
|
18
|
-
console.log(transactionData);
|
19
|
-
|
20
|
-
let isExecuted = await safeContract.dataHashes(
|
21
|
-
await safeContract.getTransactionHash(
|
22
|
-
transactionData.to,
|
23
|
-
transactionData.value,
|
24
|
-
transactionData.data,
|
25
|
-
transactionData.operation,
|
26
|
-
transactionData.safeTxGas,
|
27
|
-
transactionData.baseGas,
|
28
|
-
transactionData.gasPrice,
|
29
|
-
transactionData.gasToken,
|
30
|
-
transactionData.refundReceiver,
|
31
|
-
transactionData.nonce
|
32
|
-
)
|
33
|
-
)
|
34
|
-
|
35
|
-
while (isExecuted == 1) {
|
36
|
-
transactionData.safeTxGas = BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
|
37
|
-
|
38
|
-
isExecuted = await safeContract.dataHashes(
|
39
|
-
await safeContract.getTransactionHash(
|
40
|
-
transactionData.to,
|
41
|
-
transactionData.value,
|
42
|
-
transactionData.data,
|
43
|
-
transactionData.operation,
|
44
|
-
transactionData.safeTxGas,
|
45
|
-
transactionData.baseGas,
|
46
|
-
transactionData.gasPrice,
|
47
|
-
transactionData.gasToken,
|
48
|
-
transactionData.refundReceiver,
|
49
|
-
transactionData.nonce
|
50
|
-
)
|
51
|
-
)
|
52
|
-
}
|
53
|
-
|
54
|
-
return transactionData
|
55
|
-
}
|
56
|
-
|
57
|
-
class ProcessWithdrawEvents extends BaseTask {
|
58
|
-
provider: ethers.providers.JsonRpcProvider;
|
59
|
-
chainId: ChainId;
|
60
|
-
leadNodeOnly = true
|
61
|
-
|
62
|
-
constructor({ chainId }: { chainId: ChainId }) {
|
63
|
-
super({
|
64
|
-
logger: new Logger("InteropXGateway::ProcessWithdrawEvents"),
|
65
|
-
})
|
66
|
-
this.chainId = chainId;
|
67
|
-
}
|
68
|
-
|
69
|
-
async pollHandler() {
|
70
|
-
const blockNumber = await this.provider.getBlockNumber()
|
71
|
-
|
72
|
-
const transaction = await Transaction.findOne({
|
73
|
-
where: {
|
74
|
-
status: 'pending',
|
75
|
-
sourceStatus: 'success',
|
76
|
-
targetStatus: 'uninitialised',
|
77
|
-
action: 'withdraw',
|
78
|
-
sourceCreatedAt: {
|
79
|
-
[Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
80
|
-
},
|
81
|
-
targetDelayUntil: {
|
82
|
-
[Op.or]: {
|
83
|
-
[Op.is]: null,
|
84
|
-
[Op.lt]: new Date(),
|
85
|
-
}
|
86
|
-
},
|
87
|
-
sourceBlockNumber: {
|
88
|
-
[Op.lt]: blockNumber - 12,
|
89
|
-
},
|
90
|
-
sourceChainId: this.chainId,
|
91
|
-
}
|
92
|
-
})
|
93
|
-
|
94
|
-
if (!transaction) {
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
console.log(`Processing transaction ${transaction.transactionHash}`);
|
99
|
-
|
100
|
-
transaction.targetStatus = 'pending';
|
101
|
-
await transaction.save();
|
102
|
-
|
103
|
-
// refresh event data?
|
104
|
-
|
105
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
106
|
-
getRpcProviderUrl(transaction.targetChainId as ChainId)
|
107
|
-
);
|
108
|
-
|
109
|
-
const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
|
110
|
-
|
111
|
-
const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
|
112
|
-
|
113
|
-
|
114
|
-
const safeContract = getContract<GnosisSafe>(
|
115
|
-
safeAddress,
|
116
|
-
abi.gnosisSafe,
|
117
|
-
targetWallet
|
118
|
-
)
|
119
|
-
|
120
|
-
const ownersThreshold = await safeContract.getThreshold();
|
121
|
-
await wait(10000);
|
122
|
-
|
123
|
-
let data, logs = [];
|
124
|
-
|
125
|
-
try {
|
126
|
-
({ data, logs } = await buildGnosisAction(transaction));
|
127
|
-
} catch (error) {
|
128
|
-
console.log(error);
|
129
|
-
transaction.targetStatus = 'failed';
|
130
|
-
transaction.targetErrors = [error.message];
|
131
|
-
transaction.status = 'failed'
|
132
|
-
await transaction.save();
|
133
|
-
protocol.sendTransaction(transaction)
|
134
|
-
return;
|
135
|
-
}
|
136
|
-
|
137
|
-
let gnosisTx = await generateGnosisTransaction({
|
138
|
-
baseGas: "0",
|
139
|
-
data,
|
140
|
-
gasPrice: "0",
|
141
|
-
gasToken: "0x0000000000000000000000000000000000000000",
|
142
|
-
nonce: '0',
|
143
|
-
operation: "1",
|
144
|
-
refundReceiver: "0x0000000000000000000000000000000000000000",
|
145
|
-
safeAddress: safeAddress,
|
146
|
-
safeTxGas: "79668",
|
147
|
-
to: addresses[transaction.targetChainId].multisend,
|
148
|
-
value: "0",
|
149
|
-
}, safeContract);
|
150
|
-
|
151
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
152
|
-
|
153
|
-
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
154
|
-
|
155
|
-
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
156
|
-
|
157
|
-
console.log(ownerPeerIds);
|
158
|
-
|
159
|
-
const signatures = await protocol.requestSignatures({
|
160
|
-
type: 'source',
|
161
|
-
transactionHash: transaction.transactionHash,
|
162
|
-
safeTxGas: gnosisTx.safeTxGas,
|
163
|
-
safeNonce: gnosisTx.nonce
|
164
|
-
}, ownerPeerIds)
|
165
|
-
|
166
|
-
|
167
|
-
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x') as Signature[];
|
168
|
-
|
169
|
-
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
170
|
-
|
171
|
-
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
172
|
-
await transaction.save();
|
173
|
-
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
174
|
-
transaction.targetStatus = 'uninitialised'
|
175
|
-
|
176
|
-
await transaction.save();
|
177
|
-
const errorMessage = signatures.find(s => !!s.error)?.error;
|
178
|
-
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
183
|
-
|
184
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
185
|
-
gnosisTx.to,
|
186
|
-
gnosisTx.value,
|
187
|
-
gnosisTx.data,
|
188
|
-
gnosisTx.operation,
|
189
|
-
gnosisTx.safeTxGas,
|
190
|
-
gnosisTx.baseGas,
|
191
|
-
gnosisTx.gasPrice,
|
192
|
-
gnosisTx.gasToken,
|
193
|
-
gnosisTx.refundReceiver,
|
194
|
-
buildSignatureBytes(validSignatures)
|
195
|
-
);
|
196
|
-
|
197
|
-
console.log({
|
198
|
-
from: targetWallet.address,
|
199
|
-
gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
|
200
|
-
to: safeAddress,
|
201
|
-
data: txData,
|
202
|
-
})
|
203
|
-
|
204
|
-
|
205
|
-
const txSent = await targetWallet.sendTransaction({
|
206
|
-
from: targetWallet.address,
|
207
|
-
gasPrice: BigNumber.from(120 * 10 ** 9),
|
208
|
-
to: safeAddress,
|
209
|
-
data: txData,
|
210
|
-
})
|
211
|
-
|
212
|
-
const receipt = await txSent.wait();
|
213
|
-
|
214
|
-
const parsedLogs: LogDescription[] = [];
|
215
|
-
|
216
|
-
receipt.logs.forEach((log) => {
|
217
|
-
try {
|
218
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
219
|
-
} catch (e) { }
|
220
|
-
});
|
221
|
-
|
222
|
-
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
223
|
-
console.log('ExecutionSuccess')
|
224
|
-
transaction.targetStatus = 'success'
|
225
|
-
transaction.targetTransactionHash = txSent.hash
|
226
|
-
transaction.targetLogs = logs
|
227
|
-
transaction.status = 'success'
|
228
|
-
await transaction.save();
|
229
|
-
} else {
|
230
|
-
console.log('ExecutionFailure')
|
231
|
-
transaction.targetStatus = 'failed'
|
232
|
-
transaction.targetTransactionHash = txSent.hash
|
233
|
-
transaction.status = 'failed'
|
234
|
-
await transaction.save();
|
235
|
-
}
|
236
|
-
|
237
|
-
protocol.sendTransaction(transaction)
|
238
|
-
}
|
239
|
-
|
240
|
-
async start(): Promise<void> {
|
241
|
-
this.provider = new ethers.providers.JsonRpcProvider(
|
242
|
-
getRpcProviderUrl(this.chainId)
|
243
|
-
);
|
244
|
-
|
245
|
-
await super.start()
|
246
|
-
}
|
247
|
-
}
|
248
|
-
|
249
|
-
export default ProcessWithdrawEvents;
|
@@ -1,119 +0,0 @@
|
|
1
|
-
import { BaseTask } from "../BaseTask";
|
2
|
-
import Logger from '@/logger';
|
3
|
-
import { ethers } from "ethers";
|
4
|
-
import abi from "@/abi";
|
5
|
-
import { Transaction } from "@/db";
|
6
|
-
import { generateInteropTransactionHash, getContract, getRpcProviderUrl } from "@/utils";
|
7
|
-
import { ChainId } from "@/types";
|
8
|
-
import config from "@/config";
|
9
|
-
import { InteropBridgeToken } from "@/typechain";
|
10
|
-
|
11
|
-
class SyncBurnEvents extends BaseTask {
|
12
|
-
contractAddress: string;
|
13
|
-
provider: ethers.providers.JsonRpcProvider;
|
14
|
-
contract: InteropBridgeToken;
|
15
|
-
chainId: ChainId;
|
16
|
-
itokenAddress: string;
|
17
|
-
|
18
|
-
constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
|
19
|
-
super({
|
20
|
-
logger: new Logger("InteropBridgeToken::SyncBurnEvents"),
|
21
|
-
})
|
22
|
-
this.chainId = chainId;
|
23
|
-
this.itokenAddress = itokenAddress;
|
24
|
-
}
|
25
|
-
|
26
|
-
async pollHandler() {
|
27
|
-
const currentBlock = await this.provider.getBlockNumber();
|
28
|
-
|
29
|
-
const events = await this.contract.queryFilter(
|
30
|
-
this.contract.filters.Burn(),
|
31
|
-
currentBlock - 2000,
|
32
|
-
currentBlock,
|
33
|
-
);
|
34
|
-
|
35
|
-
let processedEvents = 0;
|
36
|
-
|
37
|
-
for (const event of events) {
|
38
|
-
|
39
|
-
try {
|
40
|
-
if (!event.args) {
|
41
|
-
continue;
|
42
|
-
}
|
43
|
-
|
44
|
-
const { to, amount, sourceChainId, targetChainId } = event.args;
|
45
|
-
|
46
|
-
const uniqueIdentifier = {
|
47
|
-
action: 'withdraw',
|
48
|
-
submitTransactionHash: event.transactionHash,
|
49
|
-
sourceChainId: sourceChainId,
|
50
|
-
targetChainId: targetChainId,
|
51
|
-
}
|
52
|
-
|
53
|
-
if (await Transaction.findOne({ where: uniqueIdentifier })) {
|
54
|
-
continue;
|
55
|
-
}
|
56
|
-
|
57
|
-
const tx = await event.getTransaction()
|
58
|
-
|
59
|
-
await Transaction.create({
|
60
|
-
...uniqueIdentifier,
|
61
|
-
transactionHash: generateInteropTransactionHash(uniqueIdentifier),
|
62
|
-
from: tx.from,
|
63
|
-
to,
|
64
|
-
|
65
|
-
submitTransactionHash: event.transactionHash,
|
66
|
-
submitBlockNumber: event.blockNumber,
|
67
|
-
|
68
|
-
// submit & source are the same
|
69
|
-
sourceTransactionHash: event.transactionHash,
|
70
|
-
sourceBlockNumber: event.blockNumber,
|
71
|
-
sourceStatus: "success",
|
72
|
-
targetStatus: "uninitialised",
|
73
|
-
|
74
|
-
submitEvent: {
|
75
|
-
to,
|
76
|
-
amount: amount.toString(),
|
77
|
-
itoken: this.itokenAddress,
|
78
|
-
sourceChainId: sourceChainId,
|
79
|
-
targetChainId: targetChainId,
|
80
|
-
},
|
81
|
-
|
82
|
-
sourceEvent: {
|
83
|
-
to,
|
84
|
-
amount: amount.toString(),
|
85
|
-
itoken: this.itokenAddress,
|
86
|
-
sourceChainId: sourceChainId,
|
87
|
-
targetChainId: targetChainId,
|
88
|
-
},
|
89
|
-
status: "pending",
|
90
|
-
})
|
91
|
-
|
92
|
-
this.logger.info(
|
93
|
-
`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`
|
94
|
-
);
|
95
|
-
} catch (error) {
|
96
|
-
this.logger.error(error);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
if (processedEvents > 0)
|
101
|
-
this.logger.info(`${processedEvents} events processed`);
|
102
|
-
}
|
103
|
-
|
104
|
-
async start(): Promise<void> {
|
105
|
-
this.provider = new ethers.providers.JsonRpcProvider(
|
106
|
-
getRpcProviderUrl(this.chainId)
|
107
|
-
);
|
108
|
-
|
109
|
-
this.contract = getContract<InteropBridgeToken>(
|
110
|
-
this.itokenAddress,
|
111
|
-
abi.interopBridgeToken,
|
112
|
-
new ethers.Wallet(config.privateKey!, this.provider)
|
113
|
-
);
|
114
|
-
|
115
|
-
await super.start()
|
116
|
-
}
|
117
|
-
}
|
118
|
-
|
119
|
-
export default SyncBurnEvents;
|