Usage Guide
Overview
The Maple SDK simplifies interaction with Maple Protocol smart contracts on Ethereum. It supports Mainnet, Base, and Sepolia networks, with production and development environments. This guide provides both conceptual understanding and practical examples, including a full integration with a React application.
There are three networks:
Mainnet: main Ethereum network.
Base Mainnet: Ethereum L2 network.
Sepolia: Ethereum test network (testnet).
Each network may have two environments:
Prod: production environment, where the official, stable versions of the contracts and subgraph, API and web applications are deployed.
Dev: development or staging environment, where new features or updates are tested before being deployed to the production environment.
Access addresses from the addresses
object exported from maple-js
. See a list of available contracts in src/addresses/*.ts
.
The available combinations are:
mainnet-prod
: Production environment on the main Ethereum networkmainnet-dev
: Staging environment on the main Ethereum networkbase-mainnet-prod
: Production environment on the Base L2 networksepolia-prod
: Production environment on the Sepolia test networksepolia-dev
: Development environment on the Sepolia test network
Getting started
Addresses
Access contract addresses using the addresses
object:
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
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:
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:
Checking Permissions and Onboarding
Before a wallet can deposit into a Maple pool, it must have a sufficient permissionsBitmap
set. This is automatically managed when users onboard and verify their accounts on the Maple Webapp. Once verified, all wallets added to the account will receive the necessary permissions. For Syrup pools, permissions are granted after an initial deposit through the UI.
Onboarding and Verification
To ensure your wallet has the necessary permissions:
Maple Webapp: Onboard and verify your account at Maple Webapp. Add your wallets to the account to automatically receive the required permissions.
Syrup Pools: Make an initial deposit through the Syrup UI to set permissions.
Querying Permissions with Subgraph
For those interested in the technical details, you can query the subgraph to check permission information. This is useful for verifying the current state of permissions.
Example Query
The following GraphQL query can be used to retrieve the necessary permission information for a specific pool and account:
API Endpoint
Use the following endpoint to execute the query: https://api.maple.finance/v2/graphql
Explanation
poolV2: Retrieves pool permission details.
account: Retrieves the
permissionsBitmap
for the account.
Ensure that the account's permissionsBitmap
meets or exceeds the pool's requirements before attempting to deposit. For more details on permissions, refer to the Pool Permission Manager documentation.
Example Integration with React
This section provides a practical example of how to integrate the Maple SDK into a React application. This example demonstrates connecting to a wallet, approving a token transfer, depositing into a pool, and requesting a withdrawal.
Prerequisites
Ensure you have the following installed and set up:
Node.js and npm
A React application (created using
create-react-app
or similar)ethers v5 installed in your project
MetaMask/Rabby extension installed in your browser
A wallet with sufficient permissions to interact with the pool (see Checking Permissions with Subgraph)
Step-by-Step Guide
Install the Maple SDK
First, ensure you have the Maple SDK installed in your project:
Set Up Your React Component
Below is a complete example of a React component that interacts with the Maple Protocol:
Run Your Application
Ensure your application is running and MetaMask or any other wallet of your choice is connected to the desired network. You can now interact with the Maple Protocol using the buttons provided in the UI.
Last updated