|
| 1 | +import assert from 'node:assert'; |
| 2 | +import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber'; |
| 3 | +import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert'; |
| 4 | +import { ethers } from 'ethers'; |
| 5 | +import { bn, bootstrapWithMockMarketAndPool } from '../../bootstrap'; |
| 6 | + |
| 7 | +describe('PoolModule Admin set pool collateral issuance ratio', function () { |
| 8 | + const { signers, systems, collateralAddress, restore } = bootstrapWithMockMarketAndPool(); |
| 9 | + |
| 10 | + let owner: ethers.Signer, user1: ethers.Signer, user2: ethers.Signer; |
| 11 | + |
| 12 | + const thirdPoolId = 3384633; |
| 13 | + |
| 14 | + before('identify signers', async () => { |
| 15 | + [owner, user1, user2] = signers(); |
| 16 | + }); |
| 17 | + |
| 18 | + before(restore); |
| 19 | + |
| 20 | + before('give user1 permission to create pool', async () => { |
| 21 | + await systems() |
| 22 | + .Core.connect(owner) |
| 23 | + .addToFeatureFlagAllowlist( |
| 24 | + ethers.utils.formatBytes32String('createPool'), |
| 25 | + await user1.getAddress() |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + before('create a pool', async () => { |
| 30 | + await ( |
| 31 | + await systems() |
| 32 | + .Core.connect(user1) |
| 33 | + .createPool(thirdPoolId, await user1.getAddress()) |
| 34 | + ).wait(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('only works for owner', async () => { |
| 38 | + await assertRevert( |
| 39 | + systems() |
| 40 | + .Core.connect(user2) |
| 41 | + .setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), { |
| 42 | + collateralLimitD18: bn(10), |
| 43 | + issuanceRatioD18: bn(2), |
| 44 | + }), |
| 45 | + `Unauthorized("${await user2.getAddress()}")`, |
| 46 | + systems().Core |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it('min collateral ratio is set to zero for the pool by default', async () => { |
| 51 | + assert.equal( |
| 52 | + await systems().Core.getPoolCollateralIssuanceRatio(thirdPoolId, collateralAddress()), |
| 53 | + 0 |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it('set the pool collateal issuance ratio to 200%', async () => { |
| 58 | + await systems() |
| 59 | + .Core.connect(user1) |
| 60 | + .setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), { |
| 61 | + collateralLimitD18: bn(10), |
| 62 | + issuanceRatioD18: bn(2), |
| 63 | + }); |
| 64 | + |
| 65 | + assertBn.equal( |
| 66 | + await systems().Core.getPoolCollateralIssuanceRatio(thirdPoolId, collateralAddress()), |
| 67 | + bn(2) |
| 68 | + ); |
| 69 | + }); |
| 70 | + |
| 71 | + it('can get pool collateral configuration', async () => { |
| 72 | + await systems() |
| 73 | + .Core.connect(user1) |
| 74 | + .setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), { |
| 75 | + collateralLimitD18: bn(123), |
| 76 | + issuanceRatioD18: bn(345), |
| 77 | + }); |
| 78 | + |
| 79 | + const { collateralLimitD18, issuanceRatioD18 } = |
| 80 | + await systems().Core.getPoolCollateralConfiguration(thirdPoolId, collateralAddress()); |
| 81 | + assert.deepEqual( |
| 82 | + { collateralLimitD18, issuanceRatioD18 }, |
| 83 | + { collateralLimitD18: bn(123), issuanceRatioD18: bn(345) } |
| 84 | + ); |
| 85 | + }); |
| 86 | +}); |
0 commit comments