Maker Protocol Technical Docs
  • MakerDAO Technical Docs
  • Getting Started
    • Maker Protocol 101
  • Smart Contract Modules
    • Dai Module
      • Dai - Detailed Documentation
    • Core Module
      • Vat - Detailed Documentation
      • Spot - Detailed Documentation
    • Collateral Module
      • Join - Detailed Documentation
    • Liquidation 2.0 Module
    • System Stabilizer Module
      • Flapper - Detailed Documentation
      • Flopper - Detailed Documentation
      • Vow - Detailed Documentation
    • Oracle Module
      • Oracle Security Module (OSM) - Detailed Documentation
      • Median - Detailed Documentation
    • MKR Module
    • Governance Module
      • Spell - Detailed Documentation
      • Pause - Detailed Documentation
      • Chief - Detailed Documentation
    • Rates Module
      • Pot - Detailed Documentation
      • Jug - Detailed Documentation
    • Proxy Module
      • Proxy Actions - Detailed Documentation
      • Vote Proxy - Detailed Documentation
      • CDP Manager - Detailed Documentation
      • DSR Manager - Detailed Documentation
    • Flash Mint Module
    • Maker Protocol Emergency Shutdown
      • Emergency Shutdown for Partners
      • The Emergency Shutdown Process for Multi-Collateral Dai (MCD)
      • End - Detailed Documentation
      • ESM - Detailed Documentation
  • Glossary
    • MCD Glossaries
    • Smart Contract Annotations
  • Deployment Addresses
    • Maker Protocol Deployments
  • Security
    • Security for the Maker Protocol
  • Building on top of the Maker Protocol
    • Developer Guides and Tutorials
    • The Dai Javascript Library of the Maker Protocol
      • Getting started
      • Configuration
        • Plugins
      • Vault manager
      • Collateral types
      • Dai Savings Rate
      • Currency units
      • System data
      • Advanced
        • Transaction manager
        • DSProxy
        • Events
        • Using multiple accounts
        • Adding a new service
      • Single-Collateral Sai
        • Collateralized Debt Position
        • CDP Service
        • Price Service
        • System Status
        • Tokens
        • Token Conversion
        • Exchange Service
    • Pymaker
  • Keepers
    • The Auctions of the Maker Protocol
    • Auction Keepers
      • Auction Keeper Bot Setup Guide
    • Market Maker Keepers
      • Market Maker Keeper Bot Setup Guide
    • Cage Keeper
    • Simple Arbitrage Keeper
    • Chief Keeper
  • Command-line Interfaces
    • Seth
    • Multi Collateral Dai (MCD) CLI
    • Dai and Collateral Redemption during Emergency Shutdown
    • Emergency Shutdown (ES) CLI
  • Miscellaneous
    • Liquidations 1.2 System (Deprecated)
      • Cat - Detailed Documentation
      • Flipper - Detailed Documentation
    • SCD <> MCD Migration
    • Upgrading to Multi-Collateral Dai Guide
Powered by GitBook
On this page
  • convertEthToWeth
  • convertWethToPeth
  • convertEthToPeth
  • convertWethToEth
  • convertPethToWeth
  • convertPethToEth
Export as PDF
  1. Building on top of the Maker Protocol
  2. The Dai Javascript Library of the Maker Protocol
  3. Single-Collateral Sai

Token Conversion

PreviousTokensNextExchange Service

Last updated 5 years ago

Get the token conversion service with maker.service('conversion').

const conversionService = maker.service('conversion');

The token conversion service offers functions to convert between Eth, Weth and Peth, handling allowances when necessary.

convertEthToWeth

return await conversionService.convertEthToWeth(ETH(10));
  • Params: amount of Eth to convert

  • Returns: promise (resolves to transactionObject once mined)

Note: this is the same as weth.deposit

convertEthToWeth deposits ETH into the WETH contract

convertWethToPeth

return await conversionService.convertWethToPeth(WETH(10));
  • Params: amount of Weth to convert

  • Returns: promise (resolves to transactionObject once mined)

convertWethToPeth joins WETH into PETH, first giving token allowance if necessary.

Note: this process is not atomic if a token allowance needs to be set, so it's possible for one of the transactions to succeed but not both. See for executing multiple transactions atomically. Also, can be called instead if you do not want the allowance to be set first automatically.

convertEthToPeth

return await conversionService.convertEthToPeth(ETH(10));
  • Params: amount of Eth to convert

  • Returns: promise (resolves to transactionObject once mined)

convertEthToPeth awaits convertEthToWeth, then calls convertWethToPeth

Note: this process is not atomic, so it's possible for some of the transactions to succeed but not all. See Using DsProxy for executing multiple transactions atomically.

convertWethToEth

return await conversionService.convertconvertWethToEth(WETH(10));
  • Params: amount of Weth to convert

  • Returns: promise (resolves to transactionObject once mined)

convertWethToEth withdraws Eth from Weth contract

Note: this is the same as weth.withdraw

convertPethToWeth

return await conversionService.convertPethToWeth(PETH(10));
  • Params: amount of Peth to convert

  • Returns: promise (resolves to transactionObject once mined)

convertPethToWeth exits PETH into WETH, first giving token allowance if necessary

Note: this process is not atomic if a token allowance needs to be set, so it's possible for one of the transactions to succeed but not both. See Using DsProxy for executing multiple transactions atomically. Also, peth.exit can be called instead if you do not want the allowance to be set first automatically.

convertPethToEth

return await conversionService.convertPethToEth(PETH(10));
  • Params: amount of Peth to convert

  • Returns: promise (resolves to transactionObject once mined)

convertPethToEth awaits convertPethToWeth, then calls convertWethToEth

Note: this process is not atomic, so it's possible for some of the transactions to succeed but not all. See Using DsProxy for executing multiple transactions atomically.

DsProxy
peth.join