@instadapp/interop-x 0.0.0-dev.d71f27e → 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.
@@ -17,7 +17,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
17
17
 
18
18
  declare transactionHash: string;
19
19
 
20
- declare action: string;
20
+ declare actionId: string;
21
21
  declare bridger: string;
22
22
  declare requestTransactionHash: string;
23
23
 
@@ -42,6 +42,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
42
42
  declare targetDelayUntil: CreationOptional<Date>;
43
43
 
44
44
  declare requestEvent: {
45
+ actionId: string;
45
46
  bridger: string;
46
47
  metadata: string;
47
48
  position: IPosition;
@@ -49,6 +50,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
49
50
  targetChainId: number;
50
51
  };
51
52
  declare requestSentEvent: CreationOptional<{
53
+ actionId: string;
52
54
  bridger: string;
53
55
  metadata: string;
54
56
  position: IPosition;
@@ -59,9 +61,6 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
59
61
  declare committedEvent: CreationOptional<any>;
60
62
  declare completedEvent: CreationOptional<any>;
61
63
 
62
- declare position: any;
63
- declare metadata: CreationOptional<any>;
64
-
65
64
  declare status: CreationOptional<string>;
66
65
 
67
66
  declare createdAt: CreationOptional<Date>;
@@ -79,7 +78,7 @@ Transaction.init({
79
78
  requestBlockNumber: DataTypes.NUMBER,
80
79
 
81
80
  transactionHash: DataTypes.STRING,
82
- action: DataTypes.STRING,
81
+ actionId: DataTypes.STRING,
83
82
  bridger: DataTypes.STRING,
84
83
 
85
84
  sourceChainId: DataTypes.NUMBER,
@@ -129,9 +128,6 @@ Transaction.init({
129
128
  committedEvent: DataTypes.JSON,
130
129
  completedEvent: DataTypes.JSON,
131
130
 
132
- position: DataTypes.JSON,
133
- metadata: DataTypes.JSON,
134
-
135
131
  status: {
136
132
  type: DataTypes.STRING,
137
133
  defaultValue: 'pending'
@@ -12,30 +12,51 @@ export default async function (transaction: Transaction, type: 'source' | 'targe
12
12
  const transactions: MetaTransaction[] = [];
13
13
  const logs: any[] = [];
14
14
 
15
- if (transaction.action !== 'withdraw') {
16
- throw new Error(`Invalid action: ${transaction.action}`)
15
+ if (transaction.actionId !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.actionId}`)
17
17
  }
18
18
 
19
19
  if (type !== 'source') {
20
- throw new Error(`Type not supported: ${type}`)
20
+ throw new Error(`[WIP] Type not supported: ${type}`)
21
21
  }
22
22
 
23
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
24
- throw Error('Cannot build data for pending withdraw transaction');
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')
25
29
  }
26
30
 
27
31
  if (!transaction.requestEvent) {
28
- throw Error('Cannot build data for transaction without requestEvent');
32
+ throw Error('Something went wrong, source transaction has no request event')
29
33
  }
30
34
 
31
- const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
35
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata} = transaction.requestEvent;
32
36
 
33
37
  const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
34
38
  const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
35
39
  const contractAddress = addresses[sourceChainId].interopXContract;
36
40
  const contract = getContract<InteropXContract>(contractAddress, abi.interopXContract, sourceWallet);
37
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
+
38
58
  const { data } = await contract.populateTransaction.withdrawRequested(
59
+ actionId,
39
60
  bridger,
40
61
  position.withdraw[0].sourceToken,
41
62
  position.withdraw[0].targetToken,
@@ -5,9 +5,9 @@ import actions from "./actions";
5
5
  export const buildGnosisAction = async (transaction: Transaction, type: 'source' | 'target') => {
6
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
  }
@@ -40,10 +40,10 @@ class SyncBridgeRequestEvents extends BaseTask {
40
40
  continue;
41
41
  }
42
42
 
43
- const { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
43
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = event.args;
44
44
 
45
45
  const uniqueIdentifier = {
46
- action: 'withdraw', //todo
46
+ actionId,
47
47
  bridger,
48
48
  requestTransactionHash: event.transactionHash,
49
49
  sourceChainId: sourceChainId.toNumber(),
@@ -61,10 +61,9 @@ class SyncBridgeRequestEvents extends BaseTask {
61
61
  await Transaction.create({
62
62
  transactionHash,
63
63
  ...uniqueIdentifier,
64
- position,
65
- metadata,
66
64
  requestBlockNumber: event.blockNumber,
67
65
  requestEvent: {
66
+ actionId,
68
67
  bridger,
69
68
  position: {
70
69
  withdraw: position.withdraw.map((v) => ({
@@ -41,10 +41,10 @@ class SyncBridgeRequestSentEvents extends BaseTask {
41
41
  continue;
42
42
  }
43
43
 
44
- const { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
44
+ const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
45
45
 
46
46
  const uniqueIdentifier = {
47
- action: 'withdraw',
47
+ actionId,
48
48
  bridger,
49
49
  requestTransactionHash,
50
50
  sourceChainId: sourceChainId,
@@ -68,6 +68,7 @@ class SyncBridgeRequestSentEvents extends BaseTask {
68
68
  transaction.sourceBlockNumber = event.blockNumber;
69
69
  transaction.sourceTransactionHash = event.transactionHash
70
70
  transaction.requestSentEvent = {
71
+ actionId,
71
72
  bridger,
72
73
  position: {
73
74
  withdraw: position.withdraw.map((v) => ({