@gearbox-protocol/deploy-tools 5.24.30 → 5.24.32
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 +333 -182
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -369150,9 +369150,7 @@ var chains = {
|
|
|
369150
369150
|
...mainnet,
|
|
369151
369151
|
network: "Mainnet",
|
|
369152
369152
|
defaultMarketConfigurators: {
|
|
369153
|
-
"0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
|
|
369154
|
-
},
|
|
369155
|
-
testMarketConfigurators: {
|
|
369153
|
+
"0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs",
|
|
369156
369154
|
"0x4d427D418342d8CE89a7634c3a402851978B680A": "K3"
|
|
369157
369155
|
},
|
|
369158
369156
|
isPublic: true,
|
|
@@ -370132,7 +370130,8 @@ var iGearboxRouterV310Abi = [
|
|
|
370132
370130
|
{ name: "token", type: "address", internalType: "address" },
|
|
370133
370131
|
{ name: "balance", type: "uint256", internalType: "uint256" },
|
|
370134
370132
|
{ name: "leftoverBalance", type: "uint256", internalType: "uint256" },
|
|
370135
|
-
{ name: "numSplits", type: "uint256", internalType: "uint256" }
|
|
370133
|
+
{ name: "numSplits", type: "uint256", internalType: "uint256" },
|
|
370134
|
+
{ name: "claimRewards", type: "bool", internalType: "bool" }
|
|
370136
370135
|
]
|
|
370137
370136
|
}
|
|
370138
370137
|
],
|
|
@@ -370240,7 +370239,8 @@ var iGearboxRouterV310Abi = [
|
|
|
370240
370239
|
{ name: "token", type: "address", internalType: "address" },
|
|
370241
370240
|
{ name: "balance", type: "uint256", internalType: "uint256" },
|
|
370242
370241
|
{ name: "leftoverBalance", type: "uint256", internalType: "uint256" },
|
|
370243
|
-
{ name: "numSplits", type: "uint256", internalType: "uint256" }
|
|
370242
|
+
{ name: "numSplits", type: "uint256", internalType: "uint256" },
|
|
370243
|
+
{ name: "claimRewards", type: "bool", internalType: "bool" }
|
|
370244
370244
|
]
|
|
370245
370245
|
}
|
|
370246
370246
|
],
|
|
@@ -377125,7 +377125,7 @@ var BaseContract = class extends SDKConstruct {
|
|
|
377125
377125
|
constructor(sdk, args) {
|
|
377126
377126
|
super(sdk);
|
|
377127
377127
|
this.abi = args.abi;
|
|
377128
|
-
this.#address = args.addr;
|
|
377128
|
+
this.#address = getAddress(args.addr);
|
|
377129
377129
|
this.contract = getContract({
|
|
377130
377130
|
address: this.address,
|
|
377131
377131
|
// add exceptions for better error decoding
|
|
@@ -377150,11 +377150,7 @@ var BaseContract = class extends SDKConstruct {
|
|
|
377150
377150
|
if (this.#address !== ADDRESS_0X0) {
|
|
377151
377151
|
throw new Error(`Address can't be changed, currently: ${this.#address}`);
|
|
377152
377152
|
}
|
|
377153
|
-
this.#address = address;
|
|
377154
|
-
this.addressLabels.set(address, this.#name);
|
|
377155
|
-
}
|
|
377156
|
-
test_setAddress(address) {
|
|
377157
|
-
this.#address = address;
|
|
377153
|
+
this.#address = getAddress(address);
|
|
377158
377154
|
this.addressLabels.set(address, this.#name);
|
|
377159
377155
|
}
|
|
377160
377156
|
get name() {
|
|
@@ -384273,7 +384269,7 @@ var AbstractRouterContract = class extends BaseContract {
|
|
|
384273
384269
|
removeHook = this.hooks.removeHook.bind(this.hooks);
|
|
384274
384270
|
getExpectedAndLeftover(ca, cm, balances) {
|
|
384275
384271
|
const b = balances || this.getDefaultExpectedAndLeftover(ca);
|
|
384276
|
-
const { leftoverBalances, expectedBalances } = b;
|
|
384272
|
+
const { leftoverBalances, expectedBalances, tokensToClaim } = b;
|
|
384277
384273
|
const expected = new AddressMap();
|
|
384278
384274
|
const leftover = new AddressMap();
|
|
384279
384275
|
for (const token of cm.collateralTokens) {
|
|
@@ -384284,7 +384280,11 @@ var AbstractRouterContract = class extends BaseContract {
|
|
|
384284
384280
|
balance: leftoverBalances.get(token)?.balance || 1n
|
|
384285
384281
|
});
|
|
384286
384282
|
}
|
|
384287
|
-
return {
|
|
384283
|
+
return {
|
|
384284
|
+
expectedBalances: expected,
|
|
384285
|
+
leftoverBalances: leftover,
|
|
384286
|
+
tokensToClaim
|
|
384287
|
+
};
|
|
384288
384288
|
}
|
|
384289
384289
|
getDefaultExpectedAndLeftover(ca) {
|
|
384290
384290
|
const expectedBalances = new AddressMap();
|
|
@@ -384299,7 +384299,11 @@ var AbstractRouterContract = class extends BaseContract {
|
|
|
384299
384299
|
leftoverBalances.upsert(token, { token, balance });
|
|
384300
384300
|
}
|
|
384301
384301
|
}
|
|
384302
|
-
return {
|
|
384302
|
+
return {
|
|
384303
|
+
expectedBalances,
|
|
384304
|
+
leftoverBalances,
|
|
384305
|
+
tokensToClaim: new AddressMap()
|
|
384306
|
+
};
|
|
384303
384307
|
}
|
|
384304
384308
|
};
|
|
384305
384309
|
|
|
@@ -384557,7 +384561,8 @@ var RouterV300Contract = class extends AbstractRouterContract {
|
|
|
384557
384561
|
cm,
|
|
384558
384562
|
balances ? {
|
|
384559
384563
|
expectedBalances: assetsMap(balances.expectedBalances),
|
|
384560
|
-
leftoverBalances: assetsMap(balances.leftoverBalances)
|
|
384564
|
+
leftoverBalances: assetsMap(balances.leftoverBalances),
|
|
384565
|
+
tokensToClaim: assetsMap(balances.tokensToClaim || [])
|
|
384561
384566
|
} : void 0
|
|
384562
384567
|
);
|
|
384563
384568
|
await this.hooks.triggerHooks("foundPathOptions", {
|
|
@@ -384802,7 +384807,8 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384802
384807
|
token,
|
|
384803
384808
|
balance: expectedMap.get(token) ?? 0n,
|
|
384804
384809
|
leftoverBalance: leftoverMap.get(token) ?? 0n,
|
|
384805
|
-
numSplits: getNumSplits(token)
|
|
384810
|
+
numSplits: getNumSplits(token),
|
|
384811
|
+
claimRewards: false
|
|
384806
384812
|
})
|
|
384807
384813
|
);
|
|
384808
384814
|
this.logger?.debug(
|
|
@@ -384843,12 +384849,13 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384843
384849
|
*/
|
|
384844
384850
|
async findBestClosePath(props) {
|
|
384845
384851
|
const { creditAccount: ca, creditManager: cm, slippage, balances } = props;
|
|
384846
|
-
const { expectedBalances, leftoverBalances } = this.getExpectedAndLeftover(
|
|
384852
|
+
const { expectedBalances, leftoverBalances, tokensToClaim } = this.getExpectedAndLeftover(
|
|
384847
384853
|
ca,
|
|
384848
384854
|
cm,
|
|
384849
384855
|
balances ? {
|
|
384850
384856
|
expectedBalances: assetsMap(balances.expectedBalances),
|
|
384851
|
-
leftoverBalances: assetsMap(balances.leftoverBalances)
|
|
384857
|
+
leftoverBalances: assetsMap(balances.leftoverBalances),
|
|
384858
|
+
tokensToClaim: assetsMap(balances.tokensToClaim || [])
|
|
384852
384859
|
} : void 0
|
|
384853
384860
|
);
|
|
384854
384861
|
const getNumSplits = this.#numSplitsGetter(cm, expectedBalances.values());
|
|
@@ -384858,7 +384865,8 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384858
384865
|
token,
|
|
384859
384866
|
balance: expectedBalances.get(token)?.balance || 0n,
|
|
384860
384867
|
leftoverBalance: leftoverBalances.get(token)?.balance || 0n,
|
|
384861
|
-
numSplits: getNumSplits(token)
|
|
384868
|
+
numSplits: getNumSplits(token),
|
|
384869
|
+
claimRewards: !!tokensToClaim.get(token)
|
|
384862
384870
|
});
|
|
384863
384871
|
}
|
|
384864
384872
|
this.logger?.debug(
|
|
@@ -384871,12 +384879,23 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384871
384879
|
},
|
|
384872
384880
|
"calling routeManyToOne"
|
|
384873
384881
|
);
|
|
384874
|
-
const
|
|
384875
|
-
|
|
384876
|
-
|
|
384882
|
+
const targetToken = ca.underlying;
|
|
384883
|
+
const filtered = tData.filter((b) => {
|
|
384884
|
+
return b.balance > 10 && b.balance - b.leftoverBalance > 1 || !!b.claimRewards;
|
|
384885
|
+
});
|
|
384886
|
+
const skipSwap = filtered.length === 0 || filtered.length === 1 && filtered[0].token.toLowerCase() === targetToken.toLowerCase();
|
|
384887
|
+
const { result } = await (skipSwap ? {
|
|
384888
|
+
result: {
|
|
384889
|
+
amount: 0n,
|
|
384890
|
+
minAmount: 0n,
|
|
384891
|
+
calls: []
|
|
384892
|
+
}
|
|
384893
|
+
} : this.contract.simulate.routeManyToOne([
|
|
384894
|
+
ca.creditAccount,
|
|
384895
|
+
targetToken,
|
|
384877
384896
|
BigInt(slippage),
|
|
384878
384897
|
tData
|
|
384879
|
-
]);
|
|
384898
|
+
]));
|
|
384880
384899
|
const underlyingBalance = ca.tokens.find((t) => t.token === ca.underlying)?.balance ?? 0n;
|
|
384881
384900
|
return {
|
|
384882
384901
|
underlyingBalance: underlyingBalance + result.minAmount,
|
|
@@ -384899,8 +384918,15 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384899
384918
|
balance: priceOracle.convertToUSD(token, balance)
|
|
384900
384919
|
};
|
|
384901
384920
|
}).sort((a, b) => {
|
|
384902
|
-
return
|
|
384921
|
+
return a.balance > b.balance ? -1 : 1;
|
|
384903
384922
|
});
|
|
384923
|
+
this.logger?.debug(
|
|
384924
|
+
inUSD.map((v) => ({
|
|
384925
|
+
token: this.labelAddress(v.token),
|
|
384926
|
+
balance: formatBN(v.balance, 8) + ` (${v.balance})`
|
|
384927
|
+
})),
|
|
384928
|
+
"balances in usd"
|
|
384929
|
+
);
|
|
384904
384930
|
const map = new AddressMap(
|
|
384905
384931
|
inUSD.map(({ token }, i) => [token, i === 0 ? 4n : 1n])
|
|
384906
384932
|
);
|
|
@@ -384909,9 +384935,10 @@ var RouterV310Contract = class extends AbstractRouterContract {
|
|
|
384909
384935
|
#debugTokenData(tData) {
|
|
384910
384936
|
return tData.map((t) => ({
|
|
384911
384937
|
token: this.labelAddress(t.token),
|
|
384912
|
-
balance: this.sdk.tokensMeta.formatBN(t.token, t.balance)
|
|
384913
|
-
leftoverBalance: this.sdk.tokensMeta.formatBN(t.token, t.leftoverBalance)
|
|
384914
|
-
numSplits: t.numSplits
|
|
384938
|
+
balance: this.sdk.tokensMeta.formatBN(t.token, t.balance) + ` (${t.balance})`,
|
|
384939
|
+
leftoverBalance: this.sdk.tokensMeta.formatBN(t.token, t.leftoverBalance) + ` (${t.leftoverBalance})`,
|
|
384940
|
+
numSplits: t.numSplits,
|
|
384941
|
+
claimRewards: t.claimRewards
|
|
384915
384942
|
}));
|
|
384916
384943
|
}
|
|
384917
384944
|
/**
|
|
@@ -384946,7 +384973,7 @@ function balancesAfterOpen(target, targetAmount, expected, leftover) {
|
|
|
384946
384973
|
]);
|
|
384947
384974
|
for (const t of tokens) {
|
|
384948
384975
|
if (t === targetAddr) {
|
|
384949
|
-
result[t] = expected.get(t) ?? 0n + targetAmount;
|
|
384976
|
+
result[t] = (expected.get(t) ?? 0n) + targetAmount;
|
|
384950
384977
|
} else {
|
|
384951
384978
|
result[t] = BigIntMath.min(expected.get(t) ?? 0n, leftover.get(t) ?? 0n);
|
|
384952
384979
|
}
|
|
@@ -385703,13 +385730,7 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
385703
385730
|
averageQuota
|
|
385704
385731
|
})
|
|
385705
385732
|
];
|
|
385706
|
-
const tx = cm.creditFacade.multicall(creditAccount.creditAccount,
|
|
385707
|
-
...priceUpdates,
|
|
385708
|
-
...this.#prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
385709
|
-
minQuota,
|
|
385710
|
-
averageQuota
|
|
385711
|
-
})
|
|
385712
|
-
]);
|
|
385733
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
385713
385734
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
385714
385735
|
}
|
|
385715
385736
|
/**
|
|
@@ -385919,6 +385940,34 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
385919
385940
|
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
385920
385941
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
385921
385942
|
}
|
|
385943
|
+
/**
|
|
385944
|
+
* Executes enable/disable tokens specified by given tokens lists and token prices
|
|
385945
|
+
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
385946
|
+
* @param {Array<Asset>} enabledTokens - list of tokens to enable {@link Asset};
|
|
385947
|
+
* @param {Array<Asset>} disabledTokens - list of tokens to disable {@link Asset};
|
|
385948
|
+
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
385949
|
+
*/
|
|
385950
|
+
async enableTokens({
|
|
385951
|
+
enabledTokens,
|
|
385952
|
+
disabledTokens,
|
|
385953
|
+
creditAccount: ca
|
|
385954
|
+
}) {
|
|
385955
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
385956
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
385957
|
+
ca.creditManager,
|
|
385958
|
+
ca,
|
|
385959
|
+
void 0
|
|
385960
|
+
);
|
|
385961
|
+
const calls = [
|
|
385962
|
+
...priceUpdatesCalls,
|
|
385963
|
+
...disabledTokens.map(
|
|
385964
|
+
(token) => this.#prepareDisableToken(ca.creditFacade, token)
|
|
385965
|
+
),
|
|
385966
|
+
...this.#prepareEnableTokens(ca.creditFacade, enabledTokens)
|
|
385967
|
+
];
|
|
385968
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
385969
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
385970
|
+
}
|
|
385922
385971
|
/**
|
|
385923
385972
|
* Executes swap specified by given calls, update quotas of affected tokens
|
|
385924
385973
|
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
|
|
@@ -385967,12 +386016,12 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
385967
386016
|
...priceUpdatesCalls,
|
|
385968
386017
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
385969
386018
|
...this.#prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
386019
|
+
...openPathCalls,
|
|
386020
|
+
...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
|
|
385970
386021
|
...this.#prepareUpdateQuotas(cm.creditFacade, {
|
|
385971
386022
|
minQuota,
|
|
385972
386023
|
averageQuota
|
|
385973
|
-
})
|
|
385974
|
-
...openPathCalls,
|
|
385975
|
-
...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : []
|
|
386024
|
+
})
|
|
385976
386025
|
];
|
|
385977
386026
|
const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
|
|
385978
386027
|
tx.value = ethAmount.toString(10);
|
|
@@ -386014,6 +386063,8 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
386014
386063
|
}
|
|
386015
386064
|
/**
|
|
386016
386065
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
386066
|
+
*
|
|
386067
|
+
* This can be used by batch liquidator
|
|
386017
386068
|
* @param accounts
|
|
386018
386069
|
* @returns
|
|
386019
386070
|
*/
|
|
@@ -386042,19 +386093,11 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
386042
386093
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
386043
386094
|
}
|
|
386044
386095
|
async getUpdateForAccount(creditManager, creditAccount, desiredQuotas) {
|
|
386045
|
-
const tokensByPool = /* @__PURE__ */ new Map();
|
|
386046
|
-
const oracleByPool = /* @__PURE__ */ new Map();
|
|
386047
386096
|
const quotaRecord = desiredQuotas ? assetsMap(desiredQuotas) : desiredQuotas;
|
|
386048
386097
|
const caBalancesRecord = creditAccount ? assetsMap(creditAccount.tokens) : creditAccount;
|
|
386049
386098
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
386050
386099
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
|
|
386051
|
-
const
|
|
386052
|
-
oracleByPool.set(pool, market.priceOracle);
|
|
386053
|
-
const insertToken = (p, t) => {
|
|
386054
|
-
const tokens = tokensByPool.get(p) ?? /* @__PURE__ */ new Set();
|
|
386055
|
-
tokens.add(t);
|
|
386056
|
-
tokensByPool.set(pool, tokens);
|
|
386057
|
-
};
|
|
386100
|
+
const tokens = /* @__PURE__ */ new Set([getAddress(cm.underlying)]);
|
|
386058
386101
|
for (const t of cm.collateralTokens) {
|
|
386059
386102
|
if (creditAccount && caBalancesRecord && quotaRecord) {
|
|
386060
386103
|
const balanceAsset = caBalancesRecord.get(t);
|
|
@@ -386063,28 +386106,30 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
386063
386106
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
386064
386107
|
const quotaAsset = quotaRecord.get(t);
|
|
386065
386108
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
386066
|
-
if (balance > 10n && isEnabled || quotaBalance > 0)
|
|
386067
|
-
|
|
386109
|
+
if (balance > 10n && isEnabled || quotaBalance > 0) {
|
|
386110
|
+
tokens.add(getAddress(t));
|
|
386111
|
+
}
|
|
386068
386112
|
} else if (creditAccount && caBalancesRecord) {
|
|
386069
386113
|
const balanceAsset = caBalancesRecord.get(t);
|
|
386070
386114
|
const balance = balanceAsset?.balance || 0n;
|
|
386071
386115
|
const mask = balanceAsset?.mask || 0n;
|
|
386072
386116
|
const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
|
|
386073
|
-
if (balance > 10n && isEnabled)
|
|
386117
|
+
if (balance > 10n && isEnabled) {
|
|
386118
|
+
tokens.add(getAddress(t));
|
|
386119
|
+
}
|
|
386074
386120
|
} else if (quotaRecord) {
|
|
386075
386121
|
const quotaAsset = quotaRecord.get(t);
|
|
386076
386122
|
const quotaBalance = quotaAsset?.balance || 0n;
|
|
386077
|
-
if (quotaBalance > 0)
|
|
386123
|
+
if (quotaBalance > 0) {
|
|
386124
|
+
tokens.add(getAddress(t));
|
|
386125
|
+
}
|
|
386078
386126
|
}
|
|
386079
386127
|
}
|
|
386080
|
-
const priceFeeds =
|
|
386081
|
-
|
|
386082
|
-
const tokens = Array.from(tokensByPool.get(pool2) ?? []);
|
|
386083
|
-
priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
|
|
386084
|
-
}
|
|
386128
|
+
const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens));
|
|
386129
|
+
const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
|
|
386085
386130
|
this.#logger?.debug(
|
|
386086
386131
|
{ account: creditAccount?.creditAccount, manager: cm.name },
|
|
386087
|
-
`generating price feed updates for ${priceFeeds.length} price feeds`
|
|
386132
|
+
`generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
|
|
386088
386133
|
);
|
|
386089
386134
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
|
|
386090
386135
|
priceFeeds,
|
|
@@ -386478,6 +386523,24 @@ var AbstractAddressProviderContract = class extends BaseContract {
|
|
|
386478
386523
|
}
|
|
386479
386524
|
return [this.getAddress(contract, version4), version4];
|
|
386480
386525
|
}
|
|
386526
|
+
getLatestInRange(contract, range2) {
|
|
386527
|
+
const allVersions = this.#addresses[contract];
|
|
386528
|
+
if (!allVersions) {
|
|
386529
|
+
return void 0;
|
|
386530
|
+
}
|
|
386531
|
+
let version4 = 0;
|
|
386532
|
+
let address;
|
|
386533
|
+
for (const [v, a] of TypedObjectUtils.entries(allVersions)) {
|
|
386534
|
+
if (v >= range2[0] && v <= range2[1] && v >= version4) {
|
|
386535
|
+
version4 = v;
|
|
386536
|
+
address = a;
|
|
386537
|
+
}
|
|
386538
|
+
}
|
|
386539
|
+
if (!address) {
|
|
386540
|
+
return void 0;
|
|
386541
|
+
}
|
|
386542
|
+
return [address, version4];
|
|
386543
|
+
}
|
|
386481
386544
|
get state() {
|
|
386482
386545
|
return {
|
|
386483
386546
|
baseParams: {
|
|
@@ -386566,6 +386629,9 @@ var AddressProviderContractV3_1 = class extends AbstractAddressProviderContract
|
|
|
386566
386629
|
const entries = await this.contract.read.getAllEntries({
|
|
386567
386630
|
blockNumber
|
|
386568
386631
|
});
|
|
386632
|
+
this.logger?.debug(
|
|
386633
|
+
`loaded ${entries.length} events in block ${blockNumber}`
|
|
386634
|
+
);
|
|
386569
386635
|
for (const { key, ver, value } of entries) {
|
|
386570
386636
|
this.setInternalAddress(key, value, Number(ver));
|
|
386571
386637
|
}
|
|
@@ -386623,10 +386689,14 @@ var AddressProviderContractV3 = class extends AbstractAddressProviderContract {
|
|
|
386623
386689
|
}
|
|
386624
386690
|
}
|
|
386625
386691
|
async syncState(blockNumber) {
|
|
386692
|
+
const fromBlock = ADDRESS_PROVIDER_BLOCK[this.sdk.provider.networkType];
|
|
386693
|
+
this.logger?.debug(
|
|
386694
|
+
`loading events from block ${fromBlock} to ${blockNumber}`
|
|
386695
|
+
);
|
|
386626
386696
|
const events = await this.sdk.provider.publicClient.getLogs({
|
|
386627
386697
|
address: this.address,
|
|
386628
386698
|
event: getAbiItem({ abi: this.abi, name: "SetAddress" }),
|
|
386629
|
-
fromBlock
|
|
386699
|
+
fromBlock,
|
|
386630
386700
|
toBlock: blockNumber,
|
|
386631
386701
|
strict: true
|
|
386632
386702
|
});
|
|
@@ -387506,17 +387576,18 @@ var CreditSuite = class extends SDKConstruct {
|
|
|
387506
387576
|
creditManager;
|
|
387507
387577
|
creditFacade;
|
|
387508
387578
|
creditConfigurator;
|
|
387579
|
+
state;
|
|
387509
387580
|
constructor(sdk, marketData, index2) {
|
|
387510
387581
|
super(sdk);
|
|
387511
387582
|
const { creditManagers, pool } = marketData;
|
|
387512
|
-
|
|
387513
|
-
const { name } =
|
|
387583
|
+
this.state = creditManagers[index2];
|
|
387584
|
+
const { name } = this.state.creditManager;
|
|
387514
387585
|
this.name = name;
|
|
387515
387586
|
this.pool = pool.baseParams.addr;
|
|
387516
387587
|
this.underlying = pool.underlying;
|
|
387517
|
-
this.creditManager = createCreditManager(sdk,
|
|
387518
|
-
this.creditFacade = createCreditFacade(sdk,
|
|
387519
|
-
this.creditConfigurator = createCreditConfigurator(sdk,
|
|
387588
|
+
this.creditManager = createCreditManager(sdk, this.state);
|
|
387589
|
+
this.creditFacade = createCreditFacade(sdk, this.state);
|
|
387590
|
+
this.creditConfigurator = createCreditConfigurator(sdk, this.state);
|
|
387520
387591
|
}
|
|
387521
387592
|
async tvl() {
|
|
387522
387593
|
const tvl = 0n;
|
|
@@ -392726,7 +392797,9 @@ var RedstoneUpdater = class extends SDKConstruct {
|
|
|
392726
392797
|
groupedFeeds[key] = /* @__PURE__ */ new Set();
|
|
392727
392798
|
}
|
|
392728
392799
|
groupedFeeds[key].add(feed.dataId);
|
|
392729
|
-
priceFeeds.
|
|
392800
|
+
const pfsForDataId = priceFeeds.get(feed.dataId) ?? new AddressMap();
|
|
392801
|
+
pfsForDataId.upsert(feed.address, feed);
|
|
392802
|
+
priceFeeds.set(feed.dataId, pfsForDataId);
|
|
392730
392803
|
}
|
|
392731
392804
|
const results = [];
|
|
392732
392805
|
for (const [key, group] of Object.entries(groupedFeeds)) {
|
|
@@ -392738,26 +392811,28 @@ var RedstoneUpdater = class extends SDKConstruct {
|
|
|
392738
392811
|
uniqueSignersCount
|
|
392739
392812
|
);
|
|
392740
392813
|
for (const { dataFeedId, data, timestamp, cached } of payloads) {
|
|
392741
|
-
const
|
|
392742
|
-
if (!
|
|
392743
|
-
throw new Error(`cannot get price feed
|
|
392744
|
-
}
|
|
392745
|
-
|
|
392746
|
-
|
|
392747
|
-
|
|
392748
|
-
|
|
392749
|
-
|
|
392750
|
-
|
|
392751
|
-
|
|
392752
|
-
|
|
392753
|
-
|
|
392754
|
-
|
|
392755
|
-
|
|
392756
|
-
|
|
392757
|
-
|
|
392758
|
-
|
|
392759
|
-
|
|
392760
|
-
|
|
392814
|
+
const pfsForDataId = priceFeeds.get(dataFeedId);
|
|
392815
|
+
if (!pfsForDataId) {
|
|
392816
|
+
throw new Error(`cannot get price feed addresses for ${dataFeedId}`);
|
|
392817
|
+
}
|
|
392818
|
+
for (const priceFeed of pfsForDataId.values()) {
|
|
392819
|
+
results.push(
|
|
392820
|
+
new RedstoneUpdateTx(
|
|
392821
|
+
priceFeed.createRawTx({
|
|
392822
|
+
functionName: "updatePrice",
|
|
392823
|
+
args: [data],
|
|
392824
|
+
description: `updating price for ${dataFeedId} [${this.labelAddress(priceFeed.address)}]`
|
|
392825
|
+
}),
|
|
392826
|
+
{
|
|
392827
|
+
dataFeedId,
|
|
392828
|
+
dataServiceId,
|
|
392829
|
+
priceFeed: priceFeed.address,
|
|
392830
|
+
timestamp,
|
|
392831
|
+
cached
|
|
392832
|
+
}
|
|
392833
|
+
)
|
|
392834
|
+
);
|
|
392835
|
+
}
|
|
392761
392836
|
}
|
|
392762
392837
|
}
|
|
392763
392838
|
this.#logger?.debug(
|
|
@@ -393009,9 +393084,10 @@ var PriceFeedRegister = class extends SDKConstruct {
|
|
|
393009
393084
|
}
|
|
393010
393085
|
}
|
|
393011
393086
|
const result = { txs, timestamp: maxTimestamp };
|
|
393087
|
+
const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
|
|
393012
393088
|
this.logger?.debug(
|
|
393013
393089
|
logContext,
|
|
393014
|
-
`generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp}`
|
|
393090
|
+
`generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
|
|
393015
393091
|
);
|
|
393016
393092
|
if (txs.length) {
|
|
393017
393093
|
await this.#hooks.triggerHooks("updatesGenerated", result);
|
|
@@ -393049,7 +393125,7 @@ var PriceFeedRegister = class extends SDKConstruct {
|
|
|
393049
393125
|
const configurators = marketConfigurators ?? this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
393050
393126
|
this.logger?.debug(
|
|
393051
393127
|
{ configurators, pools },
|
|
393052
|
-
|
|
393128
|
+
`calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`
|
|
393053
393129
|
);
|
|
393054
393130
|
const result = await this.provider.publicClient.readContract({
|
|
393055
393131
|
address: marketCompressorAddress,
|
|
@@ -393061,9 +393137,12 @@ var PriceFeedRegister = class extends SDKConstruct {
|
|
|
393061
393137
|
pools: pools ?? [],
|
|
393062
393138
|
underlying: ADDRESS_0X0
|
|
393063
393139
|
}
|
|
393064
|
-
]
|
|
393140
|
+
],
|
|
393141
|
+
blockNumber: this.sdk.currentBlock
|
|
393065
393142
|
});
|
|
393066
|
-
this.logger?.debug(
|
|
393143
|
+
this.logger?.debug(
|
|
393144
|
+
`loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`
|
|
393145
|
+
);
|
|
393067
393146
|
return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
|
|
393068
393147
|
}
|
|
393069
393148
|
create(data) {
|
|
@@ -394169,6 +394248,14 @@ var PoolSuite = class extends SDKConstruct {
|
|
|
394169
394248
|
"Rate keeper is not a gauge, but a " + this.rateKeeper.contractType
|
|
394170
394249
|
);
|
|
394171
394250
|
}
|
|
394251
|
+
get tumbler() {
|
|
394252
|
+
if (this.rateKeeper instanceof TumblerContract) {
|
|
394253
|
+
return this.rateKeeper;
|
|
394254
|
+
}
|
|
394255
|
+
throw new Error(
|
|
394256
|
+
"Rate keeper is not a tumbler, but a " + this.rateKeeper.contractType
|
|
394257
|
+
);
|
|
394258
|
+
}
|
|
394172
394259
|
get linearModel() {
|
|
394173
394260
|
if (this.interestRateModel instanceof LinearInterestRateModelContract) {
|
|
394174
394261
|
return this.interestRateModel;
|
|
@@ -394181,7 +394268,7 @@ var PoolSuite = class extends SDKConstruct {
|
|
|
394181
394268
|
return this.pool.underlying;
|
|
394182
394269
|
}
|
|
394183
394270
|
get dirty() {
|
|
394184
|
-
return this.pool.dirty || this.
|
|
394271
|
+
return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
|
|
394185
394272
|
}
|
|
394186
394273
|
get watchAddresses() {
|
|
394187
394274
|
return /* @__PURE__ */ new Set([
|
|
@@ -394340,7 +394427,7 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
394340
394427
|
}
|
|
394341
394428
|
this.#logger?.debug(
|
|
394342
394429
|
{ configurators, pools },
|
|
394343
|
-
`calling getMarkets with ${txs.length} price updates`
|
|
394430
|
+
`calling getMarkets with ${txs.length} price updates in block ${this.sdk.currentBlock}`
|
|
394344
394431
|
);
|
|
394345
394432
|
let markets = [];
|
|
394346
394433
|
if (txs.length) {
|
|
@@ -394355,7 +394442,8 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
394355
394442
|
functionName: "getMarkets",
|
|
394356
394443
|
args: [this.#marketFilter]
|
|
394357
394444
|
}
|
|
394358
|
-
]
|
|
394445
|
+
],
|
|
394446
|
+
blockNumber: this.sdk.currentBlock
|
|
394359
394447
|
}
|
|
394360
394448
|
);
|
|
394361
394449
|
markets = resp;
|
|
@@ -394364,8 +394452,8 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
394364
394452
|
abi: iMarketCompressorAbi,
|
|
394365
394453
|
address: marketCompressorAddress,
|
|
394366
394454
|
functionName: "getMarkets",
|
|
394367
|
-
args: [this.#marketFilter]
|
|
394368
|
-
|
|
394455
|
+
args: [this.#marketFilter],
|
|
394456
|
+
blockNumber: this.sdk.currentBlock
|
|
394369
394457
|
});
|
|
394370
394458
|
}
|
|
394371
394459
|
for (const data of markets) {
|
|
@@ -394374,7 +394462,9 @@ var MarketRegister = class extends SDKConstruct {
|
|
|
394374
394462
|
new MarketSuite(this.sdk, data)
|
|
394375
394463
|
);
|
|
394376
394464
|
}
|
|
394377
|
-
this.#logger?.info(
|
|
394465
|
+
this.#logger?.info(
|
|
394466
|
+
`loaded ${markets.length} markets in block ${this.sdk.currentBlock}`
|
|
394467
|
+
);
|
|
394378
394468
|
}
|
|
394379
394469
|
/**
|
|
394380
394470
|
* Loads new prices and price feeds for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
@@ -394512,10 +394602,16 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
|
|
|
394512
394602
|
}
|
|
394513
394603
|
const events = await this.client.getLogs({
|
|
394514
394604
|
address: addresses,
|
|
394515
|
-
|
|
394516
|
-
|
|
394517
|
-
|
|
394518
|
-
|
|
394605
|
+
events: [
|
|
394606
|
+
getAbiItem({
|
|
394607
|
+
abi: iPriceOracleV300Abi,
|
|
394608
|
+
name: "SetReservePriceFeed"
|
|
394609
|
+
}),
|
|
394610
|
+
getAbiItem({
|
|
394611
|
+
abi: iPriceOracleV300Abi,
|
|
394612
|
+
name: "SetPriceFeed"
|
|
394613
|
+
})
|
|
394614
|
+
],
|
|
394519
394615
|
fromBlock,
|
|
394520
394616
|
toBlock,
|
|
394521
394617
|
strict: true
|
|
@@ -394529,9 +394625,10 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
|
|
|
394529
394625
|
const token = getAddress(e.args.token);
|
|
394530
394626
|
const stalenessPeriod = e.args.stalenessPeriod;
|
|
394531
394627
|
for (const o of oracles) {
|
|
394532
|
-
const
|
|
394628
|
+
const map = e.eventName === "SetReservePriceFeed" ? o.reservePriceFeeds : o.mainPriceFeeds;
|
|
394629
|
+
const pf = map.get(token);
|
|
394533
394630
|
if (hexEq(pf?.address, priceFeed) && hexEq(o.address, oracle)) {
|
|
394534
|
-
|
|
394631
|
+
map.upsert(
|
|
394535
394632
|
token,
|
|
394536
394633
|
new PriceFeedRef(this.sdk, priceFeed, stalenessPeriod)
|
|
394537
394634
|
);
|
|
@@ -394667,6 +394764,11 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
394667
394764
|
},
|
|
394668
394765
|
`${re}attaching gearbox sdk`
|
|
394669
394766
|
);
|
|
394767
|
+
if (!!blockNumber && !redstoneHistoricTimestamp) {
|
|
394768
|
+
this.logger?.warn(
|
|
394769
|
+
`${re}attaching to fixed block number, but redstoneHistoricTimestamp is not set. price updates might fail`
|
|
394770
|
+
);
|
|
394771
|
+
}
|
|
394670
394772
|
this.#attachConfig = opts;
|
|
394671
394773
|
const time = Date.now();
|
|
394672
394774
|
const block = await this.provider.publicClient.getBlock(
|
|
@@ -394683,11 +394785,7 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
394683
394785
|
this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
|
|
394684
394786
|
}
|
|
394685
394787
|
this.logger?.debug(
|
|
394686
|
-
{
|
|
394687
|
-
number: block.number,
|
|
394688
|
-
timestamp: block.timestamp
|
|
394689
|
-
},
|
|
394690
|
-
`${re}attach block`
|
|
394788
|
+
`${re}attach block number ${this.currentBlock} timestamp ${this.timestamp}`
|
|
394691
394789
|
);
|
|
394692
394790
|
this.#addressProvider = await createAddressProvider(this, addressProvider);
|
|
394693
394791
|
this.logger?.debug(
|
|
@@ -394839,6 +394937,11 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
394839
394937
|
*/
|
|
394840
394938
|
async syncState(opts) {
|
|
394841
394939
|
let { blockNumber, timestamp, skipPriceUpdate } = opts ?? {};
|
|
394940
|
+
if (this.#attachConfig?.redstoneHistoricTimestamp) {
|
|
394941
|
+
throw new Error(
|
|
394942
|
+
"syncState is not supported with redstoneHistoricTimestamp"
|
|
394943
|
+
);
|
|
394944
|
+
}
|
|
394842
394945
|
if (!blockNumber || !timestamp) {
|
|
394843
394946
|
const block = await this.provider.publicClient.getBlock({
|
|
394844
394947
|
blockTag: "latest"
|
|
@@ -394877,16 +394980,16 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
394877
394980
|
contract.processLog(event);
|
|
394878
394981
|
}
|
|
394879
394982
|
}
|
|
394880
|
-
await this.marketRegister.syncState(skipPriceUpdate);
|
|
394881
394983
|
this.#currentBlock = blockNumber;
|
|
394882
394984
|
this.#timestamp = timestamp;
|
|
394985
|
+
await this.marketRegister.syncState(skipPriceUpdate);
|
|
394883
394986
|
await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
|
|
394884
394987
|
const pluginsList = TypedObjectUtils.entries(this.plugins);
|
|
394885
394988
|
const pluginResponse = await Promise.allSettled(
|
|
394886
394989
|
pluginsList.map(([name, plugin]) => {
|
|
394887
|
-
if (plugin.
|
|
394990
|
+
if (plugin.syncState) {
|
|
394888
394991
|
this.logger?.debug(`syncing plugin ${name}`);
|
|
394889
|
-
return plugin.
|
|
394992
|
+
return plugin.syncState();
|
|
394890
394993
|
}
|
|
394891
394994
|
return void 0;
|
|
394892
394995
|
})
|
|
@@ -413556,7 +413659,12 @@ var ForkTemplate = z.object({
|
|
|
413556
413659
|
* @-7200 = previous Monday 12:00 UTC -7200 blocks
|
|
413557
413660
|
*/
|
|
413558
413661
|
blockNumber: z.string().nullish().transform((v) => v || void 0),
|
|
413559
|
-
scripts: z.array(ScriptTemplate).nullish()
|
|
413662
|
+
scripts: z.array(ScriptTemplate).nullish().refine((scripts) => {
|
|
413663
|
+
const ids = scripts?.map((s) => s.id) ?? [];
|
|
413664
|
+
return ids.length === new Set(ids).size;
|
|
413665
|
+
}, {
|
|
413666
|
+
message: "scripts must have unique ids"
|
|
413667
|
+
}),
|
|
413560
413668
|
/**
|
|
413561
413669
|
* Will append deploy-report generation to scripts
|
|
413562
413670
|
*/
|
|
@@ -416185,7 +416293,11 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416185
416293
|
chain: service.sdk.provider.chain,
|
|
416186
416294
|
transport: service.sdk.provider.transport
|
|
416187
416295
|
});
|
|
416188
|
-
|
|
416296
|
+
try {
|
|
416297
|
+
this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
|
|
416298
|
+
} catch (e) {
|
|
416299
|
+
this.#logger?.warn("faucet not found, will not claim from faucet");
|
|
416300
|
+
}
|
|
416189
416301
|
this.#borrower = options.borrower;
|
|
416190
416302
|
this.#poolDepositMultiplier = options.poolDepositMultiplier ?? 11000n;
|
|
416191
416303
|
}
|
|
@@ -416198,7 +416310,7 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416198
416310
|
/**
|
|
416199
416311
|
* Tries to open account with underlying only in each CM
|
|
416200
416312
|
*/
|
|
416201
|
-
async openCreditAccounts(targets, depositIntoPools = true) {
|
|
416313
|
+
async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet = true) {
|
|
416202
416314
|
if (depositIntoPools) {
|
|
416203
416315
|
try {
|
|
416204
416316
|
await this.#depositIntoPools(targets);
|
|
@@ -416206,7 +416318,9 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416206
416318
|
this.#logger?.warn(`failed to deposit into pools: ${e}`);
|
|
416207
416319
|
}
|
|
416208
416320
|
}
|
|
416209
|
-
|
|
416321
|
+
if (claimFromFaucet) {
|
|
416322
|
+
await this.#prepareBorrower(targets);
|
|
416323
|
+
}
|
|
416210
416324
|
const toApprove = new AddressMap();
|
|
416211
416325
|
for (const c of targets) {
|
|
416212
416326
|
const cm = this.sdk.marketRegister.findCreditManager(c.creditManager);
|
|
@@ -416239,20 +416353,80 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416239
416353
|
return results;
|
|
416240
416354
|
}
|
|
416241
416355
|
async #openAccount(input, index2, total) {
|
|
416356
|
+
const { creditManager, target: collateral } = input;
|
|
416357
|
+
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
416358
|
+
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
416359
|
+
const logger2 = this.#logger?.child?.({
|
|
416360
|
+
creditManager: cm.name,
|
|
416361
|
+
collateral: symbol
|
|
416362
|
+
});
|
|
416363
|
+
logger2?.debug(`opening account #${index2}/${total}`);
|
|
416364
|
+
const borrower = await this.#getBorrower();
|
|
416365
|
+
const tx = await this.prepareOpen(input);
|
|
416366
|
+
let hash2;
|
|
416367
|
+
try {
|
|
416368
|
+
hash2 = await sendRawTx(this.#anvil, {
|
|
416369
|
+
tx,
|
|
416370
|
+
account: borrower
|
|
416371
|
+
});
|
|
416372
|
+
logger2?.debug(`send transaction ${hash2}`);
|
|
416373
|
+
} catch (e) {
|
|
416374
|
+
return {
|
|
416375
|
+
input,
|
|
416376
|
+
error: `${e}`,
|
|
416377
|
+
rawTx: tx
|
|
416378
|
+
};
|
|
416379
|
+
}
|
|
416380
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
|
|
416381
|
+
if (receipt.status === "reverted") {
|
|
416382
|
+
return {
|
|
416383
|
+
input,
|
|
416384
|
+
error: `open credit account tx reverted`,
|
|
416385
|
+
txHash: hash2,
|
|
416386
|
+
rawTx: tx
|
|
416387
|
+
};
|
|
416388
|
+
}
|
|
416389
|
+
logger2?.info(`opened credit account ${index2}/${total}`);
|
|
416390
|
+
const logs = parseEventLogs({
|
|
416391
|
+
abi: iCreditFacadeV300Abi,
|
|
416392
|
+
logs: receipt.logs,
|
|
416393
|
+
eventName: "OpenCreditAccount"
|
|
416394
|
+
});
|
|
416395
|
+
logger2?.info(`found ${logs.length} logs`);
|
|
416396
|
+
let account;
|
|
416397
|
+
if (logs.length > 0) {
|
|
416398
|
+
try {
|
|
416399
|
+
logger2?.debug(
|
|
416400
|
+
`getting credit account data for ${logs[0].args.creditAccount}`
|
|
416401
|
+
);
|
|
416402
|
+
account = await this.#service.getCreditAccountData(
|
|
416403
|
+
logs[0].args.creditAccount
|
|
416404
|
+
);
|
|
416405
|
+
} catch (e) {
|
|
416406
|
+
logger2?.error(`failed to get credit account data: ${e}`);
|
|
416407
|
+
}
|
|
416408
|
+
}
|
|
416409
|
+
return {
|
|
416410
|
+
input,
|
|
416411
|
+
txHash: hash2,
|
|
416412
|
+
rawTx: tx,
|
|
416413
|
+
account
|
|
416414
|
+
};
|
|
416415
|
+
}
|
|
416416
|
+
async prepareOpen(input) {
|
|
416242
416417
|
const {
|
|
416243
416418
|
creditManager,
|
|
416244
|
-
|
|
416419
|
+
target,
|
|
416245
416420
|
leverage = DEFAULT_LEVERAGE,
|
|
416246
416421
|
slippage = 50
|
|
416247
416422
|
} = input;
|
|
416248
416423
|
const borrower = await this.#getBorrower();
|
|
416249
416424
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
416250
|
-
const symbol = this.sdk.tokensMeta.symbol(
|
|
416425
|
+
const symbol = this.sdk.tokensMeta.symbol(target);
|
|
416251
416426
|
const logger2 = this.#logger?.child?.({
|
|
416252
416427
|
creditManager: cm.name,
|
|
416253
|
-
|
|
416428
|
+
target: symbol
|
|
416254
416429
|
});
|
|
416255
|
-
logger2?.debug(`opening account #${index2}/${total}`);
|
|
416256
416430
|
const { minDebt, underlying } = cm.creditFacade;
|
|
416257
416431
|
const expectedBalances = [];
|
|
416258
416432
|
const leftoverBalances = [];
|
|
@@ -416273,19 +416447,19 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416273
416447
|
expectedBalances,
|
|
416274
416448
|
leftoverBalances,
|
|
416275
416449
|
slippage,
|
|
416276
|
-
target
|
|
416450
|
+
target
|
|
416277
416451
|
});
|
|
416278
416452
|
logger2?.debug(strategy, "found open strategy");
|
|
416279
416453
|
const debt = minDebt * BigInt(leverage - 1);
|
|
416280
416454
|
const averageQuota = this.#getCollateralQuota(
|
|
416281
416455
|
cm,
|
|
416282
|
-
|
|
416456
|
+
target,
|
|
416283
416457
|
strategy.amount,
|
|
416284
416458
|
debt
|
|
416285
416459
|
);
|
|
416286
416460
|
const minQuota = this.#getCollateralQuota(
|
|
416287
416461
|
cm,
|
|
416288
|
-
|
|
416462
|
+
target,
|
|
416289
416463
|
strategy.minAmount,
|
|
416290
416464
|
debt
|
|
416291
416465
|
);
|
|
@@ -416309,55 +416483,7 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416309
416483
|
);
|
|
416310
416484
|
}
|
|
416311
416485
|
logger2?.debug("prepared open account transaction");
|
|
416312
|
-
|
|
416313
|
-
try {
|
|
416314
|
-
hash2 = await sendRawTx(this.#anvil, {
|
|
416315
|
-
tx,
|
|
416316
|
-
account: borrower
|
|
416317
|
-
});
|
|
416318
|
-
logger2?.debug(`send transaction ${hash2}`);
|
|
416319
|
-
} catch (e) {
|
|
416320
|
-
return {
|
|
416321
|
-
input,
|
|
416322
|
-
error: `${e}`,
|
|
416323
|
-
rawTx: tx
|
|
416324
|
-
};
|
|
416325
|
-
}
|
|
416326
|
-
const receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
|
|
416327
|
-
if (receipt.status === "reverted") {
|
|
416328
|
-
return {
|
|
416329
|
-
input,
|
|
416330
|
-
error: `open credit account tx reverted`,
|
|
416331
|
-
txHash: hash2,
|
|
416332
|
-
rawTx: tx
|
|
416333
|
-
};
|
|
416334
|
-
}
|
|
416335
|
-
logger2?.info(`opened credit account ${index2}/${total}`);
|
|
416336
|
-
const logs = parseEventLogs({
|
|
416337
|
-
abi: iCreditFacadeV300Abi,
|
|
416338
|
-
logs: receipt.logs,
|
|
416339
|
-
eventName: "OpenCreditAccount"
|
|
416340
|
-
});
|
|
416341
|
-
logger2?.info(`found ${logs.length} logs`);
|
|
416342
|
-
let account;
|
|
416343
|
-
if (logs.length > 0) {
|
|
416344
|
-
try {
|
|
416345
|
-
logger2?.debug(
|
|
416346
|
-
`getting credit account data for ${logs[0].args.creditAccount}`
|
|
416347
|
-
);
|
|
416348
|
-
account = await this.#service.getCreditAccountData(
|
|
416349
|
-
logs[0].args.creditAccount
|
|
416350
|
-
);
|
|
416351
|
-
} catch (e) {
|
|
416352
|
-
logger2?.error(`failed to get credit account data: ${e}`);
|
|
416353
|
-
}
|
|
416354
|
-
}
|
|
416355
|
-
return {
|
|
416356
|
-
input,
|
|
416357
|
-
txHash: hash2,
|
|
416358
|
-
rawTx: tx,
|
|
416359
|
-
account
|
|
416360
|
-
};
|
|
416486
|
+
return tx;
|
|
416361
416487
|
}
|
|
416362
416488
|
async getOpenedAccounts() {
|
|
416363
416489
|
return await this.#service.getCreditAccounts({
|
|
@@ -416456,7 +416582,6 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416456
416582
|
* Creates borrower wallet,
|
|
416457
416583
|
* Sets ETH balance,
|
|
416458
416584
|
* Gets tokens from faucet,
|
|
416459
|
-
* Approves collateral tokens to credit manager,
|
|
416460
416585
|
* Gets DEGEN_NFT,
|
|
416461
416586
|
*/
|
|
416462
416587
|
async #prepareBorrower(targets) {
|
|
@@ -416493,7 +416618,7 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416493
416618
|
}
|
|
416494
416619
|
const hash2 = await this.#anvil.writeContract({
|
|
416495
416620
|
account: claimer,
|
|
416496
|
-
address: this
|
|
416621
|
+
address: this.faucet,
|
|
416497
416622
|
abi: [
|
|
416498
416623
|
{
|
|
416499
416624
|
type: "function",
|
|
@@ -416661,6 +416786,12 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
416661
416786
|
quota = quota * (PERCENTAGE_FACTOR + 500n) / PERCENTAGE_FACTOR;
|
|
416662
416787
|
return quota / PERCENTAGE_FACTOR * PERCENTAGE_FACTOR;
|
|
416663
416788
|
}
|
|
416789
|
+
get faucet() {
|
|
416790
|
+
if (!this.#faucet) {
|
|
416791
|
+
throw new Error("faucet not found");
|
|
416792
|
+
}
|
|
416793
|
+
return this.#faucet;
|
|
416794
|
+
}
|
|
416664
416795
|
};
|
|
416665
416796
|
|
|
416666
416797
|
// ../../node_modules/@gearbox-protocol/sdk/dist/esm/dev/detectChain.js
|
|
@@ -423644,6 +423775,26 @@ var UniswapV2AdapterContract = class extends AbstractAdapterContract {
|
|
|
423644
423775
|
abi: abi43
|
|
423645
423776
|
});
|
|
423646
423777
|
}
|
|
423778
|
+
parseFunctionParams(params) {
|
|
423779
|
+
switch (params.functionName) {
|
|
423780
|
+
case "swapDiffTokensForTokens": {
|
|
423781
|
+
const [leftoverAmount, rateMinRAY, path12, _deadline] = params.args;
|
|
423782
|
+
const leftoverAmountStr = this.sdk.tokensMeta.formatBN(
|
|
423783
|
+
path12[0],
|
|
423784
|
+
leftoverAmount
|
|
423785
|
+
);
|
|
423786
|
+
const pathStr = path12.map((t) => this.labelAddress(t)).join(" => ");
|
|
423787
|
+
return [
|
|
423788
|
+
`(leftoverAmount: ${leftoverAmountStr}, rate: ${formatBN(
|
|
423789
|
+
rateMinRAY,
|
|
423790
|
+
27
|
|
423791
|
+
)}, path: ${pathStr}`
|
|
423792
|
+
];
|
|
423793
|
+
}
|
|
423794
|
+
default:
|
|
423795
|
+
return void 0;
|
|
423796
|
+
}
|
|
423797
|
+
}
|
|
423647
423798
|
};
|
|
423648
423799
|
|
|
423649
423800
|
// ../../node_modules/@gearbox-protocol/sdk/dist/esm/adapters/UniswapV3AdapterContract.js
|
|
@@ -423951,31 +424102,31 @@ function openAccounts() {
|
|
|
423951
424102
|
{
|
|
423952
424103
|
creditManager: "0x50ba483272484fc5eebe8676dc87d814a11faef6",
|
|
423953
424104
|
// restaking weth
|
|
423954
|
-
|
|
424105
|
+
target: "0xbf5495Efe5DB9ce00f80364C8B423567e58d2110"
|
|
423955
424106
|
// ezETH
|
|
423956
424107
|
},
|
|
423957
424108
|
{
|
|
423958
424109
|
creditManager: "0x50ba483272484fc5eebe8676dc87d814a11faef6",
|
|
423959
424110
|
// restaking weth
|
|
423960
|
-
|
|
424111
|
+
target: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
423961
424112
|
// WETH
|
|
423962
424113
|
},
|
|
423963
424114
|
{
|
|
423964
424115
|
creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
|
|
423965
424116
|
// [Trade USDC Tier 1]
|
|
423966
|
-
|
|
424117
|
+
target: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
|
|
423967
424118
|
// WBTC
|
|
423968
424119
|
},
|
|
423969
424120
|
{
|
|
423970
424121
|
creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
|
|
423971
424122
|
// [Trade USDC Tier 1]
|
|
423972
|
-
|
|
424123
|
+
target: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
|
|
423973
424124
|
// DAI
|
|
423974
424125
|
},
|
|
423975
424126
|
{
|
|
423976
424127
|
creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
|
|
423977
424128
|
// [Trade USDC Tier 1]
|
|
423978
|
-
|
|
424129
|
+
target: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497"
|
|
423979
424130
|
// sUSDe
|
|
423980
424131
|
}
|
|
423981
424132
|
];
|
|
@@ -423984,7 +424135,7 @@ function openAccounts() {
|
|
|
423984
424135
|
{
|
|
423985
424136
|
creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
|
|
423986
424137
|
// [Trade USDC Tier 1]
|
|
423987
|
-
|
|
424138
|
+
target: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
|
|
423988
424139
|
// DAI
|
|
423989
424140
|
}
|
|
423990
424141
|
];
|
|
@@ -424011,9 +424162,9 @@ function openAccounts() {
|
|
|
424011
424162
|
collateralTokens.delete(getAddress(cm.underlying));
|
|
424012
424163
|
accounts.push(
|
|
424013
424164
|
...Array.from(collateralTokens).map(
|
|
424014
|
-
(
|
|
424165
|
+
(target) => ({
|
|
424015
424166
|
creditManager: cmAddr,
|
|
424016
|
-
|
|
424167
|
+
target,
|
|
424017
424168
|
leverage: 3
|
|
424018
424169
|
})
|
|
424019
424170
|
)
|
|
@@ -424031,11 +424182,11 @@ function openAccounts() {
|
|
|
424031
424182
|
)
|
|
424032
424183
|
);
|
|
424033
424184
|
log_default.debug(
|
|
424034
|
-
`found ${cms.length} cms with stkcvxRLUSDUSDC as
|
|
424185
|
+
`found ${cms.length} cms with stkcvxRLUSDUSDC as target: ${cms.map((cm) => cm.name)}`
|
|
424035
424186
|
);
|
|
424036
424187
|
accounts = cms.map((cm) => ({
|
|
424037
424188
|
creditManager: cm.creditManager.address,
|
|
424038
|
-
|
|
424189
|
+
target: t.addr
|
|
424039
424190
|
}));
|
|
424040
424191
|
}
|
|
424041
424192
|
const results = await accountOpener.openCreditAccounts(accounts, true);
|
|
@@ -424151,7 +424302,7 @@ function getRenderer(opts) {
|
|
|
424151
424302
|
var package_default = {
|
|
424152
424303
|
name: "@gearbox-protocol/deploy-tools",
|
|
424153
424304
|
description: "Gearbox deploy tools",
|
|
424154
|
-
version: "5.24.
|
|
424305
|
+
version: "5.24.32",
|
|
424155
424306
|
homepage: "https://gearbox.fi",
|
|
424156
424307
|
keywords: [
|
|
424157
424308
|
"gearbox"
|
|
@@ -424194,7 +424345,7 @@ var package_default = {
|
|
|
424194
424345
|
"@gearbox-protocol/deploy-tools-node": "0.0.0",
|
|
424195
424346
|
"@gearbox-protocol/deploy-tools-shared": "0.0.0",
|
|
424196
424347
|
"@gearbox-protocol/deploy-tools-types": "0.0.0",
|
|
424197
|
-
"@gearbox-protocol/sdk": "3.0.0-vfour.
|
|
424348
|
+
"@gearbox-protocol/sdk": "3.0.0-vfour.392",
|
|
424198
424349
|
"@gearbox-protocol/sdk-gov": "^2.37.0",
|
|
424199
424350
|
"@types/lodash-es": "^4.17.12",
|
|
424200
424351
|
"@types/node": "^22.13.14",
|
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.24.
|
|
4
|
+
"version": "5.24.32",
|
|
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.392",
|
|
48
48
|
"@gearbox-protocol/sdk-gov": "^2.37.0",
|
|
49
49
|
"@types/lodash-es": "^4.17.12",
|
|
50
50
|
"@types/node": "^22.13.14",
|