1.11.3 • Published 5 months ago

@ccamp/lib v1.11.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

CCAMPClient Documentation

The CCAMPClient is a TypeScript class designed to streamline interactions with various CCAMP canisters, including the Remittance canister, the Data collection canister, and the Protocol data collection canister. This class enables users to engage with Data Collection, Protocol Data Collection, and Remittance canisters on the IC network using Ethereum-based private keys.

Table of Contents

  • Installation
  • Usage
    • Constructor
    • getCanisterInstance
    • approveLockerContract
    • deposit
    • withdraw

Installation

Ensure you have the necessary dependencies installed:

npm install

Usage

The CCAMPClient is versatile, supporting both development and production environments. This flexibility is achieved by providing an optional options parameter to the constructor. The env property within this parameter allows users to specify the environment, determining which network the CCAMP canisters will be instantiated on. By default, the environment is set to prod for production, but users can easily switch to local for development. Example usage:

Constructor

constructor(ethereumPrivateKey: string, options?: { env?: Environment })
  • ethereumPrivateKey: Private key for the Ethereum account.
  • options.env: Environment (default is ENV.prod). Options: prod or local.
const ccampClient = new CCAMPClient('your_ethereum_private_key', { env: ENV.prod });

getCanisterInstance

getCanisterInstance(canisterType: CanisterType, overrides?: { canisterId?: string }): any
  • canisterType: Type of the IC canister (e.g., CANISTER_TYPES.DATA_COLLECTION).
  • overrides.canisterId: Override the default canister ID.
const dataCollectionCanister = ccampClient.getCanisterInstance(CANISTER_TYPES.DATA_COLLECTION);

approveLockerContract

Approve the locker contract to spend tokens on your behalf.

approveLockerContract(erc20TokenAddress: string, amountToApprove: ethers.BigNumberish, signer: ethers.Wallet, overrides?: { lockerContract?: string }): Promise<any>
  • erc20TokenAddress: Ethereum address of the ERC20 token.
  • amountToApprove: Amount to approve for the locker contract.
  • signer: Ethereum Wallet signer.
  • overrides.lockerContract: Override the default locker contract address.
await ccampClient.approveLockerContract('token_address', amount, signer);

deposit

Deposit funds into the protocol.

deposit(amount: ethers.BigNumberish, tokenAddress: string, signer: ethers.Wallet, overrides?: { lockerContract?: string; dcCanister?: string }): Promise<Transaction>
  • amount: Amount to deposit.
  • tokenAddress: Ethereum address of the token.
  • signer: Ethereum Wallet signer.
  • overrides.lockerContract: Override the default locker contract address.
  • overrides.dcCanister: Override the default data collection canister ID.
await ccampClient.deposit(amount, 'token_address', signer);

withdraw

Withdraw funds from the network.

withdraw(amount: ethers.BigNumberish, tokenAddress: string, chain: string ,signer: ethers.Wallet, overrides?: { lockerContract?: string; dcCanister?: string; remittanceCanister?: string }): Promise<Transaction>
  • amount: Amount to withdraw.
  • tokenAddress: Ethereum address of the token.
  • chain: Blockchain identifier.
  • signer: Ethereum Wallet signer.
  • overrides.lockerContract: Override the default locker contract address.
  • overrides.dcCanister: Override the default data collection canister ID.
  • overrides.remittanceCanister: Override the default remittance canister ID.
await ccampClient.withdraw(amount, 'token_address', signer, 'ethereum');

Types

Below are the types used in the CCAMPClient class:

Environment

export type Environment = 'prod' | 'dev';
  • prod: Production environment.
  • dev: Development environment.

CanisterType

export type CanisterType = 'dataCollection' | 'protocolDataCollection' | 'remittance';
  • dataCollection: Type for Data Collection canister.
  • protocolDataCollection: Type for Protocol Data Collection canister.
  • remittance: Type for Remittance canister.

Canister Instances

export type DataCollectionCanister;
export type ProtocolDataCollectionCanister;
export type RemittanceCanister;
  • DataCollectionCanister: Type for Data Collection canister instance.
  • ProtocolDataCollectionCanister: Type for Protocol Data Collection canister instance.
  • RemittanceCanister: Type for Remittance canister instance.

These types are integral to the proper functioning of the CCAMPClient.getCanisterInstance method, providing a more specific interface for the different canister types.

This documentation provides a brief overview of the CCAMPClient class and its methods. Refer to the inline comments in the code for more detailed explanations of each method and its parameters.

1.11.3

5 months ago

1.11.2

5 months ago

1.9.1

5 months ago

1.9.0

5 months ago

1.8.0

5 months ago

1.6.2

5 months ago

1.9.3

5 months ago

1.11.0

5 months ago

1.10.0

5 months ago

1.6.3

5 months ago

1.6.1

5 months ago

1.2.0

5 months ago

1.6.0

5 months ago

1.5.0

5 months ago

1.4.0

5 months ago

1.3.0

5 months ago

1.0.14

5 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.3

6 months ago

1.0.0

6 months ago