@kamino-finance/klend-sdk 5.14.2 → 5.14.4
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/dist/classes/configItems.d.ts +166 -0
- package/dist/classes/configItems.d.ts.map +1 -0
- package/dist/classes/configItems.js +202 -0
- package/dist/classes/configItems.js.map +1 -0
- package/dist/classes/manager.d.ts +4 -7
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +35 -292
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +1 -1
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/reserve.d.ts +5 -14
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +88 -463
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +12 -0
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +7 -0
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/vault_types.d.ts +1 -0
- package/dist/classes/vault_types.d.ts.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +4 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +2 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +13 -9
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +34 -30
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +4 -4
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +91 -55
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +8 -6
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +40 -19
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/instruction.d.ts +3 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +17 -1
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -3
- package/dist/utils/managerTypes.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/configItems.ts +295 -0
- package/src/classes/manager.ts +47 -392
- package/src/classes/market.ts +6 -1
- package/src/classes/reserve.ts +115 -783
- package/src/classes/utils.ts +12 -0
- package/src/classes/vault.ts +15 -1
- package/src/classes/vault_types.ts +1 -0
- package/src/client_kamino_manager.ts +5 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +34 -26
- package/src/lending_operations/swap_collateral_operations.ts +43 -36
- package/src/leverage/operations.ts +175 -147
- package/src/leverage/types.ts +8 -6
- package/src/leverage/utils.ts +41 -20
- package/src/utils/instruction.ts +28 -0
- package/src/utils/managerTypes.ts +9 -3
package/src/classes/reserve.ts
CHANGED
|
@@ -23,22 +23,9 @@ import {
|
|
|
23
23
|
} from '../utils';
|
|
24
24
|
import { FeeCalculation, Fees, ReserveDataType, ReserveFarmInfo, ReserveRewardYield, ReserveStatus } from './shared';
|
|
25
25
|
import { Reserve, ReserveFields } from '../idl_codegen/accounts';
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ReserveConfig,
|
|
30
|
-
UpdateConfigMode,
|
|
31
|
-
UpdateConfigModeKind,
|
|
32
|
-
} from '../idl_codegen/types';
|
|
33
|
-
import {
|
|
34
|
-
assertNever,
|
|
35
|
-
calculateAPYFromAPR,
|
|
36
|
-
getBorrowRate,
|
|
37
|
-
lamportsToNumberDecimal,
|
|
38
|
-
parseTokenSymbol,
|
|
39
|
-
positiveOrZero,
|
|
40
|
-
sameLengthArrayEquals,
|
|
41
|
-
} from './utils';
|
|
26
|
+
import { CurvePointFields, ReserveConfig, UpdateConfigMode, UpdateConfigModeKind } from '../idl_codegen/types';
|
|
27
|
+
import { calculateAPYFromAPR, getBorrowRate, lamportsToNumberDecimal, parseTokenSymbol, positiveOrZero } from './utils';
|
|
28
|
+
import { CompositeConfigItem, encodeUsingLayout, ConfigUpdater } from './configItems';
|
|
42
29
|
import { bfToDecimal, Fraction } from './fraction';
|
|
43
30
|
import { ActionType } from './action';
|
|
44
31
|
import { BorrowCapsAndCounters, ElevationGroupDescription, KaminoMarket } from './market';
|
|
@@ -49,10 +36,10 @@ import {
|
|
|
49
36
|
UpdateReserveConfigAccounts,
|
|
50
37
|
UpdateReserveConfigArgs,
|
|
51
38
|
} from '../lib';
|
|
52
|
-
import * as anchor from '@coral-xyz/anchor';
|
|
53
39
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
54
40
|
import { aprToApy, KaminoPrices } from '@kamino-finance/kliquidity-sdk';
|
|
55
41
|
import { FarmState, RewardInfo } from '@kamino-finance/farms-sdk';
|
|
42
|
+
import BN from 'bn.js';
|
|
56
43
|
|
|
57
44
|
export const DEFAULT_RECENT_SLOT_DURATION_MS = 450;
|
|
58
45
|
|
|
@@ -1187,618 +1174,105 @@ export async function createReserveIxs(
|
|
|
1187
1174
|
}
|
|
1188
1175
|
|
|
1189
1176
|
export function updateReserveConfigIx(
|
|
1190
|
-
|
|
1177
|
+
signer: PublicKey,
|
|
1178
|
+
marketAddress: PublicKey,
|
|
1191
1179
|
reserveAddress: PublicKey,
|
|
1192
|
-
|
|
1180
|
+
mode: UpdateConfigModeKind,
|
|
1193
1181
|
value: Uint8Array,
|
|
1194
1182
|
programId: PublicKey,
|
|
1195
1183
|
skipValidation: boolean = false
|
|
1196
1184
|
): TransactionInstruction {
|
|
1197
|
-
value;
|
|
1198
1185
|
const args: UpdateReserveConfigArgs = {
|
|
1199
|
-
mode: new
|
|
1200
|
-
value
|
|
1186
|
+
mode: new BN(mode.discriminator + 1),
|
|
1187
|
+
value,
|
|
1201
1188
|
skipValidation,
|
|
1202
1189
|
};
|
|
1203
1190
|
|
|
1204
1191
|
const accounts: UpdateReserveConfigAccounts = {
|
|
1205
|
-
lendingMarketOwner:
|
|
1206
|
-
lendingMarket:
|
|
1192
|
+
lendingMarketOwner: signer,
|
|
1193
|
+
lendingMarket: marketAddress,
|
|
1207
1194
|
reserve: reserveAddress,
|
|
1208
1195
|
};
|
|
1209
1196
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
return ix;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
type BaseReserveConfigKey = keyof ReturnType<typeof ReserveConfig.toEncodable>;
|
|
1216
|
-
|
|
1217
|
-
// Type that excludes reserved and padding fields
|
|
1218
|
-
type ReserveConfigKey = Exclude<BaseReserveConfigKey, ExcludedReserveConfigKey>;
|
|
1219
|
-
|
|
1220
|
-
const EXCLUDED_RESERVE_CONFIG_KEYS = ['reserved1', 'reserved2'] as const;
|
|
1221
|
-
|
|
1222
|
-
export type ExcludedReserveConfigKey = (typeof EXCLUDED_RESERVE_CONFIG_KEYS)[number];
|
|
1223
|
-
|
|
1224
|
-
function isExcludedReserveConfigKey(value: unknown): value is ExcludedReserveConfigKey {
|
|
1225
|
-
return EXCLUDED_RESERVE_CONFIG_KEYS.includes(value as ExcludedReserveConfigKey);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
function handleConfigUpdate(
|
|
1229
|
-
key: ReserveConfigKey,
|
|
1230
|
-
reserve: Reserve | undefined,
|
|
1231
|
-
reserveConfig: ReserveConfig,
|
|
1232
|
-
updateReserveIxsArgs: UpdateReserveIxsArg[]
|
|
1233
|
-
): void {
|
|
1234
|
-
switch (key) {
|
|
1235
|
-
case 'status':
|
|
1236
|
-
if (reserve === undefined || reserve.config.status !== reserveConfig.status) {
|
|
1237
|
-
updateReserveIxsArgs.push(
|
|
1238
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateReserveStatus.discriminator, reserveConfig.status)
|
|
1239
|
-
);
|
|
1240
|
-
}
|
|
1241
|
-
break;
|
|
1242
|
-
case 'assetTier':
|
|
1243
|
-
if (reserve === undefined || reserve.config.assetTier !== reserveConfig.assetTier) {
|
|
1244
|
-
updateReserveIxsArgs.push(
|
|
1245
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateAssetTier.discriminator, reserveConfig.assetTier)
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
break;
|
|
1249
|
-
case 'hostFixedInterestRateBps':
|
|
1250
|
-
if (reserve === undefined || reserve.config.hostFixedInterestRateBps !== reserveConfig.hostFixedInterestRateBps) {
|
|
1251
|
-
updateReserveIxsArgs.push(
|
|
1252
|
-
createUpdateReserveIxsArg(
|
|
1253
|
-
UpdateConfigMode.UpdateHostFixedInterestRateBps.discriminator,
|
|
1254
|
-
reserveConfig.hostFixedInterestRateBps
|
|
1255
|
-
)
|
|
1256
|
-
);
|
|
1257
|
-
}
|
|
1258
|
-
break;
|
|
1259
|
-
case 'protocolTakeRatePct':
|
|
1260
|
-
if (reserve === undefined || reserve.config.protocolTakeRatePct !== reserveConfig.protocolTakeRatePct) {
|
|
1261
|
-
updateReserveIxsArgs.push(
|
|
1262
|
-
createUpdateReserveIxsArg(
|
|
1263
|
-
UpdateConfigMode.UpdateProtocolTakeRate.discriminator,
|
|
1264
|
-
reserveConfig.protocolTakeRatePct
|
|
1265
|
-
)
|
|
1266
|
-
);
|
|
1267
|
-
}
|
|
1268
|
-
break;
|
|
1269
|
-
case 'protocolLiquidationFeePct':
|
|
1270
|
-
if (
|
|
1271
|
-
reserve === undefined ||
|
|
1272
|
-
reserve.config.protocolLiquidationFeePct !== reserveConfig.protocolLiquidationFeePct
|
|
1273
|
-
) {
|
|
1274
|
-
updateReserveIxsArgs.push(
|
|
1275
|
-
createUpdateReserveIxsArg(
|
|
1276
|
-
UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator,
|
|
1277
|
-
reserveConfig.protocolLiquidationFeePct
|
|
1278
|
-
)
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
break;
|
|
1282
|
-
case 'protocolOrderExecutionFeePct':
|
|
1283
|
-
if (
|
|
1284
|
-
reserve === undefined ||
|
|
1285
|
-
reserve.config.protocolOrderExecutionFeePct !== reserveConfig.protocolOrderExecutionFeePct
|
|
1286
|
-
) {
|
|
1287
|
-
updateReserveIxsArgs.push(
|
|
1288
|
-
createUpdateReserveIxsArg(
|
|
1289
|
-
UpdateConfigMode.UpdateProtocolOrderExecutionFee.discriminator,
|
|
1290
|
-
reserveConfig.protocolOrderExecutionFeePct
|
|
1291
|
-
)
|
|
1292
|
-
);
|
|
1293
|
-
}
|
|
1294
|
-
break;
|
|
1295
|
-
case 'loanToValuePct':
|
|
1296
|
-
if (reserve === undefined || reserve.config.loanToValuePct !== reserveConfig.loanToValuePct) {
|
|
1297
|
-
updateReserveIxsArgs.push(
|
|
1298
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateLoanToValuePct.discriminator, reserveConfig.loanToValuePct)
|
|
1299
|
-
);
|
|
1300
|
-
}
|
|
1301
|
-
break;
|
|
1302
|
-
case 'liquidationThresholdPct':
|
|
1303
|
-
if (reserve === undefined || reserve.config.liquidationThresholdPct !== reserveConfig.liquidationThresholdPct) {
|
|
1304
|
-
updateReserveIxsArgs.push(
|
|
1305
|
-
createUpdateReserveIxsArg(
|
|
1306
|
-
UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator,
|
|
1307
|
-
reserveConfig.liquidationThresholdPct
|
|
1308
|
-
)
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
break;
|
|
1312
|
-
case 'minLiquidationBonusBps':
|
|
1313
|
-
if (reserve === undefined || reserve.config.minLiquidationBonusBps !== reserveConfig.minLiquidationBonusBps) {
|
|
1314
|
-
updateReserveIxsArgs.push(
|
|
1315
|
-
createUpdateReserveIxsArg(
|
|
1316
|
-
UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator,
|
|
1317
|
-
reserveConfig.minLiquidationBonusBps
|
|
1318
|
-
)
|
|
1319
|
-
);
|
|
1320
|
-
}
|
|
1321
|
-
break;
|
|
1322
|
-
case 'maxLiquidationBonusBps':
|
|
1323
|
-
if (reserve === undefined || reserve.config.maxLiquidationBonusBps !== reserveConfig.maxLiquidationBonusBps) {
|
|
1324
|
-
updateReserveIxsArgs.push(
|
|
1325
|
-
createUpdateReserveIxsArg(
|
|
1326
|
-
UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator,
|
|
1327
|
-
reserveConfig.maxLiquidationBonusBps
|
|
1328
|
-
)
|
|
1329
|
-
);
|
|
1330
|
-
}
|
|
1331
|
-
break;
|
|
1332
|
-
case 'badDebtLiquidationBonusBps':
|
|
1333
|
-
if (
|
|
1334
|
-
reserve === undefined ||
|
|
1335
|
-
reserve.config.badDebtLiquidationBonusBps !== reserveConfig.badDebtLiquidationBonusBps
|
|
1336
|
-
) {
|
|
1337
|
-
updateReserveIxsArgs.push(
|
|
1338
|
-
createUpdateReserveIxsArg(
|
|
1339
|
-
UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator,
|
|
1340
|
-
reserveConfig.badDebtLiquidationBonusBps
|
|
1341
|
-
)
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
break;
|
|
1345
|
-
case 'deleveragingMarginCallPeriodSecs':
|
|
1346
|
-
if (
|
|
1347
|
-
reserve === undefined ||
|
|
1348
|
-
!reserve.config.deleveragingMarginCallPeriodSecs.eq(reserveConfig.deleveragingMarginCallPeriodSecs)
|
|
1349
|
-
) {
|
|
1350
|
-
updateReserveIxsArgs.push(
|
|
1351
|
-
createUpdateReserveIxsArg(
|
|
1352
|
-
UpdateConfigMode.UpdateDeleveragingMarginCallPeriod.discriminator,
|
|
1353
|
-
reserveConfig.deleveragingMarginCallPeriodSecs.toNumber()
|
|
1354
|
-
)
|
|
1355
|
-
);
|
|
1356
|
-
}
|
|
1357
|
-
break;
|
|
1358
|
-
case 'deleveragingThresholdDecreaseBpsPerDay':
|
|
1359
|
-
if (
|
|
1360
|
-
reserve === undefined ||
|
|
1361
|
-
!reserve.config.deleveragingThresholdDecreaseBpsPerDay.eq(reserveConfig.deleveragingThresholdDecreaseBpsPerDay)
|
|
1362
|
-
) {
|
|
1363
|
-
updateReserveIxsArgs.push(
|
|
1364
|
-
createUpdateReserveIxsArg(
|
|
1365
|
-
UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.discriminator,
|
|
1366
|
-
reserveConfig.deleveragingThresholdDecreaseBpsPerDay.toNumber()
|
|
1367
|
-
)
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
break;
|
|
1371
|
-
case 'fees':
|
|
1372
|
-
if (reserve === undefined || !reserve.config.fees.borrowFeeSf.eq(reserveConfig.fees.borrowFeeSf)) {
|
|
1373
|
-
updateReserveIxsArgs.push(
|
|
1374
|
-
createUpdateReserveIxsArg(
|
|
1375
|
-
UpdateConfigMode.UpdateFeesBorrowFee.discriminator,
|
|
1376
|
-
reserveConfig.fees.borrowFeeSf.toNumber()
|
|
1377
|
-
)
|
|
1378
|
-
);
|
|
1379
|
-
}
|
|
1380
|
-
if (reserve === undefined || !reserve.config.fees.flashLoanFeeSf.eq(reserveConfig.fees.flashLoanFeeSf)) {
|
|
1381
|
-
updateReserveIxsArgs.push(
|
|
1382
|
-
createUpdateReserveIxsArg(
|
|
1383
|
-
UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator,
|
|
1384
|
-
reserveConfig.fees.flashLoanFeeSf.toNumber()
|
|
1385
|
-
)
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
1388
|
-
break;
|
|
1389
|
-
case 'borrowRateCurve':
|
|
1390
|
-
if (reserve === undefined) {
|
|
1391
|
-
updateReserveIxsArgs.push(
|
|
1392
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateBorrowRateCurve.discriminator, reserveConfig.borrowRateCurve)
|
|
1393
|
-
);
|
|
1394
|
-
} else {
|
|
1395
|
-
let shouldBorrowCurveBeUpdated = false;
|
|
1396
|
-
for (let i = 0; i < reserveConfig.borrowRateCurve.points.length; i++) {
|
|
1397
|
-
if (
|
|
1398
|
-
reserve.config.borrowRateCurve.points[i].utilizationRateBps !==
|
|
1399
|
-
reserveConfig.borrowRateCurve.points[i].utilizationRateBps ||
|
|
1400
|
-
reserve.config.borrowRateCurve.points[i].borrowRateBps !==
|
|
1401
|
-
reserveConfig.borrowRateCurve.points[i].borrowRateBps
|
|
1402
|
-
) {
|
|
1403
|
-
shouldBorrowCurveBeUpdated = true;
|
|
1404
|
-
break;
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
if (shouldBorrowCurveBeUpdated) {
|
|
1409
|
-
updateReserveIxsArgs.push(
|
|
1410
|
-
createUpdateReserveIxsArg(
|
|
1411
|
-
UpdateConfigMode.UpdateBorrowRateCurve.discriminator,
|
|
1412
|
-
reserveConfig.borrowRateCurve
|
|
1413
|
-
)
|
|
1414
|
-
);
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
break;
|
|
1419
|
-
case 'borrowFactorPct':
|
|
1420
|
-
if (reserve === undefined || !reserve.config.borrowFactorPct.eq(reserveConfig.borrowFactorPct)) {
|
|
1421
|
-
updateReserveIxsArgs.push(
|
|
1422
|
-
createUpdateReserveIxsArg(
|
|
1423
|
-
UpdateConfigMode.UpdateBorrowFactor.discriminator,
|
|
1424
|
-
reserveConfig.borrowFactorPct.toNumber()
|
|
1425
|
-
)
|
|
1426
|
-
);
|
|
1427
|
-
}
|
|
1428
|
-
break;
|
|
1429
|
-
case 'depositLimit':
|
|
1430
|
-
if (reserve === undefined || !reserve.config.depositLimit.eq(reserveConfig.depositLimit)) {
|
|
1431
|
-
updateReserveIxsArgs.push(
|
|
1432
|
-
createUpdateReserveIxsArg(
|
|
1433
|
-
UpdateConfigMode.UpdateDepositLimit.discriminator,
|
|
1434
|
-
BigInt(reserveConfig.depositLimit.toString())
|
|
1435
|
-
)
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
break;
|
|
1439
|
-
case 'borrowLimit':
|
|
1440
|
-
if (reserve === undefined || !reserve.config.borrowLimit.eq(reserveConfig.borrowLimit)) {
|
|
1441
|
-
updateReserveIxsArgs.push(
|
|
1442
|
-
createUpdateReserveIxsArg(
|
|
1443
|
-
UpdateConfigMode.UpdateBorrowLimit.discriminator,
|
|
1444
|
-
BigInt(reserveConfig.borrowLimit.toString())
|
|
1445
|
-
)
|
|
1446
|
-
);
|
|
1447
|
-
}
|
|
1448
|
-
break;
|
|
1449
|
-
case 'tokenInfo':
|
|
1450
|
-
const tokenInfo = reserveConfig.tokenInfo;
|
|
1451
|
-
if (reserve === undefined) {
|
|
1452
|
-
updateReserveIxsArgs.push(
|
|
1453
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateTokenInfoName.discriminator, tokenInfo.name)
|
|
1454
|
-
);
|
|
1455
|
-
updateReserveIxsArgs.push(
|
|
1456
|
-
createUpdateReserveIxsArg(
|
|
1457
|
-
UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1458
|
-
tokenInfo.heuristic.lower.toNumber()
|
|
1459
|
-
)
|
|
1460
|
-
);
|
|
1461
|
-
updateReserveIxsArgs.push(
|
|
1462
|
-
createUpdateReserveIxsArg(
|
|
1463
|
-
UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1464
|
-
tokenInfo.heuristic.upper.toNumber()
|
|
1465
|
-
)
|
|
1466
|
-
);
|
|
1467
|
-
updateReserveIxsArgs.push(
|
|
1468
|
-
createUpdateReserveIxsArg(
|
|
1469
|
-
UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1470
|
-
tokenInfo.heuristic.exp.toNumber()
|
|
1471
|
-
)
|
|
1472
|
-
);
|
|
1473
|
-
updateReserveIxsArgs.push(
|
|
1474
|
-
createUpdateReserveIxsArg(
|
|
1475
|
-
UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1476
|
-
tokenInfo.maxTwapDivergenceBps.toNumber()
|
|
1477
|
-
)
|
|
1478
|
-
);
|
|
1479
|
-
updateReserveIxsArgs.push(
|
|
1480
|
-
createUpdateReserveIxsArg(
|
|
1481
|
-
UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1482
|
-
tokenInfo.maxAgePriceSeconds.toNumber()
|
|
1483
|
-
)
|
|
1484
|
-
);
|
|
1485
|
-
updateReserveIxsArgs.push(
|
|
1486
|
-
createUpdateReserveIxsArg(
|
|
1487
|
-
UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1488
|
-
tokenInfo.maxAgeTwapSeconds.toNumber()
|
|
1489
|
-
)
|
|
1490
|
-
);
|
|
1491
|
-
updateReserveIxsArgs.push(
|
|
1492
|
-
createUpdateReserveIxsArg(
|
|
1493
|
-
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1494
|
-
tokenInfo.scopeConfiguration.priceChain
|
|
1495
|
-
)
|
|
1496
|
-
);
|
|
1497
|
-
updateReserveIxsArgs.push(
|
|
1498
|
-
createUpdateReserveIxsArg(
|
|
1499
|
-
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1500
|
-
tokenInfo.scopeConfiguration.twapChain
|
|
1501
|
-
)
|
|
1502
|
-
);
|
|
1503
|
-
updateReserveIxsArgs.push(
|
|
1504
|
-
createUpdateReserveIxsArg(
|
|
1505
|
-
UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1506
|
-
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1507
|
-
)
|
|
1508
|
-
);
|
|
1509
|
-
updateReserveIxsArgs.push(
|
|
1510
|
-
createUpdateReserveIxsArg(
|
|
1511
|
-
UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1512
|
-
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1513
|
-
)
|
|
1514
|
-
);
|
|
1515
|
-
updateReserveIxsArgs.push(
|
|
1516
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdatePythPrice.discriminator, tokenInfo.pythConfiguration.price)
|
|
1517
|
-
);
|
|
1518
|
-
updateReserveIxsArgs.push(
|
|
1519
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateBlockPriceUsage.discriminator, tokenInfo.blockPriceUsage)
|
|
1520
|
-
);
|
|
1521
|
-
} else {
|
|
1522
|
-
if (!sameLengthArrayEquals(reserve.config.tokenInfo.name, tokenInfo.name)) {
|
|
1523
|
-
updateReserveIxsArgs.push(
|
|
1524
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateTokenInfoName.discriminator, tokenInfo.name)
|
|
1525
|
-
);
|
|
1526
|
-
}
|
|
1527
|
-
if (!reserve.config.tokenInfo.heuristic.lower.eq(tokenInfo.heuristic.lower)) {
|
|
1528
|
-
updateReserveIxsArgs.push(
|
|
1529
|
-
createUpdateReserveIxsArg(
|
|
1530
|
-
UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1531
|
-
tokenInfo.heuristic.lower.toNumber()
|
|
1532
|
-
)
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
if (!reserve.config.tokenInfo.heuristic.upper.eq(tokenInfo.heuristic.upper)) {
|
|
1536
|
-
updateReserveIxsArgs.push(
|
|
1537
|
-
createUpdateReserveIxsArg(
|
|
1538
|
-
UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1539
|
-
tokenInfo.heuristic.upper.toNumber()
|
|
1540
|
-
)
|
|
1541
|
-
);
|
|
1542
|
-
}
|
|
1543
|
-
if (!reserve.config.tokenInfo.heuristic.exp.eq(tokenInfo.heuristic.exp)) {
|
|
1544
|
-
updateReserveIxsArgs.push(
|
|
1545
|
-
createUpdateReserveIxsArg(
|
|
1546
|
-
UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1547
|
-
tokenInfo.heuristic.exp.toNumber()
|
|
1548
|
-
)
|
|
1549
|
-
);
|
|
1550
|
-
}
|
|
1551
|
-
if (!reserve.config.tokenInfo.maxTwapDivergenceBps.eq(tokenInfo.maxTwapDivergenceBps)) {
|
|
1552
|
-
updateReserveIxsArgs.push(
|
|
1553
|
-
createUpdateReserveIxsArg(
|
|
1554
|
-
UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1555
|
-
tokenInfo.maxTwapDivergenceBps.toNumber()
|
|
1556
|
-
)
|
|
1557
|
-
);
|
|
1558
|
-
}
|
|
1559
|
-
if (!reserve.config.tokenInfo.maxAgePriceSeconds.eq(tokenInfo.maxAgePriceSeconds)) {
|
|
1560
|
-
updateReserveIxsArgs.push(
|
|
1561
|
-
createUpdateReserveIxsArg(
|
|
1562
|
-
UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1563
|
-
tokenInfo.maxAgePriceSeconds.toNumber()
|
|
1564
|
-
)
|
|
1565
|
-
);
|
|
1566
|
-
}
|
|
1567
|
-
if (!reserve.config.tokenInfo.maxAgeTwapSeconds.eq(tokenInfo.maxAgeTwapSeconds)) {
|
|
1568
|
-
updateReserveIxsArgs.push(
|
|
1569
|
-
createUpdateReserveIxsArg(
|
|
1570
|
-
UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1571
|
-
tokenInfo.maxAgeTwapSeconds.toNumber()
|
|
1572
|
-
)
|
|
1573
|
-
);
|
|
1574
|
-
}
|
|
1575
|
-
if (
|
|
1576
|
-
!sameLengthArrayEquals(
|
|
1577
|
-
reserve.config.tokenInfo.scopeConfiguration.priceChain,
|
|
1578
|
-
tokenInfo.scopeConfiguration.priceChain
|
|
1579
|
-
)
|
|
1580
|
-
) {
|
|
1581
|
-
updateReserveIxsArgs.push(
|
|
1582
|
-
createUpdateReserveIxsArg(
|
|
1583
|
-
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1584
|
-
tokenInfo.scopeConfiguration.priceChain
|
|
1585
|
-
)
|
|
1586
|
-
);
|
|
1587
|
-
}
|
|
1588
|
-
if (
|
|
1589
|
-
!sameLengthArrayEquals(
|
|
1590
|
-
reserve.config.tokenInfo.scopeConfiguration.twapChain,
|
|
1591
|
-
tokenInfo.scopeConfiguration.twapChain
|
|
1592
|
-
)
|
|
1593
|
-
) {
|
|
1594
|
-
updateReserveIxsArgs.push(
|
|
1595
|
-
createUpdateReserveIxsArg(
|
|
1596
|
-
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1597
|
-
tokenInfo.scopeConfiguration.twapChain
|
|
1598
|
-
)
|
|
1599
|
-
);
|
|
1600
|
-
}
|
|
1601
|
-
if (
|
|
1602
|
-
!reserve.config.tokenInfo.switchboardConfiguration.priceAggregator.equals(
|
|
1603
|
-
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1604
|
-
)
|
|
1605
|
-
) {
|
|
1606
|
-
updateReserveIxsArgs.push(
|
|
1607
|
-
createUpdateReserveIxsArg(
|
|
1608
|
-
UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1609
|
-
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1610
|
-
)
|
|
1611
|
-
);
|
|
1612
|
-
}
|
|
1613
|
-
if (
|
|
1614
|
-
!reserve.config.tokenInfo.switchboardConfiguration.twapAggregator.equals(
|
|
1615
|
-
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1616
|
-
)
|
|
1617
|
-
) {
|
|
1618
|
-
updateReserveIxsArgs.push(
|
|
1619
|
-
createUpdateReserveIxsArg(
|
|
1620
|
-
UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1621
|
-
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1622
|
-
)
|
|
1623
|
-
);
|
|
1624
|
-
}
|
|
1625
|
-
if (!reserve.config.tokenInfo.pythConfiguration.price.equals(tokenInfo.pythConfiguration.price)) {
|
|
1626
|
-
updateReserveIxsArgs.push(
|
|
1627
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdatePythPrice.discriminator, tokenInfo.pythConfiguration.price)
|
|
1628
|
-
);
|
|
1629
|
-
}
|
|
1630
|
-
if (reserve.config.tokenInfo.blockPriceUsage !== tokenInfo.blockPriceUsage) {
|
|
1631
|
-
updateReserveIxsArgs.push(
|
|
1632
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateBlockPriceUsage.discriminator, tokenInfo.blockPriceUsage)
|
|
1633
|
-
);
|
|
1634
|
-
}
|
|
1635
|
-
if (!reserve.config.tokenInfo.scopeConfiguration.priceFeed.equals(tokenInfo.scopeConfiguration.priceFeed)) {
|
|
1636
|
-
updateReserveIxsArgs.push(
|
|
1637
|
-
createUpdateReserveIxsArg(
|
|
1638
|
-
UpdateConfigMode.UpdateScopePriceFeed.discriminator,
|
|
1639
|
-
tokenInfo.scopeConfiguration.priceFeed
|
|
1640
|
-
)
|
|
1641
|
-
);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
break;
|
|
1645
|
-
case 'depositWithdrawalCap':
|
|
1646
|
-
if (
|
|
1647
|
-
reserve === undefined ||
|
|
1648
|
-
!reserve.config.depositWithdrawalCap.configCapacity.eq(reserveConfig.depositWithdrawalCap.configCapacity) ||
|
|
1649
|
-
!reserve.config.depositWithdrawalCap.configIntervalLengthSeconds.eq(
|
|
1650
|
-
reserveConfig.depositWithdrawalCap.configIntervalLengthSeconds
|
|
1651
|
-
)
|
|
1652
|
-
) {
|
|
1653
|
-
updateReserveIxsArgs.push(
|
|
1654
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator, [
|
|
1655
|
-
reserveConfig.depositWithdrawalCap.configCapacity.toNumber(),
|
|
1656
|
-
reserveConfig.depositWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1657
|
-
])
|
|
1658
|
-
);
|
|
1659
|
-
}
|
|
1660
|
-
break;
|
|
1661
|
-
case 'debtWithdrawalCap':
|
|
1662
|
-
if (
|
|
1663
|
-
reserve === undefined ||
|
|
1664
|
-
!reserve.config.debtWithdrawalCap.configCapacity.eq(reserveConfig.debtWithdrawalCap.configCapacity) ||
|
|
1665
|
-
!reserve.config.debtWithdrawalCap.configIntervalLengthSeconds.eq(
|
|
1666
|
-
reserveConfig.debtWithdrawalCap.configIntervalLengthSeconds
|
|
1667
|
-
)
|
|
1668
|
-
) {
|
|
1669
|
-
updateReserveIxsArgs.push(
|
|
1670
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator, [
|
|
1671
|
-
reserveConfig.debtWithdrawalCap.configCapacity.toNumber(),
|
|
1672
|
-
reserveConfig.debtWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1673
|
-
])
|
|
1674
|
-
);
|
|
1675
|
-
}
|
|
1676
|
-
break;
|
|
1677
|
-
case 'elevationGroups':
|
|
1678
|
-
if (
|
|
1679
|
-
reserve === undefined ||
|
|
1680
|
-
!sameLengthArrayEquals(reserve.config.elevationGroups, reserveConfig.elevationGroups)
|
|
1681
|
-
) {
|
|
1682
|
-
updateReserveIxsArgs.push(
|
|
1683
|
-
createUpdateReserveIxsArg(UpdateConfigMode.UpdateElevationGroup.discriminator, reserveConfig.elevationGroups)
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
break;
|
|
1687
|
-
case 'disableUsageAsCollOutsideEmode':
|
|
1688
|
-
if (
|
|
1689
|
-
reserve === undefined ||
|
|
1690
|
-
reserve.config.disableUsageAsCollOutsideEmode !== reserveConfig.disableUsageAsCollOutsideEmode
|
|
1691
|
-
) {
|
|
1692
|
-
updateReserveIxsArgs.push(
|
|
1693
|
-
createUpdateReserveIxsArg(
|
|
1694
|
-
UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator,
|
|
1695
|
-
reserveConfig.disableUsageAsCollOutsideEmode
|
|
1696
|
-
)
|
|
1697
|
-
);
|
|
1698
|
-
}
|
|
1699
|
-
break;
|
|
1700
|
-
case 'utilizationLimitBlockBorrowingAbovePct':
|
|
1701
|
-
if (
|
|
1702
|
-
reserve === undefined ||
|
|
1703
|
-
reserve.config.utilizationLimitBlockBorrowingAbovePct !== reserveConfig.utilizationLimitBlockBorrowingAbovePct
|
|
1704
|
-
) {
|
|
1705
|
-
updateReserveIxsArgs.push(
|
|
1706
|
-
createUpdateReserveIxsArg(
|
|
1707
|
-
UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator,
|
|
1708
|
-
reserveConfig.utilizationLimitBlockBorrowingAbovePct
|
|
1709
|
-
)
|
|
1710
|
-
);
|
|
1711
|
-
}
|
|
1712
|
-
break;
|
|
1713
|
-
case 'autodeleverageEnabled':
|
|
1714
|
-
if (reserve === undefined || reserve.config.autodeleverageEnabled !== reserveConfig.autodeleverageEnabled) {
|
|
1715
|
-
updateReserveIxsArgs.push(
|
|
1716
|
-
createUpdateReserveIxsArg(
|
|
1717
|
-
UpdateConfigMode.UpdateAutodeleverageEnabled.discriminator,
|
|
1718
|
-
reserveConfig.autodeleverageEnabled
|
|
1719
|
-
)
|
|
1720
|
-
);
|
|
1721
|
-
}
|
|
1722
|
-
break;
|
|
1723
|
-
case 'borrowLimitOutsideElevationGroup':
|
|
1724
|
-
if (
|
|
1725
|
-
reserve === undefined ||
|
|
1726
|
-
!reserve.config.borrowLimitOutsideElevationGroup.eq(reserveConfig.borrowLimitOutsideElevationGroup)
|
|
1727
|
-
) {
|
|
1728
|
-
updateReserveIxsArgs.push(
|
|
1729
|
-
createUpdateReserveIxsArg(
|
|
1730
|
-
UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator,
|
|
1731
|
-
BigInt(reserveConfig.borrowLimitOutsideElevationGroup.toString())
|
|
1732
|
-
)
|
|
1733
|
-
);
|
|
1734
|
-
}
|
|
1735
|
-
break;
|
|
1736
|
-
case 'borrowLimitAgainstThisCollateralInElevationGroup':
|
|
1737
|
-
if (
|
|
1738
|
-
reserve === undefined ||
|
|
1739
|
-
!sameLengthArrayEquals(
|
|
1740
|
-
reserve.config.borrowLimitAgainstThisCollateralInElevationGroup,
|
|
1741
|
-
reserveConfig.borrowLimitAgainstThisCollateralInElevationGroup
|
|
1742
|
-
)
|
|
1743
|
-
) {
|
|
1744
|
-
updateReserveIxsArgs.push(
|
|
1745
|
-
createUpdateReserveIxsArg(
|
|
1746
|
-
UpdateConfigMode.UpdateBorrowLimitsInElevationGroupAgainstThisReserve.discriminator,
|
|
1747
|
-
reserveConfig.borrowLimitAgainstThisCollateralInElevationGroup.map((borrowLimit) => borrowLimit.toNumber())
|
|
1748
|
-
)
|
|
1749
|
-
);
|
|
1750
|
-
}
|
|
1751
|
-
break;
|
|
1752
|
-
case 'deleveragingBonusIncreaseBpsPerDay':
|
|
1753
|
-
if (
|
|
1754
|
-
reserve === undefined ||
|
|
1755
|
-
!reserve.config.deleveragingBonusIncreaseBpsPerDay.eq(reserveConfig.deleveragingBonusIncreaseBpsPerDay)
|
|
1756
|
-
) {
|
|
1757
|
-
updateReserveIxsArgs.push(
|
|
1758
|
-
createUpdateReserveIxsArg(
|
|
1759
|
-
UpdateConfigMode.UpdateDeleveragingBonusIncreaseBpsPerDay.discriminator,
|
|
1760
|
-
reserveConfig.deleveragingBonusIncreaseBpsPerDay.toNumber()
|
|
1761
|
-
)
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1764
|
-
break;
|
|
1765
|
-
default:
|
|
1766
|
-
assertNever(key); // Will cause compile error if any case is missing
|
|
1767
|
-
}
|
|
1197
|
+
return updateReserveConfig(args, accounts, programId);
|
|
1768
1198
|
}
|
|
1769
1199
|
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1200
|
+
export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDecoded, ReserveConfig, (config) => ({
|
|
1201
|
+
[UpdateConfigMode.UpdateLoanToValuePct.kind]: config.loanToValuePct,
|
|
1202
|
+
[UpdateConfigMode.UpdateMaxLiquidationBonusBps.kind]: config.maxLiquidationBonusBps,
|
|
1203
|
+
[UpdateConfigMode.UpdateLiquidationThresholdPct.kind]: config.liquidationThresholdPct,
|
|
1204
|
+
[UpdateConfigMode.UpdateProtocolLiquidationFee.kind]: config.protocolLiquidationFeePct,
|
|
1205
|
+
[UpdateConfigMode.UpdateProtocolTakeRate.kind]: config.protocolTakeRatePct,
|
|
1206
|
+
[UpdateConfigMode.UpdateFeesBorrowFee.kind]: config.fees.borrowFeeSf,
|
|
1207
|
+
[UpdateConfigMode.UpdateFeesFlashLoanFee.kind]: config.fees.flashLoanFeeSf,
|
|
1208
|
+
[UpdateConfigMode.DeprecatedUpdateFeesReferralFeeBps.kind]: [], // deprecated
|
|
1209
|
+
[UpdateConfigMode.UpdateDepositLimit.kind]: config.depositLimit,
|
|
1210
|
+
[UpdateConfigMode.UpdateBorrowLimit.kind]: config.borrowLimit,
|
|
1211
|
+
[UpdateConfigMode.UpdateTokenInfoLowerHeuristic.kind]: config.tokenInfo.heuristic.lower,
|
|
1212
|
+
[UpdateConfigMode.UpdateTokenInfoUpperHeuristic.kind]: config.tokenInfo.heuristic.upper,
|
|
1213
|
+
[UpdateConfigMode.UpdateTokenInfoExpHeuristic.kind]: config.tokenInfo.heuristic.exp,
|
|
1214
|
+
[UpdateConfigMode.UpdateTokenInfoTwapDivergence.kind]: config.tokenInfo.maxTwapDivergenceBps,
|
|
1215
|
+
[UpdateConfigMode.UpdateTokenInfoScopeTwap.kind]: config.tokenInfo.scopeConfiguration.twapChain,
|
|
1216
|
+
[UpdateConfigMode.UpdateTokenInfoScopeChain.kind]: config.tokenInfo.scopeConfiguration.priceChain,
|
|
1217
|
+
[UpdateConfigMode.UpdateTokenInfoName.kind]: config.tokenInfo.name,
|
|
1218
|
+
[UpdateConfigMode.UpdateTokenInfoPriceMaxAge.kind]: config.tokenInfo.maxAgePriceSeconds,
|
|
1219
|
+
[UpdateConfigMode.UpdateTokenInfoTwapMaxAge.kind]: config.tokenInfo.maxAgeTwapSeconds,
|
|
1220
|
+
[UpdateConfigMode.UpdateScopePriceFeed.kind]: config.tokenInfo.scopeConfiguration.priceFeed,
|
|
1221
|
+
[UpdateConfigMode.UpdatePythPrice.kind]: config.tokenInfo.pythConfiguration.price,
|
|
1222
|
+
[UpdateConfigMode.UpdateSwitchboardFeed.kind]: config.tokenInfo.switchboardConfiguration.priceAggregator,
|
|
1223
|
+
[UpdateConfigMode.UpdateSwitchboardTwapFeed.kind]: config.tokenInfo.switchboardConfiguration.twapAggregator,
|
|
1224
|
+
[UpdateConfigMode.UpdateBorrowRateCurve.kind]: config.borrowRateCurve,
|
|
1225
|
+
[UpdateConfigMode.UpdateEntireReserveConfig.kind]: [], // technically `config` would be a valid thing here, but we actually do NOT want entire config update among ixs produced for field-by-field updates
|
|
1226
|
+
[UpdateConfigMode.UpdateDebtWithdrawalCap.kind]: new CompositeConfigItem(
|
|
1227
|
+
config.debtWithdrawalCap.configCapacity,
|
|
1228
|
+
config.debtWithdrawalCap.configIntervalLengthSeconds
|
|
1229
|
+
),
|
|
1230
|
+
[UpdateConfigMode.UpdateDepositWithdrawalCap.kind]: new CompositeConfigItem(
|
|
1231
|
+
config.depositWithdrawalCap.configCapacity,
|
|
1232
|
+
config.depositWithdrawalCap.configIntervalLengthSeconds
|
|
1233
|
+
),
|
|
1234
|
+
[UpdateConfigMode.DeprecatedUpdateDebtWithdrawalCapCurrentTotal.kind]: [], // deprecated
|
|
1235
|
+
[UpdateConfigMode.DeprecatedUpdateDepositWithdrawalCapCurrentTotal.kind]: [], // deprecated
|
|
1236
|
+
[UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.kind]: config.badDebtLiquidationBonusBps,
|
|
1237
|
+
[UpdateConfigMode.UpdateMinLiquidationBonusBps.kind]: config.minLiquidationBonusBps,
|
|
1238
|
+
[UpdateConfigMode.UpdateDeleveragingMarginCallPeriod.kind]: config.deleveragingMarginCallPeriodSecs,
|
|
1239
|
+
[UpdateConfigMode.UpdateBorrowFactor.kind]: config.borrowFactorPct,
|
|
1240
|
+
[UpdateConfigMode.UpdateAssetTier.kind]: config.assetTier,
|
|
1241
|
+
[UpdateConfigMode.UpdateElevationGroup.kind]: config.elevationGroups,
|
|
1242
|
+
[UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.kind]: config.deleveragingThresholdDecreaseBpsPerDay,
|
|
1243
|
+
[UpdateConfigMode.DeprecatedUpdateMultiplierSideBoost.kind]: [], // deprecated
|
|
1244
|
+
[UpdateConfigMode.DeprecatedUpdateMultiplierTagBoost.kind]: [], // deprecated
|
|
1245
|
+
[UpdateConfigMode.UpdateReserveStatus.kind]: config.status,
|
|
1246
|
+
[UpdateConfigMode.UpdateFarmCollateral.kind]: [], // the farm fields live on the `Reserve` level...
|
|
1247
|
+
[UpdateConfigMode.UpdateFarmDebt.kind]: [], // ...so we are not concerned with them in the `ReserveConfig`'s field-by-field update tx
|
|
1248
|
+
[UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.kind]: config.disableUsageAsCollOutsideEmode,
|
|
1249
|
+
[UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.kind]: config.utilizationLimitBlockBorrowingAbovePct,
|
|
1250
|
+
[UpdateConfigMode.UpdateBlockPriceUsage.kind]: config.tokenInfo.blockPriceUsage,
|
|
1251
|
+
[UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.kind]: config.borrowLimitOutsideElevationGroup,
|
|
1252
|
+
[UpdateConfigMode.UpdateBorrowLimitsInElevationGroupAgainstThisReserve.kind]:
|
|
1253
|
+
config.borrowLimitAgainstThisCollateralInElevationGroup,
|
|
1254
|
+
[UpdateConfigMode.UpdateHostFixedInterestRateBps.kind]: config.hostFixedInterestRateBps,
|
|
1255
|
+
[UpdateConfigMode.UpdateAutodeleverageEnabled.kind]: config.autodeleverageEnabled,
|
|
1256
|
+
[UpdateConfigMode.UpdateDeleveragingBonusIncreaseBpsPerDay.kind]: config.deleveragingBonusIncreaseBpsPerDay,
|
|
1257
|
+
[UpdateConfigMode.UpdateProtocolOrderExecutionFee.kind]: config.protocolOrderExecutionFeePct,
|
|
1258
|
+
}));
|
|
1781
1259
|
|
|
1782
1260
|
export function updateEntireReserveConfigIx(
|
|
1783
|
-
|
|
1261
|
+
signer: PublicKey,
|
|
1262
|
+
marketAddress: PublicKey,
|
|
1784
1263
|
reserveAddress: PublicKey,
|
|
1785
1264
|
reserveConfig: ReserveConfig,
|
|
1786
1265
|
programId: PublicKey
|
|
1787
1266
|
): TransactionInstruction {
|
|
1788
|
-
const layout = ReserveConfig.layout();
|
|
1789
|
-
const data = Buffer.alloc(1000);
|
|
1790
|
-
const len = layout.encode(reserveConfig.toEncodable(), data);
|
|
1791
|
-
const value = Uint8Array.from([...data.subarray(0, len)]);
|
|
1792
|
-
|
|
1793
1267
|
const args: UpdateReserveConfigArgs = {
|
|
1794
|
-
mode: new
|
|
1795
|
-
value:
|
|
1268
|
+
mode: new BN(UpdateConfigMode.UpdateEntireReserveConfig.discriminator + 1),
|
|
1269
|
+
value: encodeUsingLayout(ReserveConfig.layout(), reserveConfig),
|
|
1796
1270
|
skipValidation: false,
|
|
1797
1271
|
};
|
|
1798
1272
|
|
|
1799
1273
|
const accounts: UpdateReserveConfigAccounts = {
|
|
1800
|
-
lendingMarketOwner:
|
|
1801
|
-
lendingMarket:
|
|
1274
|
+
lendingMarketOwner: signer,
|
|
1275
|
+
lendingMarket: marketAddress,
|
|
1802
1276
|
reserve: reserveAddress,
|
|
1803
1277
|
};
|
|
1804
1278
|
|
|
@@ -1814,155 +1288,19 @@ export function parseForChangesReserveConfigAndGetIxs(
|
|
|
1814
1288
|
reserveConfig: ReserveConfig,
|
|
1815
1289
|
programId: PublicKey
|
|
1816
1290
|
) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
let skipValidation = false;
|
|
1831
|
-
if (modeMatches(updateReserveConfigArgs.mode) && !reserve?.liquidity.availableAmount.gten(MIN_INITIAL_DEPOSIT)) {
|
|
1832
|
-
skipValidation = true;
|
|
1833
|
-
}
|
|
1834
|
-
ixs.push(
|
|
1835
|
-
updateReserveConfigIx(
|
|
1836
|
-
marketWithAddress,
|
|
1837
|
-
reserveAddress,
|
|
1838
|
-
updateReserveConfigArgs.mode,
|
|
1839
|
-
updateReserveConfigArgs.value,
|
|
1840
|
-
programId,
|
|
1841
|
-
skipValidation
|
|
1842
|
-
)
|
|
1843
|
-
);
|
|
1844
|
-
});
|
|
1845
|
-
|
|
1846
|
-
return ixs;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
export function updateReserveConfigEncodedValue(
|
|
1850
|
-
discriminator: UpdateConfigModeKind['discriminator'],
|
|
1851
|
-
value: number | number[] | bigint | BorrowRateCurve | PublicKey
|
|
1852
|
-
): Uint8Array {
|
|
1853
|
-
let buffer: Buffer;
|
|
1854
|
-
let valueArray: number[] = [];
|
|
1855
|
-
|
|
1856
|
-
switch (discriminator) {
|
|
1857
|
-
case UpdateConfigMode.UpdateLoanToValuePct.discriminator:
|
|
1858
|
-
case UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator:
|
|
1859
|
-
case UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator:
|
|
1860
|
-
case UpdateConfigMode.UpdateProtocolTakeRate.discriminator:
|
|
1861
|
-
case UpdateConfigMode.UpdateAssetTier.discriminator:
|
|
1862
|
-
case UpdateConfigMode.UpdateReserveStatus.discriminator:
|
|
1863
|
-
case UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator:
|
|
1864
|
-
case UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.discriminator:
|
|
1865
|
-
case UpdateConfigMode.UpdateBlockPriceUsage.discriminator:
|
|
1866
|
-
case UpdateConfigMode.UpdateAutodeleverageEnabled.discriminator:
|
|
1867
|
-
buffer = Buffer.alloc(1);
|
|
1868
|
-
buffer.writeUIntLE(value as number, 0, 1);
|
|
1869
|
-
break;
|
|
1870
|
-
case UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator:
|
|
1871
|
-
case UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator:
|
|
1872
|
-
case UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator:
|
|
1873
|
-
buffer = Buffer.alloc(2);
|
|
1874
|
-
buffer.writeUInt16LE(value as number, 0);
|
|
1875
|
-
break;
|
|
1876
|
-
case UpdateConfigMode.UpdateFeesBorrowFee.discriminator:
|
|
1877
|
-
case UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator:
|
|
1878
|
-
case UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator:
|
|
1879
|
-
case UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator:
|
|
1880
|
-
case UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator:
|
|
1881
|
-
case UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator:
|
|
1882
|
-
case UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator:
|
|
1883
|
-
case UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator:
|
|
1884
|
-
case UpdateConfigMode.UpdateDeleveragingMarginCallPeriod.discriminator:
|
|
1885
|
-
case UpdateConfigMode.UpdateBorrowFactor.discriminator:
|
|
1886
|
-
case UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.discriminator:
|
|
1887
|
-
case UpdateConfigMode.UpdateDeleveragingBonusIncreaseBpsPerDay.discriminator:
|
|
1888
|
-
value = value as number;
|
|
1889
|
-
buffer = Buffer.alloc(8);
|
|
1890
|
-
buffer.writeBigUint64LE(BigInt(value), 0);
|
|
1891
|
-
break;
|
|
1892
|
-
case UpdateConfigMode.UpdateDepositLimit.discriminator:
|
|
1893
|
-
case UpdateConfigMode.UpdateBorrowLimit.discriminator:
|
|
1894
|
-
case UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator:
|
|
1895
|
-
buffer = Buffer.alloc(8);
|
|
1896
|
-
// Convert value to BigInt if it's not already
|
|
1897
|
-
const bigIntValue = typeof value === 'bigint' ? value : BigInt(value.toString());
|
|
1898
|
-
// Split into two 32-bit values
|
|
1899
|
-
const low = Number(bigIntValue & BigInt(0xffffffff));
|
|
1900
|
-
const high = Number(bigIntValue >> BigInt(32));
|
|
1901
|
-
buffer.writeUInt32LE(low, 0);
|
|
1902
|
-
buffer.writeUInt32LE(high, 4);
|
|
1903
|
-
break;
|
|
1904
|
-
case UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator:
|
|
1905
|
-
case UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator:
|
|
1906
|
-
valueArray = value as number[];
|
|
1907
|
-
buffer = Buffer.alloc(8);
|
|
1908
|
-
for (let i = 0; i < valueArray.length; i++) {
|
|
1909
|
-
buffer.writeUInt16LE(valueArray[i], 2 * i);
|
|
1910
|
-
}
|
|
1911
|
-
break;
|
|
1912
|
-
case UpdateConfigMode.UpdateTokenInfoName.discriminator:
|
|
1913
|
-
valueArray = value as number[];
|
|
1914
|
-
buffer = Buffer.alloc(32);
|
|
1915
|
-
for (let i = 0; i < valueArray.length; i++) {
|
|
1916
|
-
buffer.writeUIntLE(valueArray[i], i, 1);
|
|
1917
|
-
}
|
|
1918
|
-
break;
|
|
1919
|
-
case UpdateConfigMode.UpdateScopePriceFeed.discriminator:
|
|
1920
|
-
case UpdateConfigMode.UpdatePythPrice.discriminator:
|
|
1921
|
-
case UpdateConfigMode.UpdateSwitchboardFeed.discriminator:
|
|
1922
|
-
case UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator:
|
|
1923
|
-
case UpdateConfigMode.UpdateFarmCollateral.discriminator:
|
|
1924
|
-
case UpdateConfigMode.UpdateFarmDebt.discriminator:
|
|
1925
|
-
buffer = (value as PublicKey).toBuffer();
|
|
1926
|
-
break;
|
|
1927
|
-
case UpdateConfigMode.UpdateBorrowRateCurve.discriminator:
|
|
1928
|
-
buffer = serializeBorrowRateCurve(value as BorrowRateCurve);
|
|
1929
|
-
break;
|
|
1930
|
-
case UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator:
|
|
1931
|
-
case UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator:
|
|
1932
|
-
valueArray = value as number[];
|
|
1933
|
-
buffer = Buffer.alloc(16);
|
|
1934
|
-
buffer.writeBigUint64LE(BigInt(valueArray[0]), 0);
|
|
1935
|
-
buffer.writeBigUInt64LE(BigInt(valueArray[1]), 8);
|
|
1936
|
-
break;
|
|
1937
|
-
case UpdateConfigMode.UpdateElevationGroup.discriminator:
|
|
1938
|
-
valueArray = value as number[];
|
|
1939
|
-
buffer = Buffer.alloc(20);
|
|
1940
|
-
for (let i = 0; i < valueArray.length; i++) {
|
|
1941
|
-
buffer.writeUIntLE(valueArray[i], i, 1);
|
|
1942
|
-
}
|
|
1943
|
-
break;
|
|
1944
|
-
case UpdateConfigMode.UpdateBorrowLimitsInElevationGroupAgainstThisReserve.discriminator:
|
|
1945
|
-
valueArray = value as number[];
|
|
1946
|
-
buffer = Buffer.alloc(32 * 8);
|
|
1947
|
-
for (let i = 0; i < valueArray.length; i++) {
|
|
1948
|
-
buffer.writeBigUint64LE(BigInt(valueArray[i]), i * 8);
|
|
1949
|
-
}
|
|
1950
|
-
break;
|
|
1951
|
-
default:
|
|
1952
|
-
buffer = Buffer.alloc(0);
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
return Uint8Array.from([...buffer]);
|
|
1956
|
-
}
|
|
1957
|
-
|
|
1958
|
-
export function serializeBorrowRateCurve(curve: BorrowRateCurve): Buffer {
|
|
1959
|
-
const buffer = Buffer.alloc(8 * curve.points.length);
|
|
1960
|
-
buffer.writeUInt32LE(curve.points.length, 0);
|
|
1961
|
-
for (let i = 0; i < curve.points.length; i++) {
|
|
1962
|
-
buffer.writeUInt32LE(curve.points[i].utilizationRateBps, 8 * i);
|
|
1963
|
-
buffer.writeUInt32LE(curve.points[i].borrowRateBps, 4 + 8 * i);
|
|
1964
|
-
}
|
|
1965
|
-
return buffer;
|
|
1291
|
+
const encodedConfigUpdates = RESERVE_CONFIG_UPDATER.encodeAllUpdates(reserve?.config, reserveConfig);
|
|
1292
|
+
encodedConfigUpdates.sort((left, right) => priorityOf(left.mode) - priorityOf(right.mode));
|
|
1293
|
+
return encodedConfigUpdates.map((encodedConfigUpdate) =>
|
|
1294
|
+
updateReserveConfigIx(
|
|
1295
|
+
marketWithAddress.state.lendingMarketOwner,
|
|
1296
|
+
marketWithAddress.address,
|
|
1297
|
+
reserveAddress,
|
|
1298
|
+
encodedConfigUpdate.mode,
|
|
1299
|
+
encodedConfigUpdate.value,
|
|
1300
|
+
programId,
|
|
1301
|
+
shouldSkipValidation(encodedConfigUpdate.mode, reserve)
|
|
1302
|
+
)
|
|
1303
|
+
);
|
|
1966
1304
|
}
|
|
1967
1305
|
|
|
1968
1306
|
export type ReserveWithAddress = {
|
|
@@ -1970,36 +1308,30 @@ export type ReserveWithAddress = {
|
|
|
1970
1308
|
state: Reserve;
|
|
1971
1309
|
};
|
|
1972
1310
|
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
};
|
|
1311
|
+
const NON_VALIDATED_DISCRIMINATORS = [
|
|
1312
|
+
UpdateConfigMode.UpdateScopePriceFeed.discriminator,
|
|
1313
|
+
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1314
|
+
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1315
|
+
UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1316
|
+
UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1317
|
+
UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1318
|
+
UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1319
|
+
];
|
|
1320
|
+
|
|
1321
|
+
function shouldSkipValidation(mode: UpdateConfigModeKind, reserve: Reserve | undefined): boolean {
|
|
1322
|
+
return (
|
|
1323
|
+
NON_VALIDATED_DISCRIMINATORS.includes(mode.discriminator) &&
|
|
1324
|
+
!reserve?.liquidity.availableAmount.gten(MIN_INITIAL_DEPOSIT)
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1990
1327
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
return -1;
|
|
1999
|
-
}
|
|
2000
|
-
if (isPriorityB && !isPriorityA) {
|
|
1328
|
+
function priorityOf(mode: UpdateConfigModeKind): number {
|
|
1329
|
+
switch (mode.discriminator) {
|
|
1330
|
+
case UpdateConfigMode.UpdateScopePriceFeed.discriminator:
|
|
1331
|
+
return 0;
|
|
1332
|
+
case UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator:
|
|
1333
|
+
return 0;
|
|
1334
|
+
default:
|
|
2001
1335
|
return 1;
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
});
|
|
2005
|
-
};
|
|
1336
|
+
}
|
|
1337
|
+
}
|