@suilend/sdk 13.0.0-next.g803bba0 → 13.0.0
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/lib/initialize.d.ts +541 -7
- package/lib/initialize.js +141 -38
- package/package.json +1 -1
- package/utils/obligation.d.ts +3 -0
- package/utils/obligation.js +10 -0
package/lib/initialize.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
+
import { ObligationOwnerCap } from "../_generated/suilend/lending-market/structs";
|
|
4
|
+
import { Obligation } from "../_generated/suilend/obligation/structs";
|
|
3
5
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
4
6
|
import { SuilendClient } from "../client";
|
|
5
7
|
import { ParsedReserve } from "../parsers";
|
|
@@ -940,6 +942,538 @@ export declare const initializeSuilendRewardsAll: (markets: {
|
|
|
940
942
|
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[], fetchPrices?: FetchPrices) => Promise<{
|
|
941
943
|
rewardPriceMap: Record<string, BigNumber | undefined>;
|
|
942
944
|
}>;
|
|
945
|
+
export type OwnedStrategyOwnerCap = StrategyOwnerCap & {
|
|
946
|
+
lendingMarketType: string;
|
|
947
|
+
};
|
|
948
|
+
export type OwnedObligations = {
|
|
949
|
+
strategyOwnerCaps: OwnedStrategyOwnerCap[];
|
|
950
|
+
obligationOwnerCaps: ObligationOwnerCap<string>[];
|
|
951
|
+
obligations: Obligation<string>[];
|
|
952
|
+
obligationErrors: Record<string, unknown>;
|
|
953
|
+
};
|
|
954
|
+
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>) => {
|
|
956
|
+
strategyOwnerCaps: StrategyOwnerCap[];
|
|
957
|
+
strategyObligations: {
|
|
958
|
+
id: string;
|
|
959
|
+
depositedAmountUsd: BigNumber;
|
|
960
|
+
borrowedAmountUsd: BigNumber;
|
|
961
|
+
netValueUsd: BigNumber;
|
|
962
|
+
weightedBorrowsUsd: BigNumber;
|
|
963
|
+
maxPriceWeightedBorrowsUsd: BigNumber;
|
|
964
|
+
borrowLimitUsd: BigNumber;
|
|
965
|
+
minPriceBorrowLimitUsd: BigNumber;
|
|
966
|
+
unhealthyBorrowValueUsd: BigNumber;
|
|
967
|
+
depositPositionCount: number;
|
|
968
|
+
borrowPositionCount: number;
|
|
969
|
+
positionCount: number;
|
|
970
|
+
deposits: {
|
|
971
|
+
coinType: string;
|
|
972
|
+
reserveArrayIndex: bigint;
|
|
973
|
+
userRewardManagerIndex: number;
|
|
974
|
+
userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
|
|
975
|
+
depositedAmount: BigNumber;
|
|
976
|
+
depositedAmountUsd: BigNumber;
|
|
977
|
+
depositedCtokenAmount: BigNumber;
|
|
978
|
+
reserve: {
|
|
979
|
+
config: {
|
|
980
|
+
$typeName: `${string}::reserve_config::ReserveConfig`;
|
|
981
|
+
openLtvPct: number;
|
|
982
|
+
closeLtvPct: number;
|
|
983
|
+
maxCloseLtvPct: number;
|
|
984
|
+
borrowWeightBps: BigNumber;
|
|
985
|
+
depositLimit: BigNumber;
|
|
986
|
+
borrowLimit: BigNumber;
|
|
987
|
+
liquidationBonusBps: number;
|
|
988
|
+
maxLiquidationBonusBps: number;
|
|
989
|
+
depositLimitUsd: BigNumber;
|
|
990
|
+
borrowLimitUsd: BigNumber;
|
|
991
|
+
borrowFeeBps: number;
|
|
992
|
+
spreadFeeBps: number;
|
|
993
|
+
protocolLiquidationFeeBps: number;
|
|
994
|
+
isolated: boolean;
|
|
995
|
+
openAttributedBorrowLimitUsd: number;
|
|
996
|
+
closeAttributedBorrowLimitUsd: number;
|
|
997
|
+
additionalFields: import("../_generated/_dependencies/sui/bag/structs").Bag;
|
|
998
|
+
interestRate: {
|
|
999
|
+
id: string;
|
|
1000
|
+
utilPercent: BigNumber;
|
|
1001
|
+
aprPercent: BigNumber;
|
|
1002
|
+
}[];
|
|
1003
|
+
};
|
|
1004
|
+
$typeName: `${string}::reserve::Reserve`;
|
|
1005
|
+
id: string;
|
|
1006
|
+
arrayIndex: bigint;
|
|
1007
|
+
coinType: string;
|
|
1008
|
+
mintDecimals: number;
|
|
1009
|
+
priceIdentifier: string;
|
|
1010
|
+
price: BigNumber;
|
|
1011
|
+
smoothedPrice: BigNumber;
|
|
1012
|
+
minPrice: BigNumber;
|
|
1013
|
+
maxPrice: BigNumber;
|
|
1014
|
+
priceLastUpdateTimestampS: bigint;
|
|
1015
|
+
availableAmount: BigNumber;
|
|
1016
|
+
ctokenSupply: BigNumber;
|
|
1017
|
+
borrowedAmount: BigNumber;
|
|
1018
|
+
cumulativeBorrowRate: BigNumber;
|
|
1019
|
+
interestLastUpdateTimestampS: bigint;
|
|
1020
|
+
unclaimedSpreadFees: BigNumber;
|
|
1021
|
+
attributedBorrowValue: BigNumber;
|
|
1022
|
+
depositsPoolRewardManager: {
|
|
1023
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1024
|
+
id: string;
|
|
1025
|
+
totalShares: bigint;
|
|
1026
|
+
poolRewards: {
|
|
1027
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1028
|
+
id: string;
|
|
1029
|
+
poolRewardManagerId: string;
|
|
1030
|
+
coinType: string;
|
|
1031
|
+
startTimeMs: number;
|
|
1032
|
+
endTimeMs: number;
|
|
1033
|
+
totalRewards: BigNumber;
|
|
1034
|
+
allocatedRewards: BigNumber;
|
|
1035
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1036
|
+
numUserRewardManagers: bigint;
|
|
1037
|
+
rewardIndex: number;
|
|
1038
|
+
symbol: string;
|
|
1039
|
+
mintDecimals: number;
|
|
1040
|
+
}[];
|
|
1041
|
+
lastUpdateTimeMs: bigint;
|
|
1042
|
+
};
|
|
1043
|
+
borrowsPoolRewardManager: {
|
|
1044
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1045
|
+
id: string;
|
|
1046
|
+
totalShares: bigint;
|
|
1047
|
+
poolRewards: {
|
|
1048
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1049
|
+
id: string;
|
|
1050
|
+
poolRewardManagerId: string;
|
|
1051
|
+
coinType: string;
|
|
1052
|
+
startTimeMs: number;
|
|
1053
|
+
endTimeMs: number;
|
|
1054
|
+
totalRewards: BigNumber;
|
|
1055
|
+
allocatedRewards: BigNumber;
|
|
1056
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1057
|
+
numUserRewardManagers: bigint;
|
|
1058
|
+
rewardIndex: number;
|
|
1059
|
+
symbol: string;
|
|
1060
|
+
mintDecimals: number;
|
|
1061
|
+
}[];
|
|
1062
|
+
lastUpdateTimeMs: bigint;
|
|
1063
|
+
};
|
|
1064
|
+
availableAmountUsd: BigNumber;
|
|
1065
|
+
borrowedAmountUsd: BigNumber;
|
|
1066
|
+
depositedAmount: BigNumber;
|
|
1067
|
+
depositedAmountUsd: BigNumber;
|
|
1068
|
+
cTokenExchangeRate: BigNumber;
|
|
1069
|
+
borrowAprPercent: BigNumber;
|
|
1070
|
+
depositAprPercent: BigNumber;
|
|
1071
|
+
utilizationPercent: BigNumber;
|
|
1072
|
+
token: {
|
|
1073
|
+
id: string | null;
|
|
1074
|
+
decimals: number;
|
|
1075
|
+
name: string;
|
|
1076
|
+
symbol: string;
|
|
1077
|
+
description: string;
|
|
1078
|
+
iconUrl: string | null;
|
|
1079
|
+
coinType: string;
|
|
1080
|
+
};
|
|
1081
|
+
symbol: string;
|
|
1082
|
+
name: string;
|
|
1083
|
+
iconUrl: string | null;
|
|
1084
|
+
description: string;
|
|
1085
|
+
totalDeposits: BigNumber;
|
|
1086
|
+
};
|
|
1087
|
+
original: Obligation<string>;
|
|
1088
|
+
}[];
|
|
1089
|
+
borrows: {
|
|
1090
|
+
coinType: string;
|
|
1091
|
+
reserveArrayIndex: bigint;
|
|
1092
|
+
userRewardManagerIndex: number;
|
|
1093
|
+
userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
|
|
1094
|
+
borrowedAmount: BigNumber;
|
|
1095
|
+
borrowedAmountUsd: BigNumber;
|
|
1096
|
+
reserve: {
|
|
1097
|
+
config: {
|
|
1098
|
+
$typeName: `${string}::reserve_config::ReserveConfig`;
|
|
1099
|
+
openLtvPct: number;
|
|
1100
|
+
closeLtvPct: number;
|
|
1101
|
+
maxCloseLtvPct: number;
|
|
1102
|
+
borrowWeightBps: BigNumber;
|
|
1103
|
+
depositLimit: BigNumber;
|
|
1104
|
+
borrowLimit: BigNumber;
|
|
1105
|
+
liquidationBonusBps: number;
|
|
1106
|
+
maxLiquidationBonusBps: number;
|
|
1107
|
+
depositLimitUsd: BigNumber;
|
|
1108
|
+
borrowLimitUsd: BigNumber;
|
|
1109
|
+
borrowFeeBps: number;
|
|
1110
|
+
spreadFeeBps: number;
|
|
1111
|
+
protocolLiquidationFeeBps: number;
|
|
1112
|
+
isolated: boolean;
|
|
1113
|
+
openAttributedBorrowLimitUsd: number;
|
|
1114
|
+
closeAttributedBorrowLimitUsd: number;
|
|
1115
|
+
additionalFields: import("../_generated/_dependencies/sui/bag/structs").Bag;
|
|
1116
|
+
interestRate: {
|
|
1117
|
+
id: string;
|
|
1118
|
+
utilPercent: BigNumber;
|
|
1119
|
+
aprPercent: BigNumber;
|
|
1120
|
+
}[];
|
|
1121
|
+
};
|
|
1122
|
+
$typeName: `${string}::reserve::Reserve`;
|
|
1123
|
+
id: string;
|
|
1124
|
+
arrayIndex: bigint;
|
|
1125
|
+
coinType: string;
|
|
1126
|
+
mintDecimals: number;
|
|
1127
|
+
priceIdentifier: string;
|
|
1128
|
+
price: BigNumber;
|
|
1129
|
+
smoothedPrice: BigNumber;
|
|
1130
|
+
minPrice: BigNumber;
|
|
1131
|
+
maxPrice: BigNumber;
|
|
1132
|
+
priceLastUpdateTimestampS: bigint;
|
|
1133
|
+
availableAmount: BigNumber;
|
|
1134
|
+
ctokenSupply: BigNumber;
|
|
1135
|
+
borrowedAmount: BigNumber;
|
|
1136
|
+
cumulativeBorrowRate: BigNumber;
|
|
1137
|
+
interestLastUpdateTimestampS: bigint;
|
|
1138
|
+
unclaimedSpreadFees: BigNumber;
|
|
1139
|
+
attributedBorrowValue: BigNumber;
|
|
1140
|
+
depositsPoolRewardManager: {
|
|
1141
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1142
|
+
id: string;
|
|
1143
|
+
totalShares: bigint;
|
|
1144
|
+
poolRewards: {
|
|
1145
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1146
|
+
id: string;
|
|
1147
|
+
poolRewardManagerId: string;
|
|
1148
|
+
coinType: string;
|
|
1149
|
+
startTimeMs: number;
|
|
1150
|
+
endTimeMs: number;
|
|
1151
|
+
totalRewards: BigNumber;
|
|
1152
|
+
allocatedRewards: BigNumber;
|
|
1153
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1154
|
+
numUserRewardManagers: bigint;
|
|
1155
|
+
rewardIndex: number;
|
|
1156
|
+
symbol: string;
|
|
1157
|
+
mintDecimals: number;
|
|
1158
|
+
}[];
|
|
1159
|
+
lastUpdateTimeMs: bigint;
|
|
1160
|
+
};
|
|
1161
|
+
borrowsPoolRewardManager: {
|
|
1162
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1163
|
+
id: string;
|
|
1164
|
+
totalShares: bigint;
|
|
1165
|
+
poolRewards: {
|
|
1166
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1167
|
+
id: string;
|
|
1168
|
+
poolRewardManagerId: string;
|
|
1169
|
+
coinType: string;
|
|
1170
|
+
startTimeMs: number;
|
|
1171
|
+
endTimeMs: number;
|
|
1172
|
+
totalRewards: BigNumber;
|
|
1173
|
+
allocatedRewards: BigNumber;
|
|
1174
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1175
|
+
numUserRewardManagers: bigint;
|
|
1176
|
+
rewardIndex: number;
|
|
1177
|
+
symbol: string;
|
|
1178
|
+
mintDecimals: number;
|
|
1179
|
+
}[];
|
|
1180
|
+
lastUpdateTimeMs: bigint;
|
|
1181
|
+
};
|
|
1182
|
+
availableAmountUsd: BigNumber;
|
|
1183
|
+
borrowedAmountUsd: BigNumber;
|
|
1184
|
+
depositedAmount: BigNumber;
|
|
1185
|
+
depositedAmountUsd: BigNumber;
|
|
1186
|
+
cTokenExchangeRate: BigNumber;
|
|
1187
|
+
borrowAprPercent: BigNumber;
|
|
1188
|
+
depositAprPercent: BigNumber;
|
|
1189
|
+
utilizationPercent: BigNumber;
|
|
1190
|
+
token: {
|
|
1191
|
+
id: string | null;
|
|
1192
|
+
decimals: number;
|
|
1193
|
+
name: string;
|
|
1194
|
+
symbol: string;
|
|
1195
|
+
description: string;
|
|
1196
|
+
iconUrl: string | null;
|
|
1197
|
+
coinType: string;
|
|
1198
|
+
};
|
|
1199
|
+
symbol: string;
|
|
1200
|
+
name: string;
|
|
1201
|
+
iconUrl: string | null;
|
|
1202
|
+
description: string;
|
|
1203
|
+
totalDeposits: BigNumber;
|
|
1204
|
+
};
|
|
1205
|
+
original: Obligation<string>;
|
|
1206
|
+
}[];
|
|
1207
|
+
weightedConservativeBorrowUtilizationPercent: BigNumber;
|
|
1208
|
+
original: Obligation<string>;
|
|
1209
|
+
totalSupplyUsd: BigNumber;
|
|
1210
|
+
totalBorrowUsd: BigNumber;
|
|
1211
|
+
totalWeightedBorrowUsd: BigNumber;
|
|
1212
|
+
maxPriceTotalWeightedBorrowUsd: BigNumber;
|
|
1213
|
+
borrowLimit: BigNumber;
|
|
1214
|
+
minPriceBorrowLimit: BigNumber;
|
|
1215
|
+
}[];
|
|
1216
|
+
obligationOwnerCaps: ObligationOwnerCap<string>[];
|
|
1217
|
+
obligations: {
|
|
1218
|
+
id: string;
|
|
1219
|
+
depositedAmountUsd: BigNumber;
|
|
1220
|
+
borrowedAmountUsd: BigNumber;
|
|
1221
|
+
netValueUsd: BigNumber;
|
|
1222
|
+
weightedBorrowsUsd: BigNumber;
|
|
1223
|
+
maxPriceWeightedBorrowsUsd: BigNumber;
|
|
1224
|
+
borrowLimitUsd: BigNumber;
|
|
1225
|
+
minPriceBorrowLimitUsd: BigNumber;
|
|
1226
|
+
unhealthyBorrowValueUsd: BigNumber;
|
|
1227
|
+
depositPositionCount: number;
|
|
1228
|
+
borrowPositionCount: number;
|
|
1229
|
+
positionCount: number;
|
|
1230
|
+
deposits: {
|
|
1231
|
+
coinType: string;
|
|
1232
|
+
reserveArrayIndex: bigint;
|
|
1233
|
+
userRewardManagerIndex: number;
|
|
1234
|
+
userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
|
|
1235
|
+
depositedAmount: BigNumber;
|
|
1236
|
+
depositedAmountUsd: BigNumber;
|
|
1237
|
+
depositedCtokenAmount: BigNumber;
|
|
1238
|
+
reserve: {
|
|
1239
|
+
config: {
|
|
1240
|
+
$typeName: `${string}::reserve_config::ReserveConfig`;
|
|
1241
|
+
openLtvPct: number;
|
|
1242
|
+
closeLtvPct: number;
|
|
1243
|
+
maxCloseLtvPct: number;
|
|
1244
|
+
borrowWeightBps: BigNumber;
|
|
1245
|
+
depositLimit: BigNumber;
|
|
1246
|
+
borrowLimit: BigNumber;
|
|
1247
|
+
liquidationBonusBps: number;
|
|
1248
|
+
maxLiquidationBonusBps: number;
|
|
1249
|
+
depositLimitUsd: BigNumber;
|
|
1250
|
+
borrowLimitUsd: BigNumber;
|
|
1251
|
+
borrowFeeBps: number;
|
|
1252
|
+
spreadFeeBps: number;
|
|
1253
|
+
protocolLiquidationFeeBps: number;
|
|
1254
|
+
isolated: boolean;
|
|
1255
|
+
openAttributedBorrowLimitUsd: number;
|
|
1256
|
+
closeAttributedBorrowLimitUsd: number;
|
|
1257
|
+
additionalFields: import("../_generated/_dependencies/sui/bag/structs").Bag;
|
|
1258
|
+
interestRate: {
|
|
1259
|
+
id: string;
|
|
1260
|
+
utilPercent: BigNumber;
|
|
1261
|
+
aprPercent: BigNumber;
|
|
1262
|
+
}[];
|
|
1263
|
+
};
|
|
1264
|
+
$typeName: `${string}::reserve::Reserve`;
|
|
1265
|
+
id: string;
|
|
1266
|
+
arrayIndex: bigint;
|
|
1267
|
+
coinType: string;
|
|
1268
|
+
mintDecimals: number;
|
|
1269
|
+
priceIdentifier: string;
|
|
1270
|
+
price: BigNumber;
|
|
1271
|
+
smoothedPrice: BigNumber;
|
|
1272
|
+
minPrice: BigNumber;
|
|
1273
|
+
maxPrice: BigNumber;
|
|
1274
|
+
priceLastUpdateTimestampS: bigint;
|
|
1275
|
+
availableAmount: BigNumber;
|
|
1276
|
+
ctokenSupply: BigNumber;
|
|
1277
|
+
borrowedAmount: BigNumber;
|
|
1278
|
+
cumulativeBorrowRate: BigNumber;
|
|
1279
|
+
interestLastUpdateTimestampS: bigint;
|
|
1280
|
+
unclaimedSpreadFees: BigNumber;
|
|
1281
|
+
attributedBorrowValue: BigNumber;
|
|
1282
|
+
depositsPoolRewardManager: {
|
|
1283
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1284
|
+
id: string;
|
|
1285
|
+
totalShares: bigint;
|
|
1286
|
+
poolRewards: {
|
|
1287
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1288
|
+
id: string;
|
|
1289
|
+
poolRewardManagerId: string;
|
|
1290
|
+
coinType: string;
|
|
1291
|
+
startTimeMs: number;
|
|
1292
|
+
endTimeMs: number;
|
|
1293
|
+
totalRewards: BigNumber;
|
|
1294
|
+
allocatedRewards: BigNumber;
|
|
1295
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1296
|
+
numUserRewardManagers: bigint;
|
|
1297
|
+
rewardIndex: number;
|
|
1298
|
+
symbol: string;
|
|
1299
|
+
mintDecimals: number;
|
|
1300
|
+
}[];
|
|
1301
|
+
lastUpdateTimeMs: bigint;
|
|
1302
|
+
};
|
|
1303
|
+
borrowsPoolRewardManager: {
|
|
1304
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1305
|
+
id: string;
|
|
1306
|
+
totalShares: bigint;
|
|
1307
|
+
poolRewards: {
|
|
1308
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1309
|
+
id: string;
|
|
1310
|
+
poolRewardManagerId: string;
|
|
1311
|
+
coinType: string;
|
|
1312
|
+
startTimeMs: number;
|
|
1313
|
+
endTimeMs: number;
|
|
1314
|
+
totalRewards: BigNumber;
|
|
1315
|
+
allocatedRewards: BigNumber;
|
|
1316
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1317
|
+
numUserRewardManagers: bigint;
|
|
1318
|
+
rewardIndex: number;
|
|
1319
|
+
symbol: string;
|
|
1320
|
+
mintDecimals: number;
|
|
1321
|
+
}[];
|
|
1322
|
+
lastUpdateTimeMs: bigint;
|
|
1323
|
+
};
|
|
1324
|
+
availableAmountUsd: BigNumber;
|
|
1325
|
+
borrowedAmountUsd: BigNumber;
|
|
1326
|
+
depositedAmount: BigNumber;
|
|
1327
|
+
depositedAmountUsd: BigNumber;
|
|
1328
|
+
cTokenExchangeRate: BigNumber;
|
|
1329
|
+
borrowAprPercent: BigNumber;
|
|
1330
|
+
depositAprPercent: BigNumber;
|
|
1331
|
+
utilizationPercent: BigNumber;
|
|
1332
|
+
token: {
|
|
1333
|
+
id: string | null;
|
|
1334
|
+
decimals: number;
|
|
1335
|
+
name: string;
|
|
1336
|
+
symbol: string;
|
|
1337
|
+
description: string;
|
|
1338
|
+
iconUrl: string | null;
|
|
1339
|
+
coinType: string;
|
|
1340
|
+
};
|
|
1341
|
+
symbol: string;
|
|
1342
|
+
name: string;
|
|
1343
|
+
iconUrl: string | null;
|
|
1344
|
+
description: string;
|
|
1345
|
+
totalDeposits: BigNumber;
|
|
1346
|
+
};
|
|
1347
|
+
original: Obligation<string>;
|
|
1348
|
+
}[];
|
|
1349
|
+
borrows: {
|
|
1350
|
+
coinType: string;
|
|
1351
|
+
reserveArrayIndex: bigint;
|
|
1352
|
+
userRewardManagerIndex: number;
|
|
1353
|
+
userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
|
|
1354
|
+
borrowedAmount: BigNumber;
|
|
1355
|
+
borrowedAmountUsd: BigNumber;
|
|
1356
|
+
reserve: {
|
|
1357
|
+
config: {
|
|
1358
|
+
$typeName: `${string}::reserve_config::ReserveConfig`;
|
|
1359
|
+
openLtvPct: number;
|
|
1360
|
+
closeLtvPct: number;
|
|
1361
|
+
maxCloseLtvPct: number;
|
|
1362
|
+
borrowWeightBps: BigNumber;
|
|
1363
|
+
depositLimit: BigNumber;
|
|
1364
|
+
borrowLimit: BigNumber;
|
|
1365
|
+
liquidationBonusBps: number;
|
|
1366
|
+
maxLiquidationBonusBps: number;
|
|
1367
|
+
depositLimitUsd: BigNumber;
|
|
1368
|
+
borrowLimitUsd: BigNumber;
|
|
1369
|
+
borrowFeeBps: number;
|
|
1370
|
+
spreadFeeBps: number;
|
|
1371
|
+
protocolLiquidationFeeBps: number;
|
|
1372
|
+
isolated: boolean;
|
|
1373
|
+
openAttributedBorrowLimitUsd: number;
|
|
1374
|
+
closeAttributedBorrowLimitUsd: number;
|
|
1375
|
+
additionalFields: import("../_generated/_dependencies/sui/bag/structs").Bag;
|
|
1376
|
+
interestRate: {
|
|
1377
|
+
id: string;
|
|
1378
|
+
utilPercent: BigNumber;
|
|
1379
|
+
aprPercent: BigNumber;
|
|
1380
|
+
}[];
|
|
1381
|
+
};
|
|
1382
|
+
$typeName: `${string}::reserve::Reserve`;
|
|
1383
|
+
id: string;
|
|
1384
|
+
arrayIndex: bigint;
|
|
1385
|
+
coinType: string;
|
|
1386
|
+
mintDecimals: number;
|
|
1387
|
+
priceIdentifier: string;
|
|
1388
|
+
price: BigNumber;
|
|
1389
|
+
smoothedPrice: BigNumber;
|
|
1390
|
+
minPrice: BigNumber;
|
|
1391
|
+
maxPrice: BigNumber;
|
|
1392
|
+
priceLastUpdateTimestampS: bigint;
|
|
1393
|
+
availableAmount: BigNumber;
|
|
1394
|
+
ctokenSupply: BigNumber;
|
|
1395
|
+
borrowedAmount: BigNumber;
|
|
1396
|
+
cumulativeBorrowRate: BigNumber;
|
|
1397
|
+
interestLastUpdateTimestampS: bigint;
|
|
1398
|
+
unclaimedSpreadFees: BigNumber;
|
|
1399
|
+
attributedBorrowValue: BigNumber;
|
|
1400
|
+
depositsPoolRewardManager: {
|
|
1401
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1402
|
+
id: string;
|
|
1403
|
+
totalShares: bigint;
|
|
1404
|
+
poolRewards: {
|
|
1405
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1406
|
+
id: string;
|
|
1407
|
+
poolRewardManagerId: string;
|
|
1408
|
+
coinType: string;
|
|
1409
|
+
startTimeMs: number;
|
|
1410
|
+
endTimeMs: number;
|
|
1411
|
+
totalRewards: BigNumber;
|
|
1412
|
+
allocatedRewards: BigNumber;
|
|
1413
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1414
|
+
numUserRewardManagers: bigint;
|
|
1415
|
+
rewardIndex: number;
|
|
1416
|
+
symbol: string;
|
|
1417
|
+
mintDecimals: number;
|
|
1418
|
+
}[];
|
|
1419
|
+
lastUpdateTimeMs: bigint;
|
|
1420
|
+
};
|
|
1421
|
+
borrowsPoolRewardManager: {
|
|
1422
|
+
$typeName: `${string}::liquidity_mining::PoolRewardManager`;
|
|
1423
|
+
id: string;
|
|
1424
|
+
totalShares: bigint;
|
|
1425
|
+
poolRewards: {
|
|
1426
|
+
$typeName: `${string}::liquidity_mining::PoolReward`;
|
|
1427
|
+
id: string;
|
|
1428
|
+
poolRewardManagerId: string;
|
|
1429
|
+
coinType: string;
|
|
1430
|
+
startTimeMs: number;
|
|
1431
|
+
endTimeMs: number;
|
|
1432
|
+
totalRewards: BigNumber;
|
|
1433
|
+
allocatedRewards: BigNumber;
|
|
1434
|
+
cumulativeRewardsPerShare: BigNumber;
|
|
1435
|
+
numUserRewardManagers: bigint;
|
|
1436
|
+
rewardIndex: number;
|
|
1437
|
+
symbol: string;
|
|
1438
|
+
mintDecimals: number;
|
|
1439
|
+
}[];
|
|
1440
|
+
lastUpdateTimeMs: bigint;
|
|
1441
|
+
};
|
|
1442
|
+
availableAmountUsd: BigNumber;
|
|
1443
|
+
borrowedAmountUsd: BigNumber;
|
|
1444
|
+
depositedAmount: BigNumber;
|
|
1445
|
+
depositedAmountUsd: BigNumber;
|
|
1446
|
+
cTokenExchangeRate: BigNumber;
|
|
1447
|
+
borrowAprPercent: BigNumber;
|
|
1448
|
+
depositAprPercent: BigNumber;
|
|
1449
|
+
utilizationPercent: BigNumber;
|
|
1450
|
+
token: {
|
|
1451
|
+
id: string | null;
|
|
1452
|
+
decimals: number;
|
|
1453
|
+
name: string;
|
|
1454
|
+
symbol: string;
|
|
1455
|
+
description: string;
|
|
1456
|
+
iconUrl: string | null;
|
|
1457
|
+
coinType: string;
|
|
1458
|
+
};
|
|
1459
|
+
symbol: string;
|
|
1460
|
+
name: string;
|
|
1461
|
+
iconUrl: string | null;
|
|
1462
|
+
description: string;
|
|
1463
|
+
totalDeposits: BigNumber;
|
|
1464
|
+
};
|
|
1465
|
+
original: Obligation<string>;
|
|
1466
|
+
}[];
|
|
1467
|
+
weightedConservativeBorrowUtilizationPercent: BigNumber;
|
|
1468
|
+
original: Obligation<string>;
|
|
1469
|
+
totalSupplyUsd: BigNumber;
|
|
1470
|
+
totalBorrowUsd: BigNumber;
|
|
1471
|
+
totalWeightedBorrowUsd: BigNumber;
|
|
1472
|
+
maxPriceTotalWeightedBorrowUsd: BigNumber;
|
|
1473
|
+
borrowLimit: BigNumber;
|
|
1474
|
+
minPriceBorrowLimit: BigNumber;
|
|
1475
|
+
}[];
|
|
1476
|
+
};
|
|
943
1477
|
export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
|
|
944
1478
|
strategyOwnerCaps: StrategyOwnerCap[];
|
|
945
1479
|
strategyObligations: {
|
|
@@ -1072,7 +1606,7 @@ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suile
|
|
|
1072
1606
|
description: string;
|
|
1073
1607
|
totalDeposits: BigNumber;
|
|
1074
1608
|
};
|
|
1075
|
-
original:
|
|
1609
|
+
original: Obligation<string>;
|
|
1076
1610
|
}[];
|
|
1077
1611
|
borrows: {
|
|
1078
1612
|
coinType: string;
|
|
@@ -1190,10 +1724,10 @@ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suile
|
|
|
1190
1724
|
description: string;
|
|
1191
1725
|
totalDeposits: BigNumber;
|
|
1192
1726
|
};
|
|
1193
|
-
original:
|
|
1727
|
+
original: Obligation<string>;
|
|
1194
1728
|
}[];
|
|
1195
1729
|
weightedConservativeBorrowUtilizationPercent: BigNumber;
|
|
1196
|
-
original:
|
|
1730
|
+
original: Obligation<string>;
|
|
1197
1731
|
totalSupplyUsd: BigNumber;
|
|
1198
1732
|
totalBorrowUsd: BigNumber;
|
|
1199
1733
|
totalWeightedBorrowUsd: BigNumber;
|
|
@@ -1201,7 +1735,7 @@ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suile
|
|
|
1201
1735
|
borrowLimit: BigNumber;
|
|
1202
1736
|
minPriceBorrowLimit: BigNumber;
|
|
1203
1737
|
}[];
|
|
1204
|
-
obligationOwnerCaps:
|
|
1738
|
+
obligationOwnerCaps: ObligationOwnerCap<string>[];
|
|
1205
1739
|
obligations: {
|
|
1206
1740
|
id: string;
|
|
1207
1741
|
depositedAmountUsd: BigNumber;
|
|
@@ -1332,7 +1866,7 @@ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suile
|
|
|
1332
1866
|
description: string;
|
|
1333
1867
|
totalDeposits: BigNumber;
|
|
1334
1868
|
};
|
|
1335
|
-
original:
|
|
1869
|
+
original: Obligation<string>;
|
|
1336
1870
|
}[];
|
|
1337
1871
|
borrows: {
|
|
1338
1872
|
coinType: string;
|
|
@@ -1450,10 +1984,10 @@ export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suile
|
|
|
1450
1984
|
description: string;
|
|
1451
1985
|
totalDeposits: BigNumber;
|
|
1452
1986
|
};
|
|
1453
|
-
original:
|
|
1987
|
+
original: Obligation<string>;
|
|
1454
1988
|
}[];
|
|
1455
1989
|
weightedConservativeBorrowUtilizationPercent: BigNumber;
|
|
1456
|
-
original:
|
|
1990
|
+
original: Obligation<string>;
|
|
1457
1991
|
totalSupplyUsd: BigNumber;
|
|
1458
1992
|
totalBorrowUsd: BigNumber;
|
|
1459
1993
|
totalWeightedBorrowUsd: BigNumber;
|
package/lib/initialize.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
1
|
+
import { normalizeStructTag, parseStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
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
|
+
import { phantom } from "../_generated/_framework/reified.js";
|
|
5
|
+
import { PACKAGE_ID } from "../_generated/suilend/index.js";
|
|
6
|
+
import { ObligationOwnerCap } from "../_generated/suilend/lending-market/structs.js";
|
|
7
|
+
import { Obligation } from "../_generated/suilend/obligation/structs.js";
|
|
4
8
|
import { LENDING_MARKET_ID, SuilendClient, listAllOwnedObjects, } from "../client.js";
|
|
5
9
|
import { parseLendingMarket, parseObligation } from "../parsers/index.js";
|
|
10
|
+
import { chunkedMultiGetSettled } from "../utils/obligation.js";
|
|
6
11
|
import * as simulate from "../utils/simulate.js";
|
|
7
12
|
import { WAD } from "./constants.js";
|
|
8
13
|
import { resolvePythConnection } from "./pyth.js";
|
|
@@ -440,47 +445,84 @@ export const initializeSuilendRewards = async (reserveMap, activeRewardCoinTypes
|
|
|
440
445
|
const [rewards] = await initializeSuilendRewardsAll([{ reserveMap, activeRewardCoinTypes }], fetchPrices);
|
|
441
446
|
return rewards;
|
|
442
447
|
};
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
})
|
|
474
|
-
SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiGrpcClient),
|
|
448
|
+
const toStrategyOwnerCap = (json) => {
|
|
449
|
+
const cap = json;
|
|
450
|
+
return {
|
|
451
|
+
id: cap.id,
|
|
452
|
+
strategyType: `${cap.strategy_type}`,
|
|
453
|
+
obligationOwnerCapId: cap.inner_cap.id,
|
|
454
|
+
obligationId: cap.inner_cap.obligation_id,
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
const OBLIGATION_OWNER_CAP_TYPE = `${PACKAGE_ID}::lending_market::ObligationOwnerCap`;
|
|
458
|
+
const STRATEGY_OWNER_CAP_TYPE = `${STRATEGY_WRAPPER_PACKAGE_ID_V1}::strategy_wrapper::StrategyOwnerCap`;
|
|
459
|
+
const capType = (capStructType, lendingMarketType) => normalizeStructTag(`${capStructType}<${lendingMarketType}>`);
|
|
460
|
+
const lendingMarketTypeOf = (type) => {
|
|
461
|
+
const [lendingMarketType] = parseStructTag(type).typeParams;
|
|
462
|
+
if (lendingMarketType === undefined)
|
|
463
|
+
return undefined;
|
|
464
|
+
return typeof lendingMarketType === "string"
|
|
465
|
+
? lendingMarketType
|
|
466
|
+
: normalizeStructTag(lendingMarketType);
|
|
467
|
+
};
|
|
468
|
+
const hasStrategies = (suilendClient) => Object.values(STRATEGY_TYPE_INFO_MAP).some((info) => info.lendingMarketId === suilendClient.lendingMarket.id);
|
|
469
|
+
const listOwnedCaps = async (suiGrpcClient, address, includeStrategyOwnerCaps) => {
|
|
470
|
+
const [strategyObjects, ownerCapObjects] = await Promise.all([
|
|
471
|
+
includeStrategyOwnerCaps
|
|
472
|
+
? listAllOwnedObjects(suiGrpcClient, address, STRATEGY_OWNER_CAP_TYPE, {
|
|
473
|
+
json: true,
|
|
474
|
+
})
|
|
475
|
+
: [],
|
|
476
|
+
listAllOwnedObjects(suiGrpcClient, address, OBLIGATION_OWNER_CAP_TYPE, {
|
|
477
|
+
content: true,
|
|
478
|
+
}),
|
|
475
479
|
]);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
+
return {
|
|
481
|
+
strategyOwnerCaps: strategyObjects.flatMap((obj) => {
|
|
482
|
+
const lendingMarketType = lendingMarketTypeOf(obj.type);
|
|
483
|
+
return lendingMarketType === undefined
|
|
484
|
+
? []
|
|
485
|
+
: [{ ...toStrategyOwnerCap(obj.json), lendingMarketType }];
|
|
486
|
+
}),
|
|
487
|
+
obligationOwnerCaps: ownerCapObjects.flatMap((obj) => {
|
|
488
|
+
const lendingMarketType = lendingMarketTypeOf(obj.type);
|
|
489
|
+
return lendingMarketType === undefined
|
|
490
|
+
? []
|
|
491
|
+
: [
|
|
492
|
+
ObligationOwnerCap.fromBcs(phantom(lendingMarketType), obj.content),
|
|
493
|
+
];
|
|
494
|
+
}),
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
const selectMarketCaps = (owned, suilendClient) => {
|
|
498
|
+
const lendingMarketType = suilendClient.lendingMarket.$typeArgs[0];
|
|
499
|
+
const strategyOwnerCapType = capType(STRATEGY_OWNER_CAP_TYPE, lendingMarketType);
|
|
500
|
+
const obligationOwnerCapType = capType(OBLIGATION_OWNER_CAP_TYPE, lendingMarketType);
|
|
501
|
+
return {
|
|
502
|
+
strategyOwnerCaps: hasStrategies(suilendClient)
|
|
503
|
+
? owned.strategyOwnerCaps
|
|
504
|
+
.filter((soc) => capType(STRATEGY_OWNER_CAP_TYPE, soc.lendingMarketType) ===
|
|
505
|
+
strategyOwnerCapType)
|
|
506
|
+
.map(({ id, strategyType, obligationOwnerCapId, obligationId }) => ({
|
|
507
|
+
id,
|
|
508
|
+
strategyType,
|
|
509
|
+
obligationOwnerCapId,
|
|
510
|
+
obligationId,
|
|
511
|
+
}))
|
|
512
|
+
: [],
|
|
513
|
+
obligationOwnerCaps: owned.obligationOwnerCaps.filter((ownerCap) => capType(OBLIGATION_OWNER_CAP_TYPE, ownerCap.$typeArgs[0]) ===
|
|
514
|
+
obligationOwnerCapType),
|
|
515
|
+
};
|
|
516
|
+
};
|
|
517
|
+
const obligationIdsOf = ({ strategyOwnerCaps, obligationOwnerCaps, }) => [
|
|
518
|
+
...strategyOwnerCaps.map((soc) => soc.obligationId),
|
|
519
|
+
...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
|
|
520
|
+
];
|
|
521
|
+
const parseMarketObligations = (rawObligations, { strategyOwnerCaps, obligationOwnerCaps }, refreshedRawReserves, reserveMap) => {
|
|
522
|
+
const obligations = rawObligations
|
|
480
523
|
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
|
|
481
524
|
.map((refreshedObligation) => parseObligation(refreshedObligation, reserveMap, strategyOwnerCaps.some((soc) => soc.obligationId === refreshedObligation.id)))
|
|
482
525
|
.sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
|
|
483
|
-
// Divide into strategy and non-strategy
|
|
484
526
|
const strategyObligations = obligations.filter((o) => strategyOwnerCaps.some((soc) => soc.obligationId === o.id));
|
|
485
527
|
const nonStrategyObligations = obligations.filter((o) => !strategyObligations.some((so) => so.id === o.id));
|
|
486
528
|
return {
|
|
@@ -490,3 +532,64 @@ export const initializeObligations = async (suiGrpcClient, suilendClient, refres
|
|
|
490
532
|
obligations: nonStrategyObligations,
|
|
491
533
|
};
|
|
492
534
|
};
|
|
535
|
+
export const fetchOwnedObligations = async (suiGrpcClient, address) => {
|
|
536
|
+
const { strategyOwnerCaps, obligationOwnerCaps } = await listOwnedCaps(suiGrpcClient, address, true);
|
|
537
|
+
const lendingMarketTypeByObligationId = new Map();
|
|
538
|
+
for (const { obligationId, lendingMarketType } of [
|
|
539
|
+
...strategyOwnerCaps,
|
|
540
|
+
...obligationOwnerCaps.map((ownerCap) => ({
|
|
541
|
+
obligationId: ownerCap.obligationId,
|
|
542
|
+
lendingMarketType: ownerCap.$typeArgs[0],
|
|
543
|
+
})),
|
|
544
|
+
]) {
|
|
545
|
+
lendingMarketTypeByObligationId.set(obligationId, lendingMarketType);
|
|
546
|
+
}
|
|
547
|
+
const obligationLendingMarketTypes = Array.from(lendingMarketTypeByObligationId);
|
|
548
|
+
const objects = await chunkedMultiGetSettled(suiGrpcClient, obligationLendingMarketTypes.map(([obligationId]) => obligationId));
|
|
549
|
+
const obligations = [];
|
|
550
|
+
const obligationErrors = {};
|
|
551
|
+
for (const [index, object] of objects.entries()) {
|
|
552
|
+
const [obligationId, lendingMarketType] = obligationLendingMarketTypes[index];
|
|
553
|
+
if (object instanceof Error) {
|
|
554
|
+
obligationErrors[obligationId] = object;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
try {
|
|
558
|
+
obligations.push(Obligation.fromBcs(phantom(lendingMarketType), object.content));
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
obligationErrors[obligationId] = error;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
strategyOwnerCaps,
|
|
566
|
+
obligationOwnerCaps,
|
|
567
|
+
obligations,
|
|
568
|
+
obligationErrors,
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
export const parseOwnedObligations = (owned, suilendClient, refreshedRawReserves, reserveMap) => {
|
|
572
|
+
const marketCaps = selectMarketCaps(owned, suilendClient);
|
|
573
|
+
const obligationsById = new Map(owned.obligations.map((obligation) => [obligation.id, obligation]));
|
|
574
|
+
const rawObligations = obligationIdsOf(marketCaps).map((obligationId) => {
|
|
575
|
+
const obligation = obligationsById.get(obligationId);
|
|
576
|
+
if (obligation)
|
|
577
|
+
return obligation;
|
|
578
|
+
if (obligationId in owned.obligationErrors)
|
|
579
|
+
throw owned.obligationErrors[obligationId];
|
|
580
|
+
throw new Error(`Obligation ${obligationId} is not in the owned obligations`);
|
|
581
|
+
});
|
|
582
|
+
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
|
|
583
|
+
};
|
|
584
|
+
export const initializeObligations = async (suiGrpcClient, suilendClient, refreshedRawReserves, reserveMap, address) => {
|
|
585
|
+
if (!address)
|
|
586
|
+
return {
|
|
587
|
+
strategyOwnerCaps: [],
|
|
588
|
+
strategyObligations: [],
|
|
589
|
+
obligationOwnerCaps: [],
|
|
590
|
+
obligations: [],
|
|
591
|
+
};
|
|
592
|
+
const marketCaps = selectMarketCaps(await listOwnedCaps(suiGrpcClient, address, hasStrategies(suilendClient)), suilendClient);
|
|
593
|
+
const rawObligations = await SuilendClient.getObligations(obligationIdsOf(marketCaps), suilendClient.lendingMarket.$typeArgs, suiGrpcClient);
|
|
594
|
+
return parseMarketObligations(rawObligations, marketCaps, refreshedRawReserves, reserveMap);
|
|
595
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"13.0.0
|
|
1
|
+
{"name":"@suilend/sdk","version":"13.0.0","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/obligation.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export declare function fetchAllObligationsForMarket(suiGrpcClient: SuiGrpcClien
|
|
|
9
9
|
export declare function chunkedMultiGet(suiGrpcClient: SuiGrpcClient, objectIds: string[]): Promise<(Error | SuiClientTypes.Object<{
|
|
10
10
|
content: true;
|
|
11
11
|
}>)[]>;
|
|
12
|
+
export declare function chunkedMultiGetSettled(suiGrpcClient: SuiGrpcClient, objectIds: string[]): Promise<(Error | SuiClientTypes.Object<{
|
|
13
|
+
content: true;
|
|
14
|
+
}>)[]>;
|
|
12
15
|
export type FormattedObligationHistory = NonLiquidationHistoryEvent | LiquidationHistoryEvent;
|
|
13
16
|
export type NonLiquidationHistoryEvent = {
|
|
14
17
|
reserveId: string;
|
package/utils/obligation.js
CHANGED
|
@@ -84,6 +84,16 @@ export async function chunkedMultiGet(suiGrpcClient, objectIds) {
|
|
|
84
84
|
}
|
|
85
85
|
return results;
|
|
86
86
|
}
|
|
87
|
+
export async function chunkedMultiGetSettled(suiGrpcClient, objectIds) {
|
|
88
|
+
const limit = pLimit(30);
|
|
89
|
+
const results = await Promise.all(splitIntoChunks(objectIds, 50).map((chunk) => limit(() => suiGrpcClient.getObjects({
|
|
90
|
+
objectIds: chunk,
|
|
91
|
+
include: { content: true },
|
|
92
|
+
})).then(({ objects }) => objects.length === chunk.length
|
|
93
|
+
? objects
|
|
94
|
+
: chunk.map(() => new Error(`getObjects returned ${objects.length} objects for ${chunk.length} ids`)), (error) => chunk.map(() => error instanceof Error ? error : new Error(String(error))))));
|
|
95
|
+
return results.flat();
|
|
96
|
+
}
|
|
87
97
|
function splitIntoChunks(arr, chunkSize) {
|
|
88
98
|
const result = [];
|
|
89
99
|
for (let i = 0; i < arr.length; i += chunkSize) {
|