Skip to content

Commit

Permalink
Release 0.1.2 (#525)
Browse files Browse the repository at this point in the history
* Fix PR template

* Fix predeployment docs
  • Loading branch information
FabijanC committed Jul 1, 2024
1 parent aefef84 commit ff9ba95
Show file tree
Hide file tree
Showing 27 changed files with 1,202 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [ ] No spelling errors - `./scripts/check_spelling.sh`
- [ ] Performed code self-review
- [ ] Rebased to the latest commit of the target branch (or merged it into my branch)
- Once you make the PR reviewable, please prefer merging over rebasing
- [ ] Updated the docs if needed - `./website/README.md`
- [ ] Linked the [issues](https://github.com/0xSpaceShard/starknet-devnet-rs/issues) resolvable by this PR - [linking info](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)
- [ ] Updated the tests if needed; all passing - [execution info](https://github.com/0xSpaceShard/starknet-devnet-rs/?tab=readme-ov-file#test-execution)
- [ ] Updated the tests if needed; all passing - [execution info](https://github.com/0xSpaceShard/starknet-devnet-rs/blob/main/.github/CONTRIBUTING.md#test-execution)
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ cairo-lang-syntax = "=2.6.0"
cairo-lang-utils = "=2.6.0"

# Inner dependencies
starknet-types = { version = "0.1.1", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.1.1", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.1.1", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }
starknet-types = { version = "0.1.2", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.1.2", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.1.2", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }

# Dependabot alerts
zerocopy = "0.7.31"
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-core"
version = "0.1.1"
version = "0.1.2"
edition.workspace = true
repository.workspace = true
license-file.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-server"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
repository.workspace = true
license-file.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-types"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "Starknet types for the devnet"
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
repository.workspace = true
license-file.workspace = true
Expand Down
19 changes: 17 additions & 2 deletions website/docs/predeployed.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@ If you want to deploy an instance of an account contract class not predeclared o

## How to get predeployment info?

The predeployment information is logged on Devnet startup. Predeployed accounts can be retrieved in JSON format by sending a `GET` request to `/predeployed_accounts` of your Devnet or `JSON-RPC` request with method name `devnet_getPredeployedAccounts`. With additional query string `with_balance=true` WEI and FRI balances at the pending state will be provided.
The information on predeployed contracts is logged on Devnet startup. Predeployed accounts can be retrieved in JSON format by sending a `GET` request to `/predeployed_accounts`. With the additional query parameter `with_balance=true`, WEI and FRI balances at the pending state will be provided:

```
GET /predeployed_accounts?with_balance=true
GET /predeployed_accounts?[with_balance=true]
```

Alternatively, send a JSON-RPC request:

```
JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_getPredeployedAccounts",
"params": {
// optional; defaults to false
"with_balance": true | false
}
}
```
85 changes: 85 additions & 0 deletions website/versioned_docs/version-0.1.2/account-impersonation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Account impersonation

:::info

This page is about account impersonation. To read about account class selection and deployment, click [here](./predeployed).

:::

## Introduction

Devnet allows you to use impersonated account from mainnet/testnet. This means that a transaction sent from an impersonated account will not fail with an invalid signature error. In the general case, a transaction sent with an account that is not in the local state fails with the aforementioned error. For impersonation to work, Devnet needs to be run in [forking mode](./forking.md).

:::warning Caveat

- Only `INVOKE` and `DECLARE` transactions are supported. `DEPLOY_ACCOUNT` transaction is not supported, but you can create an `INVOKE` transaction to UDC.
- Overall fee, for transactions sent with an impersonated account, will be lower compared to normal transactions. The reason is that validation part is skipped.
- The most common way of sending a transaction is via starknet-rs/starknet.js or starkli. Trying to send with an account that **does not** exist even in the origin network will return an error:
- In transaction construction, if account nonce is not hardcoded, Devnet is queried and returns `ContractNotFound`.
- Otherwise the nonce fetching part is skipped and `InsufficientAccountBalance` is returned.

:::

## Disabling impersonation

Users can disable account impersonation by starting Devnet with CLI flag `--disable-account-impersonation` or by setting environment variable `DISABLE_ACCOUNT_IMPERSONATION`. Every subsequent JSON-RPC impersonation request will return an error. This feature can be used in CTFs to prevent participants from easily solving the task.

## API

Account impersonation follows JSON-RPC method specification. Each method returns an empty response:

### devnet_impersonateAccount

Impersonates a specific account address nonexistent in the local state.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_impersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_stopImpersonateAccount

Stops the impersonation of an account previously marked for impersonation.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopImpersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_autoImpersonate

Enables automatic account impersonation. Every account that does not exist in the local state will be impersonated.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_autoImpersonate",
"params": {}
}
```

### devnet_stopAutoImpersonate

Stops the effect of [automatic impersonation](#devnet_autoimpersonate).

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopAutoImpersonate",
"params": {}
}
```
53 changes: 53 additions & 0 deletions website/versioned_docs/version-0.1.2/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# API

## JSON-RPC API

Both Starknet's and Devnet's JSON-RPC API are reachable at `/rpc` and `/`. E.g. if spawning Devnet with default settings, these URLs are functionally equivalent: `http://127.0.0.1:5050/rpc` and `http://127.0.0.1:5050/`. The difference between these two groups of methods is their prefix: `starknet_` (e.g. `starknet_getNonce`) and `devnet_` (e.g. `devnet_mint`).

### Starknet API

Unlike Pythonic Devnet, which also supported Starknet's gateway and feeder gateway API, Devnet in Rust supports [Starknet's JSON-RPC API](https://github.com/starkware-libs/starknet-specs/tree/master/api). Since JSON-RPC v0.6.0, to find out which JSON-RPC version is supported by which Devnet version, check out the [releases page](https://github.com/0xspaceshard/starknet-devnet-rs/releases).

### Devnet API

Devnet has many additional features which are available via their own endpoints and JSON-RPC, which are all mentioned throughout the documentation.

## Interacting with Devnet in JavaScript and TypeScript

To interact with Devnet using the [Devnet API](#devnet-api), you can use [`starknet-devnet-js`](https://github.com/0xSpaceShard/starknet-devnet-js/). This can be especially useful in achieving [L1-L2 communication](./postman.md#l1-l2-interaction-via-postman).

To interact with Devnet usings the [Starknet API](#starknet-api), use [starknet.js](https://www.starknetjs.com/).

## Config API

To retrieve the current configuration of Devnet, send a `GET` request to `/config` or `JSON-RPC` request with method name `devnet_getConfig`. Example response is attached below. It can be interpreted as a JSON mapping of CLI input parameters, both specified and default ones, with some irrelevant parameters omitted. So use `starknet-devnet --help` to better understand the meaning of each value, though keep in mind that some of the parameters have slightly modified names.

```json
{
"seed": 4063802897,
"total_accounts": 10,
"account_contract_class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
"predeployed_accounts_initial_balance": "1000000000000000000000",
"start_time": null,
"gas_price_wei": 100000000000,
"gas_price_strk": 100000000000,
"data_gas_price_wei": 100000000000,
"data_gas_price_strk": 100000000000,
"chain_id": "SN_SEPOLIA",
"dump_on": "exit",
"dump_path": "dump_path.json",
"state_archive": "none",
"fork_config": {
"url": "http://rpc.pathfinder.equilibrium.co/integration-sepolia/rpc/v0_7",
"block_number": 26429
},
"server_config": {
"host": "127.0.0.1",
"port": 5050,
"timeout": 120,
"request_body_size_limit": 2000000
},
"block_generation": null,
"lite_mode": false
}
```
69 changes: 69 additions & 0 deletions website/versioned_docs/version-0.1.2/balance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Account balance

Other than using prefunded predeployed accounts, you can also add funds to an account that you deployed yourself.

Separate tokens use separate ERC20 contracts for minting and charging fees. These are the token contracts predeployed by Devnet and the addresses where they are located:

- ETH: `0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7`
- STRK: `0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d`

## Mint token - Local faucet

By sending a `POST` request to `/mint` or `JSON-RPC` request with method name `devnet_mint` for a token, you initiate a transaction on that token's ERC20 contract. The response contains the hash of this transaction, as well as the new balance after minting. The token is specified by providing the unit, and defaults to `WEI`.

The value of `amount` is in WEI and needs to be an integer (or a float whose fractional part is 0, e.g. `1000.0` or `1e21`)

```
POST /mint
{
"address": "0x6e3205f...",
"amount": 500000,
"unit": "WEI" | "FRI"
}
```

```
JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_mint",
"params": {
"address": "0x6e3205f...",
"amount": 500000,
"unit": "WEI" | "FRI"
}
}
```

Response:

```
{
"new_balance": 500000,
"unit": "WEI" | "FRI",
"tx_hash": "0xa24f23..."
}
```

## Check balance

Check the balance of an address by sending a `GET` request to `/account_balance`. The address should be a 0x-prefixed hex string; `unit` defaults to `WEI` and `block_tag` to `latest`.

```
GET /account_balance?address=<ADDRESS>[&unit=<FRI|WEI>][&block_tag=<latest|pending>]
```

```
JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_getAccountBalance",
"params": {
"address": "0x6e3205f...",
"unit": "WEI" | "FRI",
"block_tag": "latest" | "pending"
}
}
```
Loading

0 comments on commit ff9ba95

Please sign in to comment.