@haven-fi/solauto-sdk 1.0.196 → 1.0.198
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +8 -10
- package/dist/constants/marginfiAccounts.d.ts +4 -1
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +28 -32
- 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/types/accounts.d.ts +0 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +16 -11
- package/local/updateMarginfiLUT.ts +14 -12
- package/package.json +2 -1
- package/src/clients/solautoMarginfiClient.ts +18 -10
- package/src/constants/marginfiAccounts.ts +29 -32
- package/src/generated/instructions/marginfiOpenPosition.ts +13 -19
- package/src/types/accounts.ts +0 -1
- package/src/utils/marginfiUtils.ts +19 -10
- package/tests/unit/accounts.ts +32 -0
- package/tests/unit/lookupTables.ts +19 -12
- package/tests/unit/rebalanceCalculations.ts +2 -1
|
@@ -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,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;
|
|
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,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAO,CAAC,WAAW,CAAkB;IAE9B,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,EAAE,MAAM,CAAa;IAC3C,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAG5B,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,6BAA6B,EAAG,SAAS,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAsE1C,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;IA8C9B,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"}
|
|
@@ -39,12 +39,11 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
39
39
|
const marginfiAccountData = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(this.umi, (0, umi_1.publicKey)(this.marginfiAccountPk), { commitment: "confirmed" });
|
|
40
40
|
this.marginfiGroup = new web3_js_1.PublicKey(marginfiAccountData
|
|
41
41
|
? marginfiAccountData.group.toString()
|
|
42
|
-
: args.marginfiGroup ??
|
|
43
|
-
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()].marginfiGroup ??
|
|
44
|
-
marginfiAccounts_1.DEFAULT_MARGINFI_GROUP);
|
|
42
|
+
: (args.marginfiGroup ?? marginfiAccounts_1.DEFAULT_MARGINFI_GROUP));
|
|
45
43
|
this.marginfiSupplyAccounts =
|
|
46
|
-
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()];
|
|
47
|
-
this.marginfiDebtAccounts =
|
|
44
|
+
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.supplyMint.toString()];
|
|
45
|
+
this.marginfiDebtAccounts =
|
|
46
|
+
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.debtMint.toString()];
|
|
48
47
|
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
|
49
48
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
|
50
49
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
|
@@ -108,7 +107,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
108
107
|
return [0, 0];
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
111
|
-
const [maxLtv, liqThreshold] = await (0, marginfiUtils_1.getMaxLtvAndLiqThreshold)(this.umi, {
|
|
110
|
+
const [maxLtv, liqThreshold] = await (0, marginfiUtils_1.getMaxLtvAndLiqThreshold)(this.umi, this.marginfiGroup, {
|
|
112
111
|
mint: this.supplyMint,
|
|
113
112
|
}, {
|
|
114
113
|
mint: this.debtMint,
|
|
@@ -140,7 +139,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
140
139
|
signer: this.signer,
|
|
141
140
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
|
142
141
|
solautoFeesWallet: (0, umi_1.publicKey)(this.solautoFeesWallet),
|
|
143
|
-
solautoFeesSupplyTa: (0, umi_1.publicKey)(this.solautoFeesSupplyTa),
|
|
144
142
|
signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
|
|
145
143
|
referredByState: this.referredByState
|
|
146
144
|
? (0, umi_1.publicKey)(this.referredByState)
|
|
@@ -292,8 +290,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
292
290
|
});
|
|
293
291
|
}
|
|
294
292
|
rebalance(rebalanceStep, jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps) {
|
|
295
|
-
const inputIsSupply =
|
|
296
|
-
const outputIsSupply =
|
|
293
|
+
const inputIsSupply = new web3_js_1.PublicKey(jupQuote.inputMint).equals(this.supplyMint);
|
|
294
|
+
const outputIsSupply = new web3_js_1.PublicKey(jupQuote.outputMint).equals(this.supplyMint);
|
|
297
295
|
const needSupplyAccounts = (inputIsSupply && rebalanceStep === "A") ||
|
|
298
296
|
(outputIsSupply && rebalanceStep === "B") ||
|
|
299
297
|
(inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
|
@@ -435,7 +433,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
435
433
|
if (state) {
|
|
436
434
|
return state;
|
|
437
435
|
}
|
|
438
|
-
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, !this.selfManaged && this.solautoPositionData === null
|
|
436
|
+
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.marginfiGroup, !this.selfManaged && this.solautoPositionData === null
|
|
439
437
|
? this.supplyMint
|
|
440
438
|
: undefined, !this.selfManaged && this.solautoPositionData === null
|
|
441
439
|
? this.debtMint
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
|
2
2
|
export declare const DEFAULT_MARGINFI_GROUP = "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
|
3
|
+
export declare const DEFAULT_PUBKEY: string;
|
|
3
4
|
export declare const MARGINFI_ACCOUNTS: {
|
|
4
|
-
[
|
|
5
|
+
[group: string]: {
|
|
6
|
+
[token: string]: MarginfiAssetAccounts;
|
|
7
|
+
};
|
|
5
8
|
};
|
|
6
9
|
export declare const MARGINFI_ACCOUNTS_LOOKUP_TABLE = "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
|
|
7
10
|
//# sourceMappingURL=marginfiAccounts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginfiAccounts.d.ts","sourceRoot":"","sources":["../../src/constants/marginfiAccounts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,eAAO,MAAM,sBAAsB,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"marginfiAccounts.d.ts","sourceRoot":"","sources":["../../src/constants/marginfiAccounts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,eAAO,MAAM,sBAAsB,iDAAiD,CAAC;AAErF,eAAO,MAAM,cAAc,QAA+B,CAAC;AAE3D,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAAA;KAAE,CAAA;CA2B5F,CAAC;AAEF,eAAO,MAAM,8BAA8B,iDAAiD,CAAC"}
|
|
@@ -1,41 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MARGINFI_ACCOUNTS_LOOKUP_TABLE = exports.MARGINFI_ACCOUNTS = exports.DEFAULT_MARGINFI_GROUP = void 0;
|
|
3
|
+
exports.MARGINFI_ACCOUNTS_LOOKUP_TABLE = exports.MARGINFI_ACCOUNTS = exports.DEFAULT_PUBKEY = exports.DEFAULT_MARGINFI_GROUP = void 0;
|
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
|
5
5
|
const tokenConstants_1 = require("./tokenConstants");
|
|
6
6
|
const web3_js_1 = require("@solana/web3.js");
|
|
7
7
|
exports.DEFAULT_MARGINFI_GROUP = "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
|
8
|
-
|
|
8
|
+
exports.DEFAULT_PUBKEY = web3_js_1.PublicKey.default.toString();
|
|
9
9
|
exports.MARGINFI_ACCOUNTS = {
|
|
10
|
-
[
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
|
37
|
-
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
|
38
|
-
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
|
39
|
-
},
|
|
10
|
+
[exports.DEFAULT_MARGINFI_GROUP.toString()]: {
|
|
11
|
+
[spl_token_1.NATIVE_MINT.toString()]: {
|
|
12
|
+
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
|
13
|
+
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
|
14
|
+
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
|
15
|
+
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE"
|
|
16
|
+
},
|
|
17
|
+
[tokenConstants_1.USDC_MINT]: {
|
|
18
|
+
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
|
19
|
+
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
|
20
|
+
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
|
21
|
+
priceOracle: "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX"
|
|
22
|
+
},
|
|
23
|
+
[tokenConstants_1.B_SOL]: {
|
|
24
|
+
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
|
25
|
+
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
|
26
|
+
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
|
27
|
+
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
|
28
|
+
},
|
|
29
|
+
[tokenConstants_1.JUP]: {
|
|
30
|
+
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
|
31
|
+
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
|
32
|
+
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
|
33
|
+
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
|
34
|
+
}
|
|
35
|
+
}
|
|
40
36
|
};
|
|
41
37
|
exports.MARGINFI_ACCOUNTS_LOOKUP_TABLE = "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
|
|
@@ -16,7 +16,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
|
16
16
|
ataProgram?: PublicKey | Pda;
|
|
17
17
|
rent?: PublicKey | Pda;
|
|
18
18
|
solautoFeesWallet: PublicKey | Pda;
|
|
19
|
-
solautoFeesSupplyTa: PublicKey | Pda;
|
|
20
19
|
signerReferralState: PublicKey | Pda;
|
|
21
20
|
referredByState?: PublicKey | Pda;
|
|
22
21
|
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,iBAAiB,EAAE,SAAS,GAAG,GAAG,CAAC;IACnC,mBAAmB,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,
|
|
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,iBAAiB,EAAE,SAAS,GAAG,GAAG,CAAC;IACnC,mBAAmB,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,eAAe,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,kBAAkB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACrC,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,eAAe,EAAE,SAAS,GAAG,GAAG,GAAG,MAAM,CAAC;IAC1C,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC;IAC5B,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC;IAC5B,gBAAgB,EAAE,SAAS,GAAG,GAAG,CAAC;IAClC,QAAQ,EAAE,SAAS,GAAG,GAAG,CAAC;IAC1B,QAAQ,EAAE,SAAS,GAAG,GAAG,CAAC;IAC1B,cAAc,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;CAChC,CAAC;AAGF,MAAM,MAAM,mCAAmC,GAAG;IAChD,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,kBAAkB,CAAC;IACjC,sBAAsB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CACxC,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,CAiKpB"}
|
|
@@ -58,73 +58,68 @@ function marginfiOpenPosition(context, input) {
|
|
|
58
58
|
isWritable: false,
|
|
59
59
|
value: input.solautoFeesWallet ?? null,
|
|
60
60
|
},
|
|
61
|
-
solautoFeesSupplyTa: {
|
|
62
|
-
index: 7,
|
|
63
|
-
isWritable: true,
|
|
64
|
-
value: input.solautoFeesSupplyTa ?? null,
|
|
65
|
-
},
|
|
66
61
|
signerReferralState: {
|
|
67
|
-
index:
|
|
62
|
+
index: 7,
|
|
68
63
|
isWritable: false,
|
|
69
64
|
value: input.signerReferralState ?? null,
|
|
70
65
|
},
|
|
71
66
|
referredByState: {
|
|
72
|
-
index:
|
|
67
|
+
index: 8,
|
|
73
68
|
isWritable: false,
|
|
74
69
|
value: input.referredByState ?? null,
|
|
75
70
|
},
|
|
76
71
|
referredBySupplyTa: {
|
|
77
|
-
index:
|
|
72
|
+
index: 9,
|
|
78
73
|
isWritable: true,
|
|
79
74
|
value: input.referredBySupplyTa ?? null,
|
|
80
75
|
},
|
|
81
76
|
solautoPosition: {
|
|
82
|
-
index:
|
|
77
|
+
index: 10,
|
|
83
78
|
isWritable: true,
|
|
84
79
|
value: input.solautoPosition ?? null,
|
|
85
80
|
},
|
|
86
81
|
marginfiGroup: {
|
|
87
|
-
index:
|
|
82
|
+
index: 11,
|
|
88
83
|
isWritable: false,
|
|
89
84
|
value: input.marginfiGroup ?? null,
|
|
90
85
|
},
|
|
91
86
|
marginfiAccount: {
|
|
92
|
-
index:
|
|
87
|
+
index: 12,
|
|
93
88
|
isWritable: true,
|
|
94
89
|
value: input.marginfiAccount ?? null,
|
|
95
90
|
},
|
|
96
91
|
supplyMint: {
|
|
97
|
-
index:
|
|
92
|
+
index: 13,
|
|
98
93
|
isWritable: false,
|
|
99
94
|
value: input.supplyMint ?? null,
|
|
100
95
|
},
|
|
101
96
|
supplyBank: {
|
|
102
|
-
index:
|
|
97
|
+
index: 14,
|
|
103
98
|
isWritable: false,
|
|
104
99
|
value: input.supplyBank ?? null,
|
|
105
100
|
},
|
|
106
101
|
positionSupplyTa: {
|
|
107
|
-
index:
|
|
102
|
+
index: 15,
|
|
108
103
|
isWritable: true,
|
|
109
104
|
value: input.positionSupplyTa ?? null,
|
|
110
105
|
},
|
|
111
106
|
debtMint: {
|
|
112
|
-
index:
|
|
107
|
+
index: 16,
|
|
113
108
|
isWritable: false,
|
|
114
109
|
value: input.debtMint ?? null,
|
|
115
110
|
},
|
|
116
111
|
debtBank: {
|
|
117
|
-
index:
|
|
112
|
+
index: 17,
|
|
118
113
|
isWritable: false,
|
|
119
114
|
value: input.debtBank ?? null,
|
|
120
115
|
},
|
|
121
116
|
positionDebtTa: {
|
|
122
|
-
index:
|
|
117
|
+
index: 18,
|
|
123
118
|
isWritable: true,
|
|
124
119
|
value: input.positionDebtTa ?? null,
|
|
125
120
|
},
|
|
126
121
|
signerDebtTa: {
|
|
127
|
-
index:
|
|
122
|
+
index: 19,
|
|
128
123
|
isWritable: true,
|
|
129
124
|
value: input.signerDebtTa ?? null,
|
|
130
125
|
},
|
package/dist/types/accounts.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -5,7 +5,7 @@ import { MarginfiAssetAccounts } from "../types/accounts";
|
|
|
5
5
|
import { PositionState } from "../generated";
|
|
6
6
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
|
7
7
|
export declare function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts;
|
|
8
|
-
export declare function getMaxLtvAndLiqThreshold(umi: Umi, supply: {
|
|
8
|
+
export declare function getMaxLtvAndLiqThreshold(umi: Umi, marginfiGroup: PublicKey, supply: {
|
|
9
9
|
mint: PublicKey;
|
|
10
10
|
bank?: Bank | null;
|
|
11
11
|
}, debt: {
|
|
@@ -17,6 +17,6 @@ export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: P
|
|
|
17
17
|
supplyMint?: PublicKey;
|
|
18
18
|
debtMint?: PublicKey;
|
|
19
19
|
}[]>;
|
|
20
|
-
export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, supplyMint?: PublicKey, debtMint?: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
|
|
20
|
+
export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, marginfiGroup?: PublicKey, supplyMint?: PublicKey, debtMint?: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
|
|
21
21
|
export declare function getUpToDateShareValues(umi: Umi, bank: Bank): Promise<[number, number]>;
|
|
22
22
|
//# 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;AAczB,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,
|
|
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;AAczB,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,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,CA+D3B;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,CAwDA;AAgED,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,CAuKpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3B"}
|
|
@@ -15,24 +15,26 @@ const marginfiAccounts_1 = require("../constants/marginfiAccounts");
|
|
|
15
15
|
const generalAccounts_1 = require("../constants/generalAccounts");
|
|
16
16
|
const constants_1 = require("../constants");
|
|
17
17
|
function findMarginfiAccounts(bank) {
|
|
18
|
-
for (const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
for (const group in marginfiAccounts_1.MARGINFI_ACCOUNTS) {
|
|
19
|
+
for (const key in marginfiAccounts_1.MARGINFI_ACCOUNTS[group]) {
|
|
20
|
+
const account = marginfiAccounts_1.MARGINFI_ACCOUNTS[group][key];
|
|
21
|
+
if (account.bank.toString().toLowerCase() === bank.toString().toLowerCase()) {
|
|
22
|
+
return account;
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
|
25
27
|
}
|
|
26
|
-
async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
|
28
|
+
async function getMaxLtvAndLiqThreshold(umi, marginfiGroup, supply, debt, supplyPrice) {
|
|
27
29
|
if (!supply.bank && supply.mint.equals(web3_js_1.PublicKey.default)) {
|
|
28
30
|
return [0, 0];
|
|
29
31
|
}
|
|
30
32
|
if (!supply.bank || supply.bank === null) {
|
|
31
|
-
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[supply.mint.toString()].bank), { commitment: "confirmed" });
|
|
33
|
+
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup.toString()][supply.mint.toString()].bank), { commitment: "confirmed" });
|
|
32
34
|
}
|
|
33
35
|
if ((!debt.bank || debt.bank === null) &&
|
|
34
36
|
!debt.mint.equals(web3_js_1.PublicKey.default)) {
|
|
35
|
-
debt.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[debt.mint.toString()].bank), { commitment: "confirmed" });
|
|
37
|
+
debt.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup.toString()][debt.mint.toString()].bank), { commitment: "confirmed" });
|
|
36
38
|
}
|
|
37
39
|
if (!supplyPrice) {
|
|
38
40
|
const [price] = await (0, generalUtils_1.fetchTokenPrices)([
|
|
@@ -136,13 +138,16 @@ async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
|
|
|
136
138
|
padding: new Uint8Array([]),
|
|
137
139
|
};
|
|
138
140
|
}
|
|
139
|
-
async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMint, debtMint, livePositionUpdates) {
|
|
141
|
+
async function getMarginfiAccountPositionState(umi, marginfiAccountPk, marginfiGroup, supplyMint, debtMint, livePositionUpdates) {
|
|
140
142
|
let marginfiAccount = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(marginfiAccountPk), { commitment: "confirmed" });
|
|
143
|
+
if (!marginfiGroup && marginfiAccount) {
|
|
144
|
+
marginfiGroup = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(marginfiAccount.group);
|
|
145
|
+
}
|
|
141
146
|
let supplyBank = supplyMint && supplyMint !== web3_js_1.PublicKey.default
|
|
142
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[supplyMint.toString()].bank), { commitment: "confirmed" })
|
|
147
|
+
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][supplyMint.toString()].bank), { commitment: "confirmed" })
|
|
143
148
|
: null;
|
|
144
149
|
let debtBank = debtMint && debtMint !== web3_js_1.PublicKey.default
|
|
145
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[debtMint.toString()].bank), { commitment: "confirmed" })
|
|
150
|
+
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][debtMint.toString()].bank), { commitment: "confirmed" })
|
|
146
151
|
: null;
|
|
147
152
|
let supplyUsage = undefined;
|
|
148
153
|
let debtUsage = undefined;
|
|
@@ -195,7 +200,7 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
|
195
200
|
debtUsage = await getTokenUsage(umi, debtBank, false, 0, livePositionUpdates?.debtAdjustment);
|
|
196
201
|
}
|
|
197
202
|
const supplyPrice = (0, generalUtils_1.safeGetPrice)(supplyMint);
|
|
198
|
-
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(umi, {
|
|
203
|
+
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(umi, marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP), {
|
|
199
204
|
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint),
|
|
200
205
|
bank: supplyBank,
|
|
201
206
|
}, {
|
|
@@ -10,18 +10,20 @@ import { updateLookupTable } from "./shared";
|
|
|
10
10
|
const LOOKUP_TABLE_ADDRESS = new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE);
|
|
11
11
|
|
|
12
12
|
async function addBanks() {
|
|
13
|
-
for (const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
for (const group in MARGINFI_ACCOUNTS) {
|
|
14
|
+
for (const key in MARGINFI_ACCOUNTS[group]) {
|
|
15
|
+
const accounts = MARGINFI_ACCOUNTS[group][key];
|
|
16
|
+
await updateLookupTable(
|
|
17
|
+
[
|
|
18
|
+
key,
|
|
19
|
+
accounts.bank,
|
|
20
|
+
accounts.liquidityVault,
|
|
21
|
+
accounts.vaultAuthority,
|
|
22
|
+
accounts.priceOracle,
|
|
23
|
+
],
|
|
24
|
+
LOOKUP_TABLE_ADDRESS
|
|
25
|
+
);
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haven-fi/solauto-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.198",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "Typescript SDK for the Solauto program on the Solana blockchain",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@metaplex-foundation/umi-web3js-adapters": "^0.9.1",
|
|
23
23
|
"@solana/spl-token": "^0.4.0",
|
|
24
24
|
"@solana/web3.js": "^1.92.1",
|
|
25
|
+
"@sqds/multisig": "^2.1.3",
|
|
25
26
|
"@types/node": "^20.14.8",
|
|
26
27
|
"bs58": "^5.0.0",
|
|
27
28
|
"cross-fetch": "^4.0.0",
|
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
safeFetchAllMarginfiAccount,
|
|
48
48
|
safeFetchMarginfiAccount,
|
|
49
49
|
} from "../marginfi-sdk";
|
|
50
|
-
import { JupSwapDetails } from "../utils/jupiterUtils";
|
|
51
50
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
|
52
51
|
import {
|
|
53
52
|
findMarginfiAccounts,
|
|
@@ -115,14 +114,17 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
115
114
|
this.marginfiGroup = new PublicKey(
|
|
116
115
|
marginfiAccountData
|
|
117
116
|
? marginfiAccountData.group.toString()
|
|
118
|
-
: args.marginfiGroup ??
|
|
119
|
-
MARGINFI_ACCOUNTS[this.supplyMint.toString()].marginfiGroup ??
|
|
120
|
-
DEFAULT_MARGINFI_GROUP
|
|
117
|
+
: (args.marginfiGroup ?? DEFAULT_MARGINFI_GROUP)
|
|
121
118
|
);
|
|
122
119
|
|
|
123
120
|
this.marginfiSupplyAccounts =
|
|
124
|
-
MARGINFI_ACCOUNTS[this.
|
|
125
|
-
|
|
121
|
+
MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][
|
|
122
|
+
this.supplyMint.toString()
|
|
123
|
+
]!;
|
|
124
|
+
this.marginfiDebtAccounts =
|
|
125
|
+
MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][
|
|
126
|
+
this.debtMint.toString()
|
|
127
|
+
]!;
|
|
126
128
|
|
|
127
129
|
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
|
128
130
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
|
@@ -225,6 +227,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
225
227
|
} else {
|
|
226
228
|
const [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
|
227
229
|
this.umi,
|
|
230
|
+
this.marginfiGroup,
|
|
228
231
|
{
|
|
229
232
|
mint: this.supplyMint,
|
|
230
233
|
},
|
|
@@ -270,7 +273,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
270
273
|
signer: this.signer,
|
|
271
274
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
|
272
275
|
solautoFeesWallet: publicKey(this.solautoFeesWallet),
|
|
273
|
-
solautoFeesSupplyTa: publicKey(this.solautoFeesSupplyTa),
|
|
274
276
|
signerReferralState: publicKey(this.referralStateManager.referralState),
|
|
275
277
|
referredByState: this.referredByState
|
|
276
278
|
? publicKey(this.referredByState)
|
|
@@ -459,8 +461,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
459
461
|
flashLoan?: FlashLoanDetails,
|
|
460
462
|
targetLiqUtilizationRateBps?: number
|
|
461
463
|
): TransactionBuilder {
|
|
462
|
-
const inputIsSupply =
|
|
463
|
-
|
|
464
|
+
const inputIsSupply = new PublicKey(jupQuote.inputMint).equals(
|
|
465
|
+
this.supplyMint
|
|
466
|
+
);
|
|
467
|
+
const outputIsSupply = new PublicKey(jupQuote.outputMint).equals(
|
|
468
|
+
this.supplyMint
|
|
469
|
+
);
|
|
464
470
|
const needSupplyAccounts =
|
|
465
471
|
(inputIsSupply && rebalanceStep === "A") ||
|
|
466
472
|
(outputIsSupply && rebalanceStep === "B") ||
|
|
@@ -518,7 +524,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
518
524
|
: undefined,
|
|
519
525
|
rebalanceType,
|
|
520
526
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
|
521
|
-
targetInAmountBaseUnit:
|
|
527
|
+
targetInAmountBaseUnit:
|
|
528
|
+
rebalanceStep === "A" ? parseInt(jupQuote.inAmount) : null,
|
|
522
529
|
});
|
|
523
530
|
}
|
|
524
531
|
|
|
@@ -654,6 +661,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
654
661
|
const freshState = await getMarginfiAccountPositionState(
|
|
655
662
|
this.umi,
|
|
656
663
|
this.marginfiAccountPk,
|
|
664
|
+
this.marginfiGroup,
|
|
657
665
|
!this.selfManaged && this.solautoPositionData === null
|
|
658
666
|
? this.supplyMint
|
|
659
667
|
: undefined,
|
|
@@ -5,38 +5,35 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
5
5
|
|
|
6
6
|
export const DEFAULT_MARGINFI_GROUP = "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
|
7
7
|
|
|
8
|
-
const DEFAULT_PUBKEY = PublicKey.default.toString();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
|
38
|
-
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
|
39
|
-
},
|
|
8
|
+
export const DEFAULT_PUBKEY = PublicKey.default.toString();
|
|
9
|
+
|
|
10
|
+
export const MARGINFI_ACCOUNTS: { [group: string]: { [token: string]: MarginfiAssetAccounts } } = {
|
|
11
|
+
[DEFAULT_MARGINFI_GROUP.toString()]: {
|
|
12
|
+
[NATIVE_MINT.toString()]: {
|
|
13
|
+
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
|
14
|
+
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
|
15
|
+
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
|
16
|
+
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE"
|
|
17
|
+
},
|
|
18
|
+
[USDC_MINT]: {
|
|
19
|
+
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
|
20
|
+
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
|
21
|
+
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
|
22
|
+
priceOracle: "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX"
|
|
23
|
+
},
|
|
24
|
+
[B_SOL]: {
|
|
25
|
+
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
|
26
|
+
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
|
27
|
+
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
|
28
|
+
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
|
29
|
+
},
|
|
30
|
+
[JUP]: {
|
|
31
|
+
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
|
32
|
+
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
|
33
|
+
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
|
34
|
+
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
|
35
|
+
}
|
|
36
|
+
}
|
|
40
37
|
};
|
|
41
38
|
|
|
42
39
|
export const MARGINFI_ACCOUNTS_LOOKUP_TABLE = "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
|
|
@@ -48,7 +48,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
|
48
48
|
ataProgram?: PublicKey | Pda;
|
|
49
49
|
rent?: PublicKey | Pda;
|
|
50
50
|
solautoFeesWallet: PublicKey | Pda;
|
|
51
|
-
solautoFeesSupplyTa: PublicKey | Pda;
|
|
52
51
|
signerReferralState: PublicKey | Pda;
|
|
53
52
|
referredByState?: PublicKey | Pda;
|
|
54
53
|
referredBySupplyTa?: PublicKey | Pda;
|
|
@@ -152,73 +151,68 @@ export function marginfiOpenPosition(
|
|
|
152
151
|
isWritable: false as boolean,
|
|
153
152
|
value: input.solautoFeesWallet ?? null,
|
|
154
153
|
},
|
|
155
|
-
solautoFeesSupplyTa: {
|
|
156
|
-
index: 7,
|
|
157
|
-
isWritable: true as boolean,
|
|
158
|
-
value: input.solautoFeesSupplyTa ?? null,
|
|
159
|
-
},
|
|
160
154
|
signerReferralState: {
|
|
161
|
-
index:
|
|
155
|
+
index: 7,
|
|
162
156
|
isWritable: false as boolean,
|
|
163
157
|
value: input.signerReferralState ?? null,
|
|
164
158
|
},
|
|
165
159
|
referredByState: {
|
|
166
|
-
index:
|
|
160
|
+
index: 8,
|
|
167
161
|
isWritable: false as boolean,
|
|
168
162
|
value: input.referredByState ?? null,
|
|
169
163
|
},
|
|
170
164
|
referredBySupplyTa: {
|
|
171
|
-
index:
|
|
165
|
+
index: 9,
|
|
172
166
|
isWritable: true as boolean,
|
|
173
167
|
value: input.referredBySupplyTa ?? null,
|
|
174
168
|
},
|
|
175
169
|
solautoPosition: {
|
|
176
|
-
index:
|
|
170
|
+
index: 10,
|
|
177
171
|
isWritable: true as boolean,
|
|
178
172
|
value: input.solautoPosition ?? null,
|
|
179
173
|
},
|
|
180
174
|
marginfiGroup: {
|
|
181
|
-
index:
|
|
175
|
+
index: 11,
|
|
182
176
|
isWritable: false as boolean,
|
|
183
177
|
value: input.marginfiGroup ?? null,
|
|
184
178
|
},
|
|
185
179
|
marginfiAccount: {
|
|
186
|
-
index:
|
|
180
|
+
index: 12,
|
|
187
181
|
isWritable: true as boolean,
|
|
188
182
|
value: input.marginfiAccount ?? null,
|
|
189
183
|
},
|
|
190
184
|
supplyMint: {
|
|
191
|
-
index:
|
|
185
|
+
index: 13,
|
|
192
186
|
isWritable: false as boolean,
|
|
193
187
|
value: input.supplyMint ?? null,
|
|
194
188
|
},
|
|
195
189
|
supplyBank: {
|
|
196
|
-
index:
|
|
190
|
+
index: 14,
|
|
197
191
|
isWritable: false as boolean,
|
|
198
192
|
value: input.supplyBank ?? null,
|
|
199
193
|
},
|
|
200
194
|
positionSupplyTa: {
|
|
201
|
-
index:
|
|
195
|
+
index: 15,
|
|
202
196
|
isWritable: true as boolean,
|
|
203
197
|
value: input.positionSupplyTa ?? null,
|
|
204
198
|
},
|
|
205
199
|
debtMint: {
|
|
206
|
-
index:
|
|
200
|
+
index: 16,
|
|
207
201
|
isWritable: false as boolean,
|
|
208
202
|
value: input.debtMint ?? null,
|
|
209
203
|
},
|
|
210
204
|
debtBank: {
|
|
211
|
-
index:
|
|
205
|
+
index: 17,
|
|
212
206
|
isWritable: false as boolean,
|
|
213
207
|
value: input.debtBank ?? null,
|
|
214
208
|
},
|
|
215
209
|
positionDebtTa: {
|
|
216
|
-
index:
|
|
210
|
+
index: 18,
|
|
217
211
|
isWritable: true as boolean,
|
|
218
212
|
value: input.positionDebtTa ?? null,
|
|
219
213
|
},
|
|
220
214
|
signerDebtTa: {
|
|
221
|
-
index:
|
|
215
|
+
index: 19,
|
|
222
216
|
isWritable: true as boolean,
|
|
223
217
|
value: input.signerDebtTa ?? null,
|
|
224
218
|
},
|
package/src/types/accounts.ts
CHANGED
|
@@ -28,12 +28,14 @@ import { LivePositionUpdates } from "./solauto/generalUtils";
|
|
|
28
28
|
import { TOKEN_INFO } from "../constants";
|
|
29
29
|
|
|
30
30
|
export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
|
31
|
-
for (const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
for (const group in MARGINFI_ACCOUNTS) {
|
|
32
|
+
for (const key in MARGINFI_ACCOUNTS[group]) {
|
|
33
|
+
const account = MARGINFI_ACCOUNTS[group][key];
|
|
34
|
+
if (
|
|
35
|
+
account.bank.toString().toLowerCase() === bank.toString().toLowerCase()
|
|
36
|
+
) {
|
|
37
|
+
return account;
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
|
@@ -41,6 +43,7 @@ export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
|
|
41
43
|
|
|
42
44
|
export async function getMaxLtvAndLiqThreshold(
|
|
43
45
|
umi: Umi,
|
|
46
|
+
marginfiGroup: PublicKey,
|
|
44
47
|
supply: {
|
|
45
48
|
mint: PublicKey;
|
|
46
49
|
bank?: Bank | null;
|
|
@@ -58,7 +61,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
|
58
61
|
if (!supply.bank || supply.bank === null) {
|
|
59
62
|
supply.bank = await safeFetchBank(
|
|
60
63
|
umi,
|
|
61
|
-
publicKey(MARGINFI_ACCOUNTS[supply.mint.toString()].bank),
|
|
64
|
+
publicKey(MARGINFI_ACCOUNTS[marginfiGroup.toString()][supply.mint.toString()].bank),
|
|
62
65
|
{ commitment: "confirmed" }
|
|
63
66
|
);
|
|
64
67
|
}
|
|
@@ -69,7 +72,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
|
69
72
|
) {
|
|
70
73
|
debt.bank = await safeFetchBank(
|
|
71
74
|
umi,
|
|
72
|
-
publicKey(MARGINFI_ACCOUNTS[debt.mint.toString()].bank),
|
|
75
|
+
publicKey(MARGINFI_ACCOUNTS[marginfiGroup.toString()][debt.mint.toString()].bank),
|
|
73
76
|
{ commitment: "confirmed" }
|
|
74
77
|
);
|
|
75
78
|
}
|
|
@@ -244,6 +247,7 @@ async function getTokenUsage(
|
|
|
244
247
|
export async function getMarginfiAccountPositionState(
|
|
245
248
|
umi: Umi,
|
|
246
249
|
marginfiAccountPk: PublicKey,
|
|
250
|
+
marginfiGroup?: PublicKey,
|
|
247
251
|
supplyMint?: PublicKey,
|
|
248
252
|
debtMint?: PublicKey,
|
|
249
253
|
livePositionUpdates?: LivePositionUpdates
|
|
@@ -254,11 +258,15 @@ export async function getMarginfiAccountPositionState(
|
|
|
254
258
|
{ commitment: "confirmed" }
|
|
255
259
|
);
|
|
256
260
|
|
|
261
|
+
if (!marginfiGroup && marginfiAccount) {
|
|
262
|
+
marginfiGroup = toWeb3JsPublicKey(marginfiAccount.group);
|
|
263
|
+
}
|
|
264
|
+
|
|
257
265
|
let supplyBank: Bank | null =
|
|
258
266
|
supplyMint && supplyMint !== PublicKey.default
|
|
259
267
|
? await safeFetchBank(
|
|
260
268
|
umi,
|
|
261
|
-
publicKey(MARGINFI_ACCOUNTS[supplyMint.toString()].bank),
|
|
269
|
+
publicKey(MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][supplyMint.toString()].bank),
|
|
262
270
|
{ commitment: "confirmed" }
|
|
263
271
|
)
|
|
264
272
|
: null;
|
|
@@ -266,7 +274,7 @@ export async function getMarginfiAccountPositionState(
|
|
|
266
274
|
debtMint && debtMint !== PublicKey.default
|
|
267
275
|
? await safeFetchBank(
|
|
268
276
|
umi,
|
|
269
|
-
publicKey(MARGINFI_ACCOUNTS[debtMint.toString()].bank),
|
|
277
|
+
publicKey(MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][debtMint.toString()].bank),
|
|
270
278
|
{ commitment: "confirmed" }
|
|
271
279
|
)
|
|
272
280
|
: null;
|
|
@@ -368,6 +376,7 @@ export async function getMarginfiAccountPositionState(
|
|
|
368
376
|
const supplyPrice = safeGetPrice(supplyMint!)!;
|
|
369
377
|
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
|
370
378
|
umi,
|
|
379
|
+
marginfiGroup ?? new PublicKey(DEFAULT_MARGINFI_GROUP),
|
|
371
380
|
{
|
|
372
381
|
mint: toWeb3JsPublicKey(supplyBank.mint),
|
|
373
382
|
bank: supplyBank,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import {
|
|
3
|
+
ALL_SUPPORTED_TOKENS,
|
|
4
|
+
TOKEN_INFO,
|
|
5
|
+
} from "../../src/constants/tokenConstants";
|
|
6
|
+
import {
|
|
7
|
+
buildHeliusApiUrl,
|
|
8
|
+
getSolanaRpcConnection,
|
|
9
|
+
} from "../../src/utils/solanaUtils";
|
|
10
|
+
import { publicKey } from "@metaplex-foundation/umi";
|
|
11
|
+
import { assert } from "chai";
|
|
12
|
+
|
|
13
|
+
describe("Assert Solauto fee token accounts are created", async () => {
|
|
14
|
+
it("all Solauto fee token accounts created", async () => {
|
|
15
|
+
let [_, umi] = getSolanaRpcConnection(
|
|
16
|
+
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const tokenAccounts = await umi.rpc.getAccounts(
|
|
20
|
+
ALL_SUPPORTED_TOKENS.map((x) => publicKey(x))
|
|
21
|
+
);
|
|
22
|
+
for (let i = 0; i < tokenAccounts.length; i++) {
|
|
23
|
+
if (!tokenAccounts[i].exists) {
|
|
24
|
+
console.log(
|
|
25
|
+
"Missing Solauto fees TA for ",
|
|
26
|
+
TOKEN_INFO[ALL_SUPPORTED_TOKENS[i].toString()].ticker
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
assert(tokenAccounts.filter((x) => !x.exists).length === 0);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { describe, it } from
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
2
|
import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import {
|
|
4
|
+
DEFAULT_PUBKEY,
|
|
4
5
|
MARGINFI_ACCOUNTS,
|
|
5
6
|
MARGINFI_ACCOUNTS_LOOKUP_TABLE,
|
|
6
7
|
} from "../../src/constants/marginfiAccounts";
|
|
@@ -19,18 +20,24 @@ describe("Assert lookup tables up-to-date", async () => {
|
|
|
19
20
|
const existingAccounts =
|
|
20
21
|
lookupTable.value?.state.addresses.map((x) => x.toString()) ?? [];
|
|
21
22
|
|
|
22
|
-
for (const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
tokenAccounts.liquidityVault,
|
|
28
|
-
tokenAccounts.vaultAuthority,
|
|
29
|
-
tokenAccounts.priceOracle,
|
|
30
|
-
];
|
|
23
|
+
for (const group in MARGINFI_ACCOUNTS) {
|
|
24
|
+
for (const key in MARGINFI_ACCOUNTS[group]) {
|
|
25
|
+
if (key === DEFAULT_PUBKEY) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const tokenAccounts = MARGINFI_ACCOUNTS[key];
|
|
30
|
+
const addresses = [
|
|
31
|
+
new PublicKey(key),
|
|
32
|
+
tokenAccounts.bank,
|
|
33
|
+
tokenAccounts.liquidityVault,
|
|
34
|
+
tokenAccounts.vaultAuthority,
|
|
35
|
+
tokenAccounts.priceOracle,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
if (addresses.find((x) => !existingAccounts.includes(x.toString()))) {
|
|
39
|
+
throw new Error("Marginfi accounts lookup table missing an account");
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
});
|
|
@@ -10,6 +10,7 @@ import { SolautoClient } from "../../src/clients/solautoClient";
|
|
|
10
10
|
import {
|
|
11
11
|
DCASettings,
|
|
12
12
|
LendingPlatform,
|
|
13
|
+
PositionType,
|
|
13
14
|
SolautoRebalanceType,
|
|
14
15
|
SolautoSettingsParameters,
|
|
15
16
|
TokenType,
|
|
@@ -175,11 +176,11 @@ async function getFakePosition(
|
|
|
175
176
|
rebalanceType: SolautoRebalanceType.Regular,
|
|
176
177
|
targetLiqUtilizationRateBps: 0,
|
|
177
178
|
flashLoanAmount: BigInt(0),
|
|
178
|
-
priceSlippageBps: 0,
|
|
179
179
|
padding1: [],
|
|
180
180
|
padding2: [],
|
|
181
181
|
padding: new Uint8Array([]),
|
|
182
182
|
},
|
|
183
|
+
positionType: PositionType.Leverage,
|
|
183
184
|
padding1: [],
|
|
184
185
|
padding: [],
|
|
185
186
|
publicKey: publicKey(PublicKey.default),
|