@gearbox-protocol/sdk 17.10.1 → 17.11.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 (112) hide show
  1. package/dist/cjs/offchain/AbstractOffchainNamespace.js +31 -8
  2. package/dist/cjs/permissionless/api/GearboxPermissionless.js +79 -0
  3. package/dist/cjs/permissionless/api/chains/ChainsNamespace.js +180 -0
  4. package/dist/cjs/permissionless/api/chains/index.js +4 -0
  5. package/dist/cjs/permissionless/api/chains/schemas.js +34 -0
  6. package/dist/cjs/permissionless/api/chains/types.js +1 -0
  7. package/dist/cjs/permissionless/api/deploy/PermissionlessDeploy.js +152 -0
  8. package/dist/cjs/permissionless/api/deploy/effective-staleness.js +46 -0
  9. package/dist/cjs/permissionless/api/deploy/index.js +8 -0
  10. package/dist/cjs/permissionless/api/deploy/types.js +1 -0
  11. package/dist/cjs/permissionless/api/errors.js +82 -0
  12. package/dist/cjs/permissionless/api/index.js +28 -0
  13. package/dist/cjs/permissionless/api/oracles/PermissionlessOracles.js +84 -0
  14. package/dist/cjs/permissionless/api/oracles/index.js +6 -0
  15. package/dist/cjs/permissionless/api/oracles/schemas.js +64 -0
  16. package/dist/cjs/permissionless/api/oracles/types.js +1 -0
  17. package/dist/cjs/permissionless/api/schemas.js +28 -0
  18. package/dist/cjs/permissionless/api/transactions/InstanceOwnerTransactions.js +230 -0
  19. package/dist/cjs/permissionless/api/transactions/index.js +4 -0
  20. package/dist/cjs/permissionless/api/transactions/lp-price-feeds.js +86 -0
  21. package/dist/cjs/permissionless/api/transactions/types.js +1 -0
  22. package/dist/cjs/permissionless/api/types.js +1 -0
  23. package/dist/cjs/permissionless/bindings/cross-chain-multisig.js +1 -1
  24. package/dist/cjs/permissionless/bindings/index.js +3 -3
  25. package/dist/cjs/permissionless/bindings/instance-manager.js +3 -3
  26. package/dist/cjs/permissionless/index.js +31 -8
  27. package/dist/cjs/permissionless/utils/governance/timelock-txs.js +1 -1
  28. package/dist/cjs/permissionless/utils/index.js +4 -4
  29. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  30. package/dist/cjs/permissionless/utils/price-update/index.js +1 -1
  31. package/dist/esm/dev/AccountOpener.js +1 -1
  32. package/dist/esm/dev/withdrawalUtils.js +1 -1
  33. package/dist/esm/history/trace/extractTransfers.js +1 -1
  34. package/dist/esm/offchain/AbstractOffchainNamespace.js +31 -8
  35. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  36. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  37. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  38. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  39. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  40. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  41. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  42. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  43. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  44. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  45. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  46. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  47. package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
  48. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  49. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  50. package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +2 -2
  51. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  52. package/dist/esm/permissionless/api/GearboxPermissionless.js +78 -0
  53. package/dist/esm/permissionless/api/chains/ChainsNamespace.js +179 -0
  54. package/dist/esm/permissionless/api/chains/index.js +3 -0
  55. package/dist/esm/permissionless/api/chains/schemas.js +30 -0
  56. package/dist/esm/permissionless/api/chains/types.js +1 -0
  57. package/dist/esm/permissionless/api/deploy/PermissionlessDeploy.js +149 -0
  58. package/dist/esm/permissionless/api/deploy/effective-staleness.js +46 -0
  59. package/dist/esm/permissionless/api/deploy/index.js +4 -0
  60. package/dist/esm/permissionless/api/deploy/types.js +1 -0
  61. package/dist/esm/permissionless/api/errors.js +77 -0
  62. package/dist/esm/permissionless/api/index.js +13 -0
  63. package/dist/esm/permissionless/api/oracles/PermissionlessOracles.js +81 -0
  64. package/dist/esm/permissionless/api/oracles/index.js +3 -0
  65. package/dist/esm/permissionless/api/oracles/schemas.js +59 -0
  66. package/dist/esm/permissionless/api/oracles/types.js +1 -0
  67. package/dist/esm/permissionless/api/schemas.js +25 -0
  68. package/dist/esm/permissionless/api/transactions/InstanceOwnerTransactions.js +229 -0
  69. package/dist/esm/permissionless/api/transactions/index.js +3 -0
  70. package/dist/esm/permissionless/api/transactions/lp-price-feeds.js +84 -0
  71. package/dist/esm/permissionless/api/transactions/types.js +1 -0
  72. package/dist/esm/permissionless/api/types.js +1 -0
  73. package/dist/esm/permissionless/bindings/cross-chain-multisig.js +1 -1
  74. package/dist/esm/permissionless/bindings/index.js +3 -3
  75. package/dist/esm/permissionless/bindings/instance-manager.js +3 -3
  76. package/dist/esm/permissionless/index.js +17 -9
  77. package/dist/esm/permissionless/utils/governance/timelock-txs.js +1 -1
  78. package/dist/esm/permissionless/utils/index.js +4 -4
  79. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  80. package/dist/esm/permissionless/utils/price-update/index.js +1 -1
  81. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +12 -0
  82. package/dist/types/permissionless/api/GearboxPermissionless.d.ts +71 -0
  83. package/dist/types/permissionless/api/chains/ChainsNamespace.d.ts +99 -0
  84. package/dist/types/permissionless/api/chains/index.d.ts +3 -0
  85. package/dist/types/permissionless/api/chains/schemas.d.ts +49 -0
  86. package/dist/types/permissionless/api/chains/types.d.ts +58 -0
  87. package/dist/types/permissionless/api/deploy/PermissionlessDeploy.d.ts +69 -0
  88. package/dist/types/permissionless/api/deploy/effective-staleness.d.ts +19 -0
  89. package/dist/types/permissionless/api/deploy/index.d.ts +4 -0
  90. package/dist/types/permissionless/api/deploy/types.d.ts +87 -0
  91. package/dist/types/permissionless/api/errors.d.ts +63 -0
  92. package/dist/types/permissionless/api/index.d.ts +17 -0
  93. package/dist/types/permissionless/api/oracles/PermissionlessOracles.d.ts +64 -0
  94. package/dist/types/permissionless/api/oracles/index.d.ts +3 -0
  95. package/dist/types/permissionless/api/oracles/schemas.d.ts +103 -0
  96. package/dist/types/permissionless/api/oracles/types.d.ts +63 -0
  97. package/dist/types/permissionless/api/schemas.d.ts +22 -0
  98. package/dist/types/permissionless/api/transactions/InstanceOwnerTransactions.d.ts +60 -0
  99. package/dist/types/permissionless/api/transactions/index.d.ts +3 -0
  100. package/dist/types/permissionless/api/transactions/lp-price-feeds.d.ts +17 -0
  101. package/dist/types/permissionless/api/transactions/types.d.ts +36 -0
  102. package/dist/types/permissionless/api/types.d.ts +12 -0
  103. package/dist/types/permissionless/bindings/factory/credit-factory.d.ts +1 -1
  104. package/dist/types/permissionless/bindings/factory/loss-policy-factory.d.ts +1 -1
  105. package/dist/types/permissionless/bindings/factory/pool-factory.d.ts +1 -1
  106. package/dist/types/permissionless/bindings/factory/price-oracle-factory.d.ts +1 -1
  107. package/dist/types/permissionless/bindings/index.d.ts +1 -1
  108. package/dist/types/permissionless/core/index.d.ts +1 -1
  109. package/dist/types/permissionless/index.d.ts +23 -10
  110. package/dist/types/permissionless/utils/governance/index.d.ts +1 -1
  111. package/dist/types/permissionless/utils/index.d.ts +1 -1
  112. package/package.json +1 -1
@@ -48,14 +48,7 @@ var AbstractOffchainNamespace = class {
48
48
  **/
49
49
  async get(request) {
50
50
  const url = this.#url(request.path, request.query);
51
- const payload = await this.#fetchJson(url);
52
- const parsed = require_model_response_schema.responseSchema(request.schema).safeParse(payload);
53
- if (!parsed.success) {
54
- const error = new require_offchain_errors_OffchainValidationError.OffchainValidationError(url, parsed.error);
55
- this.logger?.error(error, "offchain response does not match the read model");
56
- throw error;
57
- }
58
- const { data, meta } = parsed.data;
51
+ const { data, meta } = await this.#read(url, require_model_response_schema.responseSchema(request.schema));
59
52
  return {
60
53
  data,
61
54
  meta: { chains: meta.chains.map((chain) => ({
@@ -65,6 +58,36 @@ var AbstractOffchainNamespace = class {
65
58
  };
66
59
  }
67
60
  /**
61
+ * Reads one endpoint that answers with the payload alone, and returns it
62
+ * unwrapped.
63
+ *
64
+ * A read served at no particular block has no envelope to report: the
65
+ * permissionless routes either span every chain at once, or fall through to
66
+ * a multicall on the chain itself, so the backend answers `{ data }` and
67
+ * there is no {@link ResponseMetadata} for {@link get} to decode. The
68
+ * envelope is still there, which is what keeps a payload that happens to be
69
+ * an array from being mistaken for an error body.
70
+ **/
71
+ async getData(request) {
72
+ const url = this.#url(request.path, request.query);
73
+ const { data } = await this.#read(url, zod_v4.z.object({ data: request.schema }));
74
+ return data;
75
+ }
76
+ /**
77
+ * Body of a successful read, decoded. Schema skew is reported against the
78
+ * url that produced it, which is the only thing that says which read drifted.
79
+ **/
80
+ async #read(url, schema) {
81
+ const payload = await this.#fetchJson(url);
82
+ const parsed = schema.safeParse(payload);
83
+ if (!parsed.success) {
84
+ const error = new require_offchain_errors_OffchainValidationError.OffchainValidationError(url, parsed.error);
85
+ this.logger?.error(error, "offchain response does not match the read model");
86
+ throw error;
87
+ }
88
+ return parsed.data;
89
+ }
90
+ /**
68
91
  * Reads the charts of one subject: one series per metric named, onto the one
69
92
  * grid that lets them be compared at an index.
70
93
  **/
@@ -0,0 +1,79 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_permissionless_api_chains_ChainsNamespace = require("./chains/ChainsNamespace.js");
3
+ const require_permissionless_api_deploy_PermissionlessDeploy = require("./deploy/PermissionlessDeploy.js");
4
+ const require_permissionless_api_oracles_PermissionlessOracles = require("./oracles/PermissionlessOracles.js");
5
+ const require_permissionless_api_transactions_InstanceOwnerTransactions = require("./transactions/InstanceOwnerTransactions.js");
6
+ //#region src/permissionless/api/GearboxPermissionless.ts
7
+ /**
8
+ * Client for the permissionless stack: the oracle rows of a chain, the
9
+ * batches an instance owner executes, and the deploys that produce what goes
10
+ * into both.
11
+ *
12
+ * It reads the same backend {@link GearboxAPI} does, and reads the same way —
13
+ * one namespace per subject, every call scoped by the chain it names. Which
14
+ * chains those are is not passed in: {@link attach} reads the list off the
15
+ * backend and builds a client for each, so this client covers exactly what
16
+ * the backend serves.
17
+ *
18
+ * ```ts
19
+ * const permissionless = new GearboxPermissionless({
20
+ * baseUrl: "https://api.gearbox.fi",
21
+ * });
22
+ * await permissionless.attach();
23
+ *
24
+ * const [chain] = permissionless.chains.list();
25
+ * const store = await permissionless.oracles.store({ chainId: chain.chainId });
26
+ * ```
27
+ *
28
+ * Only what needs a server goes to one. {@link chains} and {@link oracles}
29
+ * are the backend's reads; {@link deploy} and {@link transactions} read the
30
+ * target chain directly, because everything they answer is derived from there
31
+ * and a round trip would only move the derivation further from the wallet
32
+ * that has to sign for it.
33
+ **/
34
+ var GearboxPermissionless = class {
35
+ /**
36
+ * Namespace for the chains the stack runs on, and the viem clients that
37
+ * reach them.
38
+ **/
39
+ chains;
40
+ /**
41
+ * Namespace for price feeds: the store and its prices.
42
+ **/
43
+ oracles;
44
+ /**
45
+ * Namespace for the Safe batches an instance owner executes. Backend-free,
46
+ * see {@link InstanceOwnerTransactions}.
47
+ **/
48
+ transactions;
49
+ /**
50
+ * Namespace for deploys through the BytecodeRepository. Backend-free, see
51
+ * {@link PermissionlessDeploy}.
52
+ **/
53
+ deploy;
54
+ constructor(options = {}) {
55
+ this.chains = new require_permissionless_api_chains_ChainsNamespace.ChainsNamespace(options);
56
+ this.oracles = new require_permissionless_api_oracles_PermissionlessOracles.PermissionlessOracles(options, this.chains);
57
+ this.transactions = new require_permissionless_api_transactions_InstanceOwnerTransactions.InstanceOwnerTransactions(this.chains, this.oracles);
58
+ this.deploy = new require_permissionless_api_deploy_PermissionlessDeploy.PermissionlessDeploy(this.chains);
59
+ }
60
+ /**
61
+ * Loads the chain list and builds the clients, see
62
+ * {@link ChainsNamespace.attach}. Idempotent, and joins a call already in
63
+ * flight.
64
+ *
65
+ * Everything that reads a chain goes through it, so this has to finish
66
+ * before the first such call.
67
+ **/
68
+ async attach(args = {}) {
69
+ return this.chains.attach(args);
70
+ }
71
+ /**
72
+ * Whether {@link attach} has completed.
73
+ **/
74
+ get isAttached() {
75
+ return this.chains.isAttached;
76
+ }
77
+ };
78
+ //#endregion
79
+ exports.GearboxPermissionless = GearboxPermissionless;
@@ -0,0 +1,180 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_chain_chains = require("../../../onchain/chain/chains.js");
3
+ const require_offchain_AbstractOffchainNamespace = require("../../../offchain/AbstractOffchainNamespace.js");
4
+ const require_permissionless_api_errors = require("../errors.js");
5
+ const require_permissionless_api_chains_schemas = require("./schemas.js");
6
+ let viem = require("viem");
7
+ //#region src/permissionless/api/chains/ChainsNamespace.ts
8
+ /**
9
+ * The chains the permissionless stack runs on, and the viem clients that
10
+ * reach them.
11
+ *
12
+ * Both halves live here because they answer the same question. Which chains
13
+ * exist is the backend's to decide — it holds rows for chains it does not
14
+ * serve, and those must not be reachable — so the list is also the only
15
+ * honest basis for deciding which clients to build. Nothing is passed in: a
16
+ * caller that had to name the chains could name one the backend does not
17
+ * serve, or miss one it does.
18
+ *
19
+ * The list is fetched once, by {@link attach}, and kept for the client's
20
+ * lifetime:
21
+ *
22
+ * ```ts
23
+ * await permissionless.attach();
24
+ * const chains = permissionless.chains.list();
25
+ * ```
26
+ *
27
+ * Every read before that throws {@link PermissionlessNotAttachedError} rather
28
+ * than answering with an empty list, which would be indistinguishable from a
29
+ * backend that serves nothing.
30
+ *
31
+ * What {@link attach} reads is only what identifies a chain. The counters a
32
+ * list renders next to one are {@link summary}, a second read, because they
33
+ * aggregate over every market the backend knows and nothing should wait on
34
+ * that to start.
35
+ **/
36
+ var ChainsNamespace = class extends require_offchain_AbstractOffchainNamespace.AbstractOffchainNamespace {
37
+ #clients = /* @__PURE__ */ new Map();
38
+ #chains;
39
+ #attaching;
40
+ /** The scope {@link attach} settled on, which {@link summary} follows. */
41
+ #scope;
42
+ constructor(options) {
43
+ super("ChainsNamespace", {
44
+ ...options,
45
+ chainIds: []
46
+ });
47
+ }
48
+ /**
49
+ * Reads the chain list off the backend and builds a client for each chain
50
+ * it names.
51
+ *
52
+ * Idempotent, and joins a call already in flight, so a double invocation —
53
+ * React's StrictMode, two components mounting at once — costs one request.
54
+ * A second call with a different `scope` is a no-op: the list is decided
55
+ * once.
56
+ **/
57
+ async attach({ scope } = {}) {
58
+ if (this.#chains) return;
59
+ this.#attaching ??= this.#load(scope).finally(() => {
60
+ this.#attaching = void 0;
61
+ });
62
+ return this.#attaching;
63
+ }
64
+ /**
65
+ * Whether {@link attach} has completed.
66
+ **/
67
+ get isAttached() {
68
+ return this.#chains !== void 0;
69
+ }
70
+ /**
71
+ * Every chain the backend serves, in the order it listed them.
72
+ **/
73
+ list() {
74
+ if (!this.#chains) throw new require_permissionless_api_errors.PermissionlessNotAttachedError();
75
+ return this.#chains;
76
+ }
77
+ /**
78
+ * One chain by id, or nothing when the backend does not serve it.
79
+ *
80
+ * Reads the attached list rather than a route of its own, which is also
81
+ * what makes "not served" and "not activated" distinguishable: the first is
82
+ * absence here, the second is {@link PermissionlessChain.isActivated}.
83
+ **/
84
+ find(chainId) {
85
+ return this.list().find((chain) => chain.chainId === chainId);
86
+ }
87
+ /**
88
+ * The same chains, with the counters a list renders next to them.
89
+ *
90
+ * A read of its own, and not part of {@link attach}: the counters aggregate
91
+ * over every market configurator and market the backend knows, which is
92
+ * slow enough that waiting on it would hold up the whole client. A list
93
+ * renders off {@link list} and fills the numbers in when this resolves.
94
+ *
95
+ * Nothing is cached — each call is a request — so a caller that renders
96
+ * this should hold it in whatever already owns its async state.
97
+ *
98
+ * Covers the scope {@link attach} settled on unless one is named here, so
99
+ * the counters describe the list that is already on screen rather than a
100
+ * different set of chains.
101
+ *
102
+ * ```ts
103
+ * await permissionless.attach();
104
+ * const chains = permissionless.chains.list();
105
+ * const withCounters = await permissionless.chains.summary();
106
+ * ```
107
+ **/
108
+ async summary({ scope } = {}) {
109
+ return this.getData({
110
+ path: "/chain/summary",
111
+ query: { scope: scope ?? this.#scope },
112
+ schema: require_permissionless_api_chains_schemas.chainSummaryListSchema
113
+ });
114
+ }
115
+ /**
116
+ * Chains a client could be built for. A subset of {@link list} — see
117
+ * {@link client}.
118
+ **/
119
+ get chainIds() {
120
+ if (!this.#chains) throw new require_permissionless_api_errors.PermissionlessNotAttachedError();
121
+ return [...this.#clients.keys()];
122
+ }
123
+ /**
124
+ * The client for one chain.
125
+ *
126
+ * @throws {@link PermissionlessChainUnreachableError} when the backend does
127
+ * not serve the chain, or serves one this SDK carries no definition for.
128
+ **/
129
+ client(chainId) {
130
+ if (!this.#chains) throw new require_permissionless_api_errors.PermissionlessNotAttachedError();
131
+ const client = this.#clients.get(chainId);
132
+ if (!client) throw new require_permissionless_api_errors.PermissionlessChainUnreachableError(chainId);
133
+ return client;
134
+ }
135
+ async #load(scope) {
136
+ const chains = await this.getData({
137
+ path: "/chain/list",
138
+ query: { scope },
139
+ schema: require_permissionless_api_chains_schemas.chainListSchema
140
+ });
141
+ this.#scope = scope;
142
+ this.#clients.clear();
143
+ for (const { chainId } of chains) {
144
+ const client = this.#client(chainId);
145
+ if (client) this.#clients.set(chainId, client);
146
+ }
147
+ this.#chains = chains;
148
+ }
149
+ /**
150
+ * A client over the chain's own public endpoints, or nothing when this SDK
151
+ * has no definition for it.
152
+ *
153
+ * The backend will not hand over its endpoints — they carry provider keys —
154
+ * so the chain definition is all there is to go on. A chain the SDK does
155
+ * not know stays in {@link list}, because the backend serves it and its
156
+ * rows are readable through the backend; only the calls that have to reach
157
+ * it directly fail, and they say which chain they could not reach.
158
+ **/
159
+ #client(chainId) {
160
+ let chain;
161
+ try {
162
+ chain = require_onchain_chain_chains.getChain(chainId);
163
+ } catch {
164
+ this.logger?.warn(`no chain definition for ${chainId}: it will be listed, but nothing can be read off it directly`);
165
+ return;
166
+ }
167
+ const urls = chain.rpcUrls.default.http;
168
+ if (urls.length === 0) {
169
+ this.logger?.warn(`no public endpoint for chain ${chainId}`);
170
+ return;
171
+ }
172
+ const transports = urls.map((url) => (0, viem.http)(url));
173
+ return (0, viem.createPublicClient)({
174
+ chain,
175
+ transport: transports.length > 1 ? (0, viem.fallback)(transports) : transports[0]
176
+ });
177
+ }
178
+ };
179
+ //#endregion
180
+ exports.ChainsNamespace = ChainsNamespace;
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_permissionless_api_chains_ChainsNamespace = require("./ChainsNamespace.js");
3
+ require("./types.js");
4
+ exports.ChainsNamespace = require_permissionless_api_chains_ChainsNamespace.ChainsNamespace;
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let zod_v4 = require("zod/v4");
3
+ //#region src/permissionless/api/chains/schemas.ts
4
+ /**
5
+ * Runtime schema for {@link PermissionlessChain}.
6
+ **/
7
+ const chainSchema = zod_v4.z.looseObject({
8
+ chainId: zod_v4.z.number(),
9
+ name: zod_v4.z.string(),
10
+ isPublic: zod_v4.z.boolean(),
11
+ isActivated: zod_v4.z.boolean(),
12
+ explorerUrl: zod_v4.z.string()
13
+ });
14
+ /** What `GET /chain/list` answers with. */
15
+ const chainListSchema = zod_v4.z.array(chainSchema);
16
+ /**
17
+ * Runtime schema for {@link PermissionlessChainSummary}.
18
+ *
19
+ * Strict about the two counters on purpose: they are the only reason this
20
+ * read exists, and a backend that answered without them would render as
21
+ * dashes where the numbers belong — a skew worth failing on rather than
22
+ * displaying.
23
+ **/
24
+ const chainSummarySchema = chainSchema.extend({
25
+ riskCuratorsQty: zod_v4.z.number(),
26
+ marketsQty: zod_v4.z.number()
27
+ });
28
+ /** What `GET /chain/summary` answers with. */
29
+ const chainSummaryListSchema = zod_v4.z.array(chainSummarySchema);
30
+ //#endregion
31
+ exports.chainListSchema = chainListSchema;
32
+ exports.chainSchema = chainSchema;
33
+ exports.chainSummaryListSchema = chainSummaryListSchema;
34
+ exports.chainSummarySchema = chainSummarySchema;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -0,0 +1,152 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_permissionless_api_errors = require("../errors.js");
3
+ const require_permissionless_api_deploy_effective_staleness = require("./effective-staleness.js");
4
+ const require_permissionless_bindings_bytecode_repository = require("../../bindings/bytecode-repository.js");
5
+ const require_permissionless_bindings_price_feed_store = require("../../bindings/price-feed-store.js");
6
+ require("../../deployment/addresses.js");
7
+ const require_permissionless_utils_abi_encoder = require("../../utils/abi-encoder.js");
8
+ let viem = require("viem");
9
+ //#region src/permissionless/api/deploy/PermissionlessDeploy.ts
10
+ /**
11
+ * Contract type whose first leg needs a bound this client reads off the chain,
12
+ * see {@link PermissionlessDeploy.priceFeed}.
13
+ **/
14
+ const COMPOSITE = "PRICE_FEED::COMPOSITE";
15
+ /** Label the composite's first leg arrives under. */
16
+ const COMPOSITE_FIRST_LEG = "underlyingPriceFeed-0";
17
+ /**
18
+ * Salt a generic contract deploy gets when the caller does not name one. Two
19
+ * deploys of the same type and arguments by the same owner collide under it,
20
+ * which for a singleton like a pause committee is the point.
21
+ **/
22
+ const DEFAULT_DEPLOY_SALT = (0, viem.stringToHex)("SALT", { size: 32 });
23
+ /**
24
+ * The salt a price feed is deployed under, derived from its name so that two
25
+ * feeds of the same type and arguments get different addresses.
26
+ **/
27
+ function priceFeedSalt(name) {
28
+ return (0, viem.keccak256)((0, viem.toHex)(name));
29
+ }
30
+ /**
31
+ * Deploys through the BytecodeRepository: the constructor arguments it wants,
32
+ * the CREATE2 address those produce, and the transaction that gets there.
33
+ *
34
+ * Entirely on-chain — no backend is involved, every answer is derived from the
35
+ * target chain. Nothing is sent either: a browser holds the only wallet, so a
36
+ * call prepares the deploy and the caller sends
37
+ * {@link PreparedDeployment.tx} with whatever signs for them.
38
+ *
39
+ * ```ts
40
+ * const feed = await permissionless.deploy.priceFeed({
41
+ * chainId: 1,
42
+ * owner: account,
43
+ * contractType: "PRICE_FEED::CHAINLINK",
44
+ * version: 310,
45
+ * name: "WETH / USD",
46
+ * values,
47
+ * });
48
+ * if (!feed.isAlreadyDeployed) {
49
+ * await sendRawTx(wallet, { tx: feed.tx });
50
+ * }
51
+ * ```
52
+ **/
53
+ var PermissionlessDeploy = class {
54
+ #chains;
55
+ constructor(chains) {
56
+ this.#chains = chains;
57
+ }
58
+ /**
59
+ * Prepares a price feed deploy from the values a form collected: encodes
60
+ * them the way the PriceFeedStore reads them back, and reports where the
61
+ * feed will land.
62
+ *
63
+ * A COMPOSITE's first leg is the one case where the values are not taken as
64
+ * given. It arrives with `stalenessPeriod` 0 whenever it is a derived feed,
65
+ * because the store registers those with 0 and rejects anything else — which
66
+ * says nothing about what the leg itself enforces. A composite built on that
67
+ * 0 can never pass its own staleness check, so the real bound is read off
68
+ * the leg, see {@link deriveEffectiveStalenessPeriod}.
69
+ *
70
+ * The deployed feed reaches {@link PermissionlessOracles.store} only once
71
+ * it is in the PriceFeedStore, which is a batch the instance owner
72
+ * executes, see {@link InstanceOwnerTransactions.addFeeds}.
73
+ **/
74
+ async priceFeed(args) {
75
+ const client = this.#chains.client(args.chainId);
76
+ const salt = this.#priceFeedSalt(args);
77
+ const values = args.contractType === COMPOSITE ? await this.#withDerivedStaleness(client, args.values) : args.values;
78
+ const encodedParams = await new require_permissionless_bindings_price_feed_store.PriceFeedStoreContract("0x74A868AC479EE145029bB80827BB77F7B7c441cB", client).encodeConstructorParams(args.contractType, args.version, values);
79
+ return {
80
+ ...await this.#prepare(client, {
81
+ contractType: args.contractType,
82
+ version: args.version,
83
+ owner: args.owner,
84
+ encodedParams,
85
+ salt
86
+ }),
87
+ values
88
+ };
89
+ }
90
+ /**
91
+ * Prepares a generic contract deploy from ABI type/value pairs.
92
+ *
93
+ * Unlike a price feed, the arguments here are already typed by the caller,
94
+ * so nothing is looked up: they are encoded as given and the address they
95
+ * produce is reported.
96
+ **/
97
+ async contract(args) {
98
+ const client = this.#chains.client(args.chainId);
99
+ return this.#prepare(client, {
100
+ contractType: args.contractType,
101
+ version: args.version,
102
+ owner: args.owner,
103
+ encodedParams: require_permissionless_utils_abi_encoder.encodeFunctionParams(args.values),
104
+ salt: args.salt ?? DEFAULT_DEPLOY_SALT
105
+ });
106
+ }
107
+ /**
108
+ * Where the encoded deploy lands, whether it is already there, and the
109
+ * transaction that puts it there.
110
+ **/
111
+ async #prepare(client, args) {
112
+ const repository = new require_permissionless_bindings_bytecode_repository.BytecodeRepositoryContract("0x1cE2B1BE96a082b1b1539F80d5D8f82Ec06a0f9A", client);
113
+ const [isAlreadyDeployed, address] = await repository.isAlreadyDeployedAddress(args);
114
+ return {
115
+ ...args,
116
+ address,
117
+ isAlreadyDeployed,
118
+ tx: repository.deployTx({
119
+ contractType: args.contractType,
120
+ version: BigInt(args.version),
121
+ encodedParams: args.encodedParams,
122
+ salt: args.salt
123
+ })
124
+ };
125
+ }
126
+ /**
127
+ * The values with the composite's first leg given the bound it actually
128
+ * enforces, when it came in without one.
129
+ **/
130
+ async #withDerivedStaleness(client, values) {
131
+ const leg = values[COMPOSITE_FIRST_LEG];
132
+ if (!leg || typeof leg !== "object" || !leg.address || leg.stalenessPeriod !== 0) return values;
133
+ const derived = await require_permissionless_api_deploy_effective_staleness.deriveEffectiveStalenessPeriod(client, leg.address);
134
+ if (derived === null) throw new require_permissionless_api_errors.PriceFeedStalenessUnknownError(leg.address);
135
+ return {
136
+ ...values,
137
+ [COMPOSITE_FIRST_LEG]: {
138
+ ...leg,
139
+ stalenessPeriod: derived
140
+ }
141
+ };
142
+ }
143
+ #priceFeedSalt(args) {
144
+ if (args.salt) return args.salt;
145
+ if (!args.name) throw new require_permissionless_api_errors.PriceFeedSaltMissingError();
146
+ return priceFeedSalt(args.name);
147
+ }
148
+ };
149
+ //#endregion
150
+ exports.DEFAULT_DEPLOY_SALT = DEFAULT_DEPLOY_SALT;
151
+ exports.PermissionlessDeploy = PermissionlessDeploy;
152
+ exports.priceFeedSalt = priceFeedSalt;
@@ -0,0 +1,46 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/permissionless/api/deploy/effective-staleness.ts
3
+ const abi = (0, require("viem").parseAbi)(["function stalenessPeriod() view returns (uint32)", "function latestRoundData() view returns (uint80,int256,uint256,uint256,uint80)"]);
4
+ /**
5
+ * Bound for a leg that recomputes its answer on every read and stamps it with
6
+ * the current block (exchange-rate adapters, NAV feeds, Pendle oracles,
7
+ * constant feeds). One second is the tightest value that still satisfies
8
+ * `block.timestamp < updatedAt + stalenessPeriod`.
9
+ **/
10
+ const CURRENT_BLOCK_STALENESS = 1;
11
+ /**
12
+ * The staleness a deployed price feed enforces on the price it reports.
13
+ *
14
+ * This is deliberately not the value the feed is registered with in the
15
+ * PriceFeedStore — derived feeds must be registered with 0 there, and the store
16
+ * rejects anything else for them with `IncorrectParameterException()`. It is
17
+ * the value a parent feed needs when it re-checks the leg's `updatedAt`
18
+ * itself.
19
+ *
20
+ * Returns `null` when it cannot be determined. Callers must surface that
21
+ * rather than substitute a bound: a leg constructed with a staleness its
22
+ * underlying oracle can never satisfy produces a feed that reverts on every
23
+ * read and can never be added to the store.
24
+ **/
25
+ async function deriveEffectiveStalenessPeriod(client, address) {
26
+ try {
27
+ const own = await client.readContract({
28
+ address,
29
+ abi,
30
+ functionName: "stalenessPeriod"
31
+ });
32
+ if (Number(own) > 0) return Number(own);
33
+ } catch {}
34
+ try {
35
+ const [block, round] = await Promise.all([client.getBlock(), client.readContract({
36
+ address,
37
+ abi,
38
+ functionName: "latestRoundData"
39
+ })]);
40
+ const updatedAt = Number(round[3]);
41
+ if (updatedAt > 0 && updatedAt >= Number(block.timestamp)) return CURRENT_BLOCK_STALENESS;
42
+ } catch {}
43
+ return null;
44
+ }
45
+ //#endregion
46
+ exports.deriveEffectiveStalenessPeriod = deriveEffectiveStalenessPeriod;
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_permissionless_api_deploy_effective_staleness = require("./effective-staleness.js");
3
+ const require_permissionless_api_deploy_PermissionlessDeploy = require("./PermissionlessDeploy.js");
4
+ require("./types.js");
5
+ exports.DEFAULT_DEPLOY_SALT = require_permissionless_api_deploy_PermissionlessDeploy.DEFAULT_DEPLOY_SALT;
6
+ exports.PermissionlessDeploy = require_permissionless_api_deploy_PermissionlessDeploy.PermissionlessDeploy;
7
+ exports.deriveEffectiveStalenessPeriod = require_permissionless_api_deploy_effective_staleness.deriveEffectiveStalenessPeriod;
8
+ exports.priceFeedSalt = require_permissionless_api_deploy_PermissionlessDeploy.priceFeedSalt;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -0,0 +1,82 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let viem = require("viem");
3
+ //#region src/permissionless/api/errors.ts
4
+ /**
5
+ * Thrown when anything is read off {@link ChainsNamespace} before
6
+ * {@link GearboxPermissionless.attach} has completed.
7
+ *
8
+ * The chain list is the backend's answer, so there is nothing to report until
9
+ * it arrives. Answering with an empty list instead would be indistinguishable
10
+ * from a backend that serves no chains at all.
11
+ **/
12
+ var PermissionlessNotAttachedError = class extends viem.BaseError {
13
+ name = "PermissionlessNotAttachedError";
14
+ constructor() {
15
+ super("The client has not attached yet.", { metaMessages: ["Await `attach()` before reading chains off the client."] });
16
+ }
17
+ };
18
+ /**
19
+ * Thrown when a call has to read a chain the client holds no viem client for.
20
+ *
21
+ * Either the backend does not serve the chain, or it serves one this SDK
22
+ * carries no definition for: endpoints come from the chain definition, since
23
+ * the backend's own urls carry provider keys and are never handed out.
24
+ **/
25
+ var PermissionlessChainUnreachableError = class extends viem.BaseError {
26
+ name = "PermissionlessChainUnreachableError";
27
+ /** Chain that was asked for. */
28
+ chainId;
29
+ constructor(chainId) {
30
+ super(`Chain ${chainId} cannot be read directly.`, { metaMessages: ["The backend either does not serve it, or serves a chain this SDK has no definition for."] });
31
+ this.chainId = chainId;
32
+ }
33
+ };
34
+ /**
35
+ * Thrown when a rename names a feed the PriceFeedStore does not carry. A name
36
+ * is part of what the store holds, so there is nothing to change on a feed
37
+ * that never reached it.
38
+ **/
39
+ var PriceFeedNotInStoreError = class extends viem.BaseError {
40
+ name = "PriceFeedNotInStoreError";
41
+ /** Feed that was named. */
42
+ priceFeed;
43
+ chainId;
44
+ constructor(priceFeed, chainId) {
45
+ super(`Price feed ${priceFeed} is not in the PriceFeedStore of chain ${chainId}.`, { metaMessages: ["Only a feed the store already carries can be renamed; add it first."] });
46
+ this.priceFeed = priceFeed;
47
+ this.chainId = chainId;
48
+ }
49
+ };
50
+ /**
51
+ * Thrown when a composite feed names a leg whose own staleness bound cannot be
52
+ * read off the chain.
53
+ *
54
+ * Deploying with a placeholder is not an option: a composite whose check can
55
+ * never pass reverts on every read, and the store will not take it. The bound
56
+ * has to be set on the leg first.
57
+ **/
58
+ var PriceFeedStalenessUnknownError = class extends viem.BaseError {
59
+ name = "PriceFeedStalenessUnknownError";
60
+ /** Leg whose bound could not be determined. */
61
+ priceFeed;
62
+ constructor(priceFeed) {
63
+ super(`Cannot determine the staleness period of price feed ${priceFeed}.`, { metaMessages: ["Deploying with a placeholder would make this composite permanently stale.", "Set the staleness period on the underlying feed first."] });
64
+ this.priceFeed = priceFeed;
65
+ }
66
+ };
67
+ /**
68
+ * Thrown when a price feed deploy names neither a salt nor the name one would
69
+ * be derived from, leaving CREATE2 nothing to distinguish it by.
70
+ **/
71
+ var PriceFeedSaltMissingError = class extends viem.BaseError {
72
+ name = "PriceFeedSaltMissingError";
73
+ constructor() {
74
+ super("A price feed deploy needs either `salt` or `name`.", { metaMessages: ["`name` is hashed into the salt, which is what keeps two feeds of the", "same type and arguments from landing on the same address."] });
75
+ }
76
+ };
77
+ //#endregion
78
+ exports.PermissionlessChainUnreachableError = PermissionlessChainUnreachableError;
79
+ exports.PermissionlessNotAttachedError = PermissionlessNotAttachedError;
80
+ exports.PriceFeedNotInStoreError = PriceFeedNotInStoreError;
81
+ exports.PriceFeedSaltMissingError = PriceFeedSaltMissingError;
82
+ exports.PriceFeedStalenessUnknownError = PriceFeedStalenessUnknownError;
@@ -0,0 +1,28 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_permissionless_api_errors = require("./errors.js");
3
+ const require_permissionless_api_chains_ChainsNamespace = require("./chains/ChainsNamespace.js");
4
+ require("./chains/index.js");
5
+ const require_permissionless_api_deploy_effective_staleness = require("./deploy/effective-staleness.js");
6
+ const require_permissionless_api_deploy_PermissionlessDeploy = require("./deploy/PermissionlessDeploy.js");
7
+ require("./deploy/index.js");
8
+ const require_permissionless_api_oracles_PermissionlessOracles = require("./oracles/PermissionlessOracles.js");
9
+ const require_permissionless_api_transactions_InstanceOwnerTransactions = require("./transactions/InstanceOwnerTransactions.js");
10
+ const require_permissionless_api_GearboxPermissionless = require("./GearboxPermissionless.js");
11
+ require("./oracles/index.js");
12
+ require("./transactions/index.js");
13
+ require("./types.js");
14
+ exports.ChainsNamespace = require_permissionless_api_chains_ChainsNamespace.ChainsNamespace;
15
+ exports.DEFAULT_DEPLOY_SALT = require_permissionless_api_deploy_PermissionlessDeploy.DEFAULT_DEPLOY_SALT;
16
+ exports.GET_PRICES_CHUNK_SIZE = require_permissionless_api_oracles_PermissionlessOracles.GET_PRICES_CHUNK_SIZE;
17
+ exports.GET_PRICES_GAS_LIMIT_BY_CHAIN_ID = require_permissionless_api_oracles_PermissionlessOracles.GET_PRICES_GAS_LIMIT_BY_CHAIN_ID;
18
+ exports.GearboxPermissionless = require_permissionless_api_GearboxPermissionless.GearboxPermissionless;
19
+ exports.InstanceOwnerTransactions = require_permissionless_api_transactions_InstanceOwnerTransactions.InstanceOwnerTransactions;
20
+ exports.PermissionlessChainUnreachableError = require_permissionless_api_errors.PermissionlessChainUnreachableError;
21
+ exports.PermissionlessDeploy = require_permissionless_api_deploy_PermissionlessDeploy.PermissionlessDeploy;
22
+ exports.PermissionlessNotAttachedError = require_permissionless_api_errors.PermissionlessNotAttachedError;
23
+ exports.PermissionlessOracles = require_permissionless_api_oracles_PermissionlessOracles.PermissionlessOracles;
24
+ exports.PriceFeedNotInStoreError = require_permissionless_api_errors.PriceFeedNotInStoreError;
25
+ exports.PriceFeedSaltMissingError = require_permissionless_api_errors.PriceFeedSaltMissingError;
26
+ exports.PriceFeedStalenessUnknownError = require_permissionless_api_errors.PriceFeedStalenessUnknownError;
27
+ exports.deriveEffectiveStalenessPeriod = require_permissionless_api_deploy_effective_staleness.deriveEffectiveStalenessPeriod;
28
+ exports.priceFeedSalt = require_permissionless_api_deploy_PermissionlessDeploy.priceFeedSalt;