@suilend/sdk 13.0.0-next.g803bba0 → 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/initialize.d.ts +541 -7
- package/lib/initialize.js +141 -38
- 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/obligation.d.ts +3 -0
- package/utils/obligation.js +10 -0
- 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({
|