Skip to content

Commit

Permalink
make id and rpc optional in EvmParachian if is not Evm Signer - enfor…
Browse files Browse the repository at this point in the history
…ce in typescipt
  • Loading branch information
mmaurello committed Jan 31, 2025
1 parent abaac98 commit 4d2519c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 0 additions & 2 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,9 @@ export const laosAlphanet = new EvmParachain({
'0x324e69fa1a64c0b3badec0016aca64878bc2f4b6146e6da26c7aaddee21947f7',
key: 'laos-alphanet',
name: 'Laos Alphanet',
id: 0, // TODO
isTestChain: true,
nativeAsset: maos,
parachainId: 4001,
rpc: 'https://rpc.laosalphanet.gorengine.com', // TODO
ss58Format: 42,
ws: ['wss://rpc.laosalphanet.gorengine.com'],
});
Expand Down
40 changes: 23 additions & 17 deletions packages/types/src/chain/parachain/EvmParachain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ import { getViemChain } from '../Chain.utils';
import { EvmChain } from '../EvmChain';
import { Parachain, type ParachainConstructorParams } from './Parachain';

export interface EvmParachainConstructorParams
extends ParachainConstructorParams {
id: number;
rpc: string;
interface EvmParachainConstructorParams extends ParachainConstructorParams {
isEvmSigner?: boolean;
contracts?: Contracts;
}

type EvmParachainConstructorParamsForEvmSigner =
EvmParachainConstructorParams & {
id: number;
rpc: string;
};

type EvmParachainConstructorParamsForNonEvmSigner = Omit<
EvmParachainConstructorParams,
'id' | 'rpc'
>;

type EvmParachainConstructorParamsConditional =
| (EvmParachainConstructorParamsForEvmSigner & { isEvmSigner: true })
| (EvmParachainConstructorParamsForNonEvmSigner & { isEvmSigner?: false });

type Contracts = {
Batch?: Address;
XcmUtils?: Address;
Expand Down Expand Up @@ -39,19 +51,13 @@ export class EvmParachain extends Parachain {
return obj instanceof EvmParachain || obj instanceof EvmChain;
}

constructor({
id,
rpc,
isEvmSigner = false,
contracts,
...others
}: EvmParachainConstructorParams) {
super(others);

this.contracts = contracts;
this.id = id;
this.rpc = rpc;
this.isEvmSigner = isEvmSigner;
constructor(params: EvmParachainConstructorParamsConditional) {
super(params);

this.contracts = params.contracts;
this.id = 'id' in params ? params.id : 0;
this.rpc = 'rpc' in params ? params.rpc : '';
this.isEvmSigner = params.isEvmSigner ?? false;
}

getViemChain(): Chain {
Expand Down

0 comments on commit 4d2519c

Please sign in to comment.