Skip to content

DMANDATE/DMANDATE

Repository files navigation

DMANDATE

Decentralized Recurring Payments on Solana

πŸ“‹ ## βš™οΈ Backend Processor

The backend processor is a TypeScript-based service that monitors active mandates and automatically executes payments when due. It includes:

  • Mandate monitoring: Continuously scans for mandates approaching their next payment date
  • Automatic execution: Executes payments on behalf of users at the scheduled intervals
  • Transaction logging: Keeps detailed records of all payment transactions

πŸš€ Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/DMANDATE/DMANDATE.git
    cd DMANDATE
  2. Install dependencies:

    npm install
    cd cli && npm install && cd ..
    cd backend && npm install && cd ..
  3. Build the program:

    anchor build
  4. Deploy to devnet (if needed):

    anchor deploy --provider.cluster devnet

Running the CLI

cd cli
npm run start

Running the Backend Processor

cd backend
npm run start

πŸ“š Documentation

For detailed information about the project workflow, see workflow.md.

For deployment details, see DEPLOYMENT.md.

🀝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

πŸ“„ License

This project is licensed under the MIT License.


Organization: DMANDATE
Developer: DEEPANSHUormation

Organization: DMANDATE
Developer: DEEPANSHU
Network: Solana Devnet
Program ID: 8kHcaQxyxKFAK6t8KRKDUmn9FaHGZi8kwomBaSDVc4X1
Deployment Signature: 5L6VAUU4KzXy1KwnGgoJRPMSny75KgeyQsiRjRPL3mw9Jy2rEAYYARpnhtp4vGvVUTKZMGRJFNfkZMqCd1DRx5yh

πŸ“Š View on Solana Explorer

πŸš€ About

DMANDATE is a Solana-based protocol for decentralized recurring payments. Users pre-approve a PDA to transfer tokens (e.g., USDC) without locking funds. A backend processes payments at scheduled intervals, ensuring self-custody and transparency. Ideal for subscriptions, salaries, and bills, DMANDATE offers a trustless, non-custodial alternative to traditional e-mandates.

✨ Features

  • Non-custodial recurring payments: Users maintain control of their funds at all times
  • Programmable payment schedules: Set custom frequencies for payment execution
  • Transparent on-chain history: All payments and mandates are recorded on the Solana blockchain
  • Automated payment processing: Backend service checks and executes due payments
  • User-friendly CLI: Command-line interface for managing mandates and payments
  • Web3 friendly: Built natively for Solana's SPL tokens
image

πŸ“ Repository Structure

dmandate/
β”œβ”€β”€ backend/             # Backend payment processor service
β”‚   β”œβ”€β”€ idl/             # Anchor IDL for the dmandate program
β”‚   └── src/             # Source code for the mandate processor
β”œβ”€β”€ cli/                 # Command-line interface tool
β”œβ”€β”€ programs/            # Solana smart contracts written in Rust
β”‚   └── dmandate/        # Main dmandate program
└── tests/               # Integration tests for the program

πŸ”§ Smart Contract

The DMANDATE smart contract is built using the Anchor framework and includes the following key instructions:

  • register_user: Registers a user in the system
  • create_mandate: Creates a new recurring payment mandate
  • execute_payment: Executes a payment for an active mandate
  • cancel_mandate: Cancels an active mandate
  • reapprove_mandate: Updates the approval amount for an existing mandate
  • close_payment_history: Closes a payment history record to reclaim rent

Backend Mandate Processor

The backend service monitors active mandates on the Solana blockchain and automatically executes payments when they are due.

Features

  • Periodic checking of all active mandates
  • Automatic payment execution for due mandates
  • Error handling for failed payments
  • Configurable settings via environment variables or config file
  • Logging of all operations

Configuration

The mandate processor can be configured with the following options:

Option Environment Variable Description Default
Check Interval CHECK_INTERVAL How often to check for payable mandates (ms) 60000 (1 min)
RPC URL RPC_URL Solana RPC URL http://localhost:8899
Keypair Path KEYPAIR_PATH Path to keypair JSON file ~/.config/solana/id.json
Program ID PROGRAM_ID DMANDATE program ID 8kHcaQxyxKFAK6t8KRKDUmn9FaHGZi8kwomBaSDVc4X1
Batch Size BATCH_SIZE Max mandates to process in one batch 100
Buffer Time BUFFER_TIME Time buffer before scheduled payment (seconds) 60
Log Level LOG_LEVEL Logging level (debug, info, warn, error) info
Notifications ENABLE_NOTIFICATIONS Enable payment notifications false

CLI Tool

The DMANDATE CLI tool provides a convenient way to interact with the smart contract.

See the CLI README for detailed usage instructions.

Installation & Setup

Prerequisites

  • Node.js v14+ and npm
  • Rust and Cargo
  • Solana CLI tools
  • Anchor Framework

Setting Up the Project

  1. Clone the repository:

    git clone https://github.com/yourusername/dmandate.git
    cd dmandate
  2. Install dependencies:

    npm install
  3. Build the Solana program:

    anchor build
  4. Generate the program ID (if needed):

    solana-keygen new -o target/deploy/dmandate-keypair.json
    anchor keys list

    Update the program ID in Anchor.toml and lib.rs

  5. Setup the backend processor:

    cd backend
    npm install
  6. Setup the CLI:

    cd cli
    npm install
    npm link  # Optional, to use CLI globally
  7. Create a .env file in the backend directory:

    RPC_URL=https://api.devnet.solana.com
    KEYPAIR_PATH=/path/to/your/keypair.json
    CHECK_INTERVAL=60000
    BUFFER_TIME=60
    LOG_LEVEL=info
    

Running the Mandate Processor

cd backend
npm run build
node dist/index.js

Or use a process manager like PM2:

npm install -g pm2
pm2 start dist/index.js --name mandate-processor

Development

Local Development Environment

  1. Start a local Solana validator:

    solana-test-validator
  2. Deploy the program to the local network:

    anchor deploy
  3. Run the mandate processor against local network:

    cd backend
    RPC_URL=http://localhost:8899 npm run start

Making Changes to the Smart Contract

  1. Modify code in programs/dmandate/src/
  2. Build with anchor build
  3. Update IDL if needed: anchor idl parse -f programs/dmandate/src/lib.rs -o target/idl/dmandate.json
  4. Copy the new IDL to the backend: cp target/idl/dmandate.json backend/idl/
  5. Deploy: anchor deploy

Testing

Smart Contract Tests

Run the test suite:

anchor test

Backend Tests

cd backend
npm test

Deployment

Program Deployment

  1. Build the program:

    anchor build
  2. Deploy to your desired network:

    anchor deploy --provider.cluster devnet  # For devnet
    # OR
    anchor deploy --provider.cluster mainnet  # For mainnet
  3. Verify the program ID and update configuration as needed.

Backend Deployment

  1. Build the backend:

    cd backend
    npm run build
  2. Deploy using your preferred method (PM2, Docker, cloud services).

  3. Make sure to set the appropriate environment variables for your deployment.

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published