Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Deployer as Member #123

Merged
merged 11 commits into from
Sep 4, 2022
7 changes: 5 additions & 2 deletions contracts/core/Protocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ contract Protocol is IProtocol, ProtoBase {
* @param values[12] max lending ratio
*/
function initialize(address[] calldata addresses, uint256[] calldata values) external override nonReentrant whenNotPaused {
s.mustBeProtocolMember(msg.sender);

require(addresses[0] != address(0), "Invalid Burner");
// require(addresses[1] != address(0), "Invalid Uniswap V2 Router");
// require(addresses[2] != address(0), "Invalid Uniswap V2 Factory");
Expand Down Expand Up @@ -78,12 +76,16 @@ contract Protocol is IProtocol, ProtoBase {
AccessControlLibV1.mustBeAdmin(s);
require(addresses[3] == address(0), "Can't change NPM");
} else {
s.mustBeProtocolMember(msg.sender);
require(addresses[3] != address(0), "Invalid NPM");

s.setAddressByKey(ProtoUtilV1.CNS_CORE, address(this));
s.setBoolByKeys(ProtoUtilV1.NS_CONTRACTS, address(this), true);

s.setAddressByKey(ProtoUtilV1.CNS_NPM, addresses[3]);

s.deleteBoolByKeys(ProtoUtilV1.NS_MEMBERS, msg.sender);
emit MemberRemoved(msg.sender);
}

s.setAddressByKey(ProtoUtilV1.CNS_BURNER, addresses[0]);
Expand All @@ -109,6 +111,7 @@ contract Protocol is IProtocol, ProtoBase {
s.setUintByKey(ProtoUtilV1.NS_COVERAGE_LAG, 1 days);

initialized = true;

emit Initialized(addresses, values);
}

Expand Down
15 changes: 15 additions & 0 deletions test/examples/distributor/add-liquidity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ describe('Distributor: `addLiquidity` function', () => {
})

it('must reject if vault contract was not found', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const amount = helper.ether(5000, PRECISION)
const npmStake = helper.ether(1000)
Expand All @@ -104,9 +107,14 @@ describe('Distributor: `addLiquidity` function', () => {

await distributor.addLiquidity(coverKey, amount, npmStake, referralCode)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})

it('must reject if DAI was not found', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const amount = helper.ether(5000, PRECISION)
const npmStake = helper.ether(1000)
Expand All @@ -125,9 +133,14 @@ describe('Distributor: `addLiquidity` function', () => {

await distributor.addLiquidity(coverKey, amount, npmStake, referralCode)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})

it('must reject if NPM was not found', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const amount = helper.ether(5000, PRECISION)
const npmStake = helper.ether(1000)
Expand All @@ -146,5 +159,7 @@ describe('Distributor: `addLiquidity` function', () => {

await distributor.addLiquidity(coverKey, amount, npmStake, referralCode)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})
})
4 changes: 4 additions & 0 deletions test/examples/distributor/get-premium.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('Distributor: `getPremium` function', () => {
})

it('must reject if DAI address is not registered on the protocol', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const duration = '2'
const protection = helper.ether(10_000, PRECISION)
Expand All @@ -45,5 +48,6 @@ describe('Distributor: `getPremium` function', () => {
.should.be.rejectedWith('Fatal: Policy missing')

await deployed.store.setAddress(storeKey, deployed.policy.address)
await deployed.protocol.removeMember(owner.address)
})
})
10 changes: 10 additions & 0 deletions test/examples/distributor/purchase-policy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ describe('Distributor: `purchasePolicy` function', () => {
})

it('must reject if an policy contract was not found', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const duration = '2'
const protection = helper.ether(10_000, PRECISION)
Expand All @@ -97,9 +100,14 @@ describe('Distributor: `purchasePolicy` function', () => {
.should.be.rejectedWith('Fatal: Policy missing')

await deployed.store.setAddress(storeKey, deployed.policy.address)

await deployed.protocol.removeMember(owner.address)
})

it('must reject if DAI address is not registered on the protocol', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const duration = '2'
const protection = helper.ether(10_000, PRECISION)
Expand All @@ -114,5 +122,7 @@ describe('Distributor: `purchasePolicy` function', () => {
.should.be.rejectedWith('Fatal: DAI missing')

await deployed.store.setAddress(storeKey, deployed.dai.address)

await deployed.protocol.removeMember(owner.address)
})
})
15 changes: 15 additions & 0 deletions test/examples/distributor/remove-liquidity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ describe('Distributor: `removeLiquidity` function', () => {
})

it('must reject if vault is missing', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const pods = helper.ether(5000)
const npmStake = helper.ether(200)
Expand All @@ -106,9 +109,14 @@ describe('Distributor: `removeLiquidity` function', () => {

await distributor.removeLiquidity(coverKey, pods, npmStake, false)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})

it('must reject if DAI is missing', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const pods = helper.ether(5000)
const npmStake = helper.ether(200)
Expand All @@ -125,9 +133,14 @@ describe('Distributor: `removeLiquidity` function', () => {

await distributor.removeLiquidity(coverKey, pods, npmStake, false)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})

it('must reject if NPM is missing', async () => {
const [owner] = await ethers.getSigners()
await deployed.protocol.addMember(owner.address)

const coverKey = deployed.coverKey
const pods = helper.ether(5000)
const npmStake = helper.ether(200)
Expand All @@ -144,5 +157,7 @@ describe('Distributor: `removeLiquidity` function', () => {

await distributor.removeLiquidity(coverKey, pods, npmStake, false)
.should.not.be.rejected

await deployed.protocol.removeMember(owner.address)
})
})
2 changes: 1 addition & 1 deletion test/specs/libraries/access-control.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('AccessControlLibV1: hasAccess', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockStoreUser.address), true)
await deployed.protocol.addMember(mockStoreUser.address)
})

it('must return false when protocol address is zero', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/libraries/cover-util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('CoverUtilV1: getActiveLiquidityUnderProtection', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockStoreUser.address), true)
await deployed.protocol.addMember(mockStoreUser.address)
})

it('must return zero when active incident is zero', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/libraries/routine-invoker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('RoutineInvokerLibV1: _executeStrategy', () => {
{ StrategyLibV1: deployed.strategyLibV1.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockLiquidityEngineUser.address), true)
await deployed.protocol.addMember(mockLiquidityEngineUser.address)
})

it('must deposit all the balance when max lending ratio is greater than 1', async () => {
Expand Down
30 changes: 15 additions & 15 deletions test/specs/libraries/store-key-util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('StoreKeyUtil Library', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

describe('StoreKeyUtil: addUintByKey', () => {
Expand Down Expand Up @@ -720,7 +720,7 @@ describe('StoreKeyUtil: getAddressArrayItemPositionByKey', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -745,7 +745,7 @@ describe('StoreKeyUtil: getAddressArrayItemPositionByKeys (2 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -771,7 +771,7 @@ describe('StoreKeyUtil: getAddressArrayItemPositionByKeys (3 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -798,7 +798,7 @@ describe('StoreKeyUtil: getAddressArrayItemByIndexByKey', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -832,7 +832,7 @@ describe('StoreKeyUtil: getAddressArrayItemByIndexByKeys (2 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -868,7 +868,7 @@ describe('StoreKeyUtil: getAddressArrayItemByIndexByKeys (3 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -906,7 +906,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemPositionByKey', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -931,7 +931,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemPositionByKeys (2 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -957,7 +957,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemPositionByKeys (3 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand All @@ -984,7 +984,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemByIndexByKey', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -1018,7 +1018,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemByIndexByKeys (2 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -1054,7 +1054,7 @@ describe('StoreKeyUtil: getBytes32ArrayItemByIndexByKeys (3 keys)', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

it('must get value correctly', async () => {
Expand Down Expand Up @@ -1092,7 +1092,7 @@ describe('StoreKeyUtil: getBytes32ArrayByKey & getBytes32ArrayByKeys', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

describe('StoreKeyUtil: getBytes32ArrayByKey', () => {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ describe('StoreKeyUtil: getAddressArrayByKey & getAddressArrayByKeys', () => {
{ StoreKeyUtil: deployed.storeKeyUtil.address },
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

describe('StoreKeyUtil: getAddressArrayByKey', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/libraries/vault.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Vault Library', () => {
},
deployed.store.address
)
await deployed.store.setBool(key.qualifyMember(mockContract.address), true)
await deployed.protocol.addMember(mockContract.address)
})

describe('VaultLibV1: calculatePodsInternal', () => {
Expand Down
6 changes: 6 additions & 0 deletions test/specs/liquidity/strategy/aave/deposit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ describe('Aave Deposit', () => {
let deployed, aaveLendingPool, aToken, aaveStrategy

beforeEach(async () => {
const [owner] = await ethers.getSigners()

deployed = await deployDependencies()
await deployed.protocol.addMember(owner.address)

aToken = await deployer.deploy(cache, 'FakeToken', 'aToken', 'aToken', helper.ether(100_000_000), 18)
aaveLendingPool = await deployer.deploy(cache, 'FakeAaveLendingPool', aToken.address)
Expand Down Expand Up @@ -64,7 +67,10 @@ describe('Aave Deposit: Faulty Pool', () => {
let deployed, aaveLendingPool, aToken, aaveStrategy

beforeEach(async () => {
const [owner] = await ethers.getSigners()

deployed = await deployDependencies()
await deployed.protocol.addMember(owner.address)

aToken = await deployer.deploy(cache, 'FakeToken', 'aToken', 'aToken', helper.ether(100_000_000), 18)
aaveLendingPool = await deployer.deploy(cache, 'FaultyAaveLendingPool', aToken.address)
Expand Down
3 changes: 3 additions & 0 deletions test/specs/liquidity/strategy/aave/drain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ describe('Aave Deposit: Drained', () => {
let deployed, aaveLendingPool, aToken, aaveStrategy

beforeEach(async () => {
const [owner] = await ethers.getSigners()

deployed = await deployDependencies()
await deployed.protocol.addMember(owner.address)

aToken = await deployer.deploy(cache, 'FakeToken', 'aToken', 'aToken', helper.ether(100_000_000), 18)
aaveLendingPool = await deployer.deploy(cache, 'FakeAaveLendingPool', aToken.address)
Expand Down
Loading