@kamino-finance/klend-sdk 5.0.1 → 5.0.3
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/fraction.d.ts.map +1 -1
- package/dist/classes/fraction.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +14 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +4 -0
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +15 -0
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +22 -27
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +3 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +30 -0
- package/dist/classes/utils.js.map +1 -1
- package/dist/client_kamino_manager.js +1 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +27 -2
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +6 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +8 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +3 -12
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +1 -4
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +20 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +33 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +4 -4
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +5 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +5 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/pubkey.d.ts.map +1 -1
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/rpc.d.ts.map +1 -1
- package/dist/utils/rpc.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/fraction.ts +5 -0
- package/src/classes/manager.ts +14 -1
- package/src/classes/market.ts +18 -1
- package/src/classes/reserve.ts +55 -39
- package/src/classes/utils.ts +30 -0
- package/src/client_kamino_manager.ts +1 -1
- package/src/idl_codegen/accounts/LendingMarket.ts +12 -1
- package/src/idl_codegen/accounts/Obligation.ts +3 -12
- package/src/idl_codegen/types/UpdateLendingMarketConfigValue.ts +43 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +4 -0
- package/src/lending_operations/repay_with_collateral_calcs.ts +5 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +5 -1
- package/src/utils/ObligationType.ts +6 -0
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/pubkey.ts +2 -0
- package/src/utils/rpc.ts +1 -0
package/src/classes/utils.ts
CHANGED
|
@@ -142,6 +142,29 @@ export const parseTokenSymbol = (tokenSymbol: number[]): string => {
|
|
|
142
142
|
return String.fromCharCode(...tokenSymbol.filter((x) => x > 0));
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
export function parseZeroPaddedUtf8(utf8Array: number[]): string {
|
|
146
|
+
for (let last = utf8Array.length - 1; last >= 0; last--) {
|
|
147
|
+
const trailing_zero = utf8Array[last];
|
|
148
|
+
if (trailing_zero != 0) {
|
|
149
|
+
const encoding = new Uint8Array(last + 1);
|
|
150
|
+
for (let i = 0; i <= last; i++) {
|
|
151
|
+
encoding[i] = utf8Array[i];
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return new TextDecoder().decode();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function renderZeroPaddedUtf8(str: string, utf8ArrayLength: number): number[] {
|
|
160
|
+
const encoding = new TextEncoder().encode(str);
|
|
161
|
+
const result = new Array<number>(utf8ArrayLength);
|
|
162
|
+
for (let i = 0; i < result.length; i++) {
|
|
163
|
+
result[i] = i < encoding.length ? encoding[i] : 0;
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
145
168
|
export function sleep(ms: number) {
|
|
146
169
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
147
170
|
}
|
|
@@ -190,3 +213,10 @@ export function calculateAPRFromAPY(apy: Decimal.Value) {
|
|
|
190
213
|
.minus(1)
|
|
191
214
|
.times(SLOTS_PER_YEAR);
|
|
192
215
|
}
|
|
216
|
+
|
|
217
|
+
export function sameLengthArrayEquals(left: Array<number>, right: Array<number>): boolean {
|
|
218
|
+
if (left.length != right.length) {
|
|
219
|
+
throw new Error(`Not same length: ${left.length} != ${left.length}`);
|
|
220
|
+
}
|
|
221
|
+
return left.every((value, index) => value === right[index]);
|
|
222
|
+
}
|
|
@@ -87,7 +87,7 @@ async function main() {
|
|
|
87
87
|
|
|
88
88
|
commands
|
|
89
89
|
.command('add-asset-to-market')
|
|
90
|
-
.requiredOption('--market <string>', 'Market
|
|
90
|
+
.requiredOption('--market <string>', 'Market address to add asset to')
|
|
91
91
|
.requiredOption('--mint <string>', 'Reserve liquidity token mint')
|
|
92
92
|
.requiredOption('--mint-program-id <string>', 'Reserve liquidity token mint program id')
|
|
93
93
|
.requiredOption('--reserve-config-path <string>', 'Path for the reserve config')
|
|
@@ -51,6 +51,8 @@ export interface LendingMarketFields {
|
|
|
51
51
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
52
52
|
minNetValueInObligationSf: BN
|
|
53
53
|
minValueSkipLiquidationLtvBfChecks: BN
|
|
54
|
+
/** Market name, zero-padded. */
|
|
55
|
+
name: Array<number>
|
|
54
56
|
padding1: Array<BN>
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -101,6 +103,8 @@ export interface LendingMarketJSON {
|
|
|
101
103
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
102
104
|
minNetValueInObligationSf: string
|
|
103
105
|
minValueSkipLiquidationLtvBfChecks: string
|
|
106
|
+
/** Market name, zero-padded. */
|
|
107
|
+
name: Array<number>
|
|
104
108
|
padding1: Array<string>
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -151,6 +155,8 @@ export class LendingMarket {
|
|
|
151
155
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
152
156
|
readonly minNetValueInObligationSf: BN
|
|
153
157
|
readonly minValueSkipLiquidationLtvBfChecks: BN
|
|
158
|
+
/** Market name, zero-padded. */
|
|
159
|
+
readonly name: Array<number>
|
|
154
160
|
readonly padding1: Array<BN>
|
|
155
161
|
|
|
156
162
|
static readonly discriminator = Buffer.from([
|
|
@@ -180,7 +186,8 @@ export class LendingMarket {
|
|
|
180
186
|
borsh.array(borsh.u64(), 90, "elevationGroupPadding"),
|
|
181
187
|
borsh.u128("minNetValueInObligationSf"),
|
|
182
188
|
borsh.u64("minValueSkipLiquidationLtvBfChecks"),
|
|
183
|
-
borsh.array(borsh.
|
|
189
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
190
|
+
borsh.array(borsh.u64(), 173, "padding1"),
|
|
184
191
|
])
|
|
185
192
|
|
|
186
193
|
constructor(fields: LendingMarketFields) {
|
|
@@ -212,6 +219,7 @@ export class LendingMarket {
|
|
|
212
219
|
this.minNetValueInObligationSf = fields.minNetValueInObligationSf
|
|
213
220
|
this.minValueSkipLiquidationLtvBfChecks =
|
|
214
221
|
fields.minValueSkipLiquidationLtvBfChecks
|
|
222
|
+
this.name = fields.name
|
|
215
223
|
this.padding1 = fields.padding1
|
|
216
224
|
}
|
|
217
225
|
|
|
@@ -287,6 +295,7 @@ export class LendingMarket {
|
|
|
287
295
|
minNetValueInObligationSf: dec.minNetValueInObligationSf,
|
|
288
296
|
minValueSkipLiquidationLtvBfChecks:
|
|
289
297
|
dec.minValueSkipLiquidationLtvBfChecks,
|
|
298
|
+
name: dec.name,
|
|
290
299
|
padding1: dec.padding1,
|
|
291
300
|
})
|
|
292
301
|
}
|
|
@@ -320,6 +329,7 @@ export class LendingMarket {
|
|
|
320
329
|
minNetValueInObligationSf: this.minNetValueInObligationSf.toString(),
|
|
321
330
|
minValueSkipLiquidationLtvBfChecks:
|
|
322
331
|
this.minValueSkipLiquidationLtvBfChecks.toString(),
|
|
332
|
+
name: this.name,
|
|
323
333
|
padding1: this.padding1.map((item) => item.toString()),
|
|
324
334
|
}
|
|
325
335
|
}
|
|
@@ -358,6 +368,7 @@ export class LendingMarket {
|
|
|
358
368
|
minValueSkipLiquidationLtvBfChecks: new BN(
|
|
359
369
|
obj.minValueSkipLiquidationLtvBfChecks
|
|
360
370
|
),
|
|
371
|
+
name: obj.name,
|
|
361
372
|
padding1: obj.padding1.map((item) => new BN(item)),
|
|
362
373
|
})
|
|
363
374
|
}
|
|
@@ -13,10 +13,7 @@ export interface ObligationFields {
|
|
|
13
13
|
lendingMarket: PublicKey
|
|
14
14
|
/** Owner authority which can borrow liquidity */
|
|
15
15
|
owner: PublicKey
|
|
16
|
-
/**
|
|
17
|
-
* TODO: Does this break the stack size when copied onto the stack, if too big?
|
|
18
|
-
* Deposited collateral for the obligation, unique by deposit reserve address
|
|
19
|
-
*/
|
|
16
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
20
17
|
deposits: Array<types.ObligationCollateralFields>
|
|
21
18
|
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
22
19
|
lowestReserveDepositLiquidationLtv: BN
|
|
@@ -60,10 +57,7 @@ export interface ObligationJSON {
|
|
|
60
57
|
lendingMarket: string
|
|
61
58
|
/** Owner authority which can borrow liquidity */
|
|
62
59
|
owner: string
|
|
63
|
-
/**
|
|
64
|
-
* TODO: Does this break the stack size when copied onto the stack, if too big?
|
|
65
|
-
* Deposited collateral for the obligation, unique by deposit reserve address
|
|
66
|
-
*/
|
|
60
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
67
61
|
deposits: Array<types.ObligationCollateralJSON>
|
|
68
62
|
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
69
63
|
lowestReserveDepositLiquidationLtv: string
|
|
@@ -108,10 +102,7 @@ export class Obligation {
|
|
|
108
102
|
readonly lendingMarket: PublicKey
|
|
109
103
|
/** Owner authority which can borrow liquidity */
|
|
110
104
|
readonly owner: PublicKey
|
|
111
|
-
/**
|
|
112
|
-
* TODO: Does this break the stack size when copied onto the stack, if too big?
|
|
113
|
-
* Deposited collateral for the obligation, unique by deposit reserve address
|
|
114
|
-
*/
|
|
105
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
115
106
|
readonly deposits: Array<types.ObligationCollateral>
|
|
116
107
|
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
117
108
|
readonly lowestReserveDepositLiquidationLtv: BN
|
|
@@ -283,6 +283,41 @@ export class ElevationGroup {
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
export type NameFields = [Array<number>]
|
|
287
|
+
export type NameValue = [Array<number>]
|
|
288
|
+
|
|
289
|
+
export interface NameJSON {
|
|
290
|
+
kind: "Name"
|
|
291
|
+
value: [Array<number>]
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export class Name {
|
|
295
|
+
static readonly discriminator = 8
|
|
296
|
+
static readonly kind = "Name"
|
|
297
|
+
readonly discriminator = 8
|
|
298
|
+
readonly kind = "Name"
|
|
299
|
+
readonly value: NameValue
|
|
300
|
+
|
|
301
|
+
constructor(value: NameFields) {
|
|
302
|
+
this.value = [value[0]]
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
toJSON(): NameJSON {
|
|
306
|
+
return {
|
|
307
|
+
kind: "Name",
|
|
308
|
+
value: [this.value[0]],
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
toEncodable() {
|
|
313
|
+
return {
|
|
314
|
+
Name: {
|
|
315
|
+
_0: this.value[0],
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
286
321
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
287
322
|
export function fromDecoded(
|
|
288
323
|
obj: any
|
|
@@ -323,6 +358,10 @@ export function fromDecoded(
|
|
|
323
358
|
const val = obj["ElevationGroup"]
|
|
324
359
|
return new ElevationGroup([types.ElevationGroup.fromDecoded(val["_0"])])
|
|
325
360
|
}
|
|
361
|
+
if ("Name" in obj) {
|
|
362
|
+
const val = obj["Name"]
|
|
363
|
+
return new Name([val["_0"]])
|
|
364
|
+
}
|
|
326
365
|
|
|
327
366
|
throw new Error("Invalid enum object")
|
|
328
367
|
}
|
|
@@ -355,6 +394,9 @@ export function fromJSON(
|
|
|
355
394
|
case "ElevationGroup": {
|
|
356
395
|
return new ElevationGroup([types.ElevationGroup.fromJSON(obj.value[0])])
|
|
357
396
|
}
|
|
397
|
+
case "Name": {
|
|
398
|
+
return new Name([obj.value[0]])
|
|
399
|
+
}
|
|
358
400
|
}
|
|
359
401
|
}
|
|
360
402
|
|
|
@@ -368,6 +410,7 @@ export function layout(property?: string) {
|
|
|
368
410
|
borsh.struct([borsh.u128("_0")], "U128"),
|
|
369
411
|
borsh.struct([borsh.publicKey("_0")], "Pubkey"),
|
|
370
412
|
borsh.struct([types.ElevationGroup.layout("_0")], "ElevationGroup"),
|
|
413
|
+
borsh.struct([borsh.array(borsh.u8(), 32, "_0")], "Name"),
|
|
371
414
|
])
|
|
372
415
|
if (property !== undefined) {
|
|
373
416
|
return ret.replicate(property)
|
|
@@ -417,6 +417,29 @@ export class UpdatePaddingFields {
|
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
export interface UpdateNameJSON {
|
|
421
|
+
kind: "UpdateName"
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export class UpdateName {
|
|
425
|
+
static readonly discriminator = 18
|
|
426
|
+
static readonly kind = "UpdateName"
|
|
427
|
+
readonly discriminator = 18
|
|
428
|
+
readonly kind = "UpdateName"
|
|
429
|
+
|
|
430
|
+
toJSON(): UpdateNameJSON {
|
|
431
|
+
return {
|
|
432
|
+
kind: "UpdateName",
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
toEncodable() {
|
|
437
|
+
return {
|
|
438
|
+
UpdateName: {},
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
420
443
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
421
444
|
export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
|
|
422
445
|
if (typeof obj !== "object") {
|
|
@@ -477,6 +500,9 @@ export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
|
|
|
477
500
|
if ("UpdatePaddingFields" in obj) {
|
|
478
501
|
return new UpdatePaddingFields()
|
|
479
502
|
}
|
|
503
|
+
if ("UpdateName" in obj) {
|
|
504
|
+
return new UpdateName()
|
|
505
|
+
}
|
|
480
506
|
|
|
481
507
|
throw new Error("Invalid enum object")
|
|
482
508
|
}
|
|
@@ -539,6 +565,9 @@ export function fromJSON(
|
|
|
539
565
|
case "UpdatePaddingFields": {
|
|
540
566
|
return new UpdatePaddingFields()
|
|
541
567
|
}
|
|
568
|
+
case "UpdateName": {
|
|
569
|
+
return new UpdateName()
|
|
570
|
+
}
|
|
542
571
|
}
|
|
543
572
|
}
|
|
544
573
|
|
|
@@ -562,6 +591,7 @@ export function layout(property?: string) {
|
|
|
562
591
|
borsh.struct([], "UpdateMinNetValueObligationPostAction"),
|
|
563
592
|
borsh.struct([], "UpdateMinValueSkipPriorityLiqCheck"),
|
|
564
593
|
borsh.struct([], "UpdatePaddingFields"),
|
|
594
|
+
borsh.struct([], "UpdateName"),
|
|
565
595
|
])
|
|
566
596
|
if (property !== undefined) {
|
|
567
597
|
return ret.replicate(property)
|
|
@@ -116,6 +116,7 @@ export type UpdateLendingMarketConfigValueKind =
|
|
|
116
116
|
| UpdateLendingMarketConfigValue.U128
|
|
117
117
|
| UpdateLendingMarketConfigValue.Pubkey
|
|
118
118
|
| UpdateLendingMarketConfigValue.ElevationGroup
|
|
119
|
+
| UpdateLendingMarketConfigValue.Name
|
|
119
120
|
export type UpdateLendingMarketConfigValueJSON =
|
|
120
121
|
| UpdateLendingMarketConfigValue.BoolJSON
|
|
121
122
|
| UpdateLendingMarketConfigValue.U8JSON
|
|
@@ -125,6 +126,7 @@ export type UpdateLendingMarketConfigValueJSON =
|
|
|
125
126
|
| UpdateLendingMarketConfigValue.U128JSON
|
|
126
127
|
| UpdateLendingMarketConfigValue.PubkeyJSON
|
|
127
128
|
| UpdateLendingMarketConfigValue.ElevationGroupJSON
|
|
129
|
+
| UpdateLendingMarketConfigValue.NameJSON
|
|
128
130
|
|
|
129
131
|
export { UpdateLendingMarketMode }
|
|
130
132
|
|
|
@@ -147,6 +149,7 @@ export type UpdateLendingMarketModeKind =
|
|
|
147
149
|
| UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction
|
|
148
150
|
| UpdateLendingMarketMode.UpdateMinValueSkipPriorityLiqCheck
|
|
149
151
|
| UpdateLendingMarketMode.UpdatePaddingFields
|
|
152
|
+
| UpdateLendingMarketMode.UpdateName
|
|
150
153
|
export type UpdateLendingMarketModeJSON =
|
|
151
154
|
| UpdateLendingMarketMode.UpdateOwnerJSON
|
|
152
155
|
| UpdateLendingMarketMode.UpdateEmergencyModeJSON
|
|
@@ -166,6 +169,7 @@ export type UpdateLendingMarketModeJSON =
|
|
|
166
169
|
| UpdateLendingMarketMode.UpdateMinNetValueObligationPostActionJSON
|
|
167
170
|
| UpdateLendingMarketMode.UpdateMinValueSkipPriorityLiqCheckJSON
|
|
168
171
|
| UpdateLendingMarketMode.UpdatePaddingFieldsJSON
|
|
172
|
+
| UpdateLendingMarketMode.UpdateNameJSON
|
|
169
173
|
|
|
170
174
|
export { LastUpdate } from "./LastUpdate"
|
|
171
175
|
export type { LastUpdateFields, LastUpdateJSON } from "./LastUpdate"
|
|
@@ -77,7 +77,11 @@ export function calcMaxWithdrawCollateral(
|
|
|
77
77
|
const collPosition = obligation.getDepositByReserve(collReserve.address)!;
|
|
78
78
|
const initialCollValue = collPosition.amount.floor().div(collReserve.getMintFactor()).mul(collOraclePx);
|
|
79
79
|
const remainingDebtAmountLamports = debtPosition.amount.sub(repayAmountLamports);
|
|
80
|
-
const remainingDebtBfWeightedValue = remainingDebtAmountLamports
|
|
80
|
+
const remainingDebtBfWeightedValue = remainingDebtAmountLamports
|
|
81
|
+
.ceil()
|
|
82
|
+
.div(debtReserve.getMintFactor())
|
|
83
|
+
.mul(debtBorrowFactor)
|
|
84
|
+
.mul(debtOraclePx);
|
|
81
85
|
|
|
82
86
|
let isClosingPosition = false;
|
|
83
87
|
if (remainingDebtAmountLamports.lte(new Decimal(0)) && obligation.getBorrows().length === 1) {
|
|
@@ -132,7 +132,11 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
132
132
|
const swapQuote = await quoter(swapQuoteInputs, uniqueKlendAccounts);
|
|
133
133
|
|
|
134
134
|
const swapQuotePxDebtToColl = swapQuote.priceAInB;
|
|
135
|
-
const collSwapInLamports = flashRepayAmountLamports
|
|
135
|
+
const collSwapInLamports = flashRepayAmountLamports
|
|
136
|
+
.div(debtReserve.getMintFactor())
|
|
137
|
+
.div(swapQuotePxDebtToColl)
|
|
138
|
+
.mul(collReserve.getMintFactor())
|
|
139
|
+
.ceil();
|
|
136
140
|
|
|
137
141
|
return {
|
|
138
142
|
swapInputs: {
|
|
@@ -24,6 +24,7 @@ export class VanillaObligation {
|
|
|
24
24
|
constructor(programId: PublicKey) {
|
|
25
25
|
this.programId = programId;
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
toArgs() {
|
|
28
29
|
const initObligationArgs: InitObligationArgsModel = {
|
|
29
30
|
tag: VanillaObligation.tag,
|
|
@@ -34,6 +35,7 @@ export class VanillaObligation {
|
|
|
34
35
|
|
|
35
36
|
return initObligationArgs;
|
|
36
37
|
}
|
|
38
|
+
|
|
37
39
|
toPda(market: PublicKey, user: PublicKey) {
|
|
38
40
|
return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
|
|
39
41
|
}
|
|
@@ -61,6 +63,7 @@ export class MultiplyObligation {
|
|
|
61
63
|
|
|
62
64
|
return initObligationArgs;
|
|
63
65
|
}
|
|
66
|
+
|
|
64
67
|
toPda(market: PublicKey, user: PublicKey) {
|
|
65
68
|
return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
|
|
66
69
|
}
|
|
@@ -88,6 +91,7 @@ export class LeverageObligation {
|
|
|
88
91
|
|
|
89
92
|
return initObligationArgs;
|
|
90
93
|
}
|
|
94
|
+
|
|
91
95
|
toPda(market: PublicKey, user: PublicKey) {
|
|
92
96
|
return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
|
|
93
97
|
}
|
|
@@ -102,6 +106,7 @@ export class LendingObligation {
|
|
|
102
106
|
this.token = token;
|
|
103
107
|
this.programId = programId;
|
|
104
108
|
}
|
|
109
|
+
|
|
105
110
|
toArgs() {
|
|
106
111
|
const initObligationArgs: InitObligationArgsModel = {
|
|
107
112
|
tag: LendingObligation.tag,
|
|
@@ -112,6 +117,7 @@ export class LendingObligation {
|
|
|
112
117
|
|
|
113
118
|
return initObligationArgs;
|
|
114
119
|
}
|
|
120
|
+
|
|
115
121
|
toPda(market: PublicKey, user: PublicKey) {
|
|
116
122
|
return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
|
|
117
123
|
}
|
package/src/utils/pubkey.ts
CHANGED
|
@@ -239,6 +239,7 @@ export class PubkeyHashMap<K extends PublicKey, V> implements Map<K, V> {
|
|
|
239
239
|
export class HashablePublicKey extends PublicKey implements IEquality<HashablePublicKey> {
|
|
240
240
|
// We only use the last 32 bits of the public key for hashing
|
|
241
241
|
static MASK = new BN(1).shln(32).subn(1);
|
|
242
|
+
|
|
242
243
|
constructor(value: PublicKey | string | Buffer | Uint8Array | Array<number>) {
|
|
243
244
|
super(value);
|
|
244
245
|
}
|
|
@@ -257,5 +258,6 @@ export class HashablePublicKey extends PublicKey implements IEquality<HashablePu
|
|
|
257
258
|
|
|
258
259
|
interface IEquality<T extends IEquality<T>> {
|
|
259
260
|
equals(other: T): boolean;
|
|
261
|
+
|
|
260
262
|
hashCode(): number;
|
|
261
263
|
}
|