StargateFeeLibraryV02.test.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const { expect } = require("chai")
  2. const { ethers, deployments } = require("hardhat")
  3. describe("StargateFeeLibraryV02:", function () {
  4. let feeLib
  5. let idealBalance
  6. let beforeBalance
  7. beforeEach(async function () {
  8. await deployments.fixture(["test"])
  9. feeLib = await ethers.getContract("StargateFeeLibraryV02")
  10. idealBalance = ethers.utils.parseEther("100")
  11. beforeBalance = ethers.utils.parseEther("100")
  12. })
  13. it("getEquilibriumFee()", async function () {
  14. const expectedEqFee = [
  15. "0.000000000000000",
  16. "0.000030000000000",
  17. "0.000060000000000",
  18. "0.000090000000000",
  19. "0.000120000000000",
  20. "0.000150000000000",
  21. "0.000180000000000",
  22. "0.000210000000000",
  23. "0.000240000000000",
  24. "0.000270000000000",
  25. "0.000300000000000",
  26. "0.000330000000000",
  27. "0.000360000000000",
  28. "0.000390000000000",
  29. "0.000420000000000",
  30. "0.000450000000000",
  31. "0.000480000000000",
  32. "0.000510000000000",
  33. "0.000540000000000",
  34. "0.000570000000000",
  35. "0.000600000000000",
  36. "0.000630000000000",
  37. "0.000660000000000",
  38. "0.000690000000000",
  39. "0.000720000000000",
  40. "0.000750000000000",
  41. "0.000780000000000",
  42. "0.000810000000000",
  43. "0.000840000000000",
  44. "0.000870000000000",
  45. "0.000900000000000",
  46. "0.000930000000000",
  47. "0.000960000000000",
  48. "0.000990000000000",
  49. "0.001020000000000",
  50. "0.001050000000000",
  51. "0.001080000000000",
  52. "0.001110000000000",
  53. "0.001140000000000",
  54. "0.001170000000000",
  55. "0.001200000000000",
  56. "0.000036363636364",
  57. "0.000145454545455",
  58. "0.000327272727273",
  59. "0.000581818181818",
  60. "0.000909090909091",
  61. "0.001309090909091",
  62. "0.001781818181818",
  63. "0.002327272727273",
  64. "0.002945454545455",
  65. "0.003636363636364",
  66. "0.004400000000000",
  67. "0.005236363636364",
  68. "0.006145454545455",
  69. "0.007127272727273",
  70. "0.008181818181818",
  71. "0.009309090909091",
  72. "0.010509090909091",
  73. "0.011781818181818",
  74. "0.013127272727273",
  75. "0.014545454545455",
  76. "0.016036363636364",
  77. "0.017600000000000",
  78. "0.019236363636364",
  79. "0.020945454545455",
  80. "0.022727272727273",
  81. "0.024581818181818",
  82. "0.026509090909091",
  83. "0.028509090909091",
  84. "0.030581818181818",
  85. "0.032727272727273",
  86. "0.034945454545455",
  87. "0.037236363636364",
  88. "0.039600000000000",
  89. "0.042036363636364",
  90. "0.044545454545455",
  91. "0.047127272727273",
  92. "0.049781818181818",
  93. "0.052509090909091",
  94. "0.055309090909091",
  95. "0.058181818181818",
  96. "0.061127272727273",
  97. "0.064145454545455",
  98. "0.067236363636364",
  99. "0.070400000000000",
  100. "0.073636363636364",
  101. "0.076945454545455",
  102. "0.080327272727273",
  103. "0.083781818181818",
  104. "0.087309090909091",
  105. "0.090909090909091",
  106. "0.094581818181818",
  107. "0.098327272727273",
  108. "0.102145454545455",
  109. "0.106036363636364",
  110. "0.110000000000000",
  111. "0.213600000000000",
  112. "0.516400000000000",
  113. "1.018400000000000",
  114. "1.719600000000000",
  115. "2.620000000000000",
  116. ]
  117. for (let i = 0; i < 100; i++) {
  118. const swapAmount = ethers.utils.parseEther(i.toString())
  119. const expectedFee = ethers.utils.parseEther(expectedEqFee[i]).div(10000).mul(10000)
  120. const protocolSubsidy = i > 40 ? ethers.constants.Zero : expectedFee
  121. const eqFee = await feeLib.getEquilibriumFee(idealBalance, beforeBalance, swapAmount)
  122. expect(eqFee[0].div(10000).mul(10000)).to.equal(expectedFee)
  123. expect(eqFee[1]).to.equal(protocolSubsidy)
  124. }
  125. })
  126. })