Skip to content

Commit

Permalink
docs: for deployment guide and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
agustinustheo committed Jul 23, 2024
1 parent 089ec70 commit c2c9dd6
Show file tree
Hide file tree
Showing 2 changed files with 299 additions and 5 deletions.
240 changes: 240 additions & 0 deletions .maintain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# ICSI Scripts Guideline

This document serves as a comprehensive walkthrough to deploy and interact with the ICSI canister on the Internet Computer mainnet and local network.

## Prerequisites

1. **Internet Identity (II)**: Acquire your Internet Identity via [Internet Identity](https://identity.ic0.app/). It's recommended to use a password manager like Bitwarden with Chrome extension for passkey activation.

2. **NNS Login**: Access the [NNS Dapp](https://nns.ic0.app/) and log in.

3. **ICP Tokens**: Top up at least 2.0 ICP tokens to your NNS-II address. Navigate to `Tokens > Internet Computer` in the NNS Dapp.

4. **DFX CLI**: Install the DFINITY Canister SDK (DFX) on your system. Follow the guide at [Installing tools | Internet Computer](https://internetcomputer.org/docs/current/developer-docs/getting-started/install/).

5. **Git and Rust**: Ensure you have Git and Rust installed on your system.

## Deployment Process

### 1. Create a New Identity

Create a new identity locally using `dfx`:

```bash
dfx identity new custodian_name
```

Verify and manage identities:

```bash
dfx identity whoami
dfx identity list
dfx identity use some_idname
```

Export the principal address to an environment variable:

```bash
export CUSTODIAN_PRINCIPAL=$(dfx identity get-principal)
```

### 2. Create a New Canister via NNS Dashboard

1. Create a new canister through the NNS Dashboard.
2. Add cycles to the canister.
3. Add the controller using the `custodian_principal` obtained earlier.

### 3. Clone the Project

```bash
git clone git@github.com:garudaidr/icp-subaccount-indexer-prototype.git
cd icp-subaccount-indexer-prototype
```

### 4. Configure `canister_ids.json`

Create or modify `canister_ids.json` in the project root:

```json
{
"icp_prototype_backend": {
"ic": "upy4y-myaaa-aaaaal-qjbxa-cai"
}
}
```

Replace the canister ID with the one from your NNS dashboard.

### 5. Prepare for Deployment

Sync the local wallet to the mainnet:

```bash
dfx identity --network ic deploy-wallet <canister_id>
```

Convert ICP to cycles:

```bash
dfx cycles convert 0.3 --network ic
```

### 6. Deploy the Canister

Use the `deploy.sh` script for deployment:

```bash
# Deploy to mainnet (IC network)
./deploy.sh --network ic

# Deploy to local network
./deploy.sh --network local

# For a clean local deployment
./deploy.sh --network local --clean
```

Alternatively, you can use the dfx command directly:

```bash
dfx deploy icp_prototype_backend --network ic --no-wallet --argument "(variant { Mainnet }, 15 : nat64, 10 : nat32, \"ryjl3-tyaaa-aaaaa-aaaba-cai\", \"$CUSTODIAN_PRINCIPAL\")"
```

Note: If you encounter issues with the `wasm32-unknown-unknown` target, install it:

```bash
rustup target add wasm32-unknown-unknown
```

### 7. Post-Deployment Setup

Export the Canister ID:

```bash
export CANISTER_ID=<your_canister_id>
```

Initialize the poller:

```bash
dfx canister --network ic call $CANISTER_ID set_interval '(1)'
```

Set the starting block to avoid querying from 0:

```bash
dfx canister --network ic call $CANISTER_ID set_next_block '(12110174)'
```

Verify the current block:

```bash
dfx canister --network ic call $CANISTER_ID get_next_block '()'
```

## Testing and Interaction

### Using `test.sh`

The `test.sh` script provides a comprehensive test suite:

```bash
# Run tests with deployment
./test.sh --network local

# Run tests without deployment
./test.sh --network local --skip-deploy
```

### Using `index.js`

The `index.js` file offers an interactive CLI for canister interaction:

1. Interactive mode:

```bash
node index.js
```

2. CLI mode:

```bash
# Add a subaccount
node index.js --cli add_subaccount

# Set webhook URL
node index.js --cli set_webhook_url https://example.com/webhook
```

### Manual CLI Testing

Test methods using the format:

```bash
dfx canister --network ic call $CANISTER_ID <method_name> '<argument>'
```

Examples:

```bash
# Check canister status
dfx canister --network ic call $CANISTER_ID canister_status '()'

# Sweep funds
dfx canister --network ic call $CANISTER_ID sweep '()'

# Check balance
dfx ledger --network ic balance

# Transfer out (deduct 0.0001 for fee)
dfx ledger transfer --network ic --amount 0.5098 --memo 0 5c8aea1a5c6b871125c5b876688f2c28483a37314717750f2175156742fd08d8
```

## Identity Management

### Exporting Identity

```bash
dfx identity export <identity_name>
```

### Importing Identity

```bash
dfx identity import <identity_name> <pem_file>
```

List and switch identities:

```bash
dfx identity list
dfx identity use <some_id>
```

## Troubleshooting

If the initial deployment doesn't set the principal ID or ledger ID correctly, modify the `post_upgrade()` function in your Rust code:

```rust
async fn post_upgrade() {
let custodian_principal = "".to_string(); // fill this ""
let custodian_principal = Principal::from_text(&custodian_principal).expect("Invalid custodian principal");
CUSTODIAN_PRINCIPAL.with(|principal_ref| {
let stored_principal = StoredPrincipal::new(custodian_principal);
let _ = principal_ref.borrow_mut().set(stored_principal);
});

let ledger_principal = "ryjl3-tyaaa-aaaaa-aaaba-cai".to_string();
let principal = Principal::from_text(&ledger_principal).expect("Invalid ledger principal");
PRINCIPAL.with(|principal_ref| {
let stored_principal = StoredPrincipal::new(principal);
let _ = principal_ref.borrow_mut().set(stored_principal);
});

ic_cdk::println!("running post_upgrade...");
reconstruct_subaccounts();
reconstruct_network();
}
```

This comprehensive guide should help you deploy, test, and interact with your ICSI canister effectively.
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Streamline the management and indexing of principal sub-accounts for ICRC transa

ICSI (ICP Sub-Account Indexer) is a robust solution designed to streamline the management and indexing of sub-accounts within the ICP (Internet Computer Protocol) ecosystem. This project aims to enhance the efficiency, security, and scalability of handling multiple sub-accounts under a single principal, making it easier for users and administrators to manage their ICP assets.

The ICSI canister provides methods that allow organization to primarily carry several operations:
The ICSI canister provides methods that allow organizations to primarily carry out several operations:

- To generate sub-account-id in the form of hex_string
- To track incoming ICP-token transfer into created sub-account-ids
- To manage ICP-tokens that reside in the sub-account-ids
- Generate sub-account-id in the form of hex_string
- Track incoming ICP-token transfers into created sub-account-ids
- Manage ICP-tokens that reside in the sub-account-ids

### Video Demo

Expand Down Expand Up @@ -89,7 +89,61 @@ This method forwards ICP-token that was transacted within a single tx_hash provi

## Usage

The complete step-by-step guide to deploy the Canister are outline on this [Deployment Guide](./docs/canister-deployment-guideline.md)
### Deployment

To deploy the ICSI canister, use the `deploy.sh` script. This script supports both local and IC network deployments.

```bash
# Deploy to local network
.maintain/deploy.sh --network local

# Deploy to IC network
.maintain/deploy.sh --network ic
```

For a clean start on the local network, use the `--clean` flag:

```bash
.maintain/deploy.sh --network local --clean
```

For a complete step-by-step guide to deploying the Canister, refer to the [Deployment Guide](./docs/canister-deployment-guideline.md).

### Testing

The `test.sh` script provides a comprehensive test suite for the ICSI canister. It can be run with or without deployment:

```bash
# Run tests with deployment
.maintain/test.sh --network local

# Run tests without deployment
.maintain/test.sh --network local --skip-deploy
```

### Interactive CLI

The `index.js` file provides an interactive CLI for interacting with the ICSI canister. It can be used in two modes:

1. Interactive mode:

```bash
node .maintain/script/index.js
```

This will present a menu of available operations.

2. CLI mode:

```bash
# Add a subaccount
node .maintain/script/index.js --cli add_subaccount

# Set webhook URL
node .maintain/script/index.js --cli set_webhook_url https://example.com/webhook
```

For a comprehensive explanations for the scripts, refer to the [ICSI Scripts Guideline](./.maintain/README.md).

## Conclusion

Expand Down

0 comments on commit c2c9dd6

Please sign in to comment.