-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New version of ua-utils-evm with an example setPeer property
- Loading branch information
1 parent
69a6e07
commit b777f4a
Showing
12 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
artifacts | ||
cache | ||
deployments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extensions": ["ts"], | ||
"spec": ["**/*.test.*"], | ||
"loader": "ts-node/esm" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./oapp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "dist", "test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}) |