Skip to content

Commit 87d15d3

Browse files
feat: abiwan v2 intergation
1 parent dba65f3 commit 87d15d3

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@typescript-eslint/eslint-plugin": "^5.28.0",
6969
"@typescript-eslint/parser": "^5.28.0",
7070
"abi-wan-kanabi": "^1.0.3",
71+
"abi-wan-kanabi-v2": "npm:abi-wan-kanabi@^2.1.0-rc.0",
7172
"ajv": "^8.12.0",
7273
"ajv-keywords": "^5.1.0",
7374
"eslint": "^8.17.0",

src/contract/default.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Abi as AbiKanabi } from 'abi-wan-kanabi';
2+
import type { Abi as AbiKanabiV2, TypedContract as AbiWanTypedContractV2 } from 'abi-wan-kanabi-v2';
23

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

36+
export type TypedContractV2<TAbi extends AbiKanabiV2> = AbiWanTypedContractV2<TAbi> & Contract;
37+
3538
export const splitArgsAndOptions = (args: ArgsOrCalldataWithOptions) => {
3639
const options = [
3740
'blockIdentifier',
@@ -349,4 +352,8 @@ export class Contract implements ContractInterface {
349352
public typed<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContract<TAbi> {
350353
return this as TypedContract<typeof tAbi>;
351354
}
355+
356+
public typedv2<TAbi extends AbiKanabiV2>(tAbi: TAbi): TypedContractV2<TAbi> {
357+
return this as unknown as TypedContractV2<typeof tAbi>;
358+
}
352359
}

src/contract/interface.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import type { Abi as AbiKanabi, TypedContract as AbiWanTypedContract } from 'abi-wan-kanabi';
2+
import type { Abi as AbiKanabiV2, TypedContract as AbiWanTypedContractV2 } from 'abi-wan-kanabi-v2';
23

34
import { AccountInterface } from '../account';
45
import { ProviderInterface } from '../provider';
56
import {
67
Abi,
78
ArgsOrCalldata,
89
AsyncContractFunction,
10+
BigNumberish,
911
BlockIdentifier,
1012
CallOptions,
13+
Calldata,
1114
ContractFunction,
1215
ContractVersion,
1316
EstimateFeeResponse,
@@ -16,10 +19,35 @@ import {
1619
InvokeFunctionResponse,
1720
InvokeOptions,
1821
ParsedEvents,
22+
RawArgs,
1923
Result,
24+
Uint256,
2025
} from '../types';
26+
import { CairoCustomEnum } from '../utils/calldata/enum/CairoCustomEnum';
27+
import { CairoOption } from '../utils/calldata/enum/CairoOption';
28+
import { CairoResult } from '../utils/calldata/enum/CairoResult';
29+
30+
// import { ResolvedConfig } from 'abi-wan-kanabi-v2/config';
31+
32+
declare module 'abi-wan-kanabi-v2' {
33+
export interface Config<OptionT = any, ResultT = any, ErrorT = any> {
34+
FeltType: BigNumberish;
35+
U256Type: number | bigint | Uint256;
36+
Option: CairoOption<OptionT>;
37+
Tuple: Record<number, BigNumberish | object | boolean>;
38+
Result: CairoResult<ResultT, ErrorT>;
39+
Enum: CairoCustomEnum;
40+
Calldata: RawArgs | Calldata;
41+
CallOptions: CallOptions;
42+
InvokeOptions: InvokeOptions;
43+
InvokeFunctionResponse: InvokeFunctionResponse;
44+
}
45+
}
46+
47+
// export type X = ResolvedConfig['InvokeOptions'];
2148

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

2452
export abstract class ContractInterface {
2553
public abstract abi: Abi;
@@ -139,4 +167,5 @@ export abstract class ContractInterface {
139167
public abstract getVersion(): Promise<ContractVersion>;
140168

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

0 commit comments

Comments
 (0)