@gearbox-protocol/sdk 8.6.1 → 8.6.2

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.
@@ -28,6 +28,7 @@ var import_iERC20 = require("../abi/iERC20.js");
28
28
  var import_v300 = require("../abi/v300.js");
29
29
  var import_sdk = require("../sdk/index.js");
30
30
  var import_abi = require("./abi.js");
31
+ var import_claimFromFaucet = require("./claimFromFaucet.js");
31
32
  var import_createAnvilClient = require("./createAnvilClient.js");
32
33
  class OpenTxRevertedError extends import_viem.BaseError {
33
34
  txHash;
@@ -68,7 +69,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
68
69
  /**
69
70
  * Tries to open account with underlying only in each CM
70
71
  */
71
- async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet = true) {
72
+ async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet2 = true) {
72
73
  if (depositIntoPools) {
73
74
  try {
74
75
  await this.#depositIntoPools(targets);
@@ -76,7 +77,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
76
77
  this.#logger?.warn(`failed to deposit into pools: ${e}`);
77
78
  }
78
79
  }
79
- if (claimFromFaucet) {
80
+ if (claimFromFaucet2) {
80
81
  await this.#prepareBorrower(targets);
81
82
  }
82
83
  const toApprove = new import_sdk.AddressMap();
@@ -386,41 +387,14 @@ class AccountOpener extends import_sdk.SDKConstruct {
386
387
  return borrower;
387
388
  }
388
389
  async #claimFromFaucet(claimer, role, amountUSD) {
389
- const [usr, amnt] = [claimer.address, (0, import_sdk.formatBN)(amountUSD, 8)];
390
- this.#logger?.debug(`${role} ${usr} claiming ${amnt} USD from faucet`);
391
- if (amountUSD === 0n) {
392
- this.#logger?.debug("amount is 0, skipping claim");
393
- return;
394
- }
395
- const hash = await this.#anvil.writeContract({
396
- account: claimer,
397
- address: this.faucet,
398
- abi: [
399
- {
400
- type: "function",
401
- inputs: [
402
- { name: "amountUSD", internalType: "uint256", type: "uint256" }
403
- ],
404
- name: "claim",
405
- outputs: [],
406
- stateMutability: "nonpayable"
407
- }
408
- ],
409
- functionName: "claim",
410
- args: [amountUSD],
411
- chain: this.#anvil.chain
412
- });
413
- const receipt = await this.#anvil.waitForTransactionReceipt({
414
- hash
390
+ await (0, import_claimFromFaucet.claimFromFaucet)({
391
+ anvil: this.#anvil,
392
+ faucet: this.faucet,
393
+ claimer,
394
+ role,
395
+ amountUSD,
396
+ logger: this.#logger
415
397
  });
416
- if (receipt.status === "reverted") {
417
- throw new Error(
418
- `${role} ${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
419
- );
420
- }
421
- this.#logger?.debug(
422
- `${role} ${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
423
- );
424
398
  }
425
399
  async #approve(token, cm) {
426
400
  const borrower = await this.#getBorrower();
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var claimFromFaucet_exports = {};
20
+ __export(claimFromFaucet_exports, {
21
+ claimFromFaucet: () => claimFromFaucet
22
+ });
23
+ module.exports = __toCommonJS(claimFromFaucet_exports);
24
+ var import_viem = require("viem");
25
+ var import_actions = require("viem/actions");
26
+ var import_sdk = require("../sdk/index.js");
27
+ const faucetAbi = (0, import_viem.parseAbi)([
28
+ "function minAmountUSD() external view returns (uint256)",
29
+ "function claim(uint256 amountUSD) external"
30
+ ]);
31
+ async function claimFromFaucet(opts) {
32
+ const { anvil, faucet, claimer, role, amountUSD, logger } = opts;
33
+ let toClaimUSD;
34
+ if (typeof amountUSD === "function") {
35
+ toClaimUSD = await (0, import_actions.readContract)(anvil, {
36
+ address: faucet,
37
+ abi: faucetAbi,
38
+ functionName: "minAmountUSD"
39
+ });
40
+ logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
41
+ toClaimUSD = amountUSD(toClaimUSD);
42
+ } else {
43
+ toClaimUSD = amountUSD;
44
+ }
45
+ if (toClaimUSD === 0n) {
46
+ logger?.debug("amount is 0, skipping claim");
47
+ return;
48
+ }
49
+ const [usr, amnt] = [
50
+ [role, claimer.address].filter(Boolean).join(" "),
51
+ (0, import_sdk.formatBN)(toClaimUSD, 8)
52
+ ];
53
+ logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
54
+ const hash = await anvil.writeContract({
55
+ account: claimer,
56
+ 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
+ ],
68
+ functionName: "claim",
69
+ args: [toClaimUSD],
70
+ chain: anvil.chain
71
+ });
72
+ const receipt = await anvil.waitForTransactionReceipt({
73
+ hash
74
+ });
75
+ if (receipt.status === "reverted") {
76
+ throw new Error(
77
+ `${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
78
+ );
79
+ }
80
+ logger?.debug(
81
+ `${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
82
+ );
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ claimFromFaucet
87
+ });
@@ -18,6 +18,7 @@ module.exports = __toCommonJS(dev_exports);
18
18
  __reExport(dev_exports, require("./AccountOpener.js"), module.exports);
19
19
  __reExport(dev_exports, require("./CachedStateSubscriber.js"), module.exports);
20
20
  __reExport(dev_exports, require("./calcLiquidatableLTs.js"), module.exports);
21
+ __reExport(dev_exports, require("./claimFromFaucet.js"), module.exports);
21
22
  __reExport(dev_exports, require("./create2.js"), module.exports);
22
23
  __reExport(dev_exports, require("./createAnvilClient.js"), module.exports);
23
24
  __reExport(dev_exports, require("./createTransport.js"), module.exports);
@@ -29,6 +30,7 @@ __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
29
30
  ...require("./AccountOpener.js"),
30
31
  ...require("./CachedStateSubscriber.js"),
31
32
  ...require("./calcLiquidatableLTs.js"),
33
+ ...require("./claimFromFaucet.js"),
32
34
  ...require("./create2.js"),
33
35
  ...require("./createAnvilClient.js"),
34
36
  ...require("./createTransport.js"),
@@ -13,6 +13,7 @@ import {
13
13
  sendRawTx
14
14
  } from "../sdk/index.js";
15
15
  import { iDegenNftv2Abi } from "./abi.js";
16
+ import { claimFromFaucet } from "./claimFromFaucet.js";
16
17
  import { createAnvilClient } from "./createAnvilClient.js";
17
18
  class OpenTxRevertedError extends BaseError {
18
19
  txHash;
@@ -53,7 +54,7 @@ class AccountOpener extends SDKConstruct {
53
54
  /**
54
55
  * Tries to open account with underlying only in each CM
55
56
  */
56
- async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet = true) {
57
+ async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet2 = true) {
57
58
  if (depositIntoPools) {
58
59
  try {
59
60
  await this.#depositIntoPools(targets);
@@ -61,7 +62,7 @@ class AccountOpener extends SDKConstruct {
61
62
  this.#logger?.warn(`failed to deposit into pools: ${e}`);
62
63
  }
63
64
  }
64
- if (claimFromFaucet) {
65
+ if (claimFromFaucet2) {
65
66
  await this.#prepareBorrower(targets);
66
67
  }
67
68
  const toApprove = new AddressMap();
@@ -371,41 +372,14 @@ class AccountOpener extends SDKConstruct {
371
372
  return borrower;
372
373
  }
373
374
  async #claimFromFaucet(claimer, role, amountUSD) {
374
- const [usr, amnt] = [claimer.address, formatBN(amountUSD, 8)];
375
- this.#logger?.debug(`${role} ${usr} claiming ${amnt} USD from faucet`);
376
- if (amountUSD === 0n) {
377
- this.#logger?.debug("amount is 0, skipping claim");
378
- return;
379
- }
380
- const hash = await this.#anvil.writeContract({
381
- account: claimer,
382
- address: this.faucet,
383
- abi: [
384
- {
385
- type: "function",
386
- inputs: [
387
- { name: "amountUSD", internalType: "uint256", type: "uint256" }
388
- ],
389
- name: "claim",
390
- outputs: [],
391
- stateMutability: "nonpayable"
392
- }
393
- ],
394
- functionName: "claim",
395
- args: [amountUSD],
396
- chain: this.#anvil.chain
397
- });
398
- const receipt = await this.#anvil.waitForTransactionReceipt({
399
- hash
375
+ await claimFromFaucet({
376
+ anvil: this.#anvil,
377
+ faucet: this.faucet,
378
+ claimer,
379
+ role,
380
+ amountUSD,
381
+ logger: this.#logger
400
382
  });
401
- if (receipt.status === "reverted") {
402
- throw new Error(
403
- `${role} ${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
404
- );
405
- }
406
- this.#logger?.debug(
407
- `${role} ${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
408
- );
409
383
  }
410
384
  async #approve(token, cm) {
411
385
  const borrower = await this.#getBorrower();
@@ -0,0 +1,63 @@
1
+ import { parseAbi } from "viem";
2
+ import { readContract } from "viem/actions";
3
+ import { formatBN } from "../sdk/index.js";
4
+ const faucetAbi = parseAbi([
5
+ "function minAmountUSD() external view returns (uint256)",
6
+ "function claim(uint256 amountUSD) external"
7
+ ]);
8
+ async function claimFromFaucet(opts) {
9
+ const { anvil, faucet, claimer, role, amountUSD, logger } = opts;
10
+ let toClaimUSD;
11
+ if (typeof amountUSD === "function") {
12
+ toClaimUSD = await readContract(anvil, {
13
+ address: faucet,
14
+ abi: faucetAbi,
15
+ functionName: "minAmountUSD"
16
+ });
17
+ logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
18
+ toClaimUSD = amountUSD(toClaimUSD);
19
+ } else {
20
+ toClaimUSD = amountUSD;
21
+ }
22
+ if (toClaimUSD === 0n) {
23
+ logger?.debug("amount is 0, skipping claim");
24
+ return;
25
+ }
26
+ const [usr, amnt] = [
27
+ [role, claimer.address].filter(Boolean).join(" "),
28
+ formatBN(toClaimUSD, 8)
29
+ ];
30
+ logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
31
+ const hash = await anvil.writeContract({
32
+ account: claimer,
33
+ 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
+ ],
45
+ functionName: "claim",
46
+ args: [toClaimUSD],
47
+ chain: anvil.chain
48
+ });
49
+ const receipt = await anvil.waitForTransactionReceipt({
50
+ hash
51
+ });
52
+ if (receipt.status === "reverted") {
53
+ throw new Error(
54
+ `${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
55
+ );
56
+ }
57
+ logger?.debug(
58
+ `${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
59
+ );
60
+ }
61
+ export {
62
+ claimFromFaucet
63
+ };
@@ -1,6 +1,7 @@
1
1
  export * from "./AccountOpener.js";
2
2
  export * from "./CachedStateSubscriber.js";
3
3
  export * from "./calcLiquidatableLTs.js";
4
+ export * from "./claimFromFaucet.js";
4
5
  export * from "./create2.js";
5
6
  export * from "./createAnvilClient.js";
6
7
  export * from "./createTransport.js";
@@ -0,0 +1,13 @@
1
+ import { type Address, type PrivateKeyAccount } from "viem";
2
+ import { type ILogger } from "../sdk/index.js";
3
+ import type { AnvilClient } from "./createAnvilClient.js";
4
+ interface ClaimFromFaucetOptions {
5
+ anvil: AnvilClient;
6
+ faucet: Address;
7
+ claimer: PrivateKeyAccount;
8
+ role?: string;
9
+ amountUSD: bigint | ((minAmountUSD: bigint) => bigint);
10
+ logger?: ILogger;
11
+ }
12
+ export declare function claimFromFaucet(opts: ClaimFromFaucetOptions): Promise<void>;
13
+ export {};
@@ -1,6 +1,7 @@
1
1
  export * from "./AccountOpener.js";
2
2
  export * from "./CachedStateSubscriber.js";
3
3
  export * from "./calcLiquidatableLTs.js";
4
+ export * from "./claimFromFaucet.js";
4
5
  export * from "./create2.js";
5
6
  export * from "./createAnvilClient.js";
6
7
  export * from "./createTransport.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.6.1",
3
+ "version": "8.6.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",