@jpool/bond-sdk 0.9.0-next.14 → 0.9.0-next.16
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 +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +17 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1907,7 +1907,12 @@ declare class JBondClient {
|
|
|
1907
1907
|
* Fetch global state or throw if not found
|
|
1908
1908
|
*/
|
|
1909
1909
|
getGlobalState(): Promise<GlobalState>;
|
|
1910
|
-
|
|
1910
|
+
/**
|
|
1911
|
+
* Fetch bond state with stats
|
|
1912
|
+
* @param bondType - Type of the bond
|
|
1913
|
+
* @param bondName - Name of the bond
|
|
1914
|
+
*/
|
|
1915
|
+
getBondState(bondType: BondType, bondName: string, withStats?: boolean): Promise<[BondState, BondStateStats | null]>;
|
|
1911
1916
|
/**
|
|
1912
1917
|
* Get all bond states with total collected collateral
|
|
1913
1918
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1907,7 +1907,12 @@ declare class JBondClient {
|
|
|
1907
1907
|
* Fetch global state or throw if not found
|
|
1908
1908
|
*/
|
|
1909
1909
|
getGlobalState(): Promise<GlobalState>;
|
|
1910
|
-
|
|
1910
|
+
/**
|
|
1911
|
+
* Fetch bond state with stats
|
|
1912
|
+
* @param bondType - Type of the bond
|
|
1913
|
+
* @param bondName - Name of the bond
|
|
1914
|
+
*/
|
|
1915
|
+
getBondState(bondType: BondType, bondName: string, withStats?: boolean): Promise<[BondState, BondStateStats | null]>;
|
|
1911
1916
|
/**
|
|
1912
1917
|
* Get all bond states with total collected collateral
|
|
1913
1918
|
*/
|
package/dist/index.js
CHANGED
|
@@ -6718,7 +6718,7 @@ var JBondClient = class _JBondClient {
|
|
|
6718
6718
|
if (!creator) {
|
|
6719
6719
|
throw new Error("Missing creator");
|
|
6720
6720
|
}
|
|
6721
|
-
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6721
|
+
const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
|
|
6722
6722
|
const accounts = {
|
|
6723
6723
|
bondState,
|
|
6724
6724
|
validatorBond,
|
|
@@ -6761,7 +6761,7 @@ var JBondClient = class _JBondClient {
|
|
|
6761
6761
|
creator: props.payer
|
|
6762
6762
|
}));
|
|
6763
6763
|
}
|
|
6764
|
-
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6764
|
+
const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
|
|
6765
6765
|
const accounts = {
|
|
6766
6766
|
bondState,
|
|
6767
6767
|
validatorBond,
|
|
@@ -6798,7 +6798,7 @@ var JBondClient = class _JBondClient {
|
|
|
6798
6798
|
if (!payer || !destination) {
|
|
6799
6799
|
throw new Error("Missing payer/destination");
|
|
6800
6800
|
}
|
|
6801
|
-
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6801
|
+
const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
|
|
6802
6802
|
const accounts = {
|
|
6803
6803
|
bondState,
|
|
6804
6804
|
validatorBond,
|
|
@@ -6826,12 +6826,12 @@ var JBondClient = class _JBondClient {
|
|
|
6826
6826
|
const { bondType, name } = props;
|
|
6827
6827
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6828
6828
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6829
|
-
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).reserve;
|
|
6829
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name))[0].reserve;
|
|
6830
6830
|
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6831
6831
|
if (!reserve) {
|
|
6832
6832
|
throw new Error("Reserve not set");
|
|
6833
6833
|
}
|
|
6834
|
-
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6834
|
+
const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
|
|
6835
6835
|
const accounts = {
|
|
6836
6836
|
bondState,
|
|
6837
6837
|
validatorBond,
|
|
@@ -6901,9 +6901,14 @@ var JBondClient = class _JBondClient {
|
|
|
6901
6901
|
const [globalState] = this.pda.globalState();
|
|
6902
6902
|
return await this.program.account.globalState.fetch(globalState);
|
|
6903
6903
|
}
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6904
|
+
/**
|
|
6905
|
+
* Fetch bond state with stats
|
|
6906
|
+
* @param bondType - Type of the bond
|
|
6907
|
+
* @param bondName - Name of the bond
|
|
6908
|
+
*/
|
|
6909
|
+
async getBondState(bondType, bondName, withStats = false) {
|
|
6910
|
+
const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
|
|
6911
|
+
return [bondState, withStats ? await this.getBondStateStats(bondState) : null];
|
|
6907
6912
|
}
|
|
6908
6913
|
/**
|
|
6909
6914
|
* Get all bond states with total collected collateral
|
|
@@ -6970,7 +6975,7 @@ var JBondClient = class _JBondClient {
|
|
|
6970
6975
|
*/
|
|
6971
6976
|
async getBondCollateralType(bondType, bondName) {
|
|
6972
6977
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6973
|
-
return bondState.collateralType;
|
|
6978
|
+
return bondState[0].collateralType;
|
|
6974
6979
|
}
|
|
6975
6980
|
/**
|
|
6976
6981
|
* Get validator bond account balance (in SOL)
|
|
@@ -6982,7 +6987,7 @@ var JBondClient = class _JBondClient {
|
|
|
6982
6987
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6983
6988
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6984
6989
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
6985
|
-
const bondStateCollateralType = bondStateData.collateralType;
|
|
6990
|
+
const bondStateCollateralType = bondStateData[0].collateralType;
|
|
6986
6991
|
return await matchVariant(bondStateCollateralType, {
|
|
6987
6992
|
native: async () => {
|
|
6988
6993
|
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
@@ -6997,7 +7002,7 @@ var JBondClient = class _JBondClient {
|
|
|
6997
7002
|
const tokenAccount = splToken.getAssociatedTokenAddressSync(mint, address, true);
|
|
6998
7003
|
try {
|
|
6999
7004
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
7000
|
-
return Number(balance.value.uiAmount ?? 0);
|
|
7005
|
+
return Number(balance.value.uiAmount ?? 0) * web3_js.LAMPORTS_PER_SOL;
|
|
7001
7006
|
} catch {
|
|
7002
7007
|
return 0;
|
|
7003
7008
|
}
|
|
@@ -7007,7 +7012,7 @@ var JBondClient = class _JBondClient {
|
|
|
7007
7012
|
// Get total collected collateral for a bond state
|
|
7008
7013
|
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
7009
7014
|
const bondStateData = await this.getBondState(bondType, bondName);
|
|
7010
|
-
const bondStateCollateralType = bondStateData.collateralType;
|
|
7015
|
+
const bondStateCollateralType = bondStateData[0].collateralType;
|
|
7011
7016
|
const chunk = (arr, n = 100) => {
|
|
7012
7017
|
const res = [];
|
|
7013
7018
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -7033,7 +7038,6 @@ var JBondClient = class _JBondClient {
|
|
|
7033
7038
|
);
|
|
7034
7039
|
return balances.reduce((sum, v) => sum + v, 0);
|
|
7035
7040
|
},
|
|
7036
|
-
// TODO
|
|
7037
7041
|
token: async (mint) => {
|
|
7038
7042
|
const tokenAccounts = votes.map((vote) => {
|
|
7039
7043
|
const [validatorBondAddress] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|