🌳
Bonsai Docs
  • Introduction
    • Bonsai
    • What is Smart Media?
  • Platform
    • No-code creator studio
    • Guide: Create a post
  • Smart Media
    • Framework for builders
  • Building Smart Media
    • ElizaOS server setup
    • Bonsai Client
    • Templates
  • Guide: Create a Template
  • Client Integrations
    • Showing whether a post is Smart Media
    • Linking to Bonsai for remixes
  • Actions
    • Reward Swap
  • Launchpad
    • Overview
    • Getting Started
    • Launchpad Contract
    • Vesting ERC20 Contract
    • Hooks
    • API
      • Tokens
      • Token Balances
      • Buy / Sell Quotes
      • Link your token to a Lens Post & Account
  • ElizaOS
    • plugin-bonsai-launchpad
    • client-lens
Powered by GitBook
On this page
  1. Actions

Reward Swap

Lens action for promoting tokens on Lens Chain via Uniswap V3

PreviousActionsNextOverview

Last updated 15 days ago

Reward Swap is the first action created by Bonsai to give creators more tools to monetize their content more effectively. Reward Swap works by taking a token address as the configuration argument when creating a post. This token must have a pool on the Lens Chain Uniswap V3 deployment. When someone acts on the post they pass in a few parameters and can swap instantly into the post's configured token. If a reward pool has been created for that token then the post creator will earn a commission from the reward pool, if no pool exists they will get 0.25% of the swap output instead.

The contract is deployed on Lens Chain at address:

And you can view the contract metadata .

Contract Spec

  • _configure : called by the action hub when creating the post. Reward Swap expects one parameter with the token address. You can configure your params with viem as such to use with the Lens SDK:

import { blockchainData, evmAddress, uri } from "@lens-protocol/client";

const tokenAddress = "0x123...";
const result = await post(sessionClient, {
  contentUri: uri("lens://4f91ca…"),
  actions: [
    {
      unknown: {
        // RewardSwap on Lens Chain mainnet
        address: evmAddress("0x80Dc28a9Dc227ee5EC717C509c8d6ceB7Bd43C25"), 
        params: [
          {
            raw: {
              // keccak256("lens.param.token")
              key: blockchainData("0xee737c77be2981e91c179485406e6d793521b20aca5e2137b6c497949a74bc94"),
              data: blockchainData(encodeAbi(['address'], [tokenAddress]))
            },
          },
        ],
      },
    },
  ],
});
  • _execute : called by the action hub when someone acts on your post. This will trigger a swap from your desired token into the one configured for the post. You will need a few inputs related to the swap.

import { blockchainData, evmAddress, postId } from "@lens-protocol/client";
import { executePostAction } from "@lens-protocol/client/actions";

// Example function to get a Uniswap V3 path from WGHO -> Bonsai -> Bonsai content coin
const calculatePath = (tokenAddress: `0x${string}`) => {
  return encodePacked(
    ["address", "uint24", "address", "uint24", "address"],
    [WGHO_ADDRESS, 3000, BONSAI_ADDRESS, 10000, tokenAddress],
  );
};

const result = await executePostAction(sessionClient, {
  post: postId("42"),
  action: {
    unknown: {
      // RewardSwap on Lens Chain mainnet
      address: evmAddress("0x80Dc28a9Dc227ee5EC717C509c8d6ceB7Bd43C25"),
      params: [
        {
          raw: {
            // keccak256("lens.param.path");
            key: blockchainData("0xc933ed7045acf6fe8798b8a8ab584b953eb4e2ea05683ebbe5eb3617c481b1f2"),
            // encoded Uniswap V3 path
            value: blockchainData(encodeAbiParameters([{ type: 'bytes' }], [calculatePath(inputToken)])),
          },
        },
        {
          raw: {
            // keccak256("lens.param.amountIn");
            key: blockchainData("0xc933ed7045acf6fe8798b8a8ab584b953eb4e2ea05683ebbe5eb3617c481b1f2"),
            // The amount of your input token to swap in
            value: blockchainData(encodeAbiParameters([{ type: 'uint256' }], [1234n])),
          },
        },
        {
          raw: {
            // keccak256("lens.param.amountOutMinimum");
            key: blockchainData("0xc933ed7045acf6fe8798b8a8ab584b953eb4e2ea05683ebbe5eb3617c481b1f2"),
            // The minimum amount of the output token to receive. Use '0' to disable
            value: blockchainData(encodeAbiParameters([{ type: 'uint256' }], [1233n])),
          },
        },
        {
          raw: {
            // keccak256("lens.param.clientAddress");
            key: blockchainData("0xc933ed7045acf6fe8798b8a8ab584b953eb4e2ea05683ebbe5eb3617c481b1f2"),
            // Client address to receive a small integration fee
            value: blockchainData(encodeAbiParameters([{ type: 'address' }], ["0x543..."])),
          },
        },
        {
          raw: {
            // keccak256("lens.param.referrals");
            key: blockchainData("0xc933ed7045acf6fe8798b8a8ab584b953eb4e2ea05683ebbe5eb3617c481b1f2"),
            // Lens referrals
            value: blockchainData(encodeAbiParameters([{ type: 'address[]' }], [[]])),
          },
        },
      ],
    },
  },
});

if (result.isErr()) {
  return console.error(result.error);
}
  • createRewardsPool : create a reward pool for a token to pay commissions from

/**
* @notice Creates a rewards pool for a given token.
* @param token The token to swap for and distribute rewards for.
* @param rewardsAmount The total amount of rewards to be distributed.
* @param percentReward The percent of each swap to distribute as rewards bps i.e. 1000 = 10%.
* @param capAmount The max amount of rewards to distribute per tx.
* @param clubId The ID of the club on the launchpad for this token.
* @param depositor The address of the depositor.
*/
function createRewardsPool(
    address token,
    uint256 rewardsAmount,
    uint16 percentReward,
    uint256 capAmount,
    uint256 clubId,
    address depositor
) external;
  • withdrawRewards : can be used by a pool creator to withdraw unused rewards

/**
* @notice Withdraws remaining rewards from a pool. Only the creator can withdraw.
* @param token The token to withdraw rewards for.
*/
function withdrawRewards(address token) external;
  • topUpRewards : add more rewards to a pool

/**
* @notice Tops up a rewards pool with additional tokens. Anyone can top up.
* @param token The token to top up.
* @param amount The amount of tokens to add to the pool.
* @param depositor The address of the depositor.
*/
function topUpRewards(address token, uint256 amount, address depositor) external;
0x80Dc28a9Dc227ee5EC717C509c8d6ceB7Bd43C25
here