@suilend/sdk 13.8.0-next.gd1e5f5b → 13.8.0-next.gd305fde

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.
@@ -650,7 +650,7 @@ export type ReserveAssetDataEventJSON = {
650
650
  } & ReserveAssetDataEventJSONField;
651
651
  /**
652
652
  * Deprecated: this struct's layout is frozen by Sui's upgrade-compatibility check, since
653
- * it is already published on mainnet. Use `ReserveAssetDataEventV2` instead, which carries
653
+ * it is already published on mainnet. Use `events::suilend_reserve::ReserveAssetDataEventV2` instead, which carries
654
654
  * every field here plus `conf` and the unclamped prices.
655
655
  */
656
656
  export declare class ReserveAssetDataEvent implements StructClass {
@@ -698,102 +698,6 @@ export declare class ReserveAssetDataEvent implements StructClass {
698
698
  }>): ReserveAssetDataEvent;
699
699
  static fetch(client: ClientWithCoreApi, id: string): Promise<ReserveAssetDataEvent>;
700
700
  }
701
- export declare function isReserveAssetDataEventV2(type: string): boolean;
702
- export interface ReserveAssetDataEventV2Fields {
703
- lendingMarketId: ToField<'address'>;
704
- coinType: ToField<TypeName>;
705
- reserveId: ToField<'address'>;
706
- availableAmount: ToField<Decimal>;
707
- supplyAmount: ToField<Decimal>;
708
- borrowedAmount: ToField<Decimal>;
709
- availableAmountUsdEstimate: ToField<Decimal>;
710
- supplyAmountUsdEstimate: ToField<Decimal>;
711
- borrowedAmountUsdEstimate: ToField<Decimal>;
712
- borrowApr: ToField<Decimal>;
713
- supplyApr: ToField<Decimal>;
714
- ctokenSupply: ToField<'u64'>;
715
- cumulativeBorrowRate: ToField<Decimal>;
716
- price: ToField<Decimal>;
717
- smoothedPrice: ToField<Decimal>;
718
- priceLastUpdateTimestampS: ToField<'u64'>;
719
- conf: ToField<Decimal>;
720
- unclampedPrice: ToField<Decimal>;
721
- unclampedSmoothedPrice: ToField<Decimal>;
722
- }
723
- export type ReserveAssetDataEventV2Reified = Reified<ReserveAssetDataEventV2, ReserveAssetDataEventV2Fields>;
724
- export type ReserveAssetDataEventV2JSONField = {
725
- lendingMarketId: string;
726
- coinType: string;
727
- reserveId: string;
728
- availableAmount: ToJSON<Decimal>;
729
- supplyAmount: ToJSON<Decimal>;
730
- borrowedAmount: ToJSON<Decimal>;
731
- availableAmountUsdEstimate: ToJSON<Decimal>;
732
- supplyAmountUsdEstimate: ToJSON<Decimal>;
733
- borrowedAmountUsdEstimate: ToJSON<Decimal>;
734
- borrowApr: ToJSON<Decimal>;
735
- supplyApr: ToJSON<Decimal>;
736
- ctokenSupply: string;
737
- cumulativeBorrowRate: ToJSON<Decimal>;
738
- price: ToJSON<Decimal>;
739
- smoothedPrice: ToJSON<Decimal>;
740
- priceLastUpdateTimestampS: string;
741
- conf: ToJSON<Decimal>;
742
- unclampedPrice: ToJSON<Decimal>;
743
- unclampedSmoothedPrice: ToJSON<Decimal>;
744
- };
745
- export type ReserveAssetDataEventV2JSON = {
746
- $typeName: typeof ReserveAssetDataEventV2.$typeName;
747
- $typeArgs: [];
748
- } & ReserveAssetDataEventV2JSONField;
749
- export declare class ReserveAssetDataEventV2 implements StructClass {
750
- __StructClass: true;
751
- static get $typeName(): `${string}::reserve::ReserveAssetDataEventV2`;
752
- static readonly $numTypeParams = 0;
753
- static readonly $isPhantom: readonly [];
754
- readonly $typeName: typeof ReserveAssetDataEventV2.$typeName;
755
- readonly $fullTypeName: `${string}::reserve::ReserveAssetDataEventV2`;
756
- readonly $typeArgs: [];
757
- readonly $isPhantom: typeof ReserveAssetDataEventV2.$isPhantom;
758
- readonly lendingMarketId: ToField<'address'>;
759
- readonly coinType: ToField<TypeName>;
760
- readonly reserveId: ToField<'address'>;
761
- readonly availableAmount: ToField<Decimal>;
762
- readonly supplyAmount: ToField<Decimal>;
763
- readonly borrowedAmount: ToField<Decimal>;
764
- readonly availableAmountUsdEstimate: ToField<Decimal>;
765
- readonly supplyAmountUsdEstimate: ToField<Decimal>;
766
- readonly borrowedAmountUsdEstimate: ToField<Decimal>;
767
- readonly borrowApr: ToField<Decimal>;
768
- readonly supplyApr: ToField<Decimal>;
769
- readonly ctokenSupply: ToField<'u64'>;
770
- readonly cumulativeBorrowRate: ToField<Decimal>;
771
- readonly price: ToField<Decimal>;
772
- readonly smoothedPrice: ToField<Decimal>;
773
- readonly priceLastUpdateTimestampS: ToField<'u64'>;
774
- readonly conf: ToField<Decimal>;
775
- readonly unclampedPrice: ToField<Decimal>;
776
- readonly unclampedSmoothedPrice: ToField<Decimal>;
777
- private constructor();
778
- static reified(): ReserveAssetDataEventV2Reified;
779
- static get r(): ReserveAssetDataEventV2Reified;
780
- static phantom(): PhantomReified<ToTypeStr<ReserveAssetDataEventV2>>;
781
- static get p(): PhantomReified<ToTypeStr<ReserveAssetDataEventV2>>;
782
- private static instantiateBcs;
783
- private static cachedBcs;
784
- static get bcs(): ReturnType<typeof ReserveAssetDataEventV2.instantiateBcs>;
785
- static fromFields(fields: Record<string, any>): ReserveAssetDataEventV2;
786
- static fromFieldsWithTypes(item: FieldsWithTypes): ReserveAssetDataEventV2;
787
- static fromBcs(data: Uint8Array): ReserveAssetDataEventV2;
788
- toJSONField(): ReserveAssetDataEventV2JSONField;
789
- toJSON(): ReserveAssetDataEventV2JSON;
790
- static fromJSONField(field: any): ReserveAssetDataEventV2;
791
- static fromJSON(json: Record<string, any>): ReserveAssetDataEventV2;
792
- static fromCoreObject(obj: SuiClientTypes.Object<{
793
- content: true;
794
- }>): ReserveAssetDataEventV2;
795
- static fetch(client: ClientWithCoreApi, id: string): Promise<ReserveAssetDataEventV2>;
796
- }
797
701
  export declare function isClaimStakingRewardsEvent(type: string): boolean;
798
702
  export interface ClaimStakingRewardsEventFields {
799
703
  lendingMarketId: ToField<'address'>;
@@ -1756,7 +1756,7 @@ export function isReserveAssetDataEvent(type) {
1756
1756
  }
1757
1757
  /**
1758
1758
  * Deprecated: this struct's layout is frozen by Sui's upgrade-compatibility check, since
1759
- * it is already published on mainnet. Use `ReserveAssetDataEventV2` instead, which carries
1759
+ * it is already published on mainnet. Use `events::suilend_reserve::ReserveAssetDataEventV2` instead, which carries
1760
1760
  * every field here plus `conf` and the unclamped prices.
1761
1761
  */
1762
1762
  export class ReserveAssetDataEvent {
@@ -1986,260 +1986,6 @@ export class ReserveAssetDataEvent {
1986
1986
  return ReserveAssetDataEvent.fromBcs(object.content);
1987
1987
  }
1988
1988
  }
1989
- /* ============================== ReserveAssetDataEventV2 =============================== */
1990
- export function isReserveAssetDataEventV2(type) {
1991
- type = compressSuiType(type);
1992
- return type
1993
- === `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEventV2')}::reserve::ReserveAssetDataEventV2`;
1994
- }
1995
- export class ReserveAssetDataEventV2 {
1996
- __StructClass = true;
1997
- static get $typeName() {
1998
- return `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEventV2')}::reserve::ReserveAssetDataEventV2`;
1999
- }
2000
- static $numTypeParams = 0;
2001
- static $isPhantom = [];
2002
- $typeName = ReserveAssetDataEventV2.$typeName;
2003
- $fullTypeName;
2004
- $typeArgs;
2005
- $isPhantom = ReserveAssetDataEventV2.$isPhantom;
2006
- lendingMarketId;
2007
- coinType;
2008
- reserveId;
2009
- availableAmount;
2010
- supplyAmount;
2011
- borrowedAmount;
2012
- availableAmountUsdEstimate;
2013
- supplyAmountUsdEstimate;
2014
- borrowedAmountUsdEstimate;
2015
- borrowApr;
2016
- supplyApr;
2017
- ctokenSupply;
2018
- cumulativeBorrowRate;
2019
- price;
2020
- smoothedPrice;
2021
- priceLastUpdateTimestampS;
2022
- conf;
2023
- unclampedPrice;
2024
- unclampedSmoothedPrice;
2025
- constructor(typeArgs, fields) {
2026
- this.$fullTypeName = composeSuiType(ReserveAssetDataEventV2.$typeName, ...typeArgs);
2027
- this.$typeArgs = typeArgs;
2028
- this.lendingMarketId = fields.lendingMarketId;
2029
- this.coinType = fields.coinType;
2030
- this.reserveId = fields.reserveId;
2031
- this.availableAmount = fields.availableAmount;
2032
- this.supplyAmount = fields.supplyAmount;
2033
- this.borrowedAmount = fields.borrowedAmount;
2034
- this.availableAmountUsdEstimate = fields.availableAmountUsdEstimate;
2035
- this.supplyAmountUsdEstimate = fields.supplyAmountUsdEstimate;
2036
- this.borrowedAmountUsdEstimate = fields.borrowedAmountUsdEstimate;
2037
- this.borrowApr = fields.borrowApr;
2038
- this.supplyApr = fields.supplyApr;
2039
- this.ctokenSupply = fields.ctokenSupply;
2040
- this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
2041
- this.price = fields.price;
2042
- this.smoothedPrice = fields.smoothedPrice;
2043
- this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
2044
- this.conf = fields.conf;
2045
- this.unclampedPrice = fields.unclampedPrice;
2046
- this.unclampedSmoothedPrice = fields.unclampedSmoothedPrice;
2047
- }
2048
- static reified() {
2049
- const reifiedBcs = ReserveAssetDataEventV2.bcs;
2050
- return {
2051
- get typeName() {
2052
- return ReserveAssetDataEventV2.$typeName;
2053
- },
2054
- get fullTypeName() {
2055
- return composeSuiType(ReserveAssetDataEventV2.$typeName, ...[]);
2056
- },
2057
- typeArgs: [],
2058
- isPhantom: ReserveAssetDataEventV2.$isPhantom,
2059
- reifiedTypeArgs: [],
2060
- fromFields: (fields) => ReserveAssetDataEventV2.fromFields(fields),
2061
- fromFieldsWithTypes: (item) => ReserveAssetDataEventV2.fromFieldsWithTypes(item),
2062
- fromBcs: (data) => ReserveAssetDataEventV2.fromFields(reifiedBcs.parse(data)),
2063
- bcs: reifiedBcs,
2064
- fromJSONField: (field) => ReserveAssetDataEventV2.fromJSONField(field),
2065
- fromJSON: (json) => ReserveAssetDataEventV2.fromJSON(json),
2066
- fromCoreObject: (obj) => ReserveAssetDataEventV2.fromCoreObject(obj),
2067
- fetch: async (client, id) => ReserveAssetDataEventV2.fetch(client, id),
2068
- new: (fields) => {
2069
- return new ReserveAssetDataEventV2([], fields);
2070
- },
2071
- kind: 'StructClassReified',
2072
- };
2073
- }
2074
- static get r() {
2075
- return ReserveAssetDataEventV2.reified();
2076
- }
2077
- static phantom() {
2078
- return phantom(ReserveAssetDataEventV2.reified());
2079
- }
2080
- static get p() {
2081
- return ReserveAssetDataEventV2.phantom();
2082
- }
2083
- static instantiateBcs() {
2084
- return bcs.struct('ReserveAssetDataEventV2', {
2085
- lending_market_id: bcs.bytes(32).transform({
2086
- input: (val) => fromHex(val),
2087
- output: (val) => toHex(val),
2088
- }),
2089
- coin_type: TypeName.bcs,
2090
- reserve_id: bcs.bytes(32).transform({
2091
- input: (val) => fromHex(val),
2092
- output: (val) => toHex(val),
2093
- }),
2094
- available_amount: Decimal.bcs,
2095
- supply_amount: Decimal.bcs,
2096
- borrowed_amount: Decimal.bcs,
2097
- available_amount_usd_estimate: Decimal.bcs,
2098
- supply_amount_usd_estimate: Decimal.bcs,
2099
- borrowed_amount_usd_estimate: Decimal.bcs,
2100
- borrow_apr: Decimal.bcs,
2101
- supply_apr: Decimal.bcs,
2102
- ctoken_supply: bcs.u64(),
2103
- cumulative_borrow_rate: Decimal.bcs,
2104
- price: Decimal.bcs,
2105
- smoothed_price: Decimal.bcs,
2106
- price_last_update_timestamp_s: bcs.u64(),
2107
- conf: Decimal.bcs,
2108
- unclamped_price: Decimal.bcs,
2109
- unclamped_smoothed_price: Decimal.bcs,
2110
- });
2111
- }
2112
- static cachedBcs = null;
2113
- static get bcs() {
2114
- if (!ReserveAssetDataEventV2.cachedBcs) {
2115
- ReserveAssetDataEventV2.cachedBcs = ReserveAssetDataEventV2.instantiateBcs();
2116
- }
2117
- return ReserveAssetDataEventV2.cachedBcs;
2118
- }
2119
- static fromFields(fields) {
2120
- return ReserveAssetDataEventV2.reified().new({
2121
- lendingMarketId: decodeFromFields('address', fields.lending_market_id),
2122
- coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
2123
- reserveId: decodeFromFields('address', fields.reserve_id),
2124
- availableAmount: decodeFromFields(Decimal.reified(), fields.available_amount),
2125
- supplyAmount: decodeFromFields(Decimal.reified(), fields.supply_amount),
2126
- borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
2127
- availableAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.available_amount_usd_estimate),
2128
- supplyAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.supply_amount_usd_estimate),
2129
- borrowedAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.borrowed_amount_usd_estimate),
2130
- borrowApr: decodeFromFields(Decimal.reified(), fields.borrow_apr),
2131
- supplyApr: decodeFromFields(Decimal.reified(), fields.supply_apr),
2132
- ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
2133
- cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
2134
- price: decodeFromFields(Decimal.reified(), fields.price),
2135
- smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
2136
- priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
2137
- conf: decodeFromFields(Decimal.reified(), fields.conf),
2138
- unclampedPrice: decodeFromFields(Decimal.reified(), fields.unclamped_price),
2139
- unclampedSmoothedPrice: decodeFromFields(Decimal.reified(), fields.unclamped_smoothed_price),
2140
- });
2141
- }
2142
- static fromFieldsWithTypes(item) {
2143
- if (!isReserveAssetDataEventV2(item.type)) {
2144
- throw new Error('not a ReserveAssetDataEventV2 type');
2145
- }
2146
- return ReserveAssetDataEventV2.reified().new({
2147
- lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
2148
- coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
2149
- reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
2150
- availableAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount),
2151
- supplyAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount),
2152
- borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
2153
- availableAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount_usd_estimate),
2154
- supplyAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount_usd_estimate),
2155
- borrowedAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount_usd_estimate),
2156
- borrowApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrow_apr),
2157
- supplyApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_apr),
2158
- ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
2159
- cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
2160
- price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
2161
- smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
2162
- priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
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),
2166
- });
2167
- }
2168
- static fromBcs(data) {
2169
- return ReserveAssetDataEventV2.fromFields(ReserveAssetDataEventV2.bcs.parse(data));
2170
- }
2171
- toJSONField() {
2172
- return {
2173
- lendingMarketId: this.lendingMarketId,
2174
- coinType: this.coinType,
2175
- reserveId: this.reserveId,
2176
- availableAmount: this.availableAmount.toJSONField(),
2177
- supplyAmount: this.supplyAmount.toJSONField(),
2178
- borrowedAmount: this.borrowedAmount.toJSONField(),
2179
- availableAmountUsdEstimate: this.availableAmountUsdEstimate.toJSONField(),
2180
- supplyAmountUsdEstimate: this.supplyAmountUsdEstimate.toJSONField(),
2181
- borrowedAmountUsdEstimate: this.borrowedAmountUsdEstimate.toJSONField(),
2182
- borrowApr: this.borrowApr.toJSONField(),
2183
- supplyApr: this.supplyApr.toJSONField(),
2184
- ctokenSupply: this.ctokenSupply.toString(),
2185
- cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
2186
- price: this.price.toJSONField(),
2187
- smoothedPrice: this.smoothedPrice.toJSONField(),
2188
- priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
2189
- conf: this.conf.toJSONField(),
2190
- unclampedPrice: this.unclampedPrice.toJSONField(),
2191
- unclampedSmoothedPrice: this.unclampedSmoothedPrice.toJSONField(),
2192
- };
2193
- }
2194
- toJSON() {
2195
- return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
2196
- }
2197
- static fromJSONField(field) {
2198
- return ReserveAssetDataEventV2.reified().new({
2199
- lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
2200
- coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
2201
- reserveId: decodeFromJSONField('address', field.reserveId),
2202
- availableAmount: decodeFromJSONField(Decimal.reified(), field.availableAmount),
2203
- supplyAmount: decodeFromJSONField(Decimal.reified(), field.supplyAmount),
2204
- borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
2205
- availableAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.availableAmountUsdEstimate),
2206
- supplyAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.supplyAmountUsdEstimate),
2207
- borrowedAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.borrowedAmountUsdEstimate),
2208
- borrowApr: decodeFromJSONField(Decimal.reified(), field.borrowApr),
2209
- supplyApr: decodeFromJSONField(Decimal.reified(), field.supplyApr),
2210
- ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
2211
- cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
2212
- price: decodeFromJSONField(Decimal.reified(), field.price),
2213
- smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
2214
- priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
2215
- conf: decodeFromJSONField(Decimal.reified(), field.conf),
2216
- unclampedPrice: decodeFromJSONField(Decimal.reified(), field.unclampedPrice),
2217
- unclampedSmoothedPrice: decodeFromJSONField(Decimal.reified(), field.unclampedSmoothedPrice),
2218
- });
2219
- }
2220
- static fromJSON(json) {
2221
- if (json.$typeName !== ReserveAssetDataEventV2.$typeName) {
2222
- throw new Error(`not a ReserveAssetDataEventV2 json object: expected '${ReserveAssetDataEventV2.$typeName}' but got '${json.$typeName}'`);
2223
- }
2224
- return ReserveAssetDataEventV2.fromJSONField(json);
2225
- }
2226
- static fromCoreObject(obj) {
2227
- if (!isReserveAssetDataEventV2(obj.type)) {
2228
- throw new Error(`object at ${obj.objectId} is not a ReserveAssetDataEventV2 object`);
2229
- }
2230
- return ReserveAssetDataEventV2.fromBcs(obj.content);
2231
- }
2232
- static async fetch(client, id) {
2233
- const { object } = await client.core.getObject({
2234
- objectId: id,
2235
- include: { content: true },
2236
- });
2237
- if (!isReserveAssetDataEventV2(object.type)) {
2238
- throw new Error(`object at id ${id} is not a ReserveAssetDataEventV2 object`);
2239
- }
2240
- return ReserveAssetDataEventV2.fromBcs(object.content);
2241
- }
2242
- }
2243
1989
  /* ============================== ClaimStakingRewardsEvent =============================== */
2244
1990
  export function isClaimStakingRewardsEvent(type) {
2245
1991
  type = compressSuiType(type);
@@ -158,6 +158,7 @@ export type InitializePriceInputs = {
158
158
  export declare const getInitializePriceInputs: (lendingMarkets: {
159
159
  reserves: Reserve<string>[];
160
160
  }[], nowMs: number) => InitializePriceInputs;
161
+ type ConfidenceByCoinType = simulate.ConfidenceByCoinType;
161
162
  export declare const initializeSuilendAll: (suiGrpcClient: SuiGrpcClient, markets: InitializeSuilendMarket[], fallbackPythEndpoint?: string, options?: InitializeSuilendOptions) => Promise<{
162
163
  lendingMarket: {
163
164
  version: bigint;
@@ -410,6 +411,10 @@ export declare const initializeSuilendAll: (suiGrpcClient: SuiGrpcClient, market
410
411
  description: string;
411
412
  totalDeposits: BigNumber;
412
413
  }>;
414
+ confidenceByCoinType: Map<string, {
415
+ readonly share: simulate.ConfidenceShare | undefined;
416
+ readonly kBps: BigNumber;
417
+ }>;
413
418
  reserveCoinTypes: string[];
414
419
  reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
415
420
  rewardCoinTypes: string[];
@@ -669,6 +674,10 @@ export declare const initializeSuilendWithRewardsAll: (suiGrpcClient: SuiGrpcCli
669
674
  description: string;
670
675
  totalDeposits: BigNumber;
671
676
  }>;
677
+ confidenceByCoinType: Map<string, {
678
+ readonly share: simulate.ConfidenceShare | undefined;
679
+ readonly kBps: BigNumber;
680
+ }>;
672
681
  reserveCoinTypes: string[];
673
682
  reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
674
683
  rewardCoinTypes: string[];
@@ -927,6 +936,10 @@ export declare const initializeSuilend: (suiGrpcClient: SuiGrpcClient, suilendCl
927
936
  description: string;
928
937
  totalDeposits: BigNumber;
929
938
  }>;
939
+ confidenceByCoinType: Map<string, {
940
+ readonly share: simulate.ConfidenceShare | undefined;
941
+ readonly kBps: BigNumber;
942
+ }>;
930
943
  reserveCoinTypes: string[];
931
944
  reserveCoinMetadataMap: Record<string, import("@suilend/sui-core").Token>;
932
945
  rewardCoinTypes: string[];
@@ -952,7 +965,7 @@ export type OwnedObligations = {
952
965
  obligationErrors: Record<string, unknown>;
953
966
  };
954
967
  export declare const fetchOwnedObligations: (suiGrpcClient: SuiGrpcClient, address: string) => Promise<OwnedObligations>;
955
- export declare const parseOwnedObligations: (owned: OwnedObligations, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>) => {
968
+ export declare const parseOwnedObligations: (owned: OwnedObligations, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, confidenceByCoinType?: ConfidenceByCoinType) => {
956
969
  strategyOwnerCaps: StrategyOwnerCap[];
957
970
  strategyObligations: {
958
971
  id: string;
@@ -1474,7 +1487,7 @@ export declare const parseOwnedObligations: (owned: OwnedObligations, suilendCli
1474
1487
  minPriceBorrowLimit: BigNumber;
1475
1488
  }[];
1476
1489
  };
1477
- export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
1490
+ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string, confidenceByCoinType?: ConfidenceByCoinType) => Promise<{
1478
1491
  strategyOwnerCaps: StrategyOwnerCap[];
1479
1492
  strategyObligations: {
1480
1493
  id: string;
package/lib/initialize.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { normalizeStructTag, parseStructTag } from "@mysten/sui/utils";
2
2
  import BigNumber from "bignumber.js";
3
+ import pLimit from "p-limit";
3
4
  import { NORMALIZED_ALKIMI_COINTYPE, NORMALIZED_AUSD_COINTYPE, NORMALIZED_BLUE_COINTYPE, NORMALIZED_BUCK_COINTYPE, NORMALIZED_DEEP_COINTYPE, NORMALIZED_DMC_COINTYPE, NORMALIZED_FUD_COINTYPE, NORMALIZED_HAEDAL_COINTYPE, NORMALIZED_HIPPO_COINTYPE, NORMALIZED_IKA_COINTYPE, NORMALIZED_KOBAN_COINTYPE, NORMALIZED_LBTC_COINTYPE, NORMALIZED_NS_COINTYPE, NORMALIZED_SEND_COINTYPE, NORMALIZED_SEND_POINTS_S1_COINTYPE, NORMALIZED_SEND_POINTS_S2_COINTYPE, NORMALIZED_SOL_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_UP_COINTYPE, NORMALIZED_USDB_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_WAL_COINTYPE, NORMALIZED_WBTC_COINTYPE, NORMALIZED_WETH_COINTYPE, NORMALIZED_XAUm_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_eTHIRD_COINTYPE, NORMALIZED_flSUI_COINTYPE, NORMALIZED_fpSUI_COINTYPE, NORMALIZED_fudSUI_COINTYPE, NORMALIZED_iSUI_COINTYPE, NORMALIZED_jugSUI_COINTYPE, NORMALIZED_kSUI_COINTYPE, NORMALIZED_mSUI_COINTYPE, NORMALIZED_mUSD_COINTYPE, NORMALIZED_oshiSUI_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_sdeUSD_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiETH_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiUSDe_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_trevinSUI_COINTYPE, NORMALIZED_upSUI_COINTYPE, NORMALIZED_wUSDC_COINTYPE, NORMALIZED_wUSDT_COINTYPE, NORMALIZED_xBTC_COINTYPE, NORMALIZED_yapSUI_COINTYPE, TEMPORARY_PYTH_PRICE_FEED_COINTYPES, getCoinMetadataMapPartial, getPrices, isSendPoints, isSteammPoints, } from "@suilend/sui-core";
4
5
  import { phantom } from "../_generated/_framework/reified.js";
5
6
  import { PACKAGE_ID } from "../_generated/suilend/index.js";
@@ -310,7 +311,34 @@ const fillRewardPriceMap = (rewardPriceMap, reservelessActiveRewardCoinTypes, ca
310
311
  }
311
312
  return rewardPriceMap;
312
313
  };
313
- const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options, includeRewards) => {
314
+ const kBpsByConfigBagId = new Map();
315
+ const confidenceReadLimit = pLimit(8);
316
+ const configConfidenceMultiplierBps = (suiGrpcClient, bagId) => {
317
+ const cached = kBpsByConfigBagId.get(bagId);
318
+ if (cached)
319
+ return cached;
320
+ const read = confidenceReadLimit(() => SuilendClient.getReserveConfidenceMultiplierBps(suiGrpcClient, bagId));
321
+ kBpsByConfigBagId.set(bagId, read);
322
+ read.catch(() => kBpsByConfigBagId.delete(bagId));
323
+ return read;
324
+ };
325
+ const reserveConfidenceMultipliers = (suiGrpcClient, reserves) => Promise.all(reserves.map(async (reserve) => {
326
+ const { id: bagId, size } = reserve.config.element
327
+ .additionalFields;
328
+ const kBps = BigInt(size) === BigInt(0)
329
+ ? new BigNumber(0)
330
+ : await configConfidenceMultiplierBps(suiGrpcClient, bagId);
331
+ return [normalizeStructTag(reserve.coinType), kBps];
332
+ })).then((entries) => new Map(entries));
333
+ const reserveConfidenceByCoinType = async (suiGrpcClient, reserves, kBpsByCoinType) => new Map(await Promise.all(reserves.map(async (reserve) => {
334
+ const coinType = normalizeStructTag(reserve.coinType);
335
+ const kBps = kBpsByCoinType.get(coinType) ?? new BigNumber(0);
336
+ const share = kBps.isZero() || simulate.isRefreshedFromFeed(reserve)
337
+ ? undefined
338
+ : await confidenceReadLimit(() => SuilendClient.getReserveConfidenceShare(suiGrpcClient, reserve.id));
339
+ return [coinType, { share, kBps }];
340
+ })));
341
+ const initializeSuilendMarkets = async (suiGrpcClient, markets, fallbackPythEndpoint, options, includeRewards) => {
314
342
  const nowMs = Date.now();
315
343
  const nowS = Math.floor(nowMs / 1000);
316
344
  const fetchPrices = options?.fetchPrices ?? getPrices;
@@ -330,7 +358,7 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
330
358
  });
331
359
  const coinTypesByMarket = reservesByMarket.map(({ withoutTemporaryPythPriceFeeds, withTemporaryPythPriceFeeds }) => marketCoinTypes([...withoutTemporaryPythPriceFeeds, ...withTemporaryPythPriceFeeds], nowMs));
332
360
  const reservelessActiveRewardCoinTypesByMarket = coinTypesByMarket.map(reservelessActiveRewardCoinTypes);
333
- const [[refreshedWithoutTemporaryByMarket, fabricatedPriceCoinTypesByMarket], coinMetadataByMarket, rewardUsdPrices,] = await Promise.all([
361
+ const [[refreshedWithoutTemporaryByMarket, fabricatedPriceCoinTypesByMarket], coinMetadataByMarket, rewardUsdPrices, kBpsByMarket,] = await Promise.all([
334
362
  Promise.all([
335
363
  resolvePythConnection(options?.pythConnection, fallbackPythEndpoint, options?.pythConnectionConfig).then((pythConnection) => refreshReservesForInitializeAll(reservesByMarket.map((r) => r.withoutTemporaryPythPriceFeeds), pythConnection, options?.tolerateMissingPriceFeeds)),
336
364
  priceTemporaryPythFeedReservesAll(reservesByMarket.map((r) => r.withTemporaryPythPriceFeeds), fetchPrices),
@@ -346,6 +374,7 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
346
374
  return {};
347
375
  })
348
376
  : Promise.resolve({}),
377
+ Promise.all(markets.map(({ suilendClient }) => reserveConfidenceMultipliers(suiGrpcClient, suilendClient.lendingMarket.reserves))),
349
378
  ]);
350
379
  const prepared = markets.map(({ suilendClient, lendingMarketMetadata }, index) => {
351
380
  const refreshedRawReserves = [
@@ -379,6 +408,7 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
379
408
  ...coinTypesByMarket[index],
380
409
  };
381
410
  });
411
+ const confidenceByMarket = await Promise.all(prepared.map(({ refreshedRawReserves }, index) => reserveConfidenceByCoinType(suiGrpcClient, refreshedRawReserves, kBpsByMarket[index])));
382
412
  const initialized = prepared.map(({ suilendClient, lendingMarketMetadata, refreshedRawReserves, unpricedCoinTypes, uniqueReserveCoinTypes, uniqueRewardCoinTypes, uniqueActiveRewardsCoinTypes, }, index) => {
383
413
  const { coinMetadataMap, reserveCoinMetadataMap, rewardCoinMetadataMap } = coinMetadataByMarket[index];
384
414
  // const walReserve = refreshedRawReserves.find(
@@ -391,7 +421,7 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
391
421
  // (walReserve.price.value as bigint) = walPrice;
392
422
  // (walReserve.smoothedPrice.value as bigint) = walPrice;
393
423
  // }
394
- const lendingMarket = parseLendingMarket(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap, nowS, lendingMarketMetadata);
424
+ const lendingMarket = parseLendingMarket(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap, nowS, lendingMarketMetadata, confidenceByMarket[index]);
395
425
  const reserveOrder = resolveReserveOrder(lendingMarket.id, lendingMarketMetadata);
396
426
  if (reserveOrder) {
397
427
  lendingMarket.reserves = sortReservesByOrder(lendingMarket.reserves, reserveOrder);
@@ -403,6 +433,7 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
403
433
  refreshedRawReserves,
404
434
  unpricedCoinTypes,
405
435
  reserveMap,
436
+ confidenceByCoinType: confidenceByMarket[index],
406
437
  reserveCoinTypes: uniqueReserveCoinTypes,
407
438
  reserveCoinMetadataMap,
408
439
  rewardCoinTypes: uniqueRewardCoinTypes,
@@ -416,11 +447,11 @@ const initializeSuilendMarkets = async (markets, fallbackPythEndpoint, options,
416
447
  return { initialized, rewardPriceMaps };
417
448
  };
418
449
  export const initializeSuilendAll = async (suiGrpcClient, markets, fallbackPythEndpoint, options) => {
419
- const { initialized } = await initializeSuilendMarkets(markets, fallbackPythEndpoint, options, false);
450
+ const { initialized } = await initializeSuilendMarkets(suiGrpcClient, markets, fallbackPythEndpoint, options, false);
420
451
  return initialized;
421
452
  };
422
453
  export const initializeSuilendWithRewardsAll = async (suiGrpcClient, markets, fallbackPythEndpoint, options) => {
423
- const { initialized, rewardPriceMaps } = await initializeSuilendMarkets(markets, fallbackPythEndpoint, options, true);
454
+ const { initialized, rewardPriceMaps } = await initializeSuilendMarkets(suiGrpcClient, markets, fallbackPythEndpoint, options, true);
424
455
  return initialized.map((market, index) => ({
425
456
  ...market,
426
457
  rewardPriceMap: rewardPriceMaps[index],
@@ -518,9 +549,9 @@ const obligationIdsOf = ({ strategyOwnerCaps, obligationOwnerCaps, }) => [
518
549
  ...strategyOwnerCaps.map((soc) => soc.obligationId),
519
550
  ...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
520
551
  ];
521
- const parseMarketObligations = (rawObligations, { strategyOwnerCaps, obligationOwnerCaps }, refreshedRawReserves, reserveMap) => {
552
+ const parseMarketObligations = (rawObligations, { strategyOwnerCaps, obligationOwnerCaps }, refreshedRawReserves, reserveMap, confidenceByCoinType) => {
522
553
  const obligations = rawObligations
523
- .map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
554
+ .map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves, confidenceByCoinType))
524
555
  .map((refreshedObligation) => parseObligation(refreshedObligation, reserveMap, strategyOwnerCaps.some((soc) => soc.obligationId === refreshedObligation.id)))
525
556
  .sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
526
557
  const strategyObligations = obligations.filter((o) => strategyOwnerCaps.some((soc) => soc.obligationId === o.id));
@@ -568,7 +599,7 @@ export const fetchOwnedObligations = async (suiGrpcClient, address) => {
568
599
  obligationErrors,
569
600
  };
570
601
  };
571
- export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves, reserveMap) => {
602
+ export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves, reserveMap, confidenceByCoinType) => {
572
603
  const marketCaps = selectMarketCaps(owned, suilendClient);
573
604
  const obligationsById = new Map(owned.obligations.map((obligation) => [obligation.id, obligation]));
574
605
  const rawObligations = obligationIdsOf(marketCaps).map((obligationId) => {
@@ -579,9 +610,9 @@ export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves
579
610
  throw owned.obligationErrors[obligationId];
580
611
  throw new Error(`Obligation ${obligationId} is not in the owned obligations`);
581
612
  });
582
- return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
613
+ return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap, confidenceByCoinType);
583
614
  };
584
- export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address) => {
615
+ export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address, confidenceByCoinType) => {
585
616
  if (!address)
586
617
  return {
587
618
  strategyOwnerCaps: [],
@@ -591,5 +622,5 @@ export const initializeObligations = async (suiGrpcClient, suilendClient, refres
591
622
  };
592
623
  const marketCaps = selectMarketCaps(await listOwnedCaps(suiGrpcClient, address, hasStrategies(suilendClient)), suilendClient);
593
624
  const rawObligations = await SuilendClient.getObligations(obligationIdsOf(marketCaps), suilendClient.lendingMarket.$typeArgs, suiGrpcClient);
594
- return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
625
+ return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap, confidenceByCoinType);
595
626
  };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sdk","version":"13.8.0-next.gd1e5f5b","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
+ {"name":"@suilend/sdk","version":"13.8.0-next.gd305fde","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"}
@@ -3,8 +3,9 @@ import BigNumber from "bignumber.js";
3
3
  import { LendingMarket } from "../_generated/suilend/lending-market/structs";
4
4
  import { Reserve } from "../_generated/suilend/reserve/structs";
5
5
  import { LendingMarketMetadata } from "../lib";
6
+ import * as simulate from "../utils/simulate";
6
7
  export type ParsedLendingMarket = ReturnType<typeof parseLendingMarket>;
7
- export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>, nowS: number, lendingMarketMetadata?: LendingMarketMetadata) => {
8
+ export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>, nowS: number, lendingMarketMetadata?: LendingMarketMetadata, confidenceByCoinType?: simulate.ConfidenceByCoinType) => {
8
9
  version: bigint;
9
10
  reserves: {
10
11
  config: {
@@ -1,11 +1,18 @@
1
+ import { normalizeStructTag } from "@mysten/sui/utils";
1
2
  import BigNumber from "bignumber.js";
3
+ import * as simulate from "../utils/simulate.js";
2
4
  import { parseRateLimiter } from "./rateLimiter.js";
3
5
  import { parseReserve } from "./reserve.js";
4
- export const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS, lendingMarketMetadata) => {
6
+ export const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS, lendingMarketMetadata, confidenceByCoinType) => {
5
7
  const id = lendingMarket.id;
6
8
  const type = lendingMarket.$typeArgs[0];
7
9
  const version = lendingMarket.version;
8
- const parsedReserves = reserves.map((reserve) => parseReserve(reserve, coinMetadataMap));
10
+ const normalizedConfidence = confidenceByCoinType &&
11
+ simulate.normalizeConfidenceByCoinType(confidenceByCoinType);
12
+ const parsedReserves = reserves.map((reserve) => {
13
+ const confidence = simulate.resolveConfidence(normalizedConfidence?.get(normalizeStructTag(reserve.coinType)), reserve);
14
+ return parseReserve(reserve, coinMetadataMap, confidence?.share, confidence?.kBps);
15
+ });
9
16
  const obligations = lendingMarket.obligations;
10
17
  const parsedRateLimiter = parseRateLimiter(lendingMarket.rateLimiter, nowS);
11
18
  const feeReceiver = lendingMarket.feeReceiver;
@@ -6,7 +6,12 @@ export type PriceGuardState = {
6
6
  anchorTimestampS: bigint;
7
7
  };
8
8
  export declare const clampToBand: (anchor: bigint, price: bigint, bandBps: bigint) => bigint;
9
- export declare const applyPriceGuard: (price: bigint, smoothedPrice: bigint, guard: PriceGuardState) => {
9
+ export type StoredPrices = {
10
+ price: bigint;
11
+ smoothedPrice: bigint;
12
+ };
13
+ export declare const nextAnchor: (anchor: bigint, stored: bigint, incoming: bigint, bandBps: bigint) => bigint;
14
+ export declare const applyPriceGuard: (price: bigint, smoothedPrice: bigint, guard: PriceGuardState, nowS: bigint, stored: StoredPrices | null) => {
10
15
  price: bigint;
11
16
  smoothedPrice: bigint;
12
17
  wasClamped: boolean;
@@ -14,11 +14,29 @@ export const clampToBand = (anchor, price, bandBps) => {
14
14
  const atLeastLower = price > lower ? price : lower;
15
15
  return atLeastLower < upper ? atLeastLower : upper;
16
16
  };
17
- // Models one refresh against the stored anchors. The chain advances the anchors after
18
- // clamping, which this does not, so callers must re-read the guard instead of chaining results.
19
- export const applyPriceGuard = (price, smoothedPrice, guard) => {
20
- const clampedPrice = clampToBand(guard.priceAnchor, price, guard.maxPriceChangeBps);
21
- const clampedSmoothedPrice = clampToBand(guard.smoothedPriceAnchor, smoothedPrice, guard.maxPriceChangeBps);
17
+ export const nextAnchor = (anchor, stored, incoming, bandBps) => {
18
+ if (anchor === 0n)
19
+ return incoming;
20
+ const carried = clampToBand(anchor, stored, bandBps);
21
+ return carried === 0n ? clampToBand(anchor, incoming, bandBps) : carried;
22
+ };
23
+ // Models one refresh at nowS. Once the guard's interval has elapsed, the chain opens the
24
+ // next one on the prices the reserve holds, so without `stored` this clamps against the
25
+ // read anchors instead and can land up to a band off. The chain also writes the anchors,
26
+ // which this does not, so callers must re-read the guard instead of chaining results.
27
+ export const applyPriceGuard = (price, smoothedPrice, guard, nowS, stored) => {
28
+ const band = guard.maxPriceChangeBps;
29
+ const opens = stored != null &&
30
+ band > 0n &&
31
+ nowS - guard.anchorTimestampS >= guard.minUpdateIntervalS;
32
+ const priceAnchor = opens
33
+ ? nextAnchor(guard.priceAnchor, stored.price, price, band)
34
+ : guard.priceAnchor;
35
+ const smoothedPriceAnchor = opens
36
+ ? nextAnchor(guard.smoothedPriceAnchor, stored.smoothedPrice, smoothedPrice, band)
37
+ : guard.smoothedPriceAnchor;
38
+ const clampedPrice = clampToBand(priceAnchor, price, band);
39
+ const clampedSmoothedPrice = clampToBand(smoothedPriceAnchor, smoothedPrice, band);
22
40
  return {
23
41
  price: clampedPrice,
24
42
  smoothedPrice: clampedSmoothedPrice,
@@ -156,6 +156,19 @@ export type ConfidenceShare = BigNumber & {
156
156
  };
157
157
  /** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
158
158
  export declare const confidenceShare: (conf: BigNumber, spot: BigNumber) => ConfidenceShare;
159
+ export type ConfidenceByCoinType = Map<string, {
160
+ share: ConfidenceShare | undefined;
161
+ kBps: BigNumber;
162
+ }>;
163
+ export declare const normalizeConfidenceByCoinType: (confidenceByCoinType: ConfidenceByCoinType) => ConfidenceByCoinType;
164
+ export declare const isRefreshedFromFeed: (reserve: Reserve<string>) => boolean;
165
+ export declare const resolveConfidence: (entry: {
166
+ share: ConfidenceShare | undefined;
167
+ kBps: BigNumber;
168
+ } | undefined, reserve: Reserve<string>) => {
169
+ share: ConfidenceShare;
170
+ kBps: BigNumber;
171
+ } | undefined;
159
172
  /**
160
173
  * Pure computation half of `refreshObligation`: same math, but returns fresh
161
174
  * deposits/borrows/reward-manager arrays and the five USD aggregates instead
@@ -165,11 +178,8 @@ export declare const confidenceShare: (conf: BigNumber, spot: BigNumber) => Conf
165
178
  * shallow-copied), silently corrupting `unrefreshedObligation` for anyone still
166
179
  * holding a reference to it.
167
180
  */
168
- export declare function computeObligationRefresh(obligation: Obligation<string>, refreshedReserves: Reserve<string>[], nowMs: number, confidenceByCoinType?: Map<string, {
169
- share: ConfidenceShare | undefined;
170
- kBps: BigNumber;
171
- }>): ObligationRefresh;
172
- export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[]) => Obligation<string>;
181
+ export declare function computeObligationRefresh(obligation: Obligation<string>, refreshedReserves: Reserve<string>[], nowMs: number, confidenceByCoinType?: ConfidenceByCoinType): ObligationRefresh;
182
+ export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[], confidenceByCoinType?: ConfidenceByCoinType) => Obligation<string>;
173
183
  export declare const numberToDecimal: (value: number) => Decimal;
174
184
  export declare const stringToDecimal: (value: string) => Decimal;
175
185
  export declare const decimalToBigNumber: (value: Decimal) => BigNumber;
package/utils/simulate.js CHANGED
@@ -355,10 +355,15 @@ export const computeCloseLtv = (config) => new BigNumber(config.closeLtvPct / 10
355
355
  /** Mirrors reserve.move's `record_confidence`: a zero spot records a zero share. */
356
356
  export const confidenceShare = (conf, spot) => (spot.isZero() ? new BigNumber(0) : conf.dividedBy(spot));
357
357
  const ZERO_SHARE = confidenceShare(new BigNumber(0), new BigNumber(0));
358
- const resolveConfidence = (entry, reserve) => {
358
+ export const normalizeConfidenceByCoinType = (confidenceByCoinType) => new Map([...confidenceByCoinType].map(([coinType, entry]) => [
359
+ normalizeStructTag(coinType),
360
+ entry,
361
+ ]));
362
+ export const isRefreshedFromFeed = (reserve) => "feedConfidence" in reserve;
363
+ export const resolveConfidence = (entry, reserve) => {
359
364
  if (entry === undefined)
360
365
  return undefined;
361
- const refreshedFromFeed = "feedConfidence" in reserve;
366
+ const refreshedFromFeed = isRefreshedFromFeed(reserve);
362
367
  const feedConf = feedConfidenceOf(reserve);
363
368
  const share = (feedConf !== undefined
364
369
  ? confidenceShare(feedConf, unclampedSpot(reserve))
@@ -390,11 +395,7 @@ export function computeObligationRefresh(obligation, refreshedReserves, nowMs,
390
395
  // precedence because it comes from the same update as its price. A reserve
391
396
  // with no entry here gets plain min/max(price, smoothedPrice) bounds.
392
397
  confidenceByCoinType) {
393
- const normalizedConfidence = confidenceByCoinType &&
394
- new Map([...confidenceByCoinType].map(([coinType, entry]) => [
395
- normalizeStructTag(coinType),
396
- entry,
397
- ]));
398
+ const normalizedConfidence = confidenceByCoinType && normalizeConfidenceByCoinType(confidenceByCoinType);
398
399
  const userRewardManagers = [...obligation.userRewardManagers];
399
400
  let depositValueUsd = new BigNumber(0);
400
401
  let allowedBorrowValueUsd = new BigNumber(0);
@@ -475,8 +476,8 @@ confidenceByCoinType) {
475
476
  weightedBorrowedValueUpperBoundUsd,
476
477
  };
477
478
  }
478
- export const refreshObligation = (unrefreshedObligation, refreshedReserves) => {
479
- const refresh = computeObligationRefresh(unrefreshedObligation, refreshedReserves, Date.now());
479
+ export const refreshObligation = (unrefreshedObligation, refreshedReserves, confidenceByCoinType) => {
480
+ const refresh = computeObligationRefresh(unrefreshedObligation, refreshedReserves, Date.now(), confidenceByCoinType);
480
481
  return {
481
482
  ...unrefreshedObligation,
482
483
  deposits: refresh.deposits,