@instadapp/interop-x 0.0.0-dev.de23e71 → 0.0.0-dev.e33810b

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 (69) hide show
  1. package/dist/package.json +13 -12
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +454 -0
  4. package/dist/src/constants/addresses.js +3 -3
  5. package/dist/src/constants/index.js +0 -1
  6. package/dist/src/constants/tokens.js +31 -1
  7. package/dist/src/db/models/transaction.js +19 -11
  8. package/dist/src/gnosis/actions/index.js +0 -2
  9. package/dist/src/gnosis/actions/withdraw/index.js +55 -0
  10. package/dist/src/gnosis/index.js +4 -4
  11. package/dist/src/index.js +4 -2
  12. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
  13. package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +42 -52
  14. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  15. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  16. package/dist/src/tasks/index.js +13 -30
  17. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  18. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  19. package/dist/src/typechain/factories/index.js +3 -5
  20. package/dist/src/typechain/index.js +3 -5
  21. package/dist/src/utils/index.js +37 -8
  22. package/package.json +13 -12
  23. package/src/abi/index.ts +2 -4
  24. package/src/abi/interopXContract.json +454 -0
  25. package/src/constants/addresses.ts +3 -3
  26. package/src/constants/index.ts +0 -1
  27. package/src/constants/tokens.ts +32 -2
  28. package/src/db/models/transaction.ts +58 -27
  29. package/src/gnosis/actions/index.ts +0 -2
  30. package/src/gnosis/actions/withdraw/index.ts +77 -0
  31. package/src/gnosis/index.ts +5 -5
  32. package/src/index.ts +3 -1
  33. package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
  34. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +66 -99
  35. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  36. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  37. package/src/tasks/index.ts +15 -37
  38. package/src/typechain/InteropXContract.ts +680 -0
  39. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  40. package/src/typechain/factories/index.ts +1 -2
  41. package/src/typechain/index.ts +2 -4
  42. package/src/utils/index.ts +78 -8
  43. package/dist/src/abi/interopBridgeToken.json +0 -298
  44. package/dist/src/abi/interopXGateway.json +0 -184
  45. package/dist/src/constants/itokens.js +0 -13
  46. package/dist/src/gnosis/actions/deposit.js +0 -48
  47. package/dist/src/gnosis/actions/withdraw.js +0 -50
  48. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
  49. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
  50. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
  51. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  52. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
  53. package/dist/src/typechain/InteropXGateway.js +0 -2
  54. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
  55. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  56. package/src/abi/interopBridgeToken.json +0 -298
  57. package/src/abi/interopXGateway.json +0 -184
  58. package/src/constants/itokens.ts +0 -10
  59. package/src/gnosis/actions/deposit.ts +0 -63
  60. package/src/gnosis/actions/withdraw.ts +0 -67
  61. package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
  62. package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
  63. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
  64. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  65. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
  66. package/src/typechain/InteropBridgeToken.ts +0 -692
  67. package/src/typechain/InteropXGateway.ts +0 -407
  68. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
  69. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -2,16 +2,16 @@ export const addresses = {
2
2
  1: {
3
3
  gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
4
4
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
5
- interopXGateway: '',
5
+ interopXContract: '',
6
6
  },
7
7
  137: {
8
8
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
9
9
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
10
- interopXGateway: '',
10
+ interopXContract: '0x41bd77583674B3a5c073FBb4922C0C8dA91C43cF',
11
11
  },
12
12
  43114: {
13
13
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
14
14
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
15
- interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
15
+ interopXContract: '0xCF391A3057eDba541c80307aC5E3Bc1E4a9471b7',
16
16
  }
17
17
  }
@@ -1,3 +1,2 @@
1
1
  export * from './addresses';
2
2
  export * from './tokens';
3
- export * from './itokens';
@@ -1,30 +1,42 @@
1
1
  export const tokens = {
2
2
  1: [
3
3
  {
4
+ aliases: ['eth'],
4
5
  symbol: "ETH",
5
6
  name: "Ethereum",
6
7
  address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
7
8
  decimals: 18,
8
9
  },
9
10
  {
11
+ aliases: ['weth'],
12
+ symbol: "WETH",
13
+ name: "Wrapped Ethereum",
14
+ address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
15
+ decimals: 18,
16
+ },
17
+ {
18
+ aliases: ['dai'],
10
19
  symbol: "DAI",
11
20
  name: "DAI Stable",
12
21
  address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
13
22
  decimals: 18,
14
23
  },
15
24
  {
25
+ aliases: ['usdc'],
16
26
  symbol: "USDC",
17
27
  name: "USD Coin",
18
28
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
19
29
  decimals: 6,
20
30
  },
21
31
  {
32
+ aliases: ['usdt'],
22
33
  symbol: "USDT",
23
34
  name: "Tether USD Coin",
24
35
  address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
25
36
  decimals: 6,
26
37
  },
27
38
  {
39
+ aliases: ['wbtc'],
28
40
  symbol: "WBTC",
29
41
  name: "Wrapped BTC",
30
42
  address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
@@ -33,36 +45,42 @@ export const tokens = {
33
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
82
  {
83
+ aliases: ['avax'],
66
84
  symbol: "AVAX",
67
85
  name: "Avalanche Token",
68
86
  address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
@@ -71,34 +89,46 @@ export const tokens = {
71
89
  ],
72
90
  43114: [
73
91
  {
92
+ aliases: ['eth', 'weth'],
74
93
  symbol: "ETH",
75
94
  name: "Ethereum",
76
95
  address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
77
96
  decimals: 18,
78
97
  },
79
98
  {
99
+ aliases: ['dai'],
80
100
  symbol: "DAI",
81
101
  name: "DAI Stable",
82
102
  address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
83
103
  decimals: 18,
84
104
  },
85
105
  {
106
+ aliases: ['usdc'],
86
107
  symbol: "USDC",
87
108
  name: "USD Coin",
88
109
  address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
89
110
  decimals: 6,
90
111
  },
91
112
  {
92
- symbol: "USDT",
113
+ aliases: ['usdt'],
114
+ symbol: "USDt",
93
115
  name: "Tether USD Coin",
116
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
117
+ decimals: 6,
118
+ },
119
+ {
120
+ aliases: ['usdt'],
121
+ symbol: "USDT.e",
122
+ name: "Tether USD",
94
123
  address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
95
124
  decimals: 6,
96
125
  },
97
126
  {
127
+ aliases: ["wbtc"],
98
128
  symbol: "WBTC",
99
129
  name: "Wrapped BTC",
100
130
  address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
101
131
  decimals: 8,
102
132
  },
103
133
  ],
104
- };
134
+ } as Record<number, { aliases: string[], symbol: string, name: string, address: string, decimals: number }[]>;
@@ -1,21 +1,32 @@
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
+
20
+ declare actionId: string;
21
+ declare bridger: string;
22
+ declare requestTransactionHash: string;
11
23
 
12
- declare submitTransactionHash: string;
13
- declare submitBlockNumber: number;
24
+ declare requestBlockNumber: number;
14
25
 
15
26
  declare sourceChainId: number;
16
27
  declare sourceTransactionHash: CreationOptional<string>;
17
28
  declare sourceBlockNumber: CreationOptional<number>;
18
- declare sourceStatus: string;
29
+ declare sourceStatus: CreationOptional<string>;
19
30
  declare sourceErrors: CreationOptional<string[]>;
20
31
  declare sourceLogs: CreationOptional<any[]>;
21
32
  declare sourceCreatedAt: CreationOptional<Date>;
@@ -24,19 +35,33 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
24
35
  declare targetChainId: number;
25
36
  declare targetTransactionHash: CreationOptional<string>;
26
37
  declare targetBlockNumber: CreationOptional<number>;
27
- declare targetStatus: string;
38
+ declare targetStatus: CreationOptional<string>;
28
39
  declare targetErrors: CreationOptional<string[]>;
29
40
  declare targetLogs: CreationOptional<any[]>;
30
41
  declare targetCreatedAt: CreationOptional<Date>;
31
42
  declare targetDelayUntil: CreationOptional<Date>;
32
43
 
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;
44
+ declare requestEvent: {
45
+ actionId: string;
46
+ bridger: string;
47
+ metadata: string;
48
+ position: IPosition;
49
+ sourceChainId: number;
50
+ targetChainId: number;
51
+ };
52
+ declare requestSentEvent: CreationOptional<{
53
+ actionId: string;
54
+ bridger: string;
55
+ metadata: string;
56
+ position: IPosition;
57
+ sourceChainId: number;
58
+ targetChainId: number;
59
+ requestTransactionHash: string;
60
+ }>;
61
+ declare committedEvent: CreationOptional<any>;
62
+ declare completedEvent: CreationOptional<any>;
63
+
64
+ declare status: CreationOptional<string>;
40
65
 
41
66
  declare createdAt: CreationOptional<Date>;
42
67
  declare updatedAt: CreationOptional<Date>;
@@ -49,19 +74,20 @@ Transaction.init({
49
74
  primaryKey: true
50
75
  },
51
76
 
52
- submitTransactionHash: DataTypes.NUMBER,
53
- submitBlockNumber: DataTypes.NUMBER,
77
+ requestTransactionHash: DataTypes.NUMBER,
78
+ requestBlockNumber: DataTypes.NUMBER,
54
79
 
55
80
  transactionHash: DataTypes.STRING,
56
- action: DataTypes.STRING,
57
-
58
- from: DataTypes.STRING,
59
- to: DataTypes.STRING,
81
+ actionId: DataTypes.STRING,
82
+ bridger: DataTypes.STRING,
60
83
 
61
84
  sourceChainId: DataTypes.NUMBER,
62
85
  sourceTransactionHash: DataTypes.STRING,
63
86
  sourceBlockNumber: DataTypes.NUMBER,
64
- sourceStatus: DataTypes.STRING,
87
+ sourceStatus: {
88
+ type: DataTypes.STRING,
89
+ defaultValue: 'uninitialised'
90
+ },
65
91
  sourceErrors: {
66
92
  type: DataTypes.JSON,
67
93
  // defaultValue: [],
@@ -79,7 +105,10 @@ Transaction.init({
79
105
  targetChainId: DataTypes.NUMBER,
80
106
  targetTransactionHash: DataTypes.STRING,
81
107
  targetBlockNumber: DataTypes.NUMBER,
82
- targetStatus: DataTypes.STRING,
108
+ targetStatus: {
109
+ type: DataTypes.STRING,
110
+ defaultValue: 'uninitialised'
111
+ },
83
112
  targetErrors: {
84
113
  type: DataTypes.JSON,
85
114
  // defaultValue: [],
@@ -91,11 +120,13 @@ Transaction.init({
91
120
  targetCreatedAt: DataTypes.DATE,
92
121
  targetDelayUntil: DataTypes.DATE,
93
122
 
94
- submitEvent: DataTypes.JSON,
95
- sourceEvent: DataTypes.JSON,
96
- targetEvent: DataTypes.JSON,
97
-
98
- metadata: DataTypes.JSON,
123
+ requestEvent: {
124
+ type: DataTypes.JSON,
125
+ allowNull: false
126
+ },
127
+ requestSentEvent: DataTypes.JSON,
128
+ committedEvent: DataTypes.JSON,
129
+ completedEvent: DataTypes.JSON,
99
130
 
100
131
  status: {
101
132
  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,77 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropXContract } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.actionId !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.actionId}`)
17
+ }
18
+
19
+ if (type !== 'source') {
20
+ throw new Error(`[WIP] Type not supported: ${type}`)
21
+ }
22
+
23
+ if (transaction.sourceStatus === 'pending') {
24
+ throw Error('Source transaction already processesing')
25
+ }
26
+
27
+ if (transaction.sourceStatus === 'pending') {
28
+ throw Error('Source transaction already processed')
29
+ }
30
+
31
+ if (!transaction.requestEvent) {
32
+ throw Error('Something went wrong, source transaction has no request event')
33
+ }
34
+
35
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata} = transaction.requestEvent;
36
+
37
+ const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
38
+ const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
39
+ const contractAddress = addresses[sourceChainId].interopXContract;
40
+ const contract = getContract<InteropXContract>(contractAddress, abi.interopXContract, sourceWallet);
41
+
42
+ const sourceToken = tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
43
+
44
+ if (!sourceToken) {
45
+ throw Error('Source token not found')
46
+ }
47
+
48
+ const targetToken = tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
49
+
50
+ if (!targetToken) {
51
+ throw Error('Target token not found')
52
+ }
53
+
54
+ if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
55
+ throw Error('Source and target token must be the same')
56
+ }
57
+
58
+ const { data } = await contract.populateTransaction.withdrawRequested(
59
+ actionId,
60
+ bridger,
61
+ position.withdraw[0].sourceToken,
62
+ position.withdraw[0].targetToken,
63
+ position.withdraw[0].amount,
64
+ targetChainId,
65
+ transaction.requestTransactionHash,
66
+ metadata,
67
+ );
68
+
69
+ transactions.push({
70
+ to: contractAddress,
71
+ data: data!,
72
+ value: '0',
73
+ operation: OperationType.Call,
74
+ });
75
+
76
+ return { transactions, logs }
77
+ }
@@ -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
@@ -89,7 +89,9 @@ async function main() {
89
89
 
90
90
  const tasks = new Tasks()
91
91
 
92
- tasks.start();
92
+ setTimeout(() => {
93
+ tasks.start();
94
+ }, 10000)
93
95
 
94
96
  startApiServer()
95
97
 
@@ -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 });