@instadapp/interop-x 0.0.0-dev.e916c22 → 0.0.0-dev.ea4acf6
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 +9 -2
- package/dist/src/abi/aaveV2Resolver.json +832 -0
- package/dist/src/abi/aaveV3Resolver.json +628 -0
- package/dist/src/abi/balanceResolver.json +211 -0
- package/dist/src/abi/index.js +6 -0
- package/dist/src/api/index.js +7 -0
- package/dist/src/constants/addresses.js +6 -0
- package/dist/src/constants/capPerChain.js +8 -0
- package/dist/src/constants/index.js +2 -0
- package/dist/src/constants/tokens.js +44 -44
- package/dist/src/constants/wrappedNativeToken.js +8 -0
- package/dist/src/crons/index.js +3 -0
- package/dist/src/crons/prices.js +16 -0
- package/dist/src/db/models/transaction.js +1 -1
- package/dist/src/errors/index.js +30 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
- package/dist/src/gnosis/actions/aaveV2/target.js +18 -4
- 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 +2 -1
- package/dist/src/providers/index.js +17 -0
- package/dist/src/providers/retry-provider.js +45 -0
- package/dist/src/services/Prices.js +74 -0
- package/dist/src/services/index.js +8 -0
- package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +108 -14
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +30 -10
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +3 -2
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +3 -2
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +3 -2
- package/dist/src/tasks/index.js +3 -4
- package/dist/src/typechain/AaveV2Resolver.js +2 -0
- package/dist/src/typechain/AaveV3Resolver.js +2 -0
- package/dist/src/typechain/BalanceResolver.js +2 -0
- package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
- package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
- package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
- package/dist/src/typechain/factories/index.js +7 -1
- package/dist/src/typechain/index.js +7 -1
- package/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +36 -0
- package/dist/src/utils/formatting.js +67 -0
- package/dist/src/utils/gnosis.js +87 -0
- package/dist/src/utils/http.js +10 -0
- package/dist/src/utils/index.js +22 -220
- package/dist/src/utils/interop.js +16 -0
- package/dist/src/utils/tokens.js +22 -0
- package/dist/src/utils/validate.js +111 -0
- package/dist/src/utils/web3.js +93 -0
- package/package.json +9 -2
- package/src/abi/aaveV2Resolver.json +832 -0
- package/src/abi/aaveV3Resolver.json +628 -0
- package/src/abi/balanceResolver.json +211 -0
- package/src/abi/index.ts +6 -0
- package/src/api/index.ts +8 -0
- package/src/constants/addresses.ts +18 -1
- package/src/constants/capPerChain.ts +5 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/tokens.ts +44 -44
- package/src/constants/wrappedNativeToken.ts +5 -0
- package/src/crons/index.ts +1 -0
- package/src/crons/prices.ts +12 -0
- package/src/db/models/transaction.ts +1 -1
- package/src/errors/index.ts +26 -0
- package/src/gnosis/actions/aaveV2/source.ts +56 -3
- package/src/gnosis/actions/aaveV2/target.ts +30 -11
- 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/index.ts +1 -0
- package/src/providers/index.ts +1 -0
- package/src/providers/retry-provider.ts +51 -0
- package/src/services/Prices.ts +89 -0
- package/src/services/index.ts +1 -0
- package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +135 -20
- package/src/tasks/InteropX/ProcessValidateEvents.ts +42 -19
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +5 -6
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +6 -7
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +6 -7
- package/src/tasks/index.ts +3 -4
- package/src/typechain/AaveV2Resolver.ts +1017 -0
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/BalanceResolver.ts +266 -0
- package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
- package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
- package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
- package/src/typechain/factories/index.ts +3 -0
- package/src/typechain/index.ts +6 -0
- package/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +56 -0
- package/src/utils/formatting.ts +68 -0
- package/src/utils/gnosis.ts +166 -0
- package/src/utils/http.ts +6 -0
- package/src/utils/index.ts +9 -365
- package/src/utils/interop.ts +28 -0
- package/src/utils/tokens.ts +21 -0
- package/src/utils/validate.ts +179 -0
- package/src/utils/web3.ts +132 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
|
5
|
+
import { Contract, Signer, utils } from "ethers";
|
6
|
+
import type { Provider } from "@ethersproject/providers";
|
7
|
+
import type {
|
8
|
+
BalanceResolver,
|
9
|
+
BalanceResolverInterface,
|
10
|
+
} from "../BalanceResolver";
|
11
|
+
|
12
|
+
const _abi = [
|
13
|
+
{
|
14
|
+
inputs: [
|
15
|
+
{
|
16
|
+
internalType: "address",
|
17
|
+
name: "_wnativeToken",
|
18
|
+
type: "address",
|
19
|
+
},
|
20
|
+
],
|
21
|
+
stateMutability: "nonpayable",
|
22
|
+
type: "constructor",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
inputs: [
|
26
|
+
{
|
27
|
+
components: [
|
28
|
+
{
|
29
|
+
components: [
|
30
|
+
{
|
31
|
+
internalType: "address",
|
32
|
+
name: "sourceToken",
|
33
|
+
type: "address",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
internalType: "address",
|
37
|
+
name: "targetToken",
|
38
|
+
type: "address",
|
39
|
+
},
|
40
|
+
{
|
41
|
+
internalType: "uint256",
|
42
|
+
name: "amount",
|
43
|
+
type: "uint256",
|
44
|
+
},
|
45
|
+
],
|
46
|
+
internalType: "struct Variables.TokenInfo[]",
|
47
|
+
name: "supply",
|
48
|
+
type: "tuple[]",
|
49
|
+
},
|
50
|
+
{
|
51
|
+
components: [
|
52
|
+
{
|
53
|
+
internalType: "address",
|
54
|
+
name: "sourceToken",
|
55
|
+
type: "address",
|
56
|
+
},
|
57
|
+
{
|
58
|
+
internalType: "address",
|
59
|
+
name: "targetToken",
|
60
|
+
type: "address",
|
61
|
+
},
|
62
|
+
{
|
63
|
+
internalType: "uint256",
|
64
|
+
name: "amount",
|
65
|
+
type: "uint256",
|
66
|
+
},
|
67
|
+
],
|
68
|
+
internalType: "struct Variables.TokenInfo[]",
|
69
|
+
name: "withdraw",
|
70
|
+
type: "tuple[]",
|
71
|
+
},
|
72
|
+
],
|
73
|
+
internalType: "struct Variables.Position",
|
74
|
+
name: "position",
|
75
|
+
type: "tuple",
|
76
|
+
},
|
77
|
+
{
|
78
|
+
internalType: "address",
|
79
|
+
name: "liquidityContract",
|
80
|
+
type: "address",
|
81
|
+
},
|
82
|
+
{
|
83
|
+
internalType: "bool",
|
84
|
+
name: "isSupply",
|
85
|
+
type: "bool",
|
86
|
+
},
|
87
|
+
{
|
88
|
+
internalType: "bool",
|
89
|
+
name: "isTargetToken",
|
90
|
+
type: "bool",
|
91
|
+
},
|
92
|
+
],
|
93
|
+
name: "checkLiquidity",
|
94
|
+
outputs: [
|
95
|
+
{
|
96
|
+
components: [
|
97
|
+
{
|
98
|
+
internalType: "bool",
|
99
|
+
name: "isOk",
|
100
|
+
type: "bool",
|
101
|
+
},
|
102
|
+
{
|
103
|
+
components: [
|
104
|
+
{
|
105
|
+
internalType: "address",
|
106
|
+
name: "token",
|
107
|
+
type: "address",
|
108
|
+
},
|
109
|
+
{
|
110
|
+
internalType: "uint256",
|
111
|
+
name: "liquidityAvailable",
|
112
|
+
type: "uint256",
|
113
|
+
},
|
114
|
+
{
|
115
|
+
internalType: "uint256",
|
116
|
+
name: "liquidityShort",
|
117
|
+
type: "uint256",
|
118
|
+
},
|
119
|
+
],
|
120
|
+
internalType: "struct Helpers.LiquidityData[]",
|
121
|
+
name: "supply",
|
122
|
+
type: "tuple[]",
|
123
|
+
},
|
124
|
+
{
|
125
|
+
components: [
|
126
|
+
{
|
127
|
+
internalType: "address",
|
128
|
+
name: "token",
|
129
|
+
type: "address",
|
130
|
+
},
|
131
|
+
{
|
132
|
+
internalType: "uint256",
|
133
|
+
name: "liquidityAvailable",
|
134
|
+
type: "uint256",
|
135
|
+
},
|
136
|
+
{
|
137
|
+
internalType: "uint256",
|
138
|
+
name: "liquidityShort",
|
139
|
+
type: "uint256",
|
140
|
+
},
|
141
|
+
],
|
142
|
+
internalType: "struct Helpers.LiquidityData[]",
|
143
|
+
name: "withdraw",
|
144
|
+
type: "tuple[]",
|
145
|
+
},
|
146
|
+
],
|
147
|
+
internalType: "struct Helpers.PositionData",
|
148
|
+
name: "p",
|
149
|
+
type: "tuple",
|
150
|
+
},
|
151
|
+
],
|
152
|
+
stateMutability: "view",
|
153
|
+
type: "function",
|
154
|
+
},
|
155
|
+
{
|
156
|
+
inputs: [
|
157
|
+
{
|
158
|
+
internalType: "address[]",
|
159
|
+
name: "tokens",
|
160
|
+
type: "address[]",
|
161
|
+
},
|
162
|
+
{
|
163
|
+
internalType: "address",
|
164
|
+
name: "liquidityContract",
|
165
|
+
type: "address",
|
166
|
+
},
|
167
|
+
],
|
168
|
+
name: "getLiquidity",
|
169
|
+
outputs: [
|
170
|
+
{
|
171
|
+
components: [
|
172
|
+
{
|
173
|
+
internalType: "address",
|
174
|
+
name: "token",
|
175
|
+
type: "address",
|
176
|
+
},
|
177
|
+
{
|
178
|
+
internalType: "uint256",
|
179
|
+
name: "liquidityAvailable",
|
180
|
+
type: "uint256",
|
181
|
+
},
|
182
|
+
{
|
183
|
+
internalType: "uint256",
|
184
|
+
name: "liquidityShort",
|
185
|
+
type: "uint256",
|
186
|
+
},
|
187
|
+
],
|
188
|
+
internalType: "struct Helpers.LiquidityData[]",
|
189
|
+
name: "l",
|
190
|
+
type: "tuple[]",
|
191
|
+
},
|
192
|
+
],
|
193
|
+
stateMutability: "view",
|
194
|
+
type: "function",
|
195
|
+
},
|
196
|
+
{
|
197
|
+
inputs: [],
|
198
|
+
name: "nativeToken",
|
199
|
+
outputs: [
|
200
|
+
{
|
201
|
+
internalType: "address",
|
202
|
+
name: "",
|
203
|
+
type: "address",
|
204
|
+
},
|
205
|
+
],
|
206
|
+
stateMutability: "view",
|
207
|
+
type: "function",
|
208
|
+
},
|
209
|
+
{
|
210
|
+
inputs: [],
|
211
|
+
name: "wnativeToken",
|
212
|
+
outputs: [
|
213
|
+
{
|
214
|
+
internalType: "address",
|
215
|
+
name: "",
|
216
|
+
type: "address",
|
217
|
+
},
|
218
|
+
],
|
219
|
+
stateMutability: "view",
|
220
|
+
type: "function",
|
221
|
+
},
|
222
|
+
];
|
223
|
+
|
224
|
+
export class BalanceResolver__factory {
|
225
|
+
static readonly abi = _abi;
|
226
|
+
static createInterface(): BalanceResolverInterface {
|
227
|
+
return new utils.Interface(_abi) as BalanceResolverInterface;
|
228
|
+
}
|
229
|
+
static connect(
|
230
|
+
address: string,
|
231
|
+
signerOrProvider: Signer | Provider
|
232
|
+
): BalanceResolver {
|
233
|
+
return new Contract(address, _abi, signerOrProvider) as BalanceResolver;
|
234
|
+
}
|
235
|
+
}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
/* Autogenerated file. Do not edit manually. */
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
|
+
export { AaveV2Resolver__factory } from "./AaveV2Resolver__factory";
|
5
|
+
export { AaveV3Resolver__factory } from "./AaveV3Resolver__factory";
|
6
|
+
export { BalanceResolver__factory } from "./BalanceResolver__factory";
|
4
7
|
export { Erc20__factory } from "./Erc20__factory";
|
5
8
|
export { GnosisSafe__factory } from "./GnosisSafe__factory";
|
6
9
|
export { InstList__factory } from "./InstList__factory";
|
package/src/typechain/index.ts
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
/* Autogenerated file. Do not edit manually. */
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
|
+
export type { AaveV2Resolver } from "./AaveV2Resolver";
|
5
|
+
export type { AaveV3Resolver } from "./AaveV3Resolver";
|
6
|
+
export type { BalanceResolver } from "./BalanceResolver";
|
4
7
|
export type { Erc20 } from "./Erc20";
|
5
8
|
export type { GnosisSafe } from "./GnosisSafe";
|
6
9
|
export type { InstList } from "./InstList";
|
7
10
|
export type { InteropX } from "./InteropX";
|
8
11
|
export * as factories from "./factories";
|
12
|
+
export { AaveV2Resolver__factory } from "./factories/AaveV2Resolver__factory";
|
13
|
+
export { AaveV3Resolver__factory } from "./factories/AaveV3Resolver__factory";
|
14
|
+
export { BalanceResolver__factory } from "./factories/BalanceResolver__factory";
|
9
15
|
export { Erc20__factory } from "./factories/Erc20__factory";
|
10
16
|
export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
|
11
17
|
export { InstList__factory } from "./factories/InstList__factory";
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* Call an async function with a maximum time limit (in milliseconds) for the timeout
|
3
|
+
* Resolved promise for async function call, or an error if time limit reached
|
4
|
+
*/
|
5
|
+
export const asyncCallWithTimeout = async <T>(
|
6
|
+
asyncPromise: Promise<T>,
|
7
|
+
timeout: number
|
8
|
+
) => {
|
9
|
+
let timeoutHandle;
|
10
|
+
|
11
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
12
|
+
timeoutHandle = setTimeout(
|
13
|
+
() => reject(new Error("Async call timeout limit reached")),
|
14
|
+
timeout
|
15
|
+
);
|
16
|
+
});
|
17
|
+
|
18
|
+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
|
19
|
+
clearTimeout(timeoutHandle);
|
20
|
+
return result;
|
21
|
+
}) as Promise<T>;
|
22
|
+
};
|
package/src/utils/dsa.ts
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
import Web3EthAbi from "web3-eth-abi";
|
2
|
+
import { connectors } from "@/abi/connectors";
|
3
|
+
import { getContract, getRpcProviderUrl } from "./web3";
|
4
|
+
import { InstList } from "@/typechain";
|
5
|
+
import { addresses } from "@/constants";
|
6
|
+
import abi from "@/abi";
|
7
|
+
import { JsonRpcRetryProvider } from "@/providers";
|
8
|
+
import { ChainId } from "@/types";
|
9
|
+
import { ethers } from "ethers";
|
10
|
+
|
11
|
+
export const encodeConnectorMethod = (params: {
|
12
|
+
connector: string;
|
13
|
+
method: string;
|
14
|
+
args: string[];
|
15
|
+
}) => {
|
16
|
+
const connectorInterface = getInterface(
|
17
|
+
connectors.versions[2][params.connector],
|
18
|
+
params.method
|
19
|
+
);
|
20
|
+
|
21
|
+
if (!connectorInterface)
|
22
|
+
throw new Error(`ConnectorInterface '${params.method}' not found`);
|
23
|
+
|
24
|
+
//@ts-ignore
|
25
|
+
return Web3EthAbi.encodeFunctionCall(connectorInterface, params.args);
|
26
|
+
};
|
27
|
+
|
28
|
+
const getInterface = (abiItems: any[], method: string) => {
|
29
|
+
const abiItem = abiItems.find((abiItem) => abiItem.name === method);
|
30
|
+
|
31
|
+
if (!abiItem) {
|
32
|
+
console.error(`${method} is an invalid method.`);
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
return abiItem;
|
37
|
+
};
|
38
|
+
|
39
|
+
|
40
|
+
export const getDsaAccountAddress = async ({
|
41
|
+
dsaId,
|
42
|
+
chainId,
|
43
|
+
provider = null as ethers.providers.Provider | null,
|
44
|
+
}) => {
|
45
|
+
if (!dsaId) throw new Error("DSA id is required");
|
46
|
+
|
47
|
+
provider = provider || new JsonRpcRetryProvider(getRpcProviderUrl(chainId));
|
48
|
+
|
49
|
+
const instListContract = getContract<InstList>(
|
50
|
+
addresses[chainId].instList,
|
51
|
+
abi.instList,
|
52
|
+
provider,
|
53
|
+
);
|
54
|
+
|
55
|
+
return await instListContract.accountAddr(dsaId)
|
56
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
const locale = "en-US";
|
2
|
+
|
3
|
+
export function formatUsd(value: any, fractionDigits = 0) {
|
4
|
+
const formatter = new Intl.NumberFormat(locale, {
|
5
|
+
style: "currency",
|
6
|
+
currency: "USD",
|
7
|
+
minimumFractionDigits: fractionDigits,
|
8
|
+
maximumFractionDigits: fractionDigits
|
9
|
+
});
|
10
|
+
|
11
|
+
return formatter.format(value);
|
12
|
+
}
|
13
|
+
|
14
|
+
export function shortenHash(hash: string, length: number = 4) {
|
15
|
+
if (!hash) return;
|
16
|
+
|
17
|
+
if (hash.length < 12) return hash;
|
18
|
+
|
19
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
20
|
+
|
21
|
+
const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
|
22
|
+
|
23
|
+
return shortened;
|
24
|
+
}
|
25
|
+
|
26
|
+
export function short(buffer: Buffer): string {
|
27
|
+
return buffer.toString("hex").slice(0, 8) + "...";
|
28
|
+
}
|
29
|
+
|
30
|
+
export const chainIdToName = (chainId: string | number) => {
|
31
|
+
switch (String(chainId)) {
|
32
|
+
case "1":
|
33
|
+
return "Mainnet";
|
34
|
+
case "137":
|
35
|
+
return "Polygon";
|
36
|
+
case "43114":
|
37
|
+
return "Avalanche";
|
38
|
+
default:
|
39
|
+
return "Mainnet";
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
export const getChainIdNativeSymbol = (chainId: string | number) => {
|
44
|
+
switch (String(chainId)) {
|
45
|
+
case "137":
|
46
|
+
return "MATIC";
|
47
|
+
case "43114":
|
48
|
+
return "AVAX";
|
49
|
+
case "1":
|
50
|
+
return "ETH";
|
51
|
+
default:
|
52
|
+
return "ETH";
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
|
57
|
+
export const getExplorerUrl = (chainId: string | number, suffix = '/') => {
|
58
|
+
switch (String(chainId)) {
|
59
|
+
case "1":
|
60
|
+
return `https://etherscan.io${suffix}`;
|
61
|
+
case "137":
|
62
|
+
return `https://polygonscan.com${suffix}`;
|
63
|
+
case "43114":
|
64
|
+
return `https://snowtrace.io${suffix}`;
|
65
|
+
default:
|
66
|
+
return `https://etherscan.io${suffix}`;
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
import { addresses } from "@/constants";
|
2
|
+
import { peerPool } from "@/net";
|
3
|
+
import { GnosisSafe } from "@/typechain";
|
4
|
+
import { ChainId } from "@/types";
|
5
|
+
import { messagePrefix } from "@ethersproject/hash";
|
6
|
+
import { ethers, Wallet } from "ethers";
|
7
|
+
|
8
|
+
export interface Signature {
|
9
|
+
signer: string;
|
10
|
+
hash?: string;
|
11
|
+
data: string;
|
12
|
+
}
|
13
|
+
|
14
|
+
export const buildSignatureBytes = (signatures: Signature[]): string => {
|
15
|
+
signatures.sort((left, right) =>
|
16
|
+
left.signer.toLowerCase().localeCompare(right.signer.toLowerCase())
|
17
|
+
);
|
18
|
+
let signatureBytes = "0x";
|
19
|
+
for (const sig of signatures) {
|
20
|
+
signatureBytes += sig.data.slice(2);
|
21
|
+
}
|
22
|
+
return signatureBytes;
|
23
|
+
};
|
24
|
+
|
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
|
+
|
42
|
+
const gnosisSafe = addresses[chainId].gnosisSafe;
|
43
|
+
|
44
|
+
const domain = {
|
45
|
+
verifyingContract: gnosisSafe,
|
46
|
+
chainId,
|
47
|
+
};
|
48
|
+
|
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;
|
67
|
+
|
68
|
+
const message = {
|
69
|
+
baseGas,
|
70
|
+
data,
|
71
|
+
gasPrice,
|
72
|
+
gasToken,
|
73
|
+
nonce: Number(nonce),
|
74
|
+
operation,
|
75
|
+
refundReceiver,
|
76
|
+
safeAddress: gnosisSafe,
|
77
|
+
safeTxGas: String(safeTxGas),
|
78
|
+
to,
|
79
|
+
value,
|
80
|
+
};
|
81
|
+
|
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);
|
109
|
+
};
|
110
|
+
|
111
|
+
export const generateGnosisTransaction = async (
|
112
|
+
transactionData: any,
|
113
|
+
safeContract: GnosisSafe
|
114
|
+
) => {
|
115
|
+
console.log(transactionData);
|
116
|
+
|
117
|
+
let isExecuted = await safeContract.dataHashes(
|
118
|
+
await safeContract.getTransactionHash(
|
119
|
+
transactionData.to,
|
120
|
+
transactionData.value,
|
121
|
+
transactionData.data,
|
122
|
+
transactionData.operation,
|
123
|
+
transactionData.safeTxGas,
|
124
|
+
transactionData.baseGas,
|
125
|
+
transactionData.gasPrice,
|
126
|
+
transactionData.gasToken,
|
127
|
+
transactionData.refundReceiver,
|
128
|
+
transactionData.nonce
|
129
|
+
)
|
130
|
+
);
|
131
|
+
|
132
|
+
while (isExecuted == 1) {
|
133
|
+
transactionData.safeTxGas = ethers.BigNumber.from(
|
134
|
+
String(transactionData.safeTxGas)
|
135
|
+
)
|
136
|
+
.add(1)
|
137
|
+
.toString();
|
138
|
+
|
139
|
+
isExecuted = await safeContract.dataHashes(
|
140
|
+
await safeContract.getTransactionHash(
|
141
|
+
transactionData.to,
|
142
|
+
transactionData.value,
|
143
|
+
transactionData.data,
|
144
|
+
transactionData.operation,
|
145
|
+
transactionData.safeTxGas,
|
146
|
+
transactionData.baseGas,
|
147
|
+
transactionData.gasPrice,
|
148
|
+
transactionData.gasToken,
|
149
|
+
transactionData.refundReceiver,
|
150
|
+
transactionData.nonce
|
151
|
+
)
|
152
|
+
);
|
153
|
+
}
|
154
|
+
|
155
|
+
return transactionData;
|
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
|
+
}
|