A Solana-based backend service for TokenMill, providing token management, staking, and vesting functionality.
TokenMill Backend is an Express.js server that interfaces with the TokenMill Solana program, providing REST API endpoints for:
- Token creation and management
- Market operations
- Staking functionality
- Vesting schedules
- Configuration management
- Node.js (v16 or higher)
- npm or yarn
- Solana CLI tools
- A Solana wallet with some SOL for transactions
- Clone the repository:
git clone <repository-url>
cd token-mill-be
- Install dependencies:
npm install
- Create a
.env
file in the root directory:
RPC_URL=https://api.devnet.solana.com
PROGRAM_ID=JoeaRXgtME3jAoz5WuFXGEndfv4NPH9nBxsLq44hk9J
Start the development server:
npm run dev
Build the project:
npm run build
POST /api/config
- Create a new TokenMill configuration- Required body:
{ authority, protocolFeeRecipient, protocolFeeShare, referralFeeShare }
- Required body:
POST /api/quote-token-badge
- Get token badge quote- Required body:
{ quoteTokenMint, baseTokenMint, amount}
POST /api/tokens
- Create a new token- Required body:
{ name, symbol, uri, totalSupply, creatorFeeShare, stakingFeeShare, quoteTokenMint
- Required body:
POST /api/markets
- Create a new market- Required body:
{ name, symbol, uri, totalSupply, creatorFeeShare, stakingFeeShare, quoteTokenMint }
- Required body:
POST /api/stake
- Create a new staking position- Required body:
{ marketAddress }
- Required body:
POST /api/vesting
- Create a new vesting schedule- Required body:
{ marketAddress, recipient, baseTokenMint, amount, duration, cliffDuration }
POST /api/vesting/:marketAddress/claim
- Claim vested tokens- Required params: marketAddress
- Required body: Claim parameters
POST /api/swap
- Excutes swap using swap authority- Required body -
{ action, tradeType, amount, otherAmountThreshold, market, quoteTokenMint }
POST /api/get-asset
- executes get asset metadata using mint address to give the metadata- Required body:
{ assetId }
token-mill-be/
├── src/
│ ├── idl/ # Solana program interface definitions
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions and classes
│ └── index.ts # Main application entry point
├── dist/ # Compiled JavaScript output
├── .env # Environment variables
└── package.json
@coral-xyz/anchor
- Solana development framework@solana/web3.js
- Solana web3 library@solana/spl-token
- SPL Token program interactionsexpress
- Web server frameworktypescript
- Type support- Additional utilities-
big.js
,bn.js
,bs58
,dotenv
- IDL for the program - https://github.com/SendArcade/Token-Mill/tree/main/src/idl
The TokenMillClient
class provides an interface for interacting with the Token-Mill backend.
The TokenMillClient
requires RPC_URL
and WALLET_PRIVATE_KEY
to be set in the environment variables. It initializes:
- A Solana connection
- A wallet from the provided private key
- An Anchor provider and program instance
Creates a new Token-Mill configuration. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L94
- Params:
authority
- The address with configuration management rightsprotocolFeeRecipient
- Address to receive protocol feesprotocolFeeShare
- Percentage of fees allocated to the protocolreferralFeeShare
- Percentage of fees allocated to referrals
- Functionality:
- Generates a new keypair for the configuration
- Calls the Solana program to create a new config
- Sets the new configuration public key
Creates a quote token badge for Wrapped SOL (wSOL
).
function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L128
- Params:
params
- (Currently unused)
- Functionality:
- Fetches account info for
wSOL
- Calls the program to create a quote asset badge
- Signs and sends the transaction
- Confirms the transaction and logs the result
- Fetches account info for
Creates a new market on the Token-Mill platform. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L199
- Params:
name
- Market namesymbol
- Token symboluri
- Token metadata URItotalSupply
- Total token supplycreatorFeeShare
- Percentage of fees allocated to creatorsstakingFeeShare
- Percentage of fees allocated to staking
- Functionality:
- Generates a new base token mint
- Derives necessary PDAs (Program Derived Addresses) for the market and quote token badge
- Creates the market and initializes it with a locked state
- Locks the market using a swap authority
- Calls
setPrices
to establish initial pricing
Creates a new SPL token on Solana. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L399
- Functionality:
- Generates a new mint keypair
- Creates a new mint using the SPL token program
- Creates an associated token account for the user
- Mints an initial supply of 100,000,000 tokens to the user's account
- Returns the mint address and transaction signature
Handles vesting schedules and claiming tokens. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L538
- Params:
marketAddress
- The address of the marketvestingSchedule
- Schedule details (start time, duration, cliff period, etc.)userAddress
- Address of the beneficiary
- Functionality:
- Creates a new vesting schedule by locking tokens in the smart contract
- Allows users to claim vested tokens periodically
- Ensures that tokens are only released according to the defined schedule
- Calls the Solana program to manage vesting logic
Sets the market bid and ask prices. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L342
- Params:
market
- The market public key
- Functionality:
- Defines predefined bid and ask price tiers
- Calls the Solana program to set the prices
- Confirms the transaction and logs the result
Creates a new staking position for a market. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L490
- Params:
marketAddress
- The address of the market
- Functionality:
- Fetches the market details
- Retrieves or creates the staking account
- Calls the Solana program to stake tokens
- Returns the transaction signature
Executes a token swap using the swap authority. function link: https://github.com/SendArcade/Token-Mill/blob/main/src/utils/tokenMill.ts#L818
- Params:
marketAddress
- The address of the marketamount
- Amount of tokens to swapuserAddress
- Address of the user executing the swap
- Functionality:
- Fetches the market details
- Ensures the user has sufficient balance
- Calls the Solana program to execute the swap
- Returns the transaction signature
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
ISC License
For support, please open an issue in the repository or contact the maintainers.