Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: omnicounter sdk factory #113

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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