SDK
Overview
The SDK allows interaction with various components of the Risk Protocol.
Installation
Install via npm:
not yet available
Initialization
Contracts
Exposed methods on the SDK
Token Factory
getBaseToken(): returns the underlying token address
decimals(): returns the number of decimals of the underlying token
getSmartTokenAddress(index: number): Retrieves the SMART token address by index.
getRate(): Retrieves the current management fee rate
isFeeActive(): Checks if the management fee is active
calculateRollOverValue(): calculates post rebalance SMART token balance
updateUserLastRebalanceCount(owner: string): Updates the last rebalance count for a specific user.
setManagementFeeRate(rate: string): Sets a new management fee rate
setManagementFeeState(state: boolean): Activates or deactivates the management fee
setTreasuryWallet(wallet: string): Sets the address of the treasury wallet
calculateManagementFee(amount: string, isDefault: boolean, mgmtFee: number): Calculates the management fee based on the provided parameters
getTreasuryAddress(): Retrieves the current treasury wallet address
getRebalanceInterval(): Retrieves the interval between rebalances
getLastRebalanceTimestamp(): Returns the timestamp of the last rebalance
applyRebalance(owner: string): Applies a rebalance operation for the specified SMART token owner
verifyAndDecode(signature: string, encodedData: string): Verifies and decodes the provided signature and encoded data
setSignersAddress(address: string): Sets the address of the Rebalance signers
getSignersAddress(): Retrieves the address of the signers
getScheduledRebalances(): Gets the list of scheduled rebalances
getNextSequenceNumber(): Returns the next sequence number for rebalancing
getLastTimeStamp(): Retrieves the last timestamp for rebalance operations
getRebalanceNumber(): Returns the current rebalance number
getUserLastRebalanceCount(address: string): Retrieves the last rebalance count for a specific user
SMART token contract
balanceOf(address: string, contract?: 0 | 1): Retrieves the balance of a specific address for the selected contract (0 or 1)
unScaledbalanceOf(address: string, contract?: 0 | 1): Retrieves the unrebalanced balance of a specific address for the selected contract (0 or 1)
hasPendingRebalance(address: string, contract?: 0 | 1): Checks if there is a pending rebalance for the specified address in the selected contract
getTokenFactory(contract?: 0 | 1): Retrieves the token factory address for the selected contract
handlePendingRebalance(sender: string, recipient: string, contract?: 0 | 1): Handles a pending rebalance for both the sender and recipient for the selected contract
asset(contract?: 0 | 1): Retrieves the underlying token for the selected contract
convertToShares(amount: string, contract?: 0 | 1): Converts a specified amount to shares for the selected contract
convertToAssets(amount: string, contract?: 0 | 1): Converts a specified amount to assets for the selected contract
transfer(recipient: string, amount: string, contract?: 0 | 1): transfers tokens to the specified recipient on the selected contract (0 or 1)
transferFrom(sender: string, recipient: string, amount: string, contract?: 0 | 1): Transfers tokens from the sender to the recipient on the selected contract
previewDeposit(amount: string, contract?: 0 | 1): Previews the deposit operation for the specified amount on the selected contract
deposit(amount: string, recipient: string, contract?: 0 | 1): Deposits underlying tokens into the recipient's account on the selected contract
depositWithNative(amount: string, recipient: string, contract?: 0 | 1): Deposits native underlying tokens into the protocol on the selected contract
depositWithExpiry(amount: string, recipient: string, expiryDate: string, contract?: 0 | 1): Deposits underlying tokens with an expiry date into the protocol on the selected contract
depositWithPermit(amount: string, recipient: string, deadline: number, v: number, r: string, s: string, contract?: 0 | 1): Deposits underlying tokens with a permit into the protocol on the selected contract
previewMint(amount: string, contract?: 0 | 1): Previews the mint operation for the specified amount on the selected contract
mint(amount: string, recipient: string, contract?: 0 | 1): Mints SMART tokens to the recipient's account on the selected contract
previewWithdraw(amount: string, contract?: 0 | 1): Previews the withdrawal operation for the specified amount on the selected contract
withdraw(amount: string, recipient: string, owner: string, contract?: 0 | 1): Withdraws underlying tokens from the protocol to the recipient on the selected contract
withdrawWithExpiry(amount: string, recipient: string, owner: string, expiryDate: string, contract?: 0 | 1): Withdraws tokens with an expiry date from the protocol to the recipient on the selected contract
previewRedeem(amount: string, contract?: 0 | 1): Previews the redeem operation for the specified amount on the selected contract
redeem(amount: string, recipient: string, owner: string, contract?: 0 | 1): Redeems tokens from the protocol to the recipient on the selected contract
Orchestrator
executeScheduledRebalances(): Executes all scheduled rebalances in the system
addOperation(index: number, destination: string, data: string): Adds a new operation to the orchestrator at the specified index
removeOperation(index: number): Removes an operation from the orchestrator at the specified index
setOperationEnabled(index: number, destination: string, enabled: boolean): Enables or disables an operation at the specified index and destination
operationsSize(): Retrieves the total number of operations in the orchestrator
getTokenFactory(): Returns the token factory address
addBalancerPool(index: number, pool: string): Adds a Balancer pool to the orchestrator at the specified index
removeBalancerPool(index: number): Removes a Balancer pool from the orchestrator at the specified index
getBalancerPools(): Retrieves the list of Balancer pools associated with the orchestrator
Other methods
getGasInfo(): Retrieves current gas information, including gas limit, max priority fee per gas, and max fee per gas.
getBalancerPrices(chainId: number): Fetches and caches token prices from Balancer for the specified chain ID.
getBalancerPrice(tokenAddress: string, chainId: number): Retrieves the price of a specific token from the cached Balancer prices.
getNTVPrice(tokenIn: string, tokenOut: string, discount: number): Retrieves the NTV discounted price for a token pair, utilizing caching to reduce redundant API calls.
getMaxSlippage(classicSlippage: number, discountNTVSlippage: number): Calculates the maximum slippage between the classic slippage and the discounted NTV slippage.
Last updated