@haven-fi/solauto-sdk 1.0.202 → 1.0.204
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +0 -1
- 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/generated/instructions/marginfiOpenPosition.d.ts +0 -1
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiOpenPosition.js +13 -18
- package/dist/transactions/transactionUtils.d.ts +1 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +10 -10
- 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/clients/solautoMarginfiClient.ts +0 -1
- package/src/constants/marginfiAccounts.ts +6 -6
- package/src/constants/pythConstants.ts +2 -2
- package/src/constants/tokenConstants.ts +6 -6
- package/src/generated/instructions/marginfiOpenPosition.ts +13 -19
- package/src/transactions/transactionUtils.ts +20 -15
- package/src/utils/marginfiUtils.ts +14 -19
@@ -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,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cA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C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IA6D1C,8BAA8B;IA0CpC,eAAe,IAAI,SAAS;IAI5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAUzB,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0BvE,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAqErB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA6ClE"}
|
@@ -135,7 +135,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
135
135
|
return (0, generated_1.marginfiOpenPosition)(this.umi, {
|
136
136
|
signer: this.signer,
|
137
137
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
138
|
-
solautoFeesWallet: (0, umi_1.publicKey)(this.solautoFeesWallet),
|
139
138
|
signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
|
140
139
|
referredByState: this.referredByState
|
141
140
|
? (0, umi_1.publicKey)(this.referredByState)
|
@@ -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,
|
@@ -15,7 +15,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
15
15
|
tokenProgram?: PublicKey | Pda;
|
16
16
|
ataProgram?: PublicKey | Pda;
|
17
17
|
rent?: PublicKey | Pda;
|
18
|
-
solautoFeesWallet: PublicKey | Pda;
|
19
18
|
signerReferralState: PublicKey | Pda;
|
20
19
|
referredByState?: PublicKey | Pda;
|
21
20
|
referredBySupplyTa?: PublicKey | Pda;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,uCAAuC,GAAG;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,UAAU,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC7B,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACvB,
|
1
|
+
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAA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,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,sBAAsB,CAAC;IACrC,sBAAsB,EAAE,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAC3D,CAAC;AAEF,wBAAgB,gDAAgD,IAAI,UAAU,CAC5E,uCAAuC,EACvC,mCAAmC,CACpC,CAoBA;AAGD,MAAM,MAAM,mCAAmC,GAC7C,uCAAuC,CAAC;AAG1C,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,KAAK,EAAE,uCAAuC,GAC5C,mCAAmC,GACpC,kBAAkB,CA4JpB"}
|
@@ -53,73 +53,68 @@ function marginfiOpenPosition(context, input) {
|
|
53
53
|
value: input.ataProgram ?? null,
|
54
54
|
},
|
55
55
|
rent: { index: 5, isWritable: false, value: input.rent ?? null },
|
56
|
-
solautoFeesWallet: {
|
57
|
-
index: 6,
|
58
|
-
isWritable: false,
|
59
|
-
value: input.solautoFeesWallet ?? null,
|
60
|
-
},
|
61
56
|
signerReferralState: {
|
62
|
-
index:
|
57
|
+
index: 6,
|
63
58
|
isWritable: false,
|
64
59
|
value: input.signerReferralState ?? null,
|
65
60
|
},
|
66
61
|
referredByState: {
|
67
|
-
index:
|
62
|
+
index: 7,
|
68
63
|
isWritable: false,
|
69
64
|
value: input.referredByState ?? null,
|
70
65
|
},
|
71
66
|
referredBySupplyTa: {
|
72
|
-
index:
|
67
|
+
index: 8,
|
73
68
|
isWritable: true,
|
74
69
|
value: input.referredBySupplyTa ?? null,
|
75
70
|
},
|
76
71
|
solautoPosition: {
|
77
|
-
index:
|
72
|
+
index: 9,
|
78
73
|
isWritable: true,
|
79
74
|
value: input.solautoPosition ?? null,
|
80
75
|
},
|
81
76
|
marginfiGroup: {
|
82
|
-
index:
|
77
|
+
index: 10,
|
83
78
|
isWritable: false,
|
84
79
|
value: input.marginfiGroup ?? null,
|
85
80
|
},
|
86
81
|
marginfiAccount: {
|
87
|
-
index:
|
82
|
+
index: 11,
|
88
83
|
isWritable: true,
|
89
84
|
value: input.marginfiAccount ?? null,
|
90
85
|
},
|
91
86
|
supplyMint: {
|
92
|
-
index:
|
87
|
+
index: 12,
|
93
88
|
isWritable: false,
|
94
89
|
value: input.supplyMint ?? null,
|
95
90
|
},
|
96
91
|
supplyBank: {
|
97
|
-
index:
|
92
|
+
index: 13,
|
98
93
|
isWritable: false,
|
99
94
|
value: input.supplyBank ?? null,
|
100
95
|
},
|
101
96
|
positionSupplyTa: {
|
102
|
-
index:
|
97
|
+
index: 14,
|
103
98
|
isWritable: true,
|
104
99
|
value: input.positionSupplyTa ?? null,
|
105
100
|
},
|
106
101
|
debtMint: {
|
107
|
-
index:
|
102
|
+
index: 15,
|
108
103
|
isWritable: false,
|
109
104
|
value: input.debtMint ?? null,
|
110
105
|
},
|
111
106
|
debtBank: {
|
112
|
-
index:
|
107
|
+
index: 16,
|
113
108
|
isWritable: false,
|
114
109
|
value: input.debtBank ?? null,
|
115
110
|
},
|
116
111
|
positionDebtTa: {
|
117
|
-
index:
|
112
|
+
index: 17,
|
118
113
|
isWritable: true,
|
119
114
|
value: input.positionDebtTa ?? null,
|
120
115
|
},
|
121
116
|
signerDebtTa: {
|
122
|
-
index:
|
117
|
+
index: 18,
|
123
118
|
isWritable: true,
|
124
119
|
value: input.signerDebtTa ?? null,
|
125
120
|
},
|
@@ -4,7 +4,7 @@ import { ReferralState } from "../generated";
|
|
4
4
|
import { SolautoClient } from "../clients/solautoClient";
|
5
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
6
6
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
7
|
-
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): boolean
|
7
|
+
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
|
8
8
|
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<{
|
9
9
|
tx: TransactionBuilder;
|
10
10
|
lookupTableAddresses: string[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqOzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAyCzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CAkHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
|
@@ -20,6 +20,7 @@ const generalUtils_2 = require("../utils/solauto/generalUtils");
|
|
20
20
|
const accountUtils_1 = require("../utils/accountUtils");
|
21
21
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
22
22
|
const jupiter_sdk_1 = require("../jupiter-sdk");
|
23
|
+
const constants_1 = require("../constants");
|
23
24
|
function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
|
24
25
|
const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
|
25
26
|
const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
|
@@ -324,7 +325,7 @@ async function getTransactionChores(client, tx) {
|
|
324
325
|
choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.cancellingDca));
|
325
326
|
return [choresBefore, choresAfter];
|
326
327
|
}
|
327
|
-
function requiresRefreshBeforeRebalance(client) {
|
328
|
+
async function requiresRefreshBeforeRebalance(client) {
|
328
329
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
329
330
|
(0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps, 0.01)) {
|
330
331
|
return true;
|
@@ -334,14 +335,13 @@ function requiresRefreshBeforeRebalance(client) {
|
|
334
335
|
client.livePositionUpdates.debtAdjustment > BigInt(0)) {
|
335
336
|
return false;
|
336
337
|
}
|
337
|
-
const
|
338
|
-
const
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.005) {
|
338
|
+
const oldStateWithLatestPrices = await (0, generalUtils_2.positionStateWithLatestPrices)(client.solautoPositionData.state, constants_1.PRICES[client.supplyMint.toString()].price, constants_1.PRICES[client.debtMint.toString()].price);
|
339
|
+
const utilizationRateDiff = Math.abs((client.solautoPositionState?.liqUtilizationRateBps ?? 0) -
|
340
|
+
oldStateWithLatestPrices.liqUtilizationRateBps);
|
341
|
+
if (client.livePositionUpdates.supplyAdjustment === BigInt(0) &&
|
342
|
+
client.livePositionUpdates.debtAdjustment === BigInt(0) &&
|
343
|
+
utilizationRateDiff / oldStateWithLatestPrices.liqUtilizationRateBps >=
|
344
|
+
0.005) {
|
345
345
|
return true;
|
346
346
|
}
|
347
347
|
}
|
@@ -363,7 +363,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
363
363
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
364
364
|
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
365
365
|
let tx = (0, umi_1.transactionBuilder)();
|
366
|
-
if (requiresRefreshBeforeRebalance(client)) {
|
366
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
367
367
|
tx = tx.add(client.refresh());
|
368
368
|
}
|
369
369
|
if (flashLoan) {
|
@@ -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,CAY3E;AAED,wBAAgB,gCAAgC,CAC9C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BlB;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,SAAS,EACxB,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,CAwC3B;AAED,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAA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,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,CAwDA;AA6DD,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,aAAa,CAAC,EAAE,SAAS,EACzB,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+KpC;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgB3B"}
|
@@ -5,6 +5,7 @@ exports.marginfiMaxLtvAndLiqThresholdBps = marginfiMaxLtvAndLiqThresholdBps;
|
|
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
@@ -263,7 +263,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
263
263
|
return marginfiOpenPosition(this.umi, {
|
264
264
|
signer: this.signer,
|
265
265
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
266
|
-
solautoFeesWallet: publicKey(this.solautoFeesWallet),
|
267
266
|
signerReferralState: publicKey(this.referralStateManager.referralState),
|
268
267
|
referredByState: this.referredByState
|
269
268
|
? publicKey(this.referredByState)
|
@@ -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,
|
@@ -47,7 +47,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
47
47
|
tokenProgram?: PublicKey | Pda;
|
48
48
|
ataProgram?: PublicKey | Pda;
|
49
49
|
rent?: PublicKey | Pda;
|
50
|
-
solautoFeesWallet: PublicKey | Pda;
|
51
50
|
signerReferralState: PublicKey | Pda;
|
52
51
|
referredByState?: PublicKey | Pda;
|
53
52
|
referredBySupplyTa?: PublicKey | Pda;
|
@@ -146,73 +145,68 @@ export function marginfiOpenPosition(
|
|
146
145
|
value: input.ataProgram ?? null,
|
147
146
|
},
|
148
147
|
rent: { index: 5, isWritable: false as boolean, value: input.rent ?? null },
|
149
|
-
solautoFeesWallet: {
|
150
|
-
index: 6,
|
151
|
-
isWritable: false as boolean,
|
152
|
-
value: input.solautoFeesWallet ?? null,
|
153
|
-
},
|
154
148
|
signerReferralState: {
|
155
|
-
index:
|
149
|
+
index: 6,
|
156
150
|
isWritable: false as boolean,
|
157
151
|
value: input.signerReferralState ?? null,
|
158
152
|
},
|
159
153
|
referredByState: {
|
160
|
-
index:
|
154
|
+
index: 7,
|
161
155
|
isWritable: false as boolean,
|
162
156
|
value: input.referredByState ?? null,
|
163
157
|
},
|
164
158
|
referredBySupplyTa: {
|
165
|
-
index:
|
159
|
+
index: 8,
|
166
160
|
isWritable: true as boolean,
|
167
161
|
value: input.referredBySupplyTa ?? null,
|
168
162
|
},
|
169
163
|
solautoPosition: {
|
170
|
-
index:
|
164
|
+
index: 9,
|
171
165
|
isWritable: true as boolean,
|
172
166
|
value: input.solautoPosition ?? null,
|
173
167
|
},
|
174
168
|
marginfiGroup: {
|
175
|
-
index:
|
169
|
+
index: 10,
|
176
170
|
isWritable: false as boolean,
|
177
171
|
value: input.marginfiGroup ?? null,
|
178
172
|
},
|
179
173
|
marginfiAccount: {
|
180
|
-
index:
|
174
|
+
index: 11,
|
181
175
|
isWritable: true as boolean,
|
182
176
|
value: input.marginfiAccount ?? null,
|
183
177
|
},
|
184
178
|
supplyMint: {
|
185
|
-
index:
|
179
|
+
index: 12,
|
186
180
|
isWritable: false as boolean,
|
187
181
|
value: input.supplyMint ?? null,
|
188
182
|
},
|
189
183
|
supplyBank: {
|
190
|
-
index:
|
184
|
+
index: 13,
|
191
185
|
isWritable: false as boolean,
|
192
186
|
value: input.supplyBank ?? null,
|
193
187
|
},
|
194
188
|
positionSupplyTa: {
|
195
|
-
index:
|
189
|
+
index: 14,
|
196
190
|
isWritable: true as boolean,
|
197
191
|
value: input.positionSupplyTa ?? null,
|
198
192
|
},
|
199
193
|
debtMint: {
|
200
|
-
index:
|
194
|
+
index: 15,
|
201
195
|
isWritable: false as boolean,
|
202
196
|
value: input.debtMint ?? null,
|
203
197
|
},
|
204
198
|
debtBank: {
|
205
|
-
index:
|
199
|
+
index: 16,
|
206
200
|
isWritable: false as boolean,
|
207
201
|
value: input.debtBank ?? null,
|
208
202
|
},
|
209
203
|
positionDebtTa: {
|
210
|
-
index:
|
204
|
+
index: 17,
|
211
205
|
isWritable: true as boolean,
|
212
206
|
value: input.positionDebtTa ?? null,
|
213
207
|
},
|
214
208
|
signerDebtTa: {
|
215
|
-
index:
|
209
|
+
index: 18,
|
216
210
|
isWritable: true as boolean,
|
217
211
|
value: input.signerDebtTa ?? null,
|
218
212
|
},
|
@@ -51,7 +51,10 @@ import {
|
|
51
51
|
getMaxLiqUtilizationRateBps,
|
52
52
|
uint8ArrayToBigInt,
|
53
53
|
} from "../utils/numberUtils";
|
54
|
-
import {
|
54
|
+
import {
|
55
|
+
eligibleForRebalance,
|
56
|
+
positionStateWithLatestPrices,
|
57
|
+
} from "../utils/solauto/generalUtils";
|
55
58
|
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
56
59
|
import {
|
57
60
|
createMarginfiProgram,
|
@@ -68,6 +71,7 @@ import {
|
|
68
71
|
getJupiterErrorFromName,
|
69
72
|
JUPITER_PROGRAM_ID,
|
70
73
|
} from "../jupiter-sdk";
|
74
|
+
import { PRICES } from "../constants";
|
71
75
|
|
72
76
|
interface wSolTokenUsage {
|
73
77
|
wSolTokenAccount: PublicKey;
|
@@ -577,7 +581,7 @@ export async function getTransactionChores(
|
|
577
581
|
return [choresBefore, choresAfter];
|
578
582
|
}
|
579
583
|
|
580
|
-
export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
584
|
+
export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
581
585
|
if (
|
582
586
|
client.solautoPositionState!.liqUtilizationRateBps >
|
583
587
|
getMaxLiqUtilizationRateBps(
|
@@ -595,20 +599,21 @@ export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
|
595
599
|
return false;
|
596
600
|
}
|
597
601
|
|
598
|
-
const
|
599
|
-
client.solautoPositionData.state
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
oldDebt;
|
602
|
+
const oldStateWithLatestPrices = await positionStateWithLatestPrices(
|
603
|
+
client.solautoPositionData.state,
|
604
|
+
PRICES[client.supplyMint.toString()].price,
|
605
|
+
PRICES[client.debtMint.toString()].price
|
606
|
+
);
|
607
|
+
const utilizationRateDiff = Math.abs(
|
608
|
+
(client.solautoPositionState?.liqUtilizationRateBps ?? 0) -
|
609
|
+
oldStateWithLatestPrices.liqUtilizationRateBps
|
610
|
+
);
|
608
611
|
|
609
612
|
if (
|
610
|
-
|
611
|
-
|
613
|
+
client.livePositionUpdates.supplyAdjustment === BigInt(0) &&
|
614
|
+
client.livePositionUpdates.debtAdjustment === BigInt(0) &&
|
615
|
+
utilizationRateDiff / oldStateWithLatestPrices.liqUtilizationRateBps >=
|
616
|
+
0.005
|
612
617
|
) {
|
613
618
|
return true;
|
614
619
|
}
|
@@ -674,7 +679,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
674
679
|
|
675
680
|
let tx = transactionBuilder();
|
676
681
|
|
677
|
-
if (requiresRefreshBeforeRebalance(client)) {
|
682
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
678
683
|
tx = tx.add(client.refresh());
|
679
684
|
}
|
680
685
|
|
@@ -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(
|