1.5.8 • Published 21 days ago

@maplelabs/maple-js v1.5.8

Weekly downloads
-
License
AGPL-3.0-only
Repository
github
Last release
21 days ago

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.


1.5.8

21 days ago

1.5.7

25 days ago

1.5.6

2 months ago

1.5.5

3 months ago

1.5.4

3 months ago

1.5.3

3 months ago

1.5.2

3 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.2.0

7 months ago

1.2.1

6 months ago

0.2.14

9 months ago

0.2.13

9 months ago

0.2.12

9 months ago

0.2.11

9 months ago

0.2.10

9 months ago

1.1.1

7 months ago

1.1.0

8 months ago

1.1.2

7 months ago

1.4.10

4 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

1.4.6

5 months ago

1.4.5

5 months ago

1.0.9

8 months ago

1.4.4

5 months ago

1.0.8

8 months ago

1.4.3

5 months ago

1.0.7

8 months ago

1.4.2

5 months ago

1.0.6

9 months ago

1.4.1

5 months ago

1.0.5

9 months ago

1.4.0

5 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.3.3

5 months ago

1.3.2

5 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.4.9

4 months ago

1.4.8

4 months ago

1.4.7

5 months ago

0.2.7

9 months ago

0.2.6

10 months ago

0.2.9

9 months ago

0.2.8

9 months ago

0.2.3

11 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.1.20

12 months ago

0.1.21

12 months ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.19

12 months ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.2.1

11 months ago

0.2.0

11 months ago

0.2.2

11 months ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.65

1 year ago

0.0.66

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.35-goerli

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.59

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.37

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.26

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.3

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago