# ULDM Performance

{% hint style="info" %}
This study was conducted April 4, 2023
{% endhint %}

**Abstract**\
In this study, we put Unizen Trade's unique liquidity distribution mechanism ([ULDM](https://docs.unizen.io/introduction-to-unizen/unizen-overview/unizen-liquidity-distribution-mechanism-uldm)) to the test against leading decentralized exchange (DEX) aggregators [1inch ](https://1inch.com)and [Paraswap](https://www.paraswap.io/). By simulating 37 random trades across 7 different blockchains, we demonstrate the efficiency and cost-effectiveness of Unizen Trade as compared to its competitors.

**Introduction**\
Decentralized exchanges (DEXs) have gained immense popularity in recent years as an alternative to traditional centralized exchanges. With the rising interest in DEXs, the competition among DEX aggregators has also intensified. \
\
1inch, and Paraswap are among the leading DEX aggregators, each offering distinct features and benefits to their users. In this article, we compare the performance of Unizen Trade, powered by its unique liquidity distribution mechanism ("[ULDM](https://docs.unizen.io/introduction-to-unizen/unizen-overview/unizen-liquidity-distribution-mechanism-uldm)"), against [1inch ](https://1inch.com)and [Paraswap ](https://www.paraswap.io/)through a series of simulated trades.

{% hint style="info" %}
None of the trades nor networks was hand picked, nor has the data been manipulated in anyway to accommodate biases.&#x20;
{% endhint %}

**Methodology**\
We conducted a comparison by writing the below script that generated 37 random trades on 7 different blockchains, using an input amount of $10,000. The trades were executed across all platforms, and the results were recorded to evaluate the performance of Unizen Trade, 1inch, and Paraswap.

{% code lineNumbers="true" %}

```javascript
async function main() {
    const X = parseInt(prompt("Enter number of tokens in dataset to be considered "));

    const rawData = fs.readFileSync('tokenlist.json');
    const jsonData = JSON.parse(rawData);
    const tokenList = jsonData.tokens;

    const randomTokens = getRandomTokens(tokenList, X);

    for (let i = 0; i < randomTokens.length - 1; i++) {
        const tokenIn = randomTokens[i].address;
        const tokenOut = randomTokens[i + 1].address;
        const chainId = 1;

        const tokenInDetails = await getTokenDetails(tokenIn, chainId);
        const amountIn = new BigNumber(10000).dividedBy(tokenInDetails.price).multipliedBy(new BigNumber(10).pow(tokenInDetails.decimals)).toFixed(0);

        const result = await getQuotes(tokenIn, tokenOut, amountIn, chainId);
        console.log(`Swapping 10,000 USD worth of ${tokenList.find(token => token.address === tokenIn).symbol} tokens to ${tokenList.find(token => token.address === tokenOut).symbol} will get you:`);
        console.log(`ZCX: ${result.zcx}`);
        console.log(`Paraswap: ${result.paraswap}`);
        console.log(`1inch: ${result.oneInch}`);
    }
}

function getRandomTokens(tokenList, X) {
    const randomTokens = [];

    for (let i = 0; i < X; i++) {
        const randomIndex = Math.floor(Math.random() * tokenList.length);
        randomTokens.push(tokenList[randomIndex]);
    }

    return randomTokens;
}

async function getTokenDetails(tokenAddress, chainId) {
    const apiUrl = ``;
    const response = await axios.get(apiUrl);
    const data = response.data;

    return {
      decimals: data.decimals,
      price: data.price
    };
}

async function getQuotes(tokenIn, tokenOut, amountIn, chainId) {
  const paraswapUrl = `https://apiv5.paraswap.io/prices`;
  const oneInchUrl = `https://api.1inch.io/v5.0/${chainId}/quote`;
  let chainIdToRPC = new Map();

  chainIdToRPC.set(1, "");
  chainIdToRPC.set(137, "");
  chainIdToRPC.set(56, "");
  chainIdToRPC.set(43114, "");
  chainIdToRPC.set(42161, "");
  chainIdToRPC.set(10, "");
  chainIdToRPC.set(250, "");

  const tradeParams = {
    tokenIn: tokenIn,
    tokenOut: tokenOut,
    slippage: 0.03,
    chainId: chainId,
    inNative: false,
    outNative: false,
    deadline: 1679649641,
    isVIP: true,
    amount: amountIn,
  };
  const dexAggr = new DexAggregatorSDK(chainIdToRPC, undefined);
  // fetching zcx quotes
  let uzParams = dexAggr.getBestQuoteCall(
    tradeParams,
    false,
    undefined,
    undefined,
    false,
    true,
    false,
  );
  
  // fetching paraswap
  const paraswapParams = new URLSearchParams({
    srcToken: tokenIn,
    destToken: tokenOut,
    amount: amountIn,
    side: 'SELL',
    network: chainId,
    srcDecimals: 18,
    destDecimals: 18
  });
  // fetching 1inch
  const oneInchParams = new URLSearchParams({
    fromTokenAddress: tokenIn,
    toTokenAddress: tokenOut,
    amount: amountIn
  });
  const paraswapRequest = fetch(`${paraswapUrl}?${paraswapParams}`).then(response => response.json());
  const oneInchRequest = fetch(`${oneInchUrl}?${oneInchParams}`).then(response => response.json());

  const [uzResult, paraswapResult, oneInchResult] = await Promise.all([
    uzParams,
    paraswapRequest,
    oneInchRequest,
  ]);
  // splitting trade for zcx quotes
  let paramsSplit = await dexAggr.getBestQuoteCall(
    tradeParams,
    false,
    undefined,
    undefined,
    false,
    true,
    true,
    uzResult
  );
  let tot = new BigNumber(0)
  for (let i = 0; i < paramsSplit.length; i++) {
    tot = tot.plus(new BigNumber(paramsSplit[i].actualQuote));
  }
  console.log(uzResult[0].actualQuote, tot.toFixed(0))
  const results = {
    tokenIn: tokenIn,
    tokenOut: tokenOut,
    amountIn: amountIn,
    timestamp: Math.floor(Date.now() / 1000),
    chainId: chainId,
    zcx: BigNumber.max(uzResult[0].actualQuote, tot).toFixed(0),
    paraswap: paraswapResult.priceRoute == undefined ? undefined : paraswapResult.priceRoute.destAmount,
    oneInch: oneInchResult.toTokenAmount,
  };
  return results;
}

```

{% endcode %}

**Results**\
The results of the trades indicate a clear advantage for Unizen Trade, thanks to its in-house produced [ULDM](https://docs.unizen.io/introduction-to-unizen/unizen-overview/unizen-liquidity-distribution-mechanism-uldm). In many instances, Unizen Trade outperformed its competitors by a significant margin, with better exchange rates and improved efficiency. The table below summarizes the results of the trades across all platforms:

<table><thead><tr><th width="111">Sold</th><th width="98">Bought</th><th width="111">Network</th><th width="135">Unizen Out</th><th>Paraswap Out</th><th>1inch Out</th></tr></thead><tbody><tr><td>GTON</td><td>USDC</td><td>Ethereum</td><td>1593</td><td>877</td><td>873</td></tr><tr><td>GTON</td><td>OGN</td><td>Ethereum</td><td>7364</td><td>7141</td><td>7151</td></tr><tr><td>USDC</td><td>OGN</td><td>Ethereum</td><td>81201</td><td>81481</td><td>81212</td></tr><tr><td>ELON</td><td>USDC</td><td>Polygon</td><td>8922</td><td>8247</td><td>8112</td></tr><tr><td>ELON</td><td>TEL</td><td>Polygon</td><td>3571453</td><td>1</td><td>3282245</td></tr><tr><td>USDC</td><td>TEL</td><td>Polygon</td><td>3950712</td><td>1</td><td>4055932</td></tr><tr><td>STRX</td><td>BUSD</td><td>BNB Chain</td><td>9787.6920269854</td><td>9671.2718994656</td><td>9671.4917587943</td></tr><tr><td>STRX</td><td>EVER</td><td>BNB Chain</td><td>105391</td><td>7</td><td>87346</td></tr><tr><td>BUSD</td><td>EVER</td><td>BNB Chain</td><td>0</td><td>0</td><td>0</td></tr><tr><td>SPELL</td><td>USDC</td><td>Fantom</td><td>9266</td><td>9291</td><td>9419</td></tr><tr><td>SPELL</td><td>CREAM</td><td>Fantom</td><td>134</td><td>105</td><td>88</td></tr><tr><td>USDC</td><td>CREAM</td><td>Fantom</td><td>187</td><td>106</td><td>89</td></tr><tr><td>SPA</td><td>USDC</td><td>Arbitrum</td><td>9421</td><td>9512</td><td>3850</td></tr><tr><td>SPA</td><td>SPELL</td><td>Arbitrum</td><td>9044804</td><td>7485484</td><td>4897293</td></tr><tr><td>USDC</td><td>SPELL</td><td>Arbitrum</td><td>12587215</td><td>12540219</td><td>12415396</td></tr><tr><td>YAK</td><td>USDC</td><td>Avalanche</td><td>9629</td><td>9649</td><td>9651</td></tr><tr><td>YAK</td><td>MILK2</td><td>Avalanche</td><td>1075323</td><td>890454</td><td>890454</td></tr><tr><td>USDC</td><td>MILK2</td><td>Avalanche</td><td>1094318</td><td>915633</td><td>915633</td></tr><tr><td>BIT</td><td>USDC</td><td>Ethereum</td><td>9995</td><td>10006</td><td>10006</td></tr><tr><td>BIT</td><td>METIS</td><td>Ethereum</td><td>383</td><td>385</td><td>385</td></tr><tr><td>USDC</td><td>METIS</td><td>Ethereum</td><td>385</td><td>385</td><td>385</td></tr><tr><td>GFI</td><td>USDC</td><td>Polygon</td><td>5779</td><td>4651</td><td>9200</td></tr><tr><td>GFI</td><td>NEXO</td><td>Polygon</td><td>5087</td><td>2780</td><td>4981</td></tr><tr><td>USDC</td><td>NEXO</td><td>Polygon</td><td>5214</td><td>5236</td><td>5236</td></tr><tr><td>SHEESHA</td><td>BUSD</td><td>BNB Chain</td><td>9815.2053875240</td><td>9675.1578566227</td><td>9675.2488882910</td></tr><tr><td>SHEESHA</td><td>TWT</td><td>BNB Chain</td><td>8107</td><td>8171</td><td>8171</td></tr><tr><td>BUSD</td><td>TWT</td><td>BNB Chain</td><td>0</td><td>0</td><td>0</td></tr><tr><td>LINK</td><td>USDC</td><td>Fantom</td><td>9831</td><td>9852</td><td>9838</td></tr><tr><td>LINK</td><td>COVER</td><td>Fantom</td><td>218</td><td>218</td><td>209</td></tr><tr><td>USDC</td><td>COVER</td><td>Fantom</td><td>219</td><td>219</td><td>210</td></tr><tr><td>CELR</td><td>USDC</td><td>Arbitrum</td><td>1284</td><td>644</td><td>2</td></tr><tr><td>OOE</td><td>USDC</td><td>Avalanche</td><td>2074</td><td>1156</td><td>1156</td></tr><tr><td>OOE</td><td>PEFI</td><td>Avalanche</td><td>227208</td><td>127415</td><td>127302</td></tr><tr><td>USDC</td><td>PEFI</td><td>Avalanche</td><td>844622</td><td>862878</td><td>856744</td></tr><tr><td>CELR</td><td>USDC</td><td>Arbitrum</td><td>1285</td><td>645</td><td>2</td></tr><tr><td>CELR</td><td>TUSD</td><td>Arbitrum</td><td>643</td><td>1</td><td>2</td></tr><tr><td>USDC</td><td>TUSD</td><td>Arbitrum</td><td>9992</td><td>10002</td><td>10002</td></tr></tbody></table>

**Percentage Difference in Amount Returned**

For a clearer and more comprehensive representation of the data, we calculated the percentage differences in the amount returned for each trade. These percentages highlight the extent to which trades executed using Unizen Trade's engine outperformed or underperformed compared to those conducted on [1inch ](https://1inch.com)and [Paraswap](https://www.paraswap.io/).

The formula used to calculate the difference in percentage can be seen below.

$$
((Unizen Output - Competitor Output) / Competitor Output) \* 100
$$

{% hint style="info" %}
To avoid errors by zero division, one was used instead to represent the output whenever a zero output was returned. These occurrences are notable where the percentages are very excessive.
{% endhint %}

The instances where Unizen returns higher amounts compared to its competitors are color-coded in <mark style="color:green;">green</mark>. Cases with minimal differences in the amounts returned are highlighted in <mark style="color:orange;">orange</mark>. For situations where the competition returns significantly larger amounts, the color <mark style="color:red;">red</mark> is employed to visually represent these instances.

<table><thead><tr><th width="92.33333333333331">Trade</th><th>Unizen vs Paraswap</th><th>Unizen vs 1inch</th></tr></thead><tbody><tr><td>1</td><td><mark style="color:green;">81.64%</mark></td><td><mark style="color:green;">82.47%</mark></td></tr><tr><td>2</td><td><mark style="color:green;">3.12%</mark></td><td><mark style="color:green;">2.98%</mark></td></tr><tr><td>3</td><td><mark style="color:orange;">-0.34%</mark></td><td><mark style="color:orange;">-0.01%</mark></td></tr><tr><td>4</td><td><mark style="color:green;">8.18%</mark></td><td><mark style="color:green;">9.99%</mark></td></tr><tr><td>5</td><td><mark style="color:green;">357145200.00%</mark></td><td><mark style="color:green;">8.81%</mark></td></tr><tr><td>6</td><td><mark style="color:green;">395071100.00%</mark></td><td><mark style="color:orange;">-2.59%</mark></td></tr><tr><td>7</td><td><mark style="color:green;">1.20%</mark></td><td><mark style="color:green;">1.20%</mark></td></tr><tr><td>8</td><td><mark style="color:green;">1505485.71%</mark></td><td><mark style="color:green;">20.66%</mark></td></tr><tr><td>9</td><td>N/A</td><td>N/A</td></tr><tr><td>10</td><td><mark style="color:orange;">-0.27%</mark></td><td><mark style="color:orange;">-1.62%</mark></td></tr><tr><td>11</td><td><mark style="color:green;">27.62%</mark></td><td><mark style="color:green;">52.27%</mark></td></tr><tr><td>12</td><td><mark style="color:green;">76.42%</mark></td><td><mark style="color:green;">110.11%</mark></td></tr><tr><td>13</td><td><mark style="color:orange;">-0.96%</mark></td><td><mark style="color:green;">144.70%</mark></td></tr><tr><td>14</td><td><mark style="color:green;">20.83%</mark></td><td><mark style="color:green;">84.69%</mark></td></tr><tr><td>15</td><td><mark style="color:green;">0.37%</mark></td><td><mark style="color:green;">1.38%</mark></td></tr><tr><td>16</td><td><mark style="color:orange;">-0.21%</mark></td><td><mark style="color:orange;">-0.23%</mark></td></tr><tr><td>17</td><td><mark style="color:green;">20.76%</mark></td><td><mark style="color:green;">20.76%</mark></td></tr><tr><td>18</td><td><mark style="color:green;">19.51%</mark></td><td><mark style="color:green;">19.51%</mark></td></tr><tr><td>19</td><td><mark style="color:orange;">-0.11%</mark></td><td><mark style="color:orange;">-0.11%</mark></td></tr><tr><td>20</td><td><mark style="color:orange;">-0.52%</mark></td><td><mark style="color:orange;">-0.52%</mark></td></tr><tr><td>21</td><td>0.00%</td><td>0.00%</td></tr><tr><td>22</td><td><mark style="color:green;">24.25%</mark></td><td><mark style="color:red;">-37.18%</mark></td></tr><tr><td>23</td><td><mark style="color:green;">82.99%</mark></td><td><mark style="color:green;">2.13%</mark></td></tr><tr><td>24</td><td><mark style="color:orange;">-0.42%</mark></td><td><mark style="color:orange;">-0.42%</mark></td></tr><tr><td>25</td><td><mark style="color:green;">1.45%</mark></td><td><mark style="color:green;">1.45%</mark></td></tr><tr><td>26</td><td><mark style="color:orange;">-0.78%</mark></td><td><mark style="color:orange;">-0.78%</mark></td></tr><tr><td>27</td><td>N/A</td><td>N/A</td></tr><tr><td>28</td><td><mark style="color:orange;">-0.21%</mark></td><td><mark style="color:orange;">-0.07%</mark></td></tr><tr><td>29</td><td>0.00%</td><td><mark style="color:green;">4.31%</mark></td></tr><tr><td>30</td><td>0.00%</td><td><mark style="color:green;">4.29%</mark></td></tr><tr><td>31</td><td><mark style="color:green;">99.38%</mark></td><td><mark style="color:green;">64100.00%</mark></td></tr><tr><td>32</td><td><mark style="color:green;">79.41%</mark></td><td><mark style="color:green;">79.41%</mark></td></tr><tr><td>33</td><td><mark style="color:green;">78.32%</mark></td><td><mark style="color:green;">78.48%</mark></td></tr><tr><td>34</td><td><mark style="color:orange;">-2.12%</mark></td><td><mark style="color:orange;">-1.41%</mark></td></tr><tr><td>35</td><td><mark style="color:green;">99.22%</mark></td><td><mark style="color:green;">64150.00%</mark></td></tr><tr><td>36</td><td><mark style="color:green;">64200.00%</mark></td><td><mark style="color:green;">32050.00%</mark></td></tr><tr><td>37</td><td><mark style="color:orange;">-0.10%</mark></td><td><mark style="color:orange;">-0.10%</mark></td></tr></tbody></table>

**Conclusion**&#x20;

This analysis showcases the efficacy of Unizen Trade's distinctive liquidity distribution mechanism (ULDM) in delivering a superior trading experience when compared to prominent DEX aggregators like 1inch and Paraswap. By optimally distributing trades across a diverse range of decentralized liquidity pools, Unizen Trade can offer more competitive rates and enhanced efficiency, rendering it an attractive option for traders seeking optimal outcomes for their transactions.

Nevertheless, it is important to note that the trades evaluated in this study were randomly generated, and certain DEX aggregators may outperform others for specific trading pairs under different circumstances. Both 1inch and Paraswap are innovative solutions that offer additional benefits and serve thousands of DeFi traders worldwide. This study was conducted as a competitive analysis to provide deeper insights into ULDM's performance in real-world situations.
