@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.
Files changed (79) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/dist/package.json +13 -12
  3. package/dist/src/abi/index.js +2 -4
  4. package/dist/src/abi/interopX.json +1436 -0
  5. package/dist/src/alias.js +10 -0
  6. package/dist/src/api/index.js +1 -1
  7. package/dist/src/constants/addresses.js +2 -7
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/constants/tokens.js +62 -39
  10. package/dist/src/db/models/transaction.js +21 -11
  11. package/dist/src/gnosis/actions/index.js +0 -2
  12. package/dist/src/gnosis/actions/withdraw/index.js +114 -0
  13. package/dist/src/gnosis/index.js +4 -4
  14. package/dist/src/index.js +7 -19
  15. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
  16. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
  17. package/dist/src/net/protocol/index.js +11 -1
  18. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +84 -0
  19. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +6 -2
  20. package/dist/src/tasks/index.js +8 -29
  21. package/dist/src/typechain/{InteropBridgeToken.js → InteropX.js} +0 -0
  22. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  23. package/dist/src/typechain/factories/index.js +3 -5
  24. package/dist/src/typechain/index.js +3 -5
  25. package/dist/src/utils/index.js +46 -8
  26. package/package.json +13 -12
  27. package/src/abi/index.ts +2 -4
  28. package/src/abi/interopX.json +1436 -0
  29. package/src/alias.ts +6 -0
  30. package/src/api/index.ts +1 -1
  31. package/src/constants/addresses.ts +3 -8
  32. package/src/constants/index.ts +0 -1
  33. package/src/constants/tokens.ts +63 -40
  34. package/src/db/models/transaction.ts +55 -25
  35. package/src/gnosis/actions/index.ts +0 -2
  36. package/src/gnosis/actions/withdraw/index.ts +155 -0
  37. package/src/gnosis/index.ts +5 -5
  38. package/src/index.ts +6 -18
  39. package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
  40. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
  41. package/src/net/protocol/index.ts +13 -3
  42. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +136 -0
  43. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +6 -2
  44. package/src/tasks/index.ts +10 -39
  45. package/src/typechain/InteropX.ts +1216 -0
  46. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  47. package/src/typechain/factories/index.ts +1 -2
  48. package/src/typechain/index.ts +2 -4
  49. package/src/utils/index.ts +102 -11
  50. package/tsconfig.json +7 -2
  51. package/dist/src/abi/interopBridgeToken.json +0 -298
  52. package/dist/src/abi/interopXGateway.json +0 -184
  53. package/dist/src/constants/itokens.js +0 -13
  54. package/dist/src/gnosis/actions/deposit.js +0 -48
  55. package/dist/src/gnosis/actions/withdraw.js +0 -50
  56. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -162
  57. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
  58. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
  59. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
  60. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  61. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
  62. package/dist/src/typechain/InteropXGateway.js +0 -2
  63. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
  64. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  65. package/src/abi/interopBridgeToken.json +0 -298
  66. package/src/abi/interopXGateway.json +0 -184
  67. package/src/constants/itokens.ts +0 -10
  68. package/src/gnosis/actions/deposit.ts +0 -63
  69. package/src/gnosis/actions/withdraw.ts +0 -67
  70. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -249
  71. package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
  72. package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
  73. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
  74. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  75. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
  76. package/src/typechain/InteropBridgeToken.ts +0 -692
  77. package/src/typechain/InteropXGateway.ts +0 -407
  78. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
  79. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
package/src/alias.ts ADDED
@@ -0,0 +1,6 @@
1
+ import moduleAlias from 'module-alias';
2
+ moduleAlias.addAliases({
3
+ "@": __dirname,
4
+ })
5
+
6
+ moduleAlias();
package/src/api/index.ts CHANGED
@@ -21,7 +21,7 @@ export const startApiServer = async () => {
21
21
  limit: 20,
22
22
  offset: 0,
23
23
  order: [
24
- ['createdAt', 'DESC']
24
+ ['updatedAt', 'DESC']
25
25
  ]
26
26
  })
27
27
  })
@@ -1,17 +1,12 @@
1
1
  export const addresses = {
2
- 1: {
3
- gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
4
- multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
5
- interopXGateway: '',
6
- },
7
2
  137: {
8
3
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
9
4
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
10
- interopXGateway: '',
5
+ interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
11
6
  },
12
7
  43114: {
13
8
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
14
9
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
15
- interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
10
+ interopX: '0xd61f55C6d9deD35B9d13243b816c4BcC1d78592b',
16
11
  }
17
- }
12
+ } as Record<number, { gnosisSafe: string, multisend: string, interopX: string }>
@@ -1,3 +1,2 @@
1
1
  export * from './addresses';
2
2
  export * from './tokens';
3
- export * from './itokens';
@@ -1,104 +1,127 @@
1
1
  export const tokens = {
2
- 1: [
3
- {
4
- symbol: "ETH",
5
- name: "Ethereum",
6
- address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
7
- decimals: 18,
8
- },
9
- {
10
- symbol: "DAI",
11
- name: "DAI Stable",
12
- address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
13
- decimals: 18,
14
- },
15
- {
16
- symbol: "USDC",
17
- name: "USD Coin",
18
- address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
19
- decimals: 6,
20
- },
21
- {
22
- symbol: "USDT",
23
- name: "Tether USD Coin",
24
- address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
25
- decimals: 6,
26
- },
27
- {
28
- symbol: "WBTC",
29
- name: "Wrapped BTC",
30
- address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
31
- decimals: 8,
32
- },
33
- ],
2
+ // 1: [
3
+ // {
4
+ // aliases: ['eth'],
5
+ // symbol: "ETH",
6
+ // name: "Ethereum",
7
+ // address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
8
+ // decimals: 18,
9
+ // },
10
+ // {
11
+ // aliases: ['weth'],
12
+ // symbol: "WETH",
13
+ // name: "Wrapped Ethereum",
14
+ // address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
15
+ // decimals: 18,
16
+ // },
17
+ // {
18
+ // aliases: ['dai'],
19
+ // symbol: "DAI",
20
+ // name: "DAI Stable",
21
+ // address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
22
+ // decimals: 18,
23
+ // },
24
+ // {
25
+ // aliases: ['usdc'],
26
+ // symbol: "USDC",
27
+ // name: "USD Coin",
28
+ // address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
29
+ // decimals: 6,
30
+ // },
31
+ // {
32
+ // aliases: ['usdt'],
33
+ // symbol: "USDT",
34
+ // name: "Tether USD Coin",
35
+ // address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
36
+ // decimals: 6,
37
+ // },
38
+ // {
39
+ // aliases: ['wbtc'],
40
+ // symbol: "WBTC",
41
+ // name: "Wrapped BTC",
42
+ // address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
43
+ // decimals: 8,
44
+ // },
45
+ // ],
34
46
  137: [
35
47
  {
48
+ aliases: ['eth', 'weth'],
36
49
  symbol: "ETH",
37
50
  name: "Ethereum",
38
51
  address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
39
52
  decimals: 18,
40
53
  },
41
54
  {
55
+ aliases: ['dai'],
42
56
  symbol: "DAI",
43
57
  name: "DAI Stable",
44
58
  address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
45
59
  decimals: 18,
46
60
  },
47
61
  {
62
+ aliases: ['usdc'],
48
63
  symbol: "USDC",
49
64
  name: "USD Coin",
50
65
  address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
51
66
  decimals: 6,
52
67
  },
53
68
  {
69
+ aliases: ['usdt'],
54
70
  symbol: "USDT",
55
71
  name: "Tether USD Coin",
56
72
  address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
57
73
  decimals: 6,
58
74
  },
59
75
  {
76
+ aliases: ['wbtc'],
60
77
  symbol: "WBTC",
61
78
  name: "Wrapped BTC",
62
79
  address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
63
80
  decimals: 8,
64
81
  },
65
- {
66
- symbol: "AVAX",
67
- name: "Avalanche Token",
68
- address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
69
- decimals: 18,
70
- },
71
82
  ],
72
83
  43114: [
73
84
  {
85
+ aliases: ['eth', 'weth'],
74
86
  symbol: "ETH",
75
87
  name: "Ethereum",
76
88
  address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
77
89
  decimals: 18,
78
90
  },
79
91
  {
92
+ aliases: ['dai'],
80
93
  symbol: "DAI",
81
94
  name: "DAI Stable",
82
95
  address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
83
96
  decimals: 18,
84
97
  },
85
98
  {
99
+ aliases: ['usdc'],
86
100
  symbol: "USDC",
87
101
  name: "USD Coin",
88
102
  address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
89
103
  decimals: 6,
90
104
  },
91
105
  {
92
- symbol: "USDT",
106
+ aliases: ['usdt'],
107
+ symbol: "USDt",
93
108
  name: "Tether USD Coin",
109
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
110
+ decimals: 6,
111
+ },
112
+ {
113
+ aliases: ['usdt'],
114
+ symbol: "USDT.e",
115
+ name: "Tether USD",
94
116
  address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
95
117
  decimals: 6,
96
118
  },
97
119
  {
120
+ aliases: ["wbtc"],
98
121
  symbol: "WBTC",
99
122
  name: "Wrapped BTC",
100
123
  address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
101
124
  decimals: 8,
102
125
  },
103
126
  ],
104
- };
127
+ } as Record<number, { aliases: string[], symbol: string, name: string, address: string, decimals: number }[]>;
@@ -1,42 +1,64 @@
1
1
  import { sequelize } from '@/db/sequelize'
2
2
  import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
3
3
 
4
+ export interface IPositionTokenInfo {
5
+ amount: string;
6
+ sourceToken: string;
7
+ targetToken: string;
8
+ }
9
+
10
+ export interface IPosition {
11
+ supply: IPositionTokenInfo[];
12
+ withdraw: IPositionTokenInfo[];
13
+ }
14
+
4
15
  export class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
5
16
  declare id: CreationOptional<number>;
6
17
 
7
18
  declare transactionHash: string;
8
- declare action: string;
9
- declare from: string;
10
- declare to: string;
19
+ declare vnonce: string;
20
+ declare actionId: string;
21
+ declare sourceSender: string;
11
22
 
23
+ declare submitChainId: number;
12
24
  declare submitTransactionHash: string;
13
25
  declare submitBlockNumber: number;
26
+ declare submitCreatedAt: Date;
14
27
 
15
28
  declare sourceChainId: number;
29
+ declare sourceDsaId: string;
16
30
  declare sourceTransactionHash: CreationOptional<string>;
17
31
  declare sourceBlockNumber: CreationOptional<number>;
18
- declare sourceStatus: string;
32
+ declare sourceStatus: CreationOptional<string>;
19
33
  declare sourceErrors: CreationOptional<string[]>;
20
34
  declare sourceLogs: CreationOptional<any[]>;
21
35
  declare sourceCreatedAt: CreationOptional<Date>;
22
36
  declare sourceDelayUntil: CreationOptional<Date>;
23
37
 
24
38
  declare targetChainId: number;
39
+ declare targetDsaId: string;
25
40
  declare targetTransactionHash: CreationOptional<string>;
26
41
  declare targetBlockNumber: CreationOptional<number>;
27
- declare targetStatus: string;
42
+ declare targetStatus: CreationOptional<string>;
28
43
  declare targetErrors: CreationOptional<string[]>;
29
44
  declare targetLogs: CreationOptional<any[]>;
30
45
  declare targetCreatedAt: CreationOptional<Date>;
31
46
  declare targetDelayUntil: CreationOptional<Date>;
32
47
 
33
- declare submitEvent: any;
34
- declare sourceEvent: CreationOptional<any>;
35
- declare targetEvent: CreationOptional<any>;
36
-
37
- declare metadata: CreationOptional<any>;
38
-
39
- declare status: string;
48
+ declare submitEvent: {
49
+ position: IPosition;
50
+ actionId: string;
51
+ actionIdHashHash: string;
52
+ sourceSender: string;
53
+ sourceDsaId: string;
54
+ targetDsaId: string;
55
+ sourceChainId: number;
56
+ targetChainId: number;
57
+ vnonce: string;
58
+ metadata: string;
59
+ };
60
+
61
+ declare status: CreationOptional<string>;
40
62
 
41
63
  declare createdAt: CreationOptional<Date>;
42
64
  declare updatedAt: CreationOptional<Date>;
@@ -49,19 +71,24 @@ Transaction.init({
49
71
  primaryKey: true
50
72
  },
51
73
 
52
- submitTransactionHash: DataTypes.NUMBER,
53
- submitBlockNumber: DataTypes.NUMBER,
54
-
55
74
  transactionHash: DataTypes.STRING,
56
- action: DataTypes.STRING,
75
+ actionId: DataTypes.STRING,
76
+ vnonce: DataTypes.STRING,
77
+ sourceSender: DataTypes.STRING,
57
78
 
58
- from: DataTypes.STRING,
59
- to: DataTypes.STRING,
79
+ submitChainId: DataTypes.NUMBER,
80
+ submitTransactionHash: DataTypes.STRING,
81
+ submitBlockNumber: DataTypes.NUMBER,
82
+ submitCreatedAt: DataTypes.DATE,
60
83
 
61
84
  sourceChainId: DataTypes.NUMBER,
85
+ sourceDsaId: DataTypes.STRING,
62
86
  sourceTransactionHash: DataTypes.STRING,
63
87
  sourceBlockNumber: DataTypes.NUMBER,
64
- sourceStatus: DataTypes.STRING,
88
+ sourceStatus: {
89
+ type: DataTypes.STRING,
90
+ defaultValue: 'pending'
91
+ },
65
92
  sourceErrors: {
66
93
  type: DataTypes.JSON,
67
94
  // defaultValue: [],
@@ -77,9 +104,13 @@ Transaction.init({
77
104
  sourceDelayUntil: DataTypes.STRING,
78
105
 
79
106
  targetChainId: DataTypes.NUMBER,
107
+ targetDsaId: DataTypes.STRING,
80
108
  targetTransactionHash: DataTypes.STRING,
81
109
  targetBlockNumber: DataTypes.NUMBER,
82
- targetStatus: DataTypes.STRING,
110
+ targetStatus: {
111
+ type: DataTypes.STRING,
112
+ defaultValue: 'pending'
113
+ },
83
114
  targetErrors: {
84
115
  type: DataTypes.JSON,
85
116
  // defaultValue: [],
@@ -91,11 +122,10 @@ Transaction.init({
91
122
  targetCreatedAt: DataTypes.DATE,
92
123
  targetDelayUntil: DataTypes.DATE,
93
124
 
94
- submitEvent: DataTypes.JSON,
95
- sourceEvent: DataTypes.JSON,
96
- targetEvent: DataTypes.JSON,
97
-
98
- metadata: DataTypes.JSON,
125
+ submitEvent: {
126
+ type: DataTypes.JSON,
127
+ allowNull: false
128
+ },
99
129
 
100
130
  status: {
101
131
  type: DataTypes.STRING,
@@ -1,7 +1,5 @@
1
- import deposit from "./deposit"
2
1
  import withdraw from "./withdraw"
3
2
 
4
3
  export default {
5
- deposit,
6
4
  withdraw,
7
5
  }
@@ -0,0 +1,155 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { Erc20, InteropX } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl, LiquidityError } from "@/utils";
8
+ import { BigNumber, ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+
12
+ // const getBridgeAmounts = async (user: string, tokens: string[], chainId: ChainId) => {
13
+ // const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(chainId));
14
+ // const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
15
+ // const contractAddress = addresses[chainId].interopX;
16
+ // const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
17
+ // const data = await contract.getBridgeAmounts(user, tokens);
18
+
19
+
20
+ // return data.map((item, index) => ({
21
+ // token: tokens[index],
22
+ // deposit: item.deposit,
23
+ // withdraw: item.withdraw,
24
+ // }))
25
+ // }
26
+
27
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
28
+ const transactions: MetaTransaction[] = [];
29
+ const logs: any[] = [];
30
+
31
+ // if (transaction.actionId !== 'withdraw') {
32
+ // throw new Error(`Invalid action: ${transaction.actionId}`)
33
+ // }
34
+
35
+ // if (type !== 'source') {
36
+ // throw new Error(`[WIP] Type not supported: ${type}`)
37
+ // }
38
+
39
+ // if (transaction.sourceStatus === 'pending') {
40
+ // throw Error('Source transaction already processesing')
41
+ // }
42
+
43
+ // if (transaction.sourceStatus === 'pending') {
44
+ // throw Error('Source transaction already processed')
45
+ // }
46
+
47
+ // if (!transaction.requestEvent) {
48
+ // throw Error('Something went wrong, source transaction has no request event')
49
+ // }
50
+
51
+ // const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
52
+
53
+ // const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(sourceChainId as ChainId));
54
+ // const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
55
+ // const contractAddress = addresses[sourceChainId].interopX;
56
+ // const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
57
+
58
+ // const sourceToken = tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
59
+
60
+ // if (!sourceToken) {
61
+ // throw Error('Source token not found')
62
+ // }
63
+
64
+ // const targetToken = tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
65
+
66
+ // if (!targetToken) {
67
+ // throw Error('Target token not found')
68
+ // }
69
+
70
+ // if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
71
+ // throw Error('Source and target token must be the same')
72
+ // }
73
+
74
+ // const networks: ChainId[] = [137, 43114];
75
+ // const networkUserData = {}
76
+ // for (const network of networks) {
77
+ // networkUserData[network] = await getBridgeAmounts(bridger, tokens[network].map(t => t.address), network)
78
+ // }
79
+
80
+ // for (const tokenSymbol of ["dai", "usdc", "usdt", "eth", "wbtc"]) {
81
+ // let totalDeposit = BigNumber.from(0)
82
+ // let totalWithdraw = BigNumber.from(0)
83
+
84
+ // for (const network of networks) {
85
+ // // on avax might we have 2 usdc/usdt tokens
86
+ // const matchedTokens = tokens[network].filter(t => t.aliases.includes(tokenSymbol));
87
+
88
+ // for (const matchedToken of matchedTokens) {
89
+ // const data = networkUserData[network].find(t => t.token.toLowerCase() === matchedToken.address.toLowerCase());
90
+
91
+ // if (data) {
92
+ // totalDeposit = totalDeposit.add(data.deposit)
93
+ // totalWithdraw = totalWithdraw.add(data.withdraw)
94
+ // }
95
+ // }
96
+
97
+ // // on Mainent add weth too
98
+ // if (tokenSymbol === "eth" && network === 1) {
99
+ // const weth = tokens[1].find(t => t.symbol === 'WETH');
100
+
101
+ // if (weth) {
102
+ // const data = networkUserData[1].find(t => t.token.toLowerCase() === weth.address.toLowerCase());
103
+
104
+ // if (data) {
105
+ // totalDeposit = totalDeposit.add(data.deposit)
106
+ // totalWithdraw = totalWithdraw.add(data.withdraw)
107
+ // }
108
+ // }
109
+ // }
110
+ // }
111
+
112
+ // if (totalWithdraw.gt(totalDeposit)) {
113
+ // throw Error(`if withdraw > deposit, user has debt and we can't process the withdraw and reject it`)
114
+ // }
115
+
116
+ // if (totalWithdraw.lt(totalDeposit)) {
117
+ // throw Error('Something went wrong')
118
+ // }
119
+ // }
120
+
121
+ // let balance = BigNumber.from(0);
122
+
123
+ // if (position.withdraw[0].sourceToken.toLowerCase() === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'.toLowerCase()) {
124
+ // balance = await sourceChainProvider.getBalance(bridger);
125
+
126
+ // } else {
127
+ // const erc20 = getContract<Erc20>(position.withdraw[0].sourceToken, abi.erc20, sourceChainProvider);
128
+ // balance = await erc20.balanceOf(addresses[sourceChainId].gnosisSafe);
129
+ // }
130
+
131
+ // if (balance.lt(position.withdraw[0].amount)) {
132
+ // throw new LiquidityError()
133
+ // }
134
+
135
+
136
+ // const { data } = await contract.populateTransaction.withdrawRequested(
137
+ // actionId,
138
+ // bridger,
139
+ // position.withdraw[0].sourceToken,
140
+ // position.withdraw[0].targetToken,
141
+ // position.withdraw[0].amount,
142
+ // targetChainId,
143
+ // transaction.requestTransactionHash,
144
+ // metadata,
145
+ // );
146
+
147
+ // transactions.push({
148
+ // to: contractAddress,
149
+ // data: data!,
150
+ // value: '0',
151
+ // operation: OperationType.Call,
152
+ // });
153
+
154
+ return { transactions, logs }
155
+ }
@@ -2,12 +2,12 @@ import { Transaction } from "@/db";
2
2
  import { encodeMulti } from "ethers-multisend";
3
3
  import actions from "./actions";
4
4
 
5
- export const buildGnosisAction = async (transaction: Transaction, type?: 'source' | 'target') => {
6
- type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
5
+ export const buildGnosisAction = async (transaction: Transaction, type: 'source' | 'target') => {
6
+ // type = type || (transaction.sourceStatus === 'success' ? 'target' : 'source')
7
7
 
8
- if (actions.hasOwnProperty(transaction.action)) {
8
+ if (actions.hasOwnProperty(transaction.actionId)) {
9
9
 
10
- const { transactions, logs } = await actions[transaction.action](transaction, type);
10
+ const { transactions, logs } = await actions[transaction.actionId](transaction, type);
11
11
 
12
12
  return {
13
13
  data: encodeMulti(transactions).data,
@@ -15,5 +15,5 @@ export const buildGnosisAction = async (transaction: Transaction, type?: 'source
15
15
  };
16
16
  }
17
17
 
18
- throw new Error(`Unknown action: ${transaction.action}`);
18
+ throw new Error(`Unknown action: ${transaction.actionId}`);
19
19
  }
package/src/index.ts CHANGED
@@ -1,23 +1,7 @@
1
- import moduleAlias from 'module-alias';
1
+ import './alias'
2
2
  import expandHomeDir from "expand-home-dir";
3
3
  import fs from 'fs-extra'
4
- moduleAlias.addAliases({
5
- "@/": __dirname + "/",
6
- "@/logger": __dirname + "/logger",
7
- "@/tasks": __dirname + "/tasks",
8
- "@/gnosis": __dirname + "/gnosis",
9
- "@/utils": __dirname + "/utils",
10
- "@/api": __dirname + "/api",
11
- "@/net": __dirname + "/net",
12
- "@/db": __dirname + "/db",
13
- "@/config": __dirname + "/config",
14
- "@/types": __dirname + "/types",
15
- "@/abi": __dirname + "/abi",
16
- "@/constants": __dirname + "/constants",
17
- "@/typechain": __dirname + "/typechain"
18
- })
19
4
 
20
- moduleAlias();
21
5
  import dotenv from "dotenv";
22
6
  import chalk from 'chalk';
23
7
  import { ethers } from "ethers";
@@ -105,7 +89,9 @@ async function main() {
105
89
 
106
90
  const tasks = new Tasks()
107
91
 
108
- tasks.start();
92
+ setTimeout(() => {
93
+ tasks.start();
94
+ }, 10000)
109
95
 
110
96
  startApiServer()
111
97
 
@@ -130,10 +116,12 @@ async function main() {
130
116
  transaction.sourceStatus = payload.data.sourceStatus
131
117
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash
132
118
  transaction.sourceErrors = payload.data.sourceErrors
119
+ transaction.sourceLogs = payload.data.sourceLogs
133
120
 
134
121
  transaction.targetStatus = payload.data.targetStatus
135
122
  transaction.targetTransactionHash = payload.data.targetTransactionHash
136
123
  transaction.targetErrors = payload.data.targetErrors
124
+ transaction.targetLogs = payload.data.targetLogs
137
125
 
138
126
  transaction.status = payload.data.status
139
127
 
@@ -26,6 +26,10 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
26
26
  }
27
27
 
28
28
  async response(data: ISignatureRequest): Promise<ISignatureResponse> {
29
+ console.log({
30
+ tag: 'SignatureDialProtocol',
31
+ data
32
+ })
29
33
  const signer = config.wallet;
30
34
 
31
35
  let transaction: Transaction | null;
@@ -50,9 +54,9 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
50
54
  const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
51
55
 
52
56
  const signedData = await signGnosisSafeTx({
53
- to: addresses[transaction.targetChainId].multisend,
57
+ to: addresses[transaction.sourceChainId].multisend,
54
58
  data: gnosisData,
55
- chainId: transaction.targetChainId as ChainId,
59
+ chainId: transaction.sourceChainId as ChainId,
56
60
  safeTxGas: data.safeTxGas,
57
61
  nonce: data.safeNonce,
58
62
  }, { signer });
@@ -1,7 +1,7 @@
1
1
  import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import { Transaction } from "@/db";
3
3
 
4
- export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
5
5
  protected timeout = 30000;
6
6
 
7
7
  constructor(libp2p) {
@@ -20,10 +20,12 @@ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick
20
20
  sourceStatus: transaction.sourceStatus,
21
21
  sourceTransactionHash: transaction.sourceTransactionHash,
22
22
  sourceErrors: transaction.sourceErrors,
23
+ sourceLogs: transaction.sourceLogs,
23
24
 
24
25
  targetStatus: transaction.targetStatus,
25
26
  targetTransactionHash: transaction.targetTransactionHash,
26
27
  targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
27
29
 
28
30
  status: transaction.status,
29
31
  }