--- title: HackMD Dark Theme tags: theme description: Use `{%hackmd theme-dark %}` syntax to include this theme. --- <style> html, body, .ui-content { background-color: #333; color: #ddd; } .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { color: #ddd; } .markdown-body h1, .markdown-body h2 { border-bottom-color: #ffffff69; } .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { color: #fff; } .markdown-body img { background-color: transparent; } .ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a { color: white; border-left: 2px solid white; } .expand-toggle:hover, .expand-toggle:focus, .back-to-top:hover, .back-to-top:focus, .go-to-bottom:hover, .go-to-bottom:focus { color: white; } .ui-toc-dropdown { background-color: #333; } .ui-toc-label.btn { background-color: #191919; color: white; } .ui-toc-dropdown .nav>li>a:focus, .ui-toc-dropdown .nav>li>a:hover { color: white; border-left: 1px solid white; } .markdown-body blockquote { color: #bcbcbc; } .markdown-body table tr { background-color: #5f5f5f; } .markdown-body table tr:nth-child(2n) { background-color: #4f4f4f; } .markdown-body code, .markdown-body tt { color: #eee; background-color: rgba(230, 230, 230, 0.36); } a, .open-files-container li.selected a { color: #5EB7E0; } </style> # Intro Welcome to the Raisin Protocol breakdown. The core of the protocol is a smart contract that is both elegant and efficient. Below describes the core functionality of the protocol and their signature hashes. I made this as easy as possible to work with. # Integration Raisin can be integrated with third parties in a few different ways. At the protocol level, it is easy for multisigs and DAOs to start and manage a raisin directly from their contract by calling ours! Raisin will deploy everywhere from Layer 1 to multiple layer 2s. Out of the box you have a fully customizable fundraising protocol! There's a plethora of moderation features that can easily be added to the front-end. Raisin is gas efficient with the highest potential gas cost at ~120K. Smart contracts will scale only as well as the blockchain it is placed on. To call Raisin from your frontend, you will likely do 1 of 3 things. Web3.js, Ethers.js or WAGMI. In any case you need to configure the contract object using the ABI and address and the network it is on. Since the contract is ready out of the box, all you must do is call functions as a response to events. # Important Functions #### #### **9bf952b5 => initFund(uint amount, IERC20 token, address recipient)** Begins a raisin! Takes in the goal amount, the token's contract address, and the wallet of the beneficiery. After this function is called, a new raisin is created. #### **813c4274 => endFund(uint index)** Ends a fund. Can be called at any time by the fund owner. #### **cb7b75a9 => donateToken(IERC20 token, uint index, uint amount)** Allows a user to donate to any raisin in its designated token. Takes in a token's contract address, the raisin's index, and the amount to donate. #### **6f8c336e => fundWithdraw(uint index)** If the fundraise was successful then the funds can be withdrawn to the wallet of the beneficiary. Takes in a token's contract address, the raisin's index. #### **d613f2b3 => refund(uint index)** If the fundraise was not successful, the donors are able to withdraw their donations individually by calling this function. Takes in a token's contract address and the raisin's index. ![Protocol Flow](https://i.imgur.com/hOIhQiE.png) # Interacting via Smart Contract These are working examples that allow you to interact with the Raisin protocol. These examples simply work, feel free to change stuff around to fit your usecase & needs. ```solidity= import "./Raisin.sol"; contract example { //declare Raisin contract as type RaisinCore RaisinCore public raisin; constructor (address raisin) { //typecast raisin to RaisinCore and set state variable raisin = RaisinCore(raisin); } function readRaisinState(uint index) public view returns ((uint, IERC20, address)){ //get fund balance for a raisin at array {uint} index uint x = raisin.getFundBal(index); //get {IERC20} token accepted by the cause IERC20 y = raisin.getToken(index); //get {address} beneficiary of the cause address z = raisin.getRecipient(index); return (x, y, z); } //amount must use WEI floating point approximation 1 = 1e18 = 1 * 10 ** 18 //index is the position the raisin occupies in the array //token is the token contract //recipient is the address that the funds will go to on success function raisinInitFund(uint amount, IERC20 token, address recipient) external{ //start a fund (bool sent,) = raisin.initFund(amount, token, recipient); require (sent); } function raisinEndFund(uint64 index) external { //end your fund (bool sent,) = raisin.endFund(index); require (sent); } function raisinDonate(IERC20 token, uint64 index, uint amount) external { //donate to a fund (bool sent,) = raisin.donateToken(amount, token, recipient); require (sent); } function raisinfundWithdraw(uint index) external { //withdraw the fund balance upon a successful fundraising campaign (bool sent,) = raisin.fundWithdraw(token, index); require (sent); } function anotherWayToWithdraw(uint index) external returns((bool, bytes memory){ (bool sent, bytes memory) = raisin.call{value: msg.value, gas: 50000}( abi.encodeWithSignature("fundWithdraw(uint)", index); ); require(success); return (sent, memory); } function raisinRefund(uint index) external returns(){ //if the fundraising effort failed, users are automatically refunded. Make sure you can recover funds in this event unless you are handling it yourselves (bool sent,) = raisin.refund(index); require(sent); } } ```