Skip to content

Commit

Permalink
feat: New version of ua-utils-evm with an example setPeer property
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Nov 21, 2023
1 parent 69a6e07 commit b777f4a
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ua-utils-evm/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions packages/ua-utils-evm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts
cache
deployments
5 changes: 5 additions & 0 deletions packages/ua-utils-evm/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extensions": ["ts"],
"spec": ["**/*.test.*"],
"loader": "ts-node/esm"
}
2 changes: 2 additions & 0 deletions packages/ua-utils-evm/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
27 changes: 27 additions & 0 deletions packages/ua-utils-evm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<p align="center">
<a href="https://layerzero.network">
<img alt="LayerZero" style="max-width: 500px" src="https://d3a2dpnnrypp5h.cloudfront.net/bridge-app/lz.png"/>
</a>
</p>

<h1 align="center">@layerzerolabs/ua-utils-evm</h1>

<!-- The badges section -->
<p align="center">
<!-- Shields.io NPM published package version -->
<a href="https://www.npmjs.com/package/@layerzerolabs/ua-utils-evm"><img alt="NPM Version" src="https://img.shields.io/npm/v/@layerzerolabs/ua-utils-evm"/></a>
<!-- Shields.io NPM downloads -->
<a href="https://www.npmjs.com/package/@layerzerolabs/ua-utils-evm"><img alt="Downloads" src="https://img.shields.io/npm/dm/@layerzerolabs/ua-utils-evm"/></a>
<!-- Shields.io license badge -->
<a href="https://www.npmjs.com/package/@layerzerolabs/ua-utils-evm"><img alt="NPM License" src="https://img.shields.io/npm/l/@layerzerolabs/ua-utils-evm"/></a>
</p>

## Installation

```bash
yarn add @layerzerolabs/ua-utils-evm

pnpm add @layerzerolabs/ua-utils-evm

npm install @layerzerolabs/ua-utils-evm
```
49 changes: 49 additions & 0 deletions packages/ua-utils-evm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@layerzerolabs/ua-utils-evm",
"description": "Utilities for working with LayerZero EVM projects",
"version": "0.0.1",
"license": "MIT",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"files": [
"./dist/index.*"
],
"scripts": {
"build": "npx tsup",
"clean": "rm -rf dist",
"dev": "npx tsup --watch",
"lint": "npx eslint '**/*.{js,ts,json}'",
"prebuild": "npx tsc --noEmit -p tsconfig.build.json",
"test": "mocha --parallel"
},
"repository": {
"type": "git",
"url": "git+https://github.com/LayerZero-Labs/lz-utils.git",
"directory": "packages/ua-utils-evm"
},
"devDependencies": {
"@ethersproject/contracts": "5.7.0",
"@layerzerolabs/lz-definitions": "~1.5.58",
"@layerzerolabs/ua-utils": "~0.1.0",
"@types/mocha": "^10.0.1",
"@types/sinon": "^17.0.2",
"chai": "^4.3.10",
"mocha": "^10.2.0",
"sinon": "^17.0.1",
"ts-node": "^10.9.1",
"tsup": "~7.2.0",
"typescript": "^5.2.2"
},
"peerDependencies": {
"@ethersproject/contracts": "5.7.0",
"@layerzerolabs/lz-definitions": "~1.5.58",
"@layerzerolabs/ua-utils": "~0.1.0"
}
}
1 change: 1 addition & 0 deletions packages/ua-utils-evm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./oapp"
14 changes: 14 additions & 0 deletions packages/ua-utils-evm/src/oapp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Contract } from "@ethersproject/contracts"
import { GetPropertyValue, createProperty } from "@layerzerolabs/ua-utils"
import { EndpointId } from "@layerzerolabs/lz-definitions"

type SetPeerConfigurableContext = [oapp: Contract, endpointId: EndpointId]

type SetPeerConfigurableValue = string

export const createSetPeerProperty = (desired: GetPropertyValue<SetPeerConfigurableContext, SetPeerConfigurableValue>) =>
createProperty<SetPeerConfigurableContext, SetPeerConfigurableValue>({
desired,
get: (oapp, endpointId) => oapp.peers(endpointId),
set: (oapp, endpointId, peer) => oapp.setPeer(endpointId, peer),
})
30 changes: 30 additions & 0 deletions packages/ua-utils-evm/test/oapp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Contract } from "@ethersproject/contracts"
import { EndpointId } from "@layerzerolabs/lz-definitions"
import { expect } from "chai"
import { describe } from "mocha"
import sinon from "sinon"
import { createSetPeerProperty } from "../src/oapp"
import { isMisconfigured } from "@layerzerolabs/ua-utils"

describe("oapp", () => {
describe("createSetPeerProperty", () => {
it("should check peers and return Misconfigured if they don't match", async () => {
const peers = sinon.stub().resolves("peer-not-set")
const setPeer = sinon.stub().resolves("okay")
const oapp = { peers, setPeer } as unknown as Contract

const desired = (oapp: Contract, endpointId: EndpointId) => `peer-on-${endpointId}`
const configurable = createSetPeerProperty(desired)
const state = await configurable(oapp, EndpointId.AAVEGOTCHI_TESTNET)

expect(isMisconfigured(state)).to.be.true
expect(state.value).to.eql("peer-not-set")
expect(state.desiredValue).to.eql(`peer-on-${EndpointId.AAVEGOTCHI_TESTNET}`)

const result = await state.configure?.()

expect(result).to.eql("okay")
expect(setPeer.calledOnceWith(EndpointId.AAVEGOTCHI_TESTNET, `peer-on-${EndpointId.AAVEGOTCHI_TESTNET}`)).to.be.true
})
})
})
4 changes: 4 additions & 0 deletions packages/ua-utils-evm/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist", "test"]
}
9 changes: 9 additions & 0 deletions packages/ua-utils-evm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"exclude": ["dist", "node_modules"],
"include": ["src", "test", "*.config.ts"],
"compilerOptions": {
"module": "commonjs",
"types": ["node", "mocha"]
}
}
12 changes: 12 additions & 0 deletions packages/ua-utils-evm/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -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"],
})

0 comments on commit b777f4a

Please sign in to comment.