@haven-fi/solauto-sdk 1.0.626 → 1.0.628
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/README.md +73 -0
- package/dist/constants/marginfiAccounts.d.ts +3 -4
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +9 -37
- package/dist/constants/pythConstants.d.ts +4 -0
- package/dist/constants/pythConstants.d.ts.map +1 -1
- package/dist/constants/pythConstants.js +5 -1
- package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.js +7 -8
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +5 -6
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +4 -9
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +3 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +5 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +15 -2
- package/dist/solautoPosition/solautoPositionEx.d.ts +2 -0
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/utils.js +1 -1
- package/dist/types/accounts.d.ts +0 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts +1 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +10 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/instructionUtils.d.ts +15 -0
- package/dist/utils/instructionUtils.d.ts.map +1 -0
- package/dist/utils/instructionUtils.js +121 -0
- package/dist/utils/marginfiUtils.d.ts +7 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +44 -11
- package/dist/utils/pythUtils.d.ts +21 -0
- package/dist/utils/pythUtils.d.ts.map +1 -0
- package/dist/utils/pythUtils.js +67 -0
- package/dist/utils/solautoUtils.js +1 -1
- package/local/txSandbox.ts +3 -3
- package/local/updateMarginfiLUT.ts +9 -15
- package/package.json +1 -1
- package/src/constants/marginfiAccounts.ts +13 -39
- package/src/constants/pythConstants.ts +8 -0
- package/src/services/flashLoans/marginfiFlProvider.ts +9 -9
- package/src/services/solauto/solautoClient.ts +6 -6
- package/src/services/solauto/solautoMarginfiClient.ts +5 -11
- package/src/services/transactions/transactionUtils.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +22 -3
- package/src/solautoPosition/solautoPositionEx.ts +2 -0
- package/src/solautoPosition/utils.ts +1 -1
- package/src/types/accounts.ts +0 -1
- package/src/utils/generalUtils.ts +12 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/instructionUtils.ts +181 -0
- package/src/utils/marginfiUtils.ts +75 -17
- package/src/utils/pythUtils.ts +84 -0
- package/src/utils/solautoUtils.ts +1 -1
- package/tests/transactions/shared.ts +22 -66
- package/tests/unit/accounts.ts +7 -13
- package/tests/unit/lookupTables.ts +27 -48
@@ -19,4 +19,5 @@ export type ErrorsToThrow = Array<new (...args: any[]) => Error>;
|
|
19
19
|
export declare function retryWithExponentialBackoff<T>(fn: (attemptNum: number, prevErr?: Error) => Promise<T>, retries?: number, delay?: number, errorsToThrow?: ErrorsToThrow): Promise<T>;
|
20
20
|
export declare function toEnumValue<E extends object>(enumObj: E, value: number): E[keyof E] | undefined;
|
21
21
|
export declare function customRpcCall(umi: Umi, method: string, params?: any): Promise<any>;
|
22
|
+
export declare function u16ToArrayBufferLE(value: number): Uint8Array;
|
22
23
|
//# sourceMappingURL=generalUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"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BAuBzE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAU5D"}
|
@@ -20,6 +20,7 @@ exports.zip = zip;
|
|
20
20
|
exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
|
21
21
|
exports.toEnumValue = toEnumValue;
|
22
22
|
exports.customRpcCall = customRpcCall;
|
23
|
+
exports.u16ToArrayBufferLE = u16ToArrayBufferLE;
|
23
24
|
const axios_1 = __importDefault(require("axios"));
|
24
25
|
const web3_js_1 = require("@solana/web3.js");
|
25
26
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -159,3 +160,12 @@ async function customRpcCall(umi, method, params) {
|
|
159
160
|
return data;
|
160
161
|
}
|
161
162
|
}
|
163
|
+
function u16ToArrayBufferLE(value) {
|
164
|
+
// Create a buffer of 2 bytes
|
165
|
+
const buffer = new ArrayBuffer(2);
|
166
|
+
const dataView = new DataView(buffer);
|
167
|
+
// Set the Uint16 value in little-endian order
|
168
|
+
dataView.setUint16(0, value, true);
|
169
|
+
// Return the buffer
|
170
|
+
return new Uint8Array(buffer);
|
171
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export * from "./accountUtils";
|
2
2
|
export * from "./generalUtils";
|
3
|
+
export * from "./instructionUtils";
|
3
4
|
export * from "./jitoUtils";
|
4
5
|
export * from "./jupiterUtils";
|
5
6
|
export * from "./marginfiUtils";
|
@@ -8,5 +9,6 @@ export * from "./solautoUtils";
|
|
8
9
|
export * from "./solanaUtils";
|
9
10
|
export * from "./stringUtils";
|
10
11
|
export * from "./priceUtils";
|
12
|
+
export * from "./pythUtils";
|
11
13
|
export * from "./switchboardUtils";
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./accountUtils"), exports);
|
18
18
|
__exportStar(require("./generalUtils"), exports);
|
19
|
+
__exportStar(require("./instructionUtils"), exports);
|
19
20
|
__exportStar(require("./jitoUtils"), exports);
|
20
21
|
__exportStar(require("./jupiterUtils"), exports);
|
21
22
|
__exportStar(require("./marginfiUtils"), exports);
|
@@ -24,4 +25,5 @@ __exportStar(require("./solautoUtils"), exports);
|
|
24
25
|
__exportStar(require("./solanaUtils"), exports);
|
25
26
|
__exportStar(require("./stringUtils"), exports);
|
26
27
|
__exportStar(require("./priceUtils"), exports);
|
28
|
+
__exportStar(require("./pythUtils"), exports);
|
27
29
|
__exportStar(require("./switchboardUtils"), exports);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { OptionOrNullable } from "@metaplex-foundation/umi";
|
2
|
+
import { DCASettingsInpArgs, SolautoSettingsParametersInpArgs } from "../generated";
|
3
|
+
import { SolautoClient, TransactionItem } from "../services";
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
5
|
+
export declare function openSolautoPosition(client: SolautoClient, settingParams: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionItem;
|
6
|
+
export declare function closeSolautoPosition(client: SolautoClient): TransactionItem;
|
7
|
+
export declare function updateSolautoPosition(client: SolautoClient, settings: OptionOrNullable<SolautoSettingsParametersInpArgs>, dca: OptionOrNullable<DCASettingsInpArgs>): TransactionItem;
|
8
|
+
export declare function cancelSolautoDca(client: SolautoClient): TransactionItem;
|
9
|
+
export declare function deposit(client: SolautoClient, baseUnitAmount: bigint): TransactionItem;
|
10
|
+
export declare function borrow(client: SolautoClient, baseUnitAmount: bigint): TransactionItem;
|
11
|
+
export declare function withdraw(client: SolautoClient, amount: "All" | bigint): TransactionItem;
|
12
|
+
export declare function repay(client: SolautoClient, amount: "All" | bigint): TransactionItem;
|
13
|
+
export declare function rebalance(client: SolautoClient, targetLiqUtilizationRateBps?: number): TransactionItem;
|
14
|
+
export declare function swapThenDeposit(client: SolautoClient, depositMint: PublicKey, depositAmountBaseUnit: bigint): TransactionItem[];
|
15
|
+
//# sourceMappingURL=instructionUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instructionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/instructionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,aAAa,EAEb,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,gCAAgC,EAC/C,GAAG,CAAC,EAAE,kBAAkB,mBAQzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,mBAOzD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,gBAAgB,CAAC,gCAAgC,CAAC,EAC5D,GAAG,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,mBAY1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,mBAOrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUpE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUnE;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAcrE;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAclE;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,mBAUrC;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,SAAS,EACtB,qBAAqB,EAAE,MAAM,qBA2C9B"}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.openSolautoPosition = openSolautoPosition;
|
4
|
+
exports.closeSolautoPosition = closeSolautoPosition;
|
5
|
+
exports.updateSolautoPosition = updateSolautoPosition;
|
6
|
+
exports.cancelSolautoDca = cancelSolautoDca;
|
7
|
+
exports.deposit = deposit;
|
8
|
+
exports.borrow = borrow;
|
9
|
+
exports.withdraw = withdraw;
|
10
|
+
exports.repay = repay;
|
11
|
+
exports.rebalance = rebalance;
|
12
|
+
exports.swapThenDeposit = swapThenDeposit;
|
13
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
14
|
+
const services_1 = require("../services");
|
15
|
+
const generalUtils_1 = require("./generalUtils");
|
16
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
17
|
+
function openSolautoPosition(client, settingParams, dca) {
|
18
|
+
return new services_1.TransactionItem(async () => ({
|
19
|
+
tx: client.openPositionIx(settingParams, dca),
|
20
|
+
}), "open position");
|
21
|
+
}
|
22
|
+
function closeSolautoPosition(client) {
|
23
|
+
return new services_1.TransactionItem(async () => ({
|
24
|
+
tx: client.closePositionIx(),
|
25
|
+
}), "close position");
|
26
|
+
}
|
27
|
+
function updateSolautoPosition(client, settings, dca) {
|
28
|
+
return new services_1.TransactionItem(async () => ({
|
29
|
+
tx: client.updatePositionIx({
|
30
|
+
positionId: client.positionId,
|
31
|
+
settings,
|
32
|
+
dca,
|
33
|
+
}),
|
34
|
+
}), "update position");
|
35
|
+
}
|
36
|
+
function cancelSolautoDca(client) {
|
37
|
+
return new services_1.TransactionItem(async () => ({
|
38
|
+
tx: client.cancelDCAIx(),
|
39
|
+
}), "cancel DCA");
|
40
|
+
}
|
41
|
+
function deposit(client, baseUnitAmount) {
|
42
|
+
return new services_1.TransactionItem(async () => ({
|
43
|
+
tx: client.protocolInteractionIx({
|
44
|
+
__kind: "Deposit",
|
45
|
+
fields: [baseUnitAmount],
|
46
|
+
}),
|
47
|
+
}), "deposit");
|
48
|
+
}
|
49
|
+
function borrow(client, baseUnitAmount) {
|
50
|
+
return new services_1.TransactionItem(async () => ({
|
51
|
+
tx: client.protocolInteractionIx({
|
52
|
+
__kind: "Borrow",
|
53
|
+
fields: [baseUnitAmount],
|
54
|
+
}),
|
55
|
+
}), "borrow");
|
56
|
+
}
|
57
|
+
function withdraw(client, amount) {
|
58
|
+
return new services_1.TransactionItem(async () => ({
|
59
|
+
tx: client.protocolInteractionIx({
|
60
|
+
__kind: "Withdraw",
|
61
|
+
fields: [
|
62
|
+
amount === "All"
|
63
|
+
? { __kind: "All" }
|
64
|
+
: { __kind: "Some", fields: [amount] },
|
65
|
+
],
|
66
|
+
}),
|
67
|
+
}), "withdraw");
|
68
|
+
}
|
69
|
+
function repay(client, amount) {
|
70
|
+
return new services_1.TransactionItem(async () => ({
|
71
|
+
tx: client.protocolInteractionIx({
|
72
|
+
__kind: "Repay",
|
73
|
+
fields: [
|
74
|
+
amount === "All"
|
75
|
+
? { __kind: "All" }
|
76
|
+
: { __kind: "Some", fields: [amount] },
|
77
|
+
],
|
78
|
+
}),
|
79
|
+
}), "repay");
|
80
|
+
}
|
81
|
+
function rebalance(client, targetLiqUtilizationRateBps) {
|
82
|
+
return new services_1.TransactionItem(async (attemptNum) => await new services_1.RebalanceTxBuilder(client, targetLiqUtilizationRateBps).buildRebalanceTx(attemptNum), "rebalance");
|
83
|
+
}
|
84
|
+
function swapThenDeposit(client, depositMint, depositAmountBaseUnit) {
|
85
|
+
return [
|
86
|
+
new services_1.TransactionItem(async () => {
|
87
|
+
const memeSwap = (0, generalUtils_1.tokenInfo)(client.pos.supplyMint()).isMeme;
|
88
|
+
const swapInput = {
|
89
|
+
inputMint: depositMint,
|
90
|
+
outputMint: client.pos.supplyMint(),
|
91
|
+
amount: depositAmountBaseUnit,
|
92
|
+
exactIn: true,
|
93
|
+
slippageBps: memeSwap ? 300 : 50,
|
94
|
+
};
|
95
|
+
const jupSwapManager = new services_1.JupSwapManager(client.signer);
|
96
|
+
const { setupIx, swapIx, cleanupIx, lookupTableAddresses } = await jupSwapManager.getJupSwapTxData({
|
97
|
+
...swapInput,
|
98
|
+
destinationWallet: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey),
|
99
|
+
wrapAndUnwrapSol: true,
|
100
|
+
});
|
101
|
+
client.contextUpdates.new({
|
102
|
+
type: "jupSwap",
|
103
|
+
value: jupSwapManager.jupQuote,
|
104
|
+
});
|
105
|
+
return {
|
106
|
+
tx: (0, umi_1.transactionBuilder)().add([setupIx, swapIx, cleanupIx]),
|
107
|
+
lookupTableAddresses,
|
108
|
+
orderPrio: -1,
|
109
|
+
};
|
110
|
+
}, "swap"),
|
111
|
+
new services_1.TransactionItem(async () => {
|
112
|
+
const quoteOutAmount = client.contextUpdates.jupSwap?.outAmount;
|
113
|
+
return {
|
114
|
+
tx: (0, umi_1.transactionBuilder)().add(client.protocolInteractionIx({
|
115
|
+
__kind: "Deposit",
|
116
|
+
fields: [BigInt(Math.round(parseInt(quoteOutAmount) * 0.995))],
|
117
|
+
})),
|
118
|
+
};
|
119
|
+
}, "deposit"),
|
120
|
+
];
|
121
|
+
}
|
@@ -2,17 +2,22 @@ import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { Program, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { ProgramEnv, MarginfiAssetAccounts } from "../types";
|
4
4
|
import { PositionState } from "../generated";
|
5
|
+
import { MarginfiBankAccountsMap } from "../constants";
|
5
6
|
import { Bank, MarginfiAccount } from "../marginfi-sdk";
|
6
7
|
import { ContextUpdates } from "./solautoUtils";
|
7
|
-
export declare function getMarginfiProgram(env: ProgramEnv): PublicKey;
|
8
|
-
export declare function isMarginfiProgram(programId: PublicKey): boolean;
|
9
8
|
export declare function createDynamicMarginfiProgram(env?: ProgramEnv): Program;
|
10
9
|
export declare function umiWithMarginfiProgram(umi: Umi, marginfiEnv?: ProgramEnv): Umi;
|
10
|
+
export declare function getAllBankRelatedAccounts(umi: Umi, bankAccountsMap: MarginfiBankAccountsMap): Promise<PublicKey[]>;
|
11
11
|
export declare function fetchBankAddresses(umi: Umi, bankPk: PublicKey): Promise<{
|
12
12
|
bank: PublicKey;
|
13
13
|
liquidityVault: PublicKey;
|
14
14
|
vaultAuthority: PublicKey | undefined;
|
15
|
+
priceOracle: PublicKey;
|
15
16
|
}>;
|
17
|
+
export declare function getMarginfiPriceOracle(umi: Umi, bank: {
|
18
|
+
pk?: PublicKey;
|
19
|
+
data?: Bank;
|
20
|
+
}): Promise<PublicKey>;
|
16
21
|
interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
|
17
22
|
mint: PublicKey;
|
18
23
|
}
|
@@ -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,EAAE,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAKnE,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAKnE,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AACjE,OAAO,EAIL,uBAAuB,EAIxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,IAAI,EAMJ,eAAe,EAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiBhD,wBAAgB,4BAA4B,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,CActE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,UAAU,OASxE;AAED,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,GAAG,EACR,eAAe,EAAE,uBAAuB,GACvC,OAAO,CAAC,SAAS,EAAE,CAAC,CAmCtB;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,G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AgB,iCAAiC,CAC/C,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,kBAAkB,EAAE,OAAO,UAqB5B;AAsDD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,KAAK,UAAU,GAAG;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,CAAC;AAsBhE,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE;IAAE,EAAE,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,EAChE,aAAa,CAAC,EAAE,SAAS,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,UAAU,CAAC,EAAE,UAAU,EACvB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CACN;IAAE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GACxE,SAAS,CACZ,CAyKA;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getMarginfiProgram = getMarginfiProgram;
|
4
|
-
exports.isMarginfiProgram = isMarginfiProgram;
|
5
3
|
exports.createDynamicMarginfiProgram = createDynamicMarginfiProgram;
|
6
4
|
exports.umiWithMarginfiProgram = umiWithMarginfiProgram;
|
5
|
+
exports.getAllBankRelatedAccounts = getAllBankRelatedAccounts;
|
7
6
|
exports.fetchBankAddresses = fetchBankAddresses;
|
7
|
+
exports.getMarginfiPriceOracle = getMarginfiPriceOracle;
|
8
8
|
exports.findMarginfiAccounts = findMarginfiAccounts;
|
9
9
|
exports.calcMarginfiMaxLtvAndLiqThresholdBps = calcMarginfiMaxLtvAndLiqThresholdBps;
|
10
10
|
exports.getMarginfiMaxLtvAndLiqThresholdBps = getMarginfiMaxLtvAndLiqThresholdBps;
|
@@ -24,17 +24,11 @@ const priceUtils_1 = require("./priceUtils");
|
|
24
24
|
const generalUtils_1 = require("./generalUtils");
|
25
25
|
const numberUtils_1 = require("./numberUtils");
|
26
26
|
const accountUtils_1 = require("./accountUtils");
|
27
|
-
|
28
|
-
return env === "Prod" ? constants_1.MARGINFI_PROD_PROGRAM : constants_1.MARGINFI_STAGING_PROGRAM;
|
29
|
-
}
|
30
|
-
function isMarginfiProgram(programId) {
|
31
|
-
return (programId.equals(constants_1.MARGINFI_PROD_PROGRAM) ||
|
32
|
-
programId.equals(constants_1.MARGINFI_STAGING_PROGRAM));
|
33
|
-
}
|
27
|
+
const pythUtils_1 = require("./pythUtils");
|
34
28
|
function createDynamicMarginfiProgram(env) {
|
35
29
|
return {
|
36
30
|
name: "marginfi",
|
37
|
-
publicKey: (0, umi_1.publicKey)(
|
31
|
+
publicKey: (0, umi_1.publicKey)((0, constants_1.getMarginfiAccounts)(env ?? "Prod").program),
|
38
32
|
getErrorFromCode(code, cause) {
|
39
33
|
return (0, marginfi_sdk_1.getMarginfiErrorFromCode)(code, this, cause);
|
40
34
|
},
|
@@ -53,17 +47,56 @@ function umiWithMarginfiProgram(umi, marginfiEnv) {
|
|
53
47
|
},
|
54
48
|
});
|
55
49
|
}
|
50
|
+
async function getAllBankRelatedAccounts(umi, bankAccountsMap) {
|
51
|
+
const banks = Object.values(bankAccountsMap).flatMap((group) => Object.values(group).map((accounts) => accounts.bank));
|
52
|
+
const banksData = await (0, marginfi_sdk_1.safeFetchAllBank)(umi, banks.map((x) => (0, umi_1.publicKey)(x)));
|
53
|
+
const oracles = banksData
|
54
|
+
.map((bank) => {
|
55
|
+
const oracleKey = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.config.oracleKeys[0]);
|
56
|
+
return bank.config.oracleSetup === marginfi_sdk_1.OracleSetup.PythPushOracle
|
57
|
+
? [
|
58
|
+
(0, pythUtils_1.getPythPushOracleAddress)(oracleKey, constants_1.PYTH_SPONSORED_SHARD_ID),
|
59
|
+
(0, pythUtils_1.getPythPushOracleAddress)(oracleKey, constants_1.MARGINFI_SPONSORED_SHARD_ID),
|
60
|
+
]
|
61
|
+
: [oracleKey];
|
62
|
+
})
|
63
|
+
.flat()
|
64
|
+
.map((x) => x.toString());
|
65
|
+
const otherAccounts = Object.entries(bankAccountsMap).flatMap(([groupName, tokenMap]) => Object.values(tokenMap).flatMap((accounts) => [
|
66
|
+
groupName,
|
67
|
+
accounts.liquidityVault,
|
68
|
+
accounts.vaultAuthority,
|
69
|
+
]));
|
70
|
+
return Array.from(new Set([...banks, ...oracles, ...otherAccounts]))
|
71
|
+
.filter((x) => x !== web3_js_1.PublicKey.default.toString())
|
72
|
+
.map((x) => new web3_js_1.PublicKey(x));
|
73
|
+
}
|
56
74
|
async function fetchBankAddresses(umi, bankPk) {
|
57
|
-
const bank = await (0, marginfi_sdk_1.
|
75
|
+
const bank = await (0, marginfi_sdk_1.fetchBank)(umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(bankPk));
|
58
76
|
const liquidityVault = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.liquidityVault);
|
59
77
|
const vaultAuthority = (await (0, accountUtils_1.getTokenAccountData)(umi, liquidityVault))
|
60
78
|
?.owner;
|
79
|
+
const priceOracle = await getMarginfiPriceOracle(umi, { data: bank });
|
61
80
|
return {
|
62
81
|
bank: bankPk,
|
63
82
|
liquidityVault,
|
64
83
|
vaultAuthority,
|
84
|
+
priceOracle,
|
65
85
|
};
|
66
86
|
}
|
87
|
+
async function getMarginfiPriceOracle(umi, bank) {
|
88
|
+
if (!bank.data) {
|
89
|
+
bank.data = await (0, marginfi_sdk_1.fetchBank)(umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(bank.pk));
|
90
|
+
}
|
91
|
+
const oracleKey = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.data.config.oracleKeys[0]);
|
92
|
+
const priceOracle = bank.data.config.oracleSetup === marginfi_sdk_1.OracleSetup.PythPushOracle
|
93
|
+
? await (0, pythUtils_1.getMostUpToDatePythOracle)(umi, [
|
94
|
+
(0, pythUtils_1.getPythPushOracleAddress)(oracleKey, constants_1.PYTH_SPONSORED_SHARD_ID),
|
95
|
+
(0, pythUtils_1.getPythPushOracleAddress)(oracleKey, constants_1.MARGINFI_SPONSORED_SHARD_ID),
|
96
|
+
])
|
97
|
+
: oracleKey;
|
98
|
+
return priceOracle;
|
99
|
+
}
|
67
100
|
function findMarginfiAccounts(bank) {
|
68
101
|
const search = (bankAccounts) => {
|
69
102
|
for (const group in bankAccounts) {
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { Umi } from "@metaplex-foundation/umi";
|
3
|
+
type PriceUpdateV2 = {
|
4
|
+
writeAuthority: Buffer;
|
5
|
+
verificationLevel: number;
|
6
|
+
priceMessage: {
|
7
|
+
feedId: Buffer;
|
8
|
+
price: bigint;
|
9
|
+
conf: bigint;
|
10
|
+
exponent: number;
|
11
|
+
publishTime: bigint;
|
12
|
+
prevPublishTime: bigint;
|
13
|
+
emaPrice: bigint;
|
14
|
+
emaConf: bigint;
|
15
|
+
};
|
16
|
+
};
|
17
|
+
export declare function parsePriceInfo(data: Uint8Array): PriceUpdateV2;
|
18
|
+
export declare function getMostUpToDatePythOracle(umi: Umi, oracleKeys: PublicKey[]): Promise<PublicKey>;
|
19
|
+
export declare function getPythPushOracleAddress(feedId: PublicKey, shardId: number, programId?: PublicKey): PublicKey;
|
20
|
+
export {};
|
21
|
+
//# sourceMappingURL=pythUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pythUtils.d.ts","sourceRoot":"","sources":["../../src/utils/pythUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAG/C,KAAK,aAAa,GAAG;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAwBF,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAM9D;AAED,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,SAAS,EAAE,sBAiBxB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,SAA6B,GACvC,SAAS,CAMX"}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.parsePriceInfo = parsePriceInfo;
|
27
|
+
exports.getMostUpToDatePythOracle = getMostUpToDatePythOracle;
|
28
|
+
exports.getPythPushOracleAddress = getPythPushOracleAddress;
|
29
|
+
const web3_js_1 = require("@solana/web3.js");
|
30
|
+
const constants_1 = require("../constants");
|
31
|
+
const generalUtils_1 = require("./generalUtils");
|
32
|
+
const borsh = __importStar(require("borsh"));
|
33
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
34
|
+
const priceUpdateV2Schema = {
|
35
|
+
struct: {
|
36
|
+
writeAuthority: {
|
37
|
+
array: { type: "u8", len: 32 },
|
38
|
+
},
|
39
|
+
verificationLevel: "u8",
|
40
|
+
priceMessage: {
|
41
|
+
struct: {
|
42
|
+
feedId: { array: { type: "u8", len: 32 } },
|
43
|
+
price: "i64",
|
44
|
+
conf: "u64",
|
45
|
+
exponent: "i32",
|
46
|
+
publishTime: "i64",
|
47
|
+
prevPublishTime: "i64",
|
48
|
+
emaPrice: "i64",
|
49
|
+
emaConf: "u64",
|
50
|
+
},
|
51
|
+
},
|
52
|
+
postedSlot: "u64",
|
53
|
+
},
|
54
|
+
};
|
55
|
+
function parsePriceInfo(data) {
|
56
|
+
let decoded = borsh.deserialize(priceUpdateV2Schema, data);
|
57
|
+
return decoded;
|
58
|
+
}
|
59
|
+
async function getMostUpToDatePythOracle(umi, oracleKeys) {
|
60
|
+
const oracles = (0, generalUtils_1.zip)(oracleKeys, (await umi.rpc.getAccounts(oracleKeys.map((x) => (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(x)), { commitment: "confirmed" })).map((x) => (x.exists ? parsePriceInfo(x.data.slice(8)) : undefined))).sort((a, b) => Number(b[1]?.priceMessage.publishTime ?? 0) -
|
61
|
+
Number(a[1]?.priceMessage.publishTime ?? 0));
|
62
|
+
return oracles[0][0];
|
63
|
+
}
|
64
|
+
function getPythPushOracleAddress(feedId, shardId, programId = constants_1.PYTH_PUSH_PROGRAM) {
|
65
|
+
const shardBytes = (0, generalUtils_1.u16ToArrayBufferLE)(shardId);
|
66
|
+
return web3_js_1.PublicKey.findProgramAddressSync([shardBytes, feedId.toBuffer()], programId)[0];
|
67
|
+
}
|
@@ -323,7 +323,7 @@ function getClient(lendingPlatform, txHandlerProps) {
|
|
323
323
|
}
|
324
324
|
}
|
325
325
|
function isMarginfiClient(client) {
|
326
|
-
return client.lendingPlatform
|
326
|
+
return client.lendingPlatform === generated_1.LendingPlatform.Marginfi;
|
327
327
|
}
|
328
328
|
// TODO: PF
|
329
329
|
function hasFirstRebalance(rebalanceType) {
|
package/local/txSandbox.ts
CHANGED
@@ -17,7 +17,7 @@ import {
|
|
17
17
|
import { getSecretKey } from "./shared";
|
18
18
|
|
19
19
|
const payForTransaction = false;
|
20
|
-
const testProgram =
|
20
|
+
const testProgram = false;
|
21
21
|
|
22
22
|
export async function main() {
|
23
23
|
const [, umi] = getSolanaRpcConnection(
|
@@ -38,8 +38,8 @@ export async function main() {
|
|
38
38
|
});
|
39
39
|
|
40
40
|
await client.initialize({
|
41
|
-
positionId:
|
42
|
-
authority: new PublicKey("
|
41
|
+
positionId: 1,
|
42
|
+
authority: new PublicKey("7ZN1w3ZE51FTXxdDjPPNpdZHuXWRvDK2h6osTHNXfsuL"),
|
43
43
|
});
|
44
44
|
|
45
45
|
const transactionItems: TransactionItem[] = [];
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
marginfiAccountInitialize,
|
17
17
|
LOCAL_IRONFORGE_API_URL,
|
18
18
|
getMarginfiAccounts,
|
19
|
+
getAllBankRelatedAccounts,
|
19
20
|
} from "../src";
|
20
21
|
import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
|
21
22
|
|
@@ -38,21 +39,14 @@ const solautoManager = createSignerFromKeypair(
|
|
38
39
|
);
|
39
40
|
|
40
41
|
async function addBanks() {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
accounts.vaultAuthority,
|
50
|
-
accounts.priceOracle,
|
51
|
-
],
|
52
|
-
LOOKUP_TABLE_ADDRESS
|
53
|
-
);
|
54
|
-
}
|
55
|
-
}
|
42
|
+
const accounts = await getAllBankRelatedAccounts(
|
43
|
+
umi,
|
44
|
+
mfiAccounts.bankAccounts
|
45
|
+
);
|
46
|
+
await updateLookupTable(
|
47
|
+
accounts.map((x) => x.toString()),
|
48
|
+
LOOKUP_TABLE_ADDRESS
|
49
|
+
);
|
56
50
|
}
|
57
51
|
|
58
52
|
async function addImfiAccounts() {
|