code
unknown
latex
2 years ago
15 kB
7
Indexable
Never
%todo : biblio \chapter{Project Realization: Algorand in Nova DeFi} \section*{Introduction} And finally in the third chapter we’re going to present our contribution to the project along with explaining in detail the progress steps of integrating Algorand into Nova. \section{Connect on Nova with Agorand} \subsection{Connecting your Algorand account } \subsubsection{Home Page} On the home page you’ll find the ‘CONNECT WALLET’ button which will allow the access to the ‘Algosigner’ wallet extension on your browser thanks to the Algosigner.connect() function. \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/nova.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Wallet Selection} Select the Algorand option in order to connect to the Algosigner wallet \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/wallet-selection.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Account Selection} \paragraph{Grant Acces to Algosigner} \begin{figure} \centering \includegraphics{images/algo-signer.png} \caption{Caption} \label{fig:algo-signer} \end{figure} \paragraph{Choosing an account} \begin{figure} \centering \includegraphics[width=\textwidth]{images/algo-signer-account.png} \caption{Caption} \label{fig:algo-signer-account} \end{figure} \paragraph{Chosesn account list} \begin{figure} \centering \includegraphics[width=\textwidth]{images/account-number.png} \caption{Caption} \label{fig:account-number} \end{figure} \section{Using the Nova website app} \subsection{Welcome page} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-welcome.png} \caption{Caption} \label{fig:my_label} \end{figure} As we can see the second account on the wallet has been connected And connection type is displayed beside it In this case we are on the Testnet \begin{figure} \centering \includegraphics[width=\textwidth]{images/testnet-status.png} \caption{Caption} \label{fig:my_label} \end{figure} When we click on the account’s address this window will display info related to the account Like \textbf{Wallet type} , \textbf{full account address} and \textbf{Balance}. \begin{figure} \centering \includegraphics[width=\textwidth]{images/account-info.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsection{Portfolio page} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio.png} \caption{Caption} \label{fig:my_label} \end{figure} On this Page we can start the portfolio creation process by clicking the ‘Create a Portfolio’ button \subsubsection{Creating new portfolio steps} \begin{figure} \centering \includegraphics[width=\textwidth]{images/portfolio-create.png} \caption{Caption} \label{fig:my_label} \end{figure} \paragraph{Adding an asset step} Each portfolio must contain at least one asset We’re working with algorand so we chose two assets supported by the algorand blockchain \subparagraph{Add step} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-add.png} \caption{Caption} \label{fig:my_label} \end{figure} On this page we can select an asset to add to the portfolio on asset at a time because we will need to choose a \textbf{Program} and a \textbf{yield strategy} for each asset \subparagraph{Program step} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-program-selection.png} \caption{Caption} \label{fig:my_label} \end{figure} On this page we can choose three types of programs for our asset \begin{itemize} \item Take Profit (TP): This programmable asset regularly sells a percentage of an asset into USDC and places the profits into a yield strategy. It can be useful for building a good average exit price from a cryptocurrency that is experiencing consistent growth . \item Conditional Distribution (CD): These assets use triggers to determine an action. For example, if the price of the asset rises 30\% in one day, you can apply a trigger to swap a percentage of the asset into another. \item Reduced Volatility (RV): These assets allow a user to have exposure to an asset but reduce some of the volatility by allocating a percentage into a more stable asset like USDC. \end{itemize} For the rest of this demonstration we can use any type of program because we’re just testing \subparagraph{Percentage selection} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-percentage-selection.png} \caption{Caption} \label{fig:my_label} \end{figure} After choosing a program we have to select the asset percentage that will be sold into the other asset \subparagraph{Yield strategy} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-yield.png} \caption{Caption} \label{fig:my_label} \end{figure} After choosing the strategy you’ll be reverted back to creation page After that we have the option to add an other asset each with their own program and yield strategy \subparagraph{Portfolio with one asset} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-asset.png} \caption{Caption} \label{fig:my_label} \end{figure} \subparagraph{Portfolio with 2 assets} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-2-assets.png} \caption{Caption} \label{fig:my_label} \end{figure} \paragraph{Information Page step} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-information.png} \caption{Caption} \label{fig:my_label} \end{figure} On this page we provide important useful information for users visiting the portfolio Which are : \begin{itemize} \item The objective of the portfolio \item The conditions of the portfolio’s best performance \item The risk of the portfolio \item How long the success of the portfolio is expected \end{itemize} All the fields will be field with ‘test’ for testing purposes \section{Creation on the blockchain} \subsection{End result transactions} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/transaction-result.png} \caption{Caption} \label{fig:my_label} \end{figure} These informations on the console are the result of the \textbf{createAlgorandPortfolio} function Which calls the smart contract app to store the portfolio information on the blockchain. \subsection{Smart contract application} The smart contract used to store the portfolio’s information into the data account It is written in pyteal which will be converted into teal once debugged and deployed The pyteal smart contract is split into two programs : the approval program and the clear program \subsubsection{Approval program} The approval program contains the main instructions of the smart program such as manipulating global or local state \subsubsection{Clear state program} Executions of the ClearStateProgram are more stringent, in order to ensure that applications may be closed out, but that applications also are assured a chance to clean up their internal state. At the beginning of the execution of a ClearStateProgram, the pooled budget available must be MaxAppProgramCost or higher. If it is not, the containing transaction group fails without clearing the app's state. During the execution of the ClearStateProgram, no more than MaxAppProgramCost may be drawn. If further execution is attempted, the ClearStateProgram fails, and the app's state is cleared. \subsubsection{Smart contract deployment} After the deployment of the smart contract two teal files will be created each with their own program along with the \textbf{app id} that will be used in the application call. \begin{figure}[H] \centering \includegraphics[width=0.5\textwidth]{images/teal-files.png} \caption{Caption} \label{fig:my_label} \end{figure} \begin{figure}[H] \centering \includegraphics[width=0.5\textwidth]{images/app-id.png} \caption{Caption} \label{fig:my_label} \end{figure} Creating the smart contract application After preparing the smart contract programs we will use them to create the application Also we need an algorand account to be the creator of this application in this case we’ll use the multisignature account. After executing the code we get a transaction id We can use that id to track the transaction in the Algorand Explorer in order to get details about the transaction. \paragraph{Transaction overview} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/transaction-overview.png} \caption{Caption} \label{fig:my_label} \end{figure} Here, we can see: \begin{itemize} \item \textbf{Transaction ID}. \item \textbf{Timestamp}: full date and time of the transaction. \item \textbf{Block}: the number of the block which contains the information. \item \textbf{Transaction Type}: In this application, it is an \textbf{Application call} \end{itemize} \paragraph{Transaction details} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/transaction-details.png} \caption{Caption} \label{fig:my_label} \end{figure} \begin{itemize} \item \textbf{Sender}: the address of the sender of the transaction \item \textbf{Auth Address}: the address of the account that authorized the transaction \item \textbf{Signature}: the signature type \item \textbf{Multisig version}. \item \textbf{Multisig threshold}. \item \textbf{Subsignatures}: the adresses of the actual account that signed the transaction. \end{itemize} \paragraph{Approval and Clear state} \begin{figure}[H] \centering \includegraphics[width=1\textwidth]{images/approval-program.png} \includegraphics[width=1\textwidth]{images/clear-program.png} \caption{Caption} \label{fig:my_label} \end{figure} The Approval and Clear State programs responsible for this app creation Can be displayed in Base 64 or can be displayed in readable form \subsection{createAlgorandPortfolio function steps} \begin{figure}[H] \centering \includegraphics[width=.8\textwidth]{images/create-algorand-diagram.png} \caption{Caption} \label{fig:my_label} \end{figure} \begin{enumerate} \item Get the portfolio information from the database stored in json format \item Generate a Data Account Using the algorand SDK we can generate an algorand account that will serve as the data account \item Send funds into the Data Account For this purpose a simple JS function is needed to send some testnet algos to the data account \item Rekey authority process Like we previously explained the rekey process is crucial for this operation so we dont have to save the generated account’s private key we can use sign every transaction with the multisig account’s signature \item Prepare the Arguments for the smart contract application \item Get the parameters for the transaction \item Opt into to the asset \item Call the application NoOp \item Sign transactions with multisignature account \item Send transaction and wait for the confirmation \end{enumerate} \subsection{Getting the portfolio information from the Algorand blockchain} Using \textbf{algorand SDK} we can extract the contents of an account’s local state using using the \textbf{App-id} and the \textbf{account’s address}. \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/ovaire.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsection{Mint portfolio} Mint is a necessary phase for creating a portfolio It's a step done by the creator of the portfolio when he swaps and deposit tokens into the portfolio Then the portfolio becomes public and can be invested in by any user \subsubsection{Mint portfolio interface} \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/slim-portfolio-interface.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Choosing a token to deposit} \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/token-deposit.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Choosing the amount to deposit and USD conversion} After inputting the desired amount it will be converted to its monetary value in USD using a web API that gets its price in real time using Binance \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/usd-conversion.png} \caption{Caption} \label{fig:my_label} \end{figure} In case we re on the Mainnet ,if the user of the account doesn't have enough balance to deposit He can either Revert or Buy the desired amount in Sol \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/usd-conversion-solana.png} \caption{Caption} \label{fig:my_label} \end{figure} In case we are on the testnet we can always dispense free tokens from the testnet dispenser After Depositing The chosen amount will be split across your asset depending on the percentage. \subsubsection{One token on the portfolio} \begin{figure}[H] \centering \includegraphics[width=0.25\textwidth]{images/one-token.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Two tokens on the portfolio} \begin{figure}[H] \centering \includegraphics[width=0.5\textwidth]{images/two-token.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Proceeding} Once we click on the ‘join and Deposit’ button Two transactions happen \paragagraph{Asset Opt in} \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/asset-optin.png} \caption{Caption} \label{fig:my_label} \end{figure} \paragagraph{Asset transfer} \begin{figure}[H] \centering \includegraphics[width=0.7\textwidth]{images/asset-transfer.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsubsection{Portfolio Created} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-created.png} \caption{Caption} \label{fig:my_label} \end{figure} \subsection{Portfolio Result} \begin{figure}[H] \centering \includegraphics[width=\textwidth]{images/portfolio-result.png} \caption{Caption} \label{fig:my_label} \end{figure}