@parqxchange/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/accounts/marketOracle.d.ts +21 -0
- package/dist/accounts/marketOracle.js +114 -0
- package/dist/accounts/resolve.d.ts +75 -0
- package/dist/accounts/resolve.js +116 -0
- package/dist/actions/cranks.d.ts +8 -0
- package/dist/actions/cranks.js +10 -0
- package/dist/actions/liquidity.d.ts +23 -0
- package/dist/actions/liquidity.js +21 -0
- package/dist/actions/trading.d.ts +39 -0
- package/dist/actions/trading.js +95 -0
- package/dist/auth/tradingKey.d.ts +27 -0
- package/dist/auth/tradingKey.js +71 -0
- package/dist/decode/index.d.ts +39 -0
- package/dist/decode/index.js +445 -0
- package/dist/events/decoder.d.ts +60 -0
- package/dist/events/decoder.js +369 -0
- package/dist/events/emitter.d.ts +49 -0
- package/dist/events/emitter.js +153 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +93 -0
- package/dist/indexer/client.d.ts +13 -0
- package/dist/indexer/client.js +36 -0
- package/dist/indexer/types.d.ts +9 -0
- package/dist/indexer/types.js +2 -0
- package/dist/minimal.d.ts +3 -0
- package/dist/minimal.js +13 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +5 -0
- package/dist/programs/feeDistributor.d.ts +42 -0
- package/dist/programs/feeDistributor.js +42 -0
- package/dist/programs/oracle.d.ts +31 -0
- package/dist/programs/oracle.js +49 -0
- package/dist/programs/perp.d.ts +283 -0
- package/dist/programs/perp.js +346 -0
- package/dist/programs/pool.d.ts +113 -0
- package/dist/programs/pool.js +126 -0
- package/dist/programs/priceFeed.d.ts +13 -0
- package/dist/programs/priceFeed.js +21 -0
- package/dist/programs/staking.d.ts +76 -0
- package/dist/programs/staking.js +135 -0
- package/dist/types/index.d.ts +337 -0
- package/dist/types/index.js +9 -0
- package/dist/utils/computeBudget.d.ts +5 -0
- package/dist/utils/computeBudget.js +14 -0
- package/dist/utils/errors.d.ts +56 -0
- package/dist/utils/errors.js +138 -0
- package/dist/utils/pda.d.ts +28 -0
- package/dist/utils/pda.js +131 -0
- package/dist/utils/priceMath.d.ts +5 -0
- package/dist/utils/priceMath.js +46 -0
- package/dist/utils/tokenProgram.d.ts +2 -0
- package/dist/utils/tokenProgram.js +16 -0
- package/dist/utils/transaction.d.ts +2 -0
- package/dist/utils/transaction.js +12 -0
- package/dist/utils/version.d.ts +11 -0
- package/dist/utils/version.js +29 -0
- package/idl/fee_distributor.json +779 -0
- package/idl/oracle_adapter.json +767 -0
- package/idl/perp_engine.json +3908 -0
- package/idl/pool_program.json +2956 -0
- package/idl/price_feed.json +478 -0
- package/idl/staking.json +1336 -0
- package/package.json +98 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.IndexerClient = exports.decodeAnchorEvent = exports.ParquetEventEmitter = exports.buildRevokeTradingKeyIx = exports.buildRegisterTradingKeyIx = exports.revokeTradingKey = exports.registerTradingKey = exports.MARKET_ORACLE_V2_LEN = exports.clearMarketOracleFeedsCache = exports.getMarketOracleFeeds = exports.resolveLiquidityAccounts = exports.resolveUpdateMarginAccounts = exports.resolveClosePositionAccounts = exports.resolveOpenPositionAccounts = exports.crankFundingRate = exports.updateMargin = exports.closePosition = exports.openPosition = exports.removeLiquidity = exports.addLiquidity = exports.StakingClient = exports.FeeDistributorClient = exports.PRICE_FEED_PROGRAM_ID = exports.PriceFeedClient = exports.OracleClient = exports.PerpClient = exports.PoolClient = exports.DISCRIMINATORS = exports.DecoderError = exports.identifyAccountType = exports.decodeUserQueueClaims = exports.decodePayoutQueueEntry = exports.decodeStakePosition = exports.decodeStakingPool = exports.decodeFeePool = exports.decodeAffiliateReward = exports.decodeTraderReferral = exports.decodeReferralCode = exports.decodeReferralConfig = exports.decodeTradingKey = exports.decodeOrderNonce = exports.decodeOrder = exports.decodePoolState = exports.decodeMarketState = exports.decodePosition = exports.probeTokenProgram = exports.PROGRAM_IDS_V4 = exports.detectProgramVersion = exports.buildVersionedTransaction = exports.withComputeBudget = void 0;
|
|
18
|
+
exports.IndexerError = void 0;
|
|
19
|
+
__exportStar(require("./utils/pda"), exports);
|
|
20
|
+
__exportStar(require("./utils/errors"), exports);
|
|
21
|
+
__exportStar(require("./utils/priceMath"), exports);
|
|
22
|
+
var computeBudget_1 = require("./utils/computeBudget");
|
|
23
|
+
Object.defineProperty(exports, "withComputeBudget", { enumerable: true, get: function () { return computeBudget_1.withComputeBudget; } });
|
|
24
|
+
var transaction_1 = require("./utils/transaction");
|
|
25
|
+
Object.defineProperty(exports, "buildVersionedTransaction", { enumerable: true, get: function () { return transaction_1.buildVersionedTransaction; } });
|
|
26
|
+
var version_1 = require("./utils/version");
|
|
27
|
+
Object.defineProperty(exports, "detectProgramVersion", { enumerable: true, get: function () { return version_1.detectProgramVersion; } });
|
|
28
|
+
Object.defineProperty(exports, "PROGRAM_IDS_V4", { enumerable: true, get: function () { return version_1.PROGRAM_IDS_V4; } });
|
|
29
|
+
var tokenProgram_1 = require("./utils/tokenProgram");
|
|
30
|
+
Object.defineProperty(exports, "probeTokenProgram", { enumerable: true, get: function () { return tokenProgram_1.probeTokenProgram; } });
|
|
31
|
+
__exportStar(require("./types"), exports);
|
|
32
|
+
var decode_1 = require("./decode");
|
|
33
|
+
Object.defineProperty(exports, "decodePosition", { enumerable: true, get: function () { return decode_1.decodePosition; } });
|
|
34
|
+
Object.defineProperty(exports, "decodeMarketState", { enumerable: true, get: function () { return decode_1.decodeMarketState; } });
|
|
35
|
+
Object.defineProperty(exports, "decodePoolState", { enumerable: true, get: function () { return decode_1.decodePoolState; } });
|
|
36
|
+
Object.defineProperty(exports, "decodeOrder", { enumerable: true, get: function () { return decode_1.decodeOrder; } });
|
|
37
|
+
Object.defineProperty(exports, "decodeOrderNonce", { enumerable: true, get: function () { return decode_1.decodeOrderNonce; } });
|
|
38
|
+
Object.defineProperty(exports, "decodeTradingKey", { enumerable: true, get: function () { return decode_1.decodeTradingKey; } });
|
|
39
|
+
Object.defineProperty(exports, "decodeReferralConfig", { enumerable: true, get: function () { return decode_1.decodeReferralConfig; } });
|
|
40
|
+
Object.defineProperty(exports, "decodeReferralCode", { enumerable: true, get: function () { return decode_1.decodeReferralCode; } });
|
|
41
|
+
Object.defineProperty(exports, "decodeTraderReferral", { enumerable: true, get: function () { return decode_1.decodeTraderReferral; } });
|
|
42
|
+
Object.defineProperty(exports, "decodeAffiliateReward", { enumerable: true, get: function () { return decode_1.decodeAffiliateReward; } });
|
|
43
|
+
Object.defineProperty(exports, "decodeFeePool", { enumerable: true, get: function () { return decode_1.decodeFeePool; } });
|
|
44
|
+
Object.defineProperty(exports, "decodeStakingPool", { enumerable: true, get: function () { return decode_1.decodeStakingPool; } });
|
|
45
|
+
Object.defineProperty(exports, "decodeStakePosition", { enumerable: true, get: function () { return decode_1.decodeStakePosition; } });
|
|
46
|
+
Object.defineProperty(exports, "decodePayoutQueueEntry", { enumerable: true, get: function () { return decode_1.decodePayoutQueueEntry; } });
|
|
47
|
+
Object.defineProperty(exports, "decodeUserQueueClaims", { enumerable: true, get: function () { return decode_1.decodeUserQueueClaims; } });
|
|
48
|
+
Object.defineProperty(exports, "identifyAccountType", { enumerable: true, get: function () { return decode_1.identifyAccountType; } });
|
|
49
|
+
Object.defineProperty(exports, "DecoderError", { enumerable: true, get: function () { return decode_1.DecoderError; } });
|
|
50
|
+
Object.defineProperty(exports, "DISCRIMINATORS", { enumerable: true, get: function () { return decode_1.DISCRIMINATORS; } });
|
|
51
|
+
var pool_1 = require("./programs/pool");
|
|
52
|
+
Object.defineProperty(exports, "PoolClient", { enumerable: true, get: function () { return pool_1.PoolClient; } });
|
|
53
|
+
var perp_1 = require("./programs/perp");
|
|
54
|
+
Object.defineProperty(exports, "PerpClient", { enumerable: true, get: function () { return perp_1.PerpClient; } });
|
|
55
|
+
var oracle_1 = require("./programs/oracle");
|
|
56
|
+
Object.defineProperty(exports, "OracleClient", { enumerable: true, get: function () { return oracle_1.OracleClient; } });
|
|
57
|
+
var priceFeed_1 = require("./programs/priceFeed");
|
|
58
|
+
Object.defineProperty(exports, "PriceFeedClient", { enumerable: true, get: function () { return priceFeed_1.PriceFeedClient; } });
|
|
59
|
+
Object.defineProperty(exports, "PRICE_FEED_PROGRAM_ID", { enumerable: true, get: function () { return priceFeed_1.PRICE_FEED_PROGRAM_ID; } });
|
|
60
|
+
var feeDistributor_1 = require("./programs/feeDistributor");
|
|
61
|
+
Object.defineProperty(exports, "FeeDistributorClient", { enumerable: true, get: function () { return feeDistributor_1.FeeDistributorClient; } });
|
|
62
|
+
var staking_1 = require("./programs/staking");
|
|
63
|
+
Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
|
|
64
|
+
var liquidity_1 = require("./actions/liquidity");
|
|
65
|
+
Object.defineProperty(exports, "addLiquidity", { enumerable: true, get: function () { return liquidity_1.addLiquidity; } });
|
|
66
|
+
Object.defineProperty(exports, "removeLiquidity", { enumerable: true, get: function () { return liquidity_1.removeLiquidity; } });
|
|
67
|
+
var trading_1 = require("./actions/trading");
|
|
68
|
+
Object.defineProperty(exports, "openPosition", { enumerable: true, get: function () { return trading_1.openPosition; } });
|
|
69
|
+
Object.defineProperty(exports, "closePosition", { enumerable: true, get: function () { return trading_1.closePosition; } });
|
|
70
|
+
Object.defineProperty(exports, "updateMargin", { enumerable: true, get: function () { return trading_1.updateMargin; } });
|
|
71
|
+
var cranks_1 = require("./actions/cranks");
|
|
72
|
+
Object.defineProperty(exports, "crankFundingRate", { enumerable: true, get: function () { return cranks_1.crankFundingRate; } });
|
|
73
|
+
var resolve_1 = require("./accounts/resolve");
|
|
74
|
+
Object.defineProperty(exports, "resolveOpenPositionAccounts", { enumerable: true, get: function () { return resolve_1.resolveOpenPositionAccounts; } });
|
|
75
|
+
Object.defineProperty(exports, "resolveClosePositionAccounts", { enumerable: true, get: function () { return resolve_1.resolveClosePositionAccounts; } });
|
|
76
|
+
Object.defineProperty(exports, "resolveUpdateMarginAccounts", { enumerable: true, get: function () { return resolve_1.resolveUpdateMarginAccounts; } });
|
|
77
|
+
Object.defineProperty(exports, "resolveLiquidityAccounts", { enumerable: true, get: function () { return resolve_1.resolveLiquidityAccounts; } });
|
|
78
|
+
var marketOracle_1 = require("./accounts/marketOracle");
|
|
79
|
+
Object.defineProperty(exports, "getMarketOracleFeeds", { enumerable: true, get: function () { return marketOracle_1.getMarketOracleFeeds; } });
|
|
80
|
+
Object.defineProperty(exports, "clearMarketOracleFeedsCache", { enumerable: true, get: function () { return marketOracle_1.clearMarketOracleFeedsCache; } });
|
|
81
|
+
Object.defineProperty(exports, "MARKET_ORACLE_V2_LEN", { enumerable: true, get: function () { return marketOracle_1.MARKET_ORACLE_V2_LEN; } });
|
|
82
|
+
var tradingKey_1 = require("./auth/tradingKey");
|
|
83
|
+
Object.defineProperty(exports, "registerTradingKey", { enumerable: true, get: function () { return tradingKey_1.registerTradingKey; } });
|
|
84
|
+
Object.defineProperty(exports, "revokeTradingKey", { enumerable: true, get: function () { return tradingKey_1.revokeTradingKey; } });
|
|
85
|
+
Object.defineProperty(exports, "buildRegisterTradingKeyIx", { enumerable: true, get: function () { return tradingKey_1.buildRegisterTradingKeyIx; } });
|
|
86
|
+
Object.defineProperty(exports, "buildRevokeTradingKeyIx", { enumerable: true, get: function () { return tradingKey_1.buildRevokeTradingKeyIx; } });
|
|
87
|
+
var emitter_1 = require("./events/emitter");
|
|
88
|
+
Object.defineProperty(exports, "ParquetEventEmitter", { enumerable: true, get: function () { return emitter_1.ParquetEventEmitter; } });
|
|
89
|
+
var decoder_1 = require("./events/decoder");
|
|
90
|
+
Object.defineProperty(exports, "decodeAnchorEvent", { enumerable: true, get: function () { return decoder_1.decodeAnchorEvent; } });
|
|
91
|
+
var client_1 = require("./indexer/client");
|
|
92
|
+
Object.defineProperty(exports, "IndexerClient", { enumerable: true, get: function () { return client_1.IndexerClient; } });
|
|
93
|
+
Object.defineProperty(exports, "IndexerError", { enumerable: true, get: function () { return client_1.IndexerError; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StatsResponse } from "./types";
|
|
2
|
+
export declare class IndexerError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(status: number, message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class IndexerClient {
|
|
8
|
+
private readonly defaultTimeoutMs;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
constructor(baseUrl: string, defaultTimeoutMs?: number);
|
|
11
|
+
getStats(market: string): Promise<StatsResponse>;
|
|
12
|
+
private fetchJson;
|
|
13
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexerClient = exports.IndexerError = void 0;
|
|
4
|
+
class IndexerError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
name = "IndexerError";
|
|
7
|
+
constructor(status, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.status = status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.IndexerError = IndexerError;
|
|
13
|
+
class IndexerClient {
|
|
14
|
+
defaultTimeoutMs;
|
|
15
|
+
baseUrl;
|
|
16
|
+
constructor(baseUrl, defaultTimeoutMs = 15_000) {
|
|
17
|
+
this.defaultTimeoutMs = defaultTimeoutMs;
|
|
18
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
19
|
+
}
|
|
20
|
+
async getStats(market) {
|
|
21
|
+
const url = `${this.baseUrl}/stats?market=${encodeURIComponent(market)}`;
|
|
22
|
+
return this.fetchJson(url);
|
|
23
|
+
}
|
|
24
|
+
async fetchJson(url) {
|
|
25
|
+
const res = await fetch(url, {
|
|
26
|
+
signal: AbortSignal.timeout(this.defaultTimeoutMs),
|
|
27
|
+
headers: { accept: "application/json" },
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok) {
|
|
30
|
+
const body = await res.text().catch(() => "");
|
|
31
|
+
throw new IndexerError(res.status, `indexer ${res.status}: ${body.slice(0, 200)}`);
|
|
32
|
+
}
|
|
33
|
+
return (await res.json());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.IndexerClient = IndexerClient;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { PerpClient, type OpenPositionArgs } from "./programs/perp";
|
|
2
|
+
export { openPosition, closePosition, updateMargin, type TradingOpts } from "./actions/trading";
|
|
3
|
+
export { getMarketOracleFeeds, clearMarketOracleFeedsCache, MARKET_ORACLE_V2_LEN, type MarketOracleFeeds, } from "./accounts/marketOracle";
|
package/dist/minimal.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MARKET_ORACLE_V2_LEN = exports.clearMarketOracleFeedsCache = exports.getMarketOracleFeeds = exports.updateMargin = exports.closePosition = exports.openPosition = exports.PerpClient = void 0;
|
|
4
|
+
var perp_1 = require("./programs/perp");
|
|
5
|
+
Object.defineProperty(exports, "PerpClient", { enumerable: true, get: function () { return perp_1.PerpClient; } });
|
|
6
|
+
var trading_1 = require("./actions/trading");
|
|
7
|
+
Object.defineProperty(exports, "openPosition", { enumerable: true, get: function () { return trading_1.openPosition; } });
|
|
8
|
+
Object.defineProperty(exports, "closePosition", { enumerable: true, get: function () { return trading_1.closePosition; } });
|
|
9
|
+
Object.defineProperty(exports, "updateMargin", { enumerable: true, get: function () { return trading_1.updateMargin; } });
|
|
10
|
+
var marketOracle_1 = require("./accounts/marketOracle");
|
|
11
|
+
Object.defineProperty(exports, "getMarketOracleFeeds", { enumerable: true, get: function () { return marketOracle_1.getMarketOracleFeeds; } });
|
|
12
|
+
Object.defineProperty(exports, "clearMarketOracleFeedsCache", { enumerable: true, get: function () { return marketOracle_1.clearMarketOracleFeedsCache; } });
|
|
13
|
+
Object.defineProperty(exports, "MARKET_ORACLE_V2_LEN", { enumerable: true, get: function () { return marketOracle_1.MARKET_ORACLE_V2_LEN; } });
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadTradingKeypair } from "./auth/tradingKey";
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTradingKeypair = void 0;
|
|
4
|
+
var tradingKey_1 = require("./auth/tradingKey");
|
|
5
|
+
Object.defineProperty(exports, "loadTradingKeypair", { enumerable: true, get: function () { return tradingKey_1.loadTradingKeypair; } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
export declare class FeeDistributorClient {
|
|
4
|
+
private readonly program;
|
|
5
|
+
constructor(program: Program);
|
|
6
|
+
distributeFeesIx(accounts: {
|
|
7
|
+
feePool: PublicKey;
|
|
8
|
+
usdcAccount: PublicKey;
|
|
9
|
+
stakingReward: PublicKey;
|
|
10
|
+
treasury: PublicKey;
|
|
11
|
+
referralReserve: PublicKey;
|
|
12
|
+
}): Promise<TransactionInstruction>;
|
|
13
|
+
updateFeeSplitIx(accounts: {
|
|
14
|
+
admin: PublicKey;
|
|
15
|
+
feePool: PublicKey;
|
|
16
|
+
}, args: {
|
|
17
|
+
stakerSplitBps: number;
|
|
18
|
+
treasurySplitBps: number;
|
|
19
|
+
referralSplitBps: number;
|
|
20
|
+
}): Promise<TransactionInstruction>;
|
|
21
|
+
updateFeePoolAccountsIx(accounts: {
|
|
22
|
+
admin: PublicKey;
|
|
23
|
+
feePool: PublicKey;
|
|
24
|
+
usdcMint: PublicKey;
|
|
25
|
+
usdcAccount: PublicKey;
|
|
26
|
+
stakingReward: PublicKey;
|
|
27
|
+
treasury: PublicKey;
|
|
28
|
+
referralReserve: PublicKey;
|
|
29
|
+
}): Promise<TransactionInstruction>;
|
|
30
|
+
withdrawTreasuryIx(accounts: {
|
|
31
|
+
admin: PublicKey;
|
|
32
|
+
feePool: PublicKey;
|
|
33
|
+
treasury: PublicKey;
|
|
34
|
+
destination: PublicKey;
|
|
35
|
+
}, amount: bigint): Promise<TransactionInstruction>;
|
|
36
|
+
disburseReferralIx(accounts: {
|
|
37
|
+
engineAuth: PublicKey;
|
|
38
|
+
feePool: PublicKey;
|
|
39
|
+
referralReserve: PublicKey;
|
|
40
|
+
affiliateUsdc: PublicKey;
|
|
41
|
+
}, amount: bigint, marketId: Uint8Array): Promise<TransactionInstruction>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeeDistributorClient = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
class FeeDistributorClient {
|
|
7
|
+
program;
|
|
8
|
+
constructor(program) {
|
|
9
|
+
this.program = program;
|
|
10
|
+
}
|
|
11
|
+
async distributeFeesIx(accounts) {
|
|
12
|
+
return this.program.methods
|
|
13
|
+
.distributeFees()
|
|
14
|
+
.accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
|
|
15
|
+
.instruction();
|
|
16
|
+
}
|
|
17
|
+
async updateFeeSplitIx(accounts, args) {
|
|
18
|
+
return this.program.methods
|
|
19
|
+
.updateFeeSplit(args)
|
|
20
|
+
.accounts(accounts)
|
|
21
|
+
.instruction();
|
|
22
|
+
}
|
|
23
|
+
async updateFeePoolAccountsIx(accounts) {
|
|
24
|
+
return this.program.methods
|
|
25
|
+
.updateFeePoolAccounts()
|
|
26
|
+
.accounts(accounts)
|
|
27
|
+
.instruction();
|
|
28
|
+
}
|
|
29
|
+
async withdrawTreasuryIx(accounts, amount) {
|
|
30
|
+
return this.program.methods
|
|
31
|
+
.withdrawTreasury({ amount: new anchor_1.BN(amount.toString()) })
|
|
32
|
+
.accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
|
|
33
|
+
.instruction();
|
|
34
|
+
}
|
|
35
|
+
async disburseReferralIx(accounts, amount, marketId) {
|
|
36
|
+
return this.program.methods
|
|
37
|
+
.disburseReferral({ amount: new anchor_1.BN(amount.toString()), marketId: Array.from(marketId) })
|
|
38
|
+
.accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
|
|
39
|
+
.instruction();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FeeDistributorClient = FeeDistributorClient;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
type OracleType = "pyth" | "switchboard";
|
|
4
|
+
export declare class OracleClient {
|
|
5
|
+
private readonly program;
|
|
6
|
+
constructor(program: Program);
|
|
7
|
+
registerMarketOracleIx(accounts: {
|
|
8
|
+
marketOracle: PublicKey;
|
|
9
|
+
admin: PublicKey;
|
|
10
|
+
oracleConfig: PublicKey;
|
|
11
|
+
}, args: {
|
|
12
|
+
marketId: Uint8Array;
|
|
13
|
+
primaryOracleType: OracleType;
|
|
14
|
+
primaryFeedAccount: PublicKey;
|
|
15
|
+
primaryMaxStalenessSecs: bigint;
|
|
16
|
+
maxConfidencePct: number;
|
|
17
|
+
priceDecimals: number;
|
|
18
|
+
}): Promise<TransactionInstruction>;
|
|
19
|
+
updateMarketOracleFeedsIx(accounts: {
|
|
20
|
+
marketOracle: PublicKey;
|
|
21
|
+
admin: PublicKey;
|
|
22
|
+
}, args: {
|
|
23
|
+
primaryOracleType: OracleType;
|
|
24
|
+
primaryFeedAccount: PublicKey;
|
|
25
|
+
primaryMaxStalenessSecs: bigint;
|
|
26
|
+
secondaryOracleType: OracleType;
|
|
27
|
+
secondaryFeedAccount: PublicKey;
|
|
28
|
+
secondaryMaxStalenessSecs: bigint;
|
|
29
|
+
}): Promise<TransactionInstruction>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OracleClient = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
function oracleTypeArg(t) {
|
|
7
|
+
return t === "pyth" ? { pyth: {} } : { switchboard: {} };
|
|
8
|
+
}
|
|
9
|
+
class OracleClient {
|
|
10
|
+
program;
|
|
11
|
+
constructor(program) {
|
|
12
|
+
this.program = program;
|
|
13
|
+
}
|
|
14
|
+
async registerMarketOracleIx(accounts, args) {
|
|
15
|
+
return this.program.methods
|
|
16
|
+
.registerMarketOracle({
|
|
17
|
+
marketId: Array.from(args.marketId),
|
|
18
|
+
primaryOracleType: oracleTypeArg(args.primaryOracleType),
|
|
19
|
+
primaryFeedAccount: args.primaryFeedAccount,
|
|
20
|
+
primaryMaxStalenessSecs: new anchor_1.BN(args.primaryMaxStalenessSecs.toString()),
|
|
21
|
+
maxConfidencePct: args.maxConfidencePct,
|
|
22
|
+
priceDecimals: args.priceDecimals,
|
|
23
|
+
})
|
|
24
|
+
.accounts({
|
|
25
|
+
marketOracle: accounts.marketOracle,
|
|
26
|
+
admin: accounts.admin,
|
|
27
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
28
|
+
oracleConfig: accounts.oracleConfig,
|
|
29
|
+
})
|
|
30
|
+
.instruction();
|
|
31
|
+
}
|
|
32
|
+
async updateMarketOracleFeedsIx(accounts, args) {
|
|
33
|
+
return this.program.methods
|
|
34
|
+
.updateMarketOracleFeeds({
|
|
35
|
+
primaryOracleType: oracleTypeArg(args.primaryOracleType),
|
|
36
|
+
primaryFeedAccount: args.primaryFeedAccount,
|
|
37
|
+
primaryMaxStalenessSecs: new anchor_1.BN(args.primaryMaxStalenessSecs.toString()),
|
|
38
|
+
secondaryOracleType: oracleTypeArg(args.secondaryOracleType),
|
|
39
|
+
secondaryFeedAccount: args.secondaryFeedAccount,
|
|
40
|
+
secondaryMaxStalenessSecs: new anchor_1.BN(args.secondaryMaxStalenessSecs.toString()),
|
|
41
|
+
})
|
|
42
|
+
.accounts({
|
|
43
|
+
marketOracle: accounts.marketOracle,
|
|
44
|
+
admin: accounts.admin,
|
|
45
|
+
})
|
|
46
|
+
.instruction();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.OracleClient = OracleClient;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { HaltMode } from "../types";
|
|
4
|
+
import type { ProtocolConfig, ReferralTier } from "../types";
|
|
5
|
+
export interface OpenPositionArgs {
|
|
6
|
+
side: {
|
|
7
|
+
long: {};
|
|
8
|
+
} | {
|
|
9
|
+
short: {};
|
|
10
|
+
};
|
|
11
|
+
sizeUsdc: bigint;
|
|
12
|
+
walletCollateral: bigint;
|
|
13
|
+
fromQueueAmount: bigint;
|
|
14
|
+
acceptablePrice: bigint;
|
|
15
|
+
minOutputUsdc: bigint;
|
|
16
|
+
positionNonce: bigint;
|
|
17
|
+
referralCode: number[];
|
|
18
|
+
}
|
|
19
|
+
export declare class PerpClient {
|
|
20
|
+
private readonly program;
|
|
21
|
+
constructor(program: Program);
|
|
22
|
+
openPositionIx(accounts: {
|
|
23
|
+
marketState: PublicKey;
|
|
24
|
+
position: PublicKey;
|
|
25
|
+
tradingKey: PublicKey | null;
|
|
26
|
+
signer: PublicKey;
|
|
27
|
+
signerUsdc: PublicKey;
|
|
28
|
+
vaultUsdc: PublicKey;
|
|
29
|
+
referralConfig?: PublicKey;
|
|
30
|
+
referralCodeAccount?: PublicKey;
|
|
31
|
+
traderReferral?: PublicKey;
|
|
32
|
+
poolState: PublicKey;
|
|
33
|
+
poolProgram: PublicKey;
|
|
34
|
+
oracleProgram: PublicKey;
|
|
35
|
+
marketOracle: PublicKey;
|
|
36
|
+
engineAuth: PublicKey;
|
|
37
|
+
userClaims: PublicKey;
|
|
38
|
+
feeSettings: PublicKey;
|
|
39
|
+
affiliate?: PublicKey;
|
|
40
|
+
affiliateReward?: PublicKey | null;
|
|
41
|
+
}, args: OpenPositionArgs, primaryFeedAccount: PublicKey, secondaryFeedAccount: PublicKey): Promise<TransactionInstruction>;
|
|
42
|
+
closePositionIx(accounts: {
|
|
43
|
+
marketState: PublicKey;
|
|
44
|
+
position: PublicKey;
|
|
45
|
+
tradingKey: PublicKey | null;
|
|
46
|
+
signer: PublicKey;
|
|
47
|
+
owner: PublicKey;
|
|
48
|
+
userUsdc: PublicKey;
|
|
49
|
+
referralConfig?: PublicKey;
|
|
50
|
+
referralCodeAccount?: PublicKey;
|
|
51
|
+
traderReferral?: PublicKey;
|
|
52
|
+
poolState: PublicKey;
|
|
53
|
+
poolProgram: PublicKey;
|
|
54
|
+
oracleProgram: PublicKey;
|
|
55
|
+
marketOracle: PublicKey;
|
|
56
|
+
vaultUsdc: PublicKey;
|
|
57
|
+
vaultAuthority: PublicKey;
|
|
58
|
+
engineAuth: PublicKey;
|
|
59
|
+
feeSettings: PublicKey;
|
|
60
|
+
affiliate?: PublicKey;
|
|
61
|
+
affiliateReward?: PublicKey | null;
|
|
62
|
+
lpMint: PublicKey;
|
|
63
|
+
insuranceFund: PublicKey;
|
|
64
|
+
insuranceVault: PublicKey;
|
|
65
|
+
}, closeSize: bigint | null, primaryFeedAccount: PublicKey, secondaryFeedAccount: PublicKey, minOutputUsdc?: bigint, queueEntryPda?: PublicKey, userClaimsPda?: PublicKey): Promise<TransactionInstruction>;
|
|
66
|
+
updatePositionMarginIx(accounts: {
|
|
67
|
+
marketState: PublicKey;
|
|
68
|
+
position: PublicKey;
|
|
69
|
+
tradingKey: PublicKey | null;
|
|
70
|
+
signer: PublicKey;
|
|
71
|
+
owner: PublicKey;
|
|
72
|
+
signerUsdc: PublicKey;
|
|
73
|
+
vaultUsdc: PublicKey;
|
|
74
|
+
userUsdc: PublicKey;
|
|
75
|
+
vaultAuthority: PublicKey;
|
|
76
|
+
poolState: PublicKey;
|
|
77
|
+
poolProgram: PublicKey;
|
|
78
|
+
engineAuth: PublicKey;
|
|
79
|
+
oracleProgram: PublicKey;
|
|
80
|
+
marketOracle: PublicKey;
|
|
81
|
+
}, delta: bigint, primaryFeedAccount?: PublicKey, secondaryFeedAccount?: PublicKey): Promise<TransactionInstruction>;
|
|
82
|
+
updateFundingRateIx(accounts: {
|
|
83
|
+
marketState: PublicKey;
|
|
84
|
+
poolState: PublicKey;
|
|
85
|
+
}): Promise<TransactionInstruction>;
|
|
86
|
+
createOrderIx(accounts: {
|
|
87
|
+
marketState: PublicKey;
|
|
88
|
+
poolState: PublicKey;
|
|
89
|
+
orderNonce: PublicKey;
|
|
90
|
+
order: PublicKey;
|
|
91
|
+
owner: PublicKey;
|
|
92
|
+
ownerUsdc: PublicKey;
|
|
93
|
+
vaultUsdc: PublicKey;
|
|
94
|
+
poolProgram: PublicKey;
|
|
95
|
+
engineAuth: PublicKey;
|
|
96
|
+
}, args: {
|
|
97
|
+
orderType: {
|
|
98
|
+
limitIncrease: {};
|
|
99
|
+
} | {
|
|
100
|
+
stopIncrease: {};
|
|
101
|
+
} | {
|
|
102
|
+
limitDecrease: {};
|
|
103
|
+
} | {
|
|
104
|
+
stopLossDecrease: {};
|
|
105
|
+
};
|
|
106
|
+
side: {
|
|
107
|
+
long: {};
|
|
108
|
+
} | {
|
|
109
|
+
short: {};
|
|
110
|
+
};
|
|
111
|
+
sizeUsdc: bigint;
|
|
112
|
+
collateralUsdc: bigint;
|
|
113
|
+
triggerPrice: bigint;
|
|
114
|
+
acceptablePrice: bigint;
|
|
115
|
+
minOutputUsdc: bigint;
|
|
116
|
+
referralCode: number[];
|
|
117
|
+
positionNonce: bigint;
|
|
118
|
+
}): Promise<TransactionInstruction>;
|
|
119
|
+
cancelOrderIx(accounts: {
|
|
120
|
+
marketState: PublicKey;
|
|
121
|
+
order: PublicKey;
|
|
122
|
+
signer: PublicKey;
|
|
123
|
+
owner: PublicKey;
|
|
124
|
+
ownerUsdc: PublicKey;
|
|
125
|
+
vaultUsdc: PublicKey;
|
|
126
|
+
vaultAuthority: PublicKey;
|
|
127
|
+
engineAuth: PublicKey;
|
|
128
|
+
poolState: PublicKey;
|
|
129
|
+
poolProgram: PublicKey;
|
|
130
|
+
}): Promise<TransactionInstruction>;
|
|
131
|
+
initializeMarketIx(accounts: {
|
|
132
|
+
marketState: PublicKey;
|
|
133
|
+
engineAuth: PublicKey;
|
|
134
|
+
admin: PublicKey;
|
|
135
|
+
}, args: {
|
|
136
|
+
marketId: Uint8Array;
|
|
137
|
+
poolState: PublicKey;
|
|
138
|
+
poolProgram: PublicKey;
|
|
139
|
+
oracleProgram: PublicKey;
|
|
140
|
+
treasury: PublicKey;
|
|
141
|
+
stakingProgramId: PublicKey;
|
|
142
|
+
maxLeverage: number;
|
|
143
|
+
baseFeeBps: number;
|
|
144
|
+
mmrBps: number;
|
|
145
|
+
maxOiLong: bigint;
|
|
146
|
+
maxOiShort: bigint;
|
|
147
|
+
feeBpsFavorable: number;
|
|
148
|
+
initialMarginBps: number;
|
|
149
|
+
}): Promise<TransactionInstruction>;
|
|
150
|
+
updateMarketConfigIx(accounts: {
|
|
151
|
+
marketState: PublicKey;
|
|
152
|
+
poolState: PublicKey;
|
|
153
|
+
admin: PublicKey;
|
|
154
|
+
}, args: {
|
|
155
|
+
fundingIncreaseFactorPerSecond: bigint | null;
|
|
156
|
+
fundingDecreaseFactorPerSecond: bigint | null;
|
|
157
|
+
thresholdForStableFunding: bigint | null;
|
|
158
|
+
thresholdForDecreaseFunding: bigint | null;
|
|
159
|
+
minFundingFactorPerSecond: bigint | null;
|
|
160
|
+
maxFundingFactorPerSecond: bigint | null;
|
|
161
|
+
borrowingFactor: bigint | null;
|
|
162
|
+
optimalUsageFactor: bigint | null;
|
|
163
|
+
aboveOptimalBorrowingFactor: bigint | null;
|
|
164
|
+
priceImpactFactor: bigint | null;
|
|
165
|
+
maxPriceImpactBps: number | null;
|
|
166
|
+
keeper: PublicKey | null;
|
|
167
|
+
stakingProgramId?: PublicKey | null;
|
|
168
|
+
maxOiLong?: bigint | null;
|
|
169
|
+
maxOiShort?: bigint | null;
|
|
170
|
+
feeBpsFavorable?: number | null;
|
|
171
|
+
offHoursMaxOiLong?: bigint | null;
|
|
172
|
+
offHoursMaxOiShort?: bigint | null;
|
|
173
|
+
mmrBps?: number | null;
|
|
174
|
+
initialMarginBps?: number | null;
|
|
175
|
+
maxLeverage?: number | null;
|
|
176
|
+
adlFrozen?: number | null;
|
|
177
|
+
adlTailTriggerUsdcRth?: bigint | null;
|
|
178
|
+
adlTailTriggerUsdcOff?: bigint | null;
|
|
179
|
+
adlTailMinAgeSecsRth?: number | null;
|
|
180
|
+
adlTailMinAgeSecsOff?: number | null;
|
|
181
|
+
adlHaircutBpsRth?: number | null;
|
|
182
|
+
adlHaircutBpsOff?: number | null;
|
|
183
|
+
adlMaxHaircutBps?: number | null;
|
|
184
|
+
adlMaxFeedDivergenceBps?: number | null;
|
|
185
|
+
baseFeeBps?: number | null;
|
|
186
|
+
}): Promise<TransactionInstruction>;
|
|
187
|
+
setTradingHaltIx(admin: PublicKey, mode: HaltMode | number): Promise<TransactionInstruction>;
|
|
188
|
+
migrateMarketStateIx(accounts: {
|
|
189
|
+
marketState: PublicKey;
|
|
190
|
+
poolState: PublicKey;
|
|
191
|
+
admin: PublicKey;
|
|
192
|
+
}): Promise<TransactionInstruction>;
|
|
193
|
+
migratePositionIx(accounts: {
|
|
194
|
+
position: PublicKey;
|
|
195
|
+
payer: PublicKey;
|
|
196
|
+
}): Promise<TransactionInstruction>;
|
|
197
|
+
setPerSideReservedIx(accounts: {
|
|
198
|
+
marketState: PublicKey;
|
|
199
|
+
poolState: PublicKey;
|
|
200
|
+
admin: PublicKey;
|
|
201
|
+
}, args: {
|
|
202
|
+
longReservedUsdc: bigint;
|
|
203
|
+
shortReservedUsdc: bigint;
|
|
204
|
+
}): Promise<TransactionInstruction>;
|
|
205
|
+
liquidateIx(accounts: {
|
|
206
|
+
marketState: PublicKey;
|
|
207
|
+
position: PublicKey;
|
|
208
|
+
liquidator: PublicKey;
|
|
209
|
+
userUsdc: PublicKey;
|
|
210
|
+
liquidatorUsdc: PublicKey;
|
|
211
|
+
poolState: PublicKey;
|
|
212
|
+
poolProgram: PublicKey;
|
|
213
|
+
oracleProgram: PublicKey;
|
|
214
|
+
marketOracle: PublicKey;
|
|
215
|
+
vaultUsdc: PublicKey;
|
|
216
|
+
vaultAuthority: PublicKey;
|
|
217
|
+
insuranceFund: PublicKey;
|
|
218
|
+
insuranceVault: PublicKey;
|
|
219
|
+
insuranceVaultAuthority: PublicKey;
|
|
220
|
+
lpMint: PublicKey;
|
|
221
|
+
engineAuth: PublicKey;
|
|
222
|
+
}, primaryFeedAccount: PublicKey, secondaryFeedAccount: PublicKey, queueEntries: PublicKey[], userClaimsPda: PublicKey | null, hasQueueCollateral: boolean, maxCollateralLoss?: bigint): Promise<TransactionInstruction>;
|
|
223
|
+
executeOrderIx(accounts: {
|
|
224
|
+
marketState: PublicKey;
|
|
225
|
+
order: PublicKey;
|
|
226
|
+
position: PublicKey;
|
|
227
|
+
keeper: PublicKey;
|
|
228
|
+
owner: PublicKey;
|
|
229
|
+
ownerUsdc: PublicKey;
|
|
230
|
+
vaultUsdc: PublicKey;
|
|
231
|
+
poolState: PublicKey;
|
|
232
|
+
poolProgram: PublicKey;
|
|
233
|
+
oracleProgram: PublicKey;
|
|
234
|
+
marketOracle: PublicKey;
|
|
235
|
+
vaultAuthority: PublicKey;
|
|
236
|
+
engineAuth: PublicKey;
|
|
237
|
+
referralConfig: PublicKey;
|
|
238
|
+
referralCodeAccount: PublicKey;
|
|
239
|
+
traderReferral: PublicKey;
|
|
240
|
+
affiliate: PublicKey;
|
|
241
|
+
affiliateReward: PublicKey | null;
|
|
242
|
+
}, primaryFeedAccount: PublicKey, secondaryFeedAccount: PublicKey, feeSettings: PublicKey, enqueueAccounts?: {
|
|
243
|
+
queueEntry: PublicKey;
|
|
244
|
+
userClaims: PublicKey;
|
|
245
|
+
} | null): Promise<TransactionInstruction>;
|
|
246
|
+
configureReferralTiersIx(accounts: {
|
|
247
|
+
referralConfig: PublicKey;
|
|
248
|
+
admin: PublicKey;
|
|
249
|
+
}, args: {
|
|
250
|
+
tiers: [ReferralTier, ReferralTier, ReferralTier, ReferralTier];
|
|
251
|
+
}): Promise<TransactionInstruction>;
|
|
252
|
+
setReferralTierIx(accounts: {
|
|
253
|
+
referralConfig: PublicKey;
|
|
254
|
+
referralCode: PublicKey;
|
|
255
|
+
admin: PublicKey;
|
|
256
|
+
}, args: {
|
|
257
|
+
tier: number;
|
|
258
|
+
}): Promise<TransactionInstruction>;
|
|
259
|
+
createReferralCodeIx(accounts: {
|
|
260
|
+
referralCode: PublicKey;
|
|
261
|
+
affiliate: PublicKey;
|
|
262
|
+
}, args: {
|
|
263
|
+
code: Uint8Array;
|
|
264
|
+
}): Promise<TransactionInstruction>;
|
|
265
|
+
setTraderReferralIx(accounts: {
|
|
266
|
+
referralCode: PublicKey;
|
|
267
|
+
traderReferral: PublicKey;
|
|
268
|
+
trader: PublicKey;
|
|
269
|
+
}, args: {
|
|
270
|
+
code: Uint8Array;
|
|
271
|
+
}): Promise<TransactionInstruction>;
|
|
272
|
+
claimAffiliateRewardIx(accounts: {
|
|
273
|
+
affiliateReward: PublicKey;
|
|
274
|
+
marketState: PublicKey;
|
|
275
|
+
affiliate: PublicKey;
|
|
276
|
+
affiliateUsdc: PublicKey;
|
|
277
|
+
vaultUsdc: PublicKey;
|
|
278
|
+
vaultAuthority: PublicKey;
|
|
279
|
+
engineAuth: PublicKey;
|
|
280
|
+
}): Promise<TransactionInstruction>;
|
|
281
|
+
getProtocolConfig(): Promise<ProtocolConfig>;
|
|
282
|
+
getHaltMode(): Promise<HaltMode>;
|
|
283
|
+
}
|