@suilend/sdk 13.0.0 → 13.1.0-next.g093f417
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 +95 -0
- package/_generated/suilend/reserve/structs.js +245 -0
- package/client.d.ts +11 -1
- package/client.js +63 -11
- package/lib/strategyOwnerCap.js +7 -8
- package/package.json +1 -1
- package/utils/events.d.ts +20 -0
- package/utils/events.js +3 -1
- package/utils/simulate.d.ts +12 -0
- package/utils/simulate.js +14 -0
|
@@ -648,6 +648,11 @@ export type ReserveAssetDataEventJSON = {
|
|
|
648
648
|
$typeName: typeof ReserveAssetDataEvent.$typeName;
|
|
649
649
|
$typeArgs: [];
|
|
650
650
|
} & ReserveAssetDataEventJSONField;
|
|
651
|
+
/**
|
|
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
|
|
654
|
+
* every field here plus `conf`.
|
|
655
|
+
*/
|
|
651
656
|
export declare class ReserveAssetDataEvent implements StructClass {
|
|
652
657
|
__StructClass: true;
|
|
653
658
|
static get $typeName(): `${string}::reserve::ReserveAssetDataEvent`;
|
|
@@ -693,6 +698,96 @@ export declare class ReserveAssetDataEvent implements StructClass {
|
|
|
693
698
|
}>): ReserveAssetDataEvent;
|
|
694
699
|
static fetch(client: ClientWithCoreApi, id: string): Promise<ReserveAssetDataEvent>;
|
|
695
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
|
+
}
|
|
721
|
+
export type ReserveAssetDataEventV2Reified = Reified<ReserveAssetDataEventV2, ReserveAssetDataEventV2Fields>;
|
|
722
|
+
export type ReserveAssetDataEventV2JSONField = {
|
|
723
|
+
lendingMarketId: string;
|
|
724
|
+
coinType: string;
|
|
725
|
+
reserveId: string;
|
|
726
|
+
availableAmount: ToJSON<Decimal>;
|
|
727
|
+
supplyAmount: ToJSON<Decimal>;
|
|
728
|
+
borrowedAmount: ToJSON<Decimal>;
|
|
729
|
+
availableAmountUsdEstimate: ToJSON<Decimal>;
|
|
730
|
+
supplyAmountUsdEstimate: ToJSON<Decimal>;
|
|
731
|
+
borrowedAmountUsdEstimate: ToJSON<Decimal>;
|
|
732
|
+
borrowApr: ToJSON<Decimal>;
|
|
733
|
+
supplyApr: ToJSON<Decimal>;
|
|
734
|
+
ctokenSupply: string;
|
|
735
|
+
cumulativeBorrowRate: ToJSON<Decimal>;
|
|
736
|
+
price: ToJSON<Decimal>;
|
|
737
|
+
smoothedPrice: ToJSON<Decimal>;
|
|
738
|
+
priceLastUpdateTimestampS: string;
|
|
739
|
+
conf: ToJSON<Decimal>;
|
|
740
|
+
};
|
|
741
|
+
export type ReserveAssetDataEventV2JSON = {
|
|
742
|
+
$typeName: typeof ReserveAssetDataEventV2.$typeName;
|
|
743
|
+
$typeArgs: [];
|
|
744
|
+
} & ReserveAssetDataEventV2JSONField;
|
|
745
|
+
export declare class ReserveAssetDataEventV2 implements StructClass {
|
|
746
|
+
__StructClass: true;
|
|
747
|
+
static get $typeName(): `${string}::reserve::ReserveAssetDataEventV2`;
|
|
748
|
+
static readonly $numTypeParams = 0;
|
|
749
|
+
static readonly $isPhantom: readonly [];
|
|
750
|
+
readonly $typeName: typeof ReserveAssetDataEventV2.$typeName;
|
|
751
|
+
readonly $fullTypeName: `${string}::reserve::ReserveAssetDataEventV2`;
|
|
752
|
+
readonly $typeArgs: [];
|
|
753
|
+
readonly $isPhantom: typeof ReserveAssetDataEventV2.$isPhantom;
|
|
754
|
+
readonly lendingMarketId: ToField<'address'>;
|
|
755
|
+
readonly coinType: ToField<TypeName>;
|
|
756
|
+
readonly reserveId: ToField<'address'>;
|
|
757
|
+
readonly availableAmount: ToField<Decimal>;
|
|
758
|
+
readonly supplyAmount: ToField<Decimal>;
|
|
759
|
+
readonly borrowedAmount: ToField<Decimal>;
|
|
760
|
+
readonly availableAmountUsdEstimate: ToField<Decimal>;
|
|
761
|
+
readonly supplyAmountUsdEstimate: ToField<Decimal>;
|
|
762
|
+
readonly borrowedAmountUsdEstimate: ToField<Decimal>;
|
|
763
|
+
readonly borrowApr: ToField<Decimal>;
|
|
764
|
+
readonly supplyApr: ToField<Decimal>;
|
|
765
|
+
readonly ctokenSupply: ToField<'u64'>;
|
|
766
|
+
readonly cumulativeBorrowRate: ToField<Decimal>;
|
|
767
|
+
readonly price: ToField<Decimal>;
|
|
768
|
+
readonly smoothedPrice: ToField<Decimal>;
|
|
769
|
+
readonly priceLastUpdateTimestampS: ToField<'u64'>;
|
|
770
|
+
readonly conf: ToField<Decimal>;
|
|
771
|
+
private constructor();
|
|
772
|
+
static reified(): ReserveAssetDataEventV2Reified;
|
|
773
|
+
static get r(): ReserveAssetDataEventV2Reified;
|
|
774
|
+
static phantom(): PhantomReified<ToTypeStr<ReserveAssetDataEventV2>>;
|
|
775
|
+
static get p(): PhantomReified<ToTypeStr<ReserveAssetDataEventV2>>;
|
|
776
|
+
private static instantiateBcs;
|
|
777
|
+
private static cachedBcs;
|
|
778
|
+
static get bcs(): ReturnType<typeof ReserveAssetDataEventV2.instantiateBcs>;
|
|
779
|
+
static fromFields(fields: Record<string, any>): ReserveAssetDataEventV2;
|
|
780
|
+
static fromFieldsWithTypes(item: FieldsWithTypes): ReserveAssetDataEventV2;
|
|
781
|
+
static fromBcs(data: Uint8Array): ReserveAssetDataEventV2;
|
|
782
|
+
toJSONField(): ReserveAssetDataEventV2JSONField;
|
|
783
|
+
toJSON(): ReserveAssetDataEventV2JSON;
|
|
784
|
+
static fromJSONField(field: any): ReserveAssetDataEventV2;
|
|
785
|
+
static fromJSON(json: Record<string, any>): ReserveAssetDataEventV2;
|
|
786
|
+
static fromCoreObject(obj: SuiClientTypes.Object<{
|
|
787
|
+
content: true;
|
|
788
|
+
}>): ReserveAssetDataEventV2;
|
|
789
|
+
static fetch(client: ClientWithCoreApi, id: string): Promise<ReserveAssetDataEventV2>;
|
|
790
|
+
}
|
|
696
791
|
export declare function isClaimStakingRewardsEvent(type: string): boolean;
|
|
697
792
|
export interface ClaimStakingRewardsEventFields {
|
|
698
793
|
lendingMarketId: ToField<'address'>;
|
|
@@ -1754,6 +1754,11 @@ export function isReserveAssetDataEvent(type) {
|
|
|
1754
1754
|
return type
|
|
1755
1755
|
=== `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEvent')}::reserve::ReserveAssetDataEvent`;
|
|
1756
1756
|
}
|
|
1757
|
+
/**
|
|
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
|
|
1760
|
+
* every field here plus `conf`.
|
|
1761
|
+
*/
|
|
1757
1762
|
export class ReserveAssetDataEvent {
|
|
1758
1763
|
__StructClass = true;
|
|
1759
1764
|
static get $typeName() {
|
|
@@ -1981,6 +1986,246 @@ export class ReserveAssetDataEvent {
|
|
|
1981
1986
|
return ReserveAssetDataEvent.fromBcs(object.content);
|
|
1982
1987
|
}
|
|
1983
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
|
+
constructor(typeArgs, fields) {
|
|
2024
|
+
this.$fullTypeName = composeSuiType(ReserveAssetDataEventV2.$typeName, ...typeArgs);
|
|
2025
|
+
this.$typeArgs = typeArgs;
|
|
2026
|
+
this.lendingMarketId = fields.lendingMarketId;
|
|
2027
|
+
this.coinType = fields.coinType;
|
|
2028
|
+
this.reserveId = fields.reserveId;
|
|
2029
|
+
this.availableAmount = fields.availableAmount;
|
|
2030
|
+
this.supplyAmount = fields.supplyAmount;
|
|
2031
|
+
this.borrowedAmount = fields.borrowedAmount;
|
|
2032
|
+
this.availableAmountUsdEstimate = fields.availableAmountUsdEstimate;
|
|
2033
|
+
this.supplyAmountUsdEstimate = fields.supplyAmountUsdEstimate;
|
|
2034
|
+
this.borrowedAmountUsdEstimate = fields.borrowedAmountUsdEstimate;
|
|
2035
|
+
this.borrowApr = fields.borrowApr;
|
|
2036
|
+
this.supplyApr = fields.supplyApr;
|
|
2037
|
+
this.ctokenSupply = fields.ctokenSupply;
|
|
2038
|
+
this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
|
|
2039
|
+
this.price = fields.price;
|
|
2040
|
+
this.smoothedPrice = fields.smoothedPrice;
|
|
2041
|
+
this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
|
|
2042
|
+
this.conf = fields.conf;
|
|
2043
|
+
}
|
|
2044
|
+
static reified() {
|
|
2045
|
+
const reifiedBcs = ReserveAssetDataEventV2.bcs;
|
|
2046
|
+
return {
|
|
2047
|
+
get typeName() {
|
|
2048
|
+
return ReserveAssetDataEventV2.$typeName;
|
|
2049
|
+
},
|
|
2050
|
+
get fullTypeName() {
|
|
2051
|
+
return composeSuiType(ReserveAssetDataEventV2.$typeName, ...[]);
|
|
2052
|
+
},
|
|
2053
|
+
typeArgs: [],
|
|
2054
|
+
isPhantom: ReserveAssetDataEventV2.$isPhantom,
|
|
2055
|
+
reifiedTypeArgs: [],
|
|
2056
|
+
fromFields: (fields) => ReserveAssetDataEventV2.fromFields(fields),
|
|
2057
|
+
fromFieldsWithTypes: (item) => ReserveAssetDataEventV2.fromFieldsWithTypes(item),
|
|
2058
|
+
fromBcs: (data) => ReserveAssetDataEventV2.fromFields(reifiedBcs.parse(data)),
|
|
2059
|
+
bcs: reifiedBcs,
|
|
2060
|
+
fromJSONField: (field) => ReserveAssetDataEventV2.fromJSONField(field),
|
|
2061
|
+
fromJSON: (json) => ReserveAssetDataEventV2.fromJSON(json),
|
|
2062
|
+
fromCoreObject: (obj) => ReserveAssetDataEventV2.fromCoreObject(obj),
|
|
2063
|
+
fetch: async (client, id) => ReserveAssetDataEventV2.fetch(client, id),
|
|
2064
|
+
new: (fields) => {
|
|
2065
|
+
return new ReserveAssetDataEventV2([], fields);
|
|
2066
|
+
},
|
|
2067
|
+
kind: 'StructClassReified',
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
static get r() {
|
|
2071
|
+
return ReserveAssetDataEventV2.reified();
|
|
2072
|
+
}
|
|
2073
|
+
static phantom() {
|
|
2074
|
+
return phantom(ReserveAssetDataEventV2.reified());
|
|
2075
|
+
}
|
|
2076
|
+
static get p() {
|
|
2077
|
+
return ReserveAssetDataEventV2.phantom();
|
|
2078
|
+
}
|
|
2079
|
+
static instantiateBcs() {
|
|
2080
|
+
return bcs.struct('ReserveAssetDataEventV2', {
|
|
2081
|
+
lending_market_id: bcs.bytes(32).transform({
|
|
2082
|
+
input: (val) => fromHex(val),
|
|
2083
|
+
output: (val) => toHex(val),
|
|
2084
|
+
}),
|
|
2085
|
+
coin_type: TypeName.bcs,
|
|
2086
|
+
reserve_id: bcs.bytes(32).transform({
|
|
2087
|
+
input: (val) => fromHex(val),
|
|
2088
|
+
output: (val) => toHex(val),
|
|
2089
|
+
}),
|
|
2090
|
+
available_amount: Decimal.bcs,
|
|
2091
|
+
supply_amount: Decimal.bcs,
|
|
2092
|
+
borrowed_amount: Decimal.bcs,
|
|
2093
|
+
available_amount_usd_estimate: Decimal.bcs,
|
|
2094
|
+
supply_amount_usd_estimate: Decimal.bcs,
|
|
2095
|
+
borrowed_amount_usd_estimate: Decimal.bcs,
|
|
2096
|
+
borrow_apr: Decimal.bcs,
|
|
2097
|
+
supply_apr: Decimal.bcs,
|
|
2098
|
+
ctoken_supply: bcs.u64(),
|
|
2099
|
+
cumulative_borrow_rate: Decimal.bcs,
|
|
2100
|
+
price: Decimal.bcs,
|
|
2101
|
+
smoothed_price: Decimal.bcs,
|
|
2102
|
+
price_last_update_timestamp_s: bcs.u64(),
|
|
2103
|
+
conf: Decimal.bcs,
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
static cachedBcs = null;
|
|
2107
|
+
static get bcs() {
|
|
2108
|
+
if (!ReserveAssetDataEventV2.cachedBcs) {
|
|
2109
|
+
ReserveAssetDataEventV2.cachedBcs = ReserveAssetDataEventV2.instantiateBcs();
|
|
2110
|
+
}
|
|
2111
|
+
return ReserveAssetDataEventV2.cachedBcs;
|
|
2112
|
+
}
|
|
2113
|
+
static fromFields(fields) {
|
|
2114
|
+
return ReserveAssetDataEventV2.reified().new({
|
|
2115
|
+
lendingMarketId: decodeFromFields('address', fields.lending_market_id),
|
|
2116
|
+
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
2117
|
+
reserveId: decodeFromFields('address', fields.reserve_id),
|
|
2118
|
+
availableAmount: decodeFromFields(Decimal.reified(), fields.available_amount),
|
|
2119
|
+
supplyAmount: decodeFromFields(Decimal.reified(), fields.supply_amount),
|
|
2120
|
+
borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
|
|
2121
|
+
availableAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.available_amount_usd_estimate),
|
|
2122
|
+
supplyAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.supply_amount_usd_estimate),
|
|
2123
|
+
borrowedAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.borrowed_amount_usd_estimate),
|
|
2124
|
+
borrowApr: decodeFromFields(Decimal.reified(), fields.borrow_apr),
|
|
2125
|
+
supplyApr: decodeFromFields(Decimal.reified(), fields.supply_apr),
|
|
2126
|
+
ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
|
|
2127
|
+
cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
|
|
2128
|
+
price: decodeFromFields(Decimal.reified(), fields.price),
|
|
2129
|
+
smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
|
|
2130
|
+
priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
|
|
2131
|
+
conf: decodeFromFields(Decimal.reified(), fields.conf),
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
static fromFieldsWithTypes(item) {
|
|
2135
|
+
if (!isReserveAssetDataEventV2(item.type)) {
|
|
2136
|
+
throw new Error('not a ReserveAssetDataEventV2 type');
|
|
2137
|
+
}
|
|
2138
|
+
return ReserveAssetDataEventV2.reified().new({
|
|
2139
|
+
lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
|
|
2140
|
+
coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
|
|
2141
|
+
reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
|
|
2142
|
+
availableAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount),
|
|
2143
|
+
supplyAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount),
|
|
2144
|
+
borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
|
|
2145
|
+
availableAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount_usd_estimate),
|
|
2146
|
+
supplyAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount_usd_estimate),
|
|
2147
|
+
borrowedAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount_usd_estimate),
|
|
2148
|
+
borrowApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrow_apr),
|
|
2149
|
+
supplyApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_apr),
|
|
2150
|
+
ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
|
|
2151
|
+
cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
|
|
2152
|
+
price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
|
|
2153
|
+
smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
|
|
2154
|
+
priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
|
|
2155
|
+
conf: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.conf),
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
static fromBcs(data) {
|
|
2159
|
+
return ReserveAssetDataEventV2.fromFields(ReserveAssetDataEventV2.bcs.parse(data));
|
|
2160
|
+
}
|
|
2161
|
+
toJSONField() {
|
|
2162
|
+
return {
|
|
2163
|
+
lendingMarketId: this.lendingMarketId,
|
|
2164
|
+
coinType: this.coinType,
|
|
2165
|
+
reserveId: this.reserveId,
|
|
2166
|
+
availableAmount: this.availableAmount.toJSONField(),
|
|
2167
|
+
supplyAmount: this.supplyAmount.toJSONField(),
|
|
2168
|
+
borrowedAmount: this.borrowedAmount.toJSONField(),
|
|
2169
|
+
availableAmountUsdEstimate: this.availableAmountUsdEstimate.toJSONField(),
|
|
2170
|
+
supplyAmountUsdEstimate: this.supplyAmountUsdEstimate.toJSONField(),
|
|
2171
|
+
borrowedAmountUsdEstimate: this.borrowedAmountUsdEstimate.toJSONField(),
|
|
2172
|
+
borrowApr: this.borrowApr.toJSONField(),
|
|
2173
|
+
supplyApr: this.supplyApr.toJSONField(),
|
|
2174
|
+
ctokenSupply: this.ctokenSupply.toString(),
|
|
2175
|
+
cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
|
|
2176
|
+
price: this.price.toJSONField(),
|
|
2177
|
+
smoothedPrice: this.smoothedPrice.toJSONField(),
|
|
2178
|
+
priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
|
|
2179
|
+
conf: this.conf.toJSONField(),
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
toJSON() {
|
|
2183
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
2184
|
+
}
|
|
2185
|
+
static fromJSONField(field) {
|
|
2186
|
+
return ReserveAssetDataEventV2.reified().new({
|
|
2187
|
+
lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
|
|
2188
|
+
coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
|
|
2189
|
+
reserveId: decodeFromJSONField('address', field.reserveId),
|
|
2190
|
+
availableAmount: decodeFromJSONField(Decimal.reified(), field.availableAmount),
|
|
2191
|
+
supplyAmount: decodeFromJSONField(Decimal.reified(), field.supplyAmount),
|
|
2192
|
+
borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
|
|
2193
|
+
availableAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.availableAmountUsdEstimate),
|
|
2194
|
+
supplyAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.supplyAmountUsdEstimate),
|
|
2195
|
+
borrowedAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.borrowedAmountUsdEstimate),
|
|
2196
|
+
borrowApr: decodeFromJSONField(Decimal.reified(), field.borrowApr),
|
|
2197
|
+
supplyApr: decodeFromJSONField(Decimal.reified(), field.supplyApr),
|
|
2198
|
+
ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
|
|
2199
|
+
cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
|
|
2200
|
+
price: decodeFromJSONField(Decimal.reified(), field.price),
|
|
2201
|
+
smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
|
|
2202
|
+
priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
|
|
2203
|
+
conf: decodeFromJSONField(Decimal.reified(), field.conf),
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
static fromJSON(json) {
|
|
2207
|
+
if (json.$typeName !== ReserveAssetDataEventV2.$typeName) {
|
|
2208
|
+
throw new Error(`not a ReserveAssetDataEventV2 json object: expected '${ReserveAssetDataEventV2.$typeName}' but got '${json.$typeName}'`);
|
|
2209
|
+
}
|
|
2210
|
+
return ReserveAssetDataEventV2.fromJSONField(json);
|
|
2211
|
+
}
|
|
2212
|
+
static fromCoreObject(obj) {
|
|
2213
|
+
if (!isReserveAssetDataEventV2(obj.type)) {
|
|
2214
|
+
throw new Error(`object at ${obj.objectId} is not a ReserveAssetDataEventV2 object`);
|
|
2215
|
+
}
|
|
2216
|
+
return ReserveAssetDataEventV2.fromBcs(obj.content);
|
|
2217
|
+
}
|
|
2218
|
+
static async fetch(client, id) {
|
|
2219
|
+
const { object } = await client.core.getObject({
|
|
2220
|
+
objectId: id,
|
|
2221
|
+
include: { content: true },
|
|
2222
|
+
});
|
|
2223
|
+
if (!isReserveAssetDataEventV2(object.type)) {
|
|
2224
|
+
throw new Error(`object at id ${id} is not a ReserveAssetDataEventV2 object`);
|
|
2225
|
+
}
|
|
2226
|
+
return ReserveAssetDataEventV2.fromBcs(object.content);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
1984
2229
|
/* ============================== ClaimStakingRewardsEvent =============================== */
|
|
1985
2230
|
export function isClaimStakingRewardsEvent(type) {
|
|
1986
2231
|
type = compressSuiType(type);
|
package/client.d.ts
CHANGED
|
@@ -19,10 +19,12 @@ export interface PriceUpdate {
|
|
|
19
19
|
}
|
|
20
20
|
export declare function needsPriceRefresh(stalenessSeconds: number): boolean;
|
|
21
21
|
export declare const ADMIN_ADDRESS = "0xb1ffbc2e1915f44b8f271a703becc1bf8aa79bc22431a58900a102892b783c25";
|
|
22
|
+
export declare function getStrategyWrapperPackageId(): string;
|
|
23
|
+
export declare function setStrategyWrapperPackageId(packageId: string): void;
|
|
22
24
|
export declare const LENDING_MARKET_REGISTRY_ID = "0x64faff8d91a56c4f55debbb44767b009ee744a70bc2cc8e3bbd2718c92f85931";
|
|
23
25
|
export declare const LENDING_MARKET_ID: string, LENDING_MARKET_TYPE: string;
|
|
24
26
|
export declare const STEAMM_LM_LENDING_MARKET_ID: string, STEAMM_LM_LENDING_MARKET_TYPE: string;
|
|
25
|
-
export declare function getLatestPackageId(suiGrpcClient: SuiGrpcClient, upgradeCapId: string): Promise<
|
|
27
|
+
export declare function getLatestPackageId(suiGrpcClient: SuiGrpcClient, upgradeCapId: string): Promise<string>;
|
|
26
28
|
/**
|
|
27
29
|
* Lists every owned object of `type`, following pagination.
|
|
28
30
|
*
|
|
@@ -84,6 +86,12 @@ export declare class SuilendClient {
|
|
|
84
86
|
id: string;
|
|
85
87
|
type: string;
|
|
86
88
|
}[], suiGrpcClient: SuiGrpcClient, logPackageId?: boolean): Promise<SuilendClient[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Sets only the suilend package, to `publishedAt`, and leaves the
|
|
91
|
+
* strategy_wrapper package as it was. Callers that build strategy
|
|
92
|
+
* transactions must also call `setStrategyWrapperPackageId` with the
|
|
93
|
+
* strategy_wrapper package for MAIN's lending market version.
|
|
94
|
+
*/
|
|
87
95
|
static initializeAllFromObjects(lendingMarkets: {
|
|
88
96
|
id: string;
|
|
89
97
|
type: string;
|
|
@@ -94,6 +102,8 @@ export declare class SuilendClient {
|
|
|
94
102
|
}>;
|
|
95
103
|
/** A reserve's confidence multiplier `k`, in bps; pass `parsedReserve.config.additionalFields.id`. 0 when unset. */
|
|
96
104
|
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 getReserveStoredConfidence(suiGrpcClient: SuiGrpcClient, reserveId: string): Promise<BigNumber>;
|
|
97
107
|
static createNewLendingMarket(registryId: string, lendingMarketType: string, transaction: Transaction): {
|
|
98
108
|
NestedResult: [number, number];
|
|
99
109
|
$kind: "NestedResult";
|
package/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { bcs } from "@mysten/sui/bcs";
|
|
2
|
-
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, isValidSuiAddress, normalizeStructTag, normalizeSuiObjectId, toHex, } from "@mysten/sui/utils";
|
|
2
|
+
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, isValidSuiAddress, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, toHex, } from "@mysten/sui/utils";
|
|
3
3
|
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
4
4
|
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
|
+
import { Decimal } from "./_generated/suilend/decimal/structs.js";
|
|
8
|
+
import { decimalToBigNumber } from "./utils/simulate.js";
|
|
7
9
|
import { PKG_V10, setPublishedAt } from "./_generated/suilend/index.js";
|
|
8
10
|
import { getPublishedAt } from "./_generated/_envs/index.js";
|
|
9
11
|
import { PACKAGE_ID } from "./_generated/suilend/index.js";
|
|
@@ -58,6 +60,20 @@ const PUBLISHED_AT_BY_MARKET_VERSION = new Map([
|
|
|
58
60
|
"0x59672975e15c58ffc9450f5236b6aa9fa2407d94b8081e634778aa01957d8c6f",
|
|
59
61
|
],
|
|
60
62
|
]);
|
|
63
|
+
const STRATEGY_WRAPPER_UPGRADE_CAP_ID = "0x486ef016bd357fadf981aba35a6c31df8d4c0c4136b2e78fdda87cb2832f3033";
|
|
64
|
+
const STRATEGY_WRAPPER_PACKAGE_ID_V7 = "0x864b66441e95323c320ee7584592769930a2d236b45d731011ee7a98eb785b35";
|
|
65
|
+
const STRATEGY_WRAPPER_PACKAGE_ID_BY_MARKET_VERSION = new Map([
|
|
66
|
+
[BigInt(7), STRATEGY_WRAPPER_PACKAGE_ID_V7],
|
|
67
|
+
]);
|
|
68
|
+
let strategyWrapperPackage = STRATEGY_WRAPPER_PACKAGE_ID_V7;
|
|
69
|
+
export function getStrategyWrapperPackageId() {
|
|
70
|
+
if (typeof strategyWrapperPackage !== "string")
|
|
71
|
+
throw new Error(`The strategy_wrapper package is unresolved: reading its UpgradeCap ${STRATEGY_WRAPPER_UPGRADE_CAP_ID} failed at MAIN lending market version ${LATEST_MARKET_VERSION}. Retry SuilendClient.initialize before building strategy transactions.`, { cause: strategyWrapperPackage.readError });
|
|
72
|
+
return strategyWrapperPackage;
|
|
73
|
+
}
|
|
74
|
+
export function setStrategyWrapperPackageId(packageId) {
|
|
75
|
+
strategyWrapperPackage = packageId;
|
|
76
|
+
}
|
|
61
77
|
export const LENDING_MARKET_REGISTRY_ID = "0x64faff8d91a56c4f55debbb44767b009ee744a70bc2cc8e3bbd2718c92f85931";
|
|
62
78
|
export const [LENDING_MARKET_ID, LENDING_MARKET_TYPE] = [
|
|
63
79
|
"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",
|
|
@@ -84,7 +100,12 @@ export async function getLatestPackageId(suiGrpcClient, upgradeCapId) {
|
|
|
84
100
|
objectId: upgradeCapId,
|
|
85
101
|
include: { json: true },
|
|
86
102
|
})
|
|
87
|
-
.then(({ object }) =>
|
|
103
|
+
.then(({ object }) => {
|
|
104
|
+
const packageId = object.json?.package;
|
|
105
|
+
if (typeof packageId !== "string" || !isValidSuiAddress(packageId))
|
|
106
|
+
throw new Error(`UpgradeCap ${upgradeCapId} does not name a valid package id (got ${String(packageId)})`);
|
|
107
|
+
return normalizeSuiAddress(packageId);
|
|
108
|
+
})
|
|
88
109
|
.finally(() => latestPackageIdCache.delete(upgradeCapId));
|
|
89
110
|
latestPackageIdCache.set(upgradeCapId, promise);
|
|
90
111
|
return promise;
|
|
@@ -244,13 +265,27 @@ function startLatestPackageIdRead(suiGrpcClient) {
|
|
|
244
265
|
latestPackageId.catch(() => { });
|
|
245
266
|
return latestPackageId;
|
|
246
267
|
}
|
|
247
|
-
async function
|
|
248
|
-
if (mainVersion === LATEST_MARKET_VERSION)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
268
|
+
async function applyPackagesForMainVersion(suiGrpcClient, mainVersion, latestPackageId, logPackageId) {
|
|
269
|
+
if (mainVersion === LATEST_MARKET_VERSION) {
|
|
270
|
+
const [publishedAt, strategyWrapper] = await Promise.all([
|
|
271
|
+
latestPackageId,
|
|
272
|
+
getLatestPackageId(suiGrpcClient, STRATEGY_WRAPPER_UPGRADE_CAP_ID).catch((readError) => ({ readError })),
|
|
273
|
+
]);
|
|
274
|
+
applyPublishedAt(publishedAt, logPackageId);
|
|
275
|
+
strategyWrapperPackage = strategyWrapper;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const publishedAt = PUBLISHED_AT_BY_MARKET_VERSION.get(mainVersion);
|
|
279
|
+
const strategyWrapper = STRATEGY_WRAPPER_PACKAGE_ID_BY_MARKET_VERSION.get(mainVersion);
|
|
280
|
+
if (!publishedAt || !strategyWrapper) {
|
|
281
|
+
const unknown = [
|
|
282
|
+
...(publishedAt ? [] : ["suilend"]),
|
|
283
|
+
...(strategyWrapper ? [] : ["strategy_wrapper"]),
|
|
284
|
+
];
|
|
285
|
+
throw new Error(`No ${unknown.join(" or ")} package is known for lending market version ${mainVersion} (MAIN ${LENDING_MARKET_ID})`);
|
|
286
|
+
}
|
|
287
|
+
applyPublishedAt(publishedAt, logPackageId);
|
|
288
|
+
strategyWrapperPackage = strategyWrapper;
|
|
254
289
|
}
|
|
255
290
|
async function readMainVersion(suiGrpcClient) {
|
|
256
291
|
const { object } = await suiGrpcClient.getObject({
|
|
@@ -368,7 +403,7 @@ export class SuilendClient {
|
|
|
368
403
|
const mainVersion = fetchedMainVersion ?? lendingMarket.version;
|
|
369
404
|
if (lendingMarket.version !== mainVersion)
|
|
370
405
|
throw new Error(versionMismatch(lendingMarketId, lendingMarket.version, mainVersion));
|
|
371
|
-
|
|
406
|
+
await applyPackagesForMainVersion(suiGrpcClient, mainVersion, latestPackageId, logPackageId);
|
|
372
407
|
return new SuilendClient(lendingMarket, suiGrpcClient);
|
|
373
408
|
}
|
|
374
409
|
/**
|
|
@@ -396,12 +431,18 @@ export class SuilendClient {
|
|
|
396
431
|
const mainVersion = fetchedMainVersion ??
|
|
397
432
|
clients[lendingMarkets.findIndex(({ id }) => isMainMarket(id))]
|
|
398
433
|
.lendingMarket.version;
|
|
399
|
-
|
|
434
|
+
await applyPackagesForMainVersion(suiGrpcClient, mainVersion, latestPackageId, logPackageId);
|
|
400
435
|
for (const { lendingMarket } of clients)
|
|
401
436
|
if (lendingMarket.version !== mainVersion)
|
|
402
437
|
console.warn(`@suilend/sdk | ${versionMismatch(lendingMarket.id, lendingMarket.version, mainVersion)}`);
|
|
403
438
|
return clients;
|
|
404
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Sets only the suilend package, to `publishedAt`, and leaves the
|
|
442
|
+
* strategy_wrapper package as it was. Callers that build strategy
|
|
443
|
+
* transactions must also call `setStrategyWrapperPackageId` with the
|
|
444
|
+
* strategy_wrapper package for MAIN's lending market version.
|
|
445
|
+
*/
|
|
405
446
|
static initializeAllFromObjects(lendingMarkets, objects, publishedAt, suiGrpcClient, logPackageId) {
|
|
406
447
|
if (!isValidSuiAddress(publishedAt))
|
|
407
448
|
throw new Error(`publishedAt ${publishedAt} is not a Sui package id`);
|
|
@@ -426,6 +467,17 @@ export class SuilendClient {
|
|
|
426
467
|
});
|
|
427
468
|
return new BigNumber(bcs.u64().parse(dynamicField.value.bcs));
|
|
428
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 getReserveStoredConfidence(suiGrpcClient, reserveId) {
|
|
472
|
+
const match = await findBagEntryByTypeSuffix(suiGrpcClient, reserveId, "::reserve::ConfidenceKey");
|
|
473
|
+
if (!match)
|
|
474
|
+
return new BigNumber(0);
|
|
475
|
+
const { dynamicField } = await suiGrpcClient.getDynamicField({
|
|
476
|
+
parentId: reserveId,
|
|
477
|
+
name: match.name,
|
|
478
|
+
});
|
|
479
|
+
return decimalToBigNumber(Decimal.fromBcs(dynamicField.value.bcs));
|
|
480
|
+
}
|
|
429
481
|
static createNewLendingMarket(registryId, lendingMarketType, transaction) {
|
|
430
482
|
const [ownerCap, lendingMarket] = createLendingMarket(transaction, lendingMarketType, transaction.object(registryId));
|
|
431
483
|
transaction.moveCall({
|
package/lib/strategyOwnerCap.js
CHANGED
|
@@ -2,10 +2,9 @@ import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, } from "@mysten/sui/ut
|
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import BN from "bn.js";
|
|
4
4
|
import { MAX_U64, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_USDsui_COINTYPE, NORMALIZED_eEARN_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_stratSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, isSui, } from "@suilend/sui-core";
|
|
5
|
-
import { LENDING_MARKET_ID, LENDING_MARKET_TYPE, } from "../client.js";
|
|
5
|
+
import { getStrategyWrapperPackageId, LENDING_MARKET_ID, LENDING_MARKET_TYPE, } from "../client.js";
|
|
6
6
|
import { Side } from "./types.js";
|
|
7
7
|
export const STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
|
|
8
|
-
const STRATEGY_WRAPPER_PACKAGE_ID_V7 = "0x864b66441e95323c320ee7584592769930a2d236b45d731011ee7a98eb785b35";
|
|
9
8
|
export var StrategyType;
|
|
10
9
|
(function (StrategyType) {
|
|
11
10
|
StrategyType["sSUI_SUI_LOOPING"] = "1";
|
|
@@ -242,7 +241,7 @@ const getStrategyLendingMarket = (strategyType) => {
|
|
|
242
241
|
export const strategyDeposit = (strategyType, coin, coinType, strategyOwnerCap, reserveArrayIndex, transaction) => {
|
|
243
242
|
const { lendingMarketId, lendingMarketType } = getStrategyLendingMarket(strategyType);
|
|
244
243
|
return transaction.moveCall({
|
|
245
|
-
target: `${
|
|
244
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::deposit_liquidity_and_deposit_into_obligation`,
|
|
246
245
|
typeArguments: [lendingMarketType, coinType],
|
|
247
246
|
arguments: [
|
|
248
247
|
transaction.object(strategyOwnerCap),
|
|
@@ -257,7 +256,7 @@ export const strategyBorrow = (strategyType, coinType, strategyOwnerCap, reserve
|
|
|
257
256
|
const { lendingMarketId, lendingMarketType } = getStrategyLendingMarket(strategyType);
|
|
258
257
|
return isSui(coinType)
|
|
259
258
|
? transaction.moveCall({
|
|
260
|
-
target: `${
|
|
259
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::borrow_sui_from_obligation`,
|
|
261
260
|
typeArguments: [lendingMarketType],
|
|
262
261
|
arguments: [
|
|
263
262
|
transaction.object(strategyOwnerCap),
|
|
@@ -269,7 +268,7 @@ export const strategyBorrow = (strategyType, coinType, strategyOwnerCap, reserve
|
|
|
269
268
|
],
|
|
270
269
|
})
|
|
271
270
|
: transaction.moveCall({
|
|
272
|
-
target: `${
|
|
271
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::borrow_from_obligation`,
|
|
273
272
|
typeArguments: [lendingMarketType, coinType],
|
|
274
273
|
arguments: [
|
|
275
274
|
transaction.object(strategyOwnerCap),
|
|
@@ -283,7 +282,7 @@ export const strategyBorrow = (strategyType, coinType, strategyOwnerCap, reserve
|
|
|
283
282
|
export const strategyWithdraw = (strategyType, coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => {
|
|
284
283
|
const { lendingMarketId, lendingMarketType } = getStrategyLendingMarket(strategyType);
|
|
285
284
|
return transaction.moveCall({
|
|
286
|
-
target: `${
|
|
285
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::withdraw_from_obligation_and_redeem`,
|
|
287
286
|
typeArguments: [lendingMarketType, coinType],
|
|
288
287
|
arguments: [
|
|
289
288
|
transaction.object(strategyOwnerCap),
|
|
@@ -297,7 +296,7 @@ export const strategyWithdraw = (strategyType, coinType, strategyOwnerCap, reser
|
|
|
297
296
|
const strategyClaimRewards = (strategyType, coinType, strategyOwnerCap, reserveArrayIndex, rewardIndex, side, transaction) => {
|
|
298
297
|
const { lendingMarketId, lendingMarketType } = getStrategyLendingMarket(strategyType);
|
|
299
298
|
return transaction.moveCall({
|
|
300
|
-
target: `${
|
|
299
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::claim_rewards`,
|
|
301
300
|
typeArguments: [lendingMarketType, coinType],
|
|
302
301
|
arguments: [
|
|
303
302
|
transaction.object(strategyOwnerCap),
|
|
@@ -432,7 +431,7 @@ export const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCa
|
|
|
432
431
|
strategyOwnerCapId = strategyOwnerCap.id;
|
|
433
432
|
else {
|
|
434
433
|
strategyOwnerCapId = transaction.moveCall({
|
|
435
|
-
target: `${
|
|
434
|
+
target: `${getStrategyWrapperPackageId()}::strategy_wrapper::create_strategy_owner_cap`,
|
|
436
435
|
typeArguments: [lendingMarketType],
|
|
437
436
|
arguments: [
|
|
438
437
|
transaction.object(lendingMarketId),
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"13.0.
|
|
1
|
+
{"name":"@suilend/sdk","version":"13.1.0-next.g093f417","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/obligation":"./utils/obligation.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.6.3","@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.1","@mysten/sui":"2.29.0","@suilend/sui-core":"2.1.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.25","@types/node":"26.5.1","fast-check":"4.10.2","prettier":"3.9.9","ts-node":"10.9.2","typescript":"6.0.3","vite":"8.3.0","vitest":"5.0.1"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.22.1 <3","@suilend/sui-core":"^2.0.1"},"type":"module"}
|
package/utils/events.d.ts
CHANGED
|
@@ -69,6 +69,26 @@ export declare class ReserveAssetDataEvent extends TypedParamsSuiEvent<{
|
|
|
69
69
|
price_last_update_timestamp_s: u64;
|
|
70
70
|
}> {
|
|
71
71
|
}
|
|
72
|
+
export declare class ReserveAssetDataEventV2 extends TypedParamsSuiEvent<{
|
|
73
|
+
lending_market_id: address;
|
|
74
|
+
coin_type: TypeName;
|
|
75
|
+
reserve_id: address;
|
|
76
|
+
available_amount: Decimal;
|
|
77
|
+
supply_amount: Decimal;
|
|
78
|
+
borrowed_amount: Decimal;
|
|
79
|
+
available_amount_usd_estimate: Decimal;
|
|
80
|
+
supply_amount_usd_estimate: Decimal;
|
|
81
|
+
borrowed_amount_usd_estimate: Decimal;
|
|
82
|
+
borrow_apr: Decimal;
|
|
83
|
+
supply_apr: Decimal;
|
|
84
|
+
ctoken_supply: u64;
|
|
85
|
+
cumulative_borrow_rate: Decimal;
|
|
86
|
+
price: Decimal;
|
|
87
|
+
smoothed_price: Decimal;
|
|
88
|
+
price_last_update_timestamp_s: u64;
|
|
89
|
+
conf: Decimal;
|
|
90
|
+
}> {
|
|
91
|
+
}
|
|
72
92
|
export declare class MintEvent extends TypedParamsSuiEvent<{
|
|
73
93
|
lending_market_id: address;
|
|
74
94
|
coin_type: TypeName;
|
package/utils/events.js
CHANGED
|
@@ -26,7 +26,7 @@ class TypedParamsSuiEvent {
|
|
|
26
26
|
return this.event.json;
|
|
27
27
|
}
|
|
28
28
|
isType(module, eventType) {
|
|
29
|
-
return this.event.eventType.
|
|
29
|
+
return this.event.eventType.endsWith(`${module}::${eventType}`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export class GenericSuilendEvent extends TypedParamsSuiEvent {
|
|
@@ -35,6 +35,8 @@ export class InterestUpdateEvent extends TypedParamsSuiEvent {
|
|
|
35
35
|
}
|
|
36
36
|
export class ReserveAssetDataEvent extends TypedParamsSuiEvent {
|
|
37
37
|
}
|
|
38
|
+
export class ReserveAssetDataEventV2 extends TypedParamsSuiEvent {
|
|
39
|
+
}
|
|
38
40
|
export class MintEvent extends TypedParamsSuiEvent {
|
|
39
41
|
}
|
|
40
42
|
export class RedeemEvent extends TypedParamsSuiEvent {
|
package/utils/simulate.d.ts
CHANGED
|
@@ -149,6 +149,18 @@ export declare const refreshObligation: (unrefreshedObligation: Obligation<strin
|
|
|
149
149
|
export declare const numberToDecimal: (value: number) => Decimal;
|
|
150
150
|
export declare const stringToDecimal: (value: string) => Decimal;
|
|
151
151
|
export declare const decimalToBigNumber: (value: Decimal) => BigNumber;
|
|
152
|
+
/**
|
|
153
|
+
* Mirrors reserve.move's `price_lower_bound`/`price_upper_bound`: the one
|
|
154
|
+
* off-chain place this formula lives. `conf` and `kBps` are the reserve's
|
|
155
|
+
* stored Pyth confidence and its `ReserveConfig` confidence multiplier (in
|
|
156
|
+
* bps, e.g. 30000 for a logical k=3) -- both plain human-scale BigNumbers,
|
|
157
|
+
* not WAD-scaled Decimals. `kBps=0` disables the margin entirely: both
|
|
158
|
+
* bounds collapse to plain `min`/`max(price, smoothedPrice)`.
|
|
159
|
+
*/
|
|
160
|
+
export declare const applyConfidenceMargin: (price: BigNumber, smoothedPrice: BigNumber, conf: BigNumber, kBps: BigNumber) => {
|
|
161
|
+
lowerBound: BigNumber;
|
|
162
|
+
upperBound: BigNumber;
|
|
163
|
+
};
|
|
152
164
|
export declare const getCTokenMarketValue: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber) => BigNumber;
|
|
153
165
|
export declare const getCTokenMarketValueLowerBound: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber) => BigNumber;
|
|
154
166
|
export declare const cTokenRatio: (reserve: Reserve<string>) => BigNumber;
|
package/utils/simulate.js
CHANGED
|
@@ -441,6 +441,20 @@ export const stringToDecimal = (value) => {
|
|
|
441
441
|
export const decimalToBigNumber = (value) => {
|
|
442
442
|
return new BigNumber(value.value.toString()).div(WAD);
|
|
443
443
|
};
|
|
444
|
+
/**
|
|
445
|
+
* Mirrors reserve.move's `price_lower_bound`/`price_upper_bound`: the one
|
|
446
|
+
* off-chain place this formula lives. `conf` and `kBps` are the reserve's
|
|
447
|
+
* stored Pyth confidence and its `ReserveConfig` confidence multiplier (in
|
|
448
|
+
* bps, e.g. 30000 for a logical k=3) -- both plain human-scale BigNumbers,
|
|
449
|
+
* not WAD-scaled Decimals. `kBps=0` disables the margin entirely: both
|
|
450
|
+
* bounds collapse to plain `min`/`max(price, smoothedPrice)`.
|
|
451
|
+
*/
|
|
452
|
+
export const applyConfidenceMargin = (price, smoothedPrice, conf, kBps) => {
|
|
453
|
+
const margin = kBps.dividedBy(10_000).multipliedBy(conf);
|
|
454
|
+
const lowerBound = BigNumber.max(BigNumber.min(price, smoothedPrice).minus(margin), new BigNumber(0));
|
|
455
|
+
const upperBound = BigNumber.max(price, smoothedPrice).plus(margin);
|
|
456
|
+
return { lowerBound, upperBound };
|
|
457
|
+
};
|
|
444
458
|
export const getCTokenMarketValue = (reserve, depositedCTokenAmount) => {
|
|
445
459
|
const liquidityAmount = depositedCTokenAmount.multipliedBy(cTokenRatio(reserve));
|
|
446
460
|
return decimalToBigNumber(reserve.price)
|