Skip to content

Commit

Permalink
Merge pull request #124 from carbonable-labs/devnet-scripting
Browse files Browse the repository at this point in the history
Devnet scripting
  • Loading branch information
LouGel authored Aug 5, 2024
2 parents 86a55ce + 5ebe7d4 commit 175c10e
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 256 deletions.
17 changes: 17 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
KEYSTORE_PASSWORD=my_keystore_password
STARKNET_ACCOUNT=path/to/account.json
STARKNET_KEYSTORE=/path/to/keystore.json
DEPLOYER_ADDRESS=="0x to your account"


#mainnet/testnet/devnet rpc
#The entrypoint to the chain (here is a local node)

STARKNET_RPC='http://0.0.0.0:5050'

# OPTIONAL
#Nethermind juno rpc works perfectly but you can try another one ( not every rpc works)
#Here is Sepolia URL, you can replace by a mainnet one.
# If you have apikey https://free-rpc.nethermind.io/sepolia-juno/?apikey=<YOUR_API_KEY>
FORK_URL='https://free-rpc.nethermind.io/sepolia-juno/'

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keystore.json
__pycache__
env
.env
.env.*

test.*

# starknet
Expand Down
72 changes: 68 additions & 4 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you find a bug, please open an issue using the [bug report template](https://
If you have an idea for a new feature, please submit a feature request using the [feature request template](https://github.com/carbonable-labs/carbon-protocol-v3/issues/new?assignees=&labels=enhancement&template=02_FEATURE_REQUEST.md&title=feat%3A+). Include a clear and concise description of the feature, why it would be useful, and any additional context. You can also contact us through Discord or Telegram to discuss about it.

## ⛏️ Submitting Pull Requests

1. **Choose an issue**: Pick an unassigned issue and ask for more information if needed via Telegram or Discord.
2. **Fork the repository**: Click the "Fork" button on the top right of the repository page and create a new branch dedicated to the issue.
3. **Code your changes**: Implement your feature or fix the bug. Follow the project's coding style and commit message principles.
Expand All @@ -23,8 +24,8 @@ If you have an idea for a new feature, please submit a feature request using the

#### Requirements

- [Scarb](https://docs.swmansion.com/scarb/): *v2.6.0*
- [Starknet Foundry](https://foundry-rs.github.io/starknet-foundry/index.html) *v0.26.0*
- [Scarb](https://docs.swmansion.com/scarb/): _v2.6.0_
- [Starknet Foundry](https://foundry-rs.github.io/starknet-foundry/index.html) _v0.26.0_

We recommend installing dependencies using [asdf](https://asdf-vm.com/):

Expand All @@ -38,39 +39,102 @@ asdf install starknet-foundry 0.26.0
#### Compile

To compile the project, run:

```bash
scarb build
```

#### Set you env

Follow the .env.template

```bash
source .env
```

#### Code Style

To format the code, run:

```bash
scarb fmt
```

#### Testing

To run tests (using Starknet-Foundry), use:

```bash
scarb test
```

To run a specific test:

```bash
scarb test <name_of_the_test>
```

#### Devnet

To generata an accound see :
[this page](https://docs.starknet.io/quick-start/set-up-an-account/)

```bash
cargo install starknet-devnet
```

To run a new node

```bash
starknet-devnet
```

Fork existing chain with flag

```bash
--fork-network $FORK_URL
```

for further options

```bash
starknet-devnet --help
```

#### Deploy

To deploy (on testnet/mainnet/devnet), use:
1. Check available contract

```bash
bash scripts/declare.sh
```

2 Declare contract -> it gives you a class_hash

```bash
bash scripts/declare.sh <contract_name>
```

3. Deploy contracts
If you want to simulate the whole infra, please deploy in this order: mock_stable, project, minter, offsetter

```bash
bash scripts/deploy_<name>.sh <ClASS_HASH> <...ARGS>
```


### Guidelines

- All tests should be placed in the `tests/` folder.
- Tests should be organized according to the tested file and function.
- Refer to existing tests for coding style and structure.
- Use utility functions from `tests/tests_lib.cairo` to set up your tests and avoid redundancy (especially `default_setup_and_deploy` and `buy_utils`).

### License

By contributing to Carbon Protocol V3, you agree that your contributions will be licensed under the License used.

### Thank You
Thank you for your interest in contributing to Carbon Protocol V3! We look forward to building something great together.


Thank you for your interest in contributing to Carbon Protocol V3! We look forward to building something great together.
2 changes: 2 additions & 0 deletions debug_usdcarb.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare ../target/dev/carbon_v3_USDCarb.contract_class.json
contract deployed at: declarelolError at deployment: Error: Failed to create Felt from string
Empty file added deploy.js
Empty file.
100 changes: 100 additions & 0 deletions genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"number": 0,
"parentHash": "0x999",
"timestamp": 5123512314,
"stateRoot": "0x99",
"sequencerAddress": "0x100",
"gasPrices": {
"ETH": 1111,
"STRK": 2222
},
"feeToken": {
"address": "0x55",
"name": "ETHER",
"symbol": "ETH",
"decimals": 18,
"class": "0x8",
"storage": {
"0x111": "0x1",
"0x222": "0x2"
}
},
"universalDeployer": {
"address": "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
"storage": {
"0x10": "0x100"
}
},
"accounts": {
"0x10f3d55ff67700b7d7c34294c57b6489992a76d33dd8dbca1e2d47209f2d338": {
"publicKey": "0x1",
"balance": "0xD3C21BCECCEDA1000000",
"nonce": "0x1",
"class": "0x444",
"storage": {
"0x1": "0x1",
"0x2": "0x2"
}
},
"0x66efb28ac62686966ae85095ff3a772e014e7fbf56d4c5f6fac5606d4dde23a": {
"publicKey": "0x1",
"balance": "0xD3C21BCECCEDA1000000",
"nonce": "0x1",
"class": "0x444",
"storage": {
"0x1": "0x1",
"0x2": "0x2"
}
},
"0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114": {
"publicKey": "0x2",
"balance": "0xD3C21BCECCEDA1000000"
},
"0x79156ecb3d8f084001bb498c95e37fa1c4b40dbb35a3ae47b77b1ad535edcb9": {
"publicKey": "0x3"
},
"0x053a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf": {
"publicKey": "0x4",
"balance": "0xD3C21BCECCEDA1000000",
"privateKey": "0x115"
}
},
"contracts": {
"0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af": {
"balance": "0xD3C21BCECCEDA1000000",
"class": "MyERC20",
"storage": {
"0x1": "0x1",
"0x2": "0x2"
}
},
"0xe29882a1fcba1e7e10cad46212257fea5c752a4f9b1b1ec683c503a2cf5c8a": {
"balance": "0xD3C21BCECCEDA1000000"
},
"0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c": {
"storage": {
"0x1": "0x1"
}
}
},
"classes": [
{
"class": {
"abi": [
{
"members": [
{ "name": "to", "offset": 0, "type": "felt" },
{ "name": "selector", "offset": 1, "type": "felt" },
{ "name": "data_offset", "offset": 2, "type": "felt" },
{ "name": "data_len", "offset": 3, "type": "felt" }
],
"name": "AccountCallArray",
"size": 4,
"type": "struct"
}
]
},
"classHash": "0x444"
}
]
}
Empty file modified scripts/converter.sh
100755 → 100644
Empty file.
45 changes: 45 additions & 0 deletions scripts/declare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
source ../.env
source .env

# Function to set the contract path based on the given parameter
set_contract_path() {
case $1 in
project)
CONTRACT_PATH="./target/dev/carbon_v3_Project.contract_class.json"
;;
offsetter)
CONTRACT_PATH="./target/dev/carbon_v3_Offsetter.contract_class.json"
;;
mock_stable)
CONTRACT_PATH="./target/dev/carbon_v3_USDCarb.contract_class.json"
;;
minter)
CONTRACT_PATH="./target/dev/carbon_v3_Minter.contract_class.json"
;;
*)
echo "Invalid parameter. Please use one of the following: project, offsetter, mock_stable, minter."
exit 1
;;
esac
}

# Check if a parameter is passed
if [ -z "$1" ]; then
echo "No parameter provided. Please specify a parameter: project, offsetter, mock_stable, minter."
exit 1
fi

# Set the contract path based on the provided parameter
set_contract_path $1

# Declare the contract
echo "Declaring the contract with CONTRACT_PATH=$CONTRACT_PATH..."
output=$(starkli declare "$CONTRACT_PATH" --account "$STARKNET_ACCOUNT" --rpc "$STARKNET_RPC" --keystore "$STARKNET_KEYSTORE" --keystore-password "$KEYSTORE_PASSWORD" 2>&1)

if [[ $output == *"Error"* ]]; then
echo "Error: $output"
exit 1
fi

echo -e "Contract declare: $output"
Loading

0 comments on commit 175c10e

Please sign in to comment.