@gearbox-protocol/sdk 8.6.1 → 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.
- package/dist/cjs/dev/AccountOpener.js +11 -36
- package/dist/cjs/dev/claimFromFaucet.js +95 -0
- package/dist/cjs/dev/index.js +2 -0
- package/dist/esm/dev/AccountOpener.js +11 -36
- package/dist/esm/dev/claimFromFaucet.js +73 -0
- package/dist/esm/dev/index.js +1 -0
- package/dist/types/dev/claimFromFaucet.d.ts +14 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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,
|
|
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 (
|
|
80
|
+
if (claimFromFaucet2) {
|
|
80
81
|
await this.#prepareBorrower(targets);
|
|
81
82
|
}
|
|
82
83
|
const toApprove = new import_sdk.AddressMap();
|
|
@@ -386,41 +387,15 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
386
387
|
return borrower;
|
|
387
388
|
}
|
|
388
389
|
async #claimFromFaucet(claimer, role, amountUSD) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
this
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
+
publicClient: this.#anvil,
|
|
392
|
+
wallet: this.#anvil,
|
|
393
|
+
faucet: this.faucet,
|
|
394
|
+
claimer,
|
|
395
|
+
role,
|
|
396
|
+
amountUSD,
|
|
397
|
+
logger: this.#logger
|
|
415
398
|
});
|
|
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
399
|
}
|
|
425
400
|
async #approve(token, cm) {
|
|
426
401
|
const borrower = await this.#getBorrower();
|
|
@@ -0,0 +1,95 @@
|
|
|
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() external",
|
|
30
|
+
"function claim(uint256 amountUSD) external"
|
|
31
|
+
]);
|
|
32
|
+
async function claimFromFaucet(opts) {
|
|
33
|
+
const {
|
|
34
|
+
publicClient,
|
|
35
|
+
wallet,
|
|
36
|
+
faucet,
|
|
37
|
+
claimer,
|
|
38
|
+
role,
|
|
39
|
+
amountUSD,
|
|
40
|
+
logger,
|
|
41
|
+
gasMultiplier = 10n
|
|
42
|
+
} = opts;
|
|
43
|
+
let toClaimUSD;
|
|
44
|
+
if (typeof amountUSD === "bigint") {
|
|
45
|
+
toClaimUSD = amountUSD;
|
|
46
|
+
} else if (typeof amountUSD === "function") {
|
|
47
|
+
toClaimUSD = await (0, import_actions.readContract)(publicClient, {
|
|
48
|
+
address: faucet,
|
|
49
|
+
abi: faucetAbi,
|
|
50
|
+
functionName: "minAmountUSD"
|
|
51
|
+
});
|
|
52
|
+
logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
|
|
53
|
+
toClaimUSD = amountUSD(toClaimUSD);
|
|
54
|
+
}
|
|
55
|
+
if (toClaimUSD === 0n) {
|
|
56
|
+
logger?.debug("amount is 0, skipping claim");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const [usr, amnt] = [
|
|
60
|
+
[role, claimer.address].filter(Boolean).join(" "),
|
|
61
|
+
toClaimUSD ? (0, import_sdk.formatBN)(toClaimUSD, 8) : "default amount"
|
|
62
|
+
];
|
|
63
|
+
logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
|
|
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({
|
|
72
|
+
account: claimer,
|
|
73
|
+
address: faucet,
|
|
74
|
+
abi: faucetAbi,
|
|
75
|
+
functionName: "claim",
|
|
76
|
+
args: toClaimUSD ? [toClaimUSD] : [],
|
|
77
|
+
chain: wallet.chain,
|
|
78
|
+
gas: gas * gasMultiplier
|
|
79
|
+
});
|
|
80
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
81
|
+
hash
|
|
82
|
+
});
|
|
83
|
+
if (receipt.status === "reverted") {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
logger?.debug(
|
|
89
|
+
`${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
claimFromFaucet
|
|
95
|
+
});
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -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,
|
|
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 (
|
|
65
|
+
if (claimFromFaucet2) {
|
|
65
66
|
await this.#prepareBorrower(targets);
|
|
66
67
|
}
|
|
67
68
|
const toApprove = new AddressMap();
|
|
@@ -371,41 +372,15 @@ class AccountOpener extends SDKConstruct {
|
|
|
371
372
|
return borrower;
|
|
372
373
|
}
|
|
373
374
|
async #claimFromFaucet(claimer, role, amountUSD) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
this
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
+
publicClient: this.#anvil,
|
|
377
|
+
wallet: this.#anvil,
|
|
378
|
+
faucet: this.faucet,
|
|
379
|
+
claimer,
|
|
380
|
+
role,
|
|
381
|
+
amountUSD,
|
|
382
|
+
logger: this.#logger
|
|
400
383
|
});
|
|
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
384
|
}
|
|
410
385
|
async #approve(token, cm) {
|
|
411
386
|
const borrower = await this.#getBorrower();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAbi
|
|
3
|
+
} from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { formatBN } from "../sdk/index.js";
|
|
6
|
+
const faucetAbi = parseAbi([
|
|
7
|
+
"function minAmountUSD() external view returns (uint256)",
|
|
8
|
+
"function claim() external",
|
|
9
|
+
"function claim(uint256 amountUSD) external"
|
|
10
|
+
]);
|
|
11
|
+
async function claimFromFaucet(opts) {
|
|
12
|
+
const {
|
|
13
|
+
publicClient,
|
|
14
|
+
wallet,
|
|
15
|
+
faucet,
|
|
16
|
+
claimer,
|
|
17
|
+
role,
|
|
18
|
+
amountUSD,
|
|
19
|
+
logger,
|
|
20
|
+
gasMultiplier = 10n
|
|
21
|
+
} = opts;
|
|
22
|
+
let toClaimUSD;
|
|
23
|
+
if (typeof amountUSD === "bigint") {
|
|
24
|
+
toClaimUSD = amountUSD;
|
|
25
|
+
} else if (typeof amountUSD === "function") {
|
|
26
|
+
toClaimUSD = await readContract(publicClient, {
|
|
27
|
+
address: faucet,
|
|
28
|
+
abi: faucetAbi,
|
|
29
|
+
functionName: "minAmountUSD"
|
|
30
|
+
});
|
|
31
|
+
logger?.debug(`faucet min amount USD: ${toClaimUSD}`);
|
|
32
|
+
toClaimUSD = amountUSD(toClaimUSD);
|
|
33
|
+
}
|
|
34
|
+
if (toClaimUSD === 0n) {
|
|
35
|
+
logger?.debug("amount is 0, skipping claim");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const [usr, amnt] = [
|
|
39
|
+
[role, claimer.address].filter(Boolean).join(" "),
|
|
40
|
+
toClaimUSD ? formatBN(toClaimUSD, 8) : "default amount"
|
|
41
|
+
];
|
|
42
|
+
logger?.debug(`${usr} claiming ${amnt} USD from faucet`);
|
|
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({
|
|
51
|
+
account: claimer,
|
|
52
|
+
address: faucet,
|
|
53
|
+
abi: faucetAbi,
|
|
54
|
+
functionName: "claim",
|
|
55
|
+
args: toClaimUSD ? [toClaimUSD] : [],
|
|
56
|
+
chain: wallet.chain,
|
|
57
|
+
gas: gas * gasMultiplier
|
|
58
|
+
});
|
|
59
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
60
|
+
hash
|
|
61
|
+
});
|
|
62
|
+
if (receipt.status === "reverted") {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
logger?.debug(
|
|
68
|
+
`${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
claimFromFaucet
|
|
73
|
+
};
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -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,14 @@
|
|
|
1
|
+
import { type Address, type PrivateKeyAccount, type PublicClient, type WalletClient } from "viem";
|
|
2
|
+
import { type ILogger } from "../sdk/index.js";
|
|
3
|
+
interface ClaimFromFaucetOptions {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
wallet: WalletClient;
|
|
6
|
+
faucet: Address;
|
|
7
|
+
claimer: PrivateKeyAccount;
|
|
8
|
+
role?: string;
|
|
9
|
+
amountUSD?: bigint | ((minAmountUSD: bigint) => bigint);
|
|
10
|
+
gasMultiplier?: bigint;
|
|
11
|
+
logger?: ILogger;
|
|
12
|
+
}
|
|
13
|
+
export declare function claimFromFaucet(opts: ClaimFromFaucetOptions): Promise<void>;
|
|
14
|
+
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";
|