@jpool/bond-sdk 0.9.0-next.24 → 0.9.0-next.25
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 +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +182 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1728,8 +1728,6 @@ type TransactionHistoryItem = {
|
|
|
1728
1728
|
epoch: number;
|
|
1729
1729
|
type: BondTransactionType;
|
|
1730
1730
|
amount: number;
|
|
1731
|
-
beforeBalance?: number;
|
|
1732
|
-
afterBalance?: number;
|
|
1733
1731
|
};
|
|
1734
1732
|
declare enum BondTransactionType {
|
|
1735
1733
|
Deposit = "deposit",
|
|
@@ -2024,6 +2022,29 @@ declare class JBondClient {
|
|
|
2024
2022
|
* Get total collected collateral for a bond state
|
|
2025
2023
|
*/
|
|
2026
2024
|
getBondStateTotalCollected(bondType: BondType, bondName: string, votes: PublicKeyInitData[]): Promise<number>;
|
|
2025
|
+
/**
|
|
2026
|
+
* Get transaction history for a specific validator bond account
|
|
2027
|
+
*/
|
|
2028
|
+
getHistory(bondType: BondType, bondName: string, vote: PublicKey, options?: {
|
|
2029
|
+
cluster?: 'mainnet-beta' | 'testnet' | 'devnet';
|
|
2030
|
+
limit?: number;
|
|
2031
|
+
before?: string;
|
|
2032
|
+
until?: string;
|
|
2033
|
+
}): Promise<TransactionHistoryItem[]>;
|
|
2034
|
+
/**
|
|
2035
|
+
* Get full transaction history by paginating through results
|
|
2036
|
+
* @param bondType
|
|
2037
|
+
* @param bondName
|
|
2038
|
+
* @param voteAccount
|
|
2039
|
+
* @param pageSize
|
|
2040
|
+
*/
|
|
2041
|
+
getFullHistory(bondType: BondType, bondName: string, voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
|
|
2042
|
+
/**
|
|
2043
|
+
* Get instruction discriminator from IDL
|
|
2044
|
+
* @param instructionName
|
|
2045
|
+
* @private
|
|
2046
|
+
*/
|
|
2047
|
+
private getInstructionDiscriminator;
|
|
2027
2048
|
/**
|
|
2028
2049
|
* Get bond state stats
|
|
2029
2050
|
* @param state
|
package/dist/index.d.ts
CHANGED
|
@@ -1728,8 +1728,6 @@ type TransactionHistoryItem = {
|
|
|
1728
1728
|
epoch: number;
|
|
1729
1729
|
type: BondTransactionType;
|
|
1730
1730
|
amount: number;
|
|
1731
|
-
beforeBalance?: number;
|
|
1732
|
-
afterBalance?: number;
|
|
1733
1731
|
};
|
|
1734
1732
|
declare enum BondTransactionType {
|
|
1735
1733
|
Deposit = "deposit",
|
|
@@ -2024,6 +2022,29 @@ declare class JBondClient {
|
|
|
2024
2022
|
* Get total collected collateral for a bond state
|
|
2025
2023
|
*/
|
|
2026
2024
|
getBondStateTotalCollected(bondType: BondType, bondName: string, votes: PublicKeyInitData[]): Promise<number>;
|
|
2025
|
+
/**
|
|
2026
|
+
* Get transaction history for a specific validator bond account
|
|
2027
|
+
*/
|
|
2028
|
+
getHistory(bondType: BondType, bondName: string, vote: PublicKey, options?: {
|
|
2029
|
+
cluster?: 'mainnet-beta' | 'testnet' | 'devnet';
|
|
2030
|
+
limit?: number;
|
|
2031
|
+
before?: string;
|
|
2032
|
+
until?: string;
|
|
2033
|
+
}): Promise<TransactionHistoryItem[]>;
|
|
2034
|
+
/**
|
|
2035
|
+
* Get full transaction history by paginating through results
|
|
2036
|
+
* @param bondType
|
|
2037
|
+
* @param bondName
|
|
2038
|
+
* @param voteAccount
|
|
2039
|
+
* @param pageSize
|
|
2040
|
+
*/
|
|
2041
|
+
getFullHistory(bondType: BondType, bondName: string, voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
|
|
2042
|
+
/**
|
|
2043
|
+
* Get instruction discriminator from IDL
|
|
2044
|
+
* @param instructionName
|
|
2045
|
+
* @private
|
|
2046
|
+
*/
|
|
2047
|
+
private getInstructionDiscriminator;
|
|
2027
2048
|
/**
|
|
2028
2049
|
* Get bond state stats
|
|
2029
2050
|
* @param state
|
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 bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
4
5
|
var splStakePool = require('@solana/spl-stake-pool');
|
|
5
6
|
var splToken = require('@solana/spl-token');
|
|
6
7
|
var web3_js = require('@solana/web3.js');
|
|
@@ -4751,23 +4752,12 @@ var HistoryManager = class {
|
|
|
4751
4752
|
if (!type || amount <= 0) {
|
|
4752
4753
|
continue;
|
|
4753
4754
|
}
|
|
4754
|
-
let beforeBalance;
|
|
4755
|
-
let afterBalance;
|
|
4756
|
-
const accIdx = tx.transaction.message.accountKeys.findIndex(
|
|
4757
|
-
(k) => k.pubkey.equals(validatorBondAccount)
|
|
4758
|
-
);
|
|
4759
|
-
if (accIdx !== -1 && tx.meta.preBalances && tx.meta.postBalances) {
|
|
4760
|
-
beforeBalance = Number(tx.meta.preBalances[accIdx] ?? 0) / web3_js.LAMPORTS_PER_SOL;
|
|
4761
|
-
afterBalance = Number(tx.meta.postBalances[accIdx] ?? 0) / web3_js.LAMPORTS_PER_SOL;
|
|
4762
|
-
}
|
|
4763
4755
|
history.push({
|
|
4764
4756
|
signature: sig,
|
|
4765
4757
|
slot,
|
|
4766
4758
|
epoch: slotToEpoch(slot, cluster),
|
|
4767
4759
|
type,
|
|
4768
|
-
amount
|
|
4769
|
-
beforeBalance,
|
|
4770
|
-
afterBalance
|
|
4760
|
+
amount
|
|
4771
4761
|
});
|
|
4772
4762
|
}
|
|
4773
4763
|
}
|
|
@@ -7105,6 +7095,186 @@ var JBondClient = class _JBondClient {
|
|
|
7105
7095
|
}
|
|
7106
7096
|
});
|
|
7107
7097
|
}
|
|
7098
|
+
/**
|
|
7099
|
+
* Get transaction history for a specific validator bond account
|
|
7100
|
+
*/
|
|
7101
|
+
async getHistory(bondType, bondName, vote, options) {
|
|
7102
|
+
const [legacyValidatorBondAccount] = web3_js.PublicKey.findProgramAddressSync(
|
|
7103
|
+
[
|
|
7104
|
+
Buffer.from("validator_bond" /* ValidatorBond */),
|
|
7105
|
+
new web3_js.PublicKey(vote).toBuffer()
|
|
7106
|
+
],
|
|
7107
|
+
this.programId
|
|
7108
|
+
);
|
|
7109
|
+
const validatorBond = this.pda.validatorBond(bondType, bondName, vote);
|
|
7110
|
+
console.log("Derived legacy validator bond account:", legacyValidatorBondAccount.toBase58());
|
|
7111
|
+
console.log("Derived new validator bond account:", validatorBond[0].toBase58());
|
|
7112
|
+
console.log("Fetching history for legacy validator bond account:", legacyValidatorBondAccount.toBase58());
|
|
7113
|
+
console.log("Fetching history for new validator bond account:", validatorBond[0].toBase58());
|
|
7114
|
+
const legacySignatures = (await this.connection.getSignaturesForAddress(
|
|
7115
|
+
legacyValidatorBondAccount,
|
|
7116
|
+
{
|
|
7117
|
+
limit: options?.limit || 1e3,
|
|
7118
|
+
before: options?.before,
|
|
7119
|
+
until: options?.until
|
|
7120
|
+
},
|
|
7121
|
+
"confirmed"
|
|
7122
|
+
)).filter((sig) => !sig.err);
|
|
7123
|
+
const newSignatures = (await this.connection.getSignaturesForAddress(
|
|
7124
|
+
validatorBond[0],
|
|
7125
|
+
{
|
|
7126
|
+
limit: options?.limit || 1e3,
|
|
7127
|
+
before: options?.before,
|
|
7128
|
+
until: options?.until
|
|
7129
|
+
},
|
|
7130
|
+
"confirmed"
|
|
7131
|
+
)).filter((sig) => !sig.err);
|
|
7132
|
+
const signatureStrings = legacySignatures.map((sig) => sig.signature);
|
|
7133
|
+
signatureStrings.push(...newSignatures.map((sig) => sig.signature));
|
|
7134
|
+
const signatures = [...legacySignatures, ...newSignatures];
|
|
7135
|
+
const BATCH_SIZE = 100;
|
|
7136
|
+
const allTransactions = [];
|
|
7137
|
+
for (let i = 0; i < signatureStrings.length; i += BATCH_SIZE) {
|
|
7138
|
+
const batch = signatureStrings.slice(i, i + BATCH_SIZE);
|
|
7139
|
+
const transactions = await this.connection.getParsedTransactions(
|
|
7140
|
+
batch,
|
|
7141
|
+
{
|
|
7142
|
+
maxSupportedTransactionVersion: 0,
|
|
7143
|
+
commitment: "confirmed"
|
|
7144
|
+
}
|
|
7145
|
+
);
|
|
7146
|
+
allTransactions.push(...transactions);
|
|
7147
|
+
}
|
|
7148
|
+
const cluster = options?.cluster || "mainnet-beta";
|
|
7149
|
+
const history = [];
|
|
7150
|
+
for (const [idx, tx] of allTransactions.entries()) {
|
|
7151
|
+
const sigInfo = signatures[idx];
|
|
7152
|
+
if (!tx || !tx.meta || tx.meta.err !== null) {
|
|
7153
|
+
continue;
|
|
7154
|
+
}
|
|
7155
|
+
try {
|
|
7156
|
+
const slot = tx.slot || 0;
|
|
7157
|
+
const instructions = tx.transaction.message.instructions;
|
|
7158
|
+
for (const instruction of instructions) {
|
|
7159
|
+
if ("programId" in instruction && instruction.programId.equals(this.options.programId ?? this.program.programId)) {
|
|
7160
|
+
const ixData = instruction;
|
|
7161
|
+
if ("parsed" in ixData && ixData.parsed) {
|
|
7162
|
+
continue;
|
|
7163
|
+
}
|
|
7164
|
+
const data = ixData.data;
|
|
7165
|
+
if (!data) {
|
|
7166
|
+
continue;
|
|
7167
|
+
}
|
|
7168
|
+
let type = null;
|
|
7169
|
+
let amount = 0;
|
|
7170
|
+
try {
|
|
7171
|
+
const dataBuffer = bytes.bs58.decode(data);
|
|
7172
|
+
if (dataBuffer.length >= 8) {
|
|
7173
|
+
const discriminator = dataBuffer.subarray(0, 8);
|
|
7174
|
+
const legacyRegisterDiscriminator = this.getInstructionDiscriminator("register");
|
|
7175
|
+
const legacyTopUpDiscriminator = this.getInstructionDiscriminator("topUp");
|
|
7176
|
+
const legacyClaimDiscriminator = this.getInstructionDiscriminator("claim");
|
|
7177
|
+
const legacyWithdrawDiscriminator = this.getInstructionDiscriminator("withdraw");
|
|
7178
|
+
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
7179
|
+
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
7180
|
+
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
7181
|
+
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
7182
|
+
console.log("Discriminator:", Buffer.from(discriminator).toString("hex"));
|
|
7183
|
+
if (Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
7184
|
+
type = "deposit" /* Deposit */;
|
|
7185
|
+
if (dataBuffer.length >= 16 && Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator))) {
|
|
7186
|
+
const amountBytes = dataBuffer.subarray(8, 16);
|
|
7187
|
+
const amountBN = new import_bn2.BN(amountBytes, "le");
|
|
7188
|
+
amount = amountBN.toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
7189
|
+
} else {
|
|
7190
|
+
amount = 0;
|
|
7191
|
+
}
|
|
7192
|
+
} else if (dataBuffer.length >= 16) {
|
|
7193
|
+
const amountBytes = dataBuffer.subarray(8, 16);
|
|
7194
|
+
const amountBN = new import_bn2.BN(amountBytes, "le");
|
|
7195
|
+
amount = amountBN.toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
7196
|
+
if (Buffer.from(discriminator).equals(Buffer.from(legacyTopUpDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
7197
|
+
type = "deposit" /* Deposit */;
|
|
7198
|
+
} else if (Buffer.from(discriminator).equals(Buffer.from(legacyClaimDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
7199
|
+
type = "compensation" /* Compensation */;
|
|
7200
|
+
} else if (Buffer.from(discriminator).equals(Buffer.from(legacyWithdrawDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
7201
|
+
type = "withdrawal" /* Withdrawal */;
|
|
7202
|
+
}
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
} catch (e) {
|
|
7206
|
+
console.warn("Failed to decode instruction data:", e);
|
|
7207
|
+
}
|
|
7208
|
+
if (type && (amount > 0 || type === "deposit" /* Deposit */)) {
|
|
7209
|
+
history.push({
|
|
7210
|
+
signature: sigInfo.signature,
|
|
7211
|
+
slot,
|
|
7212
|
+
epoch: slotToEpoch(slot, cluster),
|
|
7213
|
+
type,
|
|
7214
|
+
amount
|
|
7215
|
+
});
|
|
7216
|
+
}
|
|
7217
|
+
}
|
|
7218
|
+
}
|
|
7219
|
+
} catch (error) {
|
|
7220
|
+
console.error(`Error processing transaction ${sigInfo.signature}:`, error);
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
return history.toSorted((a, b) => b.slot - a.slot);
|
|
7224
|
+
}
|
|
7225
|
+
/**
|
|
7226
|
+
* Get full transaction history by paginating through results
|
|
7227
|
+
* @param bondType
|
|
7228
|
+
* @param bondName
|
|
7229
|
+
* @param voteAccount
|
|
7230
|
+
* @param pageSize
|
|
7231
|
+
*/
|
|
7232
|
+
async getFullHistory(bondType, bondName, voteAccount, pageSize = 100) {
|
|
7233
|
+
const allHistory = [];
|
|
7234
|
+
let before;
|
|
7235
|
+
while (true) {
|
|
7236
|
+
const batch = await this.getHistory(bondType, bondName, voteAccount, {
|
|
7237
|
+
limit: pageSize,
|
|
7238
|
+
before
|
|
7239
|
+
});
|
|
7240
|
+
if (batch.length === 0) {
|
|
7241
|
+
break;
|
|
7242
|
+
}
|
|
7243
|
+
allHistory.push(...batch);
|
|
7244
|
+
before = batch.at(-1)?.signature;
|
|
7245
|
+
if (batch.length < pageSize) {
|
|
7246
|
+
break;
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
return allHistory;
|
|
7250
|
+
}
|
|
7251
|
+
/**
|
|
7252
|
+
* Get instruction discriminator from IDL
|
|
7253
|
+
* @param instructionName
|
|
7254
|
+
* @private
|
|
7255
|
+
*/
|
|
7256
|
+
getInstructionDiscriminator(instructionName) {
|
|
7257
|
+
const legacyDiscriminators = {
|
|
7258
|
+
register: [211, 124, 67, 15, 211, 194, 178, 240],
|
|
7259
|
+
topUp: [181, 157, 89, 67, 143, 182, 52, 72],
|
|
7260
|
+
claim: [62, 198, 214, 193, 213, 159, 108, 210],
|
|
7261
|
+
withdraw: [183, 18, 70, 156, 148, 109, 161, 34]
|
|
7262
|
+
};
|
|
7263
|
+
if (legacyDiscriminators[instructionName]) {
|
|
7264
|
+
return new Uint8Array(legacyDiscriminators[instructionName]);
|
|
7265
|
+
}
|
|
7266
|
+
if (instructionName.startsWith("bond")) {
|
|
7267
|
+
const instruction = this.program.idl.instructions.find((ix) => ix.name === instructionName);
|
|
7268
|
+
if (!instruction) {
|
|
7269
|
+
throw new Error(`Instruction ${instructionName} not found in IDL`);
|
|
7270
|
+
}
|
|
7271
|
+
if (!instruction.discriminator || !Array.isArray(instruction.discriminator)) {
|
|
7272
|
+
throw new Error(`Discriminator not found for instruction ${instructionName}`);
|
|
7273
|
+
}
|
|
7274
|
+
return new Uint8Array(instruction.discriminator);
|
|
7275
|
+
}
|
|
7276
|
+
throw new Error(`Unknown instruction: ${instructionName}`);
|
|
7277
|
+
}
|
|
7108
7278
|
/**
|
|
7109
7279
|
* Get bond state stats
|
|
7110
7280
|
* @param state
|