@funkit/core 2.3.2 → 2.3.4

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
@@ -11505,7 +11505,9 @@ import {
11505
11505
  } from "@funkit/utils";
11506
11506
 
11507
11507
  // src/utils/ApiUtils.ts
11508
- import { retry } from "@lifeomic/attempt";
11508
+ import {
11509
+ retry
11510
+ } from "@lifeomic/attempt";
11509
11511
  import {
11510
11512
  AccessDeniedError,
11511
11513
  ErrorCode,
@@ -11650,7 +11652,7 @@ var sendRequest = async (uri, method, apiKey, body, retryOptions) => {
11650
11652
  );
11651
11653
  }
11652
11654
  };
11653
- async function sendGetRequest(uri, endpoint, apiKey = globalThis.globalEnvOption?.apiKey, retryOptions = {}) {
11655
+ async function sendGetRequest(uri, endpoint, apiKey = globalThis.globalEnvOption.apiKey, retryOptions = {}) {
11654
11656
  return await sendRequest(
11655
11657
  `${uri}/${endpoint}`,
11656
11658
  "GET",
@@ -11659,7 +11661,7 @@ async function sendGetRequest(uri, endpoint, apiKey = globalThis.globalEnvOption
11659
11661
  retryOptions
11660
11662
  );
11661
11663
  }
11662
- async function sendPostRequest(uri, endpoint, body, apiKey = globalThis.globalEnvOption?.apiKey, retryOptions = {}) {
11664
+ async function sendPostRequest(uri, endpoint, body, apiKey = globalThis.globalEnvOption.apiKey, retryOptions = {}) {
11663
11665
  return await sendRequest(
11664
11666
  `${uri}/${endpoint}`,
11665
11667
  "POST",
@@ -11778,7 +11780,7 @@ var getWalletPermitNonce = async (walletAddr, chain, nonceKey = 0) => {
11778
11780
  chain
11779
11781
  );
11780
11782
  } catch (_err) {
11781
- return 0;
11783
+ return 0n;
11782
11784
  }
11783
11785
  };
11784
11786
  var getPermitHash = (token, to, amount, nonce, walletAddr, chainId) => {
@@ -11896,7 +11898,6 @@ import {
11896
11898
  toBytes as toBytes2,
11897
11899
  toHex as toHex2
11898
11900
  } from "viem";
11899
- import { safeParseJson } from "@funkit/utils";
11900
11901
  var calcPreVerificationGas = (userOp) => {
11901
11902
  const ov = DefaultGasOverheads;
11902
11903
  const p = Object.assign(
@@ -11924,12 +11925,11 @@ function encode(typevalues, forSignature) {
11924
11925
  }
11925
11926
  function packUserOp(op, forSignature = true) {
11926
11927
  if (forSignature) {
11927
- let encoded = encodeAbiParameters2(
11928
+ const encoded = encodeAbiParameters2(
11928
11929
  [userOpTypeSig],
11929
11930
  [{ ...op, signature: "0x" }]
11930
11931
  );
11931
- encoded = "0x" + encoded.slice(66, encoded.length - 64);
11932
- return encoded;
11932
+ return `0x${encoded.slice(66, encoded.length - 64)}`;
11933
11933
  }
11934
11934
  const typevalues = UserOpType.components.map((c) => ({
11935
11935
  type: c.type,
@@ -11937,15 +11937,6 @@ function packUserOp(op, forSignature = true) {
11937
11937
  }));
11938
11938
  return encode(typevalues, forSignature);
11939
11939
  }
11940
- var getPromiseFromOp = async (op) => {
11941
- const out = {};
11942
- await Promise.all(
11943
- Object.keys(op).map(async (key) => {
11944
- out[key] = await op[key];
11945
- })
11946
- );
11947
- return out;
11948
- };
11949
11940
  async function gasCalculation(txid, chain) {
11950
11941
  if (!txid || txid === "0x")
11951
11942
  return { gasUsed: "-1", opFee: "-1", opFeeUSD: "-1" };
@@ -11983,9 +11974,6 @@ var stringify = (object) => {
11983
11974
  // return everything else unchanged
11984
11975
  );
11985
11976
  };
11986
- var objectify = (op) => {
11987
- return safeParseJson(stringify(op));
11988
- };
11989
11977
  var DefaultGasOverheads = {
11990
11978
  fixed: 28e3,
11991
11979
  perUserOp: 18300,
@@ -12863,6 +12851,7 @@ var Token = class _Token {
12863
12851
 
12864
12852
  // src/viem/ContractInterface.ts
12865
12853
  var ContractInterface = class {
12854
+ // biome-ignore lint/suspicious/noExplicitAny: Strict typing here clashes when importing from JSON
12866
12855
  constructor(abi) {
12867
12856
  this.abi = abi;
12868
12857
  }
@@ -12941,11 +12930,11 @@ var parseClient = async (chainOrClient) => {
12941
12930
  if (chainOrClient instanceof Chain) {
12942
12931
  const chain = chainOrClient;
12943
12932
  return await chain.getClient();
12944
- } else if (typeof chainOrClient.readContract === "function") {
12933
+ }
12934
+ if (typeof chainOrClient.readContract === "function") {
12945
12935
  return chainOrClient;
12946
- } else {
12947
- throw new Error("No client or chain provided");
12948
12936
  }
12937
+ throw new Error("No client or chain provided");
12949
12938
  };
12950
12939
  var getItemFromAbi = (abi, name, type) => {
12951
12940
  const item = abi.find((item2) => item2.name === name && item2.type === type);
@@ -13123,7 +13112,7 @@ var convertProviderToClient = ({
13123
13112
  viemChain
13124
13113
  }) => {
13125
13114
  const chain = viemChain ? viemChain : mainnet;
13126
- if (provider.request) {
13115
+ if (typeof provider.request === "function") {
13127
13116
  return createWalletClient({
13128
13117
  chain,
13129
13118
  transport: custom(provider)
@@ -13157,7 +13146,8 @@ var convertSignerToClient = ({
13157
13146
  async request({ method, params }) {
13158
13147
  if (method === "eth_requestAccounts") {
13159
13148
  return [await signer.getAddress()];
13160
- } else if (method === "personal_sign") {
13149
+ }
13150
+ if (method === "personal_sign") {
13161
13151
  return await signer.signMessage(toBytes4(params[0]));
13162
13152
  }
13163
13153
  }
@@ -13278,13 +13268,12 @@ var Auth = class {
13278
13268
  }
13279
13269
  if (isGroupOp) {
13280
13270
  return signature;
13281
- } else {
13282
- const walletSignature = {
13283
- userId: await this.getUserId(),
13284
- signature
13285
- };
13286
- return encodeWalletSignature(walletSignature);
13287
13271
  }
13272
+ const walletSignature = {
13273
+ userId: await this.getUserId(),
13274
+ signature
13275
+ };
13276
+ return encodeWalletSignature(walletSignature);
13288
13277
  }
13289
13278
  /**
13290
13279
  * Signs an operation using the stored signer and returns the signature.
@@ -13406,22 +13395,21 @@ var Auth = class {
13406
13395
  hash,
13407
13396
  timeout: 3e4
13408
13397
  });
13409
- } else {
13410
- const maxRetry = 10;
13411
- let retryCount = 0;
13412
- while (retryCount < maxRetry) {
13413
- try {
13414
- return await client.waitForTransactionReceipt({
13415
- hash,
13416
- timeout: 3e4
13417
- });
13418
- } catch (_err) {
13419
- retryCount++;
13420
- await new Promise((r) => setTimeout(r, 5e3));
13421
- }
13398
+ }
13399
+ const maxRetry = 10;
13400
+ let retryCount = 0;
13401
+ while (retryCount < maxRetry) {
13402
+ try {
13403
+ return await client.waitForTransactionReceipt({
13404
+ hash,
13405
+ timeout: 3e4
13406
+ });
13407
+ } catch (_err) {
13408
+ retryCount++;
13409
+ await new Promise((r) => setTimeout(r, 5e3));
13422
13410
  }
13423
- throw Error("Failed to get transaction receipt after several retries");
13424
13411
  }
13412
+ throw Error("Failed to get transaction receipt after several retries");
13425
13413
  }
13426
13414
  /**
13427
13415
  * Sends an array of transactions and returns an array of corresponding transaction receipts.
@@ -13591,7 +13579,8 @@ var decodeCalldata = (callData) => {
13591
13579
  );
13592
13580
  if (callData.includes(execFromEntryPointFeeSelector)) {
13593
13581
  return _decodeExecWithFee(callData);
13594
- } else if (callData.includes(execFromEntryPointSelector)) {
13582
+ }
13583
+ if (callData.includes(execFromEntryPointSelector)) {
13595
13584
  return _decodeExec(callData);
13596
13585
  }
13597
13586
  throw new Error(
@@ -13599,7 +13588,7 @@ var decodeCalldata = (callData) => {
13599
13588
  );
13600
13589
  };
13601
13590
  var _decodeExecWithFee = (callData) => {
13602
- const walletcalldata = "0x" + callData.slice(SELECTOR_LENGTH);
13591
+ const walletcalldata = `0x${callData.slice(SELECTOR_LENGTH)}`;
13603
13592
  const [target, value, calldata] = decodeAbiParameters2(
13604
13593
  [{ type: "address" }, { type: "uint256" }, { type: "bytes" }],
13605
13594
  walletcalldata
@@ -13611,7 +13600,7 @@ var _decodeExecWithFee = (callData) => {
13611
13600
  };
13612
13601
  };
13613
13602
  var _decodeExec = (callData) => {
13614
- const walletcalldata = "0x" + callData.slice(SELECTOR_LENGTH);
13603
+ const walletcalldata = `0x${callData.slice(SELECTOR_LENGTH)}`;
13615
13604
  const [target, value, calldata] = decodeAbiParameters2(
13616
13605
  [{ type: "address" }, { type: "uint256" }, { type: "bytes" }],
13617
13606
  walletcalldata
@@ -13824,9 +13813,8 @@ var removeOwnerTxParams = async (params, txOptions = globalThis.globalEnvOption)
13824
13813
  var convertTimestampToBigInt = (timestamp) => {
13825
13814
  if (Math.abs(Date.now() - timestamp) < Math.abs(Date.now() - timestamp * 1e3)) {
13826
13815
  return BigInt(Math.floor(timestamp)) / 1000n;
13827
- } else {
13828
- return BigInt(Math.floor(timestamp));
13829
13816
  }
13817
+ return BigInt(Math.floor(timestamp));
13830
13818
  };
13831
13819
 
13832
13820
  // src/actions/BatchActions.ts
@@ -13891,7 +13879,7 @@ var getWithdrawQueueInterface = () => {
13891
13879
  return new ContractInterface(WITHDRAW_QUEUE_ABI);
13892
13880
  };
13893
13881
  var isRequestUnstakeParams = (input) => {
13894
- return input.amounts !== void 0;
13882
+ return "amounts" in input ? input.amounts !== void 0 : false;
13895
13883
  };
13896
13884
  var isFinishUnstakeParams = (input) => {
13897
13885
  return input.recipient !== void 0;
@@ -14017,18 +14005,8 @@ var getReadyToWithdrawRequests = async (params, txOptions) => {
14017
14005
  const withdrawalQueueAddr = getWithdrawalQueue(
14018
14006
  await chain.getChainId()
14019
14007
  );
14020
- const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(
14021
- withdrawalQueueAddr,
14022
- "getWithdrawalRequests",
14023
- [params.walletAddress],
14024
- chain
14025
- );
14026
- const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(
14027
- withdrawalQueueAddr,
14028
- "getWithdrawalStatus",
14029
- [withdrawalRequests],
14030
- chain
14031
- );
14008
+ const withdrawalRequests = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalRequests", [params.walletAddress], chain);
14009
+ const withdrawalStatusTx = await getWithdrawQueueInterface().readFromChain(withdrawalQueueAddr, "getWithdrawalStatus", [withdrawalRequests], chain);
14032
14010
  const readyToWithdraw = [];
14033
14011
  for (let i = 0; i < withdrawalStatusTx.length; i++) {
14034
14012
  if (withdrawalStatusTx[i].isFinalized) {
@@ -14358,7 +14336,7 @@ var Sponsor = class {
14358
14336
  }
14359
14337
  async batchTransaction(transactions) {
14360
14338
  const batchActionsData = transactions.map(
14361
- (transaction) => transaction.data ? transaction.data : "0x"
14339
+ (transaction) => transaction.data ?? "0x"
14362
14340
  );
14363
14341
  const value = transactions.reduce(
14364
14342
  (acc, transaction) => transaction.value ? acc + BigInt(transaction.value) : acc,
@@ -14457,52 +14435,52 @@ var CheckoutSponsor = class extends Sponsor {
14457
14435
  );
14458
14436
  }
14459
14437
  async lockDeposit() {
14460
- throw new Error(`lockDeposit is not supported on CheckoutSponsor`);
14438
+ throw new Error("lockDeposit is not supported on CheckoutSponsor");
14461
14439
  }
14462
14440
  async unlockDepositAfter(_blocksToWait) {
14463
- throw new Error(`unlockDepositAfter is not supported on CheckoutSponsor`);
14441
+ throw new Error("unlockDepositAfter is not supported on CheckoutSponsor");
14464
14442
  }
14465
14443
  /** True if the specified sponsor is in blacklist mode. **/
14466
14444
  async getListMode(_sponsor, _options = globalThis.globalEnvOption) {
14467
- throw new Error(`getListMode is not supported on CheckoutSponsor`);
14445
+ throw new Error("getListMode is not supported on CheckoutSponsor");
14468
14446
  }
14469
14447
  async setToBlacklistMode() {
14470
- throw new Error(`setToBlacklistMode is not supported on Checkout Sponsor`);
14448
+ throw new Error("setToBlacklistMode is not supported on Checkout Sponsor");
14471
14449
  }
14472
14450
  async setToWhitelistMode() {
14473
- throw new Error(`setToWhitelistMode is not supported on Checkout Sponsor`);
14451
+ throw new Error("setToWhitelistMode is not supported on Checkout Sponsor");
14474
14452
  }
14475
14453
  async batchTransaction(_transactions) {
14476
- throw new Error(`batchTransaction is not supported on Checkout Sponsor`);
14454
+ throw new Error("batchTransaction is not supported on Checkout Sponsor");
14477
14455
  }
14478
14456
  async addSpenderToWhitelist(_spender) {
14479
14457
  throw new Error(
14480
- `addSpenderToWhitelist is not supported on Checkout Sponsor`
14458
+ "addSpenderToWhitelist is not supported on Checkout Sponsor"
14481
14459
  );
14482
14460
  }
14483
14461
  async removeSpenderFromWhitelist(_spender) {
14484
14462
  throw new Error(
14485
- `removeSpenderFromWhitelist is not supported on Checkout Sponsor`
14463
+ "removeSpenderFromWhitelist is not supported on Checkout Sponsor"
14486
14464
  );
14487
14465
  }
14488
14466
  async batchWhitelistSpenders(_spenders, _modes) {
14489
14467
  throw new Error(
14490
- `batchWhitelistSpenders is not supported on Checkout Sponsor`
14468
+ "batchWhitelistSpenders is not supported on Checkout Sponsor"
14491
14469
  );
14492
14470
  }
14493
14471
  async addSpenderToBlacklist(_spender) {
14494
14472
  throw new Error(
14495
- `addSpenderToBlacklist is not supported on Checkout Sponsor`
14473
+ "addSpenderToBlacklist is not supported on Checkout Sponsor"
14496
14474
  );
14497
14475
  }
14498
14476
  async removeSpenderFromBlacklist(_spender) {
14499
14477
  throw new Error(
14500
- `removeSpenderFromBlacklist is not supported on Checkout Sponsor`
14478
+ "removeSpenderFromBlacklist is not supported on Checkout Sponsor"
14501
14479
  );
14502
14480
  }
14503
14481
  async batchBlacklistSpenders(_spenders, _modes) {
14504
14482
  throw new Error(
14505
- `batchBlacklistSpenders is not supported on Checkout Sponsor`
14483
+ "batchBlacklistSpenders is not supported on Checkout Sponsor"
14506
14484
  );
14507
14485
  }
14508
14486
  };
@@ -14622,10 +14600,6 @@ var GaslessSponsor = class extends Sponsor {
14622
14600
  chain
14623
14601
  );
14624
14602
  }
14625
- static async getPaymasterAddress(options = globalThis.globalEnvOption) {
14626
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
14627
- return await chain.getAddress(this.name);
14628
- }
14629
14603
  };
14630
14604
 
14631
14605
  // src/sponsors/TokenSponsor.ts
@@ -14713,7 +14687,7 @@ var TokenSponsor = class extends Sponsor {
14713
14687
  const nonce = await getWalletPermitNonce(walletAddr, chain);
14714
14688
  const client = await chain.getClient();
14715
14689
  const chainId = await client.getChainId();
14716
- const hash = await getPermitHash(
14690
+ const hash = getPermitHash(
14717
14691
  tokenAddress,
14718
14692
  paymasterAddress,
14719
14693
  decAmount,
@@ -15005,10 +14979,6 @@ var TokenSponsor = class extends Sponsor {
15005
14979
  }
15006
14980
  return this.batchTransaction(calldata);
15007
14981
  }
15008
- static async getPaymasterAddress(options = globalThis.globalEnvOption) {
15009
- const chain = await Chain.getChain({ chainIdentifier: options.chain });
15010
- return await chain.getAddress(this.name);
15011
- }
15012
14982
  };
15013
14983
 
15014
14984
  // src/wallet/FunWallet.ts
@@ -15080,21 +15050,20 @@ async function getOnChainGroupData(groupId, chain, walletAddr) {
15080
15050
  memberIds: [],
15081
15051
  threshold: 0
15082
15052
  };
15083
- } else {
15084
- const [storedGroup] = decodeAbiParameters3(
15085
- [
15086
- {
15087
- type: "tuple",
15088
- components: [{ type: "bytes32[]" }, { type: "uint256" }]
15089
- }
15090
- ],
15091
- storedGroupData
15092
- );
15093
- return {
15094
- memberIds: storedGroup[0],
15095
- threshold: Number(storedGroup[1])
15096
- };
15097
15053
  }
15054
+ const [storedGroup] = decodeAbiParameters3(
15055
+ [
15056
+ {
15057
+ type: "tuple",
15058
+ components: [{ type: "bytes32[]" }, { type: "uint256" }]
15059
+ }
15060
+ ],
15061
+ storedGroupData
15062
+ );
15063
+ return {
15064
+ memberIds: storedGroup[0],
15065
+ threshold: Number(storedGroup[1])
15066
+ };
15098
15067
  }
15099
15068
 
15100
15069
  // src/actions/FirstClassActions.ts
@@ -15681,9 +15650,8 @@ var FunWallet = class extends FirstClassActions {
15681
15650
  }
15682
15651
  if (nonce !== void 0 && nonce !== null) {
15683
15652
  return BigInt(nonce);
15684
- } else {
15685
- return BigInt(key << 64n);
15686
15653
  }
15654
+ return BigInt(key << 64n);
15687
15655
  }
15688
15656
  /**
15689
15657
  * Retrieves a list of operations associated with the wallet.
@@ -16450,13 +16418,12 @@ var FunWallet = class extends FirstClassActions {
16450
16418
  params.data,
16451
16419
  feedata
16452
16420
  ]);
16453
- } else {
16454
- return WALLET_CONTRACT_INTERFACE.encodeData("execFromEntryPoint", [
16455
- params.to,
16456
- params.value,
16457
- params.data
16458
- ]);
16459
16421
  }
16422
+ return WALLET_CONTRACT_INTERFACE.encodeData("execFromEntryPoint", [
16423
+ params.to,
16424
+ params.value,
16425
+ params.data
16426
+ ]);
16460
16427
  }
16461
16428
  };
16462
16429
  export {
@@ -16558,7 +16525,6 @@ export {
16558
16525
  getOpHash,
16559
16526
  getPaymasterType,
16560
16527
  getPermitHash,
16561
- getPromiseFromOp,
16562
16528
  getSelectorFromCall,
16563
16529
  getTargetFromCall,
16564
16530
  getTokenAddressBySymbolAndChainId,
@@ -16575,7 +16541,6 @@ export {
16575
16541
  isSignatureMissing,
16576
16542
  isTokenTransferParams,
16577
16543
  isWalletInitOp,
16578
- objectify,
16579
16544
  parseClient,
16580
16545
  parseOptions,
16581
16546
  randomBytes,