This project is a smart contract built on the Solana, designed to facilitate limit order trading of tokens. The program allows users to create, update, and manage limit orders, offering flexibility in trading while ensuring security and transparency.
- Initialization: Create a vault for tokens, specifying the amount to sell, price per token, and an expiration time after which the trade cannot occur.
- TransferToken: Transfer a specified amount of tokens to the vault created during initialization.
- Claim: Check if the expiration time has been reached and, if not, facilitate the trade by transferring tokens to the buyer and sending the equivalent worth of USDC tokens to the seller.
- Update: Allows the seller to update the price of each token and modify the expiration time.
- Close: Check if partial Trade if not, return the tokens to the seller, close the vault, and return the remaining lamports to the seller.
- Initialization:
- The seller initializes the order by specifying the details of the trade, including the token amount, price, and expiration time.
- A vault is created to hold the tokens until the trade is executed or canceled.
- TransferToken:
- The seller transfers the specified amount of tokens to the vault.
- Claim:
- The buyer claims the tokens by sending the required amount of USDC to the seller.
- The tokens are transferred from the vault to the buyer if the expiration time has not been reached.
- If the expiration time has passed, the trade is no longer valid.
- Update:
- The seller can update the price per token and the expiration time before the trade is executed.
- Close:
- If the partial trade does not happen, the seller can close the order, which returns the tokens to the seller, closes the vault, and refunds the lamports.
- Rust
- Solana CLI
- Anchor (for Solana smart contract development)
-
Clone the repository:
git clone https://github.com/AhzamAkhtar/cega-fi-assignment
-
Build the project:
anchor build
-
Deploy the program to the Solana network:
anchor deploy
-
Install the packages required for testing
yarn install
-
Go To Anchor.toml and put your rpc-url and update your programID
[programs.localnet] cega = "" // your new program ID
-
Go To tests/cega.ts and update the programId
const programId = new PublicKey(""); // Enter your new programID
-
Finally Test the Smart Contract by doing
For Testing on Localhost 1. solana-test-validator 2. anchor test --skip-local-validator
Note - Cancel test (which close the order) cannot run because a partial trade has already been made in a test above.