From 12bf62c8e78afc8067aa818ae0e8a48e2eebc850 Mon Sep 17 00:00:00 2001 From: Ryan Goulding Date: Sat, 9 Dec 2023 16:25:19 -0800 Subject: [PATCH] feat: omnicounter-utils (#92) Signed-off-by: Ryan Goulding --- packages/omnicounter-utils-evm/.eslintignore | 3 + packages/omnicounter-utils-evm/.eslintrc.json | 3 + packages/omnicounter-utils-evm/README.md | 23 ++++++++ packages/omnicounter-utils-evm/jest.config.js | 8 +++ packages/omnicounter-utils-evm/package.json | 55 +++++++++++++++++++ packages/omnicounter-utils-evm/src/index.ts | 1 + .../src/omnicounter/index.ts | 1 + .../src/omnicounter/sdk.ts | 10 ++++ packages/omnicounter-utils-evm/tsconfig.json | 11 ++++ packages/omnicounter-utils-evm/tsup.config.ts | 12 ++++ packages/omnicounter-utils/.eslintignore | 3 + packages/omnicounter-utils/.eslintrc.json | 3 + packages/omnicounter-utils/README.md | 23 ++++++++ packages/omnicounter-utils/jest.config.js | 8 +++ packages/omnicounter-utils/package.json | 50 +++++++++++++++++ packages/omnicounter-utils/src/index.ts | 1 + .../src/omnicounter/types.ts | 6 ++ packages/omnicounter-utils/tsconfig.json | 11 ++++ packages/omnicounter-utils/tsup.config.ts | 12 ++++ 19 files changed, 244 insertions(+) create mode 100644 packages/omnicounter-utils-evm/.eslintignore create mode 100644 packages/omnicounter-utils-evm/.eslintrc.json create mode 100644 packages/omnicounter-utils-evm/README.md create mode 100644 packages/omnicounter-utils-evm/jest.config.js create mode 100644 packages/omnicounter-utils-evm/package.json create mode 100644 packages/omnicounter-utils-evm/src/index.ts create mode 100644 packages/omnicounter-utils-evm/src/omnicounter/index.ts create mode 100644 packages/omnicounter-utils-evm/src/omnicounter/sdk.ts create mode 100644 packages/omnicounter-utils-evm/tsconfig.json create mode 100644 packages/omnicounter-utils-evm/tsup.config.ts create mode 100644 packages/omnicounter-utils/.eslintignore create mode 100644 packages/omnicounter-utils/.eslintrc.json create mode 100644 packages/omnicounter-utils/README.md create mode 100644 packages/omnicounter-utils/jest.config.js create mode 100644 packages/omnicounter-utils/package.json create mode 100644 packages/omnicounter-utils/src/index.ts create mode 100644 packages/omnicounter-utils/src/omnicounter/types.ts create mode 100644 packages/omnicounter-utils/tsconfig.json create mode 100644 packages/omnicounter-utils/tsup.config.ts diff --git a/packages/omnicounter-utils-evm/.eslintignore b/packages/omnicounter-utils-evm/.eslintignore new file mode 100644 index 000000000..0f295f243 --- /dev/null +++ b/packages/omnicounter-utils-evm/.eslintignore @@ -0,0 +1,3 @@ +.turbo +dist +node_modules \ No newline at end of file diff --git a/packages/omnicounter-utils-evm/.eslintrc.json b/packages/omnicounter-utils-evm/.eslintrc.json new file mode 100644 index 000000000..be97c53fb --- /dev/null +++ b/packages/omnicounter-utils-evm/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../.eslintrc.json" +} diff --git a/packages/omnicounter-utils-evm/README.md b/packages/omnicounter-utils-evm/README.md new file mode 100644 index 000000000..82e40cd04 --- /dev/null +++ b/packages/omnicounter-utils-evm/README.md @@ -0,0 +1,23 @@ +

+ + LayerZero + +

+ +

@layerzerolabs/omnicounter-utils-evm

+ + +

+ + NPM Version + + Downloads + + NPM License +

+ +## Installation + +```sh +$ npm install @layerzerolabs/omnicounter-utils-evm +``` diff --git a/packages/omnicounter-utils-evm/jest.config.js b/packages/omnicounter-utils-evm/jest.config.js new file mode 100644 index 000000000..16148cfb1 --- /dev/null +++ b/packages/omnicounter-utils-evm/jest.config.js @@ -0,0 +1,8 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, +}; diff --git a/packages/omnicounter-utils-evm/package.json b/packages/omnicounter-utils-evm/package.json new file mode 100644 index 000000000..ef12a2f3c --- /dev/null +++ b/packages/omnicounter-utils-evm/package.json @@ -0,0 +1,55 @@ +{ + "name": "@layerzerolabs/omnicounter-utils-evm", + "version": "0.0.1", + "private": true, + "description": "Utilities for working with LayerZero OmniCounter contract", + "repository": { + "type": "git", + "url": "git+https://github.com/LayerZero-Labs/lz-utils.git", + "directory": "packages/ua-utils-evm" + }, + "license": "MIT", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js", + "import": "./dist/index.mjs" + } + }, + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", + "files": [ + "dist/" + ], + "scripts": { + "prebuild": "tsc -noEmit", + "build": "npx tsup", + "clean": "rm -rf dist", + "lint": "npx eslint '**/*.{js,ts,json}'", + "test": "jest --passWithNoTests" + }, + "devDependencies": { + "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/omnicounter-utils": "~0.0.1", + "@layerzerolabs/ua-utils": "~0.1.0", + "@layerzerolabs/ua-utils-evm": "~0.0.1", + "@layerzerolabs/utils-evm": "~0.0.1", + "@types/jest": "^29.5.10", + "jest": "^29.7.0", + "ts-jest": "^29.1.1", + "ts-node": "^10.9.1", + "tslib": "~2.6.2", + "tsup": "~8.0.1", + "typescript": "^5.2.2", + "zod": "^3.22.4" + }, + "peerDependencies": { + "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/omnicounter-utils": "~0.0.1", + "@layerzerolabs/ua-utils": "~0.1.0", + "@layerzerolabs/ua-utils-evm": "~0.0.1", + "@layerzerolabs/utils-evm": "~0.0.1", + "zod": "^3.22.4" + } +} diff --git a/packages/omnicounter-utils-evm/src/index.ts b/packages/omnicounter-utils-evm/src/index.ts new file mode 100644 index 000000000..6ab4b696d --- /dev/null +++ b/packages/omnicounter-utils-evm/src/index.ts @@ -0,0 +1 @@ +export * from './omnicounter' diff --git a/packages/omnicounter-utils-evm/src/omnicounter/index.ts b/packages/omnicounter-utils-evm/src/omnicounter/index.ts new file mode 100644 index 000000000..7db67b18a --- /dev/null +++ b/packages/omnicounter-utils-evm/src/omnicounter/index.ts @@ -0,0 +1 @@ +export * from './sdk' diff --git a/packages/omnicounter-utils-evm/src/omnicounter/sdk.ts b/packages/omnicounter-utils-evm/src/omnicounter/sdk.ts new file mode 100644 index 000000000..fb8aa5feb --- /dev/null +++ b/packages/omnicounter-utils-evm/src/omnicounter/sdk.ts @@ -0,0 +1,10 @@ +import { IOmniCounterApp } from '@layerzerolabs/omnicounter-utils' +import { OApp } from '@layerzerolabs/ua-utils-evm' +import { OmniTransaction } from '@layerzerolabs/utils' + +export class OmniCounterApp extends OApp implements IOmniCounterApp { + public async increment(eid: number, type: number, options: string): Promise { + const data = this.contract.contract.interface.encodeFunctionData('increment', [eid, type, options]) + return super.createTransaction(data) + } +} diff --git a/packages/omnicounter-utils-evm/tsconfig.json b/packages/omnicounter-utils-evm/tsconfig.json new file mode 100644 index 000000000..f083b2ecb --- /dev/null +++ b/packages/omnicounter-utils-evm/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "exclude": ["dist", "node_modules"], + "include": ["src", "test"], + "compilerOptions": { + "types": ["node", "jest"], + "paths": { + "@/*": ["./src/*"] + } + } +} diff --git a/packages/omnicounter-utils-evm/tsup.config.ts b/packages/omnicounter-utils-evm/tsup.config.ts new file mode 100644 index 000000000..b0e373950 --- /dev/null +++ b/packages/omnicounter-utils-evm/tsup.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'tsup' + +export default defineConfig({ + entry: ['src/index.ts'], + outDir: './dist', + clean: true, + dts: true, + sourcemap: true, + splitting: false, + treeshake: true, + format: ['esm', 'cjs'], +}) diff --git a/packages/omnicounter-utils/.eslintignore b/packages/omnicounter-utils/.eslintignore new file mode 100644 index 000000000..0f295f243 --- /dev/null +++ b/packages/omnicounter-utils/.eslintignore @@ -0,0 +1,3 @@ +.turbo +dist +node_modules \ No newline at end of file diff --git a/packages/omnicounter-utils/.eslintrc.json b/packages/omnicounter-utils/.eslintrc.json new file mode 100644 index 000000000..be97c53fb --- /dev/null +++ b/packages/omnicounter-utils/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../.eslintrc.json" +} diff --git a/packages/omnicounter-utils/README.md b/packages/omnicounter-utils/README.md new file mode 100644 index 000000000..e4cafafd7 --- /dev/null +++ b/packages/omnicounter-utils/README.md @@ -0,0 +1,23 @@ +

+ + LayerZero + +

+ +

@layerzerolabs/omnicounter-utils

+ + +

+ + NPM Version + + Downloads + + NPM License +

+ +## Installation + +```sh +$ npm install @layerzerolabs/omnicounter-utils +``` diff --git a/packages/omnicounter-utils/jest.config.js b/packages/omnicounter-utils/jest.config.js new file mode 100644 index 000000000..16148cfb1 --- /dev/null +++ b/packages/omnicounter-utils/jest.config.js @@ -0,0 +1,8 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, +}; diff --git a/packages/omnicounter-utils/package.json b/packages/omnicounter-utils/package.json new file mode 100644 index 000000000..608da103f --- /dev/null +++ b/packages/omnicounter-utils/package.json @@ -0,0 +1,50 @@ +{ + "name": "@layerzerolabs/omnicounter-utils", + "version": "0.0.1", + "private": true, + "description": "Utilities for working with LayerZero OmniCounter contract", + "repository": { + "type": "git", + "url": "git+https://github.com/LayerZero-Labs/lz-utils.git", + "directory": "packages/omnicounter-utils" + }, + "license": "MIT", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js", + "import": "./dist/index.mjs" + } + }, + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", + "files": [ + "dist/", + "LICENSE" + ], + "scripts": { + "prebuild": "tsc -noEmit", + "build": "npx tsup", + "clean": "rm -rf dist", + "lint": "npx eslint '**/*.{js,ts,json}'", + "test": "jest --passWithNoTests" + }, + "devDependencies": { + "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/utils": "~0.0.1", + "@types/jest": "^29.5.10", + "jest": "^29.7.0", + "ts-jest": "^29.1.1", + "ts-node": "^10.9.1", + "tslib": "~2.6.2", + "tsup": "~8.0.1", + "typescript": "^5.2.2", + "zod": "^3.22.4" + }, + "peerDependencies": { + "@layerzerolabs/lz-definitions": "~1.5.70", + "@layerzerolabs/utils": "~0.0.1", + "zod": "^3.22.4" + } +} diff --git a/packages/omnicounter-utils/src/index.ts b/packages/omnicounter-utils/src/index.ts new file mode 100644 index 000000000..04ee4a493 --- /dev/null +++ b/packages/omnicounter-utils/src/index.ts @@ -0,0 +1 @@ +export * from './omnicounter/types' diff --git a/packages/omnicounter-utils/src/omnicounter/types.ts b/packages/omnicounter-utils/src/omnicounter/types.ts new file mode 100644 index 000000000..ffea90f87 --- /dev/null +++ b/packages/omnicounter-utils/src/omnicounter/types.ts @@ -0,0 +1,6 @@ +import { OmniTransaction } from '@layerzerolabs/utils' +import { EndpointId } from '@layerzerolabs/lz-definitions' + +export interface IOmniCounterApp { + increment(eid: EndpointId, type: number, options: string): Promise +} diff --git a/packages/omnicounter-utils/tsconfig.json b/packages/omnicounter-utils/tsconfig.json new file mode 100644 index 000000000..f083b2ecb --- /dev/null +++ b/packages/omnicounter-utils/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "exclude": ["dist", "node_modules"], + "include": ["src", "test"], + "compilerOptions": { + "types": ["node", "jest"], + "paths": { + "@/*": ["./src/*"] + } + } +} diff --git a/packages/omnicounter-utils/tsup.config.ts b/packages/omnicounter-utils/tsup.config.ts new file mode 100644 index 000000000..b0e373950 --- /dev/null +++ b/packages/omnicounter-utils/tsup.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'tsup' + +export default defineConfig({ + entry: ['src/index.ts'], + outDir: './dist', + clean: true, + dts: true, + sourcemap: true, + splitting: false, + treeshake: true, + format: ['esm', 'cjs'], +})