{"id":20400758,"url":"https://github.com/bifrost-technologies/solnet.jupiterperps","last_synced_at":"2026-03-07T06:02:32.566Z","repository":{"id":247976080,"uuid":"827387335","full_name":"Bifrost-Technologies/Solnet.JupiterPerps","owner":"Bifrost-Technologies","description":"A C# SDK \u0026 Client for Jupiter's Perpetuals Program on Solana","archived":false,"fork":false,"pushed_at":"2025-09-16T22:44:41.000Z","size":53,"stargazers_count":8,"open_issues_count":2,"forks_count":5,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-17T00:44:01.807Z","etag":null,"topics":["csharp","jup-ag","jupiter","perpetuals","perps","solana","solnet","trading"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bifrost-Technologies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-11T14:57:45.000Z","updated_at":"2025-09-16T22:44:45.000Z","dependencies_parsed_at":"2024-07-11T17:30:24.464Z","dependency_job_id":"eb8b5f82-b818-4e62-89ac-269d5592247d","html_url":"https://github.com/Bifrost-Technologies/Solnet.JupiterPerps","commit_stats":null,"previous_names":["bifrost-technologies/solnet.jupiterperps"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Bifrost-Technologies/Solnet.JupiterPerps","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bifrost-Technologies%2FSolnet.JupiterPerps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bifrost-Technologies%2FSolnet.JupiterPerps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bifrost-Technologies%2FSolnet.JupiterPerps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bifrost-Technologies%2FSolnet.JupiterPerps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bifrost-Technologies","download_url":"https://codeload.github.com/Bifrost-Technologies/Solnet.JupiterPerps/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bifrost-Technologies%2FSolnet.JupiterPerps/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30208801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","jup-ag","jupiter","perpetuals","perps","solana","solnet","trading"],"created_at":"2024-11-15T04:45:55.996Z","updated_at":"2026-03-07T06:02:32.547Z","avatar_url":"https://github.com/Bifrost-Technologies.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\t\u003cstrong\u003eSolnet.JupiterPerps\u003c/strong\u003e\u003cbr/\u003e\n\tC# SDK \u0026 Client for interacting with the \u003ca href=\"https://jup.ag\" target=\"_blank\"\u003eJupiter\u003c/a\u003e Perpetuals on-chain program on \u003ca href=\"https://solana.com\" target=\"_blank\"\u003eSolana\u003c/a\u003e.\n\u003c/p\u003e\n\n---\n\n## Overview\n`Solnet.JupiterPerps` is a .NET 8.0 library that enables developers, trading bots, quant systems, and backend services to read on-chain state and craft valid transactions for Jupiter's Perpetuals Program. It builds on top of the official Solnet stack (`Solana.Rpc`, `Solana.Programs`, `Solana.Extensions`, `Solana.KeyStore`).\n\nThe SDK exposes:\n* Low-level instruction builders (via `PerpetualsProgram`) for every supported on-chain instruction.\n* A typed async client (`PerpetualsClient`) to fetch and deserialize program accounts (pools, custodies, positions, position requests, etc.).\n* PDA helpers in `PDALookup` to derive program-derived addresses deterministically.\n* Strongly-typed parameters \u0026 account record classes under `Records/` and `Types/` namespaces.\n\n## Key Capabilities (Current)\n* Discover and load program state: Perpetuals config, pools, custodies, positions, position requests.\n* Create increase \u0026 decrease position market requests including SOL collateral wrapping.\n* Build raw Solana `TransactionInstruction` objects for advanced / custom pipelines.\n* Liquidate or close positions (where permitted by program state and rules).\n* Derive PDAs for custody, pool, and perpetuals accounts.\n\n## Architecture at a Glance\n```\nSolnet.JupiterPerps/\n ├─ JupiterPerpsProgram.cs     // Static instruction builders (serialization + account metas)\n ├─ JupiterPerpsClient.cs      // High-level async RPC client wrappers\n ├─ Utils.cs                   // PDA derivation helpers (PDALookup)\n ├─ Errors.cs                  // Enum mapping on-chain error codes → names\n ├─ Records/                   // Account meta groupings for each instruction\n └─ Types/                     // Parameter + account layout types (Borsh-like serialization)\n```\n\n### Instruction Builders\nEach static method on `PerpetualsProgram` returns a fully populated `TransactionInstruction`:\n```csharp\nvar ix = PerpetualsProgram.IncreasePosition4(accounts, paramsObj);\n```\nThese builders:\n1. Set the correct discriminator / instruction tag (first 8 bytes).\n2. Serialize parameters into the byte buffer.\n3. Attach ordered account metas (read-only / writable / signer flags) as required by the on-chain program.\n\n### High-Level Client\n`PerpetualsClient` wraps RPC account fetch flows with discriminator-based filtering using `getProgramAccounts` and typed deserialization:\n```csharp\nvar rpc = ClientFactory.GetClient(Cluster.MainNet); // from Solnet\nvar perpClient = new PerpetualsClient(rpc);\nvar pools = await perpClient.GetPoolsAsync();\n```\n\n### PDA Utilities\nDeterministic derivations to avoid manual seed handling:\n```csharp\nPublicKey custody = PDALookup.FindCustodyPDA(tokenMint);\nPublicKey pool    = PDALookup.FindPoolPDA(ownerOrSeedKey);\nPublicKey perpCfg = PDALookup.FindPerpetualsPDA(adminOrSeedKey);\n```\n\n## Installation\nAdd the project as a dependency (until published to NuGet):\n1. Clone the repository.\n2. Reference the `.csproj` from your solution or add a project reference:\n\t ```xml\n\t \u003cItemGroup\u003e\n\t\t \u003cProjectReference Include=\"..\\Solnet.JupiterPerps\\Solnet.JupiterPerps.csproj\" /\u003e\n\t \u003c/ItemGroup\u003e\n\t ```\n3. Restore \u0026 build:\n\t ```powershell\n\t dotnet restore; dotnet build -c Release\n\t ```\n\nPlanned: Publish to NuGet as `Solnet.JupiterPerps` once APIs stabilize.\n\n## Quick Start Example: Open / Increase a Position\n```csharp\nusing Solnet.JupiterPerps;\nusing Solnet.Wallet;\nusing Solnet.Rpc;\nusing Solnet.Rpc.Types;\n\n// 1. Initialize RPC + wallet\nvar rpc = ClientFactory.GetClient(Cluster.MainNet);\nvar trader = new Wallet.Wallet(new Mnemonic(\"\u003cseed words\u003e\"));\nvar perpClient = new PerpetualsClient(rpc);\n\n// 2. Build accounts + params (illustrative – adapt to real account keys)\nvar accounts = new CreateIncreasePositionMarketRequestAccounts\n{\n\t\t// Populate: user account, pool, custody, position request PDA, token accounts, oracle feeds, etc.\n};\nvar parameters = new CreateIncreasePositionMarketRequestParams\n{\n\t\t// Populate: size, leverage, side, slippage tolerances, etc.\n};\n\n// 3. Fund with SOL collateral (lamports) and submit combined transaction\nulong collateralLamports = 1_000_000_000; // 1 SOL example\nstring rawResponse = await perpClient.SendCreateIncreasePositionAsync(trader.Account, collateralLamports, accounts, parameters);\nConsole.WriteLine(rawResponse);\n```\n\n## Building Custom Transactions\nIf you need to batch multiple Jupiter Perps instructions, you can manually chain builders:\n```csharp\nvar ix1 = PerpetualsProgram.CreateIncreasePositionMarketRequest(accts1, params1);\nvar ix2 = PerpetualsProgram.InstantCreateLimitOrder(accts2, limitParams);\n\nvar blockhash = (await rpc.GetLatestBlockHashAsync()).Result.Value.Blockhash;\nvar tx = new TransactionBuilder()\n\t\t.SetRecentBlockHash(blockhash)\n\t\t.SetFeePayer(traderPubKey)\n\t\t.AddInstruction(ComputeBudgetProgram.SetComputeUnitLimit(120_000))\n\t\t.AddInstruction(ix1)\n\t\t.AddInstruction(ix2)\n\t\t.Build(traderAccount);\n\nvar sig = await rpc.SendTransactionAsync(tx);\n```\n\n## Error Handling\nOn-chain custom errors are enumerated in `PerpetualsErrorKind` (see `Errors.cs`). A non-exhaustive subset:\n| Code | Name | Meaning |\n|------|------|---------|\n| 6000 | MathOverflow | Internal arithmetic overflow detected |\n| 6022 | MaxLeverage | Requested leverage exceeds pool or custody limits |\n| 6021 | MaxPriceSlippage | Slippage tolerance breached |\n| 6019 | InsufficientTokenAmount | Not enough tokens provided for the action |\n| 6063 | CannotLiquidate | Liquidation conditions not met |\n\nWhen a transaction fails, decode the `InstructionError` → custom error code and map to the enum for user-friendly messaging.\n\n## Security \u0026 Reliability Notes\n* Always verify oracle freshness (stale price errors 6003 / 6046 appear if not).\n* Wrap SOL correctly (the helper flow in `SendCreateIncreasePositionAsync` creates and syncs the associated wSOL ATA).\n* Monitor compute unit usage; complex position flows may require budget increases (`ComputeBudgetProgram`).\n* Validate PDAs locally rather than trusting external input.\n\n## Roadmap / Planned Enhancements\n* Automatic position close helper (removing current manual requirement).\n* Take Profit / Stop Loss management \u0026 update flows (TPSL convenience wrappers).\n* Signed backend co-signature integration (Jupiter API) for close path optimizations.\n* NuGet packaging \u0026 semantic versioning.\n* Expanded high-level convenience methods (e.g., margin health checks, liquidation candidates scan).\n* Optional caching layer for frequently polled accounts.\n\n## Contributing\nPull requests welcome. Please ensure:\n1. Deterministic instruction ordering.\n2. No breaking changes to public method signatures without discussion.\n3. Clear commit messages referencing instruction / feature touched.\n\n## Development\n```powershell\ngit clone https://github.com/Bifrost-Technologies/Solnet.JupiterPerps.git\ncd Solnet.JupiterPerps/Solnet.JupiterPerps\ndotnet build\n```\n\nRun a quick smoke test by attempting to fetch pools:\n```csharp\nvar rpc = ClientFactory.GetClient(Cluster.MainNet);\nvar client = new PerpetualsClient(rpc);\nvar pools = await client.GetPoolsAsync();\nConsole.WriteLine($\"Pools fetched: {pools.ParsedResult?.Count}\");\n```\n\n## Disclaimer\nThis SDK is an independent, community-maintained integration layer. Use at your own risk. Always test with small amounts and review on-chain program updates.\n\n## License\nMIT – see `LICENSE`.\n\n---\nQuestions or feature requests? Open an issue or discussion on the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbifrost-technologies%2Fsolnet.jupiterperps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbifrost-technologies%2Fsolnet.jupiterperps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbifrost-technologies%2Fsolnet.jupiterperps/lists"}