Skip to content

Commit

Permalink
Clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
besated committed Jul 4, 2024
1 parent f90ef2e commit 1013e23
Show file tree
Hide file tree
Showing 33 changed files with 157 additions and 744 deletions.
23 changes: 11 additions & 12 deletions packages/evm/src/ethers/addressPrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@ import { ContractRunner, Contract, InterfaceAbi } from 'ethers';
import { ADDRESS_PRECOMPILE_ABI, ADDRESS_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* Represents the functions available in the Address precompile contract, facilitating interoperability between the EVM and Cosmos.
* Represents the functions available in the Address precompile contract.
* @category Cosmos Interoperability
*/
export interface AddressPrecompileFunctions {
/**
* Retrieves the associated EVM address for a given Cosmos address.
* @param addr The Cosmos address for which to retrieve the associated EVM address.
* @returns A Promise resolving to an object containing the associated EVM address.
* @category Cosmos Interoperability
* @returns A Promise that resolves to the associated EVM address.
*/
getEvmAddr(addr: string): Promise<string>;
/**
* Retrieves the associated Cosmos address for a given EVM address.
* @param addr The EVM address for which to retrieve the associated Cosmos address.
* @returns A Promise resolving to an object containing the associated Cosmos address.
* @category Cosmos Interoperability
* @returns A Promise that resolves to the associated Cosmos address.
*/
getSeiAddr(addr: string): Promise<string>;
}

/** Represents the typed contract instance for the ADDRESS precompile contract.
/**
* Type for the Address precompile contract, combining the base Contract and AddressPrecompileFunctions.
* @category Cosmos Interoperability
* */
*/
type AddressPrecompileContract = Contract & AddressPrecompileFunctions;

/**
* The ABI for the address precompile contract, which can be used to create an Ethers contract.
*
* The ABI for the Address precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
*/
export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as InterfaceAbi;

/**
* Creates and returns an Ethers contract instance with the provided signer.
* Creates and returns a typed Ethers v6 contract instance for the Address precompile contract.
* This contract is used for interoperability between the EVM and Cosmos.
*
* @example
* ```tsx
Expand All @@ -52,8 +51,8 @@ export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as Interface
* const seiAddr = await addressPrecompileContract.getSeiAddr(accounts[0]);
* ```
*
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the precompile contract.
* @category Cosmos Interoperability
*/
export function getAddressPrecompileEthersV6Contract(runner: ContractRunner): AddressPrecompileContract {
Expand Down
21 changes: 11 additions & 10 deletions packages/evm/src/ethers/bankPrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { BigNumberish, Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* Represents the functions available in the Bank precompile contract,
* facilitating interoperability between the EVM and Cosmos.
* Represents the functions available in the Bank precompile contract.
* @category Cosmos Interoperability
*/
export interface BankPrecompileFunctions {
Expand Down Expand Up @@ -63,24 +62,25 @@ export interface BankPrecompileFunctions {
sendNative(toNativeAddress: string, value: BigNumberish): Promise<{ success: boolean }>;
}

/** Represents the typed contract instance for the BANK precompile contract.
/**
* Type for the Bank precompile contract, combining the base Contract and BankPrecompileFunctions.
* @category Cosmos Interoperability
* */
export type BankPrecompileContract = Contract & BankPrecompileFunctions;

/**
* The Ethers ABI for the bank precompile contract.
*
* The ABI for the Bank precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
*/
export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi;

/**
* Creates and returns an Ethers contract instance with the provided signer.
* Creates and returns a typed Ethers v6 contract instance for the Bank precompile contract.
* This contract is used for interoperability between the EVM and Cosmos.
*
* @example
* ```tsx
* import { getBankPrecompileEthersV6Contract } from '@sei-js/evm';
* import { getBankPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
Expand All @@ -91,12 +91,13 @@ export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi;
* const bankPrecompileContract = getBankPrecompileEthersV6Contract(signer);
*
* const balance = await bankPrecompileContract.balance(accounts[0], 'usei');
* console.log('Balance:', balance);
* ```
*
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Bank precompile contract.
* @category Cosmos Interoperability
*/
export const getBankPrecompileEthersV6Contract = (runner: ContractRunner): BankPrecompileContract => {
return new Contract(BANK_PRECOMPILE_ADDRESS, ETHERS_BANK_PRECOMPILE_ABI, runner) as BankPrecompileContract;
return new Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, runner) as BankPrecompileContract;
};
37 changes: 12 additions & 25 deletions packages/evm/src/ethers/distributionPrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI } from '../precompiles';

/**
* Represents the functions available in the Distribution precompile contract,
* facilitating interoperability between the EVM and Cosmos.
* Represents the functions available in the Distribution precompile contract.
* @category Cosmos Interoperability
*/
export interface DistributionPrecompileFunctions {
Expand All @@ -30,39 +29,25 @@ export interface DistributionPrecompileFunctions {
withdrawMultipleDelegationRewards(validators: string[]): Promise<{ success: boolean }>;
}

/** Represents the typed contract instance for the DISTRIBUTION precompile contract.
/**
* Type for the Distribution precompile contract, combining the base Contract and DistributionPrecompileFunctions.
* @category Cosmos Interoperability
* */
*/
export type DistributionPrecompileContract = Contract & DistributionPrecompileFunctions;

/**
* The ABI for the distribution precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to set the withdrawal address for rewards for the connected account.
* ```tsx
* import { DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, DistributionPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const contract = new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, signer) as DistributionPrecompileContract;
*
* const response = await contract.setWithdrawAddress('0xADDRESS');
* ```
*
* The ABI for the Distribution precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
*/
export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as InterfaceAbi;

/**
* Creates and returns an ethers v6 contract instance with the provided signer, for use in interoperability between the EVM and Cosmos.
* Creates and returns a typed Ethers v6 contract instance for the Distribution precompile contract.
* This contract is used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to set the withdrawal address for rewards for the connected account.
* ```tsx
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/evm';
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
Expand All @@ -71,9 +56,11 @@ export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as
* const contract = getDistributionPrecompileEthersV6Contract(signer);
*
* const response = await contract.setWithdrawAddress('0xADDRESS');
* console.log('Response:', response);
* ```
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Distribution precompile contract.
* @category Cosmos Interoperability
*/
export const getDistributionPrecompileEthersV6Contract = (runner: ContractRunner): DistributionPrecompileContract => {
Expand Down
41 changes: 14 additions & 27 deletions packages/evm/src/ethers/governancePrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { BigNumberish, Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { GOVERNANCE_PRECOMPILE_ABI, GOVERNANCE_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* Represents the functions available in the Governance precompile contract,
* facilitating interoperability between the EVM and Cosmos.
* Represents the functions available in the Governance precompile contract.
* @category Cosmos Interoperability
*/
export interface GovernancePrecompileFunctions {
Expand All @@ -24,53 +23,41 @@ export interface GovernancePrecompileFunctions {
vote(proposalID: BigNumberish, option: BigNumberish): Promise<{ success: boolean }>;
}

/** Represents the typed contract instance for the GOVERNANCE precompile contract.
/**
* Type for the Governance precompile contract, combining the base Contract and GovernancePrecompileFunctions.
* @category Cosmos Interoperability
* */
*/
export type GovernancePrecompileContract = Contract & GovernancePrecompileFunctions;

/**
* The ABI for the governance precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, parseSei } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, signer) as GovernancePrecompileContract;
*
* const depositResponse = await governancePrecompileContract.connect().deposit('PROPOSAL_ID', { value: parseSei(1) });
* ```
*
* The ABI for the Governance precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
*/
export const ETHERS_GOVERNANCE_PRECOMPILE_ABI = GOVERNANCE_PRECOMPILE_ABI as InterfaceAbi;

/**
* Creates and returns an ethers v6 contract instance with the provided signer, for use in interoperability between the EVM and Cosmos.
* Creates and returns a typed Ethers v6 contract instance for the Governance precompile contract.
* This contract is used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, parseSei } from '@sei-js/evm';
* import { getGovernancePrecompileEthersV6Contract, parseSei } from '@sei-js/evm/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = getGovernancePrecompileEthersV6Contract(signer);
*
* //Surround with try/catch for detailed errors
* // Surround with try/catch for detailed errors
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseSei(1) });
* console.log('Deposit Response:', depositResponse);
* ```
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Governance precompile contract.
* @category Cosmos Interoperability
*/
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => {
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner): GovernancePrecompileContract => {
return new Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, runner) as GovernancePrecompileContract;
};
34 changes: 10 additions & 24 deletions packages/evm/src/ethers/ibcPrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { BigNumberish, Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { IBC_PRECOMPILE_ABI, IBC_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* Represents the functions available in the IBC precompile contract,
* facilitating interoperability between the EVM and Cosmos.
* Represents the functions available in the IBC precompile contract.
* @category Cosmos Interoperability
*/
export interface IbcPrecompileFunctions {
Expand Down Expand Up @@ -45,38 +44,24 @@ export interface IbcPrecompileFunctions {
}

/**
* Represents the typed contract instance for the IBC precompile contract.
* Type for the IBC precompile contract, combining the base Contract and IbcPrecompileFunctions.
* @category Cosmos Interoperability
* */
*/
export type IbcPrecompileContract = Contract & IbcPrecompileFunctions;

/**
* The ABI for the IBC precompile contract.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { IBC_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
*
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* The ABI for the IBC precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
*/
export const ETHERS_IBC_PRECOMPILE_ABI = IBC_PRECOMPILE_ABI as InterfaceAbi;

/**
* Creates and returns an ethers v6 contract instance with the provided signer, for use in interoperability between the EVM and Cosmos.
* Creates and returns a typed Ethers v6 contract instance for the IBC precompile contract.
* This contract is used for interoperability between the EVM and Cosmos.
*
* @example
* ```tsx
* import { getIbcPrecompileEthersV6Contract } from '@sei-js/evm';
* import { getIbcPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
Expand All @@ -86,10 +71,11 @@ export const ETHERS_IBC_PRECOMPILE_ABI = IBC_PRECOMPILE_ABI as InterfaceAbi;
* const cosmosAddress = 'cosmos1...';
*
* const bool = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* console.log('Transfer successful:', bool);
* ```
*
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the IBC precompile contract.
* @category Cosmos Interoperability
*/
export const getIbcPrecompileEthersV6Contract = (runner: ContractRunner): IbcPrecompileContract => {
Expand Down
Loading

0 comments on commit 1013e23

Please sign in to comment.