@gearbox-protocol/sdk 13.0.0-beta.3 → 13.0.0-beta.5
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/abi/iPriceFeed.js +84 -0
- package/dist/cjs/common-utils/index.js +22 -0
- package/dist/cjs/common-utils/package.json +1 -0
- package/dist/cjs/{sdk → common-utils}/utils/assetsMath.js +88 -21
- package/dist/cjs/common-utils/utils/bigintMath.js +65 -0
- package/dist/cjs/common-utils/utils/creditAccount/calcHealthFactor.js +76 -0
- package/dist/cjs/common-utils/utils/creditAccount/calcOverallAPY.js +81 -0
- package/dist/cjs/{sdk/utils/priceMath.js → common-utils/utils/creditAccount/calcQuotaBorrowRate.js} +19 -12
- package/dist/cjs/{sdk/utils/bigintMath.js → common-utils/utils/creditAccount/calcRelativeBaseBorrowRate.js} +11 -10
- package/dist/cjs/common-utils/utils/creditAccount/debt.js +64 -0
- package/dist/cjs/common-utils/utils/creditAccount/getTimeToLiquidation.js +38 -0
- package/dist/cjs/common-utils/utils/creditAccount/index.js +38 -0
- package/dist/cjs/common-utils/utils/creditAccount/liquidationPrice.js +47 -0
- package/dist/cjs/common-utils/utils/creditAccount/quotaUtils.js +149 -0
- package/dist/cjs/common-utils/utils/creditAccount/sort.js +95 -0
- package/dist/cjs/common-utils/utils/creditAccount/types.js +16 -0
- package/dist/cjs/{sdk → common-utils}/utils/endpoints.js +11 -17
- package/dist/cjs/common-utils/utils/index.js +30 -0
- package/dist/cjs/common-utils/utils/priceMath.js +66 -0
- package/dist/cjs/permissionless/bindings/cross-chain-multisig.js +3 -3
- package/dist/cjs/permissionless/bindings/instance-manager.js +2 -2
- package/dist/cjs/plugins/adapters/contracts/MellowDepositQueueAdapterContract.js +0 -6
- package/dist/cjs/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.js +0 -6
- package/dist/cjs/sdk/GearboxSDK.js +0 -2
- package/dist/cjs/sdk/base/BaseContract.js +5 -2
- package/dist/cjs/sdk/base/ChainContractsRegister.js +2 -10
- package/dist/cjs/sdk/base/Construct.js +25 -19
- package/dist/cjs/sdk/base/SDKConstruct.js +1 -1
- package/dist/cjs/sdk/market/adapters/PlaceholderAdapterContracts.js +16 -0
- package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -17
- package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +2 -2
- package/dist/cjs/sdk/utils/formatter.js +3 -3
- package/dist/cjs/sdk/utils/index.js +0 -10
- package/dist/esm/abi/iPriceFeed.js +60 -0
- package/dist/esm/common-utils/index.js +1 -0
- package/dist/esm/common-utils/package.json +1 -0
- package/dist/esm/{sdk → common-utils}/utils/assetsMath.js +80 -13
- package/dist/esm/common-utils/utils/bigintMath.js +41 -0
- package/dist/esm/common-utils/utils/creditAccount/calcHealthFactor.js +55 -0
- package/dist/esm/common-utils/utils/creditAccount/calcOverallAPY.js +60 -0
- package/dist/esm/common-utils/utils/creditAccount/calcQuotaBorrowRate.js +18 -0
- package/dist/esm/common-utils/utils/creditAccount/calcRelativeBaseBorrowRate.js +10 -0
- package/dist/esm/common-utils/utils/creditAccount/debt.js +43 -0
- package/dist/esm/common-utils/utils/creditAccount/getTimeToLiquidation.js +18 -0
- package/dist/esm/common-utils/utils/creditAccount/index.js +9 -0
- package/dist/esm/common-utils/utils/creditAccount/liquidationPrice.js +23 -0
- package/dist/esm/common-utils/utils/creditAccount/quotaUtils.js +125 -0
- package/dist/esm/common-utils/utils/creditAccount/sort.js +67 -0
- package/dist/esm/common-utils/utils/creditAccount/types.js +0 -0
- package/dist/esm/{sdk → common-utils}/utils/endpoints.js +9 -14
- package/dist/esm/common-utils/utils/index.js +5 -0
- package/dist/esm/common-utils/utils/priceMath.js +42 -0
- package/dist/esm/permissionless/bindings/cross-chain-multisig.js +3 -3
- package/dist/esm/permissionless/bindings/instance-manager.js +2 -2
- package/dist/esm/plugins/adapters/contracts/MellowDepositQueueAdapterContract.js +0 -6
- package/dist/esm/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.js +0 -6
- package/dist/esm/sdk/GearboxSDK.js +0 -2
- package/dist/esm/sdk/base/BaseContract.js +5 -2
- package/dist/esm/sdk/base/ChainContractsRegister.js +2 -10
- package/dist/esm/sdk/base/Construct.js +25 -19
- package/dist/esm/sdk/base/SDKConstruct.js +1 -1
- package/dist/esm/sdk/market/adapters/PlaceholderAdapterContracts.js +16 -0
- package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -17
- package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +2 -2
- package/dist/esm/sdk/utils/formatter.js +1 -1
- package/dist/esm/sdk/utils/index.js +0 -5
- package/dist/types/abi/iPriceFeed.d.ts +87 -0
- package/dist/types/common-utils/index.d.ts +1 -0
- package/dist/types/common-utils/utils/assetsMath.d.ts +114 -0
- package/dist/types/common-utils/utils/bigintMath.d.ts +43 -0
- package/dist/types/common-utils/utils/creditAccount/calcHealthFactor.d.ts +25 -0
- package/dist/types/common-utils/utils/creditAccount/calcOverallAPY.d.ts +37 -0
- package/dist/types/common-utils/utils/creditAccount/calcQuotaBorrowRate.d.ts +18 -0
- package/dist/types/common-utils/utils/creditAccount/calcRelativeBaseBorrowRate.d.ts +15 -0
- package/dist/types/common-utils/utils/creditAccount/debt.d.ts +35 -0
- package/dist/types/common-utils/utils/creditAccount/getTimeToLiquidation.d.ts +16 -0
- package/dist/types/common-utils/utils/creditAccount/index.d.ts +9 -0
- package/dist/types/common-utils/utils/creditAccount/liquidationPrice.d.ts +25 -0
- package/dist/types/common-utils/utils/creditAccount/quotaUtils.d.ts +81 -0
- package/dist/types/common-utils/utils/creditAccount/sort.d.ts +55 -0
- package/dist/types/common-utils/utils/creditAccount/types.d.ts +18 -0
- package/dist/types/{sdk → common-utils}/utils/endpoints.d.ts +13 -5
- package/dist/types/common-utils/utils/index.d.ts +5 -0
- package/dist/types/common-utils/utils/priceMath.d.ts +47 -0
- package/dist/types/permissionless/bindings/cross-chain-multisig.d.ts +3 -3
- package/dist/types/permissionless/bindings/instance-manager.d.ts +3 -3
- package/dist/types/plugins/adapters/contracts/MellowDepositQueueAdapterContract.d.ts +1 -4
- package/dist/types/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.d.ts +1 -4
- package/dist/types/sdk/base/ChainContractsRegister.d.ts +0 -2
- package/dist/types/sdk/base/Construct.d.ts +7 -10
- package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +2 -1
- package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +1 -8
- package/dist/types/sdk/utils/index.d.ts +0 -5
- package/package.json +11 -2
- package/dist/cjs/sdk/utils/creditAccount.js +0 -409
- package/dist/esm/sdk/utils/bigintMath.js +0 -9
- package/dist/esm/sdk/utils/creditAccount.js +0 -396
- package/dist/esm/sdk/utils/priceMath.js +0 -11
- package/dist/types/sdk/utils/assetsMath.d.ts +0 -42
- package/dist/types/sdk/utils/bigintMath.d.ts +0 -6
- package/dist/types/sdk/utils/creditAccount.d.ts +0 -128
- package/dist/types/sdk/utils/priceMath.d.ts +0 -9
|
@@ -0,0 +1,38 @@
|
|
|
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 getTimeToLiquidation_exports = {};
|
|
20
|
+
__export(getTimeToLiquidation_exports, {
|
|
21
|
+
getTimeToLiquidation: () => getTimeToLiquidation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getTimeToLiquidation_exports);
|
|
24
|
+
var import_sdk = require("../../../sdk/index.js");
|
|
25
|
+
function getTimeToLiquidation({
|
|
26
|
+
healthFactor,
|
|
27
|
+
totalBorrowRate_debt
|
|
28
|
+
}) {
|
|
29
|
+
if (healthFactor <= import_sdk.PERCENTAGE_FACTOR || totalBorrowRate_debt === 0n)
|
|
30
|
+
return null;
|
|
31
|
+
const HF_1 = BigInt(healthFactor) - import_sdk.PERCENTAGE_FACTOR;
|
|
32
|
+
const brPerYear = BigInt(import_sdk.SECONDS_PER_YEAR) * import_sdk.PERCENTAGE_FACTOR * import_sdk.PERCENTAGE_DECIMALS / totalBorrowRate_debt;
|
|
33
|
+
return HF_1 * brPerYear * 1000n / import_sdk.PERCENTAGE_FACTOR;
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
getTimeToLiquidation
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var creditAccount_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(creditAccount_exports);
|
|
18
|
+
__reExport(creditAccount_exports, require("./calcHealthFactor.js"), module.exports);
|
|
19
|
+
__reExport(creditAccount_exports, require("./calcQuotaBorrowRate.js"), module.exports);
|
|
20
|
+
__reExport(creditAccount_exports, require("./calcQuotaBorrowRate.js"), module.exports);
|
|
21
|
+
__reExport(creditAccount_exports, require("./calcRelativeBaseBorrowRate.js"), module.exports);
|
|
22
|
+
__reExport(creditAccount_exports, require("./debt.js"), module.exports);
|
|
23
|
+
__reExport(creditAccount_exports, require("./getTimeToLiquidation.js"), module.exports);
|
|
24
|
+
__reExport(creditAccount_exports, require("./liquidationPrice.js"), module.exports);
|
|
25
|
+
__reExport(creditAccount_exports, require("./quotaUtils.js"), module.exports);
|
|
26
|
+
__reExport(creditAccount_exports, require("./sort.js"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./calcHealthFactor.js"),
|
|
30
|
+
...require("./calcQuotaBorrowRate.js"),
|
|
31
|
+
...require("./calcQuotaBorrowRate.js"),
|
|
32
|
+
...require("./calcRelativeBaseBorrowRate.js"),
|
|
33
|
+
...require("./debt.js"),
|
|
34
|
+
...require("./getTimeToLiquidation.js"),
|
|
35
|
+
...require("./liquidationPrice.js"),
|
|
36
|
+
...require("./quotaUtils.js"),
|
|
37
|
+
...require("./sort.js")
|
|
38
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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 liquidationPrice_exports = {};
|
|
20
|
+
__export(liquidationPrice_exports, {
|
|
21
|
+
liquidationPrice: () => liquidationPrice
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(liquidationPrice_exports);
|
|
24
|
+
var import_sdk = require("../../../sdk/index.js");
|
|
25
|
+
function liquidationPrice({
|
|
26
|
+
liquidationThresholds,
|
|
27
|
+
debt,
|
|
28
|
+
underlyingToken,
|
|
29
|
+
targetToken,
|
|
30
|
+
assets,
|
|
31
|
+
tokensList
|
|
32
|
+
}) {
|
|
33
|
+
const underlyingDecimals = tokensList[underlyingToken]?.decimals || 18;
|
|
34
|
+
const { balance: underlyingBalance = 0n } = assets[underlyingToken] || {};
|
|
35
|
+
const ltUnderlying = liquidationThresholds[underlyingToken] || 0n;
|
|
36
|
+
const effectiveDebt = (debt - underlyingBalance * ltUnderlying / import_sdk.PERCENTAGE_FACTOR) * import_sdk.WAD / 10n ** BigInt(underlyingDecimals);
|
|
37
|
+
const targetDecimals = tokensList[targetToken]?.decimals || 18;
|
|
38
|
+
const { balance: targetBalance = 0n } = assets[targetToken] || {};
|
|
39
|
+
const effectiveTargetBalance = targetBalance * import_sdk.WAD / 10n ** BigInt(targetDecimals);
|
|
40
|
+
const lpLT = liquidationThresholds[targetToken] || 0n;
|
|
41
|
+
if (targetBalance <= 0n || lpLT <= 0n) return 0n;
|
|
42
|
+
return effectiveDebt * import_sdk.PRICE_DECIMALS * import_sdk.PERCENTAGE_FACTOR / (effectiveTargetBalance * lpLT);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
liquidationPrice
|
|
47
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
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 quotaUtils_exports = {};
|
|
20
|
+
__export(quotaUtils_exports, {
|
|
21
|
+
calcDefaultQuota: () => calcDefaultQuota,
|
|
22
|
+
calcQuotaUpdate: () => calcQuotaUpdate,
|
|
23
|
+
calcRecommendedQuota: () => calcRecommendedQuota,
|
|
24
|
+
roundUpQuota: () => roundUpQuota
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(quotaUtils_exports);
|
|
27
|
+
var import_sdk = require("../../../sdk/index.js");
|
|
28
|
+
var import_bigintMath = require("../bigintMath.js");
|
|
29
|
+
function roundUpQuota(quotaChange) {
|
|
30
|
+
return quotaChange !== import_sdk.MIN_INT96 ? quotaChange / import_sdk.PERCENTAGE_FACTOR * import_sdk.PERCENTAGE_FACTOR : quotaChange;
|
|
31
|
+
}
|
|
32
|
+
function calcRecommendedQuota({
|
|
33
|
+
amount,
|
|
34
|
+
debt,
|
|
35
|
+
lt,
|
|
36
|
+
quotaReserve
|
|
37
|
+
}) {
|
|
38
|
+
const recommendedBaseQuota = import_bigintMath.BigIntMath.min(
|
|
39
|
+
debt,
|
|
40
|
+
amount * lt / import_sdk.PERCENTAGE_FACTOR
|
|
41
|
+
);
|
|
42
|
+
const recommendedQuota = recommendedBaseQuota * (import_sdk.PERCENTAGE_FACTOR + quotaReserve) / import_sdk.PERCENTAGE_FACTOR;
|
|
43
|
+
return roundUpQuota(recommendedQuota);
|
|
44
|
+
}
|
|
45
|
+
function calcDefaultQuota({
|
|
46
|
+
amount,
|
|
47
|
+
lt,
|
|
48
|
+
quotaReserve
|
|
49
|
+
}) {
|
|
50
|
+
const recommendedBaseQuota = amount * lt / import_sdk.PERCENTAGE_FACTOR;
|
|
51
|
+
const recommendedQuota = recommendedBaseQuota * (import_sdk.PERCENTAGE_FACTOR + quotaReserve) / import_sdk.PERCENTAGE_FACTOR;
|
|
52
|
+
return roundUpQuota(recommendedQuota);
|
|
53
|
+
}
|
|
54
|
+
function calcQuotaUpdate(props) {
|
|
55
|
+
const { quotas, initialQuotas, maxDebt, allowedToSpend, allowedToObtain } = props;
|
|
56
|
+
const quotaDecrease = Object.keys(allowedToSpend).reduce((acc, token) => {
|
|
57
|
+
const ch = getSingleQuotaChange(token, 0n, props);
|
|
58
|
+
if (ch && ch.balance < 0) acc[ch.token] = ch;
|
|
59
|
+
return acc;
|
|
60
|
+
}, {});
|
|
61
|
+
const quotaCap = roundUpQuota(maxDebt * 2n);
|
|
62
|
+
const quotaBought = Object.values(initialQuotas).reduce(
|
|
63
|
+
(sum, q) => sum + roundUpQuota(q?.quota || 0n),
|
|
64
|
+
0n
|
|
65
|
+
);
|
|
66
|
+
const quotaReduced = Object.values(quotaDecrease).reduce((sum, q) => {
|
|
67
|
+
const quotaBalance = q.balance || 0n;
|
|
68
|
+
const safeBalance = quotaBalance === import_sdk.MIN_INT96 ? import_bigintMath.BigIntMath.neg(roundUpQuota(initialQuotas[q.token]?.quota || 0n)) : quotaBalance;
|
|
69
|
+
return sum + safeBalance;
|
|
70
|
+
}, 0n);
|
|
71
|
+
const maxQuotaIncrease = roundUpQuota(
|
|
72
|
+
import_bigintMath.BigIntMath.max(quotaCap - (quotaBought + quotaReduced), 0n)
|
|
73
|
+
);
|
|
74
|
+
const quotaIncrease = Object.keys(allowedToObtain).reduce((acc, token) => {
|
|
75
|
+
const ch = getSingleQuotaChange(token, maxQuotaIncrease, props);
|
|
76
|
+
if (ch && ch.balance > 0) acc[ch.token] = ch;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
const quotaChange = {
|
|
80
|
+
...quotaDecrease,
|
|
81
|
+
...quotaIncrease
|
|
82
|
+
};
|
|
83
|
+
const desiredQuota = Object.values(quotas).reduce(
|
|
84
|
+
(acc, cmQuota) => {
|
|
85
|
+
const { token, isActive } = cmQuota;
|
|
86
|
+
const { quota: initialQuota = 0n } = initialQuotas[token] || {};
|
|
87
|
+
if (!isActive) {
|
|
88
|
+
acc[token] = {
|
|
89
|
+
balance: initialQuota,
|
|
90
|
+
token
|
|
91
|
+
};
|
|
92
|
+
} else {
|
|
93
|
+
const change = quotaChange[token]?.balance || 0n;
|
|
94
|
+
const quotaAfter = change === import_sdk.MIN_INT96 ? 0n : initialQuota + change;
|
|
95
|
+
acc[token] = {
|
|
96
|
+
balance: quotaAfter,
|
|
97
|
+
token
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return acc;
|
|
101
|
+
},
|
|
102
|
+
{}
|
|
103
|
+
);
|
|
104
|
+
return {
|
|
105
|
+
desiredQuota,
|
|
106
|
+
quotaDecrease: Object.values(quotaDecrease),
|
|
107
|
+
quotaIncrease: Object.values(quotaIncrease)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function getSingleQuotaChange(token, unsafeMaxQuotaIncrease, props) {
|
|
111
|
+
const { isActive = false } = props.quotas[token] || {};
|
|
112
|
+
const { quota: unsafeInitialQuota = 0n } = props.initialQuotas[token] || {};
|
|
113
|
+
if (!isActive) {
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
const assetAfter = props.assetsAfterUpdate[token];
|
|
117
|
+
const { amountInTarget = 0n } = assetAfter || {};
|
|
118
|
+
const lt = props.liquidationThresholds[token] || 0n;
|
|
119
|
+
const maxQuotaIncrease = roundUpQuota(unsafeMaxQuotaIncrease);
|
|
120
|
+
const initialQuota = roundUpQuota(unsafeInitialQuota);
|
|
121
|
+
const defaultQuota = props.calcModification?.type === "recommendedQuota" && props.calcModification.debt > 0 ? calcRecommendedQuota({
|
|
122
|
+
lt,
|
|
123
|
+
quotaReserve: props.quotaReserve,
|
|
124
|
+
amount: amountInTarget,
|
|
125
|
+
debt: props.calcModification.debt
|
|
126
|
+
}) : calcDefaultQuota({
|
|
127
|
+
lt,
|
|
128
|
+
quotaReserve: props.quotaReserve,
|
|
129
|
+
amount: amountInTarget
|
|
130
|
+
});
|
|
131
|
+
const unsafeQuotaChange = roundUpQuota(defaultQuota - initialQuota);
|
|
132
|
+
const quotaChange = unsafeQuotaChange > 0 ? import_bigintMath.BigIntMath.min(maxQuotaIncrease, unsafeQuotaChange) : unsafeQuotaChange < 0 && import_bigintMath.BigIntMath.abs(unsafeQuotaChange) >= initialQuota ? import_sdk.MIN_INT96 : unsafeQuotaChange;
|
|
133
|
+
const correctIncrease = assetAfter && props.allowedToObtain[token] && quotaChange > 0;
|
|
134
|
+
const correctDecrease = assetAfter && props.allowedToSpend[token] && quotaChange < 0;
|
|
135
|
+
if (correctIncrease || correctDecrease) {
|
|
136
|
+
return {
|
|
137
|
+
balance: quotaChange,
|
|
138
|
+
token
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
calcDefaultQuota,
|
|
146
|
+
calcQuotaUpdate,
|
|
147
|
+
calcRecommendedQuota,
|
|
148
|
+
roundUpQuota
|
|
149
|
+
});
|
|
@@ -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 sort_exports = {};
|
|
20
|
+
__export(sort_exports, {
|
|
21
|
+
amountAbcComparator: () => amountAbcComparator,
|
|
22
|
+
assetComparator: () => assetComparator,
|
|
23
|
+
sortAssets: () => sortAssets,
|
|
24
|
+
sortBalances: () => sortBalances,
|
|
25
|
+
tokensAbcComparator: () => tokensAbcComparator
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(sort_exports);
|
|
28
|
+
var import_sdk = require("../../../sdk/index.js");
|
|
29
|
+
var import_priceMath = require("../priceMath.js");
|
|
30
|
+
function sortBalances(balances, prices, tokens) {
|
|
31
|
+
return Object.entries(balances).sort(
|
|
32
|
+
([addr1, amount1], [addr2, amount2]) => {
|
|
33
|
+
return assetComparator(
|
|
34
|
+
{
|
|
35
|
+
token: addr1,
|
|
36
|
+
balance: amount1
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
token: addr2,
|
|
40
|
+
balance: amount2
|
|
41
|
+
},
|
|
42
|
+
prices,
|
|
43
|
+
prices,
|
|
44
|
+
tokens,
|
|
45
|
+
tokens
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function sortAssets(balances, prices, tokens) {
|
|
51
|
+
return [...balances].sort(
|
|
52
|
+
(t1, t2) => assetComparator(t1, t2, prices, prices, tokens, tokens)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function assetComparator(t1, t2, prices1, prices2, tokens1, tokens2) {
|
|
56
|
+
const addr1Lc = t1.token.toLowerCase();
|
|
57
|
+
const addr2Lc = t2.token.toLowerCase();
|
|
58
|
+
const token1 = tokens1?.[addr1Lc];
|
|
59
|
+
const token2 = tokens2?.[addr2Lc];
|
|
60
|
+
const price1 = prices1?.[addr1Lc] || import_sdk.PRICE_DECIMALS;
|
|
61
|
+
const price2 = prices2?.[addr2Lc] || import_sdk.PRICE_DECIMALS;
|
|
62
|
+
const totalPrice1 = import_priceMath.PriceUtils.calcTotalPrice(
|
|
63
|
+
price1,
|
|
64
|
+
t1.balance,
|
|
65
|
+
token1?.decimals
|
|
66
|
+
);
|
|
67
|
+
const totalPrice2 = import_priceMath.PriceUtils.calcTotalPrice(
|
|
68
|
+
price2,
|
|
69
|
+
t2.balance,
|
|
70
|
+
token2?.decimals
|
|
71
|
+
);
|
|
72
|
+
if (totalPrice1 === totalPrice2) {
|
|
73
|
+
return t1.balance === t2.balance ? tokensAbcComparator(token1, token2) : amountAbcComparator(t1.balance, t2.balance);
|
|
74
|
+
}
|
|
75
|
+
return amountAbcComparator(totalPrice1, totalPrice2);
|
|
76
|
+
}
|
|
77
|
+
function tokensAbcComparator(t1, t2) {
|
|
78
|
+
const { symbol: symbol1 = "" } = t1 || {};
|
|
79
|
+
const { symbol: symbol2 = "" } = t2 || {};
|
|
80
|
+
const symbol1LC = symbol1.toLowerCase();
|
|
81
|
+
const symbol2LC = symbol2.toLowerCase();
|
|
82
|
+
if (symbol1LC === symbol2LC) return 0;
|
|
83
|
+
return symbol1LC > symbol2LC ? 1 : -1;
|
|
84
|
+
}
|
|
85
|
+
function amountAbcComparator(t1, t2) {
|
|
86
|
+
return t1 > t2 ? -1 : 1;
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
amountAbcComparator,
|
|
91
|
+
assetComparator,
|
|
92
|
+
sortAssets,
|
|
93
|
+
sortBalances,
|
|
94
|
+
tokensAbcComparator
|
|
95
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -18,11 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var endpoints_exports = {};
|
|
20
20
|
__export(endpoints_exports, {
|
|
21
|
-
GearboxBackendApi: () => GearboxBackendApi
|
|
22
|
-
URLApi: () => URLApi
|
|
21
|
+
GearboxBackendApi: () => GearboxBackendApi
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(endpoints_exports);
|
|
25
|
-
var
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
26
25
|
const CHARTS_BACKEND_ADDRESS = "https://charts-server.fly.dev";
|
|
27
26
|
const STATIC_TOKEN = "https://static.gearbox.finance/tokens/";
|
|
28
27
|
class GearboxBackendApi {
|
|
@@ -31,8 +30,8 @@ class GearboxBackendApi {
|
|
|
31
30
|
static getChartsUrl = (url, chainId, options = { params: {} }, priceSource) => {
|
|
32
31
|
const domain = CHARTS_BACKEND_ADDRESS;
|
|
33
32
|
const priceSourceArr = priceSource ? [priceSource] : [];
|
|
34
|
-
const isMain = (0,
|
|
35
|
-
const relativePath =
|
|
33
|
+
const isMain = (0, import_sdk.isSupportedNetwork)(chainId);
|
|
34
|
+
const relativePath = getRelativeUrl(
|
|
36
35
|
url,
|
|
37
36
|
isMain ? {
|
|
38
37
|
...options,
|
|
@@ -51,21 +50,16 @@ class GearboxBackendApi {
|
|
|
51
50
|
const url = `https://dm.gearbox.finance/${network.toLowerCase()}_${root}.json`;
|
|
52
51
|
return url;
|
|
53
52
|
};
|
|
54
|
-
static apyAllRewards = () =>
|
|
53
|
+
static apyAllRewards = () => getRelativeUrl(
|
|
55
54
|
"https://state-cache.gearbox.foundation/apy-server/latest.json"
|
|
56
55
|
);
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&");
|
|
64
|
-
return [url, ...paramsString ? [paramsString] : []].join("?");
|
|
65
|
-
};
|
|
66
|
-
}
|
|
57
|
+
const getRelativeUrl = (url, options) => {
|
|
58
|
+
const { params = {} } = options || {};
|
|
59
|
+
const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&");
|
|
60
|
+
return [url, ...paramsString ? [paramsString] : []].join("?");
|
|
61
|
+
};
|
|
67
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
63
|
0 && (module.exports = {
|
|
69
|
-
GearboxBackendApi
|
|
70
|
-
URLApi
|
|
64
|
+
GearboxBackendApi
|
|
71
65
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var utils_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(utils_exports);
|
|
18
|
+
__reExport(utils_exports, require("./assetsMath.js"), module.exports);
|
|
19
|
+
__reExport(utils_exports, require("./bigintMath.js"), module.exports);
|
|
20
|
+
__reExport(utils_exports, require("./creditAccount/index.js"), module.exports);
|
|
21
|
+
__reExport(utils_exports, require("./endpoints.js"), module.exports);
|
|
22
|
+
__reExport(utils_exports, require("./priceMath.js"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./assetsMath.js"),
|
|
26
|
+
...require("./bigintMath.js"),
|
|
27
|
+
...require("./creditAccount/index.js"),
|
|
28
|
+
...require("./endpoints.js"),
|
|
29
|
+
...require("./priceMath.js")
|
|
30
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
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 priceMath_exports = {};
|
|
20
|
+
__export(priceMath_exports, {
|
|
21
|
+
PriceUtils: () => PriceUtils
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(priceMath_exports);
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
class PriceUtils {
|
|
26
|
+
/**
|
|
27
|
+
* This class is intentionally non-instantiable.
|
|
28
|
+
*/
|
|
29
|
+
constructor() {
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calculates normalized total value for a token amount at a given price.
|
|
33
|
+
*
|
|
34
|
+
* Formula:
|
|
35
|
+
* `(amount * WAD * price) / 10^decimals / PRICE_DECIMALS`
|
|
36
|
+
*
|
|
37
|
+
* @param price Token unit price in `PRICE_DECIMALS` precision.
|
|
38
|
+
* @param amount Token amount in raw token units.
|
|
39
|
+
* @param decimals Token decimals used to normalize `amount` (defaults to `18`).
|
|
40
|
+
* @returns Total value in WAD-normalized units.
|
|
41
|
+
*/
|
|
42
|
+
static calcTotalPrice = (price, amount, decimals = 18) => amount * import_sdk.WAD * price / 10n ** BigInt(decimals) / import_sdk.PRICE_DECIMALS;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a normalized monetary value into target token amount by price.
|
|
45
|
+
*
|
|
46
|
+
* Formula:
|
|
47
|
+
* `(totalMoney * 10^targetDecimals * PRICE_DECIMALS) / targetPrice / WAD`
|
|
48
|
+
*
|
|
49
|
+
* Safety behavior:
|
|
50
|
+
* - returns `0n` when `targetPrice <= 0n` to avoid invalid division
|
|
51
|
+
*
|
|
52
|
+
* @param totalMoney Value to convert, expected in WAD-normalized units.
|
|
53
|
+
* @param target Conversion target configuration:
|
|
54
|
+
* - `price`: target token unit price in `PRICE_DECIMALS` precision
|
|
55
|
+
* - `decimals`: target token decimals (defaults to `18`)
|
|
56
|
+
* @returns Target token amount in raw token units.
|
|
57
|
+
*/
|
|
58
|
+
static convertByPrice(totalMoney, { price: targetPrice, decimals: targetDecimals = 18 }) {
|
|
59
|
+
if (targetPrice <= 0n) return 0n;
|
|
60
|
+
return totalMoney * 10n ** BigInt(targetDecimals) * import_sdk.PRICE_DECIMALS / targetPrice / import_sdk.WAD;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
PriceUtils
|
|
66
|
+
});
|
|
@@ -31,8 +31,8 @@ var import_instance_manager = require("./instance-manager.js");
|
|
|
31
31
|
var import_market_configurator_factory = require("./market-configurator-factory.js");
|
|
32
32
|
const abi = import_crossChainMultisig.crossChainMultisigAbi;
|
|
33
33
|
class CrossChainMultisigContract extends import_sdk.BaseContract {
|
|
34
|
-
constructor(addr,
|
|
35
|
-
super({
|
|
34
|
+
constructor(addr, register) {
|
|
35
|
+
super({ register }, { abi, addr, name: "CrossChainMultisig" });
|
|
36
36
|
}
|
|
37
37
|
async getExecutedBatches(fromBlock, toBlock) {
|
|
38
38
|
const events = await this.getEvents("ExecuteBatch", fromBlock, toBlock);
|
|
@@ -185,7 +185,7 @@ class CrossChainMultisigContract extends import_sdk.BaseContract {
|
|
|
185
185
|
case import_addresses.Addresses.INSTANCE_MANAGER.toLowerCase(): {
|
|
186
186
|
const instanceManager = new import_instance_manager.InstanceManagerContract(
|
|
187
187
|
target,
|
|
188
|
-
this.
|
|
188
|
+
this.register
|
|
189
189
|
);
|
|
190
190
|
return instanceManager.parseFunctionData(calldata);
|
|
191
191
|
}
|
|
@@ -38,8 +38,8 @@ var import_router = require("./router/index.js");
|
|
|
38
38
|
var import_treasury_splitter = require("./treasury-splitter.js");
|
|
39
39
|
const abi = import_instanceManager.instanceManagerAbi;
|
|
40
40
|
class InstanceManagerContract extends import_sdk.BaseContract {
|
|
41
|
-
constructor(addr,
|
|
42
|
-
super({
|
|
41
|
+
constructor(addr, register) {
|
|
42
|
+
super({ register }, { abi, addr, name: "InstanceManager" });
|
|
43
43
|
}
|
|
44
44
|
// TODO:
|
|
45
45
|
#decodeFunctionData(target, calldata) {
|
|
@@ -69,12 +69,6 @@ class MellowDepositQueueAdapterContract extends import_AbstractAdapter.AbstractA
|
|
|
69
69
|
referral: this.#referral ? this.labelAddress(this.#referral) : void 0
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
/** Legacy adapter not present in integrations-v3. */
|
|
73
|
-
classifyLegacyOperation(_parsed, _transfers) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
72
|
}
|
|
79
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
74
|
0 && (module.exports = {
|
|
@@ -61,12 +61,6 @@ class MellowRedeemQueueAdapterContract extends import_AbstractAdapter.AbstractAd
|
|
|
61
61
|
phantomToken: this.#phantomToken ? this.labelAddress(this.#phantomToken) : void 0
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
/** Legacy adapter not present in integrations-v3. */
|
|
65
|
-
classifyLegacyOperation(_parsed, _transfers) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
`classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
64
|
}
|
|
71
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
66
|
0 && (module.exports = {
|
|
@@ -153,8 +153,6 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
153
153
|
if (options.gasLimit !== null) {
|
|
154
154
|
this.gasLimit = options.gasLimit || 550000000n;
|
|
155
155
|
}
|
|
156
|
-
Object.assign(this, import_base.ChainContractsRegister.for(this.client, this.logger));
|
|
157
|
-
this.resetContracts();
|
|
158
156
|
}
|
|
159
157
|
async #attach(opts) {
|
|
160
158
|
const {
|
|
@@ -67,8 +67,11 @@ class BaseContract extends import_Construct.Construct {
|
|
|
67
67
|
this.contractType = (0, import_utils.bytes32ToString)(this.contractType);
|
|
68
68
|
}
|
|
69
69
|
this.name = args.name || this.contractType || this.address || this.constructor.name;
|
|
70
|
-
this.
|
|
71
|
-
|
|
70
|
+
const register = this.safeGetRegister();
|
|
71
|
+
if (register) {
|
|
72
|
+
register.setContract(this.address, this);
|
|
73
|
+
register.setAddressLabel(this.address, this.name);
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
stateHuman(_ = true) {
|
|
74
77
|
return {
|
|
@@ -25,16 +25,6 @@ var import_addresses = require("../constants/addresses.js");
|
|
|
25
25
|
var import_AddressMap = require("../utils/AddressMap.js");
|
|
26
26
|
var import_TokensMeta = require("./TokensMeta.js");
|
|
27
27
|
class ChainContractsRegister {
|
|
28
|
-
static #chains = /* @__PURE__ */ new Map();
|
|
29
|
-
static for(client, logger) {
|
|
30
|
-
const chainId = client.chain.id;
|
|
31
|
-
let result = ChainContractsRegister.#chains.get(chainId);
|
|
32
|
-
if (!result) {
|
|
33
|
-
result = new ChainContractsRegister(client, logger);
|
|
34
|
-
ChainContractsRegister.#chains.set(chainId, result);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
28
|
contracts = new import_AddressMap.AddressMap(
|
|
39
29
|
[],
|
|
40
30
|
"contracts"
|
|
@@ -55,7 +45,9 @@ class ChainContractsRegister {
|
|
|
55
45
|
this.logger?.debug(
|
|
56
46
|
`resetting contacts register with ${this.contracts.size} contracts`
|
|
57
47
|
);
|
|
48
|
+
this.labels.clear();
|
|
58
49
|
this.contracts.clear();
|
|
50
|
+
this.tokensMeta.reset();
|
|
59
51
|
}
|
|
60
52
|
getContract(address) {
|
|
61
53
|
return this.contracts.get(address);
|