@jpool/bond-sdk 0.9.0-next.16 → 0.9.0-next.18
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/dist/index.d.mts +96 -89
- package/dist/index.d.ts +96 -89
- package/dist/index.js +56 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4570,6 +4570,10 @@ var BondTypeVariant = {
|
|
|
4570
4570
|
Performance: { performance: {} },
|
|
4571
4571
|
Crowdfunding: { crowdfunding: {} }
|
|
4572
4572
|
};
|
|
4573
|
+
var BondStateStatusVariant = {
|
|
4574
|
+
Active: { active: {} },
|
|
4575
|
+
Disabled: { disabled: {} }
|
|
4576
|
+
};
|
|
4573
4577
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4574
4578
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4575
4579
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
@@ -4959,68 +4963,6 @@ var jbond_default = {
|
|
|
4959
4963
|
}
|
|
4960
4964
|
]
|
|
4961
4965
|
},
|
|
4962
|
-
{
|
|
4963
|
-
name: "bond_disable",
|
|
4964
|
-
docs: [
|
|
4965
|
-
"Disables a validator's bond, preventing it from participating further."
|
|
4966
|
-
],
|
|
4967
|
-
discriminator: [
|
|
4968
|
-
159,
|
|
4969
|
-
156,
|
|
4970
|
-
97,
|
|
4971
|
-
253,
|
|
4972
|
-
70,
|
|
4973
|
-
122,
|
|
4974
|
-
117,
|
|
4975
|
-
129
|
|
4976
|
-
],
|
|
4977
|
-
accounts: [
|
|
4978
|
-
{
|
|
4979
|
-
name: "bond_state",
|
|
4980
|
-
writable: true
|
|
4981
|
-
},
|
|
4982
|
-
{
|
|
4983
|
-
name: "authority",
|
|
4984
|
-
writable: true,
|
|
4985
|
-
signer: true,
|
|
4986
|
-
relations: [
|
|
4987
|
-
"bond_state"
|
|
4988
|
-
]
|
|
4989
|
-
}
|
|
4990
|
-
],
|
|
4991
|
-
args: []
|
|
4992
|
-
},
|
|
4993
|
-
{
|
|
4994
|
-
name: "bond_enable",
|
|
4995
|
-
docs: [
|
|
4996
|
-
"Enables a previously disabled validator's bond."
|
|
4997
|
-
],
|
|
4998
|
-
discriminator: [
|
|
4999
|
-
133,
|
|
5000
|
-
48,
|
|
5001
|
-
84,
|
|
5002
|
-
9,
|
|
5003
|
-
117,
|
|
5004
|
-
131,
|
|
5005
|
-
164,
|
|
5006
|
-
128
|
|
5007
|
-
],
|
|
5008
|
-
accounts: [
|
|
5009
|
-
{
|
|
5010
|
-
name: "bond_state",
|
|
5011
|
-
writable: true
|
|
5012
|
-
},
|
|
5013
|
-
{
|
|
5014
|
-
name: "authority",
|
|
5015
|
-
writable: true,
|
|
5016
|
-
signer: true,
|
|
5017
|
-
relations: [
|
|
5018
|
-
"bond_state"
|
|
5019
|
-
]
|
|
5020
|
-
}
|
|
5021
|
-
],
|
|
5022
|
-
args: []
|
|
5023
|
-
},
|
|
5024
4966
|
{
|
|
5025
4967
|
name: "bond_initialize",
|
|
5026
4968
|
docs: [
|
|
@@ -5043,8 +4985,7 @@ var jbond_default = {
|
|
|
5043
4985
|
],
|
|
5044
4986
|
accounts: [
|
|
5045
4987
|
{
|
|
5046
|
-
name: "global_state"
|
|
5047
|
-
writable: true
|
|
4988
|
+
name: "global_state"
|
|
5048
4989
|
},
|
|
5049
4990
|
{
|
|
5050
4991
|
name: "bond_state",
|
|
@@ -5080,7 +5021,10 @@ var jbond_default = {
|
|
|
5080
5021
|
{
|
|
5081
5022
|
name: "authority",
|
|
5082
5023
|
writable: true,
|
|
5083
|
-
signer: true
|
|
5024
|
+
signer: true,
|
|
5025
|
+
relations: [
|
|
5026
|
+
"global_state"
|
|
5027
|
+
]
|
|
5084
5028
|
},
|
|
5085
5029
|
{
|
|
5086
5030
|
name: "reserve"
|
|
@@ -5946,6 +5890,16 @@ var jbond_default = {
|
|
|
5946
5890
|
type: {
|
|
5947
5891
|
kind: "struct",
|
|
5948
5892
|
fields: [
|
|
5893
|
+
{
|
|
5894
|
+
name: "status",
|
|
5895
|
+
type: {
|
|
5896
|
+
option: {
|
|
5897
|
+
defined: {
|
|
5898
|
+
name: "BondStatus"
|
|
5899
|
+
}
|
|
5900
|
+
}
|
|
5901
|
+
}
|
|
5902
|
+
},
|
|
5949
5903
|
{
|
|
5950
5904
|
name: "new_reserve",
|
|
5951
5905
|
type: {
|
|
@@ -6118,6 +6072,9 @@ var jbond_default = {
|
|
|
6118
6072
|
},
|
|
6119
6073
|
{
|
|
6120
6074
|
name: "status",
|
|
6075
|
+
docs: [
|
|
6076
|
+
"Current status of the bond"
|
|
6077
|
+
],
|
|
6121
6078
|
type: {
|
|
6122
6079
|
defined: {
|
|
6123
6080
|
name: "BondStatus"
|
|
@@ -6602,14 +6559,6 @@ var JBondClient = class _JBondClient {
|
|
|
6602
6559
|
const ix = await this.buildBondFinishIx(props);
|
|
6603
6560
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6604
6561
|
}
|
|
6605
|
-
async bondEnable(props) {
|
|
6606
|
-
const ix = await this.buildBondEnableIx(props);
|
|
6607
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6608
|
-
}
|
|
6609
|
-
async bondDisable(props) {
|
|
6610
|
-
const ix = await this.buildBondDisableIx(props);
|
|
6611
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6612
|
-
}
|
|
6613
6562
|
async buildBondGlobalStateInitializeIx(props) {
|
|
6614
6563
|
const [globalState] = this.pda.globalState();
|
|
6615
6564
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
@@ -6667,6 +6616,7 @@ var JBondClient = class _JBondClient {
|
|
|
6667
6616
|
async buildConfigureIx(props) {
|
|
6668
6617
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6669
6618
|
return this.program.methods.bondConfigure({
|
|
6619
|
+
status: props.bondStateStatus ?? null,
|
|
6670
6620
|
newReserve: props.newReserve ?? null,
|
|
6671
6621
|
newAuthority: props.newAuthority ?? null
|
|
6672
6622
|
}).accountsStrict({
|
|
@@ -6682,7 +6632,7 @@ var JBondClient = class _JBondClient {
|
|
|
6682
6632
|
if (!creator) {
|
|
6683
6633
|
throw new Error("Missing creator");
|
|
6684
6634
|
}
|
|
6685
|
-
const collateralType = (await this.getBondState(bondType, name))
|
|
6635
|
+
const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
|
|
6686
6636
|
const accounts = {
|
|
6687
6637
|
bondState,
|
|
6688
6638
|
validatorBond,
|
|
@@ -6725,7 +6675,7 @@ var JBondClient = class _JBondClient {
|
|
|
6725
6675
|
creator: props.payer
|
|
6726
6676
|
}));
|
|
6727
6677
|
}
|
|
6728
|
-
const collateralType = (await this.getBondState(bondType, name))
|
|
6678
|
+
const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
|
|
6729
6679
|
const accounts = {
|
|
6730
6680
|
bondState,
|
|
6731
6681
|
validatorBond,
|
|
@@ -6762,7 +6712,7 @@ var JBondClient = class _JBondClient {
|
|
|
6762
6712
|
if (!payer || !destination) {
|
|
6763
6713
|
throw new Error("Missing payer/destination");
|
|
6764
6714
|
}
|
|
6765
|
-
const collateralType = (await this.getBondState(bondType, name))
|
|
6715
|
+
const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
|
|
6766
6716
|
const accounts = {
|
|
6767
6717
|
bondState,
|
|
6768
6718
|
validatorBond,
|
|
@@ -6790,12 +6740,12 @@ var JBondClient = class _JBondClient {
|
|
|
6790
6740
|
const { bondType, name } = props;
|
|
6791
6741
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6792
6742
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6793
|
-
const reserve = props.reserve ?? (await this.getBondState(bondType, name))
|
|
6743
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).bond_state.reserve;
|
|
6794
6744
|
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6795
6745
|
if (!reserve) {
|
|
6796
6746
|
throw new Error("Reserve not set");
|
|
6797
6747
|
}
|
|
6798
|
-
const collateralType = (await this.getBondState(bondType, name))
|
|
6748
|
+
const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
|
|
6799
6749
|
const accounts = {
|
|
6800
6750
|
bondState,
|
|
6801
6751
|
validatorBond,
|
|
@@ -6844,20 +6794,6 @@ var JBondClient = class _JBondClient {
|
|
|
6844
6794
|
authority: this.program.provider.wallet?.publicKey
|
|
6845
6795
|
}).instruction();
|
|
6846
6796
|
}
|
|
6847
|
-
async buildBondEnableIx(props) {
|
|
6848
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6849
|
-
return this.program.methods.bondEnable().accountsPartial({
|
|
6850
|
-
bondState,
|
|
6851
|
-
authority: this.program.provider.wallet?.publicKey
|
|
6852
|
-
}).instruction();
|
|
6853
|
-
}
|
|
6854
|
-
async buildBondDisableIx(props) {
|
|
6855
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6856
|
-
return this.program.methods.bondDisable().accountsPartial({
|
|
6857
|
-
bondState,
|
|
6858
|
-
authority: this.program.provider.wallet?.publicKey
|
|
6859
|
-
}).instruction();
|
|
6860
|
-
}
|
|
6861
6797
|
/**
|
|
6862
6798
|
* Fetch global state or throw if not found
|
|
6863
6799
|
*/
|
|
@@ -6869,10 +6805,14 @@ var JBondClient = class _JBondClient {
|
|
|
6869
6805
|
* Fetch bond state with stats
|
|
6870
6806
|
* @param bondType - Type of the bond
|
|
6871
6807
|
* @param bondName - Name of the bond
|
|
6808
|
+
* @param withStats
|
|
6872
6809
|
*/
|
|
6873
6810
|
async getBondState(bondType, bondName, withStats = false) {
|
|
6874
6811
|
const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
|
|
6875
|
-
return
|
|
6812
|
+
return {
|
|
6813
|
+
bond_state: bondState,
|
|
6814
|
+
state_stats: withStats ? await this.getBondStateStats(bondState) : null
|
|
6815
|
+
};
|
|
6876
6816
|
}
|
|
6877
6817
|
/**
|
|
6878
6818
|
* Get all bond states with total collected collateral
|
|
@@ -6888,7 +6828,12 @@ var JBondClient = class _JBondClient {
|
|
|
6888
6828
|
continue;
|
|
6889
6829
|
}
|
|
6890
6830
|
const bondStateStats = await this.getBondStateStats(state);
|
|
6891
|
-
bondStates.push(
|
|
6831
|
+
bondStates.push(
|
|
6832
|
+
{
|
|
6833
|
+
bond_state: state,
|
|
6834
|
+
state_stats: bondStateStats
|
|
6835
|
+
}
|
|
6836
|
+
);
|
|
6892
6837
|
}
|
|
6893
6838
|
return bondStates;
|
|
6894
6839
|
}
|
|
@@ -6903,7 +6848,9 @@ var JBondClient = class _JBondClient {
|
|
|
6903
6848
|
return 1 /* Finished */;
|
|
6904
6849
|
}
|
|
6905
6850
|
}
|
|
6906
|
-
/**
|
|
6851
|
+
/**
|
|
6852
|
+
* Get all validator bonds for a given bond state
|
|
6853
|
+
*/
|
|
6907
6854
|
async getValidatorBondsByState(bondType, bondName) {
|
|
6908
6855
|
const validatorBonds = [];
|
|
6909
6856
|
const bondStatePda = this.pda.bondState(bondType, bondName)[0];
|
|
@@ -6922,9 +6869,6 @@ var JBondClient = class _JBondClient {
|
|
|
6922
6869
|
}
|
|
6923
6870
|
/**
|
|
6924
6871
|
* Fetch validator bond data or null if not found
|
|
6925
|
-
* @param bondType
|
|
6926
|
-
* @param bondName
|
|
6927
|
-
* @param vote
|
|
6928
6872
|
*/
|
|
6929
6873
|
async getValidatorBond(bondType, bondName, vote) {
|
|
6930
6874
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
@@ -6939,7 +6883,7 @@ var JBondClient = class _JBondClient {
|
|
|
6939
6883
|
*/
|
|
6940
6884
|
async getBondCollateralType(bondType, bondName) {
|
|
6941
6885
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6942
|
-
return bondState
|
|
6886
|
+
return bondState.bond_state.collateralType;
|
|
6943
6887
|
}
|
|
6944
6888
|
/**
|
|
6945
6889
|
* Get validator bond account balance (in SOL)
|
|
@@ -6951,7 +6895,7 @@ var JBondClient = class _JBondClient {
|
|
|
6951
6895
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6952
6896
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
6953
6897
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6954
|
-
const bondStateCollateralType = bondStateData
|
|
6898
|
+
const bondStateCollateralType = bondStateData.bond_state.collateralType;
|
|
6955
6899
|
return await matchVariant(bondStateCollateralType, {
|
|
6956
6900
|
native: async () => {
|
|
6957
6901
|
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
@@ -6973,10 +6917,12 @@ var JBondClient = class _JBondClient {
|
|
|
6973
6917
|
}
|
|
6974
6918
|
});
|
|
6975
6919
|
}
|
|
6976
|
-
|
|
6920
|
+
/**
|
|
6921
|
+
* Get total collected collateral for a bond state
|
|
6922
|
+
*/
|
|
6977
6923
|
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
6978
6924
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6979
|
-
const bondStateCollateralType = bondStateData
|
|
6925
|
+
const bondStateCollateralType = bondStateData.bond_state.collateralType;
|
|
6980
6926
|
const chunk = (arr, n = 100) => {
|
|
6981
6927
|
const res = [];
|
|
6982
6928
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -7034,6 +6980,11 @@ var JBondClient = class _JBondClient {
|
|
|
7034
6980
|
}
|
|
7035
6981
|
});
|
|
7036
6982
|
}
|
|
6983
|
+
/**
|
|
6984
|
+
* Get bond state stats
|
|
6985
|
+
* @param state
|
|
6986
|
+
* @private
|
|
6987
|
+
*/
|
|
7037
6988
|
async getBondStateStats(state) {
|
|
7038
6989
|
const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
|
|
7039
6990
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
@@ -7041,11 +6992,10 @@ var JBondClient = class _JBondClient {
|
|
|
7041
6992
|
state.name,
|
|
7042
6993
|
validatorBonds.map((vb) => vb.voteAccount)
|
|
7043
6994
|
);
|
|
7044
|
-
|
|
6995
|
+
return {
|
|
7045
6996
|
totalCollected,
|
|
7046
|
-
status:
|
|
6997
|
+
status: this.getBondStateSessionStatus(state)
|
|
7047
6998
|
};
|
|
7048
|
-
return bondStateStats;
|
|
7049
6999
|
}
|
|
7050
7000
|
/**
|
|
7051
7001
|
* Load stake pool account and cache it if not already cached
|
|
@@ -7092,6 +7042,6 @@ buffer/index.js:
|
|
|
7092
7042
|
*)
|
|
7093
7043
|
*/
|
|
7094
7044
|
|
|
7095
|
-
export { BondClientEnv, BondTransactionType, BondTypeVariant, ENV_PROGRAM_ID, JBondClient, JPOOL_STAKE_POOL, NodeWallet, Seeds, SessionStatus, bondTypeToSeed };
|
|
7045
|
+
export { BondClientEnv, BondStateStatusVariant, BondTransactionType, BondTypeVariant, ENV_PROGRAM_ID, JBondClient, JPOOL_STAKE_POOL, NodeWallet, Seeds, SessionStatus, bondTypeToSeed };
|
|
7096
7046
|
//# sourceMappingURL=index.mjs.map
|
|
7097
7047
|
//# sourceMappingURL=index.mjs.map
|