-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b85494
commit 7ae2991
Showing
25 changed files
with
397 additions
and
47 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.19; | ||
|
||
contract DefaultOApp {} | ||
contract DefaultOApp { | ||
mapping(uint256 => address) public peers; | ||
|
||
function setPeer(uint256 eid, address peer) external { | ||
peers[eid] = 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
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
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
36 changes: 24 additions & 12 deletions
36
packages/ua-utils-evm-hardhat/src/omnigraph/coordinates.ts
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 |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import 'hardhat-deploy/dist/src/type-extensions' | ||
import '@layerzerolabs/utils-evm-hardhat/type-extensions' | ||
import type { Contract } from '@ethersproject/contracts' | ||
import type { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import type { OmniPoint } from '@layerzerolabs/ua-utils' | ||
import type { Deployment } from 'hardhat-deploy/types' | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
import { assertHardhatDeploy } from '@/internal/assertions' | ||
import { getNetworkNamesByEid, getNetworkRuntimeEnvironment } from '@layerzerolabs/utils-evm-hardhat' | ||
|
||
export const contractNameToPoint = async ( | ||
export const eidAndDeploymentToPoint = (eid: EndpointId, { address }: Deployment): OmniPoint => ({ | ||
eid, | ||
address, | ||
}) | ||
|
||
export const eidAndContractToPoint = (eid: EndpointId, { address }: Contract): OmniPoint => ({ | ||
eid, | ||
address, | ||
}) | ||
|
||
export const contractNameToDeployments = async ( | ||
hre: HardhatRuntimeEnvironment, | ||
contractName: string | ||
): Promise<OmniPoint | undefined> => { | ||
): Promise<Map<EndpointId, Deployment>> => { | ||
assertHardhatDeploy(hre) | ||
|
||
const eid = hre.network.config.endpointId | ||
if (eid == null) return undefined | ||
const deploymentsByEid: Map<EndpointId, Deployment> = new Map() | ||
const networkNamesByEid = getNetworkNamesByEid(hre) | ||
|
||
const deployment = await hre.deployments.getOrNull(contractName) | ||
if (deployment == null) return undefined | ||
for (const [eid, networkName] of networkNamesByEid) { | ||
const env = await getNetworkRuntimeEnvironment(networkName) | ||
const deployment = await env.deployments.getOrNull(contractName) | ||
if (deployment == null) continue | ||
|
||
return eidAndDeploymentToPoint(eid, deployment) | ||
} | ||
deploymentsByEid.set(eid, deployment) | ||
} | ||
|
||
export const eidAndDeploymentToPoint = (eid: EndpointId, { address }: Deployment): OmniPoint => ({ | ||
eid, | ||
address, | ||
}) | ||
return deploymentsByEid | ||
} |
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 @@ | ||
.turbo | ||
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 @@ | ||
{ | ||
"extends": "../../.eslintrc.json" | ||
} |
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,23 @@ | ||
<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 | ||
|
||
```sh | ||
$ 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,8 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
}; |
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,55 @@ | ||
{ | ||
"name": "@layerzerolabs/ua-utils-evm", | ||
"version": "0.1.0", | ||
"private": true, | ||
"description": "Utilities for working with LayerZero contracts", | ||
"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" | ||
}, | ||
"devDependencies": { | ||
"@ethersproject/constants": "^5.7.0", | ||
"@ethersproject/contracts": "^5.7.0", | ||
"@layerzerolabs/lz-definitions": "~1.5.62", | ||
"@layerzerolabs/test-utils": "~0.0.1", | ||
"@layerzerolabs/ua-utils": "~0.1.0", | ||
"@layerzerolabs/utils-evm": "~0.0.1", | ||
"@types/jest": "^29.5.10", | ||
"fast-check": "^3.14.0", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tslib": "~2.6.2", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"zod": "^3.22.4" | ||
}, | ||
"peerDependencies": { | ||
"@layerzerolabs/lz-definitions": "~1.5.62", | ||
"@layerzerolabs/ua-utils": "~0.0.1", | ||
"@layerzerolabs/utils-evm": "~0.0.1", | ||
"zod": "^3.22.4" | ||
} | ||
} |
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,20 @@ | ||
import { Address, OAppSdk, OmniTransaction } from '@layerzerolabs/ua-utils' | ||
import { omniContractToPoint, OmniContract, ignoreZero } from '@layerzerolabs/utils-evm' | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
|
||
export class OAppEvmSdk implements OAppSdk { | ||
constructor(public readonly contract: OmniContract) {} | ||
|
||
async peers(eid: EndpointId): Promise<string | undefined> { | ||
return ignoreZero(await this.contract.contract.peers(eid)) | ||
} | ||
|
||
async setPeer(eid: EndpointId, address: Address): Promise<OmniTransaction> { | ||
const data = this.contract.contract.interface.encodeFunctionData('setPeer', [eid, address]) | ||
|
||
return { | ||
point: omniContractToPoint(this.contract), | ||
data, | ||
} | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"exclude": ["dist", "node_modules"], | ||
"include": ["src", "test"], | ||
"compilerOptions": { | ||
"types": ["node", "jest"], | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
} | ||
} |
Oops, something went wrong.