Skip to content

Commit

Permalink
chore: bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Feb 22, 2024
1 parent 8bf55bf commit 469064e
Show file tree
Hide file tree
Showing 91 changed files with 5,435 additions and 8,381 deletions.
3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
8,907 changes: 2,784 additions & 6,123 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"dist"
],
"scripts": {
"prepare": "npm run build && husky install",
"prepare": "npm run build && husky",
"build": "tsup && npm run build:esm && npm run build:iife && npm run build:dts",
"build:esm": "tsup --clean false --format esm --platform node",
"build:iife": "tsup --clean false --format iife --platform browser",
"build:dts": "tsup --clean false --dts-only",
"pretest": "npm run lint && npm run ts:check",
"test": "jest -i",
"posttest": "npm run format",
"posttest": "npm run format -- --log-level warn",
"test:watch": "jest --watch",
"docs": "cd www && npm run start",
"docs:build": "cd www && GIT_REVISION_OVERRIDE=${npm_config_git_revision_override} npm run build",
"docs:build:version": "v=$(npm run info:version -s) && npm run docs:build --git-revision-override=${npm_config_git_revision_override=v$v}",
"docs:version": "v=$(npm run info:version -s) && cd www && npm run version ${npm_config_version_override=$v}",
"info:version": "npm pkg get version | xargs",
"format": "prettier --loglevel warn --write \"**/*.{ts,js,md,yml,json}\"",
"format": "prettier --log-level log --write \"**/*.{ts,js,md,yml,json}\"",
"lint": "eslint . --cache --fix --ext .ts",
"ts:check": "tsc --noEmit --resolveJsonModule --project tsconfig.eslint.json"
},
Expand All @@ -53,14 +53,14 @@
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^10.0.0",
"@semantic-release/release-notes-generator": "^11.0.0",
"@types/isomorphic-fetch": "^0.0.36",
"@semantic-release/npm": "^11.0.2",
"@semantic-release/release-notes-generator": "^12.1.0",
"@types/isomorphic-fetch": "^0.0.39",
"@types/jest": "^29.5.0",
"@types/jest-json-schema": "^6.1.1",
"@types/pako": "^2.0.0",
Expand All @@ -72,30 +72,31 @@
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.1.3",
"fetch-intercept": "^2.4.0",
"husky": "^8.0.1",
"husky": "^9.0.11",
"import-sort-style-module": "^6.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-json-schema": "^6.1.0",
"lint-staged": "^13.0.1",
"prettier": "^2.7.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"prettier-plugin-import-sort": "^0.0.7",
"tsup": "^6.7.0",
"semantic-release": "^23.0.2",
"tsup": "^8.0.2",
"typedoc": "^0.25.7",
"typescript": "^5.3.0"
},
"dependencies": {
"@noble/curves": "~1.3.0",
"@scure/base": "~1.1.3",
"@scure/starknet": "~1.0.0",
"abi-wan-kanabi": "^2.2.1",
"fetch-cookie": "github:NethermindEth/fetch-cookie#export-cookieimpl",
"abi-wan-kanabi-v2": "npm:abi-wan-kanabi@^2.2.1",
"isomorphic-fetch": "^3.0.0",
"lossless-json": "^2.0.8",
"lossless-json": "^4.0.1",
"pako": "^2.0.4",
"ts-mixer": "^6.0.3",
"url-join": "^4.0.1"
Expand Down
6 changes: 3 additions & 3 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Abi as AbiKanabiV2, TypedContract as AbiWanTypedContractV2 } from 'abi-wan-kanabi-v2';
import type { Abi as AbiKanabi, TypedContract as AbiWanTypedContract } from 'abi-wan-kanabi';

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

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

export const splitArgsAndOptions = (args: ArgsOrCalldataWithOptions) => {
const options = [
Expand Down Expand Up @@ -348,7 +348,7 @@ export class Contract implements ContractInterface {
return this.providerOrAccount.getContractVersion(this.address);
}

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

import { AccountInterface } from '../account';
import { ProviderInterface } from '../provider';
Expand Down Expand Up @@ -26,7 +26,7 @@ import { CairoCustomEnum } from '../utils/calldata/enum/CairoCustomEnum';
import { CairoOption } from '../utils/calldata/enum/CairoOption';
import { CairoResult } from '../utils/calldata/enum/CairoResult';

declare module 'abi-wan-kanabi-v2' {
declare module 'abi-wan-kanabi' {
export interface Config<OptionT = any, ResultT = any, ErrorT = any> {
FeltType: BigNumberish;
U256Type: number | bigint | Uint256;
Expand All @@ -41,7 +41,7 @@ declare module 'abi-wan-kanabi-v2' {
}
}

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

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

public abstract typedv2<TAbi extends AbiKanabiV2>(tAbi: TAbi): TypedContractV2<TAbi>;
public abstract typedv2<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContractV2<TAbi>;
}
10 changes: 8 additions & 2 deletions src/provider/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ export class CustomError extends Error {
export class LibraryError extends CustomError {}

export class GatewayError extends LibraryError {
constructor(message: string, public errorCode: string) {
constructor(
message: string,
public errorCode: string
) {
super(message);
}
}

export class HttpError extends LibraryError {
constructor(message: string, public errorCode: number) {
constructor(
message: string,
public errorCode: number
) {
super(message);
}
}
2 changes: 1 addition & 1 deletion src/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const parseAlwaysAsBig = (x: string): any =>
* @returns JSON string
*/
export const stringify = (
value: json.JavaScriptValue,
value: unknown,
replacer?: any,
space?: string | number | undefined,
numberStringifiers?: json.NumberStringifier[] | undefined
Expand Down
18 changes: 9 additions & 9 deletions www/docs/guides/L1message.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ function sendMessageToL2(
You have to pay in the L1 an extra fee when invoking `sendMessageToL2` (of course paid with the L1 fee TOKEN), to pay the L2 part of the messaging mechanism. You can estimate this fee with this function:

```typescript
import { SequencerProvider } from "starknet";
import { SequencerProvider } from 'starknet';
const provider = new SequencerProvider({ baseUrl: constants.BaseUrl.SN_GOERLI }); // for testnet

const responseEstimateMessageFee = await provider.estimateMessageFee({
from_address: L1address,
to_address: L2address,
entry_point_selector: "handle_l1_mess",
payload: ["1234567890123456789", "200"]
})
from_address: L1address,
to_address: L2address,
entry_point_selector: 'handle_l1_mess',
payload: ['1234567890123456789', '200'],
});
```

If the fee is paid in L1, the Cairo contract at `to_Address` is automatically executed, function `entry_point_selector` (the function shall have a decorator `@l1_handler` in the Cairo code), with parameters `payload`.
Expand All @@ -56,9 +56,9 @@ If necessary you can estimate this fee with the generic `estimateInvokeFee` func

```typescript
const { suggestedMaxFee: estimatedFee1 } = await account0.estimateInvokeFee({
contractAddress: testAddress,
entrypoint: "withdraw_to_L1",
calldata: ["123456789", "30"]
contractAddress: testAddress,
entrypoint: 'withdraw_to_L1',
calldata: ['123456789', '30'],
});
```

Expand Down
12 changes: 6 additions & 6 deletions www/docs/guides/automatic_cairo_ABI_parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Later on, to use it in our code:
```js
import { Contract, RpcProvider, constants } from 'starknet';

const address = "YOUR_ADDRESS_HERE";
const address = 'YOUR_ADDRESS_HERE';
const provider = new RpcProvider({ nodeUrl: `${yourNodeUrl}` });
const contract = new Contract(ABI, address, provider).typedv2(ABI);

Expand Down Expand Up @@ -69,14 +69,14 @@ starkli class-at "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e032
```

```typescript
import { Contract, RpcProvider, constants } from "starknet";
import { ABI } from "./abi";
import { Contract, RpcProvider, constants } from 'starknet';
import { ABI } from './abi';

const address = "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b";
const address = '0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b';
const provider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_MAIN });
const contract = new Contract(ABI, address, provider).typedv2(ABI);

// Notice the types inferred for the parameter and the returned value
const primary_inteface_id = contract.get_primary_interface_id()
const protocol_fees_collected = contract.get_protocol_fees_collected('0x1')
const primary_inteface_id = contract.get_primary_interface_id();
const protocol_fees_collected = contract.get_protocol_fees_collected('0x1');
```
80 changes: 47 additions & 33 deletions www/docs/guides/cairo_enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ fn test(self: @ContractState, val1: u16) -> Option<Order> {
In your code, the Starknet.js response will be an instance of the CairoOption class:

```typescript
import { CairoOption } from "starknet";
import { CairoOption } from 'starknet';
type Order = {
p1: BigNumberish,
p2: BigNumberish,
}
p1: BigNumberish;
p2: BigNumberish;
};
const res: CairoOption<Order> = await myTestContract.test(50);
const res2: CairoOption<Order> = await myTestContract.test(150);
```
Expand Down Expand Up @@ -71,13 +71,17 @@ fn test5(self: @ContractState, inp: Option<Order>) -> u16 {
In your code, the Starknet.js request is an instance of the CairoOption class:

```typescript
import { CairoOption, CairoOptionVariant } from "starknet";
import { CairoOption, CairoOptionVariant } from 'starknet';
type Order = {
p1: BigNumberish,
p2: BigNumberish,
}
const res = await myTestContract.call("test5", [new CairoOption<Order>(CairoOptionVariant.Some, {p1:20, p2:40})]) as bigint;
const res2 = await myTestContract.call("test5", [new CairoOption<Order>(CairoOptionVariant.None)]) as bigint;
p1: BigNumberish;
p2: BigNumberish;
};
const res = (await myTestContract.call('test5', [
new CairoOption<Order>(CairoOptionVariant.Some, { p1: 20, p2: 40 }),
])) as bigint;
const res2 = (await myTestContract.call('test5', [
new CairoOption<Order>(CairoOptionVariant.None),
])) as bigint;
```

## Cairo Result
Expand All @@ -101,10 +105,10 @@ fn test(self: @ContractState, val1: u16) -> Result<u16, u16> {
In your code, the Starknet.js response will be an instance of the CairoResult class:

```typescript
import { CairoResult } from "starknet";
import { CairoResult } from 'starknet';

const res:CairoResult<bigint, bigint> = await myTestContract.test(90);
const res2 = (await myTestContract.call("test", [110])) as CairoResult<bigint, bigint>;
const res: CairoResult<bigint, bigint> = await myTestContract.test(90);
const res2 = (await myTestContract.call('test', [110])) as CairoResult<bigint, bigint>;
```

In `CairoResult<T, U>`, T is the type of the data related to the `Ok` variant, and U is the type of the data related to the `Err` variant.
Expand Down Expand Up @@ -139,10 +143,14 @@ fn test8(self: @ContractState, inp: Result<Order, u16>) -> u16 {
In your code, the Starknet.js request is an instance of the CairoResult class:

```typescript
import { CairoResult, CairoResultVariant } from "starknet";

const res = await myTestContract.call("test8", [new CairoResult<Order, BigNumberish>(CairoResultVariant.Ok, {p1:50, p2:60})]) as bigint;
const res2 = await myTestContract.call("test8", [new CairoResult<Order, BigNumberish>(CairoResultVariant.Err, 50)])as bigint;
import { CairoResult, CairoResultVariant } from 'starknet';

const res = (await myTestContract.call('test8', [
new CairoResult<Order, BigNumberish>(CairoResultVariant.Ok, { p1: 50, p2: 60 }),
])) as bigint;
const res2 = (await myTestContract.call('test8', [
new CairoResult<Order, BigNumberish>(CairoResultVariant.Err, 50),
])) as bigint;
```

## Cairo custom Enum
Expand Down Expand Up @@ -187,7 +195,7 @@ This example Enum has 5 variants (`Response`, `Warning`, `Error`, `Critical` and
In your code, the Starknet.js response will be an instance of the CairoCustomEnum class:
```typescript
import { CairoCustomEnum } from "starknet";
import { CairoCustomEnum } from 'starknet';
const res: CairoCustomEnum = await myTestContract.test(10);
const res2: CairoCustomEnum = await myTestContract.test(100);
Expand All @@ -214,8 +222,8 @@ const c5: Object = res5.unwrap(); // {}
> In a `CairoCustomEnum` instance, you can also have a direct access to the content of a variant:
```typescript
const d: Order = res4.variant.Response // { p1: 1n, p2: 190n }
const e = res4.variant["Critical"] // undefined
const d: Order = res4.variant.Response; // { p1: 1n, p2: 190n }
const e = res4.variant['Critical']; // undefined
```
### Send Cairo custom Enum
Expand Down Expand Up @@ -245,27 +253,33 @@ fn test2a(self: @ContractState, customEnum:MyEnum ) -> u16{
In your code, the Starknet.js request is an instance of the CairoCustomEnum class:
```typescript
import { CairoCustomEnum } from "starknet";
import { CairoCustomEnum } from 'starknet';
const orderToSend: Order = { p1: 8, p2: 10 };
const myCustomEnum = new CairoCustomEnum({Response: orderToSend});
const res14 = await myTestContract.call("test2a", [myCustomEnum]) as bigint;
const res14c = await myTestContract.call("test2a", [new CairoCustomEnum({ Error: cairo.tuple(100, 110) })]) as bigint;
const res14d = await myTestContract.call("test2a", [new CairoCustomEnum({ Critical: ["0x10", "0x11"] })]) as bigint;
const res14e = await myTestContract.call("test2a", [new CairoCustomEnum({ Empty: {} })]) as bigint;
const myCustomEnum = new CairoCustomEnum({ Response: orderToSend });
const res14 = (await myTestContract.call('test2a', [myCustomEnum])) as bigint;
const res14c = (await myTestContract.call('test2a', [
new CairoCustomEnum({ Error: cairo.tuple(100, 110) }),
])) as bigint;
const res14d = (await myTestContract.call('test2a', [
new CairoCustomEnum({ Critical: ['0x10', '0x11'] }),
])) as bigint;
const res14e = (await myTestContract.call('test2a', [
new CairoCustomEnum({ Empty: {} }),
])) as bigint;
```
Take care that if you call a method that do not use the abi (as `CallData.compile`), you have to list all the variants of the enum, like this:
```typescript
const orderToSend: Order = { p1: 8, p2: 10 };
const myCustomEnum = new CairoCustomEnum({
Response: undefined,
Warning: undefined,
Error: cairo.tuple(100, 110),
Critical: undefined,
Empty: undefined
});
Response: undefined,
Warning: undefined,
Error: cairo.tuple(100, 110),
Critical: undefined,
Empty: undefined,
});
const myCalldata = CallData.compile(myCustomEnum);
const res = await myTestContract.call("test2a", myCalldata) as bigint;
const res = (await myTestContract.call('test2a', myCalldata)) as bigint;
```
Loading

0 comments on commit 469064e

Please sign in to comment.