@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.d.mts
CHANGED
|
@@ -209,9 +209,6 @@ type Jbond = {
|
|
|
209
209
|
210
|
|
210
210
|
];
|
|
211
211
|
"accounts": [
|
|
212
|
-
{
|
|
213
|
-
"name": "globalState";
|
|
214
|
-
},
|
|
215
212
|
{
|
|
216
213
|
"name": "bondState";
|
|
217
214
|
"writable": true;
|
|
@@ -247,9 +244,6 @@ type Jbond = {
|
|
|
247
244
|
"name": "authority";
|
|
248
245
|
"writable": true;
|
|
249
246
|
"signer": true;
|
|
250
|
-
"relations": [
|
|
251
|
-
"globalState"
|
|
252
|
-
];
|
|
253
247
|
},
|
|
254
248
|
{
|
|
255
249
|
"name": "reserve";
|
|
@@ -798,6 +792,80 @@ type Jbond = {
|
|
|
798
792
|
];
|
|
799
793
|
"args": [];
|
|
800
794
|
},
|
|
795
|
+
{
|
|
796
|
+
"name": "migrateBond";
|
|
797
|
+
"docs": [
|
|
798
|
+
"Migrates validator bond data from legacy structure to new structure."
|
|
799
|
+
];
|
|
800
|
+
"discriminator": [
|
|
801
|
+
107,
|
|
802
|
+
119,
|
|
803
|
+
59,
|
|
804
|
+
110,
|
|
805
|
+
76,
|
|
806
|
+
18,
|
|
807
|
+
37,
|
|
808
|
+
163
|
|
809
|
+
];
|
|
810
|
+
"accounts": [
|
|
811
|
+
{
|
|
812
|
+
"name": "bondState";
|
|
813
|
+
"writable": true;
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
"name": "legacyValidatorBond";
|
|
817
|
+
"writable": true;
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
"name": "legacyVoteAccount";
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
"name": "validatorBond";
|
|
824
|
+
"writable": true;
|
|
825
|
+
"pda": {
|
|
826
|
+
"seeds": [
|
|
827
|
+
{
|
|
828
|
+
"kind": "const";
|
|
829
|
+
"value": [
|
|
830
|
+
118,
|
|
831
|
+
97,
|
|
832
|
+
108,
|
|
833
|
+
105,
|
|
834
|
+
100,
|
|
835
|
+
97,
|
|
836
|
+
116,
|
|
837
|
+
111,
|
|
838
|
+
114,
|
|
839
|
+
95,
|
|
840
|
+
98,
|
|
841
|
+
111,
|
|
842
|
+
110,
|
|
843
|
+
100
|
|
844
|
+
];
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
"kind": "account";
|
|
848
|
+
"path": "bondState";
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
"kind": "account";
|
|
852
|
+
"path": "legacyVoteAccount";
|
|
853
|
+
}
|
|
854
|
+
];
|
|
855
|
+
};
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
"name": "creator";
|
|
859
|
+
"writable": true;
|
|
860
|
+
"signer": true;
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
"name": "systemProgram";
|
|
864
|
+
"address": "11111111111111111111111111111111";
|
|
865
|
+
}
|
|
866
|
+
];
|
|
867
|
+
"args": [];
|
|
868
|
+
},
|
|
801
869
|
{
|
|
802
870
|
"name": "sessionFinish";
|
|
803
871
|
"docs": [
|
|
@@ -1842,6 +1910,16 @@ declare class JBondClient {
|
|
|
1842
1910
|
bondType: BondType;
|
|
1843
1911
|
name: string;
|
|
1844
1912
|
}): Promise<TransactionInstruction>;
|
|
1913
|
+
migrateBond(props: {
|
|
1914
|
+
bondType: BondType;
|
|
1915
|
+
name: string;
|
|
1916
|
+
voteAccount: PublicKeyInitData;
|
|
1917
|
+
}): Promise<string | undefined>;
|
|
1918
|
+
buildBondMigrateIx(props: {
|
|
1919
|
+
bondType: BondType;
|
|
1920
|
+
name: string;
|
|
1921
|
+
voteAccount: PublicKeyInitData;
|
|
1922
|
+
}): Promise<TransactionInstruction>;
|
|
1845
1923
|
buildBondStartIx(props: {
|
|
1846
1924
|
bondType: BondType;
|
|
1847
1925
|
name: string;
|
|
@@ -1858,8 +1936,8 @@ declare class JBondClient {
|
|
|
1858
1936
|
* @param withStats
|
|
1859
1937
|
*/
|
|
1860
1938
|
getBondState(bondType: BondType, bondName: string, withStats?: boolean): Promise<{
|
|
1861
|
-
|
|
1862
|
-
|
|
1939
|
+
bondState: BondState;
|
|
1940
|
+
stateStats: BondStateStats | null;
|
|
1863
1941
|
}>;
|
|
1864
1942
|
/**
|
|
1865
1943
|
* Get all bond states with total collected collateral
|
package/dist/index.d.ts
CHANGED
|
@@ -209,9 +209,6 @@ type Jbond = {
|
|
|
209
209
|
210
|
|
210
210
|
];
|
|
211
211
|
"accounts": [
|
|
212
|
-
{
|
|
213
|
-
"name": "globalState";
|
|
214
|
-
},
|
|
215
212
|
{
|
|
216
213
|
"name": "bondState";
|
|
217
214
|
"writable": true;
|
|
@@ -247,9 +244,6 @@ type Jbond = {
|
|
|
247
244
|
"name": "authority";
|
|
248
245
|
"writable": true;
|
|
249
246
|
"signer": true;
|
|
250
|
-
"relations": [
|
|
251
|
-
"globalState"
|
|
252
|
-
];
|
|
253
247
|
},
|
|
254
248
|
{
|
|
255
249
|
"name": "reserve";
|
|
@@ -798,6 +792,80 @@ type Jbond = {
|
|
|
798
792
|
];
|
|
799
793
|
"args": [];
|
|
800
794
|
},
|
|
795
|
+
{
|
|
796
|
+
"name": "migrateBond";
|
|
797
|
+
"docs": [
|
|
798
|
+
"Migrates validator bond data from legacy structure to new structure."
|
|
799
|
+
];
|
|
800
|
+
"discriminator": [
|
|
801
|
+
107,
|
|
802
|
+
119,
|
|
803
|
+
59,
|
|
804
|
+
110,
|
|
805
|
+
76,
|
|
806
|
+
18,
|
|
807
|
+
37,
|
|
808
|
+
163
|
|
809
|
+
];
|
|
810
|
+
"accounts": [
|
|
811
|
+
{
|
|
812
|
+
"name": "bondState";
|
|
813
|
+
"writable": true;
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
"name": "legacyValidatorBond";
|
|
817
|
+
"writable": true;
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
"name": "legacyVoteAccount";
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
"name": "validatorBond";
|
|
824
|
+
"writable": true;
|
|
825
|
+
"pda": {
|
|
826
|
+
"seeds": [
|
|
827
|
+
{
|
|
828
|
+
"kind": "const";
|
|
829
|
+
"value": [
|
|
830
|
+
118,
|
|
831
|
+
97,
|
|
832
|
+
108,
|
|
833
|
+
105,
|
|
834
|
+
100,
|
|
835
|
+
97,
|
|
836
|
+
116,
|
|
837
|
+
111,
|
|
838
|
+
114,
|
|
839
|
+
95,
|
|
840
|
+
98,
|
|
841
|
+
111,
|
|
842
|
+
110,
|
|
843
|
+
100
|
|
844
|
+
];
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
"kind": "account";
|
|
848
|
+
"path": "bondState";
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
"kind": "account";
|
|
852
|
+
"path": "legacyVoteAccount";
|
|
853
|
+
}
|
|
854
|
+
];
|
|
855
|
+
};
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
"name": "creator";
|
|
859
|
+
"writable": true;
|
|
860
|
+
"signer": true;
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
"name": "systemProgram";
|
|
864
|
+
"address": "11111111111111111111111111111111";
|
|
865
|
+
}
|
|
866
|
+
];
|
|
867
|
+
"args": [];
|
|
868
|
+
},
|
|
801
869
|
{
|
|
802
870
|
"name": "sessionFinish";
|
|
803
871
|
"docs": [
|
|
@@ -1842,6 +1910,16 @@ declare class JBondClient {
|
|
|
1842
1910
|
bondType: BondType;
|
|
1843
1911
|
name: string;
|
|
1844
1912
|
}): Promise<TransactionInstruction>;
|
|
1913
|
+
migrateBond(props: {
|
|
1914
|
+
bondType: BondType;
|
|
1915
|
+
name: string;
|
|
1916
|
+
voteAccount: PublicKeyInitData;
|
|
1917
|
+
}): Promise<string | undefined>;
|
|
1918
|
+
buildBondMigrateIx(props: {
|
|
1919
|
+
bondType: BondType;
|
|
1920
|
+
name: string;
|
|
1921
|
+
voteAccount: PublicKeyInitData;
|
|
1922
|
+
}): Promise<TransactionInstruction>;
|
|
1845
1923
|
buildBondStartIx(props: {
|
|
1846
1924
|
bondType: BondType;
|
|
1847
1925
|
name: string;
|
|
@@ -1858,8 +1936,8 @@ declare class JBondClient {
|
|
|
1858
1936
|
* @param withStats
|
|
1859
1937
|
*/
|
|
1860
1938
|
getBondState(bondType: BondType, bondName: string, withStats?: boolean): Promise<{
|
|
1861
|
-
|
|
1862
|
-
|
|
1939
|
+
bondState: BondState;
|
|
1940
|
+
stateStats: BondStateStats | null;
|
|
1863
1941
|
}>;
|
|
1864
1942
|
/**
|
|
1865
1943
|
* Get all bond states with total collected collateral
|
package/dist/index.js
CHANGED
|
@@ -5019,9 +5019,6 @@ var jbond_default = {
|
|
|
5019
5019
|
210
|
|
5020
5020
|
],
|
|
5021
5021
|
accounts: [
|
|
5022
|
-
{
|
|
5023
|
-
name: "global_state"
|
|
5024
|
-
},
|
|
5025
5022
|
{
|
|
5026
5023
|
name: "bond_state",
|
|
5027
5024
|
writable: true,
|
|
@@ -5056,10 +5053,7 @@ var jbond_default = {
|
|
|
5056
5053
|
{
|
|
5057
5054
|
name: "authority",
|
|
5058
5055
|
writable: true,
|
|
5059
|
-
signer: true
|
|
5060
|
-
relations: [
|
|
5061
|
-
"global_state"
|
|
5062
|
-
]
|
|
5056
|
+
signer: true
|
|
5063
5057
|
},
|
|
5064
5058
|
{
|
|
5065
5059
|
name: "reserve"
|
|
@@ -5608,6 +5602,80 @@ var jbond_default = {
|
|
|
5608
5602
|
],
|
|
5609
5603
|
args: []
|
|
5610
5604
|
},
|
|
5605
|
+
{
|
|
5606
|
+
name: "migrate_bond",
|
|
5607
|
+
docs: [
|
|
5608
|
+
"Migrates validator bond data from legacy structure to new structure."
|
|
5609
|
+
],
|
|
5610
|
+
discriminator: [
|
|
5611
|
+
107,
|
|
5612
|
+
119,
|
|
5613
|
+
59,
|
|
5614
|
+
110,
|
|
5615
|
+
76,
|
|
5616
|
+
18,
|
|
5617
|
+
37,
|
|
5618
|
+
163
|
|
5619
|
+
],
|
|
5620
|
+
accounts: [
|
|
5621
|
+
{
|
|
5622
|
+
name: "bond_state",
|
|
5623
|
+
writable: true
|
|
5624
|
+
},
|
|
5625
|
+
{
|
|
5626
|
+
name: "legacy_validator_bond",
|
|
5627
|
+
writable: true
|
|
5628
|
+
},
|
|
5629
|
+
{
|
|
5630
|
+
name: "legacy_vote_account"
|
|
5631
|
+
},
|
|
5632
|
+
{
|
|
5633
|
+
name: "validator_bond",
|
|
5634
|
+
writable: true,
|
|
5635
|
+
pda: {
|
|
5636
|
+
seeds: [
|
|
5637
|
+
{
|
|
5638
|
+
kind: "const",
|
|
5639
|
+
value: [
|
|
5640
|
+
118,
|
|
5641
|
+
97,
|
|
5642
|
+
108,
|
|
5643
|
+
105,
|
|
5644
|
+
100,
|
|
5645
|
+
97,
|
|
5646
|
+
116,
|
|
5647
|
+
111,
|
|
5648
|
+
114,
|
|
5649
|
+
95,
|
|
5650
|
+
98,
|
|
5651
|
+
111,
|
|
5652
|
+
110,
|
|
5653
|
+
100
|
|
5654
|
+
]
|
|
5655
|
+
},
|
|
5656
|
+
{
|
|
5657
|
+
kind: "account",
|
|
5658
|
+
path: "bond_state"
|
|
5659
|
+
},
|
|
5660
|
+
{
|
|
5661
|
+
kind: "account",
|
|
5662
|
+
path: "legacy_vote_account"
|
|
5663
|
+
}
|
|
5664
|
+
]
|
|
5665
|
+
}
|
|
5666
|
+
},
|
|
5667
|
+
{
|
|
5668
|
+
name: "creator",
|
|
5669
|
+
writable: true,
|
|
5670
|
+
signer: true
|
|
5671
|
+
},
|
|
5672
|
+
{
|
|
5673
|
+
name: "system_program",
|
|
5674
|
+
address: "11111111111111111111111111111111"
|
|
5675
|
+
}
|
|
5676
|
+
],
|
|
5677
|
+
args: []
|
|
5678
|
+
},
|
|
5611
5679
|
{
|
|
5612
5680
|
name: "session_finish",
|
|
5613
5681
|
docs: [
|
|
@@ -6620,10 +6688,8 @@ var JBondClient = class _JBondClient {
|
|
|
6620
6688
|
* Build initialize instruction
|
|
6621
6689
|
*/
|
|
6622
6690
|
async buildBondInitializeIx(props) {
|
|
6623
|
-
const [globalState] = this.pda.globalState();
|
|
6624
6691
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6625
6692
|
const accounts = {
|
|
6626
|
-
globalState,
|
|
6627
6693
|
bondState,
|
|
6628
6694
|
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
6629
6695
|
reserve: props.reserve,
|
|
@@ -6668,7 +6734,7 @@ var JBondClient = class _JBondClient {
|
|
|
6668
6734
|
if (!creator) {
|
|
6669
6735
|
throw new Error("Missing creator");
|
|
6670
6736
|
}
|
|
6671
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6737
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6672
6738
|
const accounts = {
|
|
6673
6739
|
bondState,
|
|
6674
6740
|
validatorBond,
|
|
@@ -6711,7 +6777,7 @@ var JBondClient = class _JBondClient {
|
|
|
6711
6777
|
creator: props.payer
|
|
6712
6778
|
}));
|
|
6713
6779
|
}
|
|
6714
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6780
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6715
6781
|
const accounts = {
|
|
6716
6782
|
bondState,
|
|
6717
6783
|
validatorBond,
|
|
@@ -6748,7 +6814,7 @@ var JBondClient = class _JBondClient {
|
|
|
6748
6814
|
if (!payer || !destination) {
|
|
6749
6815
|
throw new Error("Missing payer/destination");
|
|
6750
6816
|
}
|
|
6751
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6817
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6752
6818
|
const accounts = {
|
|
6753
6819
|
bondState,
|
|
6754
6820
|
validatorBond,
|
|
@@ -6776,12 +6842,12 @@ var JBondClient = class _JBondClient {
|
|
|
6776
6842
|
const { bondType, name } = props;
|
|
6777
6843
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6778
6844
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6779
|
-
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).
|
|
6845
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).bondState.reserve;
|
|
6780
6846
|
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6781
6847
|
if (!reserve) {
|
|
6782
6848
|
throw new Error("Reserve not set");
|
|
6783
6849
|
}
|
|
6784
|
-
const collateralType = (await this.getBondState(bondType, name)).
|
|
6850
|
+
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6785
6851
|
const accounts = {
|
|
6786
6852
|
bondState,
|
|
6787
6853
|
validatorBond,
|
|
@@ -6823,6 +6889,28 @@ var JBondClient = class _JBondClient {
|
|
|
6823
6889
|
authority: this.program.provider.wallet?.publicKey
|
|
6824
6890
|
}).instruction();
|
|
6825
6891
|
}
|
|
6892
|
+
async migrateBond(props) {
|
|
6893
|
+
const ix = await this.buildBondMigrateIx(props);
|
|
6894
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6895
|
+
}
|
|
6896
|
+
async buildBondMigrateIx(props) {
|
|
6897
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6898
|
+
const [legacyValidatorBond] = web3_js.PublicKey.findProgramAddressSync(
|
|
6899
|
+
[
|
|
6900
|
+
Buffer.from("validator_bond"),
|
|
6901
|
+
new web3_js.PublicKey(props.voteAccount).toBuffer()
|
|
6902
|
+
],
|
|
6903
|
+
this.programId
|
|
6904
|
+
);
|
|
6905
|
+
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6906
|
+
return this.program.methods.migrateBond().accountsPartial({
|
|
6907
|
+
bondState,
|
|
6908
|
+
legacyValidatorBond,
|
|
6909
|
+
legacyVoteAccount: new web3_js.PublicKey(props.voteAccount),
|
|
6910
|
+
validatorBond,
|
|
6911
|
+
creator: this.program.provider.wallet?.publicKey
|
|
6912
|
+
}).instruction();
|
|
6913
|
+
}
|
|
6826
6914
|
async buildBondStartIx(props) {
|
|
6827
6915
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6828
6916
|
return this.program.methods.sessionStart(new import_bn2.BN(props.duration_secs)).accountsPartial({
|
|
@@ -6846,8 +6934,8 @@ var JBondClient = class _JBondClient {
|
|
|
6846
6934
|
async getBondState(bondType, bondName, withStats = false) {
|
|
6847
6935
|
const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
|
|
6848
6936
|
return {
|
|
6849
|
-
|
|
6850
|
-
|
|
6937
|
+
bondState,
|
|
6938
|
+
stateStats: withStats ? await this.getBondStateStats(bondState) : null
|
|
6851
6939
|
};
|
|
6852
6940
|
}
|
|
6853
6941
|
/**
|
|
@@ -6919,7 +7007,7 @@ var JBondClient = class _JBondClient {
|
|
|
6919
7007
|
*/
|
|
6920
7008
|
async getBondCollateralType(bondType, bondName) {
|
|
6921
7009
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6922
|
-
return bondState.
|
|
7010
|
+
return bondState.bondState.collateralType;
|
|
6923
7011
|
}
|
|
6924
7012
|
/**
|
|
6925
7013
|
* Get validator bond account balance (in SOL)
|
|
@@ -6931,7 +7019,7 @@ var JBondClient = class _JBondClient {
|
|
|
6931
7019
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6932
7020
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6933
7021
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6934
|
-
const bondStateCollateralType = bondStateData.
|
|
7022
|
+
const bondStateCollateralType = bondStateData.bondState.collateralType;
|
|
6935
7023
|
return await matchVariant(bondStateCollateralType, {
|
|
6936
7024
|
native: async () => {
|
|
6937
7025
|
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
@@ -6958,7 +7046,7 @@ var JBondClient = class _JBondClient {
|
|
|
6958
7046
|
*/
|
|
6959
7047
|
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
6960
7048
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6961
|
-
const bondStateCollateralType = bondStateData.
|
|
7049
|
+
const bondStateCollateralType = bondStateData.bondState.collateralType;
|
|
6962
7050
|
const chunk = (arr, n = 100) => {
|
|
6963
7051
|
const res = [];
|
|
6964
7052
|
for (let i = 0; i < arr.length; i += n) {
|