@haven-fi/solauto-sdk 1.0.71 → 1.0.73
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts +2 -0
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +29 -16
- package/dist/constants/solautoConstants.d.ts +3 -2
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +4 -3
- package/dist/generated/errors/solauto.d.ts +2 -2
- package/dist/generated/errors/solauto.d.ts.map +1 -1
- package/dist/generated/errors/solauto.js +7 -7
- package/dist/marginfi-sdk/types/oracleSetup.d.ts +3 -2
- package/dist/marginfi-sdk/types/oracleSetup.d.ts.map +1 -1
- package/dist/marginfi-sdk/types/oracleSetup.js +2 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts +1 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts.map +1 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.js +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +3 -3
- package/dist/utils/numberUtils.js +3 -3
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +38 -18
- package/src/constants/solautoConstants.ts +4 -2
- package/src/generated/errors/solauto.ts +5 -5
- package/src/marginfi-sdk/types/oracleSetup.ts +2 -1
- package/src/marginfi-sdk/types/wrappedI80F48.ts +8 -3
- package/src/utils/marginfiUtils.ts +4 -3
- package/src/utils/numberUtils.ts +4 -4
- package/tests/transactions/solautoMarginfi.ts +2 -2
@@ -20,6 +20,8 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
20
20
|
marginfiGroup: PublicKey;
|
21
21
|
marginfiSupplyAccounts: MarginfiAssetAccounts;
|
22
22
|
marginfiDebtAccounts: MarginfiAssetAccounts;
|
23
|
+
supplyPriceOracle: PublicKey;
|
24
|
+
debtPriceOracle: PublicKey;
|
23
25
|
intermediaryMarginfiAccountSigner?: Signer;
|
24
26
|
intermediaryMarginfiAccountPk: PublicKey;
|
25
27
|
intermediaryMarginfiAccount?: MarginfiAccount;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAGL,eAAe,EAYhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,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AAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAgFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
@@ -43,6 +43,15 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
43
43
|
this.marginfiSupplyAccounts =
|
44
44
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()];
|
45
45
|
this.marginfiDebtAccounts = marginfiAccounts_1.MARGINFI_ACCOUNTS[this.debtMint.toString()];
|
46
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
47
|
+
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
48
|
+
// publicKey(this.marginfiSupplyAccounts.bank),
|
49
|
+
// publicKey(this.marginfiDebtAccounts.bank),
|
50
|
+
// ]);
|
51
|
+
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
52
|
+
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
53
|
+
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
54
|
+
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
46
55
|
if (!this.initialized) {
|
47
56
|
await this.setIntermediaryMarginfiDetails();
|
48
57
|
}
|
@@ -140,9 +149,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
140
149
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
141
150
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccount),
|
142
151
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
143
|
-
supplyPriceOracle: (0, umi_1.publicKey)(this.
|
152
|
+
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
144
153
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
145
|
-
debtPriceOracle: (0, umi_1.publicKey)(this.
|
154
|
+
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
146
155
|
solautoPosition: (0, umi_1.publicKey)(this.solautoPosition),
|
147
156
|
});
|
148
157
|
}
|
@@ -231,8 +240,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
231
240
|
let supplyPriceOracle = undefined;
|
232
241
|
let debtPriceOracle = undefined;
|
233
242
|
if (args.__kind === "Withdraw" || args.__kind === "Borrow") {
|
234
|
-
supplyPriceOracle = (0, umi_1.publicKey)(this.
|
235
|
-
debtPriceOracle = (0, umi_1.publicKey)(this.
|
243
|
+
supplyPriceOracle = (0, umi_1.publicKey)(this.supplyPriceOracle);
|
244
|
+
debtPriceOracle = (0, umi_1.publicKey)(this.debtPriceOracle);
|
236
245
|
}
|
237
246
|
return (0, generated_1.marginfiProtocolInteraction)(this.umi, {
|
238
247
|
signer: this.signer,
|
@@ -276,7 +285,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
276
285
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccountPk),
|
277
286
|
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), swapDetails.inputMint)),
|
278
287
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
279
|
-
supplyPriceOracle: (0, umi_1.publicKey)(this.
|
288
|
+
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
280
289
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
281
290
|
signerSupplyTa: this.selfManaged
|
282
291
|
? (0, umi_1.publicKey)(this.signerSupplyTa)
|
@@ -288,7 +297,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
288
297
|
? (0, umi_1.publicKey)(this.marginfiSupplyAccounts.vaultAuthority)
|
289
298
|
: undefined,
|
290
299
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
291
|
-
debtPriceOracle: (0, umi_1.publicKey)(this.
|
300
|
+
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
292
301
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtTa),
|
293
302
|
signerDebtTa: this.selfManaged ? (0, umi_1.publicKey)(this.signerDebtTa) : undefined,
|
294
303
|
vaultDebtTa: needDebtAccounts
|
@@ -325,17 +334,21 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
325
334
|
}));
|
326
335
|
}
|
327
336
|
flashRepay(flashLoanDetails) {
|
328
|
-
const
|
329
|
-
? this.marginfiSupplyAccounts
|
330
|
-
: this.marginfiDebtAccounts;
|
337
|
+
const accounts = flashLoanDetails.mint.equals(this.supplyMint)
|
338
|
+
? { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle }
|
339
|
+
: { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle };
|
331
340
|
const remainingAccounts = [];
|
332
341
|
let includedFlashLoanToken = false;
|
333
342
|
if (this.intermediaryMarginfiAccount) {
|
334
|
-
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach((x) => {
|
343
|
+
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(async (x) => {
|
335
344
|
if (x.active) {
|
336
|
-
if (x.bankPk ===
|
345
|
+
if (x.bankPk === accounts.data.bank) {
|
337
346
|
includedFlashLoanToken = true;
|
338
347
|
}
|
348
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
349
|
+
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
350
|
+
// const priceOracle = bankData!.config.oracleKeys[0];
|
351
|
+
const priceOracle = (0, umi_1.publicKey)((0, marginfiUtils_1.findMarginfiAccounts)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.bankPk)).priceOracle);
|
339
352
|
remainingAccounts.push(...[
|
340
353
|
{
|
341
354
|
pubkey: x.bankPk,
|
@@ -343,7 +356,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
343
356
|
isWritable: false,
|
344
357
|
},
|
345
358
|
{
|
346
|
-
pubkey:
|
359
|
+
pubkey: priceOracle,
|
347
360
|
isSigner: false,
|
348
361
|
isWritable: false,
|
349
362
|
},
|
@@ -354,12 +367,12 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
354
367
|
if (!this.intermediaryMarginfiAccount || !includedFlashLoanToken) {
|
355
368
|
remainingAccounts.push(...[
|
356
369
|
{
|
357
|
-
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(
|
370
|
+
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(accounts.data.bank)),
|
358
371
|
isSigner: false,
|
359
372
|
isWritable: false,
|
360
373
|
},
|
361
374
|
{
|
362
|
-
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(
|
375
|
+
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(accounts.oracle)),
|
363
376
|
isSigner: false,
|
364
377
|
isWritable: false,
|
365
378
|
},
|
@@ -369,8 +382,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
369
382
|
.add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
370
383
|
amount: flashLoanDetails.baseUnitAmount,
|
371
384
|
repayAll: null,
|
372
|
-
bank: (0, umi_1.publicKey)(
|
373
|
-
bankLiquidityVault: (0, umi_1.publicKey)(
|
385
|
+
bank: (0, umi_1.publicKey)(accounts.data.bank),
|
386
|
+
bankLiquidityVault: (0, umi_1.publicKey)(accounts.data.liquidityVault),
|
374
387
|
marginfiAccount: (0, umi_1.publicKey)(this.intermediaryMarginfiAccountPk),
|
375
388
|
marginfiGroup: (0, umi_1.publicKey)(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP),
|
376
389
|
signer: this.signer,
|
@@ -1,7 +1,8 @@
|
|
1
|
-
export declare const
|
1
|
+
export declare const BASIS_POINTS = 10000;
|
2
2
|
export declare const DEFAULT_LIMIT_GAP_BPS = 1000;
|
3
3
|
export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
4
|
-
export declare const
|
4
|
+
export declare const MIN_REPAY_GAP_BPS = 100;
|
5
|
+
export declare const MIN_BOOST_GAP_BPS = 50;
|
5
6
|
export declare const PRICES: {
|
6
7
|
[key: string]: {
|
7
8
|
price: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAQpC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAE1E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
|
@@ -1,15 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.SOLAUTO_LUT = exports.PRICES = exports.
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.BASIS_POINTS = void 0;
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
6
6
|
// import { JitoRpcConnection } from "jito-ts";
|
7
7
|
const generated_1 = require("../generated");
|
8
8
|
const generalAccounts_1 = require("./generalAccounts");
|
9
|
-
exports.
|
9
|
+
exports.BASIS_POINTS = 10000;
|
10
10
|
exports.DEFAULT_LIMIT_GAP_BPS = 1000;
|
11
11
|
exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
12
|
-
exports.
|
12
|
+
exports.MIN_REPAY_GAP_BPS = 100;
|
13
|
+
exports.MIN_BOOST_GAP_BPS = 50;
|
13
14
|
// export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
|
14
15
|
// export const JITO_CONNECTION = new JitoRpcConnection(
|
15
16
|
// `https://${JITO_BLOCK_ENGINE}`,
|
@@ -42,8 +42,8 @@ export declare class StaleProtocolDataError extends ProgramError {
|
|
42
42
|
readonly code: number;
|
43
43
|
constructor(program: Program, cause?: Error);
|
44
44
|
}
|
45
|
-
/**
|
46
|
-
export declare class
|
45
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
46
|
+
export declare class UnableToRebalanceError extends ProgramError {
|
47
47
|
readonly name: string;
|
48
48
|
readonly code: number;
|
49
49
|
constructor(program: Program, cause?: Error);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../../src/generated/errors/solauto.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO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O,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK;CAG5C;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,KAAK,GACZ,YAAY,GAAG,IAAI,CAGrB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,KAAK,GACZ,YAAY,GAAG,IAAI,CAGrB"}
|
@@ -7,7 +7,7 @@
|
|
7
7
|
* @see https://github.com/metaplex-foundation/kinobi
|
8
8
|
*/
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
-
exports.IncorrectInstructionsError = exports.RebalanceAbuseError = exports.InstructionIsCPIError = exports.InvalidRebalanceConditionError = exports.ExceededValidUtilizationRateError = exports.
|
10
|
+
exports.IncorrectInstructionsError = exports.RebalanceAbuseError = exports.InstructionIsCPIError = exports.InvalidRebalanceConditionError = exports.ExceededValidUtilizationRateError = exports.UnableToRebalanceError = exports.StaleProtocolDataError = exports.InvalidAutomationDataError = exports.InvalidDCASettingsError = exports.InvalidPositionSettingsError = exports.FailedAccountDeserializationError = exports.IncorrectAccountsError = void 0;
|
11
11
|
exports.getSolautoErrorFromCode = getSolautoErrorFromCode;
|
12
12
|
exports.getSolautoErrorFromName = getSolautoErrorFromName;
|
13
13
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -79,17 +79,17 @@ class StaleProtocolDataError extends umi_1.ProgramError {
|
|
79
79
|
exports.StaleProtocolDataError = StaleProtocolDataError;
|
80
80
|
codeToErrorMap.set(0x5, StaleProtocolDataError);
|
81
81
|
nameToErrorMap.set('StaleProtocolData', StaleProtocolDataError);
|
82
|
-
/**
|
83
|
-
class
|
82
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
83
|
+
class UnableToRebalanceError extends umi_1.ProgramError {
|
84
84
|
constructor(program, cause) {
|
85
85
|
super('Unable to adjust position to the desired utilization rate', program, cause);
|
86
|
-
this.name = '
|
86
|
+
this.name = 'UnableToRebalance';
|
87
87
|
this.code = 0x6; // 6
|
88
88
|
}
|
89
89
|
}
|
90
|
-
exports.
|
91
|
-
codeToErrorMap.set(0x6,
|
92
|
-
nameToErrorMap.set('
|
90
|
+
exports.UnableToRebalanceError = UnableToRebalanceError;
|
91
|
+
codeToErrorMap.set(0x6, UnableToRebalanceError);
|
92
|
+
nameToErrorMap.set('UnableToRebalance', UnableToRebalanceError);
|
93
93
|
/** ExceededValidUtilizationRate: Desired action brought the utilization rate to an unsafe amount */
|
94
94
|
class ExceededValidUtilizationRateError extends umi_1.ProgramError {
|
95
95
|
constructor(program, cause) {
|
@@ -9,8 +9,9 @@ import { Serializer } from '@metaplex-foundation/umi/serializers';
|
|
9
9
|
export declare enum OracleSetup {
|
10
10
|
None = 0,
|
11
11
|
PythLegacy = 1,
|
12
|
-
|
13
|
-
PythPushOracle = 3
|
12
|
+
SwitchboardLegacy = 2,
|
13
|
+
PythPushOracle = 3,
|
14
|
+
SwitchboardPull = 4
|
14
15
|
}
|
15
16
|
export type OracleSetupArgs = OracleSetup;
|
16
17
|
export declare function getOracleSetupSerializer(): Serializer<OracleSetupArgs, OracleSetup>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,
|
1
|
+
{"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,iBAAiB,IAAA;IACjB,cAAc,IAAA;IACd,eAAe,IAAA;CAChB;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C,wBAAgB,wBAAwB,IAAI,UAAU,CACpD,eAAe,EACf,WAAW,CACZ,CAIA"}
|
@@ -14,8 +14,9 @@ var OracleSetup;
|
|
14
14
|
(function (OracleSetup) {
|
15
15
|
OracleSetup[OracleSetup["None"] = 0] = "None";
|
16
16
|
OracleSetup[OracleSetup["PythLegacy"] = 1] = "PythLegacy";
|
17
|
-
OracleSetup[OracleSetup["
|
17
|
+
OracleSetup[OracleSetup["SwitchboardLegacy"] = 2] = "SwitchboardLegacy";
|
18
18
|
OracleSetup[OracleSetup["PythPushOracle"] = 3] = "PythPushOracle";
|
19
|
+
OracleSetup[OracleSetup["SwitchboardPull"] = 4] = "SwitchboardPull";
|
19
20
|
})(OracleSetup || (exports.OracleSetup = OracleSetup = {}));
|
20
21
|
function getOracleSetupSerializer() {
|
21
22
|
return (0, serializers_1.scalarEnum)(OracleSetup, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wrappedI80F48.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/wrappedI80F48.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,
|
1
|
+
{"version":3,"file":"wrappedI80F48.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/wrappedI80F48.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EAIX,MAAM,sCAAsC,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEpD,wBAAgB,0BAA0B,IAAI,UAAU,CACtD,iBAAiB,EACjB,aAAa,CACd,CAIA"}
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.getWrappedI80F48Serializer = getWrappedI80F48Serializer;
|
11
11
|
const serializers_1 = require("@metaplex-foundation/umi/serializers");
|
12
12
|
function getWrappedI80F48Serializer() {
|
13
|
-
return (0, serializers_1.struct)([[
|
14
|
-
description:
|
13
|
+
return (0, serializers_1.struct)([["value", (0, serializers_1.array)((0, serializers_1.u8)(), { size: 16 })]], {
|
14
|
+
description: "WrappedI80F48",
|
15
15
|
});
|
16
16
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,qBAAqB,CAU3E;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,IAAI,EAAE;IACJ,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA2D3B;AAED,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CACR;IAAE,eAAe,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,CAC/E,CA6CA;AAgED,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
|
@@ -189,15 +189,15 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
189
189
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(supplyUsage.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
190
190
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(debtUsage?.amountUsed?.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS);
|
191
191
|
return {
|
192
|
-
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd,
|
192
|
+
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, (0, numberUtils_1.toBps)(liqThreshold)),
|
193
193
|
netWorth: {
|
194
194
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd - debtUsd, generalAccounts_1.USD_DECIMALS),
|
195
195
|
baseUnit: (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supplyPrice, supplyUsage.decimals),
|
196
196
|
},
|
197
197
|
supply: supplyUsage,
|
198
198
|
debt: debtUsage,
|
199
|
-
maxLtvBps:
|
200
|
-
liqThresholdBps:
|
199
|
+
maxLtvBps: (0, numberUtils_1.toBps)(maxLtv),
|
200
|
+
liqThresholdBps: (0, numberUtils_1.toBps)(liqThreshold),
|
201
201
|
lastUpdated: BigInt((0, generalUtils_1.currentUnixSeconds)()),
|
202
202
|
padding1: [],
|
203
203
|
padding2: [],
|
@@ -28,10 +28,10 @@ function fromBaseUnit(value, decimals) {
|
|
28
28
|
return Number(value) / Math.pow(10, decimals);
|
29
29
|
}
|
30
30
|
function fromBps(value) {
|
31
|
-
return value /
|
31
|
+
return value / constants_1.BASIS_POINTS;
|
32
32
|
}
|
33
33
|
function toBps(value) {
|
34
|
-
return Math.round(value *
|
34
|
+
return Math.round(value * constants_1.BASIS_POINTS);
|
35
35
|
}
|
36
36
|
function bytesToI80F48(bytes) {
|
37
37
|
if (bytes.length !== 16) {
|
@@ -107,5 +107,5 @@ function maxRepayFromBps(maxLtvBps, liqThresholdBps) {
|
|
107
107
|
return Math.min(9000, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000, 0.005));
|
108
108
|
}
|
109
109
|
function maxRepayToBps(maxLtvBps, liqThresholdBps) {
|
110
|
-
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.
|
110
|
+
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.MIN_REPAY_GAP_BPS, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, 0.005));
|
111
111
|
}
|
package/package.json
CHANGED
@@ -34,6 +34,7 @@ import {
|
|
34
34
|
import { getMarginfiAccountPDA, getTokenAccount } from "../utils/accountUtils";
|
35
35
|
import { generateRandomU64 } from "../utils/generalUtils";
|
36
36
|
import {
|
37
|
+
Bank,
|
37
38
|
MARGINFI_PROGRAM_ID,
|
38
39
|
MarginfiAccount,
|
39
40
|
lendingAccountBorrow,
|
@@ -43,7 +44,9 @@ import {
|
|
43
44
|
lendingAccountStartFlashloan,
|
44
45
|
lendingAccountWithdraw,
|
45
46
|
marginfiAccountInitialize,
|
47
|
+
safeFetchAllBank,
|
46
48
|
safeFetchAllMarginfiAccount,
|
49
|
+
safeFetchBank,
|
47
50
|
safeFetchMarginfiAccount,
|
48
51
|
} from "../marginfi-sdk";
|
49
52
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
@@ -75,6 +78,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
75
78
|
public marginfiSupplyAccounts!: MarginfiAssetAccounts;
|
76
79
|
public marginfiDebtAccounts!: MarginfiAssetAccounts;
|
77
80
|
|
81
|
+
public supplyPriceOracle!: PublicKey;
|
82
|
+
public debtPriceOracle!: PublicKey;
|
83
|
+
|
78
84
|
// For flash loans
|
79
85
|
public intermediaryMarginfiAccountSigner?: Signer;
|
80
86
|
public intermediaryMarginfiAccountPk!: PublicKey;
|
@@ -113,6 +119,17 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
113
119
|
MARGINFI_ACCOUNTS[this.supplyMint.toString()]!;
|
114
120
|
this.marginfiDebtAccounts = MARGINFI_ACCOUNTS[this.debtMint.toString()]!;
|
115
121
|
|
122
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
123
|
+
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
124
|
+
// publicKey(this.marginfiSupplyAccounts.bank),
|
125
|
+
// publicKey(this.marginfiDebtAccounts.bank),
|
126
|
+
// ]);
|
127
|
+
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
128
|
+
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
129
|
+
|
130
|
+
this.supplyPriceOracle = new PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
131
|
+
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
132
|
+
|
116
133
|
if (!this.initialized) {
|
117
134
|
await this.setIntermediaryMarginfiDetails();
|
118
135
|
}
|
@@ -246,9 +263,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
246
263
|
marginfiGroup: publicKey(this.marginfiGroup),
|
247
264
|
marginfiAccount: publicKey(this.marginfiAccount),
|
248
265
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
249
|
-
supplyPriceOracle: publicKey(this.
|
266
|
+
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
250
267
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
251
|
-
debtPriceOracle: publicKey(this.
|
268
|
+
debtPriceOracle: publicKey(this.debtPriceOracle),
|
252
269
|
solautoPosition: publicKey(this.solautoPosition),
|
253
270
|
});
|
254
271
|
}
|
@@ -364,8 +381,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
364
381
|
let supplyPriceOracle: UmiPublicKey | undefined = undefined;
|
365
382
|
let debtPriceOracle: UmiPublicKey | undefined = undefined;
|
366
383
|
if (args.__kind === "Withdraw" || args.__kind === "Borrow") {
|
367
|
-
supplyPriceOracle = publicKey(this.
|
368
|
-
debtPriceOracle = publicKey(this.
|
384
|
+
supplyPriceOracle = publicKey(this.supplyPriceOracle);
|
385
|
+
debtPriceOracle = publicKey(this.debtPriceOracle);
|
369
386
|
}
|
370
387
|
|
371
388
|
return marginfiProtocolInteraction(this.umi, {
|
@@ -427,7 +444,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
427
444
|
)
|
428
445
|
),
|
429
446
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
430
|
-
supplyPriceOracle: publicKey(this.
|
447
|
+
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
431
448
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
432
449
|
signerSupplyTa: this.selfManaged
|
433
450
|
? publicKey(this.signerSupplyTa)
|
@@ -439,7 +456,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
439
456
|
? publicKey(this.marginfiSupplyAccounts.vaultAuthority)
|
440
457
|
: undefined,
|
441
458
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
442
|
-
debtPriceOracle: publicKey(this.
|
459
|
+
debtPriceOracle: publicKey(this.debtPriceOracle),
|
443
460
|
positionDebtTa: publicKey(this.positionDebtTa),
|
444
461
|
signerDebtTa: this.selfManaged ? publicKey(this.signerDebtTa) : undefined,
|
445
462
|
vaultDebtTa: needDebtAccounts
|
@@ -485,20 +502,25 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
485
502
|
}
|
486
503
|
|
487
504
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder {
|
488
|
-
const
|
489
|
-
? this.marginfiSupplyAccounts
|
490
|
-
: this.marginfiDebtAccounts;
|
505
|
+
const accounts = flashLoanDetails.mint.equals(this.supplyMint)
|
506
|
+
? { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle }
|
507
|
+
: { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle };
|
491
508
|
|
492
509
|
const remainingAccounts: AccountMeta[] = [];
|
493
510
|
let includedFlashLoanToken = false;
|
494
511
|
|
495
512
|
if (this.intermediaryMarginfiAccount) {
|
496
|
-
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach((x) => {
|
513
|
+
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(async (x) => {
|
497
514
|
if (x.active) {
|
498
|
-
if (x.bankPk ===
|
515
|
+
if (x.bankPk === accounts.data.bank) {
|
499
516
|
includedFlashLoanToken = true;
|
500
517
|
}
|
501
518
|
|
519
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
520
|
+
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
521
|
+
// const priceOracle = bankData!.config.oracleKeys[0];
|
522
|
+
const priceOracle = publicKey(findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle);
|
523
|
+
|
502
524
|
remainingAccounts.push(
|
503
525
|
...[
|
504
526
|
{
|
@@ -507,9 +529,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
507
529
|
isWritable: false,
|
508
530
|
},
|
509
531
|
{
|
510
|
-
pubkey:
|
511
|
-
findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle
|
512
|
-
),
|
532
|
+
pubkey: priceOracle,
|
513
533
|
isSigner: false,
|
514
534
|
isWritable: false,
|
515
535
|
},
|
@@ -522,12 +542,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
522
542
|
remainingAccounts.push(
|
523
543
|
...[
|
524
544
|
{
|
525
|
-
pubkey: fromWeb3JsPublicKey(new PublicKey(
|
545
|
+
pubkey: fromWeb3JsPublicKey(new PublicKey(accounts.data.bank)),
|
526
546
|
isSigner: false,
|
527
547
|
isWritable: false,
|
528
548
|
},
|
529
549
|
{
|
530
|
-
pubkey: fromWeb3JsPublicKey(new PublicKey(
|
550
|
+
pubkey: fromWeb3JsPublicKey(new PublicKey(accounts.oracle)),
|
531
551
|
isSigner: false,
|
532
552
|
isWritable: false,
|
533
553
|
},
|
@@ -540,8 +560,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
540
560
|
lendingAccountRepay(this.umi, {
|
541
561
|
amount: flashLoanDetails.baseUnitAmount,
|
542
562
|
repayAll: null,
|
543
|
-
bank: publicKey(
|
544
|
-
bankLiquidityVault: publicKey(
|
563
|
+
bank: publicKey(accounts.data.bank),
|
564
|
+
bankLiquidityVault: publicKey(accounts.data.liquidityVault),
|
545
565
|
marginfiAccount: publicKey(this.intermediaryMarginfiAccountPk),
|
546
566
|
marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
|
547
567
|
signer: this.signer,
|
@@ -13,10 +13,12 @@ import {
|
|
13
13
|
import { SOLAUTO_PROGRAM_ID } from "../generated";
|
14
14
|
import { SOLAUTO_MANAGER } from "./generalAccounts";
|
15
15
|
|
16
|
-
export const
|
16
|
+
export const BASIS_POINTS = 10000;
|
17
|
+
|
17
18
|
export const DEFAULT_LIMIT_GAP_BPS = 1000;
|
18
19
|
export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
19
|
-
export const
|
20
|
+
export const MIN_REPAY_GAP_BPS = 100;
|
21
|
+
export const MIN_BOOST_GAP_BPS = 50;
|
20
22
|
|
21
23
|
// export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
|
22
24
|
// export const JITO_CONNECTION = new JitoRpcConnection(
|
@@ -108,9 +108,9 @@ export class StaleProtocolDataError extends ProgramError {
|
|
108
108
|
codeToErrorMap.set(0x5, StaleProtocolDataError);
|
109
109
|
nameToErrorMap.set('StaleProtocolData', StaleProtocolDataError);
|
110
110
|
|
111
|
-
/**
|
112
|
-
export class
|
113
|
-
override readonly name: string = '
|
111
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
112
|
+
export class UnableToRebalanceError extends ProgramError {
|
113
|
+
override readonly name: string = 'UnableToRebalance';
|
114
114
|
|
115
115
|
readonly code: number = 0x6; // 6
|
116
116
|
|
@@ -122,8 +122,8 @@ export class UnableToRepositionError extends ProgramError {
|
|
122
122
|
);
|
123
123
|
}
|
124
124
|
}
|
125
|
-
codeToErrorMap.set(0x6,
|
126
|
-
nameToErrorMap.set('
|
125
|
+
codeToErrorMap.set(0x6, UnableToRebalanceError);
|
126
|
+
nameToErrorMap.set('UnableToRebalance', UnableToRebalanceError);
|
127
127
|
|
128
128
|
/** ExceededValidUtilizationRate: Desired action brought the utilization rate to an unsafe amount */
|
129
129
|
export class ExceededValidUtilizationRateError extends ProgramError {
|
@@ -11,8 +11,9 @@ import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';
|
|
11
11
|
export enum OracleSetup {
|
12
12
|
None,
|
13
13
|
PythLegacy,
|
14
|
-
|
14
|
+
SwitchboardLegacy,
|
15
15
|
PythPushOracle,
|
16
|
+
SwitchboardPull,
|
16
17
|
}
|
17
18
|
|
18
19
|
export type OracleSetupArgs = OracleSetup;
|
@@ -6,7 +6,12 @@
|
|
6
6
|
* @see https://github.com/metaplex-foundation/kinobi
|
7
7
|
*/
|
8
8
|
|
9
|
-
import {
|
9
|
+
import {
|
10
|
+
Serializer,
|
11
|
+
array,
|
12
|
+
struct,
|
13
|
+
u8,
|
14
|
+
} from "@metaplex-foundation/umi/serializers";
|
10
15
|
|
11
16
|
export type WrappedI80F48 = { value: number[] };
|
12
17
|
|
@@ -16,7 +21,7 @@ export function getWrappedI80F48Serializer(): Serializer<
|
|
16
21
|
WrappedI80F48Args,
|
17
22
|
WrappedI80F48
|
18
23
|
> {
|
19
|
-
return struct<WrappedI80F48>([[
|
20
|
-
description:
|
24
|
+
return struct<WrappedI80F48>([["value", array(u8(), { size: 16 })]], {
|
25
|
+
description: "WrappedI80F48",
|
21
26
|
}) as Serializer<WrappedI80F48Args, WrappedI80F48>;
|
22
27
|
}
|
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
fromBaseUnit,
|
15
15
|
getLiqUtilzationRateBps,
|
16
16
|
toBaseUnit,
|
17
|
+
toBps,
|
17
18
|
} from "./numberUtils";
|
18
19
|
import { PRICES } from "../constants/solautoConstants";
|
19
20
|
import { MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
@@ -353,7 +354,7 @@ export async function getMarginfiAccountPositionState(
|
|
353
354
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
354
355
|
supplyUsd,
|
355
356
|
debtUsd,
|
356
|
-
|
357
|
+
toBps(liqThreshold)
|
357
358
|
),
|
358
359
|
netWorth: {
|
359
360
|
baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
|
@@ -364,8 +365,8 @@ export async function getMarginfiAccountPositionState(
|
|
364
365
|
},
|
365
366
|
supply: supplyUsage!,
|
366
367
|
debt: debtUsage!,
|
367
|
-
maxLtvBps:
|
368
|
-
liqThresholdBps:
|
368
|
+
maxLtvBps: toBps(maxLtv),
|
369
|
+
liqThresholdBps: toBps(liqThreshold),
|
369
370
|
lastUpdated: BigInt(currentUnixSeconds()),
|
370
371
|
padding1: [],
|
371
372
|
padding2: [],
|
package/src/utils/numberUtils.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { BASIS_POINTS, MIN_REPAY_GAP_BPS } from "../constants";
|
2
2
|
import { FeeType } from "../generated";
|
3
3
|
|
4
4
|
export function getLiqUtilzationRateBps(
|
@@ -22,11 +22,11 @@ export function fromBaseUnit(value: bigint, decimals: number): number {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
export function fromBps(value: number): number {
|
25
|
-
return value /
|
25
|
+
return value / BASIS_POINTS;
|
26
26
|
}
|
27
27
|
|
28
28
|
export function toBps(value: number): number {
|
29
|
-
return Math.round(value *
|
29
|
+
return Math.round(value * BASIS_POINTS);
|
30
30
|
}
|
31
31
|
|
32
32
|
export function bytesToI80F48(bytes: number[]): number {
|
@@ -148,7 +148,7 @@ export function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number) {
|
|
148
148
|
|
149
149
|
export function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number) {
|
150
150
|
return Math.min(
|
151
|
-
maxRepayFromBps(maxLtvBps, liqThresholdBps) -
|
151
|
+
maxRepayFromBps(maxLtvBps, liqThresholdBps) - MIN_REPAY_GAP_BPS,
|
152
152
|
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, 0.005)
|
153
153
|
);
|
154
154
|
}
|
@@ -20,8 +20,8 @@ import { PublicKey } from "@solana/web3.js";
|
|
20
20
|
import { USDC_MINT } from "../../src/constants";
|
21
21
|
|
22
22
|
describe("Solauto Marginfi tests", async () => {
|
23
|
-
const signer = setupTest();
|
24
|
-
|
23
|
+
// const signer = setupTest();
|
24
|
+
const signer = setupTest("solauto-manager");
|
25
25
|
|
26
26
|
const payForTransactions = false;
|
27
27
|
const useJitoBundle = false;
|