@gearbox-protocol/sdk 9.14.1 → 9.15.1

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 (258) hide show
  1. package/dist/cjs/abi/package.json +1 -0
  2. package/dist/cjs/dev/mint/factory.js +1 -1
  3. package/dist/cjs/permissionless/bindings/address-provider.js +51 -0
  4. package/dist/cjs/permissionless/bindings/base-contract.js +173 -0
  5. package/dist/cjs/permissionless/bindings/bytecode-repository.js +526 -0
  6. package/dist/cjs/permissionless/bindings/compressors/index.js +24 -0
  7. package/dist/cjs/permissionless/bindings/compressors/token-compressor.js +110 -0
  8. package/dist/cjs/permissionless/bindings/compressors/withdrawal-compressor.js +60 -0
  9. package/dist/cjs/permissionless/bindings/cross-chain-multisig.js +355 -0
  10. package/dist/cjs/permissionless/bindings/factory/abstract-factory.js +52 -0
  11. package/dist/cjs/permissionless/bindings/factory/credit-factory.js +197 -0
  12. package/dist/cjs/permissionless/bindings/factory/pool-factory.js +69 -0
  13. package/dist/cjs/permissionless/bindings/factory/price-oracle-factory.js +47 -0
  14. package/dist/cjs/permissionless/bindings/governance/batches-chain.js +41 -0
  15. package/dist/cjs/permissionless/bindings/governance/governor.js +243 -0
  16. package/dist/cjs/permissionless/bindings/governance/index.js +26 -0
  17. package/dist/cjs/permissionless/bindings/governance/timelock.js +104 -0
  18. package/dist/cjs/permissionless/bindings/governance/types.js +16 -0
  19. package/dist/cjs/permissionless/bindings/index.js +48 -0
  20. package/dist/cjs/permissionless/bindings/instance-manager.js +244 -0
  21. package/dist/cjs/permissionless/bindings/market-configurator-factory.js +75 -0
  22. package/dist/cjs/permissionless/bindings/market-configurator.js +771 -0
  23. package/dist/cjs/permissionless/bindings/price-feed-store.js +395 -0
  24. package/dist/cjs/permissionless/bindings/pricefeeds/balancer-stable.js +63 -0
  25. package/dist/cjs/permissionless/bindings/pricefeeds/balancer-weighted.js +63 -0
  26. package/dist/cjs/permissionless/bindings/pricefeeds/bounded.js +47 -0
  27. package/dist/cjs/permissionless/bindings/pricefeeds/composite.js +43 -0
  28. package/dist/cjs/permissionless/bindings/pricefeeds/constant.js +42 -0
  29. package/dist/cjs/permissionless/bindings/pricefeeds/curve-crypto.js +67 -0
  30. package/dist/cjs/permissionless/bindings/pricefeeds/curve-stable.js +67 -0
  31. package/dist/cjs/permissionless/bindings/pricefeeds/curve-twap.js +70 -0
  32. package/dist/cjs/permissionless/bindings/pricefeeds/curve-usd.js +50 -0
  33. package/dist/cjs/permissionless/bindings/pricefeeds/erc4626.js +72 -0
  34. package/dist/cjs/permissionless/bindings/pricefeeds/external.js +38 -0
  35. package/dist/cjs/permissionless/bindings/pricefeeds/index.js +63 -0
  36. package/dist/cjs/permissionless/bindings/pricefeeds/kodiak.js +50 -0
  37. package/dist/cjs/permissionless/bindings/pricefeeds/mellow-lrt.js +122 -0
  38. package/dist/cjs/permissionless/bindings/pricefeeds/pendle-pt-twap.js +51 -0
  39. package/dist/cjs/permissionless/bindings/pricefeeds/pyth.js +65 -0
  40. package/dist/cjs/permissionless/bindings/pricefeeds/redstone.js +81 -0
  41. package/dist/cjs/permissionless/bindings/pricefeeds/wsteth.js +63 -0
  42. package/dist/cjs/permissionless/bindings/pricefeeds/zero.js +33 -0
  43. package/dist/cjs/permissionless/bindings/router/index.js +22 -0
  44. package/dist/cjs/permissionless/bindings/router/routing-manager.js +58 -0
  45. package/dist/cjs/permissionless/bindings/treasury-splitter.js +60 -0
  46. package/dist/cjs/permissionless/bindings/types.js +16 -0
  47. package/dist/cjs/permissionless/chains/archive-transport.js +274 -0
  48. package/dist/cjs/permissionless/core/auditor.js +16 -0
  49. package/dist/cjs/permissionless/core/bytecode.js +16 -0
  50. package/dist/cjs/permissionless/core/index.js +32 -0
  51. package/dist/cjs/permissionless/core/pricefeed-builder.js +16 -0
  52. package/dist/cjs/permissionless/core/pricefeed.js +16 -0
  53. package/dist/cjs/permissionless/core/proposal.js +16 -0
  54. package/dist/cjs/permissionless/core/raw-tx.js +38 -0
  55. package/dist/cjs/permissionless/deployment/addresses.js +35 -0
  56. package/dist/cjs/permissionless/deployment/mainnet.js +54 -0
  57. package/dist/cjs/permissionless/index.js +32 -0
  58. package/dist/cjs/permissionless/package.json +1 -0
  59. package/dist/cjs/permissionless/plugins/index.js +40 -0
  60. package/dist/cjs/permissionless/plugins/irm/constructor-params-abi.js +81 -0
  61. package/dist/cjs/permissionless/plugins/loss-policies/constructor-params-abi.js +79 -0
  62. package/dist/cjs/permissionless/plugins/rate-keepers/constructor-params-abi.js +89 -0
  63. package/dist/cjs/permissionless/utils/abi-decoder.js +72 -0
  64. package/dist/cjs/permissionless/utils/abi-encoder.js +89 -0
  65. package/dist/cjs/permissionless/utils/block-utils.js +55 -0
  66. package/dist/cjs/permissionless/utils/create2.js +113 -0
  67. package/dist/cjs/permissionless/utils/format.js +97 -0
  68. package/dist/cjs/permissionless/utils/governance/batch.js +114 -0
  69. package/dist/cjs/permissionless/utils/governance/index.js +26 -0
  70. package/dist/cjs/permissionless/utils/governance/timelock-txs.js +44 -0
  71. package/dist/cjs/permissionless/utils/governance/types.js +16 -0
  72. package/dist/cjs/permissionless/utils/index.js +38 -0
  73. package/dist/cjs/permissionless/utils/literals.js +46 -0
  74. package/dist/cjs/permissionless/utils/price-update/get-price-feeds.js +91 -0
  75. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +84 -0
  76. package/dist/cjs/permissionless/utils/price-update/get-prices.js +123 -0
  77. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +52 -0
  78. package/dist/cjs/permissionless/utils/price-update/index.js +28 -0
  79. package/dist/cjs/permissionless/utils/signature.js +35 -0
  80. package/dist/cjs/plugins/adapters/AdaptersPlugin.js +1 -1
  81. package/dist/cjs/plugins/adapters/abi/actionAbi.js +1 -1
  82. package/dist/cjs/plugins/adapters/abi/conctructorAbi.js +2 -2
  83. package/dist/cjs/plugins/adapters/abi/utils.js +6 -6
  84. package/dist/cjs/plugins/adapters/index.js +4 -4
  85. package/dist/cjs/sdk/sdk-gov-legacy/tokens/curveLP.js +1 -1
  86. package/dist/cjs/sdk/sdk-legacy/tokens/tokenData.js +1 -1
  87. package/dist/esm/abi/package.json +1 -0
  88. package/dist/esm/dev/mint/factory.js +1 -1
  89. package/dist/esm/permissionless/bindings/address-provider.js +27 -0
  90. package/dist/esm/permissionless/bindings/base-contract.js +151 -0
  91. package/dist/esm/permissionless/bindings/bytecode-repository.js +508 -0
  92. package/dist/esm/permissionless/bindings/compressors/index.js +2 -0
  93. package/dist/esm/permissionless/bindings/compressors/token-compressor.js +89 -0
  94. package/dist/esm/permissionless/bindings/compressors/withdrawal-compressor.js +38 -0
  95. package/dist/esm/permissionless/bindings/cross-chain-multisig.js +336 -0
  96. package/dist/esm/permissionless/bindings/factory/abstract-factory.js +28 -0
  97. package/dist/esm/permissionless/bindings/factory/credit-factory.js +177 -0
  98. package/dist/esm/permissionless/bindings/factory/pool-factory.js +45 -0
  99. package/dist/esm/permissionless/bindings/factory/price-oracle-factory.js +23 -0
  100. package/dist/esm/permissionless/bindings/governance/batches-chain.js +17 -0
  101. package/dist/esm/permissionless/bindings/governance/governor.js +224 -0
  102. package/dist/esm/permissionless/bindings/governance/index.js +3 -0
  103. package/dist/esm/permissionless/bindings/governance/timelock.js +80 -0
  104. package/dist/esm/permissionless/bindings/governance/types.js +0 -0
  105. package/dist/esm/permissionless/bindings/index.js +14 -0
  106. package/dist/esm/permissionless/bindings/instance-manager.js +223 -0
  107. package/dist/esm/permissionless/bindings/market-configurator-factory.js +51 -0
  108. package/dist/esm/permissionless/bindings/market-configurator.js +765 -0
  109. package/dist/esm/permissionless/bindings/price-feed-store.js +376 -0
  110. package/dist/esm/permissionless/bindings/pricefeeds/balancer-stable.js +39 -0
  111. package/dist/esm/permissionless/bindings/pricefeeds/balancer-weighted.js +39 -0
  112. package/dist/esm/permissionless/bindings/pricefeeds/bounded.js +23 -0
  113. package/dist/esm/permissionless/bindings/pricefeeds/composite.js +19 -0
  114. package/dist/esm/permissionless/bindings/pricefeeds/constant.js +18 -0
  115. package/dist/esm/permissionless/bindings/pricefeeds/curve-crypto.js +43 -0
  116. package/dist/esm/permissionless/bindings/pricefeeds/curve-stable.js +43 -0
  117. package/dist/esm/permissionless/bindings/pricefeeds/curve-twap.js +46 -0
  118. package/dist/esm/permissionless/bindings/pricefeeds/curve-usd.js +26 -0
  119. package/dist/esm/permissionless/bindings/pricefeeds/erc4626.js +48 -0
  120. package/dist/esm/permissionless/bindings/pricefeeds/external.js +14 -0
  121. package/dist/esm/permissionless/bindings/pricefeeds/index.js +39 -0
  122. package/dist/esm/permissionless/bindings/pricefeeds/kodiak.js +26 -0
  123. package/dist/esm/permissionless/bindings/pricefeeds/mellow-lrt.js +98 -0
  124. package/dist/esm/permissionless/bindings/pricefeeds/pendle-pt-twap.js +27 -0
  125. package/dist/esm/permissionless/bindings/pricefeeds/pyth.js +41 -0
  126. package/dist/esm/permissionless/bindings/pricefeeds/redstone.js +57 -0
  127. package/dist/esm/permissionless/bindings/pricefeeds/wsteth.js +39 -0
  128. package/dist/esm/permissionless/bindings/pricefeeds/zero.js +9 -0
  129. package/dist/esm/permissionless/bindings/router/index.js +1 -0
  130. package/dist/esm/permissionless/bindings/router/routing-manager.js +36 -0
  131. package/dist/esm/permissionless/bindings/treasury-splitter.js +36 -0
  132. package/dist/esm/permissionless/bindings/types.js +0 -0
  133. package/dist/esm/permissionless/chains/archive-transport.js +250 -0
  134. package/dist/esm/permissionless/core/auditor.js +0 -0
  135. package/dist/esm/permissionless/core/bytecode.js +0 -0
  136. package/dist/esm/permissionless/core/index.js +6 -0
  137. package/dist/esm/permissionless/core/pricefeed-builder.js +0 -0
  138. package/dist/esm/permissionless/core/pricefeed.js +0 -0
  139. package/dist/esm/permissionless/core/proposal.js +0 -0
  140. package/dist/esm/permissionless/core/raw-tx.js +14 -0
  141. package/dist/esm/permissionless/deployment/addresses.js +11 -0
  142. package/dist/esm/permissionless/deployment/mainnet.js +27 -0
  143. package/dist/esm/permissionless/index.js +6 -0
  144. package/dist/esm/permissionless/package.json +1 -0
  145. package/dist/esm/permissionless/plugins/index.js +20 -0
  146. package/dist/esm/permissionless/plugins/irm/constructor-params-abi.js +52 -0
  147. package/dist/esm/permissionless/plugins/loss-policies/constructor-params-abi.js +50 -0
  148. package/dist/esm/permissionless/plugins/rate-keepers/constructor-params-abi.js +59 -0
  149. package/dist/esm/permissionless/utils/abi-decoder.js +50 -0
  150. package/dist/esm/permissionless/utils/abi-encoder.js +65 -0
  151. package/dist/esm/permissionless/utils/block-utils.js +31 -0
  152. package/dist/esm/permissionless/utils/create2.js +85 -0
  153. package/dist/esm/permissionless/utils/format.js +67 -0
  154. package/dist/esm/permissionless/utils/governance/batch.js +87 -0
  155. package/dist/esm/permissionless/utils/governance/index.js +3 -0
  156. package/dist/esm/permissionless/utils/governance/timelock-txs.js +20 -0
  157. package/dist/esm/permissionless/utils/governance/types.js +0 -0
  158. package/dist/esm/permissionless/utils/index.js +9 -0
  159. package/dist/esm/permissionless/utils/literals.js +16 -0
  160. package/dist/esm/permissionless/utils/price-update/get-price-feeds.js +65 -0
  161. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +67 -0
  162. package/dist/esm/permissionless/utils/price-update/get-prices.js +99 -0
  163. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +31 -0
  164. package/dist/esm/permissionless/utils/price-update/index.js +4 -0
  165. package/dist/esm/permissionless/utils/signature.js +11 -0
  166. package/dist/esm/plugins/adapters/AdaptersPlugin.js +1 -1
  167. package/dist/esm/plugins/adapters/abi/actionAbi.js +1 -1
  168. package/dist/esm/plugins/adapters/abi/conctructorAbi.js +2 -2
  169. package/dist/esm/plugins/adapters/abi/utils.js +2 -2
  170. package/dist/esm/plugins/adapters/index.js +2 -2
  171. package/dist/esm/sdk/sdk-gov-legacy/tokens/curveLP.js +1 -1
  172. package/dist/esm/sdk/sdk-legacy/tokens/tokenData.js +1 -1
  173. package/dist/types/dev/mint/factory.d.ts +2 -2
  174. package/dist/types/permissionless/bindings/address-provider.d.ts +259 -0
  175. package/dist/types/permissionless/bindings/base-contract.d.ts +23 -0
  176. package/dist/types/permissionless/bindings/bytecode-repository.d.ts +1352 -0
  177. package/dist/types/permissionless/bindings/compressors/index.d.ts +2 -0
  178. package/dist/types/permissionless/bindings/compressors/token-compressor.d.ts +118 -0
  179. package/dist/types/permissionless/bindings/compressors/withdrawal-compressor.d.ts +331 -0
  180. package/dist/types/permissionless/bindings/cross-chain-multisig.d.ts +835 -0
  181. package/dist/types/permissionless/bindings/factory/abstract-factory.d.ts +17 -0
  182. package/dist/types/permissionless/bindings/factory/credit-factory.d.ts +224 -0
  183. package/dist/types/permissionless/bindings/factory/pool-factory.d.ts +86 -0
  184. package/dist/types/permissionless/bindings/factory/price-oracle-factory.d.ts +38 -0
  185. package/dist/types/permissionless/bindings/governance/batches-chain.d.ts +39 -0
  186. package/dist/types/permissionless/bindings/governance/governor.d.ts +615 -0
  187. package/dist/types/permissionless/bindings/governance/index.d.ts +3 -0
  188. package/dist/types/permissionless/bindings/governance/timelock.d.ts +10 -0
  189. package/dist/types/permissionless/bindings/governance/types.d.ts +42 -0
  190. package/dist/types/permissionless/bindings/index.d.ts +14 -0
  191. package/dist/types/permissionless/bindings/instance-manager.d.ts +361 -0
  192. package/dist/types/permissionless/bindings/market-configurator-factory.d.ts +244 -0
  193. package/dist/types/permissionless/bindings/market-configurator.d.ts +1656 -0
  194. package/dist/types/permissionless/bindings/price-feed-store.d.ts +605 -0
  195. package/dist/types/permissionless/bindings/pricefeeds/balancer-stable.d.ts +2 -0
  196. package/dist/types/permissionless/bindings/pricefeeds/balancer-weighted.d.ts +2 -0
  197. package/dist/types/permissionless/bindings/pricefeeds/bounded.d.ts +2 -0
  198. package/dist/types/permissionless/bindings/pricefeeds/composite.d.ts +2 -0
  199. package/dist/types/permissionless/bindings/pricefeeds/constant.d.ts +2 -0
  200. package/dist/types/permissionless/bindings/pricefeeds/curve-crypto.d.ts +2 -0
  201. package/dist/types/permissionless/bindings/pricefeeds/curve-stable.d.ts +2 -0
  202. package/dist/types/permissionless/bindings/pricefeeds/curve-twap.d.ts +2 -0
  203. package/dist/types/permissionless/bindings/pricefeeds/curve-usd.d.ts +2 -0
  204. package/dist/types/permissionless/bindings/pricefeeds/erc4626.d.ts +2 -0
  205. package/dist/types/permissionless/bindings/pricefeeds/external.d.ts +2 -0
  206. package/dist/types/permissionless/bindings/pricefeeds/index.d.ts +2 -0
  207. package/dist/types/permissionless/bindings/pricefeeds/kodiak.d.ts +2 -0
  208. package/dist/types/permissionless/bindings/pricefeeds/mellow-lrt.d.ts +2 -0
  209. package/dist/types/permissionless/bindings/pricefeeds/pendle-pt-twap.d.ts +2 -0
  210. package/dist/types/permissionless/bindings/pricefeeds/pyth.d.ts +2 -0
  211. package/dist/types/permissionless/bindings/pricefeeds/redstone.d.ts +2 -0
  212. package/dist/types/permissionless/bindings/pricefeeds/wsteth.d.ts +2 -0
  213. package/dist/types/permissionless/bindings/pricefeeds/zero.d.ts +2 -0
  214. package/dist/types/permissionless/bindings/router/index.d.ts +1 -0
  215. package/dist/types/permissionless/bindings/router/routing-manager.d.ts +502 -0
  216. package/dist/types/permissionless/bindings/treasury-splitter.d.ts +21 -0
  217. package/dist/types/permissionless/bindings/types.d.ts +65 -0
  218. package/dist/types/permissionless/chains/archive-transport.d.ts +49 -0
  219. package/dist/types/permissionless/core/auditor.d.ts +7 -0
  220. package/dist/types/permissionless/core/bytecode.d.ts +46 -0
  221. package/dist/types/permissionless/core/index.d.ts +6 -0
  222. package/dist/types/permissionless/core/pricefeed-builder.d.ts +59 -0
  223. package/dist/types/permissionless/core/pricefeed.d.ts +10 -0
  224. package/dist/types/permissionless/core/proposal.d.ts +33 -0
  225. package/dist/types/permissionless/core/raw-tx.d.ts +4 -0
  226. package/dist/types/permissionless/deployment/addresses.d.ts +7 -0
  227. package/dist/types/permissionless/deployment/mainnet.d.ts +10 -0
  228. package/dist/types/permissionless/index.d.ts +6 -0
  229. package/dist/types/permissionless/plugins/index.d.ts +3 -0
  230. package/dist/types/permissionless/plugins/irm/constructor-params-abi.d.ts +63 -0
  231. package/dist/types/permissionless/plugins/loss-policies/constructor-params-abi.d.ts +48 -0
  232. package/dist/types/permissionless/plugins/rate-keepers/constructor-params-abi.d.ts +55 -0
  233. package/dist/types/permissionless/utils/abi-decoder.d.ts +13 -0
  234. package/dist/types/permissionless/utils/abi-encoder.d.ts +7 -0
  235. package/dist/types/permissionless/utils/block-utils.d.ts +8 -0
  236. package/dist/types/permissionless/utils/create2.d.ts +17 -0
  237. package/dist/types/permissionless/utils/format.d.ts +7 -0
  238. package/dist/types/permissionless/utils/governance/batch.d.ts +17 -0
  239. package/dist/types/permissionless/utils/governance/index.d.ts +3 -0
  240. package/dist/types/permissionless/utils/governance/timelock-txs.d.ts +2 -0
  241. package/dist/types/permissionless/utils/governance/types.d.ts +16 -0
  242. package/dist/types/permissionless/utils/index.d.ts +9 -0
  243. package/dist/types/permissionless/utils/literals.d.ts +7 -0
  244. package/dist/types/permissionless/utils/price-update/get-price-feeds.d.ts +8 -0
  245. package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +9 -0
  246. package/dist/types/permissionless/utils/price-update/get-prices.d.ts +6 -0
  247. package/dist/types/permissionless/utils/price-update/get-updatable-feeds.d.ts +8 -0
  248. package/dist/types/permissionless/utils/price-update/index.d.ts +4 -0
  249. package/dist/types/permissionless/utils/signature.d.ts +2 -0
  250. package/dist/types/plugins/adapters/abi/actionAbi.d.ts +1 -1
  251. package/dist/types/plugins/adapters/abi/conctructorAbi.d.ts +1 -1
  252. package/dist/types/plugins/adapters/abi/utils.d.ts +1 -1
  253. package/dist/types/plugins/adapters/index.d.ts +2 -2
  254. package/dist/types/plugins/zappers/extraZappers.d.ts +2 -2
  255. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +1 -2
  256. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +1 -2
  257. package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +1 -1
  258. package/package.json +6 -6
@@ -0,0 +1,151 @@
1
+ import {
2
+ getContract
3
+ } from "viem";
4
+ import { createRawTx } from "../../sdk/utils/index.js";
5
+ import { decodeFunctionWithNamedArgs } from "../utils/abi-decoder.js";
6
+ class BaseContract {
7
+ abi;
8
+ address;
9
+ name;
10
+ static register = {};
11
+ contract;
12
+ client;
13
+ constructor(abi, address, client, name) {
14
+ this.abi = abi;
15
+ this.client = client;
16
+ this.address = address.toLowerCase();
17
+ this.name = name;
18
+ this.contract = getContract({
19
+ address,
20
+ abi,
21
+ client
22
+ });
23
+ BaseContract.register[this.address] = this;
24
+ }
25
+ static parseCall(call) {
26
+ const parsedCall = BaseContract.parse(call.target, call.callData);
27
+ return {
28
+ ...parsedCall,
29
+ chainId: call.chainId
30
+ };
31
+ }
32
+ static parse(address, calldata) {
33
+ const contract = BaseContract.register[address.toLowerCase()];
34
+ if (contract) {
35
+ return contract.parseFunctionData(calldata);
36
+ } else {
37
+ return {
38
+ chainId: 0,
39
+ target: address,
40
+ label: "Unknown contract",
41
+ functionName: `Unknown function: ${calldata}`,
42
+ args: {}
43
+ };
44
+ }
45
+ }
46
+ parseFunctionData(calldata) {
47
+ const decodedWithNames = decodeFunctionWithNamedArgs(this.abi, calldata);
48
+ if (!decodedWithNames) {
49
+ return {
50
+ chainId: 0,
51
+ target: this.address,
52
+ label: this.name,
53
+ functionName: `Unknown function: ${calldata}`,
54
+ args: {}
55
+ };
56
+ }
57
+ const specParsed = this.parseFunctionParams(
58
+ decodedWithNames.originalDecoded
59
+ );
60
+ if (specParsed) {
61
+ return specParsed;
62
+ }
63
+ return this.wrapParseCall(
64
+ decodedWithNames.originalDecoded,
65
+ decodedWithNames.args
66
+ );
67
+ }
68
+ wrapParseCall(params, parsedParams) {
69
+ return {
70
+ chainId: 0,
71
+ target: this.address,
72
+ label: this.name,
73
+ functionName: params.functionName,
74
+ args: parsedParams
75
+ };
76
+ }
77
+ parseFunctionParams(_params) {
78
+ return void 0;
79
+ }
80
+ createRawTx(parameters) {
81
+ const { description: argsDescription } = parameters;
82
+ const tx = createRawTx(
83
+ this.address,
84
+ {
85
+ abi: this.abi,
86
+ ...parameters
87
+ },
88
+ argsDescription
89
+ );
90
+ tx.description = parameters.description || argsDescription || this.stringifyParsedCall(this.parseFunctionData(tx.callData));
91
+ return tx;
92
+ }
93
+ stringifyParsedCall(parsedCall) {
94
+ const argsStr = Object.entries(parsedCall.args).map(([key, value]) => `${key}: ${value}`).join(", ");
95
+ return `${parsedCall.label}.${parsedCall.functionName}(${argsStr})`;
96
+ }
97
+ async getEvents(eventName, fromBlock, toBlock, args, chunkSize) {
98
+ if (chunkSize) {
99
+ const chunkSizeBigint = BigInt(chunkSize);
100
+ const getEventPromises = [];
101
+ for (let i = fromBlock; i < toBlock; i += chunkSizeBigint) {
102
+ getEventPromises.push(
103
+ this.client.getContractEvents({
104
+ address: this.address,
105
+ fromBlock: i,
106
+ toBlock: i + chunkSizeBigint,
107
+ abi: this.abi,
108
+ eventName,
109
+ args
110
+ })
111
+ );
112
+ }
113
+ const events = (await Promise.all(getEventPromises)).flat();
114
+ return events;
115
+ }
116
+ try {
117
+ const events = await this.client.getContractEvents({
118
+ address: this.address,
119
+ fromBlock,
120
+ toBlock,
121
+ abi: this.abi,
122
+ eventName,
123
+ args
124
+ });
125
+ return events;
126
+ } catch (e) {
127
+ const blockRangeErrors = [
128
+ "query exceeds max block",
129
+ "range is too large",
130
+ "eth_getLogs is limited to",
131
+ "Unable to perform request",
132
+ "Block range limit exceeded"
133
+ ];
134
+ if (e instanceof Error && blockRangeErrors.some((errorText) => e.message.includes(errorText))) {
135
+ const middle = (fromBlock + toBlock) / 2n;
136
+ const [firstHalfEvents, secondHalfEvents] = await Promise.all([
137
+ this.getEvents(eventName, fromBlock, middle, args),
138
+ this.getEvents(eventName, middle + 1n, toBlock, args)
139
+ ]);
140
+ return [...firstHalfEvents, ...secondHalfEvents];
141
+ }
142
+ throw e;
143
+ }
144
+ }
145
+ getContract() {
146
+ return this.contract;
147
+ }
148
+ }
149
+ export {
150
+ BaseContract
151
+ };
@@ -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/index.js";
10
+ import { BYTECODE_REPOSITORY } from "../utils/literals.js";
11
+ import { BaseContract } from "./base-contract.js";
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.js";
2
+ export * from "./withdrawal-compressor.js";