@epoch-protocol/inventory-sdk 1.0.0

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 (53) hide show
  1. package/.github/workflows/main.yml +91 -0
  2. package/dist/chainlink-ops/chainlink-abi.d.ts +40 -0
  3. package/dist/chainlink-ops/chainlink-abi.d.ts.map +1 -0
  4. package/dist/chainlink-ops/chainlink-abi.js +287 -0
  5. package/dist/chainlink-ops/chainlink-abi.js.map +1 -0
  6. package/dist/chainlink-ops/index.d.ts +8 -0
  7. package/dist/chainlink-ops/index.d.ts.map +1 -0
  8. package/dist/chainlink-ops/index.js +35 -0
  9. package/dist/chainlink-ops/index.js.map +1 -0
  10. package/dist/chainlink-ops/models.d.ts +2 -0
  11. package/dist/chainlink-ops/models.d.ts.map +1 -0
  12. package/dist/chainlink-ops/models.js +3 -0
  13. package/dist/chainlink-ops/models.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +24 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/safe-ops/index.d.ts +20 -0
  19. package/dist/safe-ops/index.d.ts.map +1 -0
  20. package/dist/safe-ops/index.js +99 -0
  21. package/dist/safe-ops/index.js.map +1 -0
  22. package/dist/safe-ops/models.d.ts +22 -0
  23. package/dist/safe-ops/models.d.ts.map +1 -0
  24. package/dist/safe-ops/models.js +6 -0
  25. package/dist/safe-ops/models.js.map +1 -0
  26. package/dist/safe-ops/safe-abi.d.ts +43 -0
  27. package/dist/safe-ops/safe-abi.d.ts.map +1 -0
  28. package/dist/safe-ops/safe-abi.js +565 -0
  29. package/dist/safe-ops/safe-abi.js.map +1 -0
  30. package/dist/token/erc20-abi.d.ts +39 -0
  31. package/dist/token/erc20-abi.d.ts.map +1 -0
  32. package/dist/token/erc20-abi.js +226 -0
  33. package/dist/token/erc20-abi.js.map +1 -0
  34. package/dist/token/index.d.ts +9 -0
  35. package/dist/token/index.d.ts.map +1 -0
  36. package/dist/token/index.js +109 -0
  37. package/dist/token/index.js.map +1 -0
  38. package/dist/token/models.d.ts +27 -0
  39. package/dist/token/models.d.ts.map +1 -0
  40. package/dist/token/models.js +3 -0
  41. package/dist/token/models.js.map +1 -0
  42. package/package.json +22 -0
  43. package/src/chainlink-ops/chainlink-abi.ts +283 -0
  44. package/src/chainlink-ops/index.ts +53 -0
  45. package/src/chainlink-ops/models.ts +0 -0
  46. package/src/index.ts +7 -0
  47. package/src/safe-ops/index.ts +98 -0
  48. package/src/safe-ops/models.ts +23 -0
  49. package/src/safe-ops/safe-abi.ts +561 -0
  50. package/src/token/erc20-abi.ts +222 -0
  51. package/src/token/index.ts +126 -0
  52. package/src/token/models.ts +32 -0
  53. package/tsconfig.json +43 -0
@@ -0,0 +1,283 @@
1
+ export const CHAINLINK_FEED_ABI = [
2
+ {
3
+ inputs: [
4
+ { internalType: "address", name: "_aggregator", type: "address" },
5
+ { internalType: "address", name: "_accessController", type: "address" },
6
+ ],
7
+ stateMutability: "nonpayable",
8
+ type: "constructor",
9
+ },
10
+ {
11
+ anonymous: false,
12
+ inputs: [
13
+ {
14
+ indexed: true,
15
+ internalType: "int256",
16
+ name: "current",
17
+ type: "int256",
18
+ },
19
+ {
20
+ indexed: true,
21
+ internalType: "uint256",
22
+ name: "roundId",
23
+ type: "uint256",
24
+ },
25
+ {
26
+ indexed: false,
27
+ internalType: "uint256",
28
+ name: "updatedAt",
29
+ type: "uint256",
30
+ },
31
+ ],
32
+ name: "AnswerUpdated",
33
+ type: "event",
34
+ },
35
+ {
36
+ anonymous: false,
37
+ inputs: [
38
+ {
39
+ indexed: true,
40
+ internalType: "uint256",
41
+ name: "roundId",
42
+ type: "uint256",
43
+ },
44
+ {
45
+ indexed: true,
46
+ internalType: "address",
47
+ name: "startedBy",
48
+ type: "address",
49
+ },
50
+ {
51
+ indexed: false,
52
+ internalType: "uint256",
53
+ name: "startedAt",
54
+ type: "uint256",
55
+ },
56
+ ],
57
+ name: "NewRound",
58
+ type: "event",
59
+ },
60
+ {
61
+ anonymous: false,
62
+ inputs: [
63
+ { indexed: true, internalType: "address", name: "from", type: "address" },
64
+ { indexed: true, internalType: "address", name: "to", type: "address" },
65
+ ],
66
+ name: "OwnershipTransferRequested",
67
+ type: "event",
68
+ },
69
+ {
70
+ anonymous: false,
71
+ inputs: [
72
+ { indexed: true, internalType: "address", name: "from", type: "address" },
73
+ { indexed: true, internalType: "address", name: "to", type: "address" },
74
+ ],
75
+ name: "OwnershipTransferred",
76
+ type: "event",
77
+ },
78
+ {
79
+ inputs: [],
80
+ name: "acceptOwnership",
81
+ outputs: [],
82
+ stateMutability: "nonpayable",
83
+ type: "function",
84
+ },
85
+ {
86
+ inputs: [],
87
+ name: "accessController",
88
+ outputs: [
89
+ {
90
+ internalType: "contract AccessControllerInterface",
91
+ name: "",
92
+ type: "address",
93
+ },
94
+ ],
95
+ stateMutability: "view",
96
+ type: "function",
97
+ },
98
+ {
99
+ inputs: [],
100
+ name: "aggregator",
101
+ outputs: [{ internalType: "address", name: "", type: "address" }],
102
+ stateMutability: "view",
103
+ type: "function",
104
+ },
105
+ {
106
+ inputs: [{ internalType: "address", name: "_aggregator", type: "address" }],
107
+ name: "confirmAggregator",
108
+ outputs: [],
109
+ stateMutability: "nonpayable",
110
+ type: "function",
111
+ },
112
+ {
113
+ inputs: [],
114
+ name: "decimals",
115
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
116
+ stateMutability: "view",
117
+ type: "function",
118
+ },
119
+ {
120
+ inputs: [],
121
+ name: "description",
122
+ outputs: [{ internalType: "string", name: "", type: "string" }],
123
+ stateMutability: "view",
124
+ type: "function",
125
+ },
126
+ {
127
+ inputs: [{ internalType: "uint256", name: "_roundId", type: "uint256" }],
128
+ name: "getAnswer",
129
+ outputs: [{ internalType: "int256", name: "", type: "int256" }],
130
+ stateMutability: "view",
131
+ type: "function",
132
+ },
133
+ {
134
+ inputs: [{ internalType: "uint80", name: "_roundId", type: "uint80" }],
135
+ name: "getRoundData",
136
+ outputs: [
137
+ { internalType: "uint80", name: "roundId", type: "uint80" },
138
+ { internalType: "int256", name: "answer", type: "int256" },
139
+ { internalType: "uint256", name: "startedAt", type: "uint256" },
140
+ { internalType: "uint256", name: "updatedAt", type: "uint256" },
141
+ { internalType: "uint80", name: "answeredInRound", type: "uint80" },
142
+ ],
143
+ stateMutability: "view",
144
+ type: "function",
145
+ },
146
+ {
147
+ inputs: [{ internalType: "uint256", name: "_roundId", type: "uint256" }],
148
+ name: "getTimestamp",
149
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
150
+ stateMutability: "view",
151
+ type: "function",
152
+ },
153
+ {
154
+ inputs: [],
155
+ name: "latestAnswer",
156
+ outputs: [{ internalType: "int256", name: "", type: "int256" }],
157
+ stateMutability: "view",
158
+ type: "function",
159
+ },
160
+ {
161
+ inputs: [],
162
+ name: "latestRound",
163
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
164
+ stateMutability: "view",
165
+ type: "function",
166
+ },
167
+ {
168
+ inputs: [],
169
+ name: "latestRoundData",
170
+ outputs: [
171
+ { internalType: "uint80", name: "roundId", type: "uint80" },
172
+ { internalType: "int256", name: "answer", type: "int256" },
173
+ { internalType: "uint256", name: "startedAt", type: "uint256" },
174
+ { internalType: "uint256", name: "updatedAt", type: "uint256" },
175
+ { internalType: "uint80", name: "answeredInRound", type: "uint80" },
176
+ ],
177
+ stateMutability: "view",
178
+ type: "function",
179
+ },
180
+ {
181
+ inputs: [],
182
+ name: "latestTimestamp",
183
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
184
+ stateMutability: "view",
185
+ type: "function",
186
+ },
187
+ {
188
+ inputs: [],
189
+ name: "owner",
190
+ outputs: [{ internalType: "address", name: "", type: "address" }],
191
+ stateMutability: "view",
192
+ type: "function",
193
+ },
194
+ {
195
+ inputs: [{ internalType: "uint16", name: "", type: "uint16" }],
196
+ name: "phaseAggregators",
197
+ outputs: [
198
+ {
199
+ internalType: "contract AggregatorV2V3Interface",
200
+ name: "",
201
+ type: "address",
202
+ },
203
+ ],
204
+ stateMutability: "view",
205
+ type: "function",
206
+ },
207
+ {
208
+ inputs: [],
209
+ name: "phaseId",
210
+ outputs: [{ internalType: "uint16", name: "", type: "uint16" }],
211
+ stateMutability: "view",
212
+ type: "function",
213
+ },
214
+ {
215
+ inputs: [{ internalType: "address", name: "_aggregator", type: "address" }],
216
+ name: "proposeAggregator",
217
+ outputs: [],
218
+ stateMutability: "nonpayable",
219
+ type: "function",
220
+ },
221
+ {
222
+ inputs: [],
223
+ name: "proposedAggregator",
224
+ outputs: [
225
+ {
226
+ internalType: "contract AggregatorV2V3Interface",
227
+ name: "",
228
+ type: "address",
229
+ },
230
+ ],
231
+ stateMutability: "view",
232
+ type: "function",
233
+ },
234
+ {
235
+ inputs: [{ internalType: "uint80", name: "_roundId", type: "uint80" }],
236
+ name: "proposedGetRoundData",
237
+ outputs: [
238
+ { internalType: "uint80", name: "roundId", type: "uint80" },
239
+ { internalType: "int256", name: "answer", type: "int256" },
240
+ { internalType: "uint256", name: "startedAt", type: "uint256" },
241
+ { internalType: "uint256", name: "updatedAt", type: "uint256" },
242
+ { internalType: "uint80", name: "answeredInRound", type: "uint80" },
243
+ ],
244
+ stateMutability: "view",
245
+ type: "function",
246
+ },
247
+ {
248
+ inputs: [],
249
+ name: "proposedLatestRoundData",
250
+ outputs: [
251
+ { internalType: "uint80", name: "roundId", type: "uint80" },
252
+ { internalType: "int256", name: "answer", type: "int256" },
253
+ { internalType: "uint256", name: "startedAt", type: "uint256" },
254
+ { internalType: "uint256", name: "updatedAt", type: "uint256" },
255
+ { internalType: "uint80", name: "answeredInRound", type: "uint80" },
256
+ ],
257
+ stateMutability: "view",
258
+ type: "function",
259
+ },
260
+ {
261
+ inputs: [
262
+ { internalType: "address", name: "_accessController", type: "address" },
263
+ ],
264
+ name: "setController",
265
+ outputs: [],
266
+ stateMutability: "nonpayable",
267
+ type: "function",
268
+ },
269
+ {
270
+ inputs: [{ internalType: "address", name: "_to", type: "address" }],
271
+ name: "transferOwnership",
272
+ outputs: [],
273
+ stateMutability: "nonpayable",
274
+ type: "function",
275
+ },
276
+ {
277
+ inputs: [],
278
+ name: "version",
279
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
280
+ stateMutability: "view",
281
+ type: "function",
282
+ },
283
+ ];
@@ -0,0 +1,53 @@
1
+ import { Contract, Provider } from "ethers";
2
+ import { TokenInfo } from "../token/models";
3
+ import { CHAINLINK_FEED_ABI } from "./chainlink-abi";
4
+
5
+ export const getPrice = async (
6
+ tokenInfo: TokenInfo,
7
+ amount: BigInt,
8
+ provider: Provider
9
+ ) => {
10
+ const priceFeed = new Contract(
11
+ tokenInfo.token.priceFeed.priceFeedAddress,
12
+ CHAINLINK_FEED_ABI,
13
+ provider
14
+ );
15
+ console.log("priceFeed: ", tokenInfo.token.priceFeed.priceFeedAddress);
16
+ console.log("Networ", (await provider.getNetwork()).chainId);
17
+ const promises = Promise.all([
18
+ priceFeed?.latestAnswer?.(),
19
+ priceFeed?.decimals?.(),
20
+ ]);
21
+ const [price, decimals] = await promises;
22
+
23
+ const differenceInPrecision = BigInt(18) - BigInt(decimals.toString());
24
+ const extraDecimals = BigInt(BigInt(10) ** BigInt(differenceInPrecision));
25
+ tokenInfo.price = BigInt(price) * extraDecimals;
26
+ tokenInfo.token.priceFeed.priceFeedDecimals = decimals;
27
+ const tokenDecimalsDifference =
28
+ BigInt(18) - BigInt(tokenInfo.decimals.toString());
29
+ const tokenDecimalsExtra = BigInt(
30
+ BigInt(10) ** BigInt(tokenDecimalsDifference)
31
+ );
32
+ tokenInfo.usdValue =
33
+ (BigInt(amount.toString()) *
34
+ tokenDecimalsExtra *
35
+ BigInt(tokenInfo.price!.toString())) /
36
+ BigInt(BigInt(10) ** BigInt(18));
37
+
38
+ return tokenInfo;
39
+ };
40
+
41
+ export const getMultiplePrices = async (
42
+ tokenInfoAndProviders: { tokenInfo: TokenInfo; provider: Provider }[]
43
+ ) => {
44
+ const promises = tokenInfoAndProviders.map((tokenInfoAndProvider) =>
45
+ getPrice(
46
+ tokenInfoAndProvider.tokenInfo,
47
+ tokenInfoAndProvider.tokenInfo.balance!,
48
+ tokenInfoAndProvider.provider
49
+ )
50
+ );
51
+ const results = await Promise.all(promises);
52
+ return results;
53
+ };
File without changes
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./token";
2
+ export * from "./safe-ops";
3
+ export * from "./chainlink-ops";
4
+ export * from "./chainlink-ops/models";
5
+ export * from "./safe-ops/models";
6
+ export * from "./token/erc20-abi";
7
+ export * from "./token/models";
@@ -0,0 +1,98 @@
1
+ import Safe, { EthSafeSignature } from "@safe-global/protocol-kit";
2
+ import {
3
+ SafeSignature,
4
+ SafeTransaction,
5
+ SafeTransactionData,
6
+ } from "@safe-global/types-kit";
7
+ import { DeconstructedSafeSignature, DeconstructedSafeTx } from "./models";
8
+
9
+ export const createSafeTx = async (
10
+ safe: Safe,
11
+ txList: Array<{
12
+ to: string;
13
+ value: string;
14
+ data: string;
15
+ operation: number;
16
+ }>
17
+ ): Promise<SafeTransaction> => {
18
+ try {
19
+ const safeTx = await safe.createTransaction({ transactions: txList });
20
+ console.log("safeTx", safeTx);
21
+ return safeTx;
22
+ } catch (error) {
23
+ console.log("error", error);
24
+ throw error;
25
+ }
26
+ };
27
+
28
+ export const signSafeTx = async (
29
+ safe: Safe,
30
+ safeTx: SafeTransaction
31
+ ): Promise<SafeTransaction> => {
32
+ try {
33
+ const signedSafeTx = await safe.signTransaction(safeTx);
34
+ console.log("signedSafeTx", signedSafeTx);
35
+ return signedSafeTx;
36
+ } catch (error) {
37
+ console.log("error", error);
38
+ throw error;
39
+ }
40
+ };
41
+
42
+ export const getSafeInstance = async (
43
+ safeAddress: string,
44
+ privateKey: string,
45
+ rpcUrl: string
46
+ ): Promise<Safe> => {
47
+ const safe = await Safe.init({
48
+ safeAddress,
49
+ provider: rpcUrl,
50
+ signer: privateKey,
51
+ });
52
+ return safe;
53
+ };
54
+
55
+ export const deconstructSafeTx = async (
56
+ SafeTransaction: SafeTransaction
57
+ ): Promise<{
58
+ safeTxElements: DeconstructedSafeTx;
59
+ signatures: DeconstructedSafeSignature[];
60
+ }> => {
61
+ const safeTxElements: DeconstructedSafeTx = SafeTransaction.data;
62
+ const signatures: DeconstructedSafeSignature[] = [];
63
+ SafeTransaction.signatures.entries().forEach(([key, signature]) => {
64
+ signatures.push({
65
+ signer: key,
66
+ signature: signature.data,
67
+ isContractSignature: signature.isContractSignature,
68
+ });
69
+ });
70
+ return {
71
+ safeTxElements,
72
+ signatures,
73
+ };
74
+ };
75
+
76
+ export const reconstructSafeTx = async (
77
+ deconstructedSafeTx: DeconstructedSafeTx,
78
+ deconstructedSafeSignatures: DeconstructedSafeSignature[]
79
+ ): Promise<{
80
+ safeTx: SafeTransactionData;
81
+ safeSignatures: SafeSignature[];
82
+ }> => {
83
+ const safeTx: SafeTransactionData = deconstructedSafeTx;
84
+ const safeSignatures: SafeSignature[] = [];
85
+ deconstructedSafeSignatures.forEach((deconstructedSafeSignature) => {
86
+ safeSignatures.push(
87
+ new EthSafeSignature(
88
+ deconstructedSafeSignature.signer,
89
+ deconstructedSafeSignature.signature,
90
+ deconstructedSafeSignature.isContractSignature
91
+ )
92
+ );
93
+ });
94
+ return {
95
+ safeTx,
96
+ safeSignatures,
97
+ };
98
+ };
@@ -0,0 +1,23 @@
1
+ import { OperationType, SafeTransaction } from "@safe-global/types-kit";
2
+
3
+ export type { SafeTransaction };
4
+ export type { SafeSignature } from "@safe-global/types-kit";
5
+ export { EthSafeSignature } from "@safe-global/protocol-kit";
6
+
7
+ export interface DeconstructedSafeTx {
8
+ to: string;
9
+ value: string;
10
+ data: string;
11
+ operation: OperationType;
12
+ safeTxGas: string;
13
+ baseGas: string;
14
+ gasPrice: string;
15
+ gasToken: string;
16
+ refundReceiver: string;
17
+ nonce: number;
18
+ }
19
+ export interface DeconstructedSafeSignature {
20
+ signer: string;
21
+ signature: string;
22
+ isContractSignature: boolean;
23
+ }