@0dotxyz/p0-ts-sdk 2.2.3-alpha.1 → 2.2.4
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/{dto-rate-model.types-AQ40wS-P.d.cts → dto-rate-model.types-DveIB9Ll.d.cts} +1 -1
- package/dist/{dto-rate-model.types-AQ40wS-P.d.ts → dto-rate-model.types-DveIB9Ll.d.ts} +1 -1
- package/dist/index.cjs +93 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -22
- package/dist/index.d.ts +27 -22
- package/dist/index.js +94 -36
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.cts +2 -2
- package/dist/instructions.d.ts +2 -2
- package/dist/jupiter.cjs +61 -0
- package/dist/jupiter.cjs.map +1 -0
- package/dist/jupiter.d.cts +124 -0
- package/dist/jupiter.d.ts +124 -0
- package/dist/jupiter.js +58 -0
- package/dist/jupiter.js.map +1 -0
- package/dist/{types-DGWxbPM1.d.ts → types-CsLjciLo.d.cts} +2 -2
- package/dist/{types-ZvnTjjh4.d.cts → types-DuCxJVOn.d.ts} +2 -2
- package/dist/vendor.cjs +2834 -0
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +2837 -3
- package/dist/vendor.d.ts +2837 -3
- package/dist/vendor.js +2834 -1
- package/dist/vendor.js.map +1 -1
- package/package.json +6 -2
|
@@ -1723,4 +1723,4 @@ interface JupRateModelJSON {
|
|
|
1723
1723
|
rateAtKink2: number;
|
|
1724
1724
|
}
|
|
1725
1725
|
|
|
1726
|
-
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type
|
|
1726
|
+
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type FarmStateRaw as F, type PriceHeuristicFields as G, type HistoricalOracleData as H, type InsuranceFund as I, type JupLendingState as J, type ScopeConfigurationFields as K, type SwitchboardConfigurationFields as L, type PythConfigurationFields as M, type ReserveLiquidityJSON as N, type ObligationRaw as O, type PoolBalance as P, type ReserveCollateralJSON as Q, type ReserveRaw as R, type SpotPosition as S, type TokenInfoFields$1 as T, type ReserveConfigJSON as U, type ReserveFeesJSON as V, type WithdrawalCapsFields as W, type BorrowRateCurveJSON as X, type CurvePointJSON as Y, type TokenInfoJSON$1 as Z, type PriceHeuristicJSON as _, type DriftUser as a, type SwitchboardConfigurationJSON as a0, type PythConfigurationJSON as a1, type WithdrawalCapsJSON as a2, type ObligationLiquidityJSON as a3, type ObligationCollateralJSON as a4, type ObligationOrderJSON as a5, type ObligationCollateralFields as a6, type ObligationLiquidityFields as a7, type ObligationOrderFields as a8, type LastUpdateFields as a9, type BigFractionBytesFields as aa, type LastUpdateJSON as ab, type BigFractionBytesJSON as ac, type RewardPerTimeUnitPointFields as ad, type RewardScheduleCurveFields as ae, type RewardScheduleCurveJSON as af, type RewardPerTimeUnitPointJSON as ag, type UserFeesJSON as ah, type UserFeesFields as ai, isSpotBalanceTypeVariant as aj, type FeeTier as ak, type FeeTierJSON as al, type OrderFillerRewardStructure as am, type OrderFillerRewardStructureJSON as an, type PriceDivergenceGuardRails as ao, type PriceDivergenceGuardRailsJSON as ap, type ValidityGuardRails as aq, type ValidityGuardRailsJSON as ar, type HistoricalOracleDataJSON as as, type HistoricalIndexDataJSON as at, type PoolBalanceJSON as au, type InsuranceFundJSON as av, SpotBalanceType as aw, type SpotPositionJSON as ax, type DriftRewards as b, type DriftUserStats as c, type JupTokenReserve as d, type JupLendingRewardsRateModel as e, type JupRateModel as f, type ReserveJSON as g, type ObligationJSON as h, type FarmStateJSON as i, type DriftSpotMarketJSON as j, type DriftUserJSON as k, type DriftRewardsJSON as l, type DriftUserStatsJSON as m, type JupLendingStateJSON as n, type JupTokenReserveJSON as o, type JupLendingRewardsRateModelJSON as p, type JupRateModelJSON as q, type RewardInfoFields as r, type HistoricalIndexData as s, type FeeStructureJSON as t, type OracleGuardRailsJSON as u, type FeeStructure as v, type OracleGuardRails as w, DriftSpotBalanceType as x, type ReserveLiquidityFields as y, type ReserveCollateralFields as z };
|
|
@@ -1723,4 +1723,4 @@ interface JupRateModelJSON {
|
|
|
1723
1723
|
rateAtKink2: number;
|
|
1724
1724
|
}
|
|
1725
1725
|
|
|
1726
|
-
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type
|
|
1726
|
+
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type FarmStateRaw as F, type PriceHeuristicFields as G, type HistoricalOracleData as H, type InsuranceFund as I, type JupLendingState as J, type ScopeConfigurationFields as K, type SwitchboardConfigurationFields as L, type PythConfigurationFields as M, type ReserveLiquidityJSON as N, type ObligationRaw as O, type PoolBalance as P, type ReserveCollateralJSON as Q, type ReserveRaw as R, type SpotPosition as S, type TokenInfoFields$1 as T, type ReserveConfigJSON as U, type ReserveFeesJSON as V, type WithdrawalCapsFields as W, type BorrowRateCurveJSON as X, type CurvePointJSON as Y, type TokenInfoJSON$1 as Z, type PriceHeuristicJSON as _, type DriftUser as a, type SwitchboardConfigurationJSON as a0, type PythConfigurationJSON as a1, type WithdrawalCapsJSON as a2, type ObligationLiquidityJSON as a3, type ObligationCollateralJSON as a4, type ObligationOrderJSON as a5, type ObligationCollateralFields as a6, type ObligationLiquidityFields as a7, type ObligationOrderFields as a8, type LastUpdateFields as a9, type BigFractionBytesFields as aa, type LastUpdateJSON as ab, type BigFractionBytesJSON as ac, type RewardPerTimeUnitPointFields as ad, type RewardScheduleCurveFields as ae, type RewardScheduleCurveJSON as af, type RewardPerTimeUnitPointJSON as ag, type UserFeesJSON as ah, type UserFeesFields as ai, isSpotBalanceTypeVariant as aj, type FeeTier as ak, type FeeTierJSON as al, type OrderFillerRewardStructure as am, type OrderFillerRewardStructureJSON as an, type PriceDivergenceGuardRails as ao, type PriceDivergenceGuardRailsJSON as ap, type ValidityGuardRails as aq, type ValidityGuardRailsJSON as ar, type HistoricalOracleDataJSON as as, type HistoricalIndexDataJSON as at, type PoolBalanceJSON as au, type InsuranceFundJSON as av, SpotBalanceType as aw, type SpotPositionJSON as ax, type DriftRewards as b, type DriftUserStats as c, type JupTokenReserve as d, type JupLendingRewardsRateModel as e, type JupRateModel as f, type ReserveJSON as g, type ObligationJSON as h, type FarmStateJSON as i, type DriftSpotMarketJSON as j, type DriftUserJSON as k, type DriftRewardsJSON as l, type DriftUserStatsJSON as m, type JupLendingStateJSON as n, type JupTokenReserveJSON as o, type JupLendingRewardsRateModelJSON as p, type JupRateModelJSON as q, type RewardInfoFields as r, type HistoricalIndexData as s, type FeeStructureJSON as t, type OracleGuardRailsJSON as u, type FeeStructure as v, type OracleGuardRails as w, DriftSpotBalanceType as x, type ReserveLiquidityFields as y, type ReserveCollateralFields as z };
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,6 @@ var borsh$1 = require('borsh');
|
|
|
13
13
|
var borsh = require('@coral-xyz/borsh');
|
|
14
14
|
var WebSocket = require('ws');
|
|
15
15
|
var msgpack = require('@msgpack/msgpack');
|
|
16
|
-
var api = require('@jup-ag/api');
|
|
17
16
|
var onDemand = require('@switchboard-xyz/on-demand');
|
|
18
17
|
var common = require('@switchboard-xyz/common');
|
|
19
18
|
|
|
@@ -36125,9 +36124,9 @@ async function makeAccountTransferToNewAccountTx({
|
|
|
36125
36124
|
marginfiAccount,
|
|
36126
36125
|
newMarginfiAccount,
|
|
36127
36126
|
newAuthority,
|
|
36128
|
-
feePayer
|
|
36129
|
-
feePayerKeypair
|
|
36127
|
+
feePayer
|
|
36130
36128
|
}) {
|
|
36129
|
+
const feePayerKey = feePayer instanceof web3_js.Keypair ? feePayer.publicKey : feePayer ?? marginfiAccount.authority;
|
|
36131
36130
|
const [feeStateKey] = web3_js.PublicKey.findProgramAddressSync(
|
|
36132
36131
|
[Buffer.from("feestate", "utf-8")],
|
|
36133
36132
|
program.programId
|
|
@@ -36138,18 +36137,18 @@ async function makeAccountTransferToNewAccountTx({
|
|
|
36138
36137
|
newMarginfiAccount: newMarginfiAccount.publicKey,
|
|
36139
36138
|
newAuthority,
|
|
36140
36139
|
globalFeeWallet: feeState.globalFeeWallet,
|
|
36141
|
-
feePayer
|
|
36140
|
+
feePayer: feePayerKey
|
|
36142
36141
|
});
|
|
36143
36142
|
const {
|
|
36144
36143
|
value: { blockhash }
|
|
36145
36144
|
} = await connection.getLatestBlockhashAndContext("confirmed");
|
|
36146
36145
|
const signers = [newMarginfiAccount];
|
|
36147
|
-
if (
|
|
36146
|
+
if (feePayer instanceof web3_js.Keypair) signers.push(feePayer);
|
|
36148
36147
|
const transferTx = addTransactionMetadata(
|
|
36149
36148
|
new web3_js.VersionedTransaction(
|
|
36150
36149
|
new web3_js.TransactionMessage({
|
|
36151
36150
|
instructions: [transferIx],
|
|
36152
|
-
payerKey:
|
|
36151
|
+
payerKey: feePayerKey,
|
|
36153
36152
|
recentBlockhash: blockhash
|
|
36154
36153
|
}).compileToV0Message([])
|
|
36155
36154
|
),
|
|
@@ -49231,6 +49230,61 @@ function computeMaxWithdrawForBank(params) {
|
|
|
49231
49230
|
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
|
|
49232
49231
|
return maxWithdraw;
|
|
49233
49232
|
}
|
|
49233
|
+
|
|
49234
|
+
// src/vendor/jupiter/client.ts
|
|
49235
|
+
var DEFAULT_BASE_PATH = "https://lite-api.jup.ag/swap/v1";
|
|
49236
|
+
var JupiterApiError = class _JupiterApiError extends Error {
|
|
49237
|
+
status;
|
|
49238
|
+
body;
|
|
49239
|
+
constructor(status, body) {
|
|
49240
|
+
super(`Jupiter API request failed with status ${status}: ${body}`);
|
|
49241
|
+
this.name = "JupiterApiError";
|
|
49242
|
+
Object.setPrototypeOf(this, _JupiterApiError.prototype);
|
|
49243
|
+
this.status = status;
|
|
49244
|
+
this.body = body;
|
|
49245
|
+
}
|
|
49246
|
+
};
|
|
49247
|
+
function buildQuoteSearchParams(request) {
|
|
49248
|
+
const params = new URLSearchParams();
|
|
49249
|
+
for (const [key, value] of Object.entries(request)) {
|
|
49250
|
+
if (value === void 0 || value === null) continue;
|
|
49251
|
+
if (Array.isArray(value)) {
|
|
49252
|
+
if (value.length > 0) params.append(key, value.join(","));
|
|
49253
|
+
continue;
|
|
49254
|
+
}
|
|
49255
|
+
params.append(key, String(value));
|
|
49256
|
+
}
|
|
49257
|
+
return params;
|
|
49258
|
+
}
|
|
49259
|
+
function createJupiterClient(config = {}) {
|
|
49260
|
+
const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
|
|
49261
|
+
const baseHeaders = { ...config.headers };
|
|
49262
|
+
if (config.apiKey) baseHeaders["x-api-key"] = config.apiKey;
|
|
49263
|
+
const request = async (path, init) => {
|
|
49264
|
+
const response = await fetch(`${basePath}${path}`, init);
|
|
49265
|
+
if (!response.ok) {
|
|
49266
|
+
const body = await response.text().catch(() => "");
|
|
49267
|
+
throw new JupiterApiError(response.status, body);
|
|
49268
|
+
}
|
|
49269
|
+
return await response.json();
|
|
49270
|
+
};
|
|
49271
|
+
return {
|
|
49272
|
+
quoteGet(quoteRequest) {
|
|
49273
|
+
const search = buildQuoteSearchParams(quoteRequest);
|
|
49274
|
+
return request(`/quote?${search.toString()}`, {
|
|
49275
|
+
method: "GET",
|
|
49276
|
+
headers: baseHeaders
|
|
49277
|
+
});
|
|
49278
|
+
},
|
|
49279
|
+
swapInstructionsPost({ swapRequest }) {
|
|
49280
|
+
return request(`/swap-instructions`, {
|
|
49281
|
+
method: "POST",
|
|
49282
|
+
headers: { ...baseHeaders, "content-type": "application/json" },
|
|
49283
|
+
body: JSON.stringify(swapRequest)
|
|
49284
|
+
});
|
|
49285
|
+
}
|
|
49286
|
+
};
|
|
49287
|
+
}
|
|
49234
49288
|
var TITAN_FEE_WALLET = new web3_js.PublicKey("FEES6XLN7dMz2iBwKab9Hri9Kwc4WJ6TmDAiT4BNhyej");
|
|
49235
49289
|
var getTitanFeeAccount = (mint) => {
|
|
49236
49290
|
return getAssociatedTokenAddressSync(mint, TITAN_FEE_WALLET, true);
|
|
@@ -49608,15 +49662,17 @@ function getExactOutProviderFn({
|
|
|
49608
49662
|
});
|
|
49609
49663
|
case "JUPITER" /* JUPITER */:
|
|
49610
49664
|
return async () => {
|
|
49611
|
-
const
|
|
49612
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49665
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49613
49666
|
const estimateQuote = await jupiterApiClient.quoteGet({
|
|
49614
49667
|
inputMint,
|
|
49615
49668
|
outputMint,
|
|
49616
49669
|
amount,
|
|
49617
49670
|
swapMode: "ExactOut",
|
|
49618
49671
|
dynamicSlippage: swapOpts.swapConfig ? swapOpts.swapConfig.slippageMode === "DYNAMIC" : true,
|
|
49619
|
-
slippageBps: swapOpts.swapConfig?.slippageBps
|
|
49672
|
+
slippageBps: swapOpts.swapConfig?.slippageBps,
|
|
49673
|
+
// Match the bundle-compatible routing used by the executed flashloan
|
|
49674
|
+
// swap so the ExactOut estimate reflects an achievable route.
|
|
49675
|
+
forJitoBundle: true
|
|
49620
49676
|
});
|
|
49621
49677
|
const quoteResult = mapJupiterQuoteToSwapQuoteResult(estimateQuote);
|
|
49622
49678
|
return { otherAmountThreshold: quoteResult.otherAmountThreshold, quoteResult };
|
|
@@ -49772,7 +49828,7 @@ function toJupiterConfig(apiConfig) {
|
|
|
49772
49828
|
if (!apiConfig) return void 0;
|
|
49773
49829
|
return {
|
|
49774
49830
|
basePath: apiConfig.basePath,
|
|
49775
|
-
apiKey: apiConfig.apiKey
|
|
49831
|
+
apiKey: apiConfig.apiKey,
|
|
49776
49832
|
headers: apiConfig.headers
|
|
49777
49833
|
};
|
|
49778
49834
|
}
|
|
@@ -49784,8 +49840,7 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49784
49840
|
apiConfig,
|
|
49785
49841
|
maxSwapAccounts
|
|
49786
49842
|
}) => {
|
|
49787
|
-
const
|
|
49788
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49843
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49789
49844
|
const feeMint = quoteParams.swapMode === "ExactIn" ? quoteParams.outputMint : quoteParams.inputMint;
|
|
49790
49845
|
const { feeAccount, hasFeeAccount } = await checkFeeAccount(connection, new web3_js.PublicKey(feeMint));
|
|
49791
49846
|
const project0JupiterLut = (await connection.getAddressLookupTable(ADDRESS_LOOKUP_TABLE_FOR_SWAP))?.value;
|
|
@@ -49804,7 +49859,10 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49804
49859
|
const maxAccounts = maxSwapAccounts !== void 0 ? maxSwapAccounts - JUPITER_MAX_ACCOUNTS_MARGIN : 40;
|
|
49805
49860
|
const swapQuote = await jupiterApiClient.quoteGet({
|
|
49806
49861
|
...finalQuoteParams,
|
|
49807
|
-
maxAccounts
|
|
49862
|
+
maxAccounts,
|
|
49863
|
+
// Flashloan swaps are landed via a Jito bundle, so restrict routing to
|
|
49864
|
+
// bundle-compatible DEXes (excludes e.g. HumidiFi).
|
|
49865
|
+
forJitoBundle: true
|
|
49808
49866
|
});
|
|
49809
49867
|
const swapInstructionResponse = await jupiterApiClient.swapInstructionsPost({
|
|
49810
49868
|
swapRequest: {
|
|
@@ -54139,30 +54197,29 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
54139
54197
|
return makeEndFlashLoanIx3(program, this.address, banks, authority);
|
|
54140
54198
|
}
|
|
54141
54199
|
/**
|
|
54142
|
-
*
|
|
54200
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54143
54201
|
*
|
|
54144
|
-
*
|
|
54202
|
+
* Thin wrapper over the {@link makeAccountTransferToNewAccountTx} action,
|
|
54203
|
+
* injecting the connection and this account from context. The global fee
|
|
54204
|
+
* wallet is derived inside the action from the program's fee state.
|
|
54145
54205
|
*
|
|
54146
54206
|
* @param program - The Marginfi program instance
|
|
54147
|
-
* @param newMarginfiAccount -
|
|
54207
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54148
54208
|
* @param newAuthority - The new authority public key
|
|
54209
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54210
|
+
* payer); defaults to this account's authority
|
|
54149
54211
|
*
|
|
54150
|
-
* @returns Promise resolving to
|
|
54151
|
-
*
|
|
54152
|
-
* @see {@link makeAccountTransferToNewAccountIx} for implementation
|
|
54212
|
+
* @returns Promise resolving to the transfer transaction
|
|
54153
54213
|
*/
|
|
54154
|
-
async
|
|
54155
|
-
|
|
54214
|
+
async makeAccountTransferToNewAccountTx(program, newMarginfiAccount, newAuthority, feePayer) {
|
|
54215
|
+
return makeAccountTransferToNewAccountTx({
|
|
54216
|
+
connection: program.provider.connection,
|
|
54156
54217
|
program,
|
|
54157
|
-
|
|
54158
|
-
|
|
54159
|
-
|
|
54160
|
-
|
|
54161
|
-
|
|
54162
|
-
feePayer
|
|
54163
|
-
}
|
|
54164
|
-
);
|
|
54165
|
-
return { instructions: [accountTransferToNewAccountIx], keys: [] };
|
|
54218
|
+
marginfiAccount: this,
|
|
54219
|
+
newMarginfiAccount,
|
|
54220
|
+
newAuthority,
|
|
54221
|
+
feePayer
|
|
54222
|
+
});
|
|
54166
54223
|
}
|
|
54167
54224
|
/**
|
|
54168
54225
|
* Creates an instruction to close this marginfi account.
|
|
@@ -54810,17 +54867,18 @@ var MarginfiAccountWrapper = class {
|
|
|
54810
54867
|
);
|
|
54811
54868
|
}
|
|
54812
54869
|
/**
|
|
54813
|
-
*
|
|
54870
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54814
54871
|
*
|
|
54815
|
-
* @param newMarginfiAccount -
|
|
54872
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54816
54873
|
* @param newAuthority - New authority public key
|
|
54874
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54875
|
+
* payer); defaults to this account's authority
|
|
54817
54876
|
*/
|
|
54818
|
-
async
|
|
54819
|
-
return this.account.
|
|
54877
|
+
async makeAccountTransferToNewAccountTx(newMarginfiAccount, newAuthority, feePayer) {
|
|
54878
|
+
return this.account.makeAccountTransferToNewAccountTx(
|
|
54820
54879
|
this.client.program,
|
|
54821
54880
|
newMarginfiAccount,
|
|
54822
54881
|
newAuthority,
|
|
54823
|
-
globalFeeWallet,
|
|
54824
54882
|
feePayer
|
|
54825
54883
|
);
|
|
54826
54884
|
}
|