-
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.
Signed-off-by: Ryan Goulding <[email protected]>
- Loading branch information
1 parent
1185ca7
commit 8334e95
Showing
12 changed files
with
2,248 additions
and
75 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,21 @@ | ||
import pMemoize from 'p-memoize' | ||
import { OmniCounterApp } from '@/omnicounter/sdk' | ||
import { createEndpointFactory } from '@layerzerolabs/protocol-utils-evm' | ||
import { EndpointFactory } from '@layerzerolabs/protocol-utils' | ||
import { OAppFactory } from '@layerzerolabs/ua-utils' | ||
import { OmniContractFactory } from '@layerzerolabs/utils-evm' | ||
|
||
/** | ||
* Syntactic sugar that creates an instance of EVM `OmniCounterApp` SDK | ||
* based on an `OmniPoint` with help of an `OmniContractFactory` | ||
* and an (optional) `EndpointFactory` | ||
* | ||
* @param {OmniContractFactory} contractFactory | ||
* @param {EndpointFactory} [endpointFactory] | ||
* @returns {EndpointFactory<Endpoint>} | ||
*/ | ||
export const createOmniCounterAppFactory = ( | ||
contractFactory: OmniContractFactory, | ||
endpointFactory: EndpointFactory = createEndpointFactory(contractFactory) | ||
): OAppFactory<OmniCounterApp> => | ||
pMemoize(async (point) => new OmniCounterApp(await contractFactory(point), endpointFactory)) |
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 +1,2 @@ | ||
export * from './factory' | ||
export * from './sdk' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import { OmniCounter as OmniCounterImpl } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/examples/OmniCounter.sol"; | ||
|
||
contract OmniCounterOApp is OmniCounterImpl { | ||
constructor(address _endpoint, address _owner) OmniCounterImpl(_endpoint, _owner) {} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
packages/ua-utils-evm-hardhat-test/deploy/003_omnicounteroapp.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { formatEid } from '@layerzerolabs/utils' | ||
import { type DeployFunction } from 'hardhat-deploy/types' | ||
import assert from 'assert' | ||
|
||
/** | ||
* This deploy function will deploy and configure LayerZero OmniCounter | ||
* | ||
* @param env `HardhatRuntimeEnvironment` | ||
*/ | ||
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => { | ||
assert(network.config.eid != null, `Missing endpoint ID for network ${network.name}`) | ||
|
||
const [deployer] = await getUnnamedAccounts() | ||
assert(deployer, 'Missing deployer') | ||
|
||
await deployments.delete('OmniCounterOApp') | ||
const endpointV2 = await deployments.get('EndpointV2') | ||
const omniCounterDeployment = await deployments.deploy('OmniCounterOApp', { | ||
from: deployer, | ||
args: [endpointV2.address, deployer], | ||
}) | ||
|
||
console.table({ | ||
Network: `${network.name} (endpoint ${formatEid(network.config.eid)})`, | ||
OmniCounterOApp: omniCounterDeployment.address, | ||
}) | ||
} | ||
|
||
deploy.tags = ['OApp', 'OmniCounterOApp'] | ||
deploy.dependencies = ['Bootstrap'] | ||
|
||
export default deploy |
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
10 changes: 10 additions & 0 deletions
10
packages/ua-utils-evm-hardhat-test/test/__utils__/omnicounter.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import { createNetworkEnvironmentFactory } from '@layerzerolabs/utils-evm-hardhat' | ||
import deploy from '../../deploy/003_omnicounteroapp' | ||
|
||
export const deployOmniCounter = async () => { | ||
const environmentFactory = createNetworkEnvironmentFactory() | ||
|
||
await deploy(await environmentFactory(EndpointId.ETHEREUM_MAINNET)) | ||
await deploy(await environmentFactory(EndpointId.AVALANCHE_MAINNET)) | ||
} |
89 changes: 89 additions & 0 deletions
89
packages/ua-utils-evm-hardhat-test/test/omnicounter/options.test.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'hardhat' | ||
import { TransactionReceipt } from '@ethersproject/providers' | ||
import { EndpointId, MainnetEndpointId } from '@layerzerolabs/lz-definitions' | ||
import { Options } from '@layerzerolabs/lz-utility-v2' | ||
import { createOmniCounterAppFactory } from '@layerzerolabs/omnicounter-utils-evm' | ||
import { configureOApp } from '@layerzerolabs/ua-utils' | ||
import { OmniTransaction } from '@layerzerolabs/utils' | ||
import { omniContractToPoint } from '@layerzerolabs/utils-evm' | ||
import { | ||
createConnectedContractFactory, | ||
createSignerFactory, | ||
OmniGraphBuilderHardhat, | ||
OmniGraphHardhat, | ||
} from '@layerzerolabs/utils-evm-hardhat' | ||
import { setupDefaultEndpoint } from '../__utils__/endpoint' | ||
import { deployOmniCounter } from '../__utils__/omnicounter' | ||
|
||
describe('oapp/options', () => { | ||
const ethContract = { eid: EndpointId.ETHEREUM_MAINNET, contractName: 'OmniCounterOApp' } | ||
const avaxContract = { eid: EndpointId.AVALANCHE_MAINNET, contractName: 'OmniCounterOApp' } | ||
|
||
const config: OmniGraphHardhat = { | ||
contracts: [ | ||
{ | ||
contract: ethContract, | ||
}, | ||
{ | ||
contract: avaxContract, | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
from: ethContract, | ||
to: avaxContract, | ||
}, | ||
{ | ||
from: avaxContract, | ||
to: ethContract, | ||
}, | ||
], | ||
} | ||
|
||
beforeEach(async () => { | ||
await setupDefaultEndpoint() | ||
await deployOmniCounter() | ||
}) | ||
|
||
it('lzReceive option', async () => { | ||
const contractFactory = createConnectedContractFactory() | ||
const builder = await OmniGraphBuilderHardhat.fromConfig(config) | ||
const sdkFactory = createOmniCounterAppFactory(contractFactory) | ||
const signerFactory = createSignerFactory() | ||
|
||
const ethPoint = omniContractToPoint(await contractFactory(ethContract)) | ||
const ethSdk = await sdkFactory(ethPoint) | ||
const ethSigner = await signerFactory(ethContract.eid) | ||
|
||
const avaxPoint = omniContractToPoint(await contractFactory(avaxContract)) | ||
const avaxSdk = await sdkFactory(avaxPoint) | ||
const avaxSigner = await signerFactory(avaxContract.eid) | ||
|
||
const transactions = await configureOApp(builder.graph, sdkFactory) | ||
for (const transaction of transactions) { | ||
const signer = transaction.point.eid === MainnetEndpointId.ETHEREUM_MAINNET ? ethSigner : avaxSigner | ||
const txResponse = await signer.signAndSend(transaction) | ||
const txReceipt: TransactionReceipt = await txResponse.wait() | ||
expect(txReceipt.status).toBe(1) | ||
} | ||
|
||
expect(await ethSdk.hasPeer(avaxPoint.eid, avaxPoint.address)).toBe(true) | ||
expect(await avaxSdk.hasPeer(ethPoint.eid, ethPoint.address)).toBe(true) | ||
|
||
const options = Options.newOptions().addExecutorLzReceiveOption(200000) | ||
console.dir( | ||
{ | ||
options: options.toHex(), | ||
}, | ||
{ depth: null } | ||
) | ||
const incrementTx: OmniTransaction = { | ||
...(await ethSdk.increment(avaxPoint.eid, 1, options.toHex())), | ||
gasLimit: 2000000, | ||
value: '1000000000000000000', | ||
} | ||
const incrementTxResponse = await ethSigner.signAndSend(incrementTx) | ||
const incrementTxReceipt: TransactionReceipt = await incrementTxResponse.wait() | ||
expect(incrementTxReceipt.status).toEqual(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
Oops, something went wrong.