@funkit/core 2.3.6 → 2.3.7

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.js CHANGED
@@ -11536,7 +11536,12 @@ var DEFAULT_RETRY_OPTIONS = {
11536
11536
  beforeAttempt: null,
11537
11537
  calculateDelay: null
11538
11538
  };
11539
- var sendRequest = async (uri, method, apiKey, body, retryOptions) => {
11539
+ var sendRequest = async (uri, method, {
11540
+ apiKey,
11541
+ body,
11542
+ retryOptions,
11543
+ signal
11544
+ }) => {
11540
11545
  try {
11541
11546
  const headers = {
11542
11547
  "Content-Type": "application/json"
@@ -11553,7 +11558,8 @@ var sendRequest = async (uri, method, apiKey, body, retryOptions) => {
11553
11558
  method,
11554
11559
  headers,
11555
11560
  redirect: "follow",
11556
- body: method !== "GET" ? stringify(body) : void 0
11561
+ body: method !== "GET" ? stringify(body) : void 0,
11562
+ signal
11557
11563
  });
11558
11564
  const json = await response.json();
11559
11565
  if (response.ok) {
@@ -11652,39 +11658,17 @@ var sendRequest = async (uri, method, apiKey, body, retryOptions) => {
11652
11658
  );
11653
11659
  }
11654
11660
  };
11655
- async function sendGetRequest(uri, endpoint, apiKey = globalThis.globalEnvOption.apiKey, retryOptions = {}) {
11656
- return await sendRequest(
11657
- `${uri}/${endpoint}`,
11658
- "GET",
11659
- apiKey,
11660
- void 0,
11661
- retryOptions
11662
- );
11663
- }
11664
- async function sendPostRequest(uri, endpoint, body, apiKey = globalThis.globalEnvOption.apiKey, retryOptions = {}) {
11665
- return await sendRequest(
11666
- `${uri}/${endpoint}`,
11667
- "POST",
11668
- apiKey,
11669
- body,
11670
- retryOptions
11671
- );
11672
- }
11673
- async function sendDeleteRequest(uri, endpoint, apiKey = globalThis.globalEnvOption.apiKey) {
11674
- await sendRequest(`${uri}/${endpoint}`, "DELETE", apiKey);
11675
- }
11676
- async function sendPutRequest(uri, endpoint, body, apiKey = globalThis.globalEnvOption.apiKey) {
11677
- await sendRequest(`${uri}/${endpoint}`, "PUT", apiKey, body);
11678
- }
11679
11661
 
11680
11662
  // src/utils/AuthUtils.ts
11681
11663
  import { v4 as uuidv4 } from "uuid";
11682
11664
  import { generatePrivateKey as generateRandomPrivateKey } from "viem/accounts";
11683
11665
  import { createUser, getUserUniqueId } from "@funkit/api-base";
11684
- var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false) => {
11666
+ var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false, options) => {
11685
11667
  const authUniqueId = (skipDBActions ? addr : await getUserUniqueId({
11686
11668
  authId,
11687
- apiKey: globalThis.globalEnvOption.apiKey
11669
+ apiKey: globalThis.globalEnvOption.apiKey,
11670
+ logger: options?.logger,
11671
+ signal: options?.signal
11688
11672
  })) || uuidv4();
11689
11673
  const words = authId.split("###");
11690
11674
  const method = words[0].startsWith("0x") ? "eoa" : words[0];
@@ -11693,7 +11677,9 @@ var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false)
11693
11677
  addr,
11694
11678
  method,
11695
11679
  userUniqueId: authUniqueId,
11696
- apiKey: globalThis.globalEnvOption.apiKey
11680
+ apiKey: globalThis.globalEnvOption.apiKey,
11681
+ logger: options?.logger,
11682
+ signal: options?.signal
11697
11683
  });
11698
11684
  return authUniqueId;
11699
11685
  };
@@ -11727,8 +11713,11 @@ var isAddress = (address) => {
11727
11713
  }
11728
11714
  };
11729
11715
  var fundWallet = async (auth, wallet, value, txOptions = globalThis.globalEnvOption) => {
11730
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
11731
- const chainId = await chain.getChainId();
11716
+ const chain = await Chain.getChain(
11717
+ { chainIdentifier: txOptions.chain },
11718
+ txOptions
11719
+ );
11720
+ const chainId = await chain.getChainId(txOptions);
11732
11721
  const to = await wallet.getAddress();
11733
11722
  let txData;
11734
11723
  if (gasSpecificChain[chainId]) {
@@ -11736,7 +11725,7 @@ var fundWallet = async (auth, wallet, value, txOptions = globalThis.globalEnvOpt
11736
11725
  let maxPriorityFee;
11737
11726
  let maxFee;
11738
11727
  try {
11739
- const { standard } = await getGasStation(gasStationUrl);
11728
+ const { standard } = await getGasStation(gasStationUrl, txOptions);
11740
11729
  maxPriorityFee = standard.maxPriorityFee;
11741
11730
  maxFee = standard.maxFee;
11742
11731
  } catch (_err) {
@@ -11771,13 +11760,14 @@ var randomBytes = (length) => {
11771
11760
  }
11772
11761
  return toHex(bytes);
11773
11762
  };
11774
- var getWalletPermitNonce = async (walletAddr, chain, nonceKey = 0) => {
11763
+ var getWalletPermitNonce = async (walletAddr, chain, nonceKey = 0, options) => {
11775
11764
  try {
11776
11765
  return await WALLET_CONTRACT_INTERFACE.readFromChain(
11777
11766
  walletAddr,
11778
11767
  "getNonce",
11779
11768
  [nonceKey],
11780
- chain
11769
+ chain,
11770
+ options
11781
11771
  );
11782
11772
  } catch (_err) {
11783
11773
  return 0n;
@@ -11821,12 +11811,12 @@ var getPermitHash = (token, to, amount, nonce, walletAddr, chainId) => {
11821
11811
  );
11822
11812
  return keccak256(concat([DOMAIN_SEPARATOR, PERMIT_HASH]));
11823
11813
  };
11824
- var getGasStation = async (gasStationUrl) => {
11825
- return await sendRequest(gasStationUrl, "GET", "");
11814
+ var getGasStation = async (gasStationUrl, options) => {
11815
+ return await sendRequest(gasStationUrl, "GET", { signal: options?.signal });
11826
11816
  };
11827
- var useFaucet = async (chainIdentifier, wallet) => {
11828
- const chain = await Chain.getChain({ chainIdentifier });
11829
- const chainName = await chain.getChainName();
11817
+ var useFaucet = async (chainIdentifier, wallet, txOptions) => {
11818
+ const chain = await Chain.getChain({ chainIdentifier }, txOptions);
11819
+ const chainName = await chain.getChainName(txOptions);
11830
11820
  if (chainName !== "goerli") {
11831
11821
  throw new InvalidParameterError2(
11832
11822
  ErrorCode2.InvalidChainIdentifier,
@@ -11843,25 +11833,33 @@ var useFaucet = async (chainIdentifier, wallet) => {
11843
11833
  token: "eth",
11844
11834
  chain: chainName,
11845
11835
  walletAddress,
11846
- apiKey: globalThis.globalEnvOption.apiKey
11836
+ apiKey: globalThis.globalEnvOption.apiKey,
11837
+ logger: txOptions?.logger,
11838
+ signal: txOptions?.signal
11847
11839
  }),
11848
11840
  getAssetFromFaucet({
11849
11841
  token: "usdc",
11850
11842
  chain: chainName,
11851
11843
  walletAddress,
11852
- apiKey: globalThis.globalEnvOption.apiKey
11844
+ apiKey: globalThis.globalEnvOption.apiKey,
11845
+ logger: txOptions?.logger,
11846
+ signal: txOptions?.signal
11853
11847
  }),
11854
11848
  getAssetFromFaucet({
11855
11849
  token: "usdt",
11856
11850
  chain: chainName,
11857
11851
  walletAddress,
11858
- apiKey: globalThis.globalEnvOption.apiKey
11852
+ apiKey: globalThis.globalEnvOption.apiKey,
11853
+ logger: txOptions?.logger,
11854
+ signal: txOptions?.signal
11859
11855
  }),
11860
11856
  getAssetFromFaucet({
11861
11857
  token: "dai",
11862
11858
  chain: chainName,
11863
11859
  walletAddress,
11864
- apiKey: globalThis.globalEnvOption.apiKey
11860
+ apiKey: globalThis.globalEnvOption.apiKey,
11861
+ logger: txOptions?.logger,
11862
+ signal: txOptions?.signal
11865
11863
  })
11866
11864
  ]);
11867
11865
  return [ethRequest, usdcRequest, usdtRequest, daiRequest];
@@ -11937,10 +11935,10 @@ function packUserOp(op, forSignature = true) {
11937
11935
  }));
11938
11936
  return encode(typevalues, forSignature);
11939
11937
  }
11940
- async function gasCalculation(txid, chain) {
11938
+ async function gasCalculation(txid, chain, options) {
11941
11939
  if (!txid || txid === "0x")
11942
11940
  return { gasUsed: "-1", opFee: "-1", opFeeUSD: "-1" };
11943
- const provider = await chain.getClient();
11941
+ const provider = await chain.getClient(options);
11944
11942
  const txReceipt = await provider.waitForTransactionReceipt({
11945
11943
  hash: txid
11946
11944
  });
@@ -11948,7 +11946,9 @@ async function gasCalculation(txid, chain) {
11948
11946
  const gasPrice = txReceipt.effectiveGasPrice;
11949
11947
  const opFee = gasUsed * gasPrice;
11950
11948
  const chainPrice = BigInt(
11951
- Math.ceil(await getPriceData(await chain.getCurrency()) * 100)
11949
+ Math.ceil(
11950
+ await getPriceData(await chain.getCurrency(options), options) * 100
11951
+ )
11952
11952
  );
11953
11953
  const opFeeUSD = opFee * BigInt(chainPrice);
11954
11954
  return {
@@ -11958,12 +11958,11 @@ async function gasCalculation(txid, chain) {
11958
11958
  };
11959
11959
  }
11960
11960
  var PRICE_URL = "https://min-api.cryptocompare.com/data/price";
11961
- async function getPriceData(chainCurrency) {
11961
+ async function getPriceData(chainCurrency, options) {
11962
11962
  const data = await sendRequest(
11963
11963
  `${PRICE_URL}?fsym=${chainCurrency}&tsyms=USD`,
11964
11964
  "GET",
11965
- "",
11966
- {}
11965
+ { signal: options?.signal }
11967
11966
  );
11968
11967
  return data.USD;
11969
11968
  }
@@ -12063,20 +12062,21 @@ var userOpTypeSig = {
12063
12062
  name: "userOp",
12064
12063
  type: "tuple"
12065
12064
  };
12066
- async function getOpHash(chain, userOp) {
12067
- const entryPointAddress = await chain.getAddress("entryPointAddress");
12065
+ async function getOpHash(chain, userOp, options) {
12066
+ const entryPointAddress = await chain.getAddress("entryPointAddress", options);
12068
12067
  return await ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(
12069
12068
  entryPointAddress,
12070
12069
  "getUserOpHash",
12071
12070
  [userOp],
12072
- chain
12071
+ chain,
12072
+ options
12073
12073
  );
12074
12074
  }
12075
12075
 
12076
12076
  // src/utils/TokenUtils.ts
12077
12077
  import { getAssetErc20ByChainAndSymbol } from "@funkit/api-base";
12078
12078
  import { ErrorCode as ErrorCode3, ResourceNotFoundError as ResourceNotFoundError2 } from "@funkit/utils";
12079
- async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId) {
12079
+ async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId, options) {
12080
12080
  const normalizedSymbol = inputSymbol.toLowerCase();
12081
12081
  if (BASE_WRAP_TOKEN_ADDR?.[inputChainId]?.[normalizedSymbol]) {
12082
12082
  return BASE_WRAP_TOKEN_ADDR[inputChainId][normalizedSymbol];
@@ -12084,7 +12084,9 @@ async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId) {
12084
12084
  const tokenInfo = await getAssetErc20ByChainAndSymbol({
12085
12085
  chainId: inputChainId,
12086
12086
  symbol: normalizedSymbol,
12087
- apiKey: globalThis.globalEnvOption.apiKey
12087
+ apiKey: globalThis.globalEnvOption.apiKey,
12088
+ logger: options?.logger,
12089
+ signal: options?.signal
12088
12090
  });
12089
12091
  if (tokenInfo.address) {
12090
12092
  return tokenInfo.address;
@@ -12125,14 +12127,15 @@ var generateRandomNonce = () => {
12125
12127
  const randomKey = generateRandomNonceKey();
12126
12128
  return randomKey << 64n;
12127
12129
  };
12128
- var getWalletAddress = async (chain, walletUniqueId) => {
12130
+ var getWalletAddress = async (chain, walletUniqueId, options) => {
12129
12131
  const data = encodeLoginData({ salt: walletUniqueId });
12130
- const factoryAddress = await chain.getAddress("factoryAddress");
12132
+ const factoryAddress = await chain.getAddress("factoryAddress", options);
12131
12133
  return await FACTORY_CONTRACT_INTERFACE.readFromChain(
12132
12134
  factoryAddress,
12133
12135
  "getAddress",
12134
12136
  [data],
12135
- chain
12137
+ chain,
12138
+ options
12136
12139
  );
12137
12140
  };
12138
12141
  var isWalletInitOp = (userOp) => {
@@ -12183,11 +12186,11 @@ var Chain = class _Chain {
12183
12186
  this.name = chainInput.chainIdentifier;
12184
12187
  }
12185
12188
  }
12186
- static async getChain(chainInput) {
12189
+ static async getChain(chainInput, options) {
12187
12190
  if (chainInput.chainIdentifier instanceof _Chain) {
12188
12191
  return chainInput.chainIdentifier;
12189
12192
  }
12190
- if (!_Chain.chain || await _Chain.chain.getChainId() !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getChainName() !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getRpcUrl() !== chainInput.rpcUrl) {
12193
+ if (!_Chain.chain || await _Chain.chain.getChainId(options) !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getChainName(options) !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getRpcUrl(options) !== chainInput.rpcUrl) {
12191
12194
  if (typeof chainInput.chainIdentifier === "string") {
12192
12195
  chainInput.chainIdentifier = chainInput.chainIdentifier.replace(
12193
12196
  /\s/g,
@@ -12204,35 +12207,39 @@ var Chain = class _Chain {
12204
12207
  }
12205
12208
  return _Chain.chain;
12206
12209
  }
12207
- async init() {
12210
+ async init(options) {
12208
12211
  if (this.initialized) return;
12209
12212
  if (this.id) {
12210
- await this.loadChain(this.id);
12213
+ await this.loadChain(this.id, options);
12211
12214
  } else if (this.name) {
12212
- await this.loadChain(this.name);
12215
+ await this.loadChain(this.name, options);
12213
12216
  } else if (this.rpcUrl) {
12214
- await this.loadChainFromRpc();
12217
+ await this.loadChainFromRpc(options);
12215
12218
  }
12216
12219
  this.initialized = true;
12217
12220
  }
12218
- async loadChainFromRpc() {
12221
+ async loadChainFromRpc(options) {
12219
12222
  this.client = createPublicClient({
12220
12223
  transport: http(this.rpcUrl)
12221
12224
  });
12222
12225
  this.id = (await this.client.getChainId()).toString();
12223
- await this.loadChain(this.id);
12226
+ await this.loadChain(this.id, options);
12224
12227
  }
12225
- async loadChain(identifier) {
12228
+ async loadChain(identifier, options) {
12226
12229
  let chain;
12227
12230
  if (!Number(identifier)) {
12228
12231
  chain = await getChainFromName({
12229
12232
  name: identifier,
12230
- apiKey: globalThis.globalEnvOption.apiKey
12233
+ apiKey: globalThis.globalEnvOption.apiKey,
12234
+ logger: options?.logger,
12235
+ signal: options?.signal
12231
12236
  });
12232
12237
  } else {
12233
12238
  chain = await getChainFromId({
12234
12239
  chainId: identifier,
12235
- apiKey: globalThis.globalEnvOption.apiKey
12240
+ apiKey: globalThis.globalEnvOption.apiKey,
12241
+ logger: options?.logger,
12242
+ signal: options?.signal
12236
12243
  });
12237
12244
  }
12238
12245
  this.id = chain.id;
@@ -12251,20 +12258,20 @@ var Chain = class _Chain {
12251
12258
  this.client = createPublicClient({ transport: http(this.rpcUrl) });
12252
12259
  Object.assign(this, { ...this, addresses });
12253
12260
  }
12254
- async getChainId() {
12255
- await this.init();
12261
+ async getChainId(options) {
12262
+ await this.init(options);
12256
12263
  return this.id;
12257
12264
  }
12258
- async getChainName() {
12259
- await this.init();
12265
+ async getChainName(options) {
12266
+ await this.init(options);
12260
12267
  return this.name;
12261
12268
  }
12262
- async getRpcUrl() {
12263
- await this.init();
12269
+ async getRpcUrl(options) {
12270
+ await this.init(options);
12264
12271
  return this.rpcUrl;
12265
12272
  }
12266
- async getAddress(name) {
12267
- await this.init();
12273
+ async getAddress(name, options) {
12274
+ await this.init(options);
12268
12275
  const res = this.addresses[name];
12269
12276
  if (!res) {
12270
12277
  throw new ResourceNotFoundError3(
@@ -12278,21 +12285,23 @@ var Chain = class _Chain {
12278
12285
  }
12279
12286
  return res;
12280
12287
  }
12281
- async getCurrency() {
12282
- await this.init();
12288
+ async getCurrency(options) {
12289
+ await this.init(options);
12283
12290
  return this.currency;
12284
12291
  }
12285
- async getClient() {
12286
- await this.init();
12292
+ async getClient(options) {
12293
+ await this.init(options);
12287
12294
  return this.client;
12288
12295
  }
12289
- async getFeeData() {
12290
- await this.init();
12296
+ async getFeeData(options) {
12297
+ await this.init(options);
12291
12298
  let result;
12292
12299
  try {
12293
12300
  result = await getUserOpGasPrice({
12294
12301
  chainId: this.id,
12295
- apiKey: globalThis.globalEnvOption.apiKey
12302
+ apiKey: globalThis.globalEnvOption.apiKey,
12303
+ logger: options?.logger,
12304
+ signal: options?.signal
12296
12305
  });
12297
12306
  } catch (_err) {
12298
12307
  const fallBackGasPrice = await this.client.getGasPrice();
@@ -12303,8 +12312,8 @@ var Chain = class _Chain {
12303
12312
  }
12304
12313
  return result;
12305
12314
  }
12306
- async estimateOpGas(partialOp) {
12307
- await this.init();
12315
+ async estimateOpGas(partialOp, options) {
12316
+ await this.init(options);
12308
12317
  if (!this.addresses || !this.addresses.entryPointAddress) {
12309
12318
  throw new InternalFailureError2(
12310
12319
  ErrorCode4.AddressNotFound,
@@ -12329,7 +12338,9 @@ var Chain = class _Chain {
12329
12338
  entryPointAddress: this.addresses.entryPointAddress,
12330
12339
  userOp: estimationUserOp
12331
12340
  },
12332
- apiKey: globalThis.globalEnvOption.apiKey
12341
+ apiKey: globalThis.globalEnvOption.apiKey,
12342
+ logger: options?.logger,
12343
+ signal: options?.signal
12333
12344
  });
12334
12345
  if (!preVerificationGas || !verificationGasLimit || !callGasLimit) {
12335
12346
  throw new Error(
@@ -12345,20 +12356,25 @@ var Chain = class _Chain {
12345
12356
  verificationGasLimit = BigInt(verificationGasLimit) + 200000n;
12346
12357
  return { preVerificationGas, verificationGasLimit, callGasLimit };
12347
12358
  }
12348
- async getTxId(userOpHash, timeout = 6e4, interval = 5e3, fromBlock) {
12359
+ async getTxId(userOpHash, timeout = 6e4, interval = 5e3, fromBlock, options) {
12349
12360
  const endtime = Date.now() + timeout;
12350
- const client = await this.getClient();
12351
- const entryPointAddress = await this.getAddress("entryPointAddress");
12361
+ const client = await this.getClient(options);
12362
+ const entryPointAddress = await this.getAddress(
12363
+ "entryPointAddress",
12364
+ options
12365
+ );
12352
12366
  const fromBlockFinal = fromBlock || await client.getBlockNumber() - 100n;
12353
12367
  while (Date.now() < endtime) {
12354
12368
  let events;
12355
- if (await client.getChainId() === 84531 || await client.getChainId() === 36865) {
12369
+ const chainId = await client.getChainId();
12370
+ if (chainId === 84531 || chainId === 36865) {
12356
12371
  events = await ENTRYPOINT_CONTRACT_INTERFACE.getLog(
12357
12372
  entryPointAddress,
12358
12373
  "UserOperationEvent",
12359
12374
  { userOpHash },
12360
12375
  client,
12361
- fromBlockFinal
12376
+ fromBlockFinal,
12377
+ options
12362
12378
  );
12363
12379
  } else {
12364
12380
  const filter = await ENTRYPOINT_CONTRACT_INTERFACE.createFilter(
@@ -12366,7 +12382,8 @@ var Chain = class _Chain {
12366
12382
  "UserOperationEvent",
12367
12383
  [userOpHash],
12368
12384
  client,
12369
- fromBlockFinal
12385
+ fromBlockFinal,
12386
+ options
12370
12387
  );
12371
12388
  events = await client.getFilterLogs({ filter });
12372
12389
  }
@@ -12377,8 +12394,8 @@ var Chain = class _Chain {
12377
12394
  }
12378
12395
  return null;
12379
12396
  }
12380
- async addressIsContract(address) {
12381
- return isContract(address, await this.getClient());
12397
+ async addressIsContract(address, options) {
12398
+ return isContract(address, await this.getClient(options));
12382
12399
  }
12383
12400
  };
12384
12401
 
@@ -12406,33 +12423,43 @@ var NFT = class _NFT {
12406
12423
  }
12407
12424
  }
12408
12425
  async approve(spender, tokenId, options = globalThis.globalEnvOption) {
12409
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12426
+ const chain = await Chain.getChain(
12427
+ { chainIdentifier: options.chain },
12428
+ options
12429
+ );
12410
12430
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12411
- await this.getAddress(),
12431
+ await this.getAddress(options),
12412
12432
  "approve",
12413
12433
  [spender, tokenId]
12414
12434
  );
12415
12435
  return { ...data, chain };
12416
12436
  }
12417
12437
  async ownerOf(tokenId, options = globalThis.globalEnvOption) {
12418
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12438
+ const chain = await Chain.getChain(
12439
+ { chainIdentifier: options.chain },
12440
+ options
12441
+ );
12419
12442
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12420
- await this.getAddress(),
12443
+ await this.getAddress(options),
12421
12444
  "ownerOf",
12422
12445
  [tokenId],
12423
- chain
12446
+ chain,
12447
+ options
12424
12448
  );
12425
12449
  }
12426
12450
  async approveForAll(spender, options = globalThis.globalEnvOption) {
12427
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12451
+ const chain = await Chain.getChain(
12452
+ { chainIdentifier: options.chain },
12453
+ options
12454
+ );
12428
12455
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12429
- await this.getAddress(),
12456
+ await this.getAddress(options),
12430
12457
  "setApprovalForAll",
12431
12458
  [spender, true]
12432
12459
  );
12433
12460
  return { ...data, chain };
12434
12461
  }
12435
- async getAddress() {
12462
+ async getAddress(options) {
12436
12463
  if (!this.address) {
12437
12464
  if (!this.name) {
12438
12465
  throw new InvalidParameterError4(
@@ -12446,7 +12473,9 @@ var NFT = class _NFT {
12446
12473
  }
12447
12474
  const nft = await getNftAddress({
12448
12475
  name: this.name,
12449
- apiKey: globalThis.globalEnvOption.apiKey
12476
+ apiKey: globalThis.globalEnvOption.apiKey,
12477
+ logger: options?.logger,
12478
+ signal: options?.signal
12450
12479
  });
12451
12480
  return nft.address;
12452
12481
  }
@@ -12454,47 +12483,66 @@ var NFT = class _NFT {
12454
12483
  }
12455
12484
  async getName(options = globalThis.globalEnvOption) {
12456
12485
  if (!this.name && this.address) {
12457
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12486
+ const chain = await Chain.getChain(
12487
+ { chainIdentifier: options.chain },
12488
+ options
12489
+ );
12458
12490
  const nft = await getNftName({
12459
- chainId: await chain.getChainId(),
12491
+ chainId: await chain.getChainId(options),
12460
12492
  nftAddress: this.address,
12461
- apiKey: globalThis.globalEnvOption.apiKey
12493
+ apiKey: globalThis.globalEnvOption.apiKey,
12494
+ logger: options.logger,
12495
+ signal: options.signal
12462
12496
  });
12463
12497
  return nft.name;
12464
12498
  }
12465
12499
  return this.name;
12466
12500
  }
12467
12501
  async getBalance(address, options = globalThis.globalEnvOption) {
12468
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12502
+ const chain = await Chain.getChain(
12503
+ { chainIdentifier: options.chain },
12504
+ options
12505
+ );
12469
12506
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12470
- await this.getAddress(),
12507
+ await this.getAddress(options),
12471
12508
  "balanceOf",
12472
12509
  [address],
12473
- chain
12510
+ chain,
12511
+ options
12474
12512
  );
12475
12513
  }
12476
12514
  async getApproved(tokenId, options = globalThis.globalEnvOption) {
12477
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12515
+ const chain = await Chain.getChain(
12516
+ { chainIdentifier: options.chain },
12517
+ options
12518
+ );
12478
12519
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12479
- await this.getAddress(),
12520
+ await this.getAddress(options),
12480
12521
  "getApproved",
12481
12522
  [tokenId],
12482
- chain
12523
+ chain,
12524
+ options
12483
12525
  );
12484
12526
  }
12485
12527
  async revokeForAll(spender, options = globalThis.globalEnvOption) {
12486
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12528
+ const chain = await Chain.getChain(
12529
+ { chainIdentifier: options.chain },
12530
+ options
12531
+ );
12487
12532
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12488
- await this.getAddress(),
12533
+ await this.getAddress(options),
12489
12534
  "setApprovalForAll",
12490
12535
  [spender, false]
12491
12536
  );
12492
12537
  return { ...data, chain };
12493
12538
  }
12494
12539
  async transfer(sender, spender, tokenId, options = globalThis.globalEnvOption) {
12495
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12540
+ const chain = await Chain.getChain(
12541
+ { chainIdentifier: options.chain },
12542
+ options
12543
+ );
12496
12544
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12497
- await this.getAddress(),
12545
+ await this.getAddress(options),
12498
12546
  "transferFrom",
12499
12547
  [sender, spender, tokenId]
12500
12548
  );
@@ -12508,9 +12556,9 @@ var NFT = class _NFT {
12508
12556
  const nft = new _NFT(data);
12509
12557
  return await nft.approveForAll(spender, options);
12510
12558
  }
12511
- static async getAddress(data) {
12559
+ static async getAddress(data, options) {
12512
12560
  const nft = new _NFT(data);
12513
- return await nft.getAddress();
12561
+ return await nft.getAddress(options);
12514
12562
  }
12515
12563
  static async getApproved(data, tokenId, options = globalThis.globalEnvOption) {
12516
12564
  const nft = new _NFT(data);
@@ -12559,13 +12607,17 @@ var Operation = class _Operation {
12559
12607
  static convertTypeToObject(op) {
12560
12608
  return new _Operation(op.userOp, op);
12561
12609
  }
12562
- async getOpHash(chain) {
12563
- const entryPointAddress = await chain.getAddress("entryPointAddress");
12610
+ async getOpHash(chain, options) {
12611
+ const entryPointAddress = await chain.getAddress(
12612
+ "entryPointAddress",
12613
+ options
12614
+ );
12564
12615
  return await ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(
12565
12616
  entryPointAddress,
12566
12617
  "getUserOpHash",
12567
12618
  [this.userOp],
12568
- chain
12619
+ chain,
12620
+ options
12569
12621
  );
12570
12622
  }
12571
12623
  getMaxTxCost() {
@@ -12584,16 +12636,22 @@ var Operation = class _Operation {
12584
12636
  if (!this.userOp.signature || this.userOp.signature === "0x") {
12585
12637
  this.userOp.signature = await auth.getEstimateGasSignature(userId, this);
12586
12638
  }
12587
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12588
- const res = await chain.estimateOpGas({
12589
- ...this.userOp,
12590
- paymasterAndData: "0x",
12591
- maxFeePerGas: 0n,
12592
- maxPriorityFeePerGas: 0n,
12593
- preVerificationGas: 0n,
12594
- callGasLimit: 0n,
12595
- verificationGasLimit: BigInt(1e7)
12596
- });
12639
+ const chain = await Chain.getChain(
12640
+ { chainIdentifier: options.chain },
12641
+ options
12642
+ );
12643
+ const res = await chain.estimateOpGas(
12644
+ {
12645
+ ...this.userOp,
12646
+ paymasterAndData: "0x",
12647
+ maxFeePerGas: 0n,
12648
+ maxPriorityFeePerGas: 0n,
12649
+ preVerificationGas: 0n,
12650
+ callGasLimit: 0n,
12651
+ verificationGasLimit: BigInt(1e7)
12652
+ },
12653
+ options
12654
+ );
12597
12655
  this.userOp.preVerificationGas = res.preVerificationGas;
12598
12656
  this.userOp.verificationGasLimit = res.verificationGasLimit;
12599
12657
  this.userOp.callGasLimit = res.callGasLimit;
@@ -12716,17 +12774,25 @@ var Token = class _Token {
12716
12774
  }
12717
12775
  this.symbol = input.toLowerCase();
12718
12776
  }
12719
- async getAddress() {
12720
- const chainId = await this.chain.getChainId();
12777
+ async getAddress(options) {
12778
+ const chainId = await this.chain.getChainId(options);
12721
12779
  if (this.isNative) {
12722
12780
  const nativeName = wrappedNativeTokens[this.symbol];
12723
- return await getTokenAddressBySymbolAndChainId(nativeName, chainId);
12781
+ return await getTokenAddressBySymbolAndChainId(
12782
+ nativeName,
12783
+ chainId,
12784
+ options
12785
+ );
12724
12786
  }
12725
12787
  if (this.address) {
12726
12788
  return this.address;
12727
12789
  }
12728
12790
  if (this.symbol) {
12729
- return await getTokenAddressBySymbolAndChainId(this.symbol, chainId);
12791
+ return await getTokenAddressBySymbolAndChainId(
12792
+ this.symbol,
12793
+ chainId,
12794
+ options
12795
+ );
12730
12796
  }
12731
12797
  throw new InternalFailureError3(
12732
12798
  ErrorCode6.ServerMissingData,
@@ -12737,39 +12803,41 @@ var Token = class _Token {
12737
12803
  "https://docs.fun.xyz"
12738
12804
  );
12739
12805
  }
12740
- async getDecimals() {
12806
+ async getDecimals(options) {
12741
12807
  if (this.isNative) {
12742
12808
  return 18n;
12743
12809
  }
12744
12810
  return await ERC20_CONTRACT_INTERFACE.readFromChain(
12745
- await this.getAddress(),
12811
+ await this.getAddress(options),
12746
12812
  "decimals",
12747
12813
  [],
12748
- this.chain
12814
+ this.chain,
12815
+ options
12749
12816
  );
12750
12817
  }
12751
- async getBalance(address) {
12752
- const amount = await this.getBalanceBN(address);
12753
- const decimals = await this.getDecimals();
12818
+ async getBalance(address, options) {
12819
+ const amount = await this.getBalanceBN(address, options);
12820
+ const decimals = await this.getDecimals(options);
12754
12821
  return formatUnits2(amount, Number(decimals));
12755
12822
  }
12756
- async getBalanceBN(address) {
12823
+ async getBalanceBN(address, options) {
12757
12824
  const chain = this.chain;
12758
12825
  let amount = 0n;
12759
12826
  if (this.isNative) {
12760
- const client = await chain.getClient();
12827
+ const client = await chain.getClient(options);
12761
12828
  amount = await client.getBalance({ address });
12762
12829
  } else {
12763
12830
  amount = await ERC20_CONTRACT_INTERFACE.readFromChain(
12764
- await this.getAddress(),
12831
+ await this.getAddress(options),
12765
12832
  "balanceOf",
12766
12833
  [address],
12767
- chain
12834
+ chain,
12835
+ options
12768
12836
  );
12769
12837
  }
12770
12838
  return amount;
12771
12839
  }
12772
- async getApproval(owner, spender) {
12840
+ async getApproval(owner, spender, options) {
12773
12841
  if (this.isNative) {
12774
12842
  throw new InvalidParameterError5(
12775
12843
  ErrorCode6.InvalidParameter,
@@ -12783,66 +12851,67 @@ var Token = class _Token {
12783
12851
  const chain = this.chain;
12784
12852
  return BigInt(
12785
12853
  await ERC20_CONTRACT_INTERFACE.readFromChain(
12786
- await this.getAddress(),
12854
+ await this.getAddress(options),
12787
12855
  "allowance",
12788
12856
  [owner, spender],
12789
- chain
12857
+ chain,
12858
+ options
12790
12859
  )
12791
12860
  );
12792
12861
  }
12793
- async getDecimalAmount(amount) {
12794
- const decimals = await this.getDecimals();
12862
+ async getDecimalAmount(amount, options) {
12863
+ const decimals = await this.getDecimals(options);
12795
12864
  return parseUnits(`${amount}`, Number(decimals));
12796
12865
  }
12797
- async approve(spender, amount) {
12798
- const amountDec = await this.getDecimalAmount(amount);
12866
+ async approve(spender, amount, options) {
12867
+ const amountDec = await this.getDecimalAmount(amount, options);
12799
12868
  const calldata = ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
12800
- await this.getAddress(),
12869
+ await this.getAddress(options),
12801
12870
  "approve",
12802
12871
  [spender, amountDec]
12803
12872
  );
12804
12873
  const { to, data, value } = calldata;
12805
12874
  return { to, data, value };
12806
12875
  }
12807
- async transfer(spender, amount) {
12808
- const amountDec = await this.getDecimalAmount(amount);
12876
+ async transfer(spender, amount, options) {
12877
+ const amountDec = await this.getDecimalAmount(amount, options);
12809
12878
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
12810
- await this.getAddress(),
12879
+ await this.getAddress(options),
12811
12880
  "transfer",
12812
12881
  [spender, amountDec]
12813
12882
  );
12814
12883
  }
12815
- static async getAddress(data, chain) {
12884
+ static async getAddress(data, chain, options) {
12816
12885
  const token = new _Token(data, chain);
12817
- return await token.getAddress();
12886
+ return await token.getAddress(options);
12818
12887
  }
12819
- static async getDecimals(data, chain) {
12888
+ static async getDecimals(data, chain, options) {
12820
12889
  const token = new _Token(data, chain);
12821
- return await token.getDecimals();
12890
+ return await token.getDecimals(options);
12822
12891
  }
12823
- static async getBalance(data, address, chain) {
12892
+ static async getBalance(data, address, chain, options) {
12824
12893
  const token = new _Token(data, chain);
12825
- return await token.getBalance(address);
12894
+ return await token.getBalance(address, options);
12826
12895
  }
12827
- static async getBalanceBN(data, address, chain) {
12896
+ static async getBalanceBN(data, address, chain, options) {
12828
12897
  const token = new _Token(data, chain);
12829
- return await token.getBalanceBN(address);
12898
+ return await token.getBalanceBN(address, options);
12830
12899
  }
12831
- static async getApproval(data, owner, spender, chain) {
12900
+ static async getApproval(data, owner, spender, chain, options) {
12832
12901
  const token = new _Token(data, chain);
12833
- return await token.getApproval(owner, spender);
12902
+ return await token.getApproval(owner, spender, options);
12834
12903
  }
12835
- static async getDecimalAmount(data, amount, chain) {
12904
+ static async getDecimalAmount(data, amount, chain, options) {
12836
12905
  const token = new _Token(data, chain);
12837
- return await token.getDecimalAmount(amount);
12906
+ return await token.getDecimalAmount(amount, options);
12838
12907
  }
12839
- static async approve(data, spender, amount, chain) {
12908
+ static async approve(data, spender, amount, chain, options) {
12840
12909
  const token = new _Token(data, chain);
12841
- return await token.approve(spender, amount);
12910
+ return await token.approve(spender, amount, options);
12842
12911
  }
12843
- static async transfer(data, spender, amount, chain) {
12912
+ static async transfer(data, spender, amount, chain, options) {
12844
12913
  const token = new _Token(data, chain);
12845
- return await token.transfer(spender, amount);
12914
+ return await token.transfer(spender, amount, options);
12846
12915
  }
12847
12916
  static isNative(data) {
12848
12917
  return data.toLowerCase() in wrappedNativeTokens;
@@ -12855,8 +12924,8 @@ var ContractInterface = class {
12855
12924
  constructor(abi) {
12856
12925
  this.abi = abi;
12857
12926
  }
12858
- async readFromChain(address, functionName, args, chainOrClient) {
12859
- const client = await parseClient(chainOrClient);
12927
+ async readFromChain(address, functionName, args, chainOrClient, options) {
12928
+ const client = await parseClient(chainOrClient, options);
12860
12929
  try {
12861
12930
  return await client.readContract({
12862
12931
  abi: this.abi,
@@ -12877,15 +12946,16 @@ var ContractInterface = class {
12877
12946
  );
12878
12947
  }
12879
12948
  }
12880
- async batchReadFromChain(address, chainOrClient, calls) {
12881
- const client = await parseClient(chainOrClient);
12949
+ async batchReadFromChain(address, chainOrClient, calls, options) {
12950
+ const client = await parseClient(chainOrClient, options);
12882
12951
  return await Promise.all(
12883
12952
  calls.map(async (call) => {
12884
12953
  return this.readFromChain(
12885
12954
  address,
12886
12955
  call.functionName,
12887
12956
  call.args ? call.args : [],
12888
- client
12957
+ client,
12958
+ options
12889
12959
  );
12890
12960
  })
12891
12961
  );
@@ -12905,8 +12975,8 @@ var ContractInterface = class {
12905
12975
  args
12906
12976
  });
12907
12977
  }
12908
- async createFilter(address, eventName, args, chainOrClient, fromBlock) {
12909
- const client = await parseClient(chainOrClient);
12978
+ async createFilter(address, eventName, args, chainOrClient, fromBlock, options) {
12979
+ const client = await parseClient(chainOrClient, options);
12910
12980
  return await client.createContractEventFilter({
12911
12981
  abi: this.abi,
12912
12982
  address,
@@ -12915,8 +12985,8 @@ var ContractInterface = class {
12915
12985
  fromBlock
12916
12986
  });
12917
12987
  }
12918
- async getLog(address, name, args, chainOrClient, fromBlock) {
12919
- const client = await parseClient(chainOrClient);
12988
+ async getLog(address, name, args, chainOrClient, fromBlock, options) {
12989
+ const client = await parseClient(chainOrClient, options);
12920
12990
  const event = getItemFromAbi(this.abi, name, "event");
12921
12991
  return await client.getLogs({
12922
12992
  address,
@@ -12926,10 +12996,10 @@ var ContractInterface = class {
12926
12996
  });
12927
12997
  }
12928
12998
  };
12929
- var parseClient = async (chainOrClient) => {
12999
+ var parseClient = async (chainOrClient, options) => {
12930
13000
  if (chainOrClient instanceof Chain) {
12931
13001
  const chain = chainOrClient;
12932
- return await chain.getClient();
13002
+ return await chain.getClient(options);
12933
13003
  }
12934
13004
  if (typeof chainOrClient.readContract === "function") {
12935
13005
  return chainOrClient;
@@ -13282,9 +13352,9 @@ var Auth = class {
13282
13352
  * @param {boolean} isGroupOp - Whether the operation is a group operation (default: false).
13283
13353
  * @returns {Promise<Hex>} The signature of the operation.
13284
13354
  */
13285
- async signOp(operation, chain, isGroupOp = false) {
13355
+ async signOp(operation, chain, isGroupOp = false, options) {
13286
13356
  await this.init();
13287
- const opHash = await operation.getOpHash(chain);
13357
+ const opHash = await operation.getOpHash(chain, options);
13288
13358
  return await this.signHash(opHash, isGroupOp);
13289
13359
  }
13290
13360
  /**
@@ -13324,12 +13394,13 @@ var Auth = class {
13324
13394
  * @param {boolean} skipDBActions - Whether to skip database actions (default: false).
13325
13395
  * @returns {Promise<Hex>} The generated unique ID for the wallet.
13326
13396
  */
13327
- async getWalletUniqueId(index = 0, skipDBActions = false) {
13397
+ async getWalletUniqueId(index = 0, skipDBActions = false, options) {
13328
13398
  await this.init();
13329
13399
  const authUniqueId = await getAuthUniqueId(
13330
13400
  this.authId,
13331
13401
  await this.getAddress(),
13332
- skipDBActions
13402
+ skipDBActions,
13403
+ options
13333
13404
  );
13334
13405
  return keccak2564(toBytes5(`${authUniqueId}-${index}`));
13335
13406
  }
@@ -13341,8 +13412,11 @@ var Auth = class {
13341
13412
  */
13342
13413
  async sendTx(txData, options = globalThis.globalEnvOption) {
13343
13414
  await this.init();
13344
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
13345
- const chainId = await chain.getChainId();
13415
+ const chain = await Chain.getChain(
13416
+ { chainIdentifier: options.chain },
13417
+ options
13418
+ );
13419
+ const chainId = await chain.getChainId(options);
13346
13420
  const { to, data } = txData;
13347
13421
  const { value = 0n } = txData;
13348
13422
  if (!chain || !chainId) {
@@ -13355,11 +13429,11 @@ var Auth = class {
13355
13429
  "https://docs.fun.xyz"
13356
13430
  );
13357
13431
  }
13358
- const client = await chain.getClient();
13432
+ const client = await chain.getClient(options);
13359
13433
  const txClient = this.client ?? createWalletClient2({
13360
13434
  account: this.signer,
13361
13435
  transport: http2(client.transport.url),
13362
- chain: chains[preProcessesChains[await chain.getChainId()]]
13436
+ chain: chains[preProcessesChains[await chain.getChainId(options)]]
13363
13437
  });
13364
13438
  let tx;
13365
13439
  let maxFee;
@@ -13367,7 +13441,7 @@ var Auth = class {
13367
13441
  if (gasSpecificChain2[chainId]) {
13368
13442
  const { backupFee, backupPriorityFee, gasStationUrl } = gasSpecificChain2[chainId];
13369
13443
  try {
13370
- const { standard } = await getGasStation(gasStationUrl);
13444
+ const { standard } = await getGasStation(gasStationUrl, options);
13371
13445
  maxPriorityFee = standard.maxPriorityFee;
13372
13446
  maxFee = standard.maxFee;
13373
13447
  } catch (_err) {
@@ -13388,7 +13462,7 @@ var Auth = class {
13388
13462
  ...tx,
13389
13463
  account: this.signer ?? this.account,
13390
13464
  // TODO: Handle missing account?
13391
- chain: chains[preProcessesChains[await chain.getChainId()]]
13465
+ chain: chains[preProcessesChains[await chain.getChainId(options)]]
13392
13466
  });
13393
13467
  if (chainId !== "1" && chainId !== "5") {
13394
13468
  return await client.waitForTransactionReceipt({
@@ -13433,13 +13507,15 @@ var Auth = class {
13433
13507
  * @param {string} chainId - The chain identifier.
13434
13508
  * @returns {Promise<Hex[]>} An array of user IDs associated with the wallet address.
13435
13509
  */
13436
- async getUserIds(wallet, chainId) {
13510
+ async getUserIds(wallet, chainId, options) {
13437
13511
  await this.init();
13438
13512
  return await getUserWalletIdentities({
13439
13513
  authId: this.authId,
13440
13514
  chainId,
13441
13515
  walletAddr: wallet,
13442
- apiKey: globalThis.globalEnvOption.apiKey
13516
+ apiKey: globalThis.globalEnvOption.apiKey,
13517
+ logger: options?.logger,
13518
+ signal: options?.signal
13443
13519
  });
13444
13520
  }
13445
13521
  /**
@@ -13447,13 +13523,15 @@ var Auth = class {
13447
13523
  * @param {string} [chainId] - Optional chain identifier.
13448
13524
  * @returns {Promise<Wallet[]>} An array of wallet objects associated with the address.
13449
13525
  */
13450
- async getWallets(chainId) {
13526
+ async getWallets(chainId, options) {
13451
13527
  await this.init();
13452
13528
  try {
13453
13529
  return await getUserWalletsByAddr({
13454
13530
  addr: await this.getAddress(),
13455
13531
  chainId,
13456
- apiKey: globalThis.globalEnvOption.apiKey
13532
+ apiKey: globalThis.globalEnvOption.apiKey,
13533
+ logger: options?.logger,
13534
+ signal: options?.signal
13457
13535
  });
13458
13536
  } catch (err) {
13459
13537
  if (err instanceof ResourceNotFoundError4) {
@@ -13698,15 +13776,18 @@ var MerkleTree = class {
13698
13776
  };
13699
13777
 
13700
13778
  // src/actions/AccessControl.ts
13701
- var createFeeRecipientAndTokenMerkleTree = async (params) => {
13779
+ var createFeeRecipientAndTokenMerkleTree = async (params, txOptions) => {
13702
13780
  const recipients = (params.feeRecipientWhitelist ?? []).map(
13703
13781
  (recipient) => getAddress(recipient)
13704
13782
  );
13705
- const options = globalThis.globalEnvOption;
13706
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
13783
+ const chain = await Chain.getChain(
13784
+ // TODO: Temporary fallback, remove after refactoring -- Panda
13785
+ { chainIdentifier: globalThis.globalEnvOption.chain },
13786
+ txOptions
13787
+ );
13707
13788
  const tokens = await Promise.all(
13708
13789
  (params.feeTokenWhitelist ?? []).map(
13709
- (token) => Token.getAddress(token, chain)
13790
+ (token) => Token.getAddress(token, chain, txOptions)
13710
13791
  )
13711
13792
  );
13712
13793
  const feeRecipientAndTokenMerkleTree = new MerkleTree([
@@ -13773,8 +13854,11 @@ var createSessionKeyTransactionParams = async (params, txOptions = globalThis.gl
13773
13854
  "addUserToRole",
13774
13855
  [roleId, userId]
13775
13856
  );
13776
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13777
- const rbacAddress = await chain.getAddress("rbacAddress");
13857
+ const chain = await Chain.getChain(
13858
+ { chainIdentifier: txOptions.chain },
13859
+ txOptions
13860
+ );
13861
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13778
13862
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13779
13863
  rbacAddress,
13780
13864
  "multiCall",
@@ -13793,8 +13877,11 @@ var createSessionUser = async (auth, params) => {
13793
13877
  );
13794
13878
  };
13795
13879
  var addOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13796
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13797
- const rbacAddress = await chain.getAddress("rbacAddress");
13880
+ const chain = await Chain.getChain(
13881
+ { chainIdentifier: txOptions.chain },
13882
+ txOptions
13883
+ );
13884
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13798
13885
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13799
13886
  rbacAddress,
13800
13887
  "addOwner",
@@ -13802,8 +13889,11 @@ var addOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) =>
13802
13889
  );
13803
13890
  };
13804
13891
  var removeOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13805
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13806
- const rbacAddress = await chain.getAddress("rbacAddress");
13892
+ const chain = await Chain.getChain(
13893
+ { chainIdentifier: txOptions.chain },
13894
+ txOptions
13895
+ );
13896
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13807
13897
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13808
13898
  rbacAddress,
13809
13899
  "removeOwner",
@@ -13836,8 +13926,11 @@ var createGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13836
13926
  group.userIds = group.userIds.map((userId) => {
13837
13927
  return pad7(userId, { size: 32 });
13838
13928
  });
13839
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13840
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13929
+ const chain = await Chain.getChain(
13930
+ { chainIdentifier: txOptions.chain },
13931
+ txOptions
13932
+ );
13933
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13841
13934
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13842
13935
  userAuthAddress,
13843
13936
  "createMultiSigGroup",
@@ -13849,8 +13942,11 @@ var updateGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13849
13942
  group.userIds = group.userIds.map((userId) => {
13850
13943
  return pad7(userId, { size: 32 });
13851
13944
  }).sort((a, b) => b.localeCompare(a));
13852
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13853
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13945
+ const chain = await Chain.getChain(
13946
+ { chainIdentifier: txOptions.chain },
13947
+ txOptions
13948
+ );
13949
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13854
13950
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13855
13951
  userAuthAddress,
13856
13952
  "updateMultiSigGroup",
@@ -13859,8 +13955,11 @@ var updateGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13859
13955
  };
13860
13956
  var removeGroupTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13861
13957
  const { groupId } = params;
13862
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13863
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13958
+ const chain = await Chain.getChain(
13959
+ { chainIdentifier: txOptions.chain },
13960
+ txOptions
13961
+ );
13962
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13864
13963
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13865
13964
  userAuthAddress,
13866
13965
  "deleteMultiSigGroup",
@@ -13885,8 +13984,11 @@ var isFinishUnstakeParams = (input) => {
13885
13984
  return input.recipient !== void 0;
13886
13985
  };
13887
13986
  var stakeTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
13888
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13889
- const lidoAddress = getSteth(await chain.getChainId());
13987
+ const chain = await Chain.getChain(
13988
+ { chainIdentifier: txOptions.chain },
13989
+ txOptions
13990
+ );
13991
+ const lidoAddress = getSteth(await chain.getChainId(txOptions));
13890
13992
  return { to: lidoAddress, value: parseEther2(`${params.amount}`), data: "0x" };
13891
13993
  };
13892
13994
  var requestUnstakeTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
@@ -13900,8 +14002,11 @@ var requestUnstakeTransactionParams = async (params, txOptions = globalThis.glob
13900
14002
  "https://docs.fun.xyz"
13901
14003
  );
13902
14004
  }
13903
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13904
- const chainId = await chain.getChainId();
14005
+ const chain = await Chain.getChain(
14006
+ { chainIdentifier: txOptions.chain },
14007
+ txOptions
14008
+ );
14009
+ const chainId = await chain.getChainId(txOptions);
13905
14010
  const steth = getSteth(chainId);
13906
14011
  const withdrawalQueue = getWithdrawalQueue(chainId);
13907
14012
  if (!steth || !withdrawalQueue || steth.length === 0 || withdrawalQueue.length === 0) {
@@ -13931,7 +14036,10 @@ var requestUnstakeTransactionParams = async (params, txOptions = globalThis.glob
13931
14036
  params.recipient
13932
14037
  ]
13933
14038
  );
13934
- const approveAndExecAddress = await chain.getAddress("approveAndExecAddress");
14039
+ const approveAndExecAddress = await chain.getAddress(
14040
+ "approveAndExecAddress",
14041
+ txOptions
14042
+ );
13935
14043
  return APPROVE_AND_EXEC_CONTRACT_INTERFACE.encodeTransactionParams(
13936
14044
  approveAndExecAddress,
13937
14045
  "approveAndExecute",
@@ -13949,8 +14057,13 @@ var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globa
13949
14057
  "https://docs.fun.xyz"
13950
14058
  );
13951
14059
  }
13952
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13953
- const withdrawQueueAddress = getWithdrawalQueue(await chain.getChainId());
14060
+ const chain = await Chain.getChain(
14061
+ { chainIdentifier: txOptions.chain },
14062
+ txOptions
14063
+ );
14064
+ const withdrawQueueAddress = getWithdrawalQueue(
14065
+ await chain.getChainId(txOptions)
14066
+ );
13954
14067
  const readyToWithdrawRequestIds = (await getReadyToWithdrawRequests(params, txOptions)).slice(0, 5);
13955
14068
  if (readyToWithdrawRequestIds.length === 0) {
13956
14069
  throw new InvalidParameterError8(
@@ -13966,13 +14079,15 @@ var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globa
13966
14079
  withdrawQueueAddress,
13967
14080
  "getLastCheckpointIndex",
13968
14081
  [],
13969
- chain
14082
+ chain,
14083
+ txOptions
13970
14084
  );
13971
14085
  const hints = await getWithdrawQueueInterface().readFromChain(
13972
14086
  withdrawQueueAddress,
13973
14087
  "findCheckpointHints",
13974
14088
  [readyToWithdrawRequestIds, 1, lastCheckpoint],
13975
- chain
14089
+ chain,
14090
+ txOptions
13976
14091
  );
13977
14092
  if (!hints) {
13978
14093
  throw new InternalFailureError4(
@@ -14001,12 +14116,27 @@ var getReadyToWithdrawRequests = async (params, txOptions) => {
14001
14116
  "https://docs.fun.xyz"
14002
14117
  );
14003
14118
  }
14004
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
14119
+ const chain = await Chain.getChain(
14120
+ { chainIdentifier: txOptions.chain },
14121
+ txOptions
14122
+ );
14005
14123
  const withdrawalQueueAddr = getWithdrawalQueue(
14006
- await chain.getChainId()
14124
+ await chain.getChainId(txOptions)
14125
+ );
14126
+ const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(
14127
+ withdrawalQueueAddr,
14128
+ "getWithdrawalRequests",
14129
+ [params.walletAddress],
14130
+ chain,
14131
+ txOptions
14132
+ );
14133
+ const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(
14134
+ withdrawalQueueAddr,
14135
+ "getWithdrawalStatus",
14136
+ [withdrawalRequests],
14137
+ chain,
14138
+ txOptions
14007
14139
  );
14008
- const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalRequests", [params.walletAddress], chain);
14009
- const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalStatus", [withdrawalRequests], chain);
14010
14140
  const readyToWithdraw = [];
14011
14141
  for (let i = 0; i < withdrawalStatusTx.length; i++) {
14012
14142
  if (withdrawalStatusTx[i].isFinalized) {
@@ -14066,7 +14196,7 @@ var isERC721TransferParams = (obj) => {
14066
14196
  var isTokenTransferParams = (obj) => {
14067
14197
  return "amount" in obj && "token" in obj && "to" in obj;
14068
14198
  };
14069
- var erc721TransferTransactionParams = async (params) => {
14199
+ var erc721TransferTransactionParams = async (params, options) => {
14070
14200
  const { to, tokenId, collection, from } = params;
14071
14201
  if (!isAddress5(to ?? "") || !isAddress5(from ?? "")) {
14072
14202
  throw new InvalidParameterError9(
@@ -14078,14 +14208,14 @@ var erc721TransferTransactionParams = async (params) => {
14078
14208
  "https://docs.fun.xyz"
14079
14209
  );
14080
14210
  }
14081
- const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection);
14211
+ const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection, options);
14082
14212
  return ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
14083
14213
  tokenAddr,
14084
14214
  "transferFrom",
14085
14215
  [from, to, tokenId]
14086
14216
  );
14087
14217
  };
14088
- var tokenTransferTransactionParams = async (params, chain) => {
14218
+ var tokenTransferTransactionParams = async (params, chain, options) => {
14089
14219
  const { to, amount, token } = params;
14090
14220
  if (!isAddress5(to)) {
14091
14221
  throw new InvalidParameterError9(
@@ -14105,7 +14235,7 @@ var tokenTransferTransactionParams = async (params, chain) => {
14105
14235
  value: parseEther3(`${amount}`)
14106
14236
  };
14107
14237
  }
14108
- const tokenAddr = await tokenObj.getAddress();
14238
+ const tokenAddr = await tokenObj.getAddress(options);
14109
14239
  if (!tokenAddr) {
14110
14240
  throw new InvalidParameterError9(
14111
14241
  ErrorCode10.TokenNotFound,
@@ -14116,14 +14246,14 @@ var tokenTransferTransactionParams = async (params, chain) => {
14116
14246
  "https://docs.fun.xyz"
14117
14247
  );
14118
14248
  }
14119
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14249
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14120
14250
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14121
14251
  tokenAddr,
14122
14252
  "transfer",
14123
14253
  [to, convertedAmount]
14124
14254
  );
14125
14255
  };
14126
- var tokenTransferFromTransactionParams = async (params, chain) => {
14256
+ var tokenTransferFromTransactionParams = async (params, chain, options) => {
14127
14257
  const { to, amount, token, from } = params;
14128
14258
  if (!isAddress5(to ?? "") || !isAddress5(from ?? "")) {
14129
14259
  throw new InvalidParameterError9(
@@ -14143,7 +14273,7 @@ var tokenTransferFromTransactionParams = async (params, chain) => {
14143
14273
  value: parseEther3(`${amount}`)
14144
14274
  };
14145
14275
  }
14146
- const tokenAddr = await tokenObj.getAddress();
14276
+ const tokenAddr = await tokenObj.getAddress(options);
14147
14277
  if (!tokenAddr) {
14148
14278
  throw new InvalidParameterError9(
14149
14279
  ErrorCode10.TokenNotFound,
@@ -14154,7 +14284,7 @@ var tokenTransferFromTransactionParams = async (params, chain) => {
14154
14284
  "https://docs.fun.xyz"
14155
14285
  );
14156
14286
  }
14157
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14287
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14158
14288
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14159
14289
  tokenAddr,
14160
14290
  "transferFrom",
@@ -14167,7 +14297,7 @@ var isERC20ApproveParams = (obj) => {
14167
14297
  var isERC721ApproveParams = (obj) => {
14168
14298
  return "tokenId" in obj && "collection" in obj;
14169
14299
  };
14170
- var erc20ApproveTransactionParams = async (params) => {
14300
+ var erc20ApproveTransactionParams = async (params, options) => {
14171
14301
  const { spender, amount, token } = params;
14172
14302
  if (!isAddress5(spender ?? "")) {
14173
14303
  throw new InvalidParameterError9(
@@ -14179,18 +14309,19 @@ var erc20ApproveTransactionParams = async (params) => {
14179
14309
  "https://docs.fun.xyz"
14180
14310
  );
14181
14311
  }
14182
- const chain = await Chain.getChain({
14183
- chainIdentifier: globalThis.globalEnvOption.chain
14184
- });
14312
+ const chain = await Chain.getChain(
14313
+ { chainIdentifier: globalThis.globalEnvOption.chain },
14314
+ options
14315
+ );
14185
14316
  const tokenObj = new Token(token, chain);
14186
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14317
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14187
14318
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14188
- await tokenObj.getAddress(),
14319
+ await tokenObj.getAddress(options),
14189
14320
  "approve",
14190
14321
  [spender, convertedAmount]
14191
14322
  );
14192
14323
  };
14193
- var erc721ApproveTransactionParams = async (params) => {
14324
+ var erc721ApproveTransactionParams = async (params, options) => {
14194
14325
  const { spender, tokenId, collection } = params;
14195
14326
  if (!isAddress5(spender ?? "")) {
14196
14327
  throw new InvalidParameterError9(
@@ -14202,7 +14333,7 @@ var erc721ApproveTransactionParams = async (params) => {
14202
14333
  "https://docs.fun.xyz"
14203
14334
  );
14204
14335
  }
14205
- const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection);
14336
+ const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection, options);
14206
14337
  return ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
14207
14338
  tokenAddr,
14208
14339
  "approve",
@@ -14302,22 +14433,29 @@ var Sponsor = class {
14302
14433
  this.paymasterType = paymasterType;
14303
14434
  }
14304
14435
  async getPaymasterAddress(options = globalThis.globalEnvOption) {
14305
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14306
- const chainId = await chain.getChainId();
14436
+ const chain = await Chain.getChain(
14437
+ { chainIdentifier: options.chain },
14438
+ options
14439
+ );
14440
+ const chainId = await chain.getChainId(options);
14307
14441
  if (!this.paymasterAddress && chainId !== this.chainId) {
14308
- this.paymasterAddress = await chain.getAddress(this.name);
14442
+ this.paymasterAddress = await chain.getAddress(this.name, options);
14309
14443
  this.chainId = chainId;
14310
14444
  }
14311
14445
  return this.paymasterAddress;
14312
14446
  }
14313
14447
  /** True if the specified sponsor is in blacklist mode. **/
14314
14448
  async getListMode(sponsor, options = globalThis.globalEnvOption) {
14315
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14449
+ const chain = await Chain.getChain(
14450
+ { chainIdentifier: options.chain },
14451
+ options
14452
+ );
14316
14453
  return await this.contractInterface.readFromChain(
14317
14454
  await this.getPaymasterAddress(options),
14318
14455
  "getListMode",
14319
14456
  [sponsor],
14320
- chain
14457
+ chain,
14458
+ options
14321
14459
  );
14322
14460
  }
14323
14461
  async setToBlacklistMode() {
@@ -14416,8 +14554,16 @@ var CheckoutSponsor = class extends Sponsor {
14416
14554
  return paymasterAddress.toLowerCase();
14417
14555
  }
14418
14556
  async stake(_sponsor, amount, options) {
14419
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14420
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14557
+ const chain = await Chain.getChain(
14558
+ { chainIdentifier: options.chain },
14559
+ options
14560
+ );
14561
+ const amountdec = await Token.getDecimalAmount(
14562
+ "eth",
14563
+ amount,
14564
+ chain,
14565
+ options
14566
+ );
14421
14567
  return this.contractInterface.encodeTransactionParams(
14422
14568
  await this.getPaymasterAddress(),
14423
14569
  "deposit",
@@ -14426,8 +14572,16 @@ var CheckoutSponsor = class extends Sponsor {
14426
14572
  );
14427
14573
  }
14428
14574
  async unstake(receiver, amount, options) {
14429
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14430
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14575
+ const chain = await Chain.getChain(
14576
+ { chainIdentifier: options.chain },
14577
+ options
14578
+ );
14579
+ const amountdec = await Token.getDecimalAmount(
14580
+ "eth",
14581
+ amount,
14582
+ chain,
14583
+ options
14584
+ );
14431
14585
  return this.contractInterface.encodeTransactionParams(
14432
14586
  await this.getPaymasterAddress(),
14433
14587
  "withdrawTo",
@@ -14500,9 +14654,15 @@ var GaslessSponsor = class extends Sponsor {
14500
14654
  }
14501
14655
  async getFunSponsorAddress(options = globalThis.globalEnvOption) {
14502
14656
  if (!this.sponsorAddress) {
14503
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14504
- if (GASLESS_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId())) {
14505
- this.sponsorAddress = await chain.getAddress("funGaslessSponsorAddress");
14657
+ const chain = await Chain.getChain(
14658
+ { chainIdentifier: options.chain },
14659
+ options
14660
+ );
14661
+ if (GASLESS_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId(options))) {
14662
+ this.sponsorAddress = await chain.getAddress(
14663
+ "funGaslessSponsorAddress",
14664
+ options
14665
+ );
14506
14666
  } else {
14507
14667
  throw new ResourceNotFoundError5(
14508
14668
  ErrorCode12.MissingParameter,
@@ -14510,7 +14670,7 @@ var GaslessSponsor = class extends Sponsor {
14510
14670
  "The network you are working with does not support gasless Fun Sponsor. You will need to run and manage your own gasless sponsor.",
14511
14671
  {
14512
14672
  gaslessSponsorSupportChains: GASLESS_SPONSOR_SUPPORT_CHAINS,
14513
- chain: await chain.getChainId()
14673
+ chain: await chain.getChainId(options)
14514
14674
  },
14515
14675
  "Manage your own gasless sponsor, or use a supported network.",
14516
14676
  "https://docs.fun.xyz"
@@ -14525,8 +14685,16 @@ var GaslessSponsor = class extends Sponsor {
14525
14685
  return concat3([paymasterAddress, sponsor]);
14526
14686
  }
14527
14687
  async stake(sponsor, amount, options = globalThis.globalEnvOption) {
14528
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14529
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14688
+ const chain = await Chain.getChain(
14689
+ { chainIdentifier: options.chain },
14690
+ options
14691
+ );
14692
+ const amountdec = await Token.getDecimalAmount(
14693
+ "eth",
14694
+ amount,
14695
+ chain,
14696
+ options
14697
+ );
14530
14698
  return this.contractInterface.encodeTransactionParams(
14531
14699
  await this.getPaymasterAddress(),
14532
14700
  "addDepositTo",
@@ -14535,8 +14703,16 @@ var GaslessSponsor = class extends Sponsor {
14535
14703
  );
14536
14704
  }
14537
14705
  async unstake(receiver, amount, options = globalThis.globalEnvOption) {
14538
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14539
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14706
+ const chain = await Chain.getChain(
14707
+ { chainIdentifier: options.chain },
14708
+ options
14709
+ );
14710
+ const amountdec = await Token.getDecimalAmount(
14711
+ "eth",
14712
+ amount,
14713
+ chain,
14714
+ options
14715
+ );
14540
14716
  return this.contractInterface.encodeTransactionParams(
14541
14717
  await this.getPaymasterAddress(),
14542
14718
  "withdrawDepositTo",
@@ -14544,28 +14720,39 @@ var GaslessSponsor = class extends Sponsor {
14544
14720
  );
14545
14721
  }
14546
14722
  async getUnlockBlock(sponsor, options = globalThis.globalEnvOption) {
14547
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14723
+ const chain = await Chain.getChain(
14724
+ { chainIdentifier: options.chain },
14725
+ options
14726
+ );
14548
14727
  return await this.contractInterface.readFromChain(
14549
14728
  await this.getPaymasterAddress(options),
14550
14729
  "getUnlockBlock",
14551
14730
  [sponsor],
14552
- chain
14731
+ chain,
14732
+ options
14553
14733
  );
14554
14734
  }
14555
14735
  async getLockState(sponsor, options = globalThis.globalEnvOption) {
14556
14736
  const unlockBlock = Number(await this.getUnlockBlock(sponsor, options));
14557
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14558
- const client = await chain.getClient();
14737
+ const chain = await Chain.getChain(
14738
+ { chainIdentifier: options.chain },
14739
+ options
14740
+ );
14741
+ const client = await chain.getClient(options);
14559
14742
  const currentBlock = await client.getBlockNumber();
14560
14743
  return unlockBlock === 0 || unlockBlock > currentBlock;
14561
14744
  }
14562
14745
  async getBalance(sponsor, options = globalThis.globalEnvOption) {
14563
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14746
+ const chain = await Chain.getChain(
14747
+ { chainIdentifier: options.chain },
14748
+ options
14749
+ );
14564
14750
  return await this.contractInterface.readFromChain(
14565
14751
  await this.getPaymasterAddress(options),
14566
14752
  "getBalance",
14567
14753
  [sponsor],
14568
- chain
14754
+ chain,
14755
+ options
14569
14756
  );
14570
14757
  }
14571
14758
  async lockDeposit() {
@@ -14583,21 +14770,29 @@ var GaslessSponsor = class extends Sponsor {
14583
14770
  );
14584
14771
  }
14585
14772
  async getSpenderBlacklistMode(spender, sponsor, options = globalThis.globalEnvOption) {
14586
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14773
+ const chain = await Chain.getChain(
14774
+ { chainIdentifier: options.chain },
14775
+ options
14776
+ );
14587
14777
  return await this.contractInterface.readFromChain(
14588
14778
  await this.getPaymasterAddress(options),
14589
14779
  "getSpenderBlacklistMode",
14590
14780
  [spender, sponsor],
14591
- chain
14781
+ chain,
14782
+ options
14592
14783
  );
14593
14784
  }
14594
14785
  async getSpenderWhitelistMode(spender, sponsor, options = globalThis.globalEnvOption) {
14595
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14786
+ const chain = await Chain.getChain(
14787
+ { chainIdentifier: options.chain },
14788
+ options
14789
+ );
14596
14790
  return await this.contractInterface.readFromChain(
14597
14791
  await this.getPaymasterAddress(options),
14598
14792
  "getSpenderWhitelistMode",
14599
14793
  [spender, sponsor],
14600
- chain
14794
+ chain,
14795
+ options
14601
14796
  );
14602
14797
  }
14603
14798
  };
@@ -14632,9 +14827,15 @@ var TokenSponsor = class extends Sponsor {
14632
14827
  }
14633
14828
  async getFunSponsorAddress(options = globalThis.globalEnvOption) {
14634
14829
  if (!this.sponsorAddress) {
14635
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14636
- if (TOKEN_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId())) {
14637
- this.sponsorAddress = await chain.getAddress("funTokenSponsorAddress");
14830
+ const chain = await Chain.getChain(
14831
+ { chainIdentifier: options.chain },
14832
+ options
14833
+ );
14834
+ if (TOKEN_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId(options))) {
14835
+ this.sponsorAddress = await chain.getAddress(
14836
+ "funTokenSponsorAddress",
14837
+ options
14838
+ );
14638
14839
  } else {
14639
14840
  throw new ResourceNotFoundError6(
14640
14841
  ErrorCode13.MissingParameter,
@@ -14642,7 +14843,7 @@ var TokenSponsor = class extends Sponsor {
14642
14843
  "The network you are working with does not support token Fun Sponsor. You will need to run and manage your own token sponsor.",
14643
14844
  {
14644
14845
  tokenSponsorSupportChains: TOKEN_SPONSOR_SUPPORT_CHAINS,
14645
- chain: await chain.getChainId()
14846
+ chain: await chain.getChainId(options)
14646
14847
  },
14647
14848
  "Manage your own token sponsor, or use a supported network",
14648
14849
  "https://docs.fun.xyz"
@@ -14652,40 +14853,56 @@ var TokenSponsor = class extends Sponsor {
14652
14853
  return this.sponsorAddress;
14653
14854
  }
14654
14855
  async getPaymasterAndData(options = globalThis.globalEnvOption) {
14655
- const chain = await Chain.getChain({
14656
- chainIdentifier: globalThis.globalEnvOption.chain
14657
- });
14658
- const tokenAddress = await Token.getAddress(this.token, chain);
14856
+ const chain = await Chain.getChain(
14857
+ {
14858
+ chainIdentifier: globalThis.globalEnvOption.chain
14859
+ },
14860
+ options
14861
+ );
14862
+ const tokenAddress = await Token.getAddress(this.token, chain, options);
14659
14863
  const paymasterAddress = await this.getPaymasterAddress(options);
14660
14864
  const sponsor = await this.getFunSponsorAddress(options);
14661
14865
  return concat4([paymasterAddress, sponsor, tokenAddress]);
14662
14866
  }
14663
14867
  async getPaymasterAndDataPermit(partialOp, walletAddr, userId, auth, options = globalThis.globalEnvOption) {
14664
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14868
+ const chain = await Chain.getChain(
14869
+ { chainIdentifier: options.chain },
14870
+ options
14871
+ );
14665
14872
  const estimateGasSignature = await auth.getEstimateGasSignature(
14666
14873
  userId,
14667
14874
  partialOp
14668
14875
  );
14669
14876
  partialOp.userOp.signature = estimateGasSignature.toLowerCase();
14670
14877
  const estimationPaymasterAddress = await chain.getAddress(
14671
- "estimationPaymasterAddress"
14878
+ "estimationPaymasterAddress",
14879
+ options
14672
14880
  );
14673
- const { callGasLimit, verificationGasLimit, preVerificationGas } = await chain.estimateOpGas({
14674
- ...partialOp.userOp,
14675
- paymasterAndData: estimationPaymasterAddress
14676
- });
14677
- const { maxFeePerGas } = await chain.getFeeData();
14881
+ const { callGasLimit, verificationGasLimit, preVerificationGas } = await chain.estimateOpGas(
14882
+ {
14883
+ ...partialOp.userOp,
14884
+ paymasterAndData: estimationPaymasterAddress
14885
+ },
14886
+ options
14887
+ );
14888
+ const { maxFeePerGas } = await chain.getFeeData(options);
14678
14889
  const paymasterAddress = await this.getPaymasterAddress(options);
14679
14890
  const requiredGas = (callGasLimit + (verificationGasLimit + 400000n) * 3n + preVerificationGas) * BigInt(maxFeePerGas);
14680
- const tokenAddress = await Token.getAddress(this.token, chain);
14891
+ const tokenAddress = await Token.getAddress(this.token, chain, options);
14681
14892
  const decAmount = await TOKEN_PAYMASTER_CONTRACT_INTERFACE.readFromChain(
14682
14893
  paymasterAddress,
14683
14894
  "getTokenValueOfEth",
14684
14895
  [tokenAddress, requiredGas],
14685
- chain
14896
+ chain,
14897
+ options
14898
+ );
14899
+ const nonce = await getWalletPermitNonce(
14900
+ walletAddr,
14901
+ chain,
14902
+ void 0,
14903
+ options
14686
14904
  );
14687
- const nonce = await getWalletPermitNonce(walletAddr, chain);
14688
- const client = await chain.getClient();
14905
+ const client = await chain.getClient(options);
14689
14906
  const chainId = await client.getChainId();
14690
14907
  const hash = getPermitHash(
14691
14908
  tokenAddress,
@@ -14719,8 +14936,13 @@ var TokenSponsor = class extends Sponsor {
14719
14936
  }
14720
14937
  async stake(sponsor, amount, options = globalThis.globalEnvOption) {
14721
14938
  const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
14722
- const chain = await Chain.getChain({ chainIdentifier });
14723
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14939
+ const chain = await Chain.getChain({ chainIdentifier }, options);
14940
+ const amountdec = await Token.getDecimalAmount(
14941
+ "eth",
14942
+ amount,
14943
+ chain,
14944
+ options
14945
+ );
14724
14946
  return this.contractInterface.encodeTransactionParams(
14725
14947
  await this.getPaymasterAddress(),
14726
14948
  "addEthDepositTo",
@@ -14730,8 +14952,13 @@ var TokenSponsor = class extends Sponsor {
14730
14952
  }
14731
14953
  async unstake(receiver, amount, options = globalThis.globalEnvOption) {
14732
14954
  const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
14733
- const chain = await Chain.getChain({ chainIdentifier });
14734
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14955
+ const chain = await Chain.getChain({ chainIdentifier }, options);
14956
+ const amountdec = await Token.getDecimalAmount(
14957
+ "eth",
14958
+ amount,
14959
+ chain,
14960
+ options
14961
+ );
14735
14962
  return this.contractInterface.encodeTransactionParams(
14736
14963
  await this.getPaymasterAddress(),
14737
14964
  "withdrawEthDepositTo",
@@ -14739,39 +14966,53 @@ var TokenSponsor = class extends Sponsor {
14739
14966
  );
14740
14967
  }
14741
14968
  async getUnlockBlock(sponsor, token, options = globalThis.globalEnvOption) {
14742
- const chain = await Chain.getChain({
14743
- chainIdentifier: globalThis.globalEnvOption.chain
14744
- });
14745
- const tokenAddr = await Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain);
14969
+ const chain = await Chain.getChain(
14970
+ {
14971
+ chainIdentifier: globalThis.globalEnvOption.chain
14972
+ },
14973
+ options
14974
+ );
14975
+ const tokenAddr = Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain, options);
14746
14976
  return (await this.getAllTokenData(tokenAddr, sponsor, options)).unlockBlock;
14747
14977
  }
14748
14978
  // false means unlocked, true means locked
14749
14979
  async getLockState(sponsor, token, options = globalThis.globalEnvOption) {
14750
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14751
- const tokenAddr = await Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain);
14980
+ const chain = await Chain.getChain(
14981
+ { chainIdentifier: options.chain },
14982
+ options
14983
+ );
14984
+ const tokenAddr = Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain, options);
14752
14985
  const unlockBlock = await this.getUnlockBlock(tokenAddr, sponsor);
14753
- const provider = await chain.getClient();
14986
+ const provider = await chain.getClient(options);
14754
14987
  const currentBlock = await provider.getBlockNumber();
14755
14988
  return unlockBlock === 0n || unlockBlock > currentBlock;
14756
14989
  }
14757
14990
  async getTokenInfo(token, options = globalThis.globalEnvOption) {
14758
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14759
- const tokenAddress = await Token.getAddress(token, chain);
14991
+ const chain = await Chain.getChain(
14992
+ { chainIdentifier: options.chain },
14993
+ options
14994
+ );
14995
+ const tokenAddress = await Token.getAddress(token, chain, options);
14760
14996
  return await this.contractInterface.readFromChain(
14761
14997
  await this.getPaymasterAddress(options),
14762
14998
  "getToken",
14763
14999
  [tokenAddress],
14764
- chain
15000
+ chain,
15001
+ options
14765
15002
  );
14766
15003
  }
14767
15004
  async getAllTokenData(spender, token, options = globalThis.globalEnvOption) {
14768
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14769
- const tokenAddress = await Token.getAddress(token, chain);
15005
+ const chain = await Chain.getChain(
15006
+ { chainIdentifier: options.chain },
15007
+ options
15008
+ );
15009
+ const tokenAddress = await Token.getAddress(token, chain, options);
14770
15010
  const data = await this.contractInterface.readFromChain(
14771
15011
  await this.getPaymasterAddress(options),
14772
15012
  "getAllTokenData",
14773
15013
  [tokenAddress, spender],
14774
- chain
15014
+ chain,
15015
+ options
14775
15016
  );
14776
15017
  return {
14777
15018
  unlockBlock: data[0],
@@ -14779,29 +15020,40 @@ var TokenSponsor = class extends Sponsor {
14779
15020
  };
14780
15021
  }
14781
15022
  async getTokenBalance(spender, token, options = globalThis.globalEnvOption) {
14782
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15023
+ const chain = await Chain.getChain(
15024
+ { chainIdentifier: options.chain },
15025
+ options
15026
+ );
14783
15027
  const tokenData = new Token(token, chain);
14784
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
15028
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14785
15029
  return await this.contractInterface.readFromChain(
14786
15030
  await this.getPaymasterAddress(options),
14787
15031
  "getTokenBalance",
14788
15032
  [tokenAddress, spender],
14789
- chain
15033
+ chain,
15034
+ options
14790
15035
  );
14791
15036
  }
14792
15037
  async getAllTokens(options = globalThis.globalEnvOption) {
14793
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15038
+ const chain = await Chain.getChain(
15039
+ { chainIdentifier: options.chain },
15040
+ options
15041
+ );
14794
15042
  return await this.contractInterface.readFromChain(
14795
15043
  await this.getPaymasterAddress(options),
14796
15044
  "getAllTokens",
14797
15045
  [],
14798
- chain
15046
+ chain,
15047
+ options
14799
15048
  );
14800
15049
  }
14801
15050
  async addUsableToken(oracle, token, aggregator, options = globalThis.globalEnvOption) {
14802
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14803
- const decimals = await Token.getDecimals(token, chain);
14804
- const tokenAddress = await Token.getAddress(token, chain);
15051
+ const chain = await Chain.getChain(
15052
+ { chainIdentifier: options.chain },
15053
+ options
15054
+ );
15055
+ const decimals = await Token.getDecimals(token, chain, options);
15056
+ const tokenAddress = await Token.getAddress(token, chain, options);
14805
15057
  const data = [oracle, tokenAddress, decimals, aggregator];
14806
15058
  return this.contractInterface.encodeTransactionParams(
14807
15059
  await this.getPaymasterAddress(),
@@ -14810,10 +15062,13 @@ var TokenSponsor = class extends Sponsor {
14810
15062
  );
14811
15063
  }
14812
15064
  async depositToken(token, spender, amount, options = globalThis.globalEnvOption) {
14813
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15065
+ const chain = await Chain.getChain(
15066
+ { chainIdentifier: options.chain },
15067
+ options
15068
+ );
14814
15069
  const tokenObj = new Token(token, chain);
14815
- const tokenAddress = await tokenObj.getAddress();
14816
- const amountDec = await tokenObj.getDecimalAmount(amount);
15070
+ const tokenAddress = await tokenObj.getAddress(options);
15071
+ const amountDec = await tokenObj.getDecimalAmount(amount, options);
14817
15072
  return this.contractInterface.encodeTransactionParams(
14818
15073
  await this.getPaymasterAddress(),
14819
15074
  "addTokenDepositTo",
@@ -14821,10 +15076,13 @@ var TokenSponsor = class extends Sponsor {
14821
15076
  );
14822
15077
  }
14823
15078
  async withdrawToken(token, receiver, amount, options = globalThis.globalEnvOption) {
14824
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15079
+ const chain = await Chain.getChain(
15080
+ { chainIdentifier: options.chain },
15081
+ options
15082
+ );
14825
15083
  const tokenObj = new Token(token, chain);
14826
- const tokenAddress = await tokenObj.getAddress();
14827
- const amountdec = await tokenObj.getDecimalAmount(amount);
15084
+ const tokenAddress = await tokenObj.getAddress(options);
15085
+ const amountdec = await tokenObj.getDecimalAmount(amount, options);
14828
15086
  return this.contractInterface.encodeTransactionParams(
14829
15087
  await this.getPaymasterAddress(),
14830
15088
  "withdrawTokenDepositTo",
@@ -14832,9 +15090,12 @@ var TokenSponsor = class extends Sponsor {
14832
15090
  );
14833
15091
  }
14834
15092
  async lockTokenDeposit(token, options = globalThis.globalEnvOption) {
14835
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15093
+ const chain = await Chain.getChain(
15094
+ { chainIdentifier: options.chain },
15095
+ options
15096
+ );
14836
15097
  const tokenData = new Token(token, chain);
14837
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
15098
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14838
15099
  return this.contractInterface.encodeTransactionParams(
14839
15100
  await this.getPaymasterAddress(),
14840
15101
  "lockTokenDeposit",
@@ -14842,9 +15103,12 @@ var TokenSponsor = class extends Sponsor {
14842
15103
  );
14843
15104
  }
14844
15105
  async unlockTokenDepositAfter(token, blocksToWait, options = globalThis.globalEnvOption) {
14845
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15106
+ const chain = await Chain.getChain(
15107
+ { chainIdentifier: options.chain },
15108
+ options
15109
+ );
14846
15110
  const tokenData = new Token(token, chain);
14847
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
15111
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14848
15112
  return this.contractInterface.encodeTransactionParams(
14849
15113
  await this.getPaymasterAddress(),
14850
15114
  "unlockTokenDepositAfter",
@@ -14867,9 +15131,12 @@ var TokenSponsor = class extends Sponsor {
14867
15131
  }
14868
15132
  async approve(approver, token, amount, options = globalThis.globalEnvOption) {
14869
15133
  const gasSponsorAddress = await this.getPaymasterAddress();
14870
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15134
+ const chain = await Chain.getChain(
15135
+ { chainIdentifier: options.chain },
15136
+ options
15137
+ );
14871
15138
  addTransaction({
14872
- chainId: await chain.getChainId(),
15139
+ chainId: await chain.getChainId(options),
14873
15140
  timestamp: Date.now(),
14874
15141
  txid: "0x",
14875
15142
  transaction: {
@@ -14881,36 +15148,50 @@ var TokenSponsor = class extends Sponsor {
14881
15148
  },
14882
15149
  paymasterType: this.paymasterType,
14883
15150
  sponsorAddress: approver,
14884
- apiKey: globalThis.globalEnvOption.apiKey
15151
+ apiKey: globalThis.globalEnvOption.apiKey,
15152
+ logger: options.logger,
15153
+ signal: options.signal
14885
15154
  });
14886
- return Token.approve(token, gasSponsorAddress, amount, chain);
15155
+ return Token.approve(token, gasSponsorAddress, amount, chain, options);
14887
15156
  }
14888
15157
  async getSpenderBlacklisted(spender, sponsor, options = globalThis.globalEnvOption) {
14889
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15158
+ const chain = await Chain.getChain(
15159
+ { chainIdentifier: options.chain },
15160
+ options
15161
+ );
14890
15162
  return await this.contractInterface.readFromChain(
14891
15163
  await this.getPaymasterAddress(options),
14892
15164
  "getSpenderBlacklisted",
14893
15165
  [spender, sponsor],
14894
- chain
15166
+ chain,
15167
+ options
14895
15168
  );
14896
15169
  }
14897
15170
  async getSpenderWhitelisted(spender, sponsor, options = globalThis.globalEnvOption) {
14898
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15171
+ const chain = await Chain.getChain(
15172
+ { chainIdentifier: options.chain },
15173
+ options
15174
+ );
14899
15175
  return await this.contractInterface.readFromChain(
14900
15176
  await this.getPaymasterAddress(options),
14901
15177
  "getSpenderWhitelisted",
14902
15178
  [spender, sponsor],
14903
- chain
15179
+ chain,
15180
+ options
14904
15181
  );
14905
15182
  }
14906
15183
  async getTokenWhitelisted(sponsor, token, options = globalThis.globalEnvOption) {
14907
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14908
- const tokenAddress = await Token.getAddress(token, chain);
15184
+ const chain = await Chain.getChain(
15185
+ { chainIdentifier: options.chain },
15186
+ options
15187
+ );
15188
+ const tokenAddress = await Token.getAddress(token, chain, options);
14909
15189
  return await this.contractInterface.readFromChain(
14910
15190
  await this.getPaymasterAddress(options),
14911
15191
  "getTokenWhitelisted",
14912
15192
  [tokenAddress, sponsor],
14913
- chain
15193
+ chain,
15194
+ options
14914
15195
  );
14915
15196
  }
14916
15197
  async setTokenToWhitelistMode() {
@@ -14921,10 +15202,13 @@ var TokenSponsor = class extends Sponsor {
14921
15202
  );
14922
15203
  }
14923
15204
  async batchWhitelistTokens(tokens, modes, options = globalThis.globalEnvOption) {
14924
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15205
+ const chain = await Chain.getChain(
15206
+ { chainIdentifier: options.chain },
15207
+ options
15208
+ );
14925
15209
  const calldata = [];
14926
15210
  for (let i = 0; i < tokens.length; i++) {
14927
- const tokenAddress = await Token.getAddress(tokens[i], chain);
15211
+ const tokenAddress = await Token.getAddress(tokens[i], chain, options);
14928
15212
  calldata.push(
14929
15213
  this.contractInterface.encodeData("setTokenWhitelistMode", [
14930
15214
  tokenAddress,
@@ -14939,22 +15223,30 @@ var TokenSponsor = class extends Sponsor {
14939
15223
  );
14940
15224
  }
14941
15225
  async getTokenListMode(sponsor, options = globalThis.globalEnvOption) {
14942
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15226
+ const chain = await Chain.getChain(
15227
+ { chainIdentifier: options.chain },
15228
+ options
15229
+ );
14943
15230
  return await this.contractInterface.readFromChain(
14944
15231
  await this.getPaymasterAddress(options),
14945
15232
  "getTokenListMode",
14946
15233
  [sponsor],
14947
- chain
15234
+ chain,
15235
+ options
14948
15236
  );
14949
15237
  }
14950
15238
  async getTokenBlacklisted(sponsor, token, options = globalThis.globalEnvOption) {
14951
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14952
- const tokenAddress = await Token.getAddress(token, chain);
15239
+ const chain = await Chain.getChain(
15240
+ { chainIdentifier: options.chain },
15241
+ options
15242
+ );
15243
+ const tokenAddress = await Token.getAddress(token, chain, options);
14953
15244
  return await this.contractInterface.readFromChain(
14954
15245
  await this.getPaymasterAddress(options),
14955
15246
  "getTokenBlacklisted",
14956
15247
  [tokenAddress, sponsor],
14957
- chain
15248
+ chain,
15249
+ options
14958
15250
  );
14959
15251
  }
14960
15252
  async setTokenToBlacklistMode() {
@@ -14965,10 +15257,13 @@ var TokenSponsor = class extends Sponsor {
14965
15257
  );
14966
15258
  }
14967
15259
  async batchBlacklistTokens(tokens, modes, options = globalThis.globalEnvOption) {
14968
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15260
+ const chain = await Chain.getChain(
15261
+ { chainIdentifier: options.chain },
15262
+ options
15263
+ );
14969
15264
  const calldata = [];
14970
15265
  for (let i = 0; i < tokens.length; i++) {
14971
- const tokenAddress = await Token.getAddress(tokens[i], chain);
15266
+ const tokenAddress = await Token.getAddress(tokens[i], chain, options);
14972
15267
  calldata.push(
14973
15268
  this.contractInterface.encodeTransactionParams(
14974
15269
  await this.getPaymasterAddress(),
@@ -15036,8 +15331,11 @@ import {
15036
15331
  decodeAbiParameters as decodeAbiParameters3,
15037
15332
  keccak256 as keccak2566
15038
15333
  } from "viem";
15039
- async function getOnChainGroupData(groupId, chain, walletAddr) {
15040
- const userAuthContractAddr = await chain.getAddress("userAuthAddress");
15334
+ async function getOnChainGroupData(groupId, chain, walletAddr, options) {
15335
+ const userAuthContractAddr = await chain.getAddress(
15336
+ "userAuthAddress",
15337
+ options
15338
+ );
15041
15339
  const groupKey = keccak2566(concat5([groupId, userAuthContractAddr]));
15042
15340
  let storedGroupData;
15043
15341
  try {
@@ -15045,7 +15343,8 @@ async function getOnChainGroupData(groupId, chain, walletAddr) {
15045
15343
  walletAddr,
15046
15344
  "getState",
15047
15345
  [groupKey],
15048
- chain
15346
+ chain,
15347
+ options
15049
15348
  );
15050
15349
  } catch (err) {
15051
15350
  if (err instanceof Error && err.message.match(/returned no data/)) {
@@ -15090,23 +15389,29 @@ var FirstClassActions = class {
15090
15389
  * @throws {InvalidParameterError} When provided parameters are missing or incorrect.
15091
15390
  */
15092
15391
  async transfer(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15093
- const overrideChain = await Chain.getChain({
15094
- chainIdentifier: txOptions?.chain
15095
- });
15392
+ const overrideChain = await Chain.getChain(
15393
+ { chainIdentifier: txOptions?.chain },
15394
+ txOptions
15395
+ );
15096
15396
  let transactionParams;
15097
15397
  if (isERC721TransferParams(params)) {
15098
- params.from = params.from ? params.from : await this.getAddress();
15099
- transactionParams = await erc721TransferTransactionParams(params);
15398
+ params.from = params.from ? params.from : await this.getAddress(txOptions);
15399
+ transactionParams = await erc721TransferTransactionParams(
15400
+ params,
15401
+ txOptions
15402
+ );
15100
15403
  } else if (isTokenTransferParams(params)) {
15101
15404
  if (params.from) {
15102
15405
  transactionParams = await tokenTransferFromTransactionParams(
15103
15406
  params,
15104
- overrideChain ?? this.chain
15407
+ overrideChain ?? this.chain,
15408
+ txOptions
15105
15409
  );
15106
15410
  } else {
15107
15411
  transactionParams = await tokenTransferTransactionParams(
15108
15412
  params,
15109
- overrideChain ?? this.chain
15413
+ overrideChain ?? this.chain,
15414
+ txOptions
15110
15415
  );
15111
15416
  }
15112
15417
  } else {
@@ -15138,9 +15443,12 @@ var FirstClassActions = class {
15138
15443
  async tokenApprove(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15139
15444
  let transactionParams;
15140
15445
  if (isERC20ApproveParams(params)) {
15141
- transactionParams = await erc20ApproveTransactionParams(params);
15446
+ transactionParams = await erc20ApproveTransactionParams(params, txOptions);
15142
15447
  } else if (isERC721ApproveParams(params)) {
15143
- transactionParams = await erc721ApproveTransactionParams(params);
15448
+ transactionParams = await erc721ApproveTransactionParams(
15449
+ params,
15450
+ txOptions
15451
+ );
15144
15452
  } else {
15145
15453
  throw new InvalidParameterError12(
15146
15454
  ErrorCode14.InvalidParameter,
@@ -15185,7 +15493,7 @@ var FirstClassActions = class {
15185
15493
  * @throws {InvalidParameterError} When provided parameters are missing or incorrect.
15186
15494
  */
15187
15495
  async unstake(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15188
- params.recipient ??= await this.getAddress();
15496
+ params.recipient ??= await this.getAddress(txOptions);
15189
15497
  let transactionParams;
15190
15498
  if (isRequestUnstakeParams(params)) {
15191
15499
  transactionParams = await requestUnstakeTransactionParams(
@@ -15281,11 +15589,15 @@ var FirstClassActions = class {
15281
15589
  async addUserToGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15282
15590
  params.userId = pad8(params.userId, { size: 32 });
15283
15591
  params.groupId = pad8(params.groupId, { size: 32 });
15284
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15592
+ const chain = await Chain.getChain(
15593
+ { chainIdentifier: txOptions.chain },
15594
+ txOptions
15595
+ );
15285
15596
  const onChainGroupData = await getOnChainGroupData(
15286
15597
  params.groupId,
15287
15598
  chain,
15288
- await this.getAddress()
15599
+ await this.getAddress(txOptions),
15600
+ txOptions
15289
15601
  );
15290
15602
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15291
15603
  throw new ResourceNotFoundError7(
@@ -15331,11 +15643,15 @@ var FirstClassActions = class {
15331
15643
  async removeUserFromGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15332
15644
  params.userId = pad8(params.userId, { size: 32 });
15333
15645
  params.groupId = pad8(params.groupId, { size: 32 });
15334
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15646
+ const chain = await Chain.getChain(
15647
+ { chainIdentifier: txOptions.chain },
15648
+ txOptions
15649
+ );
15335
15650
  const onChainGroupData = await getOnChainGroupData(
15336
15651
  params.groupId,
15337
15652
  chain,
15338
- await this.getAddress()
15653
+ await this.getAddress(txOptions),
15654
+ txOptions
15339
15655
  );
15340
15656
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15341
15657
  throw new ResourceNotFoundError7(
@@ -15380,11 +15696,15 @@ var FirstClassActions = class {
15380
15696
  */
15381
15697
  async updateThresholdOfGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15382
15698
  params.groupId = pad8(params.groupId, { size: 32 });
15383
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15699
+ const chain = await Chain.getChain(
15700
+ { chainIdentifier: txOptions.chain },
15701
+ txOptions
15702
+ );
15384
15703
  const onChainGroupData = await getOnChainGroupData(
15385
15704
  params.groupId,
15386
15705
  chain,
15387
- await this.getAddress()
15706
+ await this.getAddress(txOptions),
15707
+ txOptions
15388
15708
  );
15389
15709
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15390
15710
  throw new ResourceNotFoundError7(
@@ -15438,7 +15758,7 @@ var FirstClassActions = class {
15438
15758
  * @returns {Promise<Operation>} The prepared batch operation.
15439
15759
  */
15440
15760
  async createBatchOperation(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15441
- const walletAddress = await this.getAddress();
15761
+ const walletAddress = await this.getAddress(txOptions);
15442
15762
  const txParams = createExecuteBatchTxParams(params, walletAddress);
15443
15763
  return await this.createOperation(auth, userId, txParams, txOptions);
15444
15764
  }
@@ -15516,8 +15836,12 @@ var FunWallet = class extends FirstClassActions {
15516
15836
  if (!this.address) {
15517
15837
  const chainIdentifier = txOptions.chain;
15518
15838
  this.address = await getWalletAddress(
15519
- await Chain.getChain({ chainIdentifier: chainIdentifier ?? 137 }),
15520
- this.walletUniqueId
15839
+ await Chain.getChain(
15840
+ { chainIdentifier: chainIdentifier ?? 137 },
15841
+ txOptions
15842
+ ),
15843
+ this.walletUniqueId,
15844
+ txOptions
15521
15845
  );
15522
15846
  }
15523
15847
  return this.address;
@@ -15528,11 +15852,12 @@ var FunWallet = class extends FirstClassActions {
15528
15852
  * @param {string} apiKey - The API key to access the required resources.
15529
15853
  * @returns {Promise<Address>} The wallet address.
15530
15854
  */
15531
- static async getAddress(uniqueId, apiKey) {
15855
+ static async getAddress(uniqueId, apiKey, options) {
15532
15856
  globalThis.globalEnvOption.apiKey = apiKey;
15533
15857
  return await getWalletAddress(
15534
- await Chain.getChain({ chainIdentifier: 137 }),
15535
- keccak2567(toBytes7(uniqueId))
15858
+ await Chain.getChain({ chainIdentifier: 137 }, options),
15859
+ keccak2567(toBytes7(uniqueId)),
15860
+ options
15536
15861
  );
15537
15862
  }
15538
15863
  /**
@@ -15542,15 +15867,16 @@ var FunWallet = class extends FirstClassActions {
15542
15867
  * @param {Address} factoryAddress - The address of the factory contract.
15543
15868
  * @returns {Promise<Address>} The wallet address.
15544
15869
  */
15545
- static async getAddressOffline(uniqueId, rpcUrl, factoryAddress) {
15546
- const client = await createPublicClient2({
15870
+ static async getAddressOffline(uniqueId, rpcUrl, factoryAddress, options) {
15871
+ const client = createPublicClient2({
15547
15872
  transport: http3(rpcUrl)
15548
15873
  });
15549
15874
  return await FACTORY_CONTRACT_INTERFACE.readFromChain(
15550
15875
  factoryAddress,
15551
15876
  "getAddress",
15552
15877
  [keccak2567(toBytes7(uniqueId))],
15553
- client
15878
+ client,
15879
+ options
15554
15880
  );
15555
15881
  }
15556
15882
  /**
@@ -15559,26 +15885,33 @@ var FunWallet = class extends FirstClassActions {
15559
15885
  * @param {boolean} onlyVerifiedTokens If true, only return alchemy tokens that are verified(filters spam) - defaults to false
15560
15886
  * @returns JSON
15561
15887
  */
15562
- async getTokens(chainIdInput, onlyVerifiedTokens = false) {
15888
+ async getTokens(chainIdInput, onlyVerifiedTokens = false, options) {
15563
15889
  let chainId;
15564
15890
  if (!chainIdInput) {
15565
- const chain = await Chain.getChain({
15566
- chainIdentifier: globalThis.globalEnvOption.chain
15567
- });
15568
- chainId = await chain.getChainId();
15891
+ const chain = await Chain.getChain(
15892
+ {
15893
+ chainIdentifier: globalThis.globalEnvOption.chain
15894
+ },
15895
+ options
15896
+ );
15897
+ chainId = await chain.getChainId(options);
15569
15898
  } else {
15570
15899
  chainId = chainIdInput;
15571
15900
  }
15572
- const walletAddress = await this.getAddress();
15901
+ const walletAddress = await this.getAddress(options);
15573
15902
  return chainId === "ALL" ? await getAllWalletTokens({
15574
15903
  walletAddress,
15575
15904
  onlyVerifiedTokens,
15576
- apiKey: globalThis.globalEnvOption.apiKey
15905
+ apiKey: globalThis.globalEnvOption.apiKey,
15906
+ logger: options?.logger,
15907
+ signal: options?.signal
15577
15908
  }) : await getAllWalletTokensByChainId({
15578
15909
  chainId,
15579
15910
  walletAddress,
15580
15911
  onlyVerifiedTokens,
15581
- apiKey: globalThis.globalEnvOption.apiKey
15912
+ apiKey: globalThis.globalEnvOption.apiKey,
15913
+ logger: options?.logger,
15914
+ signal: options?.signal
15582
15915
  });
15583
15916
  }
15584
15917
  /**
@@ -15586,32 +15919,41 @@ var FunWallet = class extends FirstClassActions {
15586
15919
  * @param {string} chainId string version of the chainId or ALL. If empty, then default to the one in globalEnvOption
15587
15920
  * @returns array
15588
15921
  */
15589
- async getNFTs(chainIdInput) {
15922
+ async getNFTs(chainIdInput, options) {
15590
15923
  let chainId;
15591
15924
  if (!chainIdInput) {
15592
- const chain = await Chain.getChain({
15593
- chainIdentifier: globalThis.globalEnvOption.chain
15594
- });
15595
- chainId = await chain.getChainId();
15925
+ const chain = await Chain.getChain(
15926
+ {
15927
+ chainIdentifier: globalThis.globalEnvOption.chain
15928
+ },
15929
+ options
15930
+ );
15931
+ chainId = await chain.getChainId(options);
15596
15932
  } else {
15597
15933
  chainId = chainIdInput;
15598
15934
  }
15599
- const walletAddress = await this.getAddress();
15935
+ const walletAddress = await this.getAddress(options);
15600
15936
  return chainId === "ALL" ? await getAllWalletNFTs({
15601
15937
  walletAddress,
15602
- apiKey: globalThis.globalEnvOption.apiKey
15938
+ apiKey: globalThis.globalEnvOption.apiKey,
15939
+ logger: options?.logger,
15940
+ signal: options?.signal
15603
15941
  }) : await getAllWalletNFTsByChainId({
15604
15942
  chainId,
15605
15943
  walletAddress,
15606
- apiKey: globalThis.globalEnvOption.apiKey
15944
+ apiKey: globalThis.globalEnvOption.apiKey,
15945
+ logger: options?.logger,
15946
+ signal: options?.signal
15607
15947
  });
15608
15948
  }
15609
- async getLidoWithdrawals() {
15610
- const walletAddress = await this.getAddress();
15949
+ async getLidoWithdrawals(options) {
15950
+ const walletAddress = await this.getAddress(options);
15611
15951
  return await getWalletLidoWithdrawalsByChainId({
15612
15952
  chainId: "1",
15613
15953
  walletAddress,
15614
- apiKey: globalThis.globalEnvOption.apiKey
15954
+ apiKey: globalThis.globalEnvOption.apiKey,
15955
+ logger: options?.logger,
15956
+ signal: options?.signal
15615
15957
  });
15616
15958
  }
15617
15959
  /**
@@ -15621,18 +15963,21 @@ var FunWallet = class extends FirstClassActions {
15621
15963
  * @param {boolean} checkStatus true if you want to check if the address has any pending lido withdrawals
15622
15964
  * @returns JSON of all tokens owned by address
15623
15965
  */
15624
- async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false) {
15966
+ async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false, options) {
15625
15967
  let chainId;
15626
15968
  if (!chainIdInput) {
15627
- const chain = await Chain.getChain({
15628
- chainIdentifier: globalThis.globalEnvOption.chain
15629
- });
15630
- chainId = await chain.getChainId();
15969
+ const chain = await Chain.getChain(
15970
+ {
15971
+ chainIdentifier: globalThis.globalEnvOption.chain
15972
+ },
15973
+ options
15974
+ );
15975
+ chainId = await chain.getChainId(options);
15631
15976
  } else {
15632
15977
  chainId = chainIdInput;
15633
15978
  }
15634
- const tokens = await this.getTokens(chainId, onlyVerifiedTokens);
15635
- const lidoWithdrawals = checkStatus ? await this.getLidoWithdrawals() : {};
15979
+ const tokens = await this.getTokens(chainId, onlyVerifiedTokens, options);
15980
+ const lidoWithdrawals = checkStatus ? await this.getLidoWithdrawals(options) : {};
15636
15981
  return { ...lidoWithdrawals, ...tokens };
15637
15982
  }
15638
15983
  /**
@@ -15644,8 +15989,14 @@ var FunWallet = class extends FirstClassActions {
15644
15989
  * @returns {Promise<bigint>} The nonce value.
15645
15990
  */
15646
15991
  async getNonce(sender, key = generateRandomNonceKey(), txOptions = globalThis.globalEnvOption) {
15647
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15648
- const entryPointAddress = await chain.getAddress("entryPointAddress");
15992
+ const chain = await Chain.getChain(
15993
+ { chainIdentifier: txOptions.chain },
15994
+ txOptions
15995
+ );
15996
+ const entryPointAddress = await chain.getAddress(
15997
+ "entryPointAddress",
15998
+ txOptions
15999
+ );
15649
16000
  let nonce = void 0;
15650
16001
  let retryCount = 3;
15651
16002
  while ((nonce === void 0 || nonce === null) && retryCount > 0) {
@@ -15653,7 +16004,8 @@ var FunWallet = class extends FirstClassActions {
15653
16004
  entryPointAddress,
15654
16005
  "getNonce",
15655
16006
  [sender, key],
15656
- chain
16007
+ chain,
16008
+ txOptions
15657
16009
  );
15658
16010
  retryCount--;
15659
16011
  }
@@ -15669,12 +16021,17 @@ var FunWallet = class extends FirstClassActions {
15669
16021
  * @returns {Promise<OperationData[]>} A list of operations.
15670
16022
  */
15671
16023
  async getOperations(status = OperationStatus.ALL, txOptions = globalThis.globalEnvOption) {
15672
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16024
+ const chain = await Chain.getChain(
16025
+ { chainIdentifier: txOptions.chain },
16026
+ txOptions
16027
+ );
15673
16028
  return await getOpsOfWallet({
15674
16029
  walletAddr: await this.getAddress(txOptions),
15675
- chainId: await chain.getChainId(),
16030
+ chainId: await chain.getChainId(txOptions),
15676
16031
  status,
15677
- apiKey: globalThis.globalEnvOption.apiKey
16032
+ apiKey: globalThis.globalEnvOption.apiKey,
16033
+ logger: txOptions?.logger,
16034
+ signal: txOptions?.signal
15678
16035
  });
15679
16036
  }
15680
16037
  /**
@@ -15684,11 +16041,16 @@ var FunWallet = class extends FirstClassActions {
15684
16041
  * @returns {Promise<OperationData>} The requested operation.
15685
16042
  */
15686
16043
  async getOperation(opId, txOptions = globalThis.globalEnvOption) {
15687
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16044
+ const chain = await Chain.getChain(
16045
+ { chainIdentifier: txOptions.chain },
16046
+ txOptions
16047
+ );
15688
16048
  return (await getOps({
15689
16049
  opIds: [opId],
15690
- chainId: await chain.getChainId(),
15691
- apiKey: globalThis.globalEnvOption.apiKey
16050
+ chainId: await chain.getChainId(txOptions),
16051
+ apiKey: globalThis.globalEnvOption.apiKey,
16052
+ logger: txOptions?.logger,
16053
+ signal: txOptions?.signal
15692
16054
  }))[0];
15693
16055
  }
15694
16056
  /**
@@ -15698,10 +16060,14 @@ var FunWallet = class extends FirstClassActions {
15698
16060
  * @returns {Promise<User[]>} A list of users with their group information.
15699
16061
  */
15700
16062
  async getUsers(auth, txOptions = globalThis.globalEnvOption) {
15701
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16063
+ const chain = await Chain.getChain(
16064
+ { chainIdentifier: txOptions.chain },
16065
+ txOptions
16066
+ );
15702
16067
  const storedUserIds = await auth.getUserIds(
15703
16068
  await this.getAddress(txOptions),
15704
- await chain.getChainId()
16069
+ await chain.getChainId(txOptions),
16070
+ txOptions
15705
16071
  );
15706
16072
  const userIds = /* @__PURE__ */ new Set([...storedUserIds]);
15707
16073
  if (this.userInfo) {
@@ -15721,8 +16087,10 @@ var FunWallet = class extends FirstClassActions {
15721
16087
  if (groupIds && groupIds.length > 0) {
15722
16088
  const groups = await getGroups({
15723
16089
  groupIds,
15724
- chainId: await chain.getChainId(),
15725
- apiKey: globalThis.globalEnvOption.apiKey
16090
+ chainId: await chain.getChainId(txOptions),
16091
+ apiKey: globalThis.globalEnvOption.apiKey,
16092
+ logger: txOptions?.logger,
16093
+ signal: txOptions?.signal
15726
16094
  });
15727
16095
  for (const group of groups) {
15728
16096
  users.push({
@@ -15742,8 +16110,14 @@ var FunWallet = class extends FirstClassActions {
15742
16110
  * @returns {Promise<boolean>} `true` if the address is a contract, `false` otherwise.
15743
16111
  */
15744
16112
  async getDeploymentStatus(txOptions = globalThis.globalEnvOption) {
15745
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15746
- return await chain.addressIsContract(await this.getAddress(txOptions));
16113
+ const chain = await Chain.getChain(
16114
+ { chainIdentifier: txOptions.chain },
16115
+ txOptions
16116
+ );
16117
+ return await chain.addressIsContract(
16118
+ await this.getAddress(txOptions),
16119
+ txOptions
16120
+ );
15747
16121
  }
15748
16122
  /**
15749
16123
  * Creates the wallet.
@@ -15772,28 +16146,41 @@ var FunWallet = class extends FirstClassActions {
15772
16146
  * @returns A Promise that resolves when the wallet is saved to the authentication system.
15773
16147
  */
15774
16148
  async saveWalletToAuth(auth, txOptions = globalThis.globalEnvOption) {
15775
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16149
+ const chain = await Chain.getChain(
16150
+ { chainIdentifier: txOptions.chain },
16151
+ txOptions
16152
+ );
15776
16153
  const walletAddr = await this.getAddress(txOptions);
15777
16154
  const userId = await auth.getUserId();
15778
- const users = await auth.getUserIds(walletAddr, await chain.getChainId());
16155
+ const users = await auth.getUserIds(
16156
+ walletAddr,
16157
+ await chain.getChainId(txOptions),
16158
+ txOptions
16159
+ );
15779
16160
  if (!users.includes(userId)) {
15780
16161
  if (await checkWalletAccessInitialization({
15781
16162
  walletAddr,
15782
- apiKey: globalThis.globalEnvOption.apiKey
16163
+ apiKey: globalThis.globalEnvOption.apiKey,
16164
+ logger: txOptions?.logger,
16165
+ signal: txOptions?.signal
15783
16166
  }) === false) {
15784
16167
  await initializeWalletAccess({
15785
16168
  walletAddr,
15786
16169
  creatorAddr: await auth.getAddress(),
15787
- apiKey: globalThis.globalEnvOption.apiKey
16170
+ apiKey: globalThis.globalEnvOption.apiKey,
16171
+ logger: txOptions?.logger,
16172
+ signal: txOptions?.signal
15788
16173
  });
15789
16174
  }
15790
16175
  await addUserToWallet({
15791
16176
  authId: await auth.getAddress(),
15792
- chainId: await chain.getChainId(),
16177
+ chainId: await chain.getChainId(txOptions),
15793
16178
  walletAddr,
15794
16179
  userIds: [userId],
15795
16180
  walletUniqueId: this.walletUniqueId,
15796
- apiKey: globalThis.globalEnvOption.apiKey
16181
+ apiKey: globalThis.globalEnvOption.apiKey,
16182
+ logger: txOptions?.logger,
16183
+ signal: txOptions?.signal
15797
16184
  });
15798
16185
  }
15799
16186
  }
@@ -15819,16 +16206,19 @@ var FunWallet = class extends FirstClassActions {
15819
16206
  const normalizedUserId = pad9(userId, {
15820
16207
  size: 32
15821
16208
  }).toLowerCase();
15822
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16209
+ const chain = await Chain.getChain(
16210
+ { chainIdentifier: txOptions.chain },
16211
+ txOptions
16212
+ );
15823
16213
  const sender = await this.getAddress(txOptions);
15824
- const initCode = await chain.addressIsContract(sender) ? "0x" : await this.getThisInitCode(chain);
16214
+ const initCode = await chain.addressIsContract(sender, txOptions) ? "0x" : await this.getThisInitCode(chain, txOptions);
15825
16215
  let paymasterAndData = "0x";
15826
16216
  let maxFeePerGas;
15827
16217
  let maxPriorityFeePerGas;
15828
- const chainId = await chain.getChainId();
16218
+ const chainId = await chain.getChainId(txOptions);
15829
16219
  const OPStackChains = ["10", "8453"];
15830
16220
  if (OPStackChains.includes(chainId)) {
15831
- const gasPrice = await chain.getFeeData();
16221
+ const gasPrice = await chain.getFeeData(txOptions);
15832
16222
  maxFeePerGas = gasPrice.maxFeePerGas;
15833
16223
  maxPriorityFeePerGas = gasPrice.maxPriorityFeePerGas;
15834
16224
  } else {
@@ -15847,18 +16237,18 @@ var FunWallet = class extends FirstClassActions {
15847
16237
  maxFeePerGas,
15848
16238
  maxPriorityFeePerGas,
15849
16239
  initCode,
15850
- nonce: txOptions.nonce !== null && txOptions.nonce !== void 0 ? txOptions.nonce : await this.getNonce(sender),
16240
+ nonce: txOptions.nonce !== null && txOptions.nonce !== void 0 ? txOptions.nonce : await this.getNonce(sender, void 0, txOptions),
15851
16241
  preVerificationGas: 100000n,
15852
16242
  callGasLimit: BigInt(1e7),
15853
16243
  verificationGasLimit: BigInt(1e7)
15854
16244
  };
15855
- if (await chain.getChainId() === "36865") {
16245
+ if (await chain.getChainId(txOptions) === "36865") {
15856
16246
  partialOp.callGasLimit = BigInt(1e6);
15857
16247
  partialOp.verificationGasLimit = BigInt(1e6);
15858
16248
  }
15859
16249
  const isGroupOp = await auth.getUserId() !== normalizedUserId;
15860
16250
  const operation = new Operation(partialOp, {
15861
- chainId: await chain.getChainId(),
16251
+ chainId: await chain.getChainId(txOptions),
15862
16252
  opType: isGroupOp ? OperationType.GROUP_OPERATION : OperationType.SINGLE_OPERATION,
15863
16253
  authType: isGroupOp ? AuthType2.MULTI_SIG : AuthType2.ECDSA,
15864
16254
  walletAddr: await this.getAddress(txOptions),
@@ -15901,22 +16291,29 @@ var FunWallet = class extends FirstClassActions {
15901
16291
  estimatedOperation.userOp.signature = await auth.signOp(
15902
16292
  estimatedOperation,
15903
16293
  chain,
15904
- isGroupOperation(operation)
16294
+ isGroupOperation(operation),
16295
+ txOptions
15905
16296
  );
15906
16297
  if (txOptions.skipDBAction !== true) {
15907
16298
  const opId = await createOp({
15908
16299
  op: estimatedOperation,
15909
- apiKey: globalThis.globalEnvOption.apiKey
16300
+ apiKey: globalThis.globalEnvOption.apiKey,
16301
+ logger: txOptions?.logger,
16302
+ signal: txOptions?.signal
15910
16303
  });
15911
16304
  estimatedOperation.opId = opId;
15912
16305
  if (!await checkWalletAccessInitialization({
15913
16306
  walletAddr: sender,
15914
- apiKey: globalThis.globalEnvOption.apiKey
16307
+ apiKey: globalThis.globalEnvOption.apiKey,
16308
+ logger: txOptions?.logger,
16309
+ signal: txOptions?.signal
15915
16310
  })) {
15916
16311
  await initializeWalletAccess({
15917
16312
  walletAddr: sender,
15918
16313
  creatorAddr: await auth.getAddress(),
15919
- apiKey: globalThis.globalEnvOption.apiKey
16314
+ apiKey: globalThis.globalEnvOption.apiKey,
16315
+ logger: txOptions?.logger,
16316
+ signal: txOptions?.signal
15920
16317
  });
15921
16318
  }
15922
16319
  }
@@ -15930,21 +16327,27 @@ var FunWallet = class extends FirstClassActions {
15930
16327
  * @returns {Promise<Operation>} The signed operation.
15931
16328
  */
15932
16329
  async signOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
15933
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16330
+ const chain = await Chain.getChain(
16331
+ { chainIdentifier: txOptions.chain },
16332
+ txOptions
16333
+ );
15934
16334
  const finalOperation = Operation.convertTypeToObject(operation);
15935
16335
  finalOperation.userOp.signature = await auth.signOp(
15936
16336
  finalOperation,
15937
16337
  chain,
15938
- isGroupOperation(finalOperation)
16338
+ isGroupOperation(finalOperation),
16339
+ txOptions
15939
16340
  );
15940
16341
  if (isGroupOperation(finalOperation) && txOptions.skipDBAction !== true) {
15941
16342
  await signOp({
15942
16343
  opId: finalOperation.opId,
15943
- chainId: await chain.getChainId(),
16344
+ chainId: await chain.getChainId(txOptions),
15944
16345
  signature: finalOperation.userOp.signature,
15945
16346
  signedBy: await auth.getAddress(),
15946
16347
  threshold: this.userInfo?.get(finalOperation.groupId)?.groupInfo?.threshold,
15947
- apiKey: globalThis.globalEnvOption.apiKey
16348
+ apiKey: globalThis.globalEnvOption.apiKey,
16349
+ logger: txOptions?.logger,
16350
+ signal: txOptions?.signal
15948
16351
  });
15949
16352
  }
15950
16353
  return finalOperation;
@@ -15960,16 +16363,21 @@ var FunWallet = class extends FirstClassActions {
15960
16363
  async executeOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
15961
16364
  const finalTxOptions = parseOptions(txOptions);
15962
16365
  const finalOperation = Operation.convertTypeToObject(operation);
15963
- const chain = await Chain.getChain({
15964
- chainIdentifier: finalTxOptions.chain
15965
- });
15966
- const chainId = await chain.getChainId();
16366
+ const chain = await Chain.getChain(
16367
+ {
16368
+ chainIdentifier: finalTxOptions.chain
16369
+ },
16370
+ txOptions
16371
+ );
16372
+ const chainId = await chain.getChainId(txOptions);
15967
16373
  if (finalTxOptions.skipDBAction !== true) {
15968
16374
  if (isGroupOperation(finalOperation)) {
15969
16375
  const groups = await getGroups({
15970
16376
  groupIds: [finalOperation.groupId],
15971
16377
  chainId,
15972
- apiKey: globalThis.globalEnvOption.apiKey
16378
+ apiKey: globalThis.globalEnvOption.apiKey,
16379
+ logger: txOptions?.logger,
16380
+ signal: txOptions?.signal
15973
16381
  });
15974
16382
  if (groups && groups.length > 0) {
15975
16383
  this.userInfo?.set(finalOperation.groupId, {
@@ -15988,7 +16396,8 @@ var FunWallet = class extends FirstClassActions {
15988
16396
  finalOperation.userOp.signature = await auth.signOp(
15989
16397
  finalOperation,
15990
16398
  chain,
15991
- isGroupOperation(finalOperation)
16399
+ isGroupOperation(finalOperation),
16400
+ txOptions
15992
16401
  );
15993
16402
  }
15994
16403
  } else {
@@ -15996,7 +16405,9 @@ var FunWallet = class extends FirstClassActions {
15996
16405
  const storedOps = await getOps({
15997
16406
  opIds: [finalOperation.opId],
15998
16407
  chainId,
15999
- apiKey: globalThis.globalEnvOption.apiKey
16408
+ apiKey: globalThis.globalEnvOption.apiKey,
16409
+ logger: txOptions?.logger,
16410
+ signal: txOptions?.signal
16000
16411
  });
16001
16412
  let collectedSigCount;
16002
16413
  if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
@@ -16005,7 +16416,8 @@ var FunWallet = class extends FirstClassActions {
16005
16416
  finalOperation.userOp.signature = await auth.signOp(
16006
16417
  finalOperation,
16007
16418
  chain,
16008
- isGroupOperation(finalOperation)
16419
+ isGroupOperation(finalOperation),
16420
+ txOptions
16009
16421
  );
16010
16422
  }
16011
16423
  } else {
@@ -16039,11 +16451,16 @@ var FunWallet = class extends FirstClassActions {
16039
16451
  opId: finalOperation.opId,
16040
16452
  chainId,
16041
16453
  executedBy: await auth.getAddress(),
16042
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16454
+ entryPointAddress: await chain.getAddress(
16455
+ "entryPointAddress",
16456
+ txOptions
16457
+ ),
16043
16458
  signature: finalOperation.userOp.signature,
16044
16459
  groupInfo: this.userInfo?.get(finalOperation.groupId)?.groupInfo
16045
16460
  },
16046
- apiKey: globalThis.globalEnvOption.apiKey
16461
+ apiKey: globalThis.globalEnvOption.apiKey,
16462
+ logger: txOptions.logger,
16463
+ signal: txOptions.signal
16047
16464
  });
16048
16465
  } else {
16049
16466
  receipt = await executeOp({
@@ -16051,18 +16468,25 @@ var FunWallet = class extends FirstClassActions {
16051
16468
  opId: finalOperation.opId,
16052
16469
  chainId,
16053
16470
  executedBy: await auth.getAddress(),
16054
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16471
+ entryPointAddress: await chain.getAddress(
16472
+ "entryPointAddress",
16473
+ txOptions
16474
+ ),
16055
16475
  signature: finalOperation.userOp.signature,
16056
16476
  userOp: finalOperation.userOp
16057
16477
  },
16058
- apiKey: globalThis.globalEnvOption.apiKey
16478
+ apiKey: globalThis.globalEnvOption.apiKey,
16479
+ logger: txOptions.logger,
16480
+ signal: txOptions.signal
16059
16481
  });
16060
16482
  }
16061
16483
  receipt = await getFullReceipt({
16062
16484
  opId: finalOperation.opId,
16063
16485
  chainId,
16064
16486
  userOpHash: receipt.userOpHash,
16065
- apiKey: globalThis.globalEnvOption.apiKey
16487
+ apiKey: globalThis.globalEnvOption.apiKey,
16488
+ logger: txOptions.logger,
16489
+ signal: txOptions.signal
16066
16490
  });
16067
16491
  if (isWalletInitOp(finalOperation.userOp) && finalTxOptions.skipDBAction !== true) {
16068
16492
  await addUserToWallet({
@@ -16071,7 +16495,9 @@ var FunWallet = class extends FirstClassActions {
16071
16495
  walletAddr: await this.getAddress(finalTxOptions),
16072
16496
  userIds: Array.from(this.userInfo.keys()),
16073
16497
  walletUniqueId: this.walletUniqueId,
16074
- apiKey: globalThis.globalEnvOption.apiKey
16498
+ apiKey: globalThis.globalEnvOption.apiKey,
16499
+ logger: finalTxOptions.logger,
16500
+ signal: finalTxOptions.signal
16075
16501
  });
16076
16502
  if (finalTxOptions?.gasSponsor?.sponsorAddress) {
16077
16503
  const paymasterType = getPaymasterType(finalTxOptions);
@@ -16090,7 +16516,9 @@ var FunWallet = class extends FirstClassActions {
16090
16516
  },
16091
16517
  paymasterType,
16092
16518
  sponsorAddress: finalTxOptions.gasSponsor.sponsorAddress,
16093
- apiKey: globalThis.globalEnvOption.apiKey
16519
+ apiKey: globalThis.globalEnvOption.apiKey,
16520
+ logger: finalTxOptions.logger,
16521
+ signal: finalTxOptions.signal
16094
16522
  });
16095
16523
  }
16096
16524
  }
@@ -16107,14 +16535,19 @@ var FunWallet = class extends FirstClassActions {
16107
16535
  async scheduleOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
16108
16536
  const finalTxOptions = parseOptions(txOptions);
16109
16537
  const finalOperation = Operation.convertTypeToObject(operation);
16110
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16111
- const chainId = await chain.getChainId();
16538
+ const chain = await Chain.getChain(
16539
+ { chainIdentifier: txOptions.chain },
16540
+ txOptions
16541
+ );
16542
+ const chainId = await chain.getChainId(txOptions);
16112
16543
  if (finalTxOptions.skipDBAction !== true) {
16113
16544
  if (isGroupOperation(finalOperation)) {
16114
16545
  const groups = await getGroups({
16115
16546
  groupIds: [finalOperation.groupId],
16116
16547
  chainId,
16117
- apiKey: globalThis.globalEnvOption.apiKey
16548
+ apiKey: globalThis.globalEnvOption.apiKey,
16549
+ logger: txOptions.logger,
16550
+ signal: txOptions.signal
16118
16551
  });
16119
16552
  if (groups && groups.length > 0) {
16120
16553
  this.userInfo?.set(finalOperation.groupId, {
@@ -16133,7 +16566,8 @@ var FunWallet = class extends FirstClassActions {
16133
16566
  finalOperation.userOp.signature = await auth.signOp(
16134
16567
  finalOperation,
16135
16568
  chain,
16136
- isGroupOperation(finalOperation)
16569
+ isGroupOperation(finalOperation),
16570
+ txOptions
16137
16571
  );
16138
16572
  }
16139
16573
  } else {
@@ -16141,7 +16575,9 @@ var FunWallet = class extends FirstClassActions {
16141
16575
  const storedOps = await getOps({
16142
16576
  opIds: [finalOperation.opId],
16143
16577
  chainId,
16144
- apiKey: globalThis.globalEnvOption.apiKey
16578
+ apiKey: globalThis.globalEnvOption.apiKey,
16579
+ logger: txOptions.logger,
16580
+ signal: txOptions.signal
16145
16581
  });
16146
16582
  let collectedSigCount;
16147
16583
  if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
@@ -16150,7 +16586,8 @@ var FunWallet = class extends FirstClassActions {
16150
16586
  finalOperation.userOp.signature = await auth.signOp(
16151
16587
  finalOperation,
16152
16588
  chain,
16153
- isGroupOperation(finalOperation)
16589
+ isGroupOperation(finalOperation),
16590
+ txOptions
16154
16591
  );
16155
16592
  }
16156
16593
  } else {
@@ -16183,11 +16620,16 @@ var FunWallet = class extends FirstClassActions {
16183
16620
  opId: finalOperation.opId,
16184
16621
  chainId,
16185
16622
  scheduledBy: await auth.getAddress(),
16186
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16623
+ entryPointAddress: await chain.getAddress(
16624
+ "entryPointAddress",
16625
+ txOptions
16626
+ ),
16187
16627
  signature: finalOperation.userOp.signature,
16188
16628
  groupInfo: this.userInfo?.get(finalOperation.groupId)?.groupInfo
16189
16629
  },
16190
- apiKey: globalThis.globalEnvOption.apiKey
16630
+ apiKey: globalThis.globalEnvOption.apiKey,
16631
+ logger: txOptions.logger,
16632
+ signal: txOptions.signal
16191
16633
  });
16192
16634
  } else {
16193
16635
  await scheduleOp({
@@ -16195,11 +16637,16 @@ var FunWallet = class extends FirstClassActions {
16195
16637
  opId: finalOperation.opId,
16196
16638
  chainId,
16197
16639
  scheduledBy: await auth.getAddress(),
16198
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16640
+ entryPointAddress: await chain.getAddress(
16641
+ "entryPointAddress",
16642
+ txOptions
16643
+ ),
16199
16644
  signature: finalOperation.userOp.signature,
16200
16645
  userOp: finalOperation.userOp
16201
16646
  },
16202
- apiKey: globalThis.globalEnvOption.apiKey
16647
+ apiKey: globalThis.globalEnvOption.apiKey,
16648
+ logger: txOptions.logger,
16649
+ signal: txOptions.signal
16203
16650
  });
16204
16651
  }
16205
16652
  if (!finalOperation.opId) {
@@ -16222,11 +16669,16 @@ var FunWallet = class extends FirstClassActions {
16222
16669
  * @returns {Promise<void>} A promise that resolves after the operation is removed.
16223
16670
  */
16224
16671
  async removeOperation(_, operationId, txOptions = globalThis.globalEnvOption) {
16225
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16672
+ const chain = await Chain.getChain(
16673
+ { chainIdentifier: txOptions.chain },
16674
+ txOptions
16675
+ );
16226
16676
  await deleteOp({
16227
16677
  opId: operationId,
16228
- chainId: await chain.getChainId(),
16229
- apiKey: globalThis.globalEnvOption.apiKey
16678
+ chainId: await chain.getChainId(txOptions),
16679
+ apiKey: globalThis.globalEnvOption.apiKey,
16680
+ logger: txOptions?.logger,
16681
+ signal: txOptions?.signal
16230
16682
  });
16231
16683
  }
16232
16684
  /**
@@ -16254,7 +16706,9 @@ var FunWallet = class extends FirstClassActions {
16254
16706
  rejectOperation.opType = OperationType.REJECTION;
16255
16707
  rejectOperation.opId = await createOp({
16256
16708
  op: rejectOperation,
16257
- apiKey: globalThis.globalEnvOption.apiKey
16709
+ apiKey: globalThis.globalEnvOption.apiKey,
16710
+ logger: txOptions.logger,
16711
+ signal: txOptions.signal
16258
16712
  });
16259
16713
  return rejectOperation;
16260
16714
  }
@@ -16267,7 +16721,10 @@ var FunWallet = class extends FirstClassActions {
16267
16721
  * @returns {Promise<Operation>} The updated operation with gas estimation details.
16268
16722
  */
16269
16723
  async estimateOperation(auth, userId, operation, txOptions = globalThis.globalEnvOption) {
16270
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16724
+ const chain = await Chain.getChain(
16725
+ { chainIdentifier: txOptions.chain },
16726
+ txOptions
16727
+ );
16271
16728
  const estimateGasSignature = await auth.getEstimateGasSignature(
16272
16729
  userId,
16273
16730
  operation
@@ -16279,17 +16736,20 @@ var FunWallet = class extends FirstClassActions {
16279
16736
  // ...res,
16280
16737
  paymasterAndData
16281
16738
  };
16282
- const { maxFeePerGas, maxPriorityFeePerGas } = await chain.getFeeData();
16739
+ const { maxFeePerGas, maxPriorityFeePerGas } = await chain.getFeeData(txOptions);
16283
16740
  operation.userOp.maxFeePerGas = maxFeePerGas;
16284
16741
  operation.userOp.maxPriorityFeePerGas = maxPriorityFeePerGas;
16285
16742
  return operation;
16286
16743
  }
16287
- async getThisInitCode(chain) {
16744
+ async getThisInitCode(chain, options) {
16288
16745
  const owners = Array.from(this.userInfo.keys());
16289
- const entryPointAddress = await chain.getAddress("entryPointAddress");
16290
- const factoryAddress = await chain.getAddress("factoryAddress");
16291
- const rbac = await chain.getAddress("rbacAddress");
16292
- const userAuth = await chain.getAddress("userAuthAddress");
16746
+ const entryPointAddress = await chain.getAddress(
16747
+ "entryPointAddress",
16748
+ options
16749
+ );
16750
+ const factoryAddress = await chain.getAddress("factoryAddress", options);
16751
+ const rbac = await chain.getAddress("rbacAddress", options);
16752
+ const userAuth = await chain.getAddress("userAuthAddress", options);
16293
16753
  const loginData = {
16294
16754
  salt: this.walletUniqueId
16295
16755
  };
@@ -16369,7 +16829,10 @@ var FunWallet = class extends FirstClassActions {
16369
16829
  "https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions"
16370
16830
  );
16371
16831
  }
16372
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
16832
+ const chain = await Chain.getChain(
16833
+ { chainIdentifier: options.chain },
16834
+ options
16835
+ );
16373
16836
  const token = new Token(options.fee.token, chain);
16374
16837
  if (options.fee.gasPercent && !token.isNative) {
16375
16838
  throw new InvalidParameterError13(
@@ -16384,11 +16847,11 @@ var FunWallet = class extends FirstClassActions {
16384
16847
  if (token.isNative) {
16385
16848
  options.fee.token = AddressZero;
16386
16849
  } else {
16387
- options.fee.token = await token.getAddress();
16850
+ options.fee.token = await token.getAddress(options);
16388
16851
  }
16389
16852
  if (options.fee.amount) {
16390
16853
  options.fee.amount = Number(
16391
- await token.getDecimalAmount(options.fee.amount)
16854
+ await token.getDecimalAmount(options.fee.amount, options)
16392
16855
  );
16393
16856
  } else if (options.fee.gasPercent) {
16394
16857
  const feedata2 = [options.fee.token, options.fee.recipient, 1];
@@ -16402,7 +16865,7 @@ var FunWallet = class extends FirstClassActions {
16402
16865
  { to: params.to, value: params.value, data: estimateGasCalldata },
16403
16866
  { ...options, fee: void 0 }
16404
16867
  );
16405
- const gasUsed = await operation.getMaxTxCost();
16868
+ const gasUsed = operation.getMaxTxCost();
16406
16869
  options.fee.amount = Math.ceil(
16407
16870
  Number(gasUsed) * options.fee.gasPercent / 100
16408
16871
  );
@@ -16557,10 +17020,6 @@ export {
16557
17020
  removeOwnerTxParams,
16558
17021
  requestUnstakeTransactionParams,
16559
17022
  roundToNearestBottomTenth,
16560
- sendDeleteRequest,
16561
- sendGetRequest,
16562
- sendPostRequest,
16563
- sendPutRequest,
16564
17023
  sendRequest,
16565
17024
  stakeTransactionParams,
16566
17025
  stringify,