@glamsystems/glam-sdk 0.1.19 → 0.1.21
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/README.md +3 -37
- package/index.cjs.js +1596 -220
- package/index.esm.js +1543 -218
- package/package.json +2 -4
- package/src/client/drift.d.ts +75 -59
- package/src/client/kamino.d.ts +36 -12
- package/src/client/meteora.d.ts +1 -1
- package/src/client/price.d.ts +4 -7
- package/src/client.d.ts +3 -1
- package/src/constants.d.ts +4 -0
- package/src/index.d.ts +3 -0
- package/src/react/glam.d.ts +2 -2
- package/src/utils/driftOrderParams.d.ts +28 -0
- package/src/utils/driftTypes.d.ts +1422 -0
- package/src/utils/driftUser.d.ts +2 -0
- package/src/utils/helpers.d.ts +1 -0
- package/src/utils/priorityfee.d.ts +1 -1
- package/target/idl/glam_protocol.json +8 -2
- package/target/types/glam_protocol.d.ts +8 -2
- package/target/types/glam_protocol.ts +8 -2
package/index.cjs.js
CHANGED
|
@@ -6,7 +6,6 @@ var splToken = require('@solana/spl-token');
|
|
|
6
6
|
var splTokenMetadata = require('@solana/spl-token-metadata');
|
|
7
7
|
var DLMM = require('@meteora-ag/dlmm');
|
|
8
8
|
var bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
9
|
-
var sdk = require('@drift-labs/sdk');
|
|
10
9
|
var marinadeTsSdk = require('@marinade.finance/marinade-ts-sdk');
|
|
11
10
|
var splStakePool = require('@solana/spl-stake-pool');
|
|
12
11
|
var borsh = require('@coral-xyz/borsh');
|
|
@@ -3251,6 +3250,7 @@ var instructions = [
|
|
|
3251
3250
|
},
|
|
3252
3251
|
{
|
|
3253
3252
|
name: "glam_vault",
|
|
3253
|
+
writable: true,
|
|
3254
3254
|
pda: {
|
|
3255
3255
|
seeds: [
|
|
3256
3256
|
{
|
|
@@ -9215,16 +9215,21 @@ var errors = [
|
|
|
9215
9215
|
},
|
|
9216
9216
|
{
|
|
9217
9217
|
code: 50004,
|
|
9218
|
+
name: "InvalidPlatformFeeForSwap",
|
|
9219
|
+
msg: "Invalid platform fee"
|
|
9220
|
+
},
|
|
9221
|
+
{
|
|
9222
|
+
code: 50005,
|
|
9218
9223
|
name: "InvalidTokenAccount",
|
|
9219
9224
|
msg: "Invalid token account"
|
|
9220
9225
|
},
|
|
9221
9226
|
{
|
|
9222
|
-
code:
|
|
9227
|
+
code: 50006,
|
|
9223
9228
|
name: "InvalidVoteSide",
|
|
9224
9229
|
msg: "Invalid vote side"
|
|
9225
9230
|
},
|
|
9226
9231
|
{
|
|
9227
|
-
code:
|
|
9232
|
+
code: 50007,
|
|
9228
9233
|
name: "MultipleStakeAccountsDisallowed",
|
|
9229
9234
|
msg: "Multiple stake accounts disallowed"
|
|
9230
9235
|
},
|
|
@@ -12448,9 +12453,12 @@ const MEMO_PROGRAM = new web3_js.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgD
|
|
|
12448
12453
|
* Stake pools
|
|
12449
12454
|
*/ const JITO_STAKE_POOL = new web3_js.PublicKey("Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb");
|
|
12450
12455
|
const JUPSOL_STAKE_POOL = new web3_js.PublicKey("8VpRhuxa7sUUepdY3kQiTmX9rS5vx4WgaXiAnXq4KCtr");
|
|
12456
|
+
/**
|
|
12457
|
+
* Referrers
|
|
12458
|
+
*/ const GLAM_REFERRER = new web3_js.PublicKey("GLAMrG37ZqioqvzBNQGCfCUueDz3tsr7MwMFyRk9PS89");
|
|
12451
12459
|
|
|
12452
12460
|
const GlamIntegrations = GlamProtocolIdlJson?.types?.find((t)=>t.name === "Integration")?.type?.variants?.map((v)=>v.name) ?? [];
|
|
12453
|
-
const GlamPermissions = GlamProtocolIdlJson?.types?.find((t)=>t.name === "Permission")?.type?.variants?.map((v)=>v.name) ?? [];
|
|
12461
|
+
const GlamPermissions = GlamProtocolIdlJson?.types?.find((t)=>t.name === "Permission")?.type?.variants?.map((v)=>v.name).filter((v)=>!v.startsWith("__")) ?? [];
|
|
12454
12462
|
const GLAM_PROGRAM_ID_DEFAULT = new web3_js.PublicKey(GlamProtocolIdlJson.address);
|
|
12455
12463
|
class StateIdlModel {
|
|
12456
12464
|
constructor(data){
|
|
@@ -12925,6 +12933,13 @@ const getErrorFromRPCResponse = (rpcResponse)=>{
|
|
|
12925
12933
|
throw Error(error.toString());
|
|
12926
12934
|
}
|
|
12927
12935
|
};
|
|
12936
|
+
const setsAreEqual = (a, b)=>{
|
|
12937
|
+
if (a.size !== b.size) return false;
|
|
12938
|
+
for (let item of a){
|
|
12939
|
+
if (!b.has(item)) return false;
|
|
12940
|
+
}
|
|
12941
|
+
return true;
|
|
12942
|
+
};
|
|
12928
12943
|
|
|
12929
12944
|
const ASSETS_MAINNET = new Map([
|
|
12930
12945
|
[
|
|
@@ -13594,7 +13609,901 @@ class BaseClient {
|
|
|
13594
13609
|
}
|
|
13595
13610
|
}
|
|
13596
13611
|
|
|
13597
|
-
const
|
|
13612
|
+
const ZERO = new anchor.BN(0);
|
|
13613
|
+
// # Utility Types / Enums / Constants
|
|
13614
|
+
var ExchangeStatus = /*#__PURE__*/ function(ExchangeStatus) {
|
|
13615
|
+
ExchangeStatus[ExchangeStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
13616
|
+
ExchangeStatus[ExchangeStatus["DEPOSIT_PAUSED"] = 1] = "DEPOSIT_PAUSED";
|
|
13617
|
+
ExchangeStatus[ExchangeStatus["WITHDRAW_PAUSED"] = 2] = "WITHDRAW_PAUSED";
|
|
13618
|
+
ExchangeStatus[ExchangeStatus["AMM_PAUSED"] = 4] = "AMM_PAUSED";
|
|
13619
|
+
ExchangeStatus[ExchangeStatus["FILL_PAUSED"] = 8] = "FILL_PAUSED";
|
|
13620
|
+
ExchangeStatus[ExchangeStatus["LIQ_PAUSED"] = 16] = "LIQ_PAUSED";
|
|
13621
|
+
ExchangeStatus[ExchangeStatus["FUNDING_PAUSED"] = 32] = "FUNDING_PAUSED";
|
|
13622
|
+
ExchangeStatus[ExchangeStatus["SETTLE_PNL_PAUSED"] = 64] = "SETTLE_PNL_PAUSED";
|
|
13623
|
+
ExchangeStatus[ExchangeStatus["AMM_IMMEDIATE_FILL_PAUSED"] = 128] = "AMM_IMMEDIATE_FILL_PAUSED";
|
|
13624
|
+
ExchangeStatus[ExchangeStatus["PAUSED"] = 255] = "PAUSED";
|
|
13625
|
+
return ExchangeStatus;
|
|
13626
|
+
}({});
|
|
13627
|
+
class MarketStatus {
|
|
13628
|
+
}
|
|
13629
|
+
MarketStatus.INITIALIZED = {
|
|
13630
|
+
initialized: {}
|
|
13631
|
+
};
|
|
13632
|
+
MarketStatus.ACTIVE = {
|
|
13633
|
+
active: {}
|
|
13634
|
+
};
|
|
13635
|
+
MarketStatus.FUNDING_PAUSED = {
|
|
13636
|
+
fundingPaused: {}
|
|
13637
|
+
};
|
|
13638
|
+
MarketStatus.AMM_PAUSED = {
|
|
13639
|
+
ammPaused: {}
|
|
13640
|
+
};
|
|
13641
|
+
MarketStatus.FILL_PAUSED = {
|
|
13642
|
+
fillPaused: {}
|
|
13643
|
+
};
|
|
13644
|
+
MarketStatus.WITHDRAW_PAUSED = {
|
|
13645
|
+
withdrawPaused: {}
|
|
13646
|
+
};
|
|
13647
|
+
MarketStatus.REDUCE_ONLY = {
|
|
13648
|
+
reduceOnly: {}
|
|
13649
|
+
};
|
|
13650
|
+
MarketStatus.SETTLEMENT = {
|
|
13651
|
+
settlement: {}
|
|
13652
|
+
};
|
|
13653
|
+
MarketStatus.DELISTED = {
|
|
13654
|
+
delisted: {}
|
|
13655
|
+
};
|
|
13656
|
+
var PerpOperation = /*#__PURE__*/ function(PerpOperation) {
|
|
13657
|
+
PerpOperation[PerpOperation["UPDATE_FUNDING"] = 1] = "UPDATE_FUNDING";
|
|
13658
|
+
PerpOperation[PerpOperation["AMM_FILL"] = 2] = "AMM_FILL";
|
|
13659
|
+
PerpOperation[PerpOperation["FILL"] = 4] = "FILL";
|
|
13660
|
+
PerpOperation[PerpOperation["SETTLE_PNL"] = 8] = "SETTLE_PNL";
|
|
13661
|
+
PerpOperation[PerpOperation["SETTLE_PNL_WITH_POSITION"] = 16] = "SETTLE_PNL_WITH_POSITION";
|
|
13662
|
+
PerpOperation[PerpOperation["LIQUIDATION"] = 32] = "LIQUIDATION";
|
|
13663
|
+
return PerpOperation;
|
|
13664
|
+
}({});
|
|
13665
|
+
var SpotOperation = /*#__PURE__*/ function(SpotOperation) {
|
|
13666
|
+
SpotOperation[SpotOperation["UPDATE_CUMULATIVE_INTEREST"] = 1] = "UPDATE_CUMULATIVE_INTEREST";
|
|
13667
|
+
SpotOperation[SpotOperation["FILL"] = 2] = "FILL";
|
|
13668
|
+
SpotOperation[SpotOperation["DEPOSIT"] = 4] = "DEPOSIT";
|
|
13669
|
+
SpotOperation[SpotOperation["WITHDRAW"] = 8] = "WITHDRAW";
|
|
13670
|
+
SpotOperation[SpotOperation["LIQUIDATION"] = 16] = "LIQUIDATION";
|
|
13671
|
+
return SpotOperation;
|
|
13672
|
+
}({});
|
|
13673
|
+
var InsuranceFundOperation = /*#__PURE__*/ function(InsuranceFundOperation) {
|
|
13674
|
+
InsuranceFundOperation[InsuranceFundOperation["INIT"] = 1] = "INIT";
|
|
13675
|
+
InsuranceFundOperation[InsuranceFundOperation["ADD"] = 2] = "ADD";
|
|
13676
|
+
InsuranceFundOperation[InsuranceFundOperation["REQUEST_REMOVE"] = 4] = "REQUEST_REMOVE";
|
|
13677
|
+
InsuranceFundOperation[InsuranceFundOperation["REMOVE"] = 8] = "REMOVE";
|
|
13678
|
+
return InsuranceFundOperation;
|
|
13679
|
+
}({});
|
|
13680
|
+
var UserStatus = /*#__PURE__*/ function(UserStatus) {
|
|
13681
|
+
UserStatus[UserStatus["BEING_LIQUIDATED"] = 1] = "BEING_LIQUIDATED";
|
|
13682
|
+
UserStatus[UserStatus["BANKRUPT"] = 2] = "BANKRUPT";
|
|
13683
|
+
UserStatus[UserStatus["REDUCE_ONLY"] = 4] = "REDUCE_ONLY";
|
|
13684
|
+
UserStatus[UserStatus["ADVANCED_LP"] = 8] = "ADVANCED_LP";
|
|
13685
|
+
UserStatus[UserStatus["PROTECTED_MAKER"] = 16] = "PROTECTED_MAKER";
|
|
13686
|
+
return UserStatus;
|
|
13687
|
+
}({});
|
|
13688
|
+
class MarginMode {
|
|
13689
|
+
}
|
|
13690
|
+
MarginMode.DEFAULT = {
|
|
13691
|
+
default: {}
|
|
13692
|
+
};
|
|
13693
|
+
MarginMode.HIGH_LEVERAGE = {
|
|
13694
|
+
highLeverage: {}
|
|
13695
|
+
};
|
|
13696
|
+
class ContractType {
|
|
13697
|
+
}
|
|
13698
|
+
ContractType.PERPETUAL = {
|
|
13699
|
+
perpetual: {}
|
|
13700
|
+
};
|
|
13701
|
+
ContractType.FUTURE = {
|
|
13702
|
+
future: {}
|
|
13703
|
+
};
|
|
13704
|
+
ContractType.PREDICTION = {
|
|
13705
|
+
prediction: {}
|
|
13706
|
+
};
|
|
13707
|
+
class ContractTier {
|
|
13708
|
+
}
|
|
13709
|
+
ContractTier.A = {
|
|
13710
|
+
a: {}
|
|
13711
|
+
};
|
|
13712
|
+
ContractTier.B = {
|
|
13713
|
+
b: {}
|
|
13714
|
+
};
|
|
13715
|
+
ContractTier.C = {
|
|
13716
|
+
c: {}
|
|
13717
|
+
};
|
|
13718
|
+
ContractTier.SPECULATIVE = {
|
|
13719
|
+
speculative: {}
|
|
13720
|
+
};
|
|
13721
|
+
ContractTier.HIGHLY_SPECULATIVE = {
|
|
13722
|
+
highlySpeculative: {}
|
|
13723
|
+
};
|
|
13724
|
+
ContractTier.ISOLATED = {
|
|
13725
|
+
isolated: {}
|
|
13726
|
+
};
|
|
13727
|
+
class AssetTier {
|
|
13728
|
+
}
|
|
13729
|
+
AssetTier.COLLATERAL = {
|
|
13730
|
+
collateral: {}
|
|
13731
|
+
};
|
|
13732
|
+
AssetTier.PROTECTED = {
|
|
13733
|
+
protected: {}
|
|
13734
|
+
};
|
|
13735
|
+
AssetTier.CROSS = {
|
|
13736
|
+
cross: {}
|
|
13737
|
+
};
|
|
13738
|
+
AssetTier.ISOLATED = {
|
|
13739
|
+
isolated: {}
|
|
13740
|
+
};
|
|
13741
|
+
AssetTier.UNLISTED = {
|
|
13742
|
+
unlisted: {}
|
|
13743
|
+
};
|
|
13744
|
+
class SwapDirection {
|
|
13745
|
+
}
|
|
13746
|
+
SwapDirection.ADD = {
|
|
13747
|
+
add: {}
|
|
13748
|
+
};
|
|
13749
|
+
SwapDirection.REMOVE = {
|
|
13750
|
+
remove: {}
|
|
13751
|
+
};
|
|
13752
|
+
class SpotBalanceType {
|
|
13753
|
+
}
|
|
13754
|
+
SpotBalanceType.DEPOSIT = {
|
|
13755
|
+
deposit: {}
|
|
13756
|
+
};
|
|
13757
|
+
SpotBalanceType.BORROW = {
|
|
13758
|
+
borrow: {}
|
|
13759
|
+
};
|
|
13760
|
+
class PositionDirection {
|
|
13761
|
+
}
|
|
13762
|
+
PositionDirection.LONG = {
|
|
13763
|
+
long: {}
|
|
13764
|
+
};
|
|
13765
|
+
PositionDirection.SHORT = {
|
|
13766
|
+
short: {}
|
|
13767
|
+
};
|
|
13768
|
+
class DepositDirection {
|
|
13769
|
+
}
|
|
13770
|
+
DepositDirection.DEPOSIT = {
|
|
13771
|
+
deposit: {}
|
|
13772
|
+
};
|
|
13773
|
+
DepositDirection.WITHDRAW = {
|
|
13774
|
+
withdraw: {}
|
|
13775
|
+
};
|
|
13776
|
+
class OracleSource {
|
|
13777
|
+
static get(n) {
|
|
13778
|
+
const name = Object.entries(OracleSourceNum).find(([, v])=>v === n)?.[0];
|
|
13779
|
+
const source = Object.entries(OracleSource).find(([key, _])=>key.toLocaleLowerCase() === name?.toLocaleLowerCase())?.[1];
|
|
13780
|
+
if (!source) {
|
|
13781
|
+
throw new Error(`Invalid oracle source enum value: ${n}`);
|
|
13782
|
+
}
|
|
13783
|
+
return source;
|
|
13784
|
+
}
|
|
13785
|
+
}
|
|
13786
|
+
OracleSource.PYTH = {
|
|
13787
|
+
pyth: {}
|
|
13788
|
+
};
|
|
13789
|
+
OracleSource.PYTH_1K = {
|
|
13790
|
+
pyth1K: {}
|
|
13791
|
+
};
|
|
13792
|
+
OracleSource.PYTH_1M = {
|
|
13793
|
+
pyth1M: {}
|
|
13794
|
+
};
|
|
13795
|
+
OracleSource.PYTH_PULL = {
|
|
13796
|
+
pythPull: {}
|
|
13797
|
+
};
|
|
13798
|
+
OracleSource.PYTH_1K_PULL = {
|
|
13799
|
+
pyth1KPull: {}
|
|
13800
|
+
};
|
|
13801
|
+
OracleSource.PYTH_1M_PULL = {
|
|
13802
|
+
pyth1MPull: {}
|
|
13803
|
+
};
|
|
13804
|
+
OracleSource.SWITCHBOARD = {
|
|
13805
|
+
switchboard: {}
|
|
13806
|
+
};
|
|
13807
|
+
OracleSource.QUOTE_ASSET = {
|
|
13808
|
+
quoteAsset: {}
|
|
13809
|
+
};
|
|
13810
|
+
OracleSource.PYTH_STABLE_COIN = {
|
|
13811
|
+
pythStableCoin: {}
|
|
13812
|
+
};
|
|
13813
|
+
OracleSource.PYTH_STABLE_COIN_PULL = {
|
|
13814
|
+
pythStableCoinPull: {}
|
|
13815
|
+
};
|
|
13816
|
+
OracleSource.Prelaunch = {
|
|
13817
|
+
prelaunch: {}
|
|
13818
|
+
};
|
|
13819
|
+
OracleSource.SWITCHBOARD_ON_DEMAND = {
|
|
13820
|
+
switchboardOnDemand: {}
|
|
13821
|
+
};
|
|
13822
|
+
OracleSource.PYTH_LAZER = {
|
|
13823
|
+
pythLazer: {}
|
|
13824
|
+
};
|
|
13825
|
+
OracleSource.PYTH_LAZER_1K = {
|
|
13826
|
+
pythLazer1K: {}
|
|
13827
|
+
};
|
|
13828
|
+
OracleSource.PYTH_LAZER_1M = {
|
|
13829
|
+
pythLazer1M: {}
|
|
13830
|
+
};
|
|
13831
|
+
OracleSource.PYTH_LAZER_STABLE_COIN = {
|
|
13832
|
+
pythLazerStableCoin: {}
|
|
13833
|
+
};
|
|
13834
|
+
class OracleSourceNum {
|
|
13835
|
+
}
|
|
13836
|
+
OracleSourceNum.PYTH = 0;
|
|
13837
|
+
OracleSourceNum.PYTH_1K = 1;
|
|
13838
|
+
OracleSourceNum.PYTH_1M = 2;
|
|
13839
|
+
OracleSourceNum.PYTH_PULL = 3;
|
|
13840
|
+
OracleSourceNum.PYTH_1K_PULL = 4;
|
|
13841
|
+
OracleSourceNum.PYTH_1M_PULL = 5;
|
|
13842
|
+
OracleSourceNum.SWITCHBOARD = 6;
|
|
13843
|
+
OracleSourceNum.QUOTE_ASSET = 7;
|
|
13844
|
+
OracleSourceNum.PYTH_STABLE_COIN = 8;
|
|
13845
|
+
OracleSourceNum.PYTH_STABLE_COIN_PULL = 9;
|
|
13846
|
+
OracleSourceNum.PRELAUNCH = 10;
|
|
13847
|
+
OracleSourceNum.SWITCHBOARD_ON_DEMAND = 11;
|
|
13848
|
+
OracleSourceNum.PYTH_LAZER = 12;
|
|
13849
|
+
OracleSourceNum.PYTH_LAZER_1K = 13;
|
|
13850
|
+
OracleSourceNum.PYTH_LAZER_1M = 14;
|
|
13851
|
+
OracleSourceNum.PYTH_LAZER_STABLE_COIN = 15;
|
|
13852
|
+
class OrderType {
|
|
13853
|
+
}
|
|
13854
|
+
OrderType.LIMIT = {
|
|
13855
|
+
limit: {}
|
|
13856
|
+
};
|
|
13857
|
+
OrderType.TRIGGER_MARKET = {
|
|
13858
|
+
triggerMarket: {}
|
|
13859
|
+
};
|
|
13860
|
+
OrderType.TRIGGER_LIMIT = {
|
|
13861
|
+
triggerLimit: {}
|
|
13862
|
+
};
|
|
13863
|
+
OrderType.MARKET = {
|
|
13864
|
+
market: {}
|
|
13865
|
+
};
|
|
13866
|
+
OrderType.ORACLE = {
|
|
13867
|
+
oracle: {}
|
|
13868
|
+
};
|
|
13869
|
+
class MarketType {
|
|
13870
|
+
}
|
|
13871
|
+
MarketType.SPOT = {
|
|
13872
|
+
spot: {}
|
|
13873
|
+
};
|
|
13874
|
+
MarketType.PERP = {
|
|
13875
|
+
perp: {}
|
|
13876
|
+
};
|
|
13877
|
+
class OrderStatus {
|
|
13878
|
+
}
|
|
13879
|
+
OrderStatus.INIT = {
|
|
13880
|
+
init: {}
|
|
13881
|
+
};
|
|
13882
|
+
OrderStatus.OPEN = {
|
|
13883
|
+
open: {}
|
|
13884
|
+
};
|
|
13885
|
+
OrderStatus.FILLED = {
|
|
13886
|
+
filled: {}
|
|
13887
|
+
};
|
|
13888
|
+
OrderStatus.CANCELED = {
|
|
13889
|
+
canceled: {}
|
|
13890
|
+
};
|
|
13891
|
+
class OrderAction {
|
|
13892
|
+
}
|
|
13893
|
+
OrderAction.PLACE = {
|
|
13894
|
+
place: {}
|
|
13895
|
+
};
|
|
13896
|
+
OrderAction.CANCEL = {
|
|
13897
|
+
cancel: {}
|
|
13898
|
+
};
|
|
13899
|
+
OrderAction.EXPIRE = {
|
|
13900
|
+
expire: {}
|
|
13901
|
+
};
|
|
13902
|
+
OrderAction.FILL = {
|
|
13903
|
+
fill: {}
|
|
13904
|
+
};
|
|
13905
|
+
OrderAction.TRIGGER = {
|
|
13906
|
+
trigger: {}
|
|
13907
|
+
};
|
|
13908
|
+
class OrderActionExplanation {
|
|
13909
|
+
}
|
|
13910
|
+
OrderActionExplanation.NONE = {
|
|
13911
|
+
none: {}
|
|
13912
|
+
};
|
|
13913
|
+
OrderActionExplanation.INSUFFICIENT_FREE_COLLATERAL = {
|
|
13914
|
+
insufficientFreeCollateral: {}
|
|
13915
|
+
};
|
|
13916
|
+
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
13917
|
+
oraclePriceBreachedLimitPrice: {}
|
|
13918
|
+
};
|
|
13919
|
+
OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
13920
|
+
marketOrderFilledToLimitPrice: {}
|
|
13921
|
+
};
|
|
13922
|
+
OrderActionExplanation.ORDER_EXPIRED = {
|
|
13923
|
+
orderExpired: {}
|
|
13924
|
+
};
|
|
13925
|
+
OrderActionExplanation.LIQUIDATION = {
|
|
13926
|
+
liquidation: {}
|
|
13927
|
+
};
|
|
13928
|
+
OrderActionExplanation.ORDER_FILLED_WITH_AMM = {
|
|
13929
|
+
orderFilledWithAmm: {}
|
|
13930
|
+
};
|
|
13931
|
+
OrderActionExplanation.ORDER_FILLED_WITH_AMM_JIT = {
|
|
13932
|
+
orderFilledWithAmmJit: {}
|
|
13933
|
+
};
|
|
13934
|
+
OrderActionExplanation.ORDER_FILLED_WITH_AMM_JIT_LP_SPLIT = {
|
|
13935
|
+
orderFilledWithAmmJitLpSplit: {}
|
|
13936
|
+
};
|
|
13937
|
+
OrderActionExplanation.ORDER_FILLED_WITH_LP_JIT = {
|
|
13938
|
+
orderFilledWithLpJit: {}
|
|
13939
|
+
};
|
|
13940
|
+
OrderActionExplanation.ORDER_FILLED_WITH_MATCH = {
|
|
13941
|
+
orderFilledWithMatch: {}
|
|
13942
|
+
};
|
|
13943
|
+
OrderActionExplanation.ORDER_FILLED_WITH_MATCH_JIT = {
|
|
13944
|
+
orderFilledWithMatchJit: {}
|
|
13945
|
+
};
|
|
13946
|
+
OrderActionExplanation.MARKET_EXPIRED = {
|
|
13947
|
+
marketExpired: {}
|
|
13948
|
+
};
|
|
13949
|
+
OrderActionExplanation.RISK_INCREASING_ORDER = {
|
|
13950
|
+
riskingIncreasingOrder: {}
|
|
13951
|
+
};
|
|
13952
|
+
OrderActionExplanation.ORDER_FILLED_WITH_SERUM = {
|
|
13953
|
+
orderFillWithSerum: {}
|
|
13954
|
+
};
|
|
13955
|
+
OrderActionExplanation.ORDER_FILLED_WITH_OPENBOOK_V2 = {
|
|
13956
|
+
orderFilledWithOpenbookV2: {}
|
|
13957
|
+
};
|
|
13958
|
+
OrderActionExplanation.ORDER_FILLED_WITH_PHOENIX = {
|
|
13959
|
+
orderFillWithPhoenix: {}
|
|
13960
|
+
};
|
|
13961
|
+
OrderActionExplanation.REDUCE_ONLY_ORDER_INCREASED_POSITION = {
|
|
13962
|
+
reduceOnlyOrderIncreasedPosition: {}
|
|
13963
|
+
};
|
|
13964
|
+
OrderActionExplanation.DERISK_LP = {
|
|
13965
|
+
deriskLp: {}
|
|
13966
|
+
};
|
|
13967
|
+
OrderActionExplanation.TRANSFER_PERP_POSITION = {
|
|
13968
|
+
transferPerpPosition: {}
|
|
13969
|
+
};
|
|
13970
|
+
class OrderTriggerCondition {
|
|
13971
|
+
}
|
|
13972
|
+
OrderTriggerCondition.ABOVE = {
|
|
13973
|
+
above: {}
|
|
13974
|
+
};
|
|
13975
|
+
OrderTriggerCondition.BELOW = {
|
|
13976
|
+
below: {}
|
|
13977
|
+
};
|
|
13978
|
+
OrderTriggerCondition.TRIGGERED_ABOVE = {
|
|
13979
|
+
triggeredAbove: {}
|
|
13980
|
+
} // above condition has been triggered
|
|
13981
|
+
;
|
|
13982
|
+
OrderTriggerCondition.TRIGGERED_BELOW = {
|
|
13983
|
+
triggeredBelow: {}
|
|
13984
|
+
} // below condition has been triggered
|
|
13985
|
+
;
|
|
13986
|
+
class SpotFulfillmentType {
|
|
13987
|
+
}
|
|
13988
|
+
SpotFulfillmentType.EXTERNAL = {
|
|
13989
|
+
external: {}
|
|
13990
|
+
};
|
|
13991
|
+
SpotFulfillmentType.MATCH = {
|
|
13992
|
+
match: {}
|
|
13993
|
+
};
|
|
13994
|
+
class SpotFulfillmentStatus {
|
|
13995
|
+
}
|
|
13996
|
+
SpotFulfillmentStatus.ENABLED = {
|
|
13997
|
+
enabled: {}
|
|
13998
|
+
};
|
|
13999
|
+
SpotFulfillmentStatus.DISABLED = {
|
|
14000
|
+
disabled: {}
|
|
14001
|
+
};
|
|
14002
|
+
class DepositExplanation {
|
|
14003
|
+
}
|
|
14004
|
+
DepositExplanation.NONE = {
|
|
14005
|
+
none: {}
|
|
14006
|
+
};
|
|
14007
|
+
DepositExplanation.TRANSFER = {
|
|
14008
|
+
transfer: {}
|
|
14009
|
+
};
|
|
14010
|
+
DepositExplanation.BORROW = {
|
|
14011
|
+
borrow: {}
|
|
14012
|
+
};
|
|
14013
|
+
DepositExplanation.REPAY_BORROW = {
|
|
14014
|
+
repayBorrow: {}
|
|
14015
|
+
};
|
|
14016
|
+
class SettlePnlExplanation {
|
|
14017
|
+
}
|
|
14018
|
+
SettlePnlExplanation.NONE = {
|
|
14019
|
+
none: {}
|
|
14020
|
+
};
|
|
14021
|
+
SettlePnlExplanation.EXPIRED_POSITION = {
|
|
14022
|
+
expiredPosition: {}
|
|
14023
|
+
};
|
|
14024
|
+
class SpotFulfillmentConfigStatus {
|
|
14025
|
+
}
|
|
14026
|
+
SpotFulfillmentConfigStatus.ENABLED = {
|
|
14027
|
+
enabled: {}
|
|
14028
|
+
};
|
|
14029
|
+
SpotFulfillmentConfigStatus.DISABLED = {
|
|
14030
|
+
disabled: {}
|
|
14031
|
+
};
|
|
14032
|
+
class StakeAction {
|
|
14033
|
+
}
|
|
14034
|
+
StakeAction.STAKE = {
|
|
14035
|
+
stake: {}
|
|
14036
|
+
};
|
|
14037
|
+
StakeAction.UNSTAKE_REQUEST = {
|
|
14038
|
+
unstakeRequest: {}
|
|
14039
|
+
};
|
|
14040
|
+
StakeAction.UNSTAKE_CANCEL_REQUEST = {
|
|
14041
|
+
unstakeCancelRequest: {}
|
|
14042
|
+
};
|
|
14043
|
+
StakeAction.UNSTAKE = {
|
|
14044
|
+
unstake: {}
|
|
14045
|
+
};
|
|
14046
|
+
StakeAction.UNSTAKE_TRANSFER = {
|
|
14047
|
+
unstakeTransfer: {}
|
|
14048
|
+
};
|
|
14049
|
+
StakeAction.STAKE_TRANSFER = {
|
|
14050
|
+
stakeTransfer: {}
|
|
14051
|
+
};
|
|
14052
|
+
class SettlePnlMode {
|
|
14053
|
+
}
|
|
14054
|
+
SettlePnlMode.TRY_SETTLE = {
|
|
14055
|
+
trySettle: {}
|
|
14056
|
+
};
|
|
14057
|
+
SettlePnlMode.MUST_SETTLE = {
|
|
14058
|
+
mustSettle: {}
|
|
14059
|
+
};
|
|
14060
|
+
function isVariant(object, type) {
|
|
14061
|
+
return object.hasOwnProperty(type);
|
|
14062
|
+
}
|
|
14063
|
+
function isOneOfVariant(object, types) {
|
|
14064
|
+
return types.reduce((result, type)=>{
|
|
14065
|
+
return result || object.hasOwnProperty(type);
|
|
14066
|
+
}, false);
|
|
14067
|
+
}
|
|
14068
|
+
function getVariant(object) {
|
|
14069
|
+
return Object.keys(object)[0];
|
|
14070
|
+
}
|
|
14071
|
+
var TradeSide = /*#__PURE__*/ function(TradeSide) {
|
|
14072
|
+
TradeSide[TradeSide["None"] = 0] = "None";
|
|
14073
|
+
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
14074
|
+
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
14075
|
+
return TradeSide;
|
|
14076
|
+
}({});
|
|
14077
|
+
class LPAction {
|
|
14078
|
+
}
|
|
14079
|
+
LPAction.ADD_LIQUIDITY = {
|
|
14080
|
+
addLiquidity: {}
|
|
14081
|
+
};
|
|
14082
|
+
LPAction.REMOVE_LIQUIDITY = {
|
|
14083
|
+
removeLiquidity: {}
|
|
14084
|
+
};
|
|
14085
|
+
LPAction.SETTLE_LIQUIDITY = {
|
|
14086
|
+
settleLiquidity: {}
|
|
14087
|
+
};
|
|
14088
|
+
LPAction.REMOVE_LIQUIDITY_DERISK = {
|
|
14089
|
+
removeLiquidityDerisk: {}
|
|
14090
|
+
};
|
|
14091
|
+
class LiquidationType {
|
|
14092
|
+
}
|
|
14093
|
+
LiquidationType.LIQUIDATE_PERP = {
|
|
14094
|
+
liquidatePerp: {}
|
|
14095
|
+
};
|
|
14096
|
+
LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
|
|
14097
|
+
liquidateBorrowForPerpPnl: {}
|
|
14098
|
+
};
|
|
14099
|
+
LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
14100
|
+
liquidatePerpPnlForDeposit: {}
|
|
14101
|
+
};
|
|
14102
|
+
LiquidationType.PERP_BANKRUPTCY = {
|
|
14103
|
+
perpBankruptcy: {}
|
|
14104
|
+
};
|
|
14105
|
+
LiquidationType.SPOT_BANKRUPTCY = {
|
|
14106
|
+
spotBankruptcy: {}
|
|
14107
|
+
};
|
|
14108
|
+
LiquidationType.LIQUIDATE_SPOT = {
|
|
14109
|
+
liquidateSpot: {}
|
|
14110
|
+
};
|
|
14111
|
+
class PostOnlyParams {
|
|
14112
|
+
}
|
|
14113
|
+
PostOnlyParams.NONE = {
|
|
14114
|
+
none: {}
|
|
14115
|
+
};
|
|
14116
|
+
PostOnlyParams.MUST_POST_ONLY = {
|
|
14117
|
+
mustPostOnly: {}
|
|
14118
|
+
} // Tx fails if order can't be post only
|
|
14119
|
+
;
|
|
14120
|
+
PostOnlyParams.TRY_POST_ONLY = {
|
|
14121
|
+
tryPostOnly: {}
|
|
14122
|
+
} // Tx succeeds and order not placed if can't be post only
|
|
14123
|
+
;
|
|
14124
|
+
PostOnlyParams.SLIDE = {
|
|
14125
|
+
slide: {}
|
|
14126
|
+
} // Modify price to be post only if can't be post only
|
|
14127
|
+
;
|
|
14128
|
+
var ModifyOrderPolicy = /*#__PURE__*/ function(ModifyOrderPolicy) {
|
|
14129
|
+
ModifyOrderPolicy[ModifyOrderPolicy["MustModify"] = 1] = "MustModify";
|
|
14130
|
+
ModifyOrderPolicy[ModifyOrderPolicy["ExcludePreviousFill"] = 2] = "ExcludePreviousFill";
|
|
14131
|
+
return ModifyOrderPolicy;
|
|
14132
|
+
}({});
|
|
14133
|
+
const DefaultOrderParams = {
|
|
14134
|
+
orderType: OrderType.MARKET,
|
|
14135
|
+
marketType: MarketType.PERP,
|
|
14136
|
+
userOrderId: 0,
|
|
14137
|
+
direction: PositionDirection.LONG,
|
|
14138
|
+
baseAssetAmount: ZERO,
|
|
14139
|
+
price: ZERO,
|
|
14140
|
+
marketIndex: 0,
|
|
14141
|
+
reduceOnly: false,
|
|
14142
|
+
postOnly: PostOnlyParams.NONE,
|
|
14143
|
+
immediateOrCancel: false,
|
|
14144
|
+
triggerPrice: null,
|
|
14145
|
+
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
14146
|
+
oraclePriceOffset: null,
|
|
14147
|
+
auctionDuration: null,
|
|
14148
|
+
maxTs: null,
|
|
14149
|
+
auctionStartPrice: null,
|
|
14150
|
+
auctionEndPrice: null
|
|
14151
|
+
};
|
|
14152
|
+
var ReferrerStatus = /*#__PURE__*/ function(ReferrerStatus) {
|
|
14153
|
+
ReferrerStatus[ReferrerStatus["IsReferrer"] = 1] = "IsReferrer";
|
|
14154
|
+
ReferrerStatus[ReferrerStatus["IsReferred"] = 2] = "IsReferred";
|
|
14155
|
+
return ReferrerStatus;
|
|
14156
|
+
}({});
|
|
14157
|
+
var FuelOverflowStatus = /*#__PURE__*/ function(FuelOverflowStatus) {
|
|
14158
|
+
FuelOverflowStatus[FuelOverflowStatus["Exists"] = 1] = "Exists";
|
|
14159
|
+
return FuelOverflowStatus;
|
|
14160
|
+
}({});
|
|
14161
|
+
var PlaceAndTakeOrderSuccessCondition = /*#__PURE__*/ function(PlaceAndTakeOrderSuccessCondition) {
|
|
14162
|
+
PlaceAndTakeOrderSuccessCondition[PlaceAndTakeOrderSuccessCondition["PartialFill"] = 1] = "PartialFill";
|
|
14163
|
+
PlaceAndTakeOrderSuccessCondition[PlaceAndTakeOrderSuccessCondition["FullFill"] = 2] = "FullFill";
|
|
14164
|
+
return PlaceAndTakeOrderSuccessCondition;
|
|
14165
|
+
}({});
|
|
14166
|
+
class SwapReduceOnly {
|
|
14167
|
+
}
|
|
14168
|
+
SwapReduceOnly.In = {
|
|
14169
|
+
in: {}
|
|
14170
|
+
};
|
|
14171
|
+
SwapReduceOnly.Out = {
|
|
14172
|
+
out: {}
|
|
14173
|
+
};
|
|
14174
|
+
|
|
14175
|
+
function readUnsignedBigInt64LE(buffer, offset) {
|
|
14176
|
+
return new anchor.BN(buffer.subarray(offset, offset + 8), 10, "le");
|
|
14177
|
+
}
|
|
14178
|
+
function readSignedBigInt64LE(buffer, offset) {
|
|
14179
|
+
const unsignedValue = new anchor.BN(buffer.subarray(offset, offset + 8), 10, "le");
|
|
14180
|
+
if (unsignedValue.testn(63)) {
|
|
14181
|
+
const inverted = unsignedValue.notn(64).addn(1);
|
|
14182
|
+
return inverted.neg();
|
|
14183
|
+
} else {
|
|
14184
|
+
return unsignedValue;
|
|
14185
|
+
}
|
|
14186
|
+
}
|
|
14187
|
+
function decodeUser(buffer) {
|
|
14188
|
+
let offset = 8;
|
|
14189
|
+
const authority = new web3_js.PublicKey(buffer.slice(offset, offset + 32));
|
|
14190
|
+
offset += 32;
|
|
14191
|
+
const delegate = new web3_js.PublicKey(buffer.slice(offset, offset + 32));
|
|
14192
|
+
offset += 32;
|
|
14193
|
+
const name = [];
|
|
14194
|
+
for(let i = 0; i < 32; i++){
|
|
14195
|
+
name.push(buffer.readUint8(offset + i));
|
|
14196
|
+
}
|
|
14197
|
+
offset += 32;
|
|
14198
|
+
const spotPositions = [];
|
|
14199
|
+
for(let i = 0; i < 8; i++){
|
|
14200
|
+
const scaledBalance = readUnsignedBigInt64LE(buffer, offset);
|
|
14201
|
+
const openOrders = buffer.readUInt8(offset + 35);
|
|
14202
|
+
if (scaledBalance.eq(ZERO) && openOrders === 0) {
|
|
14203
|
+
offset += 40;
|
|
14204
|
+
continue;
|
|
14205
|
+
}
|
|
14206
|
+
offset += 8;
|
|
14207
|
+
const openBids = readSignedBigInt64LE(buffer, offset);
|
|
14208
|
+
offset += 8;
|
|
14209
|
+
const openAsks = readSignedBigInt64LE(buffer, offset);
|
|
14210
|
+
offset += 8;
|
|
14211
|
+
const cumulativeDeposits = readSignedBigInt64LE(buffer, offset);
|
|
14212
|
+
offset += 8;
|
|
14213
|
+
const marketIndex = buffer.readUInt16LE(offset);
|
|
14214
|
+
offset += 2;
|
|
14215
|
+
const balanceTypeNum = buffer.readUInt8(offset);
|
|
14216
|
+
let balanceType;
|
|
14217
|
+
if (balanceTypeNum === 0) {
|
|
14218
|
+
balanceType = SpotBalanceType.DEPOSIT;
|
|
14219
|
+
} else {
|
|
14220
|
+
balanceType = SpotBalanceType.BORROW;
|
|
14221
|
+
}
|
|
14222
|
+
offset += 6;
|
|
14223
|
+
spotPositions.push({
|
|
14224
|
+
scaledBalance,
|
|
14225
|
+
openBids,
|
|
14226
|
+
openAsks,
|
|
14227
|
+
cumulativeDeposits,
|
|
14228
|
+
marketIndex,
|
|
14229
|
+
balanceType,
|
|
14230
|
+
openOrders
|
|
14231
|
+
});
|
|
14232
|
+
}
|
|
14233
|
+
const perpPositions = [];
|
|
14234
|
+
for(let i = 0; i < 8; i++){
|
|
14235
|
+
const baseAssetAmount = readSignedBigInt64LE(buffer, offset + 8);
|
|
14236
|
+
const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
|
|
14237
|
+
const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
|
|
14238
|
+
const openOrders = buffer.readUInt8(offset + 94);
|
|
14239
|
+
if (baseAssetAmount.eq(ZERO) && openOrders === 0 && quoteAssetAmount.eq(ZERO) && lpShares.eq(ZERO)) {
|
|
14240
|
+
offset += 96;
|
|
14241
|
+
continue;
|
|
14242
|
+
}
|
|
14243
|
+
const lastCumulativeFundingRate = readSignedBigInt64LE(buffer, offset);
|
|
14244
|
+
offset += 24;
|
|
14245
|
+
const quoteBreakEvenAmount = readSignedBigInt64LE(buffer, offset);
|
|
14246
|
+
offset += 8;
|
|
14247
|
+
const quoteEntryAmount = readSignedBigInt64LE(buffer, offset);
|
|
14248
|
+
offset += 8;
|
|
14249
|
+
const openBids = readSignedBigInt64LE(buffer, offset);
|
|
14250
|
+
offset += 8;
|
|
14251
|
+
const openAsks = readSignedBigInt64LE(buffer, offset);
|
|
14252
|
+
offset += 8;
|
|
14253
|
+
const settledPnl = readSignedBigInt64LE(buffer, offset);
|
|
14254
|
+
offset += 16;
|
|
14255
|
+
const lastBaseAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
14256
|
+
offset += 8;
|
|
14257
|
+
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
14258
|
+
offset += 8;
|
|
14259
|
+
const remainderBaseAssetAmount = buffer.readInt32LE(offset);
|
|
14260
|
+
offset += 4;
|
|
14261
|
+
const marketIndex = buffer.readUInt16LE(offset);
|
|
14262
|
+
offset += 3;
|
|
14263
|
+
const perLpBase = buffer.readUInt8(offset);
|
|
14264
|
+
offset += 1;
|
|
14265
|
+
perpPositions.push({
|
|
14266
|
+
lastCumulativeFundingRate,
|
|
14267
|
+
baseAssetAmount,
|
|
14268
|
+
quoteAssetAmount,
|
|
14269
|
+
quoteBreakEvenAmount,
|
|
14270
|
+
quoteEntryAmount,
|
|
14271
|
+
openBids,
|
|
14272
|
+
openAsks,
|
|
14273
|
+
settledPnl,
|
|
14274
|
+
lpShares,
|
|
14275
|
+
lastBaseAssetAmountPerLp,
|
|
14276
|
+
lastQuoteAssetAmountPerLp,
|
|
14277
|
+
remainderBaseAssetAmount,
|
|
14278
|
+
marketIndex,
|
|
14279
|
+
openOrders,
|
|
14280
|
+
perLpBase
|
|
14281
|
+
});
|
|
14282
|
+
}
|
|
14283
|
+
const orders = [];
|
|
14284
|
+
for(let i = 0; i < 32; i++){
|
|
14285
|
+
// skip order if it's not open
|
|
14286
|
+
if (buffer.readUint8(offset + 82) !== 1) {
|
|
14287
|
+
offset += 96;
|
|
14288
|
+
continue;
|
|
14289
|
+
}
|
|
14290
|
+
const slot = readUnsignedBigInt64LE(buffer, offset);
|
|
14291
|
+
offset += 8;
|
|
14292
|
+
const price = readUnsignedBigInt64LE(buffer, offset);
|
|
14293
|
+
offset += 8;
|
|
14294
|
+
const baseAssetAmount = readUnsignedBigInt64LE(buffer, offset);
|
|
14295
|
+
offset += 8;
|
|
14296
|
+
const baseAssetAmountFilled = readUnsignedBigInt64LE(buffer, offset);
|
|
14297
|
+
offset += 8;
|
|
14298
|
+
const quoteAssetAmountFilled = readUnsignedBigInt64LE(buffer, offset);
|
|
14299
|
+
offset += 8;
|
|
14300
|
+
const triggerPrice = readUnsignedBigInt64LE(buffer, offset);
|
|
14301
|
+
offset += 8;
|
|
14302
|
+
const auctionStartPrice = readSignedBigInt64LE(buffer, offset);
|
|
14303
|
+
offset += 8;
|
|
14304
|
+
const auctionEndPrice = readSignedBigInt64LE(buffer, offset);
|
|
14305
|
+
offset += 8;
|
|
14306
|
+
const maxTs = readSignedBigInt64LE(buffer, offset);
|
|
14307
|
+
offset += 8;
|
|
14308
|
+
const oraclePriceOffset = buffer.readInt32LE(offset);
|
|
14309
|
+
offset += 4;
|
|
14310
|
+
const orderId = buffer.readUInt32LE(offset);
|
|
14311
|
+
offset += 4;
|
|
14312
|
+
const marketIndex = buffer.readUInt16LE(offset);
|
|
14313
|
+
offset += 2;
|
|
14314
|
+
const orderStatusNum = buffer.readUInt8(offset);
|
|
14315
|
+
let status = OrderStatus.INIT;
|
|
14316
|
+
if (orderStatusNum === 0) {
|
|
14317
|
+
status = OrderStatus.INIT;
|
|
14318
|
+
} else if (orderStatusNum === 1) {
|
|
14319
|
+
status = OrderStatus.OPEN;
|
|
14320
|
+
} else if (orderStatusNum === 2) {
|
|
14321
|
+
status = OrderStatus.FILLED;
|
|
14322
|
+
} else if (orderStatusNum === 3) {
|
|
14323
|
+
status = OrderStatus.CANCELED;
|
|
14324
|
+
}
|
|
14325
|
+
offset += 1;
|
|
14326
|
+
const orderTypeNum = buffer.readUInt8(offset);
|
|
14327
|
+
let orderType = OrderType.MARKET;
|
|
14328
|
+
if (orderTypeNum === 0) {
|
|
14329
|
+
orderType = OrderType.MARKET;
|
|
14330
|
+
} else if (orderTypeNum === 1) {
|
|
14331
|
+
orderType = OrderType.LIMIT;
|
|
14332
|
+
} else if (orderTypeNum === 2) {
|
|
14333
|
+
orderType = OrderType.TRIGGER_MARKET;
|
|
14334
|
+
} else if (orderTypeNum === 3) {
|
|
14335
|
+
orderType = OrderType.TRIGGER_LIMIT;
|
|
14336
|
+
} else if (orderTypeNum === 4) {
|
|
14337
|
+
orderType = OrderType.ORACLE;
|
|
14338
|
+
}
|
|
14339
|
+
offset += 1;
|
|
14340
|
+
const marketTypeNum = buffer.readUInt8(offset);
|
|
14341
|
+
let marketType;
|
|
14342
|
+
if (marketTypeNum === 0) {
|
|
14343
|
+
marketType = MarketType.SPOT;
|
|
14344
|
+
} else {
|
|
14345
|
+
marketType = MarketType.PERP;
|
|
14346
|
+
}
|
|
14347
|
+
offset += 1;
|
|
14348
|
+
const userOrderId = buffer.readUint8(offset);
|
|
14349
|
+
offset += 1;
|
|
14350
|
+
const existingPositionDirectionNum = buffer.readUInt8(offset);
|
|
14351
|
+
let existingPositionDirection;
|
|
14352
|
+
if (existingPositionDirectionNum === 0) {
|
|
14353
|
+
existingPositionDirection = PositionDirection.LONG;
|
|
14354
|
+
} else {
|
|
14355
|
+
existingPositionDirection = PositionDirection.SHORT;
|
|
14356
|
+
}
|
|
14357
|
+
offset += 1;
|
|
14358
|
+
const positionDirectionNum = buffer.readUInt8(offset);
|
|
14359
|
+
let direction;
|
|
14360
|
+
if (positionDirectionNum === 0) {
|
|
14361
|
+
direction = PositionDirection.LONG;
|
|
14362
|
+
} else {
|
|
14363
|
+
direction = PositionDirection.SHORT;
|
|
14364
|
+
}
|
|
14365
|
+
offset += 1;
|
|
14366
|
+
const reduceOnly = buffer.readUInt8(offset) === 1;
|
|
14367
|
+
offset += 1;
|
|
14368
|
+
const postOnly = buffer.readUInt8(offset) === 1;
|
|
14369
|
+
offset += 1;
|
|
14370
|
+
const immediateOrCancel = buffer.readUInt8(offset) === 1;
|
|
14371
|
+
offset += 1;
|
|
14372
|
+
const triggerConditionNum = buffer.readUInt8(offset);
|
|
14373
|
+
let triggerCondition = OrderTriggerCondition.ABOVE;
|
|
14374
|
+
if (triggerConditionNum === 0) {
|
|
14375
|
+
triggerCondition = OrderTriggerCondition.ABOVE;
|
|
14376
|
+
} else if (triggerConditionNum === 1) {
|
|
14377
|
+
triggerCondition = OrderTriggerCondition.BELOW;
|
|
14378
|
+
} else if (triggerConditionNum === 2) {
|
|
14379
|
+
triggerCondition = OrderTriggerCondition.TRIGGERED_ABOVE;
|
|
14380
|
+
} else if (triggerConditionNum === 3) {
|
|
14381
|
+
triggerCondition = OrderTriggerCondition.TRIGGERED_BELOW;
|
|
14382
|
+
}
|
|
14383
|
+
offset += 1;
|
|
14384
|
+
const auctionDuration = buffer.readUInt8(offset);
|
|
14385
|
+
offset += 1;
|
|
14386
|
+
const postedSlotTail = buffer.readUint8(offset);
|
|
14387
|
+
offset += 1;
|
|
14388
|
+
const bitFlags = buffer.readUint8(offset);
|
|
14389
|
+
offset += 1;
|
|
14390
|
+
offset += 1; // padding
|
|
14391
|
+
orders.push({
|
|
14392
|
+
slot,
|
|
14393
|
+
price,
|
|
14394
|
+
baseAssetAmount,
|
|
14395
|
+
quoteAssetAmount: undefined,
|
|
14396
|
+
baseAssetAmountFilled,
|
|
14397
|
+
quoteAssetAmountFilled,
|
|
14398
|
+
triggerPrice,
|
|
14399
|
+
auctionStartPrice,
|
|
14400
|
+
auctionEndPrice,
|
|
14401
|
+
maxTs,
|
|
14402
|
+
oraclePriceOffset,
|
|
14403
|
+
orderId,
|
|
14404
|
+
marketIndex,
|
|
14405
|
+
status,
|
|
14406
|
+
orderType,
|
|
14407
|
+
marketType,
|
|
14408
|
+
userOrderId,
|
|
14409
|
+
existingPositionDirection,
|
|
14410
|
+
direction,
|
|
14411
|
+
reduceOnly,
|
|
14412
|
+
postOnly,
|
|
14413
|
+
immediateOrCancel,
|
|
14414
|
+
triggerCondition,
|
|
14415
|
+
auctionDuration,
|
|
14416
|
+
bitFlags,
|
|
14417
|
+
postedSlotTail
|
|
14418
|
+
});
|
|
14419
|
+
}
|
|
14420
|
+
const lastAddPerpLpSharesTs = readSignedBigInt64LE(buffer, offset);
|
|
14421
|
+
offset += 8;
|
|
14422
|
+
const totalDeposits = readUnsignedBigInt64LE(buffer, offset);
|
|
14423
|
+
offset += 8;
|
|
14424
|
+
const totalWithdraws = readUnsignedBigInt64LE(buffer, offset);
|
|
14425
|
+
offset += 8;
|
|
14426
|
+
const totalSocialLoss = readUnsignedBigInt64LE(buffer, offset);
|
|
14427
|
+
offset += 8;
|
|
14428
|
+
const settledPerpPnl = readSignedBigInt64LE(buffer, offset);
|
|
14429
|
+
offset += 8;
|
|
14430
|
+
const cumulativeSpotFees = readSignedBigInt64LE(buffer, offset);
|
|
14431
|
+
offset += 8;
|
|
14432
|
+
const cumulativePerpFunding = readSignedBigInt64LE(buffer, offset);
|
|
14433
|
+
offset += 8;
|
|
14434
|
+
const liquidationMarginFreed = readUnsignedBigInt64LE(buffer, offset);
|
|
14435
|
+
offset += 8;
|
|
14436
|
+
const lastActiveSlot = readUnsignedBigInt64LE(buffer, offset);
|
|
14437
|
+
offset += 8;
|
|
14438
|
+
const nextOrderId = buffer.readUInt32LE(offset);
|
|
14439
|
+
offset += 4;
|
|
14440
|
+
const maxMarginRatio = buffer.readUInt32LE(offset);
|
|
14441
|
+
offset += 4;
|
|
14442
|
+
const nextLiquidationId = buffer.readUInt16LE(offset);
|
|
14443
|
+
offset += 2;
|
|
14444
|
+
const subAccountId = buffer.readUInt16LE(offset);
|
|
14445
|
+
offset += 2;
|
|
14446
|
+
const status = buffer.readUInt8(offset);
|
|
14447
|
+
offset += 1;
|
|
14448
|
+
const isMarginTradingEnabled = buffer.readUInt8(offset) === 1;
|
|
14449
|
+
offset += 1;
|
|
14450
|
+
const idle = buffer.readUInt8(offset) === 1;
|
|
14451
|
+
offset += 1;
|
|
14452
|
+
const openOrders = buffer.readUInt8(offset);
|
|
14453
|
+
offset += 1;
|
|
14454
|
+
const hasOpenOrder = buffer.readUInt8(offset) === 1;
|
|
14455
|
+
offset += 1;
|
|
14456
|
+
const openAuctions = buffer.readUInt8(offset);
|
|
14457
|
+
offset += 1;
|
|
14458
|
+
const hasOpenAuction = buffer.readUInt8(offset) === 1;
|
|
14459
|
+
offset += 1;
|
|
14460
|
+
let marginMode;
|
|
14461
|
+
const marginModeNum = buffer.readUInt8(offset);
|
|
14462
|
+
if (marginModeNum === 0) {
|
|
14463
|
+
marginMode = MarginMode.DEFAULT;
|
|
14464
|
+
} else {
|
|
14465
|
+
marginMode = MarginMode.HIGH_LEVERAGE;
|
|
14466
|
+
}
|
|
14467
|
+
offset += 1;
|
|
14468
|
+
const poolId = buffer.readUint8(offset);
|
|
14469
|
+
offset += 1;
|
|
14470
|
+
offset += 3; // padding
|
|
14471
|
+
const lastFuelBonusUpdateTs = buffer.readUint32LE(offset);
|
|
14472
|
+
offset += 4;
|
|
14473
|
+
return {
|
|
14474
|
+
authority,
|
|
14475
|
+
delegate,
|
|
14476
|
+
name,
|
|
14477
|
+
spotPositions,
|
|
14478
|
+
perpPositions,
|
|
14479
|
+
orders,
|
|
14480
|
+
lastAddPerpLpSharesTs,
|
|
14481
|
+
totalDeposits,
|
|
14482
|
+
totalWithdraws,
|
|
14483
|
+
totalSocialLoss,
|
|
14484
|
+
settledPerpPnl,
|
|
14485
|
+
cumulativeSpotFees,
|
|
14486
|
+
cumulativePerpFunding,
|
|
14487
|
+
liquidationMarginFreed,
|
|
14488
|
+
lastActiveSlot,
|
|
14489
|
+
nextOrderId,
|
|
14490
|
+
maxMarginRatio,
|
|
14491
|
+
nextLiquidationId,
|
|
14492
|
+
subAccountId,
|
|
14493
|
+
status,
|
|
14494
|
+
isMarginTradingEnabled,
|
|
14495
|
+
idle,
|
|
14496
|
+
openOrders,
|
|
14497
|
+
hasOpenOrder,
|
|
14498
|
+
openAuctions,
|
|
14499
|
+
hasOpenAuction,
|
|
14500
|
+
marginMode,
|
|
14501
|
+
poolId,
|
|
14502
|
+
lastFuelBonusUpdateTs
|
|
14503
|
+
};
|
|
14504
|
+
}
|
|
14505
|
+
|
|
14506
|
+
const DRIFT_SIGNER = new web3_js.PublicKey("JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw");
|
|
13598
14507
|
const DRIFT_MARGIN_PRECISION = 10000;
|
|
13599
14508
|
class DriftClient {
|
|
13600
14509
|
/*
|
|
@@ -13619,83 +14528,268 @@ class DriftClient {
|
|
|
13619
14528
|
const tx = await this.deleteUserTx(new web3_js.PublicKey(statePda), subAccountId, txOptions);
|
|
13620
14529
|
return await this.base.sendAndConfirm(tx);
|
|
13621
14530
|
}
|
|
13622
|
-
async deposit(statePda, amount, marketIndex = 1, subAccountId = 0,
|
|
13623
|
-
const tx = await this.depositTx(new web3_js.PublicKey(statePda), amount, marketIndex, subAccountId,
|
|
14531
|
+
async deposit(statePda, amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
14532
|
+
const tx = await this.depositTx(new web3_js.PublicKey(statePda), amount, marketIndex, subAccountId, txOptions);
|
|
13624
14533
|
return await this.base.sendAndConfirm(tx);
|
|
13625
14534
|
}
|
|
13626
|
-
async withdraw(statePda, amount, marketIndex = 1, subAccountId = 0,
|
|
13627
|
-
const tx = await this.withdrawTx(new web3_js.PublicKey(statePda), amount, marketIndex, subAccountId,
|
|
14535
|
+
async withdraw(statePda, amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
14536
|
+
const tx = await this.withdrawTx(new web3_js.PublicKey(statePda), amount, marketIndex, subAccountId, txOptions);
|
|
13628
14537
|
return await this.base.sendAndConfirm(tx);
|
|
13629
14538
|
}
|
|
13630
|
-
async placeOrder(statePda, orderParams, subAccountId = 0,
|
|
13631
|
-
const tx = await this.placeOrderTx(new web3_js.PublicKey(statePda), orderParams, subAccountId,
|
|
14539
|
+
async placeOrder(statePda, orderParams, subAccountId = 0, txOptions = {}) {
|
|
14540
|
+
const tx = await this.placeOrderTx(new web3_js.PublicKey(statePda), orderParams, subAccountId, txOptions);
|
|
13632
14541
|
return await this.base.sendAndConfirm(tx);
|
|
13633
14542
|
}
|
|
13634
|
-
async modifyOrder(statePda, modifyOrderParams, subAccountId = 0,
|
|
13635
|
-
const tx = await this.modifyOrderTx(new web3_js.PublicKey(statePda), modifyOrderParams, subAccountId,
|
|
14543
|
+
async modifyOrder(statePda, modifyOrderParams, subAccountId = 0, txOptions = {}) {
|
|
14544
|
+
const tx = await this.modifyOrderTx(new web3_js.PublicKey(statePda), modifyOrderParams, subAccountId, txOptions);
|
|
13636
14545
|
return await this.base.sendAndConfirm(tx);
|
|
13637
14546
|
}
|
|
13638
|
-
async cancelOrders(statePda, marketType, marketIndex, direction, subAccountId = 0,
|
|
13639
|
-
const tx = await this.cancelOrdersTx(new web3_js.PublicKey(statePda), marketType, marketIndex, direction, subAccountId,
|
|
14547
|
+
async cancelOrders(statePda, marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
|
|
14548
|
+
const tx = await this.cancelOrdersTx(new web3_js.PublicKey(statePda), marketType, marketIndex, direction, subAccountId, txOptions);
|
|
13640
14549
|
return await this.base.sendAndConfirm(tx);
|
|
13641
14550
|
}
|
|
13642
|
-
async cancelOrdersByIds(statePda, orderIds, subAccountId = 0,
|
|
13643
|
-
const tx = await this.cancelOrdersByIdsTx(new web3_js.PublicKey(statePda), orderIds, subAccountId,
|
|
14551
|
+
async cancelOrdersByIds(statePda, orderIds, subAccountId = 0, txOptions = {}) {
|
|
14552
|
+
const tx = await this.cancelOrdersByIdsTx(new web3_js.PublicKey(statePda), orderIds, subAccountId, txOptions);
|
|
13644
14553
|
return await this.base.sendAndConfirm(tx);
|
|
13645
14554
|
}
|
|
13646
|
-
async settlePnl(statePda, marketIndex, subAccountId = 0,
|
|
13647
|
-
const tx = await this.settlePnlTx(new web3_js.PublicKey(statePda), marketIndex, subAccountId,
|
|
14555
|
+
async settlePnl(statePda, marketIndex, subAccountId = 0, txOptions = {}) {
|
|
14556
|
+
const tx = await this.settlePnlTx(new web3_js.PublicKey(statePda), marketIndex, subAccountId, txOptions);
|
|
13648
14557
|
return await this.base.sendAndConfirm(tx);
|
|
13649
14558
|
}
|
|
13650
|
-
async priceDrift(statePda,
|
|
13651
|
-
const tx = await this.priceDriftTx(new web3_js.PublicKey(statePda),
|
|
14559
|
+
async priceDrift(statePda, priceDenom, txOptions = {}) {
|
|
14560
|
+
const tx = await this.priceDriftTx(new web3_js.PublicKey(statePda), priceDenom, txOptions);
|
|
13652
14561
|
return await this.base.sendAndConfirm(tx);
|
|
13653
14562
|
}
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
14563
|
+
getGlamReferrerPdas() {
|
|
14564
|
+
return {
|
|
14565
|
+
user: this.getUserPda(GLAM_REFERRER, 0),
|
|
14566
|
+
userStats: this.getUserStatsPda(GLAM_REFERRER)
|
|
14567
|
+
};
|
|
14568
|
+
}
|
|
14569
|
+
parsePerpMarket(data) {
|
|
14570
|
+
const marketPda = new web3_js.PublicKey(data.subarray(8, 40));
|
|
14571
|
+
const oracle = new web3_js.PublicKey(data.subarray(40, 72));
|
|
14572
|
+
const name = this.charsToName(data.subarray(1000, 1032));
|
|
14573
|
+
const oralceEnum = data.subarray(926, 927).readUint8();
|
|
14574
|
+
const oracleSource = OracleSource.get(oralceEnum);
|
|
14575
|
+
const marketIndex = data.subarray(1160, 1162).readUint16LE();
|
|
14576
|
+
return {
|
|
14577
|
+
name,
|
|
14578
|
+
marketPda,
|
|
14579
|
+
marketIndex,
|
|
14580
|
+
oracle,
|
|
14581
|
+
oracleSource
|
|
14582
|
+
};
|
|
14583
|
+
}
|
|
14584
|
+
parseSpotMarket(data) {
|
|
14585
|
+
const marketPda = new web3_js.PublicKey(data.subarray(8, 40));
|
|
14586
|
+
const oracle = new web3_js.PublicKey(data.subarray(40, 72));
|
|
14587
|
+
const mint = new web3_js.PublicKey(data.subarray(72, 104));
|
|
14588
|
+
const vault = new web3_js.PublicKey(data.subarray(104, 136));
|
|
14589
|
+
const name = this.charsToName(data.subarray(136, 168));
|
|
14590
|
+
const cumulativeDepositInterest = new anchor.BN(data.subarray(464, 480), "le");
|
|
14591
|
+
const cumulativeBorrowInterest = new anchor.BN(data.subarray(480, 496), "le");
|
|
14592
|
+
const decimals = data.subarray(680, 684).readUint32LE();
|
|
14593
|
+
const marketIndex = data.subarray(684, 686).readUint16LE();
|
|
14594
|
+
const oralceEnum = data.subarray(687, 688).readUint8();
|
|
14595
|
+
const oracleSource = OracleSource.get(oralceEnum);
|
|
14596
|
+
const tokenProgram = data.subarray(734, 735).readUint8() == 0 ? splToken.TOKEN_PROGRAM_ID : splToken.TOKEN_2022_PROGRAM_ID;
|
|
14597
|
+
return {
|
|
14598
|
+
name,
|
|
14599
|
+
marketIndex,
|
|
14600
|
+
marketPda,
|
|
14601
|
+
oracle,
|
|
14602
|
+
oracleSource,
|
|
14603
|
+
vault,
|
|
14604
|
+
mint,
|
|
14605
|
+
decimals,
|
|
14606
|
+
tokenProgram,
|
|
14607
|
+
cumulativeDepositInterest,
|
|
14608
|
+
cumulativeBorrowInterest
|
|
14609
|
+
};
|
|
14610
|
+
}
|
|
14611
|
+
async calcSpotBalance(marketIndex, scaledBalance, scaledBalanceType) {
|
|
14612
|
+
const { decimals, cumulativeDepositInterest, cumulativeBorrowInterest } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
14613
|
+
const precisionAdjustment = new anchor.BN(10 ** (19 - decimals));
|
|
14614
|
+
let interest = cumulativeDepositInterest;
|
|
14615
|
+
if (scaledBalanceType === SpotBalanceType.BORROW) {
|
|
14616
|
+
interest = cumulativeBorrowInterest;
|
|
14617
|
+
}
|
|
14618
|
+
const balance = scaledBalance.mul(interest).div(precisionAdjustment);
|
|
14619
|
+
const amount = scaledBalanceType === SpotBalanceType.BORROW ? balance.neg().toNumber() : balance.toNumber();
|
|
14620
|
+
const uiAmount = amount / 10 ** decimals;
|
|
14621
|
+
return {
|
|
14622
|
+
amount,
|
|
14623
|
+
uiAmount
|
|
14624
|
+
};
|
|
14625
|
+
}
|
|
14626
|
+
getDriftUserPdas(statePda, subAccountId = 0) {
|
|
13657
14627
|
const vault = this.base.getVaultPda(new web3_js.PublicKey(statePda));
|
|
13658
|
-
return
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
14628
|
+
return {
|
|
14629
|
+
user: this.getUserPda(vault, subAccountId),
|
|
14630
|
+
userStats: this.getUserStatsPda(vault)
|
|
14631
|
+
};
|
|
13662
14632
|
}
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
14633
|
+
get driftStatePda() {
|
|
14634
|
+
return web3_js.PublicKey.findProgramAddressSync([
|
|
14635
|
+
Buffer.from("drift_state")
|
|
14636
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
14637
|
+
}
|
|
14638
|
+
async fetchAndParseSpotMarket(marketIndex) {
|
|
14639
|
+
const markets = await this.fetchAndParseSpotMarkets([
|
|
14640
|
+
marketIndex
|
|
14641
|
+
]);
|
|
14642
|
+
if (!markets || markets.length === 0) {
|
|
14643
|
+
throw new Error(`Spot market not found at index ${marketIndex}`);
|
|
13667
14644
|
}
|
|
13668
|
-
|
|
13669
|
-
|
|
14645
|
+
return markets[0];
|
|
14646
|
+
}
|
|
14647
|
+
async fetchAndParseSpotMarkets(marketIndexes) {
|
|
14648
|
+
const indexesToFetch = marketIndexes.filter((marketIndex)=>!this.spotMarkets.has(marketIndex));
|
|
14649
|
+
if (indexesToFetch.length > 0) {
|
|
14650
|
+
console.log("Fetching spot markets:", indexesToFetch);
|
|
14651
|
+
const marketPdas = indexesToFetch.map((marketIndex)=>this.getMarketPda(MarketType.SPOT, marketIndex));
|
|
14652
|
+
const accounts = await this.base.provider.connection.getMultipleAccountsInfo(marketPdas);
|
|
14653
|
+
accounts.forEach((account)=>{
|
|
14654
|
+
if (account) {
|
|
14655
|
+
const spotMarket = this.parseSpotMarket(account.data);
|
|
14656
|
+
this.spotMarkets.set(spotMarket.marketIndex, spotMarket);
|
|
14657
|
+
}
|
|
14658
|
+
});
|
|
14659
|
+
}
|
|
14660
|
+
// At this point this.spotMarkets has all the requested markets
|
|
14661
|
+
return marketIndexes.map((marketIndex)=>this.spotMarkets.get(marketIndex)).filter((m)=>m);
|
|
13670
14662
|
}
|
|
13671
|
-
async
|
|
13672
|
-
const
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
if (!
|
|
13676
|
-
throw new Error(
|
|
14663
|
+
async fetchAndParsePerpMarket(marketIndex) {
|
|
14664
|
+
const markets = await this.fetchAndParsePerpMarkets([
|
|
14665
|
+
marketIndex
|
|
14666
|
+
]);
|
|
14667
|
+
if (!markets || markets.length === 0) {
|
|
14668
|
+
throw new Error(`Perp market not found at index ${marketIndex}`);
|
|
13677
14669
|
}
|
|
13678
|
-
return
|
|
14670
|
+
return markets[0];
|
|
14671
|
+
}
|
|
14672
|
+
async fetchAndParsePerpMarkets(marketIndexes) {
|
|
14673
|
+
const indexesToFetch = marketIndexes.filter((marketIndex)=>!this.perpMarkets.has(marketIndex));
|
|
14674
|
+
if (indexesToFetch.length > 0) {
|
|
14675
|
+
console.log("Fetching perp markets:", indexesToFetch);
|
|
14676
|
+
const marketPdas = marketIndexes.map((marketIndex)=>this.getMarketPda(MarketType.PERP, marketIndex));
|
|
14677
|
+
const accounts = await this.base.provider.connection.getMultipleAccountsInfo(marketPdas);
|
|
14678
|
+
accounts.forEach((account)=>{
|
|
14679
|
+
if (account) {
|
|
14680
|
+
const perpMarket = this.parsePerpMarket(account.data);
|
|
14681
|
+
this.perpMarkets.set(perpMarket.marketIndex, perpMarket);
|
|
14682
|
+
}
|
|
14683
|
+
});
|
|
14684
|
+
} else {
|
|
14685
|
+
console.log("Requested perp markets already cached:", marketIndexes);
|
|
14686
|
+
}
|
|
14687
|
+
return marketIndexes.map((marketIndex)=>this.perpMarkets.get(marketIndex)).filter((m)=>m);
|
|
13679
14688
|
}
|
|
13680
|
-
async
|
|
13681
|
-
const
|
|
14689
|
+
async fetchMarketConfigs() {
|
|
14690
|
+
// const response = await fetch(
|
|
14691
|
+
// "https://api.glam.systems/v0/drift/market_configs/",
|
|
14692
|
+
// );
|
|
14693
|
+
// if (!response.ok) {
|
|
14694
|
+
// throw new Error(`Failed to fetch market configs: ${response.status}`);
|
|
14695
|
+
// }
|
|
14696
|
+
// const data = await response.json();
|
|
14697
|
+
// const { orderConstants, perp, spot } = data;
|
|
14698
|
+
// // Transform perp market from API to `PerpMarket` type
|
|
14699
|
+
// const perpMarkets = perp.map((m: any) => ({
|
|
14700
|
+
// marketIndex: m.marketIndex,
|
|
14701
|
+
// marketPda: m.marketPDA,
|
|
14702
|
+
// oracle: new PublicKey(m.oracle),
|
|
14703
|
+
// }));
|
|
14704
|
+
// // Transform spot market from API to `SpotMarket` type
|
|
14705
|
+
// const spotMarkets = spot.map((m: any) => ({
|
|
14706
|
+
// marketIndex: m.marketIndex,
|
|
14707
|
+
// marketPda: m.marketPDA,
|
|
14708
|
+
// oracle: new PublicKey(m.oracle),
|
|
14709
|
+
// mint: new PublicKey(m.mint),
|
|
14710
|
+
// vault: new PublicKey(m.vaultPDA),
|
|
14711
|
+
// decimals: m.decimals,
|
|
14712
|
+
// }));
|
|
14713
|
+
if (!this.marketConfigs) {
|
|
14714
|
+
const perpMarkets = await this.fetchAndParsePerpMarkets(Array.from(Array(100).keys()));
|
|
14715
|
+
const spotMarkets = await this.fetchAndParseSpotMarkets(Array.from(Array(100).keys()));
|
|
14716
|
+
this.marketConfigs = {
|
|
14717
|
+
orderConstants: {
|
|
14718
|
+
perpBaseScale: 9,
|
|
14719
|
+
quoteScale: 6
|
|
14720
|
+
},
|
|
14721
|
+
perpMarkets,
|
|
14722
|
+
spotMarkets
|
|
14723
|
+
};
|
|
14724
|
+
}
|
|
14725
|
+
return this.marketConfigs;
|
|
14726
|
+
}
|
|
14727
|
+
// public async fetchGlamDriftUser(
|
|
14728
|
+
// glamState: PublicKey | string,
|
|
14729
|
+
// subAccountId: number = 0,
|
|
14730
|
+
// ): Promise<GlamDriftUser> {
|
|
14731
|
+
// const vault = this.base.getVaultPda(new PublicKey(glamState));
|
|
14732
|
+
// const response = await fetch(
|
|
14733
|
+
// `https://api.glam.systems/v0/drift/user?authority=${vault.toBase58()}&accountId=${subAccountId}`,
|
|
14734
|
+
// );
|
|
14735
|
+
// const data = await response.json();
|
|
14736
|
+
// if (!data) {
|
|
14737
|
+
// throw new Error("Failed to fetch drift user.");
|
|
14738
|
+
// }
|
|
14739
|
+
// return data as GlamDriftUser;
|
|
14740
|
+
// }
|
|
14741
|
+
charsToName(chars) {
|
|
14742
|
+
return String.fromCharCode(...chars).replace(/\0/g, "").trim();
|
|
14743
|
+
}
|
|
14744
|
+
async fetchDriftUser(statePda, subAccountId = 0) {
|
|
14745
|
+
const { user } = this.getDriftUserPdas(new web3_js.PublicKey(statePda), subAccountId);
|
|
14746
|
+
const accountInfo = await this.base.provider.connection.getAccountInfo(user);
|
|
14747
|
+
if (!accountInfo) {
|
|
14748
|
+
return null;
|
|
14749
|
+
}
|
|
14750
|
+
const { delegate, name, spotPositions, marginMode, perpPositions, isMarginTradingEnabled, maxMarginRatio, orders } = decodeUser(accountInfo.data);
|
|
14751
|
+
// Prefetch market configs
|
|
14752
|
+
const marketConfigs = await this.fetchMarketConfigs();
|
|
14753
|
+
const spotPositionsExt = await Promise.all(spotPositions.map(async (p)=>{
|
|
14754
|
+
const { amount, uiAmount } = await this.calcSpotBalance(p.marketIndex, p.scaledBalance, p.balanceType);
|
|
14755
|
+
const spotMarket = marketConfigs.spotMarkets.find((m)=>m.marketIndex === p.marketIndex);
|
|
14756
|
+
return {
|
|
14757
|
+
...p,
|
|
14758
|
+
amount,
|
|
14759
|
+
uiAmount,
|
|
14760
|
+
mint: spotMarket.mint,
|
|
14761
|
+
decimals: spotMarket.decimals,
|
|
14762
|
+
marketName: spotMarket.name
|
|
14763
|
+
};
|
|
14764
|
+
}));
|
|
13682
14765
|
return {
|
|
13683
|
-
|
|
13684
|
-
|
|
14766
|
+
delegate,
|
|
14767
|
+
name: this.charsToName(name),
|
|
14768
|
+
spotPositions: spotPositionsExt,
|
|
14769
|
+
perpPositions,
|
|
14770
|
+
orders,
|
|
14771
|
+
marginMode,
|
|
14772
|
+
subAccountId,
|
|
14773
|
+
isMarginTradingEnabled,
|
|
14774
|
+
maxMarginRatio
|
|
13685
14775
|
};
|
|
13686
14776
|
}
|
|
14777
|
+
// async getPositions(statePda: PublicKey | string, subAccountId: number = 0) {
|
|
14778
|
+
// const driftUser = await this.fetchDriftUser(
|
|
14779
|
+
// new PublicKey(statePda),
|
|
14780
|
+
// subAccountId,
|
|
14781
|
+
// );
|
|
14782
|
+
// if (!driftUser) {
|
|
14783
|
+
// return { spotPositions: [], perpPositions: [] };
|
|
14784
|
+
// }
|
|
14785
|
+
// const marketConfigs = await this.fetchMarketConfigs();
|
|
14786
|
+
// const { spotPositions, perpPositions } = driftUser;
|
|
14787
|
+
// return { spotPositions, perpPositions };
|
|
14788
|
+
// }
|
|
13687
14789
|
async fetchPolicyConfig(glamState) {
|
|
13688
|
-
|
|
13689
|
-
if (glamState && glamState.id) {
|
|
13690
|
-
const [driftUserAddress] = this.getUser(glamState.id);
|
|
13691
|
-
const connection = this.base.provider.connection;
|
|
13692
|
-
const info = await connection.getAccountInfo(driftUserAddress, connection.commitment);
|
|
13693
|
-
if (info) {
|
|
13694
|
-
driftUserAccount = sdk.decodeUser(info.data);
|
|
13695
|
-
}
|
|
13696
|
-
}
|
|
14790
|
+
const driftUserAccount = glamState && glamState.id && await this.fetchDriftUser(glamState.id);
|
|
13697
14791
|
let delegate = driftUserAccount?.delegate;
|
|
13698
|
-
if (delegate && delegate.equals(
|
|
14792
|
+
if (delegate && delegate.equals(web3_js.PublicKey.default)) {
|
|
13699
14793
|
delegate = undefined;
|
|
13700
14794
|
}
|
|
13701
14795
|
return {
|
|
@@ -13708,26 +14802,33 @@ class DriftClient {
|
|
|
13708
14802
|
driftMarketIndexesSpot: glamState?.driftMarketIndexesSpot || []
|
|
13709
14803
|
};
|
|
13710
14804
|
}
|
|
13711
|
-
async composeRemainingAccounts(glamState, subAccountId,
|
|
13712
|
-
const
|
|
14805
|
+
async composeRemainingAccounts(glamState, subAccountId, marketType, marketIndex) {
|
|
14806
|
+
const driftUser = await this.fetchDriftUser(glamState, subAccountId);
|
|
14807
|
+
if (!driftUser) {
|
|
14808
|
+
throw new Error("Drift user not found");
|
|
14809
|
+
}
|
|
14810
|
+
const { spotPositions, perpPositions } = driftUser;
|
|
13713
14811
|
const spotMarketIndexes = spotPositions.map((p)=>p.marketIndex);
|
|
13714
14812
|
const perpMarketIndexes = perpPositions.map((p)=>p.marketIndex);
|
|
13715
14813
|
// Note that marketIndex is could be 0, need to explicitly check undefined
|
|
13716
|
-
if (this.marketTypeEquals(marketType,
|
|
14814
|
+
if (this.marketTypeEquals(marketType, MarketType.SPOT) && marketIndex !== undefined && !spotMarketIndexes.includes(marketIndex)) {
|
|
13717
14815
|
spotMarketIndexes.push(marketIndex);
|
|
13718
|
-
} else if (this.marketTypeEquals(marketType,
|
|
14816
|
+
} else if (this.marketTypeEquals(marketType, MarketType.PERP) && marketIndex !== undefined && !perpMarketIndexes.includes(marketIndex)) {
|
|
13719
14817
|
perpMarketIndexes.push(marketIndex);
|
|
13720
14818
|
}
|
|
13721
14819
|
// Also include USDC spot market if we're composing remaining accounts for spot or perp orders
|
|
13722
|
-
if (this.marketTypeEquals(marketType,
|
|
14820
|
+
if (this.marketTypeEquals(marketType, MarketType.PERP) || this.marketTypeEquals(marketType, MarketType.SPOT)) {
|
|
13723
14821
|
if (!spotMarketIndexes.includes(0)) {
|
|
13724
14822
|
spotMarketIndexes.push(0);
|
|
13725
14823
|
}
|
|
13726
14824
|
}
|
|
13727
|
-
const
|
|
13728
|
-
const
|
|
13729
|
-
console.log("[composeRemainingAccounts]
|
|
13730
|
-
|
|
14825
|
+
const spotMarkets = await this.fetchAndParseSpotMarkets(spotMarketIndexes);
|
|
14826
|
+
const perpMarkets = await this.fetchAndParsePerpMarkets(perpMarketIndexes);
|
|
14827
|
+
console.log("[composeRemainingAccounts] perpMarkets:", perpMarkets);
|
|
14828
|
+
const oracles = spotMarkets.map((m)=>m.oracle).concat(perpMarkets.map((m)=>m.oracle));
|
|
14829
|
+
const markets = spotMarkets.map((m)=>m.marketPda).concat(perpMarkets.map((m)=>m.marketPda));
|
|
14830
|
+
console.log("[composeRemainingAccounts] markets:", markets.map((m)=>m.toBase58()));
|
|
14831
|
+
console.log("[composeRemainingAccounts] oracles:", oracles.map((o)=>o.toBase58()));
|
|
13731
14832
|
return oracles.map((o)=>({
|
|
13732
14833
|
pubkey: new web3_js.PublicKey(o),
|
|
13733
14834
|
isWritable: false,
|
|
@@ -13739,35 +14840,44 @@ class DriftClient {
|
|
|
13739
14840
|
})));
|
|
13740
14841
|
}
|
|
13741
14842
|
async initializeUserStatsIx(glamState, glamSigner) {
|
|
13742
|
-
const
|
|
13743
|
-
const state = await sdk.getDriftStateAccountPublicKey(DRIFT_PROGRAM_ID);
|
|
14843
|
+
const { userStats } = this.getDriftUserPdas(glamState);
|
|
13744
14844
|
// @ts-ignore
|
|
13745
14845
|
return await this.base.program.methods.driftInitializeUserStats().accounts({
|
|
13746
14846
|
glamState,
|
|
13747
14847
|
glamSigner,
|
|
13748
|
-
state,
|
|
14848
|
+
state: this.driftStatePda,
|
|
13749
14849
|
userStats
|
|
13750
14850
|
}).instruction();
|
|
13751
14851
|
}
|
|
13752
14852
|
async initializeUserIx(glamState, glamSigner, subAccountId) {
|
|
13753
14853
|
const name = `GLAM *.+ ${subAccountId}`.split("").map((char)=>char.charCodeAt(0)).concat(Array(24).fill(0));
|
|
13754
|
-
const
|
|
13755
|
-
const
|
|
14854
|
+
const { user, userStats } = this.getDriftUserPdas(glamState, subAccountId);
|
|
14855
|
+
const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
|
|
14856
|
+
const remainingAccounts = [
|
|
14857
|
+
{
|
|
14858
|
+
pubkey: referrer,
|
|
14859
|
+
isWritable: true,
|
|
14860
|
+
isSigner: false
|
|
14861
|
+
},
|
|
14862
|
+
{
|
|
14863
|
+
pubkey: referrerStats,
|
|
14864
|
+
isWritable: true,
|
|
14865
|
+
isSigner: false
|
|
14866
|
+
}
|
|
14867
|
+
];
|
|
13756
14868
|
return await this.base.program.methods.driftInitializeUser(subAccountId, name).accounts({
|
|
13757
14869
|
glamState,
|
|
13758
14870
|
user,
|
|
13759
14871
|
userStats,
|
|
13760
|
-
state,
|
|
14872
|
+
state: this.driftStatePda,
|
|
13761
14873
|
glamSigner
|
|
13762
|
-
})
|
|
13763
|
-
// .remainingAccounts([]) TODO: set glam referral account
|
|
13764
|
-
.instruction();
|
|
14874
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
13765
14875
|
}
|
|
13766
14876
|
async initializeTx(glamState, subAccountId = 0, txOptions = {}) {
|
|
13767
14877
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13768
14878
|
const tx = new web3_js.Transaction();
|
|
13769
14879
|
// Create userStats account if it doesn't exist
|
|
13770
|
-
const
|
|
14880
|
+
const { userStats } = this.getDriftUserPdas(glamState);
|
|
13771
14881
|
const userStatsInfo = await this.base.provider.connection.getAccountInfo(userStats);
|
|
13772
14882
|
if (!userStatsInfo) {
|
|
13773
14883
|
tx.add(await this.initializeUserStatsIx(glamState, glamSigner));
|
|
@@ -13778,7 +14888,7 @@ class DriftClient {
|
|
|
13778
14888
|
}
|
|
13779
14889
|
async updateUserCustomMarginRatioIx(glamState, maxLeverage, subAccountId = 0, txOptions = {}) {
|
|
13780
14890
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13781
|
-
const
|
|
14891
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
13782
14892
|
// https://github.com/drift-labs/protocol-v2/blob/babed162b08b1fe34e49a81c5aa3e4ec0a88ecdf/programs/drift/src/math/constants.rs#L183-L184
|
|
13783
14893
|
const marginRatio = DRIFT_MARGIN_PRECISION / maxLeverage;
|
|
13784
14894
|
return await this.base.program.methods.driftUpdateUserCustomMarginRatio(subAccountId, marginRatio).accounts({
|
|
@@ -13793,7 +14903,7 @@ class DriftClient {
|
|
|
13793
14903
|
}
|
|
13794
14904
|
async updateUserMarginTradingEnabledIx(glamState, marginTradingEnabled, subAccountId = 0, txOptions = {}) {
|
|
13795
14905
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13796
|
-
const
|
|
14906
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
13797
14907
|
return await this.base.program.methods.driftUpdateUserMarginTradingEnabled(subAccountId, marginTradingEnabled).accounts({
|
|
13798
14908
|
glamState,
|
|
13799
14909
|
glamSigner,
|
|
@@ -13806,7 +14916,7 @@ class DriftClient {
|
|
|
13806
14916
|
}
|
|
13807
14917
|
async updateUserDelegateIx(glamState, delegate, subAccountId = 0, txOptions = {}) {
|
|
13808
14918
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13809
|
-
const
|
|
14919
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
13810
14920
|
return await this.base.program.methods.driftUpdateUserDelegate(subAccountId, new web3_js.PublicKey(delegate)).accounts({
|
|
13811
14921
|
glamState,
|
|
13812
14922
|
glamSigner,
|
|
@@ -13819,32 +14929,28 @@ class DriftClient {
|
|
|
13819
14929
|
}
|
|
13820
14930
|
async deleteUserTx(glamState, subAccountId = 0, txOptions = {}) {
|
|
13821
14931
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13822
|
-
const
|
|
13823
|
-
const state = await sdk.getDriftStateAccountPublicKey(DRIFT_PROGRAM_ID);
|
|
14932
|
+
const { user, userStats } = this.getDriftUserPdas(glamState, subAccountId);
|
|
13824
14933
|
const tx = await this.base.program.methods.driftDeleteUser().accounts({
|
|
13825
14934
|
glamState,
|
|
13826
|
-
state,
|
|
14935
|
+
state: this.driftStatePda,
|
|
13827
14936
|
user,
|
|
13828
14937
|
userStats,
|
|
13829
14938
|
glamSigner
|
|
13830
14939
|
}).transaction();
|
|
13831
14940
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13832
14941
|
}
|
|
13833
|
-
async depositTx(glamState, amount, marketIndex = 1, subAccountId = 0,
|
|
14942
|
+
async depositTx(glamState, amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
13834
14943
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13835
|
-
const
|
|
13836
|
-
const
|
|
13837
|
-
|
|
13838
|
-
console.log("mint, oracle, marketPDA, vaultPDA", mint, oracle, marketPDA, vaultPDA);
|
|
14944
|
+
const { user, userStats } = this.getDriftUserPdas(glamState, subAccountId);
|
|
14945
|
+
const { mint, oracle, tokenProgram, marketPda, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
14946
|
+
console.log(`Spot market ${marketIndex} mint ${mint}, oracle: ${oracle}, marketPda: ${marketPda}, vault: ${driftVault}`);
|
|
13839
14947
|
const preInstructions = [];
|
|
13840
14948
|
const postInstructions = [];
|
|
13841
14949
|
// If drift user doesn't exist, prepend initializeUserStats and initializeUser instructions
|
|
13842
|
-
|
|
13843
|
-
await this.fetchGlamDriftUser(glamState, subAccountId);
|
|
13844
|
-
} catch (_) {
|
|
14950
|
+
if (!await this.fetchDriftUser(glamState, subAccountId)) {
|
|
13845
14951
|
preInstructions.push(await this.initializeUserStatsIx(glamState, glamSigner), await this.initializeUserIx(glamState, glamSigner, subAccountId));
|
|
13846
14952
|
}
|
|
13847
|
-
if (mint
|
|
14953
|
+
if (mint.equals(WSOL)) {
|
|
13848
14954
|
const wrapSolIxs = await this.base.maybeWrapSol(glamState, amount, glamSigner);
|
|
13849
14955
|
preInstructions.push(...wrapSolIxs);
|
|
13850
14956
|
// If we need to wrap SOL, it means the wSOL balance will be drained,
|
|
@@ -13858,75 +14964,97 @@ class DriftClient {
|
|
|
13858
14964
|
}).instruction();
|
|
13859
14965
|
postInstructions.push(closeTokenAccountIx);
|
|
13860
14966
|
}
|
|
13861
|
-
const
|
|
13862
|
-
glamState,
|
|
13863
|
-
state,
|
|
13864
|
-
user,
|
|
13865
|
-
userStats,
|
|
13866
|
-
spotMarketVault: new web3_js.PublicKey(vaultPDA),
|
|
13867
|
-
userTokenAccount: this.base.getVaultAta(glamState, new web3_js.PublicKey(mint)),
|
|
13868
|
-
glamSigner,
|
|
13869
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID
|
|
13870
|
-
}).remainingAccounts([
|
|
14967
|
+
const remainingAccounts = [
|
|
13871
14968
|
{
|
|
13872
14969
|
pubkey: new web3_js.PublicKey(oracle),
|
|
13873
14970
|
isSigner: false,
|
|
13874
14971
|
isWritable: false
|
|
13875
14972
|
},
|
|
13876
14973
|
{
|
|
13877
|
-
pubkey: new web3_js.PublicKey(
|
|
14974
|
+
pubkey: new web3_js.PublicKey(marketPda),
|
|
13878
14975
|
isSigner: false,
|
|
13879
14976
|
isWritable: true
|
|
13880
14977
|
}
|
|
13881
|
-
]
|
|
14978
|
+
];
|
|
14979
|
+
if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
|
|
14980
|
+
remainingAccounts.push({
|
|
14981
|
+
pubkey: mint,
|
|
14982
|
+
isSigner: false,
|
|
14983
|
+
isWritable: false
|
|
14984
|
+
});
|
|
14985
|
+
}
|
|
14986
|
+
const tx = await this.base.program.methods.driftDeposit(marketIndex, amount, false).accounts({
|
|
14987
|
+
glamState,
|
|
14988
|
+
state: this.driftStatePda,
|
|
14989
|
+
user,
|
|
14990
|
+
userStats,
|
|
14991
|
+
spotMarketVault: driftVault,
|
|
14992
|
+
userTokenAccount: this.base.getVaultAta(glamState, mint, tokenProgram),
|
|
14993
|
+
glamSigner,
|
|
14994
|
+
tokenProgram
|
|
14995
|
+
}).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
13882
14996
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13883
14997
|
}
|
|
13884
|
-
async withdrawTx(statePda, amount, marketIndex = 1, subAccountId = 0,
|
|
14998
|
+
async withdrawTx(statePda, amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
13885
14999
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13886
|
-
const
|
|
13887
|
-
const
|
|
13888
|
-
const
|
|
13889
|
-
const
|
|
13890
|
-
const
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
|
|
15000
|
+
const { user, userStats } = this.getDriftUserPdas(statePda, subAccountId);
|
|
15001
|
+
const { mint, tokenProgram, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
15002
|
+
const glamVault = this.base.getVaultPda(statePda);
|
|
15003
|
+
const glamVaultAta = this.base.getVaultAta(statePda, mint, tokenProgram);
|
|
15004
|
+
const remainingAccounts = await this.composeRemainingAccounts(statePda, subAccountId, MarketType.SPOT, marketIndex);
|
|
15005
|
+
if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
|
|
15006
|
+
remainingAccounts.push({
|
|
15007
|
+
pubkey: mint,
|
|
15008
|
+
isSigner: false,
|
|
15009
|
+
isWritable: false
|
|
15010
|
+
});
|
|
15011
|
+
}
|
|
13895
15012
|
// Create vault ata in case it doesn't exist
|
|
13896
15013
|
const preInstructions = [
|
|
13897
|
-
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner,
|
|
15014
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, glamVaultAta, glamVault, mint, tokenProgram)
|
|
13898
15015
|
];
|
|
13899
15016
|
const tx = await this.base.program.methods.driftWithdraw(marketIndex, amount, false).accounts({
|
|
13900
15017
|
glamState: statePda,
|
|
13901
|
-
state,
|
|
15018
|
+
state: this.driftStatePda,
|
|
13902
15019
|
user,
|
|
13903
15020
|
userStats,
|
|
13904
15021
|
glamSigner,
|
|
13905
|
-
spotMarketVault:
|
|
13906
|
-
userTokenAccount:
|
|
13907
|
-
driftSigner:
|
|
13908
|
-
tokenProgram
|
|
15022
|
+
spotMarketVault: driftVault,
|
|
15023
|
+
userTokenAccount: glamVaultAta,
|
|
15024
|
+
driftSigner: DRIFT_SIGNER,
|
|
15025
|
+
tokenProgram
|
|
13909
15026
|
}).remainingAccounts(remainingAccounts).preInstructions(preInstructions).transaction();
|
|
13910
15027
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13911
15028
|
}
|
|
13912
|
-
async placeOrderTx(glamState, orderParams, subAccountId = 0,
|
|
15029
|
+
async placeOrderTx(glamState, orderParams, subAccountId = 0, txOptions = {}) {
|
|
13913
15030
|
const { marketIndex, marketType } = orderParams;
|
|
13914
|
-
const
|
|
15031
|
+
const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
|
|
15032
|
+
const remainingAccounts = (await this.composeRemainingAccounts(glamState, subAccountId, marketType, marketIndex)).concat([
|
|
15033
|
+
{
|
|
15034
|
+
pubkey: referrer,
|
|
15035
|
+
isWritable: true,
|
|
15036
|
+
isSigner: false
|
|
15037
|
+
},
|
|
15038
|
+
{
|
|
15039
|
+
pubkey: referrerStats,
|
|
15040
|
+
isWritable: true,
|
|
15041
|
+
isSigner: false
|
|
15042
|
+
}
|
|
15043
|
+
]);
|
|
13915
15044
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13916
|
-
const
|
|
13917
|
-
|
|
13918
|
-
const tx = await this.base.program.methods
|
|
13919
|
-
.driftPlaceOrders([
|
|
15045
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
15046
|
+
// @ts-ignore
|
|
15047
|
+
const tx = await this.base.program.methods.driftPlaceOrders([
|
|
13920
15048
|
orderParams
|
|
13921
15049
|
]).accounts({
|
|
13922
15050
|
glamState,
|
|
13923
15051
|
user,
|
|
13924
|
-
state,
|
|
15052
|
+
state: this.driftStatePda,
|
|
13925
15053
|
glamSigner
|
|
13926
15054
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
13927
15055
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13928
15056
|
}
|
|
13929
|
-
async modifyOrderTx(statePda, modifyOrderParams, subAccountId = 0,
|
|
15057
|
+
async modifyOrderTx(statePda, modifyOrderParams, subAccountId = 0, txOptions = {}) {
|
|
13930
15058
|
// const { marketIndex, marketType } = orderParams;
|
|
13931
15059
|
// const remainingAccounts = await this.composeRemainingAccounts(
|
|
13932
15060
|
// statePda,
|
|
@@ -13936,65 +15064,62 @@ class DriftClient {
|
|
|
13936
15064
|
// marketIndex,
|
|
13937
15065
|
// );
|
|
13938
15066
|
const signer = txOptions.signer || this.base.getSigner();
|
|
13939
|
-
const
|
|
13940
|
-
const driftState = await sdk.getDriftStateAccountPublicKey(DRIFT_PROGRAM_ID);
|
|
15067
|
+
const { user } = this.getDriftUserPdas(statePda, subAccountId);
|
|
13941
15068
|
const tx = await this.base.program.methods// @ts-ignore
|
|
13942
15069
|
.driftModifyOrder(1, modifyOrderParams).accounts({
|
|
13943
15070
|
glamState: statePda,
|
|
13944
15071
|
glamSigner: signer,
|
|
13945
15072
|
user,
|
|
13946
|
-
state:
|
|
15073
|
+
state: this.driftStatePda
|
|
13947
15074
|
})// .remainingAccounts(remainingAccounts)
|
|
13948
15075
|
.transaction();
|
|
13949
15076
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13950
15077
|
}
|
|
13951
|
-
async cancelOrdersTx(glamState, marketType, marketIndex, direction, subAccountId = 0,
|
|
15078
|
+
async cancelOrdersTx(glamState, marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
|
|
13952
15079
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13953
|
-
const
|
|
13954
|
-
const
|
|
13955
|
-
const remainingAccounts = await this.composeRemainingAccounts(glamState, subAccountId, marketConfigs, marketType, marketIndex);
|
|
15080
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
15081
|
+
const remainingAccounts = await this.composeRemainingAccounts(glamState, subAccountId, marketType, marketIndex);
|
|
13956
15082
|
// @ts-ignore
|
|
13957
15083
|
const tx = await this.base.program.methods.driftCancelOrders(marketType, marketIndex, direction).accounts({
|
|
13958
15084
|
glamState,
|
|
13959
15085
|
glamSigner,
|
|
13960
15086
|
user,
|
|
13961
|
-
state:
|
|
15087
|
+
state: this.driftStatePda
|
|
13962
15088
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
13963
15089
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13964
15090
|
}
|
|
13965
|
-
async cancelOrdersByIdsTx(glamState, orderIds, subAccountId = 0,
|
|
15091
|
+
async cancelOrdersByIdsTx(glamState, orderIds, subAccountId = 0, txOptions = {}) {
|
|
13966
15092
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13967
|
-
const
|
|
13968
|
-
const
|
|
13969
|
-
|
|
15093
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
15094
|
+
const remainingAccounts = await this.composeRemainingAccounts(glamState, subAccountId);
|
|
15095
|
+
// @ts-ignore
|
|
13970
15096
|
const tx = await this.base.program.methods.driftCancelOrdersByIds(orderIds).accounts({
|
|
13971
15097
|
glamState,
|
|
13972
15098
|
glamSigner,
|
|
13973
15099
|
user,
|
|
13974
|
-
state:
|
|
15100
|
+
state: this.driftStatePda
|
|
13975
15101
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
13976
15102
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13977
15103
|
}
|
|
13978
|
-
async settlePnlTx(glamState, marketIndex, subAccountId = 0,
|
|
15104
|
+
async settlePnlTx(glamState, marketIndex, subAccountId = 0, txOptions = {}) {
|
|
13979
15105
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
13980
|
-
const
|
|
13981
|
-
const
|
|
13982
|
-
|
|
15106
|
+
const { user } = this.getDriftUserPdas(glamState, subAccountId);
|
|
15107
|
+
const { vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
15108
|
+
// @ts-ignore
|
|
13983
15109
|
const tx = await this.base.program.methods.driftSettlePnl(marketIndex).accounts({
|
|
13984
15110
|
glamState,
|
|
13985
15111
|
glamSigner,
|
|
13986
15112
|
user,
|
|
13987
|
-
state:
|
|
13988
|
-
spotMarketVault:
|
|
15113
|
+
state: this.driftStatePda,
|
|
15114
|
+
spotMarketVault: driftVault
|
|
13989
15115
|
}).transaction();
|
|
13990
15116
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
13991
15117
|
}
|
|
13992
|
-
async priceDriftTx(glamState,
|
|
15118
|
+
async priceDriftTx(glamState, priceDenom, txOptions = {}) {
|
|
13993
15119
|
const signer = txOptions.signer || this.base.getSigner();
|
|
13994
15120
|
const glamVault = this.base.getVaultPda(glamState);
|
|
13995
|
-
const
|
|
13996
|
-
const
|
|
13997
|
-
const remainingAccounts = await this.composeRemainingAccounts(glamState, 0, marketConfigs);
|
|
15121
|
+
const { user, userStats } = this.getDriftUserPdas(glamState);
|
|
15122
|
+
const remainingAccounts = await this.composeRemainingAccounts(glamState, 0);
|
|
13998
15123
|
const tx = await this.base.program.methods.priceDrift(priceDenom).accounts({
|
|
13999
15124
|
glamState,
|
|
14000
15125
|
signer,
|
|
@@ -14002,12 +15127,30 @@ class DriftClient {
|
|
|
14002
15127
|
user,
|
|
14003
15128
|
userStats,
|
|
14004
15129
|
solOracle: SOL_ORACLE,
|
|
14005
|
-
state:
|
|
15130
|
+
state: this.driftStatePda
|
|
14006
15131
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
14007
15132
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14008
15133
|
}
|
|
14009
15134
|
constructor(base){
|
|
14010
15135
|
this.base = base;
|
|
15136
|
+
this.spotMarkets = new Map();
|
|
15137
|
+
this.perpMarkets = new Map();
|
|
15138
|
+
this.marketConfigs = null;
|
|
15139
|
+
this./*
|
|
15140
|
+
* Utils
|
|
15141
|
+
*/ getMarketPda = (marketType, marketIndex)=>web3_js.PublicKey.findProgramAddressSync([
|
|
15142
|
+
Buffer.from(`${marketType === MarketType.PERP ? "perp" : "spot"}_market`),
|
|
15143
|
+
new anchor__namespace.BN(marketIndex).toArrayLike(Buffer, "le", 2)
|
|
15144
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
15145
|
+
this.getUserPda = (authority, subAccountId = 0)=>web3_js.PublicKey.findProgramAddressSync([
|
|
15146
|
+
Buffer.from("user"),
|
|
15147
|
+
authority.toBuffer(),
|
|
15148
|
+
new anchor__namespace.BN(subAccountId).toArrayLike(Buffer, "le", 2)
|
|
15149
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
15150
|
+
this.getUserStatsPda = (authority)=>web3_js.PublicKey.findProgramAddressSync([
|
|
15151
|
+
Buffer.from("user_stats"),
|
|
15152
|
+
authority.toBuffer()
|
|
15153
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
14011
15154
|
this.marketTypeEquals = (a, b)=>a && Object.keys(a)[0] === Object.keys(b)[0];
|
|
14012
15155
|
}
|
|
14013
15156
|
}
|
|
@@ -15674,7 +16817,7 @@ const DEFAULT_OBLIGATION_ARGS = {
|
|
|
15674
16817
|
id: 0
|
|
15675
16818
|
};
|
|
15676
16819
|
const SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
|
|
15677
|
-
function refreshObligation(accounts, programId) {
|
|
16820
|
+
function refreshObligation(accounts, programId = KAMINO_LENDING_PROGRAM) {
|
|
15678
16821
|
const keys = [
|
|
15679
16822
|
{
|
|
15680
16823
|
pubkey: accounts.lendingMarket,
|
|
@@ -15712,7 +16855,7 @@ function refreshObligation(accounts, programId) {
|
|
|
15712
16855
|
});
|
|
15713
16856
|
return ix;
|
|
15714
16857
|
}
|
|
15715
|
-
function refreshReserve(accounts, programId) {
|
|
16858
|
+
function refreshReserve(accounts, programId = KAMINO_LENDING_PROGRAM) {
|
|
15716
16859
|
const keys = [
|
|
15717
16860
|
{
|
|
15718
16861
|
pubkey: accounts.reserve,
|
|
@@ -15763,7 +16906,7 @@ function refreshReserve(accounts, programId) {
|
|
|
15763
16906
|
});
|
|
15764
16907
|
return ix;
|
|
15765
16908
|
}
|
|
15766
|
-
function refreshObligationFarmsForReserve(args, accounts, programId) {
|
|
16909
|
+
function refreshObligationFarmsForReserve(args, accounts, programId = KAMINO_LENDING_PROGRAM) {
|
|
15767
16910
|
const keys = [
|
|
15768
16911
|
{
|
|
15769
16912
|
pubkey: accounts.crank,
|
|
@@ -15854,7 +16997,7 @@ class KaminoLendingClient {
|
|
|
15854
16997
|
* @param txOptions
|
|
15855
16998
|
* @returns
|
|
15856
16999
|
*/ async initUserMetadata(statePda, referrer, txOptions = {}) {
|
|
15857
|
-
const tx = await this.initUserMetadataTx(new web3_js.PublicKey(statePda), referrer ? new web3_js.PublicKey(referrer) :
|
|
17000
|
+
const tx = await this.initUserMetadataTx(new web3_js.PublicKey(statePda), referrer ? new web3_js.PublicKey(referrer) : null, txOptions);
|
|
15858
17001
|
return await this.base.sendAndConfirm(tx);
|
|
15859
17002
|
}
|
|
15860
17003
|
/**
|
|
@@ -15940,18 +17083,17 @@ class KaminoLendingClient {
|
|
|
15940
17083
|
], KAMINO_FARM_PROGRAM);
|
|
15941
17084
|
return obligationFarm;
|
|
15942
17085
|
}
|
|
15943
|
-
async initUserMetadataTx(glamState, referrer, txOptions) {
|
|
17086
|
+
async initUserMetadataTx(glamState, referrer, txOptions = {}) {
|
|
15944
17087
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15945
17088
|
const vault = this.base.getVaultPda(glamState);
|
|
15946
17089
|
const userMetadata = this.getUserMetadataPda(vault);
|
|
15947
17090
|
const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
|
|
15948
|
-
const referrerUserMetadata = referrer.equals(web3_js.PublicKey.default) ? KAMINO_LENDING_PROGRAM : referrer;
|
|
15949
17091
|
// @ts-ignore
|
|
15950
17092
|
const tx = await this.base.program.methods.kaminoLendingInitUserMetadata(lookupTable).accounts({
|
|
15951
17093
|
glamState,
|
|
15952
17094
|
glamSigner,
|
|
15953
17095
|
userMetadata,
|
|
15954
|
-
referrerUserMetadata
|
|
17096
|
+
referrerUserMetadata: referrer
|
|
15955
17097
|
}).transaction();
|
|
15956
17098
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15957
17099
|
return vTx;
|
|
@@ -15964,7 +17106,7 @@ class KaminoLendingClient {
|
|
|
15964
17106
|
switchboardPriceOracle: KAMINO_LENDING_PROGRAM,
|
|
15965
17107
|
switchboardTwapOracle: KAMINO_LENDING_PROGRAM,
|
|
15966
17108
|
scopePrices: SCOPE_PRICES
|
|
15967
|
-
}
|
|
17109
|
+
}));
|
|
15968
17110
|
}
|
|
15969
17111
|
refreshObligationFarmsForReserveIxs(obligation, lendingMarket, parsedReserves) {
|
|
15970
17112
|
return parsedReserves.map((parsedReserve)=>{
|
|
@@ -15989,18 +17131,21 @@ class KaminoLendingClient {
|
|
|
15989
17131
|
farmsProgram: KAMINO_FARM_PROGRAM,
|
|
15990
17132
|
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
15991
17133
|
systemProgram: web3_js.SystemProgram.programId
|
|
15992
|
-
}
|
|
17134
|
+
});
|
|
15993
17135
|
});
|
|
15994
17136
|
}).flat();
|
|
15995
17137
|
}
|
|
15996
|
-
|
|
15997
|
-
|
|
15998
|
-
|
|
15999
|
-
|
|
16000
|
-
|
|
16001
|
-
|
|
16002
|
-
|
|
16003
|
-
const { deposits, borrows } = await this.fetchAndParseObligation(obligation);
|
|
17138
|
+
// If obligation has deposits or borrows, we need the following refresh ixs:
|
|
17139
|
+
// - refreshReserve x N_reserves
|
|
17140
|
+
// - refreshObligation
|
|
17141
|
+
// - refreshObligationFarmsForReserve x M_farms
|
|
17142
|
+
//
|
|
17143
|
+
// For pricing purpose, we don't need to refresh farm states
|
|
17144
|
+
async getRefreshIxs(obligation, refreshFarms = true) {
|
|
17145
|
+
const { lendingMarket, deposits, borrows } = await this.fetchAndParseObligation(obligation);
|
|
17146
|
+
if (!lendingMarket) {
|
|
17147
|
+
throw new Error("Lending market not found");
|
|
17148
|
+
}
|
|
16004
17149
|
const reserves = deposits.concat(borrows).map((d)=>d.reserve);
|
|
16005
17150
|
const parsedReserves = await this.fetchAndParseReserves(reserves);
|
|
16006
17151
|
return [
|
|
@@ -16009,8 +17154,8 @@ class KaminoLendingClient {
|
|
|
16009
17154
|
lendingMarket,
|
|
16010
17155
|
obligation,
|
|
16011
17156
|
reserves
|
|
16012
|
-
}
|
|
16013
|
-
...this.refreshObligationFarmsForReserveIxs(obligation, lendingMarket, parsedReserves)
|
|
17157
|
+
}),
|
|
17158
|
+
...refreshFarms ? this.refreshObligationFarmsForReserveIxs(obligation, lendingMarket, parsedReserves) : []
|
|
16014
17159
|
];
|
|
16015
17160
|
}
|
|
16016
17161
|
getMarketAuthority(market) {
|
|
@@ -16061,11 +17206,14 @@ class KaminoLendingClient {
|
|
|
16061
17206
|
const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
|
|
16062
17207
|
if (!obligationAccount) {
|
|
16063
17208
|
return {
|
|
17209
|
+
address: obligation,
|
|
17210
|
+
lendingMarket: null,
|
|
16064
17211
|
deposits: [],
|
|
16065
17212
|
borrows: []
|
|
16066
17213
|
};
|
|
16067
17214
|
}
|
|
16068
17215
|
const data = obligationAccount.data;
|
|
17216
|
+
const lendingMarket = new web3_js.PublicKey(data.subarray(32, 64));
|
|
16069
17217
|
// read deposits
|
|
16070
17218
|
let depositsOffset = 96;
|
|
16071
17219
|
let depositSize = 136;
|
|
@@ -16075,8 +17223,9 @@ class KaminoLendingClient {
|
|
|
16075
17223
|
length: numDeposits
|
|
16076
17224
|
}, (_, i)=>{
|
|
16077
17225
|
const depositData = depositsData.subarray(i * depositSize, (i + 1) * depositSize);
|
|
17226
|
+
const reserve = new web3_js.PublicKey(depositData.subarray(0, 32));
|
|
16078
17227
|
return {
|
|
16079
|
-
reserve
|
|
17228
|
+
reserve
|
|
16080
17229
|
};
|
|
16081
17230
|
}).filter((d)=>!d.reserve.equals(web3_js.PublicKey.default));
|
|
16082
17231
|
// read borrows
|
|
@@ -16088,24 +17237,33 @@ class KaminoLendingClient {
|
|
|
16088
17237
|
length: numBorrows
|
|
16089
17238
|
}, (_, i)=>{
|
|
16090
17239
|
const borrowData = borrowsData.subarray(i * borrowSize, (i + 1) * borrowSize);
|
|
17240
|
+
const reserve = new web3_js.PublicKey(borrowData.subarray(0, 32));
|
|
16091
17241
|
return {
|
|
16092
|
-
reserve
|
|
17242
|
+
reserve
|
|
16093
17243
|
};
|
|
16094
17244
|
}).filter((d)=>!d.reserve.equals(web3_js.PublicKey.default));
|
|
16095
17245
|
const parsedObligation = {
|
|
17246
|
+
address: obligation,
|
|
17247
|
+
lendingMarket,
|
|
16096
17248
|
deposits,
|
|
16097
17249
|
borrows
|
|
16098
17250
|
};
|
|
16099
17251
|
this.obligations.set(obligation, parsedObligation);
|
|
16100
17252
|
return parsedObligation;
|
|
16101
17253
|
}
|
|
16102
|
-
|
|
16103
|
-
|
|
16104
|
-
|
|
16105
|
-
|
|
16106
|
-
|
|
16107
|
-
|
|
16108
|
-
|
|
17254
|
+
_parseReserveAccount(data) {
|
|
17255
|
+
const market = new web3_js.PublicKey(data.subarray(32, 64));
|
|
17256
|
+
const farmCollateral = new web3_js.PublicKey(data.subarray(64, 96));
|
|
17257
|
+
const farmDebt = new web3_js.PublicKey(data.subarray(96, 128));
|
|
17258
|
+
const liquidityMint = new web3_js.PublicKey(data.subarray(128, 160));
|
|
17259
|
+
return {
|
|
17260
|
+
farmCollateral: farmCollateral.equals(web3_js.PublicKey.default) ? null : farmCollateral,
|
|
17261
|
+
farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
|
|
17262
|
+
liquidityMint,
|
|
17263
|
+
...this.reservePdas(market, liquidityMint)
|
|
17264
|
+
};
|
|
17265
|
+
}
|
|
17266
|
+
async fetchAndParseReserves(reserves) {
|
|
16109
17267
|
if (this.pubkeyArraysEqual(reserves, Array.from(this.reserves.keys()))) {
|
|
16110
17268
|
return Array.from(this.reserves.values());
|
|
16111
17269
|
}
|
|
@@ -16114,20 +17272,12 @@ class KaminoLendingClient {
|
|
|
16114
17272
|
throw new Error("Not all reserves can be found");
|
|
16115
17273
|
}
|
|
16116
17274
|
return reserveAccounts.filter((a)=>!!a).map((account, i)=>{
|
|
16117
|
-
const
|
|
16118
|
-
const market = new web3_js.PublicKey(data.subarray(32, 64));
|
|
16119
|
-
const farmCollateral = new web3_js.PublicKey(data.subarray(64, 96));
|
|
16120
|
-
const farmDebt = new web3_js.PublicKey(data.subarray(96, 128));
|
|
16121
|
-
const liquidityMint = new web3_js.PublicKey(data.subarray(128, 160));
|
|
16122
|
-
const parsed = {
|
|
17275
|
+
const parsedReserve = {
|
|
16123
17276
|
address: reserves[i],
|
|
16124
|
-
|
|
16125
|
-
farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
|
|
16126
|
-
liquidityMint,
|
|
16127
|
-
...this.reservePdas(market, liquidityMint)
|
|
17277
|
+
...this._parseReserveAccount(account.data)
|
|
16128
17278
|
};
|
|
16129
|
-
this.reserves.set(reserves[i],
|
|
16130
|
-
return
|
|
17279
|
+
this.reserves.set(reserves[i], parsedReserve);
|
|
17280
|
+
return parsedReserve;
|
|
16131
17281
|
});
|
|
16132
17282
|
}
|
|
16133
17283
|
async findAndParseReserve(market, asset) {
|
|
@@ -16154,18 +17304,12 @@ class KaminoLendingClient {
|
|
|
16154
17304
|
throw new Error("Reserve not found");
|
|
16155
17305
|
}
|
|
16156
17306
|
const account = accounts[0];
|
|
16157
|
-
const
|
|
16158
|
-
const farmCollateral = new web3_js.PublicKey(data.subarray(64, 96));
|
|
16159
|
-
const farmDebt = new web3_js.PublicKey(data.subarray(96, 128));
|
|
16160
|
-
const parsed = {
|
|
17307
|
+
const parsedReserve = {
|
|
16161
17308
|
address: account.pubkey,
|
|
16162
|
-
|
|
16163
|
-
farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
|
|
16164
|
-
liquidityMint: asset,
|
|
16165
|
-
...this.reservePdas(market, asset)
|
|
17309
|
+
...this._parseReserveAccount(account.account.data)
|
|
16166
17310
|
};
|
|
16167
|
-
this.reserves.set(account.pubkey,
|
|
16168
|
-
return
|
|
17311
|
+
this.reserves.set(account.pubkey, parsedReserve);
|
|
17312
|
+
return parsedReserve;
|
|
16169
17313
|
}
|
|
16170
17314
|
async depositTx(glamState, market, asset, amount, txOptions) {
|
|
16171
17315
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
@@ -16223,7 +17367,7 @@ class KaminoLendingClient {
|
|
|
16223
17367
|
lendingMarket: market,
|
|
16224
17368
|
obligation,
|
|
16225
17369
|
reserves: reservesInUse
|
|
16226
|
-
}
|
|
17370
|
+
}));
|
|
16227
17371
|
if (depositReserve.farmCollateral) {
|
|
16228
17372
|
const ixs = this.refreshObligationFarmsForReserveIxs(obligation, market, [
|
|
16229
17373
|
depositReserve
|
|
@@ -16319,7 +17463,7 @@ class KaminoLendingClient {
|
|
|
16319
17463
|
lendingMarket: market,
|
|
16320
17464
|
obligation,
|
|
16321
17465
|
reserves: reservesInUse
|
|
16322
|
-
}
|
|
17466
|
+
}));
|
|
16323
17467
|
if (withdrawReserve.farmCollateral) {
|
|
16324
17468
|
const ixs = this.refreshObligationFarmsForReserveIxs(obligation, market, [
|
|
16325
17469
|
withdrawReserve
|
|
@@ -16409,7 +17553,7 @@ class KaminoLendingClient {
|
|
|
16409
17553
|
lendingMarket: market,
|
|
16410
17554
|
obligation,
|
|
16411
17555
|
reserves: reservesInUse
|
|
16412
|
-
}
|
|
17556
|
+
}));
|
|
16413
17557
|
// Don't need to refresh debt farm for borrow
|
|
16414
17558
|
/*
|
|
16415
17559
|
if (borrowReserve.farmDebt) {
|
|
@@ -16497,7 +17641,7 @@ class KaminoLendingClient {
|
|
|
16497
17641
|
lendingMarket: market,
|
|
16498
17642
|
obligation,
|
|
16499
17643
|
reserves: reservesInUse
|
|
16500
|
-
}
|
|
17644
|
+
}));
|
|
16501
17645
|
const repayIx = await this.base.program.methods.kaminoLendingRepayObligationLiquidityV2(amount).accounts({
|
|
16502
17646
|
glamState,
|
|
16503
17647
|
glamSigner,
|
|
@@ -16541,6 +17685,135 @@ class KaminoLendingClient {
|
|
|
16541
17685
|
};
|
|
16542
17686
|
}
|
|
16543
17687
|
}
|
|
17688
|
+
class KaminoFarmClient {
|
|
17689
|
+
async findAndParseFarmStates(owner) {
|
|
17690
|
+
const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_FARM_PROGRAM, {
|
|
17691
|
+
filters: [
|
|
17692
|
+
{
|
|
17693
|
+
dataSize: 920
|
|
17694
|
+
},
|
|
17695
|
+
{
|
|
17696
|
+
memcmp: {
|
|
17697
|
+
offset: 48,
|
|
17698
|
+
bytes: owner.toBase58()
|
|
17699
|
+
}
|
|
17700
|
+
}
|
|
17701
|
+
]
|
|
17702
|
+
});
|
|
17703
|
+
return accounts.map((account)=>{
|
|
17704
|
+
const data = account.account.data;
|
|
17705
|
+
const farmState = new web3_js.PublicKey(data.subarray(16, 48));
|
|
17706
|
+
return {
|
|
17707
|
+
userFarmState: account.pubkey,
|
|
17708
|
+
farmState
|
|
17709
|
+
};
|
|
17710
|
+
});
|
|
17711
|
+
}
|
|
17712
|
+
async parseFarm(data) {
|
|
17713
|
+
const globalConfig = new web3_js.PublicKey(data.subarray(40, 72));
|
|
17714
|
+
const rewardsOffset = 192;
|
|
17715
|
+
const numRewards = 10;
|
|
17716
|
+
const rewardSize = 704;
|
|
17717
|
+
const rewardsData = data.subarray(rewardsOffset, rewardsOffset + numRewards * rewardSize);
|
|
17718
|
+
const rewards = Array.from({
|
|
17719
|
+
length: numRewards
|
|
17720
|
+
}, (_, i)=>{
|
|
17721
|
+
const rewardData = rewardsData.subarray(i * rewardSize, (i + 1) * rewardSize);
|
|
17722
|
+
const mint = new web3_js.PublicKey(rewardData.subarray(0, 32));
|
|
17723
|
+
const tokenProgram = new web3_js.PublicKey(rewardData.subarray(40, 72));
|
|
17724
|
+
const rewardsVault = new web3_js.PublicKey(rewardData.subarray(120, 152));
|
|
17725
|
+
const minClaimDurationSeconds = new anchor.BN(rewardData.subarray(480, 488), "le");
|
|
17726
|
+
return {
|
|
17727
|
+
index: i,
|
|
17728
|
+
mint,
|
|
17729
|
+
minClaimDurationSeconds,
|
|
17730
|
+
tokenProgram,
|
|
17731
|
+
rewardsVault
|
|
17732
|
+
};
|
|
17733
|
+
}).filter((r)=>{
|
|
17734
|
+
if (r.mint.equals(web3_js.PublicKey.default)) {
|
|
17735
|
+
return false;
|
|
17736
|
+
}
|
|
17737
|
+
// Filter out rewards with minClaimDurationSeconds > 1 year, they are considered disabled
|
|
17738
|
+
if (r.minClaimDurationSeconds.div(new anchor.BN(365 * 24 * 60 * 60)).gt(new anchor.BN(1))) {
|
|
17739
|
+
return false;
|
|
17740
|
+
}
|
|
17741
|
+
return true;
|
|
17742
|
+
});
|
|
17743
|
+
return {
|
|
17744
|
+
globalConfig,
|
|
17745
|
+
rewards
|
|
17746
|
+
};
|
|
17747
|
+
}
|
|
17748
|
+
async fetchAndParseFarms(farms) {
|
|
17749
|
+
const farmAccounts = await this.base.provider.connection.getMultipleAccountsInfo(farms);
|
|
17750
|
+
const map = new Map();
|
|
17751
|
+
for(let i = 0; i < farmAccounts.length; i++){
|
|
17752
|
+
const account = farmAccounts[i];
|
|
17753
|
+
if (!account) {
|
|
17754
|
+
continue;
|
|
17755
|
+
}
|
|
17756
|
+
const data = account.data;
|
|
17757
|
+
const parsedFarm = await this.parseFarm(data);
|
|
17758
|
+
map.set(farms[i].toBase58(), parsedFarm);
|
|
17759
|
+
}
|
|
17760
|
+
return map;
|
|
17761
|
+
}
|
|
17762
|
+
async harvest(statePda, txOptions = {}) {
|
|
17763
|
+
const tx = await this.harvestTx(new web3_js.PublicKey(statePda), txOptions);
|
|
17764
|
+
return await this.base.sendAndConfirm(tx);
|
|
17765
|
+
}
|
|
17766
|
+
async harvestTx(glamState, txOptions = {}) {
|
|
17767
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17768
|
+
const vault = this.base.getVaultPda(glamState);
|
|
17769
|
+
const farmStates = await this.findAndParseFarmStates(vault);
|
|
17770
|
+
const parsedFarms = await this.fetchAndParseFarms(farmStates.map((f)=>f.farmState));
|
|
17771
|
+
const tx = new web3_js.Transaction();
|
|
17772
|
+
for (const { userFarmState, farmState } of farmStates){
|
|
17773
|
+
const { globalConfig, rewards } = parsedFarms.get(farmState.toBase58());
|
|
17774
|
+
for (const { index, mint, tokenProgram, rewardsVault } of rewards){
|
|
17775
|
+
console.log("Reward token:", mint.toBase58());
|
|
17776
|
+
const vaultAta = this.base.getVaultAta(glamState, mint, tokenProgram);
|
|
17777
|
+
const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultAta, vault, mint, tokenProgram);
|
|
17778
|
+
const harvestIx = await this.base.program.methods.kaminoFarmHarvestReward(new anchor.BN(index)).accounts({
|
|
17779
|
+
glamState,
|
|
17780
|
+
glamSigner,
|
|
17781
|
+
userState: userFarmState,
|
|
17782
|
+
farmState,
|
|
17783
|
+
globalConfig,
|
|
17784
|
+
rewardMint: mint,
|
|
17785
|
+
userRewardAta: vaultAta,
|
|
17786
|
+
rewardsVault,
|
|
17787
|
+
rewardsTreasuryVault: this.rewardsTreasuryVault(globalConfig, mint),
|
|
17788
|
+
farmVaultsAuthority: this.farmVaultsAuthority(farmState),
|
|
17789
|
+
scopePrices: null,
|
|
17790
|
+
tokenProgram
|
|
17791
|
+
}).instruction();
|
|
17792
|
+
tx.add(createAtaIx, harvestIx);
|
|
17793
|
+
}
|
|
17794
|
+
}
|
|
17795
|
+
const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
|
|
17796
|
+
LOOKUP_TABLE
|
|
17797
|
+
]);
|
|
17798
|
+
const vTx = await this.base.intoVersionedTransaction(tx, {
|
|
17799
|
+
...txOptions,
|
|
17800
|
+
lookupTables
|
|
17801
|
+
});
|
|
17802
|
+
return vTx;
|
|
17803
|
+
}
|
|
17804
|
+
constructor(base){
|
|
17805
|
+
this.base = base;
|
|
17806
|
+
this.farmVaultsAuthority = (farm)=>web3_js.PublicKey.findProgramAddressSync([
|
|
17807
|
+
Buffer.from("authority"),
|
|
17808
|
+
farm.toBuffer()
|
|
17809
|
+
], KAMINO_FARM_PROGRAM)[0];
|
|
17810
|
+
this.rewardsTreasuryVault = (globalConfig, mint)=>web3_js.PublicKey.findProgramAddressSync([
|
|
17811
|
+
Buffer.from("tvault"),
|
|
17812
|
+
globalConfig.toBuffer(),
|
|
17813
|
+
mint.toBuffer()
|
|
17814
|
+
], KAMINO_FARM_PROGRAM)[0];
|
|
17815
|
+
}
|
|
17816
|
+
}
|
|
16544
17817
|
|
|
16545
17818
|
// Pubkey::find_program_address(&[b"__event_authority"], &dlmm_interface::ID)
|
|
16546
17819
|
const EVENT_AUTHORITY = new web3_js.PublicKey("D1ZN9Wj1fRSUQfCjhvnu1hqDMT7hzjzBBpi12nVniYD6");
|
|
@@ -17017,6 +18290,28 @@ class PriceClient {
|
|
|
17017
18290
|
});
|
|
17018
18291
|
return pricedAssets.reduce((sum, p)=>new anchor.BN(p.amount).add(sum), new anchor.BN(0));
|
|
17019
18292
|
}
|
|
18293
|
+
async priceKaminoIxs(glamState, priceDenom) {
|
|
18294
|
+
const glamVault = this.base.getVaultPda(glamState);
|
|
18295
|
+
const obligations = await fetchKaminoObligations(this.base.provider.connection, glamVault);
|
|
18296
|
+
const refreshIxs = [];
|
|
18297
|
+
for (const obligation of obligations){
|
|
18298
|
+
const ixs = await this.klend.getRefreshIxs(obligation, false); // skip farms
|
|
18299
|
+
refreshIxs.push(...ixs);
|
|
18300
|
+
}
|
|
18301
|
+
// @ts-ignore
|
|
18302
|
+
const priceIx = await this.base.program.methods.priceKaminoObligations(priceDenom).accounts({
|
|
18303
|
+
glamState,
|
|
18304
|
+
solOracle: SOL_ORACLE
|
|
18305
|
+
}).remainingAccounts(obligations.map((o)=>({
|
|
18306
|
+
pubkey: o,
|
|
18307
|
+
isSigner: false,
|
|
18308
|
+
isWritable: false
|
|
18309
|
+
}))).instruction();
|
|
18310
|
+
return [
|
|
18311
|
+
...refreshIxs,
|
|
18312
|
+
priceIx
|
|
18313
|
+
];
|
|
18314
|
+
}
|
|
17020
18315
|
async priceVaultIxs(glamState, priceDenom) {
|
|
17021
18316
|
const vault = this.base.getVaultPda(glamState);
|
|
17022
18317
|
const tickets = await fetchMarinadeTicketAccounts(this.base.provider.connection, vault);
|
|
@@ -17046,29 +18341,18 @@ class PriceClient {
|
|
|
17046
18341
|
glamState,
|
|
17047
18342
|
solOracle: SOL_ORACLE
|
|
17048
18343
|
}).remainingAccounts(await this.remainingAccountsForPricingMeteora(glamState)).instruction();
|
|
17049
|
-
const
|
|
17050
|
-
glamState,
|
|
17051
|
-
solOracle: SOL_ORACLE
|
|
17052
|
-
}).remainingAccounts(await this.remainingAccountsForPricingKamino(glamState)).instruction();
|
|
18344
|
+
const priceKaminoIxs = await this.priceKaminoIxs(glamState, priceDenom);
|
|
17053
18345
|
return [
|
|
17054
18346
|
priceTicketsIx,
|
|
17055
18347
|
priceStakesIx,
|
|
17056
18348
|
priceVaultIx,
|
|
17057
18349
|
priceMeteoraIx,
|
|
17058
|
-
|
|
18350
|
+
...priceKaminoIxs
|
|
17059
18351
|
];
|
|
17060
18352
|
}
|
|
17061
|
-
constructor(base){
|
|
18353
|
+
constructor(base, klend){
|
|
17062
18354
|
this.base = base;
|
|
17063
|
-
this.
|
|
17064
|
-
const glamVault = this.base.getVaultPda(glamState);
|
|
17065
|
-
const obligationAccounts = await fetchKaminoObligations(this.base.provider.connection, glamVault);
|
|
17066
|
-
return obligationAccounts.map((a)=>({
|
|
17067
|
-
pubkey: a,
|
|
17068
|
-
isSigner: false,
|
|
17069
|
-
isWritable: false
|
|
17070
|
-
}));
|
|
17071
|
-
};
|
|
18355
|
+
this.klend = klend;
|
|
17072
18356
|
this.remainingAccountsForPricingMeteora = async (glamState)=>{
|
|
17073
18357
|
const glamVault = this.base.getVaultPda(glamState);
|
|
17074
18358
|
const positions = await fetchMeteoraPositions(this.base.provider.connection, glamVault);
|
|
@@ -17154,7 +18438,7 @@ class PriceClient {
|
|
|
17154
18438
|
}
|
|
17155
18439
|
get price() {
|
|
17156
18440
|
if (!this._price) {
|
|
17157
|
-
this._price = new PriceClient(this);
|
|
18441
|
+
this._price = new PriceClient(this, this.kaminoLending);
|
|
17158
18442
|
}
|
|
17159
18443
|
return this._price;
|
|
17160
18444
|
}
|
|
@@ -17176,6 +18460,12 @@ class PriceClient {
|
|
|
17176
18460
|
}
|
|
17177
18461
|
return this._kaminoLending;
|
|
17178
18462
|
}
|
|
18463
|
+
get kaminoFarm() {
|
|
18464
|
+
if (!this._kaminoFarm) {
|
|
18465
|
+
this._kaminoFarm = new KaminoFarmClient(this);
|
|
18466
|
+
}
|
|
18467
|
+
return this._kaminoFarm;
|
|
18468
|
+
}
|
|
17179
18469
|
get meteoraDlmm() {
|
|
17180
18470
|
if (!this._meteoraDlmm) {
|
|
17181
18471
|
this._meteoraDlmm = new MeteoraDlmmClient(this);
|
|
@@ -17191,7 +18481,7 @@ const getPriorityFeeEstimate = async (heliusApiKey, tx, accountKeys, priorityLev
|
|
|
17191
18481
|
if (!tx && !accountKeys) {
|
|
17192
18482
|
throw new Error("Either tx or accountKeys must be provided");
|
|
17193
18483
|
}
|
|
17194
|
-
const options = priorityLevel ? {
|
|
18484
|
+
const options = priorityLevel && priorityLevel !== "Recommended" ? {
|
|
17195
18485
|
priorityLevel
|
|
17196
18486
|
} : {
|
|
17197
18487
|
recommended: true
|
|
@@ -17223,16 +18513,60 @@ const getPriorityFeeEstimate = async (heliusApiKey, tx, accountKeys, priorityLev
|
|
|
17223
18513
|
return data.result.priorityFeeEstimate;
|
|
17224
18514
|
};
|
|
17225
18515
|
|
|
18516
|
+
function getLimitOrderParams(params) {
|
|
18517
|
+
return getOrderParams(Object.assign({}, params, {
|
|
18518
|
+
orderType: OrderType.LIMIT
|
|
18519
|
+
}));
|
|
18520
|
+
}
|
|
18521
|
+
function getTriggerMarketOrderParams(params) {
|
|
18522
|
+
return getOrderParams(Object.assign({}, params, {
|
|
18523
|
+
orderType: OrderType.TRIGGER_MARKET
|
|
18524
|
+
}));
|
|
18525
|
+
}
|
|
18526
|
+
function getTriggerLimitOrderParams(params) {
|
|
18527
|
+
return getOrderParams(Object.assign({}, params, {
|
|
18528
|
+
orderType: OrderType.TRIGGER_LIMIT
|
|
18529
|
+
}));
|
|
18530
|
+
}
|
|
18531
|
+
function getMarketOrderParams(params) {
|
|
18532
|
+
return getOrderParams(Object.assign({}, params, {
|
|
18533
|
+
orderType: OrderType.MARKET
|
|
18534
|
+
}));
|
|
18535
|
+
}
|
|
18536
|
+
/**
|
|
18537
|
+
* Creates an OrderParams object with the given OptionalOrderParams and any params to override.
|
|
18538
|
+
*
|
|
18539
|
+
* example:
|
|
18540
|
+
* ```
|
|
18541
|
+
* const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
|
|
18542
|
+
* ```
|
|
18543
|
+
*
|
|
18544
|
+
* @param optionalOrderParams
|
|
18545
|
+
* @param overridingParams
|
|
18546
|
+
* @returns
|
|
18547
|
+
*/ function getOrderParams(optionalOrderParams, overridingParams = {}) {
|
|
18548
|
+
return Object.assign({}, DefaultOrderParams, optionalOrderParams, overridingParams);
|
|
18549
|
+
}
|
|
18550
|
+
|
|
17226
18551
|
exports.ASSETS_MAINNET = ASSETS_MAINNET;
|
|
17227
18552
|
exports.ASSETS_TESTS = ASSETS_TESTS;
|
|
18553
|
+
exports.AssetTier = AssetTier;
|
|
17228
18554
|
exports.BaseClient = BaseClient;
|
|
17229
18555
|
exports.ClusterNetwork = ClusterNetwork;
|
|
17230
18556
|
exports.CompanyModel = CompanyModel;
|
|
18557
|
+
exports.ContractTier = ContractTier;
|
|
18558
|
+
exports.ContractType = ContractType;
|
|
17231
18559
|
exports.CreatedModel = CreatedModel;
|
|
17232
18560
|
exports.DRIFT_PROGRAM_ID = DRIFT_PROGRAM_ID;
|
|
18561
|
+
exports.DefaultOrderParams = DefaultOrderParams;
|
|
17233
18562
|
exports.DelegateAcl = DelegateAcl;
|
|
18563
|
+
exports.DepositDirection = DepositDirection;
|
|
18564
|
+
exports.DepositExplanation = DepositExplanation;
|
|
17234
18565
|
exports.DriftClient = DriftClient;
|
|
18566
|
+
exports.ExchangeStatus = ExchangeStatus;
|
|
18567
|
+
exports.FuelOverflowStatus = FuelOverflowStatus;
|
|
17235
18568
|
exports.FundOpenfundsModel = FundOpenfundsModel;
|
|
18569
|
+
exports.GLAM_REFERRER = GLAM_REFERRER;
|
|
17236
18570
|
exports.GOVERNANCE_PROGRAM_ID = GOVERNANCE_PROGRAM_ID;
|
|
17237
18571
|
exports.GlamClient = GlamClient;
|
|
17238
18572
|
exports.GlamError = GlamError;
|
|
@@ -17240,6 +18574,7 @@ exports.GlamIdl = GlamIdl;
|
|
|
17240
18574
|
exports.GlamIntegrations = GlamIntegrations;
|
|
17241
18575
|
exports.GlamPermissions = GlamPermissions;
|
|
17242
18576
|
exports.GlamProtocolIdlJson = GlamProtocolIdlJson;
|
|
18577
|
+
exports.InsuranceFundOperation = InsuranceFundOperation;
|
|
17243
18578
|
exports.JITOSOL = JITOSOL;
|
|
17244
18579
|
exports.JITO_STAKE_POOL = JITO_STAKE_POOL;
|
|
17245
18580
|
exports.JITO_TIP_DEFAULT = JITO_TIP_DEFAULT;
|
|
@@ -17253,6 +18588,8 @@ exports.JupiterVoteClient = JupiterVoteClient;
|
|
|
17253
18588
|
exports.KAMINO_FARM_PROGRAM = KAMINO_FARM_PROGRAM;
|
|
17254
18589
|
exports.KAMINO_LENDING_PROGRAM = KAMINO_LENDING_PROGRAM;
|
|
17255
18590
|
exports.KAMINO_OBTRIGATION_SIZE = KAMINO_OBTRIGATION_SIZE;
|
|
18591
|
+
exports.LPAction = LPAction;
|
|
18592
|
+
exports.LiquidationType = LiquidationType;
|
|
17256
18593
|
exports.MARINADE_PROGRAM_ID = MARINADE_PROGRAM_ID;
|
|
17257
18594
|
exports.MARINADE_TICKET_SIZE = MARINADE_TICKET_SIZE;
|
|
17258
18595
|
exports.MEMO_PROGRAM = MEMO_PROGRAM;
|
|
@@ -17261,11 +18598,27 @@ exports.METEORA_DLMM_PROGRAM = METEORA_DLMM_PROGRAM;
|
|
|
17261
18598
|
exports.METEORA_POSITION_SIZE = METEORA_POSITION_SIZE;
|
|
17262
18599
|
exports.MSOL = MSOL;
|
|
17263
18600
|
exports.ManagerModel = ManagerModel;
|
|
18601
|
+
exports.MarginMode = MarginMode;
|
|
18602
|
+
exports.MarketStatus = MarketStatus;
|
|
18603
|
+
exports.MarketType = MarketType;
|
|
17264
18604
|
exports.Metadata = Metadata;
|
|
17265
18605
|
exports.MintIdlModel = MintIdlModel;
|
|
17266
18606
|
exports.MintModel = MintModel;
|
|
17267
18607
|
exports.MintOpenfundsModel = MintOpenfundsModel;
|
|
18608
|
+
exports.ModifyOrderPolicy = ModifyOrderPolicy;
|
|
18609
|
+
exports.OracleSource = OracleSource;
|
|
18610
|
+
exports.OracleSourceNum = OracleSourceNum;
|
|
18611
|
+
exports.OrderAction = OrderAction;
|
|
18612
|
+
exports.OrderActionExplanation = OrderActionExplanation;
|
|
18613
|
+
exports.OrderStatus = OrderStatus;
|
|
18614
|
+
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
18615
|
+
exports.OrderType = OrderType;
|
|
18616
|
+
exports.PerpOperation = PerpOperation;
|
|
18617
|
+
exports.PlaceAndTakeOrderSuccessCondition = PlaceAndTakeOrderSuccessCondition;
|
|
18618
|
+
exports.PositionDirection = PositionDirection;
|
|
18619
|
+
exports.PostOnlyParams = PostOnlyParams;
|
|
17268
18620
|
exports.PriceDenom = PriceDenom;
|
|
18621
|
+
exports.ReferrerStatus = ReferrerStatus;
|
|
17269
18622
|
exports.SANCTUM_STAKE_POOL_PROGRAM_ID = SANCTUM_STAKE_POOL_PROGRAM_ID;
|
|
17270
18623
|
exports.SEED_ESCROW = SEED_ESCROW;
|
|
17271
18624
|
exports.SEED_METADATA = SEED_METADATA;
|
|
@@ -17274,20 +18627,43 @@ exports.SEED_STATE = SEED_STATE;
|
|
|
17274
18627
|
exports.SEED_VAULT = SEED_VAULT;
|
|
17275
18628
|
exports.SOL_ORACLE = SOL_ORACLE;
|
|
17276
18629
|
exports.STAKE_ACCOUNT_SIZE = STAKE_ACCOUNT_SIZE;
|
|
18630
|
+
exports.SettlePnlExplanation = SettlePnlExplanation;
|
|
18631
|
+
exports.SettlePnlMode = SettlePnlMode;
|
|
18632
|
+
exports.SpotBalanceType = SpotBalanceType;
|
|
18633
|
+
exports.SpotFulfillmentConfigStatus = SpotFulfillmentConfigStatus;
|
|
18634
|
+
exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
|
|
18635
|
+
exports.SpotFulfillmentType = SpotFulfillmentType;
|
|
18636
|
+
exports.SpotOperation = SpotOperation;
|
|
18637
|
+
exports.StakeAction = StakeAction;
|
|
17277
18638
|
exports.StateIdlModel = StateIdlModel;
|
|
17278
18639
|
exports.StateModel = StateModel;
|
|
18640
|
+
exports.SwapDirection = SwapDirection;
|
|
18641
|
+
exports.SwapReduceOnly = SwapReduceOnly;
|
|
17279
18642
|
exports.TRANSFER_HOOK_PROGRAM = TRANSFER_HOOK_PROGRAM;
|
|
18643
|
+
exports.TradeSide = TradeSide;
|
|
17280
18644
|
exports.USDC = USDC;
|
|
18645
|
+
exports.UserStatus = UserStatus;
|
|
17281
18646
|
exports.WBTC = WBTC;
|
|
17282
18647
|
exports.WETH = WETH;
|
|
17283
18648
|
exports.WSOL = WSOL;
|
|
18649
|
+
exports.ZERO = ZERO;
|
|
18650
|
+
exports.decodeUser = decodeUser;
|
|
17284
18651
|
exports.fetchKaminoObligations = fetchKaminoObligations;
|
|
17285
18652
|
exports.fetchMarinadeTicketAccounts = fetchMarinadeTicketAccounts;
|
|
17286
18653
|
exports.fetchMeteoraPositions = fetchMeteoraPositions;
|
|
17287
18654
|
exports.fetchStakeAccounts = fetchStakeAccounts;
|
|
17288
18655
|
exports.getGlamProgram = getGlamProgram;
|
|
17289
18656
|
exports.getGlamProgramId = getGlamProgramId;
|
|
18657
|
+
exports.getLimitOrderParams = getLimitOrderParams;
|
|
18658
|
+
exports.getMarketOrderParams = getMarketOrderParams;
|
|
18659
|
+
exports.getOrderParams = getOrderParams;
|
|
17290
18660
|
exports.getPriorityFeeEstimate = getPriorityFeeEstimate;
|
|
17291
18661
|
exports.getSimulationComputeUnits = getSimulationComputeUnits;
|
|
18662
|
+
exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
|
|
18663
|
+
exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
|
|
18664
|
+
exports.getVariant = getVariant;
|
|
17292
18665
|
exports.isBrowser = isBrowser;
|
|
18666
|
+
exports.isOneOfVariant = isOneOfVariant;
|
|
18667
|
+
exports.isVariant = isVariant;
|
|
17293
18668
|
exports.parseMeteoraPosition = parseMeteoraPosition;
|
|
18669
|
+
exports.setsAreEqual = setsAreEqual;
|