flash-sdk 1.0.134 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/CustodyAccount.d.ts +6 -8
- package/dist/CustodyAccount.js +0 -21
- package/dist/MarketAccount.d.ts +23 -0
- package/dist/MarketAccount.js +42 -0
- package/dist/OraclePrice.d.ts +2 -0
- package/dist/OraclePrice.js +12 -4
- package/dist/PerpetualsClient.d.ts +1500 -976
- package/dist/PerpetualsClient.js +1410 -825
- package/dist/PoolAccount.d.ts +13 -3
- package/dist/PoolConfig.d.ts +25 -1
- package/dist/PoolConfig.js +61 -18
- package/dist/PoolConfig.json +582 -142
- package/dist/PoolDataClient.d.ts +2 -9
- package/dist/PoolDataClient.js +1 -43
- package/dist/PositionAccount.d.ts +14 -12
- package/dist/TradingAccount.d.ts +20 -0
- package/dist/TradingAccount.js +17 -0
- package/dist/backupOracle.js +16 -3
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +3 -2
- package/dist/idl/perp_composability.d.ts +132 -86
- package/dist/idl/perp_composability.js +132 -86
- package/dist/idl/perpetuals.d.ts +2276 -1102
- package/dist/idl/perpetuals.js +2250 -1076
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +24 -2
- package/dist/types/index.js +23 -12
- package/dist/utils/getNftAccounts.d.ts +7 -0
- package/dist/utils/getNftAccounts.js +28 -0
- package/package.json +1 -1
package/dist/PoolDataClient.d.ts
CHANGED
@@ -5,6 +5,7 @@ import { CustodyAccount } from "./CustodyAccount";
|
|
5
5
|
import { OraclePrice } from "./OraclePrice";
|
6
6
|
import { PoolConfig } from "./PoolConfig";
|
7
7
|
import { PoolAccount } from "./PoolAccount";
|
8
|
+
import { MarketAccount } from "./MarketAccount";
|
8
9
|
export interface LpStats {
|
9
10
|
lpTokenSupply: BN;
|
10
11
|
decimals: number;
|
@@ -37,23 +38,16 @@ export interface CustodyStats {
|
|
37
38
|
minCapacityAmountUi: string;
|
38
39
|
maxCapacityAmountUi: string;
|
39
40
|
}
|
40
|
-
export interface PoolStats {
|
41
|
-
totalFees: BN;
|
42
|
-
totalVolume: BN;
|
43
|
-
currentLongPositionsUsd: BN;
|
44
|
-
currentShortPositionsUsd: BN;
|
45
|
-
}
|
46
41
|
export declare class PoolDataClient {
|
47
42
|
poolConfig: PoolConfig;
|
48
43
|
pool: PoolAccount;
|
49
44
|
lpTokenInfo: Mint;
|
50
45
|
custodies: CustodyAccount[];
|
46
|
+
markets: MarketAccount[];
|
51
47
|
constructor(poolConfig: PoolConfig, pool: PoolAccount, lpTokenInfo: Mint, custodies: CustodyAccount[]);
|
52
48
|
loadCustodies(custodies: CustodyAccount[]): void;
|
53
49
|
loadPoolData(pool: PoolAccount): void;
|
54
50
|
loadLpData(lpTokenInfo: Mint): void;
|
55
|
-
getOiLongUI(): BN;
|
56
|
-
getOiShortUI(): BN;
|
57
51
|
getLpStats(pricesMap: Map<string, {
|
58
52
|
price: OraclePrice;
|
59
53
|
emaPrice: OraclePrice;
|
@@ -62,5 +56,4 @@ export declare class PoolDataClient {
|
|
62
56
|
price: OraclePrice;
|
63
57
|
emaPrice: OraclePrice;
|
64
58
|
}>): CustodyStats[];
|
65
|
-
getPoolStats(): PoolStats;
|
66
59
|
}
|
package/dist/PoolDataClient.js
CHANGED
@@ -24,20 +24,6 @@ var PoolDataClient = (function () {
|
|
24
24
|
PoolDataClient.prototype.loadLpData = function (lpTokenInfo) {
|
25
25
|
this.lpTokenInfo = lpTokenInfo;
|
26
26
|
};
|
27
|
-
PoolDataClient.prototype.getOiLongUI = function () {
|
28
|
-
var totalAmount = new anchor_1.BN('0');
|
29
|
-
this.custodies.forEach(function (i) {
|
30
|
-
totalAmount = totalAmount.add(i.tradeStats.oiLong);
|
31
|
-
});
|
32
|
-
return totalAmount;
|
33
|
-
};
|
34
|
-
PoolDataClient.prototype.getOiShortUI = function () {
|
35
|
-
var totalAmount = new anchor_1.BN('0');
|
36
|
-
this.custodies.forEach(function (i) {
|
37
|
-
totalAmount = totalAmount.add(i.tradeStats.oiShort);
|
38
|
-
});
|
39
|
-
return totalAmount;
|
40
|
-
};
|
41
27
|
PoolDataClient.prototype.getLpStats = function (pricesMap) {
|
42
28
|
var stableCoinAmountBni = new bignumber_js_1.default(0);
|
43
29
|
var totalPoolValueUsdBnUi = new bignumber_js_1.default(0);
|
@@ -78,7 +64,7 @@ var PoolDataClient = (function () {
|
|
78
64
|
};
|
79
65
|
PoolDataClient.prototype.getCustodyStats = function (pricesMap) {
|
80
66
|
var totalPoolValueUsd = this.getLpStats(pricesMap).totalPoolValueUsd;
|
81
|
-
var totalPoolValueUsdUi = totalPoolValueUsd.isZero() ? '0' : (0, utils_1.nativeToUiDecimals)(totalPoolValueUsd, constants_1.
|
67
|
+
var totalPoolValueUsdUi = totalPoolValueUsd.isZero() ? '0' : (0, utils_1.nativeToUiDecimals)(totalPoolValueUsd, constants_1.USD_DECIMALS, constants_1.USD_DECIMALS);
|
82
68
|
var custodyDetails = [];
|
83
69
|
var _loop_2 = function (i) {
|
84
70
|
var custodyConfig = this_2.poolConfig.custodies[i];
|
@@ -140,34 +126,6 @@ var PoolDataClient = (function () {
|
|
140
126
|
}
|
141
127
|
return custodyDetails;
|
142
128
|
};
|
143
|
-
PoolDataClient.prototype.getPoolStats = function () {
|
144
|
-
var totalFees = new anchor_1.BN(0);
|
145
|
-
var totalVolume = new anchor_1.BN(0);
|
146
|
-
var currentLongPositionsUsd = new anchor_1.BN(0);
|
147
|
-
var currentShortPositionsUsd = new anchor_1.BN(0);
|
148
|
-
var _loop_3 = function (custody) {
|
149
|
-
var custodyData = this_3.custodies.find(function (t) { return t.mint.toBase58() === custody.mintKey.toBase58(); });
|
150
|
-
if (custodyData) {
|
151
|
-
var custodyFeeTotal = Object.values(custodyData.collectedFees).reduce(function (a, b) { return a.add(b); }, new anchor_1.BN(0));
|
152
|
-
totalFees = totalFees.add(custodyFeeTotal);
|
153
|
-
var custodyVolume = Object.values(custodyData.volumeStats).reduce(function (a, b) { return a.add(b); }, new anchor_1.BN(0));
|
154
|
-
totalVolume = totalVolume.add(custodyVolume);
|
155
|
-
currentLongPositionsUsd = currentLongPositionsUsd.add(custodyData.tradeStats.oiLong);
|
156
|
-
currentShortPositionsUsd = currentShortPositionsUsd.add(custodyData.tradeStats.oiShort);
|
157
|
-
}
|
158
|
-
};
|
159
|
-
var this_3 = this;
|
160
|
-
for (var _i = 0, _a = this.poolConfig.custodies; _i < _a.length; _i++) {
|
161
|
-
var custody = _a[_i];
|
162
|
-
_loop_3(custody);
|
163
|
-
}
|
164
|
-
return {
|
165
|
-
totalFees: totalFees,
|
166
|
-
totalVolume: totalVolume,
|
167
|
-
currentLongPositionsUsd: currentLongPositionsUsd,
|
168
|
-
currentShortPositionsUsd: currentShortPositionsUsd
|
169
|
-
};
|
170
|
-
};
|
171
129
|
return PoolDataClient;
|
172
130
|
}());
|
173
131
|
exports.PoolDataClient = PoolDataClient;
|
@@ -1,27 +1,29 @@
|
|
1
1
|
/// <reference types="bn.js" />
|
2
2
|
import { BN } from "@coral-xyz/anchor";
|
3
3
|
import { PublicKey } from "@solana/web3.js";
|
4
|
-
import {
|
4
|
+
import { ContractOraclePrice, Position } from "./types";
|
5
5
|
export declare class PositionAccount implements Position {
|
6
6
|
publicKey: PublicKey;
|
7
7
|
owner: PublicKey;
|
8
|
+
market: PublicKey;
|
8
9
|
delegate: PublicKey;
|
9
|
-
pool: PublicKey;
|
10
|
-
custody: PublicKey;
|
11
|
-
collateralCustody: PublicKey;
|
12
10
|
openTime: BN;
|
13
11
|
updateTime: BN;
|
14
|
-
|
15
|
-
price: BN;
|
12
|
+
entryPrice: ContractOraclePrice;
|
16
13
|
sizeUsd: BN;
|
17
|
-
|
18
|
-
collateralUsd: BN;
|
19
|
-
unsettledAmount: BN;
|
20
|
-
unrealizedLossUsd: BN;
|
21
|
-
cumulativeInterestSnapshot: BN;
|
14
|
+
sizeAmount: BN;
|
22
15
|
lockedAmount: BN;
|
16
|
+
lockedUsd: BN;
|
23
17
|
collateralAmount: BN;
|
24
|
-
|
18
|
+
collateralUsd: BN;
|
19
|
+
unsettledAmount: BN;
|
20
|
+
unsettledFeesUsd: BN;
|
21
|
+
cumulativeLockFeeSnapshot: BN;
|
22
|
+
takeProfitPrice: ContractOraclePrice;
|
23
|
+
stopLossPrice: ContractOraclePrice;
|
24
|
+
sizeDecimals: number;
|
25
|
+
lockedDecimals: number;
|
26
|
+
collateralDecimals: number;
|
25
27
|
bump: number;
|
26
28
|
constructor(publicKey: PublicKey, parseData: Position);
|
27
29
|
static from(publicKey: PublicKey, parseData: Position): PositionAccount;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/// <reference types="bn.js" />
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
3
|
+
import { Trading, VoltageStats } from "./types";
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
5
|
+
export declare class TradingAccount implements Trading {
|
6
|
+
publicKey: PublicKey;
|
7
|
+
nftMint: PublicKey;
|
8
|
+
owner: PublicKey;
|
9
|
+
delegate: PublicKey;
|
10
|
+
isInitialized: boolean;
|
11
|
+
level: number;
|
12
|
+
bump: number;
|
13
|
+
voltagePoints: BN;
|
14
|
+
stats: VoltageStats;
|
15
|
+
snapshot: VoltageStats;
|
16
|
+
padding: BN[];
|
17
|
+
constructor(publicKey: PublicKey, parseData: Trading);
|
18
|
+
static from(publicKey: PublicKey, parseData: Trading): TradingAccount;
|
19
|
+
updatePoolData(parseData: Trading): void;
|
20
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TradingAccount = void 0;
|
4
|
+
var TradingAccount = (function () {
|
5
|
+
function TradingAccount(publicKey, parseData) {
|
6
|
+
this.publicKey = publicKey;
|
7
|
+
Object.assign(this, parseData);
|
8
|
+
}
|
9
|
+
TradingAccount.from = function (publicKey, parseData) {
|
10
|
+
return new TradingAccount(publicKey, parseData);
|
11
|
+
};
|
12
|
+
TradingAccount.prototype.updatePoolData = function (parseData) {
|
13
|
+
Object.assign(this, parseData);
|
14
|
+
};
|
15
|
+
return TradingAccount;
|
16
|
+
}());
|
17
|
+
exports.TradingAccount = TradingAccount;
|
package/dist/backupOracle.js
CHANGED
@@ -49,14 +49,27 @@ exports.pythPriceServiceConnection = new price_service_client_1.PriceServiceConn
|
|
49
49
|
priceFeedRequestConfig: {},
|
50
50
|
});
|
51
51
|
var getPythnetOraclePrices = function (program, poolConfig, backupOracleSecretKey) { return __awaiter(void 0, void 0, void 0, function () {
|
52
|
-
var pythPriceIds, currentPrices, backupOracleAccount, caches_1, permissionlessPythCache, message, signature, preInstruction;
|
52
|
+
var custodyMintKeys, pythPriceIds, _loop_1, _i, custodyMintKeys_1, custodyMintKey, currentPrices, backupOracleAccount, caches_1, permissionlessPythCache, message, signature, preInstruction;
|
53
53
|
return __generator(this, function (_a) {
|
54
54
|
switch (_a.label) {
|
55
55
|
case 0:
|
56
|
-
|
56
|
+
custodyMintKeys = poolConfig.custodies.map(function (f) { return f.mintKey; });
|
57
|
+
pythPriceIds = [];
|
58
|
+
_loop_1 = function (custodyMintKey) {
|
59
|
+
var t = poolConfig.tokens.find(function (f) { return f.mintKey.equals(custodyMintKey); });
|
60
|
+
if (t) {
|
61
|
+
pythPriceIds.push(t.pythPriceId);
|
62
|
+
}
|
63
|
+
};
|
64
|
+
for (_i = 0, custodyMintKeys_1 = custodyMintKeys; _i < custodyMintKeys_1.length; _i++) {
|
65
|
+
custodyMintKey = custodyMintKeys_1[_i];
|
66
|
+
_loop_1(custodyMintKey);
|
67
|
+
}
|
57
68
|
return [4, exports.pythPriceServiceConnection.getLatestPriceFeeds(pythPriceIds)];
|
58
69
|
case 1:
|
59
70
|
currentPrices = _a.sent();
|
71
|
+
if (!currentPrices)
|
72
|
+
return [2];
|
60
73
|
backupOracleAccount = web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(backupOracleSecretKey));
|
61
74
|
if (pythPriceIds.length === currentPrices.length) {
|
62
75
|
caches_1 = currentPrices.map(function (price) {
|
@@ -66,7 +79,7 @@ var getPythnetOraclePrices = function (program, poolConfig, backupOracleSecretKe
|
|
66
79
|
price: new bn_js_1.default(uncheckedPrice.price),
|
67
80
|
expo: uncheckedPrice.expo,
|
68
81
|
conf: new bn_js_1.default(uncheckedPrice.conf),
|
69
|
-
|
82
|
+
emaPrice: new bn_js_1.default(uncheckedEmaPrice.price),
|
70
83
|
publishTime: new bn_js_1.default(uncheckedPrice.publishTime)
|
71
84
|
};
|
72
85
|
});
|
@@ -1,9 +1,8 @@
|
|
1
1
|
/// <reference types="bn.js" />
|
2
|
-
import { Cluster } from '@solana/web3.js';
|
2
|
+
import { Cluster, PublicKey } from '@solana/web3.js';
|
3
3
|
export declare const DEFAULT_CLUSTER: Cluster;
|
4
4
|
export declare const DEFAULT_POOL: string;
|
5
5
|
export declare const PERCENTAGE_DECIMALS = 4;
|
6
|
-
export declare const PRICE_DECIMALS = 6;
|
7
6
|
export declare const USD_DECIMALS = 6;
|
8
7
|
export declare const BPS_DECIMALS = 4;
|
9
8
|
export declare const BPS_POWER: number;
|
@@ -12,3 +11,4 @@ export declare const RATE_DECIMALS = 9;
|
|
12
11
|
export declare const RATE_POWER: number;
|
13
12
|
export declare const BN_ZERO: import("bn.js");
|
14
13
|
export declare const BN_ONE: import("bn.js");
|
14
|
+
export declare const METAPLEX_PROGRAM_ID: PublicKey;
|
package/dist/constants/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BN_ONE = exports.BN_ZERO = exports.RATE_POWER = exports.RATE_DECIMALS = exports.LP_DECIMALS = exports.BPS_POWER = exports.BPS_DECIMALS = exports.USD_DECIMALS = exports.
|
3
|
+
exports.METAPLEX_PROGRAM_ID = exports.BN_ONE = exports.BN_ZERO = exports.RATE_POWER = exports.RATE_DECIMALS = exports.LP_DECIMALS = exports.BPS_POWER = exports.BPS_DECIMALS = exports.USD_DECIMALS = exports.PERCENTAGE_DECIMALS = exports.DEFAULT_POOL = exports.DEFAULT_CLUSTER = void 0;
|
4
|
+
var web3_js_1 = require("@solana/web3.js");
|
4
5
|
var bn_js_1 = require("bn.js");
|
5
6
|
exports.DEFAULT_CLUSTER = 'devnet';
|
6
7
|
exports.DEFAULT_POOL = 'pool1';
|
7
8
|
exports.PERCENTAGE_DECIMALS = 4;
|
8
|
-
exports.PRICE_DECIMALS = 6;
|
9
9
|
exports.USD_DECIMALS = 6;
|
10
10
|
exports.BPS_DECIMALS = 4;
|
11
11
|
exports.BPS_POWER = Math.pow(10, (exports.BPS_DECIMALS));
|
@@ -14,3 +14,4 @@ exports.RATE_DECIMALS = 9;
|
|
14
14
|
exports.RATE_POWER = Math.pow(10, (exports.RATE_DECIMALS));
|
15
15
|
exports.BN_ZERO = new bn_js_1.BN(0);
|
16
16
|
exports.BN_ONE = new bn_js_1.BN(1);
|
17
|
+
exports.METAPLEX_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|