flash-sdk 1.0.134 → 2.0.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.
@@ -1,16 +1,26 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { BN } from "@coral-xyz/anchor";
3
- import { Pool, TokenRatios } from "./types";
3
+ import { Pool, TokenRatios, StakeStats, Permissions } from "./types";
4
4
  import { PublicKey } from "@solana/web3.js";
5
5
  export declare class PoolAccount implements Pool {
6
6
  publicKey: PublicKey;
7
7
  name: string;
8
+ permissions: Permissions;
9
+ inceptionTime: BN;
10
+ flpMint: PublicKey;
11
+ oracleAuthority: PublicKey;
12
+ flpTokenAccount: PublicKey;
13
+ rewardCustody: PublicKey;
8
14
  custodies: PublicKey[];
9
15
  ratios: TokenRatios[];
16
+ markets: PublicKey[];
17
+ maxAumUsd: BN;
10
18
  aumUsd: BN;
19
+ totalStaked: StakeStats;
20
+ stakingFeeShareBps: BN;
11
21
  bump: number;
12
- lpTokenBump: number;
13
- inceptionTime: BN;
22
+ flpMintBump: number;
23
+ flpTokenAccountBump: number;
14
24
  constructor(publicKey: PublicKey, parseData: Pool);
15
25
  static from(publicKey: PublicKey, parseData: Pool): PoolAccount;
16
26
  updatePoolData(parseData: Pool): void;
@@ -1,5 +1,7 @@
1
1
  import { Address } from '@coral-xyz/anchor';
2
2
  import { Cluster, PublicKey } from '@solana/web3.js';
3
+ import poolConfigs from './PoolConfig.json';
4
+ import { Side } from './types';
3
5
  export interface CustodyConfig {
4
6
  custodyId: number;
5
7
  custodyAccount: PublicKey;
@@ -11,6 +13,18 @@ export interface CustodyConfig {
11
13
  isVirtual: boolean;
12
14
  oracleAddress: PublicKey;
13
15
  }
16
+ export interface MarketConfig {
17
+ marketId: number;
18
+ marketAccount: PublicKey;
19
+ pool: PublicKey;
20
+ targetCustody: PublicKey;
21
+ collateralCustody: PublicKey;
22
+ side: Side;
23
+ targetCustodyId: number;
24
+ collateralCustodyId: number;
25
+ targetMint: PublicKey;
26
+ collateralMint: PublicKey;
27
+ }
14
28
  export type Token = {
15
29
  symbol: string;
16
30
  mintKey: PublicKey;
@@ -34,10 +48,19 @@ export declare class PoolConfig {
34
48
  multisig: PublicKey;
35
49
  addressLookupTableAddresses: PublicKey[];
36
50
  backupOracle: PublicKey;
51
+ nftCollectionAddress: PublicKey;
37
52
  tokens: Token[];
38
53
  custodies: CustodyConfig[];
39
- constructor(programId: PublicKey, perpComposibilityProgramId: 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[]);
54
+ markets: MarketConfig[];
55
+ constructor(programId: PublicKey, perpComposibilityProgramId: PublicKey, cluster: Cluster, poolName: string, poolAddress: PublicKey, lpTokenMint: PublicKey, lpDecimals: number, lpTokenSymbol: string, perpetuals: PublicKey, transferAuthority: PublicKey, multisig: PublicKey, addressLookupTableAddresses: PublicKey[], backupOracle: PublicKey, nftCollectionAddress: PublicKey, tokens: Token[], custodies: CustodyConfig[], markets: MarketConfig[]);
40
56
  getAllTokenMints(): PublicKey[];
57
+ getMarketConfigByPk(marketAccountPk: PublicKey): MarketConfig;
58
+ getMarketConfig(targetCustody: PublicKey, collateralCustody: PublicKey, side: Side): MarketConfig | null;
59
+ getMarketPk(targetCustody: PublicKey, collateralCustody: PublicKey, side: Side): PublicKey;
60
+ getPositionFromMarketPk(owner: PublicKey, marketAccount: PublicKey): PublicKey;
61
+ getPositionFromCustodyPk(owner: PublicKey, targetCustody: PublicKey, collateralCustody: PublicKey, side: Side): PublicKey;
62
+ doesMarketExist(pubkey: PublicKey): boolean;
63
+ getAllMarketPks(): PublicKey[];
41
64
  getNonStableTokens(): PublicKey[];
42
65
  getAllCustodies(): PublicKey[];
43
66
  getNonStableCustodies(): PublicKey[];
@@ -48,6 +71,7 @@ export declare class PoolConfig {
48
71
  getCustodyIdFromCustodyAccount(custodyAccountPk: Address): number;
49
72
  getCustodyAccountFromCustodyId(custodyId: number): PublicKey;
50
73
  static getTokensInPool(name: string, cluster: Cluster): Token[];
74
+ static buildPoolconfigFromJson(poolConfig: typeof poolConfigs['pools'][0]): PoolConfig;
51
75
  static fromIdsByName(name: string, cluster: Cluster): PoolConfig;
52
76
  static fromIdsByPk(poolPk: PublicKey, cluster: Cluster): PoolConfig;
53
77
  }
@@ -17,8 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.PoolConfig = void 0;
18
18
  var web3_js_1 = require("@solana/web3.js");
19
19
  var PoolConfig_json_1 = __importDefault(require("./PoolConfig.json"));
20
+ var types_1 = require("./types");
20
21
  var PoolConfig = (function () {
21
- function PoolConfig(programId, perpComposibilityProgramId, cluster, poolName, poolAddress, lpTokenMint, lpDecimals, lpTokenSymbol, perpetuals, transferAuthority, multisig, addressLookupTableAddresses, backupOracle, tokens, custodies) {
22
+ function PoolConfig(programId, perpComposibilityProgramId, cluster, poolName, poolAddress, lpTokenMint, lpDecimals, lpTokenSymbol, perpetuals, transferAuthority, multisig, addressLookupTableAddresses, backupOracle, nftCollectionAddress, tokens, custodies, markets) {
22
23
  var _this = this;
23
24
  this.programId = programId;
24
25
  this.perpComposibilityProgramId = perpComposibilityProgramId;
@@ -33,8 +34,10 @@ var PoolConfig = (function () {
33
34
  this.multisig = multisig;
34
35
  this.addressLookupTableAddresses = addressLookupTableAddresses;
35
36
  this.backupOracle = backupOracle;
37
+ this.nftCollectionAddress = nftCollectionAddress;
36
38
  this.tokens = tokens;
37
39
  this.custodies = custodies;
40
+ this.markets = markets;
38
41
  this.getTokenFromSymbol = function (symbol) {
39
42
  return _this.tokens.find(function (f) { return f.symbol.toUpperCase() === symbol.toUpperCase(); });
40
43
  };
@@ -48,6 +51,47 @@ var PoolConfig = (function () {
48
51
  PoolConfig.prototype.getAllTokenMints = function () {
49
52
  return Array.from(this.tokens.map(function (token) { return new web3_js_1.PublicKey(token.mintKey); }));
50
53
  };
54
+ PoolConfig.prototype.getMarketConfigByPk = function (marketAccountPk) {
55
+ var market = this.markets.find(function (f) { return f.marketAccount.equals(marketAccountPk); });
56
+ if (!market)
57
+ throw new Error("No such market ".concat(marketAccountPk.toBase58(), " exists."));
58
+ return market;
59
+ };
60
+ PoolConfig.prototype.getMarketConfig = function (targetCustody, collateralCustody, side) {
61
+ var marketAccountPk = this.getMarketPk(targetCustody, collateralCustody, side);
62
+ var market = this.markets.find(function (f) { return f.marketAccount.equals(marketAccountPk); });
63
+ if (!market)
64
+ return null;
65
+ return market;
66
+ };
67
+ PoolConfig.prototype.getMarketPk = function (targetCustody, collateralCustody, side) {
68
+ return web3_js_1.PublicKey.findProgramAddressSync([
69
+ Buffer.from('market'),
70
+ targetCustody.toBuffer(),
71
+ collateralCustody.toBuffer(),
72
+ Buffer.from([(0, types_1.isVariant)(side, 'long') ? 1 : 2])
73
+ ], this.programId)[0];
74
+ };
75
+ PoolConfig.prototype.getPositionFromMarketPk = function (owner, marketAccount) {
76
+ return web3_js_1.PublicKey.findProgramAddressSync([
77
+ Buffer.from("position"),
78
+ owner.toBuffer(),
79
+ marketAccount.toBuffer(),
80
+ ], this.programId)[0];
81
+ };
82
+ PoolConfig.prototype.getPositionFromCustodyPk = function (owner, targetCustody, collateralCustody, side) {
83
+ return web3_js_1.PublicKey.findProgramAddressSync([
84
+ Buffer.from("position"),
85
+ owner.toBuffer(),
86
+ this.getMarketPk(targetCustody, collateralCustody, side).toBuffer(),
87
+ ], this.programId)[0];
88
+ };
89
+ PoolConfig.prototype.doesMarketExist = function (pubkey) {
90
+ return;
91
+ };
92
+ PoolConfig.prototype.getAllMarketPks = function () {
93
+ return this.markets.map(function (m) { return m.marketAccount; });
94
+ };
51
95
  PoolConfig.prototype.getNonStableTokens = function () {
52
96
  return Array.from(this.tokens
53
97
  .filter(function (token) { return !token.isStable; })
@@ -79,10 +123,7 @@ var PoolConfig = (function () {
79
123
  });
80
124
  return tokens;
81
125
  };
82
- PoolConfig.fromIdsByName = function (name, cluster) {
83
- var poolConfig = PoolConfig_json_1.default.pools.find(function (pool) { return pool['poolName'] === name && cluster === pool['cluster']; });
84
- if (!poolConfig)
85
- throw new Error("No pool config ".concat(name, " found in Ids!"));
126
+ PoolConfig.buildPoolconfigFromJson = function (poolConfig) {
86
127
  var tokens = poolConfig['tokens'].map(function (i) {
87
128
  return __assign(__assign({}, i), { mintKey: new web3_js_1.PublicKey(i.mintKey) });
88
129
  });
@@ -93,22 +134,24 @@ var PoolConfig = (function () {
93
134
  var addressLookupTableAddresses = poolConfig['addressLookupTableAddresses'].map(function (i) {
94
135
  return new web3_js_1.PublicKey(i);
95
136
  });
96
- return new PoolConfig(new web3_js_1.PublicKey(poolConfig.programId), new web3_js_1.PublicKey(poolConfig.perpComposibilityProgramId), poolConfig.cluster, poolConfig.poolName, new web3_js_1.PublicKey(poolConfig.poolAddress), new web3_js_1.PublicKey(poolConfig.lpTokenMint), poolConfig.lpDecimals, poolConfig.lpTokenSymbol, new web3_js_1.PublicKey(poolConfig.perpetuals), new web3_js_1.PublicKey(poolConfig.transferAuthority), new web3_js_1.PublicKey(poolConfig.multisig), addressLookupTableAddresses, new web3_js_1.PublicKey(poolConfig.backupOracle), tokens, custodies);
137
+ var markets = poolConfig['markets'].map(function (i) {
138
+ return __assign(__assign({}, i), { marketAccount: new web3_js_1.PublicKey(i.marketAccount), pool: new web3_js_1.PublicKey(i.pool), targetCustody: new web3_js_1.PublicKey(i.targetCustody), collateralCustody: new web3_js_1.PublicKey(i.collateralCustody), side: i.side === 'long' ? types_1.Side.Long : types_1.Side.Short, targetMint: new web3_js_1.PublicKey(i.targetMint), collateralMint: new web3_js_1.PublicKey(i.collateralMint) });
139
+ });
140
+ return new PoolConfig(new web3_js_1.PublicKey(poolConfig.programId), new web3_js_1.PublicKey(poolConfig.perpComposibilityProgramId), poolConfig.cluster, poolConfig.poolName, new web3_js_1.PublicKey(poolConfig.poolAddress), new web3_js_1.PublicKey(poolConfig.lpTokenMint), poolConfig.lpDecimals, poolConfig.lpTokenSymbol, new web3_js_1.PublicKey(poolConfig.perpetuals), new web3_js_1.PublicKey(poolConfig.transferAuthority), new web3_js_1.PublicKey(poolConfig.multisig), addressLookupTableAddresses, new web3_js_1.PublicKey(poolConfig.backupOracle), new web3_js_1.PublicKey(poolConfig.nftCollectionAddress), tokens, custodies, markets);
141
+ };
142
+ PoolConfig.fromIdsByName = function (name, cluster) {
143
+ var poolConfig = PoolConfig_json_1.default.pools.find(function (pool) { return pool['poolName'] === name && cluster === pool['cluster']; });
144
+ if (!poolConfig) {
145
+ throw new Error("No pool with ".concat(name, " found!"));
146
+ }
147
+ return PoolConfig.buildPoolconfigFromJson(poolConfig);
97
148
  };
98
149
  PoolConfig.fromIdsByPk = function (poolPk, cluster) {
99
150
  var poolConfig = PoolConfig_json_1.default.pools.find(function (pool) { return pool['poolAddress'] === poolPk.toString() && cluster === pool['cluster']; });
100
- if (!poolConfig)
101
- throw new Error("No pool config ".concat(poolPk.toString(), " found in Ids!"));
102
- var tokens = poolConfig['tokens'].map(function (i) {
103
- return __assign(__assign({}, i), { mintKey: new web3_js_1.PublicKey(i.mintKey) });
104
- });
105
- var custodies = poolConfig['custodies'].map(function (i) {
106
- return __assign(__assign({}, i), { custodyAccount: new web3_js_1.PublicKey(i.custodyAccount), tokenAccount: new web3_js_1.PublicKey(i.tokenAccount), mintKey: new web3_js_1.PublicKey(i.mintKey), oracleAddress: new web3_js_1.PublicKey(i.oracleAddress) });
107
- });
108
- var addressLookupTableAddresses = poolConfig['addressLookupTableAddresses'].map(function (i) {
109
- return new web3_js_1.PublicKey(i);
110
- });
111
- return new PoolConfig(new web3_js_1.PublicKey(poolConfig.programId), new web3_js_1.PublicKey(poolConfig.perpComposibilityProgramId), poolConfig.cluster, poolConfig.poolName, new web3_js_1.PublicKey(poolConfig.poolAddress), new web3_js_1.PublicKey(poolConfig.lpTokenMint), poolConfig.lpDecimals, poolConfig.lpTokenSymbol, new web3_js_1.PublicKey(poolConfig.perpetuals), new web3_js_1.PublicKey(poolConfig.transferAuthority), new web3_js_1.PublicKey(poolConfig.multisig), addressLookupTableAddresses, new web3_js_1.PublicKey(poolConfig.backupOracle), tokens, custodies);
151
+ if (!poolConfig) {
152
+ throw new Error("No pool with ".concat(poolPk.toString(), " found!"));
153
+ }
154
+ return PoolConfig.buildPoolconfigFromJson(poolConfig);
112
155
  };
113
156
  return PoolConfig;
114
157
  }());