Skip to content

Commit 41366f4

Browse files
committed
Split PoolModuleFundAdmin.test.ts
1 parent 520633a commit 41366f4

6 files changed

+835
-795
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import assert from 'node:assert';
2+
import { ethers } from 'ethers';
3+
import { bootstrapWithMockMarketAndPool } from '../../bootstrap';
4+
5+
describe('PoolModule Admin createPool()', function () {
6+
const { signers, systems, restore } = bootstrapWithMockMarketAndPool();
7+
8+
let owner: ethers.Signer, user1: ethers.Signer;
9+
10+
const secondPoolId = 3384692;
11+
12+
before('identify signers', async () => {
13+
[owner, user1] = signers();
14+
});
15+
16+
before(restore);
17+
18+
it('fails when pool already exists', async () => {});
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(secondPoolId, await user1.getAddress())
34+
).wait();
35+
});
36+
37+
it('pool is created', async () => {
38+
assert.equal(await systems().Core.getPoolOwner(secondPoolId), await user1.getAddress());
39+
});
40+
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber';
2+
import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert';
3+
import { ethers } from 'ethers';
4+
import { bootstrapWithMockMarketAndPool } from '../../bootstrap';
5+
6+
describe('PoolModule Admin setMinLiquidityRatio(uint256)', function () {
7+
const { signers, systems, restore } = bootstrapWithMockMarketAndPool();
8+
9+
let owner: ethers.Signer, user1: ethers.Signer;
10+
11+
before('identify signers', async () => {
12+
[owner, user1] = signers();
13+
});
14+
15+
before(restore);
16+
17+
it('only works for owner', async () => {
18+
await assertRevert(
19+
systems().Core.connect(user1)['setMinLiquidityRatio(uint256)'](ethers.utils.parseEther('2')),
20+
`Unauthorized("${await user1.getAddress()}")`,
21+
systems().Core
22+
);
23+
});
24+
25+
it('is set when invoked successfully', async () => {
26+
const value = ethers.utils.parseEther('2');
27+
await systems().Core.connect(owner)['setMinLiquidityRatio(uint256)'](value);
28+
assertBn.equal(await systems().Core['getMinLiquidityRatio()'](), value);
29+
});
30+
});

0 commit comments

Comments
 (0)