@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.
- package/dist/package.json +4 -2
- package/dist/src/abi/aaveV3Resolver.json +628 -0
- package/dist/src/abi/index.js +2 -0
- package/dist/src/constants/addresses.js +4 -2
- package/dist/src/db/models/transaction.js +1 -1
- package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
- package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
- package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
- package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
- package/dist/src/gnosis/actions/index.js +2 -0
- package/dist/src/index.js +1 -1
- package/dist/src/providers/index.js +17 -0
- package/dist/src/providers/retry-provider.js +45 -0
- package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +38 -10
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
- package/dist/src/typechain/AaveV3Resolver.js +2 -0
- package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
- package/dist/src/typechain/factories/index.js +3 -1
- package/dist/src/typechain/index.js +3 -1
- package/dist/src/utils/gnosis.js +42 -17
- package/dist/src/utils/validate.js +10 -14
- package/package.json +4 -2
- package/src/abi/aaveV3Resolver.json +628 -0
- package/src/abi/index.ts +2 -0
- package/src/constants/addresses.ts +6 -3
- package/src/db/models/transaction.ts +1 -1
- package/src/gnosis/actions/aaveV2/source.ts +58 -2
- package/src/gnosis/actions/aaveV2/target.ts +29 -2
- package/src/gnosis/actions/aaveV3/index.ts +9 -0
- package/src/gnosis/actions/aaveV3/source.ts +119 -0
- package/src/gnosis/actions/aaveV3/target.ts +142 -0
- package/src/gnosis/actions/index.ts +2 -0
- package/src/providers/index.ts +1 -0
- package/src/providers/retry-provider.ts +51 -0
- package/src/tasks/InteropX/ProcessSubmitEvents.ts +52 -13
- package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -13
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
- package/src/typechain/factories/index.ts +1 -0
- package/src/typechain/index.ts +2 -0
- package/src/utils/gnosis.ts +75 -32
- 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";
|
package/src/typechain/index.ts
CHANGED
@@ -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";
|
package/src/utils/gnosis.ts
CHANGED
@@ -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
|
-
|
24
|
-
|
25
|
-
to,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
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
|
+
}
|
package/src/utils/validate.ts
CHANGED
@@ -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
|
40
|
+
sourceProvider = null as unknown as JsonRpcRetryProvider,
|
39
41
|
}) => {
|
40
|
-
sourceProvider = sourceProvider || new
|
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.
|
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
|
72
|
+
targetProvider = null as unknown as JsonRpcRetryProvider,
|
73
73
|
}) => {
|
74
|
-
targetProvider = targetProvider || new
|
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.
|
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:
|
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
|
133
|
+
const supplyPosition = position.supply;
|
136
134
|
|
137
|
-
for (const
|
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)) {
|