SUN.io 中文文档
SUN.ioSunPump
  • SUN.io 简介
    • 入门指南(TRON)
      • 创建钱包
      • TRON 网络代币标准
      • 连接钱包
    • 风险
    • 白皮书
    • 服务条款
    • 隐私协议
    • 最新公告
  • 开始使用
    • 兑换
      • 代币兑换
        • 如何给token授权?
        • 如何兑换token?
        • 如何查看我最近的交易记录?
        • 如何查看交易对价格走势?
      • 稳定币兑换
        • 稳定币池介绍
        • 如何进行稳定币交易?
        • 如何提供稳定币池的流动性?
        • 如何提取稳定币池流动性?
        • 如何查看自己提供的流动性?
      • 智能路由
      • 交易手续费
        • 收取手续费奖励
      • 流动性资金池
        • 如何创建交易对
        • 如何增加流动性?
        • 如何删除流动性?
        • 增加/删除资金池的token比例是如何计算的?
        • 如何录入一个新的token?
        • 创建资金池初始价格是多少?
      • 代币列表
    • 矿池
      • SUN.io 平台挖矿细则
      • 如何参与LP挖矿?
      • 如何获取LP挖矿收益?
      • 如何退出LP挖矿?
      • 如何计算LP矿池加速倍数?
      • 如何锁定SUN?
      • 如何投票?
      • 如何重置投票?
      • 智能矿池
        • 如何参与 LP 矿池的定期质押?
        • 如何在 LP 矿池中追加定期质押?
        • 如何中途延长 LP 矿池定期质押锁定期?
        • 如何提前解锁 LP 矿池中定期质押的资产?
        • 如何领取 LP 矿池的定期质押奖励?
      • Farm
      • 历史矿池
    • SunPump
      • 🌞 怎么运行的?
      • 🚀 如何启动?
      • 💡代币详情
      • 👤 个人主页
      • 🏦 服务费
      • SunPump DLive Streaming 功能使用教程
    • SunPump Referral
      • 参与方式
      • 活动规则
      • FAQ
    • PSM
      • 如何使用 PSM 在 USDD 和其他稳定币之间进行 1:1 兑换?
    • 代币经济
      • SUN 代币经济模型
        • SUN 回购及销毁
      • veSUN
      • 空投
  • 治理
    • SUN DAO 治理
    • 参与治理
      • 提案
        • SUN DAO 论坛
        • 获得选票
        • 发起提案
        • 进行投票
        • SUN DAO 提案查看
      • DAO 权益
        • 矿池权重
        • veSUN
  • 开发者
    • 兑换
      • 稳定币兑换简介
      • SunSwap兑换简介
      • SunSwap v3兑换简介
      • 智能路由
    • 挖矿
      • 智能挖矿V1
      • 智能挖矿V2
      • 治理挖矿
    • Sunpump
      • Sunpump Contracts
    • Github
    • 相关合约及ABIs
  • FAQ
    • 如何在手机 TronLink APP中使用SUN.io?
    • 价格是由什么决定的?
    • 兑换支持哪些Token?
    • 为什么我的兑换会失败?
    • 关于 SUN.io 平台能量补贴的详细说明
Powered by GitBook
On this page
  • LaunchpadProxy: TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw (Bonding Curve Period)
  • PumpSwapRouter: TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB (Launched to Dex)
  • PumpSmartExchangeRouter: TSiiYf1b1PV1fpT9T7V4wy11btsNVajw1g (Launched to Dex)
  1. 开发者
  2. Sunpump

Sunpump Contracts

PreviousSunpumpNext如何在手机 TronLink APP中使用SUN.io?

Last updated 14 days ago

LaunchpadProxy: TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw (Bonding Curve Period)

** 获取 ABI 代码:

1. createAndInitPurchase Function

描述:

  • 此函数允许创建一个新代币,并立即发起该代币的购买操作。

函数定义:

function createAndInitPurchase(string memory name, string memory symbol) external payable nonReentrant onlyActive

参数:

  • name: 要创建的代币名称。

  • symbol: 要创建的代币符号。

TRX 需求:

  • 你必须发送不少于 mintFee TRX 的调用金额用于铸造该代币。

示例:

  • 注意: 创建代币需支付 20 TRX 的费用。

  • 在此示例中,80 TRX 减去 1% 的手续费将用于初始购买该代币。

const tronWeb = require('tronweb');
const contractAddress = 'TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw';

const name = 'MyToken';
const symbol = 'MTK';
const callValue = 100 * 1e6; // 100 TRX, adjust based on the required mintFee

const createAndInitPurchase = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.createAndInitPurchase(name, symbol).send({
        callValue: callValue
    });
};

createAndInitPurchase();

2. purchaseToken Function

描述:

  • 此函数允许您通过发送 TRX 来购买代币。

函数定义:

function purchaseToken(address token, uint256 AmountMin) public payable nonReentrant onlyActive

参数:

  • token: 要购买的代币地址。

  • AmountMin: 您期望从购买中获得的最小代币数量。

TRX 需求:

  • 您必须发送至少 minTxFee TRX 作为购买的调用值。

相关辅助函数:

  • getTokenAmountByPurchaseWithFee: 使用此函数在购买之前计算预计的代币数量和费用。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const minTokensExpected = 1000 * 1e6; // Adjust based on the minimum tokens expected

const purchaseToken = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const trxAmount = 50 * 1e6; // 50 TRX, adjust as needed
    await contract.purchaseToken(tokenAddress, minTokensExpected).send({
        callValue: trxAmount
    });
};

purchaseToken();

3. saleToken Function

描述:

  • 此功能允许您将代币出售并兑换为TRX。

函数定义:

function saleToken(address token, uint256 tokenAmount, uint256 AmountMin) external nonReentrant onlyActive

参数:

  • token: 要出售的代币地址。

  • tokenAmount: 您想要出售的代币数量。

  • AmountMin: 您预期从出售中获得的最小 TRX 数量。

相关辅助函数:

  • getTrxAmountBySaleWithFee: 使用此函数在出售前计算预估的 TRX 数量和手续费。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokensToSell = 1000 * 1e6; // Amount of tokens to sell, adjust as needed
const minTrxExpected = 50 * 1e6; // Adjust based on the minimum TRX expected

const saleToken = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.saleToken(tokenAddress, tokensToSell, minTrxExpected).send();
};

saleToken();

4. getPrice Function

描述:

  • 此函数返回代币当前的价格(以TRX计价)。

函数定义 :

function getPrice(address token) external view returns (uint256)

参数:

  • token: 查询的代币地址。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address

const getPrice = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const price = await contract.getPrice(tokenAddress).call();
    console.log('Current Price:', price);
};

getPrice();

5. getTokenState Function

描述:

  • 此功能返回代币的当前状态。

函数定义:

function getTokenState(address token) public view returns (uint256)

参数:

  • token: 查询的代币地址。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address

const getTokenState = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const state = await contract.getTokenState(tokenAddress).call();
    console.log('Token State:', state);
};

getTokenState();

6. getTokenAmountByPurchaseWithFee Function

描述:

  • 此功能估算在购买代币时你将获得的代币数量及相关费用。

函数定义:

function getTokenAmountByPurchaseWithFee(address token, uint256 trxAmount) public view returns (uint256 tokenAmount, uint256 fee)

参数:

  • token: 查询的代币地址。

  • trxAmount: 您计划花费的 TRX 数量。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const trxAmount = 50 * 1e6; // 50 TRX, adjust as needed

const getTokenAmountByPurchaseWithFee = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const { tokenAmount, fee } = await contract.getTokenAmountByPurchaseWithFee(tokenAddress, trxAmount).call();
    console.log('Estimated Tokens:', tokenAmount, 'Fee:', fee);
};

getTokenAmountByPurchaseWithFee();

7. getExactTokenAmountForPurchaseWithFee Function

描述:

  • 此功能计算购买指定代币数量所需的确切 TRX 数量及相关费用。

函数定义:

function getExactTokenAmountForPurchaseWithFee(address token, uint256 tokenAmount) public view returns (uint256 trxAmount, uint256 fee)

参数:

  • token: 查询的代币地址

  • tokenAmount: 您希望购买的代币的指定数量。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokenAmount = 1000 * 1e6; // Amount of tokens to purchase, adjust as needed

const getExactTokenAmountForPurchaseWithFee = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const { trxAmount, fee } = await contract.getExactTokenAmountForPurchaseWithFee(tokenAddress, tokenAmount).call();
    console.log('Required TRX:', trxAmount, 'Fee:', fee);
};

getExactTokenAmountForPurchaseWithFee();

8. getTrxAmountBySaleWithFee Function

描述:

  • 此函数估算当卖出指定数量的代币时,您将收到的TRX数量及相关费用。

函数定义:

function getTrxAmountBySaleWithFee(address token, uint256 tokenAmount) public view returns (uint256 trxAmount, uint256 fee)

参数:

  • token: 查询的代币地址

  • tokenAmount: 您希望卖出的代币数量。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const tokenAmount = 1000 * 1e6; // Amount of tokens to sell, adjust as needed

const getTrxAmountBySaleWithFee = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const { trxAmount, fee } = await contract.getTrxAmountBySaleWithFee(tokenAddress, tokenAmount).call();
    console.log('Estimated TRX:', trxAmount, 'Fee:', fee);
};

getTrxAmountBySaleWithFee();

9. getExactTrxAmountForSaleWithFee Function

描述:

  • 此函数计算获取指定数量 TRX 所需的确切代币数量及相关费用。

函数定义:

function getExactTrxAmountForSaleWithFee(address token, uint256 trxAmount) public view returns (uint256 tokenAmount, uint256 fee)

参数:

  • token: 查询的代币地址

  • trxAmount: 您希望接收的指定 TRX 数量。

示例:

const tokenAddress = 'YourTokenAddress'; // Replace with your token address
const trxAmount = 50 * 1e6; // Amount of TRX to receive, adjust as needed

const getExactTrxAmountForSaleWithFee = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const { tokenAmount, fee } = await contract.getExactTrxAmountForSaleWithFee(tokenAddress, trxAmount).call();
    console.log('Required Tokens:', tokenAmount, 'Fee:', fee);
};

getExactTrxAmountForSaleWithFee();

PumpSwapRouter: TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB (Launched to Dex)

** 只允许 Pump 创建的代币与 TRX 的交易对,使用 Sunpump 合约来确定交易对是否被允许进行交易。否则,交易将会被回退。

** 合约 ABI 可以在 TronScan 上找到。

1. swapExactETHForTokens Function

描述:

  • 此函数将指定数量的 TRX 兑换为尽可能多的输出代币,兑换路线由路径确定。

函数定义:

function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)

参数:

  • amountOutMin: 交易不会回滚的情况下,必须接收的最小输出代币数量。

  • path: 一个代币地址的数组。path.length 必须至少为 2。每一对连续地址之间的池子必须存在并且具有流动性。

  • to: 接收输出代币的地址。

  • deadline: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。

TRX 需求:

  • 此函数要求您发送 TRX 作为调用值,TRX 将被兑换为代币。

示例:

const tronWeb = require('tronweb');
const contractAddress = 'TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB';

const amountOutMin = 100 * 1e6; // Example minimum amount of tokens to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time

const swapExactETHForTokens = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapExactETHForTokens(amountOutMin, path, to, deadline).send({
        callValue: tronWeb.toSun(1) // Example: sending 1 TRX
    });
};

swapExactETHForTokens();

2. swapTokensForExactETH Function

描述:

  • 此函数将代币兑换成指定数量的 TRX。

函数定义:

function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)

参数:

  • amountOut: 要接收的指定 TRX 数量。

  • amountInMax: 在交易回退之前可以要求的最大输入代币数量。

  • path: 一个代币地址的数组。第一个地址必须是输入代币地址,最后一个地址必须是 WTRX 地址。

  • to: 接收 TRX 的地址。

  • deadline: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。

示例:

const amountOut = tronWeb.toSun(1); // 1 TRX
const amountInMax = 200 * 1e6; // Example maximum amount of tokens to send
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time

const swapTokensForExactETH = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapTokensForExactETH(amountOut, amountInMax, path, to, deadline).send();
};

swapTokensForExactETH();

3. swapExactTokensForETH Function

描述:

  • 此功能将指定数量的代币兑换成尽可能多的 TRX。

函数定义:

function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)

参数:

  • amountIn: 要发送的指定输入代币数量。

  • amountOutMin: 为防止交易回滚,必须接收的最低 TRX 数量。

  • path: 一个代币地址数组。第一个地址必须是输入代币地址,最后一个地址必须是 WTRX 地址。

  • to: 接收 TRX 的地址。

  • deadline: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。

示例:

const amountIn = 200 * 1e6; // Example amount of tokens to send
const amountOutMin = tronWeb.toSun(0.5); // Example minimum amount of ETH to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time

const swapExactTokensForETH = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapExactTokensForETH(amountIn, amountOutMin, path, to, deadline).send();
};

swapExactTokensForETH();

4. swapETHForExactTokens Function

描述:

  • 此函数将 TRX 兑换成指定数量的代币。

函数定义:

function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)

参数:

  • amountOut: 要接收的指定代币数量。

  • path: 一个代币地址数组。第一个地址必须是 WTRX 地址,最后一个地址必须是输出代币地址。

  • to: 接收代币的地址。

  • deadline: 交易回滚的 Unix 时间戳,超过该时间戳交易将回滚。

TRX 需求:

  • 此函数要求您发送 TRX 作为调用值,这些 TRX 将被交换为代币。

示例:

const amountOut = 200 * 1e6; // Example amount of tokens to receive
const path = ['TOKEN_A_ADDRESS_HERE', 'TOKEN_B_ADDRESS_HERE']; // Example path
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time

const swapETHForExactTokens = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapETHForExactTokens(amountOut, path, to, deadline).send({
        callValue: tronWeb.toSun(1) // Example: sending 1 TRX
    });
};

swapETHForExactTokens();

5. getAmountOut Function

描述:

  • 此函数根据输入的代币数量计算最大输出的代币数量。

函数定义:

function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut)

参数:

  • amountIn: 输入的代币数量。

  • reserveIn: 交易对中输入代币的储备量。

  • reserveOut: 交易对中输出代币的储备量。

示例:

const amountIn = 100 * 1e6; // Example input amount
const reserveIn = 500 * 1e6; // Example reserve of the input token
const reserveOut = 1000 * 1e6; // Example reserve of the output token

const getAmountOut = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const amountOut = await contract.getAmountOut(amountIn, reserveIn, reserveOut).call();
    console.log('Output Amount:', amountOut);
};

getAmountOut();

6. getAmountIn Function

描述:

  • 此函数根据输出的代币数量计算所需的输入代币数量。

函数定义:

function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn)

参数:

  • amountOut: 期望的输出代币数量。

  • reserveIn: 交易对中输入代币的储备量。

  • reserveOut: 交易对中输出代币的储备量。

示例:

const amountOut = 100 * 1e6; // Example output amount
const reserveIn = 500 * 1e6; // Example reserve of the input token
const reserveOut = 1000 * 1e6; // Example reserve of the output token

const getAmountOut = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    const amountOut = await contract.getAmountIn(amountOut, reserveIn, reserveOut).call();
    console.log('Output Amount:', amountOut);
};

7. isAllowedTradingPair Function

描述

  • isAllowedTradingPair 函数用于确定给定的代币交易对是否允许交易。此函数通常用于在去中心化交易所或交易平台内执行针对特定代币对的交易政策或限制。

函数定义:

function isAllowedTradingPair(address tokenA, address tokenB) external view returns (bool);

参数:

  • tokenA: 交易对中第一个代币的地址。

  • tokenB: 交易对中第二个代币的地址。

示例:

const contractAddress = 'YOUR_CONTRACT_ADDRESS_HERE';
const tokenA = 'TOKEN_A_ADDRESS_HERE'; // Replace with the address of token A
const tokenB = 'TOKEN_B_ADDRESS_HERE'; // Replace with the address of token B

const checkTradingPair = async () => {
    try {
        const contract = await tronWeb.contract(abi, contractAddress);
        const isAllowed = await contract.isAllowedTradingPair(tokenA, tokenB).call();
        console.log(`Trading pair (${tokenA}, ${tokenB}) allowed:`, isAllowed);
    } catch (error) {
        console.error('Error checking trading pair:', error);
    }
};

checkTradingPair();

PumpSmartExchangeRouter: TSiiYf1b1PV1fpT9T7V4wy11btsNVajw1g (Launched to Dex)

1.swapExactInput Function

描述

  • swapExactInput 函数是交换操作的统一入口。

函数定义:

function swapExactInput(
        address[] calldata path,
        string[] calldata poolVersion,
        uint256[] calldata versionLen,
        uint24[] calldata fees,
        SwapData calldata data
    ) external nonReentrant payable returns (uint256[] memory amountsOut)

struct SwapData {
        uint256 amountIn;
        uint256 amountOutMin;
        address to;
        uint256 deadline;
    }

参数:

  • path: 代币兑换的地址路径。

  • poolVersion: 路径中代币池子版本列表。

  • versionLen: poolVersion 中代币池子版本的长度列表。

  • fees: 池的费用列表,仅支持 SUNSWAP V3 池。

  • data: 交换信息,使用 SwapData 结构,获取 amountIn(输入代币数量)、amountOutMin(最小输出数量)、接收者地址(to)和截止时间(deadline)。

示例:

const tronWeb = require('tronweb');
const contractAddress ='TSiiYf1b1PV1fpT9T7V4wy11btsNVajw1g
';

const amountOutMin =YOUR_TOKEN_AMOUNT_MIN; // Example minimum amount of tokens to receive
const pathTrxToToken = [address(0),WTRX,TokenAddress]; // Example path
const pathTokenToTrx = [tokenAddress,WTRX,address(0)];
const poolVersion = ["v2"];
const versionLen = ["3"];
const fees = [0,0,0];
const amountIn = YOUR_TOKEN_AMOUNT
const to = 'TYourAddressHere';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
const swapdata = [amountIn,amountOutMin,to,deadline];
// trx - token
const swapExactInput = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapExactInput(
pathTrxToToken, 
poolVersion, 
versionLen, 
fees,
swapdata
).send({
        callValue: tronWeb.toSun(amountIn) // Example: sending 1 TRX
    });
};
// token -trx
const swapExactInput = async () => {
    const contract = await tronWeb.contract(abi, contractAddress);
    await contract.swapExactInput(
pathTokenToTrx, 
poolVersion, 
versionLen, 
fees,
swapdata
).send();
};

** 使用获取交易对地址,然后从该地址获取 getReserves 来获取 token0 和 token1 的储备信息。

implementation address
工厂合约