@jpool/bond-sdk 0.1.0-next.4 → 0.2.0
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 +12 -30
- package/dist/index.d.ts +12 -30
- package/dist/index.js +46 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ import { PublicKey, Connection, Keypair, TransactionInstruction } from '@solana/
|
|
|
3
3
|
|
|
4
4
|
type Config = {
|
|
5
5
|
rpcUrl: string;
|
|
6
|
+
programId: PublicKey;
|
|
7
|
+
reserveAddress: PublicKey;
|
|
6
8
|
};
|
|
7
9
|
type ValidatorBondAccount = {
|
|
8
10
|
identity: PublicKey;
|
|
@@ -16,7 +18,6 @@ type ValidatorBondAccount = {
|
|
|
16
18
|
};
|
|
17
19
|
type InitializeProps = {
|
|
18
20
|
authority: PublicKey;
|
|
19
|
-
reserveAddress: PublicKey;
|
|
20
21
|
};
|
|
21
22
|
type RegisterValidatorProps = {
|
|
22
23
|
creator: PublicKey;
|
|
@@ -859,37 +860,20 @@ type Jbond = {
|
|
|
859
860
|
];
|
|
860
861
|
};
|
|
861
862
|
|
|
862
|
-
declare enum BondClientEnv {
|
|
863
|
-
DEV = "dev",
|
|
864
|
-
PROD = "prod"
|
|
865
|
-
}
|
|
866
863
|
declare class JBondClient {
|
|
867
864
|
connection: Connection;
|
|
868
865
|
program: Program<Jbond>;
|
|
869
866
|
provider: AnchorProvider;
|
|
870
867
|
config: Config;
|
|
871
|
-
|
|
872
|
-
constructor(config: Config, wallet?: Wallet, options?: ClientOptions);
|
|
868
|
+
constructor(config: Config, wallet?: Wallet);
|
|
873
869
|
/**
|
|
874
870
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
875
871
|
*/
|
|
876
|
-
static fromWallet(config: Config, wallet?: Wallet
|
|
872
|
+
static fromWallet(config: Config, wallet?: Wallet): JBondClient;
|
|
877
873
|
/**
|
|
878
874
|
* Creates an instance of `JBondClient` using the provided connection and keypair.
|
|
879
875
|
*/
|
|
880
|
-
static fromKeypair(config: Config, keypair: Keypair
|
|
881
|
-
/**
|
|
882
|
-
* Get the current program ID.
|
|
883
|
-
*/
|
|
884
|
-
get programId(): PublicKey;
|
|
885
|
-
/**
|
|
886
|
-
* Set the environment.
|
|
887
|
-
*/
|
|
888
|
-
env(env: BondClientEnv): this;
|
|
889
|
-
/**
|
|
890
|
-
* Configure a specific option.
|
|
891
|
-
*/
|
|
892
|
-
configure<K extends keyof ClientOptions>(key: K, val: ClientOptions[K]): this;
|
|
876
|
+
static fromKeypair(config: Config, keypair: Keypair): JBondClient;
|
|
893
877
|
getGlobalStatePDA(): [PublicKey, number];
|
|
894
878
|
getValidatorBondPDA(voteAccount: PublicKey): [PublicKey, number];
|
|
895
879
|
buildInitializeInstruction(props: InitializeProps): Promise<TransactionInstruction>;
|
|
@@ -916,10 +900,9 @@ declare class JBondClient {
|
|
|
916
900
|
authority: string;
|
|
917
901
|
totalValidators: number;
|
|
918
902
|
totalWithdrawn: number;
|
|
919
|
-
reserveAddress: string;
|
|
920
903
|
} | null>;
|
|
921
904
|
getCurrentEpoch(): Promise<number>;
|
|
922
|
-
initialize(
|
|
905
|
+
initialize(authority?: PublicKey): Promise<string>;
|
|
923
906
|
registerValidator(voteAccount: PublicKey, initialCollateral: number, withdrawalAuthority?: PublicKey, identity?: PublicKey): Promise<string>;
|
|
924
907
|
topUpCollateral(voteAccount: PublicKey, amount: number, validator?: PublicKey): Promise<string>;
|
|
925
908
|
withdrawCollateral(voteAccount: PublicKey, destination: PublicKey, amount: number, withdrawalAuthority?: PublicKey): Promise<string>;
|
|
@@ -940,12 +923,11 @@ declare class JBondClient {
|
|
|
940
923
|
getFullHistory(voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
|
|
941
924
|
private getInstructionDiscriminator;
|
|
942
925
|
}
|
|
943
|
-
type ClientOptions = {
|
|
944
|
-
programId?: PublicKey;
|
|
945
|
-
debug?: boolean;
|
|
946
|
-
} & Record<string, any>;
|
|
947
926
|
|
|
948
|
-
declare const PROGRAM_ID
|
|
949
|
-
declare const
|
|
927
|
+
declare const PROGRAM_ID = "8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr";
|
|
928
|
+
declare const RESERVE_ADDRESS = "61mS9nEir6jx6cvte6NzQpyrFk3Fj4krMNLuHhi4tjJz";
|
|
929
|
+
|
|
930
|
+
declare function loadConfig(): Config;
|
|
931
|
+
declare function loadKeypair(keypairPath: string): Keypair;
|
|
950
932
|
|
|
951
|
-
export {
|
|
933
|
+
export { BondTransactionType, type Config, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, RESERVE_ADDRESS, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps, loadConfig, loadKeypair };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { PublicKey, Connection, Keypair, TransactionInstruction } from '@solana/
|
|
|
3
3
|
|
|
4
4
|
type Config = {
|
|
5
5
|
rpcUrl: string;
|
|
6
|
+
programId: PublicKey;
|
|
7
|
+
reserveAddress: PublicKey;
|
|
6
8
|
};
|
|
7
9
|
type ValidatorBondAccount = {
|
|
8
10
|
identity: PublicKey;
|
|
@@ -16,7 +18,6 @@ type ValidatorBondAccount = {
|
|
|
16
18
|
};
|
|
17
19
|
type InitializeProps = {
|
|
18
20
|
authority: PublicKey;
|
|
19
|
-
reserveAddress: PublicKey;
|
|
20
21
|
};
|
|
21
22
|
type RegisterValidatorProps = {
|
|
22
23
|
creator: PublicKey;
|
|
@@ -859,37 +860,20 @@ type Jbond = {
|
|
|
859
860
|
];
|
|
860
861
|
};
|
|
861
862
|
|
|
862
|
-
declare enum BondClientEnv {
|
|
863
|
-
DEV = "dev",
|
|
864
|
-
PROD = "prod"
|
|
865
|
-
}
|
|
866
863
|
declare class JBondClient {
|
|
867
864
|
connection: Connection;
|
|
868
865
|
program: Program<Jbond>;
|
|
869
866
|
provider: AnchorProvider;
|
|
870
867
|
config: Config;
|
|
871
|
-
|
|
872
|
-
constructor(config: Config, wallet?: Wallet, options?: ClientOptions);
|
|
868
|
+
constructor(config: Config, wallet?: Wallet);
|
|
873
869
|
/**
|
|
874
870
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
875
871
|
*/
|
|
876
|
-
static fromWallet(config: Config, wallet?: Wallet
|
|
872
|
+
static fromWallet(config: Config, wallet?: Wallet): JBondClient;
|
|
877
873
|
/**
|
|
878
874
|
* Creates an instance of `JBondClient` using the provided connection and keypair.
|
|
879
875
|
*/
|
|
880
|
-
static fromKeypair(config: Config, keypair: Keypair
|
|
881
|
-
/**
|
|
882
|
-
* Get the current program ID.
|
|
883
|
-
*/
|
|
884
|
-
get programId(): PublicKey;
|
|
885
|
-
/**
|
|
886
|
-
* Set the environment.
|
|
887
|
-
*/
|
|
888
|
-
env(env: BondClientEnv): this;
|
|
889
|
-
/**
|
|
890
|
-
* Configure a specific option.
|
|
891
|
-
*/
|
|
892
|
-
configure<K extends keyof ClientOptions>(key: K, val: ClientOptions[K]): this;
|
|
876
|
+
static fromKeypair(config: Config, keypair: Keypair): JBondClient;
|
|
893
877
|
getGlobalStatePDA(): [PublicKey, number];
|
|
894
878
|
getValidatorBondPDA(voteAccount: PublicKey): [PublicKey, number];
|
|
895
879
|
buildInitializeInstruction(props: InitializeProps): Promise<TransactionInstruction>;
|
|
@@ -916,10 +900,9 @@ declare class JBondClient {
|
|
|
916
900
|
authority: string;
|
|
917
901
|
totalValidators: number;
|
|
918
902
|
totalWithdrawn: number;
|
|
919
|
-
reserveAddress: string;
|
|
920
903
|
} | null>;
|
|
921
904
|
getCurrentEpoch(): Promise<number>;
|
|
922
|
-
initialize(
|
|
905
|
+
initialize(authority?: PublicKey): Promise<string>;
|
|
923
906
|
registerValidator(voteAccount: PublicKey, initialCollateral: number, withdrawalAuthority?: PublicKey, identity?: PublicKey): Promise<string>;
|
|
924
907
|
topUpCollateral(voteAccount: PublicKey, amount: number, validator?: PublicKey): Promise<string>;
|
|
925
908
|
withdrawCollateral(voteAccount: PublicKey, destination: PublicKey, amount: number, withdrawalAuthority?: PublicKey): Promise<string>;
|
|
@@ -940,12 +923,11 @@ declare class JBondClient {
|
|
|
940
923
|
getFullHistory(voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
|
|
941
924
|
private getInstructionDiscriminator;
|
|
942
925
|
}
|
|
943
|
-
type ClientOptions = {
|
|
944
|
-
programId?: PublicKey;
|
|
945
|
-
debug?: boolean;
|
|
946
|
-
} & Record<string, any>;
|
|
947
926
|
|
|
948
|
-
declare const PROGRAM_ID
|
|
949
|
-
declare const
|
|
927
|
+
declare const PROGRAM_ID = "8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr";
|
|
928
|
+
declare const RESERVE_ADDRESS = "61mS9nEir6jx6cvte6NzQpyrFk3Fj4krMNLuHhi4tjJz";
|
|
929
|
+
|
|
930
|
+
declare function loadConfig(): Config;
|
|
931
|
+
declare function loadKeypair(keypairPath: string): Keypair;
|
|
950
932
|
|
|
951
|
-
export {
|
|
933
|
+
export { BondTransactionType, type Config, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, RESERVE_ADDRESS, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps, loadConfig, loadKeypair };
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
var anchor = require('@coral-xyz/anchor');
|
|
4
4
|
var web3_js = require('@solana/web3.js');
|
|
5
5
|
var bs58 = require('bs58');
|
|
6
|
+
var fs = require('fs');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
9
10
|
var bs58__default = /*#__PURE__*/_interopDefault(bs58);
|
|
10
11
|
|
|
11
12
|
// src/client.ts
|
|
12
|
-
var PROGRAM_ID = new web3_js.PublicKey("8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr");
|
|
13
|
-
var DEV_PROGRAM_ID = new web3_js.PublicKey("8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr");
|
|
14
13
|
|
|
15
14
|
// src/helpers.ts
|
|
16
15
|
var SLOTS_PER_EPOCH_MAINNET = 432e3;
|
|
@@ -832,21 +831,14 @@ var NodeWallet = class {
|
|
|
832
831
|
};
|
|
833
832
|
|
|
834
833
|
// src/client.ts
|
|
835
|
-
var BondClientEnv = /* @__PURE__ */ ((BondClientEnv2) => {
|
|
836
|
-
BondClientEnv2["DEV"] = "dev";
|
|
837
|
-
BondClientEnv2["PROD"] = "prod";
|
|
838
|
-
return BondClientEnv2;
|
|
839
|
-
})(BondClientEnv || {});
|
|
840
834
|
var JBondClient = class _JBondClient {
|
|
841
835
|
connection;
|
|
842
836
|
program;
|
|
843
837
|
provider;
|
|
844
838
|
config;
|
|
845
|
-
|
|
846
|
-
constructor(config, wallet, options) {
|
|
839
|
+
constructor(config, wallet) {
|
|
847
840
|
this.config = config;
|
|
848
841
|
this.connection = new web3_js.Connection(config.rpcUrl, "confirmed");
|
|
849
|
-
this.options = options ?? {};
|
|
850
842
|
this.provider = new anchor.AnchorProvider(
|
|
851
843
|
this.connection,
|
|
852
844
|
// @ts-expect-error support anonymous
|
|
@@ -858,42 +850,20 @@ var JBondClient = class _JBondClient {
|
|
|
858
850
|
/**
|
|
859
851
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
860
852
|
*/
|
|
861
|
-
static fromWallet(config, wallet
|
|
862
|
-
return new this(config, wallet
|
|
853
|
+
static fromWallet(config, wallet) {
|
|
854
|
+
return new this(config, wallet);
|
|
863
855
|
}
|
|
864
856
|
/**
|
|
865
857
|
* Creates an instance of `JBondClient` using the provided connection and keypair.
|
|
866
858
|
*/
|
|
867
|
-
static fromKeypair(config, keypair
|
|
868
|
-
return _JBondClient.fromWallet(config, new NodeWallet(keypair)
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* Get the current program ID.
|
|
872
|
-
*/
|
|
873
|
-
get programId() {
|
|
874
|
-
return this.options.programId ?? PROGRAM_ID;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Set the environment.
|
|
878
|
-
*/
|
|
879
|
-
env(env) {
|
|
880
|
-
if (env === "prod" /* PROD */) {
|
|
881
|
-
return this.configure("programId", PROGRAM_ID);
|
|
882
|
-
}
|
|
883
|
-
return this.configure("programId", DEV_PROGRAM_ID);
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Configure a specific option.
|
|
887
|
-
*/
|
|
888
|
-
configure(key, val) {
|
|
889
|
-
this.options[key] = val;
|
|
890
|
-
return this;
|
|
859
|
+
static fromKeypair(config, keypair) {
|
|
860
|
+
return _JBondClient.fromWallet(config, new NodeWallet(keypair));
|
|
891
861
|
}
|
|
892
862
|
// Get PDA for global state
|
|
893
863
|
getGlobalStatePDA() {
|
|
894
864
|
return web3_js.PublicKey.findProgramAddressSync(
|
|
895
865
|
[Buffer.from("global_state")],
|
|
896
|
-
this.
|
|
866
|
+
this.program.programId
|
|
897
867
|
);
|
|
898
868
|
}
|
|
899
869
|
// Get PDA for validator bond account
|
|
@@ -903,17 +873,16 @@ var JBondClient = class _JBondClient {
|
|
|
903
873
|
Buffer.from("validator_bond"),
|
|
904
874
|
voteAccount.toBuffer()
|
|
905
875
|
],
|
|
906
|
-
this.
|
|
876
|
+
this.program.programId
|
|
907
877
|
);
|
|
908
878
|
}
|
|
909
879
|
// Build initialize instruction
|
|
910
880
|
async buildInitializeInstruction(props) {
|
|
911
881
|
const [globalState] = this.getGlobalStatePDA();
|
|
912
|
-
const { authority, reserveAddress } = props;
|
|
913
882
|
return this.program.methods.initialize().accountsStrict({
|
|
914
883
|
globalState,
|
|
915
|
-
authority,
|
|
916
|
-
reserve: reserveAddress,
|
|
884
|
+
authority: props.authority,
|
|
885
|
+
reserve: this.config.reserveAddress,
|
|
917
886
|
systemProgram: web3_js.SystemProgram.programId
|
|
918
887
|
}).instruction();
|
|
919
888
|
}
|
|
@@ -960,19 +929,15 @@ var JBondClient = class _JBondClient {
|
|
|
960
929
|
}).instruction();
|
|
961
930
|
}
|
|
962
931
|
// Build withdraw compensation instruction
|
|
963
|
-
|
|
932
|
+
buildWithdrawCompensationInstruction(props) {
|
|
964
933
|
const { authority, voteAccount, amount } = props;
|
|
965
934
|
const [globalState] = this.getGlobalStatePDA();
|
|
966
935
|
const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
|
|
967
936
|
const amountLamports = new anchor.BN(amount * web3_js.LAMPORTS_PER_SOL);
|
|
968
|
-
const reserveAddress = (await this.getGlobalState())?.reserveAddress;
|
|
969
|
-
if (!reserveAddress) {
|
|
970
|
-
throw new Error("Reserve address is not set in the global state. The program might not be initialized yet.");
|
|
971
|
-
}
|
|
972
937
|
return this.program.methods.withdrawCompensation(amountLamports).accountsStrict({
|
|
973
938
|
globalState,
|
|
974
939
|
validatorBondAccount: validatorBondAccountAddress,
|
|
975
|
-
reserve: reserveAddress,
|
|
940
|
+
reserve: this.config.reserveAddress,
|
|
976
941
|
authority,
|
|
977
942
|
systemProgram: web3_js.SystemProgram.programId
|
|
978
943
|
}).instruction();
|
|
@@ -1039,8 +1004,7 @@ var JBondClient = class _JBondClient {
|
|
|
1039
1004
|
return {
|
|
1040
1005
|
authority: account.authority.toString(),
|
|
1041
1006
|
totalValidators: account.totalValidators,
|
|
1042
|
-
totalWithdrawn: account.totalWithdrawn.toNumber() / web3_js.LAMPORTS_PER_SOL
|
|
1043
|
-
reserveAddress: account.reserve.toString()
|
|
1007
|
+
totalWithdrawn: account.totalWithdrawn.toNumber() / web3_js.LAMPORTS_PER_SOL
|
|
1044
1008
|
};
|
|
1045
1009
|
} catch {
|
|
1046
1010
|
return null;
|
|
@@ -1052,9 +1016,9 @@ var JBondClient = class _JBondClient {
|
|
|
1052
1016
|
return epochInfo.epoch;
|
|
1053
1017
|
}
|
|
1054
1018
|
// Helper methods for backward compatibility (can be removed if not needed)
|
|
1055
|
-
async initialize(
|
|
1019
|
+
async initialize(authority) {
|
|
1056
1020
|
const authorityPubkey = authority || this.provider.wallet.publicKey;
|
|
1057
|
-
const ix = await this.buildInitializeInstruction({ authority: authorityPubkey
|
|
1021
|
+
const ix = await this.buildInitializeInstruction({ authority: authorityPubkey });
|
|
1058
1022
|
const tx = await this.provider.sendAndConfirm(
|
|
1059
1023
|
new web3_js.Transaction().add(ix),
|
|
1060
1024
|
[]
|
|
@@ -1179,7 +1143,7 @@ var JBondClient = class _JBondClient {
|
|
|
1179
1143
|
const slot = tx.slot || 0;
|
|
1180
1144
|
const instructions = tx.transaction.message.instructions;
|
|
1181
1145
|
for (const instruction of instructions) {
|
|
1182
|
-
if ("programId" in instruction && instruction.programId.equals(this.
|
|
1146
|
+
if ("programId" in instruction && instruction.programId.equals(this.program.programId)) {
|
|
1183
1147
|
const ixData = instruction;
|
|
1184
1148
|
if ("parsed" in ixData && ixData.parsed) {
|
|
1185
1149
|
continue;
|
|
@@ -1274,10 +1238,38 @@ var JBondClient = class _JBondClient {
|
|
|
1274
1238
|
}
|
|
1275
1239
|
};
|
|
1276
1240
|
|
|
1277
|
-
|
|
1241
|
+
// src/common.ts
|
|
1242
|
+
var PROGRAM_ID = "8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr";
|
|
1243
|
+
var RESERVE_ADDRESS = "61mS9nEir6jx6cvte6NzQpyrFk3Fj4krMNLuHhi4tjJz";
|
|
1244
|
+
function loadConfig() {
|
|
1245
|
+
const rpcUrl = process.env.SOLANA_RPC_URL || "https://api.devnet.solana.com";
|
|
1246
|
+
const programId = new web3_js.PublicKey(
|
|
1247
|
+
PROGRAM_ID
|
|
1248
|
+
);
|
|
1249
|
+
const reserveAddress = new web3_js.PublicKey(
|
|
1250
|
+
RESERVE_ADDRESS
|
|
1251
|
+
);
|
|
1252
|
+
return {
|
|
1253
|
+
rpcUrl,
|
|
1254
|
+
programId,
|
|
1255
|
+
reserveAddress
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
function loadKeypair(keypairPath) {
|
|
1259
|
+
try {
|
|
1260
|
+
const keypairString = fs.readFileSync(keypairPath, "utf8");
|
|
1261
|
+
const keypairData = JSON.parse(keypairString);
|
|
1262
|
+
return web3_js.Keypair.fromSecretKey(new Uint8Array(keypairData));
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
throw new Error(`Failed to load keypair from ${keypairPath}: ${error}`);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1278
1268
|
exports.BondTransactionType = BondTransactionType;
|
|
1279
|
-
exports.DEV_PROGRAM_ID = DEV_PROGRAM_ID;
|
|
1280
1269
|
exports.JBondClient = JBondClient;
|
|
1281
1270
|
exports.PROGRAM_ID = PROGRAM_ID;
|
|
1271
|
+
exports.RESERVE_ADDRESS = RESERVE_ADDRESS;
|
|
1272
|
+
exports.loadConfig = loadConfig;
|
|
1273
|
+
exports.loadKeypair = loadKeypair;
|
|
1282
1274
|
//# sourceMappingURL=index.js.map
|
|
1283
1275
|
//# sourceMappingURL=index.js.map
|