@gearbox-protocol/deploy-tools 5.10.12 → 5.11.0
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.mjs +110 -27
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -405570,6 +405570,7 @@ async function evmMineDetailed(client, timestamp) {
|
|
|
405570
405570
|
return void 0;
|
|
405571
405571
|
}
|
|
405572
405572
|
}
|
|
405573
|
+
var DEFAULT_LEVERAGE = 4;
|
|
405573
405574
|
var AccountOpener = class extends SDKConstruct {
|
|
405574
405575
|
#service;
|
|
405575
405576
|
#anvil;
|
|
@@ -405596,7 +405597,14 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405596
405597
|
/**
|
|
405597
405598
|
* Tries to open account with underlying only in each CM
|
|
405598
405599
|
*/
|
|
405599
|
-
async openCreditAccounts(targets) {
|
|
405600
|
+
async openCreditAccounts(targets, depositIntoPools = true) {
|
|
405601
|
+
if (depositIntoPools) {
|
|
405602
|
+
try {
|
|
405603
|
+
await this.#depositIntoPools(targets);
|
|
405604
|
+
} catch (e) {
|
|
405605
|
+
this.#logger?.warn(`failed to deposit into pools: ${e}`);
|
|
405606
|
+
}
|
|
405607
|
+
}
|
|
405600
405608
|
await this.#prepareBorrower(targets);
|
|
405601
405609
|
const toApprove = new AddressMap();
|
|
405602
405610
|
for (const c of targets) {
|
|
@@ -405630,7 +405638,12 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405630
405638
|
return results;
|
|
405631
405639
|
}
|
|
405632
405640
|
async #openAccount(input, index2, total) {
|
|
405633
|
-
const {
|
|
405641
|
+
const {
|
|
405642
|
+
creditManager,
|
|
405643
|
+
collateral,
|
|
405644
|
+
leverage = DEFAULT_LEVERAGE,
|
|
405645
|
+
slippage = 50
|
|
405646
|
+
} = input;
|
|
405634
405647
|
const borrower = await this.#getBorrower();
|
|
405635
405648
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
405636
405649
|
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
@@ -405750,6 +405763,60 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405750
405763
|
owner: this.borrower
|
|
405751
405764
|
});
|
|
405752
405765
|
}
|
|
405766
|
+
async #depositIntoPools(targets, multiplier = 10500n) {
|
|
405767
|
+
this.#logger?.debug("checking and topping up pools if necessary");
|
|
405768
|
+
const minAvailableByPool = {};
|
|
405769
|
+
for (const { leverage = DEFAULT_LEVERAGE, creditManager } of targets) {
|
|
405770
|
+
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
405771
|
+
const { minDebt } = cm.creditFacade;
|
|
405772
|
+
minAvailableByPool[cm.pool] = (minAvailableByPool[cm.pool] ?? 0n) + minDebt * BigInt(leverage - 1) * multiplier / PERCENTAGE_FACTOR;
|
|
405773
|
+
}
|
|
405774
|
+
let totalUSD = 0n;
|
|
405775
|
+
let deposits = [];
|
|
405776
|
+
for (const [p, minAvailable] of Object.entries(minAvailableByPool)) {
|
|
405777
|
+
const market = this.sdk.marketRegister.findByPool(p);
|
|
405778
|
+
const pool = market.pool.pool;
|
|
405779
|
+
let diff = minAvailable - pool.availableLiquidity;
|
|
405780
|
+
diff = diff < 0n ? 0n : diff;
|
|
405781
|
+
const [minS, availableS, diffS] = [
|
|
405782
|
+
minAvailable,
|
|
405783
|
+
pool.availableLiquidity,
|
|
405784
|
+
diff
|
|
405785
|
+
].map((v) => this.sdk.tokensMeta.formatBN(pool.underlying, v));
|
|
405786
|
+
this.#logger?.debug(
|
|
405787
|
+
`Pool ${this.labelAddress(pool.address)} has ${availableS} liquidity, needs ${diffS} more for the minimum of ${minS} ${this.sdk.tokensMeta.symbol(pool.underlying)}`
|
|
405788
|
+
);
|
|
405789
|
+
if (diff > 0n) {
|
|
405790
|
+
deposits.push([pool, diff]);
|
|
405791
|
+
totalUSD += market.priceOracle.convertToUSD(pool.underlying, diff);
|
|
405792
|
+
}
|
|
405793
|
+
}
|
|
405794
|
+
totalUSD = totalUSD * 105n / 100n;
|
|
405795
|
+
this.#logger?.debug(
|
|
405796
|
+
`total USD to claim from faucet: ${formatBN(totalUSD, 8)}`
|
|
405797
|
+
);
|
|
405798
|
+
const depositor = await this.#createAccount();
|
|
405799
|
+
this.#logger?.debug(`created depositor ${depositor.address}`);
|
|
405800
|
+
await this.#claimFromFaucet(depositor, totalUSD);
|
|
405801
|
+
for (const [pool, amount] of deposits) {
|
|
405802
|
+
const poolName = this.sdk.provider.addressLabels.get(pool.address);
|
|
405803
|
+
const amnt = this.sdk.tokensMeta.formatBN(pool.underlying, amount) + " " + this.sdk.tokensMeta.symbol(pool.underlying);
|
|
405804
|
+
this.#logger?.debug(`depositing ${amnt} into pool ${poolName}`);
|
|
405805
|
+
try {
|
|
405806
|
+
await this.#anvil.writeContract({
|
|
405807
|
+
account: depositor,
|
|
405808
|
+
chain: this.#anvil.chain,
|
|
405809
|
+
address: pool.address,
|
|
405810
|
+
abi: iPoolV300Abi,
|
|
405811
|
+
functionName: "deposit",
|
|
405812
|
+
args: [amount, depositor.address]
|
|
405813
|
+
});
|
|
405814
|
+
this.#logger?.debug(`deposited ${amnt} into ${poolName}`);
|
|
405815
|
+
} catch (e) {
|
|
405816
|
+
this.#logger?.warn(`failed to deposit ${amnt} into ${poolName}: ${e}`);
|
|
405817
|
+
}
|
|
405818
|
+
}
|
|
405819
|
+
}
|
|
405753
405820
|
/**
|
|
405754
405821
|
* Creates borrower wallet,
|
|
405755
405822
|
* Sets ETH balance,
|
|
@@ -405775,9 +405842,18 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405775
405842
|
}
|
|
405776
405843
|
}
|
|
405777
405844
|
claimUSD = claimUSD * 11n / 10n;
|
|
405778
|
-
this.#
|
|
405779
|
-
|
|
405780
|
-
|
|
405845
|
+
await this.#claimFromFaucet(borrower, claimUSD);
|
|
405846
|
+
for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
|
|
405847
|
+
await this.#mintDegenNft(degenNFT, borrower.address, amount);
|
|
405848
|
+
}
|
|
405849
|
+
this.#logger?.debug("prepared borrower");
|
|
405850
|
+
return borrower;
|
|
405851
|
+
}
|
|
405852
|
+
async #claimFromFaucet(claimer, amountUSD) {
|
|
405853
|
+
const [usr, amnt] = [claimer.address, formatBN(amountUSD, 8)];
|
|
405854
|
+
this.#logger?.debug(`account ${usr} claiming ${amnt} USD from faucet`);
|
|
405855
|
+
const hash2 = await this.#anvil.writeContract({
|
|
405856
|
+
account: claimer,
|
|
405781
405857
|
address: this.#faucet,
|
|
405782
405858
|
abi: [
|
|
405783
405859
|
{
|
|
@@ -405791,25 +405867,20 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405791
405867
|
}
|
|
405792
405868
|
],
|
|
405793
405869
|
functionName: "claim",
|
|
405794
|
-
args: [
|
|
405870
|
+
args: [amountUSD],
|
|
405795
405871
|
chain: this.#anvil.chain
|
|
405796
405872
|
});
|
|
405797
|
-
|
|
405873
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({
|
|
405798
405874
|
hash: hash2
|
|
405799
405875
|
});
|
|
405800
405876
|
if (receipt.status === "reverted") {
|
|
405801
405877
|
throw new Error(
|
|
405802
|
-
`
|
|
405878
|
+
`account ${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
|
|
405803
405879
|
);
|
|
405804
405880
|
}
|
|
405805
405881
|
this.#logger?.debug(
|
|
405806
|
-
`
|
|
405882
|
+
`account ${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
|
|
405807
405883
|
);
|
|
405808
|
-
for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
|
|
405809
|
-
await this.#mintDegenNft(degenNFT, borrower.address, amount);
|
|
405810
|
-
}
|
|
405811
|
-
this.#logger?.debug("prepared borrower");
|
|
405812
|
-
return borrower;
|
|
405813
405884
|
}
|
|
405814
405885
|
async #approve(token, cm) {
|
|
405815
405886
|
const borrower = await this.#getBorrower();
|
|
@@ -405904,15 +405975,19 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405904
405975
|
}
|
|
405905
405976
|
async #getBorrower() {
|
|
405906
405977
|
if (!this.#borrower) {
|
|
405907
|
-
this.#borrower =
|
|
405908
|
-
await this.#anvil.setBalance({
|
|
405909
|
-
address: this.#borrower.address,
|
|
405910
|
-
value: parseEther("100")
|
|
405911
|
-
});
|
|
405978
|
+
this.#borrower = await this.#createAccount();
|
|
405912
405979
|
this.#logger?.info(`created borrower ${this.#borrower.address}`);
|
|
405913
405980
|
}
|
|
405914
405981
|
return this.#borrower;
|
|
405915
405982
|
}
|
|
405983
|
+
async #createAccount() {
|
|
405984
|
+
const acc = privateKeyToAccount(generatePrivateKey());
|
|
405985
|
+
await this.#anvil.setBalance({
|
|
405986
|
+
address: acc.address,
|
|
405987
|
+
value: parseEther("100")
|
|
405988
|
+
});
|
|
405989
|
+
return acc;
|
|
405990
|
+
}
|
|
405916
405991
|
#getCollateralQuota(cm, collateral, amount, debt) {
|
|
405917
405992
|
const {
|
|
405918
405993
|
underlying,
|
|
@@ -413903,6 +413978,8 @@ function openAccounts() {
|
|
|
413903
413978
|
"--address-provider <address>",
|
|
413904
413979
|
"new address provider address"
|
|
413905
413980
|
).env("ADDRESS_PROVIDER")
|
|
413981
|
+
).addOption(
|
|
413982
|
+
new Option("--cast-bin <path>", "cast binary path").env("CAST_BIN")
|
|
413906
413983
|
).addOption(
|
|
413907
413984
|
new Option("--shared-dir <dir>", "dir to put output files").env(
|
|
413908
413985
|
"SHARED_DIR"
|
|
@@ -413917,7 +413994,8 @@ function openAccounts() {
|
|
|
413917
413994
|
marketConfigurators,
|
|
413918
413995
|
anvilUrl = "http://127.0.0.1:8545",
|
|
413919
413996
|
sharedDir = ".",
|
|
413920
|
-
nexo
|
|
413997
|
+
nexo,
|
|
413998
|
+
castBin = "cast"
|
|
413921
413999
|
} = opts;
|
|
413922
414000
|
await mkdir2(path9.resolve(sharedDir, "deploy-state"), { recursive: true });
|
|
413923
414001
|
const sdkExample2 = new SDKExample(log_default);
|
|
@@ -414023,7 +414101,7 @@ function openAccounts() {
|
|
|
414023
414101
|
// DAI
|
|
414024
414102
|
});
|
|
414025
414103
|
}
|
|
414026
|
-
const results = await accountOpener.openCreditAccounts(accounts);
|
|
414104
|
+
const results = await accountOpener.openCreditAccounts(accounts, true);
|
|
414027
414105
|
const destDir = path9.resolve(sharedDir, "open-accounts");
|
|
414028
414106
|
await mkdir2(destDir, { recursive: true });
|
|
414029
414107
|
await writeFile6(
|
|
@@ -414038,7 +414116,8 @@ function openAccounts() {
|
|
|
414038
414116
|
await runCast(r, i + 1, {
|
|
414039
414117
|
anvilUrl,
|
|
414040
414118
|
destDir,
|
|
414041
|
-
privateKey: borrowerKey
|
|
414119
|
+
privateKey: borrowerKey,
|
|
414120
|
+
castBin
|
|
414042
414121
|
});
|
|
414043
414122
|
}
|
|
414044
414123
|
}
|
|
@@ -414050,7 +414129,7 @@ function openAccounts() {
|
|
|
414050
414129
|
}
|
|
414051
414130
|
async function runCast(result, index2, opts) {
|
|
414052
414131
|
const { txHash, rawTx } = result;
|
|
414053
|
-
const { anvilUrl, destDir, privateKey } = opts;
|
|
414132
|
+
const { anvilUrl, destDir, privateKey, castBin = "cast" } = opts;
|
|
414054
414133
|
if (!txHash && !rawTx) {
|
|
414055
414134
|
return;
|
|
414056
414135
|
}
|
|
@@ -414066,10 +414145,14 @@ async function runCast(result, index2, opts) {
|
|
|
414066
414145
|
rawTx.callData
|
|
414067
414146
|
];
|
|
414068
414147
|
const argsStr = args.join(" ").replace(privateKey, "<pk>");
|
|
414069
|
-
log_default.debug(`running
|
|
414148
|
+
log_default.debug(`running ${castBin} ${argsStr}`);
|
|
414070
414149
|
try {
|
|
414071
414150
|
const traceFile = path9.resolve(destDir, `${id}.trace`);
|
|
414072
|
-
const cast = spawnSync3(
|
|
414151
|
+
const cast = spawnSync3(castBin, args, { encoding: "utf-8", stdio: "pipe" });
|
|
414152
|
+
if (cast.error) {
|
|
414153
|
+
log_default.warn(`failed to run cast: ${cast.error}`);
|
|
414154
|
+
return;
|
|
414155
|
+
}
|
|
414073
414156
|
await writeFile6(traceFile, cast.output.join(""), "utf-8");
|
|
414074
414157
|
log_default.debug(`saved trace file: ${traceFile}`);
|
|
414075
414158
|
} catch (e) {
|
|
@@ -414124,7 +414207,7 @@ function getRenderer(opts) {
|
|
|
414124
414207
|
var package_default = {
|
|
414125
414208
|
name: "@gearbox-protocol/deploy-tools",
|
|
414126
414209
|
description: "Gearbox deploy tools",
|
|
414127
|
-
version: "5.
|
|
414210
|
+
version: "5.11.0",
|
|
414128
414211
|
homepage: "https://gearbox.fi",
|
|
414129
414212
|
keywords: [
|
|
414130
414213
|
"gearbox"
|
|
@@ -414167,7 +414250,7 @@ var package_default = {
|
|
|
414167
414250
|
"@gearbox-protocol/deploy-tools-node": "0.0.0",
|
|
414168
414251
|
"@gearbox-protocol/deploy-tools-shared": "0.0.0",
|
|
414169
414252
|
"@gearbox-protocol/deploy-tools-types": "0.0.0",
|
|
414170
|
-
"@gearbox-protocol/sdk": "3.0.0-vfour.
|
|
414253
|
+
"@gearbox-protocol/sdk": "3.0.0-vfour.243",
|
|
414171
414254
|
"@gearbox-protocol/sdk-gov": "^2.34.1",
|
|
414172
414255
|
"@types/lodash-es": "^4.17.12",
|
|
414173
414256
|
"@types/node": "^22.13.1",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/deploy-tools",
|
|
3
3
|
"description": "Gearbox deploy tools",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.11.0",
|
|
5
5
|
"homepage": "https://gearbox.fi",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"gearbox"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@gearbox-protocol/deploy-tools-node": "0.0.0",
|
|
45
45
|
"@gearbox-protocol/deploy-tools-shared": "0.0.0",
|
|
46
46
|
"@gearbox-protocol/deploy-tools-types": "0.0.0",
|
|
47
|
-
"@gearbox-protocol/sdk": "3.0.0-vfour.
|
|
47
|
+
"@gearbox-protocol/sdk": "3.0.0-vfour.243",
|
|
48
48
|
"@gearbox-protocol/sdk-gov": "^2.34.1",
|
|
49
49
|
"@types/lodash-es": "^4.17.12",
|
|
50
50
|
"@types/node": "^22.13.1",
|