Energy Trading on a Peer-to-Peer Basis between Virtual Power Plants Using Decentralized Finance Instruments

: Over time, distribution systems have begun to include increased distributed energy resources (DERs) due to the advancement of auxiliary power electronics, information and communication technologies (ICT), and cost reductions. Electric vehicles (EVs) will undoubtedly join the energy community alongside DERs, and energy transfers from vehicles to grids and vice versa will become more extensive in the future. Virtual power plants (VPPs) will also play a key role in integrating these systems and participating in wholesale markets. Energy trading on a peer-to-peer (P2P) basis is a promising business model for transactive energy that aids in balancing local supply and demand. Moreover, a market scheme between VPPs can help DER owners make more proﬁt while reducing renewable energy waste. For this purpose, an inter-VPP P2P trading scheme is proposed. The scheme utilizes cutting-edge technologies of the Avalanche blockchain platform, developed from scratch with decentralized ﬁnance (DeFi), decentralized applications (DApps), and Web3 workﬂows in mind. Avalanche is more scalable and has faster transaction ﬁnality than its layer-1 predecessors. It provides interoperability abilities among other common blockchain networks, facilitating inter-VPP P2P trading between different blockchain-based VPPs. The merits of DeFi contribute signiﬁcantly to the workﬂow in this type of energy trading scenario, as the price mechanism can be determined using open market-like instruments. A detailed case study was used to examine the effectiveness of the proposed scheme and ﬂow, and important conclusions were drawn.


Introduction
Owing to the rising global demand for energy, growing political pressure, and public awareness regarding reducing carbon emissions, incorporating large-scale renewable energy sources (RESs) integration and contouring power system operation with information and communication technologies (ICT), modern electric power systems have been undergoing a revolution [1]. These concerns have led to the creation of the microgrid concept, which has seen significant developments and adjustments over the previous decade with the help of smart grid technology [2]. Despite the obvious benefits of microgrids, there are several technical obstacles, including stability and dependability issues, due to the inherent volatility and unpredictability of RESs [3]. Virtual aggregation methods, in which small-scale prosumers work together on a larger scale to acquire benefits that cannot be obtained on an individual basis, are now being implemented because of the legislative and economic constraints of the energy market. Virtual power plants (VPPs) come into play in that regard. They are theoretically utilized for DER consolidation such that they can serve as a completely dispatchable unit, processing data from a wide range of DER physical infrastructure, market operations, and distribution system operators (DSOs) [4,5]. Moreover, VPPs can trade energy on behalf of small-scale DERs who cannot engage in the electricity market; therefore, VPPs can be considered an intermediary between DERs and the wholesale market. Inside VPPs, all the current ICT facilities are typically used to superintend the structure. Traditional cloud or fog computing systems are used to store the corresponding data necessary for VPP operations [6,7].
Previously, electricity customers were connected to conventional central energy systems as only consumers. Nonetheless, this scenario has changed. In the new concept, customers are now called prosumers (combinations of producers and consumers) and can now generate electricity from DERs, the bulk of which are generally RESs [8]. Currently, excess energy is exported back to the grid based on net metering and Feed-in Tariff (FiT) billing schemes. A prosumer receives credit in kilowatt-hours for the amount of energy they export to the grid under net metering. The prosumer's electricity consumption, supplied by the main grid, is then deducted from the prosumer's credit. In the FiT scheme, the prosumer can export the surplus energy at a fixed price and receive a monetary credit rather than kilowatt-hours. However, these policies provide few benefits to prosumers and are being swiftly phased out in numerous countries worldwide. Prosumers expect greater flexibility in allocating and managing their resources, as well as the elimination of intermediaries. The rise of prosumers necessitates a more decentralized and open energy market than the traditional, centralized market. Peer-to-peer (P2P) energy trading has emerged as an innovative paradigm at this juncture. P2P trading eliminates the need for third parties, allowing prosumers to exchange their surplus energy production with their peers directly. Since electricity generation with RESs is sporadic and unpredictable, the prosumers have to store excess energy in their ESS or sell it to the main grid, their peers inside the VPPs/microgrids, or neighboring VPPs (inter-VPP trading). However, a P2P trading platform is required to establish a marketplace for prosumers and consumers, providing them with flexibility and control over their generation and consumption. Furthermore, the platform must enable communication and exchange of information with peers, make agreements and transactions, and store this information in trustworthy databases. As the size of decentralized systems grows, so does the complexity of P2P trading [9]. Distributed ledger technology distinguishes itself from centralized servers and databases by enabling safe, decentralized communication and cooperation among peers. Distributed ledgers are databases that record transactions and other related data in multiple locations without the involvement of a central authority. Blockchain is one of the leading types of distributed ledger technology that offers unique features to support P2P trading by providing a high level of transparency, security, anti-tampering, and lower operational cost due to the elimination of mediators. Thus, the new blockchain-enabled P2P trading approach differs from the conventional, centralized method of trading electricity [10].
In the design of P2P energy trading, game theory methodologies [11][12][13][14][15], auction-based procedures [16][17][18][19][20], optimization methods [20][21][22][23][24], and blockchain-based technologies are commonly employed. In a competitive situation, game theory is applied when a player's decisions and behavior affect other players' results and vice versa. The paper in [11] proposed a non-cooperative game theoretic approach to optimize the social benefits of P2P energy trading in virtual microgrids. The Stackelberg game was used to minimize consumer costs and maximize producer profit. P2P energy trading was realized using a multi-objective game-theoretic optimization in [12,13] for a clustered microgrid with three microgrids. The Nash equilibrium of game theory in these papers was used to determine the best number of participants and payoffs for peer-to-peer (P2P) and peer-togrid (P2G) energy trading. Auction-based mechanism in energy, a significant subfield of game theory, can be thought of as competitive bidding processes among prosumers and consumers. An auction based energy trading among peers is discussed in [16][17][18]. The double auction approach, which is one of the most widely used auction methods, has been applied in [18,19]. It facilitates the involvement of market participants who play a role in regulating the market price to optimize the trading strategy. A double auction-based energy trading system for smart energy communities was proposed in [20]. This paper dynamically handled the price of energy trading by integrating Lyapunov-based energy control. Optimization-based methods were also studied for the efficient realization of P2P energy trade among VPPs or microgrids [4,[20][21][22][23][24]. The optimization techniques in P2P energy trading have primarily aimed to maximize the financial benefits of participants. The study in [23] demonstrates the P2P energy trading among microgrid clusters and the shared energy storage system. Improvements in energy use efficiency and cost savings were achieved by optimizing the proposed structure. Authors in [24] present an equilibrium model of a P2P transactive energy market. In this model, each member seeks the maximum personal advantage while having the option of importing or providing energy from/to other peers. The market equilibrium condition is represented as a MILP and solved using a commercial solver to internally calculate the energy transaction price. Nevertheless, most of the methods mentioned above have a substantial computational burden, especially as the number of interconnected VPPs increases. These implementations do not consider data and financial exchange platforms, decentralization of the energy trading system, and the elimination of intermediaries. To address these limitations, this study proposes a P2P trading scheme for a distributed network of VPPs using Decentralized Finance (DeFi) instruments.
Several survey articles can be found in the literature examining all aspects of the blockchain idea in P2P energy trading [8,[25][26][27][28][29][30][31][32][33]. Double auction variants stand out among the many financial approaches that can be categorized in the virtual layer of P2P energy trading designs [32]. Multiple vendors and buyers participate in a double auction to buy and sell energy. In order to match potential sellers' asks and buyers' bids with a clearing price, the intermediate market institution will receive submissions from both potential vendors and buyers [31,33]. While using the blockchain to record energy trading transactions transparently and irreversibly, SCs take over the crucial role of these intermediaries [27]. Recent studies on P2P trading in the literature have mostly focused on local energy trading (intra-VPP/microgrid) utilizing blockchain and smart contracts (SCs). Our previous study also proposed an Ethereum-based intra-VPP P2P trading model with technical implementation details, analyzing the performance of public blockchain usage [34]. The state-of-the-art blockchain networks have the ability to run SCs, paving the way for the deployment of blockchain-based general applications. Ref. [35] is an elaborated report from a software engineering perspective regarding the SCs for transactive energy. A fully P2P energy trading market design for households has been provided by [36]. The study incorporates two trading approaches to analyze the impact of bilateral trading preferences. The first approach seeks to balance extra power and demand, while the second is intended to encourage energy trading among nearby peers. Ref. [37] presented two frameworks using Ethereum's SC functionality for a microgrid; a continuous double auction framework and a uniform price, double-sided auction framework. The paper's findings demonstrated that integrating the microgrid with P2P energy trading can strengthen the traditional centralized energy grid.
Some studies in the literature consider energy trading between VPPs as our study. The authors in [38] developed a hierarchical energy trading framework for both interand intra-VPPs. The MILP model was proposed to optimize the operation of the DERs in the system, considering the energy cost of each prosumer. A blockchain-based SC was used to record and automate transactions. Ref. [39] suggested a hybrid energy trading solution on a decentralized computer platform for microgrid clusters. This hybrid method combines linear programming with SCs on the Ethereum network. The other paper [40] proposed hierarchical energy trading between VPPs of small-scale prosumers using SCs. The optimization problem, which is to minimize the energy cost and meet energy service requirements, is addressed using a knapsack solution algorithm. However, the proposed solution was validated by a proof-of-concept prototype using Ethereum. Another authentic paper introduced a cryptocurrency-based energy trading platform (CETP) [41]. CETP uses the energy blockchain cryptocurrency (EBC) as a token for the electrical transaction between the stakeholders and performs the bidding indirectly through real-time bidding in EBC. This article aimed to improve the social welfare of the participants and inspired our work to be able to trade without the need to write SCs by ordinary system users. Nonetheless, CETP will probably not go from concept to practice since the designed trading system does not use an existing live blockchain environment. The proliferation of numerous VPPs and inter-VPP energy transfers seems likely, especially with the impending EV revolution. This possible inter-VPP trade requirement necessitates more efficient methods and flows by using more intensively the emerging tools and concepts of the blockchain ecosystem beyond the double auction approach in the financial layer. In order to perform a double auction in a blockchain-based solution, it is necessary for the agents or system operators to write a SC [42]. Failure to properly develop and audit SCs can also cause security and financial fraud problems, which have not been considered until now in transactive energy research, although many notorious incidents have happened in the blockchain world [43][44][45][46]. Therefore, in this study, a P2P trading scheme and framework between VPPs were developed by leveraging the benefits of the Avalanche ecosystem, such as speed, scalability, backward compatibility with the Ethereum network, and interoperability of Avalanche's C-chain together with multiple Ethereum Virtual Machine (EVM) based blockchain networks. Decentralized exchange (DEX) was used in the financial layer of our approach. To the best of our knowledge, our study proposes using DEXs for the first time in the financial layer of intercommunity P2P trading as a novel approach. Using DEXs to trade energy by tokenizing energy between VPPs can cut down on the use of SCs that are not written well and can be exploited. DEXs are run by SCs that have been developed and audited by professionals. They work in the public eye and handle much traffic. Experts in the field solve the problems they encounter in the live setting.
In contrast to the articles that were stated earlier, the purpose of our research is to investigate how DEX operations can be used to regulate the financial functioning and flow of P2P trading. Through tokenizing the energy of each VPP, supply and demand determine the parity balance between the tokens of VPPs. Therefore, trading in energy in the proposed scheme does not always require an auction or a bidding process. It also paves the way for trading operations like the open market without using order books.
The proposed scheme and flow are implemented based on the needs of the inter-VPP framework, using the Avalanche Platform (C-Chain, Fuji Test Network), Remix, and Pangolin, and the optimization model is formulated as mixed-integer linear programming (MILP), which is solved by the CPLEX solver included in GAMS. The contributions of this study can be summarized as follows: • As an extremely novel approach for a blockchain-based P2P trading scheme, trading has been realized with a workflow close to the open market mechanism in this study, which is completely distinguished from papers that feature auction or bidding. • It has been demonstrated that the trading on a model architecture is substantially realized; this scheme and workflow may be utilized in trading between VPPs. Further, energy prices can be calculated based on supply and demand. • A workflow and schematic are presented where VPPs using different blockchains for trading can also trade with each other. • While peer-to-peer trading is conducted on the model architecture of the power system comprising VPPs with the proposed flow, MILP is employed to get the cost of energy transfers closer to the optimum.
This study is structured into six sections. The Background Information section presents theoretical and conceptual details regarding the DeFi instruments. The System Description section describes the proposed methodology for the model architecture and problem formulation. The Proposed Scheme and Flow section details the inter-VPP trading platform's proposed scheme and flow. Finally, Discussion Section presents the analysis and results, while the last section provides the conclusions and future research avenues.

Background Information
Blockchain is the technology behind cryptocurrencies and digital P2P money transfers, which have become increasingly popular in recent decades. Fundamentally, it is a vast, widely distributed, and immutable digital ledger. As the name suggests, many blocks cryptographically interconnect to embody a chain of blocks that keeps the transactions intact. Multiple nodes scattered worldwide operate in a distributed fashion by consensus between them, removing central intermediaries and creating a massive registry and computing device. Blockchain is pushing for significant, transformative, and disruptive development in many sectors. The most promising future features of blockchain are decentralization, security, transparency, and fault tolerance. SCs are one of the benefits of blockchain, which makes a substantial difference in practical usage. They are predefined protocols between parties, programmatically coded, and live over the blockchain network autonomously. The usage of SCs in P2P energy trading is primarily for business logic flow and mandating market rules, that is, auctions and bidding mechanisms. Ethereum is an open-source blockchain platform that aims to make anyone capable of building or using decentralized applications (DApps) that run on blockchain networks primarily by using SCs [47]. DApps are expected to become a new phase in the world wide web's development process [48,49].
Since its inception by [47], Ethereum has swiftly grown to become the world's secondlargest cryptocurrency, with the potential to challenge Bitcoin's dominance in the future. The initial coin offering (ICO) tsunami, which swept the globe in 2017, increased Ethereum usage by a factor of ten. Although the ICO excitement has died down, the rise of decentralized finance (DeFi) and non-fungible tokens (NFTs) have sparked a second wave of Ethereum adoption, as the majority of DeFi and NFT platforms are built on the Ethereum blockchain. However, scalability concerns, such as high gas prices, network congestion, and slow throughput are becoming more common in Ethereum-based applications. Layer 2 alternatives-which use new consensus protocols such as Proof-of-Stake and Byzantine Fault Tolerant to replace the energy-intensive and environmentally harmful Proof-of-Work protocols-have been developed to overcome the Ethereum scalability trilemma: Blockchains, such as Ethereum, are prone to the infamous trilemma, which states that it is impossible to accomplish decentralization, scalability, and security simultaneously. As they use the proof of work mechanism, both Bitcoin and Ethereum are extremely secure and decentralized, yet they have low transactions per second. The current solutions for this fall into one of the Layer 1 or 2 categories [50]. Layer 2 protocols are based on the Ethereum Mainnet, whereas Layer 1 protocols are all new types of blockchain. Layer 1 protocols are blockchain architectures not constructed on top of another blockchain [51]. The Avalanche blockchain, for example, is a Layer 1 blockchain system that has seemingly addressed the Ethereum trilemma using its own design and unique consensus mechanism. In contrast, Layer 2 is a protocol constructed on top of an extant blockchain. For example, Lightning Network is a Layer 2 solution for Bitcoin, whereas Loopring is a Layer 2 solution for Ethereum. The Ethereum 2.0 upgrades are another significant step forward in the attempt to increase Ethereum's scalability. Ethereum 2.0 is a series of Ethereum blockchain modifications that are presently under construction to make the network more scalable, secure, and durable [52]. However, these development efforts have been on the agenda since 2014, as applying these changes to an existing operational network with backward compatibility is difficult. Therefore, many Layer-1 blockchains have recently emerged as significant alternatives. Nevertheless, there are other protocols that are neither Layer 1 nor Layer 2 solutions but separate blockchains that operate alongside another Layer 1 blockchain. They are primarily a fork of the Ethereum blockchain rather than a Layer 1 or 2 protocol. For example, the Binance Smart Chain is a fork of the Ethereum blockchain rather than a Layer 1 or 2 protocol.

Avalanche Platform
Avalanche is an open-source platform for deploying decentralized apps and businesswide blockchain installations in a unified and highly scalable environment. Avalanche was the first decentralized SCs platform for global finance with near-instant transaction finality. Because Solidity works out-of-the-box, Ethereum developers can easily build atop Avalanche. The Snow family consensus protocols distinguish Avalanche from other decentralized networks. Generally, it is assumed that blockchains must be sluggish and non-scalable. To deliver strong safety guarantees, expedient finality, and high throughput without compromising decentralization, the Avalanche protocol adopts a revolutionary method for consensus and uses repeated subsampled voting. When a validator decides whether a transaction should be allowed, it polls a small, random group of validators for their opinions. If the queried validator believes that the transaction is invalid, has already rejected it, or prefers a different competing transaction, it will respond that the transaction should be rejected. Otherwise, the validator approves the transaction if a sufficiently significant share α (alpha) of the sampled validators respond that it should be accepted. That is, it will respond in the future when enquired about the transaction that it believes should be accepted. Similarly, if a sufficiently significant number of validators respond that the transaction should be refused, the validator will reject it. The validator repeats this sampling process until α of the validators questions the response in the same way (accept or reject) for β (beta) rounds in a row. When there are no issues in a transaction, it is typically completed quickly. When disputes occur, honest validators rapidly cluster around them, creating a positive feedback loop until all accurate validators prefer that transaction. Consequently, non-conflicting transactions are accepted, and conflicting transactions are rejected. If any honest validator approves or rejects a transaction, all honest validators accept or reject that transaction (with a high likelihood based on system settings) [53].
Avalanche features three built-in blockchains: an exchange chain (X-chain), a platform chain (P-chain), and a contract chain (C-chain). All three blockchains were validated and secured using the primary network, a particular subnet. Further, all members of all custom subnets must be members of the primary network by stacking at least 2000 AVAX (explained below).

Principles
Avalanche is intended to establish permissioned (private) and permissionless (public) blockchains for application-specific usage as well as to develop and deploy highly scalable DApps and digital assets with different complexities and unique rules, commitments, and bindings (smart assets). Avalanche's overall goal was to provide a unified platform for creating, transferring, and digital trading assets.

The Native Token: AVAX
AVAX is a native token of Avalanche. It is a hard-capped (720,000,000 tokens, with 360,000,000 tokens available on mainnet launch), scarce asset that is used to pay fees, secure the platform through staking, and provide a basic unit of account between the multiple subnets created on Avalanche. One nAVAX is equal to 0.000000001 AVAX. Unlike other capped-supply tokens that maintain a constant pace of minting, AVAX is meant to respond to changing economic situations. AVAX's monetary policy aims to strike a balance between users' incentives to stake the token versus utilizing it to interact with many services on the platform.

Decentralized Finance (DeFi)
Decentralized Finance (DeFi) uses the same blockchain technology as cryptocurrencies. DeFi is a catch-all word for the cryptocurrency world dedicated to creating a new, internet-native financial system, with blockchains replacing existing mediators and trust mechanisms. DeFi gives end users the level of transparency, control, and accessibility they lack when dealing with centralized finance [54]. Intermediaries such as banks or stock exchanges are required in the traditional, centralized financial system to transmit or receive money. All parties must trust that intermediaries will behave fairly and honestly to have confidence in the transaction. These intermediaries were replaced by software in DeFi. People trade directly with one another instead of going via banks or stock exchanges, with blockchain-based "smart contracts" (SCs) handling the job of creating markets, settling deals, and guaranteeing that the entire process is fair and trustworthy. DeFi also comprises loan platforms, prediction markets, options, and derivative markets, all of which operate on decentralized blockchain networks. DeFi instruments have already processed tens of billions of dollars worth of cryptocurrency, and this number is increasing daily [55]. SCs are not available on every blockchain platform. Users can write open-source, self-executing code on SC-supporting blockchain platforms to fuel more innovative, trustless transactions. Once SCs are deployed to the blockchain, their code cannot be modified anymore, and they continue to operate autonomously. These characteristics enable the development of a vast array of decentralized applications (DApps) on blockchain networks, with decentralized finance (DeFi) constituting a prominent subset.

Decentralized Exchange (DEX)
A decentralized exchange is an excellent example of the growing suite of DeFi applications that allows two interested parties to conduct direct cryptocurrency trades, or more precisely, swaps. DEX was designed to address the shortcomings of centralized exchange (CEX). Trading cryptocurrencies has always necessitated the use of a centralized exchange (CEX). CEXs are administered by a firm or an individual with a profit motive. CEXs match cryptocurrency buyers and sellers in an order book, earn from the price spread between bids and asks, and commission per transaction. Therefore, they function similarly to traditional stock exchanges. However, DEXs are nothing but advanced DApps, which consist of professionally written and audited SCs in fact. In DEXs, the SCs that are deployed and living on the blockchain are doing most of the jobs, such as creating parity, managing parity liquidity pools, and swaps. They constructed P2P marketplaces directly on the blockchain, allowing traders to independently maintain and manage their assets. Users of such exchanges can conduct cryptocurrency transactions directly among themselves, without the need for a third party.

Pangolin
The Avalanche Platform's primary DEX is the Pangolin. It was introduced to the Avalanche network in February 2021 as a pre-tried idea for automated market makers (AMMs). In its first year, it enabled nearly $10 billion in trade activities. Pangolin can trade all tokens minted on the Avalanche and Ethereum platforms using the Avalanche Bridge (AB). Pangolin is a community-driven DEX, and its entire operation is executed by open-source and audited SCs [56]. Figure 1 illustrates the model architecture used in this study, which comprised three VPPs. These VPPs utilize either the Avalanche platform (AVAX-based VPP) or the Ethereum Platform (ETH-based VPP) for their intra-VPP trading operations. They trade their excess power among each other (inter-VPP) and the grid while taking their optimal costs into account. AB takes the stage alongside the Pangolin DEX when transacting between different blockchain-based VPPs, and only the Pangolin DEX is used when transacting between the same blockchain-based VPPs. AB is used to transfer ERC-20 tokens from Ethereum to Avalanche's C-chain and vice versa. Every VPP has its own specific token minted on the Avalanche C-chain. Try Energy Token (TRY) is the name of the token minted for this purpose. TRY1, TRY2, and TRY3 are the tokens of the VPP1, VPP2, and VPP3, respectively. These are minted as per the ERC-20 Fungible Token standard using the SC from OpenZeppelin [57]. VPPs price the power they sell with their specific token, that is, VPPi sells the power to VPPj with TRYi token, where i, j ∈ {1, 2, 3} and i = j. They used Pangolin DEX for swapping tokens to get other VPP's tokens. The exchange rate/parity between them occurs in the Pangolin according to the supply/demand of the tokens in the liquidity pools. In fact, VPPs basically tokenize their energy. Thus, VPPs can reach optimum operation with minimum energy cost by trading with each other with the tokens.

Swap Token
Swap Token

Problem Formulation
The objective function is to minimize the sum of the income and expenses associated with all bi-directional energy transfers to and from other VPPs and the grid during a given time horizon. When a VPP sells energy to other assets, it receives a profit as income. Cost is defined as an expense when it purchases energy from other assets. The objective function (C t ) is formulated as written in Equations (1) and (2). denote the power sold to another VPP j and that purchased from another VPP at time t, respectively. PR sold t , PR pur t , γ i,t , and α j,t indicate the power sell price to the grid, purchase price from the grid, i-th VPP's selling price to the j-th VPP, and purchasing price of j-th VPP from i-th VPP at time t, respectively.
For the safe operation of the system, cooperative power balance should be taken into consideration as follows: Equation (3) shows the total power sold by the ith VPP, P sold i,t , to other VPPs and the grid at time t. Equation (4) indicates the total power purchased by the ith VPP, P purc i,t , from other VPPs and the grid at time t. The total power exchange of each VPP, P T i,t , and grid, P T grid,t , at time t are given by Equations (5) and (6), respectively. The power balance equation of all system at time t is formulated by Equation (7).

Proposed Scheme and Flow
The scheme and flow are close to the open market, unlike preliminary P2P energy trading studies in the literature. The literature review clearly shows that the energy price negotiation procedure used for P2P trading so far involves auctions or bidding mechanisms. Figure 1 shows a general perspective that illustrates the capabilities of this scheme. An ETH based VPP as in our previous study, can trade with an AVAX based VPP via an ETH-AVAX bridge, for example, AB. When AVAX based VPPs are trading among themselves, they only need to use a DEX, for example, Pangolin, to swap their tokens. It is known that there will be many different blockchain-based VPPs and microgrids operating around. The interoperability and trading ability of these among themselves will be more significant than they are now. Figure 2 further details this flow. Regarding the energy transfer that occurs between VPP1 and VPP2, VPP1 goes to the Pangolin to swap TRY1 for TRY2 tokens with the exchange rate at that time. Subsequently, VPPs can choose to add liquidity to Pangolin's liquidity pool, for example, TRY1/TRY2 if it would be beneficial for their own. They buy the required energy with swapped tokens from an SC that acts as custodian. Consequently, energy prices can be determined in a supply/demand manner. Note that payments are made using the counterpart's tokens.  Figure 2. Inter-VPP Energy Trading Workflow. Figure 3 shows the daily power profile of each VPP. From this graph, one can observe that VPP1 has a power deficiency of 25 KW at the 1st hour, whereas at hour 9, it has an excess energy of 68 KW to sell to other VPPs and/or the grid. These excess/deficient states of power vary from hour to hour, and from VPP to VPP. The hourly electricity price given by the utility is presented in Figure 4. The time of use (ToU) electricity tariff of $0.21, $0.27, and $0.42 is considered in this study. However, the electricity tariff is flat for power injected/sold to the grid, $0.1. Figure 5 depicts each VPP's overall power exchange with other VPPs and the grid, including the power sold (if positive) and the power purchased (if negative). It is obvious that at hour 1, VPP1 purchased energy from the grid, while VPP2 and VPP3 had excess energy to sell. This is because the grid price is sufficiently low when we compare the VPP2's and VPP3's prices. Therefore, VPP2 and VPP3 must sell their excess energy to the grid. At hour 7, VPP1 had 37.13 kW excess energy, while VPP2 and VPP3 had 31.057 kW and 28.718 kW energy deficits, respectively. At that time, the other VPPs want to fill the energy gap from VPP1 because the grid price is higher than VPP1. While VPP3 met the entire 28.78 kW energy deficit from VPP1, VPP2 purchased 6.07 kW of its 31.057 KW energy requirement from VPP1 and completes the rest from the grid.    Figure 6 illustrates the effect of the number of tokens in the pool on the unit price of the token. As an example, the variation in VPP1 as a result of transactions between VPPs and the grid during a day is shown in the Figure 6. Initially, 3.5 AVAX and 1750 TRY1 liquids were added to the AVAX/TRY1 liquidity pool with equal values for the two tokens. The AVAX/TRY1 parity in this case is 500, and the initial unit price of TRY1 is $0.14. Moreover, the unit price of AVAX is assumed to be $70 throughout the study. As VPP1 purchased energy from the grid in the first transaction, 35.24 TRY1 tokens were added to the pool, bringing the total amount of TRY1 to 1785.24. In exchange, 0.0688855630513128 AVAX was removed from the pool to pay the grid, leaving 3.431114 AVAX in the pool. An increase in the amount of TRY1 in the pool caused the unit price to decrease to $0.136832844, while the AVAX/TRY1 parity increased to 520.3090811.

Discussion
Before the 10th transaction occurred, the pool had 1855.267 TRY1 and 3.302563 AVAX, the AVAX/TRY1 parity was 561.7658462, and the unit price of TRY1 was $0.124416114. VPP1 sold its excess energy to VPP3, as seen in Figure 5 at hour 7; thus, a transaction occurred between VPP1 and VPP3. This poll is a non-AVAX pool, which is why the liquidity was calculated by observing the price of the VPP3 token in comparison to AVAX. Hence, from this exchange between VPP1 and VPP3, VPP3 had to pay 28.718 TRY1 to VPP1, which is equal to 0.052080937AVAX. Consequently, 0.052080937AVAX was added to the pool and 28.718 TRY1 left the pool. At the end of this swap, there was a total of 1826.549257 TRY1 and 3.35464422 AVAX in the pool. The AVAX/TRY1 parity decreased from 561.7658462 to 544.4837477 and the unit price of TRY1 increased from $0.124416114 to $0.126947058.
Liquidity might be added to the pool at any time during the trading flow. Figure 6 depicts the salient effect of this addition on pool and parity. In the 17th transaction, we added 982.7653475 TRY1 and 2 AVAX liquidity to the pool. Therefore, the pool has 2718.171754 TRY1 and 5.531680093 AVAX with 491.3826737 AVAX/TRY1 and 0.142455165 TRY1/$ after liquidity addition. This explains the dramatic shift in the 17th transaction in the figure. Finally, 5.1413 AVAX and 2925.8786 TRY1 remained in the pool owing to the transactions conducted over the day. Additionally, the remaining tokens can be observed in the Avalanche Fuji test network, as shown in Figure 7. Further, the AVAX/TRY1 parity increased to 569.0857769, with a daily fluctuation of 13.81715% between the beginning and end of day. Similarly, the unit price of TRY1 fell to $0.12416 at the end of day, declining by 11.31036% owing to an increase in the amount of TRY1 in the pool.  Table 1 shows the transactions between the VPPs and grid. These transactions are swapping of VPP specific tokens through the Pangolin DEX to trade energy between VPPs. G, V1, V2, and V3 represent the grid, VPP1, VPP2, and VPP3, respectively. Every column represents transactions occurring between pairs stated in the column head. That is, during the 19th hour of the day, VPP1 swapped 57.36531253 TRY1 tokens for AVAX to buy energy from the grid. VPP1 again swapped the TRY1 tokens to 1.964588468 TRY2 tokens to buy energy from VPP2. Finally, VPP3 swapped TRY3 for 24.12165254 TRY2 tokens to buy energy from VPP2. Therefore, the positive and negative signs in the transactions specify the transaction direction.

Conclusions
In this study, an inter-VPP trading platform scheme and flow were developed to achieve efficient, transparent, and economic P2P energy trading between the same or different blockchain based VPP frameworks without the supervision of the intermediaries. A DEX (Pangolin) running on a public blockchain platform (Avalanche), unlike other studies and applications in the extant literature, is utilized for the implementation. The primary purpose of this study is to demonstrate the feasibility of P2P trading with professional Defi instruments in current use. In line with this purpose, the entire flow was tested by making the token swaps via Pangolin and transactions on a realistic test network named Fuji of the Avalanche Platform. These transactions were performed according to the case study's MILP-based power optimization model results. Obviously, the parity of the tokens against each other is shaped by the initial ratios of the pools on the DEX and the supplydemand balance that emerges after the swaps. Graphs showing these parity variations of tokens while swapping transactions are crucial and justifying outcomes for the proposed cheme. As the focus of this study was on the applicability and implementation of inter-VPP trading with DeFi blessings, trading advertisement requirements for sellers and buyers are still present in this scheme and flow, which can be easily overcome with off-chain solutions. Utilizing software controlled by an authority or a decentralized, intermediaryfree blockchain structure with SCs can be necessary for the purchaser and vendor to peer with each other. This issue, intra-VPP optimization, and more technical drawbacks and impacts of DEXs on energy trading can be investigated in future studies.

Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.

Data Availability Statement:
The data presented in this study are available on request from the corresponding author. The data are not publicly available due to the project is not completed.

Conflicts of Interest:
The authors declare no conflict of interest.

Abbreviations
The following abbreviations are used in this manuscript: