@gearbox-protocol/sdk 18.5.0-next.3 → 18.5.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 (78) hide show
  1. package/dist/cjs/onchain/abi/index.js +0 -2
  2. package/dist/cjs/onchain/abi/oracles.js +0 -617
  3. package/dist/cjs/onchain/index.js +0 -4
  4. package/dist/cjs/onchain/market/index.js +0 -4
  5. package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +0 -4
  6. package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +0 -4
  7. package/dist/cjs/onchain/market/pricefeeds/index.js +0 -4
  8. package/dist/cjs/permissionless/bindings/price-feed-store.js +0 -1
  9. package/dist/cjs/permissionless/bindings/pricefeeds/index.js +3 -7
  10. package/dist/cjs/sdk/execute/ExecuteApi.js +41 -0
  11. package/dist/cjs/testnets/TestnetsAPI.js +178 -0
  12. package/dist/cjs/testnets/errors/TestnetNotFoundError.js +14 -0
  13. package/dist/cjs/testnets/errors/TestnetRequestFailedError.js +23 -0
  14. package/dist/cjs/testnets/errors/TestnetStatusError.js +18 -0
  15. package/dist/cjs/testnets/errors/TestnetValidationError.js +23 -0
  16. package/dist/cjs/testnets/errors/TestnetWaitTimeoutError.js +29 -0
  17. package/dist/cjs/testnets/errors/TestnetsError.js +33 -0
  18. package/dist/cjs/testnets/errors/index.js +13 -0
  19. package/dist/cjs/testnets/index.js +32 -0
  20. package/dist/cjs/testnets/package.json +1 -0
  21. package/dist/cjs/testnets/schemas.js +241 -0
  22. package/dist/cjs/testnets/types.js +1 -0
  23. package/dist/esm/onchain/abi/index.js +1 -1
  24. package/dist/esm/onchain/abi/oracles.js +1 -616
  25. package/dist/esm/onchain/index.js +1 -3
  26. package/dist/esm/onchain/market/index.js +1 -3
  27. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +0 -4
  28. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +1 -3
  29. package/dist/esm/onchain/market/pricefeeds/index.js +1 -3
  30. package/dist/esm/permissionless/bindings/price-feed-store.js +0 -1
  31. package/dist/esm/permissionless/bindings/pricefeeds/index.js +3 -7
  32. package/dist/esm/sdk/execute/ExecuteApi.js +41 -0
  33. package/dist/esm/testnets/TestnetsAPI.js +177 -0
  34. package/dist/esm/testnets/errors/TestnetNotFoundError.js +13 -0
  35. package/dist/esm/testnets/errors/TestnetRequestFailedError.js +22 -0
  36. package/dist/esm/testnets/errors/TestnetStatusError.js +17 -0
  37. package/dist/esm/testnets/errors/TestnetValidationError.js +22 -0
  38. package/dist/esm/testnets/errors/TestnetWaitTimeoutError.js +28 -0
  39. package/dist/esm/testnets/errors/TestnetsError.js +32 -0
  40. package/dist/esm/testnets/errors/index.js +7 -0
  41. package/dist/esm/testnets/index.js +11 -0
  42. package/dist/esm/testnets/package.json +1 -0
  43. package/dist/esm/testnets/schemas.js +227 -0
  44. package/dist/esm/testnets/types.js +1 -0
  45. package/dist/types/onchain/abi/index.d.ts +2 -2
  46. package/dist/types/onchain/abi/oracles.d.ts +0 -536
  47. package/dist/types/onchain/index.d.ts +1 -3
  48. package/dist/types/onchain/market/index.d.ts +1 -3
  49. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +1 -3
  50. package/dist/types/onchain/market/pricefeeds/index.d.ts +1 -3
  51. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -1
  52. package/dist/types/permissionless/core/pricefeed-builder.d.ts +0 -2
  53. package/dist/types/sdk/execute/ExecuteApi.d.ts +8 -0
  54. package/dist/types/sdk/execute/types.d.ts +14 -0
  55. package/dist/types/testnets/TestnetsAPI.d.ts +106 -0
  56. package/dist/types/testnets/errors/TestnetNotFoundError.d.ts +10 -0
  57. package/dist/types/testnets/errors/TestnetRequestFailedError.d.ts +9 -0
  58. package/dist/types/testnets/errors/TestnetStatusError.d.ts +13 -0
  59. package/dist/types/testnets/errors/TestnetValidationError.d.ts +14 -0
  60. package/dist/types/testnets/errors/TestnetWaitTimeoutError.d.ts +19 -0
  61. package/dist/types/testnets/errors/TestnetsError.d.ts +45 -0
  62. package/dist/types/testnets/errors/index.d.ts +7 -0
  63. package/dist/types/testnets/index.d.ts +17 -0
  64. package/dist/types/testnets/schemas.d.ts +552 -0
  65. package/dist/types/testnets/types.d.ts +715 -0
  66. package/package.json +6 -1
  67. package/dist/cjs/onchain/market/pricefeeds/feeds/FixedRateWindowPriceFeed.js +0 -15
  68. package/dist/cjs/onchain/market/pricefeeds/feeds/MedianPriceFeed.js +0 -15
  69. package/dist/cjs/permissionless/bindings/pricefeeds/fix-rate-window.js +0 -53
  70. package/dist/cjs/permissionless/bindings/pricefeeds/median.js +0 -22
  71. package/dist/esm/onchain/market/pricefeeds/feeds/FixedRateWindowPriceFeed.js +0 -14
  72. package/dist/esm/onchain/market/pricefeeds/feeds/MedianPriceFeed.js +0 -14
  73. package/dist/esm/permissionless/bindings/pricefeeds/fix-rate-window.js +0 -52
  74. package/dist/esm/permissionless/bindings/pricefeeds/median.js +0 -21
  75. package/dist/types/onchain/market/pricefeeds/feeds/FixedRateWindowPriceFeed.d.ts +0 -9
  76. package/dist/types/onchain/market/pricefeeds/feeds/MedianPriceFeed.d.ts +0 -9
  77. package/dist/types/permissionless/bindings/pricefeeds/fix-rate-window.d.ts +0 -3
  78. package/dist/types/permissionless/bindings/pricefeeds/median.d.ts +0 -3
@@ -15,8 +15,6 @@ const require_onchain_market_pricefeeds_feeds_CurveStablePriceFeed = require("./
15
15
  const require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed = require("./feeds/CurveUSDPriceFeed.js");
16
16
  const require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed = require("./feeds/Erc4626PriceFeed.js");
17
17
  const require_onchain_market_pricefeeds_feeds_ExternalPriceFeed = require("./feeds/ExternalPriceFeed.js");
18
- const require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed = require("./feeds/FixedRateWindowPriceFeed.js");
19
- const require_onchain_market_pricefeeds_feeds_MedianPriceFeed = require("./feeds/MedianPriceFeed.js");
20
18
  const require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed = require("./feeds/MellowLRTPriceFeed.js");
21
19
  const require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed = require("./feeds/PendleTWAPPTPriceFeed.js");
22
20
  const require_onchain_market_pricefeeds_feeds_PythPriceFeed = require("./feeds/PythPriceFeed.js");
@@ -109,8 +107,6 @@ var PriceFeedRegistry = class extends require_onchain_base_SDKConstruct.SDKConst
109
107
  case "PRICE_FEED::CURVE_USD": return new require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed.CurveUSDPriceFeedContract(this.sdk, data);
110
108
  case "PRICE_FEED::ERC4626": return new require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed.Erc4626PriceFeedContract(this.sdk, data);
111
109
  case "PRICE_FEED::EXTERNAL": return new require_onchain_market_pricefeeds_feeds_ExternalPriceFeed.ExternalPriceFeedContract(this.sdk, data);
112
- case "PRICE_FEED::FIXED_RATE_WINDOW": return new require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed.FixedRateWindowPriceFeedContract(this.sdk, data);
113
- case "PRICE_FEED::MEDIAN": return new require_onchain_market_pricefeeds_feeds_MedianPriceFeed.MedianPriceFeedContract(this.sdk, data);
114
110
  case "PRICE_FEED::MELLOW_LRT": return new require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract(this.sdk, data);
115
111
  case "PRICE_FEED::PENDLE_PT_TWAP": return new require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed.PendleTWAPPTPriceFeed(this.sdk, data);
116
112
  case "PRICE_FEED::PYTH": return new require_onchain_market_pricefeeds_feeds_PythPriceFeed.PythPriceFeed(this.sdk, data);
@@ -9,8 +9,6 @@ const require_onchain_market_pricefeeds_feeds_CurveStablePriceFeed = require("./
9
9
  const require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed = require("./CurveUSDPriceFeed.js");
10
10
  const require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed = require("./Erc4626PriceFeed.js");
11
11
  const require_onchain_market_pricefeeds_feeds_ExternalPriceFeed = require("./ExternalPriceFeed.js");
12
- const require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed = require("./FixedRateWindowPriceFeed.js");
13
- const require_onchain_market_pricefeeds_feeds_MedianPriceFeed = require("./MedianPriceFeed.js");
14
12
  const require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed = require("./MellowLRTPriceFeed.js");
15
13
  const require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed = require("./PendleTWAPPTPriceFeed.js");
16
14
  const require_onchain_market_pricefeeds_feeds_PythPriceFeed = require("./PythPriceFeed.js");
@@ -28,8 +26,6 @@ exports.CurveStablePriceFeedContract = require_onchain_market_pricefeeds_feeds_C
28
26
  exports.CurveUSDPriceFeedContract = require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed.CurveUSDPriceFeedContract;
29
27
  exports.Erc4626PriceFeedContract = require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed.Erc4626PriceFeedContract;
30
28
  exports.ExternalPriceFeedContract = require_onchain_market_pricefeeds_feeds_ExternalPriceFeed.ExternalPriceFeedContract;
31
- exports.FixedRateWindowPriceFeedContract = require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed.FixedRateWindowPriceFeedContract;
32
- exports.MedianPriceFeedContract = require_onchain_market_pricefeeds_feeds_MedianPriceFeed.MedianPriceFeedContract;
33
29
  exports.MellowLRTPriceFeedContract = require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract;
34
30
  exports.PendleTWAPPTPriceFeed = require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed.PendleTWAPPTPriceFeed;
35
31
  exports.PythPriceFeed = require_onchain_market_pricefeeds_feeds_PythPriceFeed.PythPriceFeed;
@@ -12,8 +12,6 @@ const require_onchain_market_pricefeeds_feeds_CurveStablePriceFeed = require("./
12
12
  const require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed = require("./feeds/CurveUSDPriceFeed.js");
13
13
  const require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed = require("./feeds/Erc4626PriceFeed.js");
14
14
  const require_onchain_market_pricefeeds_feeds_ExternalPriceFeed = require("./feeds/ExternalPriceFeed.js");
15
- const require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed = require("./feeds/FixedRateWindowPriceFeed.js");
16
- const require_onchain_market_pricefeeds_feeds_MedianPriceFeed = require("./feeds/MedianPriceFeed.js");
17
15
  const require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed = require("./feeds/MellowLRTPriceFeed.js");
18
16
  const require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed = require("./feeds/PendleTWAPPTPriceFeed.js");
19
17
  const require_onchain_market_pricefeeds_feeds_PythPriceFeed = require("./feeds/PythPriceFeed.js");
@@ -42,8 +40,6 @@ exports.CurveStablePriceFeedContract = require_onchain_market_pricefeeds_feeds_C
42
40
  exports.CurveUSDPriceFeedContract = require_onchain_market_pricefeeds_feeds_CurveUSDPriceFeed.CurveUSDPriceFeedContract;
43
41
  exports.Erc4626PriceFeedContract = require_onchain_market_pricefeeds_feeds_Erc4626PriceFeed.Erc4626PriceFeedContract;
44
42
  exports.ExternalPriceFeedContract = require_onchain_market_pricefeeds_feeds_ExternalPriceFeed.ExternalPriceFeedContract;
45
- exports.FixedRateWindowPriceFeedContract = require_onchain_market_pricefeeds_feeds_FixedRateWindowPriceFeed.FixedRateWindowPriceFeedContract;
46
- exports.MedianPriceFeedContract = require_onchain_market_pricefeeds_feeds_MedianPriceFeed.MedianPriceFeedContract;
47
43
  exports.MellowLRTPriceFeedContract = require_onchain_market_pricefeeds_feeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract;
48
44
  exports.PartialPriceFeedInitError = require_onchain_market_pricefeeds_AbstractPriceFeed.PartialPriceFeedInitError;
49
45
  exports.PendleTWAPPTPriceFeed = require_onchain_market_pricefeeds_feeds_PendleTWAPPTPriceFeed.PendleTWAPPTPriceFeed;
@@ -157,7 +157,6 @@ var PriceFeedStoreContract = class extends require_onchain_base_BaseContract.Bas
157
157
  types.push({ type: param.type.type });
158
158
  values.push(BigInt(data[param.label]));
159
159
  break;
160
- case "uint16":
161
160
  case "uint8":
162
161
  types.push({ type: param.type.type });
163
162
  values.push(Number(data[param.label]));
@@ -10,9 +10,7 @@ const require_permissionless_bindings_pricefeeds_curve_twap = require("./curve-t
10
10
  const require_permissionless_bindings_pricefeeds_curve_usd = require("./curve-usd.js");
11
11
  const require_permissionless_bindings_pricefeeds_erc4626 = require("./erc4626.js");
12
12
  const require_permissionless_bindings_pricefeeds_external = require("./external.js");
13
- const require_permissionless_bindings_pricefeeds_fix_rate_window = require("./fix-rate-window.js");
14
13
  const require_permissionless_bindings_pricefeeds_kodiak = require("./kodiak.js");
15
- const require_permissionless_bindings_pricefeeds_median = require("./median.js");
16
14
  const require_permissionless_bindings_pricefeeds_mellow_lrt = require("./mellow-lrt.js");
17
15
  const require_permissionless_bindings_pricefeeds_pendle_pt_twap = require("./pendle-pt-twap.js");
18
16
  const require_permissionless_bindings_pricefeeds_pyth = require("./pyth.js");
@@ -24,8 +22,8 @@ const priceFeedSetupParams = [
24
22
  require_permissionless_bindings_pricefeeds_composite.compositePriceFeed,
25
23
  require_permissionless_bindings_pricefeeds_bounded.boundedPriceFeed,
26
24
  require_permissionless_bindings_pricefeeds_constant.constantPriceFeed,
27
- require_permissionless_bindings_pricefeeds_median.medianPriceFeed,
28
- require_permissionless_bindings_pricefeeds_fix_rate_window.fixRateWindowPriceFeed,
25
+ require_permissionless_bindings_pricefeeds_redstone.redstonePriceFeed,
26
+ require_permissionless_bindings_pricefeeds_pyth.pythPriceFeed,
29
27
  require_permissionless_bindings_pricefeeds_erc4626.erc4626PriceFeed,
30
28
  require_permissionless_bindings_pricefeeds_curve_crypto.curveCryptoPriceFeed,
31
29
  require_permissionless_bindings_pricefeeds_curve_stable.curveStablePriceFeed,
@@ -34,10 +32,8 @@ const priceFeedSetupParams = [
34
32
  require_permissionless_bindings_pricefeeds_mellow_lrt.mellowLrtPriceFeed,
35
33
  require_permissionless_bindings_pricefeeds_pendle_pt_twap.pendlePtTwapPriceFeed,
36
34
  require_permissionless_bindings_pricefeeds_kodiak.kodiakPriceFeed,
37
- require_permissionless_bindings_pricefeeds_wsteth.wstethPriceFeed,
38
35
  require_permissionless_bindings_pricefeeds_balancer_stable.balancerStablePriceFeed,
39
36
  require_permissionless_bindings_pricefeeds_balancer_weighted.balancerWeightedPriceFeed,
40
- require_permissionless_bindings_pricefeeds_redstone.redstonePriceFeed,
41
- require_permissionless_bindings_pricefeeds_pyth.pythPriceFeed
37
+ require_permissionless_bindings_pricefeeds_wsteth.wstethPriceFeed
42
38
  ];
43
39
  exports.priceFeedSetupParams = priceFeedSetupParams;
@@ -1,4 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_utils_AddressMap = require("../../onchain/utils/AddressMap.js");
3
+ require("../../model/rwa.js");
4
+ require("../../model/index.js");
5
+ const require_onchain_market_rwa_securitize_SecuritizeRWAFactory = require("../../onchain/market/rwa/securitize/SecuritizeRWAFactory.js");
6
+ const require_onchain_market_rwa_types = require("../../onchain/market/rwa/types.js");
7
+ require("../../onchain/index.js");
8
+ let viem = require("viem");
2
9
  // src/sdk/execute/ExecuteApi.ts
3
10
  /**
4
11
  * {@inheritDoc IOpportunitiesExecute}
@@ -8,6 +15,40 @@ var ExecuteApi = class {
8
15
  constructor(chainOf) {
9
16
  this.#chainOf = chainOf;
10
17
  }
18
+ /** {@inheritDoc IOpportunitiesExecute.withSecuritizeSignatures} */
19
+ withSecuritizeSignatures({ tx, signatures }) {
20
+ const factory = this.#chainOf(tx.chainId).getContract(tx.to);
21
+ if (!(factory instanceof require_onchain_market_rwa_securitize_SecuritizeRWAFactory.SecuritizeRWAFactory) || !require_onchain_market_rwa_types.isRWAFactory(factory, "RWA_FACTORY::SECURITIZE")) throw new Error(`transaction target ${tx.to} is not a Securitize RWA factory`);
22
+ const decoded = (0, viem.decodeFunctionData)({
23
+ abi: factory.abi,
24
+ data: tx.calldata
25
+ });
26
+ if (decoded.functionName !== "openCreditAccount" && decoded.functionName !== "multicall") throw new Error(`expected openCreditAccount or multicall on SecuritizeRWAFactory ${tx.to}, got ${decoded.functionName}`);
27
+ const [target, calls, tokensToRegister, existing] = decoded.args;
28
+ const byToken = new require_onchain_utils_AddressMap.AddressMap();
29
+ for (const message of [...existing, ...signatures]) byToken.upsert(message.token, message);
30
+ const signaturesToCache = tokensToRegister.map((token) => byToken.get(token) ?? {
31
+ token,
32
+ signature: {
33
+ deadline: 0n,
34
+ signature: "0x"
35
+ }
36
+ });
37
+ const calldata = (0, viem.encodeFunctionData)({
38
+ abi: factory.abi,
39
+ functionName: decoded.functionName,
40
+ args: [
41
+ target,
42
+ calls,
43
+ tokensToRegister,
44
+ signaturesToCache
45
+ ]
46
+ });
47
+ return {
48
+ ...tx,
49
+ calldata
50
+ };
51
+ }
11
52
  /**
12
53
  * {@inheritDoc IOpportunitiesExecute.buildTx}
13
54
  **/
@@ -0,0 +1,178 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetStatusError = require("./errors/TestnetStatusError.js");
3
+ const require_testnets_errors_TestnetNotFoundError = require("./errors/TestnetNotFoundError.js");
4
+ const require_testnets_errors_TestnetRequestFailedError = require("./errors/TestnetRequestFailedError.js");
5
+ const require_testnets_errors_TestnetValidationError = require("./errors/TestnetValidationError.js");
6
+ const require_testnets_errors_TestnetWaitTimeoutError = require("./errors/TestnetWaitTimeoutError.js");
7
+ require("./errors/index.js");
8
+ const require_testnets_schemas = require("./schemas.js");
9
+ let zod_v4 = require("zod/v4");
10
+ // src/testnets/TestnetsAPI.ts
11
+ const DEFAULT_BASE_URL = "https://anvil.gearbox.foundation";
12
+ const DEFAULT_TIMEOUT = 3e4;
13
+ const DEFAULT_WAIT_TIMEOUT = 6e5;
14
+ const DEFAULT_WAIT_INTERVAL = 5e3;
15
+ const errorBodySchema = zod_v4.z.object({ error: zod_v4.z.string() });
16
+ /**
17
+ * Client for anvil-manager, which runs the anvil forks Gearbox calls
18
+ * testnets. It manages non-persistent testnets only, addressed by their
19
+ * execution id.
20
+ *
21
+ * ```ts
22
+ * const testnets = new TestnetsAPI({ apiKey: process.env.ANVIL_MANAGER_API_KEY });
23
+ * const { executionId } = await testnets.create({ network: "Mainnet", timeout: "2h" });
24
+ * const status = await testnets.waitUntilReady(executionId);
25
+ * // ... use status.rpcUrl ...
26
+ * await testnets.kill(executionId);
27
+ * ```
28
+ *
29
+ * Every method throws a {@link TestnetsError} subclass when it fails, except
30
+ * when a response body is not JSON: then it rejects with the error of
31
+ * `response.json()`.
32
+ **/
33
+ var TestnetsAPI = class {
34
+ logger;
35
+ #baseUrl;
36
+ #apiKey;
37
+ #timeout;
38
+ constructor(options = {}) {
39
+ this.#baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
40
+ this.#apiKey = options.apiKey;
41
+ this.#timeout = options.timeout ?? DEFAULT_TIMEOUT;
42
+ this.logger = options.logger?.child?.({ name: "TestnetsAPI" }) ?? options.logger;
43
+ }
44
+ /**
45
+ * Base URL every request of this client is sent to.
46
+ **/
47
+ get baseUrl() {
48
+ return this.#baseUrl;
49
+ }
50
+ /**
51
+ * Every testnet anvil-manager knows of, persistent ones included.
52
+ **/
53
+ async list() {
54
+ const url = this.#url("/api/v1/forks");
55
+ const response = await this.#fetch(url, { method: "GET" });
56
+ return this.#decode(url, response, zod_v4.z.array(require_testnets_schemas.testnetSchema));
57
+ }
58
+ /**
59
+ * Status of one testnet.
60
+ *
61
+ * @param id - Execution id of the testnet.
62
+ * @throws {@link TestnetNotFoundError} when there is no such testnet.
63
+ **/
64
+ async get(id) {
65
+ const url = this.#forkUrl(id);
66
+ const response = await this.#fetch(url, { method: "GET" });
67
+ return this.#decode(url, response, require_testnets_schemas.testnetStatusSchema);
68
+ }
69
+ /**
70
+ * Starts a testnet. It answers as soon as the testnet is created, long
71
+ * before it is {@link TestnetStatus.ready}.
72
+ *
73
+ * @param files - Saved in the testnet's shared dir, where scripts and tasks
74
+ * can read them.
75
+ **/
76
+ async create(request, files) {
77
+ const url = this.#url("/api/v1/forks");
78
+ const response = await this.#fetch(url, {
79
+ method: "POST",
80
+ ...createBody(request, files)
81
+ });
82
+ return this.#decode(url, response, require_testnets_schemas.testnetStatusSchema);
83
+ }
84
+ /**
85
+ * Stops a testnet. Stopping one that is already stopped succeeds.
86
+ *
87
+ * @param id - Execution id of the testnet.
88
+ * @throws {@link TestnetNotFoundError} when there is no such testnet.
89
+ * @throws {@link TestnetStatusError} with status 400 when the testnet is
90
+ * persistent.
91
+ **/
92
+ async kill(id) {
93
+ await this.#fetch(this.#forkUrl(id), { method: "DELETE" });
94
+ }
95
+ /**
96
+ * Polls a testnet's status until it is {@link TestnetStatus.ready}.
97
+ *
98
+ * @param id - Execution id of the testnet.
99
+ * @returns The first status that is ready.
100
+ * @throws {@link TestnetWaitTimeoutError} when the testnet is not ready in
101
+ * time. Any error of a poll is thrown as is, without retrying.
102
+ **/
103
+ async waitUntilReady(id, options = {}) {
104
+ const { timeout = DEFAULT_WAIT_TIMEOUT, interval = DEFAULT_WAIT_INTERVAL } = options;
105
+ const deadline = Date.now() + timeout;
106
+ while (true) {
107
+ const status = await this.get(id);
108
+ if (status.ready) return status;
109
+ const remaining = deadline - Date.now();
110
+ if (remaining <= 0) throw new require_testnets_errors_TestnetWaitTimeoutError.TestnetWaitTimeoutError(this.#forkUrl(id), id, timeout);
111
+ this.logger?.debug(`testnet ${id} is not ready yet`);
112
+ await new Promise((resolve) => setTimeout(resolve, Math.min(interval, remaining)));
113
+ }
114
+ }
115
+ #url(path) {
116
+ return `${this.#baseUrl}${path}`;
117
+ }
118
+ #forkUrl(id) {
119
+ return this.#url(`/api/v1/forks/${encodeURIComponent(id)}`);
120
+ }
121
+ /**
122
+ * Sends one request and returns its response once it is known to be 2xx.
123
+ **/
124
+ async #fetch(url, init) {
125
+ const headers = new Headers(init.headers);
126
+ headers.set("accept", "application/json");
127
+ if (this.#apiKey) headers.set("authorization", `Bearer ${this.#apiKey}`);
128
+ let response;
129
+ try {
130
+ response = await fetch(url, {
131
+ ...init,
132
+ headers,
133
+ signal: AbortSignal.timeout(this.#timeout)
134
+ });
135
+ } catch (error) {
136
+ throw new require_testnets_errors_TestnetRequestFailedError.TestnetRequestFailedError(url, error);
137
+ }
138
+ if (!response.ok) {
139
+ const responseBody = await response.text();
140
+ const details = errorBodySchema.safeParse(responseBody).data?.error;
141
+ throw response.status === 404 ? new require_testnets_errors_TestnetNotFoundError.TestnetNotFoundError(url, details) : new require_testnets_errors_TestnetStatusError.TestnetStatusError(url, response.status, details);
142
+ }
143
+ return response;
144
+ }
145
+ /**
146
+ * Body of a 2xx response, decoded.
147
+ **/
148
+ async #decode(url, response, schema) {
149
+ const payload = await response.json();
150
+ const parsed = schema.safeParse(payload);
151
+ if (!parsed.success) {
152
+ const error = new require_testnets_errors_TestnetValidationError.TestnetValidationError(url, parsed.error);
153
+ this.logger?.error(error, "anvil-manager response does not match the testnet schemas");
154
+ throw error;
155
+ }
156
+ return parsed.data;
157
+ }
158
+ };
159
+ /**
160
+ * Body and content type of a create request: JSON alone, or a multipart form
161
+ * with the JSON in its `json` field when there are files to upload.
162
+ **/
163
+ function createBody(request, files) {
164
+ const json = JSON.stringify(request);
165
+ if (!files || Object.keys(files).length === 0) return {
166
+ body: json,
167
+ headers: { "content-type": "application/json" }
168
+ };
169
+ const form = new FormData();
170
+ form.append("json", json);
171
+ for (const [name, contents] of Object.entries(files)) form.append("file", toBlob(contents), name);
172
+ return { body: form };
173
+ }
174
+ function toBlob(contents) {
175
+ if (contents instanceof Blob) return contents;
176
+ return new Blob([typeof contents === "string" ? contents : new Uint8Array(contents)]);
177
+ }
178
+ exports.TestnetsAPI = TestnetsAPI;
@@ -0,0 +1,14 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetStatusError = require("./TestnetStatusError.js");
3
+ // src/testnets/errors/TestnetNotFoundError.ts
4
+ /**
5
+ * Thrown when anvil-manager answered 404: there is no testnet with that
6
+ * execution id.
7
+ **/
8
+ var TestnetNotFoundError = class extends require_testnets_errors_TestnetStatusError.TestnetStatusError {
9
+ name = "TestnetNotFoundError";
10
+ constructor(url, details) {
11
+ super(url, 404, details);
12
+ }
13
+ };
14
+ exports.TestnetNotFoundError = TestnetNotFoundError;
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetsError = require("./TestnetsError.js");
3
+ // src/testnets/errors/TestnetRequestFailedError.ts
4
+ /**
5
+ * Thrown when a request to anvil-manager never completed: the network was
6
+ * down, or it took longer than the client's timeout.
7
+ **/
8
+ var TestnetRequestFailedError = class extends require_testnets_errors_TestnetsError.TestnetsError {
9
+ name = "TestnetRequestFailedError";
10
+ constructor(url, cause) {
11
+ super(timedOut(cause) ? "The request to anvil-manager timed out." : "The request to anvil-manager failed.", {
12
+ url,
13
+ cause
14
+ });
15
+ }
16
+ };
17
+ /**
18
+ * Whether a caught value is the rejection `AbortSignal.timeout` produces.
19
+ **/
20
+ function timedOut(error) {
21
+ return error instanceof Error && error.name === "TimeoutError";
22
+ }
23
+ exports.TestnetRequestFailedError = TestnetRequestFailedError;
@@ -0,0 +1,18 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetsError = require("./TestnetsError.js");
3
+ // src/testnets/errors/TestnetStatusError.ts
4
+ /**
5
+ * Thrown when anvil-manager answered with a status outside the 2xx range. What
6
+ * it said about it, when it said anything, is the `details` of the error.
7
+ **/
8
+ var TestnetStatusError = class extends require_testnets_errors_TestnetsError.TestnetsError {
9
+ name = "TestnetStatusError";
10
+ constructor(url, status, details) {
11
+ super(`anvil-manager answered ${status}.`, {
12
+ url,
13
+ status,
14
+ details
15
+ });
16
+ }
17
+ };
18
+ exports.TestnetStatusError = TestnetStatusError;
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetsError = require("./TestnetsError.js");
3
+ let zod_v4 = require("zod/v4");
4
+ // src/testnets/errors/TestnetValidationError.ts
5
+ /**
6
+ * Thrown when anvil-manager answered, but with a payload the testnet schemas
7
+ * do not describe, i.e. the two are of different versions.
8
+ **/
9
+ var TestnetValidationError = class extends require_testnets_errors_TestnetsError.TestnetsError {
10
+ name = "TestnetValidationError";
11
+ /**
12
+ * The zod failure itself, e.g. for `z.treeifyError(error.zodError)`.
13
+ **/
14
+ zodError;
15
+ constructor(url, zodError) {
16
+ super("The anvil-manager response does not match the testnet schemas.", {
17
+ url,
18
+ metaMessages: zod_v4.z.prettifyError(zodError).split("\n")
19
+ });
20
+ this.zodError = zodError;
21
+ }
22
+ };
23
+ exports.TestnetValidationError = TestnetValidationError;
@@ -0,0 +1,29 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetsError = require("./TestnetsError.js");
3
+ // src/testnets/errors/TestnetWaitTimeoutError.ts
4
+ /**
5
+ * Thrown when a testnet did not become ready before the wait for it ran out.
6
+ **/
7
+ var TestnetWaitTimeoutError = class extends require_testnets_errors_TestnetsError.TestnetsError {
8
+ name = "TestnetWaitTimeoutError";
9
+ /**
10
+ * Execution id of the testnet that was waited for.
11
+ **/
12
+ id;
13
+ /**
14
+ * How long the wait lasted, in milliseconds.
15
+ **/
16
+ timeout;
17
+ /**
18
+ * @param url - Status URL that was polled.
19
+ **/
20
+ constructor(url, id, timeout) {
21
+ super(`Testnet ${id} did not become ready within ${timeout} ms.`, {
22
+ url,
23
+ metaMessages: [`Execution id: ${id}`, `Timeout: ${timeout} ms`]
24
+ });
25
+ this.id = id;
26
+ this.timeout = timeout;
27
+ }
28
+ };
29
+ exports.TestnetWaitTimeoutError = TestnetWaitTimeoutError;
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let viem = require("viem");
3
+ // src/testnets/errors/TestnetsError.ts
4
+ /**
5
+ * Thrown by every testnet API call that fails. Its subclasses say how it
6
+ * failed; catch this one to catch all of them.
7
+ **/
8
+ var TestnetsError = class extends viem.BaseError {
9
+ /**
10
+ * URL that was requested.
11
+ **/
12
+ url;
13
+ /**
14
+ * Status anvil-manager answered with, absent when the request never
15
+ * completed.
16
+ **/
17
+ status;
18
+ constructor(summary, params) {
19
+ const { cause, details } = params;
20
+ super(summary, {
21
+ cause: cause instanceof Error ? cause : void 0,
22
+ details: cause === void 0 || cause instanceof Error ? details : String(cause),
23
+ metaMessages: [
24
+ `URL: ${params.url}`,
25
+ ...params.status === void 0 ? [] : [`Status: ${params.status}`],
26
+ ...params.metaMessages ?? []
27
+ ]
28
+ });
29
+ this.url = params.url;
30
+ this.status = params.status;
31
+ }
32
+ };
33
+ exports.TestnetsError = TestnetsError;
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetNotFoundError = require("./TestnetNotFoundError.js");
3
+ const require_testnets_errors_TestnetRequestFailedError = require("./TestnetRequestFailedError.js");
4
+ const require_testnets_errors_TestnetStatusError = require("./TestnetStatusError.js");
5
+ const require_testnets_errors_TestnetsError = require("./TestnetsError.js");
6
+ const require_testnets_errors_TestnetValidationError = require("./TestnetValidationError.js");
7
+ const require_testnets_errors_TestnetWaitTimeoutError = require("./TestnetWaitTimeoutError.js");
8
+ exports.TestnetNotFoundError = require_testnets_errors_TestnetNotFoundError.TestnetNotFoundError;
9
+ exports.TestnetRequestFailedError = require_testnets_errors_TestnetRequestFailedError.TestnetRequestFailedError;
10
+ exports.TestnetStatusError = require_testnets_errors_TestnetStatusError.TestnetStatusError;
11
+ exports.TestnetValidationError = require_testnets_errors_TestnetValidationError.TestnetValidationError;
12
+ exports.TestnetWaitTimeoutError = require_testnets_errors_TestnetWaitTimeoutError.TestnetWaitTimeoutError;
13
+ exports.TestnetsError = require_testnets_errors_TestnetsError.TestnetsError;
@@ -0,0 +1,32 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_testnets_errors_TestnetsError = require("./errors/TestnetsError.js");
3
+ const require_testnets_errors_TestnetStatusError = require("./errors/TestnetStatusError.js");
4
+ const require_testnets_errors_TestnetNotFoundError = require("./errors/TestnetNotFoundError.js");
5
+ const require_testnets_errors_TestnetRequestFailedError = require("./errors/TestnetRequestFailedError.js");
6
+ const require_testnets_errors_TestnetValidationError = require("./errors/TestnetValidationError.js");
7
+ const require_testnets_errors_TestnetWaitTimeoutError = require("./errors/TestnetWaitTimeoutError.js");
8
+ require("./errors/index.js");
9
+ const require_testnets_schemas = require("./schemas.js");
10
+ const require_testnets_TestnetsAPI = require("./TestnetsAPI.js");
11
+ require("./types.js");
12
+ exports.TestnetNotFoundError = require_testnets_errors_TestnetNotFoundError.TestnetNotFoundError;
13
+ exports.TestnetRequestFailedError = require_testnets_errors_TestnetRequestFailedError.TestnetRequestFailedError;
14
+ exports.TestnetStatusError = require_testnets_errors_TestnetStatusError.TestnetStatusError;
15
+ exports.TestnetValidationError = require_testnets_errors_TestnetValidationError.TestnetValidationError;
16
+ exports.TestnetWaitTimeoutError = require_testnets_errors_TestnetWaitTimeoutError.TestnetWaitTimeoutError;
17
+ exports.TestnetsAPI = require_testnets_TestnetsAPI.TestnetsAPI;
18
+ exports.TestnetsError = require_testnets_errors_TestnetsError.TestnetsError;
19
+ exports.testnetBackendOptionsSchema = require_testnets_schemas.testnetBackendOptionsSchema;
20
+ exports.testnetBackendStateSchema = require_testnets_schemas.testnetBackendStateSchema;
21
+ exports.testnetBackendStatusSchema = require_testnets_schemas.testnetBackendStatusSchema;
22
+ exports.testnetBlockSchema = require_testnets_schemas.testnetBlockSchema;
23
+ exports.testnetOptionsSchema = require_testnets_schemas.testnetOptionsSchema;
24
+ exports.testnetSchema = require_testnets_schemas.testnetSchema;
25
+ exports.testnetScriptBlockSchema = require_testnets_schemas.testnetScriptBlockSchema;
26
+ exports.testnetScriptOptionsSchema = require_testnets_schemas.testnetScriptOptionsSchema;
27
+ exports.testnetScriptSchema = require_testnets_schemas.testnetScriptSchema;
28
+ exports.testnetStageStatusSchema = require_testnets_schemas.testnetStageStatusSchema;
29
+ exports.testnetStatusSchema = require_testnets_schemas.testnetStatusSchema;
30
+ exports.testnetTaskDefinitionSchema = require_testnets_schemas.testnetTaskDefinitionSchema;
31
+ exports.testnetTaskProgressSchema = require_testnets_schemas.testnetTaskProgressSchema;
32
+ exports.testnetTaskSchema = require_testnets_schemas.testnetTaskSchema;
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}