@haven-fi/solauto-sdk 1.0.70 → 1.0.72
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts +2 -0
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +35 -24
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +14 -4
- package/dist/constants/pythConstants.d.ts +2 -0
- package/dist/constants/pythConstants.d.ts.map +1 -1
- package/dist/constants/pythConstants.js +2 -0
- package/dist/constants/tokenConstants.d.ts +10 -4
- package/dist/constants/tokenConstants.d.ts.map +1 -1
- package/dist/constants/tokenConstants.js +21 -8
- package/dist/generated/errors/solauto.d.ts +2 -2
- package/dist/generated/errors/solauto.d.ts.map +1 -1
- package/dist/generated/errors/solauto.js +7 -7
- package/dist/marginfi-sdk/types/oracleSetup.d.ts +3 -2
- package/dist/marginfi-sdk/types/oracleSetup.d.ts.map +1 -1
- package/dist/marginfi-sdk/types/oracleSetup.js +2 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts +1 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts.map +1 -1
- package/dist/marginfi-sdk/types/wrappedI80F48.js +2 -2
- package/dist/types/accounts.d.ts +0 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.d.ts +1 -4
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +9 -15
- package/dist/utils/solauto/generalUtils.js +2 -2
- package/local/updateMarginfiLUT.ts +1 -1
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +46 -31
- package/src/constants/marginfiAccounts.ts +15 -5
- package/src/constants/pythConstants.ts +4 -2
- package/src/constants/tokenConstants.ts +26 -8
- package/src/generated/errors/solauto.ts +5 -5
- package/src/marginfi-sdk/types/oracleSetup.ts +2 -1
- package/src/marginfi-sdk/types/wrappedI80F48.ts +8 -3
- package/src/types/accounts.ts +0 -1
- package/src/utils/marginfiUtils.ts +13 -23
- package/src/utils/solauto/generalUtils.ts +3 -3
- package/tests/transactions/solautoMarginfi.ts +2 -2
@@ -20,6 +20,8 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
20
20
|
marginfiGroup: PublicKey;
|
21
21
|
marginfiSupplyAccounts: MarginfiAssetAccounts;
|
22
22
|
marginfiDebtAccounts: MarginfiAssetAccounts;
|
23
|
+
supplyPriceOracle: PublicKey;
|
24
|
+
debtPriceOracle: PublicKey;
|
23
25
|
intermediaryMarginfiAccountSigner?: Signer;
|
24
26
|
intermediaryMarginfiAccountPk: PublicKey;
|
25
27
|
intermediaryMarginfiAccount?: MarginfiAccount;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAGL,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AAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAgFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
@@ -40,12 +40,18 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
40
40
|
this.marginfiGroup = marginfiAccountData
|
41
41
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(marginfiAccountData.group)
|
42
42
|
: args.marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP);
|
43
|
-
this.marginfiSupplyAccounts =
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
this.marginfiSupplyAccounts =
|
44
|
+
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.supplyMint.toString()];
|
45
|
+
this.marginfiDebtAccounts = marginfiAccounts_1.MARGINFI_ACCOUNTS[this.debtMint.toString()];
|
46
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
47
|
+
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
48
|
+
// publicKey(this.marginfiSupplyAccounts.bank),
|
49
|
+
// publicKey(this.marginfiDebtAccounts.bank),
|
50
|
+
// ]);
|
51
|
+
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
52
|
+
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
53
|
+
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
54
|
+
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
49
55
|
if (!this.initialized) {
|
50
56
|
await this.setIntermediaryMarginfiDetails();
|
51
57
|
}
|
@@ -78,7 +84,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
78
84
|
return [
|
79
85
|
...super.lutAccountsToAdd(),
|
80
86
|
this.marginfiAccountPk,
|
81
|
-
...(this.signer.publicKey.toString() === this.authority.toString()
|
87
|
+
...(this.signer.publicKey.toString() === this.authority.toString()
|
88
|
+
? [this.intermediaryMarginfiAccountPk]
|
89
|
+
: []),
|
82
90
|
];
|
83
91
|
}
|
84
92
|
marginfiAccountInitialize() {
|
@@ -141,9 +149,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
141
149
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
142
150
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccount),
|
143
151
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
144
|
-
supplyPriceOracle: (0, umi_1.publicKey)(this.
|
152
|
+
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
145
153
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
146
|
-
debtPriceOracle: (0, umi_1.publicKey)(this.
|
154
|
+
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
147
155
|
solautoPosition: (0, umi_1.publicKey)(this.solautoPosition),
|
148
156
|
});
|
149
157
|
}
|
@@ -232,8 +240,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
232
240
|
let supplyPriceOracle = undefined;
|
233
241
|
let debtPriceOracle = undefined;
|
234
242
|
if (args.__kind === "Withdraw" || args.__kind === "Borrow") {
|
235
|
-
supplyPriceOracle = (0, umi_1.publicKey)(this.
|
236
|
-
debtPriceOracle = (0, umi_1.publicKey)(this.
|
243
|
+
supplyPriceOracle = (0, umi_1.publicKey)(this.supplyPriceOracle);
|
244
|
+
debtPriceOracle = (0, umi_1.publicKey)(this.debtPriceOracle);
|
237
245
|
}
|
238
246
|
return (0, generated_1.marginfiProtocolInteraction)(this.umi, {
|
239
247
|
signer: this.signer,
|
@@ -277,7 +285,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
277
285
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccountPk),
|
278
286
|
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), swapDetails.inputMint)),
|
279
287
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
280
|
-
supplyPriceOracle: (0, umi_1.publicKey)(this.
|
288
|
+
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
281
289
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
282
290
|
signerSupplyTa: this.selfManaged
|
283
291
|
? (0, umi_1.publicKey)(this.signerSupplyTa)
|
@@ -289,7 +297,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
289
297
|
? (0, umi_1.publicKey)(this.marginfiSupplyAccounts.vaultAuthority)
|
290
298
|
: undefined,
|
291
299
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
292
|
-
debtPriceOracle: (0, umi_1.publicKey)(this.
|
300
|
+
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
293
301
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtTa),
|
294
302
|
signerDebtTa: this.selfManaged ? (0, umi_1.publicKey)(this.signerDebtTa) : undefined,
|
295
303
|
vaultDebtTa: needDebtAccounts
|
@@ -326,17 +334,21 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
326
334
|
}));
|
327
335
|
}
|
328
336
|
flashRepay(flashLoanDetails) {
|
329
|
-
const
|
330
|
-
? this.marginfiSupplyAccounts
|
331
|
-
: this.marginfiDebtAccounts;
|
337
|
+
const accounts = flashLoanDetails.mint.equals(this.supplyMint)
|
338
|
+
? { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle }
|
339
|
+
: { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle };
|
332
340
|
const remainingAccounts = [];
|
333
341
|
let includedFlashLoanToken = false;
|
334
342
|
if (this.intermediaryMarginfiAccount) {
|
335
|
-
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach((x) => {
|
343
|
+
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(async (x) => {
|
336
344
|
if (x.active) {
|
337
|
-
if (x.bankPk ===
|
345
|
+
if (x.bankPk === accounts.data.bank) {
|
338
346
|
includedFlashLoanToken = true;
|
339
347
|
}
|
348
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
349
|
+
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
350
|
+
// const priceOracle = bankData!.config.oracleKeys[0];
|
351
|
+
const priceOracle = (0, umi_1.publicKey)((0, marginfiUtils_1.findMarginfiAccounts)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.bankPk)).priceOracle);
|
340
352
|
remainingAccounts.push(...[
|
341
353
|
{
|
342
354
|
pubkey: x.bankPk,
|
@@ -344,8 +356,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
344
356
|
isWritable: false,
|
345
357
|
},
|
346
358
|
{
|
347
|
-
pubkey:
|
348
|
-
.priceOracle),
|
359
|
+
pubkey: priceOracle,
|
349
360
|
isSigner: false,
|
350
361
|
isWritable: false,
|
351
362
|
},
|
@@ -356,12 +367,12 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
356
367
|
if (!this.intermediaryMarginfiAccount || !includedFlashLoanToken) {
|
357
368
|
remainingAccounts.push(...[
|
358
369
|
{
|
359
|
-
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(
|
370
|
+
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(accounts.data.bank)),
|
360
371
|
isSigner: false,
|
361
372
|
isWritable: false,
|
362
373
|
},
|
363
374
|
{
|
364
|
-
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(
|
375
|
+
pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(new web3_js_1.PublicKey(accounts.oracle)),
|
365
376
|
isSigner: false,
|
366
377
|
isWritable: false,
|
367
378
|
},
|
@@ -371,8 +382,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
371
382
|
.add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
372
383
|
amount: flashLoanDetails.baseUnitAmount,
|
373
384
|
repayAll: null,
|
374
|
-
bank: (0, umi_1.publicKey)(
|
375
|
-
bankLiquidityVault: (0, umi_1.publicKey)(
|
385
|
+
bank: (0, umi_1.publicKey)(accounts.data.bank),
|
386
|
+
bankLiquidityVault: (0, umi_1.publicKey)(accounts.data.liquidityVault),
|
376
387
|
marginfiAccount: (0, umi_1.publicKey)(this.intermediaryMarginfiAccountPk),
|
377
388
|
marginfiGroup: (0, umi_1.publicKey)(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP),
|
378
389
|
signer: this.signer,
|
@@ -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;AAE1D,eAAO,MAAM,sBAAsB,iDAAiD,CAAC;AAErF,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;
|
1
|
+
{"version":3,"file":"marginfiAccounts.d.ts","sourceRoot":"","sources":["../../src/constants/marginfiAccounts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,eAAO,MAAM,sBAAsB,iDAAiD,CAAC;AAErF,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;CAyBrE,CAAC;AAEF,eAAO,MAAM,8BAA8B,iDAAiD,CAAC"}
|
@@ -5,19 +5,29 @@ const spl_token_1 = require("@solana/spl-token");
|
|
5
5
|
const tokenConstants_1 = require("./tokenConstants");
|
6
6
|
exports.DEFAULT_MARGINFI_GROUP = "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
7
7
|
exports.MARGINFI_ACCOUNTS = {
|
8
|
-
|
9
|
-
mint: spl_token_1.NATIVE_MINT.toString(),
|
8
|
+
[spl_token_1.NATIVE_MINT.toString()]: {
|
10
9
|
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
11
10
|
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
12
11
|
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
13
12
|
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE"
|
14
13
|
},
|
15
|
-
|
16
|
-
mint: tokenConstants_1.USDC_MINT,
|
14
|
+
[tokenConstants_1.USDC_MINT]: {
|
17
15
|
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
18
16
|
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
19
17
|
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
20
18
|
priceOracle: "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX"
|
19
|
+
},
|
20
|
+
[tokenConstants_1.B_SOL]: {
|
21
|
+
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
22
|
+
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
23
|
+
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
24
|
+
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
25
|
+
},
|
26
|
+
[tokenConstants_1.JUP]: {
|
27
|
+
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
28
|
+
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
29
|
+
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
30
|
+
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
21
31
|
}
|
22
32
|
};
|
23
33
|
exports.MARGINFI_ACCOUNTS_LOOKUP_TABLE = "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
|
@@ -1,5 +1,7 @@
|
|
1
1
|
export declare const PYTH_PRICE_FEED_IDS: {
|
2
2
|
[x: string]: string;
|
3
3
|
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: string;
|
4
|
+
bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1: string;
|
5
|
+
JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN: string;
|
4
6
|
};
|
5
7
|
//# sourceMappingURL=pythConstants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pythConstants.d.ts","sourceRoot":"","sources":["../../src/constants/pythConstants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB
|
1
|
+
{"version":3,"file":"pythConstants.d.ts","sourceRoot":"","sources":["../../src/constants/pythConstants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB;;;;;CAO/B,CAAC"}
|
@@ -7,4 +7,6 @@ const tokenConstants_1 = require("./tokenConstants");
|
|
7
7
|
exports.PYTH_PRICE_FEED_IDS = {
|
8
8
|
[spl_token_1.NATIVE_MINT.toString()]: "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
9
9
|
[tokenConstants_1.USDC_MINT]: "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
10
|
+
[tokenConstants_1.B_SOL]: "0x89875379e70f8fbadc17aef315adf3a8d5d160b811435537e03c97e8aac97d9c",
|
11
|
+
[tokenConstants_1.JUP]: "0x0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996",
|
10
12
|
};
|
@@ -1,8 +1,14 @@
|
|
1
1
|
export declare const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
2
|
+
export declare const B_SOL = "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1";
|
3
|
+
export declare const JUP = "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN";
|
2
4
|
export declare const ALL_SUPPORTED_TOKENS: string[];
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
interface TokenInfo {
|
6
|
+
decimals: number;
|
7
|
+
isStableCoin?: boolean;
|
8
|
+
isLST?: boolean;
|
9
|
+
}
|
10
|
+
export declare const TOKEN_INFO: {
|
11
|
+
[key: string]: TokenInfo;
|
6
12
|
};
|
7
|
-
export
|
13
|
+
export {};
|
8
14
|
//# sourceMappingURL=tokenConstants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,iDAAiD,CAAC;
|
1
|
+
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AACxE,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AAGjE,eAAO,MAAM,oBAAoB,UAKhC,CAAC;AAEF,UAAU,SAAS;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAelD,CAAC"}
|
@@ -1,17 +1,30 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.TOKEN_INFO = exports.ALL_SUPPORTED_TOKENS = exports.JUP = exports.B_SOL = exports.USDC_MINT = void 0;
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
5
|
-
// When adding token ensure a price feed is provided in pythConstants.ts & the token is
|
5
|
+
// When adding token ensure a price feed is provided in pythConstants.ts & the token is in TOKEN_INFO
|
6
6
|
exports.USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
7
|
+
exports.B_SOL = "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1";
|
8
|
+
exports.JUP = "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN";
|
7
9
|
exports.ALL_SUPPORTED_TOKENS = [
|
8
10
|
spl_token_1.NATIVE_MINT.toString(),
|
9
11
|
exports.USDC_MINT,
|
12
|
+
exports.B_SOL,
|
13
|
+
exports.JUP,
|
10
14
|
];
|
11
|
-
exports.
|
12
|
-
[spl_token_1.NATIVE_MINT.toString()]:
|
13
|
-
|
15
|
+
exports.TOKEN_INFO = {
|
16
|
+
[spl_token_1.NATIVE_MINT.toString()]: {
|
17
|
+
decimals: 9,
|
18
|
+
},
|
19
|
+
[exports.USDC_MINT]: {
|
20
|
+
decimals: 6,
|
21
|
+
isStableCoin: true
|
22
|
+
},
|
23
|
+
[exports.B_SOL]: {
|
24
|
+
decimals: 9,
|
25
|
+
isLST: true
|
26
|
+
},
|
27
|
+
[exports.JUP]: {
|
28
|
+
decimals: 6
|
29
|
+
}
|
14
30
|
};
|
15
|
-
exports.STABLECOINS = [
|
16
|
-
exports.USDC_MINT
|
17
|
-
];
|
@@ -42,8 +42,8 @@ export declare class StaleProtocolDataError extends ProgramError {
|
|
42
42
|
readonly code: number;
|
43
43
|
constructor(program: Program, cause?: Error);
|
44
44
|
}
|
45
|
-
/**
|
46
|
-
export declare class
|
45
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
46
|
+
export declare class UnableToRebalanceError extends ProgramError {
|
47
47
|
readonly name: string;
|
48
48
|
readonly code: number;
|
49
49
|
constructor(program: Program, cause?: Error);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../../src/generated/errors/solauto.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AASjE,0FAA0F;AAC1F,qBAAa,sBAAuB,SAAQ,YAAY;IACtD,SAAkB,IAAI,EAAE,MAAM,CAAuB;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAO;gBAEhB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK;CAO5C;AAID,2GAA2G;AAC3G,qBAAa,iCAAkC,SAAQ,YAAY;IACjE,SAAkB,IAAI,EAAE,MAAM,CAAkC;IAEhE,QAAQ,CAAC,IAAI,EAAE,MAAM,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|
* @see https://github.com/metaplex-foundation/kinobi
|
8
8
|
*/
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
-
exports.IncorrectInstructionsError = exports.RebalanceAbuseError = exports.InstructionIsCPIError = exports.InvalidRebalanceConditionError = exports.ExceededValidUtilizationRateError = exports.
|
10
|
+
exports.IncorrectInstructionsError = exports.RebalanceAbuseError = exports.InstructionIsCPIError = exports.InvalidRebalanceConditionError = exports.ExceededValidUtilizationRateError = exports.UnableToRebalanceError = exports.StaleProtocolDataError = exports.InvalidAutomationDataError = exports.InvalidDCASettingsError = exports.InvalidPositionSettingsError = exports.FailedAccountDeserializationError = exports.IncorrectAccountsError = void 0;
|
11
11
|
exports.getSolautoErrorFromCode = getSolautoErrorFromCode;
|
12
12
|
exports.getSolautoErrorFromName = getSolautoErrorFromName;
|
13
13
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -79,17 +79,17 @@ class StaleProtocolDataError extends umi_1.ProgramError {
|
|
79
79
|
exports.StaleProtocolDataError = StaleProtocolDataError;
|
80
80
|
codeToErrorMap.set(0x5, StaleProtocolDataError);
|
81
81
|
nameToErrorMap.set('StaleProtocolData', StaleProtocolDataError);
|
82
|
-
/**
|
83
|
-
class
|
82
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
83
|
+
class UnableToRebalanceError extends umi_1.ProgramError {
|
84
84
|
constructor(program, cause) {
|
85
85
|
super('Unable to adjust position to the desired utilization rate', program, cause);
|
86
|
-
this.name = '
|
86
|
+
this.name = 'UnableToRebalance';
|
87
87
|
this.code = 0x6; // 6
|
88
88
|
}
|
89
89
|
}
|
90
|
-
exports.
|
91
|
-
codeToErrorMap.set(0x6,
|
92
|
-
nameToErrorMap.set('
|
90
|
+
exports.UnableToRebalanceError = UnableToRebalanceError;
|
91
|
+
codeToErrorMap.set(0x6, UnableToRebalanceError);
|
92
|
+
nameToErrorMap.set('UnableToRebalance', UnableToRebalanceError);
|
93
93
|
/** ExceededValidUtilizationRate: Desired action brought the utilization rate to an unsafe amount */
|
94
94
|
class ExceededValidUtilizationRateError extends umi_1.ProgramError {
|
95
95
|
constructor(program, cause) {
|
@@ -9,8 +9,9 @@ import { Serializer } from '@metaplex-foundation/umi/serializers';
|
|
9
9
|
export declare enum OracleSetup {
|
10
10
|
None = 0,
|
11
11
|
PythLegacy = 1,
|
12
|
-
|
13
|
-
PythPushOracle = 3
|
12
|
+
SwitchboardLegacy = 2,
|
13
|
+
PythPushOracle = 3,
|
14
|
+
SwitchboardPull = 4
|
14
15
|
}
|
15
16
|
export type OracleSetupArgs = OracleSetup;
|
16
17
|
export declare function getOracleSetupSerializer(): Serializer<OracleSetupArgs, OracleSetup>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,
|
1
|
+
{"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,iBAAiB,IAAA;IACjB,cAAc,IAAA;IACd,eAAe,IAAA;CAChB;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C,wBAAgB,wBAAwB,IAAI,UAAU,CACpD,eAAe,EACf,WAAW,CACZ,CAIA"}
|
@@ -14,8 +14,9 @@ var OracleSetup;
|
|
14
14
|
(function (OracleSetup) {
|
15
15
|
OracleSetup[OracleSetup["None"] = 0] = "None";
|
16
16
|
OracleSetup[OracleSetup["PythLegacy"] = 1] = "PythLegacy";
|
17
|
-
OracleSetup[OracleSetup["
|
17
|
+
OracleSetup[OracleSetup["SwitchboardLegacy"] = 2] = "SwitchboardLegacy";
|
18
18
|
OracleSetup[OracleSetup["PythPushOracle"] = 3] = "PythPushOracle";
|
19
|
+
OracleSetup[OracleSetup["SwitchboardPull"] = 4] = "SwitchboardPull";
|
19
20
|
})(OracleSetup || (exports.OracleSetup = OracleSetup = {}));
|
20
21
|
function getOracleSetupSerializer() {
|
21
22
|
return (0, serializers_1.scalarEnum)(OracleSetup, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wrappedI80F48.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/wrappedI80F48.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,
|
1
|
+
{"version":3,"file":"wrappedI80F48.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/wrappedI80F48.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EAIX,MAAM,sCAAsC,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEpD,wBAAgB,0BAA0B,IAAI,UAAU,CACtD,iBAAiB,EACjB,aAAa,CACd,CAIA"}
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.getWrappedI80F48Serializer = getWrappedI80F48Serializer;
|
11
11
|
const serializers_1 = require("@metaplex-foundation/umi/serializers");
|
12
12
|
function getWrappedI80F48Serializer() {
|
13
|
-
return (0, serializers_1.struct)([[
|
14
|
-
description:
|
13
|
+
return (0, serializers_1.struct)([["value", (0, serializers_1.array)((0, serializers_1.u8)(), { size: 16 })]], {
|
14
|
+
description: "WrappedI80F48",
|
15
15
|
});
|
16
16
|
}
|
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,
|
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"}
|
@@ -4,10 +4,7 @@ import { Bank } from "../marginfi-sdk";
|
|
4
4
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
5
5
|
import { PositionState } from "../generated";
|
6
6
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
7
|
-
export declare function findMarginfiAccounts(
|
8
|
-
mint?: string;
|
9
|
-
bank?: string;
|
10
|
-
}): MarginfiAssetAccounts;
|
7
|
+
export declare function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts;
|
11
8
|
export declare function getMaxLtvAndLiqThreshold(umi: Umi, supply: {
|
12
9
|
mint: PublicKey;
|
13
10
|
bank?: Bank | null;
|
@@ -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;AAUzB,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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AAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
|
@@ -15,28 +15,22 @@ const solautoConstants_1 = require("../constants/solautoConstants");
|
|
15
15
|
const marginfiAccounts_1 = require("../constants/marginfiAccounts");
|
16
16
|
const generalAccounts_1 = require("../constants/generalAccounts");
|
17
17
|
const solanaUtils_1 = require("./solanaUtils");
|
18
|
-
function findMarginfiAccounts(
|
18
|
+
function findMarginfiAccounts(bank) {
|
19
19
|
for (const key in marginfiAccounts_1.MARGINFI_ACCOUNTS) {
|
20
20
|
const account = marginfiAccounts_1.MARGINFI_ACCOUNTS[key];
|
21
|
-
if (
|
22
|
-
return account;
|
23
|
-
}
|
24
|
-
if (bank && account.bank.toString().toLowerCase() === bank.toLowerCase()) {
|
21
|
+
if (account.bank.toString().toLowerCase() === bank.toString().toLowerCase()) {
|
25
22
|
return account;
|
26
23
|
}
|
27
24
|
}
|
28
|
-
throw new Error(`Marginfi accounts not found by the
|
25
|
+
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
29
26
|
}
|
30
27
|
async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
31
28
|
if (!supply.bank || supply.bank === null) {
|
32
|
-
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(
|
33
|
-
mint: supply.mint.toString(),
|
34
|
-
}).bank));
|
29
|
+
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[supply.mint.toString()].bank));
|
35
30
|
}
|
36
|
-
if ((!debt.bank || debt.bank === null) &&
|
37
|
-
debt.
|
38
|
-
|
39
|
-
}).bank));
|
31
|
+
if ((!debt.bank || debt.bank === null) &&
|
32
|
+
!debt.mint.equals(web3_js_1.PublicKey.default)) {
|
33
|
+
debt.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[debt.mint.toString()].bank));
|
40
34
|
}
|
41
35
|
if (!supplyPrice) {
|
42
36
|
const [price] = await (0, generalUtils_1.getTokenPrices)([
|
@@ -141,10 +135,10 @@ async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
|
|
141
135
|
async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMint, debtMint, livePositionUpdates) {
|
142
136
|
let marginfiAccount = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(marginfiAccountPk));
|
143
137
|
let supplyBank = supplyMint && supplyMint !== web3_js_1.PublicKey.default
|
144
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(
|
138
|
+
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[supplyMint.toString()].bank))
|
145
139
|
: null;
|
146
140
|
let debtBank = debtMint && debtMint !== web3_js_1.PublicKey.default
|
147
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(
|
141
|
+
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[debtMint.toString()].bank))
|
148
142
|
: null;
|
149
143
|
let supplyUsage = undefined;
|
150
144
|
let debtUsage = undefined;
|
@@ -235,8 +235,8 @@ async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
|
|
235
235
|
};
|
236
236
|
}
|
237
237
|
function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
238
|
-
const supplyDecimals = constants_1.
|
239
|
-
const debtDecimals = constants_1.
|
238
|
+
const supplyDecimals = constants_1.TOKEN_INFO[supply.mint.toString()].decimals;
|
239
|
+
const debtDecimals = constants_1.TOKEN_INFO[debt.mint.toString()].decimals;
|
240
240
|
const supplyUsd = supply.amountUsed * supply.price;
|
241
241
|
const debtUsd = debt.amountUsed * debt.price;
|
242
242
|
return {
|
package/package.json
CHANGED
@@ -16,6 +16,7 @@ import { SolautoClient, SolautoClientArgs } from "./solautoClient";
|
|
16
16
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
17
17
|
import {
|
18
18
|
DEFAULT_MARGINFI_GROUP,
|
19
|
+
MARGINFI_ACCOUNTS,
|
19
20
|
MARGINFI_ACCOUNTS_LOOKUP_TABLE,
|
20
21
|
} from "../constants/marginfiAccounts";
|
21
22
|
import {
|
@@ -33,6 +34,7 @@ import {
|
|
33
34
|
import { getMarginfiAccountPDA, getTokenAccount } from "../utils/accountUtils";
|
34
35
|
import { generateRandomU64 } from "../utils/generalUtils";
|
35
36
|
import {
|
37
|
+
Bank,
|
36
38
|
MARGINFI_PROGRAM_ID,
|
37
39
|
MarginfiAccount,
|
38
40
|
lendingAccountBorrow,
|
@@ -42,7 +44,9 @@ import {
|
|
42
44
|
lendingAccountStartFlashloan,
|
43
45
|
lendingAccountWithdraw,
|
44
46
|
marginfiAccountInitialize,
|
47
|
+
safeFetchAllBank,
|
45
48
|
safeFetchAllMarginfiAccount,
|
49
|
+
safeFetchBank,
|
46
50
|
safeFetchMarginfiAccount,
|
47
51
|
} from "../marginfi-sdk";
|
48
52
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
@@ -74,6 +78,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
74
78
|
public marginfiSupplyAccounts!: MarginfiAssetAccounts;
|
75
79
|
public marginfiDebtAccounts!: MarginfiAssetAccounts;
|
76
80
|
|
81
|
+
public supplyPriceOracle!: PublicKey;
|
82
|
+
public debtPriceOracle!: PublicKey;
|
83
|
+
|
77
84
|
// For flash loans
|
78
85
|
public intermediaryMarginfiAccountSigner?: Signer;
|
79
86
|
public intermediaryMarginfiAccountPk!: PublicKey;
|
@@ -108,12 +115,20 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
108
115
|
? toWeb3JsPublicKey(marginfiAccountData.group)
|
109
116
|
: args.marginfiGroup ?? new PublicKey(DEFAULT_MARGINFI_GROUP);
|
110
117
|
|
111
|
-
this.marginfiSupplyAccounts =
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
118
|
+
this.marginfiSupplyAccounts =
|
119
|
+
MARGINFI_ACCOUNTS[this.supplyMint.toString()]!;
|
120
|
+
this.marginfiDebtAccounts = MARGINFI_ACCOUNTS[this.debtMint.toString()]!;
|
121
|
+
|
122
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
123
|
+
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
124
|
+
// publicKey(this.marginfiSupplyAccounts.bank),
|
125
|
+
// publicKey(this.marginfiDebtAccounts.bank),
|
126
|
+
// ]);
|
127
|
+
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
128
|
+
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
129
|
+
|
130
|
+
this.supplyPriceOracle = new PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
131
|
+
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
117
132
|
|
118
133
|
if (!this.initialized) {
|
119
134
|
await this.setIntermediaryMarginfiDetails();
|
@@ -171,7 +186,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
171
186
|
return [
|
172
187
|
...super.lutAccountsToAdd(),
|
173
188
|
this.marginfiAccountPk,
|
174
|
-
...(this.signer.publicKey.toString() === this.authority.toString()
|
189
|
+
...(this.signer.publicKey.toString() === this.authority.toString()
|
190
|
+
? [this.intermediaryMarginfiAccountPk]
|
191
|
+
: []),
|
175
192
|
];
|
176
193
|
}
|
177
194
|
|
@@ -246,9 +263,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
246
263
|
marginfiGroup: publicKey(this.marginfiGroup),
|
247
264
|
marginfiAccount: publicKey(this.marginfiAccount),
|
248
265
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
249
|
-
supplyPriceOracle: publicKey(this.
|
266
|
+
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
250
267
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
251
|
-
debtPriceOracle: publicKey(this.
|
268
|
+
debtPriceOracle: publicKey(this.debtPriceOracle),
|
252
269
|
solautoPosition: publicKey(this.solautoPosition),
|
253
270
|
});
|
254
271
|
}
|
@@ -358,18 +375,14 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
358
375
|
: this.positionDebtTa
|
359
376
|
);
|
360
377
|
vaultDebtTa = publicKey(this.marginfiDebtAccounts.liquidityVault);
|
361
|
-
debtVaultAuthority = publicKey(
|
362
|
-
this.marginfiDebtAccounts.vaultAuthority
|
363
|
-
);
|
378
|
+
debtVaultAuthority = publicKey(this.marginfiDebtAccounts.vaultAuthority);
|
364
379
|
}
|
365
380
|
|
366
381
|
let supplyPriceOracle: UmiPublicKey | undefined = undefined;
|
367
382
|
let debtPriceOracle: UmiPublicKey | undefined = undefined;
|
368
383
|
if (args.__kind === "Withdraw" || args.__kind === "Borrow") {
|
369
|
-
supplyPriceOracle = publicKey(
|
370
|
-
|
371
|
-
);
|
372
|
-
debtPriceOracle = publicKey(this.marginfiDebtAccounts.priceOracle);
|
384
|
+
supplyPriceOracle = publicKey(this.supplyPriceOracle);
|
385
|
+
debtPriceOracle = publicKey(this.debtPriceOracle);
|
373
386
|
}
|
374
387
|
|
375
388
|
return marginfiProtocolInteraction(this.umi, {
|
@@ -431,7 +444,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
431
444
|
)
|
432
445
|
),
|
433
446
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
434
|
-
supplyPriceOracle: publicKey(this.
|
447
|
+
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
435
448
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
436
449
|
signerSupplyTa: this.selfManaged
|
437
450
|
? publicKey(this.signerSupplyTa)
|
@@ -443,7 +456,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
443
456
|
? publicKey(this.marginfiSupplyAccounts.vaultAuthority)
|
444
457
|
: undefined,
|
445
458
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
446
|
-
debtPriceOracle: publicKey(this.
|
459
|
+
debtPriceOracle: publicKey(this.debtPriceOracle),
|
447
460
|
positionDebtTa: publicKey(this.positionDebtTa),
|
448
461
|
signerDebtTa: this.selfManaged ? publicKey(this.signerDebtTa) : undefined,
|
449
462
|
vaultDebtTa: needDebtAccounts
|
@@ -489,20 +502,25 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
489
502
|
}
|
490
503
|
|
491
504
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder {
|
492
|
-
const
|
493
|
-
? this.marginfiSupplyAccounts
|
494
|
-
: this.marginfiDebtAccounts;
|
505
|
+
const accounts = flashLoanDetails.mint.equals(this.supplyMint)
|
506
|
+
? { data: this.marginfiSupplyAccounts, oracle: this.supplyPriceOracle }
|
507
|
+
: { data: this.marginfiDebtAccounts, oracle: this.debtPriceOracle };
|
495
508
|
|
496
509
|
const remainingAccounts: AccountMeta[] = [];
|
497
510
|
let includedFlashLoanToken = false;
|
498
511
|
|
499
512
|
if (this.intermediaryMarginfiAccount) {
|
500
|
-
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach((x) => {
|
513
|
+
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(async (x) => {
|
501
514
|
if (x.active) {
|
502
|
-
if (x.bankPk ===
|
515
|
+
if (x.bankPk === accounts.data.bank) {
|
503
516
|
includedFlashLoanToken = true;
|
504
517
|
}
|
505
518
|
|
519
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
520
|
+
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
521
|
+
// const priceOracle = bankData!.config.oracleKeys[0];
|
522
|
+
const priceOracle = publicKey(findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle);
|
523
|
+
|
506
524
|
remainingAccounts.push(
|
507
525
|
...[
|
508
526
|
{
|
@@ -511,10 +529,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
511
529
|
isWritable: false,
|
512
530
|
},
|
513
531
|
{
|
514
|
-
pubkey:
|
515
|
-
findMarginfiAccounts({ bank: x.bankPk.toString() })
|
516
|
-
.priceOracle
|
517
|
-
),
|
532
|
+
pubkey: priceOracle,
|
518
533
|
isSigner: false,
|
519
534
|
isWritable: false,
|
520
535
|
},
|
@@ -527,12 +542,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
527
542
|
remainingAccounts.push(
|
528
543
|
...[
|
529
544
|
{
|
530
|
-
pubkey: fromWeb3JsPublicKey(new PublicKey(
|
545
|
+
pubkey: fromWeb3JsPublicKey(new PublicKey(accounts.data.bank)),
|
531
546
|
isSigner: false,
|
532
547
|
isWritable: false,
|
533
548
|
},
|
534
549
|
{
|
535
|
-
pubkey: fromWeb3JsPublicKey(new PublicKey(
|
550
|
+
pubkey: fromWeb3JsPublicKey(new PublicKey(accounts.oracle)),
|
536
551
|
isSigner: false,
|
537
552
|
isWritable: false,
|
538
553
|
},
|
@@ -545,8 +560,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
545
560
|
lendingAccountRepay(this.umi, {
|
546
561
|
amount: flashLoanDetails.baseUnitAmount,
|
547
562
|
repayAll: null,
|
548
|
-
bank: publicKey(
|
549
|
-
bankLiquidityVault: publicKey(
|
563
|
+
bank: publicKey(accounts.data.bank),
|
564
|
+
bankLiquidityVault: publicKey(accounts.data.liquidityVault),
|
550
565
|
marginfiAccount: publicKey(this.intermediaryMarginfiAccountPk),
|
551
566
|
marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
|
552
567
|
signer: this.signer,
|
@@ -1,23 +1,33 @@
|
|
1
1
|
import { NATIVE_MINT } from "@solana/spl-token";
|
2
|
-
import { USDC_MINT } from "./tokenConstants";
|
2
|
+
import { B_SOL, JUP, USDC_MINT } from "./tokenConstants";
|
3
3
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
4
4
|
|
5
5
|
export const DEFAULT_MARGINFI_GROUP = "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
6
6
|
|
7
7
|
export const MARGINFI_ACCOUNTS: { [key: string]: MarginfiAssetAccounts } = {
|
8
|
-
|
9
|
-
mint: NATIVE_MINT.toString(),
|
8
|
+
[NATIVE_MINT.toString()]: {
|
10
9
|
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
11
10
|
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
12
11
|
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
13
12
|
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE"
|
14
13
|
},
|
15
|
-
|
16
|
-
mint: USDC_MINT,
|
14
|
+
[USDC_MINT]: {
|
17
15
|
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
18
16
|
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
19
17
|
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
20
18
|
priceOracle: "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX"
|
19
|
+
},
|
20
|
+
[B_SOL]: {
|
21
|
+
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
22
|
+
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
23
|
+
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
24
|
+
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
25
|
+
},
|
26
|
+
[JUP]: {
|
27
|
+
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
28
|
+
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
29
|
+
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
30
|
+
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
21
31
|
}
|
22
32
|
};
|
23
33
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NATIVE_MINT } from "@solana/spl-token";
|
2
|
-
import { USDC_MINT } from "./tokenConstants";
|
2
|
+
import { B_SOL, JUP, USDC_MINT } from "./tokenConstants";
|
3
3
|
|
4
4
|
// https://pyth.network/developers/price-feed-ids#solana-stable
|
5
5
|
export const PYTH_PRICE_FEED_IDS = {
|
@@ -7,4 +7,6 @@ export const PYTH_PRICE_FEED_IDS = {
|
|
7
7
|
"0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
8
8
|
[USDC_MINT]:
|
9
9
|
"0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
10
|
-
|
10
|
+
[B_SOL]: "0x89875379e70f8fbadc17aef315adf3a8d5d160b811435537e03c97e8aac97d9c",
|
11
|
+
[JUP]: "0x0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996",
|
12
|
+
};
|
@@ -1,19 +1,37 @@
|
|
1
1
|
import { NATIVE_MINT } from "@solana/spl-token";
|
2
2
|
|
3
|
-
// When adding token ensure a price feed is provided in pythConstants.ts & the token is
|
3
|
+
// When adding token ensure a price feed is provided in pythConstants.ts & the token is in TOKEN_INFO
|
4
4
|
export const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
5
|
+
export const B_SOL = "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1";
|
6
|
+
export const JUP = "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN";
|
5
7
|
|
6
8
|
|
7
9
|
export const ALL_SUPPORTED_TOKENS = [
|
8
10
|
NATIVE_MINT.toString(),
|
9
11
|
USDC_MINT,
|
12
|
+
B_SOL,
|
13
|
+
JUP,
|
10
14
|
];
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
interface TokenInfo {
|
17
|
+
decimals: number;
|
18
|
+
isStableCoin?: boolean;
|
19
|
+
isLST?: boolean;
|
20
|
+
}
|
16
21
|
|
17
|
-
export const
|
18
|
-
|
19
|
-
|
22
|
+
export const TOKEN_INFO: { [key: string]: TokenInfo } = {
|
23
|
+
[NATIVE_MINT.toString()]: {
|
24
|
+
decimals: 9,
|
25
|
+
},
|
26
|
+
[USDC_MINT]: {
|
27
|
+
decimals: 6,
|
28
|
+
isStableCoin: true
|
29
|
+
},
|
30
|
+
[B_SOL]: {
|
31
|
+
decimals: 9,
|
32
|
+
isLST: true
|
33
|
+
},
|
34
|
+
[JUP]: {
|
35
|
+
decimals: 6
|
36
|
+
}
|
37
|
+
};
|
@@ -108,9 +108,9 @@ export class StaleProtocolDataError extends ProgramError {
|
|
108
108
|
codeToErrorMap.set(0x5, StaleProtocolDataError);
|
109
109
|
nameToErrorMap.set('StaleProtocolData', StaleProtocolDataError);
|
110
110
|
|
111
|
-
/**
|
112
|
-
export class
|
113
|
-
override readonly name: string = '
|
111
|
+
/** UnableToRebalance: Unable to adjust position to the desired utilization rate */
|
112
|
+
export class UnableToRebalanceError extends ProgramError {
|
113
|
+
override readonly name: string = 'UnableToRebalance';
|
114
114
|
|
115
115
|
readonly code: number = 0x6; // 6
|
116
116
|
|
@@ -122,8 +122,8 @@ export class UnableToRepositionError extends ProgramError {
|
|
122
122
|
);
|
123
123
|
}
|
124
124
|
}
|
125
|
-
codeToErrorMap.set(0x6,
|
126
|
-
nameToErrorMap.set('
|
125
|
+
codeToErrorMap.set(0x6, UnableToRebalanceError);
|
126
|
+
nameToErrorMap.set('UnableToRebalance', UnableToRebalanceError);
|
127
127
|
|
128
128
|
/** ExceededValidUtilizationRate: Desired action brought the utilization rate to an unsafe amount */
|
129
129
|
export class ExceededValidUtilizationRateError extends ProgramError {
|
@@ -11,8 +11,9 @@ import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';
|
|
11
11
|
export enum OracleSetup {
|
12
12
|
None,
|
13
13
|
PythLegacy,
|
14
|
-
|
14
|
+
SwitchboardLegacy,
|
15
15
|
PythPushOracle,
|
16
|
+
SwitchboardPull,
|
16
17
|
}
|
17
18
|
|
18
19
|
export type OracleSetupArgs = OracleSetup;
|
@@ -6,7 +6,12 @@
|
|
6
6
|
* @see https://github.com/metaplex-foundation/kinobi
|
7
7
|
*/
|
8
8
|
|
9
|
-
import {
|
9
|
+
import {
|
10
|
+
Serializer,
|
11
|
+
array,
|
12
|
+
struct,
|
13
|
+
u8,
|
14
|
+
} from "@metaplex-foundation/umi/serializers";
|
10
15
|
|
11
16
|
export type WrappedI80F48 = { value: number[] };
|
12
17
|
|
@@ -16,7 +21,7 @@ export function getWrappedI80F48Serializer(): Serializer<
|
|
16
21
|
WrappedI80F48Args,
|
17
22
|
WrappedI80F48
|
18
23
|
> {
|
19
|
-
return struct<WrappedI80F48>([[
|
20
|
-
description:
|
24
|
+
return struct<WrappedI80F48>([["value", array(u8(), { size: 16 })]], {
|
25
|
+
description: "WrappedI80F48",
|
21
26
|
}) as Serializer<WrappedI80F48Args, WrappedI80F48>;
|
22
27
|
}
|
package/src/types/accounts.ts
CHANGED
@@ -23,23 +23,16 @@ import { USD_DECIMALS } from "../constants/generalAccounts";
|
|
23
23
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
24
24
|
import { currentUnixSecondsSolana } from "./solanaUtils";
|
25
25
|
|
26
|
-
export function findMarginfiAccounts({
|
27
|
-
mint,
|
28
|
-
bank,
|
29
|
-
}: {
|
30
|
-
mint?: string;
|
31
|
-
bank?: string;
|
32
|
-
}): MarginfiAssetAccounts {
|
26
|
+
export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
33
27
|
for (const key in MARGINFI_ACCOUNTS) {
|
34
28
|
const account = MARGINFI_ACCOUNTS[key];
|
35
|
-
if (
|
36
|
-
|
37
|
-
|
38
|
-
if (bank && account.bank.toString().toLowerCase() === bank.toLowerCase()) {
|
29
|
+
if (
|
30
|
+
account.bank.toString().toLowerCase() === bank.toString().toLowerCase()
|
31
|
+
) {
|
39
32
|
return account;
|
40
33
|
}
|
41
34
|
}
|
42
|
-
throw new Error(`Marginfi accounts not found by the
|
35
|
+
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
43
36
|
}
|
44
37
|
|
45
38
|
export async function getMaxLtvAndLiqThreshold(
|
@@ -57,21 +50,18 @@ export async function getMaxLtvAndLiqThreshold(
|
|
57
50
|
if (!supply.bank || supply.bank === null) {
|
58
51
|
supply.bank = await safeFetchBank(
|
59
52
|
umi,
|
60
|
-
publicKey(
|
61
|
-
findMarginfiAccounts({
|
62
|
-
mint: supply.mint.toString(),
|
63
|
-
}).bank
|
64
|
-
)
|
53
|
+
publicKey(MARGINFI_ACCOUNTS[supply.mint.toString()].bank)
|
65
54
|
);
|
66
55
|
}
|
67
56
|
|
68
|
-
if (
|
57
|
+
if (
|
58
|
+
(!debt.bank || debt.bank === null) &&
|
59
|
+
!debt.mint.equals(PublicKey.default)
|
60
|
+
) {
|
69
61
|
debt.bank = await safeFetchBank(
|
70
62
|
umi,
|
71
63
|
publicKey(
|
72
|
-
|
73
|
-
mint: debt.mint.toString(),
|
74
|
-
}).bank
|
64
|
+
MARGINFI_ACCOUNTS[debt.mint.toString()].bank
|
75
65
|
)
|
76
66
|
);
|
77
67
|
}
|
@@ -248,14 +238,14 @@ export async function getMarginfiAccountPositionState(
|
|
248
238
|
supplyMint && supplyMint !== PublicKey.default
|
249
239
|
? await safeFetchBank(
|
250
240
|
umi,
|
251
|
-
publicKey(
|
241
|
+
publicKey(MARGINFI_ACCOUNTS[supplyMint.toString()].bank)
|
252
242
|
)
|
253
243
|
: null;
|
254
244
|
let debtBank: Bank | null =
|
255
245
|
debtMint && debtMint !== PublicKey.default
|
256
246
|
? await safeFetchBank(
|
257
247
|
umi,
|
258
|
-
publicKey(
|
248
|
+
publicKey(MARGINFI_ACCOUNTS[debtMint.toString()].bank)
|
259
249
|
)
|
260
250
|
: null;
|
261
251
|
|
@@ -23,7 +23,7 @@ import { getReferralState } from "../accountUtils";
|
|
23
23
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
24
24
|
import {
|
25
25
|
ALL_SUPPORTED_TOKENS,
|
26
|
-
|
26
|
+
TOKEN_INFO,
|
27
27
|
USD_DECIMALS,
|
28
28
|
} from "../../constants";
|
29
29
|
import {
|
@@ -368,8 +368,8 @@ export function createFakePositionState(
|
|
368
368
|
maxLtvBps: number,
|
369
369
|
liqThresholdBps: number
|
370
370
|
): PositionState {
|
371
|
-
const supplyDecimals =
|
372
|
-
const debtDecimals =
|
371
|
+
const supplyDecimals = TOKEN_INFO[supply.mint.toString()].decimals;
|
372
|
+
const debtDecimals = TOKEN_INFO[debt.mint.toString()].decimals;
|
373
373
|
|
374
374
|
const supplyUsd = supply.amountUsed * supply.price;
|
375
375
|
const debtUsd = debt.amountUsed * debt.price;
|
@@ -20,8 +20,8 @@ import { PublicKey } from "@solana/web3.js";
|
|
20
20
|
import { USDC_MINT } from "../../src/constants";
|
21
21
|
|
22
22
|
describe("Solauto Marginfi tests", async () => {
|
23
|
-
const signer = setupTest();
|
24
|
-
|
23
|
+
// const signer = setupTest();
|
24
|
+
const signer = setupTest("solauto-manager");
|
25
25
|
|
26
26
|
const payForTransactions = false;
|
27
27
|
const useJitoBundle = false;
|