branded-lst-sdk
v0.0.31
Published
This is the Dinero Branded LST SDK. It provides a set of functions to be able to easier interact with blockchain contract interactions related to your Branded LST implementation. The sdk is built on top of [viem](https://viem.sh).
Downloads
24
Readme
Dinero Branded LST SDK
This is the Dinero Branded LST SDK. It provides a set of functions to be able to easier interact with blockchain contract interactions related to your Branded LST implementation. The sdk is built on top of viem.
Installation
yarn add branded-lst-sdk
Usage
Set up the SDK
Initialize the SDK using your Branded LST Mainnet and L2 details. Example below:
import BrandedLstSdk from 'branded-lst-sdk'
import { modeTestnet, holesky } from 'viem/chains'
const sdk = new BrandedLstSdk({
l2Details: {
chain: modeTestnet,
rpcUrl: 'https://sepolia.mode.network',
syncPool: '0x7950cD6317d88068Ad2DE6461dB3C5eBDE298896',
lst: '0xBbF1EC701f3214578f14282d9182E016682b729D',
lzEndpointId: 40260,
},
mainnetDetails: {
chain: holesky,
rpcUrl: 'https://ethereum-holesky-rpc.publicnode.com',
lockBox: '0xBbF1EC701f3214578f14282d9182E016682b729D',
lzEndpointId: 40217,
},
})
Deposit ETH into LST
There are two possibilities when depositing into your LST. You can either deposit ETH from mainnet, or you can deposit ETH from L2. Either way, the user will receive the LST on L2. Depending on the chain specified as an argument will determine which route the deposit flow goes through.
The second argument is a callback function which allows use of the transaction hashes for multi step processes involved with cross chain transactions.
Below is an example of a deposit using wagmi (react wrapper for viem):
import type { Chain, WalletClient } from 'viem'
import { holesky } from 'viem/chains'
import { useAccount, useBalance, useWalletClient } from 'wagmi'
const { address: walletAddress } = useAccount()
const { data: client } = useWalletClient()
const callbackFn = ({ srcTxHash, dstTxHash, state }) => {
console.log('srcTxHash', srcTxHash)
console.log('dstTxHash', dstTxHash)
console.log('state', state)
}
const dstTxHash = await sdk.deposit(
{
// Need to coerce types if using wagmi
walletClient: client as WalletClient,
receiver: walletAddress!,
amount: BigInt(depositAmount),
chain: holesky,
},
callbackFn
)
Withdraw LST from L2
Withdrawals can only be done from L2 -> Mainnet so no chain argument is necessary but the rest is the same as the deposit flow, including the typing of the callback function.
const dstTxhash = await sdk.withdraw(
{
walletClient: client as WalletClient,
receiver: walletAddress!,
amount: BigInt(withdrawAmount),
},
callbackFn
)
Layer Zero quotes
To receive the fee required for the crosschain transaction, you can use the quoteWithdraw() or quoteDeposit() functions. The quoteWithdraw function will return the fee required to withdraw from L2 to Mainnet, and the quoteDeposit function will return the fee required to deposit from Mainnet to L2. This fee will be automatically included in the transaction when using the sdk but is exposed if you want to display the fee on your UI.
const lzWithdrawFee = await sdk.quoteWithdraw({
receiver: walletAddress!,
amount: BigInt(withdrawAmount),
})
const lzDepositFee = await sdk.quoteDeposit({
receiver: walletAddress!,
amount: BigInt(depositAmount),
})