Skip to content

Commit

Permalink
feat: omnicounter sdk factory
Browse files Browse the repository at this point in the history
- rename everything to OmniCounter, dropping App.
- adapt to new OApp super constructor.
- make endpointFactory protected in OApp so it can be inherited.

Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Dec 13, 2023
1 parent 878f278 commit 70d8b12
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions packages/omnicounter-utils-evm/src/omnicounter/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pMemoize from 'p-memoize'
import { OmniCounter } 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 `OmniCounter` 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 createOmniCounterFactory = (
contractFactory: OmniContractFactory,
endpointFactory: EndpointFactory = createEndpointFactory(contractFactory)
): OAppFactory<OmniCounter> => pMemoize(async (point) => new OmniCounter(await contractFactory(point), endpointFactory))
1 change: 1 addition & 0 deletions packages/omnicounter-utils-evm/src/omnicounter/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './factory'
export * from './sdk'
13 changes: 11 additions & 2 deletions packages/omnicounter-utils-evm/src/omnicounter/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { IOmniCounterApp } from '@layerzerolabs/omnicounter-utils'
import { IOmniCounter } from '@layerzerolabs/omnicounter-utils'
import { EndpointFactory } from '@layerzerolabs/protocol-utils'
import { OApp } from '@layerzerolabs/ua-utils-evm'
import { OmniTransaction } from '@layerzerolabs/utils'
import { OmniContract } from '@layerzerolabs/utils-evm'

export class OmniCounter extends OApp implements IOmniCounter {
public constructor(
public override contract: OmniContract,
protected override endpointFactory: EndpointFactory
) {
super(contract, endpointFactory)
}

export class OmniCounterApp extends OApp implements IOmniCounterApp {
public async increment(eid: number, type: number, options: string): Promise<OmniTransaction> {
const data = this.contract.contract.interface.encodeFunctionData('increment', [eid, type, options])
return super.createTransaction(data)
Expand Down
2 changes: 1 addition & 1 deletion packages/omnicounter-utils/src/omnicounter/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OmniTransaction } from '@layerzerolabs/utils'
import { EndpointId } from '@layerzerolabs/lz-definitions'

export interface IOmniCounterApp {
export interface IOmniCounter {
increment(eid: EndpointId, type: number, options: string): Promise<OmniTransaction>
}
2 changes: 1 addition & 1 deletion packages/ua-utils-evm/src/oapp/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { OmniSDK } from '@layerzerolabs/utils-evm'
export class OApp extends OmniSDK implements IOApp {
constructor(
contract: OmniContract,
private readonly endpointFactory: EndpointFactory
protected readonly endpointFactory: EndpointFactory
) {
super(contract)
}
Expand Down

0 comments on commit 70d8b12

Please sign in to comment.