@jpool/bond-sdk 0.9.0-next.20 → 0.9.0-next.22
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 +86 -8
- package/dist/index.d.ts +86 -8
- package/dist/index.js +107 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4984,9 +4984,6 @@ var jbond_default = {
|
|
|
4984
4984
|
210
|
|
4985
4985
|
],
|
|
4986
4986
|
accounts: [
|
|
4987
|
-
{
|
|
4988
|
-
name: "global_state"
|
|
4989
|
-
},
|
|
4990
4987
|
{
|
|
4991
4988
|
name: "bond_state",
|
|
4992
4989
|
writable: true,
|
|
@@ -5021,10 +5018,7 @@ var jbond_default = {
|
|
|
5021
5018
|
{
|
|
5022
5019
|
name: "authority",
|
|
5023
5020
|
writable: true,
|
|
5024
|
-
signer: true
|
|
5025
|
-
relations: [
|
|
5026
|
-
"global_state"
|
|
5027
|
-
]
|
|
5021
|
+
signer: true
|
|
5028
5022
|
},
|
|
5029
5023
|
{
|
|
5030
5024
|
name: "reserve"
|
|
@@ -5573,6 +5567,80 @@ var jbond_default = {
|
|
|
5573
5567
|
],
|
|
5574
5568
|
args: []
|
|
5575
5569
|
},
|
|
5570
|
+
{
|
|
5571
|
+
name: "migrate_bond",
|
|
5572
|
+
docs: [
|
|
5573
|
+
"Migrates validator bond data from legacy structure to new structure."
|
|
5574
|
+
],
|
|
5575
|
+
discriminator: [
|
|
5576
|
+
107,
|
|
5577
|
+
119,
|
|
5578
|
+
59,
|
|
5579
|
+
110,
|
|
5580
|
+
76,
|
|
5581
|
+
18,
|
|
5582
|
+
37,
|
|
5583
|
+
163
|
|
5584
|
+
],
|
|
5585
|
+
accounts: [
|
|
5586
|
+
{
|
|
5587
|
+
name: "bond_state",
|
|
5588
|
+
writable: true
|
|
5589
|
+
},
|
|
5590
|
+
{
|
|
5591
|
+
name: "legacy_validator_bond",
|
|
5592
|
+
writable: true
|
|
5593
|
+
},
|
|
5594
|
+
{
|
|
5595
|
+
name: "legacy_vote_account"
|
|
5596
|
+
},
|
|
5597
|
+
{
|
|
5598
|
+
name: "validator_bond",
|
|
5599
|
+
writable: true,
|
|
5600
|
+
pda: {
|
|
5601
|
+
seeds: [
|
|
5602
|
+
{
|
|
5603
|
+
kind: "const",
|
|
5604
|
+
value: [
|
|
5605
|
+
118,
|
|
5606
|
+
97,
|
|
5607
|
+
108,
|
|
5608
|
+
105,
|
|
5609
|
+
100,
|
|
5610
|
+
97,
|
|
5611
|
+
116,
|
|
5612
|
+
111,
|
|
5613
|
+
114,
|
|
5614
|
+
95,
|
|
5615
|
+
98,
|
|
5616
|
+
111,
|
|
5617
|
+
110,
|
|
5618
|
+
100
|
|
5619
|
+
]
|
|
5620
|
+
},
|
|
5621
|
+
{
|
|
5622
|
+
kind: "account",
|
|
5623
|
+
path: "bond_state"
|
|
5624
|
+
},
|
|
5625
|
+
{
|
|
5626
|
+
kind: "account",
|
|
5627
|
+
path: "legacy_vote_account"
|
|
5628
|
+
}
|
|
5629
|
+
]
|
|
5630
|
+
}
|
|
5631
|
+
},
|
|
5632
|
+
{
|
|
5633
|
+
name: "creator",
|
|
5634
|
+
writable: true,
|
|
5635
|
+
signer: true
|
|
5636
|
+
},
|
|
5637
|
+
{
|
|
5638
|
+
name: "system_program",
|
|
5639
|
+
address: "11111111111111111111111111111111"
|
|
5640
|
+
}
|
|
5641
|
+
],
|
|
5642
|
+
args: []
|
|
5643
|
+
},
|
|
5576
5644
|
{
|
|
5577
5645
|
name: "session_finish",
|
|
5578
5646
|
docs: [
|
|
@@ -6584,10 +6652,8 @@ var JBondClient = class _JBondClient {
|
|
|
6584
6652
|
* Build initialize instruction
|
|
6585
6653
|
*/
|
|
6586
6654
|
async buildBondInitializeIx(props) {
|
|
6587
|
-
const [globalState] = this.pda.globalState();
|
|
6588
6655
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6589
6656
|
const accounts = {
|
|
6590
|
-
globalState,
|
|
6591
6657
|
bondState,
|
|
6592
6658
|
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
6593
6659
|
reserve: props.reserve,
|
|
@@ -6632,7 +6698,7 @@ var JBondClient = class _JBondClient {
|
|
|
6632
6698
|
if (!creator) {
|
|
6633
6699
|
throw new Error("Missing creator");
|
|
6634
6700
|
}
|
|
6635
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6701
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6636
6702
|
const accounts = {
|
|
6637
6703
|
bondState,
|
|
6638
6704
|
validatorBond,
|
|
@@ -6675,7 +6741,7 @@ var JBondClient = class _JBondClient {
|
|
|
6675
6741
|
creator: props.payer
|
|
6676
6742
|
}));
|
|
6677
6743
|
}
|
|
6678
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6744
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6679
6745
|
const accounts = {
|
|
6680
6746
|
bondState,
|
|
6681
6747
|
validatorBond,
|
|
@@ -6712,7 +6778,7 @@ var JBondClient = class _JBondClient {
|
|
|
6712
6778
|
if (!payer || !destination) {
|
|
6713
6779
|
throw new Error("Missing payer/destination");
|
|
6714
6780
|
}
|
|
6715
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6781
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6716
6782
|
const accounts = {
|
|
6717
6783
|
bondState,
|
|
6718
6784
|
validatorBond,
|
|
@@ -6740,12 +6806,12 @@ var JBondClient = class _JBondClient {
|
|
|
6740
6806
|
const { bondType, name } = props;
|
|
6741
6807
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6742
6808
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6743
|
-
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).
|
|
6809
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).bondState.reserve;
|
|
6744
6810
|
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6745
6811
|
if (!reserve) {
|
|
6746
6812
|
throw new Error("Reserve not set");
|
|
6747
6813
|
}
|
|
6748
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6814
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6749
6815
|
const accounts = {
|
|
6750
6816
|
bondState,
|
|
6751
6817
|
validatorBond,
|
|
@@ -6787,6 +6853,28 @@ var JBondClient = class _JBondClient {
|
|
|
6787
6853
|
authority: this.program.provider.wallet?.publicKey
|
|
6788
6854
|
}).instruction();
|
|
6789
6855
|
}
|
|
6856
|
+
async migrateBond(props) {
|
|
6857
|
+
const ix = await this.buildBondMigrateIx(props);
|
|
6858
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6859
|
+
}
|
|
6860
|
+
async buildBondMigrateIx(props) {
|
|
6861
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6862
|
+
const [legacyValidatorBond] = PublicKey.findProgramAddressSync(
|
|
6863
|
+
[
|
|
6864
|
+
Buffer.from("validator_bond"),
|
|
6865
|
+
new PublicKey(props.voteAccount).toBuffer()
|
|
6866
|
+
],
|
|
6867
|
+
this.programId
|
|
6868
|
+
);
|
|
6869
|
+
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6870
|
+
return this.program.methods.migrateBond().accountsPartial({
|
|
6871
|
+
bondState,
|
|
6872
|
+
legacyValidatorBond,
|
|
6873
|
+
legacyVoteAccount: new PublicKey(props.voteAccount),
|
|
6874
|
+
validatorBond,
|
|
6875
|
+
creator: this.program.provider.wallet?.publicKey
|
|
6876
|
+
}).instruction();
|
|
6877
|
+
}
|
|
6790
6878
|
async buildBondStartIx(props) {
|
|
6791
6879
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6792
6880
|
return this.program.methods.sessionStart(new import_bn2.BN(props.duration_secs)).accountsPartial({
|
|
@@ -6810,8 +6898,8 @@ var JBondClient = class _JBondClient {
|
|
|
6810
6898
|
async getBondState(bondType, bondName, withStats = false) {
|
|
6811
6899
|
const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
|
|
6812
6900
|
return {
|
|
6813
|
-
|
|
6814
|
-
|
|
6901
|
+
bondState,
|
|
6902
|
+
stateStats: withStats ? await this.getBondStateStats(bondState) : null
|
|
6815
6903
|
};
|
|
6816
6904
|
}
|
|
6817
6905
|
/**
|
|
@@ -6883,7 +6971,7 @@ var JBondClient = class _JBondClient {
|
|
|
6883
6971
|
*/
|
|
6884
6972
|
async getBondCollateralType(bondType, bondName) {
|
|
6885
6973
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6886
|
-
return bondState.
|
|
6974
|
+
return bondState.bondState.collateralType;
|
|
6887
6975
|
}
|
|
6888
6976
|
/**
|
|
6889
6977
|
* Get validator bond account balance (in SOL)
|
|
@@ -6895,7 +6983,7 @@ var JBondClient = class _JBondClient {
|
|
|
6895
6983
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6896
6984
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
6897
6985
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6898
|
-
const bondStateCollateralType = bondStateData.
|
|
6986
|
+
const bondStateCollateralType = bondStateData.bondState.collateralType;
|
|
6899
6987
|
return await matchVariant(bondStateCollateralType, {
|
|
6900
6988
|
native: async () => {
|
|
6901
6989
|
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
@@ -6922,7 +7010,7 @@ var JBondClient = class _JBondClient {
|
|
|
6922
7010
|
*/
|
|
6923
7011
|
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
6924
7012
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6925
|
-
const bondStateCollateralType = bondStateData.
|
|
7013
|
+
const bondStateCollateralType = bondStateData.bondState.collateralType;
|
|
6926
7014
|
const chunk = (arr, n = 100) => {
|
|
6927
7015
|
const res = [];
|
|
6928
7016
|
for (let i = 0; i < arr.length; i += n) {
|