@symmetry-hq/sdk 1.0.1
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/constants.d.ts +23 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/index.d.ts +804 -0
- package/dist/src/index.js +2097 -0
- package/dist/src/instructions/automation/auction.d.ts +6 -0
- package/dist/src/instructions/automation/auction.js +40 -0
- package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
- package/dist/src/instructions/automation/claimBounty.js +44 -0
- package/dist/src/instructions/automation/flashSwap.d.ts +21 -0
- package/dist/src/instructions/automation/flashSwap.js +74 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +19 -0
- package/dist/src/instructions/automation/priceUpdate.js +89 -0
- package/dist/src/instructions/automation/rebalanceIntent.d.ts +32 -0
- package/dist/src/instructions/automation/rebalanceIntent.js +117 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +11 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +41 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +53 -0
- package/dist/src/instructions/management/claimFees.d.ts +15 -0
- package/dist/src/instructions/management/claimFees.js +95 -0
- package/dist/src/instructions/management/createBasket.d.ts +21 -0
- package/dist/src/instructions/management/createBasket.js +98 -0
- package/dist/src/instructions/management/edit.d.ts +51 -0
- package/dist/src/instructions/management/edit.js +477 -0
- package/dist/src/instructions/management/luts.d.ts +30 -0
- package/dist/src/instructions/management/luts.js +99 -0
- package/dist/src/instructions/pda.d.ts +25 -0
- package/dist/src/instructions/pda.js +128 -0
- package/dist/src/instructions/user/deposit.d.ts +20 -0
- package/dist/src/instructions/user/deposit.js +100 -0
- package/dist/src/instructions/user/withdraw.d.ts +8 -0
- package/dist/src/instructions/user/withdraw.js +36 -0
- package/dist/src/jup.d.ts +49 -0
- package/dist/src/jup.js +80 -0
- package/dist/src/keeperMonitor.d.ts +52 -0
- package/dist/src/keeperMonitor.js +624 -0
- package/dist/src/layouts/basket.d.ts +191 -0
- package/dist/src/layouts/basket.js +51 -0
- package/dist/src/layouts/config.d.ts +281 -0
- package/dist/src/layouts/config.js +237 -0
- package/dist/src/layouts/fraction.d.ts +20 -0
- package/dist/src/layouts/fraction.js +164 -0
- package/dist/src/layouts/intents/bounty.d.ts +18 -0
- package/dist/src/layouts/intents/bounty.js +19 -0
- package/dist/src/layouts/intents/intent.d.ts +209 -0
- package/dist/src/layouts/intents/intent.js +97 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +212 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +94 -0
- package/dist/src/layouts/lookupTable.d.ts +7 -0
- package/dist/src/layouts/lookupTable.js +10 -0
- package/dist/src/layouts/oracle.d.ts +63 -0
- package/dist/src/layouts/oracle.js +96 -0
- package/dist/src/states/basket.d.ts +14 -0
- package/dist/src/states/basket.js +479 -0
- package/dist/src/states/config.d.ts +3 -0
- package/dist/src/states/config.js +71 -0
- package/dist/src/states/intents/intent.d.ts +10 -0
- package/dist/src/states/intents/intent.js +316 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +42 -0
- package/dist/src/states/intents/rebalanceIntent.js +680 -0
- package/dist/src/states/oracles/constants.d.ts +9 -0
- package/dist/src/states/oracles/constants.js +15 -0
- package/dist/src/states/oracles/oracle.d.ts +24 -0
- package/dist/src/states/oracles/oracle.js +168 -0
- package/dist/src/states/oracles/pythOracle.d.ts +132 -0
- package/dist/src/states/oracles/pythOracle.js +609 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +184 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +843 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +120 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +540 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/withdrawBasketFees.d.ts +10 -0
- package/dist/src/states/withdrawBasketFees.js +154 -0
- package/dist/src/txUtils.d.ts +65 -0
- package/dist/src/txUtils.js +306 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +561 -0
- package/package.json +31 -0
- package/src/constants.ts +40 -0
- package/src/index.ts +2431 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/flashSwap.ts +104 -0
- package/src/instructions/automation/priceUpdate.ts +117 -0
- package/src/instructions/automation/rebalanceIntent.ts +181 -0
- package/src/instructions/management/addBounty.ts +55 -0
- package/src/instructions/management/admin.ts +72 -0
- package/src/instructions/management/claimFees.ts +129 -0
- package/src/instructions/management/createBasket.ts +138 -0
- package/src/instructions/management/edit.ts +602 -0
- package/src/instructions/management/luts.ts +157 -0
- package/src/instructions/pda.ts +151 -0
- package/src/instructions/user/deposit.ts +143 -0
- package/src/instructions/user/withdraw.ts +53 -0
- package/src/jup.ts +113 -0
- package/src/keeperMonitor.ts +585 -0
- package/src/layouts/basket.ts +233 -0
- package/src/layouts/config.ts +576 -0
- package/src/layouts/fraction.ts +164 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +324 -0
- package/src/layouts/intents/rebalanceIntent.ts +306 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +157 -0
- package/src/states/basket.ts +527 -0
- package/src/states/config.ts +62 -0
- package/src/states/intents/intent.ts +311 -0
- package/src/states/intents/rebalanceIntent.ts +751 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +212 -0
- package/src/states/oracles/pythOracle.ts +874 -0
- package/src/states/oracles/raydiumClmmOracle.ts +1193 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +784 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/states/withdrawBasketFees.ts +160 -0
- package/src/txUtils.ts +424 -0
- package/test.ts +609 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
export declare const U8_MAX: BN;
|
|
3
|
+
export declare const U16_MAX: BN;
|
|
4
|
+
export declare const U32_MAX: BN;
|
|
5
|
+
export declare const U64_MAX: BN;
|
|
6
|
+
export declare const U128_MAX: BN;
|
|
7
|
+
export declare const HERMES_PUBLIC_ENDPOINT = "https://hermes.pyth.network";
|
|
8
|
+
export declare const SOLANA_DEVNET_ENDPOINT = "https://api.devnet.solana.com";
|
|
9
|
+
export declare const SOLANA_MAINNET_ENDPOINT = "https://api.mainnet-beta.solana.com";
|
|
@@ -0,0 +1,15 @@
|
|
|
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.SOLANA_MAINNET_ENDPOINT = exports.SOLANA_DEVNET_ENDPOINT = exports.HERMES_PUBLIC_ENDPOINT = exports.U128_MAX = exports.U64_MAX = exports.U32_MAX = exports.U16_MAX = exports.U8_MAX = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
exports.U8_MAX = new bn_js_1.default(0xff);
|
|
9
|
+
exports.U16_MAX = new bn_js_1.default(0xffff);
|
|
10
|
+
exports.U32_MAX = new bn_js_1.default(0xffffffff);
|
|
11
|
+
exports.U64_MAX = new bn_js_1.default(1).shln(64).sub(new bn_js_1.default(1));
|
|
12
|
+
exports.U128_MAX = new bn_js_1.default(1).shln(128).sub(new bn_js_1.default(1));
|
|
13
|
+
exports.HERMES_PUBLIC_ENDPOINT = "https://hermes.pyth.network";
|
|
14
|
+
exports.SOLANA_DEVNET_ENDPOINT = "https://api.devnet.solana.com";
|
|
15
|
+
exports.SOLANA_MAINNET_ENDPOINT = "https://api.mainnet-beta.solana.com";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import { AccountInfo, AddressLookupTableAccount } from '@solana/web3.js';
|
|
3
|
+
import { Fraction } from '../../layouts/fraction';
|
|
4
|
+
import { OracleAggregator, OracleData } from '../../layouts/oracle';
|
|
5
|
+
export declare class OraclePrice {
|
|
6
|
+
price: Decimal;
|
|
7
|
+
conf: Decimal;
|
|
8
|
+
updateTime: number;
|
|
9
|
+
validated?: boolean;
|
|
10
|
+
constructor(price: Decimal, conf: Decimal, updateTime: number, validated?: boolean);
|
|
11
|
+
getMid(): Decimal;
|
|
12
|
+
getLow(): Decimal;
|
|
13
|
+
getHigh(): Decimal;
|
|
14
|
+
}
|
|
15
|
+
export declare class PriceAggregator {
|
|
16
|
+
numOracles: number;
|
|
17
|
+
oracles: OracleData[];
|
|
18
|
+
minConfBps: number;
|
|
19
|
+
confThreshBps: number;
|
|
20
|
+
minOraclesThresh: number;
|
|
21
|
+
confMultiplier: Fraction;
|
|
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>, solPrice: OraclePrice, usdPrice: OraclePrice): OraclePrice;
|
|
24
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
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.PriceAggregator = exports.OraclePrice = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const fraction_1 = require("../../layouts/fraction");
|
|
10
|
+
const oracle_1 = require("../../layouts/oracle");
|
|
11
|
+
const constants_2 = require("./constants");
|
|
12
|
+
const pythOracle_1 = require("./pythOracle");
|
|
13
|
+
const raydiumClmmOracle_1 = require("./raydiumClmmOracle");
|
|
14
|
+
const raydiumCpmmOracle_1 = require("./raydiumCpmmOracle");
|
|
15
|
+
class OraclePrice {
|
|
16
|
+
constructor(price, conf, updateTime, validated) {
|
|
17
|
+
this.price = price;
|
|
18
|
+
this.conf = conf;
|
|
19
|
+
this.updateTime = updateTime;
|
|
20
|
+
let zero_Decimal = new decimal_js_1.default(0);
|
|
21
|
+
if (this.price.lt(zero_Decimal))
|
|
22
|
+
throw new Error("price should be more than 0");
|
|
23
|
+
if (this.conf.lt(zero_Decimal))
|
|
24
|
+
throw new Error("confidence can't be negative");
|
|
25
|
+
if (this.updateTime < 0)
|
|
26
|
+
throw new Error("update time should be more than 0");
|
|
27
|
+
this.validated = validated;
|
|
28
|
+
}
|
|
29
|
+
getMid() {
|
|
30
|
+
return this.price;
|
|
31
|
+
}
|
|
32
|
+
getLow() {
|
|
33
|
+
return this.price.sub(this.conf);
|
|
34
|
+
}
|
|
35
|
+
getHigh() {
|
|
36
|
+
return this.price.add(this.conf);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.OraclePrice = OraclePrice;
|
|
40
|
+
class PriceAggregator {
|
|
41
|
+
constructor(numOracles, oracles, minConfBps, confThreshBps, minOraclesThresh, confMultiplier) {
|
|
42
|
+
this.numOracles = numOracles;
|
|
43
|
+
this.oracles = oracles;
|
|
44
|
+
this.minConfBps = minConfBps;
|
|
45
|
+
this.confThreshBps = confThreshBps;
|
|
46
|
+
this.minOraclesThresh = minOraclesThresh;
|
|
47
|
+
this.confMultiplier = confMultiplier;
|
|
48
|
+
if (!(this.oracles.length > 0))
|
|
49
|
+
throw new Error(`At least one oracle is required`);
|
|
50
|
+
if (!(0 <= this.minConfBps && this.minConfBps < 10000))
|
|
51
|
+
throw new Error(`Minimum confidence must be between 0 and 10000`);
|
|
52
|
+
if (!(0 <= this.confThreshBps && this.confThreshBps < 10000))
|
|
53
|
+
throw new Error(`Confidence threshold must be between 0 and 10000`);
|
|
54
|
+
if (!(0 <= this.minOraclesThresh && this.minOraclesThresh <= constants_2.U32_MAX.toNumber()))
|
|
55
|
+
throw new Error(`Minimum number of oracles must be between 0 and ${constants_2.U32_MAX}`);
|
|
56
|
+
}
|
|
57
|
+
static fetch(oracleAggregator, lutAccounts, accountInfoMap, solPrice, usdPrice) {
|
|
58
|
+
let validated = true;
|
|
59
|
+
const agg = oracleAggregator;
|
|
60
|
+
const oracleResults = [];
|
|
61
|
+
for (let i = 0; i < agg.numOracles; i++) {
|
|
62
|
+
const oracleData = agg.oracles[i];
|
|
63
|
+
const settings = oracleData.oracleSettings;
|
|
64
|
+
let loadedAccounts = [];
|
|
65
|
+
for (let j = 0; j < settings.numRequiredAccounts; j++) {
|
|
66
|
+
const lutId = oracleData.accountsToLoadLutIds[j];
|
|
67
|
+
const lutIdx = oracleData.accountsToLoadLutIndices[j];
|
|
68
|
+
const pubkey = lutAccounts[lutId].state.addresses[lutIdx];
|
|
69
|
+
const account = accountInfoMap.get(pubkey.toBase58());
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
loadedAccounts.push(account);
|
|
72
|
+
}
|
|
73
|
+
if (settings.oracleType === oracle_1.OracleType.RaydiumClmm) {
|
|
74
|
+
// ensure tick arrays are appended in order: prev, current, next
|
|
75
|
+
const poolPubkey = lutAccounts[oracleData.accountsToLoadLutIds[0]].state.addresses[oracleData.accountsToLoadLutIndices[0]];
|
|
76
|
+
const poolAi = accountInfoMap.get(poolPubkey.toBase58());
|
|
77
|
+
if (poolAi) {
|
|
78
|
+
const [poolState] = raydiumClmmOracle_1.PoolState.decode(poolAi.data, 8);
|
|
79
|
+
const currStart = (0, raydiumClmmOracle_1.getTickArrayStartIndexByTick)(poolState.tickCurrent, poolState.tickSpacing);
|
|
80
|
+
const prevStart = (0, raydiumClmmOracle_1.getNextTickArrayStartIndex)(currStart, poolState.tickSpacing, true);
|
|
81
|
+
const nextStart = (0, raydiumClmmOracle_1.getNextTickArrayStartIndex)(currStart, poolState.tickSpacing, false);
|
|
82
|
+
const poolId = poolPubkey;
|
|
83
|
+
[prevStart, currStart, nextStart].forEach(start => {
|
|
84
|
+
const pk = (0, raydiumClmmOracle_1.getPdaTickArrayAddress)(poolId, start);
|
|
85
|
+
const ai = accountInfoMap.get(pk.toBase58());
|
|
86
|
+
if (ai)
|
|
87
|
+
loadedAccounts.push(ai);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let result = (() => {
|
|
92
|
+
switch (settings.oracleType) {
|
|
93
|
+
case oracle_1.OracleType.Pyth:
|
|
94
|
+
return pythOracle_1.PythOracle.fetch(settings, loadedAccounts, solPrice, usdPrice);
|
|
95
|
+
case oracle_1.OracleType.RaydiumClmm:
|
|
96
|
+
return raydiumClmmOracle_1.RaydiumCLMMOracle.fetch(settings, loadedAccounts, solPrice, usdPrice);
|
|
97
|
+
case oracle_1.OracleType.RaydiumCpmm:
|
|
98
|
+
return raydiumCpmmOracle_1.RaydiumCPMMOracle.fetch(settings, loadedAccounts, solPrice, usdPrice);
|
|
99
|
+
default:
|
|
100
|
+
return new OraclePrice(new decimal_js_1.default(0), new decimal_js_1.default(0), 0);
|
|
101
|
+
}
|
|
102
|
+
})();
|
|
103
|
+
// if oracle is required and price is 0, return 0 price, else skip oraclce
|
|
104
|
+
if (result.getMid().eq(new decimal_js_1.default(0))) {
|
|
105
|
+
if (settings.isRequired)
|
|
106
|
+
validated = false;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!result.validated) {
|
|
110
|
+
if (settings.isRequired)
|
|
111
|
+
validated = false;
|
|
112
|
+
}
|
|
113
|
+
oracleResults.push(result);
|
|
114
|
+
}
|
|
115
|
+
// check this
|
|
116
|
+
if (oracleResults.length < agg.minOraclesThresh)
|
|
117
|
+
validated = false;
|
|
118
|
+
let prices = [];
|
|
119
|
+
for (let i = 0; i < oracleResults.length; i++) {
|
|
120
|
+
const pr = oracleResults[i];
|
|
121
|
+
const weight = new decimal_js_1.default(agg.oracles[i].oracleSettings.weight);
|
|
122
|
+
prices.push({ price: pr.getMid(), weight: weight });
|
|
123
|
+
prices.push({ price: pr.getLow(), weight: weight });
|
|
124
|
+
prices.push({ price: pr.getHigh(), weight: weight });
|
|
125
|
+
}
|
|
126
|
+
const medianPrice = weightedPercentile(prices, 50);
|
|
127
|
+
const p25Price = weightedPercentile(prices, 25);
|
|
128
|
+
const p75Price = weightedPercentile(prices, 75);
|
|
129
|
+
let first = medianPrice.sub(p25Price);
|
|
130
|
+
let second = p75Price.sub(medianPrice);
|
|
131
|
+
let conf = first.gte(second) ? first : second;
|
|
132
|
+
// confidence should be strictly less than median price
|
|
133
|
+
conf = conf.lt(medianPrice) ? conf : medianPrice;
|
|
134
|
+
conf = conf.mul((0, fraction_1.fractionToDecimal)(agg.confMultiplier));
|
|
135
|
+
if (conf.div(medianPrice).mul(new decimal_js_1.default(constants_1.HUNDRED_PERCENT_BPS)).lt(new decimal_js_1.default(agg.minConfBps)))
|
|
136
|
+
conf = medianPrice.mul(new decimal_js_1.default(agg.minConfBps)).div(new decimal_js_1.default(constants_1.HUNDRED_PERCENT_BPS));
|
|
137
|
+
if (conf.div(medianPrice).mul(new decimal_js_1.default(constants_1.HUNDRED_PERCENT_BPS)).gt(new decimal_js_1.default(agg.confThreshBps)))
|
|
138
|
+
return new OraclePrice(new decimal_js_1.default(0), new decimal_js_1.default(0), 0);
|
|
139
|
+
const oldest = Math.min(...oracleResults.map(p => p.updateTime));
|
|
140
|
+
return new OraclePrice(medianPrice, conf, oldest, validated);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.PriceAggregator = PriceAggregator;
|
|
144
|
+
function weightedPercentile(prices, percentile) {
|
|
145
|
+
if (percentile < 0 || percentile > 100) {
|
|
146
|
+
throw new Error("Percentile must be between 0 and 100");
|
|
147
|
+
}
|
|
148
|
+
// Sort by price ascending
|
|
149
|
+
prices.sort((a, b) => a.price.sub(b.price).toNumber());
|
|
150
|
+
// Edge cases
|
|
151
|
+
if (percentile === 0)
|
|
152
|
+
return prices[0].price;
|
|
153
|
+
if (percentile === 100)
|
|
154
|
+
return prices[prices.length - 1].price;
|
|
155
|
+
// Compute total weight
|
|
156
|
+
const totalWeight = prices.reduce((sum, x) => sum.add(x.weight), new decimal_js_1.default(0));
|
|
157
|
+
// Threshold = percentile% of total weight
|
|
158
|
+
const thresh = totalWeight.mul(new decimal_js_1.default(percentile)).div(new decimal_js_1.default(100));
|
|
159
|
+
// Cumulative sum
|
|
160
|
+
let cum = new decimal_js_1.default(0);
|
|
161
|
+
for (const { price, weight } of prices) {
|
|
162
|
+
cum = cum.add(weight);
|
|
163
|
+
if (cum.gte(thresh))
|
|
164
|
+
return price; // nearest-rank percentile
|
|
165
|
+
}
|
|
166
|
+
// fallback (should not happen, but safe)
|
|
167
|
+
return prices[prices.length - 1].price;
|
|
168
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
import { HermesClient } from '@pythnetwork/hermes-client';
|
|
3
|
+
import { AccountInfo, Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
|
+
import { OracleSettings } from '../../layouts/oracle';
|
|
5
|
+
import { TxBatchData } from '../../txUtils';
|
|
6
|
+
import { OraclePrice } from './oracle';
|
|
7
|
+
export type VerificationLevel = {
|
|
8
|
+
kind: 'Partial';
|
|
9
|
+
numSignatures: number;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'Full';
|
|
12
|
+
};
|
|
13
|
+
export declare function parseVerificationLevel(buf: Buffer, offset: number): {
|
|
14
|
+
level: VerificationLevel;
|
|
15
|
+
size: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const TIP_ACCOUNTS: string[];
|
|
18
|
+
export declare function getRandomTipAccount(): PublicKey;
|
|
19
|
+
export declare function buildJitoTipInstruction(payer: PublicKey, lamports: number): TransactionInstruction;
|
|
20
|
+
/**
|
|
21
|
+
* Derives the Pyth price feed account address
|
|
22
|
+
*/
|
|
23
|
+
export declare function getPythPriceFeedAccountAddress(shardId: number, priceFeedId: string | Buffer, pushOracleProgramId?: PublicKey): PublicKey;
|
|
24
|
+
export interface InstructionWithSigners {
|
|
25
|
+
instruction: TransactionInstruction;
|
|
26
|
+
signers: Keypair[];
|
|
27
|
+
computeUnits?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PythUpdateResult {
|
|
30
|
+
postInstructions: InstructionWithSigners[];
|
|
31
|
+
closeInstructions: InstructionWithSigners[];
|
|
32
|
+
signers: Keypair[];
|
|
33
|
+
priceFeedAccounts: Map<string, PublicKey>;
|
|
34
|
+
}
|
|
35
|
+
export declare function parsePriceFeedMessage(message: Buffer): {
|
|
36
|
+
feedId: Buffer;
|
|
37
|
+
price: Buffer;
|
|
38
|
+
confidence: Buffer;
|
|
39
|
+
exponent: number;
|
|
40
|
+
publishTime: Buffer;
|
|
41
|
+
prevPublishTime: Buffer;
|
|
42
|
+
emaPrice: Buffer;
|
|
43
|
+
emaConf: Buffer;
|
|
44
|
+
};
|
|
45
|
+
/** parsing of accumulator update data (VAA + updates) */
|
|
46
|
+
export declare function parseAccumulatorUpdateData(data: Buffer): {
|
|
47
|
+
vaa: Buffer;
|
|
48
|
+
updates: {
|
|
49
|
+
message: Buffer;
|
|
50
|
+
proof: number[][];
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Get the size of a transaction that would contain the provided array of instructions
|
|
55
|
+
*/
|
|
56
|
+
export declare function getSizeOfTransaction(instructions: TransactionInstruction[], versionedTransaction?: boolean, addressLookupTable?: {
|
|
57
|
+
state: {
|
|
58
|
+
addresses: PublicKey[];
|
|
59
|
+
};
|
|
60
|
+
}): number;
|
|
61
|
+
/** Get the size of n in bytes when serialized as a CompressedU16 */
|
|
62
|
+
export declare function getSizeOfCompressedU16(n: number): number;
|
|
63
|
+
export interface InstructionBatch {
|
|
64
|
+
instructions: TransactionInstruction[];
|
|
65
|
+
signers: Keypair[];
|
|
66
|
+
computeUnits: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Fetch Pyth price accounts from RPC and extract feed IDs
|
|
70
|
+
*/
|
|
71
|
+
export declare function fetchFeedIdsFromAccounts(connection: Connection, priceAccounts: PublicKey[]): Promise<{
|
|
72
|
+
feedIds: string[];
|
|
73
|
+
feedIdToAccount: Map<string, PublicKey>;
|
|
74
|
+
}>;
|
|
75
|
+
export interface PythUpdateTxResult {
|
|
76
|
+
txBatchData: TxBatchData;
|
|
77
|
+
/** Keypairs that must sign their respective transactions before sending */
|
|
78
|
+
extraSigners: Map<number, Keypair[]>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build Pyth price feed update as TxBatchData compatible with SDK txUtils.
|
|
82
|
+
*
|
|
83
|
+
* TxBatchData.batches layout:
|
|
84
|
+
* batch 0 (sequential): [createAccount + initEncodedVaa + writeVaa_part1]
|
|
85
|
+
* batch 1 (sequential): [writeVaa_part2 + verifyEncodedVaa]
|
|
86
|
+
* batch 2 (parallel): [updateFeed_0], [updateFeed_1], ... [updateFeed_N-2]
|
|
87
|
+
* batch 3 (sequential): [updateFeed_last + closeEncodedVaa]
|
|
88
|
+
*
|
|
89
|
+
* Transactions within each batch are sent in parallel by sendVersionedTxs.
|
|
90
|
+
* Batches are sent sequentially.
|
|
91
|
+
*/
|
|
92
|
+
export declare function buildPythPriceFeedUpdateIxs(payer: PublicKey, priceFeedIds: string[], defaultShardId?: number, hermesClient?: HermesClient): Promise<{
|
|
93
|
+
vaaCreateInitEncodeIxs: {
|
|
94
|
+
ixs: TransactionInstruction[];
|
|
95
|
+
signer: Keypair;
|
|
96
|
+
}[];
|
|
97
|
+
vaaWriteVerifyIxs: TransactionInstruction[][];
|
|
98
|
+
updateFeedIxs: TransactionInstruction[];
|
|
99
|
+
closeVaaIxs: TransactionInstruction[];
|
|
100
|
+
}>;
|
|
101
|
+
export declare class PriceFeedMessage {
|
|
102
|
+
feedId: Buffer;
|
|
103
|
+
price: BN;
|
|
104
|
+
conf: BN;
|
|
105
|
+
exponent: number;
|
|
106
|
+
publishTime: BN;
|
|
107
|
+
prevPublishTime: BN;
|
|
108
|
+
emaPrice: BN;
|
|
109
|
+
emaConf: BN;
|
|
110
|
+
constructor(params: {
|
|
111
|
+
feedId: Buffer;
|
|
112
|
+
price: BN;
|
|
113
|
+
conf: BN;
|
|
114
|
+
exponent: number;
|
|
115
|
+
publishTime: BN;
|
|
116
|
+
prevPublishTime: BN;
|
|
117
|
+
emaPrice: BN;
|
|
118
|
+
emaConf: BN;
|
|
119
|
+
});
|
|
120
|
+
static decode(buf: Buffer, offset?: number): [PriceFeedMessage, number];
|
|
121
|
+
}
|
|
122
|
+
export declare class PythState {
|
|
123
|
+
writeAuthority: PublicKey;
|
|
124
|
+
verificationLevel: VerificationLevel;
|
|
125
|
+
priceMessage: PriceFeedMessage;
|
|
126
|
+
postedSlot: BN;
|
|
127
|
+
constructor(writeAuthority: PublicKey, verificationLevel: VerificationLevel, priceMessage: PriceFeedMessage, postedSlot: BN);
|
|
128
|
+
static decode(buf: Buffer, offset?: number): [PythState, number];
|
|
129
|
+
}
|
|
130
|
+
export declare class PythOracle {
|
|
131
|
+
static fetch(oracleParams: OracleSettings, accountInfos: AccountInfo<Buffer>[], solPrice?: OraclePrice, usdPrice?: OraclePrice): OraclePrice;
|
|
132
|
+
}
|