@suilend/sdk 13.6.0-next.g7eab84a → 13.7.0-next.g199bec7
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/_generated/suilend/reserve/structs.d.ts +7 -1
- package/_generated/suilend/reserve/structs.js +15 -1
- package/client.d.ts +16 -2
- package/client.js +31 -6
- package/lib/types.d.ts +2 -0
- package/package.json +1 -1
- package/parsers/apiReserveAssetDataEvent.js +9 -2
- package/parsers/reserve.d.ts +2 -1
- package/parsers/reserve.js +8 -8
- package/utils/events.d.ts +15 -12
- package/utils/simulate.d.ts +28 -8
- package/utils/simulate.js +44 -29
|
@@ -651,7 +651,7 @@ export type ReserveAssetDataEventJSON = {
|
|
|
651
651
|
/**
|
|
652
652
|
* Deprecated: this struct's layout is frozen by Sui's upgrade-compatibility check, since
|
|
653
653
|
* it is already published on mainnet. Use `ReserveAssetDataEventV2` instead, which carries
|
|
654
|
-
* every field here plus `conf
|
|
654
|
+
* every field here plus `conf` and the unclamped prices.
|
|
655
655
|
*/
|
|
656
656
|
export declare class ReserveAssetDataEvent implements StructClass {
|
|
657
657
|
__StructClass: true;
|
|
@@ -717,6 +717,8 @@ export interface ReserveAssetDataEventV2Fields {
|
|
|
717
717
|
smoothedPrice: ToField<Decimal>;
|
|
718
718
|
priceLastUpdateTimestampS: ToField<'u64'>;
|
|
719
719
|
conf: ToField<Decimal>;
|
|
720
|
+
unclampedPrice: ToField<Decimal>;
|
|
721
|
+
unclampedSmoothedPrice: ToField<Decimal>;
|
|
720
722
|
}
|
|
721
723
|
export type ReserveAssetDataEventV2Reified = Reified<ReserveAssetDataEventV2, ReserveAssetDataEventV2Fields>;
|
|
722
724
|
export type ReserveAssetDataEventV2JSONField = {
|
|
@@ -737,6 +739,8 @@ export type ReserveAssetDataEventV2JSONField = {
|
|
|
737
739
|
smoothedPrice: ToJSON<Decimal>;
|
|
738
740
|
priceLastUpdateTimestampS: string;
|
|
739
741
|
conf: ToJSON<Decimal>;
|
|
742
|
+
unclampedPrice: ToJSON<Decimal>;
|
|
743
|
+
unclampedSmoothedPrice: ToJSON<Decimal>;
|
|
740
744
|
};
|
|
741
745
|
export type ReserveAssetDataEventV2JSON = {
|
|
742
746
|
$typeName: typeof ReserveAssetDataEventV2.$typeName;
|
|
@@ -768,6 +772,8 @@ export declare class ReserveAssetDataEventV2 implements StructClass {
|
|
|
768
772
|
readonly smoothedPrice: ToField<Decimal>;
|
|
769
773
|
readonly priceLastUpdateTimestampS: ToField<'u64'>;
|
|
770
774
|
readonly conf: ToField<Decimal>;
|
|
775
|
+
readonly unclampedPrice: ToField<Decimal>;
|
|
776
|
+
readonly unclampedSmoothedPrice: ToField<Decimal>;
|
|
771
777
|
private constructor();
|
|
772
778
|
static reified(): ReserveAssetDataEventV2Reified;
|
|
773
779
|
static get r(): ReserveAssetDataEventV2Reified;
|
|
@@ -1757,7 +1757,7 @@ export function isReserveAssetDataEvent(type) {
|
|
|
1757
1757
|
/**
|
|
1758
1758
|
* Deprecated: this struct's layout is frozen by Sui's upgrade-compatibility check, since
|
|
1759
1759
|
* it is already published on mainnet. Use `ReserveAssetDataEventV2` instead, which carries
|
|
1760
|
-
* every field here plus `conf
|
|
1760
|
+
* every field here plus `conf` and the unclamped prices.
|
|
1761
1761
|
*/
|
|
1762
1762
|
export class ReserveAssetDataEvent {
|
|
1763
1763
|
__StructClass = true;
|
|
@@ -2020,6 +2020,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2020
2020
|
smoothedPrice;
|
|
2021
2021
|
priceLastUpdateTimestampS;
|
|
2022
2022
|
conf;
|
|
2023
|
+
unclampedPrice;
|
|
2024
|
+
unclampedSmoothedPrice;
|
|
2023
2025
|
constructor(typeArgs, fields) {
|
|
2024
2026
|
this.$fullTypeName = composeSuiType(ReserveAssetDataEventV2.$typeName, ...typeArgs);
|
|
2025
2027
|
this.$typeArgs = typeArgs;
|
|
@@ -2040,6 +2042,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2040
2042
|
this.smoothedPrice = fields.smoothedPrice;
|
|
2041
2043
|
this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
|
|
2042
2044
|
this.conf = fields.conf;
|
|
2045
|
+
this.unclampedPrice = fields.unclampedPrice;
|
|
2046
|
+
this.unclampedSmoothedPrice = fields.unclampedSmoothedPrice;
|
|
2043
2047
|
}
|
|
2044
2048
|
static reified() {
|
|
2045
2049
|
const reifiedBcs = ReserveAssetDataEventV2.bcs;
|
|
@@ -2101,6 +2105,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2101
2105
|
smoothed_price: Decimal.bcs,
|
|
2102
2106
|
price_last_update_timestamp_s: bcs.u64(),
|
|
2103
2107
|
conf: Decimal.bcs,
|
|
2108
|
+
unclamped_price: Decimal.bcs,
|
|
2109
|
+
unclamped_smoothed_price: Decimal.bcs,
|
|
2104
2110
|
});
|
|
2105
2111
|
}
|
|
2106
2112
|
static cachedBcs = null;
|
|
@@ -2129,6 +2135,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2129
2135
|
smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
|
|
2130
2136
|
priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
|
|
2131
2137
|
conf: decodeFromFields(Decimal.reified(), fields.conf),
|
|
2138
|
+
unclampedPrice: decodeFromFields(Decimal.reified(), fields.unclamped_price),
|
|
2139
|
+
unclampedSmoothedPrice: decodeFromFields(Decimal.reified(), fields.unclamped_smoothed_price),
|
|
2132
2140
|
});
|
|
2133
2141
|
}
|
|
2134
2142
|
static fromFieldsWithTypes(item) {
|
|
@@ -2153,6 +2161,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2153
2161
|
smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
|
|
2154
2162
|
priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
|
|
2155
2163
|
conf: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.conf),
|
|
2164
|
+
unclampedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unclamped_price),
|
|
2165
|
+
unclampedSmoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unclamped_smoothed_price),
|
|
2156
2166
|
});
|
|
2157
2167
|
}
|
|
2158
2168
|
static fromBcs(data) {
|
|
@@ -2177,6 +2187,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2177
2187
|
smoothedPrice: this.smoothedPrice.toJSONField(),
|
|
2178
2188
|
priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
|
|
2179
2189
|
conf: this.conf.toJSONField(),
|
|
2190
|
+
unclampedPrice: this.unclampedPrice.toJSONField(),
|
|
2191
|
+
unclampedSmoothedPrice: this.unclampedSmoothedPrice.toJSONField(),
|
|
2180
2192
|
};
|
|
2181
2193
|
}
|
|
2182
2194
|
toJSON() {
|
|
@@ -2201,6 +2213,8 @@ export class ReserveAssetDataEventV2 {
|
|
|
2201
2213
|
smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
|
|
2202
2214
|
priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
|
|
2203
2215
|
conf: decodeFromJSONField(Decimal.reified(), field.conf),
|
|
2216
|
+
unclampedPrice: decodeFromJSONField(Decimal.reified(), field.unclampedPrice),
|
|
2217
|
+
unclampedSmoothedPrice: decodeFromJSONField(Decimal.reified(), field.unclampedSmoothedPrice),
|
|
2204
2218
|
});
|
|
2205
2219
|
}
|
|
2206
2220
|
static fromJSON(json) {
|
package/client.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
|
3
3
|
import { Transaction, TransactionArgument, TransactionObjectArgument, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
4
4
|
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
|
+
import { Decimal } from "./_generated/suilend/decimal/structs";
|
|
7
|
+
import { type ConfidenceShare } from "./utils/simulate";
|
|
6
8
|
import { LendingMarket, ObligationOwnerCap } from "./_generated/suilend/lending-market/structs";
|
|
7
9
|
import { Obligation } from "./_generated/suilend/obligation/structs";
|
|
8
10
|
import { NewConfigArgs as CreateRateLimiterConfigArgs } from "./_generated/suilend/rate-limiter/functions";
|
|
@@ -102,8 +104,13 @@ export declare class SuilendClient {
|
|
|
102
104
|
}>;
|
|
103
105
|
/** A reserve's confidence multiplier `k`, in bps; pass `parsedReserve.config.additionalFields.id`. 0 when unset. */
|
|
104
106
|
static getReserveConfidenceMultiplierBps(suiGrpcClient: SuiGrpcClient, additionalFieldsBagId: string): Promise<BigNumber>;
|
|
105
|
-
/** A reserve's stored Pyth confidence (the `ConfidenceKey` dynamic field on `reserve.id` directly, not inside `config.additionalFields`). Reads as 0 until the reserve's first price update writes it. */
|
|
106
|
-
static
|
|
107
|
+
/** A reserve's stored Pyth confidence as a share of the spot it was read with, `conf / spot` (the `ConfidenceKey` dynamic field on `reserve.id` directly, not inside `config.additionalFields`). Reads as 0 until the reserve's first price update writes it. */
|
|
108
|
+
static getReserveConfidenceShare(suiGrpcClient: SuiGrpcClient, reserveId: string): Promise<ConfidenceShare>;
|
|
109
|
+
/** The raw spot and EMA of the reserve's last refresh under a price guard (the `RawPriceKey` dynamic field on `reserve.id`). Undefined until its first refresh under a guard. Attach them with `withUnclampedPrices` only to a reserve as stored on chain, never to one a feed refresh has repriced. */
|
|
110
|
+
static getReserveRawPrices(suiGrpcClient: SuiGrpcClient, reserveId: string): Promise<{
|
|
111
|
+
price: Decimal;
|
|
112
|
+
smoothedPrice: Decimal;
|
|
113
|
+
} | undefined>;
|
|
107
114
|
static createNewLendingMarket(registryId: string, lendingMarketType: string, transaction: Transaction): {
|
|
108
115
|
NestedResult: [number, number];
|
|
109
116
|
$kind: "NestedResult";
|
|
@@ -128,6 +135,13 @@ export declare class SuilendClient {
|
|
|
128
135
|
claimRewardsAndDeposit(ownerId: string, obligationOwnerCap: TransactionObjectInput, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
|
|
129
136
|
findReserveArrayIndex(coinType: string): bigint;
|
|
130
137
|
private submitReserveConfigUpdate;
|
|
138
|
+
/**
|
|
139
|
+
* From market version 8, sets every `CreateReserveConfigArgs` field on a
|
|
140
|
+
* builder seeded from the reserve's live config, so `additionalFields`
|
|
141
|
+
* entries (confidence multiplier, oracle thresholds, stable pause) keep
|
|
142
|
+
* their current values: version 8 installs only `build` output. At version
|
|
143
|
+
* 7 it replaces the whole config, which resets those entries.
|
|
144
|
+
*/
|
|
131
145
|
updateReserveConfig(lendingMarketOwnerCapId: string, transaction: Transaction, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
132
146
|
/**
|
|
133
147
|
* Updates a subset of a reserve's config fields, leaving every unspecified
|
package/client.js
CHANGED
|
@@ -5,7 +5,7 @@ import BigNumber from "bignumber.js";
|
|
|
5
5
|
import { extractCTokenCoinType, getAllCoins, getSpendableCoin, } from "@suilend/sui-core";
|
|
6
6
|
import { phantom } from "./_generated/_framework/reified.js";
|
|
7
7
|
import { Decimal } from "./_generated/suilend/decimal/structs.js";
|
|
8
|
-
import { decimalToBigNumber } from "./utils/simulate.js";
|
|
8
|
+
import { confidenceShare, decimalToBigNumber, } from "./utils/simulate.js";
|
|
9
9
|
import { PKG_V10, setPublishedAt } from "./_generated/suilend/index.js";
|
|
10
10
|
import { getPublishedAt } from "./_generated/_envs/index.js";
|
|
11
11
|
import { PACKAGE_ID } from "./_generated/suilend/index.js";
|
|
@@ -467,17 +467,32 @@ export class SuilendClient {
|
|
|
467
467
|
});
|
|
468
468
|
return new BigNumber(bcs.u64().parse(dynamicField.value.bcs));
|
|
469
469
|
}
|
|
470
|
-
/** A reserve's stored Pyth confidence (the `ConfidenceKey` dynamic field on `reserve.id` directly, not inside `config.additionalFields`). Reads as 0 until the reserve's first price update writes it. */
|
|
471
|
-
static async
|
|
470
|
+
/** A reserve's stored Pyth confidence as a share of the spot it was read with, `conf / spot` (the `ConfidenceKey` dynamic field on `reserve.id` directly, not inside `config.additionalFields`). Reads as 0 until the reserve's first price update writes it. */
|
|
471
|
+
static async getReserveConfidenceShare(suiGrpcClient, reserveId) {
|
|
472
472
|
const match = await findBagEntryByTypeSuffix(suiGrpcClient, reserveId, "::reserve::ConfidenceKey");
|
|
473
473
|
if (!match)
|
|
474
|
-
return new BigNumber(0);
|
|
474
|
+
return confidenceShare(new BigNumber(0), new BigNumber(0));
|
|
475
475
|
const { dynamicField } = await suiGrpcClient.getDynamicField({
|
|
476
476
|
parentId: reserveId,
|
|
477
477
|
name: match.name,
|
|
478
478
|
});
|
|
479
479
|
return decimalToBigNumber(Decimal.fromBcs(dynamicField.value.bcs));
|
|
480
480
|
}
|
|
481
|
+
/** The raw spot and EMA of the reserve's last refresh under a price guard (the `RawPriceKey` dynamic field on `reserve.id`). Undefined until its first refresh under a guard. Attach them with `withUnclampedPrices` only to a reserve as stored on chain, never to one a feed refresh has repriced. */
|
|
482
|
+
static async getReserveRawPrices(suiGrpcClient, reserveId) {
|
|
483
|
+
const match = await findBagEntryByTypeSuffix(suiGrpcClient, reserveId, "::reserve::RawPriceKey");
|
|
484
|
+
if (!match)
|
|
485
|
+
return undefined;
|
|
486
|
+
const { dynamicField } = await suiGrpcClient.getDynamicField({
|
|
487
|
+
parentId: reserveId,
|
|
488
|
+
name: match.name,
|
|
489
|
+
});
|
|
490
|
+
const bytes = dynamicField.value.bcs;
|
|
491
|
+
return {
|
|
492
|
+
price: Decimal.fromBcs(bytes.slice(0, 32)),
|
|
493
|
+
smoothedPrice: Decimal.fromBcs(bytes.slice(32, 64)),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
481
496
|
static createNewLendingMarket(registryId, lendingMarketType, transaction) {
|
|
482
497
|
const [ownerCap, lendingMarket] = createLendingMarket(transaction, lendingMarketType, transaction.object(registryId));
|
|
483
498
|
transaction.moveCall({
|
|
@@ -650,9 +665,19 @@ export class SuilendClient {
|
|
|
650
665
|
config: transaction.object(config),
|
|
651
666
|
});
|
|
652
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* From market version 8, sets every `CreateReserveConfigArgs` field on a
|
|
670
|
+
* builder seeded from the reserve's live config, so `additionalFields`
|
|
671
|
+
* entries (confidence multiplier, oracle thresholds, stable pause) keep
|
|
672
|
+
* their current values: version 8 installs only `build` output. At version
|
|
673
|
+
* 7 it replaces the whole config, which resets those entries.
|
|
674
|
+
*/
|
|
653
675
|
updateReserveConfig(lendingMarketOwnerCapId, transaction, coinType, createReserveConfigArgs) {
|
|
654
|
-
|
|
655
|
-
|
|
676
|
+
if (this.lendingMarket.version < 8n) {
|
|
677
|
+
const [config] = createReserveConfig(transaction, createReserveConfigArgs);
|
|
678
|
+
return this.submitReserveConfigUpdate(lendingMarketOwnerCapId, transaction, coinType, config);
|
|
679
|
+
}
|
|
680
|
+
return this.patchReserveConfig(lendingMarketOwnerCapId, transaction, coinType, createReserveConfigArgs);
|
|
656
681
|
}
|
|
657
682
|
/**
|
|
658
683
|
* Updates a subset of a reserve's config fields, leaving every unspecified
|
package/lib/types.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type ApiReserveAssetDataEvent = {
|
|
|
51
51
|
smoothedPrice: string;
|
|
52
52
|
priceLastUpdateTimestampS: number;
|
|
53
53
|
conf: string | null;
|
|
54
|
+
unclampedPrice: string | null;
|
|
55
|
+
unclampedSmoothedPrice: string | null;
|
|
54
56
|
timestamp: number;
|
|
55
57
|
digest: string;
|
|
56
58
|
eventIndex: number;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"13.
|
|
1
|
+
{"name":"@suilend/sdk","version":"13.7.0-next.g199bec7","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/proCompatible":"./lib/proCompatible.js","./lib/pyth":"./lib/pyth.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./margin":"./margin/index.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils/feedId":"./utils/feedId.js","./utils":"./utils/index.js","./utils/interpolate":"./utils/interpolate.js","./utils/obligation":"./utils/obligation.js","./utils/priceGuard":"./utils/priceGuard.js","./utils/simulate":"./utils/simulate.js","./_generated/_envs":"./_generated/_envs/index.js","./_generated/_envs/mainnet":"./_generated/_envs/mainnet.js","./_generated/_framework/env":"./_generated/_framework/env.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/version":"./margin/margin/version.js","./margin/utils":"./margin/utils/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/pyth-2/price-identifier/structs":"./_generated/_dependencies/pyth-2/price-identifier/structs.js","./_generated/_dependencies/std/ascii/structs":"./_generated/_dependencies/std/ascii/structs.js","./_generated/_dependencies/std/option/structs":"./_generated/_dependencies/std/option/structs.js","./_generated/_dependencies/std/type-name/structs":"./_generated/_dependencies/std/type-name/structs.js","./_generated/_dependencies/sui/bag/structs":"./_generated/_dependencies/sui/bag/structs.js","./_generated/_dependencies/sui/balance/structs":"./_generated/_dependencies/sui/balance/structs.js","./_generated/_dependencies/sui/object/structs":"./_generated/_dependencies/sui/object/structs.js","./_generated/_dependencies/sui/object-table/structs":"./_generated/_dependencies/sui/object-table/structs.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js"},"types":"./index.d.ts","scripts":{"codegen":"node ./codegen.js","codegen:install":"node ./install-codegen.js","build":"rm -rf ./dist && tsc && node ./fix-esm-imports.js","typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json","test":"vitest run","lint:ci":"yarn run typecheck","prettier":"prettier --write src/ tests/","release":"yarn run build && node ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/fireflyprotocol/lending-mono.git","directory":"ts/sdks/sdk"},"dependencies":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"7.7.0","@cetusprotocol/aggregator-sdk":"1.7.3","@flowx-finance/sdk":"2.1.0","@pythnetwork/hermes-client":"3.1.0","@pythnetwork/pyth-sui-js":"4.0.0","@suilend/springsui-sdk":"4.1.0","bignumber.js":"11.1.5","bn.js":"5.2.5","crypto-js":"4.2.0","lodash":"4.18.1","p-limit":"7.3.3","uuid":"14.0.2"},"devDependencies":{"@mysten/bcs":"2.1.2","@mysten/sui":"2.35.0","@suilend/sui-core":"2.2.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.26","@types/node":"26.6.5","fast-check":"4.10.2","prettier":"3.9.10","ts-node":"10.9.2","typescript":"6.0.3","vite":"8.3.4","vitest":"5.0.4"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.31.3 <3","@suilend/sui-core":"^2.0.1"},"type":"module"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { WAD } from "../lib/constants.js";
|
|
4
|
-
import { applyConfidenceMargin } from "../utils/simulate.js";
|
|
4
|
+
import { applyConfidenceMargin, confidenceShare } from "../utils/simulate.js";
|
|
5
5
|
// Reproduces the exact pre-confidence-margin bounds when a caller doesn't
|
|
6
6
|
// supply the reserve's current multiplier.
|
|
7
7
|
const ZERO_K_BPS = new BigNumber(0);
|
|
@@ -30,7 +30,14 @@ kBps = ZERO_K_BPS) => {
|
|
|
30
30
|
// Null conf (a pre-upgrade event) has no margin to apply -- 0 reproduces
|
|
31
31
|
// plain min/max exactly, same as kBps=0 does.
|
|
32
32
|
const conf = event.conf ? new BigNumber(event.conf).div(WAD) : new BigNumber(0);
|
|
33
|
-
const
|
|
33
|
+
const unclampedPrice = event.unclampedPrice
|
|
34
|
+
? new BigNumber(event.unclampedPrice).div(WAD)
|
|
35
|
+
: price;
|
|
36
|
+
const unclampedSmoothedPrice = event.unclampedSmoothedPrice
|
|
37
|
+
? new BigNumber(event.unclampedSmoothedPrice).div(WAD)
|
|
38
|
+
: smoothedPrice;
|
|
39
|
+
const rangePrices = [price, smoothedPrice, unclampedPrice, unclampedSmoothedPrice];
|
|
40
|
+
const { lowerBound: minPrice, upperBound: maxPrice } = applyConfidenceMargin(BigNumber.min(...rangePrices), BigNumber.max(...rangePrices), confidenceShare(conf, unclampedPrice), kBps);
|
|
34
41
|
// Custom
|
|
35
42
|
const utilizationPercent = depositedAmount.eq(0)
|
|
36
43
|
? new BigNumber(0)
|
package/parsers/reserve.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { SuiClientTypes } from "@mysten/sui/client";
|
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { PoolReward, PoolRewardManager } from "../_generated/suilend/liquidity-mining/structs";
|
|
4
4
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
5
|
+
import * as simulate from "../utils/simulate";
|
|
5
6
|
export type ParsedReserve = ReturnType<typeof parseReserve>;
|
|
6
7
|
export type ParsedReserveConfig = ReturnType<typeof parseReserveConfig>;
|
|
7
8
|
export type ParsedPoolRewardManager = ReturnType<typeof parsePoolRewardManager>;
|
|
8
9
|
export type ParsedPoolReward = NonNullable<ReturnType<typeof parsePoolReward>>;
|
|
9
|
-
export declare const parseReserve: (reserve: Reserve<string>, coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>,
|
|
10
|
+
export declare const parseReserve: (reserve: Reserve<string>, coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>, share?: simulate.ConfidenceShare, kBps?: BigNumber) => {
|
|
10
11
|
config: {
|
|
11
12
|
$typeName: `${string}::reserve_config::ReserveConfig`;
|
|
12
13
|
openLtvPct: number;
|
package/parsers/reserve.js
CHANGED
|
@@ -5,13 +5,14 @@ import { WAD } from "../lib/constants.js";
|
|
|
5
5
|
import { toHexString } from "../utils/index.js";
|
|
6
6
|
import * as simulate from "../utils/simulate.js";
|
|
7
7
|
export const parseReserve = (reserve, coinMetadataMap,
|
|
8
|
-
// The reserve's stored
|
|
8
|
+
// The reserve's stored conf / spot share and its CURRENT confidence
|
|
9
9
|
// multiplier (in bps) -- a ConfidenceKey dynamic field and a
|
|
10
10
|
// ReserveConfig.additionalFields Bag entry respectively, neither of which
|
|
11
11
|
// lives on the Reserve object's own BCS content, so this parser can't
|
|
12
12
|
// fetch them itself without becoming async. Omit either (or both) for
|
|
13
|
-
// plain
|
|
14
|
-
|
|
13
|
+
// plain bounds. The raw prices of a guarded reserve come attached with
|
|
14
|
+
// simulate.withUnclampedPrices.
|
|
15
|
+
share, kBps) => {
|
|
15
16
|
const config = parseReserveConfig(reserve);
|
|
16
17
|
const $typeName = reserve.$typeName;
|
|
17
18
|
const id = reserve.id;
|
|
@@ -22,11 +23,10 @@ conf, kBps) => {
|
|
|
22
23
|
const priceIdentifier = `0x${toHexString(reserve.priceIdentifier.bytes)}`;
|
|
23
24
|
const price = new BigNumber(reserve.price.value.toString()).div(WAD);
|
|
24
25
|
const smoothedPrice = new BigNumber(reserve.smoothedPrice.value.toString()).div(WAD);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const maxPrice = bounds.upperBound;
|
|
26
|
+
const { low, high } = simulate.priceRange(reserve);
|
|
27
|
+
const { lowerBound: minPrice, upperBound: maxPrice } = share !== undefined && kBps !== undefined
|
|
28
|
+
? simulate.applyConfidenceMargin(low, high, share, kBps)
|
|
29
|
+
: { lowerBound: low, upperBound: high };
|
|
30
30
|
const priceLastUpdateTimestampS = reserve.priceLastUpdateTimestampS;
|
|
31
31
|
const availableAmount = new BigNumber(reserve.availableAmount.toString()).div(10 ** mintDecimals);
|
|
32
32
|
const ctokenSupply = new BigNumber(reserve.ctokenSupply.toString()).div(10 ** mintDecimals);
|
package/utils/events.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ type Decimal = {
|
|
|
8
8
|
};
|
|
9
9
|
type address = string;
|
|
10
10
|
type u64 = string;
|
|
11
|
+
type u256 = string;
|
|
11
12
|
export declare enum SuilendEventType {
|
|
12
13
|
InterestUpdateEvent = "InterestUpdateEvent",
|
|
13
14
|
ReserveAssetDataEvent = "ReserveAssetDataEvent",
|
|
@@ -73,20 +74,22 @@ export declare class ReserveAssetDataEventV2 extends TypedParamsSuiEvent<{
|
|
|
73
74
|
lending_market_id: address;
|
|
74
75
|
coin_type: TypeName;
|
|
75
76
|
reserve_id: address;
|
|
76
|
-
available_amount:
|
|
77
|
-
supply_amount:
|
|
78
|
-
borrowed_amount:
|
|
79
|
-
available_amount_usd_estimate:
|
|
80
|
-
supply_amount_usd_estimate:
|
|
81
|
-
borrowed_amount_usd_estimate:
|
|
82
|
-
borrow_apr:
|
|
83
|
-
supply_apr:
|
|
77
|
+
available_amount: u256;
|
|
78
|
+
supply_amount: u256;
|
|
79
|
+
borrowed_amount: u256;
|
|
80
|
+
available_amount_usd_estimate: u256;
|
|
81
|
+
supply_amount_usd_estimate: u256;
|
|
82
|
+
borrowed_amount_usd_estimate: u256;
|
|
83
|
+
borrow_apr: u256;
|
|
84
|
+
supply_apr: u256;
|
|
84
85
|
ctoken_supply: u64;
|
|
85
|
-
cumulative_borrow_rate:
|
|
86
|
-
price:
|
|
87
|
-
smoothed_price:
|
|
86
|
+
cumulative_borrow_rate: u256;
|
|
87
|
+
price: u256;
|
|
88
|
+
smoothed_price: u256;
|
|
88
89
|
price_last_update_timestamp_s: u64;
|
|
89
|
-
conf:
|
|
90
|
+
conf: u256;
|
|
91
|
+
unclamped_price: u256;
|
|
92
|
+
unclamped_smoothed_price: u256;
|
|
90
93
|
}> {
|
|
91
94
|
}
|
|
92
95
|
export declare class MintEvent extends TypedParamsSuiEvent<{
|
package/utils/simulate.d.ts
CHANGED
|
@@ -40,6 +40,13 @@ export interface FeedPrice {
|
|
|
40
40
|
}
|
|
41
41
|
export declare const feedConfidenceOf: (reserve: Reserve<string>) => BigNumber | undefined;
|
|
42
42
|
export declare const withUnclampedPrices: (reserve: Reserve<string>, price: Decimal, smoothedPrice: Decimal) => Reserve<string>;
|
|
43
|
+
/** Mirrors reserve.move's `price_range`. */
|
|
44
|
+
export declare const priceRange: (reserve: Reserve<string>) => {
|
|
45
|
+
low: BigNumber;
|
|
46
|
+
high: BigNumber;
|
|
47
|
+
};
|
|
48
|
+
/** Mirrors reserve.move's `unclamped_price`: the spot a reserve's conf was quoted with. */
|
|
49
|
+
export declare const unclampedSpot: (reserve: Reserve<string>) => BigNumber;
|
|
43
50
|
/**
|
|
44
51
|
* A source of latest prices. Structural on purpose: any object with this method
|
|
45
52
|
* qualifies, so a caller can inject its own client (authenticated, failover,
|
|
@@ -139,6 +146,16 @@ export type ObligationRefresh = {
|
|
|
139
146
|
weightedBorrowedValueUsd: BigNumber;
|
|
140
147
|
weightedBorrowedValueUpperBoundUsd: BigNumber;
|
|
141
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* `conf / spot` from a single price read: what a reserve stores in
|
|
151
|
+
* `ConfidenceKey`. Branded so a USD conf cannot be passed where a share is
|
|
152
|
+
* expected; build one with `confidenceShare`.
|
|
153
|
+
*/
|
|
154
|
+
export type ConfidenceShare = BigNumber & {
|
|
155
|
+
readonly __brand: "ConfidenceShare";
|
|
156
|
+
};
|
|
157
|
+
/** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
|
|
158
|
+
export declare const confidenceShare: (conf: BigNumber, spot: BigNumber) => ConfidenceShare;
|
|
142
159
|
/**
|
|
143
160
|
* Pure computation half of `refreshObligation`: same math, but returns fresh
|
|
144
161
|
* deposits/borrows/reward-manager arrays and the five USD aggregates instead
|
|
@@ -149,7 +166,7 @@ export type ObligationRefresh = {
|
|
|
149
166
|
* holding a reference to it.
|
|
150
167
|
*/
|
|
151
168
|
export declare function computeObligationRefresh(obligation: Obligation<string>, refreshedReserves: Reserve<string>[], nowMs: number, confidenceByCoinType?: Map<string, {
|
|
152
|
-
|
|
169
|
+
share: ConfidenceShare | undefined;
|
|
153
170
|
kBps: BigNumber;
|
|
154
171
|
}>): ObligationRefresh;
|
|
155
172
|
export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[]) => Obligation<string>;
|
|
@@ -158,18 +175,21 @@ export declare const stringToDecimal: (value: string) => Decimal;
|
|
|
158
175
|
export declare const decimalToBigNumber: (value: Decimal) => BigNumber;
|
|
159
176
|
/**
|
|
160
177
|
* Mirrors reserve.move's `price_lower_bound`/`price_upper_bound`: the one
|
|
161
|
-
* off-chain place this formula lives. `
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
178
|
+
* off-chain place this formula lives. `low` and `high` are the ends of the
|
|
179
|
+
* reserve's price range (`priceRange`), which the bounds widen by
|
|
180
|
+
* `k * share`. `share` is `conf / spot` from a single price read -- what the
|
|
181
|
+
* reserve stores in `ConfidenceKey` -- and `kBps` is its `ReserveConfig`
|
|
182
|
+
* confidence multiplier (in bps, e.g. 30000 for a logical k=3); both are
|
|
183
|
+
* plain human-scale BigNumbers, not WAD-scaled Decimals. `kBps=0` or
|
|
184
|
+
* `share=0` disables the margin entirely: both bounds collapse to `low` and
|
|
185
|
+
* `high`.
|
|
166
186
|
*/
|
|
167
|
-
export declare const applyConfidenceMargin: (
|
|
187
|
+
export declare const applyConfidenceMargin: (low: BigNumber, high: BigNumber, share: ConfidenceShare, kBps: BigNumber) => {
|
|
168
188
|
lowerBound: BigNumber;
|
|
169
189
|
upperBound: BigNumber;
|
|
170
190
|
};
|
|
171
191
|
export declare const getCTokenMarketValue: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber) => BigNumber;
|
|
172
|
-
export declare const getCTokenMarketValueLowerBound: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber,
|
|
192
|
+
export declare const getCTokenMarketValueLowerBound: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber, share?: ConfidenceShare, kBps?: BigNumber) => BigNumber;
|
|
173
193
|
export declare const cTokenRatio: (reserve: Reserve<string>) => BigNumber;
|
|
174
194
|
export declare const totalSupply: (reserve: Reserve<string>) => BigNumber;
|
|
175
195
|
export declare const compoundBorrowedAmount: (snapshotAmount: BigNumber, currentCumulativeBorrowRate: BigNumber, snapshotCumulativeBorrowRate: BigNumber) => BigNumber;
|
package/utils/simulate.js
CHANGED
|
@@ -124,7 +124,7 @@ export const withUnclampedPrices = (reserve, price, smoothedPrice) => Object.ass
|
|
|
124
124
|
unclampedPrices: { price, smoothedPrice },
|
|
125
125
|
});
|
|
126
126
|
/** Mirrors reserve.move's `price_range`. */
|
|
127
|
-
const priceRange = (reserve) => {
|
|
127
|
+
export const priceRange = (reserve) => {
|
|
128
128
|
const unclamped = reserve.unclampedPrices;
|
|
129
129
|
const prices = [
|
|
130
130
|
reserve.price,
|
|
@@ -133,6 +133,9 @@ const priceRange = (reserve) => {
|
|
|
133
133
|
].map(decimalToBigNumber);
|
|
134
134
|
return { low: BigNumber.min(...prices), high: BigNumber.max(...prices) };
|
|
135
135
|
};
|
|
136
|
+
/** Mirrors reserve.move's `unclamped_price`: the spot a reserve's conf was quoted with. */
|
|
137
|
+
export const unclampedSpot = (reserve) => decimalToBigNumber(reserve.unclampedPrices?.price ??
|
|
138
|
+
reserve.price);
|
|
136
139
|
// Re-exported, not redefined: it was part of this module's public surface before
|
|
137
140
|
// it moved to ./feedId, and every consumer that normalizes a feed id to compare
|
|
138
141
|
// it against `unpricedCoinTypes` imports it from here.
|
|
@@ -349,18 +352,24 @@ export const findReserveOrThrow = (reserves, coinType) => {
|
|
|
349
352
|
// (`v * WAD / 10_000`); dividing in BigNumber here matches that.
|
|
350
353
|
export const computeBorrowWeight = (config) => new BigNumber(config.borrowWeightBps.toString()).div(10000);
|
|
351
354
|
export const computeCloseLtv = (config) => new BigNumber(config.closeLtvPct / 100);
|
|
355
|
+
/** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
|
|
356
|
+
export const confidenceShare = (conf, spot) => (spot.isZero() ? new BigNumber(0) : conf.dividedBy(spot));
|
|
357
|
+
const ZERO_SHARE = confidenceShare(new BigNumber(0), new BigNumber(0));
|
|
352
358
|
const resolveConfidence = (entry, reserve) => {
|
|
353
359
|
if (entry === undefined)
|
|
354
360
|
return undefined;
|
|
355
361
|
const refreshedFromFeed = "feedConfidence" in reserve;
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
362
|
+
const feedConf = feedConfidenceOf(reserve);
|
|
363
|
+
const share = (feedConf !== undefined
|
|
364
|
+
? confidenceShare(feedConf, unclampedSpot(reserve))
|
|
365
|
+
: undefined) ??
|
|
366
|
+
(refreshedFromFeed ? undefined : entry.share) ??
|
|
367
|
+
(entry.kBps.isZero() ? ZERO_SHARE : undefined);
|
|
368
|
+
if (share === undefined)
|
|
360
369
|
throw new Error(refreshedFromFeed
|
|
361
|
-
? `Reserve ${reserve.coinType} was refreshed from a feed without conf, so the stored
|
|
362
|
-
: `No conf for reserve ${reserve.coinType}: refresh it from a feed that carries conf, or supply
|
|
363
|
-
return {
|
|
370
|
+
? `Reserve ${reserve.coinType} was refreshed from a feed without conf, so the stored share is from a different update: use a feed that carries conf`
|
|
371
|
+
: `No conf for reserve ${reserve.coinType}: refresh it from a feed that carries conf, or supply the stored share in the entry`);
|
|
372
|
+
return { share, kBps: entry.kBps };
|
|
364
373
|
};
|
|
365
374
|
/**
|
|
366
375
|
* Pure computation half of `refreshObligation`: same math, but returns fresh
|
|
@@ -373,12 +382,13 @@ const resolveConfidence = (entry, reserve) => {
|
|
|
373
382
|
*/
|
|
374
383
|
export function computeObligationRefresh(obligation, refreshedReserves, nowMs,
|
|
375
384
|
// Per-reserve CURRENT confidence multiplier, keyed by coinType in either
|
|
376
|
-
// raw or normalized form. `
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
-
//
|
|
385
|
+
// raw or normalized form. `share` is the reserve's stored conf / spot
|
|
386
|
+
// (`SuilendClient.getReserveConfidenceShare`), the fallback for a reserve that
|
|
387
|
+
// was never price-refreshed; a reserve refreshed from a feed without `conf`
|
|
388
|
+
// throws instead (unless kBps is 0), because its price and the stored share
|
|
389
|
+
// come from different updates. A reserve's own `feedConfidence` takes
|
|
390
|
+
// precedence because it comes from the same update as its price. A reserve
|
|
391
|
+
// with no entry here gets plain min/max(price, smoothedPrice) bounds.
|
|
382
392
|
confidenceByCoinType) {
|
|
383
393
|
const normalizedConfidence = confidenceByCoinType &&
|
|
384
394
|
new Map([...confidenceByCoinType].map(([coinType, entry]) => [
|
|
@@ -397,7 +407,7 @@ confidenceByCoinType) {
|
|
|
397
407
|
updateUserRewardManager(reserve.depositsPoolRewardManager, userRewardManagers[Number(deposit.userRewardManagerIndex)], nowMs);
|
|
398
408
|
const confidence = resolveConfidence(normalizedConfidence?.get(normalizeStructTag(deposit.coinType)), reserve);
|
|
399
409
|
const marketValue = getCTokenMarketValue(reserve, new BigNumber(deposit.depositedCtokenAmount.toString()));
|
|
400
|
-
const marketValueLowerBound = getCTokenMarketValueLowerBound(reserve, new BigNumber(deposit.depositedCtokenAmount.toString()), confidence?.
|
|
410
|
+
const marketValueLowerBound = getCTokenMarketValueLowerBound(reserve, new BigNumber(deposit.depositedCtokenAmount.toString()), confidence?.share, confidence?.kBps);
|
|
401
411
|
deposit.marketValue = stringToDecimal(marketValue.toString());
|
|
402
412
|
depositValueUsd = depositValueUsd.plus(new BigNumber(marketValue.toString()));
|
|
403
413
|
allowedBorrowValueUsd = allowedBorrowValueUsd.plus(marketValueLowerBound.multipliedBy(new BigNumber(config.openLtvPct / 100)));
|
|
@@ -432,7 +442,7 @@ confidenceByCoinType) {
|
|
|
432
442
|
const confidence = resolveConfidence(normalizedConfidence?.get(normalizeStructTag(unrefreshedBorrow.coinType)), reserve);
|
|
433
443
|
const { low, high } = priceRange(reserve);
|
|
434
444
|
const upperBoundPrice = confidence !== undefined
|
|
435
|
-
? applyConfidenceMargin(low, high, confidence.
|
|
445
|
+
? applyConfidenceMargin(low, high, confidence.share, confidence.kBps)
|
|
436
446
|
.upperBound
|
|
437
447
|
: high;
|
|
438
448
|
// `exactBorrowedAmount` (this borrow's own amount), not
|
|
@@ -492,16 +502,21 @@ export const decimalToBigNumber = (value) => {
|
|
|
492
502
|
};
|
|
493
503
|
/**
|
|
494
504
|
* Mirrors reserve.move's `price_lower_bound`/`price_upper_bound`: the one
|
|
495
|
-
* off-chain place this formula lives. `
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
505
|
+
* off-chain place this formula lives. `low` and `high` are the ends of the
|
|
506
|
+
* reserve's price range (`priceRange`), which the bounds widen by
|
|
507
|
+
* `k * share`. `share` is `conf / spot` from a single price read -- what the
|
|
508
|
+
* reserve stores in `ConfidenceKey` -- and `kBps` is its `ReserveConfig`
|
|
509
|
+
* confidence multiplier (in bps, e.g. 30000 for a logical k=3); both are
|
|
510
|
+
* plain human-scale BigNumbers, not WAD-scaled Decimals. `kBps=0` or
|
|
511
|
+
* `share=0` disables the margin entirely: both bounds collapse to `low` and
|
|
512
|
+
* `high`.
|
|
500
513
|
*/
|
|
501
|
-
export const applyConfidenceMargin = (
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
514
|
+
export const applyConfidenceMargin = (low, high, share, kBps) => {
|
|
515
|
+
if (kBps.isZero() || share.isZero())
|
|
516
|
+
return { lowerBound: low, upperBound: high };
|
|
517
|
+
const fraction = kBps.dividedBy(10_000).multipliedBy(share);
|
|
518
|
+
const lowerBound = BigNumber.max(low.minus(low.multipliedBy(fraction)), new BigNumber(0));
|
|
519
|
+
const upperBound = high.plus(high.multipliedBy(fraction));
|
|
505
520
|
return { lowerBound, upperBound };
|
|
506
521
|
};
|
|
507
522
|
export const getCTokenMarketValue = (reserve, depositedCTokenAmount) => {
|
|
@@ -511,14 +526,14 @@ export const getCTokenMarketValue = (reserve, depositedCTokenAmount) => {
|
|
|
511
526
|
.dividedBy(new BigNumber(10 ** reserve.mintDecimals));
|
|
512
527
|
};
|
|
513
528
|
export const getCTokenMarketValueLowerBound = (reserve, depositedCTokenAmount,
|
|
514
|
-
// The reserve's stored
|
|
529
|
+
// The reserve's stored conf / spot share and its CURRENT confidence
|
|
515
530
|
// multiplier (in bps). Omit either (or both) for the plain
|
|
516
531
|
// min(price, smoothedPrice) lower bound.
|
|
517
|
-
|
|
532
|
+
share, kBps) => {
|
|
518
533
|
const liquidityAmount = depositedCTokenAmount.multipliedBy(cTokenRatio(reserve));
|
|
519
534
|
const { low, high } = priceRange(reserve);
|
|
520
|
-
const lowerBoundPrice =
|
|
521
|
-
? applyConfidenceMargin(low, high,
|
|
535
|
+
const lowerBoundPrice = share !== undefined && kBps !== undefined
|
|
536
|
+
? applyConfidenceMargin(low, high, share, kBps).lowerBound
|
|
522
537
|
: low;
|
|
523
538
|
return lowerBoundPrice
|
|
524
539
|
.multipliedBy(liquidityAmount)
|