### Setup Starknet Account with RpcProvider Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/quick-start.md Initializes a Starknet provider and an Account object for signing transactions. Requires a Starknet RPC provider URL and your account's private key and address. ```typescript import { Account, RpcProvider } from "starknet"; // Setup Starknet provider const provider = new RpcProvider({ nodeUrl: "YOUR_RPC_PROVIDER", specVersion: "0.8.1", }); // Your Starknet account (for paying gas fees) const signer = new Account({ provider, address: "YOUR_STARKNET_ADDRESS", signer: "YOUR_STARKNET_PRIVATE_KEY" }); ``` -------------------------------- ### Install Tongo SDK and Starknet.js Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/quick-start.md Installs the Tongo SDK and a compatible version of starknet.js using npm. Requires starknet.js version 8.x.x or higher. ```bash npm install @fatsolutions/tongo-sdk npm install starknet@8.x.x ``` -------------------------------- ### SDK Installation and Setup Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Instructions for installing the Tongo TypeScript SDK and setting up Starknet and Tongo accounts. ```APIDOC ## SDK Installation and Setup ### Description Install the TypeScript SDK and set up Starknet and Tongo accounts for confidential operations. ### Method N/A (Installation and Setup) ### Endpoint N/A ### Parameters N/A ### Request Example ```bash npm install @fatsolutions/tongo-sdk npm install starknet@8.x.x ``` ```typescript import { Account as TongoAccount } from "@fatsolutions/tongo-sdk"; import { Account, RpcProvider } from "starknet"; // Setup Starknet provider const provider = new RpcProvider({ nodeUrl: "https://starknet-mainnet.infura.io/v3/YOUR_API_KEY", specVersion: "0.8.1", }); // Starknet account for paying gas fees const signer = new Account({ provider, address: "0x075662cc8b986d55d709d58f698bbb47090e2474918343b010192f487e30c23f", signer: "0x1234567890abcdef..." }); // Tongo account for confidential operations const tongoAddress = "0x3a542d7eb73b3e33a2c54e9827ec17a6365e289ec35ccc94dde97950d9db498"; // STRK Mainnet const privateKey = "0xabcdef1234567890..."; const tongoAccount = new TongoAccount(privateKey, tongoAddress, provider); console.log("Public Key:", tongoAccount.publicKey); // { x: bigint, y: bigint } console.log("Tongo Address:", tongoAccount.tongoAddress()); // Base58 encoded: "Um6QEVHZaXkii8hWzayJf6PBWrJCTuJomAst75Zmy12" ``` ### Response N/A ``` -------------------------------- ### Initialize Tongo Account Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/quick-start.md Creates an instance of the Tongo Account class. Requires the user's private key, the Tongo contract address, and an initialized Starknet RPC provider. ```typescript import { Account as TongoAccount } from "@fatsolutions/tongo-sdk"; const tongoAddress = "TONGO_CONTRACT_ADDRESS"; const privateKey = "USER_TONGO_PRIVATE_KEY"; const tongoAccount = new TongoAccount( privateKey, tongoAddress, provider ); console.log("Your Tongo public key is:", tongoAcount.publicKey); ``` -------------------------------- ### Install mdbook Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Installs the mdbook tool, used for building and serving the documentation. It can be installed via cargo or package managers like pacman. ```bash # Install via cargo (Rust package manager) car go install mdbook # Or on Arch Linux sudo pacman -S mdbook ``` -------------------------------- ### TypeScript SHE Basic Usage Example Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/she.md Demonstrates basic usage of the SHE TypeScript library, including generating a fund proof and deciphering a balance. It imports necessary functions and constants like `proveFund` and `decipherBalance` from the `@fatsolutions/she` package. ```typescript import { GENERATOR as g, proveFund, decipherBalance } from "@fatsolutions/she"; // Generate a fund proof const { inputs, proof, newBalance } = proveFund( privateKey, amount, currentBalance, currentCipher, nonce ); // Decrypt a balance const balance = decipherBalance(privateKey, L, R); ``` -------------------------------- ### SHE Cryptography Library - Cairo Verification Example Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Provides a Cairo verification example for a Proof of Exponent (POE) using the Fiat-Shamir transform. This function demonstrates how to verify a proof by computing a challenge based on commitments and then using the verify function. ```rust // Cairo verification example with Fiat-Shamir transform pub fn verify_with_prefix(inputs: PoeInputs, proof: PoeProofWithPrefix) -> Result<(), Errors> { let PoeInputs { y, g } = inputs; let PoeProofWithPrefix { A, prefix, s } = proof; let commitments = array![A]; let c = compute_challenge(prefix, commitments); // Hash(prefix, A) verify(y, g, A, c, s) } ``` -------------------------------- ### Cairo SHE Contract Integration Example Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/she.md Shows how to integrate the SHE Cairo library for on-chain proof verification. It demonstrates verifying a Proof of Exponent (POE) using the `verify_poe` function from the `she::protocols::poe` module. ```cairo use she::protocols::poe::verify as verify_poe; use she::protocols::ElGamal::verify as verify_elgamal; use she::protocols::range::verify as verify_range; // Verify a fund proof let valid = verify_poe(y, g, A, c, s); ``` -------------------------------- ### Install SHE TypeScript Package Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/she.md Installs the `@fatsolutions/she` package, which contains the TypeScript implementation of the SHE library. This package is used for client-side proof generation and encryption within the Tongo SDK. ```bash npm install @fatsolutions/she ``` -------------------------------- ### Execute Tongo Operation Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/quick-start.md Constructs a Tongo operation call and executes it using the Starknet Account. This involves creating an operation with the Tongo Account and then converting it to call data for execution. ```typescript const operation = tongoAccount.someOperation({...params}); const call = operation.toCalldata(); signer.execute(call) ``` -------------------------------- ### Get Tongo Account Public Key (TypeScript) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/accounts.md Illustrates how to access the public key of a Tongo Account instance. It shows how to retrieve the raw public key in affine coordinates (x, y) and how to obtain a more user-friendly base58-encoded representation, referred to as the Tongo address. ```typescript console.log(account.publicKey); // { x: bigint, y: bigint } const address = account.tongoAddress(); console.log(address); // "Um6QEVHZaXkii8hWzayJf6PBWrJCTuJomAst75Zmy12" ``` -------------------------------- ### Tongo Contract Interface Definition (Rust) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/abi.md Defines the ITongo interface in Rust, specifying functions for managing confidential payments. It includes setup, user operations, state reading, and auditor handling. Dependencies include Starknet's interface macro and various data types like ContractAddress, u256, u32, PubKey, CipherBalance, State, Fund, Withdraw, Ragequit, Transfer, and Rollover. ```rust #[starknet::interface] pub trait ITongo { // Tongo general setup: /// Returns the contract address that Tongo is wraping. fn ERC20(self: @TContractState) -> ContractAddress; /// Returns the rate of conversion between the wrapped ERC20 a tongo: /// /// ERC20_amount = Tongo_amount*rate /// /// The amount variable in all operation refers to the amount of Tongos. fn get_rate(self: @TContractState) -> u256; /// Returns the bit_size set for this Tongo contract. fn get_bit_size(self: @TContractState) -> u32; /// Returns the contract address of the owner of the Tongo account. fn get_owner(self: @TContractState) -> ContractAddress; // User operations: /// Funds a tongo account. Callable only by the account owner /// /// Emits FundEvent fn fund(ref self: TContractState, fund: Fund); /// Withdraw Tongos and send the ERC20 to a starknet address. /// /// Emits WithdrawEvent fn withdraw(ref self: TContractState, withdraw: Withdraw); /// Withdraw all the balance of an account and send the ERC20 to a starknet address. This proof /// avoids the limitations of the range prove that are present in the regular withdraw. /// /// Emits RagequitEvent fn ragequit(ref self: TContractState, ragequit: Ragequit); /// Transfer Tongos from the balanca of te sender to the pending of the receiver /// /// Emits TransferEvent fn transfer(ref self: TContractState, transfer: Transfer); /// Moves to the balance the amount stored in the pending. Callable only by the account owner. /// /// Emits RolloverEvent fn rollover(ref self: TContractState, rollover: Rollover); // State reading functions /// Returns the curretn stored balance of a Tongo account fn get_balance(self: @TContractState, y: PubKey) -> CipherBalance; /// Returns the current pending balance of a Tongo account fn get_pending(self: @TContractState, y: PubKey) -> CipherBalance; /// Return, if the Tongo instance allows, the current declared balance of a Tongo account for /// the auditor fn get_audit(self: @TContractState, y: PubKey) -> Option; /// Returns the current nonce of a Tongo account fn get_nonce(self: @TContractState, y: PubKey) -> u64; /// Returns the current state of a Tongo account. fn get_state(self: @TContractState, y: PubKey) -> State; // Auditor handling /// Returns the current auditor public key. fn auditor_key(self: @TContractState) -> Option; /// Rotates the current auditor public key. fn change_auditor_key(ref self: TContractState, new_auditor_key: PubKey); } ``` -------------------------------- ### Build and Serve Documentation with mdbook Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Commands to build static HTML documentation or serve it locally with live reloading. Assumes you are in the project's root directory. ```bash # Navigate to this directory cd /home/john/fatsolutions/tongo-v1/tongo-docs # Option A: Build static HTML mdbook build # Output in: book/index.html # Option B: Serve with live reload (RECOMMENDED) mdbook serve # Opens at: http://localhost:3000 # Auto-reloads when you edit files! # Option C: Serve and auto-open browser mdbook serve --open ``` -------------------------------- ### Create Tongo Account Instance (TypeScript) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/accounts.md Demonstrates how to create an instance of the Tongo Account class. This involves importing necessary components from the tongo-sdk and starknet libraries, initializing an RPC provider, and then instantiating the TongoAccount with a private key, contract address, and provider. ```typescript import { Account as TongoAccount } from "@fatsolutions/tongo-sdk"; import { RpcProvider } from "starknet"; const provider = new RpcProvider({ nodeUrl: "YOUR_RPC_URL", specVersion: "0.8.1", }); const tongoAddress = "TONGO_CONTRACT_ADDRESS"; const privateKey = "USER_TONGO_PRIVATE_KEY"; const tongoAccount = new TongoAccount( privateKey, tongoAddress, provider ); ``` -------------------------------- ### Initialize Tongo and Starknet Accounts (TypeScript) Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Sets up Starknet and Tongo accounts using provided RPC provider, Starknet signer, and Tongo private key. This initializes the necessary objects for interacting with the Tongo protocol on Starknet. ```typescript import { Account as TongoAccount } from "@fatsolutions/tongo-sdk"; import { Account, RpcProvider } from "starknet"; // Setup Starknet provider const provider = new RpcProvider({ nodeUrl: "https://starknet-mainnet.infura.io/v3/YOUR_API_KEY", specVersion: "0.8.1", }); // Starknet account for paying gas fees const signer = new Account({ provider, address: "0x075662cc8b986d55d709d58f698bbb47090e2474918343b010192f487e30c23f", signer: "0x1234567890abcdef..." }); // Tongo account for confidential operations const tongoAddress = "0x3a542d7eb73b3e33a2c54e9827ec17a6365e289ec35ccc94dde97950d9db498"; // STRK Mainnet const privateKey = "0xabcdef1234567890..."; const tongoAccount = new TongoAccount(privateKey, tongoAddress, provider); console.log("Public Key:", tongoAccount.publicKey); // { x: bigint, y: bigint } console.log("Tongo Address:", tongoAccount.tongoAddress()); // Base58 encoded: "Um6QEVHZaXkii8hWzayJf6PBWrJCTuJomAst75Zmy12" ``` -------------------------------- ### Deploy Documentation to GitHub Pages Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Steps to build the documentation and push the generated 'book/' directory to the 'gh-pages' branch for deployment on GitHub Pages. ```bash # Build the docs mdbook build # Push the book/ directory to gh-pages branch git subtree push --prefix book origin gh-pages ``` -------------------------------- ### Query and Decrypt Account Balances (TypeScript) Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Retrieves and decrypts the Tongo account state, including usable balance, pending incoming transfers, and transaction nonce. It also shows how to fetch the raw encrypted state and get the conversion rate to ERC20 tokens. ```typescript // Get decrypted account state const state = await tongoAccount.state(); console.log(state); /* { balance: 1000n, // Decrypted usable balance in Tongo units pending: 50n, // Decrypted pending transfers awaiting rollover nonce: 5n // Account operation counter } */ // Get raw encrypted state from contract const rawState = await tongoAccount.rawState(); console.log(rawState); /* { balance: CipherBalance, // ElGamal encrypted balance pending: CipherBalance, // ElGamal encrypted pending audit: CipherBalance | undefined, // Balance encrypted for auditor (if enabled) nonce: 5n, aeBalance: AEBalance | undefined, // XChaCha12 hint for fast decryption aeAuditBalance: AEBalance | undefined } */ // Get conversion rate between Tongo units and ERC20 const rate = await tongoAccount.rate(); const erc20Amount = tongoAccount.tongoToERC20(100n); // Convert 100 Tongo to ERC20 amount ``` -------------------------------- ### Retrieve Transaction History in TypeScript Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Fetches and decrypts the complete transaction history for a Tongo account by parsing on-chain events. This function requires an initial block number to start the history retrieval. The output is an array of transaction objects, each detailing the type, hash, block number, nonce, amount, and recipient. ```typescript const initialBlock = 0; // Starting block number const txHistory = await tongoAccount.getTxHistory(initialBlock); console.log(txHistory); /* [ { type: 'withdraw', tx_hash: '0x3ee8a6a351b05b4684e3e329399f6df02c446ce986c1e0be925ca71b757c6e0', block_number: 6, nonce: 2n, amount: 1n, to: '0x075662cc8b986d55d709d58f698bbb47090e2474918343b010192f487e30c23f' }, { type: 'transferOut', tx_hash: '0x3dc4e84d5212c125bb92e43c0c097d4630ec7899d60bdca408f7bcdb563b0c1', block_number: 4, nonce: 1n, amount: 23n, to: 'tpBg43FFq7SQhmimTMxubT7cJ4dDpjsp5r2TtYYToKV9' }, { type: 'fund', tx_hash: '0x4e134a86b86db0fe494e030d9b3baa664f5ca51750051cda759d06e27931e1', block_number: 3, nonce: 0n, amount: 100n } ] */ ``` -------------------------------- ### TypeScript SHE Development Commands Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/she.md Provides the necessary commands to set up, build, and test the TypeScript implementation of the SHE library. These commands are executed within the `/packages/typescript` directory of the project. ```bash cd packages/typescript pnpm install pnpm build pnpm test ``` -------------------------------- ### Contract Deployment for Custom Tongo Instance Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Demonstrates the constructor for deploying a custom Tongo instance with configurable parameters. It takes the owner address, the ERC20 token address, the exchange rate, bit size for range proofs, and an optional auditor public key. ```rust #[constructor] fn constructor( ref self: ContractState, owner: ContractAddress, // Contract owner address ERC20: ContractAddress, // Token to wrap rate: u256, // ERC20_amount = Tongo_amount * rate bit_size: u32, // Max 128, affects range proof (typically 32) auditor_key: Option, // Optional auditor public key ) { self.owner.write(owner); self.ERC20.write(ERC20); self.rate.write(rate); assert!(bit_size <= 128_u32, "Bit size should be 128 at max"); self.bit_size.write(bit_size); if let Some(key) = auditor_key { self._set_auditor_key(key); } } ``` -------------------------------- ### Run Tongo Documentation Docker Container Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Commands to build the Docker image for Tongo documentation and run it as a container, exposing port 8080. ```bash docker build -t tongo-docs . docker run -p 8080:80 tongo-docs ``` -------------------------------- ### Dockerfile for Tongo Documentation Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md A Dockerfile to build and serve the Tongo documentation using Nginx. It first builds the documentation using mdbook and then serves the static files. ```dockerfile FROM rust:latest as builder RUN cargo install mdbook COPY . /docs WORKDIR /docs RUN mdbook build FROM nginx:alpine COPY --from=builder /docs/book /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` -------------------------------- ### Deploy Tongo Instance (Rust) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/contracts.md This Rust code snippet shows the constructor for deploying a new Tongo contract instance. It takes the owner's address, an ERC20 contract address, the exchange rate, a bit size (max 128), and an optional auditor public key as parameters. ```rust #[constructor] fn constructor( ref self: ContractState, owner: ContractAddress, ERC20: ContractAddress, rate: u256, bit_size: u32, auditor_key: Option, ) { self.owner.write(owner); self.ERC20.write(ERC20); self.rate.write(rate); assert!(bit_size <= 128_u32, "Bit size should be 128 at max"); self.bit_size.write(bit_size); if let Some(key) = auditor_key { self._set_auditor_key(key); } } ``` -------------------------------- ### Add New Documentation Page Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Demonstrates how to add a new Markdown file to the documentation and register it in the SUMMARY.md file for navigation. ```markdown - [My New Page](path/to/new-page.md) ``` -------------------------------- ### Force mdbook Rebuild for Changes Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Solves the 'Changes not showing' issue by performing a hard rebuild of the mdbook documentation. This involves cleaning the previous build artifacts and then rebuilding the entire project. ```bash # Hard rebuild mdbook clean mdbook build ``` -------------------------------- ### ITongo Contract Interface ABI in Rust Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Defines the Starknet interface for the Tongo smart contract, enabling direct contract interactions. It includes functions for contract configuration, core operations like fund, withdraw, ragequit, transfer, and rollover, as well as state queries and auditor management. ```rust #[starknet::interface] pub trait ITongo { // Contract configuration fn ERC20(self: @TContractState) -> ContractAddress; fn get_rate(self: @TContractState) -> u256; fn get_bit_size(self: @TContractState) -> u32; fn get_owner(self: @TContractState) -> ContractAddress; // Core operations fn fund(ref self: TContractState, fund: Fund); fn withdraw(ref self: TContractState, withdraw: Withdraw); fn ragequit(ref self: TContractState, ragequit: Ragequit); fn transfer(ref self: TContractState, transfer: Transfer); fn rollover(ref self: TContractState, rollover: Rollover); // State queries fn get_balance(self: @TContractState, y: PubKey) -> CipherBalance; fn get_pending(self: @TContractState, y: PubKey) -> CipherBalance; fn get_audit(self: @TContractState, y: PubKey) -> Option; fn get_nonce(self: @TContractState, y: PubKey) -> u64; fn get_state(self: @TContractState, y: PubKey) -> State; // Auditor management fn auditor_key(self: @TContractState) -> Option; fn change_auditor_key(ref self: TContractState, new_auditor_key: PubKey); } ``` -------------------------------- ### Verify Proof with Prefix in Rust (SHE) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/she/sigma.md Demonstrates the `verify_with_prefix` function for the POE protocol in Rust. This function computes the challenge by hashing a prefix with the commitment and then calls the standard `verify` function. It's used to bind external data to the proof, such as a chain ID. ```rust pub fn verify_with_prefix(inputs: PoeInputs, proof: PoeProofWithPrefix) -> Result<(), Errors> { let PoeInputs { y, g } = inputs; let PoeProofWithPrefix { A, prefix, s } = proof; let commitments = array![A]; let c = compute_challenge(prefix, commitments); verify(y, g, A, c, s) } ``` -------------------------------- ### Execute Rollover Operation (TypeScript) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/operations/rollover.md This snippet demonstrates how to execute a rollover operation using the Tongo SDK in TypeScript. It involves creating a rollover transaction and then executing it using a signer. Ensure you have the account and signer objects initialized. ```typescript const rolloverOp = await account.rollover({ sender: "SENDER_ADDRESS" }); await signer.execute([rolloverOp.toCalldata()]); ``` -------------------------------- ### TypeScript SHE Available Protocols Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/protocol/she.md Lists the available zero-knowledge proof generation functions within the SHE TypeScript library. These functions cover various operations like funding, transfers, withdrawals, and rollovers, enabling client-side proof creation. ```typescript import { proveFund, proveTransfer, proveWithdraw, proveRollover, proveRagequit, prove_audit, } from "@fatsolutions/she"; ``` -------------------------------- ### SHE Cryptography Library - Zero-Knowledge Proofs Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt Details the SHE (Sigma Haskell Extension) cryptography library, which provides implementations of Sigma protocols for various zero-knowledge proofs. It supports proofs for exponentiation, bit commitment, range proofs, and ElGamal encryption. ```typescript // Package: @fatsolutions/she (v0.4.0) // Implements ZK proofs for: // - POE: Proof of Exponent (discrete log knowledge) // - POE2: Proof of double exponent // - POEN: Proof of N exponents // - Bit: Proof that committed value is 0 or 1 // - Range: Proof that value is in [0, 2^n) // - ElGamal: Proof of correct ElGamal encryption // - SameEncryption: Proof two encryptions contain same value ``` -------------------------------- ### Contract ABI - ITongo Interface Source: https://context7.com/fatlabsxyz/tongo-docs/llms.txt The Cairo smart contract interface for direct contract interactions. ```APIDOC ## Contract ABI - ITongo Interface ### Description The Cairo smart contract interface for direct contract interactions. ### Method Not applicable (this defines the contract interface, not an API endpoint). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example ```rust #[starknet::interface] pub trait ITongo { // Contract configuration fn ERC20(self: @TContractState) -> ContractAddress; fn get_rate(self: @TContractState) -> u256; fn get_bit_size(self: @TContractState) -> u32; fn get_owner(self: @TContractState) -> ContractAddress; // Core operations fn fund(ref self: TContractState, fund: Fund); fn withdraw(ref self: TContractState, withdraw: Withdraw); fn ragequit(ref self: TContractState, ragequit: Ragequit); fn transfer(ref self: TContractState, transfer: Transfer); fn rollover(ref self: TContractState, rollover: Rollover); // State queries fn get_balance(self: @TContractState, y: PubKey) -> CipherBalance; fn get_pending(self: @TContractState, y: PubKey) -> CipherBalance; fn get_audit(self: @TContractState, y: PubKey) -> Option; fn get_nonce(self: @TContractState, y: PubKey) -> u64; fn get_state(self: @TContractState, y: PubKey) -> State; // Auditor management fn auditor_key(self: @TContractState) -> Option; fn change_auditor_key(ref self: TContractState, new_auditor_key: PubKey); } ``` ### Response Not applicable (this defines the contract interface). #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Tongo Operation Lifecycle in TypeScript Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/operations/operations.md Demonstrates the typical lifecycle of a Tongo operation, from creation using a Tongo Account class, conversion to calldata, execution via a Starknet signer, and waiting for transaction confirmation. This process is essential for interacting with the Tongo protocol. ```typescript const operation = await tongoAccount.someOperation({...params}); const calldata = operation.toCalldata(); const tx = await signer.execute([calldata]); await provider.waitForTransaction(tx.transaction_hash); ``` -------------------------------- ### Execute Ragequit Operation (TypeScript) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/operations/ragequit.md This snippet demonstrates how to execute the Ragequit operation using TypeScript. It involves calling the ragequit function on the sender account and then executing the transaction via a signer and provider. Dependencies include the Tongo SDK and Starknet.js. ```typescript const ragequitOp = await senderAccount.ragequit({ to: "RECEIVER_STARKNET_ACCOUNT_ADDRESS", sender: "SENDER_ADDRESS" }); const tx = await signer.execute([ragequit.toCalldata()]); await provider.waitForTransaction(tx.transaction_hash); ``` -------------------------------- ### Execute Fund Operation - TypeScript Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/operations/fund.md This TypeScript code snippet demonstrates how to execute a Fund operation. It first creates the operation, then executes both the ERC20 approval and the fund operation using a signer. The `approve!` property is for ERC20 approval, and `toCalldata()` prepares the fund operation. ```typescript const fundOp = await account.fund({ amount: "AMOUNT_TO_FUND" sender: "SENDER_ADDRESS" }); // Execute both approval and fund await signer.execute([ fundOp.approve!, // ERC20 approval fundOp.toCalldata() // Fund operation ]); ``` -------------------------------- ### Fix mdbook Not Found Error with Cargo Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/README.md Resolves the 'mdbook not found' error by ensuring the cargo bin directory is included in the system's PATH environment variable or by reinstalling mdbook using cargo. ```bash # Make sure cargo bin is in PATH export PATH="$HOME/.cargo/bin:$PATH" # Or reinstall cargo install mdbook ``` -------------------------------- ### Retrieve Tongo Account State (TypeScript) Source: https://github.com/fatlabsxyz/tongo-docs/blob/master/src/sdk/accounts.md Shows how to fetch the current state of a Tongo Account. The `state()` method returns the decrypted balance, pending amount, and nonce. For a more detailed view including encrypted data, the `rawState()` method can be used, which provides CipherBalance and AEBalance objects. ```typescript const state = await account.state(); console.log(state); /* { balance: bigint, // Decrypted balance pending: bigint, // Decrypted pending nonce: bigint // Account nonce } */ const rawState = await account.rawState(); console.log(rawState); /* { balance: CipherBalance, // Encrypted balance pending: CipherBalance, // Encrypted pending balance audit: CipherBalance | undefined, // Encrypted balance for auditor nonce: bigint, aeBalance: AEBalance | undefined, // Encrypted hint to decrypt `balance` aeAuditBalance: AEBalance | undefined //Encrypted hint to decrypt `audit` } */ ```