James Bachini

Pump.fun Clone In Solidity

Pump Fun Solidity

Pump.fun is a token factory that lets users create and trade memecoins on Solana with dynamic pricing along a bonding curve. In this article I’ll show how I went about converting this concept to Solidity and deploying it on Ethereum.

Full code for this is open source at: https://github.com/jamesbachini/Pump.sol


Token Factory Contract

At the core of the Pump.fun clone is a factory contract that allows anyone to create their own ERC20 tokens. This is a fundamental aspect of the platform because it enables users to easily deploy custom tokens that they can hold, trade, and manage using wallets like MetaMask. By creating a token standard it creates a fair playing field in which users know that the tokens generated don’t have malicious internal functions.

MemeToken newToken = new MemeToken(name, symbol, description, image, twitter, telegram, website, msg.sender);

The code above is the business end of this factory contract. It takes in the user defined values and sets up a new ERC20 token.

In the Solidity implementation, the MemeTokenFactory works by allowing users to input a token name, symbol, description, and other metadata. When a user calls the createToken function, a new instance of the MemeToken contract is deployed. These tokens are fully compliant with the ERC20 standard, so they integrate seamlessly with Ethereum wallets like MetaMask.

https://pump.fun frontend

Buy And Sell Along A Bonding Curve

One of the interesting aspects of Pump.fun is its internal market system that allows users to buy and sell tokens based on a bonding curve. In this Solidity clone, the MemeToken contract handles the dynamic pricing of tokens. The price of each token increases exponentially as more ETH is added to the contract, making it more expensive to buy tokens over time.

function getCurrentPrice() public view returns (uint tokensPerETH) {
    uint remainingTokens = balanceOf(address(this));
    uint contractETHBalance = address(this).balance;
    if (contractETHBalance < 0.01 ether) contractETHBalance =  0.01 ether;
    tokensPerETH = remainingTokens * 1e18 / contractETHBalance;
}

Here’s how it works:

  • Buying Tokens Users can call the buyTokens function to purchase tokens directly from the contract by sending ETH. The price is determined by a bonding curve, where the more ETH the contract holds and the less remaining tokens in the contract, the higher the price per token. As the contract accumulates more ETH (liquidity), this ratio shifts making tokens more expensive to acquire.
  • Selling Tokens Similarly, users can call the sellTokens function to sell their tokens back to the contract and receive ETH in return. The selling price is also dictated by the bonding curve, which ensures that users get a price based on the increasing token holdings and decreasing eth in the contract. This system mimics a natural supply and demand mechanism, incentivizing early buyers and creating scarcity as demand increases.

Although the current implementation provides a solid foundation for a dynamic token marketplace, one feature that is missing is the ability to add liquidity to Uniswap or other decentralized exchanges. When a Pump.fun token reaches a threshold all the liquidity is moved to the Radium dex and trading goes live on the 3rd party platform. In a future version of this Solidity clone, this functionality could be easily integrated.

It’s important to note that this code is experimental and not fit for production use. The code is designed to illustrate the basic mechanics of token creation and trading using a bonding curve but lacks the rigorous testing and security audits needed for a production level project. There are no guarantees for security or performance, and deploying this code in a live environment should be done with extreme caution.


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.