For the complete documentation index, see llms.txt. This page is also available as Markdown.

SDK

API Reference

Complete API reference for the Risk Protocol SDK.

TokenFactory

Core token operations and management.

Base Methods

Method
Parameters
Returns
Description

getBaseToken()

-

Promise<string>

Get base token address

decimals()

-

Promise<number>

Get token decimals

getSmartTokenAddress(index)

index: number

Promise<string>

Get smart token address by index

Management Fees

Access via sdk.tokenFactory.managementFees

Method
Parameters
Returns
Description

getRate()

-

Promise<bigint>

Get current fee rate in wei (1 bps = 10^14)

isFeeActive()

-

Promise<boolean>

Check if fees are currently active

calculateManagementFee(amount, mgmtFee)

amount: string mgmtFee: number

Promise<bigint>

Calculate fee for given amount

getTreasuryAddress()

-

Promise<string>

Get treasury wallet address

calculateRollOverValue()

-

Promise<bigint>

Calculate rollover value

updateUserLastRebalanceCount(owner)

owner: string

Promise<TransactionResponse>

Update user's last rebalance count

Admin Methods

Method
Parameters
Returns
Description

setManagementFeeRate(rate)

rate: string

Promise<TransactionResponse>

Set new fee rate

setManagementFeeState(state)

state: boolean

Promise<TransactionResponse>

Enable/disable fees

setTreasuryWallet(wallet)

wallet: string

Promise<TransactionResponse>

Set treasury wallet address

Rebalance

Access via sdk.tokenFactory.rebalance

Method
Parameters
Returns
Description

getRebalanceInterval()

-

Promise<number>

Get rebalance interval in seconds

getLastRebalanceTimestamp()

-

Promise<number>

Get timestamp of last rebalance

getScheduledRebalances()

-

Promise<any[]>

Get all scheduled rebalances

getNextSequenceNumber()

-

Promise<number>

Get next sequence number

getLastTimeStamp()

-

Promise<number>

Get last rebalance timestamp

getRebalanceNumber()

-

Promise<number>

Get total rebalance count

getUserLastRebalanceCount(address)

address: string

Promise<number>

Get user's last rebalance count

getInterval()

-

Promise<number>

Get rebalance interval

applyRebalance(owner)

owner: string

Promise<TransactionResponse>

Apply rebalance for user

verifyAndDecode(signature, encodedData)

signature: string encodedData: string

Promise<any>

Verify signature and decode data

Admin Methods

Method
Parameters
Returns
Description

setSignersAddress(address)

address: string

Promise<TransactionResponse>

Set authorized signer address

getSignersAddress()

-

Promise<string>

Get authorized signer address


SmartToken

Read Methods

Method
Parameters
Returns
Description

balanceOf(address, contract?)

address: string contract?: 0|1

Promise<bigint>

Get token balance

unScaledbalanceOf(address, contract?)

address: string contract?: 0|1

Promise<bigint>

Get unscaled balance

hasPendingRebalance(address, contract?)

address: string contract?: 0|1

Promise<boolean>

Check for pending rebalance

getTokenFactory(contract?)

contract?: 0|1

Promise<string>

Get TokenFactory address

asset(contract?)

contract?: 0|1

Promise<string>

Get underlying asset address

totalAssets(contract?)

contract?: 0|1

Promise<bigint>

Get total assets in vault

convertToShares(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Convert assets to shares

convertToAssets(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Convert shares to assets

Write Methods

Method
Parameters
Returns
Description

handlePendingRebalance(sender, recipient, contract?)

sender: string recipient: string contract?: 0|1

Promise<TransactionResponse>

Handle pending rebalance

Transactions

Access via sdk.smartToken.transaction

Transfers

Method
Parameters
Returns
Description

transfer(recipient, amount, contract?)

recipient: string amount: string contract?: 0|1

Promise<TransactionResponse>

Transfer tokens

transferFrom(sender, recipient, amount, contract?)

sender: string recipient: string amount: string contract?: 0|1

Promise<TransactionResponse>

Transfer tokens from another address

Deposits

Method
Parameters
Returns
Description

maxDeposit(account, contract?)

account: string contract?: 0|1

Promise<bigint>

Get max deposit allowed

previewDeposit(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Preview shares received for deposit

deposit(amount, recipient, contract?)

amount: string recipient: string contract?: 0|1

Promise<TransactionResponse>

Deposit assets for shares

depositWithNative(amount, recipient, contract?)

amount: string recipient: string contract?: 0|1

Promise<TransactionResponse>

Deposit native token (ETH)

depositWithExpiry(amount, recipient, expiryDate, contract?)

amount: string recipient: string expiryDate: string contract?: 0|1

Promise<TransactionResponse>

Deposit with expiry timestamp

depositWithPermit(amount, recipient, deadline, v, r, s, contract?)

amount: string recipient: string deadline: number v: number r: string s: string contract?: 0|1

Promise<TransactionResponse>

Deposit with EIP-2612 permit

Minting

Method
Parameters
Returns
Description

maxMint(account, contract?)

account: string contract?: 0|1

Promise<bigint>

Get max mint allowed

previewMint(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Preview assets needed for mint

mint(amount, recipient, contract?)

amount: string recipient: string contract?: 0|1

Promise<TransactionResponse>

Mint exact shares

Withdrawals

Method
Parameters
Returns
Description

maxWithdraw(account, contract?)

account: string contract?: 0|1

Promise<bigint>

Get max withdrawal allowed

previewWithdraw(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Preview shares burned for withdrawal

withdraw(amount, recipient, owner, contract?)

amount: string recipient: string owner: string contract?: 0|1

Promise<TransactionResponse>

Withdraw exact assets

withdrawWithExpiry(amount, recipient, owner, expiryDate, contract?)

amount: string recipient: string owner: string expiryDate: string contract?: 0|1

Promise<TransactionResponse>

Withdraw with expiry timestamp

Redemptions

Method
Parameters
Returns
Description

maxRedeem(account, contract?)

account: string contract?: 0|1

Promise<bigint>

Get max redemption allowed

previewRedeem(amount, contract?)

amount: string contract?: 0|1

Promise<bigint>

Preview assets received for redemption

redeem(amount, recipient, owner, contract?)

amount: string recipient: string owner: string contract?: 0|1

Promise<TransactionResponse>

Redeem exact shares for assets


Orchestrator

Scheduled operations and Balancer pool management.

Method
Parameters
Returns
Description

executeScheduledRebalances()

-

Promise<TransactionResponse>

Execute all scheduled rebalances

getTokenFactory()

-

Promise<string>

Get TokenFactory address

operationsSize()

-

Promise<number>

Get number of operations

getBalancerPools()

-

Promise<string[]>

Get all Balancer pool addresses

Admin Methods

Method
Parameters
Returns
Description

addOperation(index, destination, data)

index: number destination: string data: string

Promise<TransactionResponse>

Add new operation

removeOperation(index)

index: number

Promise<TransactionResponse>

Remove operation by index

setOperationEnabled(index, destination, enabled)

index: number destination: string enabled: boolean

Promise<TransactionResponse>

Enable/disable operation

addBalancerPool(index, pool)

index: number pool: string

Promise<TransactionResponse>

Add Balancer pool

removeBalancerPool(index)

index: number

Promise<TransactionResponse>

Remove Balancer pool


BalancerHelper

Balancer pool calculations and utilities.

Method
Parameters
Returns
Description

getExpectedAmountOut(bpoolCoreAddress, tokenInAddress, tokenOutAddress, amountIn)

bpoolCoreAddress: string tokenInAddress: string tokenOutAddress: string amountIn: bigint

Promise<bigint>

Calculate expected output for swap

calculatePoolAmountOut(bpoolEsPAddress, tokens, outAmount)

bpoolEsPAddress: string tokens: string[] outAmount: bigint

Promise<{amountsIn: bigint[], approveAmt: bigint[]}>

Calculate amounts needed for liquidity provision

getDollarAmounts(underlying, fees, inputToken, outputToken, inputAmount, tokenInAddress, tokenOutAddress, underlyingAddress, bpoolCoreAddress)

underlying: number fees: number inputToken: string outputToken: string inputAmount: number tokenInAddress: string tokenOutAddress: string underlyingAddress: string bpoolCoreAddress: string

Promise<{ronDollarValue: Decimal, roffDollarValue: Decimal, underlying: Decimal, LPfee: Decimal, swapFee: Decimal}>

Calculate dollar values and fees for token swaps. Valid tokens: "ron", "roff", "underlying"


PriceEstimates

Price discovery, NTV calculations, and slippage management.

Method
Parameters
Returns
Description

getGasInfo()

-

Promise<any>

Get current gas price information

getBalancerPrices(chainId)

chainId: number

Promise<any>

Get all Balancer token prices

getBalancerPrice(tokenAddress, chainId)

tokenAddress: string chainId: number

Promise<number>

Get price for specific token

getNTVPrice(tokenIn, tokenOut, discount)

tokenIn: string tokenOut: string discount: number

Promise<{outRatio: number}>

Get NTV price with discount

getMaxSlippage(classicSlippage, discountNTVSlippage)

classicSlippage: number discountNTVSlippage: number

number

Calculate maximum slippage

getSplitOutputAmounts(smartTokenX, input)

smartTokenX: string input: string

Promise<{outputAmount: bigint, mgmtFeeAmount: bigint}>

Calculate output for split operation

getRedeemOutputAmounts(smartTokenX, input)

smartTokenX: string input: string

Promise<{outputAmount: bigint, mgmtFeeRefund: bigint}>

Calculate output for redeem operation

getSignedFeeData()

-

Promise<any>

Get signed fee data

Last updated