flash-sdk 1.0.130 → 1.0.132
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/PerpetualsClient.d.ts +4 -5
- package/dist/PerpetualsClient.js +82 -112
- package/dist/PoolAccount.d.ts +1 -7
- package/dist/PoolAccount.js +0 -89
- package/dist/PoolConfig.d.ts +3 -2
- package/dist/PoolConfig.js +4 -3
- package/dist/PoolConfig.json +52 -47
- package/dist/backupOracle.js +1 -1
- package/dist/idl/perpetuals.d.ts +50 -0
- package/dist/idl/perpetuals.js +50 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -25,7 +25,6 @@ export declare class PerpetualsClient {
|
|
25
25
|
admin: PublicKey;
|
26
26
|
programId: PublicKey;
|
27
27
|
composabilityProgramId: PublicKey;
|
28
|
-
poolConfig: PoolConfig;
|
29
28
|
multisig: {
|
30
29
|
publicKey: PublicKey;
|
31
30
|
bump: number;
|
@@ -46,7 +45,7 @@ export declare class PerpetualsClient {
|
|
46
45
|
private postSendTxCallback?;
|
47
46
|
private prioritizationFee;
|
48
47
|
private txConfirmationCommitment;
|
49
|
-
constructor(provider: AnchorProvider,
|
48
|
+
constructor(provider: AnchorProvider, programId: PublicKey, composabilityProgramId: PublicKey, opts: PerpClientOptions);
|
50
49
|
setPrioritizationFee: (fee: number) => void;
|
51
50
|
loadAddressLookupTable: (poolConfig: PoolConfig) => Promise<void>;
|
52
51
|
findProgramAddress: (label: string, extraSeeds?: any) => {
|
@@ -2178,10 +2177,9 @@ export declare class PerpetualsClient {
|
|
2178
2177
|
addCustody: (poolName: string, tokenMint: PublicKey, isStable: boolean, isVirtual: boolean, oracle: OracleParams, pricing: PricingParams, permissions: Permissions, fees: Fees, borrowRate: BorrowRateParams, ratios: TokenRatios[]) => Promise<void>;
|
2179
2178
|
editCustody: (poolName: string, tokenMint: PublicKey, isStable: boolean, oracle: OracleParams, pricing: PricingParams, permissions: Permissions, fees: Fees, borrowRate: BorrowRateParams, ratios: TokenRatios[]) => Promise<void>;
|
2180
2179
|
removeCustody: (poolName: string, tokenMint: PublicKey, ratios: TokenRatios[]) => Promise<void>;
|
2181
|
-
|
2182
|
-
getLiquidationState: (wallet: PublicKey, poolName: string, tokenMint: PublicKey, collateralMint: PublicKey, side: PositionSide) => Promise<any>;
|
2180
|
+
getLiquidationState: (wallet: PublicKey, poolName: string, tokenMint: PublicKey, collateralMint: PublicKey, side: PositionSide, poolConfig: PoolConfig) => Promise<any>;
|
2183
2181
|
validateCollectivePnl: (marketSymbol: string, collateralSymbol: string, poolConfig: PoolConfig, poolName: string, side: Side) => Promise<void>;
|
2184
|
-
liquidate: (wallet: PublicKey,
|
2182
|
+
liquidate: (wallet: PublicKey, poolConfig: PoolConfig, tokenMint: PublicKey, collateralMint: PublicKey, side: PositionSide, receivingAccount: PublicKey, rewardsReceivingAccount: PublicKey) => Promise<string>;
|
2185
2183
|
getOraclePriceView: (poolName: string, tokenMint: PublicKey, ema: boolean) => Promise<any>;
|
2186
2184
|
getAddLiquidityAmountAndFeeView: (poolName: string, tokenMint: PublicKey, amount: BN) => Promise<any>;
|
2187
2185
|
getRemoveLiquidityAmountAndFeeView: (poolName: string, tokenMint: PublicKey, lpAmount: BN) => Promise<any>;
|
@@ -2209,6 +2207,7 @@ export declare class PerpetualsClient {
|
|
2209
2207
|
getLeverageAtAmountEntryWithSwapSync: (positionAccount: PositionAccount | null, inputDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, poolAccount: PoolAccount, inputTokenPrice: OraclePrice, inputTokenEmaPrice: OraclePrice, inputTokenCustodyAccount: CustodyAccount, collateralTokenPrice: OraclePrice, collateralTokenEmaPrice: OraclePrice, collateralTokenCustodyAccount: CustodyAccount, marketTokenPrice: OraclePrice, marketTokenEmaPrice: OraclePrice, marketTokenCustodyAccount: CustodyAccount, poolAumUsdMax: BN, poolConfig: PoolConfig, pnlUsd: BN) => BN;
|
2210
2208
|
getEntryPriceAndFeeSync: (positionAccount: PositionAccount | null, collateralDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, marketCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN) => EntryPriceAndFee;
|
2211
2209
|
getEntryPriceSync: (side: Side, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, marketCustodyAccount: CustodyAccount) => BN;
|
2210
|
+
getPriceAfterSlippage(isEntry: boolean, slippageBps: BN, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, side: Side, custody: CustodyAccount): BN;
|
2212
2211
|
getExitPriceAndFeeSync: (positionAccount: PositionAccount, collateralDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, marketCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN) => ExitPriceAndFee;
|
2213
2212
|
getExitPriceSync: (side: Side, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, marketCustodyAccount: CustodyAccount) => BN;
|
2214
2213
|
getSizeAmountFromLeverageAndCollateral: (collateralAmtWithFee: BN, leverage: string, marketToken: Token, collateralToken: Token, side: Side, marketPrice: OraclePrice, marketEmaPrice: OraclePrice, marketCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount) => BN;
|
package/dist/PerpetualsClient.js
CHANGED
@@ -10,29 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
10
10
|
};
|
11
11
|
return __assign.apply(this, arguments);
|
12
12
|
};
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
14
|
-
if (k2 === undefined) k2 = k;
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
18
|
-
}
|
19
|
-
Object.defineProperty(o, k2, desc);
|
20
|
-
}) : (function(o, m, k, k2) {
|
21
|
-
if (k2 === undefined) k2 = k;
|
22
|
-
o[k2] = m[k];
|
23
|
-
}));
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
26
|
-
}) : function(o, v) {
|
27
|
-
o["default"] = v;
|
28
|
-
});
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
30
|
-
if (mod && mod.__esModule) return mod;
|
31
|
-
var result = {};
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
33
|
-
__setModuleDefault(result, mod);
|
34
|
-
return result;
|
35
|
-
};
|
36
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
37
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
38
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -97,11 +74,8 @@ var rpc_1 = require("./utils/rpc");
|
|
97
74
|
var utils_1 = require("./utils");
|
98
75
|
var constants_1 = require("./constants");
|
99
76
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
100
|
-
var backupOracle_1 = require("./backupOracle");
|
101
|
-
var bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
102
|
-
var nacl = __importStar(require("tweetnacl"));
|
103
77
|
var PerpetualsClient = (function () {
|
104
|
-
function PerpetualsClient(provider,
|
78
|
+
function PerpetualsClient(provider, programId, composabilityProgramId, opts) {
|
105
79
|
var _this = this;
|
106
80
|
var _a;
|
107
81
|
this.addressLookupTables = [];
|
@@ -595,45 +569,7 @@ var PerpetualsClient = (function () {
|
|
595
569
|
}
|
596
570
|
});
|
597
571
|
}); };
|
598
|
-
this.
|
599
|
-
var pythPriceIds, currentPrices, backupOracleAccount, caches_1, permissionlessPythCache, message, signature, preInstruction;
|
600
|
-
return __generator(this, function (_a) {
|
601
|
-
switch (_a.label) {
|
602
|
-
case 0:
|
603
|
-
pythPriceIds = poolConfig.custodies.map(function (f) { return f.pythPriceId; });
|
604
|
-
return [4, backupOracle_1.pythPriceServiceConnection.getLatestPriceFeeds(pythPriceIds)];
|
605
|
-
case 1:
|
606
|
-
currentPrices = _a.sent();
|
607
|
-
backupOracleAccount = web3_js_1.Keypair.fromSecretKey(bytes_1.bs58.decode(backupOracleSecretKey));
|
608
|
-
if (pythPriceIds.length === currentPrices.length) {
|
609
|
-
caches_1 = currentPrices.map(function (price) {
|
610
|
-
var uncheckedPrice = price.getPriceUnchecked();
|
611
|
-
var uncheckedEmaPrice = price.getEmaPriceUnchecked();
|
612
|
-
return {
|
613
|
-
price: new anchor_1.BN(uncheckedPrice.price),
|
614
|
-
expo: uncheckedPrice.expo,
|
615
|
-
conf: new anchor_1.BN(uncheckedPrice.conf),
|
616
|
-
ema: new anchor_1.BN(uncheckedEmaPrice.price),
|
617
|
-
publishTime: new anchor_1.BN(uncheckedPrice.publishTime)
|
618
|
-
};
|
619
|
-
});
|
620
|
-
permissionlessPythCache = {
|
621
|
-
backupCache: caches_1
|
622
|
-
};
|
623
|
-
message = this.program._coder.types.encode('PermissionlessPythCache', permissionlessPythCache);
|
624
|
-
signature = nacl.sign.detached(message, backupOracleAccount.secretKey);
|
625
|
-
preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
626
|
-
publicKey: backupOracleAccount.publicKey.toBytes(),
|
627
|
-
message: message,
|
628
|
-
signature: signature,
|
629
|
-
});
|
630
|
-
return [2, preInstruction];
|
631
|
-
}
|
632
|
-
return [2];
|
633
|
-
}
|
634
|
-
});
|
635
|
-
}); };
|
636
|
-
this.getLiquidationState = function (wallet, poolName, tokenMint, collateralMint, side) { return __awaiter(_this, void 0, void 0, function () {
|
572
|
+
this.getLiquidationState = function (wallet, poolName, tokenMint, collateralMint, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
637
573
|
var _a, _b;
|
638
574
|
var _c;
|
639
575
|
return __generator(this, function (_d) {
|
@@ -651,9 +587,9 @@ var PerpetualsClient = (function () {
|
|
651
587
|
return [4, this.getCustodyOracleAccountKey(poolName, tokenMint)];
|
652
588
|
case 1:
|
653
589
|
_c.custodyOracleAccount = _d.sent(),
|
654
|
-
_c.custodyCustomOracleAccount =
|
590
|
+
_c.custodyCustomOracleAccount = poolConfig.backupOracle,
|
655
591
|
_c.collateralCustody = this.getCustodyKey(poolName, collateralMint),
|
656
|
-
_c.collateralCustodyCustomOracleAccount =
|
592
|
+
_c.collateralCustodyCustomOracleAccount = poolConfig.backupOracle;
|
657
593
|
return [4, this.getCustodyOracleAccountKey(poolName, collateralMint)];
|
658
594
|
case 2: return [4, _b.apply(_a, [(_c.collateralCustodyOracleAccount = _d.sent(),
|
659
595
|
_c.ixSysvar = web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
@@ -681,10 +617,10 @@ var PerpetualsClient = (function () {
|
|
681
617
|
pool: this.getPoolKey(poolName),
|
682
618
|
custody: marketCustodyConfig.custodyAccount,
|
683
619
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
684
|
-
custodyCustomOracleAccount:
|
620
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
685
621
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
686
622
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
687
|
-
collateralCustodyCustomOracleAccount:
|
623
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
688
624
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
689
625
|
})
|
690
626
|
.remainingAccounts([])
|
@@ -699,12 +635,13 @@ var PerpetualsClient = (function () {
|
|
699
635
|
}
|
700
636
|
});
|
701
637
|
}); };
|
702
|
-
this.liquidate = function (wallet,
|
703
|
-
var _a, _b;
|
638
|
+
this.liquidate = function (wallet, poolConfig, tokenMint, collateralMint, side, receivingAccount, rewardsReceivingAccount) { return __awaiter(_this, void 0, void 0, function () {
|
639
|
+
var poolName, _a, _b;
|
704
640
|
var _c;
|
705
641
|
return __generator(this, function (_d) {
|
706
642
|
switch (_d.label) {
|
707
643
|
case 0:
|
644
|
+
poolName = poolConfig.poolName;
|
708
645
|
_b = (_a = this.program.methods
|
709
646
|
.liquidate({}))
|
710
647
|
.accounts;
|
@@ -725,8 +662,8 @@ var PerpetualsClient = (function () {
|
|
725
662
|
return [4, this.getCustodyOracleAccountKey(poolName, collateralMint)];
|
726
663
|
case 2: return [4, _b.apply(_a, [(_c.collateralCustodyOracleAccount = _d.sent(),
|
727
664
|
_c.collateralCustodyTokenAccount = this.getCustodyTokenAccountKey(poolName, collateralMint),
|
728
|
-
_c.collateralCustodyCustomOracleAccount =
|
729
|
-
_c.custodyCustomOracleAccount =
|
665
|
+
_c.collateralCustodyCustomOracleAccount = poolConfig.backupOracle,
|
666
|
+
_c.custodyCustomOracleAccount = poolConfig.backupOracle,
|
730
667
|
_c.eventAuthority = this.eventAuthority.publicKey,
|
731
668
|
_c.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
|
732
669
|
_c.program = this.program.programId,
|
@@ -1868,10 +1805,10 @@ var PerpetualsClient = (function () {
|
|
1868
1805
|
position: positionAccount,
|
1869
1806
|
custody: marketCustodyConfig.custodyAccount,
|
1870
1807
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
1871
|
-
custodyCustomOracleAccount:
|
1808
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
1872
1809
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
1873
1810
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
1874
|
-
collateralCustodyCustomOracleAccount:
|
1811
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
1875
1812
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
1876
1813
|
eventAuthority: this.eventAuthority.publicKey,
|
1877
1814
|
systemProgram: web3_js_1.SystemProgram.programId,
|
@@ -1984,7 +1921,7 @@ var PerpetualsClient = (function () {
|
|
1984
1921
|
isWritable: false,
|
1985
1922
|
});
|
1986
1923
|
custodyCustomOracles.push({
|
1987
|
-
pubkey:
|
1924
|
+
pubkey: poolConfig.backupOracle,
|
1988
1925
|
isSigner: false,
|
1989
1926
|
isWritable: false,
|
1990
1927
|
});
|
@@ -2020,16 +1957,16 @@ var PerpetualsClient = (function () {
|
|
2020
1957
|
pool: poolConfig.poolAddress,
|
2021
1958
|
receivingCustody: inputCustodyConfig.custodyAccount,
|
2022
1959
|
receivingCustodyOracleAccount: inputCustodyConfig.oracleAddress,
|
2023
|
-
receivingCustodyCustomOracleAccount:
|
1960
|
+
receivingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2024
1961
|
receivingCustodyTokenAccount: inputCustodyConfig.tokenAccount,
|
2025
1962
|
dispensingCustody: collateralCustodyConfig.custodyAccount,
|
2026
1963
|
dispensingCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2027
|
-
dispensingCustodyCustomOracleAccount:
|
1964
|
+
dispensingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2028
1965
|
dispensingCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2029
1966
|
position: positionAccount,
|
2030
1967
|
custody: marketCustodyConfig.custodyAccount,
|
2031
1968
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2032
|
-
custodyCustomOracleAccount:
|
1969
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2033
1970
|
eventAuthority: this.eventAuthority.publicKey,
|
2034
1971
|
systemProgram: web3_js_1.SystemProgram.programId,
|
2035
1972
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
@@ -2124,10 +2061,10 @@ var PerpetualsClient = (function () {
|
|
2124
2061
|
position: positionAccount,
|
2125
2062
|
custody: marketCustodyConfig.custodyAccount,
|
2126
2063
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2127
|
-
custodyCustomOracleAccount:
|
2064
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2128
2065
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
2129
2066
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2130
|
-
collateralCustodyCustomOracleAccount:
|
2067
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2131
2068
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2132
2069
|
eventAuthority: this.eventAuthority.publicKey,
|
2133
2070
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
@@ -2230,7 +2167,7 @@ var PerpetualsClient = (function () {
|
|
2230
2167
|
isWritable: false,
|
2231
2168
|
});
|
2232
2169
|
custodyCustomOracles.push({
|
2233
|
-
pubkey:
|
2170
|
+
pubkey: poolConfig.backupOracle,
|
2234
2171
|
isSigner: false,
|
2235
2172
|
isWritable: false,
|
2236
2173
|
});
|
@@ -2263,16 +2200,16 @@ var PerpetualsClient = (function () {
|
|
2263
2200
|
pool: poolConfig.poolAddress,
|
2264
2201
|
receivingCustody: collateralCustodyConfig.custodyAccount,
|
2265
2202
|
receivingCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2266
|
-
receivingCustodyCustomOracleAccount:
|
2203
|
+
receivingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2267
2204
|
receivingCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2268
2205
|
dispensingCustody: outputCustodyConfig.custodyAccount,
|
2269
2206
|
dispensingCustodyOracleAccount: outputCustodyConfig.oracleAddress,
|
2270
|
-
dispensingCustodyCustomOracleAccount:
|
2207
|
+
dispensingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2271
2208
|
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
2272
2209
|
position: positionAccount,
|
2273
2210
|
custody: marketCustodyConfig.custodyAccount,
|
2274
2211
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2275
|
-
custodyCustomOracleAccount:
|
2212
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2276
2213
|
eventAuthority: this.eventAuthority.publicKey,
|
2277
2214
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2278
2215
|
perpProgram: this.programId,
|
@@ -2450,7 +2387,7 @@ var PerpetualsClient = (function () {
|
|
2450
2387
|
isWritable: false,
|
2451
2388
|
});
|
2452
2389
|
custodyCustomOracles.push({
|
2453
|
-
pubkey:
|
2390
|
+
pubkey: poolConfig.backupOracle,
|
2454
2391
|
isSigner: false,
|
2455
2392
|
isWritable: false,
|
2456
2393
|
});
|
@@ -2484,11 +2421,11 @@ var PerpetualsClient = (function () {
|
|
2484
2421
|
pool: poolConfig.poolAddress,
|
2485
2422
|
receivingCustody: userInputCustodyConfig.custodyAccount,
|
2486
2423
|
receivingCustodyOracleAccount: userInputCustodyConfig.oracleAddress,
|
2487
|
-
receivingCustodyCustomOracleAccount:
|
2424
|
+
receivingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2488
2425
|
receivingCustodyTokenAccount: userInputCustodyConfig.tokenAccount,
|
2489
2426
|
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
2490
2427
|
dispensingCustodyOracleAccount: userOutputCustodyConfig.oracleAddress,
|
2491
|
-
dispensingCustodyCustomOracleAccount:
|
2428
|
+
dispensingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2492
2429
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
2493
2430
|
eventAuthority: this.eventAuthority.publicKey,
|
2494
2431
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
@@ -2595,10 +2532,10 @@ var PerpetualsClient = (function () {
|
|
2595
2532
|
pool: poolConfig.poolAddress,
|
2596
2533
|
custody: marketCustodyConfig.custodyAccount,
|
2597
2534
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2598
|
-
custodyCustomOracleAccount:
|
2535
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2599
2536
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
2600
2537
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2601
|
-
collateralCustodyCustomOracleAccount:
|
2538
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2602
2539
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2603
2540
|
eventAuthority: this.eventAuthority.publicKey,
|
2604
2541
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
@@ -2708,7 +2645,7 @@ var PerpetualsClient = (function () {
|
|
2708
2645
|
isWritable: false,
|
2709
2646
|
});
|
2710
2647
|
custodyCustomOracles.push({
|
2711
|
-
pubkey:
|
2648
|
+
pubkey: poolConfig.backupOracle,
|
2712
2649
|
isSigner: false,
|
2713
2650
|
isWritable: false,
|
2714
2651
|
});
|
@@ -2740,15 +2677,15 @@ var PerpetualsClient = (function () {
|
|
2740
2677
|
pool: poolConfig.poolAddress,
|
2741
2678
|
receivingCustody: inputCustodyConfig.custodyAccount,
|
2742
2679
|
receivingCustodyOracleAccount: inputCustodyConfig.oracleAddress,
|
2743
|
-
receivingCustodyCustomOracleAccount:
|
2680
|
+
receivingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2744
2681
|
receivingCustodyTokenAccount: inputCustodyConfig.tokenAccount,
|
2745
2682
|
dispensingCustody: collateralCustodyConfig.custodyAccount,
|
2746
2683
|
dispensingCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2747
|
-
dispensingCustodyCustomOracleAccount:
|
2684
|
+
dispensingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2748
2685
|
dispensingCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2749
2686
|
custody: marketCustodyConfig.custodyAccount,
|
2750
2687
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2751
|
-
custodyCustomOracleAccount:
|
2688
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2752
2689
|
eventAuthority: this.eventAuthority.publicKey,
|
2753
2690
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2754
2691
|
perpProgram: this.programId,
|
@@ -2842,10 +2779,10 @@ var PerpetualsClient = (function () {
|
|
2842
2779
|
position: positionPubKey,
|
2843
2780
|
custody: marketCustodyConfig.custodyAccount,
|
2844
2781
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2845
|
-
custodyCustomOracleAccount:
|
2782
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2846
2783
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
2847
2784
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2848
|
-
collateralCustodyCustomOracleAccount:
|
2785
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2849
2786
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2850
2787
|
eventAuthority: this.eventAuthority.publicKey,
|
2851
2788
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
@@ -2949,7 +2886,7 @@ var PerpetualsClient = (function () {
|
|
2949
2886
|
isWritable: false,
|
2950
2887
|
});
|
2951
2888
|
custodyCustomOracles.push({
|
2952
|
-
pubkey:
|
2889
|
+
pubkey: poolConfig.backupOracle,
|
2953
2890
|
isSigner: false,
|
2954
2891
|
isWritable: false,
|
2955
2892
|
});
|
@@ -2982,16 +2919,16 @@ var PerpetualsClient = (function () {
|
|
2982
2919
|
pool: poolConfig.poolAddress,
|
2983
2920
|
receivingCustody: collateralCustodyConfig.custodyAccount,
|
2984
2921
|
receivingCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
2985
|
-
receivingCustodyCustomOracleAccount:
|
2922
|
+
receivingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2986
2923
|
receivingCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2987
2924
|
dispensingCustody: outputCustodyConfig.custodyAccount,
|
2988
2925
|
dispensingCustodyOracleAccount: outputCustodyConfig.oracleAddress,
|
2989
|
-
dispensingCustodyCustomOracleAccount:
|
2926
|
+
dispensingCustodyCustomOracleAccount: poolConfig.backupOracle,
|
2990
2927
|
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
2991
2928
|
position: positionAccount,
|
2992
2929
|
custody: marketCustodyConfig.custodyAccount,
|
2993
2930
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
2994
|
-
custodyCustomOracleAccount:
|
2931
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
2995
2932
|
eventAuthority: this.eventAuthority.publicKey,
|
2996
2933
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2997
2934
|
perpProgram: this.programId,
|
@@ -3041,10 +2978,10 @@ var PerpetualsClient = (function () {
|
|
3041
2978
|
position: positionPubKey,
|
3042
2979
|
custody: marketCustodyConfig.custodyAccount,
|
3043
2980
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
3044
|
-
custodyCustomOracleAccount:
|
2981
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
3045
2982
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3046
2983
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
3047
|
-
collateralCustodyCustomOracleAccount:
|
2984
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
3048
2985
|
eventAuthority: this.eventAuthority.publicKey,
|
3049
2986
|
program: this.programId,
|
3050
2987
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
@@ -3093,10 +3030,10 @@ var PerpetualsClient = (function () {
|
|
3093
3030
|
position: positionPubKey,
|
3094
3031
|
custody: marketCustodyConfig.custodyAccount,
|
3095
3032
|
custodyOracleAccount: marketCustodyConfig.oracleAddress,
|
3096
|
-
custodyCustomOracleAccount:
|
3033
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
3097
3034
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3098
3035
|
collateralCustodyOracleAccount: collateralCustodyConfig.oracleAddress,
|
3099
|
-
collateralCustodyCustomOracleAccount:
|
3036
|
+
collateralCustodyCustomOracleAccount: poolConfig.backupOracle,
|
3100
3037
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3101
3038
|
eventAuthority: this.eventAuthority.publicKey,
|
3102
3039
|
program: this.programId,
|
@@ -3154,7 +3091,7 @@ var PerpetualsClient = (function () {
|
|
3154
3091
|
isWritable: false,
|
3155
3092
|
});
|
3156
3093
|
custodyCustomOracles.push({
|
3157
|
-
pubkey:
|
3094
|
+
pubkey: poolConfig.backupOracle,
|
3158
3095
|
isSigner: false,
|
3159
3096
|
isWritable: false,
|
3160
3097
|
});
|
@@ -3236,7 +3173,7 @@ var PerpetualsClient = (function () {
|
|
3236
3173
|
pool: poolConfig.poolAddress,
|
3237
3174
|
custody: payTokenCustodyConfig.custodyAccount,
|
3238
3175
|
custodyOracleAccount: payTokenCustodyConfig.oracleAddress,
|
3239
|
-
custodyCustomOracleAccount:
|
3176
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
3240
3177
|
custodyTokenAccount: payTokenCustodyConfig.tokenAccount,
|
3241
3178
|
lpTokenMint: poolConfig.lpTokenMint,
|
3242
3179
|
eventAuthority: this.eventAuthority.publicKey,
|
@@ -3301,7 +3238,7 @@ var PerpetualsClient = (function () {
|
|
3301
3238
|
isWritable: false,
|
3302
3239
|
});
|
3303
3240
|
custodyCustomOracles.push({
|
3304
|
-
pubkey:
|
3241
|
+
pubkey: poolConfig.backupOracle,
|
3305
3242
|
isSigner: false,
|
3306
3243
|
isWritable: false,
|
3307
3244
|
});
|
@@ -3370,7 +3307,7 @@ var PerpetualsClient = (function () {
|
|
3370
3307
|
pool: poolConfig.poolAddress,
|
3371
3308
|
custody: recieveTokenCustodyConfig.custodyAccount,
|
3372
3309
|
custodyOracleAccount: recieveTokenCustodyConfig.oracleAddress,
|
3373
|
-
custodyCustomOracleAccount:
|
3310
|
+
custodyCustomOracleAccount: poolConfig.backupOracle,
|
3374
3311
|
custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
|
3375
3312
|
lpTokenMint: poolConfig.lpTokenMint,
|
3376
3313
|
eventAuthority: this.eventAuthority.publicKey,
|
@@ -3405,10 +3342,9 @@ var PerpetualsClient = (function () {
|
|
3405
3342
|
};
|
3406
3343
|
this.provider = provider;
|
3407
3344
|
(0, anchor_1.setProvider)(provider);
|
3408
|
-
this.program = new anchor_1.Program(perpetuals_1.IDL,
|
3345
|
+
this.program = new anchor_1.Program(perpetuals_1.IDL, programId);
|
3409
3346
|
this.programPerpComposability = new anchor_1.Program(perp_composability_1.IDL, composabilityProgramId);
|
3410
|
-
this.
|
3411
|
-
this.programId = poolConfig.programId;
|
3347
|
+
this.programId = programId;
|
3412
3348
|
this.composabilityProgramId = composabilityProgramId;
|
3413
3349
|
this.admin = this.provider.wallet.publicKey;
|
3414
3350
|
this.multisig = this.findProgramAddress("multisig");
|
@@ -3447,6 +3383,40 @@ var PerpetualsClient = (function () {
|
|
3447
3383
|
}
|
3448
3384
|
return newRatio;
|
3449
3385
|
};
|
3386
|
+
PerpetualsClient.prototype.getPriceAfterSlippage = function (isEntry, slippageBps, marketPrice, marketEmaPrice, side, custody) {
|
3387
|
+
if (isEntry) {
|
3388
|
+
var current_price = this.getEntryPriceSync(side, marketPrice, marketEmaPrice, custody);
|
3389
|
+
var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
|
3390
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
3391
|
+
return current_price.add(spread_i);
|
3392
|
+
}
|
3393
|
+
else {
|
3394
|
+
if (spread_i.lt(current_price)) {
|
3395
|
+
return current_price.sub(spread_i);
|
3396
|
+
}
|
3397
|
+
else {
|
3398
|
+
return constants_1.BN_ZERO;
|
3399
|
+
}
|
3400
|
+
;
|
3401
|
+
}
|
3402
|
+
}
|
3403
|
+
else {
|
3404
|
+
var current_price = this.getExitPriceSync(side, marketPrice, marketEmaPrice, custody);
|
3405
|
+
var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
|
3406
|
+
if ((0, types_1.isVariant)(side, 'long')) {
|
3407
|
+
if (spread_i.lt(current_price)) {
|
3408
|
+
return current_price.sub(spread_i);
|
3409
|
+
}
|
3410
|
+
else {
|
3411
|
+
return constants_1.BN_ZERO;
|
3412
|
+
}
|
3413
|
+
;
|
3414
|
+
}
|
3415
|
+
else {
|
3416
|
+
return current_price.add(spread_i);
|
3417
|
+
}
|
3418
|
+
}
|
3419
|
+
};
|
3450
3420
|
PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
|
3451
3421
|
if (opts === void 0) { opts = {}; }
|
3452
3422
|
return __awaiter(this, void 0, void 0, function () {
|
package/dist/PoolAccount.d.ts
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
/// <reference types="bn.js" />
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
3
|
-
import { Pool,
|
3
|
+
import { Pool, TokenRatios } from "./types";
|
4
4
|
import { PublicKey } from "@solana/web3.js";
|
5
|
-
import { CustodyAccount } from "./CustodyAccount";
|
6
|
-
import { OraclePrice } from "./OraclePrice";
|
7
5
|
export declare class PoolAccount implements Pool {
|
8
6
|
publicKey: PublicKey;
|
9
7
|
name: string;
|
@@ -17,8 +15,4 @@ export declare class PoolAccount implements Pool {
|
|
17
15
|
static from(publicKey: PublicKey, parseData: Pool): PoolAccount;
|
18
16
|
updatePoolData(parseData: Pool): void;
|
19
17
|
getTokenId(custodyKey: PublicKey): number;
|
20
|
-
static getPriceAfterSlippage(isEntry: boolean, slippageBps: BN, token_price: OraclePrice, token_ema_price: OraclePrice, side: Side, custody: CustodyAccount): BN;
|
21
|
-
static getPrice(token_price: OraclePrice, token_ema_price: OraclePrice, side: Side, spread: BN): OraclePrice;
|
22
|
-
static getEntryPrice(token_price: OraclePrice, token_ema_price: OraclePrice, side: Side, custody: CustodyAccount): BN;
|
23
|
-
static getExitPrice(token_price: OraclePrice, token_ema_price: OraclePrice, side: Side, custody: CustodyAccount): BN;
|
24
18
|
}
|
package/dist/PoolAccount.js
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.PoolAccount = void 0;
|
4
|
-
var constants_1 = require("./constants");
|
5
|
-
var anchor_1 = require("@coral-xyz/anchor");
|
6
|
-
var types_1 = require("./types");
|
7
|
-
var OraclePrice_1 = require("./OraclePrice");
|
8
|
-
var utils_1 = require("./utils");
|
9
4
|
var PoolAccount = (function () {
|
10
5
|
function PoolAccount(publicKey, parseData) {
|
11
6
|
this.publicKey = publicKey;
|
@@ -20,90 +15,6 @@ var PoolAccount = (function () {
|
|
20
15
|
PoolAccount.prototype.getTokenId = function (custodyKey) {
|
21
16
|
return this.custodies.findIndex(function (i) { return i.toBase58() == custodyKey.toBase58(); });
|
22
17
|
};
|
23
|
-
PoolAccount.getPriceAfterSlippage = function (isEntry, slippageBps, token_price, token_ema_price, side, custody) {
|
24
|
-
if (isEntry) {
|
25
|
-
var current_price = this.getEntryPrice(token_price, token_ema_price, side, custody);
|
26
|
-
var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
|
27
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
28
|
-
return current_price.add(spread_i);
|
29
|
-
}
|
30
|
-
else {
|
31
|
-
if (spread_i.lt(current_price)) {
|
32
|
-
return current_price.sub(spread_i);
|
33
|
-
}
|
34
|
-
else {
|
35
|
-
return constants_1.BN_ZERO;
|
36
|
-
}
|
37
|
-
;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
else {
|
41
|
-
var current_price = this.getExitPrice(token_price, token_ema_price, side, custody);
|
42
|
-
var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
|
43
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
44
|
-
if (spread_i.lt(current_price)) {
|
45
|
-
return current_price.sub(spread_i);
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
return constants_1.BN_ZERO;
|
49
|
-
}
|
50
|
-
;
|
51
|
-
}
|
52
|
-
else {
|
53
|
-
return current_price.add(spread_i);
|
54
|
-
}
|
55
|
-
}
|
56
|
-
};
|
57
|
-
PoolAccount.getPrice = function (token_price, token_ema_price, side, spread) {
|
58
|
-
if ((0, types_1.isVariant)(side, 'long')) {
|
59
|
-
var max_price = void 0;
|
60
|
-
if (token_price.cmp(token_ema_price)) {
|
61
|
-
max_price = token_price;
|
62
|
-
}
|
63
|
-
else {
|
64
|
-
max_price = token_ema_price;
|
65
|
-
}
|
66
|
-
;
|
67
|
-
var spread_i = (0, utils_1.checkedDecimalCeilMul)(max_price.price, max_price.exponent, spread, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), max_price.exponent);
|
68
|
-
return new OraclePrice_1.OraclePrice({
|
69
|
-
price: max_price.price.add(spread_i),
|
70
|
-
exponent: max_price.exponent,
|
71
|
-
confidence: constants_1.BN_ZERO,
|
72
|
-
});
|
73
|
-
}
|
74
|
-
else {
|
75
|
-
var min_price = void 0;
|
76
|
-
if (token_price.cmp(token_ema_price)) {
|
77
|
-
min_price = token_ema_price;
|
78
|
-
}
|
79
|
-
else {
|
80
|
-
min_price = token_price;
|
81
|
-
}
|
82
|
-
;
|
83
|
-
var spread_i = (0, utils_1.checkedDecimalMul)(min_price.price, min_price.exponent, spread, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), min_price.exponent);
|
84
|
-
var price = void 0;
|
85
|
-
if (spread_i.lt(min_price.price)) {
|
86
|
-
price = min_price.price.sub(spread_i);
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
price = constants_1.BN_ZERO;
|
90
|
-
}
|
91
|
-
;
|
92
|
-
return new OraclePrice_1.OraclePrice({
|
93
|
-
price: price,
|
94
|
-
exponent: min_price.exponent,
|
95
|
-
confidence: constants_1.BN_ZERO,
|
96
|
-
});
|
97
|
-
}
|
98
|
-
};
|
99
|
-
PoolAccount.getEntryPrice = function (token_price, token_ema_price, side, custody) {
|
100
|
-
var price = PoolAccount.getPrice(token_price, token_ema_price, ((0, types_1.isVariant)(side, 'long')) ? types_1.Side.Long : types_1.Side.Short, ((0, types_1.isVariant)(side, 'long')) ? custody.pricing.tradeSpreadLong : custody.pricing.tradeSpreadShort);
|
101
|
-
return price.scale_to_exponent(new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS)).price;
|
102
|
-
};
|
103
|
-
PoolAccount.getExitPrice = function (token_price, token_ema_price, side, custody) {
|
104
|
-
var price = PoolAccount.getPrice(token_price, token_ema_price, ((0, types_1.isVariant)(side, 'long')) ? types_1.Side.Short : types_1.Side.Long, ((0, types_1.isVariant)(side, 'long')) ? custody.pricing.tradeSpreadShort : custody.pricing.tradeSpreadLong);
|
105
|
-
return price.scale_to_exponent(new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS)).price;
|
106
|
-
};
|
107
18
|
return PoolAccount;
|
108
19
|
}());
|
109
20
|
exports.PoolAccount = PoolAccount;
|
package/dist/PoolConfig.d.ts
CHANGED
@@ -10,7 +10,6 @@ export interface CustodyConfig {
|
|
10
10
|
isStable: boolean;
|
11
11
|
isVirtual: boolean;
|
12
12
|
oracleAddress: PublicKey;
|
13
|
-
pythPriceId: string;
|
14
13
|
}
|
15
14
|
export type Token = {
|
16
15
|
symbol: string;
|
@@ -19,6 +18,7 @@ export type Token = {
|
|
19
18
|
isStable: boolean;
|
20
19
|
isVirtual: boolean;
|
21
20
|
pythTicker: string;
|
21
|
+
pythPriceId: string;
|
22
22
|
};
|
23
23
|
export declare class PoolConfig {
|
24
24
|
programId: PublicKey;
|
@@ -27,6 +27,7 @@ export declare class PoolConfig {
|
|
27
27
|
poolAddress: PublicKey;
|
28
28
|
lpTokenMint: PublicKey;
|
29
29
|
lpDecimals: number;
|
30
|
+
lpTokenSymbol: string;
|
30
31
|
perpetuals: PublicKey;
|
31
32
|
transferAuthority: PublicKey;
|
32
33
|
multisig: PublicKey;
|
@@ -34,7 +35,7 @@ export declare class PoolConfig {
|
|
34
35
|
backupOracle: PublicKey;
|
35
36
|
tokens: Token[];
|
36
37
|
custodies: CustodyConfig[];
|
37
|
-
constructor(programId: PublicKey, cluster: Cluster, poolName: string, poolAddress: PublicKey, lpTokenMint: PublicKey, lpDecimals: number, perpetuals: PublicKey, transferAuthority: PublicKey, multisig: PublicKey, addressLookupTableAddresses: PublicKey[], backupOracle: PublicKey, tokens: Token[], custodies: CustodyConfig[]);
|
38
|
+
constructor(programId: PublicKey, cluster: Cluster, poolName: string, poolAddress: PublicKey, lpTokenMint: PublicKey, lpDecimals: number, lpTokenSymbol: string, perpetuals: PublicKey, transferAuthority: PublicKey, multisig: PublicKey, addressLookupTableAddresses: PublicKey[], backupOracle: PublicKey, tokens: Token[], custodies: CustodyConfig[]);
|
38
39
|
getAllTokenMints(): PublicKey[];
|
39
40
|
getNonStableTokens(): PublicKey[];
|
40
41
|
getAllCustodies(): PublicKey[];
|