rng-layer-sdk
v1.0.3
Published
SDK for shared liquidity pool and its utilities
Readme
RNG Layer SDK Documentation
Overview
RNG Layer SDK is a clean, modular, and extensible TypeScript SDK for interacting with the liquidity protocol on Arbitrum and preparing on-chain transactions.
The SDK exposes two entry-point classes:
Liquidity→ Liquidity pool interactions (read pool state, deposit, withdraw, unreserve)Allowance→ USDT token allowance checks
Installation
npm install rng-layer-sdkor
yarn add rng-layer-sdkInitialization
Both classes accept an optional environment option. The default environment is "development".
import { Liquidity, Allowance } from "rng-layer-sdk";
// Default (development)
const liquidity = new Liquidity();
const allowance = new Allowance();
// Specify environment
const liquidity = new Liquidity({ environment: "production" });
const allowance = new Allowance({ environment: "production" });Environments
| Value | Description |
| -------------- | ------------------------------ |
| development | Dev contracts on Arbitrum |
| staging | Staging contracts on Arbitrum |
| production | Production contracts on Arbitrum |
Liquidity Class
Read Methods
getCurrentLiquidityYouProvide
Fetches the current liquidity balance provided by a user.
Method Signature
CurrentLiquidityYouProvide(
internalAccount: `0x${string}`
): Promise<string>Parameters
| Parameter | Type | Required | Description |
| ----------------- | ------------------- | -------- | ------------------------------- |
| internalAccount | `0x${string}` | ✅ | User's internal account address |
Returns
string — User's liquidity balance converted from gwei (9 decimals).
Example
const myLiquidity = await liquidity.CurrentLiquidityYouProvide(
"0xa682C9022871881b3257A72E103B50fC75013245"
);
console.log(myLiquidity); // "3.412555239"getMaxOpen
Fetches the maximum amount that can be opened in the liquidity pool. Calculated as (totalAssets - totalFees) / 520.
Method Signature
getMaxOpen(): Promise<number>Returns
number — Max openable amount in USD (6 decimals, mwei-based).
Example
const maxOpen = await liquidity.getMaxOpen();
console.log(maxOpen); // 628.657getMaxTrade
Fetches the total assets available in the liquidity pool.
Method Signature
getMaxTrade(): Promise<string>Returns
string — Total assets converted from Wei (mwei / 6 decimals).
Example
const maxTrade = await liquidity.getMaxTrade();
console.log(maxTrade); // "326901.222201"getPlatformFee
Fetches the total platform fees collected.
Method Signature
getPlatformFee(): Promise<string>Returns
string — Total fees converted from Wei (mwei / 6 decimals).
Example
const fees = await liquidity.getPlatformFee();
console.log(fees); // "1788.410256"getTotalLiquidity
Fetches the total liquidity (total assets) in the pool.
Method Signature
getTotalLiquidity(): Promise<string>Returns
string — Total liquidity converted from Wei (mwei / 6 decimals).
Example
const total = await liquidity.getTotalLiquidity();
console.log(total); // "326901.222201"UserPrviewUnreserve
Previews the unreserve data for a user before executing the unreserve transaction.
Method Signature
UserPrviewUnreserve(
internalAccount: `0x${string}`
): Promise<object>Parameters
| Parameter | Type | Required | Description |
| ----------------- | ------------------- | -------- | ------------------------------- |
| internalAccount | `0x${string}` | ✅ | User's internal account address |
Returns
object — Raw unreserve preview data returned from the contract.
Example
const preview = await liquidity.UserPrviewUnreserve(
"0xa682C9022871881b3257A72E103B50fC75013245"
);
console.log(preview);UserReserved
Fetches the raw reserved amount for a user.
Method Signature
UserReserved(
internalAccount: `0x${string}`
): Promise<bigint>Parameters
| Parameter | Type | Required | Description |
| ----------------- | ------------------- | -------- | ------------------------------- |
| internalAccount | `0x${string}` | ✅ | User's internal account address |
Returns
bigint — Raw reserved amount (not converted).
Example
const reserved = await liquidity.UserReserved(
"0xa682C9022871881b3257A72E103B50fC75013245"
);
console.log(reserved); // 9500000nWrite Methods
Write methods return encoded transaction calldata as an array of EncodedCall objects. They do not execute transactions — you must send them through your own provider or smart account client.
Return Type (All Write Methods)
interface EncodedCall {
to: `0x${string}`;
data: `0x${string}`;
}All write methods return Promise<EncodedCall[]>.
addLiquidityMethod
Builds encoded calldata for depositing liquidity into the pool.
Method Signature
addLiquidityMethod(params: {
amount: string;
smartAccount: string;
}): Promise<EncodedCall[]>Parameters
| Parameter | Type | Required | Description |
| -------------- | -------- | -------- | ------------------------------ |
| amount | string | ✅ | Amount of USDT to deposit |
| smartAccount | string | ✅ | Smart account address |
Example
const calls = await liquidity.addLiquidityMethod({
amount: "1000",
smartAccount: "0xa682C9022871881b3257A72E103B50fC75013245",
});
// Execute via your smart account client
await smartAccountClient.sendTransaction({ calls });removeLiquidity
Builds encoded calldata for withdrawing liquidity from the pool.
Method Signature
removeLiquidity(params: {
address: `0x${string}`;
amount: string;
smartAccount: `0x${string}`;
}): Promise<EncodedCall[]>Parameters
| Parameter | Type | Required | Description |
| -------------- | ------------------- | -------- | ------------------------------- |
| address | `0x${string}` | ✅ | Liquidity provider address |
| amount | string | ✅ | Amount of liquidity to withdraw |
| smartAccount | `0x${string}` | ✅ | Smart account address |
Example
const calls = await liquidity.removeLiquidity({
address: "0xa682C9022871881b3257A72E103B50fC75013245",
amount: "500",
smartAccount: "0xa682C9022871881b3257A72E103B50fC75013245",
});
// Execute via your smart account client
await smartAccountClient.sendTransaction({ calls });addUnReserveMethod
Builds encoded calldata for unreserving liquidity.
Method Signature
addUnReserveMethod(params: {
address: `0x${string}`;
}): Promise<EncodedCall[]>Parameters
| Parameter | Type | Required | Description |
| --------- | ------------------- | -------- | -------------- |
| address | `0x${string}` | ✅ | User's address |
Example
const calls = await liquidity.addUnReserveMethod({
address: "0xa682C9022871881b3257A72E103B50fC75013245",
});
// Execute via your smart account client
await smartAccountClient.sendTransaction({ calls });Allowance Class
Read Methods
checkAllowance
Checks the USDT token allowance for a smart account against the liquidity contract.
Method Signature
checkAllowance(smartAccount: `0x${string}`): Promise<string>Parameters
| Parameter | Type | Required | Description |
| -------------- | ------------------- | -------- | --------------------- |
| smartAccount | `0x${string}` | ✅ | Smart account address |
Returns
string — Allowance amount converted from Wei (mwei / 6 decimals).
Example
const allowanceInstance = new Allowance();
const allowance = await allowanceInstance.checkAllowance(
"0xa682C9022871881b3257A72E103B50fC75013245"
);
console.log(allowance); // "0"getAllowanceByAddress
Checks the USDT token allowance for a smart account against a specific contract address.
Method Signature
getAllowanceByAddress(
smartAccount: `0x${string}`,
contractAddress: `0x${string}`
): Promise<bigint>Parameters
| Parameter | Type | Required | Description |
| ----------------- | ------------------- | -------- | --------------------------------------- |
| smartAccount | `0x${string}` | ✅ | Smart account address |
| contractAddress | `0x${string}` | ✅ | Contract address to check allowance for |
Returns
bigint — Raw allowance value (not converted).
Example
const allowanceInstance = new Allowance();
const allowance = await allowanceInstance.getAllowanceByAddress(
"0xa682C9022871881b3257A72E103B50fC75013245",
"0xc973DE9a335887e86309eC8419E0430fF8C0293c"
);
console.log(allowance); // 9999999999999999999999999999996176830000nRecommended Usage Pattern
import { Liquidity, Allowance } from "rng-layer-sdk";
const liquidity = new Liquidity({ environment: "production" });
const allowanceClient = new Allowance({ environment: "production" });
const myAccount = "0xYourSmartAccount...";
// 1. Read pool state
const totalLiquidity = await liquidity.getTotalLiquidity();
const maxTrade = await liquidity.getMaxTrade();
const maxOpen = await liquidity.getMaxOpen();
const myLiquidity = await liquidity.CurrentLiquidityYouProvide(myAccount);
// 2. Check allowance before depositing
const allowance = await allowanceClient.checkAllowance(myAccount);
// 3. Build deposit calldata
const depositCalls = await liquidity.addLiquidityMethod({
amount: "1000",
smartAccount: myAccount,
});
// 4. Execute via your smart account client
await smartAccountClient.sendTransaction({ calls: depositCalls });
// 5. To withdraw — preview unreserve first, then remove
const preview = await liquidity.UserPrviewUnreserve(myAccount);
const withdrawCalls = await liquidity.removeLiquidity({
address: myAccount,
amount: "500",
smartAccount: myAccount,
});
await smartAccountClient.sendTransaction({ calls: withdrawCalls });Local Development Setup
To use this SDK locally during development:
Navigate to the SDK directory and link it:
cd rng-layer-sdk yarn build yarn linkIn your consumer application directory, link to the local SDK:
cd /path/to/your/consumer/app yarn link "rng-layer-sdk"After making changes to the SDK, rebuild it:
yarn buildRestart your consumer application to pick up the changes.
Versioning Policy
RNG Layer SDK follows Semantic Versioning:
- Patch (
1.0.x) → Bug fixes - Minor (
1.x.0) → New features, backward compatible - Major (
x.0.0) → Breaking API changes
RNG Layer SDK is built to scale with both products and protocols.
