{"id":27066032,"url":"https://github.com/balancednetwork/balanced-solana-contracts","last_synced_at":"2025-04-05T18:34:46.867Z","repository":{"id":250254514,"uuid":"816168550","full_name":"balancednetwork/Balanced-Solana-contracts","owner":"balancednetwork","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-20T07:18:33.000Z","size":5477,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-20T07:38:03.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/balancednetwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-06-17T07:13:41.000Z","updated_at":"2024-12-16T07:32:57.000Z","dependencies_parsed_at":"2025-02-20T07:32:30.627Z","dependency_job_id":"b770d505-1544-4b00-945d-47b58f533376","html_url":"https://github.com/balancednetwork/Balanced-Solana-contracts","commit_stats":null,"previous_names":["balancednetwork/balanced-solana-contracts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balancednetwork%2FBalanced-Solana-contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balancednetwork%2FBalanced-Solana-contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balancednetwork%2FBalanced-Solana-contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balancednetwork%2FBalanced-Solana-contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/balancednetwork","download_url":"https://codeload.github.com/balancednetwork/Balanced-Solana-contracts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247384924,"owners_count":20930557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-04-05T18:34:46.193Z","updated_at":"2025-04-05T18:34:46.856Z","avatar_url":"https://github.com/balancednetwork.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Balanced Solana Programs\n\n## Overview\n\nThe Balanced programs on Solana blockchain ecosystem is designed to manage various aspects of the decentralized application (dApp) including asset management, stablecoin operations and crosschain administration. This structure ensures efficient handling of these operations through well-defined programs with unique program ID.\n\n## Programs\n\nThere are three solana programs associated with balanced, each responsible for specific functionalities:\n\n### 1. Asset Manager: asset_manager\n\n-  **Purpose**: Manages assets within the Balanced ecosystem.\n\n### 2. xCall Manager: xcall_manager\n\n-  **Purpose**: Facilitates cross-chain administration from the icon side.\n\n### 3. Balanced Dollar: balanced_dollar_crosschain\n\n-  **Purpose**: Manages the crosschain bnUSD operations within the Balanced ecosystem.\n\n## Identifiers\n\n### Program IDs\n\n-  **Definition**: Unique identifiers for each program, akin to contract addresses in other blockchain ecosystems.\n\n-  **Usage**:\n\n- Each program (Asset Manager, xCall Manager, Balanced Dollar) has its own Program ID.\n\n- Program IDs are used for configuring the Balanced programs in other chains.\n\n- They enable specific interactions and operations within each program, ensuring modular and isolated management of functionalities.\n\n\n## Usage in Cross-Chain Configuration\n\n-  **Configuration**: Program IDs are critical for setting up Balanced in cross-chain environments. They ensure that each module can be independently addressed and interacted with from other chains.\n\n-  **Function Calls**: The Program ID is used for function calls from the Solana blockchain, there is no cli infrastructure for function calls on Solana ecosystem, the main reason for this is all accounts used in the transaction should be passed while calling a function on Solana, and that makes it complex to use shell command\n\n## Frontend Integration Interfaces\n\nThis guide provides an overview of the key functions for interacting with the Solana blockchain within your frontend application. These functions are part of the Asset Manager, Balanced Dollar, and XCall Programs, which allow for token deposits, cross-chain transfers, and cross-chain calls.\n\n### Important Note: Accessing states in Solana\nIn Solana programs data are stored in specific accounts, those data later can be read directly from the program accounts providing the specific account, Hence there is no read api's available on the Solana programs\n\n\n### Important Note: Statelessness in Solana\n\nSolana is a stateless blockchain, which means that unlike stateful blockchains, it does not automatically keep track of states between transactions. Due to this, when interacting with Solana, you need to provide all the accounts used in the transaction. \n\nThe transaction may include multiple program such that accounts of multiple programs should be provided with the Function call. The accounts of the called program are sent on the \"accountsStrict\" and the accounts of the other programs are sent on the \"remainingAccounts\". For the user accounts and program ids the public key is used, system Id is provided by SDK and the accounts of data storage (PDAs =\u003e Program derived accounts) are derived using program Id and seeds that are defined by the programs.\n\n  #### PDAs of Asset Manager Program\n\n```typescript \nstatic state() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"state\")],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic token_state(mint: PublicKey) {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"token_state\"), mint.toBuffer()],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic vault(mint: PublicKey) {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"vault\"), mint.toBuffer()],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic vault_native() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"vault_native\")],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic rate_limit(token_key: Buffer) {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"rate_limit\"), token_key],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic xcall_manager_state() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"state\")],\n\txcallManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic xcall_authority() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"dapp_authority\")],\n\tassetManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n```\n#### PDAs of Balanced Dollar Program\n\n```typescript\nstatic state() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"state\")],\n\tbalancedDollarProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic program_authority() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"bnusd_authority\")],\n\tbalancedDollarProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic xcall_manager_state() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"state\")],\n\txcallManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n\nstatic xcall_authority() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"dapp_authority\")],\n\tbalancedDollarProgram.programId\n\t);\n\treturn { bump, pda };\n}\n```\n#### PDAs of Xcall Manager Program\n```typescript\nstatic state() {\n\tlet [pda, bump] = PublicKey.findProgramAddressSync(\n\t[Buffer.from(\"state\")],\n\txcallManagerProgram.programId\n\t);\n\treturn { bump, pda };\n}\n```\n####  The Xcall and Centralized connection PDAs are available in their document \n---\n\n  \n\n### Asset Manager Program\n\nThe Asset Manager Program handles depositing Solana native token and Solana SPL tokens in balanced.\n\n  \n\n#### `deposit`\n\nDeposits a specified amount of a token into the Solana blockchain.\n```typescript\nfunction deposit_token(\n\tctx: Context\u003cDepositToken\u003e, //All the required accounts are passed on the transaction context, In case of optional acccount, if not needed can be sent null\n\tamount: u64, //amount of token being deposited\n\tto: Option\u003cString\u003e,// (Optional) The recipient's address if needed\n\tdata: Option\u003cVec\u003cu8\u003e\u003e //(Optional) An additional data you want to attach to the deposit\n)\n```\n ##### Calling the deposit method using Typescript \n\n```typescript \n\tawait program.methods.depositToken(\n\t\tbn(1000000000),\n\t\tdepositorTokenAccount.address.toString(),\n\t\tbytes\n\t).accountsStrict({\n\t\tfrom: depositorTokenAccount.address,\n\t\tvaultNativeAccount: null,\n\t\tfromAuthority: depositorKeyPair.publicKey,\n\t\tvaultTokenAccount: vaultTokenAccount.address,\n\t\tvaultAuthority: AssetManagerPDA.vault(mint).pda,\n\t\tstate: AssetManagerPDA.state().pda,\n\t\txcallManagerState: AssetManagerPDA.xcall_manager_state().pda,\n\t\txcallConfig: XcallPDA.config().pda,\n\t\txcall: xcall_program.programId,\n\t\txcallManager: xcall_manager_program.programId,\n\t\ttokenProgram: TOKEN_PROGRAM_ID,\n\t\tsystemProgram: SYSTEM_PROGRAM_ID,\n\t\txcallAuthority: AssetManagerPDA.xcall_authority().pda,\n\t}).remainingAccounts([\n\t\t{\n\t\t\tpubkey: XcallPDA.config().pda,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\t\t{\n\t\t\tpubkey: XcallPDA.rollback(xcall_config.sequenceNo.toNumber() + 1).pda,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\t\t{\n\t\t\tpubkey: new PublicKey(\"Sysvar1nstructions1111111111111111111111111\"),\n\t\t\tisSigner: false,\n\t\t\tisWritable: false,\n\t\t},\n\t\t{\n\t\t\tpubkey: xcall_config.feeHandler,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\n\t\t//connection params\n\t\t{\n\t\t\tpubkey: connectionProgram.programId,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\t\t{\n\t\t\tpubkey: ConnectionPDA.config().pda,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\t\t{\n\t\t\tpubkey: ConnectionPDA.network_fee(IconNetworkId).pda,\n\t\t\tisSigner: false,\n\t\t\tisWritable: true,\n\t\t},\n\t]).instruction();\n\t\n\tconst modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({\n\t\tunits: 1000000,\n\t});\n\t\n\tconst addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({\n\t\tmicroLamports: 0,\n\t});\n\t\n\tlet tx = await ctx.txnHelpers.buildV0Txn(\n\t\t[modifyComputeUnits, addPriorityFee, depositTokenIx],\n\t\t[depositorKeyPair]\n\t);\n\tawait connection.sendTransaction(tx);\n```\n---\n### Balanced Dollar Program\n\nThe Balanced Dollar module facilitates the transfer of `BALANCED_DOLLAR` tokens across chains.\n\n#### `cross_transfer`\n\nTransfers `BALANCED_DOLLAR` tokens across chains.\n\n```typescript\nfunction cross_transfer(\n\tctx: Context\u003cCrossTransfer\u003e, //All the required accounts are passed on the transaction context, In case of optional acccount, if not needed can be sent null\n\tto: String,  // The recipient's address on the destination chain.\n\tvalue: u64,  // the bnUSD amount being transferred\n\tdata: Option\u003cVec\u003cu8\u003e\u003e, // (Optional) Any additional data to attach to the transfer.\n)\n```\n\n### XCallManager Program\nThe xcall manager program incluses the crosschain administration features. In Solana data stored on accounts can be accessed directly via programs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalancednetwork%2Fbalanced-solana-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalancednetwork%2Fbalanced-solana-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalancednetwork%2Fbalanced-solana-contracts/lists"}