@funkit/core 2.3.6 → 2.3.8

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
@@ -1,6 +1,6 @@
1
1
  // src/actions/AccessControl.ts
2
2
  import { getAddress, pad as pad6 } from "viem";
3
- import { ErrorCode as ErrorCode8, InvalidParameterError as InvalidParameterError7 } from "@funkit/utils";
3
+ import { ErrorCode as ErrorCode7, InvalidParameterError as InvalidParameterError7 } from "@funkit/utils";
4
4
 
5
5
  // src/auth/Auth.ts
6
6
  import {
@@ -19,7 +19,7 @@ import {
19
19
  getUserWalletsByAddr
20
20
  } from "@funkit/api-base";
21
21
  import {
22
- ErrorCode as ErrorCode7,
22
+ ErrorCode as ErrorCode6,
23
23
  InvalidParameterError as InvalidParameterError6,
24
24
  ResourceNotFoundError as ResourceNotFoundError4
25
25
  } from "@funkit/utils";
@@ -11498,23 +11498,19 @@ import {
11498
11498
  } from "@funkit/api-base";
11499
11499
  import { FUNKIT_CONNECT_SUPPORTED_CHAINS_INFO } from "@funkit/chains";
11500
11500
  import {
11501
- ErrorCode as ErrorCode4,
11502
- InternalFailureError as InternalFailureError2,
11501
+ ErrorCode as ErrorCode3,
11502
+ InternalFailureError,
11503
11503
  InvalidParameterError as InvalidParameterError3,
11504
11504
  ResourceNotFoundError as ResourceNotFoundError3
11505
11505
  } from "@funkit/utils";
11506
11506
 
11507
+ // src/utils/index.ts
11508
+ import { toHex as toHex3 } from "viem";
11509
+
11507
11510
  // src/utils/ApiUtils.ts
11508
11511
  import {
11509
- retry
11510
- } from "@lifeomic/attempt";
11511
- import {
11512
- AccessDeniedError,
11513
- ErrorCode,
11514
- InternalFailureError,
11515
11512
  InvalidParameterError,
11516
11513
  ResourceNotFoundError,
11517
- ThrottlingError,
11518
11514
  UserOpFailureError
11519
11515
  } from "@funkit/utils";
11520
11516
  var errorHandler = (err, context) => {
@@ -11536,155 +11532,17 @@ var DEFAULT_RETRY_OPTIONS = {
11536
11532
  beforeAttempt: null,
11537
11533
  calculateDelay: null
11538
11534
  };
11539
- var sendRequest = async (uri, method, apiKey, body, retryOptions) => {
11540
- try {
11541
- const headers = {
11542
- "Content-Type": "application/json"
11543
- };
11544
- if (apiKey) {
11545
- headers["X-Api-Key"] = apiKey;
11546
- }
11547
- const finalRetryOptions = {
11548
- ...DEFAULT_RETRY_OPTIONS,
11549
- ...retryOptions || {}
11550
- };
11551
- return retry(async () => {
11552
- const response = await fetch(uri, {
11553
- method,
11554
- headers,
11555
- redirect: "follow",
11556
- body: method !== "GET" ? stringify(body) : void 0
11557
- });
11558
- const json = await response.json();
11559
- if (response.ok) {
11560
- return json;
11561
- }
11562
- if (response.status === 400) {
11563
- throw new InvalidParameterError(
11564
- ErrorCode.InvalidParameter,
11565
- `bad request ${JSON.stringify(json)}`,
11566
- `bad request ${JSON.stringify(json)}`,
11567
- { body },
11568
- "check the api call parameters. its mostly because some call parameters are wrong",
11569
- "https://docs.fun.xyz"
11570
- );
11571
- }
11572
- if (response.status === 403) {
11573
- throw new AccessDeniedError(
11574
- ErrorCode.Unauthorized,
11575
- "Invalid API key or insufficient access.",
11576
- "Invalid API key or insufficient access.",
11577
- { apiKey },
11578
- "Check your api key at https://app.fun.xyz and check with fun team if you believe something is off",
11579
- "https://docs.fun.xyz"
11580
- );
11581
- }
11582
- if (response.status === 404) {
11583
- throw new ResourceNotFoundError(
11584
- ErrorCode.ServerMissingData,
11585
- JSON.stringify(json),
11586
- JSON.stringify(json),
11587
- { body },
11588
- "check the api call parameters. its mostly because some call parameters are wrong",
11589
- "https://docs.fun.xyz"
11590
- );
11591
- }
11592
- if (response.status === 429) {
11593
- throw new ThrottlingError(
11594
- ErrorCode.RequestLimitExceeded,
11595
- `too many requests ${JSON.stringify(json)}`,
11596
- `too many requests ${JSON.stringify(json)}`,
11597
- { body },
11598
- "you are making too many requests. please slow down. Reach out to fun team if you need more quota",
11599
- "https://docs.fun.xyz"
11600
- );
11601
- }
11602
- if (response.status === 500) {
11603
- if (json.errorCode === ErrorCode.UserOpFailureError) {
11604
- throw new UserOpFailureError(
11605
- ErrorCode.UserOpFailureError,
11606
- JSON.stringify(json),
11607
- JSON.stringify(json),
11608
- { body },
11609
- "fix user op failure. Most of the time this is due to invalid parameters",
11610
- "https://docs.fun.xyz"
11611
- );
11612
- }
11613
- throw new InternalFailureError(
11614
- ErrorCode.ServerFailure,
11615
- `server failure ${JSON.stringify(json)}`,
11616
- json.errorMsg,
11617
- { body },
11618
- "retry later. if it still fails, please contact us.",
11619
- "https://docs.fun.xyz"
11620
- );
11621
- }
11622
- if (response.status === 504) {
11623
- throw new InternalFailureError(
11624
- ErrorCode.ServerTimeout,
11625
- `server timeout failure ${JSON.stringify(json)}`,
11626
- json.errorMsg,
11627
- { body },
11628
- "retry later. if it still fails, please contact us.",
11629
- "https://docs.fun.xyz"
11630
- );
11631
- }
11632
- if (!response.ok) {
11633
- throw new InternalFailureError(
11634
- ErrorCode.UnknownServerError,
11635
- `unknown server failure ${JSON.stringify(json)}`,
11636
- json.errorMsg,
11637
- { body },
11638
- "retry later. if it still fails, please contact us.",
11639
- "https://docs.fun.xyz"
11640
- );
11641
- }
11642
- return {};
11643
- }, finalRetryOptions);
11644
- } catch (err) {
11645
- throw new InternalFailureError(
11646
- ErrorCode.ServerConnectionError,
11647
- `Cannot connect to Fun API Service ${err}`,
11648
- "",
11649
- { body },
11650
- "retry later. if it still fails, please contact us.",
11651
- "https://docs.fun.xyz"
11652
- );
11653
- }
11654
- };
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
11535
 
11680
11536
  // src/utils/AuthUtils.ts
11681
11537
  import { v4 as uuidv4 } from "uuid";
11682
11538
  import { generatePrivateKey as generateRandomPrivateKey } from "viem/accounts";
11683
11539
  import { createUser, getUserUniqueId } from "@funkit/api-base";
11684
- var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false) => {
11540
+ var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false, options) => {
11685
11541
  const authUniqueId = (skipDBActions ? addr : await getUserUniqueId({
11686
11542
  authId,
11687
- apiKey: globalThis.globalEnvOption.apiKey
11543
+ apiKey: globalThis.globalEnvOption.apiKey,
11544
+ logger: options?.logger,
11545
+ signal: options?.signal
11688
11546
  })) || uuidv4();
11689
11547
  const words = authId.split("###");
11690
11548
  const method = words[0].startsWith("0x") ? "eoa" : words[0];
@@ -11693,7 +11551,9 @@ var getAuthUniqueId = async (authId, addr = "NO_ADDRESS", skipDBActions = false)
11693
11551
  addr,
11694
11552
  method,
11695
11553
  userUniqueId: authUniqueId,
11696
- apiKey: globalThis.globalEnvOption.apiKey
11554
+ apiKey: globalThis.globalEnvOption.apiKey,
11555
+ logger: options?.logger,
11556
+ signal: options?.signal
11697
11557
  });
11698
11558
  return authUniqueId;
11699
11559
  };
@@ -11702,7 +11562,7 @@ var generatePrivateKey = () => {
11702
11562
  };
11703
11563
 
11704
11564
  // src/utils/ChainUtils.ts
11705
- import { getAssetFromFaucet } from "@funkit/api-base";
11565
+ import { getAssetFromFaucet, sendGetRequest } from "@funkit/api-base";
11706
11566
  import {
11707
11567
  concat,
11708
11568
  decodeAbiParameters,
@@ -11714,7 +11574,7 @@ import {
11714
11574
  toBytes,
11715
11575
  toHex
11716
11576
  } from "viem";
11717
- import { ErrorCode as ErrorCode2, InvalidParameterError as InvalidParameterError2 } from "@funkit/utils";
11577
+ import { ErrorCode, InvalidParameterError as InvalidParameterError2 } from "@funkit/utils";
11718
11578
  var isAddress = (address) => {
11719
11579
  try {
11720
11580
  const [decodedAddr] = decodeAbiParameters(
@@ -11727,8 +11587,11 @@ var isAddress = (address) => {
11727
11587
  }
11728
11588
  };
11729
11589
  var fundWallet = async (auth, wallet, value, txOptions = globalThis.globalEnvOption) => {
11730
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
11731
- const chainId = await chain.getChainId();
11590
+ const chain = await Chain.getChain(
11591
+ { chainIdentifier: txOptions.chain },
11592
+ txOptions
11593
+ );
11594
+ const chainId = await chain.getChainId(txOptions);
11732
11595
  const to = await wallet.getAddress();
11733
11596
  let txData;
11734
11597
  if (gasSpecificChain[chainId]) {
@@ -11736,7 +11599,7 @@ var fundWallet = async (auth, wallet, value, txOptions = globalThis.globalEnvOpt
11736
11599
  let maxPriorityFee;
11737
11600
  let maxFee;
11738
11601
  try {
11739
- const { standard } = await getGasStation(gasStationUrl);
11602
+ const { standard } = await getGasStation(gasStationUrl, txOptions);
11740
11603
  maxPriorityFee = standard.maxPriorityFee;
11741
11604
  maxFee = standard.maxFee;
11742
11605
  } catch (_err) {
@@ -11771,13 +11634,14 @@ var randomBytes = (length) => {
11771
11634
  }
11772
11635
  return toHex(bytes);
11773
11636
  };
11774
- var getWalletPermitNonce = async (walletAddr, chain, nonceKey = 0) => {
11637
+ var getWalletPermitNonce = async (walletAddr, chain, nonceKey = 0, options) => {
11775
11638
  try {
11776
11639
  return await WALLET_CONTRACT_INTERFACE.readFromChain(
11777
11640
  walletAddr,
11778
11641
  "getNonce",
11779
11642
  [nonceKey],
11780
- chain
11643
+ chain,
11644
+ options
11781
11645
  );
11782
11646
  } catch (_err) {
11783
11647
  return 0n;
@@ -11821,15 +11685,19 @@ var getPermitHash = (token, to, amount, nonce, walletAddr, chainId) => {
11821
11685
  );
11822
11686
  return keccak256(concat([DOMAIN_SEPARATOR, PERMIT_HASH]));
11823
11687
  };
11824
- var getGasStation = async (gasStationUrl) => {
11825
- return await sendRequest(gasStationUrl, "GET", "");
11688
+ var getGasStation = async (gasStationUrl, options) => {
11689
+ return await sendGetRequest({
11690
+ uri: gasStationUrl,
11691
+ apiKey: globalThis.globalEnvOption.apiKey,
11692
+ signal: options?.signal
11693
+ });
11826
11694
  };
11827
- var useFaucet = async (chainIdentifier, wallet) => {
11828
- const chain = await Chain.getChain({ chainIdentifier });
11829
- const chainName = await chain.getChainName();
11695
+ var useFaucet = async (chainIdentifier, wallet, txOptions) => {
11696
+ const chain = await Chain.getChain({ chainIdentifier }, txOptions);
11697
+ const chainName = await chain.getChainName(txOptions);
11830
11698
  if (chainName !== "goerli") {
11831
11699
  throw new InvalidParameterError2(
11832
- ErrorCode2.InvalidChainIdentifier,
11700
+ ErrorCode.InvalidChainIdentifier,
11833
11701
  "Only Goerli is supported",
11834
11702
  "Only Goerli is supported",
11835
11703
  chainIdentifier,
@@ -11843,25 +11711,33 @@ var useFaucet = async (chainIdentifier, wallet) => {
11843
11711
  token: "eth",
11844
11712
  chain: chainName,
11845
11713
  walletAddress,
11846
- apiKey: globalThis.globalEnvOption.apiKey
11714
+ apiKey: globalThis.globalEnvOption.apiKey,
11715
+ logger: txOptions?.logger,
11716
+ signal: txOptions?.signal
11847
11717
  }),
11848
11718
  getAssetFromFaucet({
11849
11719
  token: "usdc",
11850
11720
  chain: chainName,
11851
11721
  walletAddress,
11852
- apiKey: globalThis.globalEnvOption.apiKey
11722
+ apiKey: globalThis.globalEnvOption.apiKey,
11723
+ logger: txOptions?.logger,
11724
+ signal: txOptions?.signal
11853
11725
  }),
11854
11726
  getAssetFromFaucet({
11855
11727
  token: "usdt",
11856
11728
  chain: chainName,
11857
11729
  walletAddress,
11858
- apiKey: globalThis.globalEnvOption.apiKey
11730
+ apiKey: globalThis.globalEnvOption.apiKey,
11731
+ logger: txOptions?.logger,
11732
+ signal: txOptions?.signal
11859
11733
  }),
11860
11734
  getAssetFromFaucet({
11861
11735
  token: "dai",
11862
11736
  chain: chainName,
11863
11737
  walletAddress,
11864
- apiKey: globalThis.globalEnvOption.apiKey
11738
+ apiKey: globalThis.globalEnvOption.apiKey,
11739
+ logger: txOptions?.logger,
11740
+ signal: txOptions?.signal
11865
11741
  })
11866
11742
  ]);
11867
11743
  return [ethRequest, usdcRequest, usdtRequest, daiRequest];
@@ -11891,13 +11767,7 @@ var getPaymasterType = (txOptions) => {
11891
11767
  };
11892
11768
 
11893
11769
  // src/utils/UserOpUtils.ts
11894
- import {
11895
- encodeAbiParameters as encodeAbiParameters2,
11896
- formatUnits,
11897
- keccak256 as keccak2562,
11898
- toBytes as toBytes2,
11899
- toHex as toHex2
11900
- } from "viem";
11770
+ import { encodeAbiParameters as encodeAbiParameters2, keccak256 as keccak2562, toBytes as toBytes2, toHex as toHex2 } from "viem";
11901
11771
  var calcPreVerificationGas = (userOp) => {
11902
11772
  const ov = DefaultGasOverheads;
11903
11773
  const p = Object.assign(
@@ -11937,43 +11807,6 @@ function packUserOp(op, forSignature = true) {
11937
11807
  }));
11938
11808
  return encode(typevalues, forSignature);
11939
11809
  }
11940
- async function gasCalculation(txid, chain) {
11941
- if (!txid || txid === "0x")
11942
- return { gasUsed: "-1", opFee: "-1", opFeeUSD: "-1" };
11943
- const provider = await chain.getClient();
11944
- const txReceipt = await provider.waitForTransactionReceipt({
11945
- hash: txid
11946
- });
11947
- const gasUsed = txReceipt.gasUsed;
11948
- const gasPrice = txReceipt.effectiveGasPrice;
11949
- const opFee = gasUsed * gasPrice;
11950
- const chainPrice = BigInt(
11951
- Math.ceil(await getPriceData(await chain.getCurrency()) * 100)
11952
- );
11953
- const opFeeUSD = opFee * BigInt(chainPrice);
11954
- return {
11955
- gasUsed: gasUsed.toString(),
11956
- opFee: formatUnits(opFee, 18).toString(),
11957
- opFeeUSD: formatUnits(opFeeUSD, 20).toString()
11958
- };
11959
- }
11960
- var PRICE_URL = "https://min-api.cryptocompare.com/data/price";
11961
- async function getPriceData(chainCurrency) {
11962
- const data = await sendRequest(
11963
- `${PRICE_URL}?fsym=${chainCurrency}&tsyms=USD`,
11964
- "GET",
11965
- "",
11966
- {}
11967
- );
11968
- return data.USD;
11969
- }
11970
- var stringify = (object) => {
11971
- return JSON.stringify(
11972
- object,
11973
- (_, value) => typeof value === "bigint" ? toHex2(value) : value
11974
- // return everything else unchanged
11975
- );
11976
- };
11977
11810
  var DefaultGasOverheads = {
11978
11811
  fixed: 28e3,
11979
11812
  perUserOp: 18300,
@@ -12063,20 +11896,21 @@ var userOpTypeSig = {
12063
11896
  name: "userOp",
12064
11897
  type: "tuple"
12065
11898
  };
12066
- async function getOpHash(chain, userOp) {
12067
- const entryPointAddress = await chain.getAddress("entryPointAddress");
11899
+ async function getOpHash(chain, userOp, options) {
11900
+ const entryPointAddress = await chain.getAddress("entryPointAddress", options);
12068
11901
  return await ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(
12069
11902
  entryPointAddress,
12070
11903
  "getUserOpHash",
12071
11904
  [userOp],
12072
- chain
11905
+ chain,
11906
+ options
12073
11907
  );
12074
11908
  }
12075
11909
 
12076
11910
  // src/utils/TokenUtils.ts
12077
11911
  import { getAssetErc20ByChainAndSymbol } from "@funkit/api-base";
12078
- import { ErrorCode as ErrorCode3, ResourceNotFoundError as ResourceNotFoundError2 } from "@funkit/utils";
12079
- async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId) {
11912
+ import { ErrorCode as ErrorCode2, ResourceNotFoundError as ResourceNotFoundError2 } from "@funkit/utils";
11913
+ async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId, options) {
12080
11914
  const normalizedSymbol = inputSymbol.toLowerCase();
12081
11915
  if (BASE_WRAP_TOKEN_ADDR?.[inputChainId]?.[normalizedSymbol]) {
12082
11916
  return BASE_WRAP_TOKEN_ADDR[inputChainId][normalizedSymbol];
@@ -12084,13 +11918,15 @@ async function getTokenAddressBySymbolAndChainId(inputSymbol, inputChainId) {
12084
11918
  const tokenInfo = await getAssetErc20ByChainAndSymbol({
12085
11919
  chainId: inputChainId,
12086
11920
  symbol: normalizedSymbol,
12087
- apiKey: globalThis.globalEnvOption.apiKey
11921
+ apiKey: globalThis.globalEnvOption.apiKey,
11922
+ logger: options?.logger,
11923
+ signal: options?.signal
12088
11924
  });
12089
11925
  if (tokenInfo.address) {
12090
11926
  return tokenInfo.address;
12091
11927
  }
12092
11928
  throw new ResourceNotFoundError2(
12093
- ErrorCode3.TokenNotFound,
11929
+ ErrorCode2.TokenNotFound,
12094
11930
  "token symbol does not exist on provided chain",
12095
11931
  "token symbol does not exist on provided chain",
12096
11932
  { symbol: inputSymbol, chainId: inputChainId },
@@ -12125,14 +11961,15 @@ var generateRandomNonce = () => {
12125
11961
  const randomKey = generateRandomNonceKey();
12126
11962
  return randomKey << 64n;
12127
11963
  };
12128
- var getWalletAddress = async (chain, walletUniqueId) => {
11964
+ var getWalletAddress = async (chain, walletUniqueId, options) => {
12129
11965
  const data = encodeLoginData({ salt: walletUniqueId });
12130
- const factoryAddress = await chain.getAddress("factoryAddress");
11966
+ const factoryAddress = await chain.getAddress("factoryAddress", options);
12131
11967
  return await FACTORY_CONTRACT_INTERFACE.readFromChain(
12132
11968
  factoryAddress,
12133
11969
  "getAddress",
12134
11970
  [data],
12135
- chain
11971
+ chain,
11972
+ options
12136
11973
  );
12137
11974
  };
12138
11975
  var isWalletInitOp = (userOp) => {
@@ -12158,6 +11995,15 @@ var isSignatureMissing = (userId, signatures) => {
12158
11995
  return sigMissing;
12159
11996
  };
12160
11997
 
11998
+ // src/utils/index.ts
11999
+ var stringify = (object) => {
12000
+ return JSON.stringify(
12001
+ object,
12002
+ (_, value) => typeof value === "bigint" ? toHex3(value) : value
12003
+ // return everything else unchanged
12004
+ );
12005
+ };
12006
+
12161
12007
  // src/data/Chain.ts
12162
12008
  var Chain = class _Chain {
12163
12009
  constructor(chainInput) {
@@ -12165,7 +12011,7 @@ var Chain = class _Chain {
12165
12011
  this.addresses = {};
12166
12012
  if (!chainInput.chainIdentifier && !chainInput.rpcUrl) {
12167
12013
  throw new InvalidParameterError3(
12168
- ErrorCode4.InvalidChainIdentifier,
12014
+ ErrorCode3.InvalidChainIdentifier,
12169
12015
  "valid chain identifier or rpcUrl is required, could be chainId, chainName, Fun Chain object, or rpcUrl",
12170
12016
  "valid chain identifier or rpcUrl is required, could be chainId, chainName, Fun Chain object, or rpcUrl",
12171
12017
  { chainInput },
@@ -12183,11 +12029,11 @@ var Chain = class _Chain {
12183
12029
  this.name = chainInput.chainIdentifier;
12184
12030
  }
12185
12031
  }
12186
- static async getChain(chainInput) {
12032
+ static async getChain(chainInput, options) {
12187
12033
  if (chainInput.chainIdentifier instanceof _Chain) {
12188
12034
  return chainInput.chainIdentifier;
12189
12035
  }
12190
- if (!_Chain.chain || await _Chain.chain.getChainId() !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getChainName() !== chainInput.chainIdentifier?.toString() && await _Chain.chain.getRpcUrl() !== chainInput.rpcUrl) {
12036
+ 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
12037
  if (typeof chainInput.chainIdentifier === "string") {
12192
12038
  chainInput.chainIdentifier = chainInput.chainIdentifier.replace(
12193
12039
  /\s/g,
@@ -12204,35 +12050,39 @@ var Chain = class _Chain {
12204
12050
  }
12205
12051
  return _Chain.chain;
12206
12052
  }
12207
- async init() {
12053
+ async init(options) {
12208
12054
  if (this.initialized) return;
12209
12055
  if (this.id) {
12210
- await this.loadChain(this.id);
12056
+ await this.loadChain(this.id, options);
12211
12057
  } else if (this.name) {
12212
- await this.loadChain(this.name);
12058
+ await this.loadChain(this.name, options);
12213
12059
  } else if (this.rpcUrl) {
12214
- await this.loadChainFromRpc();
12060
+ await this.loadChainFromRpc(options);
12215
12061
  }
12216
12062
  this.initialized = true;
12217
12063
  }
12218
- async loadChainFromRpc() {
12064
+ async loadChainFromRpc(options) {
12219
12065
  this.client = createPublicClient({
12220
12066
  transport: http(this.rpcUrl)
12221
12067
  });
12222
12068
  this.id = (await this.client.getChainId()).toString();
12223
- await this.loadChain(this.id);
12069
+ await this.loadChain(this.id, options);
12224
12070
  }
12225
- async loadChain(identifier) {
12071
+ async loadChain(identifier, options) {
12226
12072
  let chain;
12227
12073
  if (!Number(identifier)) {
12228
12074
  chain = await getChainFromName({
12229
12075
  name: identifier,
12230
- apiKey: globalThis.globalEnvOption.apiKey
12076
+ apiKey: globalThis.globalEnvOption.apiKey,
12077
+ logger: options?.logger,
12078
+ signal: options?.signal
12231
12079
  });
12232
12080
  } else {
12233
12081
  chain = await getChainFromId({
12234
12082
  chainId: identifier,
12235
- apiKey: globalThis.globalEnvOption.apiKey
12083
+ apiKey: globalThis.globalEnvOption.apiKey,
12084
+ logger: options?.logger,
12085
+ signal: options?.signal
12236
12086
  });
12237
12087
  }
12238
12088
  this.id = chain.id;
@@ -12251,24 +12101,24 @@ var Chain = class _Chain {
12251
12101
  this.client = createPublicClient({ transport: http(this.rpcUrl) });
12252
12102
  Object.assign(this, { ...this, addresses });
12253
12103
  }
12254
- async getChainId() {
12255
- await this.init();
12104
+ async getChainId(options) {
12105
+ await this.init(options);
12256
12106
  return this.id;
12257
12107
  }
12258
- async getChainName() {
12259
- await this.init();
12108
+ async getChainName(options) {
12109
+ await this.init(options);
12260
12110
  return this.name;
12261
12111
  }
12262
- async getRpcUrl() {
12263
- await this.init();
12112
+ async getRpcUrl(options) {
12113
+ await this.init(options);
12264
12114
  return this.rpcUrl;
12265
12115
  }
12266
- async getAddress(name) {
12267
- await this.init();
12116
+ async getAddress(name, options) {
12117
+ await this.init(options);
12268
12118
  const res = this.addresses[name];
12269
12119
  if (!res) {
12270
12120
  throw new ResourceNotFoundError3(
12271
- ErrorCode4.AddressNotFound,
12121
+ ErrorCode3.AddressNotFound,
12272
12122
  "address not found",
12273
12123
  "address not found",
12274
12124
  { name },
@@ -12278,21 +12128,23 @@ var Chain = class _Chain {
12278
12128
  }
12279
12129
  return res;
12280
12130
  }
12281
- async getCurrency() {
12282
- await this.init();
12131
+ async getCurrency(options) {
12132
+ await this.init(options);
12283
12133
  return this.currency;
12284
12134
  }
12285
- async getClient() {
12286
- await this.init();
12135
+ async getClient(options) {
12136
+ await this.init(options);
12287
12137
  return this.client;
12288
12138
  }
12289
- async getFeeData() {
12290
- await this.init();
12139
+ async getFeeData(options) {
12140
+ await this.init(options);
12291
12141
  let result;
12292
12142
  try {
12293
12143
  result = await getUserOpGasPrice({
12294
12144
  chainId: this.id,
12295
- apiKey: globalThis.globalEnvOption.apiKey
12145
+ apiKey: globalThis.globalEnvOption.apiKey,
12146
+ logger: options?.logger,
12147
+ signal: options?.signal
12296
12148
  });
12297
12149
  } catch (_err) {
12298
12150
  const fallBackGasPrice = await this.client.getGasPrice();
@@ -12303,11 +12155,11 @@ var Chain = class _Chain {
12303
12155
  }
12304
12156
  return result;
12305
12157
  }
12306
- async estimateOpGas(partialOp) {
12307
- await this.init();
12158
+ async estimateOpGas(partialOp, options) {
12159
+ await this.init(options);
12308
12160
  if (!this.addresses || !this.addresses.entryPointAddress) {
12309
- throw new InternalFailureError2(
12310
- ErrorCode4.AddressNotFound,
12161
+ throw new InternalFailureError(
12162
+ ErrorCode3.AddressNotFound,
12311
12163
  "entryPointAddress is required",
12312
12164
  "",
12313
12165
  { partialOp },
@@ -12329,7 +12181,9 @@ var Chain = class _Chain {
12329
12181
  entryPointAddress: this.addresses.entryPointAddress,
12330
12182
  userOp: estimationUserOp
12331
12183
  },
12332
- apiKey: globalThis.globalEnvOption.apiKey
12184
+ apiKey: globalThis.globalEnvOption.apiKey,
12185
+ logger: options?.logger,
12186
+ signal: options?.signal
12333
12187
  });
12334
12188
  if (!preVerificationGas || !verificationGasLimit || !callGasLimit) {
12335
12189
  throw new Error(
@@ -12345,20 +12199,25 @@ var Chain = class _Chain {
12345
12199
  verificationGasLimit = BigInt(verificationGasLimit) + 200000n;
12346
12200
  return { preVerificationGas, verificationGasLimit, callGasLimit };
12347
12201
  }
12348
- async getTxId(userOpHash, timeout = 6e4, interval = 5e3, fromBlock) {
12202
+ async getTxId(userOpHash, timeout = 6e4, interval = 5e3, fromBlock, options) {
12349
12203
  const endtime = Date.now() + timeout;
12350
- const client = await this.getClient();
12351
- const entryPointAddress = await this.getAddress("entryPointAddress");
12204
+ const client = await this.getClient(options);
12205
+ const entryPointAddress = await this.getAddress(
12206
+ "entryPointAddress",
12207
+ options
12208
+ );
12352
12209
  const fromBlockFinal = fromBlock || await client.getBlockNumber() - 100n;
12353
12210
  while (Date.now() < endtime) {
12354
12211
  let events;
12355
- if (await client.getChainId() === 84531 || await client.getChainId() === 36865) {
12212
+ const chainId = await client.getChainId();
12213
+ if (chainId === 84531 || chainId === 36865) {
12356
12214
  events = await ENTRYPOINT_CONTRACT_INTERFACE.getLog(
12357
12215
  entryPointAddress,
12358
12216
  "UserOperationEvent",
12359
12217
  { userOpHash },
12360
12218
  client,
12361
- fromBlockFinal
12219
+ fromBlockFinal,
12220
+ options
12362
12221
  );
12363
12222
  } else {
12364
12223
  const filter = await ENTRYPOINT_CONTRACT_INTERFACE.createFilter(
@@ -12366,7 +12225,8 @@ var Chain = class _Chain {
12366
12225
  "UserOperationEvent",
12367
12226
  [userOpHash],
12368
12227
  client,
12369
- fromBlockFinal
12228
+ fromBlockFinal,
12229
+ options
12370
12230
  );
12371
12231
  events = await client.getFilterLogs({ filter });
12372
12232
  }
@@ -12377,21 +12237,21 @@ var Chain = class _Chain {
12377
12237
  }
12378
12238
  return null;
12379
12239
  }
12380
- async addressIsContract(address) {
12381
- return isContract(address, await this.getClient());
12240
+ async addressIsContract(address, options) {
12241
+ return isContract(address, await this.getClient(options));
12382
12242
  }
12383
12243
  };
12384
12244
 
12385
12245
  // src/data/NFT.ts
12386
12246
  import { isAddress as isAddress2 } from "viem";
12387
12247
  import { getNftAddress, getNftName } from "@funkit/api-base";
12388
- import { ErrorCode as ErrorCode5, InvalidParameterError as InvalidParameterError4 } from "@funkit/utils";
12248
+ import { ErrorCode as ErrorCode4, InvalidParameterError as InvalidParameterError4 } from "@funkit/utils";
12389
12249
  var NFT = class _NFT {
12390
12250
  constructor(input) {
12391
12251
  this.name = "";
12392
12252
  if (!input) {
12393
12253
  throw new InvalidParameterError4(
12394
- ErrorCode5.InvalidNFTIdentifier,
12254
+ ErrorCode4.InvalidNFTIdentifier,
12395
12255
  "valid NFT identifier is required, could be address or name",
12396
12256
  "valid NFT identifier is required, could be address or name",
12397
12257
  { input },
@@ -12406,37 +12266,47 @@ var NFT = class _NFT {
12406
12266
  }
12407
12267
  }
12408
12268
  async approve(spender, tokenId, options = globalThis.globalEnvOption) {
12409
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12269
+ const chain = await Chain.getChain(
12270
+ { chainIdentifier: options.chain },
12271
+ options
12272
+ );
12410
12273
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12411
- await this.getAddress(),
12274
+ await this.getAddress(options),
12412
12275
  "approve",
12413
12276
  [spender, tokenId]
12414
12277
  );
12415
12278
  return { ...data, chain };
12416
12279
  }
12417
12280
  async ownerOf(tokenId, options = globalThis.globalEnvOption) {
12418
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12281
+ const chain = await Chain.getChain(
12282
+ { chainIdentifier: options.chain },
12283
+ options
12284
+ );
12419
12285
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12420
- await this.getAddress(),
12286
+ await this.getAddress(options),
12421
12287
  "ownerOf",
12422
12288
  [tokenId],
12423
- chain
12289
+ chain,
12290
+ options
12424
12291
  );
12425
12292
  }
12426
12293
  async approveForAll(spender, options = globalThis.globalEnvOption) {
12427
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12294
+ const chain = await Chain.getChain(
12295
+ { chainIdentifier: options.chain },
12296
+ options
12297
+ );
12428
12298
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12429
- await this.getAddress(),
12299
+ await this.getAddress(options),
12430
12300
  "setApprovalForAll",
12431
12301
  [spender, true]
12432
12302
  );
12433
12303
  return { ...data, chain };
12434
12304
  }
12435
- async getAddress() {
12305
+ async getAddress(options) {
12436
12306
  if (!this.address) {
12437
12307
  if (!this.name) {
12438
12308
  throw new InvalidParameterError4(
12439
- ErrorCode5.InvalidNFTIdentifier,
12309
+ ErrorCode4.InvalidNFTIdentifier,
12440
12310
  "valid NFT identifier is required, could be address or name",
12441
12311
  "valid NFT identifier is required, could be address or name",
12442
12312
  {},
@@ -12446,7 +12316,9 @@ var NFT = class _NFT {
12446
12316
  }
12447
12317
  const nft = await getNftAddress({
12448
12318
  name: this.name,
12449
- apiKey: globalThis.globalEnvOption.apiKey
12319
+ apiKey: globalThis.globalEnvOption.apiKey,
12320
+ logger: options?.logger,
12321
+ signal: options?.signal
12450
12322
  });
12451
12323
  return nft.address;
12452
12324
  }
@@ -12454,47 +12326,66 @@ var NFT = class _NFT {
12454
12326
  }
12455
12327
  async getName(options = globalThis.globalEnvOption) {
12456
12328
  if (!this.name && this.address) {
12457
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12329
+ const chain = await Chain.getChain(
12330
+ { chainIdentifier: options.chain },
12331
+ options
12332
+ );
12458
12333
  const nft = await getNftName({
12459
- chainId: await chain.getChainId(),
12334
+ chainId: await chain.getChainId(options),
12460
12335
  nftAddress: this.address,
12461
- apiKey: globalThis.globalEnvOption.apiKey
12336
+ apiKey: globalThis.globalEnvOption.apiKey,
12337
+ logger: options.logger,
12338
+ signal: options.signal
12462
12339
  });
12463
12340
  return nft.name;
12464
12341
  }
12465
12342
  return this.name;
12466
12343
  }
12467
12344
  async getBalance(address, options = globalThis.globalEnvOption) {
12468
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12345
+ const chain = await Chain.getChain(
12346
+ { chainIdentifier: options.chain },
12347
+ options
12348
+ );
12469
12349
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12470
- await this.getAddress(),
12350
+ await this.getAddress(options),
12471
12351
  "balanceOf",
12472
12352
  [address],
12473
- chain
12353
+ chain,
12354
+ options
12474
12355
  );
12475
12356
  }
12476
12357
  async getApproved(tokenId, options = globalThis.globalEnvOption) {
12477
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12358
+ const chain = await Chain.getChain(
12359
+ { chainIdentifier: options.chain },
12360
+ options
12361
+ );
12478
12362
  return await ERC721_CONTRACT_INTERFACE.readFromChain(
12479
- await this.getAddress(),
12363
+ await this.getAddress(options),
12480
12364
  "getApproved",
12481
12365
  [tokenId],
12482
- chain
12366
+ chain,
12367
+ options
12483
12368
  );
12484
12369
  }
12485
12370
  async revokeForAll(spender, options = globalThis.globalEnvOption) {
12486
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12371
+ const chain = await Chain.getChain(
12372
+ { chainIdentifier: options.chain },
12373
+ options
12374
+ );
12487
12375
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12488
- await this.getAddress(),
12376
+ await this.getAddress(options),
12489
12377
  "setApprovalForAll",
12490
12378
  [spender, false]
12491
12379
  );
12492
12380
  return { ...data, chain };
12493
12381
  }
12494
12382
  async transfer(sender, spender, tokenId, options = globalThis.globalEnvOption) {
12495
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
12383
+ const chain = await Chain.getChain(
12384
+ { chainIdentifier: options.chain },
12385
+ options
12386
+ );
12496
12387
  const data = ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
12497
- await this.getAddress(),
12388
+ await this.getAddress(options),
12498
12389
  "transferFrom",
12499
12390
  [sender, spender, tokenId]
12500
12391
  );
@@ -12508,9 +12399,9 @@ var NFT = class _NFT {
12508
12399
  const nft = new _NFT(data);
12509
12400
  return await nft.approveForAll(spender, options);
12510
12401
  }
12511
- static async getAddress(data) {
12402
+ static async getAddress(data, options) {
12512
12403
  const nft = new _NFT(data);
12513
- return await nft.getAddress();
12404
+ return await nft.getAddress(options);
12514
12405
  }
12515
12406
  static async getApproved(data, tokenId, options = globalThis.globalEnvOption) {
12516
12407
  const nft = new _NFT(data);
@@ -12559,13 +12450,17 @@ var Operation = class _Operation {
12559
12450
  static convertTypeToObject(op) {
12560
12451
  return new _Operation(op.userOp, op);
12561
12452
  }
12562
- async getOpHash(chain) {
12563
- const entryPointAddress = await chain.getAddress("entryPointAddress");
12453
+ async getOpHash(chain, options) {
12454
+ const entryPointAddress = await chain.getAddress(
12455
+ "entryPointAddress",
12456
+ options
12457
+ );
12564
12458
  return await ENTRYPOINT_CONTRACT_INTERFACE.readFromChain(
12565
12459
  entryPointAddress,
12566
12460
  "getUserOpHash",
12567
12461
  [this.userOp],
12568
- chain
12462
+ chain,
12463
+ options
12569
12464
  );
12570
12465
  }
12571
12466
  getMaxTxCost() {
@@ -12584,16 +12479,22 @@ var Operation = class _Operation {
12584
12479
  if (!this.userOp.signature || this.userOp.signature === "0x") {
12585
12480
  this.userOp.signature = await auth.getEstimateGasSignature(userId, this);
12586
12481
  }
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
- });
12482
+ const chain = await Chain.getChain(
12483
+ { chainIdentifier: options.chain },
12484
+ options
12485
+ );
12486
+ const res = await chain.estimateOpGas(
12487
+ {
12488
+ ...this.userOp,
12489
+ paymasterAndData: "0x",
12490
+ maxFeePerGas: 0n,
12491
+ maxPriorityFeePerGas: 0n,
12492
+ preVerificationGas: 0n,
12493
+ callGasLimit: 0n,
12494
+ verificationGasLimit: BigInt(1e7)
12495
+ },
12496
+ options
12497
+ );
12597
12498
  this.userOp.preVerificationGas = res.preVerificationGas;
12598
12499
  this.userOp.verificationGasLimit = res.verificationGasLimit;
12599
12500
  this.userOp.callGasLimit = res.callGasLimit;
@@ -12690,10 +12591,10 @@ function toBytes32Arr(data) {
12690
12591
  }
12691
12592
 
12692
12593
  // src/data/Token.ts
12693
- import { formatUnits as formatUnits2, isAddress as isAddress3, parseUnits } from "viem";
12594
+ import { formatUnits, isAddress as isAddress3, parseUnits } from "viem";
12694
12595
  import {
12695
- ErrorCode as ErrorCode6,
12696
- InternalFailureError as InternalFailureError3,
12596
+ ErrorCode as ErrorCode5,
12597
+ InternalFailureError as InternalFailureError2,
12697
12598
  InvalidParameterError as InvalidParameterError5
12698
12599
  } from "@funkit/utils";
12699
12600
  var wrappedNativeTokens = {
@@ -12716,20 +12617,28 @@ var Token = class _Token {
12716
12617
  }
12717
12618
  this.symbol = input.toLowerCase();
12718
12619
  }
12719
- async getAddress() {
12720
- const chainId = await this.chain.getChainId();
12620
+ async getAddress(options) {
12621
+ const chainId = await this.chain.getChainId(options);
12721
12622
  if (this.isNative) {
12722
12623
  const nativeName = wrappedNativeTokens[this.symbol];
12723
- return await getTokenAddressBySymbolAndChainId(nativeName, chainId);
12624
+ return await getTokenAddressBySymbolAndChainId(
12625
+ nativeName,
12626
+ chainId,
12627
+ options
12628
+ );
12724
12629
  }
12725
12630
  if (this.address) {
12726
12631
  return this.address;
12727
12632
  }
12728
12633
  if (this.symbol) {
12729
- return await getTokenAddressBySymbolAndChainId(this.symbol, chainId);
12634
+ return await getTokenAddressBySymbolAndChainId(
12635
+ this.symbol,
12636
+ chainId,
12637
+ options
12638
+ );
12730
12639
  }
12731
- throw new InternalFailureError3(
12732
- ErrorCode6.ServerMissingData,
12640
+ throw new InternalFailureError2(
12641
+ ErrorCode5.ServerMissingData,
12733
12642
  "server missing token symbol and address info",
12734
12643
  "",
12735
12644
  { symbol: this.symbol, address: this.address, isNative: this.isNative },
@@ -12737,42 +12646,44 @@ var Token = class _Token {
12737
12646
  "https://docs.fun.xyz"
12738
12647
  );
12739
12648
  }
12740
- async getDecimals() {
12649
+ async getDecimals(options) {
12741
12650
  if (this.isNative) {
12742
12651
  return 18n;
12743
12652
  }
12744
12653
  return await ERC20_CONTRACT_INTERFACE.readFromChain(
12745
- await this.getAddress(),
12654
+ await this.getAddress(options),
12746
12655
  "decimals",
12747
12656
  [],
12748
- this.chain
12657
+ this.chain,
12658
+ options
12749
12659
  );
12750
12660
  }
12751
- async getBalance(address) {
12752
- const amount = await this.getBalanceBN(address);
12753
- const decimals = await this.getDecimals();
12754
- return formatUnits2(amount, Number(decimals));
12661
+ async getBalance(address, options) {
12662
+ const amount = await this.getBalanceBN(address, options);
12663
+ const decimals = await this.getDecimals(options);
12664
+ return formatUnits(amount, Number(decimals));
12755
12665
  }
12756
- async getBalanceBN(address) {
12666
+ async getBalanceBN(address, options) {
12757
12667
  const chain = this.chain;
12758
12668
  let amount = 0n;
12759
12669
  if (this.isNative) {
12760
- const client = await chain.getClient();
12670
+ const client = await chain.getClient(options);
12761
12671
  amount = await client.getBalance({ address });
12762
12672
  } else {
12763
12673
  amount = await ERC20_CONTRACT_INTERFACE.readFromChain(
12764
- await this.getAddress(),
12674
+ await this.getAddress(options),
12765
12675
  "balanceOf",
12766
12676
  [address],
12767
- chain
12677
+ chain,
12678
+ options
12768
12679
  );
12769
12680
  }
12770
12681
  return amount;
12771
12682
  }
12772
- async getApproval(owner, spender) {
12683
+ async getApproval(owner, spender, options) {
12773
12684
  if (this.isNative) {
12774
12685
  throw new InvalidParameterError5(
12775
- ErrorCode6.InvalidParameter,
12686
+ ErrorCode5.InvalidParameter,
12776
12687
  "Native token can not approve",
12777
12688
  "Native token can not approve",
12778
12689
  { isNative: this.isNative },
@@ -12783,66 +12694,67 @@ var Token = class _Token {
12783
12694
  const chain = this.chain;
12784
12695
  return BigInt(
12785
12696
  await ERC20_CONTRACT_INTERFACE.readFromChain(
12786
- await this.getAddress(),
12697
+ await this.getAddress(options),
12787
12698
  "allowance",
12788
12699
  [owner, spender],
12789
- chain
12700
+ chain,
12701
+ options
12790
12702
  )
12791
12703
  );
12792
12704
  }
12793
- async getDecimalAmount(amount) {
12794
- const decimals = await this.getDecimals();
12705
+ async getDecimalAmount(amount, options) {
12706
+ const decimals = await this.getDecimals(options);
12795
12707
  return parseUnits(`${amount}`, Number(decimals));
12796
12708
  }
12797
- async approve(spender, amount) {
12798
- const amountDec = await this.getDecimalAmount(amount);
12709
+ async approve(spender, amount, options) {
12710
+ const amountDec = await this.getDecimalAmount(amount, options);
12799
12711
  const calldata = ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
12800
- await this.getAddress(),
12712
+ await this.getAddress(options),
12801
12713
  "approve",
12802
12714
  [spender, amountDec]
12803
12715
  );
12804
12716
  const { to, data, value } = calldata;
12805
12717
  return { to, data, value };
12806
12718
  }
12807
- async transfer(spender, amount) {
12808
- const amountDec = await this.getDecimalAmount(amount);
12719
+ async transfer(spender, amount, options) {
12720
+ const amountDec = await this.getDecimalAmount(amount, options);
12809
12721
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
12810
- await this.getAddress(),
12722
+ await this.getAddress(options),
12811
12723
  "transfer",
12812
12724
  [spender, amountDec]
12813
12725
  );
12814
12726
  }
12815
- static async getAddress(data, chain) {
12727
+ static async getAddress(data, chain, options) {
12816
12728
  const token = new _Token(data, chain);
12817
- return await token.getAddress();
12729
+ return await token.getAddress(options);
12818
12730
  }
12819
- static async getDecimals(data, chain) {
12731
+ static async getDecimals(data, chain, options) {
12820
12732
  const token = new _Token(data, chain);
12821
- return await token.getDecimals();
12733
+ return await token.getDecimals(options);
12822
12734
  }
12823
- static async getBalance(data, address, chain) {
12735
+ static async getBalance(data, address, chain, options) {
12824
12736
  const token = new _Token(data, chain);
12825
- return await token.getBalance(address);
12737
+ return await token.getBalance(address, options);
12826
12738
  }
12827
- static async getBalanceBN(data, address, chain) {
12739
+ static async getBalanceBN(data, address, chain, options) {
12828
12740
  const token = new _Token(data, chain);
12829
- return await token.getBalanceBN(address);
12741
+ return await token.getBalanceBN(address, options);
12830
12742
  }
12831
- static async getApproval(data, owner, spender, chain) {
12743
+ static async getApproval(data, owner, spender, chain, options) {
12832
12744
  const token = new _Token(data, chain);
12833
- return await token.getApproval(owner, spender);
12745
+ return await token.getApproval(owner, spender, options);
12834
12746
  }
12835
- static async getDecimalAmount(data, amount, chain) {
12747
+ static async getDecimalAmount(data, amount, chain, options) {
12836
12748
  const token = new _Token(data, chain);
12837
- return await token.getDecimalAmount(amount);
12749
+ return await token.getDecimalAmount(amount, options);
12838
12750
  }
12839
- static async approve(data, spender, amount, chain) {
12751
+ static async approve(data, spender, amount, chain, options) {
12840
12752
  const token = new _Token(data, chain);
12841
- return await token.approve(spender, amount);
12753
+ return await token.approve(spender, amount, options);
12842
12754
  }
12843
- static async transfer(data, spender, amount, chain) {
12755
+ static async transfer(data, spender, amount, chain, options) {
12844
12756
  const token = new _Token(data, chain);
12845
- return await token.transfer(spender, amount);
12757
+ return await token.transfer(spender, amount, options);
12846
12758
  }
12847
12759
  static isNative(data) {
12848
12760
  return data.toLowerCase() in wrappedNativeTokens;
@@ -12855,8 +12767,8 @@ var ContractInterface = class {
12855
12767
  constructor(abi) {
12856
12768
  this.abi = abi;
12857
12769
  }
12858
- async readFromChain(address, functionName, args, chainOrClient) {
12859
- const client = await parseClient(chainOrClient);
12770
+ async readFromChain(address, functionName, args, chainOrClient, options) {
12771
+ const client = await parseClient(chainOrClient, options);
12860
12772
  try {
12861
12773
  return await client.readContract({
12862
12774
  abi: this.abi,
@@ -12877,15 +12789,16 @@ var ContractInterface = class {
12877
12789
  );
12878
12790
  }
12879
12791
  }
12880
- async batchReadFromChain(address, chainOrClient, calls) {
12881
- const client = await parseClient(chainOrClient);
12792
+ async batchReadFromChain(address, chainOrClient, calls, options) {
12793
+ const client = await parseClient(chainOrClient, options);
12882
12794
  return await Promise.all(
12883
12795
  calls.map(async (call) => {
12884
12796
  return this.readFromChain(
12885
12797
  address,
12886
12798
  call.functionName,
12887
12799
  call.args ? call.args : [],
12888
- client
12800
+ client,
12801
+ options
12889
12802
  );
12890
12803
  })
12891
12804
  );
@@ -12905,8 +12818,8 @@ var ContractInterface = class {
12905
12818
  args
12906
12819
  });
12907
12820
  }
12908
- async createFilter(address, eventName, args, chainOrClient, fromBlock) {
12909
- const client = await parseClient(chainOrClient);
12821
+ async createFilter(address, eventName, args, chainOrClient, fromBlock, options) {
12822
+ const client = await parseClient(chainOrClient, options);
12910
12823
  return await client.createContractEventFilter({
12911
12824
  abi: this.abi,
12912
12825
  address,
@@ -12915,8 +12828,8 @@ var ContractInterface = class {
12915
12828
  fromBlock
12916
12829
  });
12917
12830
  }
12918
- async getLog(address, name, args, chainOrClient, fromBlock) {
12919
- const client = await parseClient(chainOrClient);
12831
+ async getLog(address, name, args, chainOrClient, fromBlock, options) {
12832
+ const client = await parseClient(chainOrClient, options);
12920
12833
  const event = getItemFromAbi(this.abi, name, "event");
12921
12834
  return await client.getLogs({
12922
12835
  address,
@@ -12926,10 +12839,10 @@ var ContractInterface = class {
12926
12839
  });
12927
12840
  }
12928
12841
  };
12929
- var parseClient = async (chainOrClient) => {
12842
+ var parseClient = async (chainOrClient, options) => {
12930
12843
  if (chainOrClient instanceof Chain) {
12931
12844
  const chain = chainOrClient;
12932
- return await chain.getClient();
12845
+ return await chain.getClient(options);
12933
12846
  }
12934
12847
  if (typeof chainOrClient.readContract === "function") {
12935
12848
  return chainOrClient;
@@ -13214,7 +13127,7 @@ var Auth = class {
13214
13127
  privateKey = `0x${authInput.privateKey}`;
13215
13128
  } else {
13216
13129
  throw new InvalidParameterError6(
13217
- ErrorCode7.InvalidParameter,
13130
+ ErrorCode6.InvalidParameter,
13218
13131
  "privateKey is not a valid one",
13219
13132
  "privateKey is not a valid one",
13220
13133
  authInput.privateKey,
@@ -13225,7 +13138,7 @@ var Auth = class {
13225
13138
  this.signer = privateKeyToAccount(privateKey);
13226
13139
  } else {
13227
13140
  throw new InvalidParameterError6(
13228
- ErrorCode7.MissingParameter,
13141
+ ErrorCode6.MissingParameter,
13229
13142
  "valid authInput is required",
13230
13143
  "valid authInput is required",
13231
13144
  authInput,
@@ -13282,9 +13195,9 @@ var Auth = class {
13282
13195
  * @param {boolean} isGroupOp - Whether the operation is a group operation (default: false).
13283
13196
  * @returns {Promise<Hex>} The signature of the operation.
13284
13197
  */
13285
- async signOp(operation, chain, isGroupOp = false) {
13198
+ async signOp(operation, chain, isGroupOp = false, options) {
13286
13199
  await this.init();
13287
- const opHash = await operation.getOpHash(chain);
13200
+ const opHash = await operation.getOpHash(chain, options);
13288
13201
  return await this.signHash(opHash, isGroupOp);
13289
13202
  }
13290
13203
  /**
@@ -13324,12 +13237,13 @@ var Auth = class {
13324
13237
  * @param {boolean} skipDBActions - Whether to skip database actions (default: false).
13325
13238
  * @returns {Promise<Hex>} The generated unique ID for the wallet.
13326
13239
  */
13327
- async getWalletUniqueId(index = 0, skipDBActions = false) {
13240
+ async getWalletUniqueId(index = 0, skipDBActions = false, options) {
13328
13241
  await this.init();
13329
13242
  const authUniqueId = await getAuthUniqueId(
13330
13243
  this.authId,
13331
13244
  await this.getAddress(),
13332
- skipDBActions
13245
+ skipDBActions,
13246
+ options
13333
13247
  );
13334
13248
  return keccak2564(toBytes5(`${authUniqueId}-${index}`));
13335
13249
  }
@@ -13341,13 +13255,16 @@ var Auth = class {
13341
13255
  */
13342
13256
  async sendTx(txData, options = globalThis.globalEnvOption) {
13343
13257
  await this.init();
13344
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
13345
- const chainId = await chain.getChainId();
13258
+ const chain = await Chain.getChain(
13259
+ { chainIdentifier: options.chain },
13260
+ options
13261
+ );
13262
+ const chainId = await chain.getChainId(options);
13346
13263
  const { to, data } = txData;
13347
13264
  const { value = 0n } = txData;
13348
13265
  if (!chain || !chainId) {
13349
13266
  throw new InvalidParameterError6(
13350
- ErrorCode7.MissingParameter,
13267
+ ErrorCode6.MissingParameter,
13351
13268
  "chain object is missing or incorrect",
13352
13269
  "chain object is missing or incorrect",
13353
13270
  { options, chainId },
@@ -13355,11 +13272,11 @@ var Auth = class {
13355
13272
  "https://docs.fun.xyz"
13356
13273
  );
13357
13274
  }
13358
- const client = await chain.getClient();
13275
+ const client = await chain.getClient(options);
13359
13276
  const txClient = this.client ?? createWalletClient2({
13360
13277
  account: this.signer,
13361
13278
  transport: http2(client.transport.url),
13362
- chain: chains[preProcessesChains[await chain.getChainId()]]
13279
+ chain: chains[preProcessesChains[await chain.getChainId(options)]]
13363
13280
  });
13364
13281
  let tx;
13365
13282
  let maxFee;
@@ -13367,7 +13284,7 @@ var Auth = class {
13367
13284
  if (gasSpecificChain2[chainId]) {
13368
13285
  const { backupFee, backupPriorityFee, gasStationUrl } = gasSpecificChain2[chainId];
13369
13286
  try {
13370
- const { standard } = await getGasStation(gasStationUrl);
13287
+ const { standard } = await getGasStation(gasStationUrl, options);
13371
13288
  maxPriorityFee = standard.maxPriorityFee;
13372
13289
  maxFee = standard.maxFee;
13373
13290
  } catch (_err) {
@@ -13388,7 +13305,7 @@ var Auth = class {
13388
13305
  ...tx,
13389
13306
  account: this.signer ?? this.account,
13390
13307
  // TODO: Handle missing account?
13391
- chain: chains[preProcessesChains[await chain.getChainId()]]
13308
+ chain: chains[preProcessesChains[await chain.getChainId(options)]]
13392
13309
  });
13393
13310
  if (chainId !== "1" && chainId !== "5") {
13394
13311
  return await client.waitForTransactionReceipt({
@@ -13433,13 +13350,15 @@ var Auth = class {
13433
13350
  * @param {string} chainId - The chain identifier.
13434
13351
  * @returns {Promise<Hex[]>} An array of user IDs associated with the wallet address.
13435
13352
  */
13436
- async getUserIds(wallet, chainId) {
13353
+ async getUserIds(wallet, chainId, options) {
13437
13354
  await this.init();
13438
13355
  return await getUserWalletIdentities({
13439
13356
  authId: this.authId,
13440
13357
  chainId,
13441
13358
  walletAddr: wallet,
13442
- apiKey: globalThis.globalEnvOption.apiKey
13359
+ apiKey: globalThis.globalEnvOption.apiKey,
13360
+ logger: options?.logger,
13361
+ signal: options?.signal
13443
13362
  });
13444
13363
  }
13445
13364
  /**
@@ -13447,13 +13366,15 @@ var Auth = class {
13447
13366
  * @param {string} [chainId] - Optional chain identifier.
13448
13367
  * @returns {Promise<Wallet[]>} An array of wallet objects associated with the address.
13449
13368
  */
13450
- async getWallets(chainId) {
13369
+ async getWallets(chainId, options) {
13451
13370
  await this.init();
13452
13371
  try {
13453
13372
  return await getUserWalletsByAddr({
13454
13373
  addr: await this.getAddress(),
13455
13374
  chainId,
13456
- apiKey: globalThis.globalEnvOption.apiKey
13375
+ apiKey: globalThis.globalEnvOption.apiKey,
13376
+ logger: options?.logger,
13377
+ signal: options?.signal
13457
13378
  });
13458
13379
  } catch (err) {
13459
13380
  if (err instanceof ResourceNotFoundError4) {
@@ -13698,15 +13619,18 @@ var MerkleTree = class {
13698
13619
  };
13699
13620
 
13700
13621
  // src/actions/AccessControl.ts
13701
- var createFeeRecipientAndTokenMerkleTree = async (params) => {
13622
+ var createFeeRecipientAndTokenMerkleTree = async (params, txOptions) => {
13702
13623
  const recipients = (params.feeRecipientWhitelist ?? []).map(
13703
13624
  (recipient) => getAddress(recipient)
13704
13625
  );
13705
- const options = globalThis.globalEnvOption;
13706
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
13626
+ const chain = await Chain.getChain(
13627
+ // TODO: Temporary fallback, remove after refactoring -- Panda
13628
+ { chainIdentifier: globalThis.globalEnvOption.chain },
13629
+ txOptions
13630
+ );
13707
13631
  const tokens = await Promise.all(
13708
13632
  (params.feeTokenWhitelist ?? []).map(
13709
- (token) => Token.getAddress(token, chain)
13633
+ (token) => Token.getAddress(token, chain, txOptions)
13710
13634
  )
13711
13635
  );
13712
13636
  const feeRecipientAndTokenMerkleTree = new MerkleTree([
@@ -13728,7 +13652,7 @@ var createTargetSelectorMerkleTree = (params) => {
13728
13652
  var createSessionKeyTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
13729
13653
  if (params.targetWhitelist.length === 0) {
13730
13654
  throw new InvalidParameterError7(
13731
- ErrorCode8.MissingParameter,
13655
+ ErrorCode7.MissingParameter,
13732
13656
  "targetWhitelist is required",
13733
13657
  "targetWhitelist is required",
13734
13658
  { params },
@@ -13738,7 +13662,7 @@ var createSessionKeyTransactionParams = async (params, txOptions = globalThis.gl
13738
13662
  }
13739
13663
  if (params.userId === void 0) {
13740
13664
  throw new InvalidParameterError7(
13741
- ErrorCode8.MissingParameter,
13665
+ ErrorCode7.MissingParameter,
13742
13666
  "userId is required",
13743
13667
  "userId is required",
13744
13668
  { params },
@@ -13773,8 +13697,11 @@ var createSessionKeyTransactionParams = async (params, txOptions = globalThis.gl
13773
13697
  "addUserToRole",
13774
13698
  [roleId, userId]
13775
13699
  );
13776
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13777
- const rbacAddress = await chain.getAddress("rbacAddress");
13700
+ const chain = await Chain.getChain(
13701
+ { chainIdentifier: txOptions.chain },
13702
+ txOptions
13703
+ );
13704
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13778
13705
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13779
13706
  rbacAddress,
13780
13707
  "multiCall",
@@ -13793,8 +13720,11 @@ var createSessionUser = async (auth, params) => {
13793
13720
  );
13794
13721
  };
13795
13722
  var addOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13796
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13797
- const rbacAddress = await chain.getAddress("rbacAddress");
13723
+ const chain = await Chain.getChain(
13724
+ { chainIdentifier: txOptions.chain },
13725
+ txOptions
13726
+ );
13727
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13798
13728
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13799
13729
  rbacAddress,
13800
13730
  "addOwner",
@@ -13802,8 +13732,11 @@ var addOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) =>
13802
13732
  );
13803
13733
  };
13804
13734
  var removeOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13805
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13806
- const rbacAddress = await chain.getAddress("rbacAddress");
13735
+ const chain = await Chain.getChain(
13736
+ { chainIdentifier: txOptions.chain },
13737
+ txOptions
13738
+ );
13739
+ const rbacAddress = await chain.getAddress("rbacAddress", txOptions);
13807
13740
  return RBAC_CONTRACT_INTERFACE.encodeTransactionParams(
13808
13741
  rbacAddress,
13809
13742
  "removeOwner",
@@ -13836,8 +13769,11 @@ var createGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13836
13769
  group.userIds = group.userIds.map((userId) => {
13837
13770
  return pad7(userId, { size: 32 });
13838
13771
  });
13839
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13840
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13772
+ const chain = await Chain.getChain(
13773
+ { chainIdentifier: txOptions.chain },
13774
+ txOptions
13775
+ );
13776
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13841
13777
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13842
13778
  userAuthAddress,
13843
13779
  "createMultiSigGroup",
@@ -13849,8 +13785,11 @@ var updateGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13849
13785
  group.userIds = group.userIds.map((userId) => {
13850
13786
  return pad7(userId, { size: 32 });
13851
13787
  }).sort((a, b) => b.localeCompare(a));
13852
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13853
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13788
+ const chain = await Chain.getChain(
13789
+ { chainIdentifier: txOptions.chain },
13790
+ txOptions
13791
+ );
13792
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13854
13793
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13855
13794
  userAuthAddress,
13856
13795
  "updateMultiSigGroup",
@@ -13859,8 +13798,11 @@ var updateGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13859
13798
  };
13860
13799
  var removeGroupTxParams = async (params, txOptions = globalThis.globalEnvOption) => {
13861
13800
  const { groupId } = params;
13862
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13863
- const userAuthAddress = await chain.getAddress("userAuthAddress");
13801
+ const chain = await Chain.getChain(
13802
+ { chainIdentifier: txOptions.chain },
13803
+ txOptions
13804
+ );
13805
+ const userAuthAddress = await chain.getAddress("userAuthAddress", txOptions);
13864
13806
  return USER_AUTHENTICATION_CONTRACT_INTERFACE.encodeTransactionParams(
13865
13807
  userAuthAddress,
13866
13808
  "deleteMultiSigGroup",
@@ -13871,8 +13813,8 @@ var removeGroupTxParams = async (params, txOptions = globalThis.globalEnvOption)
13871
13813
  // src/actions/Stake.ts
13872
13814
  import { isAddress as isAddress4, parseEther as parseEther2 } from "viem";
13873
13815
  import {
13874
- ErrorCode as ErrorCode9,
13875
- InternalFailureError as InternalFailureError4,
13816
+ ErrorCode as ErrorCode8,
13817
+ InternalFailureError as InternalFailureError3,
13876
13818
  InvalidParameterError as InvalidParameterError8
13877
13819
  } from "@funkit/utils";
13878
13820
  var getWithdrawQueueInterface = () => {
@@ -13885,14 +13827,17 @@ var isFinishUnstakeParams = (input) => {
13885
13827
  return input.recipient !== void 0;
13886
13828
  };
13887
13829
  var stakeTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
13888
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13889
- const lidoAddress = getSteth(await chain.getChainId());
13830
+ const chain = await Chain.getChain(
13831
+ { chainIdentifier: txOptions.chain },
13832
+ txOptions
13833
+ );
13834
+ const lidoAddress = getSteth(await chain.getChainId(txOptions));
13890
13835
  return { to: lidoAddress, value: parseEther2(`${params.amount}`), data: "0x" };
13891
13836
  };
13892
13837
  var requestUnstakeTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
13893
13838
  if (!isAddress4(params.recipient ?? "")) {
13894
13839
  throw new InvalidParameterError8(
13895
- ErrorCode9.InvalidParameter,
13840
+ ErrorCode8.InvalidParameter,
13896
13841
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13897
13842
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13898
13843
  { params },
@@ -13900,13 +13845,16 @@ var requestUnstakeTransactionParams = async (params, txOptions = globalThis.glob
13900
13845
  "https://docs.fun.xyz"
13901
13846
  );
13902
13847
  }
13903
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13904
- const chainId = await chain.getChainId();
13848
+ const chain = await Chain.getChain(
13849
+ { chainIdentifier: txOptions.chain },
13850
+ txOptions
13851
+ );
13852
+ const chainId = await chain.getChainId(txOptions);
13905
13853
  const steth = getSteth(chainId);
13906
13854
  const withdrawalQueue = getWithdrawalQueue(chainId);
13907
13855
  if (!steth || !withdrawalQueue || steth.length === 0 || withdrawalQueue.length === 0) {
13908
13856
  throw new InvalidParameterError8(
13909
- ErrorCode9.ChainNotSupported,
13857
+ ErrorCode8.ChainNotSupported,
13910
13858
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
13911
13859
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
13912
13860
  { params },
@@ -13931,7 +13879,10 @@ var requestUnstakeTransactionParams = async (params, txOptions = globalThis.glob
13931
13879
  params.recipient
13932
13880
  ]
13933
13881
  );
13934
- const approveAndExecAddress = await chain.getAddress("approveAndExecAddress");
13882
+ const approveAndExecAddress = await chain.getAddress(
13883
+ "approveAndExecAddress",
13884
+ txOptions
13885
+ );
13935
13886
  return APPROVE_AND_EXEC_CONTRACT_INTERFACE.encodeTransactionParams(
13936
13887
  approveAndExecAddress,
13937
13888
  "approveAndExecute",
@@ -13941,7 +13892,7 @@ var requestUnstakeTransactionParams = async (params, txOptions = globalThis.glob
13941
13892
  var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globalEnvOption) => {
13942
13893
  if (!isAddress4(params.recipient ?? "")) {
13943
13894
  throw new InvalidParameterError8(
13944
- ErrorCode9.InvalidParameter,
13895
+ ErrorCode8.InvalidParameter,
13945
13896
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13946
13897
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13947
13898
  { params },
@@ -13949,12 +13900,17 @@ var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globa
13949
13900
  "https://docs.fun.xyz"
13950
13901
  );
13951
13902
  }
13952
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13953
- const withdrawQueueAddress = getWithdrawalQueue(await chain.getChainId());
13903
+ const chain = await Chain.getChain(
13904
+ { chainIdentifier: txOptions.chain },
13905
+ txOptions
13906
+ );
13907
+ const withdrawQueueAddress = getWithdrawalQueue(
13908
+ await chain.getChainId(txOptions)
13909
+ );
13954
13910
  const readyToWithdrawRequestIds = (await getReadyToWithdrawRequests(params, txOptions)).slice(0, 5);
13955
13911
  if (readyToWithdrawRequestIds.length === 0) {
13956
13912
  throw new InvalidParameterError8(
13957
- ErrorCode9.InvalidParameter,
13913
+ ErrorCode8.InvalidParameter,
13958
13914
  "Not ready to withdraw requests",
13959
13915
  "Not ready to withdraw requests",
13960
13916
  { params },
@@ -13966,17 +13922,19 @@ var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globa
13966
13922
  withdrawQueueAddress,
13967
13923
  "getLastCheckpointIndex",
13968
13924
  [],
13969
- chain
13925
+ chain,
13926
+ txOptions
13970
13927
  );
13971
13928
  const hints = await getWithdrawQueueInterface().readFromChain(
13972
13929
  withdrawQueueAddress,
13973
13930
  "findCheckpointHints",
13974
13931
  [readyToWithdrawRequestIds, 1, lastCheckpoint],
13975
- chain
13932
+ chain,
13933
+ txOptions
13976
13934
  );
13977
13935
  if (!hints) {
13978
- throw new InternalFailureError4(
13979
- ErrorCode9.CheckPointHintsNotFound,
13936
+ throw new InternalFailureError3(
13937
+ ErrorCode8.CheckPointHintsNotFound,
13980
13938
  "lido checkpoint hints are not found when batching the withdrawal",
13981
13939
  "",
13982
13940
  { params, readyToWithdrawRequestIds, lastCheckpoint, hints },
@@ -13993,7 +13951,7 @@ var finishUnstakeTransactionParams = async (params, txOptions = globalThis.globa
13993
13951
  var getReadyToWithdrawRequests = async (params, txOptions) => {
13994
13952
  if (!isAddress4(params.recipient ?? "")) {
13995
13953
  throw new InvalidParameterError8(
13996
- ErrorCode9.InvalidParameter,
13954
+ ErrorCode8.InvalidParameter,
13997
13955
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13998
13956
  "Recipient address is not a valid address, please make sure it is a valid checksum address.",
13999
13957
  { params },
@@ -14001,12 +13959,27 @@ var getReadyToWithdrawRequests = async (params, txOptions) => {
14001
13959
  "https://docs.fun.xyz"
14002
13960
  );
14003
13961
  }
14004
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
13962
+ const chain = await Chain.getChain(
13963
+ { chainIdentifier: txOptions.chain },
13964
+ txOptions
13965
+ );
14005
13966
  const withdrawalQueueAddr = getWithdrawalQueue(
14006
- await chain.getChainId()
13967
+ await chain.getChainId(txOptions)
13968
+ );
13969
+ const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(
13970
+ withdrawalQueueAddr,
13971
+ "getWithdrawalRequests",
13972
+ [params.walletAddress],
13973
+ chain,
13974
+ txOptions
13975
+ );
13976
+ const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(
13977
+ withdrawalQueueAddr,
13978
+ "getWithdrawalStatus",
13979
+ [withdrawalRequests],
13980
+ chain,
13981
+ txOptions
14007
13982
  );
14008
- const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalRequests", [params.walletAddress], chain);
14009
- const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalStatus", [withdrawalRequests], chain);
14010
13983
  const readyToWithdraw = [];
14011
13984
  for (let i = 0; i < withdrawalStatusTx.length; i++) {
14012
13985
  if (withdrawalStatusTx[i].isFinalized) {
@@ -14028,7 +14001,7 @@ var getWithdrawalQueue = (chainId) => {
14028
14001
  return "0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1";
14029
14002
  default:
14030
14003
  throw new InvalidParameterError8(
14031
- ErrorCode9.ChainNotSupported,
14004
+ ErrorCode8.ChainNotSupported,
14032
14005
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
14033
14006
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
14034
14007
  { chainId },
@@ -14047,7 +14020,7 @@ var getSteth = (chainId) => {
14047
14020
  return "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84";
14048
14021
  default:
14049
14022
  throw new InvalidParameterError8(
14050
- ErrorCode9.ChainNotSupported,
14023
+ ErrorCode8.ChainNotSupported,
14051
14024
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
14052
14025
  "Incorrect chainId, staking only available on Ethereum mainnet and Goerli",
14053
14026
  { chainId },
@@ -14059,18 +14032,18 @@ var getSteth = (chainId) => {
14059
14032
 
14060
14033
  // src/actions/Token.ts
14061
14034
  import { isAddress as isAddress5, parseEther as parseEther3 } from "viem";
14062
- import { ErrorCode as ErrorCode10, InvalidParameterError as InvalidParameterError9 } from "@funkit/utils";
14035
+ import { ErrorCode as ErrorCode9, InvalidParameterError as InvalidParameterError9 } from "@funkit/utils";
14063
14036
  var isERC721TransferParams = (obj) => {
14064
14037
  return "tokenId" in obj;
14065
14038
  };
14066
14039
  var isTokenTransferParams = (obj) => {
14067
14040
  return "amount" in obj && "token" in obj && "to" in obj;
14068
14041
  };
14069
- var erc721TransferTransactionParams = async (params) => {
14042
+ var erc721TransferTransactionParams = async (params, options) => {
14070
14043
  const { to, tokenId, collection, from } = params;
14071
14044
  if (!isAddress5(to ?? "") || !isAddress5(from ?? "")) {
14072
14045
  throw new InvalidParameterError9(
14073
- ErrorCode10.InvalidParameter,
14046
+ ErrorCode9.InvalidParameter,
14074
14047
  "To/from address is not a valid address, please make sure it is a valid checksum address.",
14075
14048
  "To/from address is not a valid address, please make sure it is a valid checksum address.",
14076
14049
  { params },
@@ -14078,18 +14051,18 @@ var erc721TransferTransactionParams = async (params) => {
14078
14051
  "https://docs.fun.xyz"
14079
14052
  );
14080
14053
  }
14081
- const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection);
14054
+ const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection, options);
14082
14055
  return ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
14083
14056
  tokenAddr,
14084
14057
  "transferFrom",
14085
14058
  [from, to, tokenId]
14086
14059
  );
14087
14060
  };
14088
- var tokenTransferTransactionParams = async (params, chain) => {
14061
+ var tokenTransferTransactionParams = async (params, chain, options) => {
14089
14062
  const { to, amount, token } = params;
14090
14063
  if (!isAddress5(to)) {
14091
14064
  throw new InvalidParameterError9(
14092
- ErrorCode10.InvalidParameter,
14065
+ ErrorCode9.InvalidParameter,
14093
14066
  "To address is not a valid address, please make sure it is a valid checksum address.",
14094
14067
  "To address is not a valid address, please make sure it is a valid checksum address.",
14095
14068
  { params },
@@ -14105,10 +14078,10 @@ var tokenTransferTransactionParams = async (params, chain) => {
14105
14078
  value: parseEther3(`${amount}`)
14106
14079
  };
14107
14080
  }
14108
- const tokenAddr = await tokenObj.getAddress();
14081
+ const tokenAddr = await tokenObj.getAddress(options);
14109
14082
  if (!tokenAddr) {
14110
14083
  throw new InvalidParameterError9(
14111
- ErrorCode10.TokenNotFound,
14084
+ ErrorCode9.TokenNotFound,
14112
14085
  "Token address not found. Please check the token passed in.",
14113
14086
  "Token address not found. Please check the token passed in.",
14114
14087
  { params },
@@ -14116,18 +14089,18 @@ var tokenTransferTransactionParams = async (params, chain) => {
14116
14089
  "https://docs.fun.xyz"
14117
14090
  );
14118
14091
  }
14119
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14092
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14120
14093
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14121
14094
  tokenAddr,
14122
14095
  "transfer",
14123
14096
  [to, convertedAmount]
14124
14097
  );
14125
14098
  };
14126
- var tokenTransferFromTransactionParams = async (params, chain) => {
14099
+ var tokenTransferFromTransactionParams = async (params, chain, options) => {
14127
14100
  const { to, amount, token, from } = params;
14128
14101
  if (!isAddress5(to ?? "") || !isAddress5(from ?? "")) {
14129
14102
  throw new InvalidParameterError9(
14130
- ErrorCode10.InvalidParameter,
14103
+ ErrorCode9.InvalidParameter,
14131
14104
  "To/from address is not a valid address, please make sure it is a valid checksum address.",
14132
14105
  "To/from address is not a valid address, please make sure it is a valid checksum address.",
14133
14106
  { params },
@@ -14143,10 +14116,10 @@ var tokenTransferFromTransactionParams = async (params, chain) => {
14143
14116
  value: parseEther3(`${amount}`)
14144
14117
  };
14145
14118
  }
14146
- const tokenAddr = await tokenObj.getAddress();
14119
+ const tokenAddr = await tokenObj.getAddress(options);
14147
14120
  if (!tokenAddr) {
14148
14121
  throw new InvalidParameterError9(
14149
- ErrorCode10.TokenNotFound,
14122
+ ErrorCode9.TokenNotFound,
14150
14123
  "Token address not found. Please check the token passed in.",
14151
14124
  "Token address not found. Please check the token passed in.",
14152
14125
  { params },
@@ -14154,7 +14127,7 @@ var tokenTransferFromTransactionParams = async (params, chain) => {
14154
14127
  "https://docs.fun.xyz"
14155
14128
  );
14156
14129
  }
14157
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14130
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14158
14131
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14159
14132
  tokenAddr,
14160
14133
  "transferFrom",
@@ -14167,11 +14140,11 @@ var isERC20ApproveParams = (obj) => {
14167
14140
  var isERC721ApproveParams = (obj) => {
14168
14141
  return "tokenId" in obj && "collection" in obj;
14169
14142
  };
14170
- var erc20ApproveTransactionParams = async (params) => {
14143
+ var erc20ApproveTransactionParams = async (params, options) => {
14171
14144
  const { spender, amount, token } = params;
14172
14145
  if (!isAddress5(spender ?? "")) {
14173
14146
  throw new InvalidParameterError9(
14174
- ErrorCode10.InvalidParameter,
14147
+ ErrorCode9.InvalidParameter,
14175
14148
  "Spender address is not a valid address, please make sure it is a valid checksum address.",
14176
14149
  "Spender address is not a valid address, please make sure it is a valid checksum address.",
14177
14150
  { params },
@@ -14179,22 +14152,23 @@ var erc20ApproveTransactionParams = async (params) => {
14179
14152
  "https://docs.fun.xyz"
14180
14153
  );
14181
14154
  }
14182
- const chain = await Chain.getChain({
14183
- chainIdentifier: globalThis.globalEnvOption.chain
14184
- });
14155
+ const chain = await Chain.getChain(
14156
+ { chainIdentifier: globalThis.globalEnvOption.chain },
14157
+ options
14158
+ );
14185
14159
  const tokenObj = new Token(token, chain);
14186
- const convertedAmount = await tokenObj.getDecimalAmount(amount);
14160
+ const convertedAmount = await tokenObj.getDecimalAmount(amount, options);
14187
14161
  return ERC20_CONTRACT_INTERFACE.encodeTransactionParams(
14188
- await tokenObj.getAddress(),
14162
+ await tokenObj.getAddress(options),
14189
14163
  "approve",
14190
14164
  [spender, convertedAmount]
14191
14165
  );
14192
14166
  };
14193
- var erc721ApproveTransactionParams = async (params) => {
14167
+ var erc721ApproveTransactionParams = async (params, options) => {
14194
14168
  const { spender, tokenId, collection } = params;
14195
14169
  if (!isAddress5(spender ?? "")) {
14196
14170
  throw new InvalidParameterError9(
14197
- ErrorCode10.InvalidParameter,
14171
+ ErrorCode9.InvalidParameter,
14198
14172
  "Spender address is not a valid address, please make sure it is a valid checksum address.",
14199
14173
  "Spender address is not a valid address, please make sure it is a valid checksum address.",
14200
14174
  { params },
@@ -14202,7 +14176,7 @@ var erc721ApproveTransactionParams = async (params) => {
14202
14176
  "https://docs.fun.xyz"
14203
14177
  );
14204
14178
  }
14205
- const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection);
14179
+ const tokenAddr = isAddress5(collection) ? collection : await NFT.getAddress(collection, options);
14206
14180
  return ERC721_CONTRACT_INTERFACE.encodeTransactionParams(
14207
14181
  tokenAddr,
14208
14182
  "approve",
@@ -14226,7 +14200,7 @@ var SocketSort = /* @__PURE__ */ ((SocketSort2) => {
14226
14200
  })(SocketSort || {});
14227
14201
 
14228
14202
  // src/config/Config.ts
14229
- import { ErrorCode as ErrorCode11, InvalidParameterError as InvalidParameterError10 } from "@funkit/utils";
14203
+ import { ErrorCode as ErrorCode10, InvalidParameterError as InvalidParameterError10 } from "@funkit/utils";
14230
14204
  function getEnvOptions() {
14231
14205
  return globalThis.globalEnvOption;
14232
14206
  }
@@ -14243,7 +14217,7 @@ async function configureEnvironment(option) {
14243
14217
  globalEnvOption.apiKey = option.apiKey ? option.apiKey : globalEnvOption.apiKey;
14244
14218
  if (!globalEnvOption.apiKey) {
14245
14219
  throw new InvalidParameterError10(
14246
- ErrorCode11.MissingParameter,
14220
+ ErrorCode10.MissingParameter,
14247
14221
  "apiKey is required",
14248
14222
  "apiKey is required",
14249
14223
  { option },
@@ -14302,22 +14276,29 @@ var Sponsor = class {
14302
14276
  this.paymasterType = paymasterType;
14303
14277
  }
14304
14278
  async getPaymasterAddress(options = globalThis.globalEnvOption) {
14305
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14306
- const chainId = await chain.getChainId();
14279
+ const chain = await Chain.getChain(
14280
+ { chainIdentifier: options.chain },
14281
+ options
14282
+ );
14283
+ const chainId = await chain.getChainId(options);
14307
14284
  if (!this.paymasterAddress && chainId !== this.chainId) {
14308
- this.paymasterAddress = await chain.getAddress(this.name);
14285
+ this.paymasterAddress = await chain.getAddress(this.name, options);
14309
14286
  this.chainId = chainId;
14310
14287
  }
14311
14288
  return this.paymasterAddress;
14312
14289
  }
14313
14290
  /** True if the specified sponsor is in blacklist mode. **/
14314
14291
  async getListMode(sponsor, options = globalThis.globalEnvOption) {
14315
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14292
+ const chain = await Chain.getChain(
14293
+ { chainIdentifier: options.chain },
14294
+ options
14295
+ );
14316
14296
  return await this.contractInterface.readFromChain(
14317
14297
  await this.getPaymasterAddress(options),
14318
14298
  "getListMode",
14319
14299
  [sponsor],
14320
- chain
14300
+ chain,
14301
+ options
14321
14302
  );
14322
14303
  }
14323
14304
  async setToBlacklistMode() {
@@ -14416,8 +14397,16 @@ var CheckoutSponsor = class extends Sponsor {
14416
14397
  return paymasterAddress.toLowerCase();
14417
14398
  }
14418
14399
  async stake(_sponsor, amount, options) {
14419
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14420
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14400
+ const chain = await Chain.getChain(
14401
+ { chainIdentifier: options.chain },
14402
+ options
14403
+ );
14404
+ const amountdec = await Token.getDecimalAmount(
14405
+ "eth",
14406
+ amount,
14407
+ chain,
14408
+ options
14409
+ );
14421
14410
  return this.contractInterface.encodeTransactionParams(
14422
14411
  await this.getPaymasterAddress(),
14423
14412
  "deposit",
@@ -14426,8 +14415,16 @@ var CheckoutSponsor = class extends Sponsor {
14426
14415
  );
14427
14416
  }
14428
14417
  async unstake(receiver, amount, options) {
14429
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14430
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14418
+ const chain = await Chain.getChain(
14419
+ { chainIdentifier: options.chain },
14420
+ options
14421
+ );
14422
+ const amountdec = await Token.getDecimalAmount(
14423
+ "eth",
14424
+ amount,
14425
+ chain,
14426
+ options
14427
+ );
14431
14428
  return this.contractInterface.encodeTransactionParams(
14432
14429
  await this.getPaymasterAddress(),
14433
14430
  "withdrawTo",
@@ -14488,7 +14485,7 @@ var CheckoutSponsor = class extends Sponsor {
14488
14485
  // src/sponsors/GaslessSponsor.ts
14489
14486
  import { concat as concat3 } from "viem";
14490
14487
  import { PaymasterType as PaymasterType3 } from "@funkit/api-base";
14491
- import { ErrorCode as ErrorCode12, ResourceNotFoundError as ResourceNotFoundError5 } from "@funkit/utils";
14488
+ import { ErrorCode as ErrorCode11, ResourceNotFoundError as ResourceNotFoundError5 } from "@funkit/utils";
14492
14489
  var GaslessSponsor = class extends Sponsor {
14493
14490
  constructor(options = globalThis.globalEnvOption) {
14494
14491
  super(
@@ -14500,17 +14497,23 @@ var GaslessSponsor = class extends Sponsor {
14500
14497
  }
14501
14498
  async getFunSponsorAddress(options = globalThis.globalEnvOption) {
14502
14499
  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");
14500
+ const chain = await Chain.getChain(
14501
+ { chainIdentifier: options.chain },
14502
+ options
14503
+ );
14504
+ if (GASLESS_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId(options))) {
14505
+ this.sponsorAddress = await chain.getAddress(
14506
+ "funGaslessSponsorAddress",
14507
+ options
14508
+ );
14506
14509
  } else {
14507
14510
  throw new ResourceNotFoundError5(
14508
- ErrorCode12.MissingParameter,
14511
+ ErrorCode11.MissingParameter,
14509
14512
  "The network you are working with does not support gasless Fun Sponsor. You will need to run and manage your own gasless sponsor.",
14510
14513
  "The network you are working with does not support gasless Fun Sponsor. You will need to run and manage your own gasless sponsor.",
14511
14514
  {
14512
14515
  gaslessSponsorSupportChains: GASLESS_SPONSOR_SUPPORT_CHAINS,
14513
- chain: await chain.getChainId()
14516
+ chain: await chain.getChainId(options)
14514
14517
  },
14515
14518
  "Manage your own gasless sponsor, or use a supported network.",
14516
14519
  "https://docs.fun.xyz"
@@ -14525,8 +14528,16 @@ var GaslessSponsor = class extends Sponsor {
14525
14528
  return concat3([paymasterAddress, sponsor]);
14526
14529
  }
14527
14530
  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);
14531
+ const chain = await Chain.getChain(
14532
+ { chainIdentifier: options.chain },
14533
+ options
14534
+ );
14535
+ const amountdec = await Token.getDecimalAmount(
14536
+ "eth",
14537
+ amount,
14538
+ chain,
14539
+ options
14540
+ );
14530
14541
  return this.contractInterface.encodeTransactionParams(
14531
14542
  await this.getPaymasterAddress(),
14532
14543
  "addDepositTo",
@@ -14535,8 +14546,16 @@ var GaslessSponsor = class extends Sponsor {
14535
14546
  );
14536
14547
  }
14537
14548
  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);
14549
+ const chain = await Chain.getChain(
14550
+ { chainIdentifier: options.chain },
14551
+ options
14552
+ );
14553
+ const amountdec = await Token.getDecimalAmount(
14554
+ "eth",
14555
+ amount,
14556
+ chain,
14557
+ options
14558
+ );
14540
14559
  return this.contractInterface.encodeTransactionParams(
14541
14560
  await this.getPaymasterAddress(),
14542
14561
  "withdrawDepositTo",
@@ -14544,28 +14563,39 @@ var GaslessSponsor = class extends Sponsor {
14544
14563
  );
14545
14564
  }
14546
14565
  async getUnlockBlock(sponsor, options = globalThis.globalEnvOption) {
14547
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14566
+ const chain = await Chain.getChain(
14567
+ { chainIdentifier: options.chain },
14568
+ options
14569
+ );
14548
14570
  return await this.contractInterface.readFromChain(
14549
14571
  await this.getPaymasterAddress(options),
14550
14572
  "getUnlockBlock",
14551
14573
  [sponsor],
14552
- chain
14574
+ chain,
14575
+ options
14553
14576
  );
14554
14577
  }
14555
14578
  async getLockState(sponsor, options = globalThis.globalEnvOption) {
14556
14579
  const unlockBlock = Number(await this.getUnlockBlock(sponsor, options));
14557
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14558
- const client = await chain.getClient();
14580
+ const chain = await Chain.getChain(
14581
+ { chainIdentifier: options.chain },
14582
+ options
14583
+ );
14584
+ const client = await chain.getClient(options);
14559
14585
  const currentBlock = await client.getBlockNumber();
14560
14586
  return unlockBlock === 0 || unlockBlock > currentBlock;
14561
14587
  }
14562
14588
  async getBalance(sponsor, options = globalThis.globalEnvOption) {
14563
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14589
+ const chain = await Chain.getChain(
14590
+ { chainIdentifier: options.chain },
14591
+ options
14592
+ );
14564
14593
  return await this.contractInterface.readFromChain(
14565
14594
  await this.getPaymasterAddress(options),
14566
14595
  "getBalance",
14567
14596
  [sponsor],
14568
- chain
14597
+ chain,
14598
+ options
14569
14599
  );
14570
14600
  }
14571
14601
  async lockDeposit() {
@@ -14583,21 +14613,29 @@ var GaslessSponsor = class extends Sponsor {
14583
14613
  );
14584
14614
  }
14585
14615
  async getSpenderBlacklistMode(spender, sponsor, options = globalThis.globalEnvOption) {
14586
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14616
+ const chain = await Chain.getChain(
14617
+ { chainIdentifier: options.chain },
14618
+ options
14619
+ );
14587
14620
  return await this.contractInterface.readFromChain(
14588
14621
  await this.getPaymasterAddress(options),
14589
14622
  "getSpenderBlacklistMode",
14590
14623
  [spender, sponsor],
14591
- chain
14624
+ chain,
14625
+ options
14592
14626
  );
14593
14627
  }
14594
14628
  async getSpenderWhitelistMode(spender, sponsor, options = globalThis.globalEnvOption) {
14595
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14629
+ const chain = await Chain.getChain(
14630
+ { chainIdentifier: options.chain },
14631
+ options
14632
+ );
14596
14633
  return await this.contractInterface.readFromChain(
14597
14634
  await this.getPaymasterAddress(options),
14598
14635
  "getSpenderWhitelistMode",
14599
14636
  [spender, sponsor],
14600
- chain
14637
+ chain,
14638
+ options
14601
14639
  );
14602
14640
  }
14603
14641
  };
@@ -14606,7 +14644,7 @@ var GaslessSponsor = class extends Sponsor {
14606
14644
  import { concat as concat4, encodeAbiParameters as encodeAbiParameters4 } from "viem";
14607
14645
  import { PaymasterType as PaymasterType4, addTransaction } from "@funkit/api-base";
14608
14646
  import {
14609
- ErrorCode as ErrorCode13,
14647
+ ErrorCode as ErrorCode12,
14610
14648
  InvalidParameterError as InvalidParameterError11,
14611
14649
  ResourceNotFoundError as ResourceNotFoundError6
14612
14650
  } from "@funkit/utils";
@@ -14620,7 +14658,7 @@ var TokenSponsor = class extends Sponsor {
14620
14658
  );
14621
14659
  if (!options.gasSponsor?.token) {
14622
14660
  throw new InvalidParameterError11(
14623
- ErrorCode13.MissingParameter,
14661
+ ErrorCode12.MissingParameter,
14624
14662
  "token field is missing",
14625
14663
  "token field is missing",
14626
14664
  { gasSponsor: options.gasSponsor },
@@ -14632,17 +14670,23 @@ var TokenSponsor = class extends Sponsor {
14632
14670
  }
14633
14671
  async getFunSponsorAddress(options = globalThis.globalEnvOption) {
14634
14672
  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");
14673
+ const chain = await Chain.getChain(
14674
+ { chainIdentifier: options.chain },
14675
+ options
14676
+ );
14677
+ if (TOKEN_SPONSOR_SUPPORT_CHAINS.includes(await chain.getChainId(options))) {
14678
+ this.sponsorAddress = await chain.getAddress(
14679
+ "funTokenSponsorAddress",
14680
+ options
14681
+ );
14638
14682
  } else {
14639
14683
  throw new ResourceNotFoundError6(
14640
- ErrorCode13.MissingParameter,
14684
+ ErrorCode12.MissingParameter,
14641
14685
  "The network you are working with does not support token Fun Sponsor. You will need to run and manage your own token sponsor.",
14642
14686
  "The network you are working with does not support token Fun Sponsor. You will need to run and manage your own token sponsor.",
14643
14687
  {
14644
14688
  tokenSponsorSupportChains: TOKEN_SPONSOR_SUPPORT_CHAINS,
14645
- chain: await chain.getChainId()
14689
+ chain: await chain.getChainId(options)
14646
14690
  },
14647
14691
  "Manage your own token sponsor, or use a supported network",
14648
14692
  "https://docs.fun.xyz"
@@ -14652,40 +14696,56 @@ var TokenSponsor = class extends Sponsor {
14652
14696
  return this.sponsorAddress;
14653
14697
  }
14654
14698
  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);
14699
+ const chain = await Chain.getChain(
14700
+ {
14701
+ chainIdentifier: globalThis.globalEnvOption.chain
14702
+ },
14703
+ options
14704
+ );
14705
+ const tokenAddress = await Token.getAddress(this.token, chain, options);
14659
14706
  const paymasterAddress = await this.getPaymasterAddress(options);
14660
14707
  const sponsor = await this.getFunSponsorAddress(options);
14661
14708
  return concat4([paymasterAddress, sponsor, tokenAddress]);
14662
14709
  }
14663
14710
  async getPaymasterAndDataPermit(partialOp, walletAddr, userId, auth, options = globalThis.globalEnvOption) {
14664
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14711
+ const chain = await Chain.getChain(
14712
+ { chainIdentifier: options.chain },
14713
+ options
14714
+ );
14665
14715
  const estimateGasSignature = await auth.getEstimateGasSignature(
14666
14716
  userId,
14667
14717
  partialOp
14668
14718
  );
14669
14719
  partialOp.userOp.signature = estimateGasSignature.toLowerCase();
14670
14720
  const estimationPaymasterAddress = await chain.getAddress(
14671
- "estimationPaymasterAddress"
14721
+ "estimationPaymasterAddress",
14722
+ options
14672
14723
  );
14673
- const { callGasLimit, verificationGasLimit, preVerificationGas } = await chain.estimateOpGas({
14674
- ...partialOp.userOp,
14675
- paymasterAndData: estimationPaymasterAddress
14676
- });
14677
- const { maxFeePerGas } = await chain.getFeeData();
14724
+ const { callGasLimit, verificationGasLimit, preVerificationGas } = await chain.estimateOpGas(
14725
+ {
14726
+ ...partialOp.userOp,
14727
+ paymasterAndData: estimationPaymasterAddress
14728
+ },
14729
+ options
14730
+ );
14731
+ const { maxFeePerGas } = await chain.getFeeData(options);
14678
14732
  const paymasterAddress = await this.getPaymasterAddress(options);
14679
14733
  const requiredGas = (callGasLimit + (verificationGasLimit + 400000n) * 3n + preVerificationGas) * BigInt(maxFeePerGas);
14680
- const tokenAddress = await Token.getAddress(this.token, chain);
14734
+ const tokenAddress = await Token.getAddress(this.token, chain, options);
14681
14735
  const decAmount = await TOKEN_PAYMASTER_CONTRACT_INTERFACE.readFromChain(
14682
14736
  paymasterAddress,
14683
14737
  "getTokenValueOfEth",
14684
14738
  [tokenAddress, requiredGas],
14685
- chain
14739
+ chain,
14740
+ options
14686
14741
  );
14687
- const nonce = await getWalletPermitNonce(walletAddr, chain);
14688
- const client = await chain.getClient();
14742
+ const nonce = await getWalletPermitNonce(
14743
+ walletAddr,
14744
+ chain,
14745
+ void 0,
14746
+ options
14747
+ );
14748
+ const client = await chain.getClient(options);
14689
14749
  const chainId = await client.getChainId();
14690
14750
  const hash = getPermitHash(
14691
14751
  tokenAddress,
@@ -14719,8 +14779,13 @@ var TokenSponsor = class extends Sponsor {
14719
14779
  }
14720
14780
  async stake(sponsor, amount, options = globalThis.globalEnvOption) {
14721
14781
  const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
14722
- const chain = await Chain.getChain({ chainIdentifier });
14723
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14782
+ const chain = await Chain.getChain({ chainIdentifier }, options);
14783
+ const amountdec = await Token.getDecimalAmount(
14784
+ "eth",
14785
+ amount,
14786
+ chain,
14787
+ options
14788
+ );
14724
14789
  return this.contractInterface.encodeTransactionParams(
14725
14790
  await this.getPaymasterAddress(),
14726
14791
  "addEthDepositTo",
@@ -14730,8 +14795,13 @@ var TokenSponsor = class extends Sponsor {
14730
14795
  }
14731
14796
  async unstake(receiver, amount, options = globalThis.globalEnvOption) {
14732
14797
  const chainIdentifier = options.chain ?? globalThis.globalEnvOption.chain;
14733
- const chain = await Chain.getChain({ chainIdentifier });
14734
- const amountdec = await Token.getDecimalAmount("eth", amount, chain);
14798
+ const chain = await Chain.getChain({ chainIdentifier }, options);
14799
+ const amountdec = await Token.getDecimalAmount(
14800
+ "eth",
14801
+ amount,
14802
+ chain,
14803
+ options
14804
+ );
14735
14805
  return this.contractInterface.encodeTransactionParams(
14736
14806
  await this.getPaymasterAddress(),
14737
14807
  "withdrawEthDepositTo",
@@ -14739,39 +14809,53 @@ var TokenSponsor = class extends Sponsor {
14739
14809
  );
14740
14810
  }
14741
14811
  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);
14812
+ const chain = await Chain.getChain(
14813
+ {
14814
+ chainIdentifier: globalThis.globalEnvOption.chain
14815
+ },
14816
+ options
14817
+ );
14818
+ const tokenAddr = Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain, options);
14746
14819
  return (await this.getAllTokenData(tokenAddr, sponsor, options)).unlockBlock;
14747
14820
  }
14748
14821
  // false means unlocked, true means locked
14749
14822
  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);
14823
+ const chain = await Chain.getChain(
14824
+ { chainIdentifier: options.chain },
14825
+ options
14826
+ );
14827
+ const tokenAddr = Token.isNative(token) ? AddressZero : await Token.getAddress(token, chain, options);
14752
14828
  const unlockBlock = await this.getUnlockBlock(tokenAddr, sponsor);
14753
- const provider = await chain.getClient();
14829
+ const provider = await chain.getClient(options);
14754
14830
  const currentBlock = await provider.getBlockNumber();
14755
14831
  return unlockBlock === 0n || unlockBlock > currentBlock;
14756
14832
  }
14757
14833
  async getTokenInfo(token, options = globalThis.globalEnvOption) {
14758
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14759
- const tokenAddress = await Token.getAddress(token, chain);
14834
+ const chain = await Chain.getChain(
14835
+ { chainIdentifier: options.chain },
14836
+ options
14837
+ );
14838
+ const tokenAddress = await Token.getAddress(token, chain, options);
14760
14839
  return await this.contractInterface.readFromChain(
14761
14840
  await this.getPaymasterAddress(options),
14762
14841
  "getToken",
14763
14842
  [tokenAddress],
14764
- chain
14843
+ chain,
14844
+ options
14765
14845
  );
14766
14846
  }
14767
14847
  async getAllTokenData(spender, token, options = globalThis.globalEnvOption) {
14768
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14769
- const tokenAddress = await Token.getAddress(token, chain);
14848
+ const chain = await Chain.getChain(
14849
+ { chainIdentifier: options.chain },
14850
+ options
14851
+ );
14852
+ const tokenAddress = await Token.getAddress(token, chain, options);
14770
14853
  const data = await this.contractInterface.readFromChain(
14771
14854
  await this.getPaymasterAddress(options),
14772
14855
  "getAllTokenData",
14773
14856
  [tokenAddress, spender],
14774
- chain
14857
+ chain,
14858
+ options
14775
14859
  );
14776
14860
  return {
14777
14861
  unlockBlock: data[0],
@@ -14779,29 +14863,40 @@ var TokenSponsor = class extends Sponsor {
14779
14863
  };
14780
14864
  }
14781
14865
  async getTokenBalance(spender, token, options = globalThis.globalEnvOption) {
14782
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14866
+ const chain = await Chain.getChain(
14867
+ { chainIdentifier: options.chain },
14868
+ options
14869
+ );
14783
14870
  const tokenData = new Token(token, chain);
14784
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
14871
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14785
14872
  return await this.contractInterface.readFromChain(
14786
14873
  await this.getPaymasterAddress(options),
14787
14874
  "getTokenBalance",
14788
14875
  [tokenAddress, spender],
14789
- chain
14876
+ chain,
14877
+ options
14790
14878
  );
14791
14879
  }
14792
14880
  async getAllTokens(options = globalThis.globalEnvOption) {
14793
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14881
+ const chain = await Chain.getChain(
14882
+ { chainIdentifier: options.chain },
14883
+ options
14884
+ );
14794
14885
  return await this.contractInterface.readFromChain(
14795
14886
  await this.getPaymasterAddress(options),
14796
14887
  "getAllTokens",
14797
14888
  [],
14798
- chain
14889
+ chain,
14890
+ options
14799
14891
  );
14800
14892
  }
14801
14893
  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);
14894
+ const chain = await Chain.getChain(
14895
+ { chainIdentifier: options.chain },
14896
+ options
14897
+ );
14898
+ const decimals = await Token.getDecimals(token, chain, options);
14899
+ const tokenAddress = await Token.getAddress(token, chain, options);
14805
14900
  const data = [oracle, tokenAddress, decimals, aggregator];
14806
14901
  return this.contractInterface.encodeTransactionParams(
14807
14902
  await this.getPaymasterAddress(),
@@ -14810,10 +14905,13 @@ var TokenSponsor = class extends Sponsor {
14810
14905
  );
14811
14906
  }
14812
14907
  async depositToken(token, spender, amount, options = globalThis.globalEnvOption) {
14813
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14908
+ const chain = await Chain.getChain(
14909
+ { chainIdentifier: options.chain },
14910
+ options
14911
+ );
14814
14912
  const tokenObj = new Token(token, chain);
14815
- const tokenAddress = await tokenObj.getAddress();
14816
- const amountDec = await tokenObj.getDecimalAmount(amount);
14913
+ const tokenAddress = await tokenObj.getAddress(options);
14914
+ const amountDec = await tokenObj.getDecimalAmount(amount, options);
14817
14915
  return this.contractInterface.encodeTransactionParams(
14818
14916
  await this.getPaymasterAddress(),
14819
14917
  "addTokenDepositTo",
@@ -14821,10 +14919,13 @@ var TokenSponsor = class extends Sponsor {
14821
14919
  );
14822
14920
  }
14823
14921
  async withdrawToken(token, receiver, amount, options = globalThis.globalEnvOption) {
14824
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14922
+ const chain = await Chain.getChain(
14923
+ { chainIdentifier: options.chain },
14924
+ options
14925
+ );
14825
14926
  const tokenObj = new Token(token, chain);
14826
- const tokenAddress = await tokenObj.getAddress();
14827
- const amountdec = await tokenObj.getDecimalAmount(amount);
14927
+ const tokenAddress = await tokenObj.getAddress(options);
14928
+ const amountdec = await tokenObj.getDecimalAmount(amount, options);
14828
14929
  return this.contractInterface.encodeTransactionParams(
14829
14930
  await this.getPaymasterAddress(),
14830
14931
  "withdrawTokenDepositTo",
@@ -14832,9 +14933,12 @@ var TokenSponsor = class extends Sponsor {
14832
14933
  );
14833
14934
  }
14834
14935
  async lockTokenDeposit(token, options = globalThis.globalEnvOption) {
14835
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14936
+ const chain = await Chain.getChain(
14937
+ { chainIdentifier: options.chain },
14938
+ options
14939
+ );
14836
14940
  const tokenData = new Token(token, chain);
14837
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
14941
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14838
14942
  return this.contractInterface.encodeTransactionParams(
14839
14943
  await this.getPaymasterAddress(),
14840
14944
  "lockTokenDeposit",
@@ -14842,9 +14946,12 @@ var TokenSponsor = class extends Sponsor {
14842
14946
  );
14843
14947
  }
14844
14948
  async unlockTokenDepositAfter(token, blocksToWait, options = globalThis.globalEnvOption) {
14845
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14949
+ const chain = await Chain.getChain(
14950
+ { chainIdentifier: options.chain },
14951
+ options
14952
+ );
14846
14953
  const tokenData = new Token(token, chain);
14847
- const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress();
14954
+ const tokenAddress = tokenData.isNative ? AddressZero : await tokenData.getAddress(options);
14848
14955
  return this.contractInterface.encodeTransactionParams(
14849
14956
  await this.getPaymasterAddress(),
14850
14957
  "unlockTokenDepositAfter",
@@ -14867,9 +14974,12 @@ var TokenSponsor = class extends Sponsor {
14867
14974
  }
14868
14975
  async approve(approver, token, amount, options = globalThis.globalEnvOption) {
14869
14976
  const gasSponsorAddress = await this.getPaymasterAddress();
14870
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14977
+ const chain = await Chain.getChain(
14978
+ { chainIdentifier: options.chain },
14979
+ options
14980
+ );
14871
14981
  addTransaction({
14872
- chainId: await chain.getChainId(),
14982
+ chainId: await chain.getChainId(options),
14873
14983
  timestamp: Date.now(),
14874
14984
  txid: "0x",
14875
14985
  transaction: {
@@ -14881,36 +14991,50 @@ var TokenSponsor = class extends Sponsor {
14881
14991
  },
14882
14992
  paymasterType: this.paymasterType,
14883
14993
  sponsorAddress: approver,
14884
- apiKey: globalThis.globalEnvOption.apiKey
14994
+ apiKey: globalThis.globalEnvOption.apiKey,
14995
+ logger: options.logger,
14996
+ signal: options.signal
14885
14997
  });
14886
- return Token.approve(token, gasSponsorAddress, amount, chain);
14998
+ return Token.approve(token, gasSponsorAddress, amount, chain, options);
14887
14999
  }
14888
15000
  async getSpenderBlacklisted(spender, sponsor, options = globalThis.globalEnvOption) {
14889
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15001
+ const chain = await Chain.getChain(
15002
+ { chainIdentifier: options.chain },
15003
+ options
15004
+ );
14890
15005
  return await this.contractInterface.readFromChain(
14891
15006
  await this.getPaymasterAddress(options),
14892
15007
  "getSpenderBlacklisted",
14893
15008
  [spender, sponsor],
14894
- chain
15009
+ chain,
15010
+ options
14895
15011
  );
14896
15012
  }
14897
15013
  async getSpenderWhitelisted(spender, sponsor, options = globalThis.globalEnvOption) {
14898
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15014
+ const chain = await Chain.getChain(
15015
+ { chainIdentifier: options.chain },
15016
+ options
15017
+ );
14899
15018
  return await this.contractInterface.readFromChain(
14900
15019
  await this.getPaymasterAddress(options),
14901
15020
  "getSpenderWhitelisted",
14902
15021
  [spender, sponsor],
14903
- chain
15022
+ chain,
15023
+ options
14904
15024
  );
14905
15025
  }
14906
15026
  async getTokenWhitelisted(sponsor, token, options = globalThis.globalEnvOption) {
14907
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14908
- const tokenAddress = await Token.getAddress(token, chain);
15027
+ const chain = await Chain.getChain(
15028
+ { chainIdentifier: options.chain },
15029
+ options
15030
+ );
15031
+ const tokenAddress = await Token.getAddress(token, chain, options);
14909
15032
  return await this.contractInterface.readFromChain(
14910
15033
  await this.getPaymasterAddress(options),
14911
15034
  "getTokenWhitelisted",
14912
15035
  [tokenAddress, sponsor],
14913
- chain
15036
+ chain,
15037
+ options
14914
15038
  );
14915
15039
  }
14916
15040
  async setTokenToWhitelistMode() {
@@ -14921,10 +15045,13 @@ var TokenSponsor = class extends Sponsor {
14921
15045
  );
14922
15046
  }
14923
15047
  async batchWhitelistTokens(tokens, modes, options = globalThis.globalEnvOption) {
14924
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15048
+ const chain = await Chain.getChain(
15049
+ { chainIdentifier: options.chain },
15050
+ options
15051
+ );
14925
15052
  const calldata = [];
14926
15053
  for (let i = 0; i < tokens.length; i++) {
14927
- const tokenAddress = await Token.getAddress(tokens[i], chain);
15054
+ const tokenAddress = await Token.getAddress(tokens[i], chain, options);
14928
15055
  calldata.push(
14929
15056
  this.contractInterface.encodeData("setTokenWhitelistMode", [
14930
15057
  tokenAddress,
@@ -14939,22 +15066,30 @@ var TokenSponsor = class extends Sponsor {
14939
15066
  );
14940
15067
  }
14941
15068
  async getTokenListMode(sponsor, options = globalThis.globalEnvOption) {
14942
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15069
+ const chain = await Chain.getChain(
15070
+ { chainIdentifier: options.chain },
15071
+ options
15072
+ );
14943
15073
  return await this.contractInterface.readFromChain(
14944
15074
  await this.getPaymasterAddress(options),
14945
15075
  "getTokenListMode",
14946
15076
  [sponsor],
14947
- chain
15077
+ chain,
15078
+ options
14948
15079
  );
14949
15080
  }
14950
15081
  async getTokenBlacklisted(sponsor, token, options = globalThis.globalEnvOption) {
14951
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14952
- const tokenAddress = await Token.getAddress(token, chain);
15082
+ const chain = await Chain.getChain(
15083
+ { chainIdentifier: options.chain },
15084
+ options
15085
+ );
15086
+ const tokenAddress = await Token.getAddress(token, chain, options);
14953
15087
  return await this.contractInterface.readFromChain(
14954
15088
  await this.getPaymasterAddress(options),
14955
15089
  "getTokenBlacklisted",
14956
15090
  [tokenAddress, sponsor],
14957
- chain
15091
+ chain,
15092
+ options
14958
15093
  );
14959
15094
  }
14960
15095
  async setTokenToBlacklistMode() {
@@ -14965,10 +15100,13 @@ var TokenSponsor = class extends Sponsor {
14965
15100
  );
14966
15101
  }
14967
15102
  async batchBlacklistTokens(tokens, modes, options = globalThis.globalEnvOption) {
14968
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15103
+ const chain = await Chain.getChain(
15104
+ { chainIdentifier: options.chain },
15105
+ options
15106
+ );
14969
15107
  const calldata = [];
14970
15108
  for (let i = 0; i < tokens.length; i++) {
14971
- const tokenAddress = await Token.getAddress(tokens[i], chain);
15109
+ const tokenAddress = await Token.getAddress(tokens[i], chain, options);
14972
15110
  calldata.push(
14973
15111
  this.contractInterface.encodeTransactionParams(
14974
15112
  await this.getPaymasterAddress(),
@@ -15017,15 +15155,15 @@ import {
15017
15155
  toBytes as toBytes7
15018
15156
  } from "viem";
15019
15157
  import {
15020
- ErrorCode as ErrorCode15,
15021
- InternalFailureError as InternalFailureError5,
15158
+ ErrorCode as ErrorCode14,
15159
+ InternalFailureError as InternalFailureError4,
15022
15160
  InvalidParameterError as InvalidParameterError13
15023
15161
  } from "@funkit/utils";
15024
15162
 
15025
15163
  // src/actions/FirstClassActions.ts
15026
15164
  import { pad as pad8 } from "viem";
15027
15165
  import {
15028
- ErrorCode as ErrorCode14,
15166
+ ErrorCode as ErrorCode13,
15029
15167
  InvalidParameterError as InvalidParameterError12,
15030
15168
  ResourceNotFoundError as ResourceNotFoundError7
15031
15169
  } from "@funkit/utils";
@@ -15036,8 +15174,11 @@ import {
15036
15174
  decodeAbiParameters as decodeAbiParameters3,
15037
15175
  keccak256 as keccak2566
15038
15176
  } from "viem";
15039
- async function getOnChainGroupData(groupId, chain, walletAddr) {
15040
- const userAuthContractAddr = await chain.getAddress("userAuthAddress");
15177
+ async function getOnChainGroupData(groupId, chain, walletAddr, options) {
15178
+ const userAuthContractAddr = await chain.getAddress(
15179
+ "userAuthAddress",
15180
+ options
15181
+ );
15041
15182
  const groupKey = keccak2566(concat5([groupId, userAuthContractAddr]));
15042
15183
  let storedGroupData;
15043
15184
  try {
@@ -15045,7 +15186,8 @@ async function getOnChainGroupData(groupId, chain, walletAddr) {
15045
15186
  walletAddr,
15046
15187
  "getState",
15047
15188
  [groupKey],
15048
- chain
15189
+ chain,
15190
+ options
15049
15191
  );
15050
15192
  } catch (err) {
15051
15193
  if (err instanceof Error && err.message.match(/returned no data/)) {
@@ -15090,28 +15232,34 @@ var FirstClassActions = class {
15090
15232
  * @throws {InvalidParameterError} When provided parameters are missing or incorrect.
15091
15233
  */
15092
15234
  async transfer(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15093
- const overrideChain = await Chain.getChain({
15094
- chainIdentifier: txOptions?.chain
15095
- });
15235
+ const overrideChain = await Chain.getChain(
15236
+ { chainIdentifier: txOptions?.chain },
15237
+ txOptions
15238
+ );
15096
15239
  let transactionParams;
15097
15240
  if (isERC721TransferParams(params)) {
15098
- params.from = params.from ? params.from : await this.getAddress();
15099
- transactionParams = await erc721TransferTransactionParams(params);
15241
+ params.from = params.from ? params.from : await this.getAddress(txOptions);
15242
+ transactionParams = await erc721TransferTransactionParams(
15243
+ params,
15244
+ txOptions
15245
+ );
15100
15246
  } else if (isTokenTransferParams(params)) {
15101
15247
  if (params.from) {
15102
15248
  transactionParams = await tokenTransferFromTransactionParams(
15103
15249
  params,
15104
- overrideChain ?? this.chain
15250
+ overrideChain ?? this.chain,
15251
+ txOptions
15105
15252
  );
15106
15253
  } else {
15107
15254
  transactionParams = await tokenTransferTransactionParams(
15108
15255
  params,
15109
- overrideChain ?? this.chain
15256
+ overrideChain ?? this.chain,
15257
+ txOptions
15110
15258
  );
15111
15259
  }
15112
15260
  } else {
15113
15261
  throw new InvalidParameterError12(
15114
- ErrorCode14.InvalidParameter,
15262
+ ErrorCode13.InvalidParameter,
15115
15263
  "Params were missing or incorrect",
15116
15264
  "Params were missing or incorrect",
15117
15265
  { params },
@@ -15138,12 +15286,15 @@ var FirstClassActions = class {
15138
15286
  async tokenApprove(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15139
15287
  let transactionParams;
15140
15288
  if (isERC20ApproveParams(params)) {
15141
- transactionParams = await erc20ApproveTransactionParams(params);
15289
+ transactionParams = await erc20ApproveTransactionParams(params, txOptions);
15142
15290
  } else if (isERC721ApproveParams(params)) {
15143
- transactionParams = await erc721ApproveTransactionParams(params);
15291
+ transactionParams = await erc721ApproveTransactionParams(
15292
+ params,
15293
+ txOptions
15294
+ );
15144
15295
  } else {
15145
15296
  throw new InvalidParameterError12(
15146
- ErrorCode14.InvalidParameter,
15297
+ ErrorCode13.InvalidParameter,
15147
15298
  "Params were missing or incorrect",
15148
15299
  "Params were missing or incorrect",
15149
15300
  { params },
@@ -15185,7 +15336,7 @@ var FirstClassActions = class {
15185
15336
  * @throws {InvalidParameterError} When provided parameters are missing or incorrect.
15186
15337
  */
15187
15338
  async unstake(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15188
- params.recipient ??= await this.getAddress();
15339
+ params.recipient ??= await this.getAddress(txOptions);
15189
15340
  let transactionParams;
15190
15341
  if (isRequestUnstakeParams(params)) {
15191
15342
  transactionParams = await requestUnstakeTransactionParams(
@@ -15199,7 +15350,7 @@ var FirstClassActions = class {
15199
15350
  );
15200
15351
  } else {
15201
15352
  throw new InvalidParameterError12(
15202
- ErrorCode14.InvalidParameter,
15353
+ ErrorCode13.InvalidParameter,
15203
15354
  "Params were missing or incorrect",
15204
15355
  "Params were missing or incorrect",
15205
15356
  { params },
@@ -15281,15 +15432,19 @@ var FirstClassActions = class {
15281
15432
  async addUserToGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15282
15433
  params.userId = pad8(params.userId, { size: 32 });
15283
15434
  params.groupId = pad8(params.groupId, { size: 32 });
15284
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15435
+ const chain = await Chain.getChain(
15436
+ { chainIdentifier: txOptions.chain },
15437
+ txOptions
15438
+ );
15285
15439
  const onChainGroupData = await getOnChainGroupData(
15286
15440
  params.groupId,
15287
15441
  chain,
15288
- await this.getAddress()
15442
+ await this.getAddress(txOptions),
15443
+ txOptions
15289
15444
  );
15290
15445
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15291
15446
  throw new ResourceNotFoundError7(
15292
- ErrorCode14.GroupNotFound,
15447
+ ErrorCode13.GroupNotFound,
15293
15448
  "group is not found",
15294
15449
  "group is not found",
15295
15450
  { params },
@@ -15302,7 +15457,7 @@ var FirstClassActions = class {
15302
15457
  members.add(params.userId);
15303
15458
  if (members.size <= originalMembers.size) {
15304
15459
  throw new InvalidParameterError12(
15305
- ErrorCode14.UserAlreadyExists,
15460
+ ErrorCode13.UserAlreadyExists,
15306
15461
  "user already exists in group",
15307
15462
  "user already exists in group",
15308
15463
  { params, originalMembers, userId: params.userId },
@@ -15331,15 +15486,19 @@ var FirstClassActions = class {
15331
15486
  async removeUserFromGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15332
15487
  params.userId = pad8(params.userId, { size: 32 });
15333
15488
  params.groupId = pad8(params.groupId, { size: 32 });
15334
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15489
+ const chain = await Chain.getChain(
15490
+ { chainIdentifier: txOptions.chain },
15491
+ txOptions
15492
+ );
15335
15493
  const onChainGroupData = await getOnChainGroupData(
15336
15494
  params.groupId,
15337
15495
  chain,
15338
- await this.getAddress()
15496
+ await this.getAddress(txOptions),
15497
+ txOptions
15339
15498
  );
15340
15499
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15341
15500
  throw new ResourceNotFoundError7(
15342
- ErrorCode14.GroupNotFound,
15501
+ ErrorCode13.GroupNotFound,
15343
15502
  "group is not found",
15344
15503
  "group is not found",
15345
15504
  { params },
@@ -15352,7 +15511,7 @@ var FirstClassActions = class {
15352
15511
  members.delete(params.userId);
15353
15512
  if (members.size >= originalMembers.size) {
15354
15513
  throw new ResourceNotFoundError7(
15355
- ErrorCode14.UserNotFound,
15514
+ ErrorCode13.UserNotFound,
15356
15515
  "user does not exist in group",
15357
15516
  "user does not exist in group",
15358
15517
  { params, originalMembers, userId: params.userId },
@@ -15380,15 +15539,19 @@ var FirstClassActions = class {
15380
15539
  */
15381
15540
  async updateThresholdOfGroup(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15382
15541
  params.groupId = pad8(params.groupId, { size: 32 });
15383
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15542
+ const chain = await Chain.getChain(
15543
+ { chainIdentifier: txOptions.chain },
15544
+ txOptions
15545
+ );
15384
15546
  const onChainGroupData = await getOnChainGroupData(
15385
15547
  params.groupId,
15386
15548
  chain,
15387
- await this.getAddress()
15549
+ await this.getAddress(txOptions),
15550
+ txOptions
15388
15551
  );
15389
15552
  if (!onChainGroupData || onChainGroupData.memberIds.length === 0) {
15390
15553
  throw new ResourceNotFoundError7(
15391
- ErrorCode14.GroupNotFound,
15554
+ ErrorCode13.GroupNotFound,
15392
15555
  "group is not found",
15393
15556
  "group is not found",
15394
15557
  { params },
@@ -15398,7 +15561,7 @@ var FirstClassActions = class {
15398
15561
  }
15399
15562
  if (!Number.isInteger(params.threshold) || params.threshold < 1 || params.threshold > onChainGroupData.memberIds.length) {
15400
15563
  throw new InvalidParameterError12(
15401
- ErrorCode14.InvalidThreshold,
15564
+ ErrorCode13.InvalidThreshold,
15402
15565
  "threshold can not be 0 or bigger than number of members in the group",
15403
15566
  "threshold can not be 0 or bigger than number of members in the group",
15404
15567
  { params, memberIds: onChainGroupData.memberIds },
@@ -15438,7 +15601,7 @@ var FirstClassActions = class {
15438
15601
  * @returns {Promise<Operation>} The prepared batch operation.
15439
15602
  */
15440
15603
  async createBatchOperation(auth, userId, params, txOptions = globalThis.globalEnvOption) {
15441
- const walletAddress = await this.getAddress();
15604
+ const walletAddress = await this.getAddress(txOptions);
15442
15605
  const txParams = createExecuteBatchTxParams(params, walletAddress);
15443
15606
  return await this.createOperation(auth, userId, txParams, txOptions);
15444
15607
  }
@@ -15459,7 +15622,7 @@ var FunWallet = class extends FirstClassActions {
15459
15622
  this.address = params;
15460
15623
  } else {
15461
15624
  throw new InvalidParameterError13(
15462
- ErrorCode15.InvalidParameter,
15625
+ ErrorCode14.InvalidParameter,
15463
15626
  "string input must be an address type",
15464
15627
  "string input must be an address type",
15465
15628
  params,
@@ -15471,7 +15634,7 @@ var FunWallet = class extends FirstClassActions {
15471
15634
  const { users, uniqueId } = params;
15472
15635
  if (!uniqueId || !isBytes32(uniqueId) || !users || users.length <= 0) {
15473
15636
  throw new InvalidParameterError13(
15474
- ErrorCode15.InvalidParameter,
15637
+ ErrorCode14.InvalidParameter,
15475
15638
  "uniqueId must be bytes32 and users must be non-empty",
15476
15639
  "uniqueId must be bytes32 and users must be non-empty",
15477
15640
  params,
@@ -15483,7 +15646,7 @@ var FunWallet = class extends FirstClassActions {
15483
15646
  users?.map((user) => {
15484
15647
  if (!user.userId || !isHex3(user.userId)) {
15485
15648
  throw new InvalidParameterError13(
15486
- ErrorCode15.InvalidParameter,
15649
+ ErrorCode14.InvalidParameter,
15487
15650
  "userId is required and must be a hex string",
15488
15651
  "userId is required and must be a hex string",
15489
15652
  users,
@@ -15493,7 +15656,7 @@ var FunWallet = class extends FirstClassActions {
15493
15656
  }
15494
15657
  if (user.groupInfo && (!Number.isInteger(user.groupInfo.threshold) || !Array.isArray(user.groupInfo.memberIds) || !user.groupInfo.memberIds.every((memberId) => isHex3(memberId)))) {
15495
15658
  throw new InvalidParameterError13(
15496
- ErrorCode15.InvalidParameter,
15659
+ ErrorCode14.InvalidParameter,
15497
15660
  "groupInfo must be an object with threshold as integer and memberIds as array of hex strings",
15498
15661
  "groupInfo must be an object with threshold as integer and memberIds as array of hex strings",
15499
15662
  users,
@@ -15516,8 +15679,12 @@ var FunWallet = class extends FirstClassActions {
15516
15679
  if (!this.address) {
15517
15680
  const chainIdentifier = txOptions.chain;
15518
15681
  this.address = await getWalletAddress(
15519
- await Chain.getChain({ chainIdentifier: chainIdentifier ?? 137 }),
15520
- this.walletUniqueId
15682
+ await Chain.getChain(
15683
+ { chainIdentifier: chainIdentifier ?? 137 },
15684
+ txOptions
15685
+ ),
15686
+ this.walletUniqueId,
15687
+ txOptions
15521
15688
  );
15522
15689
  }
15523
15690
  return this.address;
@@ -15528,11 +15695,12 @@ var FunWallet = class extends FirstClassActions {
15528
15695
  * @param {string} apiKey - The API key to access the required resources.
15529
15696
  * @returns {Promise<Address>} The wallet address.
15530
15697
  */
15531
- static async getAddress(uniqueId, apiKey) {
15698
+ static async getAddress(uniqueId, apiKey, options) {
15532
15699
  globalThis.globalEnvOption.apiKey = apiKey;
15533
15700
  return await getWalletAddress(
15534
- await Chain.getChain({ chainIdentifier: 137 }),
15535
- keccak2567(toBytes7(uniqueId))
15701
+ await Chain.getChain({ chainIdentifier: 137 }, options),
15702
+ keccak2567(toBytes7(uniqueId)),
15703
+ options
15536
15704
  );
15537
15705
  }
15538
15706
  /**
@@ -15542,15 +15710,16 @@ var FunWallet = class extends FirstClassActions {
15542
15710
  * @param {Address} factoryAddress - The address of the factory contract.
15543
15711
  * @returns {Promise<Address>} The wallet address.
15544
15712
  */
15545
- static async getAddressOffline(uniqueId, rpcUrl, factoryAddress) {
15546
- const client = await createPublicClient2({
15713
+ static async getAddressOffline(uniqueId, rpcUrl, factoryAddress, options) {
15714
+ const client = createPublicClient2({
15547
15715
  transport: http3(rpcUrl)
15548
15716
  });
15549
15717
  return await FACTORY_CONTRACT_INTERFACE.readFromChain(
15550
15718
  factoryAddress,
15551
15719
  "getAddress",
15552
15720
  [keccak2567(toBytes7(uniqueId))],
15553
- client
15721
+ client,
15722
+ options
15554
15723
  );
15555
15724
  }
15556
15725
  /**
@@ -15559,26 +15728,33 @@ var FunWallet = class extends FirstClassActions {
15559
15728
  * @param {boolean} onlyVerifiedTokens If true, only return alchemy tokens that are verified(filters spam) - defaults to false
15560
15729
  * @returns JSON
15561
15730
  */
15562
- async getTokens(chainIdInput, onlyVerifiedTokens = false) {
15731
+ async getTokens(chainIdInput, onlyVerifiedTokens = false, options) {
15563
15732
  let chainId;
15564
15733
  if (!chainIdInput) {
15565
- const chain = await Chain.getChain({
15566
- chainIdentifier: globalThis.globalEnvOption.chain
15567
- });
15568
- chainId = await chain.getChainId();
15734
+ const chain = await Chain.getChain(
15735
+ {
15736
+ chainIdentifier: globalThis.globalEnvOption.chain
15737
+ },
15738
+ options
15739
+ );
15740
+ chainId = await chain.getChainId(options);
15569
15741
  } else {
15570
15742
  chainId = chainIdInput;
15571
15743
  }
15572
- const walletAddress = await this.getAddress();
15744
+ const walletAddress = await this.getAddress(options);
15573
15745
  return chainId === "ALL" ? await getAllWalletTokens({
15574
15746
  walletAddress,
15575
15747
  onlyVerifiedTokens,
15576
- apiKey: globalThis.globalEnvOption.apiKey
15748
+ apiKey: globalThis.globalEnvOption.apiKey,
15749
+ logger: options?.logger,
15750
+ signal: options?.signal
15577
15751
  }) : await getAllWalletTokensByChainId({
15578
15752
  chainId,
15579
15753
  walletAddress,
15580
15754
  onlyVerifiedTokens,
15581
- apiKey: globalThis.globalEnvOption.apiKey
15755
+ apiKey: globalThis.globalEnvOption.apiKey,
15756
+ logger: options?.logger,
15757
+ signal: options?.signal
15582
15758
  });
15583
15759
  }
15584
15760
  /**
@@ -15586,32 +15762,41 @@ var FunWallet = class extends FirstClassActions {
15586
15762
  * @param {string} chainId string version of the chainId or ALL. If empty, then default to the one in globalEnvOption
15587
15763
  * @returns array
15588
15764
  */
15589
- async getNFTs(chainIdInput) {
15765
+ async getNFTs(chainIdInput, options) {
15590
15766
  let chainId;
15591
15767
  if (!chainIdInput) {
15592
- const chain = await Chain.getChain({
15593
- chainIdentifier: globalThis.globalEnvOption.chain
15594
- });
15595
- chainId = await chain.getChainId();
15768
+ const chain = await Chain.getChain(
15769
+ {
15770
+ chainIdentifier: globalThis.globalEnvOption.chain
15771
+ },
15772
+ options
15773
+ );
15774
+ chainId = await chain.getChainId(options);
15596
15775
  } else {
15597
15776
  chainId = chainIdInput;
15598
15777
  }
15599
- const walletAddress = await this.getAddress();
15778
+ const walletAddress = await this.getAddress(options);
15600
15779
  return chainId === "ALL" ? await getAllWalletNFTs({
15601
15780
  walletAddress,
15602
- apiKey: globalThis.globalEnvOption.apiKey
15781
+ apiKey: globalThis.globalEnvOption.apiKey,
15782
+ logger: options?.logger,
15783
+ signal: options?.signal
15603
15784
  }) : await getAllWalletNFTsByChainId({
15604
15785
  chainId,
15605
15786
  walletAddress,
15606
- apiKey: globalThis.globalEnvOption.apiKey
15787
+ apiKey: globalThis.globalEnvOption.apiKey,
15788
+ logger: options?.logger,
15789
+ signal: options?.signal
15607
15790
  });
15608
15791
  }
15609
- async getLidoWithdrawals() {
15610
- const walletAddress = await this.getAddress();
15792
+ async getLidoWithdrawals(options) {
15793
+ const walletAddress = await this.getAddress(options);
15611
15794
  return await getWalletLidoWithdrawalsByChainId({
15612
15795
  chainId: "1",
15613
15796
  walletAddress,
15614
- apiKey: globalThis.globalEnvOption.apiKey
15797
+ apiKey: globalThis.globalEnvOption.apiKey,
15798
+ logger: options?.logger,
15799
+ signal: options?.signal
15615
15800
  });
15616
15801
  }
15617
15802
  /**
@@ -15621,18 +15806,21 @@ var FunWallet = class extends FirstClassActions {
15621
15806
  * @param {boolean} checkStatus true if you want to check if the address has any pending lido withdrawals
15622
15807
  * @returns JSON of all tokens owned by address
15623
15808
  */
15624
- async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false) {
15809
+ async getAssets(chainIdInput, onlyVerifiedTokens = false, checkStatus = false, options) {
15625
15810
  let chainId;
15626
15811
  if (!chainIdInput) {
15627
- const chain = await Chain.getChain({
15628
- chainIdentifier: globalThis.globalEnvOption.chain
15629
- });
15630
- chainId = await chain.getChainId();
15812
+ const chain = await Chain.getChain(
15813
+ {
15814
+ chainIdentifier: globalThis.globalEnvOption.chain
15815
+ },
15816
+ options
15817
+ );
15818
+ chainId = await chain.getChainId(options);
15631
15819
  } else {
15632
15820
  chainId = chainIdInput;
15633
15821
  }
15634
- const tokens = await this.getTokens(chainId, onlyVerifiedTokens);
15635
- const lidoWithdrawals = checkStatus ? await this.getLidoWithdrawals() : {};
15822
+ const tokens = await this.getTokens(chainId, onlyVerifiedTokens, options);
15823
+ const lidoWithdrawals = checkStatus ? await this.getLidoWithdrawals(options) : {};
15636
15824
  return { ...lidoWithdrawals, ...tokens };
15637
15825
  }
15638
15826
  /**
@@ -15644,8 +15832,14 @@ var FunWallet = class extends FirstClassActions {
15644
15832
  * @returns {Promise<bigint>} The nonce value.
15645
15833
  */
15646
15834
  async getNonce(sender, key = generateRandomNonceKey(), txOptions = globalThis.globalEnvOption) {
15647
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15648
- const entryPointAddress = await chain.getAddress("entryPointAddress");
15835
+ const chain = await Chain.getChain(
15836
+ { chainIdentifier: txOptions.chain },
15837
+ txOptions
15838
+ );
15839
+ const entryPointAddress = await chain.getAddress(
15840
+ "entryPointAddress",
15841
+ txOptions
15842
+ );
15649
15843
  let nonce = void 0;
15650
15844
  let retryCount = 3;
15651
15845
  while ((nonce === void 0 || nonce === null) && retryCount > 0) {
@@ -15653,7 +15847,8 @@ var FunWallet = class extends FirstClassActions {
15653
15847
  entryPointAddress,
15654
15848
  "getNonce",
15655
15849
  [sender, key],
15656
- chain
15850
+ chain,
15851
+ txOptions
15657
15852
  );
15658
15853
  retryCount--;
15659
15854
  }
@@ -15669,12 +15864,17 @@ var FunWallet = class extends FirstClassActions {
15669
15864
  * @returns {Promise<OperationData[]>} A list of operations.
15670
15865
  */
15671
15866
  async getOperations(status = OperationStatus.ALL, txOptions = globalThis.globalEnvOption) {
15672
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15867
+ const chain = await Chain.getChain(
15868
+ { chainIdentifier: txOptions.chain },
15869
+ txOptions
15870
+ );
15673
15871
  return await getOpsOfWallet({
15674
15872
  walletAddr: await this.getAddress(txOptions),
15675
- chainId: await chain.getChainId(),
15873
+ chainId: await chain.getChainId(txOptions),
15676
15874
  status,
15677
- apiKey: globalThis.globalEnvOption.apiKey
15875
+ apiKey: globalThis.globalEnvOption.apiKey,
15876
+ logger: txOptions?.logger,
15877
+ signal: txOptions?.signal
15678
15878
  });
15679
15879
  }
15680
15880
  /**
@@ -15684,11 +15884,16 @@ var FunWallet = class extends FirstClassActions {
15684
15884
  * @returns {Promise<OperationData>} The requested operation.
15685
15885
  */
15686
15886
  async getOperation(opId, txOptions = globalThis.globalEnvOption) {
15687
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15887
+ const chain = await Chain.getChain(
15888
+ { chainIdentifier: txOptions.chain },
15889
+ txOptions
15890
+ );
15688
15891
  return (await getOps({
15689
15892
  opIds: [opId],
15690
- chainId: await chain.getChainId(),
15691
- apiKey: globalThis.globalEnvOption.apiKey
15893
+ chainId: await chain.getChainId(txOptions),
15894
+ apiKey: globalThis.globalEnvOption.apiKey,
15895
+ logger: txOptions?.logger,
15896
+ signal: txOptions?.signal
15692
15897
  }))[0];
15693
15898
  }
15694
15899
  /**
@@ -15698,10 +15903,14 @@ var FunWallet = class extends FirstClassActions {
15698
15903
  * @returns {Promise<User[]>} A list of users with their group information.
15699
15904
  */
15700
15905
  async getUsers(auth, txOptions = globalThis.globalEnvOption) {
15701
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15906
+ const chain = await Chain.getChain(
15907
+ { chainIdentifier: txOptions.chain },
15908
+ txOptions
15909
+ );
15702
15910
  const storedUserIds = await auth.getUserIds(
15703
15911
  await this.getAddress(txOptions),
15704
- await chain.getChainId()
15912
+ await chain.getChainId(txOptions),
15913
+ txOptions
15705
15914
  );
15706
15915
  const userIds = /* @__PURE__ */ new Set([...storedUserIds]);
15707
15916
  if (this.userInfo) {
@@ -15721,8 +15930,10 @@ var FunWallet = class extends FirstClassActions {
15721
15930
  if (groupIds && groupIds.length > 0) {
15722
15931
  const groups = await getGroups({
15723
15932
  groupIds,
15724
- chainId: await chain.getChainId(),
15725
- apiKey: globalThis.globalEnvOption.apiKey
15933
+ chainId: await chain.getChainId(txOptions),
15934
+ apiKey: globalThis.globalEnvOption.apiKey,
15935
+ logger: txOptions?.logger,
15936
+ signal: txOptions?.signal
15726
15937
  });
15727
15938
  for (const group of groups) {
15728
15939
  users.push({
@@ -15742,8 +15953,14 @@ var FunWallet = class extends FirstClassActions {
15742
15953
  * @returns {Promise<boolean>} `true` if the address is a contract, `false` otherwise.
15743
15954
  */
15744
15955
  async getDeploymentStatus(txOptions = globalThis.globalEnvOption) {
15745
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15746
- return await chain.addressIsContract(await this.getAddress(txOptions));
15956
+ const chain = await Chain.getChain(
15957
+ { chainIdentifier: txOptions.chain },
15958
+ txOptions
15959
+ );
15960
+ return await chain.addressIsContract(
15961
+ await this.getAddress(txOptions),
15962
+ txOptions
15963
+ );
15747
15964
  }
15748
15965
  /**
15749
15966
  * Creates the wallet.
@@ -15772,28 +15989,41 @@ var FunWallet = class extends FirstClassActions {
15772
15989
  * @returns A Promise that resolves when the wallet is saved to the authentication system.
15773
15990
  */
15774
15991
  async saveWalletToAuth(auth, txOptions = globalThis.globalEnvOption) {
15775
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
15992
+ const chain = await Chain.getChain(
15993
+ { chainIdentifier: txOptions.chain },
15994
+ txOptions
15995
+ );
15776
15996
  const walletAddr = await this.getAddress(txOptions);
15777
15997
  const userId = await auth.getUserId();
15778
- const users = await auth.getUserIds(walletAddr, await chain.getChainId());
15998
+ const users = await auth.getUserIds(
15999
+ walletAddr,
16000
+ await chain.getChainId(txOptions),
16001
+ txOptions
16002
+ );
15779
16003
  if (!users.includes(userId)) {
15780
16004
  if (await checkWalletAccessInitialization({
15781
16005
  walletAddr,
15782
- apiKey: globalThis.globalEnvOption.apiKey
16006
+ apiKey: globalThis.globalEnvOption.apiKey,
16007
+ logger: txOptions?.logger,
16008
+ signal: txOptions?.signal
15783
16009
  }) === false) {
15784
16010
  await initializeWalletAccess({
15785
16011
  walletAddr,
15786
16012
  creatorAddr: await auth.getAddress(),
15787
- apiKey: globalThis.globalEnvOption.apiKey
16013
+ apiKey: globalThis.globalEnvOption.apiKey,
16014
+ logger: txOptions?.logger,
16015
+ signal: txOptions?.signal
15788
16016
  });
15789
16017
  }
15790
16018
  await addUserToWallet({
15791
16019
  authId: await auth.getAddress(),
15792
- chainId: await chain.getChainId(),
16020
+ chainId: await chain.getChainId(txOptions),
15793
16021
  walletAddr,
15794
16022
  userIds: [userId],
15795
16023
  walletUniqueId: this.walletUniqueId,
15796
- apiKey: globalThis.globalEnvOption.apiKey
16024
+ apiKey: globalThis.globalEnvOption.apiKey,
16025
+ logger: txOptions?.logger,
16026
+ signal: txOptions?.signal
15797
16027
  });
15798
16028
  }
15799
16029
  }
@@ -15808,7 +16038,7 @@ var FunWallet = class extends FirstClassActions {
15808
16038
  async createOperation(auth, userId, transactionParams, txOptions = globalThis.globalEnvOption) {
15809
16039
  if (!userId || userId === "") {
15810
16040
  throw new InvalidParameterError13(
15811
- ErrorCode15.MissingParameter,
16041
+ ErrorCode14.MissingParameter,
15812
16042
  "userId is required",
15813
16043
  "userId is required",
15814
16044
  { userId },
@@ -15819,16 +16049,19 @@ var FunWallet = class extends FirstClassActions {
15819
16049
  const normalizedUserId = pad9(userId, {
15820
16050
  size: 32
15821
16051
  }).toLowerCase();
15822
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16052
+ const chain = await Chain.getChain(
16053
+ { chainIdentifier: txOptions.chain },
16054
+ txOptions
16055
+ );
15823
16056
  const sender = await this.getAddress(txOptions);
15824
- const initCode = await chain.addressIsContract(sender) ? "0x" : await this.getThisInitCode(chain);
16057
+ const initCode = await chain.addressIsContract(sender, txOptions) ? "0x" : await this.getThisInitCode(chain, txOptions);
15825
16058
  let paymasterAndData = "0x";
15826
16059
  let maxFeePerGas;
15827
16060
  let maxPriorityFeePerGas;
15828
- const chainId = await chain.getChainId();
16061
+ const chainId = await chain.getChainId(txOptions);
15829
16062
  const OPStackChains = ["10", "8453"];
15830
16063
  if (OPStackChains.includes(chainId)) {
15831
- const gasPrice = await chain.getFeeData();
16064
+ const gasPrice = await chain.getFeeData(txOptions);
15832
16065
  maxFeePerGas = gasPrice.maxFeePerGas;
15833
16066
  maxPriorityFeePerGas = gasPrice.maxPriorityFeePerGas;
15834
16067
  } else {
@@ -15847,18 +16080,18 @@ var FunWallet = class extends FirstClassActions {
15847
16080
  maxFeePerGas,
15848
16081
  maxPriorityFeePerGas,
15849
16082
  initCode,
15850
- nonce: txOptions.nonce !== null && txOptions.nonce !== void 0 ? txOptions.nonce : await this.getNonce(sender),
16083
+ nonce: txOptions.nonce !== null && txOptions.nonce !== void 0 ? txOptions.nonce : await this.getNonce(sender, void 0, txOptions),
15851
16084
  preVerificationGas: 100000n,
15852
16085
  callGasLimit: BigInt(1e7),
15853
16086
  verificationGasLimit: BigInt(1e7)
15854
16087
  };
15855
- if (await chain.getChainId() === "36865") {
16088
+ if (await chain.getChainId(txOptions) === "36865") {
15856
16089
  partialOp.callGasLimit = BigInt(1e6);
15857
16090
  partialOp.verificationGasLimit = BigInt(1e6);
15858
16091
  }
15859
16092
  const isGroupOp = await auth.getUserId() !== normalizedUserId;
15860
16093
  const operation = new Operation(partialOp, {
15861
- chainId: await chain.getChainId(),
16094
+ chainId: await chain.getChainId(txOptions),
15862
16095
  opType: isGroupOp ? OperationType.GROUP_OPERATION : OperationType.SINGLE_OPERATION,
15863
16096
  authType: isGroupOp ? AuthType2.MULTI_SIG : AuthType2.ECDSA,
15864
16097
  walletAddr: await this.getAddress(txOptions),
@@ -15901,22 +16134,29 @@ var FunWallet = class extends FirstClassActions {
15901
16134
  estimatedOperation.userOp.signature = await auth.signOp(
15902
16135
  estimatedOperation,
15903
16136
  chain,
15904
- isGroupOperation(operation)
16137
+ isGroupOperation(operation),
16138
+ txOptions
15905
16139
  );
15906
16140
  if (txOptions.skipDBAction !== true) {
15907
16141
  const opId = await createOp({
15908
16142
  op: estimatedOperation,
15909
- apiKey: globalThis.globalEnvOption.apiKey
16143
+ apiKey: globalThis.globalEnvOption.apiKey,
16144
+ logger: txOptions?.logger,
16145
+ signal: txOptions?.signal
15910
16146
  });
15911
16147
  estimatedOperation.opId = opId;
15912
16148
  if (!await checkWalletAccessInitialization({
15913
16149
  walletAddr: sender,
15914
- apiKey: globalThis.globalEnvOption.apiKey
16150
+ apiKey: globalThis.globalEnvOption.apiKey,
16151
+ logger: txOptions?.logger,
16152
+ signal: txOptions?.signal
15915
16153
  })) {
15916
16154
  await initializeWalletAccess({
15917
16155
  walletAddr: sender,
15918
16156
  creatorAddr: await auth.getAddress(),
15919
- apiKey: globalThis.globalEnvOption.apiKey
16157
+ apiKey: globalThis.globalEnvOption.apiKey,
16158
+ logger: txOptions?.logger,
16159
+ signal: txOptions?.signal
15920
16160
  });
15921
16161
  }
15922
16162
  }
@@ -15930,21 +16170,27 @@ var FunWallet = class extends FirstClassActions {
15930
16170
  * @returns {Promise<Operation>} The signed operation.
15931
16171
  */
15932
16172
  async signOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
15933
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16173
+ const chain = await Chain.getChain(
16174
+ { chainIdentifier: txOptions.chain },
16175
+ txOptions
16176
+ );
15934
16177
  const finalOperation = Operation.convertTypeToObject(operation);
15935
16178
  finalOperation.userOp.signature = await auth.signOp(
15936
16179
  finalOperation,
15937
16180
  chain,
15938
- isGroupOperation(finalOperation)
16181
+ isGroupOperation(finalOperation),
16182
+ txOptions
15939
16183
  );
15940
16184
  if (isGroupOperation(finalOperation) && txOptions.skipDBAction !== true) {
15941
16185
  await signOp({
15942
16186
  opId: finalOperation.opId,
15943
- chainId: await chain.getChainId(),
16187
+ chainId: await chain.getChainId(txOptions),
15944
16188
  signature: finalOperation.userOp.signature,
15945
16189
  signedBy: await auth.getAddress(),
15946
16190
  threshold: this.userInfo?.get(finalOperation.groupId)?.groupInfo?.threshold,
15947
- apiKey: globalThis.globalEnvOption.apiKey
16191
+ apiKey: globalThis.globalEnvOption.apiKey,
16192
+ logger: txOptions?.logger,
16193
+ signal: txOptions?.signal
15948
16194
  });
15949
16195
  }
15950
16196
  return finalOperation;
@@ -15960,16 +16206,21 @@ var FunWallet = class extends FirstClassActions {
15960
16206
  async executeOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
15961
16207
  const finalTxOptions = parseOptions(txOptions);
15962
16208
  const finalOperation = Operation.convertTypeToObject(operation);
15963
- const chain = await Chain.getChain({
15964
- chainIdentifier: finalTxOptions.chain
15965
- });
15966
- const chainId = await chain.getChainId();
16209
+ const chain = await Chain.getChain(
16210
+ {
16211
+ chainIdentifier: finalTxOptions.chain
16212
+ },
16213
+ txOptions
16214
+ );
16215
+ const chainId = await chain.getChainId(txOptions);
15967
16216
  if (finalTxOptions.skipDBAction !== true) {
15968
16217
  if (isGroupOperation(finalOperation)) {
15969
16218
  const groups = await getGroups({
15970
16219
  groupIds: [finalOperation.groupId],
15971
16220
  chainId,
15972
- apiKey: globalThis.globalEnvOption.apiKey
16221
+ apiKey: globalThis.globalEnvOption.apiKey,
16222
+ logger: txOptions?.logger,
16223
+ signal: txOptions?.signal
15973
16224
  });
15974
16225
  if (groups && groups.length > 0) {
15975
16226
  this.userInfo?.set(finalOperation.groupId, {
@@ -15988,7 +16239,8 @@ var FunWallet = class extends FirstClassActions {
15988
16239
  finalOperation.userOp.signature = await auth.signOp(
15989
16240
  finalOperation,
15990
16241
  chain,
15991
- isGroupOperation(finalOperation)
16242
+ isGroupOperation(finalOperation),
16243
+ txOptions
15992
16244
  );
15993
16245
  }
15994
16246
  } else {
@@ -15996,7 +16248,9 @@ var FunWallet = class extends FirstClassActions {
15996
16248
  const storedOps = await getOps({
15997
16249
  opIds: [finalOperation.opId],
15998
16250
  chainId,
15999
- apiKey: globalThis.globalEnvOption.apiKey
16251
+ apiKey: globalThis.globalEnvOption.apiKey,
16252
+ logger: txOptions?.logger,
16253
+ signal: txOptions?.signal
16000
16254
  });
16001
16255
  let collectedSigCount;
16002
16256
  if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
@@ -16005,7 +16259,8 @@ var FunWallet = class extends FirstClassActions {
16005
16259
  finalOperation.userOp.signature = await auth.signOp(
16006
16260
  finalOperation,
16007
16261
  chain,
16008
- isGroupOperation(finalOperation)
16262
+ isGroupOperation(finalOperation),
16263
+ txOptions
16009
16264
  );
16010
16265
  }
16011
16266
  } else {
@@ -16013,7 +16268,7 @@ var FunWallet = class extends FirstClassActions {
16013
16268
  }
16014
16269
  if (collectedSigCount < threshold) {
16015
16270
  throw new InvalidParameterError13(
16016
- ErrorCode15.InsufficientSignatures,
16271
+ ErrorCode14.InsufficientSignatures,
16017
16272
  "Signatures are not sufficient to execute the operation",
16018
16273
  "Signatures are not sufficient to execute the operation",
16019
16274
  { threshold, collectedSigCount, chainId },
@@ -16023,7 +16278,7 @@ var FunWallet = class extends FirstClassActions {
16023
16278
  }
16024
16279
  } else {
16025
16280
  throw new InvalidParameterError13(
16026
- ErrorCode15.InsufficientSignatures,
16281
+ ErrorCode14.InsufficientSignatures,
16027
16282
  "Signatures are not sufficient to execute the operation",
16028
16283
  "Signatures are not sufficient to execute the operation",
16029
16284
  { threshold, chainId, skipDBAction: finalTxOptions.skipDBAction },
@@ -16039,11 +16294,16 @@ var FunWallet = class extends FirstClassActions {
16039
16294
  opId: finalOperation.opId,
16040
16295
  chainId,
16041
16296
  executedBy: await auth.getAddress(),
16042
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16297
+ entryPointAddress: await chain.getAddress(
16298
+ "entryPointAddress",
16299
+ txOptions
16300
+ ),
16043
16301
  signature: finalOperation.userOp.signature,
16044
16302
  groupInfo: this.userInfo?.get(finalOperation.groupId)?.groupInfo
16045
16303
  },
16046
- apiKey: globalThis.globalEnvOption.apiKey
16304
+ apiKey: globalThis.globalEnvOption.apiKey,
16305
+ logger: txOptions.logger,
16306
+ signal: txOptions.signal
16047
16307
  });
16048
16308
  } else {
16049
16309
  receipt = await executeOp({
@@ -16051,18 +16311,25 @@ var FunWallet = class extends FirstClassActions {
16051
16311
  opId: finalOperation.opId,
16052
16312
  chainId,
16053
16313
  executedBy: await auth.getAddress(),
16054
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16314
+ entryPointAddress: await chain.getAddress(
16315
+ "entryPointAddress",
16316
+ txOptions
16317
+ ),
16055
16318
  signature: finalOperation.userOp.signature,
16056
16319
  userOp: finalOperation.userOp
16057
16320
  },
16058
- apiKey: globalThis.globalEnvOption.apiKey
16321
+ apiKey: globalThis.globalEnvOption.apiKey,
16322
+ logger: txOptions.logger,
16323
+ signal: txOptions.signal
16059
16324
  });
16060
16325
  }
16061
16326
  receipt = await getFullReceipt({
16062
16327
  opId: finalOperation.opId,
16063
16328
  chainId,
16064
16329
  userOpHash: receipt.userOpHash,
16065
- apiKey: globalThis.globalEnvOption.apiKey
16330
+ apiKey: globalThis.globalEnvOption.apiKey,
16331
+ logger: txOptions.logger,
16332
+ signal: txOptions.signal
16066
16333
  });
16067
16334
  if (isWalletInitOp(finalOperation.userOp) && finalTxOptions.skipDBAction !== true) {
16068
16335
  await addUserToWallet({
@@ -16071,7 +16338,9 @@ var FunWallet = class extends FirstClassActions {
16071
16338
  walletAddr: await this.getAddress(finalTxOptions),
16072
16339
  userIds: Array.from(this.userInfo.keys()),
16073
16340
  walletUniqueId: this.walletUniqueId,
16074
- apiKey: globalThis.globalEnvOption.apiKey
16341
+ apiKey: globalThis.globalEnvOption.apiKey,
16342
+ logger: finalTxOptions.logger,
16343
+ signal: finalTxOptions.signal
16075
16344
  });
16076
16345
  if (finalTxOptions?.gasSponsor?.sponsorAddress) {
16077
16346
  const paymasterType = getPaymasterType(finalTxOptions);
@@ -16090,7 +16359,9 @@ var FunWallet = class extends FirstClassActions {
16090
16359
  },
16091
16360
  paymasterType,
16092
16361
  sponsorAddress: finalTxOptions.gasSponsor.sponsorAddress,
16093
- apiKey: globalThis.globalEnvOption.apiKey
16362
+ apiKey: globalThis.globalEnvOption.apiKey,
16363
+ logger: finalTxOptions.logger,
16364
+ signal: finalTxOptions.signal
16094
16365
  });
16095
16366
  }
16096
16367
  }
@@ -16107,14 +16378,19 @@ var FunWallet = class extends FirstClassActions {
16107
16378
  async scheduleOperation(auth, operation, txOptions = globalThis.globalEnvOption) {
16108
16379
  const finalTxOptions = parseOptions(txOptions);
16109
16380
  const finalOperation = Operation.convertTypeToObject(operation);
16110
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16111
- const chainId = await chain.getChainId();
16381
+ const chain = await Chain.getChain(
16382
+ { chainIdentifier: txOptions.chain },
16383
+ txOptions
16384
+ );
16385
+ const chainId = await chain.getChainId(txOptions);
16112
16386
  if (finalTxOptions.skipDBAction !== true) {
16113
16387
  if (isGroupOperation(finalOperation)) {
16114
16388
  const groups = await getGroups({
16115
16389
  groupIds: [finalOperation.groupId],
16116
16390
  chainId,
16117
- apiKey: globalThis.globalEnvOption.apiKey
16391
+ apiKey: globalThis.globalEnvOption.apiKey,
16392
+ logger: txOptions.logger,
16393
+ signal: txOptions.signal
16118
16394
  });
16119
16395
  if (groups && groups.length > 0) {
16120
16396
  this.userInfo?.set(finalOperation.groupId, {
@@ -16133,7 +16409,8 @@ var FunWallet = class extends FirstClassActions {
16133
16409
  finalOperation.userOp.signature = await auth.signOp(
16134
16410
  finalOperation,
16135
16411
  chain,
16136
- isGroupOperation(finalOperation)
16412
+ isGroupOperation(finalOperation),
16413
+ txOptions
16137
16414
  );
16138
16415
  }
16139
16416
  } else {
@@ -16141,7 +16418,9 @@ var FunWallet = class extends FirstClassActions {
16141
16418
  const storedOps = await getOps({
16142
16419
  opIds: [finalOperation.opId],
16143
16420
  chainId,
16144
- apiKey: globalThis.globalEnvOption.apiKey
16421
+ apiKey: globalThis.globalEnvOption.apiKey,
16422
+ logger: txOptions.logger,
16423
+ signal: txOptions.signal
16145
16424
  });
16146
16425
  let collectedSigCount;
16147
16426
  if (isSignatureMissing(await auth.getUserId(), storedOps[0]?.signatures)) {
@@ -16150,7 +16429,8 @@ var FunWallet = class extends FirstClassActions {
16150
16429
  finalOperation.userOp.signature = await auth.signOp(
16151
16430
  finalOperation,
16152
16431
  chain,
16153
- isGroupOperation(finalOperation)
16432
+ isGroupOperation(finalOperation),
16433
+ txOptions
16154
16434
  );
16155
16435
  }
16156
16436
  } else {
@@ -16158,7 +16438,7 @@ var FunWallet = class extends FirstClassActions {
16158
16438
  }
16159
16439
  if (collectedSigCount < threshold) {
16160
16440
  throw new InvalidParameterError13(
16161
- ErrorCode15.InsufficientSignatures,
16441
+ ErrorCode14.InsufficientSignatures,
16162
16442
  "Signatures are not sufficient to execute the operation",
16163
16443
  "Signatures are not sufficient to execute the operation",
16164
16444
  { threshold, collectedSigCount, chainId },
@@ -16168,7 +16448,7 @@ var FunWallet = class extends FirstClassActions {
16168
16448
  }
16169
16449
  } else {
16170
16450
  throw new InvalidParameterError13(
16171
- ErrorCode15.InsufficientSignatures,
16451
+ ErrorCode14.InsufficientSignatures,
16172
16452
  "Signatures are not sufficient to execute the operation",
16173
16453
  "Signatures are not sufficient to execute the operation",
16174
16454
  { threshold, chainId, skipDBAction: finalTxOptions.skipDBAction },
@@ -16183,11 +16463,16 @@ var FunWallet = class extends FirstClassActions {
16183
16463
  opId: finalOperation.opId,
16184
16464
  chainId,
16185
16465
  scheduledBy: await auth.getAddress(),
16186
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16466
+ entryPointAddress: await chain.getAddress(
16467
+ "entryPointAddress",
16468
+ txOptions
16469
+ ),
16187
16470
  signature: finalOperation.userOp.signature,
16188
16471
  groupInfo: this.userInfo?.get(finalOperation.groupId)?.groupInfo
16189
16472
  },
16190
- apiKey: globalThis.globalEnvOption.apiKey
16473
+ apiKey: globalThis.globalEnvOption.apiKey,
16474
+ logger: txOptions.logger,
16475
+ signal: txOptions.signal
16191
16476
  });
16192
16477
  } else {
16193
16478
  await scheduleOp({
@@ -16195,16 +16480,21 @@ var FunWallet = class extends FirstClassActions {
16195
16480
  opId: finalOperation.opId,
16196
16481
  chainId,
16197
16482
  scheduledBy: await auth.getAddress(),
16198
- entryPointAddress: await chain.getAddress("entryPointAddress"),
16483
+ entryPointAddress: await chain.getAddress(
16484
+ "entryPointAddress",
16485
+ txOptions
16486
+ ),
16199
16487
  signature: finalOperation.userOp.signature,
16200
16488
  userOp: finalOperation.userOp
16201
16489
  },
16202
- apiKey: globalThis.globalEnvOption.apiKey
16490
+ apiKey: globalThis.globalEnvOption.apiKey,
16491
+ logger: txOptions.logger,
16492
+ signal: txOptions.signal
16203
16493
  });
16204
16494
  }
16205
16495
  if (!finalOperation.opId) {
16206
- throw new InternalFailureError5(
16207
- ErrorCode15.ServerFailure,
16496
+ throw new InternalFailureError4(
16497
+ ErrorCode14.ServerFailure,
16208
16498
  "Operation id is required",
16209
16499
  "",
16210
16500
  finalOperation,
@@ -16222,11 +16512,16 @@ var FunWallet = class extends FirstClassActions {
16222
16512
  * @returns {Promise<void>} A promise that resolves after the operation is removed.
16223
16513
  */
16224
16514
  async removeOperation(_, operationId, txOptions = globalThis.globalEnvOption) {
16225
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16515
+ const chain = await Chain.getChain(
16516
+ { chainIdentifier: txOptions.chain },
16517
+ txOptions
16518
+ );
16226
16519
  await deleteOp({
16227
16520
  opId: operationId,
16228
- chainId: await chain.getChainId(),
16229
- apiKey: globalThis.globalEnvOption.apiKey
16521
+ chainId: await chain.getChainId(txOptions),
16522
+ apiKey: globalThis.globalEnvOption.apiKey,
16523
+ logger: txOptions?.logger,
16524
+ signal: txOptions?.signal
16230
16525
  });
16231
16526
  }
16232
16527
  /**
@@ -16254,7 +16549,9 @@ var FunWallet = class extends FirstClassActions {
16254
16549
  rejectOperation.opType = OperationType.REJECTION;
16255
16550
  rejectOperation.opId = await createOp({
16256
16551
  op: rejectOperation,
16257
- apiKey: globalThis.globalEnvOption.apiKey
16552
+ apiKey: globalThis.globalEnvOption.apiKey,
16553
+ logger: txOptions.logger,
16554
+ signal: txOptions.signal
16258
16555
  });
16259
16556
  return rejectOperation;
16260
16557
  }
@@ -16267,7 +16564,10 @@ var FunWallet = class extends FirstClassActions {
16267
16564
  * @returns {Promise<Operation>} The updated operation with gas estimation details.
16268
16565
  */
16269
16566
  async estimateOperation(auth, userId, operation, txOptions = globalThis.globalEnvOption) {
16270
- const chain = await Chain.getChain({ chainIdentifier: txOptions.chain });
16567
+ const chain = await Chain.getChain(
16568
+ { chainIdentifier: txOptions.chain },
16569
+ txOptions
16570
+ );
16271
16571
  const estimateGasSignature = await auth.getEstimateGasSignature(
16272
16572
  userId,
16273
16573
  operation
@@ -16279,17 +16579,20 @@ var FunWallet = class extends FirstClassActions {
16279
16579
  // ...res,
16280
16580
  paymasterAndData
16281
16581
  };
16282
- const { maxFeePerGas, maxPriorityFeePerGas } = await chain.getFeeData();
16582
+ const { maxFeePerGas, maxPriorityFeePerGas } = await chain.getFeeData(txOptions);
16283
16583
  operation.userOp.maxFeePerGas = maxFeePerGas;
16284
16584
  operation.userOp.maxPriorityFeePerGas = maxPriorityFeePerGas;
16285
16585
  return operation;
16286
16586
  }
16287
- async getThisInitCode(chain) {
16587
+ async getThisInitCode(chain, options) {
16288
16588
  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");
16589
+ const entryPointAddress = await chain.getAddress(
16590
+ "entryPointAddress",
16591
+ options
16592
+ );
16593
+ const factoryAddress = await chain.getAddress("factoryAddress", options);
16594
+ const rbac = await chain.getAddress("rbacAddress", options);
16595
+ const userAuth = await chain.getAddress("userAuthAddress", options);
16293
16596
  const loginData = {
16294
16597
  salt: this.walletUniqueId
16295
16598
  };
@@ -16351,7 +16654,7 @@ var FunWallet = class extends FirstClassActions {
16351
16654
  }
16352
16655
  if (!options.fee.token) {
16353
16656
  throw new InvalidParameterError13(
16354
- ErrorCode15.MissingParameter,
16657
+ ErrorCode14.MissingParameter,
16355
16658
  "EnvOption.fee.token or EnvOption.gasSponsor.token is required",
16356
16659
  "EnvOption.fee.token or EnvOption.gasSponsor.token is required",
16357
16660
  { options },
@@ -16361,7 +16664,7 @@ var FunWallet = class extends FirstClassActions {
16361
16664
  }
16362
16665
  if (!options.fee.recipient) {
16363
16666
  throw new InvalidParameterError13(
16364
- ErrorCode15.MissingParameter,
16667
+ ErrorCode14.MissingParameter,
16365
16668
  "EnvOption.fee.recipient is required",
16366
16669
  "EnvOption.fee.recipient is required",
16367
16670
  { options },
@@ -16369,11 +16672,14 @@ var FunWallet = class extends FirstClassActions {
16369
16672
  "https://docs.fun.xyz/how-to-guides/execute-transactions#execute-transactions"
16370
16673
  );
16371
16674
  }
16372
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
16675
+ const chain = await Chain.getChain(
16676
+ { chainIdentifier: options.chain },
16677
+ options
16678
+ );
16373
16679
  const token = new Token(options.fee.token, chain);
16374
16680
  if (options.fee.gasPercent && !token.isNative) {
16375
16681
  throw new InvalidParameterError13(
16376
- ErrorCode15.InvalidParameterCombination,
16682
+ ErrorCode14.InvalidParameterCombination,
16377
16683
  "GasPercent is only valid for native tokens",
16378
16684
  "GasPercent is only valid for native tokens",
16379
16685
  { options },
@@ -16384,11 +16690,11 @@ var FunWallet = class extends FirstClassActions {
16384
16690
  if (token.isNative) {
16385
16691
  options.fee.token = AddressZero;
16386
16692
  } else {
16387
- options.fee.token = await token.getAddress();
16693
+ options.fee.token = await token.getAddress(options);
16388
16694
  }
16389
16695
  if (options.fee.amount) {
16390
16696
  options.fee.amount = Number(
16391
- await token.getDecimalAmount(options.fee.amount)
16697
+ await token.getDecimalAmount(options.fee.amount, options)
16392
16698
  );
16393
16699
  } else if (options.fee.gasPercent) {
16394
16700
  const feedata2 = [options.fee.token, options.fee.recipient, 1];
@@ -16402,13 +16708,13 @@ var FunWallet = class extends FirstClassActions {
16402
16708
  { to: params.to, value: params.value, data: estimateGasCalldata },
16403
16709
  { ...options, fee: void 0 }
16404
16710
  );
16405
- const gasUsed = await operation.getMaxTxCost();
16711
+ const gasUsed = operation.getMaxTxCost();
16406
16712
  options.fee.amount = Math.ceil(
16407
16713
  Number(gasUsed) * options.fee.gasPercent / 100
16408
16714
  );
16409
16715
  } else {
16410
16716
  throw new InvalidParameterError13(
16411
- ErrorCode15.MissingParameter,
16717
+ ErrorCode14.MissingParameter,
16412
16718
  "EnvOption.fee.amount or EnvOption.fee.gasPercent is required",
16413
16719
  "EnvOption.fee.amount or EnvOption.fee.gasPercent is required",
16414
16720
  { options },
@@ -16517,7 +16823,6 @@ export {
16517
16823
  erc721TransferTransactionParams,
16518
16824
  finishUnstakeTransactionParams,
16519
16825
  fundWallet,
16520
- gasCalculation,
16521
16826
  gasSpecificChain,
16522
16827
  generatePrivateKey,
16523
16828
  generateRandomBytes32,
@@ -16557,11 +16862,6 @@ export {
16557
16862
  removeOwnerTxParams,
16558
16863
  requestUnstakeTransactionParams,
16559
16864
  roundToNearestBottomTenth,
16560
- sendDeleteRequest,
16561
- sendGetRequest,
16562
- sendPostRequest,
16563
- sendPutRequest,
16564
- sendRequest,
16565
16865
  stakeTransactionParams,
16566
16866
  stringify,
16567
16867
  toBytes32Arr,