Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into fix/CAN-590
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosampler committed Oct 17, 2024
2 parents fd742f3 + 25f7208 commit f762635
Show file tree
Hide file tree
Showing 13 changed files with 439 additions and 144 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/commitlint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: false
types: |
hotfix
feat
fix
chore
docs
test
37 changes: 21 additions & 16 deletions packages/builder/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as viem from 'viem';
import { Abi, Address, Hash, Hex, SendTransactionParameters } from 'viem';

import _ from 'lodash';
import * as viem from 'viem';
import { viemContext } from './utils/viem-context';
import { PackageReference } from './package-reference';

import type { RawChainDefinition } from './actions';

import { PackageReference } from './package-reference';

// loosely based on the hardhat `Artifact` type
export type ContractArtifact = {
contractName: string;
sourceName: string;
abi: Abi;
bytecode: Hex;
abi: viem.Abi;
bytecode: viem.Hex;
deployedBytecode: string;
linkReferences: {
[fileName: string]: {
Expand All @@ -29,8 +27,8 @@ export type ContractArtifact = {
};

export type ContractData = {
address: Address;
abi: Abi;
address: viem.Address;
abi: viem.Abi;
constructorArgs?: any[]; // only needed for external verification
linkedLibraries?: { [sourceName: string]: { [libName: string]: string } }; // only needed for external verification
deployTxnHash: string;
Expand All @@ -50,7 +48,7 @@ export type ContractMap = {

export type TransactionMap = {
[label: string]: {
hash: Hash | '';
hash: viem.Hash | '';
blockNumber?: string;
timestamp?: string;
events: EventMap;
Expand Down Expand Up @@ -94,13 +92,12 @@ export interface ChainBuilderContext extends PreChainBuilderContext {

const etherUnitNames = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];

export const CannonHelperContext = {
// ethers style constants
// Ethers.js compatible context functions. Consider deprecating.
const ethersStyleConstants = {
AddressZero: viem.zeroAddress,
HashZero: viem.zeroHash,
MaxUint256: viem.maxUint256,

// ethers style utils
defaultAbiCoder: {
encode: (a: string[], v: any[]) => {
return viem.encodeAbiParameters(
Expand Down Expand Up @@ -162,13 +159,18 @@ export const CannonHelperContext = {
decodeFunctionResult: viem.decodeFunctionResult,
};

export const CannonHelperContext = {
...viemContext,
...ethersStyleConstants,
};

export type ChainBuilderContextWithHelpers = ChainBuilderContext & typeof CannonHelperContext;

export type BuildOptions = { [val: string]: string };

export type StorageMode = 'all' | 'metadata' | 'none';

export type CannonSigner = { wallet: viem.WalletClient; address: Address };
export type CannonSigner = { wallet: viem.WalletClient; address: viem.Address };

export type Contract = Pick<viem.SimulateContractParameters, 'abi' | 'address'>;

Expand All @@ -183,7 +185,10 @@ export interface ChainBuilderRuntimeInfo {
getSigner: (addr: viem.Address) => Promise<CannonSigner>;

// returns a signer which should be used for sending the specified transaction.
getDefaultSigner?: (txn: Omit<SendTransactionParameters, 'account' | 'chain'>, salt?: string) => Promise<CannonSigner>;
getDefaultSigner?: (
txn: Omit<viem.SendTransactionParameters, 'account' | 'chain'>,
salt?: string
) => Promise<CannonSigner>;

// returns contract information from the specified artifact name.
getArtifact?: (name: string) => Promise<ContractArtifact>;
Expand Down Expand Up @@ -301,7 +306,7 @@ export type StepState = {
artifacts: ChainArtifacts;

// If this is a cannon network build, the full dump of the chain blob is recorded
chainDump?: Hex | null; // only included if cannon network build
chainDump?: viem.Hex | null; // only included if cannon network build
};

export type DeploymentState = { [label: string]: StepState };
Expand Down
221 changes: 221 additions & 0 deletions packages/builder/src/utils/viem-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import * as viem from 'viem';

export const viemContext = {
// viem/utils
offchainLookupAbiItem: viem.offchainLookupAbiItem,
offchainLookupSignature: viem.offchainLookupSignature,
assertCurrentChain: viem.assertCurrentChain,
stringify: viem.stringify,
serializeTypedData: viem.serializeTypedData,
validateTypedData: viem.validateTypedData,
decodeAbiParameters: viem.decodeAbiParameters,
decodeErrorResult: viem.decodeErrorResult,
decodeEventLog: viem.decodeEventLog,
decodeFunctionData: viem.decodeFunctionData,
decodeFunctionResult: viem.decodeFunctionResult,
encodeAbiParameters: viem.encodeAbiParameters,
encodeDeployData: viem.encodeDeployData,
encodeErrorResult: viem.encodeErrorResult,
encodeEventTopics: viem.encodeEventTopics,
encodeFunctionData: viem.encodeFunctionData,
encodeFunctionResult: viem.encodeFunctionResult,
parseEventLogs: viem.parseEventLogs,
getAbiItem: viem.getAbiItem,
parseAbi: viem.parseAbi,
parseAbiItem: viem.parseAbiItem,
parseAbiParameter: viem.parseAbiParameter,
parseAbiParameters: viem.parseAbiParameters,
encodePacked: viem.encodePacked,
getContractAddress: viem.getContractAddress,
getCreateAddress: viem.getCreateAddress,
getCreate2Address: viem.getCreate2Address,
getAddress: viem.getAddress,
isAddress: viem.isAddress,
isAddressEqual: viem.isAddressEqual,
concat: viem.concat,
concatBytes: viem.concatBytes,
concatHex: viem.concatHex,
isBytes: viem.isBytes,
isHex: viem.isHex,
pad: viem.pad,
padBytes: viem.padBytes,
padHex: viem.padHex,
size: viem.size,
slice: viem.slice,
sliceBytes: viem.sliceBytes,
sliceHex: viem.sliceHex,
trim: viem.trim,
defineBlock: viem.defineBlock,
formatBlock: viem.formatBlock,
defineTransaction: viem.defineTransaction,
formatTransaction: viem.formatTransaction,
transactionType: viem.transactionType,
formatLog: viem.formatLog,
defineTransactionReceipt: viem.defineTransactionReceipt,
defineTransactionRequest: viem.defineTransactionRequest,
formatTransactionRequest: viem.formatTransactionRequest,
toRlp: viem.toRlp,
boolToBytes: viem.boolToBytes,
toBytes: viem.toBytes,
hexToBytes: viem.hexToBytes,
numberToBytes: viem.numberToBytes,
stringToBytes: viem.stringToBytes,
boolToHex: viem.boolToHex,
bytesToHex: viem.bytesToHex,
toHex: viem.toHex,
numberToHex: viem.numberToHex,
stringToHex: viem.stringToHex,
bytesToBigInt: viem.bytesToBigInt,
bytesToBool: viem.bytesToBool,
bytesToNumber: viem.bytesToNumber,
bytesToString: viem.bytesToString,
fromBytes: viem.fromBytes,
fromHex: viem.fromHex,
hexToBool: viem.hexToBool,
hexToBigInt: viem.hexToBigInt,
hexToNumber: viem.hexToNumber,
hexToString: viem.hexToString,
fromRlp: viem.fromRlp,
getContractError: viem.getContractError,
toEventSelector: viem.toEventSelector,
toFunctionSelector: viem.toFunctionSelector,
toEventSignature: viem.toEventSignature,
toFunctionSignature: viem.toFunctionSignature,
toEventHash: viem.toEventHash,
toFunctionHash: viem.toFunctionHash,
isHash: viem.isHash,
keccak256: viem.keccak256,
sha256: viem.sha256,
ripemd160: viem.ripemd160,
hashTypedData: viem.hashTypedData,
recoverAddress: viem.recoverAddress,
recoverMessageAddress: viem.recoverMessageAddress,
recoverPublicKey: viem.recoverPublicKey,
recoverTypedDataAddress: viem.recoverTypedDataAddress,
verifyHash: viem.verifyHash,
verifyMessage: viem.verifyMessage,
verifyTypedData: viem.verifyTypedData,
hashMessage: viem.hashMessage,
parseErc6492Signature: viem.parseErc6492Signature,
isErc6492Signature: viem.isErc6492Signature,
serializeErc6492Signature: viem.serializeErc6492Signature,
getSerializedTransactionType: viem.getSerializedTransactionType,
getTransactionType: viem.getTransactionType,
assertRequest: viem.assertRequest,
assertTransactionEIP1559: viem.assertTransactionEIP1559,
assertTransactionEIP2930: viem.assertTransactionEIP2930,
assertTransactionLegacy: viem.assertTransactionLegacy,
parseTransaction: viem.parseTransaction,
serializeTransaction: viem.serializeTransaction,
serializeAccessList: viem.serializeAccessList,
formatEther: viem.formatEther,
formatGwei: viem.formatGwei,
formatUnits: viem.formatUnits,
parseUnits: viem.parseUnits,
parseEther: viem.parseEther,
parseGwei: viem.parseGwei,

// viem/constants/number
maxInt8: viem.maxInt8,
maxInt16: viem.maxInt16,
maxInt24: viem.maxInt24,
maxInt32: viem.maxInt32,
maxInt40: viem.maxInt40,
maxInt48: viem.maxInt48,
maxInt56: viem.maxInt56,
maxInt64: viem.maxInt64,
maxInt72: viem.maxInt72,
maxInt80: viem.maxInt80,
maxInt88: viem.maxInt88,
maxInt96: viem.maxInt96,
maxInt104: viem.maxInt104,
maxInt112: viem.maxInt112,
maxInt120: viem.maxInt120,
maxInt128: viem.maxInt128,
maxInt136: viem.maxInt136,
maxInt144: viem.maxInt144,
maxInt152: viem.maxInt152,
maxInt160: viem.maxInt160,
maxInt168: viem.maxInt168,
maxInt176: viem.maxInt176,
maxInt184: viem.maxInt184,
maxInt192: viem.maxInt192,
maxInt200: viem.maxInt200,
maxInt208: viem.maxInt208,
maxInt216: viem.maxInt216,
maxInt224: viem.maxInt224,
maxInt232: viem.maxInt232,
maxInt240: viem.maxInt240,
maxInt248: viem.maxInt248,
maxInt256: viem.maxInt256,
minInt8: viem.minInt8,
minInt16: viem.minInt16,
minInt24: viem.minInt24,
minInt32: viem.minInt32,
minInt40: viem.minInt40,
minInt48: viem.minInt48,
minInt56: viem.minInt56,
minInt64: viem.minInt64,
minInt72: viem.minInt72,
minInt80: viem.minInt80,
minInt88: viem.minInt88,
minInt96: viem.minInt96,
minInt104: viem.minInt104,
minInt112: viem.minInt112,
minInt120: viem.minInt120,
minInt128: viem.minInt128,
minInt136: viem.minInt136,
minInt144: viem.minInt144,
minInt152: viem.minInt152,
minInt160: viem.minInt160,
minInt168: viem.minInt168,
minInt176: viem.minInt176,
minInt184: viem.minInt184,
minInt192: viem.minInt192,
minInt200: viem.minInt200,
minInt208: viem.minInt208,
minInt216: viem.minInt216,
minInt224: viem.minInt224,
minInt232: viem.minInt232,
minInt240: viem.minInt240,
minInt248: viem.minInt248,
minInt256: viem.minInt256,
maxUint8: viem.maxUint8,
maxUint16: viem.maxUint16,
maxUint24: viem.maxUint24,
maxUint32: viem.maxUint32,
maxUint40: viem.maxUint40,
maxUint48: viem.maxUint48,
maxUint56: viem.maxUint56,
maxUint64: viem.maxUint64,
maxUint72: viem.maxUint72,
maxUint80: viem.maxUint80,
maxUint88: viem.maxUint88,
maxUint96: viem.maxUint96,
maxUint104: viem.maxUint104,
maxUint112: viem.maxUint112,
maxUint120: viem.maxUint120,
maxUint128: viem.maxUint128,
maxUint136: viem.maxUint136,
maxUint144: viem.maxUint144,
maxUint152: viem.maxUint152,
maxUint160: viem.maxUint160,
maxUint168: viem.maxUint168,
maxUint176: viem.maxUint176,
maxUint184: viem.maxUint184,
maxUint192: viem.maxUint192,
maxUint200: viem.maxUint200,
maxUint208: viem.maxUint208,
maxUint216: viem.maxUint216,
maxUint224: viem.maxUint224,
maxUint232: viem.maxUint232,
maxUint240: viem.maxUint240,
maxUint248: viem.maxUint248,
maxUint256: viem.maxUint256,

// viem/constants/address
zeroAddress: viem.zeroAddress,

// viem/constants/bytes
zeroHash: viem.zeroHash,
};
10 changes: 6 additions & 4 deletions packages/cli/src/commands/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ export const commandsConfig: CommandsConfig = {
],
},
trace: {
description: 'Get a full stack trace for a transaction hash or explicit transaction call',
description:
'Get a full stack trace for a transaction hash or explicit transaction call. This command will spin up a local fork and simulate the given transaction.',
arguments: [
{
flags: '<packageRef>',
Expand Down Expand Up @@ -636,15 +637,16 @@ export const commandsConfig: CommandsConfig = {
],
},
decode: {
description: 'decode transaction data using the ABIs of the given Cannon package',
description:
'Decode the given data using the ABIs from the specified Cannon package. It will try to parse the data as Function Call, Error or Event. If a tx hash is given it will fetch it using the rpc and try to parse the input.',
arguments: [
{
flags: '<packageRef>',
description: 'Name, version and preset of the package to decode from (name:version@preset)',
},
{
flags: '<transactionHash OR bytes32Data>',
description: 'bytes32 encoded transaction data, or transaction hash',
flags: '<transactionHash OR hexData>',
description: 'hex encoded transaction data or a transaction hash',
},
],
options: [
Expand Down
Loading

0 comments on commit f762635

Please sign in to comment.