Pool.test.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. const { expect } = require("chai")
  2. const { ethers } = require("hardhat")
  3. const { ZERO_ADDRESS } = require("./util/constants")
  4. const { getAddr, deployNew } = require("./util/helpers")
  5. describe("Pool", function () {
  6. let owner, alice, badUser1, fakeContract, feeLibrary, lzEndpoint, factory, tokenOne, tokenTwo, pool
  7. let chainId, stargateTokenSpender, poolId, decimals, maxInt256Str, maxInt256, initSupplyMainEndpoint
  8. let mainEndpointId, name, symbol, dstPoolId, dstChainId, defaultChainPathWeight, nonDefaultChainPathWeight
  9. let defaultAmountLD, defaultMinAmountLD
  10. before(async function () {
  11. ;({ owner, alice, badUser1, fakeContract } = await getAddr(ethers))
  12. poolId = 1
  13. chainId = 11
  14. dstPoolId = 2
  15. dstChainId = 22
  16. decimals = 18
  17. mainEndpointId = 1
  18. defaultChainPathWeight = 1
  19. nonDefaultChainPathWeight = 4
  20. defaultAmountLD = 1
  21. defaultMinAmountLD = 1
  22. maxInt256Str = "115792089237316195423570985008687907853269984665640564039457584007913129639935"
  23. maxInt256 = ethers.BigNumber.from(maxInt256Str)
  24. initSupplyMainEndpoint = ethers.utils.parseEther("1000000000")
  25. name = "Pool1"
  26. symbol = "S*P1"
  27. })
  28. beforeEach(async function () {
  29. // contracts
  30. lzEndpoint = await deployNew("LZEndpointMock", [chainId])
  31. tokenOne = await deployNew("MockToken", ["One", "ONE", 18])
  32. tokenTwo = await deployNew("MockToken", ["Two", "TWO", 18])
  33. stargateTokenSpender = await deployNew("StargateToken", ["SGTest", "SGTEST", lzEndpoint.address, mainEndpointId, initSupplyMainEndpoint])
  34. factory = await deployNew("Factory", [fakeContract.address])
  35. feeLibrary = await deployNew("StargateFeeLibraryV02", [factory.address])
  36. pool = await deployNew("Pool", [
  37. poolId,
  38. owner.address,
  39. tokenOne.address,
  40. decimals,
  41. await tokenOne.decimals(),
  42. feeLibrary.address,
  43. name,
  44. symbol,
  45. ])
  46. // setup
  47. await factory.setDefaultFeeLibrary(feeLibrary.address)
  48. })
  49. it("constructor() - reverts for 0x0 params", async function () {
  50. const Pool = await ethers.getContractFactory("Pool")
  51. await expect(
  52. deployNew("Pool", [
  53. poolId,
  54. fakeContract.address,
  55. ZERO_ADDRESS,
  56. decimals,
  57. await tokenOne.decimals(),
  58. feeLibrary.address,
  59. name,
  60. symbol,
  61. ])
  62. ).to.be.revertedWith("Stargate: _token cannot be 0x0")
  63. await expect(
  64. Pool.deploy(poolId, ZERO_ADDRESS, tokenOne.address, decimals, await tokenOne.decimals(), feeLibrary.address, name, symbol)
  65. ).to.be.revertedWith("Stargate: _router cannot be 0x0")
  66. })
  67. it("constructor() - globals are set properly", async function () {
  68. expect(await pool.poolId()).to.equal(poolId)
  69. expect(await pool.token()).to.equal(tokenOne.address)
  70. expect(await pool.token()).to.not.equal(tokenTwo.address)
  71. expect(await pool.decimals()).to.equal(decimals)
  72. expect(await pool.localDecimals()).to.equal(await tokenOne.decimals())
  73. expect(await pool.name()).to.equal(name)
  74. expect(await pool.symbol()).to.equal(symbol)
  75. })
  76. it("createChainPath() - creates a proper pool connection", async function () {
  77. // verify there are no chains
  78. await expect(pool.chainPaths(0)).to.be.reverted
  79. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  80. expect((await pool.chainPaths(0)).dstChainId).to.equal(dstChainId)
  81. expect((await pool.chainPaths(0)).dstPoolId).to.equal(dstPoolId)
  82. // verify there is only 1 chain path existing
  83. await expect(pool.chainPaths(1)).to.be.reverted
  84. })
  85. it("mint() - reverts when called by non Router ", async function () {
  86. await expect(pool.connect(badUser1).mint(alice.address, 1)).to.be.revertedWith("Stargate: only the router can call this method")
  87. })
  88. it("mint() - reverts if there are no chain paths", async function () {
  89. await expect(pool.chainPaths(0)).to.be.reverted // verify there are no chains
  90. await expect(pool.mint(alice.address, 1)).to.be.reverted
  91. })
  92. it("mint() - reverts with no weights for chainpaths", async function () {
  93. await pool.createChainPath(dstChainId, dstPoolId, 0) // 0 weight
  94. await expect(pool.mint(alice.address, 1)).to.be.reverted
  95. })
  96. it("mint() - mints to user", async function () {
  97. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  98. await pool.mint(alice.address, 100)
  99. expect(await pool.balanceOf(alice.address)).to.equal(100)
  100. })
  101. it("transferFrom()", async function () {
  102. const amount = ethers.utils.parseEther("100")
  103. const amount2 = ethers.utils.parseEther("50")
  104. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  105. await pool.mint(alice.address, amount)
  106. expect(await pool.balanceOf(alice.address)).to.equal(amount)
  107. await expect(pool.connect(alice).transfer(alice.address, amount2)).to.emit(pool, "Transfer")
  108. await pool.connect(alice).approve(alice.address, amount2)
  109. await expect(pool.connect(alice).transferFrom(alice.address, alice.address, amount2)).to.emit(pool, "Transfer")
  110. })
  111. it("transferFrom() - reverts if the transfer is not approved", async function () {
  112. const amount = ethers.utils.parseEther("100")
  113. const amount2 = ethers.utils.parseEther("50")
  114. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  115. await pool.mint(alice.address, amount)
  116. expect(await pool.balanceOf(alice.address)).to.equal(amount)
  117. await expect(pool.connect(alice).transfer(alice.address, amount2)).to.emit(pool, "Transfer")
  118. await pool.connect(alice).approve(alice.address, maxInt256)
  119. await expect(pool.connect(alice).transferFrom(alice.address, alice.address, amount2.add(1))).to.emit(pool, "Transfer")
  120. })
  121. it("createChainPath() - weights are set", async function () {
  122. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  123. expect((await pool.chainPaths(0)).weight).to.equal(defaultChainPathWeight)
  124. await pool.setWeightForChainPath(dstChainId, dstPoolId, nonDefaultChainPathWeight)
  125. expect((await pool.chainPaths(0)).weight).to.equal(nonDefaultChainPathWeight)
  126. })
  127. it("getChainPathsLength()", async function () {
  128. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  129. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  130. expect(await pool.getChainPathsLength()).to.equal(2)
  131. })
  132. it("setWeightForChainPath() - properly allocate to two pools based on weights", async function () {
  133. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  134. await pool.createChainPath(dstChainId, dstPoolId, nonDefaultChainPathWeight)
  135. await pool.mint(alice.address, 100)
  136. expect(await pool.balanceOf(alice.address)).to.equal(100)
  137. expect((await pool.chainPaths(0)).credits).to.equal(20)
  138. expect((await pool.chainPaths(1)).credits).to.equal(80)
  139. // change the weight back to 50/ 50
  140. await pool.setWeightForChainPath(chainId, poolId, nonDefaultChainPathWeight)
  141. await pool.mint(alice.address, 60)
  142. expect((await pool.chainPaths(0)).credits).to.equal(80)
  143. expect((await pool.chainPaths(1)).credits).to.equal(80)
  144. })
  145. it("creditChainPath() - adds to balance for remote chain", async function () {
  146. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  147. await pool.creditChainPath(dstChainId, dstPoolId, { credits: 100, idealBalance: 100 })
  148. expect((await pool.chainPaths(0)).balance).to.equal(100)
  149. await pool.creditChainPath(dstChainId, dstPoolId, { credits: 100, idealBalance: 100 })
  150. expect((await pool.chainPaths(0)).balance).to.equal(200)
  151. })
  152. it("amountLPtoLD() - reverts when totalSupply is 0", async function () {
  153. const amountLP = 100
  154. await expect(pool.amountLPtoLD(amountLP)).to.revertedWith("Stargate: cant convert LPtoSD when totalSupply == 0")
  155. })
  156. it("getChainPath() - reverts when local chain path does not exist", async function () {
  157. await pool.createChainPath(dstChainId, dstPoolId, defaultChainPathWeight)
  158. await expect(pool.getChainPath(dstChainId, dstPoolId + 1)).to.revertedWith("Stargate: local chainPath does not exist")
  159. })
  160. it("redeemLocal() ", async function () {
  161. const amountLP = 100
  162. await pool.createChainPath(chainId, poolId, defaultChainPathWeight) // setup chain path
  163. await pool.activateChainPath(chainId, poolId)
  164. await pool.mint(alice.address, amountLP) // give them some LP tokens
  165. await expect(pool.redeemLocal(alice.address, amountLP, chainId, poolId, alice.address)).to.emit(pool, "RedeemLocal")
  166. })
  167. it("redeemLocal() - reverts if path is not activated", async function () {
  168. const amountLP = 100
  169. await pool.createChainPath(chainId, poolId, defaultChainPathWeight) // setup chain path
  170. await pool.mint(alice.address, amountLP) // give them some LP tokens
  171. await expect(pool.redeemLocal(alice.address, amountLP, chainId, poolId, alice.address)).to.revertedWith(
  172. "Stargate: counter chainPath is not ready"
  173. )
  174. })
  175. it("creditChainPath() - emits event", async function () {
  176. const amountSD = 99
  177. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  178. await expect(
  179. pool.creditChainPath(chainId, poolId, {
  180. credits: amountSD,
  181. idealBalance: amountSD,
  182. })
  183. )
  184. .to.emit(pool, "CreditChainPath")
  185. .withArgs(chainId, poolId, amountSD, amountSD)
  186. })
  187. it("swapRemote() - emits event", async function () {
  188. const amountToMintSD = 99
  189. const srcReward = 5
  190. const protocolFee = 6
  191. const dstFee = 7
  192. const lpFee = 3
  193. const lkbRemove = 0
  194. await tokenOne.mint(pool.address, 10000000)
  195. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  196. const swapObj = {
  197. amount: amountToMintSD,
  198. eqFee: dstFee,
  199. eqReward: srcReward,
  200. lpFee,
  201. protocolFee: protocolFee,
  202. lkbRemove,
  203. }
  204. await expect(pool.swapRemote(chainId, poolId, alice.address, swapObj))
  205. .to.emit(pool, "SwapRemote")
  206. .withArgs(alice.address, amountToMintSD + srcReward, protocolFee, dstFee)
  207. await expect(pool.connect(owner).withdrawProtocolFeeBalance(alice.address)).to.emit(pool, "WithdrawProtocolFeeBalance")
  208. })
  209. it("withdrawMintFeeBalance() - emits event", async function () {
  210. const amountLD = 12341234
  211. const amountToMintSD = 10000000
  212. const mintFeeFP = 789
  213. // give the pool some tokens so the inner _safeTransfer works
  214. await tokenOne.mint(pool.address, amountToMintSD)
  215. await pool.setFee(mintFeeFP)
  216. await pool.createChainPath(chainId, poolId, nonDefaultChainPathWeight)
  217. await pool.mint(alice.address, amountLD)
  218. await expect(pool.withdrawMintFeeBalance(alice.address)).to.emit(pool, "WithdrawMintFeeBalance")
  219. })
  220. it("withdrawMintFeeBalance() - reverts when to address is 0x0", async function () {
  221. const amountLD = 12341234
  222. const amountToMintSD = 10000000
  223. const mintFeeFP = 789
  224. // give the pool some tokens so the inner _safeTransfer works
  225. await tokenOne.mint(pool.address, amountToMintSD)
  226. await pool.setFee(mintFeeFP)
  227. await pool.createChainPath(chainId, poolId, nonDefaultChainPathWeight)
  228. await pool.mint(alice.address, amountLD)
  229. await expect(pool.withdrawMintFeeBalance(ZERO_ADDRESS)).to.revertedWith("Stargate: TRANSFER_FAILED")
  230. })
  231. it("redeemLocalCallback() - emits event when _amountToMintSD is > 0", async function () {
  232. const amountLD = 12341234
  233. const amountToMintSD = 10000000
  234. const mintFeeFP = 789
  235. // give the pool some of the token so the inner _safeTransfer works
  236. await tokenOne.mint(pool.address, amountToMintSD)
  237. await pool.setFee(mintFeeFP)
  238. await pool.createChainPath(chainId, poolId, nonDefaultChainPathWeight)
  239. await pool.mint(alice.address, amountLD)
  240. await expect(pool.redeemLocalCallback(chainId, poolId, alice.address, 0, 0)).to.emit(pool, "RedeemLocalCallback")
  241. })
  242. it("redeemLocalCallback() - setup to call _delta() where total > _amountSD", async function () {
  243. const chainId = 6543
  244. const poolId = 1
  245. const chainId1 = 6544
  246. const chainId2 = 6545
  247. const chainId3 = 6546
  248. const weight = 1234
  249. const amountLD = 12341234
  250. const amountToMintSD = 10000000
  251. const mintFeeFP = 789
  252. // give the pool some of the token so the inner _safeTransfer works
  253. await tokenOne.mint(pool.address, amountToMintSD)
  254. await pool.setFee(mintFeeFP)
  255. await pool.createChainPath(chainId, poolId, weight)
  256. await pool.createChainPath(chainId1, poolId, weight)
  257. await pool.createChainPath(chainId2, poolId, weight)
  258. await pool.createChainPath(chainId3, poolId, weight)
  259. await pool.mint(alice.address, amountLD)
  260. await expect(pool.redeemLocalCallback(chainId, poolId, alice.address, 0, 0)).to.emit(pool, "RedeemLocalCallback")
  261. })
  262. it("redeemLocalCheckOnRemote() - emits event", async function () {
  263. const amountSD = 12
  264. const swapAmount = 0
  265. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  266. await expect(pool.redeemLocalCheckOnRemote(chainId, poolId, amountSD))
  267. .to.emit(pool, "WithdrawRemote")
  268. .withArgs(chainId, poolId, swapAmount, amountSD)
  269. })
  270. it("createChainPath() - emit correct event", async function () {
  271. await expect(pool.createChainPath(chainId, poolId, defaultChainPathWeight))
  272. .to.emit(pool, "ChainPathUpdate")
  273. .withArgs(chainId, poolId, defaultChainPathWeight)
  274. })
  275. it("setWeightForChainPath() - emit correct event", async function () {
  276. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  277. await expect(pool.setWeightForChainPath(chainId, poolId, nonDefaultChainPathWeight))
  278. .to.emit(pool, "ChainPathUpdate")
  279. .withArgs(chainId, poolId, nonDefaultChainPathWeight)
  280. })
  281. it("setFee() - emits correct event", async function () {
  282. const mintFeeFP = 789
  283. await expect(pool.setFee(mintFeeFP)).to.emit(pool, "FeesUpdated").withArgs(mintFeeFP)
  284. })
  285. it("swap() - reverts when called by non Router ", async function () {
  286. await expect(pool.connect(alice).swap(dstChainId, poolId, alice.address, defaultAmountLD, defaultMinAmountLD, true)).to.be.revertedWith(
  287. "Stargate: only the router can call this method"
  288. )
  289. })
  290. it("swap() - reverts if swapStop called", async function () {
  291. await pool.setSwapStop(true)
  292. await expect(pool.swap(dstChainId, poolId, alice.address, defaultAmountLD, defaultMinAmountLD, true)).to.be.revertedWith(
  293. "Stargate: swap func stopped"
  294. )
  295. })
  296. it("swap() - reverts if chainPath not active", async function () {
  297. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  298. await expect(pool.swap(chainId, poolId, alice.address, defaultAmountLD, defaultMinAmountLD, true)).to.be.revertedWith(
  299. "Stargate: counter chainPath is not ready"
  300. )
  301. })
  302. it("sendCredits() - reverts when called by non Router ", async function () {
  303. await expect(pool.connect(alice).sendCredits(dstChainId, poolId)).to.be.revertedWith("Stargate: only the router can call this method")
  304. })
  305. it("sendCredits() - emits event", async function () {
  306. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  307. // it fails because the chainPath not yet activatged
  308. await expect(pool.connect(owner).sendCredits(chainId, poolId)).to.be.revertedWith("Stargate: counter chainPath is not ready")
  309. // activate it
  310. await pool.connect(owner).activateChainPath(chainId, poolId)
  311. // input wrong chain id
  312. await expect(pool.connect(owner).sendCredits(17856, poolId)).to.be.revertedWith("Stargate: local chainPath does not exist")
  313. // this would succeed
  314. await expect(pool.connect(owner).sendCredits(chainId, poolId)).to.emit(pool, "SendCredits").withArgs(chainId, poolId, 0, 0)
  315. })
  316. it("redeemRemote() - reverts when _from is 0x0", async function () {
  317. await expect(pool.redeemRemote(chainId, poolId, ZERO_ADDRESS, 1)).to.be.revertedWith("Stargate: _from cannot be 0x0")
  318. })
  319. it("redeemLocal() - reverts when _from is 0x0", async function () {
  320. await expect(pool.redeemLocal(ZERO_ADDRESS, 1, dstChainId, dstPoolId, ZERO_ADDRESS)).to.be.revertedWith("Stargate: _from cannot be 0x0")
  321. })
  322. it("redeemRemote() - reverts when called by non Router ", async function () {
  323. await expect(pool.connect(alice).redeemRemote(dstChainId, dstPoolId, alice.address, 1)).to.be.revertedWith(
  324. "Stargate: only the router can call this method"
  325. )
  326. })
  327. it("redeemRemote() - reverts when trying to burn and totalSupply is 0", async function () {
  328. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  329. await pool.activateChainPath(chainId, poolId)
  330. await expect(pool.connect(owner).redeemRemote(chainId, poolId, alice.address, 1)).to.be.revertedWith(
  331. "Stargate: cant burn when totalSupply == 0"
  332. )
  333. })
  334. it("activateChainPath() - reverts when called on already activated path", async function () {
  335. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  336. await pool.activateChainPath(chainId, poolId)
  337. await expect(pool.activateChainPath(chainId, poolId)).to.be.revertedWith("Stargate: chainPath is already active")
  338. })
  339. it("createChainPath() - reverts when duplicate chainpath tried to be created", async function () {
  340. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  341. await expect(pool.createChainPath(chainId, poolId, 1)).to.be.revertedWith(
  342. "Stargate: cant createChainPath of existing dstChainId and _dstPoolId"
  343. )
  344. })
  345. it("activateChainPath() - reverts when called on a cp that doesnt exist", async function () {
  346. await pool.createChainPath(chainId, poolId, defaultChainPathWeight)
  347. await expect(pool.activateChainPath(chainId + 1, poolId)).to.be.revertedWith("Stargate: local chainPath does not exist")
  348. })
  349. it("redeemLocal() - reverts when called by non Router ", async function () {
  350. await expect(pool.connect(alice).redeemLocal(alice.address, 1, dstChainId, dstPoolId, alice.address)).to.be.revertedWith(
  351. "Stargate: only the router can call this method"
  352. )
  353. })
  354. it("creditChainPath() - reverts when called by non Router ", async function () {
  355. await expect(pool.connect(alice).creditChainPath(dstChainId, poolId, { credits: 1, idealBalance: 1 })).to.be.revertedWith(
  356. "Stargate: only the router can call this method"
  357. )
  358. })
  359. it("swapRemote() - reverts when called by non Router ", async function () {
  360. const swapObj = { amount: 1, eqFee: 2, eqReward: 3, lpFee: 4, protocolFee: 5, lkbRemove: 6 } // dummy object for this test
  361. await expect(pool.connect(alice).swapRemote(chainId, poolId, alice.address, swapObj)).to.be.revertedWith(
  362. "Stargate: only the router can call this method"
  363. )
  364. })
  365. it("redeemLocalCallback() - reverts when called by non Router ", async function () {
  366. await expect(pool.connect(alice).redeemLocalCallback(chainId, poolId, alice.address, 1, 1)).to.be.revertedWith(
  367. "Stargate: only the router can call this method"
  368. )
  369. })
  370. it("redeemLocalCheckOnRemote() - reverts when called by non Router ", async function () {
  371. await expect(pool.connect(alice).redeemLocalCheckOnRemote(dstChainId, poolId, 1)).to.be.revertedWith(
  372. "Stargate: only the router can call this method"
  373. )
  374. })
  375. it("createChainPath() - reverts when called by non Router ", async function () {
  376. await expect(pool.connect(alice).createChainPath(chainId, poolId, 1)).to.be.revertedWith(
  377. "Stargate: only the router can call this method"
  378. )
  379. })
  380. it("setWeightForChainPath() - reverts when called by non Router ", async function () {
  381. await expect(pool.connect(alice).setWeightForChainPath(chainId, poolId, nonDefaultChainPathWeight)).to.be.revertedWith(
  382. "Stargate: only the router can call this method"
  383. )
  384. })
  385. it("setWeightForChainPath() - reverts when no chainPaths have been created yet", async function () {
  386. await expect(pool.setWeightForChainPath(chainId, poolId, nonDefaultChainPathWeight)).to.be.revertedWith("Stargate: no chainpaths exist")
  387. })
  388. it("setFee() - reverts when called by non Router ", async function () {
  389. const fee = 3
  390. await expect(pool.connect(alice).setFee(fee)).to.be.revertedWith("Stargate: only the router can call this method")
  391. })
  392. it("setFee() - reverts cumulative fee exceeds 100%", async function () {
  393. const fee = 10001
  394. await expect(pool.setFee(fee)).to.be.revertedWith("Bridge: cum fees > 100%")
  395. })
  396. it("setFeeLibrary() - sets properly", async function () {
  397. await expect(pool.setFeeLibrary(fakeContract.address)).to.emit(pool, "FeeLibraryUpdated").withArgs(fakeContract.address)
  398. })
  399. it("setFeeLibrary() - reverts by non-router", async function () {
  400. await expect(pool.connect(alice).setFeeLibrary(fakeContract.address)).to.be.revertedWith(
  401. "Stargate: only the router can call this method"
  402. )
  403. })
  404. it("setFeeLibrary() - reverts library address is 0x0", async function () {
  405. await expect(pool.setFeeLibrary(ZERO_ADDRESS)).to.be.revertedWith("Stargate: fee library cant be 0x0")
  406. })
  407. it("setSwapStop() - set / emit event", async function () {
  408. await expect(pool.setSwapStop(true)).to.emit(pool, "StopSwapUpdated").withArgs(true)
  409. })
  410. it("setSwapStop() - reverts by non router", async function () {
  411. await expect(pool.connect(alice).setSwapStop(fakeContract.address)).to.be.revertedWith("Stargate: only the router can call this method")
  412. })
  413. it("setDeltaParam() - reverts by non-router", async function () {
  414. const swapDeltaBP = 1
  415. const lpDeltaBP = 1
  416. await expect(pool.connect(alice).setDeltaParam(true, swapDeltaBP, lpDeltaBP, true, true)).to.be.revertedWith(
  417. "Stargate: only the router can call this method"
  418. )
  419. })
  420. it("setDeltaParam() - reverts if basis points are wrong", async function () {
  421. const swapDeltaBP = 10001
  422. const lpDeltaBP = 10001
  423. await expect(pool.setDeltaParam(true, swapDeltaBP, lpDeltaBP, true, true)).to.be.revertedWith("Stargate: wrong Delta param")
  424. })
  425. it("setDeltaParam() - emits event", async function () {
  426. const swapDeltaBP = 100
  427. const lpDeltaBP = 100
  428. await expect(pool.setDeltaParam(true, swapDeltaBP, lpDeltaBP, true, true))
  429. .to.emit(pool, "DeltaParamUpdated")
  430. .withArgs(true, swapDeltaBP, lpDeltaBP, true, true)
  431. })
  432. it("callDelta() - reverts by non-router", async function () {
  433. await expect(pool.connect(alice).callDelta(true)).to.be.revertedWith("Stargate: only the router can call this method")
  434. })
  435. it("withdrawProtocolFeeBalance() - reverts when called by non Router ", async function () {
  436. await expect(pool.connect(alice).withdrawProtocolFeeBalance(alice.address)).to.be.revertedWith(
  437. "Stargate: only the router can call this method"
  438. )
  439. })
  440. it("withdrawMintFeeBalance() - reverts when called by non Router ", async function () {
  441. await expect(pool.connect(alice).withdrawMintFeeBalance(alice.address)).to.be.revertedWith(
  442. "Stargate: only the router can call this method"
  443. )
  444. })
  445. it("withdrawMintFeeBalance() - no event when mintFeeBalance equal to 0", async function () {
  446. await expect(pool.withdrawMintFeeBalance(alice.address)).to.not.emit(pool, "WithdrawMintFeeBalance")
  447. })
  448. it("withdrawProtocolFeeBalance() - no event when protocolFeeBalance equal to 0", async function () {
  449. await expect(pool.withdrawProtocolFeeBalance(alice.address)).to.not.emit(pool, "WithdrawProtocolFeeBalance")
  450. })
  451. it("createChainPath() - x6 and mint() which calls _distribute fees", async function () {
  452. for (let i = 1; i <= 6; ++i) {
  453. await pool.createChainPath(i, i, defaultChainPathWeight)
  454. await pool.mint(alice.address, 10000)
  455. }
  456. })
  457. it("createChainPath() - x10 and mint() which calls _distribute fees", async function () {
  458. for (let i = 1; i <= 10; ++i) {
  459. await pool.createChainPath(i, i, nonDefaultChainPathWeight)
  460. await pool.mint(alice.address, 12341234)
  461. }
  462. })
  463. it("createChainPath() - x50 and mint() which calls _distribute fees", async function () {
  464. for (let i = 0; i < 50; ++i) {
  465. // 50 connected chains
  466. await pool.createChainPath(i, i, nonDefaultChainPathWeight)
  467. await pool.mint(alice.address, 777)
  468. }
  469. })
  470. })