Product Documentation
  • 👋Welcome to K3 Labs
  • Getting Started
    • Quick Start Guide
  • Automate
    • How to create a Workflow
    • Design Page: Key Sections
    • Trigger Set Up
      • Scheduled / Manual Trigger
      • Smart Contract-based Trigger
        • Token Smart Contracts Trigger Examples
        • Swap/Staking Smart Contracts Examples
        • NFT Collection Smart Contracts Examples
      • Wallet event-based
    • Functions Overview
      • Details on Read functions datapoints
      • Transform Function Details
        • Transform Custom Formula
      • JSON Data Preview
      • Custom Inputs
    • What are Actions?
  • Deploy
    • Deploy Page
    • Project Creation
  • Integrations
    • Coinbase
    • Slack
    • Telegram
    • Cubist Wallet
    • Safe Wallet
    • Hyperliquid
  • Stellar Blockchain
  • Tech Documentation
    • K3 Framework
      • Abstract
      • K3 Consensus
    • Networks & Usage
    • K3 Wasm
      • K3 Wasm Rust SDK
      • K3 Wasm Internal Specifications
    • Operator onboarding
Powered by GitBook
On this page
  • Overview
  • Supported Expressions
  • Usage
  • Integration with K3 Labs Workflows
  1. Automate
  2. Functions Overview
  3. Transform Function Details

Transform Custom Formula

Overview

The Transform Function in K3 Labs allows users to manipulate and enrich data within workflows. The Custom Formula feature enables users to apply complex mathematical expressions and logical operations on input data, making it a powerful tool for data transformation.

Supported Expressions

The Custom Formula function supports a variety of mathematical operations on floating-point numbers:

Binary Operators

  • + (addition)

  • - (subtraction)

  • * (multiplication)

  • / (division)

  • % (remainder/modulus)

  • ^ (power/exponentiation)

Unary Operators

  • + (positive sign)

  • - (negation)

Built-in Functions

The Custom Formula function provides built-in mathematical functions, similar to those found in the Rust standard library:

  • Basic Functions:

    • sqrt(x): Square root

    • abs(x): Absolute value

    • exp(x): Exponential function (e^x)

    • ln(x): Natural logarithm

  • Trigonometric Functions:

    • sin(x), cos(x), tan(x): Sine, cosine, and tangent

    • asin(x), acos(x), atan(x), atan2(y, x): Inverse trigonometric functions

    • sinh(x), cosh(x), tanh(x): Hyperbolic sine, cosine, and tangent

    • asinh(x), acosh(x), atanh(x): Inverse hyperbolic functions

  • Rounding Functions:

    • floor(x): Rounds down to the nearest integer

    • ceil(x): Rounds up to the nearest integer

    • round(x): Rounds to the nearest integer

    • roundto(x, d): Rounds x to d decimal places. Example: roundto(10.55235, 2) returns 10.55

  • Sign Function:

    • signum(x): Returns -1, 0, or 1 depending on the sign of x

  • Time Function:

    • Now: Returns the current timestamp in UTC as seconds since the Unix epoch. No parentheses are required (e.g., Now).

Other Functions

  • max(x, ...): Returns the maximum value from one or more numbers

  • min(x, ...): Returns the minimum value from one or more numbers

Constants

  • pi: Mathematical constant Ï€ (3.14159...)

  • e: Euler's number (2.718...)

Usage

The Custom Formula function can be used within a Transform Function node in the K3 Labs workflow builder. Users can define custom variables and apply formulas directly to input data.

Example 1: Basic Arithmetic

Expression:

(x + y) * 2

Usage:

  • If x = 5 and y = 3, the result will be 16.

Example 2: Using Built-in Functions

Expression:

sqrt(a^2 + b^2)

Usage:

  • If a = 3 and b = 4, the result will be 5 (Pythagorean theorem).

Example 3: Conditional Calculation

Expression:

if(x > 0, ln(x), 0)

Usage:

  • If x = 10, the result will be ln(10) ≈ 2.302.

  • If x = -5, the result will be 0 (avoiding logarithm of a negative number).

Example 4: Finding Maximum Value

Expression:

max(a, b, c)

Usage:

  • If a = 10, b = 15, and c = 7, the result will be 15.

Integration with K3 Labs Workflows

The Custom Formula function can be used in:

  • Data Filtering: Modify or filter data before passing it to the next step.

  • Alert Triggers: Calculate thresholds and trigger alerts based on computed values.

  • Trading Strategies: Apply mathematical operations on financial data for automated trading.

  • API Data Processing: Transform API responses before sending them to another service.

PreviousTransform Function DetailsNextJSON Data Preview

Last updated 1 month ago