@gearbox-protocol/sdk 8.6.2 → 8.6.3
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
|
-
|
|
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 {
|
|
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 === "
|
|
35
|
-
toClaimUSD =
|
|
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
|
|
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:
|
|
76
|
+
args: toClaimUSD ? [toClaimUSD] : [],
|
|
77
|
+
chain: wallet.chain,
|
|
78
|
+
gas: gas * gasMultiplier
|
|
71
79
|
});
|
|
72
|
-
const receipt = await
|
|
80
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
73
81
|
hash
|
|
74
82
|
});
|
|
75
83
|
if (receipt.status === "reverted") {
|
|
@@ -373,7 +373,8 @@ class AccountOpener extends SDKConstruct {
|
|
|
373
373
|
}
|
|
374
374
|
async #claimFromFaucet(claimer, role, amountUSD) {
|
|
375
375
|
await claimFromFaucet({
|
|
376
|
-
|
|
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 {
|
|
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 {
|
|
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 === "
|
|
12
|
-
toClaimUSD =
|
|
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
|
|
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:
|
|
55
|
+
args: toClaimUSD ? [toClaimUSD] : [],
|
|
56
|
+
chain: wallet.chain,
|
|
57
|
+
gas: gas * gasMultiplier
|
|
48
58
|
});
|
|
49
|
-
const receipt = await
|
|
59
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
50
60
|
hash
|
|
51
61
|
});
|
|
52
62
|
if (receipt.status === "reverted") {
|
|
@@ -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
|
-
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
wallet: WalletClient;
|
|
6
6
|
faucet: Address;
|
|
7
7
|
claimer: PrivateKeyAccount;
|
|
8
8
|
role?: string;
|
|
9
|
-
amountUSD
|
|
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>;
|