@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.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var anchor = require('@coral-xyz/anchor');
|
|
4
|
+
var splStakePool = require('@solana/spl-stake-pool');
|
|
4
5
|
var splToken = require('@solana/spl-token');
|
|
5
6
|
var web3_js = require('@solana/web3.js');
|
|
6
7
|
|
|
@@ -33,19 +34,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
34
|
mod
|
|
34
35
|
));
|
|
35
36
|
|
|
36
|
-
// ../../node_modules/.pnpm/tsup@8.5.
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.13.5_@swc+helpers@0.5.17__jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
37
38
|
var init_cjs_shims = __esm({
|
|
38
|
-
"../../node_modules/.pnpm/tsup@8.5.
|
|
39
|
+
"../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.13.5_@swc+helpers@0.5.17__jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js"() {
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
// ../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
|
|
43
44
|
var require_base64_js = __commonJS({
|
|
44
|
-
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports) {
|
|
45
|
+
"../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports$1) {
|
|
45
46
|
init_cjs_shims();
|
|
46
|
-
exports.byteLength = byteLength;
|
|
47
|
-
exports.toByteArray = toByteArray;
|
|
48
|
-
exports.fromByteArray = fromByteArray;
|
|
47
|
+
exports$1.byteLength = byteLength;
|
|
48
|
+
exports$1.toByteArray = toByteArray;
|
|
49
|
+
exports$1.fromByteArray = fromByteArray;
|
|
49
50
|
var lookup = [];
|
|
50
51
|
var revLookup = [];
|
|
51
52
|
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
@@ -142,9 +143,9 @@ var require_base64_js = __commonJS({
|
|
|
142
143
|
|
|
143
144
|
// ../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
|
|
144
145
|
var require_ieee754 = __commonJS({
|
|
145
|
-
"../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js"(exports) {
|
|
146
|
+
"../../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js"(exports$1) {
|
|
146
147
|
init_cjs_shims();
|
|
147
|
-
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
148
|
+
exports$1.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
148
149
|
var e, m;
|
|
149
150
|
var eLen = nBytes * 8 - mLen - 1;
|
|
150
151
|
var eMax = (1 << eLen) - 1;
|
|
@@ -174,7 +175,7 @@ var require_ieee754 = __commonJS({
|
|
|
174
175
|
}
|
|
175
176
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
176
177
|
};
|
|
177
|
-
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
178
|
+
exports$1.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
178
179
|
var e, m, c;
|
|
179
180
|
var eLen = nBytes * 8 - mLen - 1;
|
|
180
181
|
var eMax = (1 << eLen) - 1;
|
|
@@ -226,16 +227,16 @@ var require_ieee754 = __commonJS({
|
|
|
226
227
|
|
|
227
228
|
// ../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
|
|
228
229
|
var require_buffer = __commonJS({
|
|
229
|
-
"../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js"(exports) {
|
|
230
|
+
"../../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js"(exports$1) {
|
|
230
231
|
init_cjs_shims();
|
|
231
232
|
var base64 = require_base64_js();
|
|
232
233
|
var ieee754 = require_ieee754();
|
|
233
234
|
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
234
|
-
exports.Buffer = Buffer2;
|
|
235
|
-
exports.SlowBuffer = SlowBuffer;
|
|
236
|
-
exports.INSPECT_MAX_BYTES = 50;
|
|
235
|
+
exports$1.Buffer = Buffer2;
|
|
236
|
+
exports$1.SlowBuffer = SlowBuffer;
|
|
237
|
+
exports$1.INSPECT_MAX_BYTES = 50;
|
|
237
238
|
var K_MAX_LENGTH = 2147483647;
|
|
238
|
-
exports.kMaxLength = K_MAX_LENGTH;
|
|
239
|
+
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
239
240
|
Buffer2.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
240
241
|
if (!Buffer2.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
241
242
|
console.error(
|
|
@@ -665,7 +666,7 @@ var require_buffer = __commonJS({
|
|
|
665
666
|
};
|
|
666
667
|
Buffer2.prototype.inspect = function inspect() {
|
|
667
668
|
let str = "";
|
|
668
|
-
const max = exports.INSPECT_MAX_BYTES;
|
|
669
|
+
const max = exports$1.INSPECT_MAX_BYTES;
|
|
669
670
|
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
670
671
|
if (this.length > max) str += " ... ";
|
|
671
672
|
return "<Buffer " + str + ">";
|
|
@@ -1816,7 +1817,7 @@ var require_buffer = __commonJS({
|
|
|
1816
1817
|
|
|
1817
1818
|
// ../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js
|
|
1818
1819
|
var require_bn = __commonJS({
|
|
1819
|
-
"../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js"(exports, module) {
|
|
1820
|
+
"../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js"(exports$1, module) {
|
|
1820
1821
|
init_cjs_shims();
|
|
1821
1822
|
(function(module2, exports2) {
|
|
1822
1823
|
function assert(val, msg) {
|
|
@@ -4555,7 +4556,7 @@ var require_bn = __commonJS({
|
|
|
4555
4556
|
var res = this.imod(a._invmp(this.m).mul(this.r2));
|
|
4556
4557
|
return res._forceRed(this);
|
|
4557
4558
|
};
|
|
4558
|
-
})(typeof module === "undefined" || module, exports);
|
|
4559
|
+
})(typeof module === "undefined" || module, exports$1);
|
|
4559
4560
|
}
|
|
4560
4561
|
});
|
|
4561
4562
|
|
|
@@ -4588,6 +4589,7 @@ var BondType = /* @__PURE__ */ ((BondType2) => {
|
|
|
4588
4589
|
return BondType2;
|
|
4589
4590
|
})(BondType || {});
|
|
4590
4591
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4592
|
+
BondTransactionType2["Registered"] = "registered";
|
|
4591
4593
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4592
4594
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
4593
4595
|
BondTransactionType2["Compensation"] = "compensation";
|
|
@@ -4605,6 +4607,8 @@ var ENV_PROGRAM_ID = {
|
|
|
4605
4607
|
["stage" /* STAGE */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4606
4608
|
["prod" /* PROD */]: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU"
|
|
4607
4609
|
};
|
|
4610
|
+
var JSOL_MINT = new web3_js.PublicKey("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn");
|
|
4611
|
+
var JPOOL_POOL_ADDRESS = new web3_js.PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
|
|
4608
4612
|
|
|
4609
4613
|
// src/history.ts
|
|
4610
4614
|
init_cjs_shims();
|
|
@@ -4671,7 +4675,7 @@ var HistoryManager = class {
|
|
|
4671
4675
|
continue;
|
|
4672
4676
|
}
|
|
4673
4677
|
const { type, amount } = this.decodeInstructionData(ix.data);
|
|
4674
|
-
if (!type || amount <= 0) {
|
|
4678
|
+
if (!type || amount <= 0 && type !== "registered" /* Registered */) {
|
|
4675
4679
|
continue;
|
|
4676
4680
|
}
|
|
4677
4681
|
history.push({
|
|
@@ -4691,7 +4695,6 @@ var HistoryManager = class {
|
|
|
4691
4695
|
before: options?.before,
|
|
4692
4696
|
until: options?.until
|
|
4693
4697
|
}, "confirmed");
|
|
4694
|
-
console.log(sigs);
|
|
4695
4698
|
return sigs.filter((s) => !s.err);
|
|
4696
4699
|
}
|
|
4697
4700
|
async fetchParsedTransactions(sigs, batchSize = 100) {
|
|
@@ -4713,7 +4716,7 @@ var HistoryManager = class {
|
|
|
4713
4716
|
}
|
|
4714
4717
|
const ix = this.program.idl.instructions.find((i) => i.name === name);
|
|
4715
4718
|
if (!ix || !Array.isArray(ix.discriminator)) {
|
|
4716
|
-
|
|
4719
|
+
return new Uint8Array();
|
|
4717
4720
|
}
|
|
4718
4721
|
const disc = new Uint8Array(ix.discriminator);
|
|
4719
4722
|
this.discCache.set(name, disc);
|
|
@@ -4721,47 +4724,45 @@ var HistoryManager = class {
|
|
|
4721
4724
|
}
|
|
4722
4725
|
decodeInstructionData(data) {
|
|
4723
4726
|
if (!data) {
|
|
4724
|
-
return {
|
|
4725
|
-
type: null,
|
|
4726
|
-
amount: 0
|
|
4727
|
-
};
|
|
4727
|
+
return { type: null, amount: 0 };
|
|
4728
4728
|
}
|
|
4729
4729
|
try {
|
|
4730
4730
|
const buf = bs58.decode(data);
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
const
|
|
4742
|
-
const
|
|
4743
|
-
const
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
if (
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
}
|
|
4756
|
-
return { type
|
|
4757
|
-
} catch {
|
|
4731
|
+
let type = null;
|
|
4732
|
+
const disc = buf.subarray(0, 8);
|
|
4733
|
+
const amountBytes = buf.subarray(8, 16);
|
|
4734
|
+
let amount = 0;
|
|
4735
|
+
let noAmount = false;
|
|
4736
|
+
try {
|
|
4737
|
+
amount = new anchor.BN(amountBytes, "le").toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
4738
|
+
} catch {
|
|
4739
|
+
noAmount = true;
|
|
4740
|
+
}
|
|
4741
|
+
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
4742
|
+
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
4743
|
+
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
4744
|
+
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
4745
|
+
if (Buffer.from(disc).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
4746
|
+
type = "registered" /* Registered */;
|
|
4747
|
+
} else if (!noAmount) {
|
|
4748
|
+
if (Buffer.from(disc).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
4749
|
+
type = "deposit" /* Deposit */;
|
|
4750
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
4751
|
+
type = "compensation" /* Compensation */;
|
|
4752
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
4753
|
+
type = "withdrawal" /* Withdrawal */;
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
return { type, amount };
|
|
4757
|
+
} catch (error) {
|
|
4758
|
+
console.error("Failed to decode instruction data:", error);
|
|
4758
4759
|
return { type: null, amount: 0 };
|
|
4759
4760
|
}
|
|
4760
4761
|
}
|
|
4761
4762
|
};
|
|
4762
4763
|
function slotToEpoch(slot, cluster) {
|
|
4763
|
-
const
|
|
4764
|
-
const slotsPerEpoch =
|
|
4764
|
+
const isDevnet = cluster?.includes("devnet") || cluster?.includes("localnet");
|
|
4765
|
+
const slotsPerEpoch = isDevnet ? 4e5 : 432e3;
|
|
4765
4766
|
return Math.floor(slot / slotsPerEpoch);
|
|
4766
4767
|
}
|
|
4767
4768
|
|
|
@@ -4770,7 +4771,7 @@ var jbond_default = {
|
|
|
4770
4771
|
address: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU",
|
|
4771
4772
|
metadata: {
|
|
4772
4773
|
name: "jbond",
|
|
4773
|
-
version: "0.2.
|
|
4774
|
+
version: "0.2.6",
|
|
4774
4775
|
spec: "0.1.0",
|
|
4775
4776
|
description: "Jpool Bond Program"
|
|
4776
4777
|
},
|
|
@@ -5521,38 +5522,6 @@ var jbond_default = {
|
|
|
5521
5522
|
}
|
|
5522
5523
|
]
|
|
5523
5524
|
},
|
|
5524
|
-
{
|
|
5525
|
-
name: "bond_update",
|
|
5526
|
-
docs: [
|
|
5527
|
-
"Applies any pending unlocks from previous epochs.",
|
|
5528
|
-
"",
|
|
5529
|
-
"This instruction is optional - all other operations now automatically",
|
|
5530
|
-
"sync the epoch state. It is kept for backwards compatibility and can",
|
|
5531
|
-
"be used to explicitly trigger epoch synchronization without performing",
|
|
5532
|
-
"another operation."
|
|
5533
|
-
],
|
|
5534
|
-
discriminator: [
|
|
5535
|
-
237,
|
|
5536
|
-
102,
|
|
5537
|
-
183,
|
|
5538
|
-
192,
|
|
5539
|
-
94,
|
|
5540
|
-
83,
|
|
5541
|
-
52,
|
|
5542
|
-
82
|
|
5543
|
-
],
|
|
5544
|
-
accounts: [
|
|
5545
|
-
{
|
|
5546
|
-
name: "validator_bond",
|
|
5547
|
-
writable: true
|
|
5548
|
-
},
|
|
5549
|
-
{
|
|
5550
|
-
name: "payer",
|
|
5551
|
-
signer: true
|
|
5552
|
-
}
|
|
5553
|
-
],
|
|
5554
|
-
args: []
|
|
5555
|
-
},
|
|
5556
5525
|
{
|
|
5557
5526
|
name: "bond_withdraw",
|
|
5558
5527
|
docs: [
|
|
@@ -5663,6 +5632,103 @@ var jbond_default = {
|
|
|
5663
5632
|
}
|
|
5664
5633
|
]
|
|
5665
5634
|
},
|
|
5635
|
+
{
|
|
5636
|
+
name: "close_validator_bond",
|
|
5637
|
+
docs: [
|
|
5638
|
+
"Closes a validator bond account and transfers remaining balance to the rent receiver.",
|
|
5639
|
+
"",
|
|
5640
|
+
"# Security",
|
|
5641
|
+
"- Only the validator identity or withdrawal authority can close the bond",
|
|
5642
|
+
"- All funds must be unlocked (locked == 0 and pending_unlock == 0)",
|
|
5643
|
+
"- For token collateral, closes the associated token account as well",
|
|
5644
|
+
"- Decrements the bond state's total_members counter",
|
|
5645
|
+
"",
|
|
5646
|
+
"# Errors",
|
|
5647
|
+
"Fails if the signer is not authorized, if funds are still locked,",
|
|
5648
|
+
"or if the rent receiver is not the identity or withdrawal authority."
|
|
5649
|
+
],
|
|
5650
|
+
discriminator: [
|
|
5651
|
+
51,
|
|
5652
|
+
235,
|
|
5653
|
+
111,
|
|
5654
|
+
163,
|
|
5655
|
+
176,
|
|
5656
|
+
239,
|
|
5657
|
+
95,
|
|
5658
|
+
122
|
|
5659
|
+
],
|
|
5660
|
+
accounts: [
|
|
5661
|
+
{
|
|
5662
|
+
name: "bond_state",
|
|
5663
|
+
writable: true
|
|
5664
|
+
},
|
|
5665
|
+
{
|
|
5666
|
+
name: "validator_bond",
|
|
5667
|
+
writable: true,
|
|
5668
|
+
pda: {
|
|
5669
|
+
seeds: [
|
|
5670
|
+
{
|
|
5671
|
+
kind: "const",
|
|
5672
|
+
value: [
|
|
5673
|
+
118,
|
|
5674
|
+
97,
|
|
5675
|
+
108,
|
|
5676
|
+
105,
|
|
5677
|
+
100,
|
|
5678
|
+
97,
|
|
5679
|
+
116,
|
|
5680
|
+
111,
|
|
5681
|
+
114,
|
|
5682
|
+
95,
|
|
5683
|
+
98,
|
|
5684
|
+
111,
|
|
5685
|
+
110,
|
|
5686
|
+
100
|
|
5687
|
+
]
|
|
5688
|
+
},
|
|
5689
|
+
{
|
|
5690
|
+
kind: "account",
|
|
5691
|
+
path: "bond_state"
|
|
5692
|
+
},
|
|
5693
|
+
{
|
|
5694
|
+
kind: "account",
|
|
5695
|
+
path: "validator_bond.vote_account",
|
|
5696
|
+
account: "ValidatorBond"
|
|
5697
|
+
}
|
|
5698
|
+
]
|
|
5699
|
+
}
|
|
5700
|
+
},
|
|
5701
|
+
{
|
|
5702
|
+
name: "authority",
|
|
5703
|
+
writable: true,
|
|
5704
|
+
signer: true
|
|
5705
|
+
},
|
|
5706
|
+
{
|
|
5707
|
+
name: "rent_receiver",
|
|
5708
|
+
writable: true
|
|
5709
|
+
},
|
|
5710
|
+
{
|
|
5711
|
+
name: "bond_token_account",
|
|
5712
|
+
writable: true,
|
|
5713
|
+
optional: true
|
|
5714
|
+
},
|
|
5715
|
+
{
|
|
5716
|
+
name: "destination_token_account",
|
|
5717
|
+
writable: true,
|
|
5718
|
+
optional: true
|
|
5719
|
+
},
|
|
5720
|
+
{
|
|
5721
|
+
name: "system_program",
|
|
5722
|
+
address: "11111111111111111111111111111111"
|
|
5723
|
+
},
|
|
5724
|
+
{
|
|
5725
|
+
name: "token_program",
|
|
5726
|
+
optional: true,
|
|
5727
|
+
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
5728
|
+
}
|
|
5729
|
+
],
|
|
5730
|
+
args: []
|
|
5731
|
+
},
|
|
5666
5732
|
{
|
|
5667
5733
|
name: "global_configure",
|
|
5668
5734
|
discriminator: [
|
|
@@ -6023,6 +6089,19 @@ var jbond_default = {
|
|
|
6023
6089
|
128
|
|
6024
6090
|
]
|
|
6025
6091
|
},
|
|
6092
|
+
{
|
|
6093
|
+
name: "ValidatorBondClosed",
|
|
6094
|
+
discriminator: [
|
|
6095
|
+
71,
|
|
6096
|
+
54,
|
|
6097
|
+
59,
|
|
6098
|
+
241,
|
|
6099
|
+
91,
|
|
6100
|
+
35,
|
|
6101
|
+
123,
|
|
6102
|
+
123
|
|
6103
|
+
]
|
|
6104
|
+
},
|
|
6026
6105
|
{
|
|
6027
6106
|
name: "ValidatorRegistered",
|
|
6028
6107
|
discriminator: [
|
|
@@ -6722,6 +6801,34 @@ var jbond_default = {
|
|
|
6722
6801
|
]
|
|
6723
6802
|
}
|
|
6724
6803
|
},
|
|
6804
|
+
{
|
|
6805
|
+
name: "ValidatorBondClosed",
|
|
6806
|
+
type: {
|
|
6807
|
+
kind: "struct",
|
|
6808
|
+
fields: [
|
|
6809
|
+
{
|
|
6810
|
+
name: "validator",
|
|
6811
|
+
type: "pubkey"
|
|
6812
|
+
},
|
|
6813
|
+
{
|
|
6814
|
+
name: "vote_account",
|
|
6815
|
+
type: "pubkey"
|
|
6816
|
+
},
|
|
6817
|
+
{
|
|
6818
|
+
name: "rent_receiver",
|
|
6819
|
+
type: "pubkey"
|
|
6820
|
+
},
|
|
6821
|
+
{
|
|
6822
|
+
name: "final_balance",
|
|
6823
|
+
type: "u64"
|
|
6824
|
+
},
|
|
6825
|
+
{
|
|
6826
|
+
name: "timestamp",
|
|
6827
|
+
type: "i64"
|
|
6828
|
+
}
|
|
6829
|
+
]
|
|
6830
|
+
}
|
|
6831
|
+
},
|
|
6725
6832
|
{
|
|
6726
6833
|
name: "ValidatorRegistered",
|
|
6727
6834
|
type: {
|
|
@@ -6828,6 +6935,25 @@ function anchorToBondType(variant) {
|
|
|
6828
6935
|
return fromAnchor(variant);
|
|
6829
6936
|
}
|
|
6830
6937
|
|
|
6938
|
+
// src/utils/stake-pool.ts
|
|
6939
|
+
init_cjs_shims();
|
|
6940
|
+
async function getStakePoolAccountData(connection, stakePoolAddress) {
|
|
6941
|
+
const stakePoolAccount = await splStakePool.getStakePoolAccount(connection, stakePoolAddress);
|
|
6942
|
+
if (!stakePoolAccount) {
|
|
6943
|
+
throw new Error(`Stake pool account not found: ${stakePoolAddress.toBase58()}`);
|
|
6944
|
+
}
|
|
6945
|
+
return stakePoolAccount.account.data;
|
|
6946
|
+
}
|
|
6947
|
+
function lamportsToPoolTokenLamports(lamports, stakePool) {
|
|
6948
|
+
if (stakePool.totalLamports.isZero()) {
|
|
6949
|
+
throw new Error("Stake pool has zero total lamports");
|
|
6950
|
+
}
|
|
6951
|
+
if (stakePool.poolTokenSupply.isZero()) {
|
|
6952
|
+
throw new Error("Stake pool has zero pool token supply");
|
|
6953
|
+
}
|
|
6954
|
+
return lamports.mul(stakePool.poolTokenSupply).div(stakePool.totalLamports);
|
|
6955
|
+
}
|
|
6956
|
+
|
|
6831
6957
|
// src/utils/wallet.ts
|
|
6832
6958
|
init_cjs_shims();
|
|
6833
6959
|
function isVersionedTransaction(tx) {
|
|
@@ -6974,6 +7100,9 @@ var JBondClient = class _JBondClient {
|
|
|
6974
7100
|
*/
|
|
6975
7101
|
configure(key, val) {
|
|
6976
7102
|
this.options[key] = val;
|
|
7103
|
+
if (key === "programId") {
|
|
7104
|
+
this._program = null;
|
|
7105
|
+
}
|
|
6977
7106
|
return this;
|
|
6978
7107
|
}
|
|
6979
7108
|
/**
|
|
@@ -7032,8 +7161,8 @@ var JBondClient = class _JBondClient {
|
|
|
7032
7161
|
* Top up collateral
|
|
7033
7162
|
*/
|
|
7034
7163
|
async topUpCollateral(props) {
|
|
7035
|
-
const
|
|
7036
|
-
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...
|
|
7164
|
+
const { instructions, signers } = await this.getTopUpIxs(props);
|
|
7165
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...instructions), signers);
|
|
7037
7166
|
}
|
|
7038
7167
|
/**
|
|
7039
7168
|
* Withdraw collateral
|
|
@@ -7042,6 +7171,13 @@ var JBondClient = class _JBondClient {
|
|
|
7042
7171
|
const ix = await this.getWithdrawIx(props);
|
|
7043
7172
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7044
7173
|
}
|
|
7174
|
+
/**
|
|
7175
|
+
* Migrate SOL collateral from one bond account to JSOL collateral in another bond account
|
|
7176
|
+
*/
|
|
7177
|
+
async migrateBond(props) {
|
|
7178
|
+
const { instructions, signers } = await this.getMigrateBondIx(props);
|
|
7179
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...instructions), signers);
|
|
7180
|
+
}
|
|
7045
7181
|
/**
|
|
7046
7182
|
* Claim compensation for a validator
|
|
7047
7183
|
*/
|
|
@@ -7088,6 +7224,10 @@ var JBondClient = class _JBondClient {
|
|
|
7088
7224
|
const ix = await this.getBondRemoveIx(props);
|
|
7089
7225
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7090
7226
|
}
|
|
7227
|
+
async closeValidatorBond(props) {
|
|
7228
|
+
const ix = await this.getCloseValidatorBondIx(props);
|
|
7229
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7230
|
+
}
|
|
7091
7231
|
/**
|
|
7092
7232
|
* Build global state initialize instruction
|
|
7093
7233
|
*/
|
|
@@ -7198,6 +7338,9 @@ var JBondClient = class _JBondClient {
|
|
|
7198
7338
|
collateralType = bondState2.collateralType;
|
|
7199
7339
|
}
|
|
7200
7340
|
const instructions = [];
|
|
7341
|
+
const signers = [];
|
|
7342
|
+
const amountLamports = solToLamports(amount);
|
|
7343
|
+
let topUpAmount = amountLamports;
|
|
7201
7344
|
try {
|
|
7202
7345
|
await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
7203
7346
|
} catch {
|
|
@@ -7229,10 +7372,33 @@ var JBondClient = class _JBondClient {
|
|
|
7229
7372
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7230
7373
|
}
|
|
7231
7374
|
});
|
|
7375
|
+
if (props.solUsage) {
|
|
7376
|
+
let usesJsolCollateral = false;
|
|
7377
|
+
matchVariant(collateralType, {
|
|
7378
|
+
token: (mint) => {
|
|
7379
|
+
usesJsolCollateral = mint.equals(JSOL_MINT);
|
|
7380
|
+
}
|
|
7381
|
+
});
|
|
7382
|
+
if (usesJsolCollateral) {
|
|
7383
|
+
const stakePool = await getStakePoolAccountData(this.connection, JPOOL_POOL_ADDRESS);
|
|
7384
|
+
const deposit = await splStakePool.depositSol(
|
|
7385
|
+
this.connection,
|
|
7386
|
+
JPOOL_POOL_ADDRESS,
|
|
7387
|
+
payer,
|
|
7388
|
+
amountLamports.toNumber(),
|
|
7389
|
+
void 0,
|
|
7390
|
+
void 0,
|
|
7391
|
+
void 0
|
|
7392
|
+
);
|
|
7393
|
+
instructions.push(...deposit.instructions);
|
|
7394
|
+
signers.push(...deposit.signers);
|
|
7395
|
+
topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7396
|
+
}
|
|
7397
|
+
}
|
|
7232
7398
|
instructions.push(
|
|
7233
|
-
await this.program.methods.bondTopUp(
|
|
7399
|
+
await this.program.methods.bondTopUp(topUpAmount).accountsPartial(accounts).instruction()
|
|
7234
7400
|
);
|
|
7235
|
-
return instructions;
|
|
7401
|
+
return { instructions, signers };
|
|
7236
7402
|
}
|
|
7237
7403
|
/**
|
|
7238
7404
|
* Build withdraw collateral instruction
|
|
@@ -7271,6 +7437,139 @@ var JBondClient = class _JBondClient {
|
|
|
7271
7437
|
});
|
|
7272
7438
|
return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7273
7439
|
}
|
|
7440
|
+
/**
|
|
7441
|
+
* Build instructions for migrating SOL bond collateral into JSOL bond collateral in a single transaction
|
|
7442
|
+
*/
|
|
7443
|
+
async getMigrateBondIx(props) {
|
|
7444
|
+
const {
|
|
7445
|
+
bondType,
|
|
7446
|
+
voteAccount,
|
|
7447
|
+
identity,
|
|
7448
|
+
withdrawName = "performance",
|
|
7449
|
+
topUpName = "perf",
|
|
7450
|
+
stakePoolAddress = JPOOL_POOL_ADDRESS
|
|
7451
|
+
} = props;
|
|
7452
|
+
const payer = props.payer ?? this.provider.wallet?.publicKey;
|
|
7453
|
+
const destination = props.destination ?? payer;
|
|
7454
|
+
if (!payer || !destination) {
|
|
7455
|
+
throw new Error("Missing payer/destination");
|
|
7456
|
+
}
|
|
7457
|
+
const withdrawBondState = await this.getBondState(bondType, withdrawName);
|
|
7458
|
+
await matchVariant(withdrawBondState.collateralType, {
|
|
7459
|
+
native: () => {
|
|
7460
|
+
},
|
|
7461
|
+
token: () => {
|
|
7462
|
+
throw new Error("Withdraw bond collateral type must be native SOL for migration");
|
|
7463
|
+
}
|
|
7464
|
+
});
|
|
7465
|
+
const availableLamports = await this.getAvailableCollateral(bondType, withdrawName, voteAccount);
|
|
7466
|
+
if (!availableLamports || availableLamports <= 0) {
|
|
7467
|
+
throw new Error("No available balance to migrate");
|
|
7468
|
+
}
|
|
7469
|
+
const amount = lamportsToSol(availableLamports);
|
|
7470
|
+
const amountLamports = solToLamports(amount);
|
|
7471
|
+
const withdrawIx = await this.getWithdrawIx({
|
|
7472
|
+
bondType,
|
|
7473
|
+
name: withdrawName,
|
|
7474
|
+
amount,
|
|
7475
|
+
voteAccount,
|
|
7476
|
+
destination,
|
|
7477
|
+
withdrawalAuthority: props.withdrawalAuthority
|
|
7478
|
+
});
|
|
7479
|
+
const deposit = await this.getDepositSolIxsWithoutBalanceCheck(
|
|
7480
|
+
stakePoolAddress,
|
|
7481
|
+
payer,
|
|
7482
|
+
amountLamports.toNumber()
|
|
7483
|
+
);
|
|
7484
|
+
const topUpBondState = await this.getBondState(bondType, topUpName);
|
|
7485
|
+
const topUpCollateralType = topUpBondState.collateralType;
|
|
7486
|
+
const instructions = [withdrawIx, ...deposit.instructions];
|
|
7487
|
+
const signers = [...deposit.signers];
|
|
7488
|
+
try {
|
|
7489
|
+
await this.getValidatorBond(bondType, topUpName, voteAccount);
|
|
7490
|
+
} catch {
|
|
7491
|
+
instructions.push(
|
|
7492
|
+
await this.getRegisterValidatorIx({
|
|
7493
|
+
bondType,
|
|
7494
|
+
name: topUpName,
|
|
7495
|
+
voteAccount,
|
|
7496
|
+
identity,
|
|
7497
|
+
creator: payer,
|
|
7498
|
+
collateralType: topUpCollateralType
|
|
7499
|
+
})
|
|
7500
|
+
);
|
|
7501
|
+
}
|
|
7502
|
+
const [topUpBondStateAddress] = this.pda.bondState(bondType, topUpName);
|
|
7503
|
+
const [topUpValidatorBond] = this.pda.validatorBond(bondType, topUpName, voteAccount);
|
|
7504
|
+
await matchVariant(topUpCollateralType, {
|
|
7505
|
+
native: () => {
|
|
7506
|
+
throw new Error("Top up bond collateral type must be token for migration");
|
|
7507
|
+
},
|
|
7508
|
+
token: async (mint) => {
|
|
7509
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7510
|
+
const topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7511
|
+
const topUpIx = await this.program.methods.bondTopUp(topUpAmount).accountsPartial({
|
|
7512
|
+
bondState: topUpBondStateAddress,
|
|
7513
|
+
validatorBond: topUpValidatorBond,
|
|
7514
|
+
payer,
|
|
7515
|
+
payerTokenAccount: splToken.getAssociatedTokenAddressSync(mint, payer),
|
|
7516
|
+
bondTokenAccount: splToken.getAssociatedTokenAddressSync(mint, topUpValidatorBond, true),
|
|
7517
|
+
stakeAccount: null,
|
|
7518
|
+
stakeProgram: null
|
|
7519
|
+
}).instruction();
|
|
7520
|
+
instructions.push(topUpIx);
|
|
7521
|
+
}
|
|
7522
|
+
});
|
|
7523
|
+
return { instructions, signers };
|
|
7524
|
+
}
|
|
7525
|
+
/**
|
|
7526
|
+
* Build stake-pool SOL deposit instructions without pre-checking payer balance.
|
|
7527
|
+
* This allows composing withdraw->deposit in a single transaction where SOL is obtained by the prior instruction.
|
|
7528
|
+
*/
|
|
7529
|
+
async getDepositSolIxsWithoutBalanceCheck(stakePoolAddress, payer, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
|
|
7530
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7531
|
+
const transferSigner = new web3_js.Keypair();
|
|
7532
|
+
const signers = [transferSigner];
|
|
7533
|
+
const instructions = [
|
|
7534
|
+
web3_js.SystemProgram.transfer({
|
|
7535
|
+
fromPubkey: payer,
|
|
7536
|
+
toPubkey: transferSigner.publicKey,
|
|
7537
|
+
lamports
|
|
7538
|
+
})
|
|
7539
|
+
];
|
|
7540
|
+
let destinationPoolAccount = destinationTokenAccount;
|
|
7541
|
+
if (!destinationPoolAccount) {
|
|
7542
|
+
const associatedAddress = splToken.getAssociatedTokenAddressSync(stakePool.poolMint, payer);
|
|
7543
|
+
instructions.push(
|
|
7544
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(
|
|
7545
|
+
payer,
|
|
7546
|
+
associatedAddress,
|
|
7547
|
+
payer,
|
|
7548
|
+
stakePool.poolMint
|
|
7549
|
+
)
|
|
7550
|
+
);
|
|
7551
|
+
destinationPoolAccount = associatedAddress;
|
|
7552
|
+
}
|
|
7553
|
+
const [withdrawAuthority] = web3_js.PublicKey.findProgramAddressSync(
|
|
7554
|
+
[stakePoolAddress.toBuffer(), Buffer.from("withdraw")],
|
|
7555
|
+
splStakePool.STAKE_POOL_PROGRAM_ID
|
|
7556
|
+
);
|
|
7557
|
+
instructions.push(
|
|
7558
|
+
splStakePool.StakePoolInstruction.depositSol({
|
|
7559
|
+
stakePool: stakePoolAddress,
|
|
7560
|
+
reserveStake: stakePool.reserveStake,
|
|
7561
|
+
fundingAccount: transferSigner.publicKey,
|
|
7562
|
+
destinationPoolAccount,
|
|
7563
|
+
managerFeeAccount: stakePool.managerFeeAccount,
|
|
7564
|
+
referralPoolAccount: referrerTokenAccount ?? destinationPoolAccount,
|
|
7565
|
+
poolMint: stakePool.poolMint,
|
|
7566
|
+
lamports,
|
|
7567
|
+
withdrawAuthority,
|
|
7568
|
+
depositAuthority
|
|
7569
|
+
})
|
|
7570
|
+
);
|
|
7571
|
+
return { instructions, signers };
|
|
7572
|
+
}
|
|
7274
7573
|
/**
|
|
7275
7574
|
* Build claim instruction
|
|
7276
7575
|
*/
|
|
@@ -7378,22 +7677,6 @@ var JBondClient = class _JBondClient {
|
|
|
7378
7677
|
const ix = await this.getReleaseFundsIx(props);
|
|
7379
7678
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7380
7679
|
}
|
|
7381
|
-
/**
|
|
7382
|
-
* Update epoch locks
|
|
7383
|
-
*/
|
|
7384
|
-
async updateEpochLocks(props) {
|
|
7385
|
-
const { bondType, bondName, voteAccount, payer } = props;
|
|
7386
|
-
const ix = await this.getUpdateEpochLocksIx({ bondType, bondName, voteAccount, payer });
|
|
7387
|
-
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7388
|
-
}
|
|
7389
|
-
/**
|
|
7390
|
-
* Build update epoch locks instruction
|
|
7391
|
-
*/
|
|
7392
|
-
async getUpdateEpochLocksIx(props) {
|
|
7393
|
-
const { bondType, bondName, voteAccount, payer } = props;
|
|
7394
|
-
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7395
|
-
return this.program.methods.bondUpdate().accountsPartial({ validatorBond, payer }).instruction();
|
|
7396
|
-
}
|
|
7397
7680
|
/**
|
|
7398
7681
|
* Build bond remove instruction
|
|
7399
7682
|
*/
|
|
@@ -7403,17 +7686,55 @@ var JBondClient = class _JBondClient {
|
|
|
7403
7686
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7404
7687
|
return this.program.methods.bondRemove().accountsPartial({ bondState, authority }).instruction();
|
|
7405
7688
|
}
|
|
7689
|
+
/**
|
|
7690
|
+
* Build close validator bond instruction
|
|
7691
|
+
*/
|
|
7692
|
+
async getCloseValidatorBondIx(props) {
|
|
7693
|
+
const { bondType, name, voteAccount } = props;
|
|
7694
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7695
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7696
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7697
|
+
const rentReceiver = props.rentReceiver ?? authority;
|
|
7698
|
+
if (!authority || !rentReceiver) {
|
|
7699
|
+
throw new Error("Missing authority or rentReceiver");
|
|
7700
|
+
}
|
|
7701
|
+
let collateralType = props.collateralType;
|
|
7702
|
+
if (!collateralType) {
|
|
7703
|
+
const state = await this.getBondState(bondType, name);
|
|
7704
|
+
collateralType = state.collateralType;
|
|
7705
|
+
}
|
|
7706
|
+
const accounts = {
|
|
7707
|
+
bondState,
|
|
7708
|
+
validatorBond,
|
|
7709
|
+
authority,
|
|
7710
|
+
rentReceiver,
|
|
7711
|
+
bondTokenAccount: null,
|
|
7712
|
+
destinationTokenAccount: null
|
|
7713
|
+
};
|
|
7714
|
+
matchVariant(collateralType, {
|
|
7715
|
+
native: () => {
|
|
7716
|
+
},
|
|
7717
|
+
token: (mint) => {
|
|
7718
|
+
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7719
|
+
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, rentReceiver, true);
|
|
7720
|
+
}
|
|
7721
|
+
});
|
|
7722
|
+
return this.program.methods.closeValidatorBond().accountsPartial(accounts).instruction();
|
|
7723
|
+
}
|
|
7406
7724
|
/**
|
|
7407
7725
|
* Build test set last update epoch instruction
|
|
7408
7726
|
* NOTE!: This instruction is for testing purposes only.
|
|
7409
7727
|
* It allows direct manipulation of the validator bond's last epoch update.
|
|
7410
7728
|
* This should not be used in production environments.
|
|
7411
7729
|
*/
|
|
7412
|
-
async getTestSetLastUpdateEpochIx(props) {
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7730
|
+
// async getTestSetLastUpdateEpochIx(props: { bondType: BondType, bondName: string, voteAccount: PublicKeyInitData, payer: PublicKey, epoch: number }) {
|
|
7731
|
+
// const { bondType, bondName, voteAccount, payer, epoch } = props
|
|
7732
|
+
// const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount)
|
|
7733
|
+
// return this.program.methods
|
|
7734
|
+
// .testSetLastUpdateEpoch(new BN(epoch))
|
|
7735
|
+
// .accountsPartial({ validatorBond, payer })
|
|
7736
|
+
// .instruction()
|
|
7737
|
+
// }
|
|
7417
7738
|
/**
|
|
7418
7739
|
* Build lock funds instruction
|
|
7419
7740
|
*/
|
|
@@ -7466,20 +7787,32 @@ var JBondClient = class _JBondClient {
|
|
|
7466
7787
|
/**
|
|
7467
7788
|
* Get all bond states with total collected collateral
|
|
7468
7789
|
*/
|
|
7469
|
-
async getAllBondStates(bondType, sessionStatus) {
|
|
7470
|
-
const
|
|
7790
|
+
async getAllBondStates(bondType, sessionStatus, options) {
|
|
7791
|
+
const includeStats = options?.includeStats ?? true;
|
|
7792
|
+
const targetBondType = bondTypeToAnchor(bondType);
|
|
7471
7793
|
const accounts = await this.program.account.bondState.all();
|
|
7472
|
-
|
|
7473
|
-
if (!sameVariant(account.bondType,
|
|
7474
|
-
|
|
7794
|
+
const filteredAccounts = accounts.filter(({ account }) => {
|
|
7795
|
+
if (!sameVariant(account.bondType, targetBondType)) {
|
|
7796
|
+
return false;
|
|
7475
7797
|
}
|
|
7476
7798
|
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
|
|
7477
|
-
|
|
7799
|
+
return false;
|
|
7478
7800
|
}
|
|
7479
|
-
|
|
7480
|
-
|
|
7801
|
+
return true;
|
|
7802
|
+
});
|
|
7803
|
+
if (!includeStats) {
|
|
7804
|
+
return filteredAccounts.map(({ publicKey, account }) => ({
|
|
7805
|
+
publicKey,
|
|
7806
|
+
bondState: account,
|
|
7807
|
+
stateStats: null
|
|
7808
|
+
}));
|
|
7481
7809
|
}
|
|
7482
|
-
return
|
|
7810
|
+
return Promise.all(
|
|
7811
|
+
filteredAccounts.map(async ({ publicKey, account }) => {
|
|
7812
|
+
const stateStats = await this.getBondStateStats(account);
|
|
7813
|
+
return { publicKey, bondState: account, stateStats };
|
|
7814
|
+
})
|
|
7815
|
+
);
|
|
7483
7816
|
}
|
|
7484
7817
|
/**
|
|
7485
7818
|
* Fetch global state or throw if not found
|
|
@@ -7500,13 +7833,26 @@ var JBondClient = class _JBondClient {
|
|
|
7500
7833
|
return { publicKey, ...data };
|
|
7501
7834
|
}
|
|
7502
7835
|
/**
|
|
7503
|
-
* Fetch validator bond data or
|
|
7836
|
+
* Fetch validator bond data or error if not found
|
|
7504
7837
|
*/
|
|
7505
7838
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7506
7839
|
const [publicKey] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7840
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7507
7841
|
const data = await this.program.account.validatorBond.fetch(publicKey);
|
|
7508
7842
|
return { publicKey, ...data };
|
|
7509
7843
|
}
|
|
7844
|
+
/**
|
|
7845
|
+
* Fetch validator bond data or null if not found
|
|
7846
|
+
*/
|
|
7847
|
+
async getValidatorBondNullable(bondType, bondName, vote) {
|
|
7848
|
+
const [publicKey] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7849
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7850
|
+
const data = await this.program.account.validatorBond.fetchNullable(publicKey);
|
|
7851
|
+
if (!data) {
|
|
7852
|
+
return null;
|
|
7853
|
+
}
|
|
7854
|
+
return { publicKey, ...data };
|
|
7855
|
+
}
|
|
7510
7856
|
/**
|
|
7511
7857
|
* Get validator bond account balance (in SOL)
|
|
7512
7858
|
*/
|
|
@@ -7528,16 +7874,16 @@ var JBondClient = class _JBondClient {
|
|
|
7528
7874
|
const tokenAccount = splToken.getAssociatedTokenAddressSync(mint, address, true);
|
|
7529
7875
|
try {
|
|
7530
7876
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
7531
|
-
return
|
|
7877
|
+
return Number(balance.value.amount);
|
|
7532
7878
|
} catch {
|
|
7533
7879
|
return 0;
|
|
7534
7880
|
}
|
|
7535
7881
|
}
|
|
7536
7882
|
});
|
|
7537
7883
|
}
|
|
7538
|
-
async getBondStateValidatorBondBalances(bondType, bondName) {
|
|
7539
|
-
const
|
|
7540
|
-
const collateralType =
|
|
7884
|
+
async getBondStateValidatorBondBalances(bondType, bondName, bondState) {
|
|
7885
|
+
const state = bondState ?? await this.getBondState(bondType, bondName);
|
|
7886
|
+
const collateralType = state.collateralType;
|
|
7541
7887
|
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7542
7888
|
if (!validatorBonds.length) {
|
|
7543
7889
|
return [];
|
|
@@ -7594,20 +7940,20 @@ var JBondClient = class _JBondClient {
|
|
|
7594
7940
|
/**
|
|
7595
7941
|
* Get total collected collateral for a bond state
|
|
7596
7942
|
*/
|
|
7597
|
-
async getBondStateTotalCollected(bondType, bondName) {
|
|
7598
|
-
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName);
|
|
7943
|
+
async getBondStateTotalCollected(bondType, bondName, bondState) {
|
|
7944
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName, bondState);
|
|
7599
7945
|
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7600
7946
|
}
|
|
7601
7947
|
/**
|
|
7602
7948
|
* Get bond state stats
|
|
7603
7949
|
* @param state
|
|
7604
|
-
* @private
|
|
7605
7950
|
*/
|
|
7606
7951
|
async getBondStateStats(state) {
|
|
7607
7952
|
const bondType = anchorToBondType(state.bondType);
|
|
7608
7953
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
7609
7954
|
bondType,
|
|
7610
|
-
state.name
|
|
7955
|
+
state.name,
|
|
7956
|
+
state
|
|
7611
7957
|
);
|
|
7612
7958
|
return {
|
|
7613
7959
|
totalCollected,
|
|
@@ -7674,9 +8020,12 @@ exports.ENV_PROGRAM_ID = ENV_PROGRAM_ID;
|
|
|
7674
8020
|
exports.GLOBAL_STATE_SEED = GLOBAL_STATE_SEED;
|
|
7675
8021
|
exports.JBondClient = JBondClient;
|
|
7676
8022
|
exports.JBondClientEnv = JBondClientEnv;
|
|
8023
|
+
exports.JPOOL_POOL_ADDRESS = JPOOL_POOL_ADDRESS;
|
|
8024
|
+
exports.JSOL_MINT = JSOL_MINT;
|
|
7677
8025
|
exports.NodeWallet = NodeWallet;
|
|
7678
8026
|
exports.STANDARD_BOND_SEED = STANDARD_BOND_SEED;
|
|
7679
8027
|
exports.SessionStatus = SessionStatus;
|
|
7680
8028
|
exports.VALIDATOR_BOND_SEED = VALIDATOR_BOND_SEED;
|
|
8029
|
+
exports.lamportsToSol = lamportsToSol;
|
|
7681
8030
|
//# sourceMappingURL=index.js.map
|
|
7682
8031
|
//# sourceMappingURL=index.js.map
|