@haven-fi/solauto-sdk 1.0.202 → 1.0.203
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/constants/marginfiAccounts.js +6 -6
- package/dist/constants/pythConstants.d.ts +1 -1
- package/dist/constants/pythConstants.js +1 -1
- package/dist/constants/tokenConstants.js +6 -6
- package/dist/utils/marginfiUtils.d.ts +2 -1
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +16 -12
- package/package.json +1 -1
- package/src/constants/marginfiAccounts.ts +6 -6
- package/src/constants/pythConstants.ts +2 -2
- package/src/constants/tokenConstants.ts +6 -6
- package/src/utils/marginfiUtils.ts +14 -19
@@ -43,6 +43,12 @@ exports.MARGINFI_ACCOUNTS = {
|
|
43
43
|
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
44
44
|
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
45
45
|
},
|
46
|
+
[tokens.M_SOL]: {
|
47
|
+
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
48
|
+
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
49
|
+
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
50
|
+
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
51
|
+
},
|
46
52
|
[tokens.JITO_SOL]: {
|
47
53
|
bank: "Bohoc1ikHLD7xKJuzTyiTyCwzaL5N7ggJQu75A8mKYM8",
|
48
54
|
liquidityVault: "38VGtXd2pDPq9FMh1z6AVjcHCoHgvWyMhdNyamDTeeks",
|
@@ -55,12 +61,6 @@ exports.MARGINFI_ACCOUNTS = {
|
|
55
61
|
vaultAuthority: "6PWVauGLhBFHUJspsnBVZHr56ZnbvmhSD2gS7czBHGpE",
|
56
62
|
priceOracle: "7aT9A5knp62jVvnEW33xaWopaPHa3Y7ggULyYiUsDhu8",
|
57
63
|
},
|
58
|
-
[tokens.M_SOL]: {
|
59
|
-
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
60
|
-
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
61
|
-
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
62
|
-
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
63
|
-
},
|
64
64
|
[tokens.INF]: {
|
65
65
|
bank: "AwLRW3aPMMftXEjgWhTkYwM9CGBHdtKecvahCJZBwAqY",
|
66
66
|
liquidityVault: "HQ1CGcqRshMhuonTGTnnmgw9ffcXxizGdZ6F6PKffWWi",
|
@@ -1,9 +1,9 @@
|
|
1
1
|
export declare const PYTH_PRICE_FEED_IDS: {
|
2
2
|
[x: string]: string;
|
3
3
|
bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1: string;
|
4
|
+
mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So: string;
|
4
5
|
J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn: string;
|
5
6
|
LSTxxxnJzKDFSLr4dUkPcmCf5VyryEqzPLz5j4bpxFp: string;
|
6
|
-
mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So: string;
|
7
7
|
"5oVNBeEEQvYi1cX3ir8Dx5n1P7pdxydbGF2X4TxVusJm": string;
|
8
8
|
JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN: string;
|
9
9
|
DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263: string;
|
@@ -30,9 +30,9 @@ const tokens = __importStar(require("./tokenConstants"));
|
|
30
30
|
exports.PYTH_PRICE_FEED_IDS = {
|
31
31
|
[spl_token_1.NATIVE_MINT.toString()]: "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
32
32
|
[tokens.B_SOL]: "0x89875379e70f8fbadc17aef315adf3a8d5d160b811435537e03c97e8aac97d9c",
|
33
|
+
[tokens.M_SOL]: "0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4",
|
33
34
|
[tokens.JITO_SOL]: "0x67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb",
|
34
35
|
[tokens.LST]: "0x12fb674ee496045b1d9cf7d5e65379acb026133c2ad69f3ed996fb9fe68e3a37",
|
35
|
-
[tokens.M_SOL]: "0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4",
|
36
36
|
[tokens.INF]: "0xf51570985c642c49c2d6e50156390fdba80bb6d5f7fa389d2f012ced4f7d208f",
|
37
37
|
[tokens.JUP]: "0x0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996",
|
38
38
|
[tokens.BONK]: "0x72b021217ca3fe68922a19aaf990109cb9d84e9ad004b4d2025ad6f529314419",
|
@@ -23,9 +23,9 @@ exports.USDT = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
|
|
23
23
|
exports.ALL_SUPPORTED_TOKENS = [
|
24
24
|
spl_token_1.NATIVE_MINT.toString(),
|
25
25
|
exports.B_SOL,
|
26
|
+
exports.M_SOL,
|
26
27
|
exports.JITO_SOL,
|
27
28
|
exports.LST,
|
28
|
-
exports.M_SOL,
|
29
29
|
exports.INF,
|
30
30
|
exports.JUP,
|
31
31
|
exports.BONK,
|
@@ -53,6 +53,11 @@ exports.TOKEN_INFO = {
|
|
53
53
|
decimals: 9,
|
54
54
|
isLST: true,
|
55
55
|
},
|
56
|
+
[exports.M_SOL]: {
|
57
|
+
ticker: "mSOL",
|
58
|
+
decimals: 9,
|
59
|
+
isLST: true,
|
60
|
+
},
|
56
61
|
[exports.JITO_SOL]: {
|
57
62
|
ticker: "JitoSOL",
|
58
63
|
decimals: 9,
|
@@ -63,11 +68,6 @@ exports.TOKEN_INFO = {
|
|
63
68
|
decimals: 9,
|
64
69
|
isLST: true,
|
65
70
|
},
|
66
|
-
[exports.M_SOL]: {
|
67
|
-
ticker: "mSOL",
|
68
|
-
decimals: 9,
|
69
|
-
isLST: true,
|
70
|
-
},
|
71
71
|
[exports.INF]: {
|
72
72
|
ticker: "INF",
|
73
73
|
decimals: 9,
|
@@ -19,5 +19,6 @@ export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: P
|
|
19
19
|
debtMint?: PublicKey;
|
20
20
|
}[]>;
|
21
21
|
export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, marginfiGroup?: PublicKey, supplyMint?: PublicKey, debtMint?: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
|
22
|
-
export declare function
|
22
|
+
export declare function calculateAnnualAPYs(bank: Bank): [number, number];
|
23
|
+
export declare function getUpToDateShareValues(bank: Bank): Promise<[number, number]>;
|
23
24
|
//# sourceMappingURL=marginfiUtils.d.ts.map
|
@@ -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;AAiBzB,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,CAY3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LiqThresholdBps;
|
|
5
5
|
exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
|
6
6
|
exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
|
7
7
|
exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
|
8
|
+
exports.calculateAnnualAPYs = calculateAnnualAPYs;
|
8
9
|
exports.getUpToDateShareValues = getUpToDateShareValues;
|
9
10
|
const web3_js_1 = require("@solana/web3.js");
|
10
11
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -103,13 +104,13 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
|
|
103
104
|
}));
|
104
105
|
}
|
105
106
|
}
|
106
|
-
async function getTokenUsage(
|
107
|
+
async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment) {
|
107
108
|
let amountUsed = 0;
|
108
109
|
let amountCanBeUsed = 0;
|
109
110
|
let marketPrice = 0;
|
110
111
|
if (bank !== null) {
|
111
112
|
[marketPrice] = await (0, generalUtils_1.fetchTokenPrices)([(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.mint)]);
|
112
|
-
const [assetShareValue, liabilityShareValue] = await getUpToDateShareValues(
|
113
|
+
const [assetShareValue, liabilityShareValue] = await getUpToDateShareValues(bank);
|
113
114
|
const shareValue = isAsset ? assetShareValue : liabilityShareValue;
|
114
115
|
amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
|
115
116
|
const totalDeposited = (0, numberUtils_1.bytesToI80F48)(bank.totalAssetShares.value) * assetShareValue;
|
@@ -172,7 +173,7 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, marginfiG
|
|
172
173
|
if (!supplyMint) {
|
173
174
|
supplyMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint);
|
174
175
|
}
|
175
|
-
supplyUsage = await getTokenUsage(
|
176
|
+
supplyUsage = await getTokenUsage(supplyBank, true, (0, numberUtils_1.bytesToI80F48)(supplyBalances[0].assetShares.value), livePositionUpdates?.supplyAdjustment);
|
176
177
|
}
|
177
178
|
if (debtBalances.length > 0) {
|
178
179
|
if (debtBank === null) {
|
@@ -183,7 +184,7 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, marginfiG
|
|
183
184
|
if (!debtMint) {
|
184
185
|
debtMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(debtBank.mint);
|
185
186
|
}
|
186
|
-
debtUsage = await getTokenUsage(
|
187
|
+
debtUsage = await getTokenUsage(debtBank, false, (0, numberUtils_1.bytesToI80F48)(debtBalances[0].liabilityShares.value), livePositionUpdates?.debtAdjustment);
|
187
188
|
}
|
188
189
|
}
|
189
190
|
if (supplyBank === null) {
|
@@ -194,14 +195,14 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, marginfiG
|
|
194
195
|
return undefined;
|
195
196
|
}
|
196
197
|
if (!supplyUsage) {
|
197
|
-
supplyUsage = await getTokenUsage(
|
198
|
+
supplyUsage = await getTokenUsage(supplyBank, true, 0, livePositionUpdates?.supplyAdjustment);
|
198
199
|
}
|
199
200
|
if (constants_1.TOKEN_INFO[supplyBank.mint.toString()].isStableCoin &&
|
200
201
|
(debtBank === null || constants_1.TOKEN_INFO[debtBank.mint.toString()].isStableCoin)) {
|
201
202
|
return undefined;
|
202
203
|
}
|
203
204
|
if (!debtUsage) {
|
204
|
-
debtUsage = await getTokenUsage(
|
205
|
+
debtUsage = await getTokenUsage(debtBank, false, 0, livePositionUpdates?.debtAdjustment);
|
205
206
|
}
|
206
207
|
const supplyPrice = (0, generalUtils_1.safeGetPrice)(supplyMint);
|
207
208
|
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(umi, marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP), {
|
@@ -234,10 +235,10 @@ function marginfiInterestRateCurve(bank, utilizationRatio) {
|
|
234
235
|
const plateauIr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.plateauInterestRate.value);
|
235
236
|
const maxIr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.maxInterestRate.value);
|
236
237
|
if (utilizationRatio <= optimalUr) {
|
237
|
-
return (utilizationRatio
|
238
|
+
return (utilizationRatio * plateauIr) / optimalUr;
|
238
239
|
}
|
239
240
|
else {
|
240
|
-
return (((utilizationRatio - optimalUr) / (1 - optimalUr)) * (maxIr - plateauIr) +
|
241
|
+
return ((((utilizationRatio - optimalUr) / (1 - optimalUr)) * (maxIr - plateauIr)) +
|
241
242
|
plateauIr);
|
242
243
|
}
|
243
244
|
}
|
@@ -250,7 +251,7 @@ function calcInterestRate(bank, utilizationRatio) {
|
|
250
251
|
const insuranceFixedFeeApr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.insuranceFeeFixedApr.value);
|
251
252
|
const rateFee = protocolIrFee + insuranceIrFee;
|
252
253
|
const totalFixedFeeApr = protocolFixedFeeApr + insuranceFixedFeeApr;
|
253
|
-
const borrowingRate = baseRate * (1 + rateFee)
|
254
|
+
const borrowingRate = (baseRate * (1 + rateFee)) + totalFixedFeeApr;
|
254
255
|
return [lendingRate, borrowingRate];
|
255
256
|
}
|
256
257
|
function calcAccruedInterestPaymentPerPeriod(apr, timeDelta, shareValue) {
|
@@ -258,14 +259,17 @@ function calcAccruedInterestPaymentPerPeriod(apr, timeDelta, shareValue) {
|
|
258
259
|
const newValue = shareValue * (1 + irPerPeriod);
|
259
260
|
return newValue;
|
260
261
|
}
|
261
|
-
|
262
|
-
let timeDelta = (0, generalUtils_1.currentUnixSeconds)() - Number(bank.lastUpdate);
|
262
|
+
function calculateAnnualAPYs(bank) {
|
263
263
|
const totalAssets = (0, numberUtils_1.bytesToI80F48)(bank.totalAssetShares.value) *
|
264
264
|
(0, numberUtils_1.bytesToI80F48)(bank.assetShareValue.value);
|
265
265
|
const totalLiabilities = (0, numberUtils_1.bytesToI80F48)(bank.totalLiabilityShares.value) *
|
266
266
|
(0, numberUtils_1.bytesToI80F48)(bank.liabilityShareValue.value);
|
267
267
|
const utilizationRatio = totalLiabilities / totalAssets;
|
268
|
-
|
268
|
+
return calcInterestRate(bank, utilizationRatio);
|
269
|
+
}
|
270
|
+
async function getUpToDateShareValues(bank) {
|
271
|
+
let timeDelta = (0, generalUtils_1.currentUnixSeconds)() - Number(bank.lastUpdate);
|
272
|
+
const [lendingApr, borrowingApr] = calculateAnnualAPYs(bank);
|
269
273
|
return [
|
270
274
|
calcAccruedInterestPaymentPerPeriod(lendingApr, timeDelta, (0, numberUtils_1.bytesToI80F48)(bank.assetShareValue.value)),
|
271
275
|
calcAccruedInterestPaymentPerPeriod(borrowingApr, timeDelta, (0, numberUtils_1.bytesToI80F48)(bank.liabilityShareValue.value)),
|
package/package.json
CHANGED
@@ -24,6 +24,12 @@ export const MARGINFI_ACCOUNTS: {
|
|
24
24
|
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
25
25
|
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
26
26
|
},
|
27
|
+
[tokens.M_SOL]: {
|
28
|
+
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
29
|
+
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
30
|
+
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
31
|
+
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
32
|
+
},
|
27
33
|
[tokens.JITO_SOL]: {
|
28
34
|
bank: "Bohoc1ikHLD7xKJuzTyiTyCwzaL5N7ggJQu75A8mKYM8",
|
29
35
|
liquidityVault: "38VGtXd2pDPq9FMh1z6AVjcHCoHgvWyMhdNyamDTeeks",
|
@@ -36,12 +42,6 @@ export const MARGINFI_ACCOUNTS: {
|
|
36
42
|
vaultAuthority: "6PWVauGLhBFHUJspsnBVZHr56ZnbvmhSD2gS7czBHGpE",
|
37
43
|
priceOracle: "7aT9A5knp62jVvnEW33xaWopaPHa3Y7ggULyYiUsDhu8",
|
38
44
|
},
|
39
|
-
[tokens.M_SOL]: {
|
40
|
-
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
41
|
-
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
42
|
-
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
43
|
-
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
44
|
-
},
|
45
45
|
[tokens.INF]: {
|
46
46
|
bank: "AwLRW3aPMMftXEjgWhTkYwM9CGBHdtKecvahCJZBwAqY",
|
47
47
|
liquidityVault: "HQ1CGcqRshMhuonTGTnnmgw9ffcXxizGdZ6F6PKffWWi",
|
@@ -7,12 +7,12 @@ export const PYTH_PRICE_FEED_IDS = {
|
|
7
7
|
"0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
8
8
|
[tokens.B_SOL]:
|
9
9
|
"0x89875379e70f8fbadc17aef315adf3a8d5d160b811435537e03c97e8aac97d9c",
|
10
|
+
[tokens.M_SOL]:
|
11
|
+
"0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4",
|
10
12
|
[tokens.JITO_SOL]:
|
11
13
|
"0x67be9f519b95cf24338801051f9a808eff0a578ccb388db73b7f6fe1de019ffb",
|
12
14
|
[tokens.LST]:
|
13
15
|
"0x12fb674ee496045b1d9cf7d5e65379acb026133c2ad69f3ed996fb9fe68e3a37",
|
14
|
-
[tokens.M_SOL]:
|
15
|
-
"0xc2289a6a43d2ce91c6f55caec370f4acc38a2ed477f58813334c6d03749ff2a4",
|
16
16
|
[tokens.INF]:
|
17
17
|
"0xf51570985c642c49c2d6e50156390fdba80bb6d5f7fa389d2f012ced4f7d208f",
|
18
18
|
[tokens.JUP]:
|
@@ -22,9 +22,9 @@ export const USDT = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
|
|
22
22
|
export const ALL_SUPPORTED_TOKENS = [
|
23
23
|
NATIVE_MINT.toString(),
|
24
24
|
B_SOL,
|
25
|
+
M_SOL,
|
25
26
|
JITO_SOL,
|
26
27
|
LST,
|
27
|
-
M_SOL,
|
28
28
|
INF,
|
29
29
|
JUP,
|
30
30
|
BONK,
|
@@ -60,6 +60,11 @@ export const TOKEN_INFO: { [key: string]: TokenInfo } = {
|
|
60
60
|
decimals: 9,
|
61
61
|
isLST: true,
|
62
62
|
},
|
63
|
+
[M_SOL]: {
|
64
|
+
ticker: "mSOL",
|
65
|
+
decimals: 9,
|
66
|
+
isLST: true,
|
67
|
+
},
|
63
68
|
[JITO_SOL]: {
|
64
69
|
ticker: "JitoSOL",
|
65
70
|
decimals: 9,
|
@@ -70,11 +75,6 @@ export const TOKEN_INFO: { [key: string]: TokenInfo } = {
|
|
70
75
|
decimals: 9,
|
71
76
|
isLST: true,
|
72
77
|
},
|
73
|
-
[M_SOL]: {
|
74
|
-
ticker: "mSOL",
|
75
|
-
decimals: 9,
|
76
|
-
isLST: true,
|
77
|
-
},
|
78
78
|
[INF]: {
|
79
79
|
ticker: "INF",
|
80
80
|
decimals: 9,
|
@@ -198,7 +198,6 @@ export async function getAllMarginfiAccountsByAuthority(
|
|
198
198
|
}
|
199
199
|
|
200
200
|
async function getTokenUsage(
|
201
|
-
umi: Umi,
|
202
201
|
bank: Bank | null,
|
203
202
|
isAsset: boolean,
|
204
203
|
shares: number,
|
@@ -210,10 +209,8 @@ async function getTokenUsage(
|
|
210
209
|
|
211
210
|
if (bank !== null) {
|
212
211
|
[marketPrice] = await fetchTokenPrices([toWeb3JsPublicKey(bank.mint)]);
|
213
|
-
const [assetShareValue, liabilityShareValue] =
|
214
|
-
|
215
|
-
bank
|
216
|
-
);
|
212
|
+
const [assetShareValue, liabilityShareValue] =
|
213
|
+
await getUpToDateShareValues(bank);
|
217
214
|
const shareValue = isAsset ? assetShareValue : liabilityShareValue;
|
218
215
|
amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
|
219
216
|
|
@@ -333,7 +330,6 @@ export async function getMarginfiAccountPositionState(
|
|
333
330
|
supplyMint = toWeb3JsPublicKey(supplyBank!.mint);
|
334
331
|
}
|
335
332
|
supplyUsage = await getTokenUsage(
|
336
|
-
umi,
|
337
333
|
supplyBank!,
|
338
334
|
true,
|
339
335
|
bytesToI80F48(supplyBalances[0].assetShares.value),
|
@@ -351,7 +347,6 @@ export async function getMarginfiAccountPositionState(
|
|
351
347
|
debtMint = toWeb3JsPublicKey(debtBank!.mint);
|
352
348
|
}
|
353
349
|
debtUsage = await getTokenUsage(
|
354
|
-
umi,
|
355
350
|
debtBank!,
|
356
351
|
false,
|
357
352
|
bytesToI80F48(debtBalances[0].liabilityShares.value),
|
@@ -375,7 +370,6 @@ export async function getMarginfiAccountPositionState(
|
|
375
370
|
|
376
371
|
if (!supplyUsage) {
|
377
372
|
supplyUsage = await getTokenUsage(
|
378
|
-
umi,
|
379
373
|
supplyBank,
|
380
374
|
true,
|
381
375
|
0,
|
@@ -392,7 +386,6 @@ export async function getMarginfiAccountPositionState(
|
|
392
386
|
|
393
387
|
if (!debtUsage) {
|
394
388
|
debtUsage = await getTokenUsage(
|
395
|
-
umi,
|
396
389
|
debtBank,
|
397
390
|
false,
|
398
391
|
0,
|
@@ -462,10 +455,10 @@ function marginfiInterestRateCurve(
|
|
462
455
|
);
|
463
456
|
|
464
457
|
if (utilizationRatio <= optimalUr) {
|
465
|
-
return (utilizationRatio
|
458
|
+
return (utilizationRatio * plateauIr) / optimalUr;
|
466
459
|
} else {
|
467
460
|
return (
|
468
|
-
((utilizationRatio - optimalUr) / (1 - optimalUr)) * (maxIr - plateauIr) +
|
461
|
+
(((utilizationRatio - optimalUr) / (1 - optimalUr)) * (maxIr - plateauIr)) +
|
469
462
|
plateauIr
|
470
463
|
);
|
471
464
|
}
|
@@ -493,7 +486,7 @@ function calcInterestRate(
|
|
493
486
|
);
|
494
487
|
const rateFee = protocolIrFee + insuranceIrFee;
|
495
488
|
const totalFixedFeeApr = protocolFixedFeeApr + insuranceFixedFeeApr;
|
496
|
-
const borrowingRate = baseRate * (1 + rateFee)
|
489
|
+
const borrowingRate = (baseRate * (1 + rateFee)) + totalFixedFeeApr;
|
497
490
|
|
498
491
|
return [lendingRate, borrowingRate];
|
499
492
|
}
|
@@ -508,12 +501,7 @@ function calcAccruedInterestPaymentPerPeriod(
|
|
508
501
|
return newValue;
|
509
502
|
}
|
510
503
|
|
511
|
-
export
|
512
|
-
umi: Umi,
|
513
|
-
bank: Bank
|
514
|
-
): Promise<[number, number]> {
|
515
|
-
let timeDelta = currentUnixSeconds() - Number(bank.lastUpdate);
|
516
|
-
|
504
|
+
export function calculateAnnualAPYs(bank: Bank) {
|
517
505
|
const totalAssets =
|
518
506
|
bytesToI80F48(bank.totalAssetShares.value) *
|
519
507
|
bytesToI80F48(bank.assetShareValue.value);
|
@@ -522,7 +510,14 @@ export async function getUpToDateShareValues(
|
|
522
510
|
bytesToI80F48(bank.liabilityShareValue.value);
|
523
511
|
|
524
512
|
const utilizationRatio = totalLiabilities / totalAssets;
|
525
|
-
|
513
|
+
return calcInterestRate(bank, utilizationRatio);
|
514
|
+
}
|
515
|
+
|
516
|
+
export async function getUpToDateShareValues(
|
517
|
+
bank: Bank
|
518
|
+
): Promise<[number, number]> {
|
519
|
+
let timeDelta = currentUnixSeconds() - Number(bank.lastUpdate);
|
520
|
+
const [lendingApr, borrowingApr] = calculateAnnualAPYs(bank);
|
526
521
|
|
527
522
|
return [
|
528
523
|
calcAccruedInterestPaymentPerPeriod(
|