-
Notifications
You must be signed in to change notification settings - Fork 28
refactor(cosmwasm): use TS mainProcessor #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+31
−151
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
248883c
feat: TS version of mainProcessor and config handler
kulikthebird 1c02f02
refactor: use TS mainProcessor in JS scripts
kulikthebird 65b9f81
Merge branch 'main' into feat/main_processor_ts
kulikthebird 76a76e2
Merge branch 'main' into feat/main_processor_ts
nbayindirli 3625663
Merge branch 'feat/main_processor_ts' into chore/use_ts_main_processor
nbayindirli adebc3f
Merge branch 'main' into feat/main_processor_ts
blockchainguyy 263bdc4
refactor: ConfigManager - enhanced config scheme ; prints reach outpu…
kulikthebird f0081f2
refactoring: removed TODO - covered by a task ; generic type extraction
kulikthebird 9ab2ccd
chore: required fields fix ; loop instead of single checks
kulikthebird da4dff5
chore: remove generic arg
kulikthebird 2823b7a
fix: required fields check - zeros are correct values
kulikthebird 4dc6bdd
Merge branch 'feat/main_processor_ts' into chore/use_ts_main_processor
kulikthebird 94bd68f
Apply suggestion from @nbayindirli
kulikthebird cadcec2
fix: remove undefined export
kulikthebird c6786bb
Merge branch 'main' into feat/main_processor_ts
kulikthebird 06765b5
fix: gasLimit & gasPrice validation
kulikthebird 99937be
fix: import
kulikthebird 9a1f31e
fix: imports
kulikthebird 08e2446
fix: remove saveConfig from query - it's saved in mainProcessor
kulikthebird b7de9bb
Merge branch 'feat/main_processor_ts' into chore/use_ts_main_processor
kulikthebird 693d560
Apply suggestion from @nbayindirli
kulikthebird c7fb43b
Apply suggestion from @nbayindirli
kulikthebird 17113ca
Merge branch 'feat/main_processor_ts' into chore/use_ts_main_processor
kulikthebird 942e783
Merge branch 'main' into feat/main_processor_ts
kulikthebird 5849332
Merge branch 'feat/main_processor_ts' into chore/use_ts_main_processor
kulikthebird 5ad8882
Merge branch 'main' into chore/use_ts_main_processor
kulikthebird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { StdFee } from '@cosmjs/stargate'; | ||
import { GasPrice, calculateFee } from '@cosmjs/stargate'; | ||
|
||
import { loadConfig, saveConfig } from '.'; | ||
|
||
export interface FullConfig { | ||
axelar: { | ||
contracts: { | ||
[key: string]: ContractConfig & { | ||
governanceAddress?: string; | ||
governanceAccount?: string; | ||
}; | ||
}; | ||
rpc: string; | ||
gasPrice: string; | ||
gasLimit: string | number; | ||
govProposalInstantiateAddresses: string[]; | ||
govProposalDepositAmount: string; | ||
}; | ||
chains: { | ||
[chainName: string]: ChainConfig; | ||
}; | ||
[key: string]: unknown; | ||
} | ||
|
||
export interface ChainConfig { | ||
name: string; | ||
axelarId: string; | ||
chainId: number; | ||
rpc: string; | ||
tokenSymbol: string; | ||
decimals: number; | ||
confirmations?: number; | ||
chainType: string; | ||
contracts: { | ||
[key: string]: ContractConfig; | ||
}; | ||
} | ||
|
||
export interface ContractConfig { | ||
address?: string; | ||
codeId?: number; | ||
storeCodeProposalCodeHash?: string; | ||
storeCodeProposalId?: string; | ||
lastUploadedCodeId?: number; | ||
[key: string]: unknown; | ||
} | ||
|
||
export class ConfigManager { | ||
private environment: string; | ||
private fullConfig: FullConfig; | ||
|
||
constructor(environment: string, fullConfig?: FullConfig) { | ||
this.environment = environment; | ||
|
||
if (fullConfig) { | ||
this.fullConfig = fullConfig; | ||
} else { | ||
this.fullConfig = loadConfig(this.environment); | ||
} | ||
|
||
this.validateConfig(); | ||
} | ||
|
||
private validateConfig(): void { | ||
if (!this.fullConfig.axelar) { | ||
throw new Error(`Missing 'axelar' section in ${this.environment} config`); | ||
} | ||
|
||
if (!this.fullConfig.axelar.contracts) { | ||
throw new Error(`Missing 'axelar.contracts' section in ${this.environment} config`); | ||
} | ||
|
||
if (!this.fullConfig.chains) { | ||
throw new Error( | ||
`Missing 'chains' section in ${this.environment} config. Please ensure the config file has a 'chains' property.`, | ||
); | ||
} | ||
|
||
if (typeof this.fullConfig.chains !== 'object' || this.fullConfig.chains === null) { | ||
throw new Error(`'chains' section in ${this.environment} config must be an object`); | ||
} | ||
|
||
if (!this.fullConfig.axelar.rpc) { | ||
throw new Error(`Missing 'axelar.rpc' in ${this.environment} config`); | ||
} | ||
|
||
if (!this.fullConfig.axelar.gasPrice) { | ||
throw new Error(`Missing 'axelar.gasPrice' in ${this.environment} config`); | ||
} | ||
|
||
if (!this.fullConfig.axelar.gasLimit) { | ||
throw new Error(`Missing 'axelar.gasLimit' in ${this.environment} config`); | ||
} | ||
} | ||
|
||
public initContractConfig(contractName: string, chainName: string) { | ||
if (!this.fullConfig.axelar.contracts[contractName]) { | ||
this.fullConfig.axelar.contracts[contractName] = {}; | ||
} | ||
|
||
if (chainName) { | ||
this.fullConfig.axelar.contracts[contractName][chainName] = this.fullConfig.axelar.contracts[contractName][chainName] || {}; | ||
} | ||
} | ||
|
||
public saveConfig(): void { | ||
saveConfig(this.fullConfig, this.environment); | ||
} | ||
|
||
public getFullConfig(): FullConfig { | ||
return this.fullConfig; | ||
} | ||
|
||
public getProposalInstantiateAddresses(): string[] { | ||
return this.fullConfig.axelar.govProposalInstantiateAddresses; | ||
} | ||
|
||
public getProposalDepositAmount(): string { | ||
return this.fullConfig.axelar.govProposalDepositAmount; | ||
} | ||
|
||
public getFee(): string | StdFee { | ||
const { gasPrice, gasLimit } = this.fullConfig.axelar; | ||
|
||
return gasLimit === 'auto' ? 'auto' : calculateFee(gasLimit as number, GasPrice.fromString(gasPrice)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'; | ||
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; | ||
import { StdFee } from '@cosmjs/stargate'; | ||
|
||
import { ConfigManager, FullConfig } from '../common/config'; | ||
import { prepareClient, prepareWallet } from './utils'; | ||
|
||
type Options = { | ||
env: string; | ||
contractName: string; | ||
chainName: string; | ||
mnemonic: string; | ||
runAs?: string; | ||
deposit?: string; | ||
instantiateAddresses?: string[]; | ||
}; | ||
|
||
export async function mainProcessor< | ||
Processor extends ( | ||
client: SigningCosmWasmClient, | ||
wallet: DirectSecp256k1HdWallet, | ||
config: FullConfig, | ||
options: Options, | ||
args?: string[], | ||
fee?: string | StdFee, | ||
) => Promise<void>, | ||
>(processor: Processor, options: Options, args?: string[]) { | ||
const { runAs, deposit, instantiateAddresses, env } = options; | ||
const configManager = new ConfigManager(env); | ||
|
||
// TODO tkulik: The `runAs` should be moved to config | ||
options.runAs = | ||
runAs || | ||
(env == 'devnet-amplifier' ? 'axelar1zlr7e5qf3sz7yf890rkh9tcnu87234k6k7ytd9' : 'axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj'); | ||
options.deposit = deposit || configManager.getProposalDepositAmount(); | ||
options.instantiateAddresses = instantiateAddresses || configManager.getProposalInstantiateAddresses(); | ||
|
||
configManager.initContractConfig(options.contractName, options.chainName); | ||
|
||
const wallet = await prepareWallet(options); | ||
const client = await prepareClient(configManager.getFullConfig(), wallet); | ||
|
||
const fee = configManager.getFee(); | ||
|
||
await processor(client, wallet, configManager.getFullConfig(), options, args, fee); | ||
|
||
configManager.saveConfig(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.