flash-sdk 1.0.4 → 1.0.5
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/lib/CustodyAccount.js +9 -19
- package/lib/OraclePrice.d.ts +2 -0
- package/lib/OraclePrice.js +4 -0
- package/lib/PerpetualsClient.d.ts +26 -5
- package/lib/PerpetualsClient.js +586 -24
- package/lib/PoolAccount.d.ts +2 -1
- package/lib/PoolAccount.js +16 -29
- package/lib/PoolConfig.d.ts +7 -2
- package/lib/PoolConfig.js +15 -7
- package/lib/PoolConfig.json +4 -0
- package/lib/{PoolDisplayData.d.ts → PoolDataClient.d.ts} +3 -2
- package/lib/{PoolDisplayData.js → PoolDataClient.js} +13 -13
- package/lib/PositionAccount.d.ts +1 -0
- package/lib/Token.js +1 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/idl/perpetuals.d.ts +3675 -0
- package/{src/target/types → lib/idl}/perpetuals.js +140 -3
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +5 -3
- package/lib/types/index.js +21 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +57 -1
- package/lib/utils/rpc.d.ts +13 -0
- package/lib/utils/rpc.js +217 -0
- package/package.json +1 -1
- package/src/CustodyAccount.ts +24 -23
- package/src/OraclePrice.ts +4 -4
- package/src/PerpetualsClient.ts +737 -96
- package/src/PoolAccount.ts +34 -32
- package/src/PoolConfig.json +4 -0
- package/src/PoolConfig.ts +21 -6
- package/src/{PoolDisplayData.ts → PoolDataClient.ts} +2 -2
- package/src/Token.ts +1 -0
- package/src/{target/types → idl}/perpetuals.ts +280 -6
- package/src/index.ts +3 -0
- package/src/types/index.ts +26 -3
- package/src/utils/index.ts +14 -0
- package/src/utils/rpc.ts +162 -0
- package/lib/CustodyAccount.d.ts.map +0 -1
- package/lib/CustodyAccount.js.map +0 -1
- package/lib/OraclePrice.d.ts.map +0 -1
- package/lib/OraclePrice.js.map +0 -1
- package/lib/PerpetualsClient.d.ts.map +0 -1
- package/lib/PerpetualsClient.js.map +0 -1
- package/lib/PoolAccount.d.ts.map +0 -1
- package/lib/PoolAccount.js.map +0 -1
- package/lib/PositionAccount.d.ts.map +0 -1
- package/lib/PositionAccount.js.map +0 -1
- package/lib/client/src/CustodyAccount.d.ts +0 -30
- package/lib/client/src/CustodyAccount.d.ts.map +0 -1
- package/lib/client/src/CustodyAccount.js +0 -64
- package/lib/client/src/CustodyAccount.js.map +0 -1
- package/lib/client/src/OraclePrice.d.ts +0 -19
- package/lib/client/src/OraclePrice.d.ts.map +0 -1
- package/lib/client/src/OraclePrice.js +0 -84
- package/lib/client/src/OraclePrice.js.map +0 -1
- package/lib/client/src/PerpetualsClient.d.ts +0 -1938
- package/lib/client/src/PerpetualsClient.d.ts.map +0 -1
- package/lib/client/src/PerpetualsClient.js +0 -1043
- package/lib/client/src/PerpetualsClient.js.map +0 -1
- package/lib/client/src/PoolAccount.d.ts +0 -35
- package/lib/client/src/PoolAccount.d.ts.map +0 -1
- package/lib/client/src/PoolAccount.js +0 -307
- package/lib/client/src/PoolAccount.js.map +0 -1
- package/lib/client/src/PositionAccount.d.ts +0 -27
- package/lib/client/src/PositionAccount.d.ts.map +0 -1
- package/lib/client/src/PositionAccount.js +0 -91
- package/lib/client/src/PositionAccount.js.map +0 -1
- package/lib/client/src/constants/index.d.ts +0 -12
- package/lib/client/src/constants/index.d.ts.map +0 -1
- package/lib/client/src/constants/index.js +0 -15
- package/lib/client/src/constants/index.js.map +0 -1
- package/lib/client/src/index.d.ts +0 -9
- package/lib/client/src/index.d.ts.map +0 -1
- package/lib/client/src/index.js +0 -26
- package/lib/client/src/index.js.map +0 -1
- package/lib/client/src/types/index.d.ts +0 -188
- package/lib/client/src/types/index.d.ts.map +0 -1
- package/lib/client/src/types/index.js +0 -57
- package/lib/client/src/types/index.js.map +0 -1
- package/lib/client/src/utils/helpers.d.ts +0 -8
- package/lib/client/src/utils/helpers.d.ts.map +0 -1
- package/lib/client/src/utils/helpers.js +0 -152
- package/lib/client/src/utils/helpers.js.map +0 -1
- package/lib/constants/index.d.ts.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib/utils/helpers.d.ts +0 -7
- package/lib/utils/helpers.d.ts.map +0 -1
- package/lib/utils/helpers.js +0 -151
- package/lib/utils/helpers.js.map +0 -1
- package/src/target/types/limit_order_cpi.js +0 -132
- package/src/target/types/limit_order_cpi.ts +0 -259
- /package/{src/target/idl/perpetuals.json → lib/Token.d.ts} +0 -0
- /package/src/{readme.md → type-rules.md} +0 -0
package/lib/CustodyAccount.js
CHANGED
@@ -15,7 +15,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
exports.CustodyAccount = void 0;
|
18
|
+
var web3_js_1 = require("@solana/web3.js");
|
18
19
|
var types_1 = require("./types");
|
20
|
+
var PositionAccount_1 = require("./PositionAccount");
|
19
21
|
var bn_js_1 = __importDefault(require("bn.js"));
|
20
22
|
var constants_1 = require("./constants");
|
21
23
|
var utils_1 = require("./utils");
|
@@ -69,25 +71,13 @@ var CustodyAccount = /** @class */ (function () {
|
|
69
71
|
stats = this.shortPositions;
|
70
72
|
}
|
71
73
|
;
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
// unrealized_loss_usd: stats.cumulative_interest_usd,
|
80
|
-
// cumulative_interest_snapshot: stats.cumulative_interest_snapshot,
|
81
|
-
// locked_amount: stats.locked_amount,
|
82
|
-
// ..Position::default()
|
83
|
-
// }
|
84
|
-
// return new PositionAccount(
|
85
|
-
// new PublicKey('dgfgfg'),
|
86
|
-
// )
|
87
|
-
// } else {
|
88
|
-
// Ok(Position::default())
|
89
|
-
// }
|
90
|
-
throw Error("Incomplete");
|
74
|
+
if (stats.openPositions.gt(constants_1.BN_ZERO)) {
|
75
|
+
var obj = __assign({ side: side, price: stats.weightedPrice.div(stats.totalQuantity), sizeUsd: stats.sizeUsd, collateralUsd: stats.collateralUsd, unrealizedLossUsd: stats.cumulativeInterestUsd, cumulativeInterestSnapshot: stats.cumulativeInterestSnapshot, lockedAmount: stats.lockedAmount }, types_1.DEFAULT_POSITION);
|
76
|
+
return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, obj);
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, types_1.DEFAULT_POSITION);
|
80
|
+
}
|
91
81
|
};
|
92
82
|
return CustodyAccount;
|
93
83
|
}());
|
package/lib/OraclePrice.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/// <reference types="bn.js" />
|
1
2
|
import { BN } from "@coral-xyz/anchor";
|
2
3
|
export declare class OraclePrice {
|
3
4
|
price: BN;
|
@@ -14,4 +15,5 @@ export declare class OraclePrice {
|
|
14
15
|
scale_to_exponent(target_exponent: BN): OraclePrice;
|
15
16
|
getTokenAmount(asset_amount_usd: BN, token_decimals: number): BN;
|
16
17
|
getAssetAmountUsd(token_amount: BN, token_decimals: number): BN;
|
18
|
+
toUiPrice(precision: number): number;
|
17
19
|
}
|
package/lib/OraclePrice.js
CHANGED
@@ -78,6 +78,10 @@ var OraclePrice = /** @class */ (function () {
|
|
78
78
|
}
|
79
79
|
return (0, utils_1.checkedDecimalMul)(token_amount, new anchor_1.BN(-1 * token_decimals), this.price, this.exponent, new anchor_1.BN(-1 * constants_1.USD_DECIMALS));
|
80
80
|
};
|
81
|
+
OraclePrice.prototype.toUiPrice = function (precision) {
|
82
|
+
var x = this.price.div(new anchor_1.BN(10).pow(new anchor_1.BN((this.exponent.toNumber() * -1) - precision)));
|
83
|
+
return x.toNumber() / Math.pow(10, precision);
|
84
|
+
};
|
81
85
|
return OraclePrice;
|
82
86
|
}());
|
83
87
|
exports.OraclePrice = OraclePrice;
|
@@ -1,10 +1,20 @@
|
|
1
|
+
/// <reference types="bn.js" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { Program, AnchorProvider, BN } from "@coral-xyz/anchor";
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
4
|
+
import { PublicKey, TransactionInstruction, Commitment } from "@solana/web3.js";
|
3
5
|
import { PoolAccount } from "./PoolAccount";
|
4
|
-
import { BorrowRateParams, Fees, OracleParams, Permissions, Position, PositionSide, PricingParams, TokenRatios } from "./types";
|
6
|
+
import { AumCalcMode, BorrowRateParams, Fees, OracleParams, Permissions, Position, PositionSide, PricingParams, Side, TokenRatios } from "./types";
|
5
7
|
import { OraclePrice } from "./OraclePrice";
|
6
8
|
import { CustodyAccount } from "./CustodyAccount";
|
7
|
-
import { Perpetuals } from "./
|
9
|
+
import { Perpetuals } from "./idl/perpetuals";
|
10
|
+
import { PoolConfig } from "./PoolConfig";
|
11
|
+
export type PerpClientOptions = {
|
12
|
+
postSendTxCallback?: ({ txid }: {
|
13
|
+
txid: string;
|
14
|
+
}) => void;
|
15
|
+
prioritizationFee?: number;
|
16
|
+
txConfirmationCommitment?: Commitment;
|
17
|
+
};
|
8
18
|
export declare class PerpetualsClient {
|
9
19
|
provider: AnchorProvider;
|
10
20
|
program: Program<Perpetuals>;
|
@@ -22,7 +32,10 @@ export declare class PerpetualsClient {
|
|
22
32
|
publicKey: PublicKey;
|
23
33
|
bump: number;
|
24
34
|
};
|
25
|
-
|
35
|
+
private postSendTxCallback?;
|
36
|
+
private prioritizationFee;
|
37
|
+
private txConfirmationCommitment;
|
38
|
+
constructor(provider: AnchorProvider, programId: PublicKey, opts: PerpClientOptions);
|
26
39
|
findProgramAddress: (label: string, extraSeeds?: any) => {
|
27
40
|
publicKey: PublicKey;
|
28
41
|
bump: number;
|
@@ -1934,5 +1947,13 @@ export declare class PerpetualsClient {
|
|
1934
1947
|
loss: BN;
|
1935
1948
|
};
|
1936
1949
|
getSwapAmountAndFees: (poolName: string, tokenMintIn: PublicKey, tokenMintOut: PublicKey, amountIn: BN) => Promise<any>;
|
1937
|
-
|
1950
|
+
getAumView: (poolName: string) => Promise<any>;
|
1951
|
+
getAumTrx: (poolName: string) => Promise<string>;
|
1952
|
+
getAumSdk: (poolAccount: PoolAccount, token_prices: OraclePrice[], token_ema_prices: OraclePrice[], custodies: CustodyAccount[], aum_calc_mode: AumCalcMode, currentTime: BN) => BN;
|
1953
|
+
openPosition: (payTokenSymbol: string, price: BN, collateral: BN, size: BN, side: Side, slippagePercentage: number, poolConfig: PoolConfig) => Promise<TransactionInstruction[]>;
|
1954
|
+
closePosition: (receivingTokenSymbol: string, price: BN, side: Side, slippagePercentage: number, poolConfig: PoolConfig) => Promise<TransactionInstruction[]>;
|
1955
|
+
swap: (receivingTokenSymbol: string, dispensingTokenSymbol: string, amountIn: BN, minAmountOut: BN, poolConfig: PoolConfig) => Promise<TransactionInstruction[]>;
|
1956
|
+
addLiquidity: (payTokenSymbol: string, tokenAmountIn: BN, minLpAmountOut: BN, poolConfig: PoolConfig) => Promise<TransactionInstruction[]>;
|
1957
|
+
removeLiquidity: (recieveTokenSymbol: string, liquidityAmountIn: BN, minTokenAmountOut: BN, poolConfig: PoolConfig, closeLpATA?: boolean) => Promise<TransactionInstruction[]>;
|
1958
|
+
sendTransaction(ixs: TransactionInstruction[], opts?: any): Promise<string>;
|
1938
1959
|
}
|