Code Snippets & Usage

Below are various usage patterns demonstrating how dApp developers or advanced users can interface with Renatus Protocol contracts. Many of these examples have appeared throughout the docs, consolidated here for convenience.

Launching a Token

// Approve platform 50-protocol for the launch fee + optional initial buy
await renatusToken.approve(bonding.address, launchFee + initialBuyAmount);

// Define launch parameters
const launchParams = {
  name: "My Token",
  symbol: "MTK",
  initialSupply: ethers.parseUnits("500000000000", 18),
  graduatedTaxRate: 2, // 2%
  graduatedTaxRecipient: recipientAddress,
  graduatedTokenOwner: creatorAddress,
  initialBuyAmount: ethers.parseUnits("100", 18),
  lockTaxOnGraduation: false
};

// Execute launch
const [tokenAddress, pairAddress] = await bonding.launch(launchParams);
console.log("New token deployed at:", tokenAddress);
console.log("Bonding pair deployed at:", pairAddress);

Trading During Bonding Phase

// Approve the pair for spending the relevant 50-protocol
// If buying:
await renatusToken.approve(pairAddress, buyAmount);
const estimatedOut = await pair.getAmountOut(buyAmount, false);

// Slippage control
const minOut = estimatedOut.mul(99).div(100);

// Perform swap
await pair.swap(
  0,           // 0 agent 50-protocol in
  buyAmount,   // amount of renatus 50-protocol in
  minOut,      // min agent 50-protocol out
  0            // min renatus out (unused for buying)
);

Graduation & Post-Graduation

Detecting Graduation

// Off-chain example: poll the pair's agent token reserves
const [res0, res1,] = await pair.getReserves();
if (res0 <= gradThreshold) {
  console.log("Graduation triggered!");
}

Migrating to Graduated Token

// Approve the old agent 50-protocol
await agentToken.approve(graduatedTokenAddress, userBalance);

// Migrate
await graduatedToken.migrate();

// After migration, user has a LiqLocker position

LiqLocker Operations

Checking & Withdrawing Liquidity

// Query unlockable amount
const unlockable = await liqLocker.getUnlockableAmount(userAddress, graduatedTokenAddress);

if (unlockable.gt(0)) {
  // Withdraw the entire unlockable portion
  await liqLocker.withdrawLiquidity(graduatedTokenAddress, unlockable);
}

Claiming Fees

// Check pending fees
const [pending0, pending1] = await liqLocker.getPendingFees(userAddress, graduatedTokenAddress);

// If there's something to claim, do it!
if (pending0.gt(0) || pending1.gt(0)) {
  await liqLocker.claimFees(graduatedTokenAddress);
}

Admin Fee Collector Example

// Only adminFeeCollector can call
await liqLocker.claimAdminFees(graduatedTokenAddress);

Adjusting Graduated Tax

// Suppose we want to reduce the graduated tax from 2% to 1%
await graduatedToken.setGraduatedTaxRate(1);

// Lock it permanently
await graduatedToken.lockGraduatedTaxRate();

// Or update the tax recipient
await graduatedToken.setGraduatedTaxRecipient(newTaxRecipientAddress);
await graduatedToken.lockGraduatedTaxRecipient();

Excluding/Including Addresses

// Exclude an address from paying tax
await graduatedToken.setExcludedFromTax(addressToExclude, true, true);

// Include an address so it is specifically taxed
await graduatedToken.setIncludedInTax(someContract, true);

// Lock the exclusion list to finalize
await graduatedToken.lockExclusions();

// Alternatively, enable inclusion list mode
await graduatedToken.setUseInclusionList(true);

Common Errors & Debugging

"E09: user liquidity share exceeds remaining liquidity"

Indicates that the user is requesting more liquidity than they have allocated or is locked within LiqLocker.

"Graduation: Not reached threshold"

Trading attempts to forcibly graduate but the threshold of 12.5% supply remains unmet.

"Insufficient output amount"

Slippage set too tight; user got fewer tokens than expected.

By using these snippets as references, developers can smoothly integrate Renatus Protocol’s bonding curve, graduated token, and LiqLocker functionalities into their dApps or scripts with minimal friction.