Skip to content

Commit 7c6dd0b

Browse files
committed
Clean up
1 parent c69e39a commit 7c6dd0b

File tree

3 files changed

+19
-206
lines changed

3 files changed

+19
-206
lines changed

packages/polygon/src/staker.ts

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export class PolygonStaker {
8282
private readonly rpcUrl?: string
8383
private readonly network: PolygonNetworks
8484
private readonly contracts: NetworkContracts
85-
private publicClient?: PublicClient
86-
private chain!: Chain
85+
private readonly publicClient: PublicClient
86+
private readonly chain: Chain
8787

8888
/**
8989
* This **static** method is used to derive an address from a public key.
@@ -114,22 +114,16 @@ export class PolygonStaker {
114114
this.network = params.network
115115
this.rpcUrl = params.rpcUrl
116116
this.contracts = NETWORK_CONTRACTS[params.network]
117-
}
118-
119-
/**
120-
* Initializes the PolygonStaker instance and connects to the blockchain
121-
*
122-
* @returns A promise which resolves once the PolygonStaker instance has been initialized
123-
*/
124-
async init (): Promise<void> {
125-
this.chain = NETWORK_CHAINS[this.network]
126-
117+
this.chain = NETWORK_CHAINS[params.network]
127118
this.publicClient = createPublicClient({
128119
chain: this.chain,
129120
transport: http(this.rpcUrl)
130121
})
131122
}
132123

124+
/** @deprecated No longer required. Kept for backward compatibility. */
125+
async init (): Promise<void> {}
126+
133127
/**
134128
* Builds a token approval transaction
135129
*
@@ -143,9 +137,6 @@ export class PolygonStaker {
143137
* @returns Returns a promise that resolves to an approval transaction
144138
*/
145139
async buildApproveTx (params: { amount: string; referrer?: Hex }): Promise<{ tx: Transaction }> {
146-
if (!this.publicClient) {
147-
throw new Error('PolygonStaker not initialized, call init() to initialize')
148-
}
149140
const { amount, referrer } = params
150141

151142
const amountWei = amount === 'max' ? maxUint256 : this.parseAmount(amount)
@@ -186,9 +177,6 @@ export class PolygonStaker {
186177
amount: string
187178
referrer?: Hex
188179
}): Promise<{ tx: Transaction }> {
189-
if (!this.publicClient) {
190-
throw new Error('PolygonStaker not initialized, call init() to initialize')
191-
}
192180
const { delegatorAddress, validatorShareAddress, amount, referrer } = params
193181

194182
if (!isAddress(delegatorAddress)) {
@@ -243,9 +231,6 @@ export class PolygonStaker {
243231
amount: string
244232
referrer?: Hex
245233
}): Promise<{ tx: Transaction }> {
246-
if (!this.publicClient) {
247-
throw new Error('PolygonStaker not initialized, call init() to initialize')
248-
}
249234
const { delegatorAddress, validatorShareAddress, amount, referrer } = params
250235

251236
if (!isAddress(delegatorAddress)) {
@@ -300,9 +285,6 @@ export class PolygonStaker {
300285
unbondNonce: bigint
301286
referrer?: Hex
302287
}): Promise<{ tx: Transaction }> {
303-
if (!this.publicClient) {
304-
throw new Error('PolygonStaker not initialized, call init() to initialize')
305-
}
306288
const { delegatorAddress, validatorShareAddress, unbondNonce, referrer } = params
307289

308290
if (!isAddress(delegatorAddress)) {
@@ -357,9 +339,6 @@ export class PolygonStaker {
357339
validatorShareAddress: Address
358340
referrer?: Hex
359341
}): Promise<{ tx: Transaction }> {
360-
if (!this.publicClient) {
361-
throw new Error('PolygonStaker not initialized, call init() to initialize')
362-
}
363342
const { delegatorAddress, validatorShareAddress, referrer } = params
364343

365344
if (!isAddress(delegatorAddress)) {
@@ -406,9 +385,6 @@ export class PolygonStaker {
406385
validatorShareAddress: Address
407386
referrer?: Hex
408387
}): Promise<{ tx: Transaction }> {
409-
if (!this.publicClient) {
410-
throw new Error('PolygonStaker not initialized, call init() to initialize')
411-
}
412388
const { delegatorAddress, validatorShareAddress, referrer } = params
413389

414390
if (!isAddress(delegatorAddress)) {
@@ -452,9 +428,6 @@ export class PolygonStaker {
452428
* - shares: Total shares held by the delegator
453429
*/
454430
async getStake (params: { delegatorAddress: Address; validatorShareAddress: Address }): Promise<StakeInfo> {
455-
if (!this.publicClient) {
456-
throw new Error('PolygonStaker not initialized, call init() to initialize')
457-
}
458431
const { delegatorAddress, validatorShareAddress } = params
459432

460433
const result = await this.publicClient.readContract({
@@ -483,9 +456,6 @@ export class PolygonStaker {
483456
* @returns Promise resolving to the current unbond nonce
484457
*/
485458
async getUnbondNonce (params: { delegatorAddress: Address; validatorShareAddress: Address }): Promise<bigint> {
486-
if (!this.publicClient) {
487-
throw new Error('PolygonStaker not initialized, call init() to initialize')
488-
}
489459

490460
return this.publicClient.readContract({
491461
address: params.validatorShareAddress,
@@ -512,9 +482,6 @@ export class PolygonStaker {
512482
validatorShareAddress: Address
513483
unbondNonce: bigint
514484
}): Promise<UnbondInfo> {
515-
if (!this.publicClient) {
516-
throw new Error('PolygonStaker not initialized, call init() to initialize')
517-
}
518485
const { delegatorAddress, validatorShareAddress, unbondNonce } = params
519486

520487
const result = await this.publicClient.readContract({
@@ -540,9 +507,6 @@ export class PolygonStaker {
540507
* @returns Promise resolving to the pending rewards in wei
541508
*/
542509
async getLiquidRewards (params: { delegatorAddress: Address; validatorShareAddress: Address }): Promise<bigint> {
543-
if (!this.publicClient) {
544-
throw new Error('PolygonStaker not initialized, call init() to initialize')
545-
}
546510

547511
return this.publicClient.readContract({
548512
address: params.validatorShareAddress,
@@ -560,9 +524,6 @@ export class PolygonStaker {
560524
* @returns Promise resolving to the current allowance in wei
561525
*/
562526
async getAllowance (ownerAddress: Address): Promise<bigint> {
563-
if (!this.publicClient) {
564-
throw new Error('PolygonStaker not initialized, call init() to initialize')
565-
}
566527

567528
return this.publicClient.readContract({
568529
address: this.contracts.stakingTokenAddress,
@@ -578,9 +539,6 @@ export class PolygonStaker {
578539
* @returns Promise resolving to the current epoch number
579540
*/
580541
async getEpoch (): Promise<bigint> {
581-
if (!this.publicClient) {
582-
throw new Error('PolygonStaker not initialized, call init() to initialize')
583-
}
584542

585543
return this.publicClient.readContract({
586544
address: this.contracts.stakeManagerAddress,
@@ -608,9 +566,6 @@ export class PolygonStaker {
608566
baseFeeMultiplier?: number
609567
defaultPriorityFee?: string
610568
}): Promise<{ signedTx: Hex }> {
611-
if (!this.publicClient) {
612-
throw new Error('PolygonStaker not initialized, call init() to initialize')
613-
}
614569

615570
const { signer, signerAddress, tx, baseFeeMultiplier, defaultPriorityFee } = params
616571

@@ -670,9 +625,6 @@ export class PolygonStaker {
670625
* @returns A promise that resolves to the transaction hash
671626
*/
672627
async broadcast (params: { signedTx: Hex }): Promise<{ txHash: Hex }> {
673-
if (!this.publicClient) {
674-
throw new Error('PolygonStaker not initialized, call init() to initialize')
675-
}
676628

677629
const { signedTx } = params
678630
const hash = await this.publicClient.sendRawTransaction({ serializedTransaction: signedTx })
@@ -688,9 +640,6 @@ export class PolygonStaker {
688640
* @returns A promise that resolves to an object containing the transaction status
689641
*/
690642
async getTxStatus (params: { txHash: Hex }): Promise<PolygonTxStatus> {
691-
if (!this.publicClient) {
692-
throw new Error('PolygonStaker not initialized, call init() to initialize')
693-
}
694643

695644
const { txHash } = params
696645

packages/polygon/test/integration/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const prepareTests = async (): Promise<TestSetup> => {
4444
network: 'mainnet',
4545
rpcUrl: hardhat.rpcUrls.default.http[0]
4646
})
47-
await staker.init()
4847

4948
return {
5049
validatorShareAddress: CHORUS_ONE_POLYGON_VALIDATORS.mainnet,

0 commit comments

Comments
 (0)