Skip to content

Commit

Permalink
dynamic num of retries with logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinagill15 committed Jan 7, 2025
1 parent 811219d commit 6b65397
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/asset/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class Asset extends Ownable implements IAsset {
}
}

@AsyncRetriable()
async setAddressConfig(config: AddressConfig): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setAddressConfig', [
{
Expand Down Expand Up @@ -70,6 +71,7 @@ export class Asset extends Ownable implements IAsset {
return credit.toBigInt() === UNLIMITED_CREDIT
}

@AsyncRetriable()
async setOFTPath(dstEid: EndpointId, isOft: boolean): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setOFTPath', [dstEid, isOft])

Expand Down Expand Up @@ -128,6 +130,7 @@ export class Asset extends Ownable implements IAsset {
return paused === PAUSED
}

@AsyncRetriable()
async setPaused(paused: boolean): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPause', [paused])

Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/blacklistable/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export class Blacklistable extends OmniSDK implements IBlacklistable {
async getBlacklister(): Promise<string> {
return BlacklistableMixin.getBlacklister.call(this)
}
@AsyncRetriable()
async setBlacklister(blacklister: string): Promise<OmniTransaction> {
return BlacklistableMixin.setBlacklister.call(this, blacklister)
}
@AsyncRetriable()
async isBlacklisted(address: string): Promise<boolean> {
return BlacklistableMixin.isBlacklisted.call(this, address)
}
@AsyncRetriable()
async setBlacklisted(address: string, blacklisted: boolean): Promise<OmniTransaction> {
return BlacklistableMixin.setBlacklisted.call(this, address, blacklisted)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class CreditMessaging extends Messaging implements ICreditMessaging {
return ignoreZero(planner)
}

@AsyncRetriable()
async setPlanner(planner: OmniAddress): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPlanner', [planner])

Expand All @@ -33,6 +34,7 @@ export class CreditMessaging extends Messaging implements ICreditMessaging {
return gasLimit.toBigInt()
}

@AsyncRetriable()
async setGasLimit(eid: EndpointId, gasLimit: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setGasLimit', [eid, gasLimit])

Expand Down
1 change: 1 addition & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/erc20/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class ERC20 extends Ownable implements IERC20 {
return allowance.toBigInt()
}

@AsyncRetriable()
async mint(account: OmniAddress, amount: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('mint', [account, amount])

Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/feeLib_v1/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class FeeLibV1 extends Ownable implements IFeeLibV1 {
return FeeConfigSchema.parse({ ...config })
}

@AsyncRetriable()
async setFeeConfig(
eid: EndpointId,
zone1UpperBound: bigint,
Expand Down Expand Up @@ -59,6 +60,7 @@ export class FeeLibV1 extends Ownable implements IFeeLibV1 {
return (await this.contract.contract.feeConfigs(eid)).paused
}

@AsyncRetriable()
async setPaused(eid: EndpointId, paused: boolean): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPaused', [eid, paused])

Expand Down
3 changes: 3 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/messaging/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export abstract class Messaging extends OApp implements IMessaging {
return UIntNumberSchema.parse(await this.contract.contract.assetIds(asset))
}

@AsyncRetriable()
async setAssetId(asset: OmniAddress, assetId: number): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setAssetId', [asset, assetId])

Expand All @@ -37,6 +38,7 @@ export abstract class Messaging extends OApp implements IMessaging {
return UIntNumberSchema.parse(await this.contract.contract.maxAssetId())
}

@AsyncRetriable()
async setMaxAssetId(maxAssetId: number): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setMaxAssetId', [maxAssetId])

Expand All @@ -53,6 +55,7 @@ export abstract class Messaging extends OApp implements IMessaging {
return ignoreZero(planner)
}

@AsyncRetriable()
async setPlanner(planner: OmniAddress): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPlanner', [planner])

Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/mintable/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export class Mintable extends Ownable implements IMintable {
async isMinter(minter: OmniAddress): Promise<boolean> {
return MintableMixin.isMinter.call(this, minter)
}
@AsyncRetriable()
async addMinter(minter: OmniAddress): Promise<OmniTransaction> {
return MintableMixin.addMinter.call(this, minter)
}
@AsyncRetriable()
async removeMinter(minter: OmniAddress): Promise<OmniTransaction> {
return MintableMixin.removeMinter.call(this, minter)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/oft-wrapper/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class OFTWrapper extends Ownable implements IOFTWrapper {
return BigNumberishBigIntSchema.parse(bps)
}

@AsyncRetriable()
async setDefaultBps(bps: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setDefaultBps', [bps])

Expand All @@ -28,6 +29,7 @@ export class OFTWrapper extends Ownable implements IOFTWrapper {
}
}

@AsyncRetriable()
async setOFTBps(token: OmniAddress, bps: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setOFTBps', [token, bps])

Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/pausable/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Pausable extends OmniSDK implements IPausable {
return PausableMixin.getPauser.call(this)
}

@AsyncRetriable()
async setPauser(pauser: OmniAddress): Promise<OmniTransaction> {
return PausableMixin.setPauser.call(this, pauser)
}
Expand All @@ -20,6 +21,7 @@ export class Pausable extends OmniSDK implements IPausable {
return PausableMixin.isPaused.call(this)
}

@AsyncRetriable()
async setPaused(paused: boolean): Promise<OmniTransaction> {
return PausableMixin.setPaused.call(this, paused)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/stg-devtools-evm-hardhat-v2/src/pool/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { IPool } from '@stargatefinance/stg-devtools-v2'

import { OmniAddress, OmniTransaction } from '@layerzerolabs/devtools'
import { AsyncRetriable, OmniAddress, OmniTransaction } from '@layerzerolabs/devtools'
import { Ownable } from '@layerzerolabs/ua-devtools-evm'

export class Pool extends Ownable implements IPool {
@AsyncRetriable()
async deposit(receiver: OmniAddress, amount: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('deposit', [receiver, amount])

Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/rescuable/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export class Rescuable extends OmniSDK implements IRescuable {
return RescuableMixin.getRescuer.call(this)
}

@AsyncRetriable()
async setRescuer(rescuer: OmniAddress): Promise<OmniTransaction> {
return RescuableMixin.setRescuer.call(this, rescuer)
}

@AsyncRetriable()
async rescueERC20(tokenContract: OmniAddress, to: OmniAddress, amount: bigint): Promise<OmniTransaction> {
return RescuableMixin.rescueERC20.call(this, tokenContract, to, amount)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/rewarder/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AsyncRetriable, OmniAddress, type OmniTransaction } from '@layerzerolab
import { Ownable } from '@layerzerolabs/ua-devtools-evm'

export class Rewarder extends Ownable implements IRewarder {
@AsyncRetriable()
async setReward(token: OmniAddress, amount: bigint, start: number, duration: number): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setReward', [token, amount, start, duration])

Expand Down Expand Up @@ -37,6 +38,7 @@ export class Rewarder extends Ownable implements IRewarder {
return allocations
}

@AsyncRetriable()
async setAllocPoints(rewardToken: OmniAddress, allocations: Allocations): Promise<OmniTransaction> {
const stakingTokens = Object.keys(allocations)
const points = Object.values(allocations)
Expand Down
1 change: 1 addition & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/staking/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Staking extends Ownable implements IStaking {
return ignoreZero(rewarder)
}

@AsyncRetriable()
async setPool(token: OmniAddress, rewarder: OmniAddress): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPool', [token, rewarder])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
return ignoreZero(planner)
}

@AsyncRetriable()
async setPlanner(planner: OmniAddress): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setPlanner', [planner])

Expand All @@ -55,6 +56,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
return ignoreZero(hash)
}

@AsyncRetriable()
async initializeBusQueueStorage(
dstEids: EndpointId[],
startSlot: bigint,
Expand All @@ -79,6 +81,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
return UIntNumberSchema.parse(queue.maxNumPassengers)
}

@AsyncRetriable()
async setMaxPassengers(dstEid: EndpointId, maxPassengers: number): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setMaxNumPassengers', [dstEid, maxPassengers])

Expand All @@ -98,6 +101,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
}
}

@AsyncRetriable()
async setFares(dstEid: EndpointId, fares: Fares): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setFares', [
dstEid,
Expand All @@ -121,6 +125,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
}
}

@AsyncRetriable()
async setGasLimit(dstEid: EndpointId, gasLimit: TokenMessagingGasLimits): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setGasLimit', [
dstEid,
Expand All @@ -141,6 +146,7 @@ export class TokenMessaging extends Messaging implements ITokenMessaging {
return nativeDropAmount.toBigInt()
}

@AsyncRetriable()
async setNativeDropAmount(dstEid: EndpointId, nativeDropAmount: bigint): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setNativeDropAmount', [
dstEid,
Expand Down
2 changes: 2 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/treasurer/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class Treasurer extends Ownable implements ITreasurer {
return await this.contract.contract.admin()
}

@AsyncRetriable()
async setAdmin(admin: OmniAddress): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('setAdmin', [admin])

Expand All @@ -23,6 +24,7 @@ export class Treasurer extends Ownable implements ITreasurer {
return await this.contract.contract.stargates(asset)
}

@AsyncRetriable()
async setAsset(asset: OmniAddress, managed: boolean): Promise<OmniTransaction> {
// The contracts reference these as stargates, but really they are 'assets'
const data = this.contract.contract.interface.encodeFunctionData('setStargate', [asset, managed])
Expand Down
11 changes: 11 additions & 0 deletions packages/stg-devtools-evm-hardhat-v2/src/usdc/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,51 @@ export class USDC extends OmniSDK implements IUSDC {
async hasOwner(address: string): Promise<boolean> {
return OwnableMixin.hasOwner.call(this, address)
}
@AsyncRetriable()
async setOwner(address: string): Promise<OmniTransaction> {
return OwnableMixin.setOwner.call(this, address)
}
@AsyncRetriable()
async getPauser(): Promise<string> {
return PausableMixin.getPauser.call(this)
}
@AsyncRetriable()
async setPauser(pauser: string): Promise<OmniTransaction> {
return PausableMixin.setPauser.call(this, pauser)
}
@AsyncRetriable()
async isPaused(): Promise<boolean> {
return PausableMixin.isPaused.call(this)
}
@AsyncRetriable()
async setPaused(paused: boolean): Promise<OmniTransaction> {
return PausableMixin.setPaused.call(this, paused)
}
@AsyncRetriable()
async getRescuer(): Promise<string> {
return RescuableMixin.getRescuer.call(this)
}
@AsyncRetriable()
async setRescuer(rescuer: string): Promise<OmniTransaction> {
return RescuableMixin.setRescuer.call(this, rescuer)
}
@AsyncRetriable()
async rescueERC20(tokenContract: string, to: string, amount: bigint): Promise<OmniTransaction> {
return RescuableMixin.rescueERC20.call(this, tokenContract, to, amount)
}
@AsyncRetriable()
async getBlacklister(): Promise<string> {
return BlacklistableMixin.getBlacklister.call(this)
}
@AsyncRetriable()
async setBlacklister(blacklister: string): Promise<OmniTransaction> {
return BlacklistableMixin.setBlacklister.call(this, blacklister)
}
@AsyncRetriable()
async isBlacklisted(address: string): Promise<boolean> {
return BlacklistableMixin.isBlacklisted.call(this, address)
}
@AsyncRetriable()
async setBlacklisted(address: string, blacklisted: boolean): Promise<OmniTransaction> {
return BlacklistableMixin.setBlacklisted.call(this, address, blacklisted)
}
Expand All @@ -70,6 +77,7 @@ export class USDC extends OmniSDK implements IUSDC {

return UIntBigIntSchema.parse(await this.contract.contract.minterAllowance(minter))
}
@AsyncRetriable()
async configureMinter(minter: OmniAddress, allowance: bigint): Promise<OmniTransaction> {
this.logger.debug(`Configuring minter for ${this.label} : ${minter} <${allowance}>`)

Expand All @@ -80,6 +88,7 @@ export class USDC extends OmniSDK implements IUSDC {
description: `Configuring minter: ${minter} to ${allowance} allowance`,
}
}
@AsyncRetriable()
async removeMinter(minter: OmniAddress): Promise<OmniTransaction> {
this.logger.debug(`Removing minter for ${this.label} : ${minter}`)

Expand All @@ -96,6 +105,7 @@ export class USDC extends OmniSDK implements IUSDC {

return await this.contract.contract.masterMinter()
}
@AsyncRetriable()
async setMasterMinter(masterMinter: OmniAddress): Promise<OmniTransaction> {
this.logger.debug(`Setting master minter for ${this.label} : ${masterMinter}`)

Expand All @@ -113,6 +123,7 @@ export class USDC extends OmniSDK implements IUSDC {

return this.logger.debug(`Got admin: ${admin}`), admin
}
@AsyncRetriable()
async setAdmin(admin: OmniAddress): Promise<OmniTransaction> {
this.logger.debug(`Setting admin for ${this.label} : ${admin}`)

Expand Down
11 changes: 9 additions & 2 deletions packages/stg-evm-v2/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ configDotenv({
path: ['.env.local', '.env'],
})

import { AsyncRetriable } from '@layerzerolabs/devtools'
import { EndpointId } from '@layerzerolabs/lz-definitions'

import { getSafeConfig } from './devtools/config/utils'
Expand All @@ -32,8 +33,14 @@ import '@typechain/hardhat'
// Devtools-specific tasks
import './devtools/tasks'

// AsyncRetriable.config.numAttempts = process.env.NUM_RETRIES ? parseInt(process.env.NUM_RETRIES) : 5

AsyncRetriable.config = {
enabled: true,
numAttempts: process.env.NUM_RETRIES ? parseInt(process.env.NUM_RETRIES) : 5,
maxDelay: 1_000,
onRetry: (attemptNum, totalNumRetries, error) => {
console.log(`Attempt ${attemptNum}/${totalNumRetries}: ${error} \n`)
},
}
const v1Deployments = join(dirname(require.resolve('@stargatefinance/stg-evm-v1/package.json')), 'deployments')

/**
Expand Down

0 comments on commit 6b65397

Please sign in to comment.