@symmetry-hq/sdk 1.0.12 → 1.0.13
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/src/states/oracles/oracle.d.ts +1 -1
- package/dist/src/states/oracles/oracle.js +9 -14
- package/dist/src/states/oracles/pythOracle.d.ts +6 -2
- package/dist/src/states/oracles/pythOracle.js +11 -8
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +1 -1
- package/dist/src/states/oracles/raydiumCpmmOracle.js +4 -3
- package/dist/test.js +6 -6
- package/package.json +1 -1
- package/src/states/oracles/oracle.ts +11 -16
- package/src/states/oracles/pythOracle.ts +19 -14
- package/src/states/oracles/raydiumCpmmOracle.ts +5 -4
- package/test.ts +11 -9
|
@@ -20,5 +20,5 @@ export declare class PriceAggregator {
|
|
|
20
20
|
minOraclesThresh: number;
|
|
21
21
|
confMultiplier: Fraction;
|
|
22
22
|
constructor(numOracles: number, oracles: OracleData[], minConfBps: number, confThreshBps: number, minOraclesThresh: number, confMultiplier: Fraction);
|
|
23
|
-
static fetch(oracleAggregator: OracleAggregator, lutAccounts: AddressLookupTableAccount[], accountInfoMap: Map<string, AccountInfo<Buffer> | null>,
|
|
23
|
+
static fetch(oracleAggregator: OracleAggregator, lutAccounts: AddressLookupTableAccount[], accountInfoMap: Map<string, AccountInfo<Buffer> | null>, wsolPrice: OraclePrice, usdcPrice: OraclePrice, pythPriceOverrides?: Map<string, OraclePrice>): OraclePrice;
|
|
24
24
|
}
|
|
@@ -54,7 +54,7 @@ class PriceAggregator {
|
|
|
54
54
|
if (!(0 <= this.minOraclesThresh && this.minOraclesThresh <= constants_2.U32_MAX.toNumber()))
|
|
55
55
|
throw new Error(`Minimum number of oracles must be between 0 and ${constants_2.U32_MAX}`);
|
|
56
56
|
}
|
|
57
|
-
static fetch(oracleAggregator, lutAccounts, accountInfoMap,
|
|
57
|
+
static fetch(oracleAggregator, lutAccounts, accountInfoMap, wsolPrice, usdcPrice, pythPriceOverrides) {
|
|
58
58
|
let validated = true;
|
|
59
59
|
const agg = oracleAggregator;
|
|
60
60
|
const oracleResults = [];
|
|
@@ -62,15 +62,11 @@ class PriceAggregator {
|
|
|
62
62
|
const oracleData = agg.oracles[i];
|
|
63
63
|
const settings = oracleData.oracleSettings;
|
|
64
64
|
let loadedAccounts = [];
|
|
65
|
-
let firstLoadedPubkey;
|
|
66
65
|
for (let j = 0; j < settings.numRequiredAccounts; j++) {
|
|
67
66
|
const lutId = oracleData.accountsToLoadLutIds[j];
|
|
68
67
|
const lutIdx = oracleData.accountsToLoadLutIndices[j];
|
|
69
68
|
const pubkey = lutAccounts[lutId].state.addresses[lutIdx];
|
|
70
69
|
const account = accountInfoMap.get(pubkey.toBase58());
|
|
71
|
-
if (!firstLoadedPubkey) {
|
|
72
|
-
firstLoadedPubkey = pubkey;
|
|
73
|
-
}
|
|
74
70
|
// @ts-ignore
|
|
75
71
|
loadedAccounts.push(account);
|
|
76
72
|
}
|
|
@@ -95,17 +91,16 @@ class PriceAggregator {
|
|
|
95
91
|
let result = (() => {
|
|
96
92
|
switch (settings.oracleType) {
|
|
97
93
|
case oracle_1.OracleType.Pyth:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return pythOracle_1.PythOracle.fetch(settings, loadedAccounts, solPrice, usdPrice);
|
|
94
|
+
const lutId = oracleData.accountsToLoadLutIds[0];
|
|
95
|
+
const lutIdx = oracleData.accountsToLoadLutIndices[0];
|
|
96
|
+
const pubkey = lutAccounts[lutId].state.addresses[lutIdx];
|
|
97
|
+
const override = pythPriceOverrides === null || pythPriceOverrides === void 0 ? void 0 : pythPriceOverrides.get(pubkey.toBase58());
|
|
98
|
+
const price = pythOracle_1.PythOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
99
|
+
return (override ? override : price);
|
|
105
100
|
case oracle_1.OracleType.RaydiumClmm:
|
|
106
|
-
return raydiumClmmOracle_1.RaydiumCLMMOracle.fetch(settings, loadedAccounts,
|
|
101
|
+
return raydiumClmmOracle_1.RaydiumCLMMOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
107
102
|
case oracle_1.OracleType.RaydiumCpmm:
|
|
108
|
-
return raydiumCpmmOracle_1.RaydiumCPMMOracle.fetch(settings, loadedAccounts,
|
|
103
|
+
return raydiumCpmmOracle_1.RaydiumCPMMOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
109
104
|
default:
|
|
110
105
|
throw new Error(`Invalid oracle type: ${settings.oracleType}`);
|
|
111
106
|
}
|
|
@@ -14,7 +14,7 @@ export interface HermesPythPriceData {
|
|
|
14
14
|
emaConf?: string | number;
|
|
15
15
|
}
|
|
16
16
|
export declare function fetchHermesPythPrices(priceFeedIds: string[]): Promise<Map<string, HermesPythPriceData>>;
|
|
17
|
-
export declare function buildPythOraclePriceFromHermesPriceData(oracleParams: OracleSettings, priceData: HermesPythPriceData,
|
|
17
|
+
export declare function buildPythOraclePriceFromHermesPriceData(oracleParams: OracleSettings, priceData: HermesPythPriceData, wsolPrice: OraclePrice, usdcPrice: OraclePrice): OraclePrice;
|
|
18
18
|
export type VerificationLevel = {
|
|
19
19
|
kind: 'Partial';
|
|
20
20
|
numSignatures: number;
|
|
@@ -38,6 +38,10 @@ export interface InstructionWithSigners {
|
|
|
38
38
|
signers: Keypair[];
|
|
39
39
|
computeUnits?: number;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Build closeEncodedVaa instruction
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildCloseEncodedVaaInstruction(writeAuthority: PublicKey, encodedVaa: PublicKey, wormholeProgramId?: PublicKey): TransactionInstruction;
|
|
41
45
|
export interface PythUpdateResult {
|
|
42
46
|
postInstructions: InstructionWithSigners[];
|
|
43
47
|
closeInstructions: InstructionWithSigners[];
|
|
@@ -140,5 +144,5 @@ export declare class PythState {
|
|
|
140
144
|
static decode(buf: Buffer, offset?: number): [PythState, number];
|
|
141
145
|
}
|
|
142
146
|
export declare class PythOracle {
|
|
143
|
-
static fetch(oracleParams: OracleSettings, accountInfos: AccountInfo<Buffer>[],
|
|
147
|
+
static fetch(oracleParams: OracleSettings, accountInfos: AccountInfo<Buffer>[], wsolPrice?: OraclePrice, usdcPrice?: OraclePrice): OraclePrice;
|
|
144
148
|
}
|
|
@@ -20,6 +20,7 @@ exports.buildFreshVaultPythPriceOverrides = buildFreshVaultPythPriceOverrides;
|
|
|
20
20
|
exports.getRandomTipAccount = getRandomTipAccount;
|
|
21
21
|
exports.buildJitoTipInstruction = buildJitoTipInstruction;
|
|
22
22
|
exports.getPythPriceFeedAccountAddress = getPythPriceFeedAccountAddress;
|
|
23
|
+
exports.buildCloseEncodedVaaInstruction = buildCloseEncodedVaaInstruction;
|
|
23
24
|
exports.parsePriceFeedMessage = parsePriceFeedMessage;
|
|
24
25
|
exports.parseAccumulatorUpdateData = parseAccumulatorUpdateData;
|
|
25
26
|
exports.getSizeOfTransaction = getSizeOfTransaction;
|
|
@@ -72,17 +73,19 @@ function fetchHermesPythPrices(priceFeedIds) {
|
|
|
72
73
|
return result;
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
|
-
function buildPythOraclePriceFromHermesPriceData(oracleParams, priceData,
|
|
76
|
+
function buildPythOraclePriceFromHermesPriceData(oracleParams, priceData, wsolPrice, usdcPrice) {
|
|
76
77
|
var _a;
|
|
78
|
+
let quoteDecimals = (oracleParams.quote == oracle_1.Quote.Usdc) ? constants_1.USDC_DECIMALS : ((oracleParams.quote == oracle_1.Quote.Wsol) ? constants_1.WSOL_DECIMALS : 0);
|
|
77
79
|
let pr = new decimal_js_1.default(priceData.price.toString())
|
|
78
|
-
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
80
|
+
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
79
81
|
let ema = new decimal_js_1.default(((_a = priceData.emaPrice) !== null && _a !== void 0 ? _a : priceData.price).toString())
|
|
80
|
-
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
82
|
+
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
81
83
|
let cf = new decimal_js_1.default(priceData.conf.toString())
|
|
82
|
-
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
84
|
+
.mul(decimal_js_1.default.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
83
85
|
const lastUpdateTimestamp = priceData.publishTime;
|
|
84
|
-
let quotePrice = (oracleParams.quote === oracle_1.Quote.Usdc) ?
|
|
85
|
-
((oracleParams.quote === oracle_1.Quote.Wsol) ?
|
|
86
|
+
let quotePrice = (oracleParams.quote === oracle_1.Quote.Usdc) ? usdcPrice :
|
|
87
|
+
((oracleParams.quote === oracle_1.Quote.Wsol) ? wsolPrice :
|
|
88
|
+
new oracle_2.OraclePrice(new decimal_js_1.default(1), new decimal_js_1.default(0), 0));
|
|
86
89
|
pr = pr.mul(quotePrice.price);
|
|
87
90
|
ema = ema.mul(quotePrice.price);
|
|
88
91
|
cf = cf.mul(quotePrice.price);
|
|
@@ -711,7 +714,7 @@ class PythState {
|
|
|
711
714
|
}
|
|
712
715
|
exports.PythState = PythState;
|
|
713
716
|
class PythOracle {
|
|
714
|
-
static fetch(oracleParams, accountInfos,
|
|
717
|
+
static fetch(oracleParams, accountInfos, wsolPrice, usdcPrice) {
|
|
715
718
|
//@ts-ignore
|
|
716
719
|
let state = null;
|
|
717
720
|
try {
|
|
@@ -729,7 +732,7 @@ class PythOracle {
|
|
|
729
732
|
publishTime: parseInt(state.priceMessage.publishTime.toString()),
|
|
730
733
|
emaPrice: state.priceMessage.emaPrice.toString(),
|
|
731
734
|
emaConf: state.priceMessage.emaConf.toString(),
|
|
732
|
-
},
|
|
735
|
+
}, wsolPrice !== null && wsolPrice !== void 0 ? wsolPrice : new oracle_2.OraclePrice(new decimal_js_1.default(1), new decimal_js_1.default(0), 0), usdcPrice !== null && usdcPrice !== void 0 ? usdcPrice : new oracle_2.OraclePrice(new decimal_js_1.default(1), new decimal_js_1.default(0), 0));
|
|
733
736
|
}
|
|
734
737
|
}
|
|
735
738
|
exports.PythOracle = PythOracle;
|
|
@@ -115,6 +115,6 @@ export declare class RaydiumCPMMOracle {
|
|
|
115
115
|
* - SELL: delta_quote_out = netQuote * delta_base / (netBase + delta_base)
|
|
116
116
|
*/
|
|
117
117
|
static calculateMaxPriceImpactForMinLiquidity(oracleParams: OracleSettings, netBase: Decimal, netQuote: Decimal, spotPriceUsd: Decimal, quotePrice: OraclePrice): Decimal;
|
|
118
|
-
static fetch(oracleParams: OracleSettings, accountInfos: AccountInfo<Buffer>[],
|
|
118
|
+
static fetch(oracleParams: OracleSettings, accountInfos: AccountInfo<Buffer>[], wsolPrice: OraclePrice, usdcPrice: OraclePrice): OraclePrice;
|
|
119
119
|
}
|
|
120
120
|
export {};
|
|
@@ -462,7 +462,7 @@ class RaydiumCPMMOracle {
|
|
|
462
462
|
const maxImpact = decimal_js_1.default.max(impactBuy, impactSell);
|
|
463
463
|
return maxImpact.mul(new decimal_js_1.default(10000)); // Convert to bps
|
|
464
464
|
}
|
|
465
|
-
static fetch(oracleParams, accountInfos,
|
|
465
|
+
static fetch(oracleParams, accountInfos, wsolPrice, usdcPrice) {
|
|
466
466
|
const poolStateInfo = accountInfos[0];
|
|
467
467
|
const vault0Info = accountInfos[1];
|
|
468
468
|
const vault1Info = accountInfos[2];
|
|
@@ -473,8 +473,9 @@ class RaydiumCPMMOracle {
|
|
|
473
473
|
const [decodedObservationState, ____] = ObservationState.decode(observationStateInfo.data, 8);
|
|
474
474
|
const currentTime = new bn_js_1.default(Math.floor(Date.now() / 1000));
|
|
475
475
|
// Determine quote oracle
|
|
476
|
-
let quotePrice = (oracleParams.quote === oracle_1.Quote.Usdc) ?
|
|
477
|
-
((oracleParams.quote === oracle_1.Quote.Wsol) ?
|
|
476
|
+
let quotePrice = (oracleParams.quote === oracle_1.Quote.Usdc) ? usdcPrice :
|
|
477
|
+
((oracleParams.quote === oracle_1.Quote.Wsol) ? wsolPrice :
|
|
478
|
+
new oracle_2.OraclePrice(new decimal_js_1.default(1), new decimal_js_1.default(0), 0));
|
|
478
479
|
// Get spot price with reserves
|
|
479
480
|
const { netBase, netQuote, spotPrice } = this.getSpotPriceWithReserves(decodedPoolState, decodedVault0State, decodedVault1State, oracleParams.side, quotePrice);
|
|
480
481
|
// Get TWAP prices
|
package/dist/test.js
CHANGED
|
@@ -521,13 +521,13 @@ function testStates() {
|
|
|
521
521
|
symmetryLimitOrderFeeBps: 0,
|
|
522
522
|
symmetryFeesExtraData: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
|
|
523
523
|
bountyMint: new web3_js_1.PublicKey("So11111111111111111111111111111111111111112"),
|
|
524
|
-
minBountyForVaultAutomation: new anchor_1.BN(
|
|
525
|
-
bountyBondAmount: new anchor_1.BN(
|
|
524
|
+
minBountyForVaultAutomation: new anchor_1.BN(2000 * 5000),
|
|
525
|
+
bountyBondAmount: new anchor_1.BN(20 * 5000),
|
|
526
526
|
bountyPerTask: {
|
|
527
|
-
minBounty: new anchor_1.BN(
|
|
528
|
-
maxBounty: new anchor_1.BN(
|
|
529
|
-
minBountyUntil: new anchor_1.BN(
|
|
530
|
-
maxBountyAfter: new anchor_1.BN(
|
|
527
|
+
minBounty: new anchor_1.BN(20 * 5000),
|
|
528
|
+
maxBounty: new anchor_1.BN(50 * 5000),
|
|
529
|
+
minBountyUntil: new anchor_1.BN(10),
|
|
530
|
+
maxBountyAfter: new anchor_1.BN(40),
|
|
531
531
|
},
|
|
532
532
|
bountyPerPriceUpdateTaskDivisor: new anchor_1.BN(3),
|
|
533
533
|
minRemainingValue: { high: new anchor_1.BN(0), low: new anchor_1.BN("1844674407370955161") },
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import { AccountInfo, AddressLookupTableAccount, PublicKey } from '@solana/web3.
|
|
|
6
6
|
import { HUNDRED_PERCENT_BPS } from '../../constants';
|
|
7
7
|
import { Fraction, fractionToDecimal } from '../../layouts/fraction';
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
OracleAggregator, OracleData, OracleType,
|
|
10
10
|
} from '../../layouts/oracle';
|
|
11
11
|
import { U32_MAX } from './constants';
|
|
12
12
|
import { PythOracle } from './pythOracle';
|
|
@@ -79,8 +79,8 @@ export class PriceAggregator{
|
|
|
79
79
|
oracleAggregator: OracleAggregator,
|
|
80
80
|
lutAccounts: AddressLookupTableAccount[],
|
|
81
81
|
accountInfoMap: Map<string, AccountInfo<Buffer> | null>,
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
wsolPrice: OraclePrice,
|
|
83
|
+
usdcPrice: OraclePrice,
|
|
84
84
|
pythPriceOverrides?: Map<string, OraclePrice>,
|
|
85
85
|
): OraclePrice {
|
|
86
86
|
let validated: boolean = true;
|
|
@@ -93,15 +93,11 @@ export class PriceAggregator{
|
|
|
93
93
|
const settings = oracleData.oracleSettings;
|
|
94
94
|
|
|
95
95
|
let loadedAccounts: AccountInfo<Buffer>[] = [];
|
|
96
|
-
let firstLoadedPubkey: PublicKey | undefined;
|
|
97
96
|
for (let j = 0; j < settings.numRequiredAccounts; j++) {
|
|
98
97
|
const lutId = oracleData.accountsToLoadLutIds[j];
|
|
99
98
|
const lutIdx = oracleData.accountsToLoadLutIndices[j];
|
|
100
99
|
const pubkey = lutAccounts[lutId].state.addresses[lutIdx];
|
|
101
100
|
const account = accountInfoMap.get(pubkey.toBase58());
|
|
102
|
-
if (!firstLoadedPubkey) {
|
|
103
|
-
firstLoadedPubkey = pubkey;
|
|
104
|
-
}
|
|
105
101
|
// @ts-ignore
|
|
106
102
|
loadedAccounts.push(account);
|
|
107
103
|
}
|
|
@@ -127,17 +123,16 @@ export class PriceAggregator{
|
|
|
127
123
|
let result = (() => {
|
|
128
124
|
switch (settings.oracleType) {
|
|
129
125
|
case OracleType.Pyth:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return PythOracle.fetch(settings, loadedAccounts, solPrice, usdPrice);
|
|
126
|
+
const lutId = oracleData.accountsToLoadLutIds[0];
|
|
127
|
+
const lutIdx = oracleData.accountsToLoadLutIndices[0];
|
|
128
|
+
const pubkey = lutAccounts[lutId].state.addresses[lutIdx];
|
|
129
|
+
const override = pythPriceOverrides?.get(pubkey.toBase58());
|
|
130
|
+
const price = PythOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
131
|
+
return (override ? override : price);
|
|
137
132
|
case OracleType.RaydiumClmm:
|
|
138
|
-
return RaydiumCLMMOracle.fetch(settings, loadedAccounts,
|
|
133
|
+
return RaydiumCLMMOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
139
134
|
case OracleType.RaydiumCpmm:
|
|
140
|
-
return RaydiumCPMMOracle.fetch(settings, loadedAccounts,
|
|
135
|
+
return RaydiumCPMMOracle.fetch(settings, loadedAccounts, wsolPrice, usdcPrice);
|
|
141
136
|
default:
|
|
142
137
|
throw new Error(`Invalid oracle type: ${settings.oracleType}`);
|
|
143
138
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
SystemProgram, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction
|
|
8
8
|
} from '@solana/web3.js';
|
|
9
9
|
|
|
10
|
-
import { HUNDRED_PERCENT_BPS, PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT } from '../../constants';
|
|
10
|
+
import { HUNDRED_PERCENT_BPS, PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT, USDC_DECIMALS, WSOL_DECIMALS } from '../../constants';
|
|
11
11
|
import { OracleSettings, OracleType, PYTH_USDC_ORACLE_SETTINGS, PYTH_WSOL_ORACLE_SETTINGS, Quote } from '../../layouts/oracle';
|
|
12
12
|
import { TxBatchData, TxData } from '../../txUtils';
|
|
13
13
|
import { HERMES_PUBLIC_ENDPOINT, SOLANA_DEVNET_ENDPOINT } from './constants';
|
|
@@ -87,20 +87,25 @@ export async function fetchHermesPythPrices(priceFeedIds: string[]): Promise<Map
|
|
|
87
87
|
export function buildPythOraclePriceFromHermesPriceData(
|
|
88
88
|
oracleParams: OracleSettings,
|
|
89
89
|
priceData: HermesPythPriceData,
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
wsolPrice: OraclePrice,
|
|
91
|
+
usdcPrice: OraclePrice,
|
|
92
92
|
): OraclePrice {
|
|
93
|
+
let quoteDecimals =
|
|
94
|
+
(oracleParams.quote == Quote.Usdc) ? USDC_DECIMALS : (
|
|
95
|
+
(oracleParams.quote == Quote.Wsol) ? WSOL_DECIMALS : 0);
|
|
96
|
+
|
|
93
97
|
let pr = new Decimal(priceData.price.toString())
|
|
94
|
-
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
98
|
+
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
95
99
|
let ema = new Decimal((priceData.emaPrice ?? priceData.price).toString())
|
|
96
|
-
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
100
|
+
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
97
101
|
let cf = new Decimal(priceData.conf.toString())
|
|
98
|
-
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals));
|
|
102
|
+
.mul(Decimal.pow(10, priceData.expo - oracleParams.tokenDecimals + quoteDecimals));
|
|
99
103
|
const lastUpdateTimestamp = priceData.publishTime;
|
|
100
|
-
|
|
104
|
+
|
|
101
105
|
let quotePrice =
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
(oracleParams.quote === Quote.Usdc) ? usdcPrice :
|
|
107
|
+
((oracleParams.quote === Quote.Wsol) ? wsolPrice :
|
|
108
|
+
new OraclePrice(new Decimal(1), new Decimal(0), 0));
|
|
104
109
|
|
|
105
110
|
pr = pr.mul(quotePrice.price);
|
|
106
111
|
ema = ema.mul(quotePrice.price);
|
|
@@ -490,7 +495,7 @@ function buildVerifyEncodedVaaV1Instruction(
|
|
|
490
495
|
/**
|
|
491
496
|
* Build closeEncodedVaa instruction
|
|
492
497
|
*/
|
|
493
|
-
function buildCloseEncodedVaaInstruction(
|
|
498
|
+
export function buildCloseEncodedVaaInstruction(
|
|
494
499
|
writeAuthority: PublicKey,
|
|
495
500
|
encodedVaa: PublicKey,
|
|
496
501
|
wormholeProgramId: PublicKey = DEFAULT_WORMHOLE_PROGRAM_ID
|
|
@@ -976,8 +981,8 @@ export class PythOracle {
|
|
|
976
981
|
static fetch(
|
|
977
982
|
oracleParams: OracleSettings,
|
|
978
983
|
accountInfos: AccountInfo<Buffer>[],
|
|
979
|
-
|
|
980
|
-
|
|
984
|
+
wsolPrice?: OraclePrice,
|
|
985
|
+
usdcPrice?: OraclePrice,
|
|
981
986
|
): OraclePrice {
|
|
982
987
|
//@ts-ignore
|
|
983
988
|
let state: PythState = null;
|
|
@@ -999,8 +1004,8 @@ export class PythOracle {
|
|
|
999
1004
|
emaPrice: state.priceMessage.emaPrice.toString(),
|
|
1000
1005
|
emaConf: state.priceMessage.emaConf.toString(),
|
|
1001
1006
|
},
|
|
1002
|
-
|
|
1003
|
-
|
|
1007
|
+
wsolPrice ?? new OraclePrice(new Decimal(1), new Decimal(0), 0),
|
|
1008
|
+
usdcPrice ?? new OraclePrice(new Decimal(1), new Decimal(0), 0),
|
|
1004
1009
|
);
|
|
1005
1010
|
}
|
|
1006
1011
|
|
|
@@ -667,8 +667,8 @@ export class RaydiumCPMMOracle {
|
|
|
667
667
|
static fetch(
|
|
668
668
|
oracleParams: OracleSettings,
|
|
669
669
|
accountInfos: AccountInfo<Buffer>[],
|
|
670
|
-
|
|
671
|
-
|
|
670
|
+
wsolPrice: OraclePrice,
|
|
671
|
+
usdcPrice: OraclePrice,
|
|
672
672
|
): OraclePrice {
|
|
673
673
|
const poolStateInfo = accountInfos[0];
|
|
674
674
|
const vault0Info = accountInfos[1];
|
|
@@ -684,8 +684,9 @@ export class RaydiumCPMMOracle {
|
|
|
684
684
|
|
|
685
685
|
// Determine quote oracle
|
|
686
686
|
let quotePrice =
|
|
687
|
-
|
|
688
|
-
|
|
687
|
+
(oracleParams.quote === Quote.Usdc) ? usdcPrice :
|
|
688
|
+
((oracleParams.quote === Quote.Wsol) ? wsolPrice :
|
|
689
|
+
new OraclePrice(new Decimal(1), new Decimal(0), 0));
|
|
689
690
|
|
|
690
691
|
// Get spot price with reserves
|
|
691
692
|
const { netBase, netQuote, spotPrice } = this.getSpotPriceWithReserves(
|
package/test.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
1
|
+
import { ComputeBudgetProgram, Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { BN, Wallet } from "@coral-xyz/anchor";
|
|
3
3
|
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
|
|
4
|
-
import { Vault, Intent, RebalanceIntent, SymmetryCore, TaskContext, KeeperMonitor } from "./src";
|
|
4
|
+
import { Vault, Intent, RebalanceIntent, SymmetryCore, TaskContext, KeeperMonitor, isRebalanceRequired } from "./src";
|
|
5
5
|
import { AddOrEditTokenInput, UpdateWeightsInput, MakeDirectSwapInput } from "./src";
|
|
6
6
|
import { EditCreatorSettings, EditManagerSettings, EditFeeSettings, EditScheduleSettings, EditAutomationSettings, EditLpSettings, EditMetadataSettings, EditDepositsSettings, EditForceRebalanceSettings, EditCustomRebalanceSettings, EditAddTokenSettings, EditUpdateWeightsSettings, EditMakeDirectSwapSettings } from "./src";
|
|
7
7
|
import { getRebalanceIntentPda } from "./src/instructions/pda";
|
|
8
|
-
import { PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT } from "./src/constants";
|
|
8
|
+
import { COMPUTE_UNITS, PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT } from "./src/constants";
|
|
9
9
|
import { getJupTokenLedgerAndSwapInstructions } from "./src/jup";
|
|
10
10
|
import { getSwapPairs } from "./src/states/intents/rebalanceIntent";
|
|
11
|
+
import { buildCloseEncodedVaaInstruction } from "./src/states/oracles/pythOracle";
|
|
12
|
+
import { prepareTxPayloadBatchSequence, prepareVersionedTxs, TxBatchData } from "./src/txUtils";
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
let kp = Array.from(Keypair.generate().secretKey);
|
|
@@ -565,13 +567,13 @@ async function testStates() {
|
|
|
565
567
|
symmetryFeesExtraData: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
|
|
566
568
|
|
|
567
569
|
bountyMint: new PublicKey("So11111111111111111111111111111111111111112"),
|
|
568
|
-
minBountyForVaultAutomation: new BN(
|
|
569
|
-
bountyBondAmount: new BN(
|
|
570
|
+
minBountyForVaultAutomation: new BN(2000 * 5000),
|
|
571
|
+
bountyBondAmount: new BN(20 * 5000),
|
|
570
572
|
bountyPerTask: {
|
|
571
|
-
minBounty: new BN(
|
|
572
|
-
maxBounty: new BN(
|
|
573
|
-
minBountyUntil: new BN(
|
|
574
|
-
maxBountyAfter: new BN(
|
|
573
|
+
minBounty: new BN(20 * 5000),
|
|
574
|
+
maxBounty: new BN(50 * 5000),
|
|
575
|
+
minBountyUntil: new BN(10),
|
|
576
|
+
maxBountyAfter: new BN(40),
|
|
575
577
|
},
|
|
576
578
|
bountyPerPriceUpdateTaskDivisor: new BN(3),
|
|
577
579
|
minRemainingValue: {high: new BN(0), low: new BN("1844674407370955161")},
|