@jpool/bond-sdk 0.11.3 → 0.11.5
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 +269 -68
- package/dist/index.d.ts +269 -68
- package/dist/index.js +478 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +473 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { utils, AnchorProvider, Program, BN } from '@coral-xyz/anchor';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { STAKE_POOL_PROGRAM_ID, StakePoolInstruction, getStakePoolAccount, depositSol } from '@solana/spl-stake-pool';
|
|
3
|
+
import { getAssociatedTokenAddressSync, createAssociatedTokenAccountIdempotentInstruction, ACCOUNT_SIZE, AccountLayout } from '@solana/spl-token';
|
|
4
|
+
import { PublicKey, LAMPORTS_PER_SOL, Transaction, Keypair, SystemProgram } from '@solana/web3.js';
|
|
4
5
|
|
|
5
6
|
var __create = Object.create;
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
@@ -30,10 +31,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
31
|
|
|
31
32
|
// ../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
|
|
32
33
|
var require_base64_js = __commonJS({
|
|
33
|
-
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports) {
|
|
34
|
-
exports.byteLength = byteLength;
|
|
35
|
-
exports.toByteArray = toByteArray;
|
|
36
|
-
exports.fromByteArray = fromByteArray;
|
|
34
|
+
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports$1) {
|
|
35
|
+
exports$1.byteLength = byteLength;
|
|
36
|
+
exports$1.toByteArray = toByteArray;
|
|
37
|
+
exports$1.fromByteArray = fromByteArray;
|
|
37
38
|
var lookup = [];
|
|
38
39
|
var revLookup = [];
|
|
39
40
|
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
@@ -130,8 +131,8 @@ var require_base64_js = __commonJS({
|
|
|
130
131
|
|
|
131
132
|
// ../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
|
|
132
133
|
var require_ieee754 = __commonJS({
|
|
133
|
-
"../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js"(exports) {
|
|
134
|
-
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
134
|
+
"../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js"(exports$1) {
|
|
135
|
+
exports$1.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
135
136
|
var e, m;
|
|
136
137
|
var eLen = nBytes * 8 - mLen - 1;
|
|
137
138
|
var eMax = (1 << eLen) - 1;
|
|
@@ -161,7 +162,7 @@ var require_ieee754 = __commonJS({
|
|
|
161
162
|
}
|
|
162
163
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
163
164
|
};
|
|
164
|
-
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
165
|
+
exports$1.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
165
166
|
var e, m, c;
|
|
166
167
|
var eLen = nBytes * 8 - mLen - 1;
|
|
167
168
|
var eMax = (1 << eLen) - 1;
|
|
@@ -213,15 +214,15 @@ var require_ieee754 = __commonJS({
|
|
|
213
214
|
|
|
214
215
|
// ../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
|
|
215
216
|
var require_buffer = __commonJS({
|
|
216
|
-
"../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js"(exports) {
|
|
217
|
+
"../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js"(exports$1) {
|
|
217
218
|
var base64 = require_base64_js();
|
|
218
219
|
var ieee754 = require_ieee754();
|
|
219
220
|
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
220
|
-
exports.Buffer = Buffer2;
|
|
221
|
-
exports.SlowBuffer = SlowBuffer;
|
|
222
|
-
exports.INSPECT_MAX_BYTES = 50;
|
|
221
|
+
exports$1.Buffer = Buffer2;
|
|
222
|
+
exports$1.SlowBuffer = SlowBuffer;
|
|
223
|
+
exports$1.INSPECT_MAX_BYTES = 50;
|
|
223
224
|
var K_MAX_LENGTH = 2147483647;
|
|
224
|
-
exports.kMaxLength = K_MAX_LENGTH;
|
|
225
|
+
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
225
226
|
Buffer2.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
226
227
|
if (!Buffer2.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
227
228
|
console.error(
|
|
@@ -651,7 +652,7 @@ var require_buffer = __commonJS({
|
|
|
651
652
|
};
|
|
652
653
|
Buffer2.prototype.inspect = function inspect() {
|
|
653
654
|
let str = "";
|
|
654
|
-
const max = exports.INSPECT_MAX_BYTES;
|
|
655
|
+
const max = exports$1.INSPECT_MAX_BYTES;
|
|
655
656
|
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
656
657
|
if (this.length > max) str += " ... ";
|
|
657
658
|
return "<Buffer " + str + ">";
|
|
@@ -1802,7 +1803,7 @@ var require_buffer = __commonJS({
|
|
|
1802
1803
|
|
|
1803
1804
|
// ../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js
|
|
1804
1805
|
var require_bn = __commonJS({
|
|
1805
|
-
"../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js"(exports, module) {
|
|
1806
|
+
"../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js"(exports$1, module) {
|
|
1806
1807
|
(function(module2, exports2) {
|
|
1807
1808
|
function assert(val, msg) {
|
|
1808
1809
|
if (!val) throw new Error(msg || "Assertion failed");
|
|
@@ -4540,7 +4541,7 @@ var require_bn = __commonJS({
|
|
|
4540
4541
|
var res = this.imod(a._invmp(this.m).mul(this.r2));
|
|
4541
4542
|
return res._forceRed(this);
|
|
4542
4543
|
};
|
|
4543
|
-
})(typeof module === "undefined" || module, exports);
|
|
4544
|
+
})(typeof module === "undefined" || module, exports$1);
|
|
4544
4545
|
}
|
|
4545
4546
|
});
|
|
4546
4547
|
|
|
@@ -4565,6 +4566,7 @@ var BondType = /* @__PURE__ */ ((BondType2) => {
|
|
|
4565
4566
|
return BondType2;
|
|
4566
4567
|
})(BondType || {});
|
|
4567
4568
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4569
|
+
BondTransactionType2["Registered"] = "registered";
|
|
4568
4570
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4569
4571
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
4570
4572
|
BondTransactionType2["Compensation"] = "compensation";
|
|
@@ -4582,6 +4584,8 @@ var ENV_PROGRAM_ID = {
|
|
|
4582
4584
|
["stage" /* STAGE */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4583
4585
|
["prod" /* PROD */]: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU"
|
|
4584
4586
|
};
|
|
4587
|
+
var JSOL_MINT = new PublicKey("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn");
|
|
4588
|
+
var JPOOL_POOL_ADDRESS = new PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
|
|
4585
4589
|
var { bs58 } = utils.bytes;
|
|
4586
4590
|
var HistoryManager = class {
|
|
4587
4591
|
constructor(client) {
|
|
@@ -4645,7 +4649,7 @@ var HistoryManager = class {
|
|
|
4645
4649
|
continue;
|
|
4646
4650
|
}
|
|
4647
4651
|
const { type, amount } = this.decodeInstructionData(ix.data);
|
|
4648
|
-
if (!type || amount <= 0) {
|
|
4652
|
+
if (!type || amount <= 0 && type !== "registered" /* Registered */) {
|
|
4649
4653
|
continue;
|
|
4650
4654
|
}
|
|
4651
4655
|
history.push({
|
|
@@ -4665,7 +4669,6 @@ var HistoryManager = class {
|
|
|
4665
4669
|
before: options?.before,
|
|
4666
4670
|
until: options?.until
|
|
4667
4671
|
}, "confirmed");
|
|
4668
|
-
console.log(sigs);
|
|
4669
4672
|
return sigs.filter((s) => !s.err);
|
|
4670
4673
|
}
|
|
4671
4674
|
async fetchParsedTransactions(sigs, batchSize = 100) {
|
|
@@ -4687,7 +4690,7 @@ var HistoryManager = class {
|
|
|
4687
4690
|
}
|
|
4688
4691
|
const ix = this.program.idl.instructions.find((i) => i.name === name);
|
|
4689
4692
|
if (!ix || !Array.isArray(ix.discriminator)) {
|
|
4690
|
-
|
|
4693
|
+
return new Uint8Array();
|
|
4691
4694
|
}
|
|
4692
4695
|
const disc = new Uint8Array(ix.discriminator);
|
|
4693
4696
|
this.discCache.set(name, disc);
|
|
@@ -4695,47 +4698,45 @@ var HistoryManager = class {
|
|
|
4695
4698
|
}
|
|
4696
4699
|
decodeInstructionData(data) {
|
|
4697
4700
|
if (!data) {
|
|
4698
|
-
return {
|
|
4699
|
-
type: null,
|
|
4700
|
-
amount: 0
|
|
4701
|
-
};
|
|
4701
|
+
return { type: null, amount: 0 };
|
|
4702
4702
|
}
|
|
4703
4703
|
try {
|
|
4704
4704
|
const buf = bs58.decode(data);
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
const
|
|
4716
|
-
const
|
|
4717
|
-
const
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
if (
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
}
|
|
4730
|
-
return { type
|
|
4731
|
-
} catch {
|
|
4705
|
+
let type = null;
|
|
4706
|
+
const disc = buf.subarray(0, 8);
|
|
4707
|
+
const amountBytes = buf.subarray(8, 16);
|
|
4708
|
+
let amount = 0;
|
|
4709
|
+
let noAmount = false;
|
|
4710
|
+
try {
|
|
4711
|
+
amount = new BN(amountBytes, "le").toNumber() / LAMPORTS_PER_SOL;
|
|
4712
|
+
} catch {
|
|
4713
|
+
noAmount = true;
|
|
4714
|
+
}
|
|
4715
|
+
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
4716
|
+
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
4717
|
+
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
4718
|
+
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
4719
|
+
if (Buffer.from(disc).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
4720
|
+
type = "registered" /* Registered */;
|
|
4721
|
+
} else if (!noAmount) {
|
|
4722
|
+
if (Buffer.from(disc).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
4723
|
+
type = "deposit" /* Deposit */;
|
|
4724
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
4725
|
+
type = "compensation" /* Compensation */;
|
|
4726
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
4727
|
+
type = "withdrawal" /* Withdrawal */;
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
return { type, amount };
|
|
4731
|
+
} catch (error) {
|
|
4732
|
+
console.error("Failed to decode instruction data:", error);
|
|
4732
4733
|
return { type: null, amount: 0 };
|
|
4733
4734
|
}
|
|
4734
4735
|
}
|
|
4735
4736
|
};
|
|
4736
4737
|
function slotToEpoch(slot, cluster) {
|
|
4737
|
-
const
|
|
4738
|
-
const slotsPerEpoch =
|
|
4738
|
+
const isDevnet = cluster?.includes("devnet") || cluster?.includes("localnet");
|
|
4739
|
+
const slotsPerEpoch = isDevnet ? 4e5 : 432e3;
|
|
4739
4740
|
return Math.floor(slot / slotsPerEpoch);
|
|
4740
4741
|
}
|
|
4741
4742
|
|
|
@@ -4744,7 +4745,7 @@ var jbond_default = {
|
|
|
4744
4745
|
address: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU",
|
|
4745
4746
|
metadata: {
|
|
4746
4747
|
name: "jbond",
|
|
4747
|
-
version: "0.2.
|
|
4748
|
+
version: "0.2.6",
|
|
4748
4749
|
spec: "0.1.0",
|
|
4749
4750
|
description: "Jpool Bond Program"
|
|
4750
4751
|
},
|
|
@@ -5495,38 +5496,6 @@ var jbond_default = {
|
|
|
5495
5496
|
}
|
|
5496
5497
|
]
|
|
5497
5498
|
},
|
|
5498
|
-
{
|
|
5499
|
-
name: "bond_update",
|
|
5500
|
-
docs: [
|
|
5501
|
-
"Applies any pending unlocks from previous epochs.",
|
|
5502
|
-
"",
|
|
5503
|
-
"This instruction is optional - all other operations now automatically",
|
|
5504
|
-
"sync the epoch state. It is kept for backwards compatibility and can",
|
|
5505
|
-
"be used to explicitly trigger epoch synchronization without performing",
|
|
5506
|
-
"another operation."
|
|
5507
|
-
],
|
|
5508
|
-
discriminator: [
|
|
5509
|
-
237,
|
|
5510
|
-
102,
|
|
5511
|
-
183,
|
|
5512
|
-
192,
|
|
5513
|
-
94,
|
|
5514
|
-
83,
|
|
5515
|
-
52,
|
|
5516
|
-
82
|
|
5517
|
-
],
|
|
5518
|
-
accounts: [
|
|
5519
|
-
{
|
|
5520
|
-
name: "validator_bond",
|
|
5521
|
-
writable: true
|
|
5522
|
-
},
|
|
5523
|
-
{
|
|
5524
|
-
name: "payer",
|
|
5525
|
-
signer: true
|
|
5526
|
-
}
|
|
5527
|
-
],
|
|
5528
|
-
args: []
|
|
5529
|
-
},
|
|
5530
5499
|
{
|
|
5531
5500
|
name: "bond_withdraw",
|
|
5532
5501
|
docs: [
|
|
@@ -5637,6 +5606,103 @@ var jbond_default = {
|
|
|
5637
5606
|
}
|
|
5638
5607
|
]
|
|
5639
5608
|
},
|
|
5609
|
+
{
|
|
5610
|
+
name: "close_validator_bond",
|
|
5611
|
+
docs: [
|
|
5612
|
+
"Closes a validator bond account and transfers remaining balance to the rent receiver.",
|
|
5613
|
+
"",
|
|
5614
|
+
"# Security",
|
|
5615
|
+
"- Only the validator identity or withdrawal authority can close the bond",
|
|
5616
|
+
"- All funds must be unlocked (locked == 0 and pending_unlock == 0)",
|
|
5617
|
+
"- For token collateral, closes the associated token account as well",
|
|
5618
|
+
"- Decrements the bond state's total_members counter",
|
|
5619
|
+
"",
|
|
5620
|
+
"# Errors",
|
|
5621
|
+
"Fails if the signer is not authorized, if funds are still locked,",
|
|
5622
|
+
"or if the rent receiver is not the identity or withdrawal authority."
|
|
5623
|
+
],
|
|
5624
|
+
discriminator: [
|
|
5625
|
+
51,
|
|
5626
|
+
235,
|
|
5627
|
+
111,
|
|
5628
|
+
163,
|
|
5629
|
+
176,
|
|
5630
|
+
239,
|
|
5631
|
+
95,
|
|
5632
|
+
122
|
|
5633
|
+
],
|
|
5634
|
+
accounts: [
|
|
5635
|
+
{
|
|
5636
|
+
name: "bond_state",
|
|
5637
|
+
writable: true
|
|
5638
|
+
},
|
|
5639
|
+
{
|
|
5640
|
+
name: "validator_bond",
|
|
5641
|
+
writable: true,
|
|
5642
|
+
pda: {
|
|
5643
|
+
seeds: [
|
|
5644
|
+
{
|
|
5645
|
+
kind: "const",
|
|
5646
|
+
value: [
|
|
5647
|
+
118,
|
|
5648
|
+
97,
|
|
5649
|
+
108,
|
|
5650
|
+
105,
|
|
5651
|
+
100,
|
|
5652
|
+
97,
|
|
5653
|
+
116,
|
|
5654
|
+
111,
|
|
5655
|
+
114,
|
|
5656
|
+
95,
|
|
5657
|
+
98,
|
|
5658
|
+
111,
|
|
5659
|
+
110,
|
|
5660
|
+
100
|
|
5661
|
+
]
|
|
5662
|
+
},
|
|
5663
|
+
{
|
|
5664
|
+
kind: "account",
|
|
5665
|
+
path: "bond_state"
|
|
5666
|
+
},
|
|
5667
|
+
{
|
|
5668
|
+
kind: "account",
|
|
5669
|
+
path: "validator_bond.vote_account",
|
|
5670
|
+
account: "ValidatorBond"
|
|
5671
|
+
}
|
|
5672
|
+
]
|
|
5673
|
+
}
|
|
5674
|
+
},
|
|
5675
|
+
{
|
|
5676
|
+
name: "authority",
|
|
5677
|
+
writable: true,
|
|
5678
|
+
signer: true
|
|
5679
|
+
},
|
|
5680
|
+
{
|
|
5681
|
+
name: "rent_receiver",
|
|
5682
|
+
writable: true
|
|
5683
|
+
},
|
|
5684
|
+
{
|
|
5685
|
+
name: "bond_token_account",
|
|
5686
|
+
writable: true,
|
|
5687
|
+
optional: true
|
|
5688
|
+
},
|
|
5689
|
+
{
|
|
5690
|
+
name: "destination_token_account",
|
|
5691
|
+
writable: true,
|
|
5692
|
+
optional: true
|
|
5693
|
+
},
|
|
5694
|
+
{
|
|
5695
|
+
name: "system_program",
|
|
5696
|
+
address: "11111111111111111111111111111111"
|
|
5697
|
+
},
|
|
5698
|
+
{
|
|
5699
|
+
name: "token_program",
|
|
5700
|
+
optional: true,
|
|
5701
|
+
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
5702
|
+
}
|
|
5703
|
+
],
|
|
5704
|
+
args: []
|
|
5705
|
+
},
|
|
5640
5706
|
{
|
|
5641
5707
|
name: "global_configure",
|
|
5642
5708
|
discriminator: [
|
|
@@ -5997,6 +6063,19 @@ var jbond_default = {
|
|
|
5997
6063
|
128
|
|
5998
6064
|
]
|
|
5999
6065
|
},
|
|
6066
|
+
{
|
|
6067
|
+
name: "ValidatorBondClosed",
|
|
6068
|
+
discriminator: [
|
|
6069
|
+
71,
|
|
6070
|
+
54,
|
|
6071
|
+
59,
|
|
6072
|
+
241,
|
|
6073
|
+
91,
|
|
6074
|
+
35,
|
|
6075
|
+
123,
|
|
6076
|
+
123
|
|
6077
|
+
]
|
|
6078
|
+
},
|
|
6000
6079
|
{
|
|
6001
6080
|
name: "ValidatorRegistered",
|
|
6002
6081
|
discriminator: [
|
|
@@ -6696,6 +6775,34 @@ var jbond_default = {
|
|
|
6696
6775
|
]
|
|
6697
6776
|
}
|
|
6698
6777
|
},
|
|
6778
|
+
{
|
|
6779
|
+
name: "ValidatorBondClosed",
|
|
6780
|
+
type: {
|
|
6781
|
+
kind: "struct",
|
|
6782
|
+
fields: [
|
|
6783
|
+
{
|
|
6784
|
+
name: "validator",
|
|
6785
|
+
type: "pubkey"
|
|
6786
|
+
},
|
|
6787
|
+
{
|
|
6788
|
+
name: "vote_account",
|
|
6789
|
+
type: "pubkey"
|
|
6790
|
+
},
|
|
6791
|
+
{
|
|
6792
|
+
name: "rent_receiver",
|
|
6793
|
+
type: "pubkey"
|
|
6794
|
+
},
|
|
6795
|
+
{
|
|
6796
|
+
name: "final_balance",
|
|
6797
|
+
type: "u64"
|
|
6798
|
+
},
|
|
6799
|
+
{
|
|
6800
|
+
name: "timestamp",
|
|
6801
|
+
type: "i64"
|
|
6802
|
+
}
|
|
6803
|
+
]
|
|
6804
|
+
}
|
|
6805
|
+
},
|
|
6699
6806
|
{
|
|
6700
6807
|
name: "ValidatorRegistered",
|
|
6701
6808
|
type: {
|
|
@@ -6797,6 +6904,22 @@ function bondTypeToAnchor(type, payload) {
|
|
|
6797
6904
|
function anchorToBondType(variant) {
|
|
6798
6905
|
return fromAnchor(variant);
|
|
6799
6906
|
}
|
|
6907
|
+
async function getStakePoolAccountData(connection, stakePoolAddress) {
|
|
6908
|
+
const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
|
|
6909
|
+
if (!stakePoolAccount) {
|
|
6910
|
+
throw new Error(`Stake pool account not found: ${stakePoolAddress.toBase58()}`);
|
|
6911
|
+
}
|
|
6912
|
+
return stakePoolAccount.account.data;
|
|
6913
|
+
}
|
|
6914
|
+
function lamportsToPoolTokenLamports(lamports, stakePool) {
|
|
6915
|
+
if (stakePool.totalLamports.isZero()) {
|
|
6916
|
+
throw new Error("Stake pool has zero total lamports");
|
|
6917
|
+
}
|
|
6918
|
+
if (stakePool.poolTokenSupply.isZero()) {
|
|
6919
|
+
throw new Error("Stake pool has zero pool token supply");
|
|
6920
|
+
}
|
|
6921
|
+
return lamports.mul(stakePool.poolTokenSupply).div(stakePool.totalLamports);
|
|
6922
|
+
}
|
|
6800
6923
|
|
|
6801
6924
|
// src/utils/wallet.ts
|
|
6802
6925
|
function isVersionedTransaction(tx) {
|
|
@@ -6940,6 +7063,9 @@ var JBondClient = class _JBondClient {
|
|
|
6940
7063
|
*/
|
|
6941
7064
|
configure(key, val) {
|
|
6942
7065
|
this.options[key] = val;
|
|
7066
|
+
if (key === "programId") {
|
|
7067
|
+
this._program = null;
|
|
7068
|
+
}
|
|
6943
7069
|
return this;
|
|
6944
7070
|
}
|
|
6945
7071
|
/**
|
|
@@ -6998,8 +7124,8 @@ var JBondClient = class _JBondClient {
|
|
|
6998
7124
|
* Top up collateral
|
|
6999
7125
|
*/
|
|
7000
7126
|
async topUpCollateral(props) {
|
|
7001
|
-
const
|
|
7002
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(...
|
|
7127
|
+
const { instructions, signers } = await this.getTopUpIxs(props);
|
|
7128
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(...instructions), signers);
|
|
7003
7129
|
}
|
|
7004
7130
|
/**
|
|
7005
7131
|
* Withdraw collateral
|
|
@@ -7008,6 +7134,13 @@ var JBondClient = class _JBondClient {
|
|
|
7008
7134
|
const ix = await this.getWithdrawIx(props);
|
|
7009
7135
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7010
7136
|
}
|
|
7137
|
+
/**
|
|
7138
|
+
* Migrate SOL collateral from one bond account to JSOL collateral in another bond account
|
|
7139
|
+
*/
|
|
7140
|
+
async migrateBond(props) {
|
|
7141
|
+
const { instructions, signers } = await this.getMigrateBondIx(props);
|
|
7142
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(...instructions), signers);
|
|
7143
|
+
}
|
|
7011
7144
|
/**
|
|
7012
7145
|
* Claim compensation for a validator
|
|
7013
7146
|
*/
|
|
@@ -7054,6 +7187,10 @@ var JBondClient = class _JBondClient {
|
|
|
7054
7187
|
const ix = await this.getBondRemoveIx(props);
|
|
7055
7188
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7056
7189
|
}
|
|
7190
|
+
async closeValidatorBond(props) {
|
|
7191
|
+
const ix = await this.getCloseValidatorBondIx(props);
|
|
7192
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7193
|
+
}
|
|
7057
7194
|
/**
|
|
7058
7195
|
* Build global state initialize instruction
|
|
7059
7196
|
*/
|
|
@@ -7164,6 +7301,9 @@ var JBondClient = class _JBondClient {
|
|
|
7164
7301
|
collateralType = bondState2.collateralType;
|
|
7165
7302
|
}
|
|
7166
7303
|
const instructions = [];
|
|
7304
|
+
const signers = [];
|
|
7305
|
+
const amountLamports = solToLamports(amount);
|
|
7306
|
+
let topUpAmount = amountLamports;
|
|
7167
7307
|
try {
|
|
7168
7308
|
await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
7169
7309
|
} catch {
|
|
@@ -7195,10 +7335,33 @@ var JBondClient = class _JBondClient {
|
|
|
7195
7335
|
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7196
7336
|
}
|
|
7197
7337
|
});
|
|
7338
|
+
if (props.solUsage) {
|
|
7339
|
+
let usesJsolCollateral = false;
|
|
7340
|
+
matchVariant(collateralType, {
|
|
7341
|
+
token: (mint) => {
|
|
7342
|
+
usesJsolCollateral = mint.equals(JSOL_MINT);
|
|
7343
|
+
}
|
|
7344
|
+
});
|
|
7345
|
+
if (usesJsolCollateral) {
|
|
7346
|
+
const stakePool = await getStakePoolAccountData(this.connection, JPOOL_POOL_ADDRESS);
|
|
7347
|
+
const deposit = await depositSol(
|
|
7348
|
+
this.connection,
|
|
7349
|
+
JPOOL_POOL_ADDRESS,
|
|
7350
|
+
payer,
|
|
7351
|
+
amountLamports.toNumber(),
|
|
7352
|
+
void 0,
|
|
7353
|
+
void 0,
|
|
7354
|
+
void 0
|
|
7355
|
+
);
|
|
7356
|
+
instructions.push(...deposit.instructions);
|
|
7357
|
+
signers.push(...deposit.signers);
|
|
7358
|
+
topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7359
|
+
}
|
|
7360
|
+
}
|
|
7198
7361
|
instructions.push(
|
|
7199
|
-
await this.program.methods.bondTopUp(
|
|
7362
|
+
await this.program.methods.bondTopUp(topUpAmount).accountsPartial(accounts).instruction()
|
|
7200
7363
|
);
|
|
7201
|
-
return instructions;
|
|
7364
|
+
return { instructions, signers };
|
|
7202
7365
|
}
|
|
7203
7366
|
/**
|
|
7204
7367
|
* Build withdraw collateral instruction
|
|
@@ -7237,6 +7400,139 @@ var JBondClient = class _JBondClient {
|
|
|
7237
7400
|
});
|
|
7238
7401
|
return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7239
7402
|
}
|
|
7403
|
+
/**
|
|
7404
|
+
* Build instructions for migrating SOL bond collateral into JSOL bond collateral in a single transaction
|
|
7405
|
+
*/
|
|
7406
|
+
async getMigrateBondIx(props) {
|
|
7407
|
+
const {
|
|
7408
|
+
bondType,
|
|
7409
|
+
voteAccount,
|
|
7410
|
+
identity,
|
|
7411
|
+
withdrawName = "performance",
|
|
7412
|
+
topUpName = "perf",
|
|
7413
|
+
stakePoolAddress = JPOOL_POOL_ADDRESS
|
|
7414
|
+
} = props;
|
|
7415
|
+
const payer = props.payer ?? this.provider.wallet?.publicKey;
|
|
7416
|
+
const destination = props.destination ?? payer;
|
|
7417
|
+
if (!payer || !destination) {
|
|
7418
|
+
throw new Error("Missing payer/destination");
|
|
7419
|
+
}
|
|
7420
|
+
const withdrawBondState = await this.getBondState(bondType, withdrawName);
|
|
7421
|
+
await matchVariant(withdrawBondState.collateralType, {
|
|
7422
|
+
native: () => {
|
|
7423
|
+
},
|
|
7424
|
+
token: () => {
|
|
7425
|
+
throw new Error("Withdraw bond collateral type must be native SOL for migration");
|
|
7426
|
+
}
|
|
7427
|
+
});
|
|
7428
|
+
const availableLamports = await this.getAvailableCollateral(bondType, withdrawName, voteAccount);
|
|
7429
|
+
if (!availableLamports || availableLamports <= 0) {
|
|
7430
|
+
throw new Error("No available balance to migrate");
|
|
7431
|
+
}
|
|
7432
|
+
const amount = lamportsToSol(availableLamports);
|
|
7433
|
+
const amountLamports = solToLamports(amount);
|
|
7434
|
+
const withdrawIx = await this.getWithdrawIx({
|
|
7435
|
+
bondType,
|
|
7436
|
+
name: withdrawName,
|
|
7437
|
+
amount,
|
|
7438
|
+
voteAccount,
|
|
7439
|
+
destination,
|
|
7440
|
+
withdrawalAuthority: props.withdrawalAuthority
|
|
7441
|
+
});
|
|
7442
|
+
const deposit = await this.getDepositSolIxsWithoutBalanceCheck(
|
|
7443
|
+
stakePoolAddress,
|
|
7444
|
+
payer,
|
|
7445
|
+
amountLamports.toNumber()
|
|
7446
|
+
);
|
|
7447
|
+
const topUpBondState = await this.getBondState(bondType, topUpName);
|
|
7448
|
+
const topUpCollateralType = topUpBondState.collateralType;
|
|
7449
|
+
const instructions = [withdrawIx, ...deposit.instructions];
|
|
7450
|
+
const signers = [...deposit.signers];
|
|
7451
|
+
try {
|
|
7452
|
+
await this.getValidatorBond(bondType, topUpName, voteAccount);
|
|
7453
|
+
} catch {
|
|
7454
|
+
instructions.push(
|
|
7455
|
+
await this.getRegisterValidatorIx({
|
|
7456
|
+
bondType,
|
|
7457
|
+
name: topUpName,
|
|
7458
|
+
voteAccount,
|
|
7459
|
+
identity,
|
|
7460
|
+
creator: payer,
|
|
7461
|
+
collateralType: topUpCollateralType
|
|
7462
|
+
})
|
|
7463
|
+
);
|
|
7464
|
+
}
|
|
7465
|
+
const [topUpBondStateAddress] = this.pda.bondState(bondType, topUpName);
|
|
7466
|
+
const [topUpValidatorBond] = this.pda.validatorBond(bondType, topUpName, voteAccount);
|
|
7467
|
+
await matchVariant(topUpCollateralType, {
|
|
7468
|
+
native: () => {
|
|
7469
|
+
throw new Error("Top up bond collateral type must be token for migration");
|
|
7470
|
+
},
|
|
7471
|
+
token: async (mint) => {
|
|
7472
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7473
|
+
const topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7474
|
+
const topUpIx = await this.program.methods.bondTopUp(topUpAmount).accountsPartial({
|
|
7475
|
+
bondState: topUpBondStateAddress,
|
|
7476
|
+
validatorBond: topUpValidatorBond,
|
|
7477
|
+
payer,
|
|
7478
|
+
payerTokenAccount: getAssociatedTokenAddressSync(mint, payer),
|
|
7479
|
+
bondTokenAccount: getAssociatedTokenAddressSync(mint, topUpValidatorBond, true),
|
|
7480
|
+
stakeAccount: null,
|
|
7481
|
+
stakeProgram: null
|
|
7482
|
+
}).instruction();
|
|
7483
|
+
instructions.push(topUpIx);
|
|
7484
|
+
}
|
|
7485
|
+
});
|
|
7486
|
+
return { instructions, signers };
|
|
7487
|
+
}
|
|
7488
|
+
/**
|
|
7489
|
+
* Build stake-pool SOL deposit instructions without pre-checking payer balance.
|
|
7490
|
+
* This allows composing withdraw->deposit in a single transaction where SOL is obtained by the prior instruction.
|
|
7491
|
+
*/
|
|
7492
|
+
async getDepositSolIxsWithoutBalanceCheck(stakePoolAddress, payer, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
|
|
7493
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7494
|
+
const transferSigner = new Keypair();
|
|
7495
|
+
const signers = [transferSigner];
|
|
7496
|
+
const instructions = [
|
|
7497
|
+
SystemProgram.transfer({
|
|
7498
|
+
fromPubkey: payer,
|
|
7499
|
+
toPubkey: transferSigner.publicKey,
|
|
7500
|
+
lamports
|
|
7501
|
+
})
|
|
7502
|
+
];
|
|
7503
|
+
let destinationPoolAccount = destinationTokenAccount;
|
|
7504
|
+
if (!destinationPoolAccount) {
|
|
7505
|
+
const associatedAddress = getAssociatedTokenAddressSync(stakePool.poolMint, payer);
|
|
7506
|
+
instructions.push(
|
|
7507
|
+
createAssociatedTokenAccountIdempotentInstruction(
|
|
7508
|
+
payer,
|
|
7509
|
+
associatedAddress,
|
|
7510
|
+
payer,
|
|
7511
|
+
stakePool.poolMint
|
|
7512
|
+
)
|
|
7513
|
+
);
|
|
7514
|
+
destinationPoolAccount = associatedAddress;
|
|
7515
|
+
}
|
|
7516
|
+
const [withdrawAuthority] = PublicKey.findProgramAddressSync(
|
|
7517
|
+
[stakePoolAddress.toBuffer(), Buffer.from("withdraw")],
|
|
7518
|
+
STAKE_POOL_PROGRAM_ID
|
|
7519
|
+
);
|
|
7520
|
+
instructions.push(
|
|
7521
|
+
StakePoolInstruction.depositSol({
|
|
7522
|
+
stakePool: stakePoolAddress,
|
|
7523
|
+
reserveStake: stakePool.reserveStake,
|
|
7524
|
+
fundingAccount: transferSigner.publicKey,
|
|
7525
|
+
destinationPoolAccount,
|
|
7526
|
+
managerFeeAccount: stakePool.managerFeeAccount,
|
|
7527
|
+
referralPoolAccount: referrerTokenAccount ?? destinationPoolAccount,
|
|
7528
|
+
poolMint: stakePool.poolMint,
|
|
7529
|
+
lamports,
|
|
7530
|
+
withdrawAuthority,
|
|
7531
|
+
depositAuthority
|
|
7532
|
+
})
|
|
7533
|
+
);
|
|
7534
|
+
return { instructions, signers };
|
|
7535
|
+
}
|
|
7240
7536
|
/**
|
|
7241
7537
|
* Build claim instruction
|
|
7242
7538
|
*/
|
|
@@ -7344,22 +7640,6 @@ var JBondClient = class _JBondClient {
|
|
|
7344
7640
|
const ix = await this.getReleaseFundsIx(props);
|
|
7345
7641
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7346
7642
|
}
|
|
7347
|
-
/**
|
|
7348
|
-
* Update epoch locks
|
|
7349
|
-
*/
|
|
7350
|
-
async updateEpochLocks(props) {
|
|
7351
|
-
const { bondType, bondName, voteAccount, payer } = props;
|
|
7352
|
-
const ix = await this.getUpdateEpochLocksIx({ bondType, bondName, voteAccount, payer });
|
|
7353
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7354
|
-
}
|
|
7355
|
-
/**
|
|
7356
|
-
* Build update epoch locks instruction
|
|
7357
|
-
*/
|
|
7358
|
-
async getUpdateEpochLocksIx(props) {
|
|
7359
|
-
const { bondType, bondName, voteAccount, payer } = props;
|
|
7360
|
-
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7361
|
-
return this.program.methods.bondUpdate().accountsPartial({ validatorBond, payer }).instruction();
|
|
7362
|
-
}
|
|
7363
7643
|
/**
|
|
7364
7644
|
* Build bond remove instruction
|
|
7365
7645
|
*/
|
|
@@ -7369,17 +7649,55 @@ var JBondClient = class _JBondClient {
|
|
|
7369
7649
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7370
7650
|
return this.program.methods.bondRemove().accountsPartial({ bondState, authority }).instruction();
|
|
7371
7651
|
}
|
|
7652
|
+
/**
|
|
7653
|
+
* Build close validator bond instruction
|
|
7654
|
+
*/
|
|
7655
|
+
async getCloseValidatorBondIx(props) {
|
|
7656
|
+
const { bondType, name, voteAccount } = props;
|
|
7657
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7658
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7659
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7660
|
+
const rentReceiver = props.rentReceiver ?? authority;
|
|
7661
|
+
if (!authority || !rentReceiver) {
|
|
7662
|
+
throw new Error("Missing authority or rentReceiver");
|
|
7663
|
+
}
|
|
7664
|
+
let collateralType = props.collateralType;
|
|
7665
|
+
if (!collateralType) {
|
|
7666
|
+
const state = await this.getBondState(bondType, name);
|
|
7667
|
+
collateralType = state.collateralType;
|
|
7668
|
+
}
|
|
7669
|
+
const accounts = {
|
|
7670
|
+
bondState,
|
|
7671
|
+
validatorBond,
|
|
7672
|
+
authority,
|
|
7673
|
+
rentReceiver,
|
|
7674
|
+
bondTokenAccount: null,
|
|
7675
|
+
destinationTokenAccount: null
|
|
7676
|
+
};
|
|
7677
|
+
matchVariant(collateralType, {
|
|
7678
|
+
native: () => {
|
|
7679
|
+
},
|
|
7680
|
+
token: (mint) => {
|
|
7681
|
+
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7682
|
+
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, rentReceiver, true);
|
|
7683
|
+
}
|
|
7684
|
+
});
|
|
7685
|
+
return this.program.methods.closeValidatorBond().accountsPartial(accounts).instruction();
|
|
7686
|
+
}
|
|
7372
7687
|
/**
|
|
7373
7688
|
* Build test set last update epoch instruction
|
|
7374
7689
|
* NOTE!: This instruction is for testing purposes only.
|
|
7375
7690
|
* It allows direct manipulation of the validator bond's last epoch update.
|
|
7376
7691
|
* This should not be used in production environments.
|
|
7377
7692
|
*/
|
|
7378
|
-
async getTestSetLastUpdateEpochIx(props) {
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
|
|
7693
|
+
// async getTestSetLastUpdateEpochIx(props: { bondType: BondType, bondName: string, voteAccount: PublicKeyInitData, payer: PublicKey, epoch: number }) {
|
|
7694
|
+
// const { bondType, bondName, voteAccount, payer, epoch } = props
|
|
7695
|
+
// const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount)
|
|
7696
|
+
// return this.program.methods
|
|
7697
|
+
// .testSetLastUpdateEpoch(new BN(epoch))
|
|
7698
|
+
// .accountsPartial({ validatorBond, payer })
|
|
7699
|
+
// .instruction()
|
|
7700
|
+
// }
|
|
7383
7701
|
/**
|
|
7384
7702
|
* Build lock funds instruction
|
|
7385
7703
|
*/
|
|
@@ -7432,20 +7750,32 @@ var JBondClient = class _JBondClient {
|
|
|
7432
7750
|
/**
|
|
7433
7751
|
* Get all bond states with total collected collateral
|
|
7434
7752
|
*/
|
|
7435
|
-
async getAllBondStates(bondType, sessionStatus) {
|
|
7436
|
-
const
|
|
7753
|
+
async getAllBondStates(bondType, sessionStatus, options) {
|
|
7754
|
+
const includeStats = options?.includeStats ?? true;
|
|
7755
|
+
const targetBondType = bondTypeToAnchor(bondType);
|
|
7437
7756
|
const accounts = await this.program.account.bondState.all();
|
|
7438
|
-
|
|
7439
|
-
if (!sameVariant(account.bondType,
|
|
7440
|
-
|
|
7757
|
+
const filteredAccounts = accounts.filter(({ account }) => {
|
|
7758
|
+
if (!sameVariant(account.bondType, targetBondType)) {
|
|
7759
|
+
return false;
|
|
7441
7760
|
}
|
|
7442
7761
|
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
|
|
7443
|
-
|
|
7762
|
+
return false;
|
|
7444
7763
|
}
|
|
7445
|
-
|
|
7446
|
-
|
|
7764
|
+
return true;
|
|
7765
|
+
});
|
|
7766
|
+
if (!includeStats) {
|
|
7767
|
+
return filteredAccounts.map(({ publicKey, account }) => ({
|
|
7768
|
+
publicKey,
|
|
7769
|
+
bondState: account,
|
|
7770
|
+
stateStats: null
|
|
7771
|
+
}));
|
|
7447
7772
|
}
|
|
7448
|
-
return
|
|
7773
|
+
return Promise.all(
|
|
7774
|
+
filteredAccounts.map(async ({ publicKey, account }) => {
|
|
7775
|
+
const stateStats = await this.getBondStateStats(account);
|
|
7776
|
+
return { publicKey, bondState: account, stateStats };
|
|
7777
|
+
})
|
|
7778
|
+
);
|
|
7449
7779
|
}
|
|
7450
7780
|
/**
|
|
7451
7781
|
* Fetch global state or throw if not found
|
|
@@ -7466,13 +7796,26 @@ var JBondClient = class _JBondClient {
|
|
|
7466
7796
|
return { publicKey, ...data };
|
|
7467
7797
|
}
|
|
7468
7798
|
/**
|
|
7469
|
-
* Fetch validator bond data or
|
|
7799
|
+
* Fetch validator bond data or error if not found
|
|
7470
7800
|
*/
|
|
7471
7801
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7472
7802
|
const [publicKey] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7803
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7473
7804
|
const data = await this.program.account.validatorBond.fetch(publicKey);
|
|
7474
7805
|
return { publicKey, ...data };
|
|
7475
7806
|
}
|
|
7807
|
+
/**
|
|
7808
|
+
* Fetch validator bond data or null if not found
|
|
7809
|
+
*/
|
|
7810
|
+
async getValidatorBondNullable(bondType, bondName, vote) {
|
|
7811
|
+
const [publicKey] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7812
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7813
|
+
const data = await this.program.account.validatorBond.fetchNullable(publicKey);
|
|
7814
|
+
if (!data) {
|
|
7815
|
+
return null;
|
|
7816
|
+
}
|
|
7817
|
+
return { publicKey, ...data };
|
|
7818
|
+
}
|
|
7476
7819
|
/**
|
|
7477
7820
|
* Get validator bond account balance (in SOL)
|
|
7478
7821
|
*/
|
|
@@ -7494,16 +7837,16 @@ var JBondClient = class _JBondClient {
|
|
|
7494
7837
|
const tokenAccount = getAssociatedTokenAddressSync(mint, address, true);
|
|
7495
7838
|
try {
|
|
7496
7839
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
7497
|
-
return
|
|
7840
|
+
return Number(balance.value.amount);
|
|
7498
7841
|
} catch {
|
|
7499
7842
|
return 0;
|
|
7500
7843
|
}
|
|
7501
7844
|
}
|
|
7502
7845
|
});
|
|
7503
7846
|
}
|
|
7504
|
-
async getBondStateValidatorBondBalances(bondType, bondName) {
|
|
7505
|
-
const
|
|
7506
|
-
const collateralType =
|
|
7847
|
+
async getBondStateValidatorBondBalances(bondType, bondName, bondState) {
|
|
7848
|
+
const state = bondState ?? await this.getBondState(bondType, bondName);
|
|
7849
|
+
const collateralType = state.collateralType;
|
|
7507
7850
|
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7508
7851
|
if (!validatorBonds.length) {
|
|
7509
7852
|
return [];
|
|
@@ -7560,20 +7903,20 @@ var JBondClient = class _JBondClient {
|
|
|
7560
7903
|
/**
|
|
7561
7904
|
* Get total collected collateral for a bond state
|
|
7562
7905
|
*/
|
|
7563
|
-
async getBondStateTotalCollected(bondType, bondName) {
|
|
7564
|
-
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName);
|
|
7906
|
+
async getBondStateTotalCollected(bondType, bondName, bondState) {
|
|
7907
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName, bondState);
|
|
7565
7908
|
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7566
7909
|
}
|
|
7567
7910
|
/**
|
|
7568
7911
|
* Get bond state stats
|
|
7569
7912
|
* @param state
|
|
7570
|
-
* @private
|
|
7571
7913
|
*/
|
|
7572
7914
|
async getBondStateStats(state) {
|
|
7573
7915
|
const bondType = anchorToBondType(state.bondType);
|
|
7574
7916
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
7575
7917
|
bondType,
|
|
7576
|
-
state.name
|
|
7918
|
+
state.name,
|
|
7919
|
+
state
|
|
7577
7920
|
);
|
|
7578
7921
|
return {
|
|
7579
7922
|
totalCollected,
|
|
@@ -7632,6 +7975,6 @@ buffer/index.js:
|
|
|
7632
7975
|
*)
|
|
7633
7976
|
*/
|
|
7634
7977
|
|
|
7635
|
-
export { BOND_STATE_SEED, BondTransactionType, BondType, CROWDFUNDING_BOND_SEED, ENV_PROGRAM_ID, GLOBAL_STATE_SEED, JBondClient, JBondClientEnv, NodeWallet, STANDARD_BOND_SEED, SessionStatus, VALIDATOR_BOND_SEED };
|
|
7978
|
+
export { BOND_STATE_SEED, BondTransactionType, BondType, CROWDFUNDING_BOND_SEED, ENV_PROGRAM_ID, GLOBAL_STATE_SEED, JBondClient, JBondClientEnv, JPOOL_POOL_ADDRESS, JSOL_MINT, NodeWallet, STANDARD_BOND_SEED, SessionStatus, VALIDATOR_BOND_SEED, lamportsToSol };
|
|
7636
7979
|
//# sourceMappingURL=index.mjs.map
|
|
7637
7980
|
//# sourceMappingURL=index.mjs.map
|