flash-sdk 12.0.0 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/CustodyAccount.d.ts +1 -1
  2. package/dist/MarketAccount.d.ts +2 -2
  3. package/dist/OraclePrice.d.ts +0 -1
  4. package/dist/OrderAccount.d.ts +0 -1
  5. package/dist/PerpetualsClient.d.ts +325 -4360
  6. package/dist/PerpetualsClient.js +1205 -558
  7. package/dist/PoolAccount.d.ts +0 -1
  8. package/dist/PoolConfig.d.ts +3 -1
  9. package/dist/PoolConfig.js +30 -2
  10. package/dist/PoolConfig.json +955 -133
  11. package/dist/PoolDataClient.d.ts +0 -1
  12. package/dist/PositionAccount.d.ts +3 -3
  13. package/dist/TokenStakeAccount.d.ts +0 -1
  14. package/dist/TokenVaultAccount.d.ts +0 -1
  15. package/dist/ViewHelper.d.ts +2 -1
  16. package/dist/ViewHelper.js +11 -8
  17. package/dist/backupOracle.js +27 -6
  18. package/dist/constants/index.d.ts +0 -1
  19. package/dist/idl/perpetuals.d.ts +26433 -13458
  20. package/dist/idl/perpetuals.js +0 -18010
  21. package/dist/idl/perpetuals.json +30985 -0
  22. package/dist/index.d.ts +3 -1
  23. package/dist/index.js +6 -2
  24. package/dist/remoraTokensWithPriceIds.d.ts +13 -0
  25. package/dist/remoraTokensWithPriceIds.js +265 -0
  26. package/dist/testPublkey.d.ts +0 -0
  27. package/dist/testPublkey.js +0 -0
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/types/generated.d.ts +2275 -0
  30. package/dist/types/generated.js +2 -0
  31. package/dist/types/index.d.ts +47 -160
  32. package/dist/types/index.js +22 -6
  33. package/dist/utils/IdlCoder.d.ts +3 -2
  34. package/dist/utils/IdlCoder.js +21 -9
  35. package/dist/utils/alt.js +5 -6
  36. package/dist/utils/anchorCpiEvents.d.ts +1 -2
  37. package/dist/utils/anchorCpiEvents.js +14 -10
  38. package/dist/utils/index.js +6 -6
  39. package/dist/utils/rpc.js +9 -9
  40. package/package.json +3 -3
  41. package/readme.md +37 -3
  42. package/dist/idl/fbnft_rewards.d.ts +0 -290
  43. package/dist/idl/fbnft_rewards.js +0 -292
  44. package/dist/idl/perp_composability.d.ts +0 -760
  45. package/dist/idl/perp_composability.js +0 -762
  46. package/dist/idl/reward_distribution.d.ts +0 -347
  47. package/dist/idl/reward_distribution.js +0 -349
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from "@coral-xyz/anchor";
3
2
  import { Mint } from "@solana/spl-token";
4
3
  import { CustodyAccount } from "./CustodyAccount";
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from "@coral-xyz/anchor";
3
2
  import { PublicKey } from "@solana/web3.js";
4
3
  import { ContractOraclePrice, Position } from "./types";
@@ -14,14 +13,15 @@ export declare class PositionAccount implements Position {
14
13
  sizeAmount: BN;
15
14
  lockedAmount: BN;
16
15
  lockedUsd: BN;
17
- collateralAmount: BN;
16
+ priceImpactUsd: BN;
18
17
  collateralUsd: BN;
19
18
  unsettledValueUsd: BN;
20
19
  unsettledFeesUsd: BN;
21
20
  cumulativeLockFeeSnapshot: BN;
22
21
  degenSizeUsd: BN;
23
22
  referencePrice: ContractOraclePrice;
24
- buffer: number;
23
+ buffer: number[];
24
+ priceImpactSet: number;
25
25
  sizeDecimals: number;
26
26
  lockedDecimals: number;
27
27
  collateralDecimals: number;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { TokenStake, WithdrawStakeLog } from "./types";
3
2
  import { BN } from "@coral-xyz/anchor";
4
3
  import { PublicKey } from "@solana/web3.js";
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from "@coral-xyz/anchor";
3
2
  import { PublicKey } from "@solana/web3.js";
4
3
  import { TokenVault } from "./types";
@@ -1,8 +1,9 @@
1
1
  import { PublicKey, RpcResponseAndContext, SimulatedTransactionResponse, Transaction } from "@solana/web3.js";
2
2
  import { PerpetualsClient } from "./PerpetualsClient";
3
+ import { AddressLookupTableAccount } from "@solana/web3.js";
3
4
  export declare class ViewHelper {
4
5
  private perpetualsClient;
5
6
  constructor(client: PerpetualsClient);
6
7
  decodeLogs<T>(data: RpcResponseAndContext<SimulatedTransactionResponse>, instructionNumber: number, instructionName?: string): T | undefined;
7
- simulateTransaction(transaction: Transaction, userPublicKey?: PublicKey | undefined): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
8
+ simulateTransaction(transaction: Transaction, addressLookupTableAccounts: AddressLookupTableAccount[], userPublicKey?: PublicKey | undefined): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
8
9
  }
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -44,11 +44,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
44
  }
45
45
  return to.concat(ar || Array.prototype.slice.call(from));
46
46
  };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
47
50
  Object.defineProperty(exports, "__esModule", { value: true });
48
51
  exports.ViewHelper = void 0;
49
52
  var web3_js_1 = require("@solana/web3.js");
50
53
  var base64_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes/base64");
51
- var perpetuals_1 = require("./idl/perpetuals");
54
+ var perpetuals_json_1 = __importDefault(require("./idl/perpetuals.json"));
52
55
  var IdlCoder_1 = require("./utils/IdlCoder");
53
56
  var ViewHelper = (function () {
54
57
  function ViewHelper(client) {
@@ -65,11 +68,11 @@ var ViewHelper = (function () {
65
68
  throw new Error('View expected return log');
66
69
  }
67
70
  var returnData = (0, base64_1.decode)(returnLog.slice(returnPrefix_1.length));
68
- var returnType = perpetuals_1.IDL.instructions[instructionNumber].returns;
71
+ var returnType = perpetuals_json_1.default.instructions[instructionNumber].returns;
69
72
  if (!returnType) {
70
73
  throw new Error('View expected return type');
71
74
  }
72
- var coder = IdlCoder_1.IdlCoder.fieldLayout({ type: returnType }, Array.from(__spreadArray(__spreadArray([], ((_a = perpetuals_1.IDL.accounts) !== null && _a !== void 0 ? _a : []), true), ((_b = perpetuals_1.IDL.types) !== null && _b !== void 0 ? _b : []), true)));
75
+ var coder = IdlCoder_1.IdlCoder.fieldLayout({ type: returnType }, Array.from(__spreadArray(__spreadArray([], ((_a = perpetuals_json_1.default.accounts) !== null && _a !== void 0 ? _a : []), true), ((_b = perpetuals_json_1.default.types) !== null && _b !== void 0 ? _b : []), true)));
73
76
  return coder.decode(returnData);
74
77
  }
75
78
  else {
@@ -82,8 +85,8 @@ var ViewHelper = (function () {
82
85
  console.log("decode error::", error);
83
86
  }
84
87
  };
85
- ViewHelper.prototype.simulateTransaction = function (transaction_1) {
86
- return __awaiter(this, arguments, void 0, function (transaction, userPublicKey) {
88
+ ViewHelper.prototype.simulateTransaction = function (transaction_1, addressLookupTableAccounts_1) {
89
+ return __awaiter(this, arguments, void 0, function (transaction, addressLookupTableAccounts, userPublicKey) {
87
90
  var latestBlockhash, messageV0, transaction2;
88
91
  if (userPublicKey === void 0) { userPublicKey = undefined; }
89
92
  return __generator(this, function (_a) {
@@ -97,7 +100,7 @@ var ViewHelper = (function () {
97
100
  payerKey: this.perpetualsClient.provider.publicKey,
98
101
  recentBlockhash: latestBlockhash.blockhash,
99
102
  instructions: transaction.instructions,
100
- }).compileToV0Message(this.perpetualsClient.addressLookupTables);
103
+ }).compileToV0Message(addressLookupTableAccounts);
101
104
  transaction2 = new web3_js_1.VersionedTransaction(messageV0);
102
105
  return [2, this.perpetualsClient.provider.connection.simulateTransaction(transaction2, { sigVerify: false, replaceRecentBlockhash: true })];
103
106
  }
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -40,12 +40,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  var _a;
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.createBackupOracleInstruction = exports.getBackupOracleInstruction = exports.getPythnetOraclePrices = exports.pythPriceServiceConnection = void 0;
43
+ exports.getBackupOracleInstruction = exports.getPythnetOraclePrices = exports.pythPriceServiceConnection = void 0;
44
+ exports.createBackupOracleInstruction = createBackupOracleInstruction;
44
45
  var price_service_client_1 = require("@pythnetwork/price-service-client");
45
46
  var web3_js_1 = require("@solana/web3.js");
46
47
  var bn_js_1 = __importDefault(require("bn.js"));
47
48
  var bs58_1 = __importDefault(require("bs58"));
48
49
  var tweetnacl_1 = __importDefault(require("tweetnacl"));
50
+ var BACKUP_ORACLE_SIZE = 36;
51
+ function encodePermissionlessPythCache(cache) {
52
+ var backupCache = cache.backupCache;
53
+ var buf = Buffer.alloc(4 + backupCache.length * BACKUP_ORACLE_SIZE);
54
+ buf.writeUInt32LE(backupCache.length, 0);
55
+ var offset = 4;
56
+ for (var _i = 0, backupCache_1 = backupCache; _i < backupCache_1.length; _i++) {
57
+ var oracle = backupCache_1[_i];
58
+ buf.writeBigInt64LE(BigInt(oracle.price.toString()), offset);
59
+ offset += 8;
60
+ buf.writeInt32LE(oracle.expo, offset);
61
+ offset += 4;
62
+ buf.writeBigInt64LE(BigInt(oracle.conf.toString()), offset);
63
+ offset += 8;
64
+ buf.writeBigInt64LE(BigInt(oracle.emaPrice.toString()), offset);
65
+ offset += 8;
66
+ buf.writeBigInt64LE(BigInt(oracle.publishTime.toString()), offset);
67
+ offset += 8;
68
+ }
69
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
70
+ }
49
71
  var API_ENDPOINT = (_a = process.env.NEXT_PUBLIC_API_ENDPOINT) !== null && _a !== void 0 ? _a : 'https://api.prod.flash.trade';
50
72
  exports.pythPriceServiceConnection = new price_service_client_1.PriceServiceConnection('https://hermes.pyth.network', {
51
73
  priceFeedRequestConfig: {},
@@ -88,7 +110,7 @@ var getPythnetOraclePrices = function (program, poolConfig, backupOracleSecretKe
88
110
  permissionlessPythCache = {
89
111
  backupCache: caches_1
90
112
  };
91
- message = program._coder.types.encode('PermissionlessPythCache', permissionlessPythCache);
113
+ message = encodePermissionlessPythCache(permissionlessPythCache);
92
114
  signature = tweetnacl_1.default.sign.detached(message, backupOracleAccount.secretKey);
93
115
  preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
94
116
  publicKey: backupOracleAccount.publicKey.toBytes(),
@@ -114,7 +136,7 @@ var getBackupOracleInstruction = function (program, poolConfig, backupOracleSecr
114
136
  var permissionlessPythCache = {
115
137
  backupCache: backupCaches
116
138
  };
117
- var message = program._coder.types.encode('PermissionlessPythCache', permissionlessPythCache);
139
+ var message = encodePermissionlessPythCache(permissionlessPythCache);
118
140
  var signature = tweetnacl_1.default.sign.detached(message, backupOracleAccount.secretKey);
119
141
  var preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
120
142
  publicKey: backupOracleAccount.publicKey.toBytes(),
@@ -156,4 +178,3 @@ function createBackupOracleInstruction(poolAddress_1) {
156
178
  });
157
179
  });
158
180
  }
159
- exports.createBackupOracleInstruction = createBackupOracleInstruction;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  export declare const PERCENTAGE_DECIMALS = 4;
4
3
  export declare const USD_DECIMALS = 6;