@gearbox-protocol/sdk 4.2.0-next.3 → 5.0.0-next.2
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/bots/BotsPlugin.js +2 -2
- package/dist/cjs/dev/calcLiquidatableLTs.js +5 -1
- package/dist/cjs/dev/index.js +1 -3
- package/dist/cjs/dev/ltUtils.js +2 -2
- package/dist/cjs/sdk/GearboxSDK.js +2 -5
- package/dist/cjs/sdk/accounts/CreditAccountsService.js +10 -5
- package/dist/cjs/sdk/base/BaseContract.js +0 -1
- package/dist/cjs/sdk/constants/index.js +3 -1
- package/dist/cjs/sdk/{utils/version.js → constants/versions.js} +18 -7
- package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
- package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +3 -3
- package/dist/cjs/sdk/gauges/GaugeStakingService.js +4 -1
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/market/MarketSuite.js +1 -5
- package/dist/cjs/sdk/market/credit/createCreditConfigurator.js +3 -2
- package/dist/cjs/sdk/market/credit/createCreditFacade.js +3 -2
- package/dist/cjs/sdk/market/credit/createCreditManager.js +3 -2
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +55 -49
- package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
- package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
- package/dist/cjs/sdk/market/oracle/createPriceOracle.js +29 -9
- package/dist/cjs/sdk/market/pool/createPool.js +3 -2
- package/dist/cjs/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -1
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +5 -5
- package/dist/cjs/sdk/router/createRouter.js +3 -2
- package/dist/cjs/sdk/utils/index.js +1 -3
- package/dist/cjs/zappers/ZappersPlugin.js +2 -2
- package/dist/esm/bots/BotsPlugin.js +4 -3
- package/dist/esm/dev/calcLiquidatableLTs.js +5 -1
- package/dist/esm/dev/index.js +0 -1
- package/dist/esm/dev/ltUtils.js +9 -3
- package/dist/esm/sdk/GearboxSDK.js +6 -6
- package/dist/esm/sdk/accounts/CreditAccountsService.js +12 -6
- package/dist/esm/sdk/base/BaseContract.js +0 -1
- package/dist/esm/sdk/constants/index.js +1 -0
- package/dist/esm/sdk/constants/versions.js +18 -0
- package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
- package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/esm/sdk/gauges/GaugeStakingService.js +5 -2
- package/dist/esm/sdk/market/MarketRegister.js +7 -3
- package/dist/esm/sdk/market/MarketSuite.js +2 -6
- package/dist/esm/sdk/market/credit/createCreditConfigurator.js +3 -2
- package/dist/esm/sdk/market/credit/createCreditFacade.js +3 -2
- package/dist/esm/sdk/market/credit/createCreditManager.js +3 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +60 -50
- package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
- package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
- package/dist/esm/sdk/market/oracle/createPriceOracle.js +28 -8
- package/dist/esm/sdk/market/pool/createPool.js +3 -2
- package/dist/esm/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -3
- package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -2
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +6 -6
- package/dist/esm/sdk/router/createRouter.js +3 -2
- package/dist/esm/sdk/utils/index.js +0 -1
- package/dist/esm/zappers/ZappersPlugin.js +4 -3
- package/dist/types/dev/index.d.ts +0 -1
- package/dist/types/sdk/constants/index.d.ts +1 -0
- package/dist/types/sdk/constants/versions.d.ts +9 -0
- package/dist/types/sdk/core/address-provider/AbstractAddressProviderContract.d.ts +3 -2
- package/dist/types/sdk/core/address-provider/types.d.ts +3 -2
- package/dist/types/sdk/market/MarketSuite.d.ts +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +28 -684
- package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +1 -1
- package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/oracle/createPriceOracle.d.ts +14 -3
- package/dist/types/sdk/market/oracle/types.d.ts +97 -6
- package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +3 -2
- package/dist/types/sdk/utils/index.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/dev/PriceFeedStore.js +0 -93
- package/dist/esm/dev/PriceFeedStore.js +0 -74
- package/dist/esm/sdk/utils/version.js +0 -10
- package/dist/types/dev/PriceFeedStore.d.ts +0 -10
- package/dist/types/sdk/utils/version.d.ts +0 -2
|
@@ -58,9 +58,9 @@ class BotsPlugin extends import_sdk.SDKConstruct {
|
|
|
58
58
|
}
|
|
59
59
|
async #load() {
|
|
60
60
|
this.#botsByMarket.clear();
|
|
61
|
-
const pcAddr = this.sdk.addressProvider.
|
|
61
|
+
const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
|
|
62
62
|
import_sdk.AP_PERIPHERY_COMPRESSOR,
|
|
63
|
-
|
|
63
|
+
import_sdk.VERSION_RANGE_310
|
|
64
64
|
);
|
|
65
65
|
this.#logger?.debug(`loading bots with periphery compressor ${pcAddr}`);
|
|
66
66
|
const mcs = this.sdk.marketRegister.marketConfigurators.map(
|
|
@@ -30,7 +30,11 @@ async function calcLiquidatableLTs(sdk, ca, factor = 9990n, logger) {
|
|
|
30
30
|
return balance > minBalance;
|
|
31
31
|
}).map((t) => {
|
|
32
32
|
const { token, balance } = t;
|
|
33
|
-
const balanceU = market.priceOracle.
|
|
33
|
+
const balanceU = market.priceOracle.convert(
|
|
34
|
+
token,
|
|
35
|
+
ca.underlying,
|
|
36
|
+
balance
|
|
37
|
+
);
|
|
34
38
|
const lt = BigInt(cm.creditManager.liquidationThresholds.mustGet(token));
|
|
35
39
|
return {
|
|
36
40
|
token,
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -23,7 +23,6 @@ __reExport(dev_exports, require("./createTransport.js"), module.exports);
|
|
|
23
23
|
__reExport(dev_exports, require("./detectChain.js"), module.exports);
|
|
24
24
|
__reExport(dev_exports, require("./ltUtils.js"), module.exports);
|
|
25
25
|
__reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
|
|
26
|
-
__reExport(dev_exports, require("./PriceFeedStore.js"), module.exports);
|
|
27
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
27
|
0 && (module.exports = {
|
|
29
28
|
...require("./AccountOpener.js"),
|
|
@@ -33,6 +32,5 @@ __reExport(dev_exports, require("./PriceFeedStore.js"), module.exports);
|
|
|
33
32
|
...require("./createTransport.js"),
|
|
34
33
|
...require("./detectChain.js"),
|
|
35
34
|
...require("./ltUtils.js"),
|
|
36
|
-
...require("./migrateFaucet.js")
|
|
37
|
-
...require("./PriceFeedStore.js")
|
|
35
|
+
...require("./migrateFaucet.js")
|
|
38
36
|
});
|
package/dist/cjs/dev/ltUtils.js
CHANGED
|
@@ -45,9 +45,9 @@ async function setLTs(anvil, cm, newLTs, logger) {
|
|
|
45
45
|
}
|
|
46
46
|
async function setLTZero(anvil, cm, logger) {
|
|
47
47
|
const v = Number(cm.creditConfigurator.baseParams.version);
|
|
48
|
-
if (
|
|
48
|
+
if ((0, import_sdk.isV300)(v)) {
|
|
49
49
|
await setLTZeroV300(anvil, cm, logger);
|
|
50
|
-
} else if (
|
|
50
|
+
} else if ((0, import_sdk.isV310)(v)) {
|
|
51
51
|
await setLTZeroV310(anvil, cm, logger);
|
|
52
52
|
} else {
|
|
53
53
|
throw new Error(
|
|
@@ -485,11 +485,8 @@ class GearboxSDK {
|
|
|
485
485
|
facadeAddr = cm.creditFacade.address;
|
|
486
486
|
}
|
|
487
487
|
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
488
|
-
const routerRange = facadeV
|
|
489
|
-
const routerEntry = this.addressProvider.
|
|
490
|
-
import_constants.AP_ROUTER,
|
|
491
|
-
routerRange
|
|
492
|
-
);
|
|
488
|
+
const routerRange = (0, import_constants.isV310)(facadeV) ? import_constants.VERSION_RANGE_310 : import_constants.VERSION_RANGE_300;
|
|
489
|
+
const routerEntry = this.addressProvider.getLatest(import_constants.AP_ROUTER, routerRange);
|
|
493
490
|
if (!routerEntry) {
|
|
494
491
|
throw new Error(
|
|
495
492
|
`router not found for facade v ${facadeV} at ${facadeAddr}`
|
|
@@ -39,8 +39,9 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
39
39
|
#logger;
|
|
40
40
|
constructor(sdk, options) {
|
|
41
41
|
super(sdk);
|
|
42
|
-
[this.#compressor] = sdk.addressProvider.
|
|
43
|
-
import_constants.AP_CREDIT_ACCOUNT_COMPRESSOR
|
|
42
|
+
[this.#compressor] = sdk.addressProvider.mustGetLatest(
|
|
43
|
+
import_constants.AP_CREDIT_ACCOUNT_COMPRESSOR,
|
|
44
|
+
import_constants.VERSION_RANGE_310
|
|
44
45
|
);
|
|
45
46
|
this.#batchSize = options?.batchSize;
|
|
46
47
|
this.#logger = (0, import_utils.childLogger)("CreditAccountsService", sdk.logger);
|
|
@@ -1176,11 +1177,15 @@ class CreditAccountsService extends import_base.SDKConstruct {
|
|
|
1176
1177
|
return this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
|
|
1177
1178
|
}
|
|
1178
1179
|
get rewardCompressor() {
|
|
1179
|
-
return this.sdk.addressProvider.
|
|
1180
|
+
return this.sdk.addressProvider.mustGetLatest(
|
|
1181
|
+
import_constants.AP_REWARDS_COMPRESSOR,
|
|
1182
|
+
import_constants.VERSION_RANGE_310
|
|
1183
|
+
)[0];
|
|
1180
1184
|
}
|
|
1181
1185
|
get peripheryCompressor() {
|
|
1182
|
-
return this.sdk.addressProvider.
|
|
1183
|
-
import_constants.AP_PERIPHERY_COMPRESSOR
|
|
1186
|
+
return this.sdk.addressProvider.mustGetLatest(
|
|
1187
|
+
import_constants.AP_PERIPHERY_COMPRESSOR,
|
|
1188
|
+
import_constants.VERSION_RANGE_310
|
|
1184
1189
|
)[0];
|
|
1185
1190
|
}
|
|
1186
1191
|
}
|
|
@@ -21,6 +21,7 @@ __reExport(constants_exports, require("./bot-permissions.js"), module.exports);
|
|
|
21
21
|
__reExport(constants_exports, require("./math.js"), module.exports);
|
|
22
22
|
__reExport(constants_exports, require("./networks.js"), module.exports);
|
|
23
23
|
__reExport(constants_exports, require("./periphery.js"), module.exports);
|
|
24
|
+
__reExport(constants_exports, require("./versions.js"), module.exports);
|
|
24
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
26
|
0 && (module.exports = {
|
|
26
27
|
...require("./address-provider.js"),
|
|
@@ -28,5 +29,6 @@ __reExport(constants_exports, require("./periphery.js"), module.exports);
|
|
|
28
29
|
...require("./bot-permissions.js"),
|
|
29
30
|
...require("./math.js"),
|
|
30
31
|
...require("./networks.js"),
|
|
31
|
-
...require("./periphery.js")
|
|
32
|
+
...require("./periphery.js"),
|
|
33
|
+
...require("./versions.js")
|
|
32
34
|
});
|
|
@@ -16,20 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var versions_exports = {};
|
|
20
|
+
__export(versions_exports, {
|
|
21
|
+
VERSION_RANGE_300: () => VERSION_RANGE_300,
|
|
22
|
+
VERSION_RANGE_310: () => VERSION_RANGE_310,
|
|
21
23
|
isV300: () => isV300,
|
|
22
|
-
isV310: () => isV310
|
|
24
|
+
isV310: () => isV310,
|
|
25
|
+
isVersionRange: () => isVersionRange
|
|
23
26
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(versions_exports);
|
|
28
|
+
const VERSION_RANGE_300 = [300, 309];
|
|
29
|
+
const VERSION_RANGE_310 = [310, 319];
|
|
25
30
|
function isV300(version) {
|
|
26
|
-
return version
|
|
31
|
+
return isVersionRange(version, VERSION_RANGE_300);
|
|
27
32
|
}
|
|
28
33
|
function isV310(version) {
|
|
29
|
-
return version
|
|
34
|
+
return isVersionRange(version, VERSION_RANGE_310);
|
|
35
|
+
}
|
|
36
|
+
function isVersionRange(version, range) {
|
|
37
|
+
return Number(version) >= range[0] && Number(version) <= range[1];
|
|
30
38
|
}
|
|
31
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
40
|
0 && (module.exports = {
|
|
41
|
+
VERSION_RANGE_300,
|
|
42
|
+
VERSION_RANGE_310,
|
|
33
43
|
isV300,
|
|
34
|
-
isV310
|
|
44
|
+
isV310,
|
|
45
|
+
isVersionRange
|
|
35
46
|
});
|
|
@@ -27,7 +27,6 @@ var import_constants = require("../../constants/index.js");
|
|
|
27
27
|
var import_mappers = require("../../utils/mappers.js");
|
|
28
28
|
class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
29
29
|
#addresses = {};
|
|
30
|
-
#latest = {};
|
|
31
30
|
constructor(sdk, args, addresses = {}) {
|
|
32
31
|
super(sdk, args);
|
|
33
32
|
this.#addresses = addresses;
|
|
@@ -38,9 +37,6 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
38
37
|
this.#addresses[k] = {};
|
|
39
38
|
}
|
|
40
39
|
this.#addresses[k][version] = address;
|
|
41
|
-
if (!this.#latest[k] || version > this.#latest[k]) {
|
|
42
|
-
this.#latest[k] = version;
|
|
43
|
-
}
|
|
44
40
|
this.logger?.debug(`Set address for ${k}@${version} to ${address}`);
|
|
45
41
|
}
|
|
46
42
|
getAddress(contract, version = import_constants.NO_VERSION) {
|
|
@@ -53,14 +49,7 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
53
49
|
}
|
|
54
50
|
return result;
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
const version = this.#latest[contract];
|
|
58
|
-
if (!version) {
|
|
59
|
-
throw new Error(`Latest version for ${contract} not found`);
|
|
60
|
-
}
|
|
61
|
-
return [this.getAddress(contract, version), version];
|
|
62
|
-
}
|
|
63
|
-
getLatestInRange(contract, range) {
|
|
52
|
+
getLatest(contract, range) {
|
|
64
53
|
const allVersions = this.#addresses[contract];
|
|
65
54
|
if (!allVersions) {
|
|
66
55
|
return void 0;
|
|
@@ -79,6 +68,13 @@ class AbstractAddressProviderContract extends import_base.BaseContract {
|
|
|
79
68
|
}
|
|
80
69
|
return [address, version];
|
|
81
70
|
}
|
|
71
|
+
mustGetLatest(contract, range) {
|
|
72
|
+
const result = this.getLatest(contract, range);
|
|
73
|
+
if (!result) {
|
|
74
|
+
throw new Error(`no address found for ${contract} in range ${range}`);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
82
78
|
get state() {
|
|
83
79
|
return {
|
|
84
80
|
baseParams: {
|
|
@@ -23,7 +23,7 @@ __export(createAddressProvider_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(createAddressProvider_exports);
|
|
25
25
|
var import_iVersion = require("../../../abi/iVersion.js");
|
|
26
|
-
var
|
|
26
|
+
var import_constants = require("../../constants/index.js");
|
|
27
27
|
var import_AddressProviderV300Contract = require("./AddressProviderV300Contract.js");
|
|
28
28
|
var import_AddressProviderV310Contract = require("./AddressProviderV310Contract.js");
|
|
29
29
|
async function createAddressProvider(sdk, address) {
|
|
@@ -39,10 +39,10 @@ function hydrateAddressProvider(sdk, state) {
|
|
|
39
39
|
return newAddressProvider(sdk, addr, Number(version), state.addresses);
|
|
40
40
|
}
|
|
41
41
|
function newAddressProvider(sdk, address, version, addresses) {
|
|
42
|
-
if ((0,
|
|
42
|
+
if ((0, import_constants.isV300)(version)) {
|
|
43
43
|
return new import_AddressProviderV300Contract.AddressProviderV300Contract(sdk, address, version, addresses);
|
|
44
44
|
}
|
|
45
|
-
if ((0,
|
|
45
|
+
if ((0, import_constants.isV310)(version)) {
|
|
46
46
|
return new import_AddressProviderV310Contract.AddressProviderV310Contract(sdk, address, version, addresses);
|
|
47
47
|
}
|
|
48
48
|
throw new Error(`unsupported address provider version: ${version}`);
|
|
@@ -28,7 +28,10 @@ class GaugeStakingService extends import_base.SDKConstruct {
|
|
|
28
28
|
#compressor;
|
|
29
29
|
constructor(sdk) {
|
|
30
30
|
super(sdk);
|
|
31
|
-
[this.#compressor] = this.sdk.addressProvider.
|
|
31
|
+
[this.#compressor] = this.sdk.addressProvider.mustGetLatest(
|
|
32
|
+
import_constants.AP_GAUGE_COMPRESSOR,
|
|
33
|
+
import_constants.VERSION_RANGE_310
|
|
34
|
+
);
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Returns voting state for wallet
|
|
@@ -85,9 +85,9 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
85
85
|
pools,
|
|
86
86
|
underlying: import_constants.ADDRESS_0X0
|
|
87
87
|
};
|
|
88
|
-
const marketCompressorAddress = this.sdk.addressProvider.
|
|
88
|
+
const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
|
|
89
89
|
import_constants.AP_MARKET_COMPRESSOR,
|
|
90
|
-
|
|
90
|
+
import_constants.VERSION_RANGE_310
|
|
91
91
|
);
|
|
92
92
|
let txs = [];
|
|
93
93
|
if (!ignoreUpdateablePrices) {
|
|
@@ -58,11 +58,7 @@ class MarketSuite extends import_base.SDKConstruct {
|
|
|
58
58
|
for (let i = 0; i < marketData.creditManagers.length; i++) {
|
|
59
59
|
this.creditManagers.push(new import_credit.CreditSuite(sdk, marketData, i));
|
|
60
60
|
}
|
|
61
|
-
this.priceOracle = (0, import_oracle.
|
|
62
|
-
sdk,
|
|
63
|
-
marketData.priceOracle,
|
|
64
|
-
marketData.pool.underlying
|
|
65
|
-
);
|
|
61
|
+
this.priceOracle = (0, import_oracle.getOrCreatePriceOracle)(sdk, marketData.priceOracle);
|
|
66
62
|
}
|
|
67
63
|
get dirty() {
|
|
68
64
|
return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
|
|
@@ -21,13 +21,14 @@ __export(createCreditConfigurator_exports, {
|
|
|
21
21
|
default: () => createCreditConfigurator
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createCreditConfigurator_exports);
|
|
24
|
+
var import_constants = require("../../constants/index.js");
|
|
24
25
|
var import_CreditConfiguratorV300Contract = require("./CreditConfiguratorV300Contract.js");
|
|
25
26
|
var import_CreditConfiguratorV310Contract = require("./CreditConfiguratorV310Contract.js");
|
|
26
27
|
function createCreditConfigurator(sdk, data) {
|
|
27
28
|
const v = data.creditConfigurator.baseParams.version;
|
|
28
|
-
if (
|
|
29
|
+
if ((0, import_constants.isV300)(v)) {
|
|
29
30
|
return new import_CreditConfiguratorV300Contract.CreditConfiguratorV300Contract(sdk, data);
|
|
30
|
-
} else if (
|
|
31
|
+
} else if ((0, import_constants.isV310)(v)) {
|
|
31
32
|
return new import_CreditConfiguratorV310Contract.CreditConfiguratorV310Contract(sdk, data);
|
|
32
33
|
}
|
|
33
34
|
throw new Error(`Unsupported credit configurator version: ${v}`);
|
|
@@ -21,13 +21,14 @@ __export(createCreditFacade_exports, {
|
|
|
21
21
|
default: () => createCreditFacade
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createCreditFacade_exports);
|
|
24
|
+
var import_constants = require("../../constants/index.js");
|
|
24
25
|
var import_CreditFacadeV300Contract = require("./CreditFacadeV300Contract.js");
|
|
25
26
|
var import_CreditFacadeV310Contract = require("./CreditFacadeV310Contract.js");
|
|
26
27
|
function createCreditFacade(sdk, data) {
|
|
27
28
|
const v = data.creditFacade.baseParams.version;
|
|
28
|
-
if (
|
|
29
|
+
if ((0, import_constants.isV300)(v)) {
|
|
29
30
|
return new import_CreditFacadeV300Contract.CreditFacadeV300Contract(sdk, data);
|
|
30
|
-
} else if (
|
|
31
|
+
} else if ((0, import_constants.isV310)(v)) {
|
|
31
32
|
return new import_CreditFacadeV310Contract.CreditFacadeV310Contract(sdk, data);
|
|
32
33
|
}
|
|
33
34
|
throw new Error(`Unsupported credit facade version: ${v}`);
|
|
@@ -21,13 +21,14 @@ __export(createCreditManager_exports, {
|
|
|
21
21
|
default: () => createCreditManager
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createCreditManager_exports);
|
|
24
|
+
var import_constants = require("../../constants/index.js");
|
|
24
25
|
var import_CreditManagerV300Contract = require("./CreditManagerV300Contract.js");
|
|
25
26
|
var import_CreditManagerV310Contract = require("./CreditManagerV310Contract.js");
|
|
26
27
|
function createCreditManager(sdk, data) {
|
|
27
28
|
const v = data.creditManager.baseParams.version;
|
|
28
|
-
if (
|
|
29
|
+
if ((0, import_constants.isV300)(v)) {
|
|
29
30
|
return new import_CreditManagerV300Contract.CreditManagerV300Contract(sdk, data);
|
|
30
|
-
} else if (
|
|
31
|
+
} else if ((0, import_constants.isV310)(v)) {
|
|
31
32
|
return new import_CreditManagerV310Contract.CreditManagerV310Contract(sdk, data);
|
|
32
33
|
}
|
|
33
34
|
throw new Error(`Unsupported credit manager version: ${v}`);
|
|
@@ -42,10 +42,6 @@ var import_pricefeeds = require("../pricefeeds/index.js");
|
|
|
42
42
|
var import_PriceFeedAnswerMap = __toESM(require("./PriceFeedAnswerMap.js"));
|
|
43
43
|
const ZERO_PRICE_FEED = (0, import_viem.stringToHex)("PRICE_FEED::ZERO", { size: 32 });
|
|
44
44
|
class PriceOracleBaseContract extends import_base.BaseContract {
|
|
45
|
-
/**
|
|
46
|
-
* Underlying token of market to which this price oracle belongs
|
|
47
|
-
*/
|
|
48
|
-
underlying;
|
|
49
45
|
/**
|
|
50
46
|
* Mapping Token => [PriceFeed Address, stalenessPeriod]
|
|
51
47
|
*/
|
|
@@ -71,12 +67,14 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
71
67
|
void 0,
|
|
72
68
|
"reservePrices"
|
|
73
69
|
);
|
|
74
|
-
#priceFeedTree =
|
|
75
|
-
|
|
70
|
+
#priceFeedTree = new import_utils.AddressMap(
|
|
71
|
+
void 0,
|
|
72
|
+
"priceFeedTree"
|
|
73
|
+
);
|
|
74
|
+
constructor(sdk, args, data) {
|
|
76
75
|
super(sdk, args);
|
|
77
|
-
this.underlying = underlying;
|
|
78
76
|
const { priceFeedMap, priceFeedTree } = data;
|
|
79
|
-
this.#loadState(priceFeedMap, priceFeedTree);
|
|
77
|
+
this.#loadState(priceFeedMap, priceFeedTree, true);
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
80
|
* Returns main and reserve price feeds for given tokens
|
|
@@ -98,7 +96,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
98
96
|
*/
|
|
99
97
|
async updatePriceFeeds() {
|
|
100
98
|
const updatables = [];
|
|
101
|
-
for (const node of this.#priceFeedTree) {
|
|
99
|
+
for (const node of this.#priceFeedTree.values()) {
|
|
102
100
|
if (node.updatable) {
|
|
103
101
|
updatables.push(this.sdk.priceFeeds.mustGet(node.baseParams.addr));
|
|
104
102
|
}
|
|
@@ -164,30 +162,19 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
164
162
|
}
|
|
165
163
|
/**
|
|
166
164
|
* Returns true if oracle's price feed tree contains given price feed
|
|
165
|
+
* This feed is not necessary connected to token, but can be a component of composite feed for some token
|
|
167
166
|
* @param priceFeed
|
|
168
167
|
* @returns
|
|
169
168
|
*/
|
|
170
169
|
usesPriceFeed(priceFeed) {
|
|
171
|
-
return this.#priceFeedTree.
|
|
172
|
-
(node) => node.baseParams.addr.toLowerCase() === priceFeed.toLowerCase()
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Tries to convert amount of token into underlying of current market
|
|
177
|
-
* @param token
|
|
178
|
-
* @param amount
|
|
179
|
-
* @param reserve
|
|
180
|
-
* @returns
|
|
181
|
-
*/
|
|
182
|
-
convertToUnderlying(token, amount, reserve = false) {
|
|
183
|
-
return this.convert(token, this.underlying, amount, reserve);
|
|
170
|
+
return this.#priceFeedTree.has(priceFeed);
|
|
184
171
|
}
|
|
185
172
|
/**
|
|
186
173
|
* Tries to convert amount of from one token to another, using latest known prices
|
|
187
174
|
* @param from
|
|
188
175
|
* @param to
|
|
189
176
|
* @param amount
|
|
190
|
-
* @param reserve
|
|
177
|
+
* @param reserve use reserve price feed instead of main
|
|
191
178
|
*/
|
|
192
179
|
convert(from, to, amount, reserve = false) {
|
|
193
180
|
if (from === to) {
|
|
@@ -202,9 +189,8 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
202
189
|
/**
|
|
203
190
|
* Tries to convert amount of token to USD, using latest known prices
|
|
204
191
|
* @param from
|
|
205
|
-
* @param to
|
|
206
192
|
* @param amount
|
|
207
|
-
* @param reserve
|
|
193
|
+
* @param reserve use reserve price feed instead of main
|
|
208
194
|
*/
|
|
209
195
|
convertToUSD(from, amount, reserve = false) {
|
|
210
196
|
const price = reserve ? this.reservePrice(from) : this.mainPrice(from);
|
|
@@ -215,7 +201,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
215
201
|
* Tries to convert amount of USD to token, using latest known prices
|
|
216
202
|
* @param to
|
|
217
203
|
* @param amount
|
|
218
|
-
* @param reserve
|
|
204
|
+
* @param reserve use reserve price feed instead of main
|
|
219
205
|
*/
|
|
220
206
|
convertFromUSD(to, amount, reserve = false) {
|
|
221
207
|
const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
|
|
@@ -224,26 +210,30 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
224
210
|
}
|
|
225
211
|
/**
|
|
226
212
|
* Loads new prices for this oracle from PriceFeedCompressor
|
|
227
|
-
*
|
|
213
|
+
* Will (re)create price feeds if needed
|
|
228
214
|
*/
|
|
229
215
|
async updatePrices() {
|
|
230
216
|
await this.sdk.marketRegister.updatePrices([this.address]);
|
|
231
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Paired method to updatePrices, helps to update prices on all oracles in one multicall
|
|
220
|
+
*/
|
|
232
221
|
syncStateMulticall() {
|
|
233
|
-
|
|
234
|
-
if (this.version
|
|
235
|
-
args
|
|
222
|
+
let args = [this.address];
|
|
223
|
+
if ((0, import_constants.isV300)(this.version)) {
|
|
224
|
+
args = [
|
|
225
|
+
args[0],
|
|
236
226
|
Array.from(
|
|
237
227
|
/* @__PURE__ */ new Set([
|
|
238
|
-
this.underlying,
|
|
239
228
|
...this.mainPriceFeeds.keys(),
|
|
240
229
|
...this.reservePriceFeeds.keys()
|
|
241
230
|
])
|
|
242
231
|
)
|
|
243
|
-
|
|
232
|
+
];
|
|
244
233
|
}
|
|
245
|
-
const [address] = this.sdk.addressProvider.
|
|
246
|
-
import_constants.AP_PRICE_FEED_COMPRESSOR
|
|
234
|
+
const [address] = this.sdk.addressProvider.mustGetLatest(
|
|
235
|
+
import_constants.AP_PRICE_FEED_COMPRESSOR,
|
|
236
|
+
import_constants.VERSION_RANGE_310
|
|
247
237
|
);
|
|
248
238
|
return {
|
|
249
239
|
call: {
|
|
@@ -254,25 +244,39 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
254
244
|
},
|
|
255
245
|
onResult: (resp) => {
|
|
256
246
|
const { priceFeedMap, priceFeedTree } = resp;
|
|
257
|
-
this.#loadState(priceFeedMap, priceFeedTree);
|
|
247
|
+
this.#loadState(priceFeedMap, priceFeedTree, true);
|
|
258
248
|
}
|
|
259
249
|
};
|
|
260
250
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Helper function to handle situation when we have multiple different compressor data entries for same oracle
|
|
253
|
+
* This happens in v300
|
|
254
|
+
*
|
|
255
|
+
* @deprecated should be unnecessary after full v310 migration (oracles will be unique)
|
|
256
|
+
* @param data
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
merge(data) {
|
|
260
|
+
const { priceFeedMap, priceFeedTree } = data;
|
|
261
|
+
this.#loadState(priceFeedMap, priceFeedTree, false);
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
#loadState(entries, tree, reset) {
|
|
265
|
+
if (reset) {
|
|
266
|
+
this.#priceFeedTree.clear();
|
|
267
|
+
this.mainPriceFeeds.clear();
|
|
268
|
+
this.reservePriceFeeds.clear();
|
|
269
|
+
this.mainPrices.clear();
|
|
270
|
+
this.reservePrices.clear();
|
|
271
|
+
}
|
|
267
272
|
for (const node of tree) {
|
|
273
|
+
this.#priceFeedTree.upsert(node.baseParams.addr, node);
|
|
268
274
|
this.sdk.priceFeeds.getOrCreate(node);
|
|
269
275
|
}
|
|
270
|
-
|
|
276
|
+
for (const entry of entries) {
|
|
271
277
|
const { token, priceFeed, reserve, stalenessPeriod } = entry;
|
|
272
278
|
const ref = new import_pricefeeds.PriceFeedRef(this.sdk, priceFeed, stalenessPeriod);
|
|
273
|
-
const node = this.#priceFeedTree.
|
|
274
|
-
(n) => n.baseParams.addr === priceFeed
|
|
275
|
-
);
|
|
279
|
+
const node = this.#priceFeedTree.get(priceFeed);
|
|
276
280
|
const price = node?.answer?.price;
|
|
277
281
|
const priceFeedType = node?.baseParams.contractType;
|
|
278
282
|
if (reserve) {
|
|
@@ -289,7 +293,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
289
293
|
}
|
|
290
294
|
}
|
|
291
295
|
this.#labelPriceFeed(priceFeed, reserve ? "Reserve" : "Main", token);
|
|
292
|
-
}
|
|
296
|
+
}
|
|
293
297
|
this.logger?.debug(
|
|
294
298
|
`Got ${this.mainPriceFeeds.size} main and ${this.reservePriceFeeds.size} reserve price feeds`
|
|
295
299
|
);
|
|
@@ -310,6 +314,8 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
310
314
|
* Helper method to find "attachment point" of price feed (makes sense for updatable price feeds only) -
|
|
311
315
|
* returns token (in v3.0 can be ticker) and main/reserve flag
|
|
312
316
|
*
|
|
317
|
+
* @deprecated Should be gone after v310 migration
|
|
318
|
+
*
|
|
313
319
|
* @param priceFeed
|
|
314
320
|
* @returns
|
|
315
321
|
*/
|
|
@@ -326,6 +332,9 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
326
332
|
}
|
|
327
333
|
return [void 0, false];
|
|
328
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Returns list of addresses that should be watched for events to sync state
|
|
337
|
+
*/
|
|
329
338
|
get watchAddresses() {
|
|
330
339
|
return /* @__PURE__ */ new Set([this.address]);
|
|
331
340
|
}
|
|
@@ -352,9 +361,6 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
352
361
|
)
|
|
353
362
|
};
|
|
354
363
|
}
|
|
355
|
-
get priceFeedTree() {
|
|
356
|
-
return this.#priceFeedTree;
|
|
357
|
-
}
|
|
358
364
|
#noAnswerWarn(priceFeed, node) {
|
|
359
365
|
let label = this.labelAddress(priceFeed);
|
|
360
366
|
if (!node) {
|
|
@@ -27,7 +27,7 @@ var import_sdk_gov_legacy = require("../../sdk-gov-legacy/index.js");
|
|
|
27
27
|
var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
|
|
28
28
|
const abi = [...import_v300.iPriceOracleV300Abi, ...import_iPausable.iPausableAbi];
|
|
29
29
|
class PriceOracleV300Contract extends import_PriceOracleBaseContract.PriceOracleBaseContract {
|
|
30
|
-
constructor(sdk, data
|
|
30
|
+
constructor(sdk, data) {
|
|
31
31
|
super(
|
|
32
32
|
sdk,
|
|
33
33
|
{
|
|
@@ -35,8 +35,7 @@ class PriceOracleV300Contract extends import_PriceOracleBaseContract.PriceOracle
|
|
|
35
35
|
name: "PriceOracleV3",
|
|
36
36
|
abi
|
|
37
37
|
},
|
|
38
|
-
data
|
|
39
|
-
underlying
|
|
38
|
+
data
|
|
40
39
|
);
|
|
41
40
|
}
|
|
42
41
|
processLog(log) {
|
|
@@ -25,7 +25,7 @@ var import_v310 = require("../../../abi/v310.js");
|
|
|
25
25
|
var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
|
|
26
26
|
const abi = import_v310.iPriceOracleV310Abi;
|
|
27
27
|
class PriceOracleV310Contract extends import_PriceOracleBaseContract.PriceOracleBaseContract {
|
|
28
|
-
constructor(sdk, data
|
|
28
|
+
constructor(sdk, data) {
|
|
29
29
|
super(
|
|
30
30
|
sdk,
|
|
31
31
|
{
|
|
@@ -33,8 +33,7 @@ class PriceOracleV310Contract extends import_PriceOracleBaseContract.PriceOracle
|
|
|
33
33
|
name: "PriceOracleV3",
|
|
34
34
|
abi
|
|
35
35
|
},
|
|
36
|
-
data
|
|
37
|
-
underlying
|
|
36
|
+
data
|
|
38
37
|
);
|
|
39
38
|
}
|
|
40
39
|
processLog(log) {
|
|
@@ -18,22 +18,42 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var createPriceOracle_exports = {};
|
|
20
20
|
__export(createPriceOracle_exports, {
|
|
21
|
-
|
|
21
|
+
getOrCreatePriceOracle: () => getOrCreatePriceOracle
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createPriceOracle_exports);
|
|
24
|
+
var import_constants = require("../../constants/index.js");
|
|
25
|
+
var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
|
|
24
26
|
var import_PriceOracleV300Contract = require("./PriceOracleV300Contract.js");
|
|
25
27
|
var import_PriceOracleV310Contract = require("./PriceOracleV310Contract.js");
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
function getOrCreatePriceOracle(sdk, data) {
|
|
29
|
+
const { version, addr } = data.baseParams;
|
|
30
|
+
const existing = sdk.contracts.get(addr);
|
|
31
|
+
if (existing) {
|
|
32
|
+
return tryExtendExistingOracle(existing, data);
|
|
30
33
|
}
|
|
31
|
-
if (
|
|
32
|
-
return new
|
|
34
|
+
if ((0, import_constants.isV300)(version)) {
|
|
35
|
+
return new import_PriceOracleV300Contract.PriceOracleV300Contract(sdk, data);
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
if ((0, import_constants.isV310)(version)) {
|
|
38
|
+
return new import_PriceOracleV310Contract.PriceOracleV310Contract(sdk, data);
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Unsupported oracle version ${version}`);
|
|
41
|
+
}
|
|
42
|
+
function tryExtendExistingOracle(existing, data) {
|
|
43
|
+
const { version, addr } = data.baseParams;
|
|
44
|
+
if (!(existing instanceof import_PriceOracleBaseContract.PriceOracleBaseContract)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`expected oracle contract at ${addr}, found existing ${existing.contractType}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (Number(existing.version) !== Number(version)) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`expected oracle contract at ${addr} to have version ${version}, found ${existing.version}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return existing.merge(data);
|
|
35
55
|
}
|
|
36
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
57
|
0 && (module.exports = {
|
|
38
|
-
|
|
58
|
+
getOrCreatePriceOracle
|
|
39
59
|
});
|
|
@@ -21,14 +21,15 @@ __export(createPool_exports, {
|
|
|
21
21
|
default: () => createPool
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createPool_exports);
|
|
24
|
+
var import_constants = require("../../constants/index.js");
|
|
24
25
|
var import_PoolV300Contract = require("./PoolV300Contract.js");
|
|
25
26
|
var import_PoolV310Contract = require("./PoolV310Contract.js");
|
|
26
27
|
function createPool(sdk, data) {
|
|
27
28
|
const v = data.baseParams.version;
|
|
28
|
-
if (
|
|
29
|
+
if ((0, import_constants.isV300)(v)) {
|
|
29
30
|
return new import_PoolV300Contract.PoolV300Contract(sdk, data);
|
|
30
31
|
}
|
|
31
|
-
if (
|
|
32
|
+
if ((0, import_constants.isV310)(v)) {
|
|
32
33
|
return new import_PoolV310Contract.PoolV310Contract(sdk, data);
|
|
33
34
|
}
|
|
34
35
|
throw new Error(`Unsupported pool version ${v}`);
|