Skip to content

Commit

Permalink
feat: Add bytesToBool function (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukema95 authored Jun 14, 2024
1 parent 916dab5 commit 779147b
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 2 deletions.
13 changes: 13 additions & 0 deletions contracts/BytesHelperLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity =0.8.7;

library BytesHelperLib {
error OffsetOutOfBounds();

function bytesToAddress(
bytes calldata data,
uint256 offset
Expand Down Expand Up @@ -48,4 +50,15 @@ library BytesHelperLib {

return bech32Bytes;
}

function bytesToBool(bytes calldata data, uint256 offset)
internal
pure
returns (bool)
{
if (offset >= data.length) {
revert OffsetOutOfBounds();
}
return uint8(data[offset]) != 0;
}
}
55 changes: 55 additions & 0 deletions typechain-types/contracts/BytesHelperLib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type { BaseContract, Signer, utils } from "ethers";

import type { Listener, Provider } from "@ethersproject/providers";
import type {
TypedEventFilter,
TypedEvent,
TypedListener,
OnEvent,
} from "../common";

export interface BytesHelperLibInterface extends utils.Interface {
functions: {};

events: {};
}

export interface BytesHelperLib extends BaseContract {
connect(signerOrProvider: Signer | Provider | string): this;
attach(addressOrName: string): this;
deployed(): Promise<this>;

interface: BytesHelperLibInterface;

queryFilter<TEvent extends TypedEvent>(
event: TypedEventFilter<TEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TEvent>>;

listeners<TEvent extends TypedEvent>(
eventFilter?: TypedEventFilter<TEvent>
): Array<TypedListener<TEvent>>;
listeners(eventName?: string): Array<Listener>;
removeAllListeners<TEvent extends TypedEvent>(
eventFilter: TypedEventFilter<TEvent>
): this;
removeAllListeners(eventName?: string): this;
off: OnEvent<this>;
on: OnEvent<this>;
once: OnEvent<this>;
removeListener: OnEvent<this>;

functions: {};

callStatic: {};

filters: {};

estimateGas: {};

populateTransaction: {};
}
1 change: 1 addition & 0 deletions typechain-types/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type * as zetaConnectorMockSol from "./ZetaConnectorMock.sol";
export type { zetaConnectorMockSol };
import type * as shared from "./shared";
export type { shared };
export type { BytesHelperLib } from "./BytesHelperLib";
export type { OnlySystem } from "./OnlySystem";
export type { SwapHelperLib } from "./SwapHelperLib";
export type { TestSystemContract } from "./TestSystemContract";
Expand Down
68 changes: 68 additions & 0 deletions typechain-types/factories/contracts/BytesHelperLib__factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
import type { Provider, TransactionRequest } from "@ethersproject/providers";
import type { PromiseOrValue } from "../../common";
import type {
BytesHelperLib,
BytesHelperLibInterface,
} from "../../contracts/BytesHelperLib";

const _abi = [
{
inputs: [],
name: "OffsetOutOfBounds",
type: "error",
},
] as const;

const _bytecode =
"0x60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220db9c0f1b135916f15772ca92fae45f42347adcdba0acca9f1f72dea8794c690664736f6c63430008070033";

type BytesHelperLibConstructorParams =
| [signer?: Signer]
| ConstructorParameters<typeof ContractFactory>;

const isSuperArgs = (
xs: BytesHelperLibConstructorParams
): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;

export class BytesHelperLib__factory extends ContractFactory {
constructor(...args: BytesHelperLibConstructorParams) {
if (isSuperArgs(args)) {
super(...args);
} else {
super(_abi, _bytecode, args[0]);
}
}

override deploy(
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BytesHelperLib> {
return super.deploy(overrides || {}) as Promise<BytesHelperLib>;
}
override getDeployTransaction(
overrides?: Overrides & { from?: PromiseOrValue<string> }
): TransactionRequest {
return super.getDeployTransaction(overrides || {});
}
override attach(address: string): BytesHelperLib {
return super.attach(address) as BytesHelperLib;
}
override connect(signer: Signer): BytesHelperLib__factory {
return super.connect(signer) as BytesHelperLib__factory;
}

static readonly bytecode = _bytecode;
static readonly abi = _abi;
static createInterface(): BytesHelperLibInterface {
return new utils.Interface(_abi) as BytesHelperLibInterface;
}
static connect(
address: string,
signerOrProvider: Signer | Provider
): BytesHelperLib {
return new Contract(address, _abi, signerOrProvider) as BytesHelperLib;
}
}
2 changes: 1 addition & 1 deletion typechain-types/factories/contracts/TestZRC20__factory.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions typechain-types/factories/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export * as ethZetaMockSol from "./EthZetaMock.sol";
export * as zetaConnectorMockSol from "./ZetaConnectorMock.sol";
export * as shared from "./shared";
export { BytesHelperLib__factory } from "./BytesHelperLib__factory";
export { OnlySystem__factory } from "./OnlySystem__factory";
export { SwapHelperLib__factory } from "./SwapHelperLib__factory";
export { TestSystemContract__factory } from "./TestSystemContract__factory";
Expand Down

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions typechain-types/hardhat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ declare module "hardhat/types/runtime" {
name: "SystemContractErrors",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.SystemContractErrors__factory>;
getContractFactory(
name: "BytesHelperLib",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.BytesHelperLib__factory>;
getContractFactory(
name: "ZetaEthMock",
signerOrOptions?: ethers.Signer | FactoryOptions
Expand Down Expand Up @@ -289,6 +293,11 @@ declare module "hardhat/types/runtime" {
address: string,
signer?: ethers.Signer
): Promise<Contracts.SystemContractErrors>;
getContractAt(
name: "BytesHelperLib",
address: string,
signer?: ethers.Signer
): Promise<Contracts.BytesHelperLib>;
getContractAt(
name: "ZetaEthMock",
address: string,
Expand Down
2 changes: 2 additions & 0 deletions typechain-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export type { SystemContract } from "./@zetachain/protocol-contracts/contracts/z
export { SystemContract__factory } from "./factories/@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol/SystemContract__factory";
export type { SystemContractErrors } from "./@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol/SystemContractErrors";
export { SystemContractErrors__factory } from "./factories/@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol/SystemContractErrors__factory";
export type { BytesHelperLib } from "./contracts/BytesHelperLib";
export { BytesHelperLib__factory } from "./factories/contracts/BytesHelperLib__factory";
export type { ZetaEthMock } from "./contracts/EthZetaMock.sol/ZetaEthMock";
export { ZetaEthMock__factory } from "./factories/contracts/EthZetaMock.sol/ZetaEthMock__factory";
export type { OnlySystem } from "./contracts/OnlySystem";
Expand Down

0 comments on commit 779147b

Please sign in to comment.