@sovereign-sdk/web3 0.0.13 → 0.0.15
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.
- package/dist/index.d.mts +138 -60
- package/dist/index.d.ts +138 -60
- package/dist/index.js +165 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -19,6 +19,18 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
}
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
|
+
var __objRest = (source, exclude) => {
|
|
23
|
+
var target = {};
|
|
24
|
+
for (var prop in source)
|
|
25
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
26
|
+
target[prop] = source[prop];
|
|
27
|
+
if (source != null && __getOwnPropSymbols)
|
|
28
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
29
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
}
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
22
34
|
var __export = (target, all) => {
|
|
23
35
|
for (var name in all)
|
|
24
36
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -64,21 +76,23 @@ var __async = (__this, __arguments, generator) => {
|
|
|
64
76
|
// src/index.ts
|
|
65
77
|
var src_exports = {};
|
|
66
78
|
__export(src_exports, {
|
|
79
|
+
InvalidRollupConfigError: () => InvalidRollupConfigError,
|
|
80
|
+
Rollup: () => Rollup,
|
|
67
81
|
Schema: () => import_universal_wallet_wasm2.Schema,
|
|
68
82
|
SovereignClient: () => SovereignClient2,
|
|
69
83
|
SovereignError: () => SovereignError,
|
|
70
84
|
StandardRollup: () => StandardRollup,
|
|
71
|
-
createSerializer: () => createSerializer
|
|
85
|
+
createSerializer: () => createSerializer,
|
|
86
|
+
createStandardRollup: () => createStandardRollup,
|
|
87
|
+
standardTypeBuilder: () => standardTypeBuilder
|
|
72
88
|
});
|
|
73
89
|
module.exports = __toCommonJS(src_exports);
|
|
74
90
|
|
|
75
|
-
// src/rollup.ts
|
|
91
|
+
// src/rollup/rollup.ts
|
|
76
92
|
var import_client = __toESM(require("@sovereign-sdk/client"));
|
|
93
|
+
var import_utils = require("@sovereign-sdk/utils");
|
|
77
94
|
var import_js_base64 = require("js-base64");
|
|
78
95
|
|
|
79
|
-
// src/serialization.ts
|
|
80
|
-
var import_universal_wallet_wasm = require("@sovereign-sdk/universal-wallet-wasm");
|
|
81
|
-
|
|
82
96
|
// src/errors.ts
|
|
83
97
|
var SovereignError = class extends Error {
|
|
84
98
|
constructor(message) {
|
|
@@ -87,8 +101,11 @@ var SovereignError = class extends Error {
|
|
|
87
101
|
this.stack = new Error().stack;
|
|
88
102
|
}
|
|
89
103
|
};
|
|
104
|
+
var InvalidRollupConfigError = class extends SovereignError {
|
|
105
|
+
};
|
|
90
106
|
|
|
91
107
|
// src/serialization.ts
|
|
108
|
+
var import_universal_wallet_wasm = require("@sovereign-sdk/universal-wallet-wasm");
|
|
92
109
|
function loadSchema(schemaObject) {
|
|
93
110
|
try {
|
|
94
111
|
return import_universal_wallet_wasm.Schema.fromJSON(JSON.stringify(schemaObject));
|
|
@@ -135,30 +152,42 @@ function createSerializer(schemaObject) {
|
|
|
135
152
|
};
|
|
136
153
|
}
|
|
137
154
|
|
|
138
|
-
// src/
|
|
139
|
-
|
|
140
|
-
let hex = "";
|
|
141
|
-
for (let i = 0; i < arr.length; i++) {
|
|
142
|
-
let hexValue = arr[i].toString(16);
|
|
143
|
-
if (hexValue.length === 1) {
|
|
144
|
-
hexValue = `0${hexValue}`;
|
|
145
|
-
}
|
|
146
|
-
hex += hexValue;
|
|
147
|
-
}
|
|
148
|
-
return hex;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// src/rollup.ts
|
|
152
|
-
var StandardRollup = class {
|
|
155
|
+
// src/rollup/rollup.ts
|
|
156
|
+
var Rollup = class {
|
|
153
157
|
/**
|
|
154
158
|
* Creates a new rollup client.
|
|
155
159
|
*
|
|
160
|
+
* @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.
|
|
161
|
+
*
|
|
156
162
|
* @param config - The configuration for the rollup client.
|
|
163
|
+
* @param typeBuilder - The type builder for the rollup.
|
|
157
164
|
*/
|
|
158
|
-
constructor(config) {
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
constructor(config, typeBuilder) {
|
|
166
|
+
var _a;
|
|
167
|
+
if (config.serializer) {
|
|
168
|
+
this._serializer = config.serializer;
|
|
169
|
+
} else {
|
|
170
|
+
if (!config.schema) {
|
|
171
|
+
throw new InvalidRollupConfigError(
|
|
172
|
+
"At least 1 of config.schema or config.serializer must be provided"
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
this._serializer = createSerializer(config.schema);
|
|
176
|
+
}
|
|
177
|
+
this._client = (_a = config.client) != null ? _a : new import_client.default({ baseURL: config.url });
|
|
161
178
|
this._config = config;
|
|
179
|
+
this._typeBuilder = typeBuilder;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Retrieve dedup information about the provided address.
|
|
183
|
+
*
|
|
184
|
+
* @param address - The public key to dedup.
|
|
185
|
+
*/
|
|
186
|
+
dedup(address) {
|
|
187
|
+
return __async(this, null, function* () {
|
|
188
|
+
const response = yield this.rollup.addresses.dedup((0, import_utils.bytesToHex)(address));
|
|
189
|
+
return response.data;
|
|
190
|
+
});
|
|
162
191
|
}
|
|
163
192
|
/**
|
|
164
193
|
* Submits a transaction to the rollup.
|
|
@@ -178,20 +207,20 @@ var StandardRollup = class {
|
|
|
178
207
|
* Utilizes the provided signer to sign the transaction.
|
|
179
208
|
*
|
|
180
209
|
* @param unsignedTx - The unsigned transaction to sign and submit.
|
|
210
|
+
* @param {SignerParams} params - The params for signing and submitting the transaction.
|
|
181
211
|
*/
|
|
182
212
|
signAndSubmitTransaction(_0, _1) {
|
|
183
213
|
return __async(this, arguments, function* (unsignedTx, { signer }) {
|
|
184
214
|
const serializedUnsignedTx = this.serializer.serializeUnsignedTx(unsignedTx);
|
|
185
215
|
const signature = yield signer.sign(serializedUnsignedTx);
|
|
186
216
|
const publicKey = yield signer.publicKey();
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}, unsignedTx);
|
|
217
|
+
const context = {
|
|
218
|
+
unsignedTx,
|
|
219
|
+
sender: publicKey,
|
|
220
|
+
signature,
|
|
221
|
+
rollup: this
|
|
222
|
+
};
|
|
223
|
+
const tx = yield this._typeBuilder.transaction(context);
|
|
195
224
|
const result = yield this.submitTransaction(tx);
|
|
196
225
|
return { transaction: tx, response: result };
|
|
197
226
|
});
|
|
@@ -200,68 +229,41 @@ var StandardRollup = class {
|
|
|
200
229
|
* Performs a runtime call transaction.
|
|
201
230
|
* Utilizes the provided signer to sign the transaction.
|
|
202
231
|
*
|
|
203
|
-
* @param
|
|
232
|
+
* @param runtimeCall - The runtime message to call.
|
|
233
|
+
* @param {CallParams<S>} params - The params for submitting a runtime call transaction.
|
|
204
234
|
*/
|
|
205
235
|
call(_0, _1) {
|
|
206
|
-
return __async(this, arguments, function* (
|
|
207
|
-
const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);
|
|
236
|
+
return __async(this, arguments, function* (runtimeCall, { signer, overrides }) {
|
|
208
237
|
const publicKey = yield signer.publicKey();
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
details: txDetails != null ? txDetails : this._config.defaultTxDetails
|
|
238
|
+
const context = {
|
|
239
|
+
runtimeCall,
|
|
240
|
+
sender: publicKey,
|
|
241
|
+
rollup: this,
|
|
242
|
+
overrides: overrides != null ? overrides : {}
|
|
215
243
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
signer
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Simulates a runtime call transaction.
|
|
226
|
-
*
|
|
227
|
-
* This method can be useful to estimate the gas cost of a runtime call transaction.
|
|
228
|
-
*
|
|
229
|
-
* @param runtimeMessage - The runtime message to call.
|
|
230
|
-
*/
|
|
231
|
-
simulate(_0, _1) {
|
|
232
|
-
return __async(this, arguments, function* (runtimeMessage, { signer, txDetails }) {
|
|
233
|
-
const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);
|
|
234
|
-
const publicKey = yield signer.publicKey();
|
|
235
|
-
const dedup = yield this.rollup.addresses.dedup(bytesToHex(publicKey));
|
|
236
|
-
const nonce = dedup.data.nonce;
|
|
237
|
-
const response = yield this.rollup.simulate({
|
|
238
|
-
body: {
|
|
239
|
-
details: txDetails,
|
|
240
|
-
encoded_call_message: bytesToHex(runtimeCall),
|
|
241
|
-
nonce,
|
|
242
|
-
sender_pub_key: bytesToHex(publicKey)
|
|
243
|
-
}
|
|
244
|
+
const unsignedTx = yield this._typeBuilder.unsignedTransaction(context);
|
|
245
|
+
return this.signAndSubmitTransaction(unsignedTx, {
|
|
246
|
+
signer
|
|
244
247
|
});
|
|
245
|
-
return response.data;
|
|
246
248
|
});
|
|
247
249
|
}
|
|
248
250
|
/**
|
|
249
251
|
* A ledger client that can be used to query the ledger.
|
|
250
252
|
*/
|
|
251
253
|
get ledger() {
|
|
252
|
-
return this.
|
|
254
|
+
return this.http.ledger;
|
|
253
255
|
}
|
|
254
256
|
/**
|
|
255
257
|
* A sequencer client that can be used to submit transactions & batches to the rollup.
|
|
256
258
|
*/
|
|
257
259
|
get sequencer() {
|
|
258
|
-
return this.
|
|
260
|
+
return this.http.sequencer;
|
|
259
261
|
}
|
|
260
262
|
/**
|
|
261
263
|
* A rollup client that can be used to perform operations on the rollup.
|
|
262
264
|
*/
|
|
263
265
|
get rollup() {
|
|
264
|
-
return this.
|
|
266
|
+
return this.http.rollup;
|
|
265
267
|
}
|
|
266
268
|
/**
|
|
267
269
|
* A client that can be used to perform HTTP requests to the Sovereign API.
|
|
@@ -279,17 +281,107 @@ var StandardRollup = class {
|
|
|
279
281
|
get serializer() {
|
|
280
282
|
return this._serializer;
|
|
281
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* The context for the rollup.
|
|
286
|
+
*/
|
|
287
|
+
get context() {
|
|
288
|
+
return this._config.context;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// src/rollup/standard-rollup.ts
|
|
293
|
+
var import_utils2 = require("@sovereign-sdk/utils");
|
|
294
|
+
var useOrFetchNonce = (_0) => __async(void 0, [_0], function* ({
|
|
295
|
+
sender,
|
|
296
|
+
rollup,
|
|
297
|
+
overrides
|
|
298
|
+
}) {
|
|
299
|
+
if ((overrides == null ? void 0 : overrides.nonce) !== void 0 && overrides.nonce >= 0) {
|
|
300
|
+
return overrides.nonce;
|
|
301
|
+
}
|
|
302
|
+
const { data } = yield rollup.rollup.addresses.dedup((0, import_utils2.bytesToHex)(sender));
|
|
303
|
+
return data.nonce;
|
|
304
|
+
});
|
|
305
|
+
function standardTypeBuilder() {
|
|
306
|
+
return {
|
|
307
|
+
unsignedTransaction(context) {
|
|
308
|
+
return __async(this, null, function* () {
|
|
309
|
+
const { rollup, runtimeCall } = context;
|
|
310
|
+
const runtime_msg = rollup.serializer.serializeRuntimeCall(runtimeCall);
|
|
311
|
+
const _a2 = context.overrides, { nonce: _ } = _a2, overrides = __objRest(_a2, ["nonce"]);
|
|
312
|
+
const nonce = yield useOrFetchNonce(context);
|
|
313
|
+
const details = __spreadValues(__spreadValues({}, rollup.context.defaultTxDetails), overrides.details);
|
|
314
|
+
return {
|
|
315
|
+
runtime_msg,
|
|
316
|
+
nonce,
|
|
317
|
+
details
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
transaction(_0) {
|
|
322
|
+
return __async(this, arguments, function* ({
|
|
323
|
+
sender,
|
|
324
|
+
signature,
|
|
325
|
+
unsignedTx
|
|
326
|
+
}) {
|
|
327
|
+
return __spreadValues({
|
|
328
|
+
pub_key: {
|
|
329
|
+
pub_key: sender
|
|
330
|
+
},
|
|
331
|
+
signature: {
|
|
332
|
+
msg_sig: signature
|
|
333
|
+
}
|
|
334
|
+
}, unsignedTx);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
var StandardRollup = class extends Rollup {
|
|
340
|
+
/**
|
|
341
|
+
* Simulates a runtime call transaction.
|
|
342
|
+
*
|
|
343
|
+
* This method can be useful to estimate the gas cost of a runtime call transaction.
|
|
344
|
+
*
|
|
345
|
+
* @param runtimeMessage - The runtime message to call.
|
|
346
|
+
*/
|
|
347
|
+
simulate(_0, _1) {
|
|
348
|
+
return __async(this, arguments, function* (runtimeMessage, { signer, txDetails, nonce: overrideNonce }) {
|
|
349
|
+
const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);
|
|
350
|
+
const publicKey = yield signer.publicKey();
|
|
351
|
+
const nonce = yield useOrFetchNonce({
|
|
352
|
+
sender: publicKey,
|
|
353
|
+
rollup: this,
|
|
354
|
+
overrides: { nonce: overrideNonce }
|
|
355
|
+
});
|
|
356
|
+
const response = yield this.rollup.simulate({
|
|
357
|
+
body: {
|
|
358
|
+
details: txDetails,
|
|
359
|
+
encoded_call_message: (0, import_utils2.bytesToHex)(runtimeCall),
|
|
360
|
+
nonce,
|
|
361
|
+
sender_pub_key: (0, import_utils2.bytesToHex)(publicKey)
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return response.data;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
282
367
|
};
|
|
368
|
+
function createStandardRollup(config, typeBuilderOverrides) {
|
|
369
|
+
return new StandardRollup(config, __spreadValues(__spreadValues({}, standardTypeBuilder()), typeBuilderOverrides));
|
|
370
|
+
}
|
|
283
371
|
|
|
284
372
|
// src/index.ts
|
|
285
373
|
var SovereignClient2 = __toESM(require("@sovereign-sdk/client"));
|
|
286
374
|
var import_universal_wallet_wasm2 = require("@sovereign-sdk/universal-wallet-wasm");
|
|
287
375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
288
376
|
0 && (module.exports = {
|
|
377
|
+
InvalidRollupConfigError,
|
|
378
|
+
Rollup,
|
|
289
379
|
Schema,
|
|
290
380
|
SovereignClient,
|
|
291
381
|
SovereignError,
|
|
292
382
|
StandardRollup,
|
|
293
|
-
createSerializer
|
|
383
|
+
createSerializer,
|
|
384
|
+
createStandardRollup,
|
|
385
|
+
standardTypeBuilder
|
|
294
386
|
});
|
|
295
387
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/rollup.ts","../src/serialization.ts","../src/errors.ts","../src/utils.ts"],"sourcesContent":["export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { Base64 } from \"js-base64\";\nimport {\n type RollupSchema,\n type RollupSerializer,\n createSerializer,\n} from \"./serialization\";\nimport type { BaseTypeSpec } from \"./type-spec\";\nimport { bytesToHex } from \"./utils\";\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The configuration for a rollup client.\n */\nexport type RollupConfig = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The schema of the rollup.\n */\n schema: RollupSchema;\n /**\n * The default transaction details.\n * This will be deprecated soon to remove Sovereign SDK specific types.\n * @deprecated\n * @private\n */\n defaultTxDetails: TxDetails;\n};\n\ntype TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit?: number[];\n chain_id: number;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams = {\n /**\n * The transaction details to use for the call.\n * @deprecated This will be removed soon to remove Sovereign SDK specific types.\n * In favor of a looser type specification.\n */\n txDetails?: TxDetails;\n} & SignerParams;\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n * @deprecated This will be removed soon to remove Sovereign SDK specific types.\n * In favor of a looser type specification.\n */\n txDetails: TxDetails;\n} & SignerParams;\n\n/**\n * The rollup client.\n *\n * @template T - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n */\nexport class StandardRollup<T extends BaseTypeSpec = BaseTypeSpec> {\n private readonly _config: RollupConfig;\n private readonly _client: SovereignClient;\n private readonly _serializer: RollupSerializer;\n\n /**\n * Creates a new rollup client.\n *\n * @param config - The configuration for the rollup client.\n */\n constructor(config: RollupConfig) {\n this._client = new SovereignClient({ baseURL: config.url });\n this._serializer = createSerializer(config.schema);\n this._config = config;\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: T[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs.create({\n body: Base64.fromUint8Array(serializedTx),\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n */\n async signAndSubmitTransaction(\n unsignedTx: T[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<T[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const tx = {\n pub_key: {\n pub_key: publicKey,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n } as T[\"Transaction\"];\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async call(\n runtimeMessage: T[\"RuntimeCall\"],\n { signer, txDetails }: CallParams,\n ): Promise<TransactionResult<T[\"Transaction\"]>> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const dedup = await this.rollup.addresses.dedup(bytesToHex(publicKey));\n // biome-ignore lint/suspicious/noExplicitAny: fix later\n const nonce = (dedup.data as any).nonce as number;\n const unsignedTx = {\n runtime_msg: runtimeCall,\n nonce,\n details: txDetails ?? this._config.defaultTxDetails,\n };\n\n return this.signAndSubmitTransaction(\n unsignedTx as T[\"UnsignedTransaction\"],\n {\n signer,\n },\n );\n }\n\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: T[\"RuntimeCall\"],\n { signer, txDetails }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const dedup = await this.rollup.addresses.dedup(bytesToHex(publicKey));\n // biome-ignore lint/suspicious/noExplicitAny: fix later\n const nonce = (dedup.data as any).nonce as number;\n const response = await this.rollup.simulate({\n body: {\n details: txDetails,\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this._client.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this._client.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this._client.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._serializer;\n }\n}\n","import { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n","export function hexToBytes(hex: string) {\n if (hex.length && hex.length % 2 !== 0) {\n throw new Error(`Invalid hex string length: ${hex.length}`);\n }\n\n const matches = hex.match(/[\\da-f]{2}/gi);\n\n if (!matches) {\n throw new Error(\"Invalid hex string: No valid hex digits found\");\n }\n\n return new Uint8Array(matches.map((h) => Number.parseInt(h, 16)));\n}\n\nexport function bytesToHex(arr: Uint8Array): string {\n let hex = \"\";\n for (let i = 0; i < arr.length; i++) {\n let hexValue = arr[i].toString(16);\n if (hexValue.length === 1) {\n hexValue = `0${hexValue}`;\n }\n hex += hexValue;\n }\n return hex;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA4B;AAE5B,uBAAuB;;;ACFvB,mCAAoC;;;ACG7B,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,IAAI,MAAM,EAAE;AAAA,EAC3B;AACF;;;ADoDA,SAAS,WAAW,cAAoC;AACtD,MAAI;AACF,WAAO,oCAAO,SAAS,KAAK,UAAU,YAAY,CAAC;AAAA,EACrD,SAAS,KAAK;AACZ,UAAM,IAAI,eAAe,2CAA2C,GAAG,EAAE;AAAA,EAC3E;AACF;AASO,SAAS,iBAAiB,cAA8C;AAC7E,QAAM,SAAS,WAAW,YAAY;AAEtC,SAAO;AAAA,IACL,UAAU,OAAgB,OAA2B;AACnD,UAAI;AACF,eAAO,OAAO;AAAA,UACZ;AAAA,UACA,KAAK,UAAU,OAAO,CAAC,GAAG,UAAU;AAClC,gBAAI,iBAAiB,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK;AAAA,YACzB;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,SAAS,KAAK;AACZ,cAAM,IAAI,eAAe,qCAAqC,GAAG,EAAE;AAAA,MACrE;AAAA,IACF;AAAA,IACA,qBAAqB,OAA4B;AAC/C,aAAO,KAAK;AAAA,QACV;AAAA,QACA,OAAO,eAAe,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C;AACnC,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAuC;AACzC,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiC;AACnC,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAwB;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,aAA+B;AACjC,WAAO,KAAK;AAAA,EACd;AACF;;;ADtPA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","SovereignClient","SovereignClient","import_universal_wallet_wasm"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/rollup/standard-rollup.ts"],"sourcesContent":["export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { InvalidRollupConfigError } from \"../errors\";\nimport {\n type RollupSchema,\n type RollupSerializer,\n createSerializer,\n} from \"../serialization\";\nimport type { BaseTypeSpec } from \"../type-spec\";\nimport type { DeepPartial } from \"../utils\";\n\nexport type UnsignedTransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n runtimeCall: S[\"RuntimeCall\"];\n sender: Uint8Array;\n // able to override nonce\n overrides: DeepPartial<S[\"UnsignedTransaction\"]>;\n rollup: Rollup<S, C>;\n};\n\nexport type TransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n unsignedTx: S[\"UnsignedTransaction\"];\n sender: Uint8Array;\n signature: Uint8Array;\n rollup: Rollup<S, C>;\n};\n\nexport type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {\n unsignedTransaction: (\n context: UnsignedTransactionContext<S, C>,\n ) => Promise<S[\"UnsignedTransaction\"]>;\n\n transaction: (context: TransactionContext<S, C>) => Promise<S[\"Transaction\"]>;\n};\n\n/**\n * Arbitrary context that is associated with the rollup.\n */\nexport type RollupContext = Record<string, unknown>;\n\n/**\n * The configuration for a rollup client.\n */\nexport type RollupConfig<C extends RollupContext> = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The Sovereign SDK client to use for the rollup.\n * If not provided, the default client will be used using {@link RollupConfig.url}.\n */\n client?: SovereignClient;\n /**\n * The schema of the rollup.\n */\n schema?: RollupSchema;\n /**\n * The serializer to use for the rollup.\n * If not provided, a serializer will be created using the provided {@link RollupConfig.schema}.\n */\n serializer?: RollupSerializer;\n /**\n * Arbitrary context that is associated with the rollup.\n */\n context: C;\n};\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams<S extends BaseTypeSpec> = {\n overrides?: DeepPartial<S[\"UnsignedTransaction\"]>;\n} & SignerParams;\n\n/**\n * A generic rollup client.\n *\n * @template S - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n * @template C - The context for the rollup.\n */\nexport class Rollup<S extends BaseTypeSpec, C extends RollupContext> {\n private readonly _config: RollupConfig<C>;\n private readonly _client: SovereignClient;\n private readonly _serializer: RollupSerializer;\n private readonly _typeBuilder: TypeBuilder<S, C>;\n\n /**\n * Creates a new rollup client.\n *\n * @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.\n *\n * @param config - The configuration for the rollup client.\n * @param typeBuilder - The type builder for the rollup.\n */\n constructor(config: RollupConfig<C>, typeBuilder: TypeBuilder<S, C>) {\n if (config.serializer) {\n this._serializer = config.serializer;\n } else {\n if (!config.schema) {\n throw new InvalidRollupConfigError(\n \"At least 1 of config.schema or config.serializer must be provided\",\n );\n }\n this._serializer = createSerializer(config.schema);\n }\n\n this._client =\n config.client ?? new SovereignClient({ baseURL: config.url });\n this._config = config;\n this._typeBuilder = typeBuilder;\n }\n\n /**\n * Retrieve dedup information about the provided address.\n *\n * @param address - The public key to dedup.\n */\n async dedup(address: Uint8Array): Promise<S[\"Dedup\"]> {\n const response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response.data as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs.create({\n body: Base64.fromUint8Array(serializedTx),\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n * @param {SignerParams} params - The params for signing and submitting the transaction.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const context = {\n unsignedTx,\n sender: publicKey,\n signature,\n rollup: this,\n };\n const tx = await this._typeBuilder.transaction(context);\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeCall - The runtime message to call.\n * @param {CallParams<S>} params - The params for submitting a runtime call transaction.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const publicKey = await signer.publicKey();\n const context = {\n runtimeCall,\n sender: publicKey,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(unsignedTx, {\n signer,\n });\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this.http.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this.http.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this.http.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._serializer;\n }\n\n /**\n * The context for the rollup.\n */\n get context(): C {\n return this._config.context;\n }\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n\nexport class InvalidRollupConfigError extends SovereignError {}\n","import { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport {\n Rollup,\n type RollupConfig,\n type SignerParams,\n type TransactionContext,\n type TypeBuilder,\n type UnsignedTransactionContext,\n} from \"./rollup\";\n\nexport type TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit?: number[];\n chain_id: number;\n};\n\nexport type UnsignedTransaction = {\n runtime_msg: Uint8Array;\n nonce: number;\n details: TxDetails;\n};\n\nexport type Transaction = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction;\n\nexport type Dedup = {\n nonce: number;\n};\n\nexport type StandardRollupContext = {\n defaultTxDetails: TxDetails;\n};\n\nexport type StandardRollupSpec<RuntimeCall> = {\n UnsignedTransaction: UnsignedTransaction;\n Transaction: Transaction;\n RuntimeCall: RuntimeCall;\n Dedup: Dedup;\n};\n\nconst useOrFetchNonce = async <S extends StandardRollupSpec<unknown>>({\n sender,\n rollup,\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.nonce !== undefined && overrides.nonce >= 0) {\n return overrides.nonce;\n }\n const { data } = await rollup.rollup.addresses.dedup(bytesToHex(sender));\n\n return (data as S[\"Dedup\"]).nonce;\n};\n\nexport function standardTypeBuilder<\n S extends StandardRollupSpec<unknown>,\n>(): TypeBuilder<S, StandardRollupContext> {\n return {\n async unsignedTransaction(\n context: UnsignedTransactionContext<S, StandardRollupContext>,\n ) {\n const { rollup, runtimeCall } = context;\n const runtime_msg = rollup.serializer.serializeRuntimeCall(runtimeCall);\n const { nonce: _, ...overrides } = context.overrides;\n const nonce = await useOrFetchNonce(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_msg,\n nonce,\n details,\n };\n },\n async transaction({\n sender,\n signature,\n unsignedTx,\n }: TransactionContext<S, StandardRollupContext>) {\n return {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n };\n },\n };\n}\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n */\n txDetails: TxDetails;\n\n nonce?: number;\n} & SignerParams;\n\nexport class StandardRollup<RuntimeCall> extends Rollup<\n StandardRollupSpec<RuntimeCall>,\n StandardRollupContext\n> {\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: StandardRollupSpec<RuntimeCall>[\"RuntimeCall\"],\n { signer, txDetails, nonce: overrideNonce }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const nonce = await useOrFetchNonce({\n sender: publicKey,\n rollup: this,\n overrides: { nonce: overrideNonce },\n });\n const response = await this.rollup.simulate({\n body: {\n details: txDetails,\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n}\n\nexport function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n config: RollupConfig<C>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n return new StandardRollup<RuntimeCall>(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Ac;AAAA,MACpC,CAAC;AACD,YAAM,WAAW,MAAM,KAAK,OAAO,SAAS;AAAA,QAC1C,MAAM;AAAA,UACJ,SAAS;AAAA,UACT,0BAAsB,0BAAW,WAAW;AAAA,UAC5C;AAAA,UACA,oBAAgB,0BAAW,SAAS;AAAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEO,SAAS,qBAId,QACA,sBAGA;AACA,SAAO,IAAI,eAA4B,QAAQ,kCAC1C,oBAAoB,IACpB,qBACJ;AACH;;;AJ7JA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","SovereignClient","import_utils","_a","SovereignClient","import_universal_wallet_wasm"]}
|