@gearbox-protocol/sdk 8.6.2 → 8.6.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.
@@ -388,7 +388,8 @@ class AccountOpener extends import_sdk.SDKConstruct {
388
388
  }
389
389
  async #claimFromFaucet(claimer, role, amountUSD) {
390
390
  await (0, import_claimFromFaucet.claimFromFaucet)({
391
- anvil: this.#anvil,
391
+ publicClient: this.#anvil,
392
+ wallet: this.#anvil,
392
393
  faucet: this.faucet,
393
394
  claimer,
394
395
  role,
@@ -26,21 +26,31 @@ var import_actions = require("viem/actions");
26
26
  var import_sdk = require("../sdk/index.js");
27
27
  const faucetAbi = (0, import_viem.parseAbi)([
28
28
  "function minAmountUSD() external view returns (uint256)",
29
+ "function claim() external",
29
30
  "function claim(uint256 amountUSD) external"
30
31
  ]);
31
32
  async function claimFromFaucet(opts) {
32
- const { anvil, faucet, claimer, role, amountUSD, logger } = opts;
33
+ const {
34
+ publicClient,
35
+ wallet,
36
+ faucet,
37
+ claimer,
38
+ role,
39
+ amountUSD,
40
+ logger,
41
+ gasMultiplier = 10n
42
+ } = opts;
33
43
  let toClaimUSD;
34
- if (typeof amountUSD === "function") {
35
- toClaimUSD = await (0, import_actions.readContract)(anvil, {
44
+ if (typeof amountUSD === "bigint") {
45
+ toClaimUSD = amountUSD;
46
+ } else if (typeof amountUSD === "function") {
47
+ toClaimUSD = await (0, import_actions.readContract)(publicClient, {
36
48
  address: faucet,
37
49
  abi: faucetAbi,
38
50
  functionName: "minAmountUSD"
39
51
  });
40
52
  logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
41
53
  toClaimUSD = amountUSD(toClaimUSD);
42
- } else {
43
- toClaimUSD = amountUSD;
44
54
  }
45
55
  if (toClaimUSD === 0n) {
46
56
  logger?.debug("amount is 0, skipping claim");
@@ -48,28 +58,26 @@ async function claimFromFaucet(opts) {
48
58
  }
49
59
  const [usr, amnt] = [
50
60
  [role, claimer.address].filter(Boolean).join(" "),
51
- (0, import_sdk.formatBN)(toClaimUSD, 8)
61
+ toClaimUSD ? (0, import_sdk.formatBN)(toClaimUSD, 8) : "default amount"
52
62
  ];
53
63
  logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
54
- const hash = await anvil.writeContract({
64
+ const gas = await publicClient.estimateContractGas({
65
+ account: claimer,
66
+ address: faucet,
67
+ abi: faucetAbi,
68
+ functionName: "claim",
69
+ args: toClaimUSD ? [toClaimUSD] : []
70
+ });
71
+ const hash = await wallet.writeContract({
55
72
  account: claimer,
56
73
  address: faucet,
57
- abi: [
58
- {
59
- type: "function",
60
- inputs: [
61
- { name: "amountUSD", internalType: "uint256", type: "uint256" }
62
- ],
63
- name: "claim",
64
- outputs: [],
65
- stateMutability: "nonpayable"
66
- }
67
- ],
74
+ abi: faucetAbi,
68
75
  functionName: "claim",
69
- args: [toClaimUSD],
70
- chain: anvil.chain
76
+ args: toClaimUSD ? [toClaimUSD] : [],
77
+ chain: wallet.chain,
78
+ gas: gas * gasMultiplier
71
79
  });
72
- const receipt = await anvil.waitForTransactionReceipt({
80
+ const receipt = await publicClient.waitForTransactionReceipt({
73
81
  hash
74
82
  });
75
83
  if (receipt.status === "reverted") {
@@ -24,12 +24,12 @@ module.exports = __toCommonJS(createCreditAccountService_exports);
24
24
  var import_constants = require("../constants/index.js");
25
25
  var import_CreditAccountsServiceV300 = require("./CreditAccountsServiceV300.js");
26
26
  var import_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
27
- function createCreditAccountService(sdk, version) {
27
+ function createCreditAccountService(sdk, version, options) {
28
28
  if ((0, import_constants.isV300)(version)) {
29
- return new import_CreditAccountsServiceV300.CreditAccountServiceV300(sdk);
29
+ return new import_CreditAccountsServiceV300.CreditAccountServiceV300(sdk, options);
30
30
  }
31
31
  if ((0, import_constants.isV310)(version)) {
32
- return new import_CreditAccountsServiceV310.CreditAccountServiceV310(sdk);
32
+ return new import_CreditAccountsServiceV310.CreditAccountServiceV310(sdk, options);
33
33
  }
34
34
  throw new Error(`Unsupported Credit Account Service version ${version}`);
35
35
  }
@@ -373,7 +373,8 @@ class AccountOpener extends SDKConstruct {
373
373
  }
374
374
  async #claimFromFaucet(claimer, role, amountUSD) {
375
375
  await claimFromFaucet({
376
- anvil: this.#anvil,
376
+ publicClient: this.#anvil,
377
+ wallet: this.#anvil,
377
378
  faucet: this.faucet,
378
379
  claimer,
379
380
  role,
@@ -1,23 +1,35 @@
1
- import { parseAbi } from "viem";
1
+ import {
2
+ parseAbi
3
+ } from "viem";
2
4
  import { readContract } from "viem/actions";
3
5
  import { formatBN } from "../sdk/index.js";
4
6
  const faucetAbi = parseAbi([
5
7
  "function minAmountUSD() external view returns (uint256)",
8
+ "function claim() external",
6
9
  "function claim(uint256 amountUSD) external"
7
10
  ]);
8
11
  async function claimFromFaucet(opts) {
9
- const { anvil, faucet, claimer, role, amountUSD, logger } = opts;
12
+ const {
13
+ publicClient,
14
+ wallet,
15
+ faucet,
16
+ claimer,
17
+ role,
18
+ amountUSD,
19
+ logger,
20
+ gasMultiplier = 10n
21
+ } = opts;
10
22
  let toClaimUSD;
11
- if (typeof amountUSD === "function") {
12
- toClaimUSD = await readContract(anvil, {
23
+ if (typeof amountUSD === "bigint") {
24
+ toClaimUSD = amountUSD;
25
+ } else if (typeof amountUSD === "function") {
26
+ toClaimUSD = await readContract(publicClient, {
13
27
  address: faucet,
14
28
  abi: faucetAbi,
15
29
  functionName: "minAmountUSD"
16
30
  });
17
31
  logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
18
32
  toClaimUSD = amountUSD(toClaimUSD);
19
- } else {
20
- toClaimUSD = amountUSD;
21
33
  }
22
34
  if (toClaimUSD === 0n) {
23
35
  logger?.debug("amount is 0, skipping claim");
@@ -25,28 +37,26 @@ async function claimFromFaucet(opts) {
25
37
  }
26
38
  const [usr, amnt] = [
27
39
  [role, claimer.address].filter(Boolean).join(" "),
28
- formatBN(toClaimUSD, 8)
40
+ toClaimUSD ? formatBN(toClaimUSD, 8) : "default amount"
29
41
  ];
30
42
  logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
31
- const hash = await anvil.writeContract({
43
+ const gas = await publicClient.estimateContractGas({
44
+ account: claimer,
45
+ address: faucet,
46
+ abi: faucetAbi,
47
+ functionName: "claim",
48
+ args: toClaimUSD ? [toClaimUSD] : []
49
+ });
50
+ const hash = await wallet.writeContract({
32
51
  account: claimer,
33
52
  address: faucet,
34
- abi: [
35
- {
36
- type: "function",
37
- inputs: [
38
- { name: "amountUSD", internalType: "uint256", type: "uint256" }
39
- ],
40
- name: "claim",
41
- outputs: [],
42
- stateMutability: "nonpayable"
43
- }
44
- ],
53
+ abi: faucetAbi,
45
54
  functionName: "claim",
46
- args: [toClaimUSD],
47
- chain: anvil.chain
55
+ args: toClaimUSD ? [toClaimUSD] : [],
56
+ chain: wallet.chain,
57
+ gas: gas * gasMultiplier
48
58
  });
49
- const receipt = await anvil.waitForTransactionReceipt({
59
+ const receipt = await publicClient.waitForTransactionReceipt({
50
60
  hash
51
61
  });
52
62
  if (receipt.status === "reverted") {
@@ -1,12 +1,12 @@
1
1
  import { isV300, isV310 } from "../constants/index.js";
2
2
  import { CreditAccountServiceV300 } from "./CreditAccountsServiceV300.js";
3
3
  import { CreditAccountServiceV310 } from "./CreditAccountsServiceV310.js";
4
- function createCreditAccountService(sdk, version) {
4
+ function createCreditAccountService(sdk, version, options) {
5
5
  if (isV300(version)) {
6
- return new CreditAccountServiceV300(sdk);
6
+ return new CreditAccountServiceV300(sdk, options);
7
7
  }
8
8
  if (isV310(version)) {
9
- return new CreditAccountServiceV310(sdk);
9
+ return new CreditAccountServiceV310(sdk, options);
10
10
  }
11
11
  throw new Error(`Unsupported Credit Account Service version ${version}`);
12
12
  }
@@ -1,12 +1,13 @@
1
- import { type Address, type PrivateKeyAccount } from "viem";
1
+ import { type Address, type PrivateKeyAccount, type PublicClient, type WalletClient } from "viem";
2
2
  import { type ILogger } from "../sdk/index.js";
3
- import type { AnvilClient } from "./createAnvilClient.js";
4
3
  interface ClaimFromFaucetOptions {
5
- anvil: AnvilClient;
4
+ publicClient: PublicClient;
5
+ wallet: WalletClient;
6
6
  faucet: Address;
7
7
  claimer: PrivateKeyAccount;
8
8
  role?: string;
9
- amountUSD: bigint | ((minAmountUSD: bigint) => bigint);
9
+ amountUSD?: bigint | ((minAmountUSD: bigint) => bigint);
10
+ gasMultiplier?: bigint;
10
11
  logger?: ILogger;
11
12
  }
12
13
  export declare function claimFromFaucet(opts: ClaimFromFaucetOptions): Promise<void>;
@@ -1,8 +1,9 @@
1
1
  import type { GearboxSDK } from "../GearboxSDK.js";
2
+ import type { CreditAccountServiceOptions } from "./AbstractCreditAccountsService.js";
2
3
  import type { CreditAccountsServiceInstance } from "./types.js";
3
4
  /**
4
5
  * @sdk
5
6
  * @version version of desired credit facade; if no credit facade is considered (you only want to get ca list), either v300 or v310 is fine, because ca compressor has nothing to do with credit facade version
6
7
  * @returns
7
8
  */
8
- export declare function createCreditAccountService(sdk: GearboxSDK, version: number): CreditAccountsServiceInstance;
9
+ export declare function createCreditAccountService(sdk: GearboxSDK, version: number, options?: CreditAccountServiceOptions): CreditAccountsServiceInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.6.2",
3
+ "version": "8.6.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",