Skip to content

Commit

Permalink
feat: abiwan v2 intergation
Browse files Browse the repository at this point in the history
  • Loading branch information
haroune-mohammedi committed Dec 29, 2023
1 parent dba65f3 commit 87d15d3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"abi-wan-kanabi": "^1.0.3",
"abi-wan-kanabi-v2": "npm:abi-wan-kanabi@^2.1.0-rc.0",
"ajv": "^8.12.0",
"ajv-keywords": "^5.1.0",
"eslint": "^8.17.0",
Expand Down
7 changes: 7 additions & 0 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Abi as AbiKanabi } from 'abi-wan-kanabi';
import type { Abi as AbiKanabiV2, TypedContract as AbiWanTypedContractV2 } from 'abi-wan-kanabi-v2';

import { AccountInterface } from '../account';
import { ProviderInterface, defaultProvider } from '../provider';
Expand Down Expand Up @@ -32,6 +33,8 @@ import { getAbiEvents, parseEvents as parseRawEvents } from '../utils/events/ind
import { cleanHex } from '../utils/num';
import { ContractInterface, TypedContract } from './interface';

export type TypedContractV2<TAbi extends AbiKanabiV2> = AbiWanTypedContractV2<TAbi> & Contract;

export const splitArgsAndOptions = (args: ArgsOrCalldataWithOptions) => {
const options = [
'blockIdentifier',
Expand Down Expand Up @@ -349,4 +352,8 @@ export class Contract implements ContractInterface {
public typed<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContract<TAbi> {
return this as TypedContract<typeof tAbi>;
}

public typedv2<TAbi extends AbiKanabiV2>(tAbi: TAbi): TypedContractV2<TAbi> {
return this as unknown as TypedContractV2<typeof tAbi>;
}
}
29 changes: 29 additions & 0 deletions src/contract/interface.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { Abi as AbiKanabi, TypedContract as AbiWanTypedContract } from 'abi-wan-kanabi';
import type { Abi as AbiKanabiV2, TypedContract as AbiWanTypedContractV2 } from 'abi-wan-kanabi-v2';

import { AccountInterface } from '../account';
import { ProviderInterface } from '../provider';
import {
Abi,
ArgsOrCalldata,
AsyncContractFunction,
BigNumberish,
BlockIdentifier,
CallOptions,
Calldata,
ContractFunction,
ContractVersion,
EstimateFeeResponse,
Expand All @@ -16,10 +19,35 @@ import {
InvokeFunctionResponse,
InvokeOptions,
ParsedEvents,
RawArgs,
Result,
Uint256,
} from '../types';
import { CairoCustomEnum } from '../utils/calldata/enum/CairoCustomEnum';
import { CairoOption } from '../utils/calldata/enum/CairoOption';
import { CairoResult } from '../utils/calldata/enum/CairoResult';

// import { ResolvedConfig } from 'abi-wan-kanabi-v2/config';

declare module 'abi-wan-kanabi-v2' {
export interface Config<OptionT = any, ResultT = any, ErrorT = any> {
FeltType: BigNumberish;
U256Type: number | bigint | Uint256;
Option: CairoOption<OptionT>;
Tuple: Record<number, BigNumberish | object | boolean>;
Result: CairoResult<ResultT, ErrorT>;
Enum: CairoCustomEnum;
Calldata: RawArgs | Calldata;
CallOptions: CallOptions;
InvokeOptions: InvokeOptions;
InvokeFunctionResponse: InvokeFunctionResponse;
}
}

// export type X = ResolvedConfig['InvokeOptions'];

export type TypedContract<TAbi extends AbiKanabi> = AbiWanTypedContract<TAbi> & ContractInterface;
type TypedContractV2<TAbi extends AbiKanabiV2> = AbiWanTypedContractV2<TAbi> & ContractInterface;

export abstract class ContractInterface {
public abstract abi: Abi;
Expand Down Expand Up @@ -139,4 +167,5 @@ export abstract class ContractInterface {
public abstract getVersion(): Promise<ContractVersion>;

public abstract typed<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContract<TAbi>;
public abstract typedv2<TAbi extends AbiKanabiV2>(tAbi: TAbi): TypedContractV2<TAbi>;
}

0 comments on commit 87d15d3

Please sign in to comment.