Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat icp proxy #993

Merged
merged 34 commits into from
Dec 4, 2024
Merged

Feat icp proxy #993

merged 34 commits into from
Dec 4, 2024

Conversation

alenmestrov
Copy link
Member

@alenmestrov alenmestrov commented Nov 28, 2024

ICP Proxy Contract Implementation

Summary

This PR implements the Internet Computer (ICP) version of the proxy contract, enabling multi-signature management of cross-canister calls and contract administration.

Key Features

  • Multi-signature proposal system
  • Support for various proposal actions:
    • External function calls to any canister
    • ICP token transfers
    • Contract configuration updates (num approvals, proposal limits)
    • Context value management
  • Proposal lifecycle management with approval tracking
  • Secure signature verification

Changes

Core Implementation

  • Added ICP-specific contract implementation using Candid types
  • Implemented core types matching NEAR's structure:
    • Base types: ICSignerId, ICProposalId
    • Proposal types: ICProposal, ICProposalAction
    • Request types: ICRequest, ICRequestKind
    • Contract state management

Integration Tests

Added comprehensive test suite covering:

  • Proposal creation and execution
  • Multi-signature approval flow
  • External function calls
  • Token transfers
  • Configuration updates
  • Edge cases and error handling

Build and Test Instructions

Prerequisites

  • DFX installed
  • Rust with wasm32-unknown-unknown target
  • candid-extractor: cargo add candid-extractor

Build and Test Process

Prerequisites

  1. Install Rust and add wasm target:
rustup target add wasm32-unknown-unknown
  1. Install DFX (Internet Computer SDK):
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
  1. Add candid-extractor for .did file generation:
cargo add candid-extractor
  1. Download and install pocket-ic:

Mock Contracts

The project includes mock contracts for testing purposes:

  1. Mock Ledger Contract (`mock/ledger`):

    • Simulates the ICP ledger functionality
    • Handles token transfers
    • Maintains balance state
    • Used for testing transfer proposal actions
  2. Mock External Contract (`mock/external`):

    • Generic test contract for external calls
    • Records received calls and arguments
    • Used for testing external function call proposal actions

Build Process

  1. First, build the mock contracts using the provided script:
./build_mock_contracts.sh

This script:

  • Builds both mock contracts to wasm
  • Generates their .did files
  • Must be run before running tests
  1. Then build the main contract:
./build.sh

This script:

  • Check if the wasm32 target is installed
  • Builds the Proxy contract
  • Generate .did file
  • Stop local environment if running
  • Start local environment in the background
  • Deploy the contract on the local environment

Running Tests

To run the integration tests:

cargo test --test integration -- --nocapture

Test Structure

The integration tests cover:

  • Proposal creation and validation
  • Multi-signature approval flow
  • External function calls to other canisters
  • Token transfers
  • Contract configuration updates
  • Error cases and edge conditions

Notes

  • External function calls accept hex-encoded arguments to support any canister interface
  • Proposals require multiple approvals based on contract configuration
  • Contract maintains proposal state and approval tracking
  • Integration with ICP ledger for token transfers

@alenmestrov alenmestrov requested a review from miraclx November 30, 2024 13:32
@alenmestrov alenmestrov self-assigned this Nov 30, 2024
@alenmestrov alenmestrov marked this pull request as ready for review November 30, 2024 17:46
contracts/icp/proxy-contract/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/types.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/mutate.rs Outdated Show resolved Hide resolved
contracts/icp/proxy-contract/src/types.rs Show resolved Hide resolved
contracts/icp/proxy-contract/src/query.rs Outdated Show resolved Hide resolved
@alenmestrov alenmestrov requested a review from miraclx December 2, 2024 19:37
contracts/icp/proxy-contract/src/lib.rs Outdated Show resolved Hide resolved
scripts/test.sh Outdated Show resolved Hide resolved
@alenmestrov alenmestrov merged commit 78bfaae into feat--icp-contracts Dec 4, 2024
1 check passed
@alenmestrov alenmestrov deleted the feat--icp-proxy branch December 4, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants