Paycer
Search…
⌃K

# 2. Paycer Protocol

The Paycer protocol is the core engine and includes a solid smart contract architecture to consume different DeFi services. The smart-contract-based protocol will include Paycer's decentralized business logic, including staking, liquidity mining, yield farming, investment strategies, lending, and more. It will be able to interact with DeFi protocols from different blockchains and will also implement automated risk checks. In this chapter, the Paycer protocol is discussed in more detail, including its technical aspects and architecture.

## 2.1 On-Chain Yield Aggregator

The Paycer protocol will aggregate selected DeFi products and strategies from different blockchains; it can be described as a kind of backend system, mainly consisting of multiple smart contracts that are executed on public blockchains. The two main objectives are to spread the potential risk and maximize (within certain parameters) and stabilize the interest rate by allocating it across several DeFi products. The combined output will be strategies similar to ETFs, which can be purchased to invest in a combination of different platforms. However, the Paycer protocol will give greater weight to the security of the investments than to the maximization of interest. Achieving a lower interest rate is easier to cope with than the complete loss of a portion of the investment. The challenge is to find a good mix; therefore, a large part of the deposits will be invested in stable coin-based products and ecosystems, and lending as well as a few other products will be added in smaller portions.
The goal is to maximize the expected return for a given portfolio while respecting the risk tier of the respective Paycer DeFi category. This can be formalized as a constraint optimization problem where the weights
$w=(w_1,...,w_N)$
are chosen so that
\begin{align*} \max E(r) &=\max_wE_w(r) \\&=\max_w\sum_{i=1}^Nw_iE(r_i) \end{align*}
under the constraints
• .
$\sigma_p^2=\sum_{i=1}^N w_i^2 \sigma_p^2+\sum_{i=1}^{N-1} \sum_{j=i+1}^N w_i w_j \sigma_i \sigma_j \rho_{ij} \le \sigma_{tier}^{max}$
• $\sum_{i=1}^N w_i = 1$
• $w_i \ge 0 \quad \forall i \in \{ 1, 2, ..., N\}$

## 2.2 Yield Aggregation Strategies

Generating returns in the DeFi market is often referred to as yield farming, where the aim is to achieve the highest possible profits, that is to maximize them. Yield farming is about developing strategies to increase returns when using DeFi protocols. In the following section, the different investment strategies, products, and services used by the Paycer protocol are addressed, and the details of each strategy are explained in more detail.

### 2.2.1 Liquidity Mining

DeFi platforms need liquidity to be able to offer decentralized services; this can be, for example, a decentralized exchange (DEX) that uses an automated market maker (AMM) algorithm. Platforms that are new to the market are dependent on an initial supply of liquidity to be able to begin operating. To provide this, liquidity pools are deployed into which investors can deposit token pairs. A liquidity pool is basically a smart contract that contains funds. In return for providing liquidity to the pool, so-called liquidity providers (LPs) receive a reward. This reward can come from fees generated by the underlying DeFi platform or from a combination of generated fees and additional platform tokens. For new DeFi platforms, there is usually a high payout in rewards, which then decreases as the total amount of liquidity increases. However, new DeFi platforms also come with a higher risk than established platforms. Paycer will also invest in liquidity mining pools to earn interest for its customers. The strategy is to invest mainly in established pools with a high total volume to keep risks low. Regarding liquidity mining, the risks include price risk, impermanent loss, smart contract risks, and rug pull or scam. As for price risk, there is a risk of holding one or two risky assets when acting as a LP. For example, if a LP invests in a pool with UNI-ETH, then he is taking the price volatility of two risky assets: UNI and ETH, which both can change dramatically compared to their USD value. When investing in an ETH-DAI pool, there would only be one risky asset: ETH. Another risk is the so-called impermanent loss that occurs if the ratio of a token pair deviates significantly from the ratio at which the liquidity was provided to the pool. The loss is seen as impermanent because future price developments of these two underlaying tokens can approach the initial ratio again, resulting in reducing or even eliminating the impermanent loss. The impermanent loss ratio (ILR) describes the impermanent loss at time
$t_2$
compared to
$t_1$
, divided by the value of the token pair at
$t_2$
if it had been deposited. This can be obtained as
$ILR=1- \frac{2\sqrt{\frac{p_2}{p_1}}}{1+\frac{p_2}{p_1}}$
where
$p_1$
and
$p_2$
are the prices of token
$a$
in units of token
$b$
at times
$t_1$
and
$t_2$
[5]. Another potential risk could be present in the smart contracts. If the smart contracts of a liquidity pool are exploited by an attacker, a liquidity provider could lose all provided tokens and/or LP tokens. Hence, new projects with less experience and unaudited smart contracts could pose a significantly higher risk than established protocols. Finally, there is the risk that a team with bad intentions could carry out a scam/rug pull [6]. For example, a scammer could create a scam token called SCAM and open an ETH-SCAM pool. Then, an infinite number of SCAM tokens could be minted, and the liquidity for the then worthless tokens could be pulled from a pool. Everyone who bought the SCAM token for ETH from that pool would take a loss from the scam. Scammers could also perform an exit scam and run away with all the funds of a DeFi platform. Paycer is aware of these risks and will be extremely careful with its investments. In order to reduce the risk of impermanent loss, the Paycer protocol will provide investment strategies mainly in high volume stable coin pools by entering the best selected projects.

### 2.2.2 Staking

Token owners can delegate their tokens to receive rewards in the form of tokens. This mechanism is called staking. The staking rewards can, for example, amount to around 15% per year and be paid out daily. Staking was originally used primarily as proof of stake (PoS) for consensus building on public blockchains. Now, staking is also used to provide an incentive to hold a token for a long period of time and ensure price stability, but other reasons for this incentive are also possible. By continuously reinvesting the rewards, a compound interest rate can be achieved, which causes the total interest earned to rise significantly over time. The Paycer protocol will also invest part of its funds in staking to achieve a return on investment through the distributed tokens. The compound interest rate can be calculated as follows:
$A_t=P \left( 1+\frac{r}{n} \right)^{nt}$
where
$t$
is the period of time in years for which the amount is invested,
$A_t$
is the value of the investment time after time
$t$
,
$P$
is the initial investment,
$r$
is the annual interest rate and
$n$
is the number of times the interest is compounded per year. Staking tokens can be risky because the price of the reward token might drop and lose its value. Therefore, it can be useful to sell received rewards directly to realize the profit. This process can be automated so that rewards are sold based on the reward token performance. For long-term projects, it can also make sense to hold and re-stake the tokens to generate a much higher profit.

### 2.2.3 Lending

In order to enable lending, liquidity must also be provided, for which a share of the fees and/or liquidity mining is usually offered. The Paycer protocol will also allocate a portion of its investment to decentralized lending services. These can be lending protocols from other platforms but also Paycer’s own lending service. Decentralized lending services are not as risky as they may sound when it comes to giving loans to strangers. To obtain a loan, collateral must be deposited, which is usually a cryptocurrency. The size of the possible loan granted
$L$
is determined by the amount of collateral deposited
$V$
and the loan-to-value (LTV) factor
$X_{LTV}$
:
$L=X_{LTV}\cdot V$
The LVT value usually ranges up to 50%.
If the cryptocurrency deposited as collateral falls sharply, the collateral can be sold by the platform to avoid a credit loss. There is also the possibility of depositing more collateral during a fixed period of time so that liquidation of the position can be avoided. The Paycer protocol will react according to risk threshold fluctuations and rebalance the positions.

### 2.2.4 Arbitrage

Arbitrage is the mostly risk-free exploitation of value, interest rate, or price differences through trading at the same time in different markets for the purpose of profit taking. Mathematically, arbitrage is defined as a strategy that satisfies the conditions
$P(V_t \ge 0) = 1 \quad \text{and} \quad P(V_t \ne 0) > 0$
where
$V_0=0$
, and
$V_t$
denotes the portfolio value at time
$t>0$
.
For example, there can be an arbitrage opportunity if the price of a certain asset is lower on one exchange than on another. To realize profit, the asset is bought at the exchange with the lower price and within a very close time proximity sold on the exchange with the higher price. A bit more complex than the described strategy is triangular arbitrage in which cryptocurrency A is exchanged for cryptocurrency B, which is exchanged for cryptocurrency C and then exchanged back to cryptocurrency A. If an arbitrage opportunity is taken, the resulting amount of A will be higher than the initial value. However, considering costs, transaction fees, and market instability, the price difference must be high enough so that the sum of the trades is profitable after costs.
Mathematically, a triangular arbitrage opportunity exists when
$S_{A/C} \neq S_{A/B} \cdot S_{B/C}$
where
$S_{X/Y}$
is the implicit cross-exchange rate for currency
$Y$
in terms of currency
$X$
.
As an example of triangular arbitrage, consider the following trading pairs:
• USDC/SUSHI: 0.110
• USDC/UNI: 0.041
• UNI/SUSHI: 2.69
The following trades could be performed nearly simultaneously to exploit the arbitrage opportunity:
Step 1: Borrow 100,000 USDC. Step 2: For 100,000 USDC, buy UNI: 100,000 USDC ⋅ 0.041 USD/UNI = 4100 UNI. Step 3: For 4100 UNI, buy SUSHI: 4100 UNI ⋅ 2.69 = 11029 SUSHI. Step 4: For 422.30 SUSHI, buy USDC: 11029 ⋅ 1/0.110 = 100,263.64 USDC. Step 5: Pay back the 100,000 USDC.
Consequently, the profit of this set of trades would be 263.64 USDC minus transaction fees.
In an arbitrage strategy, the profits per token can be relatively low, but by trading a very high volume, a large ROI can be achieved in a short period of time.
The Paycer protocol will provide simple and more complex arbitrage strategies and implement such automated strategies on its own. The risk of arbitrage also depends on how high the volatility of the markets is where an arbitrage profit is to be achieved. When the fluctuations in an asset are small, the maximum loss would be small if the arbitrage profit could no longer be realized because, for example, another market participant was faster. Conversely, with low volatility and a rather high trading volume, only very low arbitrage profits can be achieved. The art is to seek a profitable middle way between risks and yields.

### 2.2.5 Other DeFi Investments

The entire DeFi space is currently undergoing rapid change, with many new projects appearing on the scene and new opportunities to earn yields emerging. Paycer will continuously follow current developments to always be up to date and at the pulse of new DeFi trends. This will make it possible to test new strategies and products in detail right from the start and to utilize them if applicable. New DeFi trends could include new forms of lending, stablecoins, GameFi, gaming, gamification, products, and services around NFTs.

## 2.4 Automated Risk Mitigation

In order to minimize risks at all times, it is crucial to implement automated checks. These checks need to detect specified patterns to recognize negative signals and trigger a shift in investments in response. In step one, these patterns will be specified based on human experience and empirical values. In step two, the Paycer team will use artificial intelligence (AI) and machine learning (ML) to find new patterns and rules where the interrelationships are too complex for humans. Historical blockchain data will be used to train the AI and ML models, and additional test data will also be generated since the amount of real data in relation to DeFi risks could be too small. In a third step, reinforcement learning will be used, whereby different AI agents work against each other to significantly increase the learning effect. The goal is to develop intelligent bots that recognize negative signals, estimate the current risk, and exit a DeFi product at a certain threshold. This will allow Paycer to offer a secure and stable product in a rapidly changing environment and reduce risk for the customer to a minimum.

## 2.5 Flash Loan Manipulation and Hack Prevention

Recently, flash loans have become an increasing problem in the DeFi area because prices can be manipulated in a high volume without the attacker needing to have a large amount of capital. With a flash loan, a person can borrow a large amount of cryptocurrency and return it directly at the end of the transaction. The transaction then consists of three parts: taking the loan, performing actions with the loan, and returning the loan. Flash loans can constitute a legitimate tool, for example to make an arbitrage profit. A problem arises when attackers find a way to manipulate prices using large sums of money, for example to achieve a high artificial arbitrage profit, which leads to a loss for the affected platform. There are several ways to protect a DApp from flash loans, including decentralized price oracles that use multiple sources to find the true average price. High frequency pricing updates (HFPU) can also be a solution, but these increase the number of requests sent to a price oracle by a great deal and hence increase costs. Another way to protect against such attacks is time-weighted average pricing (TWAP), in which the average price is calculated over multiple blocks. A DeFi protocol can also be protected with flash loan attack detection tools that help to identify and neutralize such attacks [7]. Paycer will implement different mechanisms to prevent the protocol and platform from flash loan attacks. This will include the usage of decentralized price oracles and the implementation of automated detections. Automated checks will lock funds or prevent further investments if a protocol in which Paycer is invested or the Paycer protocol itself is targeted by a flash loan or other hacking attacks. To prevent the Paycer protocol from security vulnerabilities, all smart contracts will be checked with peer code reviews to find any possible vulnerabilities or bugs. Beyond that, Paycer will use automated third-party tools that check smart contracts for vulnerabilities and other patterns during the deployment process. As an additional protection, Paycer’s smart contracts and other code will be checked with internal and external security audits. However, Paycer will not stop at the boundary of its own code; most DeFi protocols and platforms are open source, hence Paycer will also review the code of third-party protocols used by Paycer.

## 2.6 Avoiding High Transaction Fees

High traffic on blockchains like Ethereum can lead to high transaction fees that can reduce profit. To reduce the transaction fees paid, Paycer will collect funds in a pool and execute them in an aggregated way. The existing processes will be constantly reviewed and optimized to use as few on-chain transactions as possible. For centralized processes within the Paycer platform, off-chain transactions will be used to a large extent, and very few on-chain transactions will be executed.

## 2.7 Paycer Protocol Architecture

### 2.7.1 Design Principles

• Regulated and open participation (KYC may be required)
• Secure and transparent processes
• Cross chain operability
• Minimized trust assumptions
• Easy integration with third-party services
• Automated checks and adjustments
• Usage of price oracles
• Test-driven development and test automation
• The Paycer v1 core contracts are not upgradeable

### 2.7.2 Technology Stack

The Paycer protocol is mainly written in the Solidity language and uses the Hardhat framework. It is planned to integrate price oracles provided by Chainlink to prevent price manipulation with flash loans and other attacks. Paycer will also integrate Chainlink Keepers in the Paycer protocol. Chainlink Keepers could be used to scan and check the blockchain data 24 hours a day, 7 days a week and execute preprogrammed actions when certain states occur. This process could be used to shift funds to rebalance a portfolio regarding risks or yields.

### 2.7.3 General Protocol Functionality

The Paycer protocol will offer different investment strategies with which a user can invest with ETH, stablecoins, or other tokens. These strategies will be implemented based on smart contracts; there will be one smart contract acting as a pool for each strategy. The strategy pool will distribute synthetic pool tokens to investors in return for investments. The pool tokens can then be utilized to keep track of the ownership of investments in the pool and to distribute interest to the investors. The investment strategy associated with the pool is also a smart contract that contains the business logic of the strategy and invests in predefined products with the investments provided in the pool as shown in Figure 3. The investment strategy will perform multiple swaps to invest in different blockchain ecosystems and DeFi protocols. Investments will be monitored around the clock by automated watcher services. In case predefined parameters arise, the risk mitigation service will be triggered to limit the losses of the corresponding strategy. For this purpose, further investments or the withdrawal of funds can be blocked automatically. This could be the case, for example, if an attacker were to try to steal liquidity from the smart contract. The risk mitigation service might also remove funds from a DeFi protocol and shift it to stablecoins if there is a problem with the corresponding platform.

### 2.7.4 Cross-Chain and Interchain Operability

Most crypto ecosystems emerge and evolve around one blockchain (technology). The Ethereum blockchain is a good example of this as many tokens, services, and platforms have been developed on top of it. Communication and exchange of values between different blockchains are challenging. Most solutions that allow transactions, tokens, or values to be exchanged between two blockchains rely on a third party. This interrupts the trustless space of blockchains because a third party must be trusted. One good example is wrapped Bitcoin (WBTC), in which a user can exchange Bitcoin for an ERC-20 token that is fully backed with BTC at a 1:1 ratio. The WBTC can then be used on the Ethereum blockchain. There are many other wrapped cryptos and a whole ecosystem around them, but the point is that one needs to trust the organization distributing the wrapped token. If Paycer wants to interact with different DeFi protocols from separate blockchains, it faces the same challenges. In the first step, Paycer will operate with its own liquidity pools and internal swaps as well as through automated swaps on decentralized exchanges. Therefore, Paycer will be the third party to rely on, and other third parties might also be involved. Paycer will also evaluate, test, and develop various more advanced technical solutions. The main disadvantages of some current solutions are the following. Single-relay chains are involved to transfer transactions between different chains, and this could be a future bottleneck limiting the transaction rate. Some existing solutions require all connected chains to have the same consensus algorithm, or, as already mentioned, users need to rely on third parties [8]. An appropriate solution could be provided by hash time-locked contracts (HTLCs), smart contracts that are locked by a secret s that expires after a defined time t. The contract stores two values, hash h and timeout t. The hash h is the result of processing the secret s with a known hash function H. If the secret is provided as an input to the contract, the contract then calculates the hash internally. If the resulting hash matches hash h, the asset is transferred to the contract. Because of the collision resistant characteristic of the hash function, only the one correct secret can trigger the contract. That is why the contract is referred to as hash locked. If the correct secret is not provided before time t, the asset will be refunded to the owner. That is why the contract is also considered time locked. The HTLC can be utilized to allow transactions between two parties. For example, Alice creates a secret and calculates its hash. She then creates a contract including that hash to transfer her asset to Bob. Even though the contract is to send her assets to Bob, Alice's assets are still protected with her secret. Bob then receives Alice’s contract with the hash. He creates a contract to send his assets to Alice using the same hash as in Alice’s contract. Bob’s contract can only be triggered with the matching secret from Alice. When Alice now releases her secret, both contracts can be triggered by Bob and Alice before the timeout. If the contracts are not triggered within time t, the funds will be returned to their initial owners [9]. HTLCs are also a key technology for the implementation of payment channels in the Bitcoin Lightning Network as they allow a global state across a network of multiple nodes [10]. HTLCs are also crucial for the implementation of atomic swaps, a technology that can provide exchange of different cryptocurrencies without a central market or intermediaries [11]. This process can be implemented as smart contracts and embedded in the Paycer protocol. Currently, there are several scientific approaches and some research addressing cross-chain transactions. Further research into potential solutions is essential for Paycer until the most suitable solution is implemented.

### 2.7.5 Architecture Diagram

Figure 3 Paycer protocol architecture and Paycer platform entry point