@jpool/bond-sdk 0.11.0-next.3 → 0.11.0-next.6
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 +157 -2
- package/dist/index.d.ts +157 -2
- package/dist/index.js +184 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4984,6 +4984,50 @@ var jbond_default = {
|
|
|
4984
4984
|
}
|
|
4985
4985
|
]
|
|
4986
4986
|
},
|
|
4987
|
+
{
|
|
4988
|
+
name: "bond_lock_funds",
|
|
4989
|
+
docs: [
|
|
4990
|
+
"Locks funds for the upcoming epoch.",
|
|
4991
|
+
"Moves collateral from available to locked state which cannot be withdrawn.",
|
|
4992
|
+
"# Errors",
|
|
4993
|
+
"Fails if the validator is not active, or if there are insufficient available funds."
|
|
4994
|
+
],
|
|
4995
|
+
discriminator: [
|
|
4996
|
+
117,
|
|
4997
|
+
166,
|
|
4998
|
+
195,
|
|
4999
|
+
99,
|
|
5000
|
+
103,
|
|
5001
|
+
45,
|
|
5002
|
+
195,
|
|
5003
|
+
2
|
|
5004
|
+
],
|
|
5005
|
+
accounts: [
|
|
5006
|
+
{
|
|
5007
|
+
name: "bond_state",
|
|
5008
|
+
writable: true
|
|
5009
|
+
},
|
|
5010
|
+
{
|
|
5011
|
+
name: "validator_bond",
|
|
5012
|
+
writable: true
|
|
5013
|
+
},
|
|
5014
|
+
{
|
|
5015
|
+
name: "bond_token_account",
|
|
5016
|
+
optional: true
|
|
5017
|
+
},
|
|
5018
|
+
{
|
|
5019
|
+
name: "payer",
|
|
5020
|
+
writable: true,
|
|
5021
|
+
signer: true
|
|
5022
|
+
}
|
|
5023
|
+
],
|
|
5024
|
+
args: [
|
|
5025
|
+
{
|
|
5026
|
+
name: "amount",
|
|
5027
|
+
type: "u64"
|
|
5028
|
+
}
|
|
5029
|
+
]
|
|
5030
|
+
},
|
|
4987
5031
|
{
|
|
4988
5032
|
name: "bond_register",
|
|
4989
5033
|
docs: [
|
|
@@ -5096,6 +5140,42 @@ var jbond_default = {
|
|
|
5096
5140
|
}
|
|
5097
5141
|
]
|
|
5098
5142
|
},
|
|
5143
|
+
{
|
|
5144
|
+
name: "bond_release_funds",
|
|
5145
|
+
docs: [
|
|
5146
|
+
"Releases locked funds after an epoch ends.",
|
|
5147
|
+
"Moves collateral from locked back to available state, allowing withdrawals.",
|
|
5148
|
+
"# Errors",
|
|
5149
|
+
"Fails if the validator is not active, or if there are insufficient locked funds."
|
|
5150
|
+
],
|
|
5151
|
+
discriminator: [
|
|
5152
|
+
184,
|
|
5153
|
+
224,
|
|
5154
|
+
14,
|
|
5155
|
+
24,
|
|
5156
|
+
76,
|
|
5157
|
+
14,
|
|
5158
|
+
226,
|
|
5159
|
+
190
|
|
5160
|
+
],
|
|
5161
|
+
accounts: [
|
|
5162
|
+
{
|
|
5163
|
+
name: "validator_bond",
|
|
5164
|
+
writable: true
|
|
5165
|
+
},
|
|
5166
|
+
{
|
|
5167
|
+
name: "payer",
|
|
5168
|
+
writable: true,
|
|
5169
|
+
signer: true
|
|
5170
|
+
}
|
|
5171
|
+
],
|
|
5172
|
+
args: [
|
|
5173
|
+
{
|
|
5174
|
+
name: "amount",
|
|
5175
|
+
type: "u64"
|
|
5176
|
+
}
|
|
5177
|
+
]
|
|
5178
|
+
},
|
|
5099
5179
|
{
|
|
5100
5180
|
name: "bond_set_withdraw_authority",
|
|
5101
5181
|
docs: [
|
|
@@ -5275,6 +5355,31 @@ var jbond_default = {
|
|
|
5275
5355
|
}
|
|
5276
5356
|
]
|
|
5277
5357
|
},
|
|
5358
|
+
{
|
|
5359
|
+
name: "bond_update",
|
|
5360
|
+
discriminator: [
|
|
5361
|
+
237,
|
|
5362
|
+
102,
|
|
5363
|
+
183,
|
|
5364
|
+
192,
|
|
5365
|
+
94,
|
|
5366
|
+
83,
|
|
5367
|
+
52,
|
|
5368
|
+
82
|
|
5369
|
+
],
|
|
5370
|
+
accounts: [
|
|
5371
|
+
{
|
|
5372
|
+
name: "validator_bond",
|
|
5373
|
+
writable: true
|
|
5374
|
+
},
|
|
5375
|
+
{
|
|
5376
|
+
name: "payer",
|
|
5377
|
+
writable: true,
|
|
5378
|
+
signer: true
|
|
5379
|
+
}
|
|
5380
|
+
],
|
|
5381
|
+
args: []
|
|
5382
|
+
},
|
|
5278
5383
|
{
|
|
5279
5384
|
name: "bond_withdraw",
|
|
5280
5385
|
docs: [
|
|
@@ -5875,6 +5980,11 @@ var jbond_default = {
|
|
|
5875
5980
|
code: 6023,
|
|
5876
5981
|
name: "BondNotEnabled",
|
|
5877
5982
|
msg: "Bond is not enabled"
|
|
5983
|
+
},
|
|
5984
|
+
{
|
|
5985
|
+
code: 6024,
|
|
5986
|
+
name: "InvalidEpoch",
|
|
5987
|
+
msg: "Invalid epoch for this operation"
|
|
5878
5988
|
}
|
|
5879
5989
|
],
|
|
5880
5990
|
types: [
|
|
@@ -6306,6 +6416,27 @@ var jbond_default = {
|
|
|
6306
6416
|
"Bump for the PDA"
|
|
6307
6417
|
],
|
|
6308
6418
|
type: "u8"
|
|
6419
|
+
},
|
|
6420
|
+
{
|
|
6421
|
+
name: "next_epoch_locked",
|
|
6422
|
+
docs: [
|
|
6423
|
+
"Amount of collateral locked for the next epoch"
|
|
6424
|
+
],
|
|
6425
|
+
type: "u64"
|
|
6426
|
+
},
|
|
6427
|
+
{
|
|
6428
|
+
name: "current_epoch_locked",
|
|
6429
|
+
docs: [
|
|
6430
|
+
"Amount of collateral locked for the current epoch"
|
|
6431
|
+
],
|
|
6432
|
+
type: "u64"
|
|
6433
|
+
},
|
|
6434
|
+
{
|
|
6435
|
+
name: "last_update_epoch",
|
|
6436
|
+
docs: [
|
|
6437
|
+
"The last epoch when the bond was updated"
|
|
6438
|
+
],
|
|
6439
|
+
type: "u64"
|
|
6309
6440
|
}
|
|
6310
6441
|
]
|
|
6311
6442
|
}
|
|
@@ -6853,20 +6984,17 @@ var JBondClient = class _JBondClient {
|
|
|
6853
6984
|
*/
|
|
6854
6985
|
async getClaimAllCompensationsIxs(props) {
|
|
6855
6986
|
const ixs = [];
|
|
6856
|
-
const validatorBonds = await this.getBondValidatorStates(props.bondType, props.name);
|
|
6857
6987
|
const validatorBondBalances = await this.getBondStateValidatorBondBalances(
|
|
6858
6988
|
props.bondType,
|
|
6859
6989
|
props.name
|
|
6860
6990
|
);
|
|
6861
|
-
for (const
|
|
6862
|
-
|
|
6863
|
-
const validatorBondBalance = lamportsToSol(validatorBondBalances.find((vbb) => vbb.voteAccount.equals(vb.voteAccount))?.balance || 0);
|
|
6864
|
-
const amountToClaim = validatorBondBalance - (props.collateralType ? 0 : lamportsToSol(await this.validatorBondRentExempt()));
|
|
6991
|
+
for (const bond_balance of validatorBondBalances) {
|
|
6992
|
+
const amountToClaim = lamportsToSol(bond_balance.balance);
|
|
6865
6993
|
if (amountToClaim <= 0) {
|
|
6866
|
-
|
|
6994
|
+
this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
|
|
6867
6995
|
continue;
|
|
6868
6996
|
}
|
|
6869
|
-
|
|
6997
|
+
this.debug("Amount to claim:", amountToClaim);
|
|
6870
6998
|
const ix = await this.getClaimIx({
|
|
6871
6999
|
bondType: props.bondType,
|
|
6872
7000
|
name: props.name,
|
|
@@ -6874,7 +7002,7 @@ var JBondClient = class _JBondClient {
|
|
|
6874
7002
|
collateralType: props.collateralType,
|
|
6875
7003
|
reserve: props.reserve,
|
|
6876
7004
|
authority: props.authority,
|
|
6877
|
-
voteAccount:
|
|
7005
|
+
voteAccount: bond_balance.voteAccount
|
|
6878
7006
|
});
|
|
6879
7007
|
ixs.push(ix);
|
|
6880
7008
|
}
|
|
@@ -6908,6 +7036,48 @@ var JBondClient = class _JBondClient {
|
|
|
6908
7036
|
const authority = this.provider.wallet?.publicKey;
|
|
6909
7037
|
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6910
7038
|
}
|
|
7039
|
+
/**
|
|
7040
|
+
* Build lock funds instruction
|
|
7041
|
+
*/
|
|
7042
|
+
async getLockFundsIx(props) {
|
|
7043
|
+
const { bondType, name, voteAccount, amount } = props;
|
|
7044
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7045
|
+
let collateralType = props.collateralType;
|
|
7046
|
+
if (!collateralType) {
|
|
7047
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
7048
|
+
collateralType = bondState2.collateralType;
|
|
7049
|
+
}
|
|
7050
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7051
|
+
const authority = this.provider.wallet?.publicKey;
|
|
7052
|
+
const accounts = {
|
|
7053
|
+
bondState,
|
|
7054
|
+
validatorBond,
|
|
7055
|
+
payer: authority,
|
|
7056
|
+
bondTokenAccount: null
|
|
7057
|
+
};
|
|
7058
|
+
matchVariant(collateralType, {
|
|
7059
|
+
native: () => {
|
|
7060
|
+
},
|
|
7061
|
+
token: (mint) => {
|
|
7062
|
+
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7063
|
+
accounts.bondTokenAccount = bondTokenAccount;
|
|
7064
|
+
}
|
|
7065
|
+
});
|
|
7066
|
+
return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7067
|
+
}
|
|
7068
|
+
/**
|
|
7069
|
+
* Build release funds instruction
|
|
7070
|
+
*/
|
|
7071
|
+
async getReleaseFundsIx(props) {
|
|
7072
|
+
const { bondType, name, voteAccount, amount } = props;
|
|
7073
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7074
|
+
const authority = this.provider.wallet?.publicKey;
|
|
7075
|
+
const accounts = {
|
|
7076
|
+
validatorBond,
|
|
7077
|
+
payer: authority
|
|
7078
|
+
};
|
|
7079
|
+
return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7080
|
+
}
|
|
6911
7081
|
/**
|
|
6912
7082
|
* Get all bond states with total collected collateral
|
|
6913
7083
|
*/
|
|
@@ -6965,8 +7135,8 @@ var JBondClient = class _JBondClient {
|
|
|
6965
7135
|
if (!accountInfo) {
|
|
6966
7136
|
return 0;
|
|
6967
7137
|
}
|
|
6968
|
-
const {
|
|
6969
|
-
const rentExempt = await this.
|
|
7138
|
+
const { lamports } = accountInfo;
|
|
7139
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
6970
7140
|
return Math.max(0, lamports - rentExempt);
|
|
6971
7141
|
},
|
|
6972
7142
|
token: async (mint) => {
|
|
@@ -6983,7 +7153,7 @@ var JBondClient = class _JBondClient {
|
|
|
6983
7153
|
async getBondStateValidatorBondBalances(bondType, bondName) {
|
|
6984
7154
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6985
7155
|
const collateralType = bondState.collateralType;
|
|
6986
|
-
const validatorBonds = await this.
|
|
7156
|
+
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
6987
7157
|
if (!validatorBonds.length) {
|
|
6988
7158
|
return [];
|
|
6989
7159
|
}
|
|
@@ -6998,9 +7168,10 @@ var JBondClient = class _JBondClient {
|
|
|
6998
7168
|
native: async () => {
|
|
6999
7169
|
const addresses = validatorBonds.map((vb) => vb.publicKey);
|
|
7000
7170
|
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
7171
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
7001
7172
|
return validatorBonds.map((vb, idx) => ({
|
|
7002
7173
|
voteAccount: vb.voteAccount,
|
|
7003
|
-
balance: accountInfos[idx]?.lamports ?? 0
|
|
7174
|
+
balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
|
|
7004
7175
|
}));
|
|
7005
7176
|
},
|
|
7006
7177
|
token: async (mint) => {
|
|
@@ -7067,7 +7238,7 @@ var JBondClient = class _JBondClient {
|
|
|
7067
7238
|
/**
|
|
7068
7239
|
* Get all validator bonds for a given bond state
|
|
7069
7240
|
*/
|
|
7070
|
-
async
|
|
7241
|
+
async getValidatorBondsForState(bondType, bondName) {
|
|
7071
7242
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7072
7243
|
const accounts = await this.program.account.validatorBond.all([
|
|
7073
7244
|
{
|