@haven-fi/solauto-sdk 1.0.303 → 1.0.304
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 +1 -2
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +22 -26
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +4 -3
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +15 -0
- package/dist/utils/generalUtils.d.ts +2 -6
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +0 -91
- 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/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +10 -2
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +13 -12
- package/dist/utils/priceUtils.d.ts +12 -0
- package/dist/utils/priceUtils.d.ts.map +1 -0
- package/dist/utils/priceUtils.js +97 -0
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +1 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +2 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +5 -4
- package/dist/utils/switchboardUtils.d.ts +7 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -0
- package/dist/utils/switchboardUtils.js +41 -0
- package/local/createISMAccounts.ts +59 -0
- package/local/updateMarginfiLUT.ts +0 -1
- package/local/updateSolautoLUT.ts +38 -7
- package/package.json +2 -1
- package/src/clients/solautoMarginfiClient.ts +17 -28
- package/src/constants/README.md +0 -2
- package/src/transactions/transactionUtils.ts +8 -3
- package/src/transactions/transactionsManager.ts +33 -2
- package/src/utils/generalUtils.ts +2 -152
- package/src/utils/index.ts +3 -1
- package/src/utils/jupiterUtils.ts +13 -3
- package/src/utils/marginfiUtils.ts +5 -16
- package/src/utils/priceUtils.ts +154 -0
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/generalUtils.ts +3 -2
- package/src/utils/solauto/rebalanceUtils.ts +2 -1
- package/src/utils/switchboardUtils.ts +66 -0
- package/tests/transactions/solautoMarginfi.ts +38 -35
- package/tests/unit/rebalanceCalculations.ts +6 -5
- package/local/createSolautoManagerAccount.ts +0 -48
@@ -0,0 +1,97 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.fetchTokenPrices = fetchTokenPrices;
|
4
|
+
exports.getPythPrices = getPythPrices;
|
5
|
+
exports.getSwitchboardPrices = getSwitchboardPrices;
|
6
|
+
exports.safeGetPrice = safeGetPrice;
|
7
|
+
exports.getJupTokenPrices = getJupTokenPrices;
|
8
|
+
const pythConstants_1 = require("../constants/pythConstants");
|
9
|
+
const numberUtils_1 = require("./numberUtils");
|
10
|
+
const solautoConstants_1 = require("../constants/solautoConstants");
|
11
|
+
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
12
|
+
const generalUtils_1 = require("./generalUtils");
|
13
|
+
const switchboardUtils_1 = require("./switchboardUtils");
|
14
|
+
async function fetchTokenPrices(mints) {
|
15
|
+
const currentTime = (0, generalUtils_1.currentUnixSeconds)();
|
16
|
+
if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
|
17
|
+
currentTime - solautoConstants_1.PRICES[mint.toString()].time > 3)) {
|
18
|
+
return mints.map((mint) => solautoConstants_1.PRICES[mint.toString()].price);
|
19
|
+
}
|
20
|
+
const pythMints = mints.filter((x) => x.toString() in pythConstants_1.PYTH_PRICE_FEED_IDS);
|
21
|
+
const switchboardMints = mints.filter((x) => x.toString() in switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS);
|
22
|
+
const [pythData, switchboardData] = await Promise.all([
|
23
|
+
(0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
|
24
|
+
(0, generalUtils_1.zip)(switchboardMints, await getJupTokenPrices(switchboardMints)),
|
25
|
+
]);
|
26
|
+
const prices = mints.map((mint) => {
|
27
|
+
const item = [...pythData, ...switchboardData].find((data) => data[0].equals(mint));
|
28
|
+
return item ? item[1] : 0;
|
29
|
+
});
|
30
|
+
for (var i = 0; i < mints.length; i++) {
|
31
|
+
solautoConstants_1.PRICES[mints[i].toString()] = {
|
32
|
+
price: prices[i],
|
33
|
+
time: (0, generalUtils_1.currentUnixSeconds)(),
|
34
|
+
};
|
35
|
+
}
|
36
|
+
return prices;
|
37
|
+
}
|
38
|
+
async function getPythPrices(mints) {
|
39
|
+
if (mints.length === 0) {
|
40
|
+
return [];
|
41
|
+
}
|
42
|
+
const priceFeedIds = mints.map((mint) => pythConstants_1.PYTH_PRICE_FEED_IDS[mint.toString()]);
|
43
|
+
const getReq = async () => await fetch(`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`);
|
44
|
+
const prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
45
|
+
let resp = await getReq();
|
46
|
+
let status = resp.status;
|
47
|
+
if (status !== 200) {
|
48
|
+
throw new Error(JSON.stringify(resp));
|
49
|
+
}
|
50
|
+
const json = await resp.json();
|
51
|
+
const prices = json.parsed.map((x) => {
|
52
|
+
if (x.price.expo > 0) {
|
53
|
+
return Number((0, numberUtils_1.toBaseUnit)(Number(x.price.price), x.price.expo));
|
54
|
+
}
|
55
|
+
else if (x.price.expo < 0) {
|
56
|
+
return (0, numberUtils_1.fromBaseUnit)(BigInt(x.price.price), Math.abs(x.price.expo));
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
return Number(x.price.price);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
return prices;
|
63
|
+
}, 5, 200);
|
64
|
+
return prices;
|
65
|
+
}
|
66
|
+
async function getSwitchboardPrices(conn, mints) {
|
67
|
+
if (mints.length === 0) {
|
68
|
+
return [];
|
69
|
+
}
|
70
|
+
const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
|
71
|
+
const results = await Promise.all(mints.map(async (mint) => {
|
72
|
+
const feed = (0, switchboardUtils_1.getPullFeed)(conn, mint);
|
73
|
+
const result = await feed.loadData();
|
74
|
+
const price = Number(result.result.value) / Math.pow(10, 18);
|
75
|
+
const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
|
76
|
+
return { mint, price, stale };
|
77
|
+
}));
|
78
|
+
return results;
|
79
|
+
}
|
80
|
+
function safeGetPrice(mint) {
|
81
|
+
if (mint && mint?.toString() in solautoConstants_1.PRICES) {
|
82
|
+
return solautoConstants_1.PRICES[mint.toString()].price;
|
83
|
+
}
|
84
|
+
return undefined;
|
85
|
+
}
|
86
|
+
async function getJupTokenPrices(mints) {
|
87
|
+
if (mints.length == 0) {
|
88
|
+
return [];
|
89
|
+
}
|
90
|
+
const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
91
|
+
const res = (await fetch("https://api.jup.ag/price/v2?ids=" +
|
92
|
+
mints.map((x) => x.toString()).join(","))).json();
|
93
|
+
return res;
|
94
|
+
}, 6);
|
95
|
+
const prices = Object.values(data.data).map((x) => parseFloat(x.price));
|
96
|
+
return prices;
|
97
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,
|
1
|
+
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAgBzB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,UAErD;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,MAAM,UAE3D;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAgC,GAC1C,CAAC,UAAU,EAAE,GAAG,CAAC,CAQnB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAsB,GACzB,kBAAkB,CAMpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,kBAAkB,CAOpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAOpB;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,kBAAkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,EACtB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,EACvB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,GACb,kBAAkB,CAKpB;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,oBAAoB,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBpC;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,CAAC,EAAE,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBAa1B;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,CAAC,EAAE,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBA2D1B;AAuBD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,GAClC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAsB7B;AAiDD,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,eAAe,GAAE,kBAA2C,EAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CA2DjC"}
|
@@ -170,7 +170,7 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
|
|
170
170
|
}
|
171
171
|
return feeEstimate;
|
172
172
|
}
|
173
|
-
async function spamSendTransactionUntilConfirmed(connection, transaction, blockhash, spamInterval =
|
173
|
+
async function spamSendTransactionUntilConfirmed(connection, transaction, blockhash, spamInterval = 3000) {
|
174
174
|
let transactionSignature = null;
|
175
175
|
const sendTx = async () => {
|
176
176
|
try {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAGL,OAAO,EAEP,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,EAMV,MAAM,iBAAiB,CAAC;AAkBzB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"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"}
|
@@ -24,6 +24,7 @@ const accountUtils_1 = require("../accountUtils");
|
|
24
24
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
25
25
|
const constants_1 = require("../../constants");
|
26
26
|
const marginfiUtils_1 = require("../marginfiUtils");
|
27
|
+
const priceUtils_1 = require("../priceUtils");
|
27
28
|
function createDynamicSolautoProgram(programId) {
|
28
29
|
return {
|
29
30
|
name: "solauto",
|
@@ -258,7 +259,7 @@ async function getAllPositionsByAuthority(conn, umi, user, positionTypeFilter) {
|
|
258
259
|
}
|
259
260
|
async function positionStateWithLatestPrices(conn, state, supplyPrice, debtPrice) {
|
260
261
|
if (!supplyPrice || !debtPrice) {
|
261
|
-
[supplyPrice, debtPrice] = await (0,
|
262
|
+
[supplyPrice, debtPrice] = await (0, priceUtils_1.fetchTokenPrices)([
|
262
263
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint),
|
263
264
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint),
|
264
265
|
]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmI9C,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,GACnC,eAAe,CAiDjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA0D9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAyChB"}
|
@@ -9,6 +9,7 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
9
9
|
const generalUtils_2 = require("../generalUtils");
|
10
10
|
const numberUtils_1 = require("../numberUtils");
|
11
11
|
const generalAccounts_1 = require("../../constants/generalAccounts");
|
12
|
+
const priceUtils_1 = require("../priceUtils");
|
12
13
|
function getAdditionalAmountToDcaIn(dca) {
|
13
14
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
14
15
|
return 0;
|
@@ -118,11 +119,11 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
118
119
|
let flashLoanTokenPrice = 0;
|
119
120
|
if (values.rebalanceDirection === generated_1.RebalanceDirection.Boost) {
|
120
121
|
flashLoanToken = client.solautoPositionState.debt;
|
121
|
-
flashLoanTokenPrice = (0,
|
122
|
+
flashLoanTokenPrice = (0, priceUtils_1.safeGetPrice)(client.debtMint);
|
122
123
|
}
|
123
124
|
else {
|
124
125
|
flashLoanToken = client.solautoPositionState.supply;
|
125
|
-
flashLoanTokenPrice = (0,
|
126
|
+
flashLoanTokenPrice = (0, priceUtils_1.safeGetPrice)(client.supplyMint);
|
126
127
|
}
|
127
128
|
const exactAmountBaseUnit = jupQuote.swapMode === "ExactOut" || jupQuote.swapMode === "ExactIn"
|
128
129
|
? BigInt(parseInt(jupQuote.inAmount))
|
@@ -145,13 +146,13 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
145
146
|
: client.solautoPositionState.debt;
|
146
147
|
const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
|
147
148
|
(values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
148
|
-
const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0,
|
149
|
+
const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(input.mint), input.decimals);
|
149
150
|
const outputAmount = targetLiqUtilizationRateBps === 0
|
150
151
|
? output.amountUsed.baseUnit +
|
151
152
|
BigInt(Math.round(Number(output.amountUsed.baseUnit) *
|
152
153
|
// Add this small percentage to account for the APR on the debt between now and the transaction
|
153
154
|
0.0001))
|
154
|
-
: (0, numberUtils_1.toBaseUnit)(usdToSwap / (0,
|
155
|
+
: (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(output.mint), output.decimals);
|
155
156
|
const exactOut = targetLiqUtilizationRateBps === 0 || values.repayingCloseToMaxLtv;
|
156
157
|
const exactIn = !exactOut;
|
157
158
|
return {
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
2
|
+
import { PullFeed } from "@switchboard-xyz/on-demand";
|
3
|
+
import { TransactionItemInputs } from "../types";
|
4
|
+
import { Signer } from "@metaplex-foundation/umi";
|
5
|
+
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): PullFeed;
|
6
|
+
export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
7
|
+
//# sourceMappingURL=switchboardUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAkB,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAMtE,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,YAsBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAiB5C"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getPullFeed = getPullFeed;
|
7
|
+
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
8
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
9
|
+
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
10
|
+
const web3_js_1 = require("@solana/web3.js");
|
11
|
+
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
12
|
+
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
13
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
14
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
15
|
+
function getPullFeed(conn, mint, wallet) {
|
16
|
+
const dummyWallet = {
|
17
|
+
publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
|
18
|
+
signTransaction: async (tx) => tx,
|
19
|
+
signAllTransactions: async (txs) => txs,
|
20
|
+
};
|
21
|
+
const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
|
22
|
+
const program = new anchor_1.Program(switchboard_json_1.default, provider);
|
23
|
+
return new on_demand_1.PullFeed(program, new web3_js_1.PublicKey(switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()]));
|
24
|
+
}
|
25
|
+
async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
26
|
+
const crossbar = new on_demand_1.CrossbarClient("https://crossbar.switchboard.xyz");
|
27
|
+
const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
|
28
|
+
const [pullIx, responses] = await feed.fetchUpdateIx({
|
29
|
+
crossbarClient: crossbar,
|
30
|
+
});
|
31
|
+
return {
|
32
|
+
tx: (0, umi_1.transactionBuilder)().add({
|
33
|
+
bytesCreatedOnChain: 0,
|
34
|
+
instruction: (0, umi_web3js_adapters_1.fromWeb3JsInstruction)(pullIx),
|
35
|
+
signers: [signer],
|
36
|
+
}),
|
37
|
+
lookupTableAddresses: responses
|
38
|
+
.filter((x) => Boolean(x.oracle.lut?.key))
|
39
|
+
.map((x) => x.oracle.lut.key.toString()),
|
40
|
+
};
|
41
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import {
|
2
|
+
createSignerFromKeypair,
|
3
|
+
publicKey,
|
4
|
+
signerIdentity,
|
5
|
+
transactionBuilder,
|
6
|
+
} from "@metaplex-foundation/umi";
|
7
|
+
import {
|
8
|
+
buildHeliusApiUrl,
|
9
|
+
getSolanaRpcConnection,
|
10
|
+
sendSingleOptimizedTransaction,
|
11
|
+
} from "../src/utils/solanaUtils";
|
12
|
+
import { marginfiAccountInitialize, safeFetchAllMarginfiAccount } from "../src/marginfi-sdk";
|
13
|
+
import { MARGINFI_ACCOUNTS, SOLAUTO_MANAGER } from "../src/constants";
|
14
|
+
import { getSecretKey } from "./shared";
|
15
|
+
import { updateSolautoLut } from "./updateSolautoLUT";
|
16
|
+
import { getAllMarginfiAccountsByAuthority } from "../src/utils";
|
17
|
+
|
18
|
+
async function createIntermediarySolautoManagerAccounts() {
|
19
|
+
let [connection, umi] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY!));
|
20
|
+
|
21
|
+
const secretKey = getSecretKey("solauto-manager");
|
22
|
+
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
23
|
+
const signer = createSignerFromKeypair(umi, signerKeypair);
|
24
|
+
|
25
|
+
umi = umi.use(signerIdentity(signer));
|
26
|
+
|
27
|
+
const accounts = await getAllMarginfiAccountsByAuthority(connection, umi, SOLAUTO_MANAGER, false);
|
28
|
+
const data = await safeFetchAllMarginfiAccount(umi, accounts.map(x => publicKey(x.marginfiAccount)));
|
29
|
+
const existingMarginfiGroups = data.map(x => x.group.toString());
|
30
|
+
|
31
|
+
for (const group of Object.keys(MARGINFI_ACCOUNTS)) {
|
32
|
+
if (existingMarginfiGroups.includes(group.toString())) {
|
33
|
+
console.log("Already have Solauto Manager Marginfi Account for group:", group);
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
|
37
|
+
const marginfiAccount = createSignerFromKeypair(
|
38
|
+
umi,
|
39
|
+
umi.eddsa.generateKeypair()
|
40
|
+
);
|
41
|
+
|
42
|
+
const tx = marginfiAccountInitialize(umi, {
|
43
|
+
marginfiAccount,
|
44
|
+
marginfiGroup: publicKey(group),
|
45
|
+
authority: signer,
|
46
|
+
feePayer: signer,
|
47
|
+
});
|
48
|
+
|
49
|
+
await sendSingleOptimizedTransaction(
|
50
|
+
umi,
|
51
|
+
connection,
|
52
|
+
transactionBuilder().add(tx)
|
53
|
+
);
|
54
|
+
|
55
|
+
await updateSolautoLut([marginfiAccount.publicKey.toString()]);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
createIntermediarySolautoManagerAccounts();
|
@@ -1,24 +1,55 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { getTokenAccounts } from "../src/utils/accountUtils";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
SOLAUTO_FEES_WALLET,
|
5
|
+
SOLAUTO_MANAGER,
|
6
|
+
} from "../src/constants/generalAccounts";
|
4
7
|
import { ALL_SUPPORTED_TOKENS } from "../src/constants/tokenConstants";
|
5
8
|
import { updateLookupTable } from "./shared";
|
6
|
-
import {
|
9
|
+
import {
|
10
|
+
SOLAUTO_LUT,
|
11
|
+
STANDARD_LUT_ACCOUNTS,
|
12
|
+
} from "../src/constants/solautoConstants";
|
13
|
+
import {
|
14
|
+
buildHeliusApiUrl,
|
15
|
+
getAllMarginfiAccountsByAuthority,
|
16
|
+
getSolanaRpcConnection,
|
17
|
+
} from "../src/utils";
|
18
|
+
import { SWITCHBOARD_PRICE_FEED_IDS } from "../src/constants/switchboardConstants";
|
7
19
|
|
8
20
|
const LOOKUP_TABLE_ADDRESS = new PublicKey(SOLAUTO_LUT);
|
9
|
-
const solautoManagerTokenAccounts = getTokenAccounts(
|
10
|
-
|
21
|
+
const solautoManagerTokenAccounts = getTokenAccounts(
|
22
|
+
SOLAUTO_MANAGER,
|
23
|
+
ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x))
|
24
|
+
);
|
25
|
+
const solautoFeeWalletTokenAccounts = getTokenAccounts(
|
26
|
+
SOLAUTO_FEES_WALLET,
|
27
|
+
ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x))
|
28
|
+
);
|
11
29
|
|
12
30
|
export async function updateSolautoLut(additionalAccounts?: string[]) {
|
31
|
+
const [connection, umi] = getSolanaRpcConnection(
|
32
|
+
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
33
|
+
);
|
34
|
+
const ismAccounts = await getAllMarginfiAccountsByAuthority(
|
35
|
+
connection,
|
36
|
+
umi,
|
37
|
+
SOLAUTO_MANAGER,
|
38
|
+
false
|
39
|
+
);
|
40
|
+
|
13
41
|
return updateLookupTable(
|
14
42
|
[
|
15
43
|
...STANDARD_LUT_ACCOUNTS,
|
44
|
+
...ALL_SUPPORTED_TOKENS,
|
16
45
|
...solautoManagerTokenAccounts.map((x) => x.toString()),
|
17
|
-
...solautoFeeWalletTokenAccounts.map(x => x.toString()),
|
18
|
-
...(
|
46
|
+
...solautoFeeWalletTokenAccounts.map((x) => x.toString()),
|
47
|
+
...ismAccounts.map((x) => x.marginfiAccount.toString()),
|
48
|
+
...Object.values(SWITCHBOARD_PRICE_FEED_IDS),
|
49
|
+
...(additionalAccounts ?? []),
|
19
50
|
],
|
20
51
|
LOOKUP_TABLE_ADDRESS
|
21
52
|
);
|
22
53
|
}
|
23
54
|
|
24
|
-
updateSolautoLut();
|
55
|
+
updateSolautoLut();
|
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.304",
|
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",
|
@@ -13,6 +13,7 @@
|
|
13
13
|
"test:all": "pnpm test:unit && pnpm test:txs",
|
14
14
|
"update-lut:solauto": "npx ts-node local/updateSolautoLUT.ts",
|
15
15
|
"update-lut:marginfi": "npx ts-node local/updateMarginfiLUT.ts",
|
16
|
+
"create-ism-accounts": "npx ts-node local/createISMAccounts.ts",
|
16
17
|
"create-fee-accounts": "npx ts-node local/createFeeAccounts.ts"
|
17
18
|
},
|
18
19
|
"dependencies": {
|
@@ -33,12 +33,8 @@ import {
|
|
33
33
|
marginfiRebalance,
|
34
34
|
marginfiRefreshData,
|
35
35
|
} from "../generated";
|
36
|
-
import {
|
37
|
-
|
38
|
-
getReferralState,
|
39
|
-
getTokenAccount,
|
40
|
-
} from "../utils/accountUtils";
|
41
|
-
import { generateRandomU64, safeGetPrice } from "../utils/generalUtils";
|
36
|
+
import { getMarginfiAccountPDA, getTokenAccount } from "../utils/accountUtils";
|
37
|
+
import { generateRandomU64 } from "../utils/generalUtils";
|
42
38
|
import {
|
43
39
|
MARGINFI_PROGRAM_ID,
|
44
40
|
MarginfiAccount,
|
@@ -64,6 +60,7 @@ import {
|
|
64
60
|
} from "../utils/marginfiUtils";
|
65
61
|
import { bytesToI80F48, fromBaseUnit, toBps } from "../utils/numberUtils";
|
66
62
|
import { QuoteResponse } from "@jup-ag/api";
|
63
|
+
import { safeGetPrice } from "../utils";
|
67
64
|
|
68
65
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
69
66
|
marginfiAccount?: PublicKey | Signer;
|
@@ -126,9 +123,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
126
123
|
)
|
127
124
|
: null;
|
128
125
|
this.marginfiGroup = new PublicKey(
|
129
|
-
|
126
|
+
marginfiAccountData
|
130
127
|
? marginfiAccountData.group.toString()
|
131
|
-
: args.marginfiGroup
|
128
|
+
: (args.marginfiGroup ?? DEFAULT_MARGINFI_GROUP)
|
132
129
|
);
|
133
130
|
|
134
131
|
this.marginfiSupplyAccounts =
|
@@ -171,7 +168,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
171
168
|
.sort((a, b) =>
|
172
169
|
a.marginfiAccount.toString().localeCompare(b.marginfiAccount.toString())
|
173
170
|
);
|
174
|
-
const
|
171
|
+
const compatibleMarginfiAccounts =
|
175
172
|
existingMarginfiAccounts.length > 0
|
176
173
|
? (
|
177
174
|
await safeFetchAllMarginfiAccount(
|
@@ -180,6 +177,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
180
177
|
)
|
181
178
|
).filter(
|
182
179
|
(x) =>
|
180
|
+
x.group.toString() === this.marginfiGroup.toString() &&
|
183
181
|
x.lendingAccount.balances.find(
|
184
182
|
(y) =>
|
185
183
|
y.bankPk.toString() !== PublicKey.default.toString() &&
|
@@ -190,15 +188,17 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
190
188
|
: [];
|
191
189
|
|
192
190
|
this.intermediaryMarginfiAccountSigner =
|
193
|
-
|
191
|
+
compatibleMarginfiAccounts.length > 0
|
194
192
|
? undefined
|
195
193
|
: createSignerFromKeypair(this.umi, this.umi.eddsa.generateKeypair());
|
196
194
|
this.intermediaryMarginfiAccountPk =
|
197
|
-
|
198
|
-
? toWeb3JsPublicKey(
|
195
|
+
compatibleMarginfiAccounts.length > 0
|
196
|
+
? toWeb3JsPublicKey(compatibleMarginfiAccounts[0].publicKey)
|
199
197
|
: toWeb3JsPublicKey(this.intermediaryMarginfiAccountSigner!.publicKey);
|
200
198
|
this.intermediaryMarginfiAccount =
|
201
|
-
|
199
|
+
compatibleMarginfiAccounts.length > 0
|
200
|
+
? compatibleMarginfiAccounts[0]
|
201
|
+
: undefined;
|
202
202
|
}
|
203
203
|
|
204
204
|
protocolAccount(): PublicKey {
|
@@ -230,7 +230,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
230
230
|
return [0, 0];
|
231
231
|
} else {
|
232
232
|
const [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
233
|
-
this.connection,
|
234
233
|
this.umi,
|
235
234
|
this.marginfiGroup,
|
236
235
|
{
|
@@ -246,9 +245,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
246
245
|
}
|
247
246
|
}
|
248
247
|
|
249
|
-
marginfiAccountInitialize(): TransactionBuilder {
|
248
|
+
marginfiAccountInitialize(marginfiAccount: Signer): TransactionBuilder {
|
250
249
|
return marginfiAccountInitialize(this.umi, {
|
251
|
-
marginfiAccount:
|
250
|
+
marginfiAccount: marginfiAccount,
|
252
251
|
marginfiGroup: publicKey(this.marginfiGroup),
|
253
252
|
authority: this.signer,
|
254
253
|
feePayer: this.signer,
|
@@ -569,7 +568,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
569
568
|
bankLiquidityVaultAuthority: publicKey(bank.vaultAuthority),
|
570
569
|
destinationTokenAccount: publicKey(destinationTokenAccount),
|
571
570
|
marginfiAccount: publicKey(this.intermediaryMarginfiAccountPk),
|
572
|
-
marginfiGroup: publicKey(
|
571
|
+
marginfiGroup: publicKey(this.marginfiGroup),
|
573
572
|
signer: this.signer,
|
574
573
|
})
|
575
574
|
);
|
@@ -641,7 +640,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
641
640
|
bank: publicKey(accounts.data.bank),
|
642
641
|
bankLiquidityVault: publicKey(accounts.data.liquidityVault),
|
643
642
|
marginfiAccount: publicKey(this.intermediaryMarginfiAccountPk),
|
644
|
-
marginfiGroup: publicKey(
|
643
|
+
marginfiGroup: publicKey(this.marginfiGroup),
|
645
644
|
signer: this.signer,
|
646
645
|
signerTokenAccount: publicKey(
|
647
646
|
getTokenAccount(
|
@@ -659,15 +658,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
659
658
|
);
|
660
659
|
}
|
661
660
|
|
662
|
-
createIntermediaryMarginfiAccount(): TransactionBuilder {
|
663
|
-
return marginfiAccountInitialize(this.umi, {
|
664
|
-
marginfiAccount: this.intermediaryMarginfiAccountSigner!,
|
665
|
-
marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
|
666
|
-
authority: this.signer,
|
667
|
-
feePayer: this.signer,
|
668
|
-
});
|
669
|
-
}
|
670
|
-
|
671
661
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
672
662
|
const state = await super.getFreshPositionState();
|
673
663
|
if (state) {
|
@@ -680,7 +670,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
680
670
|
!toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority));
|
681
671
|
|
682
672
|
const freshState = await getMarginfiAccountPositionState(
|
683
|
-
this.connection,
|
684
673
|
this.umi,
|
685
674
|
{ pk: this.marginfiAccountPk },
|
686
675
|
this.marginfiGroup,
|
package/src/constants/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
Instruction,
|
3
3
|
ProgramError,
|
4
|
+
Signer,
|
4
5
|
TransactionBuilder,
|
5
6
|
Umi,
|
6
7
|
publicKey,
|
@@ -42,7 +43,6 @@ import {
|
|
42
43
|
currentUnixSeconds,
|
43
44
|
getSolanaAccountCreated,
|
44
45
|
rpcAccountCreated,
|
45
|
-
safeGetPrice,
|
46
46
|
} from "../utils/generalUtils";
|
47
47
|
import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
|
48
48
|
import {
|
@@ -71,6 +71,7 @@ import {
|
|
71
71
|
} from "../jupiter-sdk";
|
72
72
|
import { PRICES } from "../constants";
|
73
73
|
import { TransactionItemInputs } from "../types";
|
74
|
+
import { safeGetPrice } from "../utils";
|
74
75
|
|
75
76
|
interface wSolTokenUsage {
|
76
77
|
wSolTokenAccount: PublicKey;
|
@@ -161,7 +162,9 @@ async function transactionChoresBefore(
|
|
161
162
|
))
|
162
163
|
) {
|
163
164
|
chores = chores.add(
|
164
|
-
(client as SolautoMarginfiClient).marginfiAccountInitialize(
|
165
|
+
(client as SolautoMarginfiClient).marginfiAccountInitialize(
|
166
|
+
(client as SolautoMarginfiClient).marginfiAccount as Signer
|
167
|
+
)
|
165
168
|
);
|
166
169
|
}
|
167
170
|
// TODO: PF
|
@@ -335,7 +338,9 @@ export async function rebalanceChoresBefore(
|
|
335
338
|
) {
|
336
339
|
client.log("Creating intermediary marginfi account");
|
337
340
|
chores = chores.add(
|
338
|
-
(client as SolautoMarginfiClient).
|
341
|
+
(client as SolautoMarginfiClient).marginfiAccountInitialize(
|
342
|
+
(client as SolautoMarginfiClient).intermediaryMarginfiAccountSigner!
|
343
|
+
)
|
339
344
|
);
|
340
345
|
}
|
341
346
|
|
@@ -23,8 +23,12 @@ import {
|
|
23
23
|
TransactionRunType,
|
24
24
|
} from "../types";
|
25
25
|
import { ReferralStateManager, TxHandler } from "../clients";
|
26
|
-
import {
|
27
|
-
|
26
|
+
import {
|
27
|
+
PublicKey,
|
28
|
+
TransactionExpiredBlockheightExceededError,
|
29
|
+
} from "@solana/web3.js";
|
30
|
+
import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants/switchboardConstants";
|
31
|
+
import { buildSwbSubmitResponseTx, getSwitchboardPrices } from "../utils";
|
28
32
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
29
33
|
|
30
34
|
const CHORES_TX_NAME = "account chores";
|
@@ -386,6 +390,33 @@ export class TransactionsManager {
|
|
386
390
|
await item.initialize();
|
387
391
|
}
|
388
392
|
|
393
|
+
const allAccounts = items.flatMap((x) =>
|
394
|
+
x.tx
|
395
|
+
?.getInstructions()
|
396
|
+
.flatMap((x) => x.keys.map((x) => x.pubkey.toString()))
|
397
|
+
);
|
398
|
+
const swbOracle = allAccounts.find((x) =>
|
399
|
+
Object.values(SWITCHBOARD_PRICE_FEED_IDS).includes(x ?? "")
|
400
|
+
);
|
401
|
+
if (swbOracle) {
|
402
|
+
const mint = new PublicKey(
|
403
|
+
Object.keys(SWITCHBOARD_PRICE_FEED_IDS).find(
|
404
|
+
(x) => SWITCHBOARD_PRICE_FEED_IDS[x] === swbOracle
|
405
|
+
)!
|
406
|
+
);
|
407
|
+
const stale = (await getSwitchboardPrices(client.connection, [mint]))[0]
|
408
|
+
.stale;
|
409
|
+
|
410
|
+
if (stale) {
|
411
|
+
const swbTx = new TransactionItem(
|
412
|
+
async () =>
|
413
|
+
buildSwbSubmitResponseTx(client.connection, client.signer, mint),
|
414
|
+
items.length === 1 ? "Update oracle" : ""
|
415
|
+
);
|
416
|
+
items.unshift(swbTx);
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
389
420
|
let [choresBefore, choresAfter] = await getTransactionChores(
|
390
421
|
client,
|
391
422
|
transactionBuilder().add(
|