@haven-fi/solauto-sdk 1.0.647 → 1.0.649
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 +0 -1
- package/dist/generated/types/positionData.d.ts +6 -6
- package/dist/generated/types/positionData.d.ts.map +1 -1
- package/dist/generated/types/positionData.js +3 -3
- package/dist/idls/switchboard.json +1949 -1
- package/dist/pyth-sdk/accounts/index.d.ts +9 -0
- package/dist/pyth-sdk/accounts/index.d.ts.map +1 -0
- package/dist/pyth-sdk/accounts/index.js +24 -0
- package/dist/pyth-sdk/accounts/priceUpdateV2Account.d.ts +39 -0
- package/dist/pyth-sdk/accounts/priceUpdateV2Account.d.ts.map +1 -0
- package/dist/pyth-sdk/accounts/priceUpdateV2Account.js +75 -0
- package/dist/pyth-sdk/index.d.ts +10 -0
- package/dist/pyth-sdk/index.d.ts.map +1 -0
- package/dist/pyth-sdk/index.js +25 -0
- package/dist/pyth-sdk/types/index.d.ts +10 -0
- package/dist/pyth-sdk/types/index.d.ts.map +1 -0
- package/dist/pyth-sdk/types/index.js +25 -0
- package/dist/pyth-sdk/types/priceMessage.d.ts +31 -0
- package/dist/pyth-sdk/types/priceMessage.d.ts.map +1 -0
- package/dist/pyth-sdk/types/priceMessage.js +23 -0
- package/dist/pyth-sdk/types/priceUpdateV2.d.ts +24 -0
- package/dist/pyth-sdk/types/priceUpdateV2.d.ts.map +1 -0
- package/dist/pyth-sdk/types/priceUpdateV2.js +20 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +0 -2
- package/dist/services/solauto/solautoClient.d.ts +0 -1
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/swap/jupSwapManager.d.ts.map +1 -1
- package/dist/services/swap/jupSwapManager.js +3 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +2 -2
- package/dist/utils/instructionUtils.d.ts.map +1 -1
- package/dist/utils/instructionUtils.js +0 -3
- package/dist/utils/numberUtils.js +1 -1
- package/dist/utils/pythUtils.d.ts +0 -16
- package/dist/utils/pythUtils.d.ts.map +1 -1
- package/dist/utils/pythUtils.js +3 -52
- package/dist/utils/solautoUtils.js +3 -3
- package/package.json +1 -2
- package/src/generated/types/positionData.ts +9 -9
- package/src/idls/switchboard.json +1949 -1
- package/src/pyth-sdk/accounts/index.ts +9 -0
- package/src/pyth-sdk/accounts/priceUpdateV2Account.ts +179 -0
- package/src/pyth-sdk/index.ts +10 -0
- package/src/pyth-sdk/types/index.ts +10 -0
- package/src/pyth-sdk/types/priceMessage.ts +58 -0
- package/src/pyth-sdk/types/priceUpdateV2.ts +46 -0
- package/src/services/rebalance/rebalanceSwapManager.ts +0 -3
- package/src/services/solauto/solautoClient.ts +0 -1
- package/src/services/swap/jupSwapManager.ts +6 -1
- package/src/solautoPosition/solautoPositionEx.ts +5 -4
- package/src/utils/instructionUtils.ts +0 -2
- package/src/utils/numberUtils.ts +1 -1
- package/src/utils/pythUtils.ts +7 -54
- package/src/utils/solautoUtils.ts +3 -3
- package/tests/unit/rebalanceCalculations.ts +4 -4
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
export * from './priceUpdateV2Account';
|
@@ -0,0 +1,179 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
import {
|
10
|
+
Account,
|
11
|
+
Context,
|
12
|
+
Pda,
|
13
|
+
PublicKey,
|
14
|
+
RpcAccount,
|
15
|
+
RpcGetAccountOptions,
|
16
|
+
RpcGetAccountsOptions,
|
17
|
+
assertAccountExists,
|
18
|
+
deserializeAccount,
|
19
|
+
gpaBuilder,
|
20
|
+
publicKey as toPublicKey,
|
21
|
+
} from '@metaplex-foundation/umi';
|
22
|
+
import {
|
23
|
+
Serializer,
|
24
|
+
array,
|
25
|
+
mapSerializer,
|
26
|
+
publicKey as publicKeySerializer,
|
27
|
+
struct,
|
28
|
+
u64,
|
29
|
+
u8,
|
30
|
+
} from '@metaplex-foundation/umi/serializers';
|
31
|
+
import {
|
32
|
+
PriceMessage,
|
33
|
+
PriceMessageArgs,
|
34
|
+
getPriceMessageSerializer,
|
35
|
+
} from '../types';
|
36
|
+
|
37
|
+
export type PriceUpdateV2Account = Account<PriceUpdateV2AccountAccountData>;
|
38
|
+
|
39
|
+
export type PriceUpdateV2AccountAccountData = {
|
40
|
+
discriminator: Array<number>;
|
41
|
+
writeAuthority: PublicKey;
|
42
|
+
verificationLevel: number;
|
43
|
+
priceMessage: PriceMessage;
|
44
|
+
postedSlot: bigint;
|
45
|
+
};
|
46
|
+
|
47
|
+
export type PriceUpdateV2AccountAccountDataArgs = {
|
48
|
+
writeAuthority: PublicKey;
|
49
|
+
verificationLevel: number;
|
50
|
+
priceMessage: PriceMessageArgs;
|
51
|
+
postedSlot: number | bigint;
|
52
|
+
};
|
53
|
+
|
54
|
+
export function getPriceUpdateV2AccountAccountDataSerializer(): Serializer<
|
55
|
+
PriceUpdateV2AccountAccountDataArgs,
|
56
|
+
PriceUpdateV2AccountAccountData
|
57
|
+
> {
|
58
|
+
return mapSerializer<
|
59
|
+
PriceUpdateV2AccountAccountDataArgs,
|
60
|
+
any,
|
61
|
+
PriceUpdateV2AccountAccountData
|
62
|
+
>(
|
63
|
+
struct<PriceUpdateV2AccountAccountData>(
|
64
|
+
[
|
65
|
+
['discriminator', array(u8(), { size: 8 })],
|
66
|
+
['writeAuthority', publicKeySerializer()],
|
67
|
+
['verificationLevel', u8()],
|
68
|
+
['priceMessage', getPriceMessageSerializer()],
|
69
|
+
['postedSlot', u64()],
|
70
|
+
],
|
71
|
+
{ description: 'PriceUpdateV2AccountAccountData' }
|
72
|
+
),
|
73
|
+
(value) => ({
|
74
|
+
...value,
|
75
|
+
discriminator: [93, 77, 250, 192, 211, 157, 97, 248],
|
76
|
+
})
|
77
|
+
) as Serializer<
|
78
|
+
PriceUpdateV2AccountAccountDataArgs,
|
79
|
+
PriceUpdateV2AccountAccountData
|
80
|
+
>;
|
81
|
+
}
|
82
|
+
|
83
|
+
export function deserializePriceUpdateV2Account(
|
84
|
+
rawAccount: RpcAccount
|
85
|
+
): PriceUpdateV2Account {
|
86
|
+
return deserializeAccount(
|
87
|
+
rawAccount,
|
88
|
+
getPriceUpdateV2AccountAccountDataSerializer()
|
89
|
+
);
|
90
|
+
}
|
91
|
+
|
92
|
+
export async function fetchPriceUpdateV2Account(
|
93
|
+
context: Pick<Context, 'rpc'>,
|
94
|
+
publicKey: PublicKey | Pda,
|
95
|
+
options?: RpcGetAccountOptions
|
96
|
+
): Promise<PriceUpdateV2Account> {
|
97
|
+
const maybeAccount = await context.rpc.getAccount(
|
98
|
+
toPublicKey(publicKey, false),
|
99
|
+
options
|
100
|
+
);
|
101
|
+
assertAccountExists(maybeAccount, 'PriceUpdateV2Account');
|
102
|
+
return deserializePriceUpdateV2Account(maybeAccount);
|
103
|
+
}
|
104
|
+
|
105
|
+
export async function safeFetchPriceUpdateV2Account(
|
106
|
+
context: Pick<Context, 'rpc'>,
|
107
|
+
publicKey: PublicKey | Pda,
|
108
|
+
options?: RpcGetAccountOptions
|
109
|
+
): Promise<PriceUpdateV2Account | null> {
|
110
|
+
const maybeAccount = await context.rpc.getAccount(
|
111
|
+
toPublicKey(publicKey, false),
|
112
|
+
options
|
113
|
+
);
|
114
|
+
return maybeAccount.exists
|
115
|
+
? deserializePriceUpdateV2Account(maybeAccount)
|
116
|
+
: null;
|
117
|
+
}
|
118
|
+
|
119
|
+
export async function fetchAllPriceUpdateV2Account(
|
120
|
+
context: Pick<Context, 'rpc'>,
|
121
|
+
publicKeys: Array<PublicKey | Pda>,
|
122
|
+
options?: RpcGetAccountsOptions
|
123
|
+
): Promise<PriceUpdateV2Account[]> {
|
124
|
+
const maybeAccounts = await context.rpc.getAccounts(
|
125
|
+
publicKeys.map((key) => toPublicKey(key, false)),
|
126
|
+
options
|
127
|
+
);
|
128
|
+
return maybeAccounts.map((maybeAccount) => {
|
129
|
+
assertAccountExists(maybeAccount, 'PriceUpdateV2Account');
|
130
|
+
return deserializePriceUpdateV2Account(maybeAccount);
|
131
|
+
});
|
132
|
+
}
|
133
|
+
|
134
|
+
export async function safeFetchAllPriceUpdateV2Account(
|
135
|
+
context: Pick<Context, 'rpc'>,
|
136
|
+
publicKeys: Array<PublicKey | Pda>,
|
137
|
+
options?: RpcGetAccountsOptions
|
138
|
+
): Promise<PriceUpdateV2Account[]> {
|
139
|
+
const maybeAccounts = await context.rpc.getAccounts(
|
140
|
+
publicKeys.map((key) => toPublicKey(key, false)),
|
141
|
+
options
|
142
|
+
);
|
143
|
+
return maybeAccounts
|
144
|
+
.filter((maybeAccount) => maybeAccount.exists)
|
145
|
+
.map((maybeAccount) =>
|
146
|
+
deserializePriceUpdateV2Account(maybeAccount as RpcAccount)
|
147
|
+
);
|
148
|
+
}
|
149
|
+
|
150
|
+
export function getPriceUpdateV2AccountGpaBuilder(
|
151
|
+
context: Pick<Context, 'rpc' | 'programs'>
|
152
|
+
) {
|
153
|
+
const programId = context.programs.getPublicKey(
|
154
|
+
'',
|
155
|
+
'pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT'
|
156
|
+
);
|
157
|
+
return gpaBuilder(context, programId)
|
158
|
+
.registerFields<{
|
159
|
+
discriminator: Array<number>;
|
160
|
+
writeAuthority: PublicKey;
|
161
|
+
verificationLevel: number;
|
162
|
+
priceMessage: PriceMessageArgs;
|
163
|
+
postedSlot: number | bigint;
|
164
|
+
}>({
|
165
|
+
discriminator: [0, array(u8(), { size: 8 })],
|
166
|
+
writeAuthority: [8, publicKeySerializer()],
|
167
|
+
verificationLevel: [40, u8()],
|
168
|
+
priceMessage: [41, getPriceMessageSerializer()],
|
169
|
+
postedSlot: [125, u64()],
|
170
|
+
})
|
171
|
+
.deserializeUsing<PriceUpdateV2Account>((account) =>
|
172
|
+
deserializePriceUpdateV2Account(account)
|
173
|
+
)
|
174
|
+
.whereField('discriminator', [93, 77, 250, 192, 211, 157, 97, 248]);
|
175
|
+
}
|
176
|
+
|
177
|
+
export function getPriceUpdateV2AccountSize(): number {
|
178
|
+
return 133;
|
179
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
export * from './accounts';
|
10
|
+
export * from './types';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
export * from './priceMessage';
|
10
|
+
export * from './priceUpdateV2';
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
import { PublicKey } from '@metaplex-foundation/umi';
|
10
|
+
import {
|
11
|
+
Serializer,
|
12
|
+
i32,
|
13
|
+
i64,
|
14
|
+
publicKey as publicKeySerializer,
|
15
|
+
struct,
|
16
|
+
u64,
|
17
|
+
} from '@metaplex-foundation/umi/serializers';
|
18
|
+
|
19
|
+
export type PriceMessage = {
|
20
|
+
feedId: PublicKey;
|
21
|
+
price: bigint;
|
22
|
+
conf: bigint;
|
23
|
+
exponent: number;
|
24
|
+
publishTime: bigint;
|
25
|
+
prevPublishTime: bigint;
|
26
|
+
emaPrice: bigint;
|
27
|
+
emaConf: bigint;
|
28
|
+
};
|
29
|
+
|
30
|
+
export type PriceMessageArgs = {
|
31
|
+
feedId: PublicKey;
|
32
|
+
price: number | bigint;
|
33
|
+
conf: number | bigint;
|
34
|
+
exponent: number;
|
35
|
+
publishTime: number | bigint;
|
36
|
+
prevPublishTime: number | bigint;
|
37
|
+
emaPrice: number | bigint;
|
38
|
+
emaConf: number | bigint;
|
39
|
+
};
|
40
|
+
|
41
|
+
export function getPriceMessageSerializer(): Serializer<
|
42
|
+
PriceMessageArgs,
|
43
|
+
PriceMessage
|
44
|
+
> {
|
45
|
+
return struct<PriceMessage>(
|
46
|
+
[
|
47
|
+
['feedId', publicKeySerializer()],
|
48
|
+
['price', i64()],
|
49
|
+
['conf', u64()],
|
50
|
+
['exponent', i32()],
|
51
|
+
['publishTime', i64()],
|
52
|
+
['prevPublishTime', i64()],
|
53
|
+
['emaPrice', i64()],
|
54
|
+
['emaConf', u64()],
|
55
|
+
],
|
56
|
+
{ description: 'PriceMessage' }
|
57
|
+
) as Serializer<PriceMessageArgs, PriceMessage>;
|
58
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/**
|
2
|
+
* This code was AUTOGENERATED using the kinobi library.
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
4
|
+
* to add features, then rerun kinobi to update it.
|
5
|
+
*
|
6
|
+
* @see https://github.com/metaplex-foundation/kinobi
|
7
|
+
*/
|
8
|
+
|
9
|
+
import { PublicKey } from '@metaplex-foundation/umi';
|
10
|
+
import {
|
11
|
+
Serializer,
|
12
|
+
publicKey as publicKeySerializer,
|
13
|
+
struct,
|
14
|
+
u64,
|
15
|
+
u8,
|
16
|
+
} from '@metaplex-foundation/umi/serializers';
|
17
|
+
import { PriceMessage, PriceMessageArgs, getPriceMessageSerializer } from '.';
|
18
|
+
|
19
|
+
export type PriceUpdateV2 = {
|
20
|
+
writeAuthority: PublicKey;
|
21
|
+
verificationLevel: number;
|
22
|
+
priceMessage: PriceMessage;
|
23
|
+
postedSlot: bigint;
|
24
|
+
};
|
25
|
+
|
26
|
+
export type PriceUpdateV2Args = {
|
27
|
+
writeAuthority: PublicKey;
|
28
|
+
verificationLevel: number;
|
29
|
+
priceMessage: PriceMessageArgs;
|
30
|
+
postedSlot: number | bigint;
|
31
|
+
};
|
32
|
+
|
33
|
+
export function getPriceUpdateV2Serializer(): Serializer<
|
34
|
+
PriceUpdateV2Args,
|
35
|
+
PriceUpdateV2
|
36
|
+
> {
|
37
|
+
return struct<PriceUpdateV2>(
|
38
|
+
[
|
39
|
+
['writeAuthority', publicKeySerializer()],
|
40
|
+
['verificationLevel', u8()],
|
41
|
+
['priceMessage', getPriceMessageSerializer()],
|
42
|
+
['postedSlot', u64()],
|
43
|
+
],
|
44
|
+
{ description: 'PriceUpdateV2' }
|
45
|
+
) as Serializer<PriceUpdateV2Args, PriceUpdateV2>;
|
46
|
+
}
|
@@ -166,15 +166,12 @@ export class RebalanceSwapManager {
|
|
166
166
|
|
167
167
|
const inputMint = toWeb3JsPublicKey(input.mint);
|
168
168
|
const outputMint = toWeb3JsPublicKey(output.mint);
|
169
|
-
const swappingMeme =
|
170
|
-
tokenInfo(inputMint).isMeme || tokenInfo(outputMint).isMeme;
|
171
169
|
const swapInput: SwapInput = {
|
172
170
|
inputMint,
|
173
171
|
outputMint,
|
174
172
|
exactIn,
|
175
173
|
exactOut,
|
176
174
|
amount: swapAmount,
|
177
|
-
slippageBps: swappingMeme ? 250 : 100,
|
178
175
|
};
|
179
176
|
consoleLog("Swap input:", swapInput);
|
180
177
|
|
@@ -18,6 +18,7 @@ import {
|
|
18
18
|
toBps,
|
19
19
|
getTokenAccount,
|
20
20
|
jupIxToSolanaIx,
|
21
|
+
tokenInfo,
|
21
22
|
} from "../../utils";
|
22
23
|
import { TransactionItemInputs } from "../../types";
|
23
24
|
|
@@ -52,6 +53,10 @@ export class JupSwapManager {
|
|
52
53
|
constructor(private signer: Signer) {}
|
53
54
|
|
54
55
|
public async getQuote(data: SwapInput): Promise<QuoteResponse> {
|
56
|
+
const memeSwap =
|
57
|
+
tokenInfo(data.inputMint).isMeme || tokenInfo(data.outputMint).isMeme;
|
58
|
+
const slippageBps = data.slippageBps ?? (memeSwap ? 250 : 100);
|
59
|
+
|
55
60
|
return await retryWithExponentialBackoff(
|
56
61
|
async (attemptNum: number) =>
|
57
62
|
await this.jupApi.quoteGet({
|
@@ -63,7 +68,7 @@ export class JupSwapManager {
|
|
63
68
|
: data.exactIn
|
64
69
|
? "ExactIn"
|
65
70
|
: undefined,
|
66
|
-
slippageBps
|
71
|
+
slippageBps,
|
67
72
|
maxAccounts: !data.exactOut ? 15 + attemptNum * 5 : undefined,
|
68
73
|
}),
|
69
74
|
4,
|
@@ -16,7 +16,6 @@ import {
|
|
16
16
|
import {
|
17
17
|
calcDebtUsd,
|
18
18
|
calcNetWorth,
|
19
|
-
calcNetWorthUsd,
|
20
19
|
calcSupplyUsd,
|
21
20
|
calcTotalDebt,
|
22
21
|
calcTotalSupply,
|
@@ -25,7 +24,6 @@ import {
|
|
25
24
|
currentUnixSeconds,
|
26
25
|
debtLiquidityAvailable,
|
27
26
|
debtLiquidityUsdAvailable,
|
28
|
-
fetchTokenPrices,
|
29
27
|
getLiqUtilzationRateBps,
|
30
28
|
maxBoostToBps,
|
31
29
|
maxRepayFromBps,
|
@@ -92,7 +90,7 @@ export abstract class SolautoPositionEx {
|
|
92
90
|
this.lpUserAccount =
|
93
91
|
args.customArgs?.lpUserAccount ??
|
94
92
|
(args.data.position
|
95
|
-
? toWeb3JsPublicKey(args.data.position!.
|
93
|
+
? toWeb3JsPublicKey(args.data.position!.lpUserAccount)
|
96
94
|
: undefined);
|
97
95
|
this.lpEnv = args.customArgs?.lpEnv ?? "Prod";
|
98
96
|
|
@@ -193,7 +191,10 @@ export abstract class SolautoPositionEx {
|
|
193
191
|
}
|
194
192
|
|
195
193
|
get repayFromBps() {
|
196
|
-
return
|
194
|
+
return Math.min(
|
195
|
+
(this.settings?.repayToBps ?? 0) + (this.settings?.repayGap ?? 0),
|
196
|
+
this.maxRepayFromBps
|
197
|
+
);
|
197
198
|
}
|
198
199
|
|
199
200
|
get maxRepayFromBps() {
|
@@ -139,13 +139,11 @@ export function swapThenDeposit(
|
|
139
139
|
) {
|
140
140
|
return [
|
141
141
|
new TransactionItem(async () => {
|
142
|
-
const memeSwap = tokenInfo(client.pos.supplyMint).isMeme;
|
143
142
|
const swapInput: SwapInput = {
|
144
143
|
inputMint: depositMint,
|
145
144
|
outputMint: client.pos.supplyMint,
|
146
145
|
amount: depositAmountBaseUnit,
|
147
146
|
exactIn: true,
|
148
|
-
slippageBps: memeSwap ? 250 : 100,
|
149
147
|
};
|
150
148
|
const jupSwapManager = new JupSwapManager(client.signer);
|
151
149
|
const { setupIx, swapIx, cleanupIx, lookupTableAddresses } =
|
package/src/utils/numberUtils.ts
CHANGED
@@ -168,7 +168,7 @@ export function getMaxLiqUtilizationRateBps(
|
|
168
168
|
|
169
169
|
export function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number) {
|
170
170
|
return Math.min(
|
171
|
-
|
171
|
+
9000,
|
172
172
|
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000, OFFSET_FROM_MAX_LTV)
|
173
173
|
);
|
174
174
|
}
|
package/src/utils/pythUtils.ts
CHANGED
@@ -1,54 +1,8 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
2
3
|
import { PYTH_PUSH_PROGRAM } from "../constants";
|
3
4
|
import { u16ToArrayBufferLE, zip } from "./generalUtils";
|
4
|
-
import
|
5
|
-
import { Umi } from "@metaplex-foundation/umi";
|
6
|
-
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
7
|
-
|
8
|
-
type PriceUpdateV2 = {
|
9
|
-
writeAuthority: Buffer;
|
10
|
-
verificationLevel: number;
|
11
|
-
priceMessage: {
|
12
|
-
feedId: Buffer;
|
13
|
-
price: bigint;
|
14
|
-
conf: bigint;
|
15
|
-
exponent: number;
|
16
|
-
publishTime: bigint;
|
17
|
-
prevPublishTime: bigint;
|
18
|
-
emaPrice: bigint;
|
19
|
-
emaConf: bigint;
|
20
|
-
};
|
21
|
-
};
|
22
|
-
|
23
|
-
const priceUpdateV2Schema = {
|
24
|
-
struct: {
|
25
|
-
writeAuthority: {
|
26
|
-
array: { type: "u8", len: 32 },
|
27
|
-
},
|
28
|
-
verificationLevel: "u8",
|
29
|
-
priceMessage: {
|
30
|
-
struct: {
|
31
|
-
feedId: { array: { type: "u8", len: 32 } },
|
32
|
-
price: "i64",
|
33
|
-
conf: "u64",
|
34
|
-
exponent: "i32",
|
35
|
-
publishTime: "i64",
|
36
|
-
prevPublishTime: "i64",
|
37
|
-
emaPrice: "i64",
|
38
|
-
emaConf: "u64",
|
39
|
-
},
|
40
|
-
},
|
41
|
-
postedSlot: "u64",
|
42
|
-
},
|
43
|
-
};
|
44
|
-
|
45
|
-
export function parsePriceInfo(data: Uint8Array): PriceUpdateV2 {
|
46
|
-
let decoded: PriceUpdateV2 = borsh.deserialize(
|
47
|
-
priceUpdateV2Schema,
|
48
|
-
data
|
49
|
-
) as any;
|
50
|
-
return decoded;
|
51
|
-
}
|
5
|
+
import { safeFetchAllPriceUpdateV2Account } from "../pyth-sdk";
|
52
6
|
|
53
7
|
export async function getMostUpToDatePythOracle(
|
54
8
|
umi: Umi,
|
@@ -56,12 +10,11 @@ export async function getMostUpToDatePythOracle(
|
|
56
10
|
) {
|
57
11
|
const oracles = zip(
|
58
12
|
oracleKeys,
|
59
|
-
(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
).map((x) => (x.exists ? parsePriceInfo(x!.data.slice(8)) : undefined))
|
13
|
+
await safeFetchAllPriceUpdateV2Account(
|
14
|
+
umi,
|
15
|
+
oracleKeys.map((x) => publicKey(x)),
|
16
|
+
{ commitment: "confirmed" }
|
17
|
+
)
|
65
18
|
).sort(
|
66
19
|
(a, b) =>
|
67
20
|
Number(b[1]?.priceMessage.publishTime ?? 0) -
|
@@ -177,10 +177,10 @@ export async function getSolautoManagedPositions(
|
|
177
177
|
if (position.position.lendingPlatform === LendingPlatform.Marginfi) {
|
178
178
|
tokens = [
|
179
179
|
findMarginfiAccounts(
|
180
|
-
toWeb3JsPublicKey(position.position.
|
180
|
+
toWeb3JsPublicKey(position.position.lpSupplyAccount)
|
181
181
|
).mint,
|
182
182
|
findMarginfiAccounts(
|
183
|
-
toWeb3JsPublicKey(position.position.
|
183
|
+
toWeb3JsPublicKey(position.position.lpDebtAccount)
|
184
184
|
).mint,
|
185
185
|
];
|
186
186
|
}
|
@@ -192,7 +192,7 @@ export async function getSolautoManagedPositions(
|
|
192
192
|
positionId: position.positionId[0],
|
193
193
|
lendingPlatform: position.position.lendingPlatform,
|
194
194
|
positionType: position.positionType,
|
195
|
-
lpUserAccount: toWeb3JsPublicKey(position.position.
|
195
|
+
lpUserAccount: toWeb3JsPublicKey(position.position.lpUserAccount),
|
196
196
|
supplyMint: tokens![0],
|
197
197
|
debtMint: tokens![1],
|
198
198
|
};
|
@@ -36,7 +36,7 @@ function assertAccurateRebalance(
|
|
36
36
|
SolautoFeesBps.create(
|
37
37
|
false,
|
38
38
|
targetLiqUtilizationRateBps,
|
39
|
-
client.pos.netWorthUsd
|
39
|
+
client.pos.netWorthUsd()
|
40
40
|
),
|
41
41
|
50
|
42
42
|
);
|
@@ -99,9 +99,9 @@ async function getFakePosition(
|
|
99
99
|
state: fakeState,
|
100
100
|
position: {
|
101
101
|
lendingPlatform: LendingPlatform.Marginfi,
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
lpUserAccount: publicKey(PublicKey.default),
|
103
|
+
lpSupplyAccount: publicKey(PublicKey.default),
|
104
|
+
lpDebtAccount: publicKey(PublicKey.default),
|
105
105
|
settings,
|
106
106
|
dca: null,
|
107
107
|
padding: [],
|