LogoLogo
MidpointContact UsThe Docs are Wrong!
  • What is Midpoint
  • What actually is a midpoint?
  • Midpoint FAQs
  • Get Started
    • Sample Midpoints
      • Filecoin Filrep Oracle: Obtain miner reputations on-chain
      • Oracle: Call any API from a smart contract
      • Listener: Subscribe an internal service to any event
      • Data Feed: Stream a data feed on-chain at regular intervals
      • Data Bridge: Pass arbitrary messages between chains
      • Automation: Ensure a function is called at regular intervals
    • Videos
  • Using Midpoint
    • API Key
    • Midpoint CLI
    • GraphQL API
    • Dashboard
  • Core Concepts
    • Midpoints
      • Midpoint ID
      • Sources
      • Tasks
      • Source and Task Definitions
        • Secrets
        • Variables
        • Exclude Logs
        • Extracts
    • Requests
      • Request ID
      • Events
    • Credits and Payment
  • Sources
    • Startpoint Called
    • EVM Event Emitted
    • Cron Job Triggered
  • Tasks
    • Make HTTP Request
      • OAuth and Multi-Step Authentication
    • Call EVM Function
    • Transact to EVM Function
      • Security
    • Shift Decimal
  • More Reading
    • Chain IDs
    • Startpoints
    • Midpoint EOAs
  • Get in Touch
    • Contact Links
Powered by GitBook
On this page
  • Definition
  • Returned Values
  • Examples
  • Tips for Using Shift Decimal

Was this helpful?

  1. Tasks

Shift Decimal

Shifts the decimal point of a numeric value. Us for turning prices into integers.

The Shift Decimal task is a purely functional task that takes two values - A and B - and outputs A * 10^B.

This task can be used to transform floating/fixed point values into integer values 2.54812 —> 254812. This task is commonly used to normalize price data into EVM-compatible formats. This task can also be used to convert a large EVM-normalized value (ex. 1500000000000000000 wei) into a human-readable format (1.5 Eth).

Definition

inputValue: string # Required
decimalPlaces: string # Required
outputName: string # Required
round: string 
extracts: [ 
    {
        name: string 
        from: string
    }
]
excludeLogs: [string]

inputValue: Numeric. The value to be transformed.

decimalPlaces: Numeric. The number of decimal places to move the value. Positive values means the decimal is moved to the right.

round: Boolean. Whether or not to round the output down to the nearest integer value.

outputName: String. The name to be assigned to the resultant value. This is the name that will be extracted.

  • Timestamp Unixtime of execution.

  • TaskDefinition The complete definition of this task at runtime.

  • TaskOutputData The complete set of returned values from this task.

Returned Values

This task returns one numeric value which is assigned the name given by outputName along with any extracts.

Examples

Takes a value in Ether produced by a previous source/task. This scales the value up by 10^18 to produce a value in Wei which can be used back on-chain.

{
	"inputValue": "{{valueInEth}}",
	"decimalPlaces": "18",
	"outputName": "valueInWei",
	"round": "true"
}

Takes the value and decimal count of an erc20 balance from a previous source/task. Scales the value down by the decimal count. Ex: 65 USDC is expressed as 65000000 USDC and USDC has a decimal count of 6. This normalizes the value to 65 for use in future tasks.

{
	"inputValue": "{{erc20-value}}",
	"decimalPlaces": "-{{erc20-decimals}}",
	"outputName": "erc20-shifted",
	"round": "true"
}

Tips for Using Shift Decimal

  • Use a variable extracted from a previous task (ex. a value from a price API or an on-chain value) as an inputValue.

  • Only use a variable for decimalPlaces if it is not possible to know the translation factor before runtime.

  • Set round to true if you are returning a value back on-chain and to false if you are creating a human-readable value.

  • Ignore extracts unless there is a critical need for the timestamp.

  • Typically you should ignore excludeLogs. It is rare that your exponentiation needs to be concealed from logs.

PreviousSecurityNextChain IDs

Last updated 2 years ago

Was this helpful?

extracts: See . Legal values:

excludeLogs: See . Legal values:

extracts
exclude logs