npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@maplelabs/maple-js

v1.8.1

Published

Maple SDK for JavaScript

Downloads

532

Readme

maple-js

A JavaScript SDK for interacting with Maple Protocol's smart contracts.

Table of Contents

Getting Started

Installation

Install the SDK using npm:

npm install @maplelabs/maple-js

Or, if using yarn:

yarn add @maplelabs/maple-js

Addresses

maple-js provides smart contract addresses for the following networks: Ethereum Mainnet, Base Mainnet & Sepolia.

Valid network values are: 'mainnet' | 'sepolia' | 'base-mainnet'.

Valid project values are 'mainnet-prod' | 'mainnet-dev' | 'sepolia-dev' | 'base-mainnet-prod'.

Access addresses from the addresses object exported from maple-js. See a list of available contracts in src/addresses/*.ts.

Addresses Usage

import { addresses } from '@maplelabs/maple-js'

// Returns the contract address for MapleToken on Ethereum Mainnet
const contractAddress = addresses.mainnet.MapleToken

Connecting to a Contract

To connect to a contract, you'll need its address and a signer. The signer should be an instance of a wallet that can sign transactions. Refer to the ethers docs (or your choice of web3 library) for further assistance.

Connecting to a Contract Usage

import { mapleGlobals } from '@maplelabs/maple-js'

const contractAddress = addresses.mainnet.MapleToken
const signer = 'yourSigner'

const contract = mapleGlobals.core.connect(contractAddress, signer)

Interacting with a Contract

Once connected to a contract, you can call any available methods using the contract instance. maple-js contracts use typechain, so you can see all available methods using intellisense in your IDE.

Usage for Queries

Basic queries can be called using the standard await pattern:

const basicQuery = await contract.lpCooldownPeriod()

Usage for Transactions

When executing a transaction, use the .wait() method to resolve the Promise once the block containing your transaction has enough confirmations to be considered final:

import { pool } from '@maplelabs/maple-js'

const poolContract = pool.core.connect(poolAddress, signer)
const method = await (await poolContract.deposit(depositAmount)).wait()

Utils

Generating Unsigned Transaction Data

This utility allows you to generate unsigned transaction data, facilitating the creation of transactions that can later be signed and sent to the network. This is particularly useful for offline transaction preparation or when keys are managed externally. Usage

import { utils } from '@maplelabs/maple-js'

const { txBytes, txInstance } = utils.generateUnsignedTransactionData(parameters)

The generateUnsignedTransactionData function supports creating unsigned transactions for specific actions, currently including poolDeposit and poolQueueWithdrawal. Depending on the action, parameters must be provided accordingly:

  • For poolApprove, specify the spender address and approve amount in assets.
  • For poolDeposit, specify the deposit amount in assets.
  • For poolQueueWithdrawal, specify the withdrawal amount in shares.

Parameters

All calls to generateUnsignedTransactionData require the following parameters:

interface CommonInputs {
  provider: Provider
  walletAddress: string
  contractAddress: string
  type: poolApprove | poolDeposit | poolQueueWithdrawal
  params: {}
}

poolApprove requires the following params:

  params: {
    spender: string // address
    amount: BigNumberish // denominated in assets
  }

poolDeposit requires the following params:

  params: {
    depositAmount: BigNumberish // denominated in assets
  }

poolQueueWithdrawal requires the following params:

  params: {
    withdrawalAmount: BigNumberish // denominated in shares
  }

Generating Signed Transaction Data

This utility provides the functionality to combine unsigned transaction with a signature to create a signed transaction string. This is crucial for scenarios where transactions are prepared offline or in secure environments.

import { utils } from '@maplelabs/maple-js'

const signedTxData = utils.generateSignedTransactionData({
  txBytes: 'unsignedTransactionBytes',
  signature: 'signature'
})

Parameters

  • txBytes: The serialized unsigned transaction data.
  • signature: The signature obtained from signing the transaction hash.

This function returns the serialized signed transaction data, ready for broadcasting to the Ethereum network.

Broadcasting Signed Transactions

This utility allows you to broadcast a signed transaction to the Ethereum network. This step is the final stage in submitting transactions, where the transaction is sent to a node in the network for processing and inclusion in the blockchain.

import { utils } from '@maplelabs/maple-js'

const txReceipt = await utils.broadcastSignedTransaction(
  'signedTransactionData',
  'rpcUrl'
)

Parameters

  • signedTxData: The serialized signed transaction data.
  • rpcUrl: The URL of the Ethereum JSON-RPC endpoint to which you are broadcasting the transaction.

This function sends the signed transaction to the network and returns the transaction receipt once the transaction has been processed.

Utils Example

An example usage of these utilities, including parameter setup and function calls, can be found in the repository at src/helpers/serialiseExampleUse.

Additional Resources

For technical infomration about Maple Protocol, visit: our GitBook.

About Maple

Maple Finance is a decentralized corporate credit market. Maple provides capital to institutional borrowers through globally accessible fixed-income yield opportunities.