@instadapp/interop-x 0.0.0-dev.f39d622 → 0.0.0-dev.f45bd03

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 (49) hide show
  1. package/dist/package.json +4 -2
  2. package/dist/src/abi/aaveV3Resolver.json +628 -0
  3. package/dist/src/abi/index.js +2 -0
  4. package/dist/src/constants/addresses.js +4 -2
  5. package/dist/src/db/models/transaction.js +1 -1
  6. package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
  7. package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
  8. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  9. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  10. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  11. package/dist/src/gnosis/actions/index.js +2 -0
  12. package/dist/src/index.js +1 -1
  13. package/dist/src/providers/index.js +17 -0
  14. package/dist/src/providers/retry-provider.js +45 -0
  15. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +38 -10
  16. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
  17. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
  18. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
  19. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
  20. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  21. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  22. package/dist/src/typechain/factories/index.js +3 -1
  23. package/dist/src/typechain/index.js +3 -1
  24. package/dist/src/utils/gnosis.js +42 -17
  25. package/dist/src/utils/validate.js +10 -14
  26. package/package.json +4 -2
  27. package/src/abi/aaveV3Resolver.json +628 -0
  28. package/src/abi/index.ts +2 -0
  29. package/src/constants/addresses.ts +6 -3
  30. package/src/db/models/transaction.ts +1 -1
  31. package/src/gnosis/actions/aaveV2/source.ts +58 -2
  32. package/src/gnosis/actions/aaveV2/target.ts +29 -2
  33. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  34. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  35. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  36. package/src/gnosis/actions/index.ts +2 -0
  37. package/src/providers/index.ts +1 -0
  38. package/src/providers/retry-provider.ts +51 -0
  39. package/src/tasks/InteropX/ProcessSubmitEvents.ts +52 -13
  40. package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -13
  41. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
  42. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
  43. package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
  44. package/src/typechain/AaveV3Resolver.ts +935 -0
  45. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  46. package/src/typechain/factories/index.ts +1 -0
  47. package/src/typechain/index.ts +2 -0
  48. package/src/utils/gnosis.ts +75 -32
  49. package/src/utils/validate.ts +17 -19
@@ -2,6 +2,7 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
  export { AaveV2Resolver__factory } from "./AaveV2Resolver__factory";
5
+ export { AaveV3Resolver__factory } from "./AaveV3Resolver__factory";
5
6
  export { BalanceResolver__factory } from "./BalanceResolver__factory";
6
7
  export { Erc20__factory } from "./Erc20__factory";
7
8
  export { GnosisSafe__factory } from "./GnosisSafe__factory";
@@ -2,6 +2,7 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
  export type { AaveV2Resolver } from "./AaveV2Resolver";
5
+ export type { AaveV3Resolver } from "./AaveV3Resolver";
5
6
  export type { BalanceResolver } from "./BalanceResolver";
6
7
  export type { Erc20 } from "./Erc20";
7
8
  export type { GnosisSafe } from "./GnosisSafe";
@@ -9,6 +10,7 @@ export type { InstList } from "./InstList";
9
10
  export type { InteropX } from "./InteropX";
10
11
  export * as factories from "./factories";
11
12
  export { AaveV2Resolver__factory } from "./factories/AaveV2Resolver__factory";
13
+ export { AaveV3Resolver__factory } from "./factories/AaveV3Resolver__factory";
12
14
  export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
13
15
  export { Erc20__factory } from "./factories/Erc20__factory";
14
16
  export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
@@ -1,6 +1,8 @@
1
1
  import { addresses } from "@/constants";
2
+ import { peerPool } from "@/net";
2
3
  import { GnosisSafe } from "@/typechain";
3
4
  import { ChainId } from "@/types";
5
+ import { messagePrefix } from "@ethersproject/hash";
4
6
  import { ethers, Wallet } from "ethers";
5
7
 
6
8
  export interface Signature {
@@ -20,22 +22,23 @@ export const buildSignatureBytes = (signatures: Signature[]): string => {
20
22
  return signatureBytes;
21
23
  };
22
24
 
23
- export const signGnosisSafeTx = async (
24
- {
25
- to,
26
- data = null as any,
27
- value = "0",
28
- operation = "1",
29
- baseGas = "0",
30
- gasPrice = "0",
31
- gasToken = "0x0000000000000000000000000000000000000000",
32
- refundReceiver = "0x0000000000000000000000000000000000000000",
33
- safeTxGas = "79668" as string | number,
34
- nonce = "0",
35
- chainId = 137 as ChainId,
36
- },
37
- { signer }: { signer: Wallet }
38
- ) => {
25
+ const gnosisSignatureTypes = {
26
+ SafeTx: [
27
+ { type: "address", name: "to" },
28
+ { type: "uint256", name: "value" },
29
+ { type: "bytes", name: "data" },
30
+ { type: "uint8", name: "operation" },
31
+ { type: "uint256", name: "safeTxGas" },
32
+ { type: "uint256", name: "baseGas" },
33
+ { type: "uint256", name: "gasPrice" },
34
+ { type: "address", name: "gasToken" },
35
+ { type: "address", name: "refundReceiver" },
36
+ { type: "uint256", name: "nonce" },
37
+ ],
38
+ };
39
+
40
+ export const getGnosisSignatureAddress = ({ signature, message, chainId }: { signature: string, message: Record<string, any>, chainId: ChainId }) => {
41
+
39
42
  const gnosisSafe = addresses[chainId].gnosisSafe;
40
43
 
41
44
  const domain = {
@@ -43,20 +46,24 @@ export const signGnosisSafeTx = async (
43
46
  chainId,
44
47
  };
45
48
 
46
- const types = {
47
- SafeTx: [
48
- { type: "address", name: "to" },
49
- { type: "uint256", name: "value" },
50
- { type: "bytes", name: "data" },
51
- { type: "uint8", name: "operation" },
52
- { type: "uint256", name: "safeTxGas" },
53
- { type: "uint256", name: "baseGas" },
54
- { type: "uint256", name: "gasPrice" },
55
- { type: "address", name: "gasToken" },
56
- { type: "address", name: "refundReceiver" },
57
- { type: "uint256", name: "nonce" },
58
- ],
59
- };
49
+ return ethers.utils.verifyTypedData(domain, gnosisSignatureTypes, message, signature)
50
+
51
+ }
52
+
53
+ export const generateGnosisSignatureMessage = ({
54
+ to,
55
+ data = null as any,
56
+ value = "0",
57
+ operation = "1",
58
+ baseGas = "0",
59
+ gasPrice = "0",
60
+ gasToken = "0x0000000000000000000000000000000000000000",
61
+ refundReceiver = "0x0000000000000000000000000000000000000000",
62
+ safeTxGas = "79668" as string | number,
63
+ nonce = "0",
64
+ chainId = 137 as ChainId,
65
+ }) => {
66
+ const gnosisSafe = addresses[chainId].gnosisSafe;
60
67
 
61
68
  const message = {
62
69
  baseGas,
@@ -72,7 +79,33 @@ export const signGnosisSafeTx = async (
72
79
  value,
73
80
  };
74
81
 
75
- return await signer._signTypedData(domain, types, message);
82
+ return message;
83
+ }
84
+
85
+ export const signGnosisSafeTx = async ({
86
+ to,
87
+ data = null as any,
88
+ value = "0",
89
+ operation = "1",
90
+ baseGas = "0",
91
+ gasPrice = "0",
92
+ gasToken = "0x0000000000000000000000000000000000000000",
93
+ refundReceiver = "0x0000000000000000000000000000000000000000",
94
+ safeTxGas = "79668" as string | number,
95
+ nonce = "0",
96
+ chainId = 137 as ChainId,
97
+ }, { signer }: { signer: Wallet }
98
+ ) => {
99
+ const gnosisSafe = addresses[chainId].gnosisSafe;
100
+
101
+ const domain = {
102
+ verifyingContract: gnosisSafe,
103
+ chainId,
104
+ };
105
+
106
+ const message = generateGnosisSignatureMessage({ to, data, value, operation, baseGas, gasPrice, gasToken, refundReceiver, safeTxGas, nonce, chainId });
107
+
108
+ return await signer._signTypedData(domain, gnosisSignatureTypes, message);
76
109
  };
77
110
 
78
111
  export const generateGnosisTransaction = async (
@@ -120,4 +153,14 @@ export const generateGnosisTransaction = async (
120
153
  }
121
154
 
122
155
  return transactionData;
123
- };
156
+ };
157
+
158
+ export const getGnosisOwnerPeerIds = async ({ gnosisContract = null as unknown as GnosisSafe }) => {
159
+ const owners = await gnosisContract
160
+ .getOwners()
161
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
162
+
163
+ return peerPool.activePeers
164
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
165
+ .map((peer) => peer.id);
166
+ }
@@ -7,6 +7,8 @@ import BigNumber from "bignumber.js";
7
7
  import { chainIdToName, formatUsd } from "./formatting";
8
8
  import { isNativeWrappedToken } from "./tokens";
9
9
  import { Prices } from "@/services";
10
+ import { JsonRpcRetryProvider } from "@/providers";
11
+ import { IPosition } from "@/db";
10
12
 
11
13
  export const validateChains = ({ sourceChainId, targetChainId }) => {
12
14
  if (!sourceChainId) {
@@ -32,12 +34,12 @@ export const validateChains = ({ sourceChainId, targetChainId }) => {
32
34
 
33
35
 
34
36
  export const validateSourceLiquidity = async ({
35
- position,
37
+ position = null as unknown as IPosition,
36
38
  sourceChainId,
37
39
  isSupply = false,
38
- sourceProvider = null as unknown as ethers.providers.JsonRpcProvider,
40
+ sourceProvider = null as unknown as JsonRpcRetryProvider,
39
41
  }) => {
40
- sourceProvider = sourceProvider || new ethers.providers.JsonRpcProvider(getRpcProviderUrl(sourceChainId));
42
+ sourceProvider = sourceProvider || new JsonRpcRetryProvider(getRpcProviderUrl(sourceChainId));
41
43
 
42
44
 
43
45
  const sourceBalanceResolverContract = getContract(
@@ -46,9 +48,7 @@ export const validateSourceLiquidity = async ({
46
48
  sourceProvider,
47
49
  )
48
50
 
49
- const srcBalance = await sourceBalanceResolverContract.methods
50
- .checkLiquidity(position, addresses[sourceChainId].interopX, isSupply, false)
51
- .call();
51
+ const srcBalance = await sourceBalanceResolverContract.checkLiquidity(position, addresses[sourceChainId].interopX, isSupply, false)
52
52
 
53
53
  if (!srcBalance.isOk) {
54
54
 
@@ -67,11 +67,11 @@ export const validateSourceLiquidity = async ({
67
67
  };
68
68
 
69
69
  export const validateTargetLiquidity = async ({
70
- position,
70
+ position = null as unknown as IPosition,
71
71
  targetChainId,
72
- targetProvider = null as unknown as ethers.providers.JsonRpcProvider,
72
+ targetProvider = null as unknown as JsonRpcRetryProvider,
73
73
  }) => {
74
- targetProvider = targetProvider || new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId));
74
+ targetProvider = targetProvider || new JsonRpcRetryProvider(getRpcProviderUrl(targetChainId));
75
75
 
76
76
 
77
77
  const sourceBalanceResolverContract = getContract(
@@ -80,9 +80,7 @@ export const validateTargetLiquidity = async ({
80
80
  targetProvider,
81
81
  )
82
82
 
83
- const targetBalance = await sourceBalanceResolverContract.methods
84
- .checkLiquidity(position, addresses[targetChainId].interopX, true, true)
85
- .call();
83
+ const targetBalance = await sourceBalanceResolverContract.checkLiquidity(position, addresses[targetChainId].interopX, true, true)
86
84
 
87
85
  if (!targetBalance.isOk) {
88
86
 
@@ -103,7 +101,7 @@ export const validateTargetLiquidity = async ({
103
101
 
104
102
  const mapTokenAddressToMainnetToken = (
105
103
  address: string,
106
- targetChainId: number|string
104
+ targetChainId: number | string
107
105
  ) => {
108
106
  targetChainId = String(targetChainId);
109
107
  const token = tokens[targetChainId].find(
@@ -122,9 +120,9 @@ const mapTokenAddressToMainnetToken = (
122
120
  };
123
121
 
124
122
  export const validateLiquidityCap = async (
125
- position: any,
126
- sourceChainId: number|string,
127
- targetChainId: number|string
123
+ position: IPosition,
124
+ sourceChainId: number | string,
125
+ targetChainId: number | string
128
126
  ) => {
129
127
  const cap = capPerChain[targetChainId] || 1_000_000;
130
128
  const mainnetPrices = Prices.getMainnetPrices();
@@ -132,9 +130,9 @@ export const validateLiquidityCap = async (
132
130
 
133
131
  let total = new BigNumber(0);
134
132
 
135
- const supplyPosition = position[0];
133
+ const supplyPosition = position.supply;
136
134
 
137
- for (const [srcTokenAddress, tokenAddress, amount] of supplyPosition) {
135
+ for (const { sourceToken: srcTokenAddress, targetToken: tokenAddress, amount } of supplyPosition) {
138
136
  let tokenPrice;
139
137
  let token;
140
138
 
@@ -160,7 +158,7 @@ export const validateLiquidityCap = async (
160
158
  }
161
159
 
162
160
 
163
- total = total.plus((tokenPrice * amount) / 10 ** token.decimals);
161
+ total = total.plus((tokenPrice * Number(amount)) / 10 ** token.decimals);
164
162
  }
165
163
 
166
164
  if (total.isGreaterThan(cap)) {