@gearbox-protocol/sdk 9.14.1 → 9.15.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 (231) hide show
  1. package/dist/cjs/permissionless/bindings/address-provider.js +51 -0
  2. package/dist/cjs/permissionless/bindings/base-contract.js +173 -0
  3. package/dist/cjs/permissionless/bindings/bytecode-repository.js +526 -0
  4. package/dist/cjs/permissionless/bindings/compressors/index.js +24 -0
  5. package/dist/cjs/permissionless/bindings/compressors/token-compressor.js +110 -0
  6. package/dist/cjs/permissionless/bindings/compressors/withdrawal-compressor.js +60 -0
  7. package/dist/cjs/permissionless/bindings/cross-chain-multisig.js +355 -0
  8. package/dist/cjs/permissionless/bindings/factory/abstract-factory.js +52 -0
  9. package/dist/cjs/permissionless/bindings/factory/credit-factory.js +197 -0
  10. package/dist/cjs/permissionless/bindings/factory/pool-factory.js +69 -0
  11. package/dist/cjs/permissionless/bindings/factory/price-oracle-factory.js +47 -0
  12. package/dist/cjs/permissionless/bindings/governance/batches-chain.js +41 -0
  13. package/dist/cjs/permissionless/bindings/governance/governor.js +243 -0
  14. package/dist/cjs/permissionless/bindings/governance/index.js +26 -0
  15. package/dist/cjs/permissionless/bindings/governance/timelock.js +104 -0
  16. package/dist/cjs/permissionless/bindings/governance/types.js +16 -0
  17. package/dist/cjs/permissionless/bindings/index.js +48 -0
  18. package/dist/cjs/permissionless/bindings/instance-manager.js +244 -0
  19. package/dist/cjs/permissionless/bindings/market-configurator-factory.js +75 -0
  20. package/dist/cjs/permissionless/bindings/market-configurator.js +771 -0
  21. package/dist/cjs/permissionless/bindings/price-feed-store.js +395 -0
  22. package/dist/cjs/permissionless/bindings/pricefeeds/balancer-stable.js +63 -0
  23. package/dist/cjs/permissionless/bindings/pricefeeds/balancer-weighted.js +63 -0
  24. package/dist/cjs/permissionless/bindings/pricefeeds/bounded.js +47 -0
  25. package/dist/cjs/permissionless/bindings/pricefeeds/composite.js +43 -0
  26. package/dist/cjs/permissionless/bindings/pricefeeds/constant.js +42 -0
  27. package/dist/cjs/permissionless/bindings/pricefeeds/curve-crypto.js +67 -0
  28. package/dist/cjs/permissionless/bindings/pricefeeds/curve-stable.js +67 -0
  29. package/dist/cjs/permissionless/bindings/pricefeeds/curve-twap.js +70 -0
  30. package/dist/cjs/permissionless/bindings/pricefeeds/curve-usd.js +50 -0
  31. package/dist/cjs/permissionless/bindings/pricefeeds/erc4626.js +72 -0
  32. package/dist/cjs/permissionless/bindings/pricefeeds/external.js +38 -0
  33. package/dist/cjs/permissionless/bindings/pricefeeds/index.js +63 -0
  34. package/dist/cjs/permissionless/bindings/pricefeeds/kodiak.js +50 -0
  35. package/dist/cjs/permissionless/bindings/pricefeeds/mellow-lrt.js +122 -0
  36. package/dist/cjs/permissionless/bindings/pricefeeds/pendle-pt-twap.js +51 -0
  37. package/dist/cjs/permissionless/bindings/pricefeeds/pyth.js +65 -0
  38. package/dist/cjs/permissionless/bindings/pricefeeds/redstone.js +81 -0
  39. package/dist/cjs/permissionless/bindings/pricefeeds/wsteth.js +63 -0
  40. package/dist/cjs/permissionless/bindings/pricefeeds/zero.js +33 -0
  41. package/dist/cjs/permissionless/bindings/router/index.js +22 -0
  42. package/dist/cjs/permissionless/bindings/router/routing-manager.js +58 -0
  43. package/dist/cjs/permissionless/bindings/treasury-splitter.js +60 -0
  44. package/dist/cjs/permissionless/bindings/types.js +16 -0
  45. package/dist/cjs/permissionless/chains/archive-transport.js +274 -0
  46. package/dist/cjs/permissionless/core/auditor.js +16 -0
  47. package/dist/cjs/permissionless/core/bytecode.js +16 -0
  48. package/dist/cjs/permissionless/core/index.js +32 -0
  49. package/dist/cjs/permissionless/core/pricefeed-builder.js +16 -0
  50. package/dist/cjs/permissionless/core/pricefeed.js +16 -0
  51. package/dist/cjs/permissionless/core/proposal.js +16 -0
  52. package/dist/cjs/permissionless/core/raw-tx.js +38 -0
  53. package/dist/cjs/permissionless/deployment/addresses.js +35 -0
  54. package/dist/cjs/permissionless/deployment/mainnet.js +54 -0
  55. package/dist/cjs/permissionless/index.js +32 -0
  56. package/dist/cjs/permissionless/package.json +1 -0
  57. package/dist/cjs/permissionless/plugins/index.js +40 -0
  58. package/dist/cjs/permissionless/plugins/irm/constructor-params-abi.js +81 -0
  59. package/dist/cjs/permissionless/plugins/loss-policies/constructor-params-abi.js +79 -0
  60. package/dist/cjs/permissionless/plugins/rate-keepers/constructor-params-abi.js +89 -0
  61. package/dist/cjs/permissionless/utils/abi-decoder.js +72 -0
  62. package/dist/cjs/permissionless/utils/abi-encoder.js +89 -0
  63. package/dist/cjs/permissionless/utils/block-utils.js +55 -0
  64. package/dist/cjs/permissionless/utils/create2.js +113 -0
  65. package/dist/cjs/permissionless/utils/format.js +97 -0
  66. package/dist/cjs/permissionless/utils/governance/batch.js +114 -0
  67. package/dist/cjs/permissionless/utils/governance/index.js +26 -0
  68. package/dist/cjs/permissionless/utils/governance/timelock-txs.js +44 -0
  69. package/dist/cjs/permissionless/utils/governance/types.js +16 -0
  70. package/dist/cjs/permissionless/utils/index.js +38 -0
  71. package/dist/cjs/permissionless/utils/literals.js +46 -0
  72. package/dist/cjs/permissionless/utils/price-update/get-price-feeds.js +91 -0
  73. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +84 -0
  74. package/dist/cjs/permissionless/utils/price-update/get-prices.js +123 -0
  75. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +52 -0
  76. package/dist/cjs/permissionless/utils/price-update/index.js +28 -0
  77. package/dist/cjs/permissionless/utils/signature.js +35 -0
  78. package/dist/esm/permissionless/bindings/address-provider.js +27 -0
  79. package/dist/esm/permissionless/bindings/base-contract.js +151 -0
  80. package/dist/esm/permissionless/bindings/bytecode-repository.js +508 -0
  81. package/dist/esm/permissionless/bindings/compressors/index.js +2 -0
  82. package/dist/esm/permissionless/bindings/compressors/token-compressor.js +89 -0
  83. package/dist/esm/permissionless/bindings/compressors/withdrawal-compressor.js +38 -0
  84. package/dist/esm/permissionless/bindings/cross-chain-multisig.js +336 -0
  85. package/dist/esm/permissionless/bindings/factory/abstract-factory.js +28 -0
  86. package/dist/esm/permissionless/bindings/factory/credit-factory.js +177 -0
  87. package/dist/esm/permissionless/bindings/factory/pool-factory.js +45 -0
  88. package/dist/esm/permissionless/bindings/factory/price-oracle-factory.js +23 -0
  89. package/dist/esm/permissionless/bindings/governance/batches-chain.js +17 -0
  90. package/dist/esm/permissionless/bindings/governance/governor.js +224 -0
  91. package/dist/esm/permissionless/bindings/governance/index.js +3 -0
  92. package/dist/esm/permissionless/bindings/governance/timelock.js +80 -0
  93. package/dist/esm/permissionless/bindings/governance/types.js +0 -0
  94. package/dist/esm/permissionless/bindings/index.js +14 -0
  95. package/dist/esm/permissionless/bindings/instance-manager.js +223 -0
  96. package/dist/esm/permissionless/bindings/market-configurator-factory.js +51 -0
  97. package/dist/esm/permissionless/bindings/market-configurator.js +765 -0
  98. package/dist/esm/permissionless/bindings/price-feed-store.js +376 -0
  99. package/dist/esm/permissionless/bindings/pricefeeds/balancer-stable.js +39 -0
  100. package/dist/esm/permissionless/bindings/pricefeeds/balancer-weighted.js +39 -0
  101. package/dist/esm/permissionless/bindings/pricefeeds/bounded.js +23 -0
  102. package/dist/esm/permissionless/bindings/pricefeeds/composite.js +19 -0
  103. package/dist/esm/permissionless/bindings/pricefeeds/constant.js +18 -0
  104. package/dist/esm/permissionless/bindings/pricefeeds/curve-crypto.js +43 -0
  105. package/dist/esm/permissionless/bindings/pricefeeds/curve-stable.js +43 -0
  106. package/dist/esm/permissionless/bindings/pricefeeds/curve-twap.js +46 -0
  107. package/dist/esm/permissionless/bindings/pricefeeds/curve-usd.js +26 -0
  108. package/dist/esm/permissionless/bindings/pricefeeds/erc4626.js +48 -0
  109. package/dist/esm/permissionless/bindings/pricefeeds/external.js +14 -0
  110. package/dist/esm/permissionless/bindings/pricefeeds/index.js +39 -0
  111. package/dist/esm/permissionless/bindings/pricefeeds/kodiak.js +26 -0
  112. package/dist/esm/permissionless/bindings/pricefeeds/mellow-lrt.js +98 -0
  113. package/dist/esm/permissionless/bindings/pricefeeds/pendle-pt-twap.js +27 -0
  114. package/dist/esm/permissionless/bindings/pricefeeds/pyth.js +41 -0
  115. package/dist/esm/permissionless/bindings/pricefeeds/redstone.js +57 -0
  116. package/dist/esm/permissionless/bindings/pricefeeds/wsteth.js +39 -0
  117. package/dist/esm/permissionless/bindings/pricefeeds/zero.js +9 -0
  118. package/dist/esm/permissionless/bindings/router/index.js +1 -0
  119. package/dist/esm/permissionless/bindings/router/routing-manager.js +36 -0
  120. package/dist/esm/permissionless/bindings/treasury-splitter.js +36 -0
  121. package/dist/esm/permissionless/bindings/types.js +0 -0
  122. package/dist/esm/permissionless/chains/archive-transport.js +250 -0
  123. package/dist/esm/permissionless/core/auditor.js +0 -0
  124. package/dist/esm/permissionless/core/bytecode.js +0 -0
  125. package/dist/esm/permissionless/core/index.js +6 -0
  126. package/dist/esm/permissionless/core/pricefeed-builder.js +0 -0
  127. package/dist/esm/permissionless/core/pricefeed.js +0 -0
  128. package/dist/esm/permissionless/core/proposal.js +0 -0
  129. package/dist/esm/permissionless/core/raw-tx.js +14 -0
  130. package/dist/esm/permissionless/deployment/addresses.js +11 -0
  131. package/dist/esm/permissionless/deployment/mainnet.js +27 -0
  132. package/dist/esm/permissionless/index.js +6 -0
  133. package/dist/esm/permissionless/package.json +1 -0
  134. package/dist/esm/permissionless/plugins/index.js +20 -0
  135. package/dist/esm/permissionless/plugins/irm/constructor-params-abi.js +52 -0
  136. package/dist/esm/permissionless/plugins/loss-policies/constructor-params-abi.js +50 -0
  137. package/dist/esm/permissionless/plugins/rate-keepers/constructor-params-abi.js +59 -0
  138. package/dist/esm/permissionless/utils/abi-decoder.js +50 -0
  139. package/dist/esm/permissionless/utils/abi-encoder.js +65 -0
  140. package/dist/esm/permissionless/utils/block-utils.js +31 -0
  141. package/dist/esm/permissionless/utils/create2.js +85 -0
  142. package/dist/esm/permissionless/utils/format.js +67 -0
  143. package/dist/esm/permissionless/utils/governance/batch.js +87 -0
  144. package/dist/esm/permissionless/utils/governance/index.js +3 -0
  145. package/dist/esm/permissionless/utils/governance/timelock-txs.js +20 -0
  146. package/dist/esm/permissionless/utils/governance/types.js +0 -0
  147. package/dist/esm/permissionless/utils/index.js +9 -0
  148. package/dist/esm/permissionless/utils/literals.js +16 -0
  149. package/dist/esm/permissionless/utils/price-update/get-price-feeds.js +65 -0
  150. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +65 -0
  151. package/dist/esm/permissionless/utils/price-update/get-prices.js +103 -0
  152. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +31 -0
  153. package/dist/esm/permissionless/utils/price-update/index.js +4 -0
  154. package/dist/esm/permissionless/utils/signature.js +11 -0
  155. package/dist/types/permissionless/bindings/address-provider.d.ts +259 -0
  156. package/dist/types/permissionless/bindings/base-contract.d.ts +23 -0
  157. package/dist/types/permissionless/bindings/bytecode-repository.d.ts +1352 -0
  158. package/dist/types/permissionless/bindings/compressors/index.d.ts +2 -0
  159. package/dist/types/permissionless/bindings/compressors/token-compressor.d.ts +118 -0
  160. package/dist/types/permissionless/bindings/compressors/withdrawal-compressor.d.ts +331 -0
  161. package/dist/types/permissionless/bindings/cross-chain-multisig.d.ts +835 -0
  162. package/dist/types/permissionless/bindings/factory/abstract-factory.d.ts +17 -0
  163. package/dist/types/permissionless/bindings/factory/credit-factory.d.ts +224 -0
  164. package/dist/types/permissionless/bindings/factory/pool-factory.d.ts +86 -0
  165. package/dist/types/permissionless/bindings/factory/price-oracle-factory.d.ts +38 -0
  166. package/dist/types/permissionless/bindings/governance/batches-chain.d.ts +39 -0
  167. package/dist/types/permissionless/bindings/governance/governor.d.ts +615 -0
  168. package/dist/types/permissionless/bindings/governance/index.d.ts +3 -0
  169. package/dist/types/permissionless/bindings/governance/timelock.d.ts +10 -0
  170. package/dist/types/permissionless/bindings/governance/types.d.ts +42 -0
  171. package/dist/types/permissionless/bindings/index.d.ts +14 -0
  172. package/dist/types/permissionless/bindings/instance-manager.d.ts +361 -0
  173. package/dist/types/permissionless/bindings/market-configurator-factory.d.ts +244 -0
  174. package/dist/types/permissionless/bindings/market-configurator.d.ts +1656 -0
  175. package/dist/types/permissionless/bindings/price-feed-store.d.ts +605 -0
  176. package/dist/types/permissionless/bindings/pricefeeds/balancer-stable.d.ts +2 -0
  177. package/dist/types/permissionless/bindings/pricefeeds/balancer-weighted.d.ts +2 -0
  178. package/dist/types/permissionless/bindings/pricefeeds/bounded.d.ts +2 -0
  179. package/dist/types/permissionless/bindings/pricefeeds/composite.d.ts +2 -0
  180. package/dist/types/permissionless/bindings/pricefeeds/constant.d.ts +2 -0
  181. package/dist/types/permissionless/bindings/pricefeeds/curve-crypto.d.ts +2 -0
  182. package/dist/types/permissionless/bindings/pricefeeds/curve-stable.d.ts +2 -0
  183. package/dist/types/permissionless/bindings/pricefeeds/curve-twap.d.ts +2 -0
  184. package/dist/types/permissionless/bindings/pricefeeds/curve-usd.d.ts +2 -0
  185. package/dist/types/permissionless/bindings/pricefeeds/erc4626.d.ts +2 -0
  186. package/dist/types/permissionless/bindings/pricefeeds/external.d.ts +2 -0
  187. package/dist/types/permissionless/bindings/pricefeeds/index.d.ts +2 -0
  188. package/dist/types/permissionless/bindings/pricefeeds/kodiak.d.ts +2 -0
  189. package/dist/types/permissionless/bindings/pricefeeds/mellow-lrt.d.ts +2 -0
  190. package/dist/types/permissionless/bindings/pricefeeds/pendle-pt-twap.d.ts +2 -0
  191. package/dist/types/permissionless/bindings/pricefeeds/pyth.d.ts +2 -0
  192. package/dist/types/permissionless/bindings/pricefeeds/redstone.d.ts +2 -0
  193. package/dist/types/permissionless/bindings/pricefeeds/wsteth.d.ts +2 -0
  194. package/dist/types/permissionless/bindings/pricefeeds/zero.d.ts +2 -0
  195. package/dist/types/permissionless/bindings/router/index.d.ts +1 -0
  196. package/dist/types/permissionless/bindings/router/routing-manager.d.ts +502 -0
  197. package/dist/types/permissionless/bindings/treasury-splitter.d.ts +21 -0
  198. package/dist/types/permissionless/bindings/types.d.ts +65 -0
  199. package/dist/types/permissionless/chains/archive-transport.d.ts +49 -0
  200. package/dist/types/permissionless/core/auditor.d.ts +7 -0
  201. package/dist/types/permissionless/core/bytecode.d.ts +46 -0
  202. package/dist/types/permissionless/core/index.d.ts +6 -0
  203. package/dist/types/permissionless/core/pricefeed-builder.d.ts +59 -0
  204. package/dist/types/permissionless/core/pricefeed.d.ts +10 -0
  205. package/dist/types/permissionless/core/proposal.d.ts +33 -0
  206. package/dist/types/permissionless/core/raw-tx.d.ts +4 -0
  207. package/dist/types/permissionless/deployment/addresses.d.ts +7 -0
  208. package/dist/types/permissionless/deployment/mainnet.d.ts +10 -0
  209. package/dist/types/permissionless/index.d.ts +6 -0
  210. package/dist/types/permissionless/plugins/index.d.ts +3 -0
  211. package/dist/types/permissionless/plugins/irm/constructor-params-abi.d.ts +63 -0
  212. package/dist/types/permissionless/plugins/loss-policies/constructor-params-abi.d.ts +48 -0
  213. package/dist/types/permissionless/plugins/rate-keepers/constructor-params-abi.d.ts +55 -0
  214. package/dist/types/permissionless/utils/abi-decoder.d.ts +13 -0
  215. package/dist/types/permissionless/utils/abi-encoder.d.ts +7 -0
  216. package/dist/types/permissionless/utils/block-utils.d.ts +8 -0
  217. package/dist/types/permissionless/utils/create2.d.ts +17 -0
  218. package/dist/types/permissionless/utils/format.d.ts +7 -0
  219. package/dist/types/permissionless/utils/governance/batch.d.ts +17 -0
  220. package/dist/types/permissionless/utils/governance/index.d.ts +3 -0
  221. package/dist/types/permissionless/utils/governance/timelock-txs.d.ts +2 -0
  222. package/dist/types/permissionless/utils/governance/types.d.ts +16 -0
  223. package/dist/types/permissionless/utils/index.d.ts +9 -0
  224. package/dist/types/permissionless/utils/literals.d.ts +7 -0
  225. package/dist/types/permissionless/utils/price-update/get-price-feeds.d.ts +8 -0
  226. package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +9 -0
  227. package/dist/types/permissionless/utils/price-update/get-prices.d.ts +6 -0
  228. package/dist/types/permissionless/utils/price-update/get-updatable-feeds.d.ts +8 -0
  229. package/dist/types/permissionless/utils/price-update/index.d.ts +4 -0
  230. package/dist/types/permissionless/utils/signature.d.ts +2 -0
  231. package/package.json +11 -1
@@ -0,0 +1,508 @@
1
+ import {
2
+ hashStruct,
3
+ hexToString,
4
+ parseEventLogs,
5
+ recoverTypedDataAddress,
6
+ stringToHex
7
+ } from "viem";
8
+ import { iBytecodeRepositoryAbi } from "../../abi/310/iBytecodeRepository.js";
9
+ import { normalizeSignature } from "../utils";
10
+ import { BYTECODE_REPOSITORY } from "../utils/literals";
11
+ import { BaseContract } from "./base-contract";
12
+ const abi = iBytecodeRepositoryAbi;
13
+ class BytecodeRepositoryContract extends BaseContract {
14
+ constructor(address, client) {
15
+ super(abi, address, client, "BytecodeRepository");
16
+ }
17
+ async getBytecodeByHash(hash) {
18
+ return await this.contract.read.getBytecode([hash]);
19
+ }
20
+ async getAuditReports(hash) {
21
+ return await this.contract.read.getAuditReports([hash]);
22
+ }
23
+ async getPublicDomains() {
24
+ return await this.contract.read.getPublicDomains();
25
+ }
26
+ async isBytecodeUploaded(hash) {
27
+ return await this.contract.read.isBytecodeUploaded([hash]);
28
+ }
29
+ async isBytecodeAudited(hash) {
30
+ return await this.contract.read.isBytecodeAudited([hash]);
31
+ }
32
+ async getLatestVersion(type_) {
33
+ return await this.contract.read.getLatestVersion([
34
+ stringToHex(type_, { size: 32 })
35
+ ]);
36
+ }
37
+ async isPublicDomain(domain) {
38
+ return await this.contract.read.isPublicDomain([
39
+ stringToHex(domain, { size: 32 })
40
+ ]);
41
+ }
42
+ // // Write functions
43
+ // async uploadBytecode(bytecode: Bytecode) {
44
+ // return await this.contract.write.uploadBytecode([bytecode]);
45
+ // }
46
+ async getUploadBytecodeEvents(fromBlock, toBlock, chunkSize) {
47
+ const events = await this.getEvents(
48
+ "UploadBytecode",
49
+ fromBlock,
50
+ toBlock,
51
+ void 0,
52
+ chunkSize
53
+ );
54
+ return events.map((e) => ({
55
+ bytecodeHash: e.args.bytecodeHash,
56
+ author: e.args.author,
57
+ version: Number(e.args.version),
58
+ contractType: e.args.contractType,
59
+ source: e.args.source,
60
+ initCode: "0x",
61
+ size: 0,
62
+ transactionHash: e.transactionHash,
63
+ blockNumber: Number(e.blockNumber)
64
+ }));
65
+ }
66
+ async getAddAuditorEvents(fromBlock, toBlock) {
67
+ const events = await this.getEvents("AddAuditor", fromBlock, toBlock);
68
+ const result = [];
69
+ for (const e of events) {
70
+ result.push({
71
+ address: e.args.auditor,
72
+ name: e.args.name,
73
+ removed: false,
74
+ removedAt: null,
75
+ addedAt: Number(e.blockNumber)
76
+ });
77
+ }
78
+ return result;
79
+ }
80
+ async getDeployContractEvents(fromBlock, toBlock) {
81
+ const events = await this.getEvents("DeployContract", fromBlock, toBlock);
82
+ const result = [];
83
+ for (const e of events) {
84
+ result.push({
85
+ address: e.args.contractAddress,
86
+ chainId: 1,
87
+ // BigInt(this.client.chain!.id!),
88
+ txHash: e.transactionHash,
89
+ blockNumber: Number(e.blockNumber),
90
+ bytecodeHash: e.args.bytecodeHash
91
+ });
92
+ }
93
+ return result;
94
+ }
95
+ async getAuditBytecodeEvents(fromBlock, toBlock) {
96
+ try {
97
+ const events = await this.getEvents("AuditBytecode", fromBlock, toBlock);
98
+ const result = [];
99
+ for (const e of events) {
100
+ result.push({
101
+ bytecodeHash: e.args.bytecodeHash,
102
+ auditor: e.args.auditor,
103
+ reportUrl: e.args.reportUrl,
104
+ signature: e.args.signature,
105
+ transactionHash: e.transactionHash,
106
+ blockNumber: Number(e.blockNumber)
107
+ });
108
+ }
109
+ return result;
110
+ } catch (e) {
111
+ if (e instanceof Error && e.message.includes("query exceeds max block")) {
112
+ const middle = (fromBlock + toBlock) / 2n;
113
+ return [
114
+ ...await this.getAuditBytecodeEvents(fromBlock, middle),
115
+ ...await this.getAuditBytecodeEvents(middle + 1n, toBlock)
116
+ ];
117
+ }
118
+ throw e;
119
+ }
120
+ }
121
+ async getAllowPublicContractEvents(fromBlock, toBlock) {
122
+ const code = await this.client.getCode({ address: this.address });
123
+ if (code === void 0 || code === "0x") {
124
+ return [];
125
+ }
126
+ const publicDomains = await this.contract.read.getPublicDomains();
127
+ const publicDomainsString = publicDomains.map(
128
+ (domain) => hexToString(domain, { size: 32 })
129
+ );
130
+ const events = await this.getAllowContractEvents(fromBlock, toBlock);
131
+ return events.filter((e) => {
132
+ const contractTypeString = hexToString(e.contractType, { size: 32 });
133
+ return publicDomainsString.includes(
134
+ this.extractDomain(contractTypeString)
135
+ );
136
+ });
137
+ }
138
+ async getAllowContractEvents(fromBlock, toBlock) {
139
+ try {
140
+ const events = await this.getEvents("AllowContract", fromBlock, toBlock);
141
+ const result = [];
142
+ for (const e of events) {
143
+ result.push({
144
+ bytecodeHash: e.args.bytecodeHash,
145
+ contractType: e.args.contractType,
146
+ version: e.args.version,
147
+ transactionHash: e.transactionHash,
148
+ blockNumber: Number(e.blockNumber)
149
+ });
150
+ }
151
+ return result;
152
+ } catch (e) {
153
+ if (e instanceof Error && e.message.includes("query exceeds max block")) {
154
+ const middle = (fromBlock + toBlock) / 2n;
155
+ return [
156
+ ...await this.getAllowContractEvents(fromBlock, middle),
157
+ ...await this.getAllowContractEvents(middle + 1n, toBlock)
158
+ ];
159
+ }
160
+ throw e;
161
+ }
162
+ }
163
+ async getUploadUpdates(fromBlock, toBlock) {
164
+ const events = await this.getUploadBytecodeEvents(fromBlock, toBlock);
165
+ const initCodes = await Promise.all(
166
+ events.map((event) => this.getBytecodeByHash(event.bytecodeHash))
167
+ );
168
+ events.forEach((event, index) => {
169
+ event.initCode = initCodes[index].initCode;
170
+ event.size = initCodes[index].initCode.length;
171
+ });
172
+ return events;
173
+ }
174
+ parseFunctionParams(params) {
175
+ switch (params.functionName) {
176
+ case "allowSystemContract": {
177
+ const [bytecodeHash] = params.args;
178
+ return this.wrapParseCall(params, {
179
+ bytecodeHash
180
+ });
181
+ }
182
+ case "addAuditor": {
183
+ const [auditor, name] = params.args;
184
+ return this.wrapParseCall(params, {
185
+ auditor,
186
+ name
187
+ });
188
+ }
189
+ case "removeAuditor": {
190
+ const [auditor] = params.args;
191
+ return this.wrapParseCall(params, {
192
+ auditor
193
+ });
194
+ }
195
+ case "addPublicDomain": {
196
+ const [domain] = params.args;
197
+ return this.wrapParseCall(params, {
198
+ domain: hexToString(domain, { size: 32 })
199
+ });
200
+ }
201
+ case "removePublicContractType": {
202
+ const [contractType] = params.args;
203
+ return this.wrapParseCall(params, {
204
+ contractType: hexToString(contractType, { size: 32 })
205
+ });
206
+ }
207
+ case "forbidInitCode": {
208
+ const [bytecodeHash] = params.args;
209
+ return this.wrapParseCall(params, {
210
+ bytecodeHash
211
+ });
212
+ }
213
+ case "setTokenSpecificPostfix": {
214
+ const [token, postfix] = params.args;
215
+ return this.wrapParseCall(params, {
216
+ token,
217
+ postfix: hexToString(postfix, { size: 32 })
218
+ });
219
+ }
220
+ case "uploadBytecode": {
221
+ const [uploadData] = params.args;
222
+ return this.wrapParseCall(params, {
223
+ contractType: hexToString(uploadData.contractType, { size: 32 }),
224
+ version: uploadData.version.toString(),
225
+ initCode: uploadData.initCode,
226
+ author: uploadData.author,
227
+ source: uploadData.source,
228
+ authorSignature: uploadData.authorSignature
229
+ });
230
+ }
231
+ case "submitAuditReport": {
232
+ const [bytecodeHash, { auditor, reportUrl, signature }] = params.args;
233
+ return this.wrapParseCall(params, {
234
+ bytecodeHash,
235
+ auditor,
236
+ reportUrl,
237
+ signature
238
+ });
239
+ }
240
+ // TODO: add all functions here!
241
+ // case "deployContract": {
242
+ // const [contractType, version, encodedParams, salt, owner] = params.args;
243
+ // return this.wrapParseCall(params, {
244
+ // contractType: hexToString(contractType, { size: 32 }),
245
+ // version: version.toString(),
246
+ // encodedParams,
247
+ // salt,
248
+ // owner,
249
+ // });
250
+ // }
251
+ // case "setContractTypeVersion": {
252
+ // const [contractType, version] = params.args;
253
+ // return this.wrapParseCall(params, {
254
+ // contractType: hexToString(contractType, { size: 32 }),
255
+ // version: version.toString(),
256
+ // });
257
+ // }
258
+ default:
259
+ return void 0;
260
+ }
261
+ }
262
+ async signBytecodeHash(bytecodeHash, auditor, reportUrl, signature, sponsor) {
263
+ return await this.contract.write.submitAuditReport(
264
+ [bytecodeHash, { auditor, reportUrl, signature }],
265
+ {
266
+ account: sponsor.account,
267
+ chain: sponsor.chain
268
+ }
269
+ );
270
+ }
271
+ signBytecodeHashTx(bytecodeHash, auditor, reportUrl, signature) {
272
+ const normalizedSignature = normalizeSignature(signature);
273
+ return this.createRawTx({
274
+ functionName: "submitAuditReport",
275
+ args: [
276
+ bytecodeHash,
277
+ { auditor, reportUrl, signature: normalizedSignature }
278
+ ]
279
+ });
280
+ }
281
+ async recoverAuditorSignature(bytecodeHash, auditor, reportUrl, signature) {
282
+ const digest = this.computeEIP712AuditorDigest(
283
+ bytecodeHash,
284
+ auditor,
285
+ reportUrl
286
+ );
287
+ return await recoverTypedDataAddress({
288
+ ...digest,
289
+ signature
290
+ });
291
+ }
292
+ async recoverAuthorSignature(contractType, version, initCode, author, source, signature) {
293
+ const digest = this.computeEIP712AuthorDigest({
294
+ contractType: stringToHex(contractType, { size: 32 }),
295
+ version: BigInt(version),
296
+ initCode,
297
+ author,
298
+ source
299
+ });
300
+ return await recoverTypedDataAddress({
301
+ ...digest,
302
+ signature
303
+ });
304
+ }
305
+ // computeEIP712AuditorDigest(bytecodeHash: Hex, reportUrl: string) {
306
+ // return {
307
+ // domain: this.getEIP712Domain(),
308
+ // types: {
309
+ // SignBytecodeHash: [
310
+ // { name: "bytecodeHash", type: "bytes32" },
311
+ // { name: "reportUrl", type: "string" },
312
+ // ],
313
+ // },
314
+ // primaryType: "SignBytecodeHash",
315
+ // message: {
316
+ // bytecodeHash,
317
+ // reportUrl,
318
+ // },
319
+ // } as const;
320
+ // }
321
+ computeEIP712AuditorDigest(bytecodeHash, auditor, reportUrl) {
322
+ return {
323
+ domain: this.getEIP712Domain(),
324
+ types: {
325
+ AuditReport: [
326
+ { name: "bytecodeHash", type: "bytes32" },
327
+ { name: "auditor", type: "address" },
328
+ { name: "reportUrl", type: "string" }
329
+ ]
330
+ },
331
+ primaryType: "AuditReport",
332
+ message: {
333
+ bytecodeHash,
334
+ auditor,
335
+ reportUrl
336
+ }
337
+ };
338
+ }
339
+ computeEIP712AuthorDigest(args) {
340
+ return {
341
+ domain: this.getEIP712Domain(),
342
+ ...BytecodeRepositoryContract.getBytecodeHashTypes(),
343
+ message: args
344
+ };
345
+ }
346
+ getEIP712Domain() {
347
+ return {
348
+ name: BYTECODE_REPOSITORY,
349
+ version: "310",
350
+ chainId: 1,
351
+ verifyingContract: this.address
352
+ };
353
+ }
354
+ computeBytecodeHash(args) {
355
+ return hashStruct({
356
+ data: args,
357
+ ...BytecodeRepositoryContract.getBytecodeHashTypes()
358
+ });
359
+ }
360
+ static getBytecodeHashTypes() {
361
+ return {
362
+ primaryType: "Bytecode",
363
+ types: {
364
+ Bytecode: [
365
+ { name: "contractType", type: "bytes32" },
366
+ { name: "version", type: "uint256" },
367
+ { name: "initCode", type: "bytes" },
368
+ { name: "author", type: "address" },
369
+ { name: "source", type: "string" }
370
+ ]
371
+ }
372
+ };
373
+ }
374
+ async computeBytecodeHashContract(args) {
375
+ return await this.contract.read.computeBytecodeHash([
376
+ { ...args, authorSignature: "0x" }
377
+ ]);
378
+ }
379
+ async getAuditors() {
380
+ return [...await this.contract.read.getAuditors()];
381
+ }
382
+ isAuditor(auditor) {
383
+ return this.contract.read.isAuditor([auditor]);
384
+ }
385
+ extractDeployDataEvent(logs) {
386
+ const events = parseEventLogs({
387
+ logs: logs.filter(
388
+ (log) => log.address.toLowerCase() === this.address.toLowerCase()
389
+ ),
390
+ abi
391
+ });
392
+ const deployEvents = events.filter(
393
+ (event) => event.eventName === "DeployContract"
394
+ );
395
+ if (deployEvents.length !== 1) {
396
+ throw new Error("Invalid deploy event");
397
+ }
398
+ return {
399
+ address: deployEvents[0].args.contractAddress,
400
+ bytecodeHash: deployEvents[0].args.bytecodeHash,
401
+ contractType: deployEvents[0].args.contractType,
402
+ version: Number(deployEvents[0].args.version)
403
+ };
404
+ }
405
+ async computeAddress(args) {
406
+ return await this.contract.read.computeAddress([
407
+ stringToHex(args.contractType, { size: 32 }),
408
+ BigInt(args.version),
409
+ args.encodedParams,
410
+ args.salt,
411
+ args.owner
412
+ ]);
413
+ }
414
+ async isAlreadyDeployedAddress(args) {
415
+ const address = await this.computeAddress(args);
416
+ const code = await this.client.getCode({ address });
417
+ return [code !== void 0, address];
418
+ }
419
+ async isAlreadyDeployed(args) {
420
+ return (await this.isAlreadyDeployedAddress(args))[0];
421
+ }
422
+ async uploadBytecode(uploadByteCode, sponsor) {
423
+ const normalizedSignature = normalizeSignature(
424
+ uploadByteCode.authorSignature
425
+ );
426
+ return await this.contract.write.uploadBytecode(
427
+ [{ ...uploadByteCode, authorSignature: normalizedSignature }],
428
+ {
429
+ account: sponsor.account,
430
+ chain: sponsor.chain
431
+ // gas: 35_000_000n,
432
+ }
433
+ );
434
+ }
435
+ addAuditorTx(args) {
436
+ const { name, address } = args;
437
+ return this.createRawTx({
438
+ functionName: "addAuditor",
439
+ args: [address, name],
440
+ description: `BytecodeRepository.addAuditor(${name})`
441
+ });
442
+ }
443
+ addPublicDomainTx(args) {
444
+ const { domain } = args;
445
+ const domainHex = stringToHex(domain, { size: 32 });
446
+ return this.createRawTx({
447
+ functionName: "addPublicDomain",
448
+ args: [domainHex],
449
+ description: `BytecodeRepository.addPublicDomain(${domain})`
450
+ });
451
+ }
452
+ allowPublicContractTx(args) {
453
+ const { bytecodeHash } = args;
454
+ return this.createRawTx({
455
+ functionName: "allowPublicContract",
456
+ args: [bytecodeHash],
457
+ description: `BytecodeRepository.allowPublicContract(${bytecodeHash})`
458
+ });
459
+ }
460
+ allowSystemContractTx(args) {
461
+ const { bytecodeHash } = args;
462
+ return this.createRawTx({
463
+ functionName: "allowSystemContract",
464
+ args: [bytecodeHash],
465
+ description: `BytecodeRepository.allowSystemContract(${bytecodeHash})`
466
+ });
467
+ }
468
+ setTokenSpecificPostfixTx(args) {
469
+ const { token, postfix } = args;
470
+ const postfixHex = stringToHex(postfix, { size: 32 });
471
+ return this.createRawTx({
472
+ functionName: "setTokenSpecificPostfix",
473
+ args: [token, postfixHex],
474
+ description: `BytecodeRepository.setTokenSpecificPostfix(${token}, ${postfix})`
475
+ });
476
+ }
477
+ uploadBytecodeRawTx(uploadByteCode) {
478
+ return this.createRawTx({
479
+ functionName: "uploadBytecode",
480
+ args: [uploadByteCode]
481
+ });
482
+ }
483
+ extractDomain(contractType) {
484
+ const separatorIndex = contractType.indexOf("::");
485
+ if (separatorIndex === -1) return contractType;
486
+ return contractType.slice(0, separatorIndex);
487
+ }
488
+ async allowPublicContract(bytecodeHash, sponsor) {
489
+ return await this.contract.write.allowPublicContract([bytecodeHash], {
490
+ account: sponsor.account,
491
+ chain: sponsor.chain
492
+ });
493
+ }
494
+ deployTx(args) {
495
+ return this.createRawTx({
496
+ functionName: "deploy",
497
+ args: [
498
+ stringToHex(args.contractType, { size: 32 }),
499
+ args.version,
500
+ args.encodedParams,
501
+ args.salt
502
+ ]
503
+ });
504
+ }
505
+ }
506
+ export {
507
+ BytecodeRepositoryContract
508
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./token-compressor";
2
+ export * from "./withdrawal-compressor";
@@ -0,0 +1,89 @@
1
+ import {
2
+ erc20Abi,
3
+ parseAbi
4
+ } from "viem";
5
+ import { tokenCompressorAbi } from "../../../abi/compressors/tokenCompressor.js";
6
+ import { BaseContract } from "../base-contract";
7
+ const abi = tokenCompressorAbi;
8
+ class TokenCompressorContract extends BaseContract {
9
+ constructor(address, client) {
10
+ super(abi, address, client, "TokenCompressor");
11
+ }
12
+ async getTokenInfo(token) {
13
+ const result = await this.contract.read.getTokenInfo([token]);
14
+ return result;
15
+ }
16
+ // @dev workaround for mellow withdrawal phantom token symbol
17
+ async getMellowWithdrawalPhantomTokenInfo(tokens) {
18
+ const abi2 = parseAbi([
19
+ "function multiVault() public view returns (address)"
20
+ ]);
21
+ const contracts = tokens.map((token) => ({
22
+ address: token,
23
+ abi: abi2,
24
+ functionName: "multiVault",
25
+ args: []
26
+ }));
27
+ const results = await this.client.multicall({
28
+ contracts
29
+ });
30
+ const multivaultToToken = /* @__PURE__ */ new Map();
31
+ const multivaults = [];
32
+ for (let i = 0; i < results.length; i++) {
33
+ if (results[i].status === "success") {
34
+ const token = tokens[i];
35
+ const multivault = results[i].result;
36
+ multivaultToToken.set(multivault, token);
37
+ multivaults.push(multivault);
38
+ }
39
+ }
40
+ const resultsSymbols = await this.client.multicall({
41
+ contracts: multivaults.map((multiVault) => ({
42
+ address: multiVault,
43
+ abi: erc20Abi,
44
+ functionName: "symbol",
45
+ args: []
46
+ })),
47
+ allowFailure: true
48
+ });
49
+ const tokenToSymbol = /* @__PURE__ */ new Map();
50
+ for (let i = 0; i < resultsSymbols.length; i++) {
51
+ if (resultsSymbols[i].status === "success") {
52
+ const multivault = multivaults[i];
53
+ const token = multivaultToToken.get(multivault);
54
+ if (token) {
55
+ tokenToSymbol.set(token, resultsSymbols[i].result);
56
+ }
57
+ }
58
+ }
59
+ return Object.fromEntries(tokenToSymbol);
60
+ }
61
+ async getTokensInfo(tokens) {
62
+ const mellowPTInfo = await this.getMellowWithdrawalPhantomTokenInfo(tokens);
63
+ const results = await this.client.multicall({
64
+ contracts: tokens.map((token) => ({
65
+ address: this.address,
66
+ abi,
67
+ functionName: "getTokenInfo",
68
+ args: [token]
69
+ }))
70
+ });
71
+ const tokenInfos = results.map((result, index) => {
72
+ if (result.status === "failure") {
73
+ throw new Error(`Failed to get token info: ${result.error}`);
74
+ }
75
+ const token = tokens[index];
76
+ const multivaultSymbol = mellowPTInfo[token];
77
+ const tokenInfo = result.result;
78
+ const postfix = multivaultSymbol ? `[${multivaultSymbol}]` : "";
79
+ return {
80
+ ...tokenInfo,
81
+ symbol: `${tokenInfo.symbol} ${postfix}`
82
+ };
83
+ });
84
+ return tokenInfos;
85
+ }
86
+ }
87
+ export {
88
+ TokenCompressorContract
89
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ hexToString
3
+ } from "viem";
4
+ import { withdrawalCompressorAbi } from "../../../abi/compressors/withdrawalCompressor.js";
5
+ import { BaseContract } from "../base-contract";
6
+ const abi = withdrawalCompressorAbi;
7
+ class WithdrawalCompressorContract extends BaseContract {
8
+ constructor(address, client) {
9
+ super(abi, address, client, "RoutingManager");
10
+ }
11
+ parseFunctionParams(params) {
12
+ const { functionName, args } = params;
13
+ switch (functionName) {
14
+ case "setWithdrawableTypeToCompressorType": {
15
+ const [withdrawableType, compressorType] = args;
16
+ return {
17
+ chainId: 0,
18
+ target: this.address,
19
+ label: this.name,
20
+ functionName,
21
+ args: {
22
+ withdrawableType: hexToString(withdrawableType, {
23
+ size: 32
24
+ }),
25
+ compressorType: hexToString(compressorType, {
26
+ size: 32
27
+ })
28
+ }
29
+ };
30
+ }
31
+ default:
32
+ return void 0;
33
+ }
34
+ }
35
+ }
36
+ export {
37
+ WithdrawalCompressorContract
38
+ };