-
Notifications
You must be signed in to change notification settings - Fork 3
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
test(medusa): multiple strat #48
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,20 +8,30 @@ import {Allo, IAllo, Metadata} from "contracts/core/Allo.sol"; | |
import {Registry, Anchor} from "contracts/core/Anchor.sol"; | ||
import {IRegistry} from "contracts/core/interfaces/IRegistry.sol"; | ||
import {DirectAllocationStrategy} from "contracts/strategies/examples/direct-allocation/DirectAllocation.sol"; | ||
import {QVSimple} from "contracts/strategies/examples/quadratic-voting/QVSimple.sol"; | ||
import {SQFSuperfluid} from "contracts/strategies/examples/sqf-superfluid/SQFSuperfluid.sol"; | ||
|
||
import {IRecipientsExtension} from "strategies/extensions/register/IRecipientsExtension.sol"; | ||
|
||
import {Actors} from "./helpers/Actors.t.sol"; | ||
import {Pools} from "./helpers/Pools.t.sol"; | ||
import {Utils} from "./helpers/Utils.t.sol"; | ||
import {FuzzERC20, ERC20} from "./helpers/FuzzERC20.sol"; | ||
|
||
contract Setup is Actors { | ||
contract Setup is Actors, Pools { | ||
uint256 percentFee; | ||
uint256 baseFee; | ||
|
||
uint64 defaultRegistrationStartTime; | ||
uint64 defaultRegistrationEndTime; | ||
uint256 defaultAllocationStartTime; | ||
uint256 defaultAllocationEndTime; | ||
uint256 defaultWithdrawalCooldown; | ||
uint256 DEFAULT_MAX_BID; | ||
|
||
Allo allo; | ||
Registry registry; | ||
|
||
DirectAllocationStrategy strategy_directAllocation; | ||
|
||
ERC20 token; | ||
|
||
address protocolDeployer = makeAddr("protocolDeployer"); | ||
|
@@ -58,8 +68,10 @@ contract Setup is Actors { | |
forwarder | ||
); | ||
|
||
// Deploy base strategy | ||
strategy_directAllocation = new DirectAllocationStrategy(address(allo)); | ||
// Deploy strategies implementations | ||
_initImplementations(address(allo)); | ||
|
||
// strategy_directAllocation = new DirectAllocationStrategy(address(allo)); | ||
|
||
// Deploy token | ||
token = ERC20(address(new FuzzERC20())); | ||
|
@@ -79,5 +91,101 @@ contract Setup is Actors { | |
registry.getProfileById(_id).anchor | ||
); | ||
} | ||
|
||
// Create pools for each strategy | ||
_initPools(); | ||
} | ||
|
||
function _initPools() internal { | ||
defaultRegistrationStartTime = uint64(block.timestamp); | ||
defaultRegistrationEndTime = uint64(block.timestamp + 7 days); | ||
defaultAllocationStartTime = uint64(block.timestamp + 7 days + 1); | ||
defaultAllocationEndTime = uint64(block.timestamp + 10 days); | ||
defaultWithdrawalCooldown = 1 days; | ||
DEFAULT_MAX_BID = 1000; | ||
|
||
for (uint256 i = 1; i <= uint256(type(PoolStrategies).max); i++) { | ||
address _deployer = _ghost_actors[i % 4]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the first 4 actors are anchor owner, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense |
||
|
||
IRegistry.Profile memory profile = registry.getProfileByAnchor( | ||
_ghost_anchorOf[_deployer] | ||
); | ||
|
||
bytes memory _metadata; | ||
|
||
if (PoolStrategies(i) == PoolStrategies.DirectAllocation) { | ||
_metadata = ""; | ||
} else if (PoolStrategies(i) == PoolStrategies.DonationVoting) { | ||
_metadata = abi.encode( | ||
IRecipientsExtension.RecipientInitializeData({ | ||
metadataRequired: false, | ||
registrationStartTime: defaultRegistrationStartTime, | ||
registrationEndTime: defaultRegistrationEndTime | ||
}), | ||
defaultAllocationStartTime, | ||
defaultAllocationEndTime, | ||
defaultWithdrawalCooldown, | ||
token, | ||
true | ||
); | ||
} else if ( | ||
PoolStrategies(i) == PoolStrategies.EasyRPGF | ||
) {} else if (PoolStrategies(i) == PoolStrategies.ImpactStream) { | ||
_metadata = abi.encode( | ||
IRecipientsExtension.RecipientInitializeData({ | ||
metadataRequired: false, | ||
registrationStartTime: uint64(block.timestamp), | ||
registrationEndTime: uint64(block.timestamp + 7 days) | ||
}), | ||
QVSimple.QVSimpleInitializeData({ | ||
allocationStartTime: uint64(block.timestamp), | ||
allocationEndTime: uint64(block.timestamp + 7 days), | ||
maxVoiceCreditsPerAllocator: 100, | ||
isUsingAllocationMetadata: false | ||
}) | ||
); | ||
} else if (PoolStrategies(i) == PoolStrategies.QuadraticVoting) { | ||
_metadata = abi.encode( | ||
IRecipientsExtension.RecipientInitializeData({ | ||
metadataRequired: false, | ||
registrationStartTime: uint64(block.timestamp), | ||
registrationEndTime: uint64(block.timestamp + 7 days) | ||
}), | ||
QVSimple.QVSimpleInitializeData({ | ||
allocationStartTime: uint64(block.timestamp), | ||
allocationEndTime: uint64(block.timestamp + 7 days), | ||
maxVoiceCreditsPerAllocator: 100, | ||
isUsingAllocationMetadata: false | ||
}) | ||
); | ||
} else if (PoolStrategies(i) == PoolStrategies.RFP) { | ||
_metadata = abi.encode( | ||
IRecipientsExtension.RecipientInitializeData({ | ||
metadataRequired: false, | ||
registrationStartTime: uint64(block.timestamp), | ||
registrationEndTime: uint64(block.timestamp + 7 days) | ||
}), | ||
DEFAULT_MAX_BID | ||
); | ||
} else if (PoolStrategies(i) == PoolStrategies.SQFSuperfluid) { | ||
// Skip for now - mock? | ||
return; | ||
} | ||
|
||
vm.prank(_deployer); | ||
uint256 _poolId = allo.createPool( | ||
profile.id, | ||
_strategyImplementations[PoolStrategies(i)], | ||
_metadata, | ||
address(token), | ||
0, | ||
profile.metadata, | ||
new address[](0) | ||
); | ||
|
||
ghost_poolAdmins[_poolId] = _deployer; | ||
|
||
_recordPool(_poolId, PoolStrategies(i)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.19; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {Utils} from "./Utils.t.sol"; | ||
import {Anchor} from "contracts/core/Anchor.sol"; | ||
import {Allo, IAllo} from "contracts/core/Allo.sol"; | ||
|
||
import {DirectAllocationStrategy} from "contracts/strategies/examples/direct-allocation/DirectAllocation.sol"; | ||
import {DonationVotingOnchain} from "contracts/strategies/examples/donation-voting/DonationVotingOnchain.sol"; | ||
import {EasyRPGF} from "contracts/strategies/examples/easy-rpgf/EasyRPGF.sol"; | ||
import {QVImpactStream} from "contracts/strategies/examples/impact-stream/QVImpactStream.sol"; | ||
import {QVSimple} from "contracts/strategies/examples/quadratic-voting/QVSimple.sol"; | ||
import {RFPSimple} from "contracts/strategies/examples/rfp/RFPSimple.sol"; | ||
import {SQFSuperfluid} from "contracts/strategies/examples/sqf-superfluid/SQFSuperfluid.sol"; | ||
|
||
contract Pools is Utils { | ||
Allo private allo; | ||
|
||
enum PoolStrategies { | ||
None, | ||
DirectAllocation, | ||
DonationVoting, | ||
EasyRPGF, | ||
ImpactStream, | ||
QuadraticVoting, | ||
RFP, | ||
SQFSuperfluid | ||
} | ||
|
||
uint256[] internal ghost_poolIds; | ||
mapping(uint256 _poolId => address _poolAdmin) ghost_poolAdmins; | ||
|
||
// mapping(uint256 _poolId => PoolStrategies _strategy) internal _poolStrategy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this mapping be deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
|
||
mapping(PoolStrategies _strategy => address _implementation) | ||
internal _strategyImplementations; | ||
|
||
function _initImplementations(address _allo) internal { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
_strategyImplementations[PoolStrategies.DirectAllocation] = address( | ||
new DirectAllocationStrategy(_allo) | ||
); | ||
_strategyImplementations[PoolStrategies.DonationVoting] = address( | ||
new DonationVotingOnchain(_allo, "MyFancyName") | ||
); | ||
_strategyImplementations[PoolStrategies.EasyRPGF] = address( | ||
new EasyRPGF(_allo) | ||
); | ||
_strategyImplementations[PoolStrategies.ImpactStream] = address( | ||
new QVImpactStream(_allo) | ||
); | ||
_strategyImplementations[PoolStrategies.QuadraticVoting] = address( | ||
new QVSimple(_allo, "MyFancyName") | ||
); | ||
_strategyImplementations[PoolStrategies.RFP] = address( | ||
new RFPSimple(_allo) | ||
); | ||
_strategyImplementations[PoolStrategies.SQFSuperfluid] = address( | ||
new SQFSuperfluid(_allo) | ||
); | ||
|
||
allo = Allo(_allo); | ||
} | ||
|
||
function _recordPool(uint256 _poolId, PoolStrategies _strategy) internal { | ||
// _poolStrategy[_poolId] = _strategy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
ghost_poolIds.push(_poolId); | ||
} | ||
|
||
// reverse lookup pool id -> strategy type | ||
function _poolStrategy(uint256 _poolId) internal returns (PoolStrategies) { | ||
IAllo.Pool memory _pool = allo.getPool(_poolId); | ||
for (uint256 i; i < uint256(type(PoolStrategies).max); i++) | ||
if ( | ||
_strategyImplementations[PoolStrategies(i)] == | ||
address(_pool.strategy) | ||
) return PoolStrategies(i); | ||
|
||
emit TestFailure("Wrong pool strategy implementation address"); | ||
} | ||
|
||
function _strategyHasImplementation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another option is to use an aux There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we are not optimising for gas, I think we should avoid as much as possible having state in the test contract, when we can easily(ish) compute it instead - wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it's fine for me |
||
PoolStrategies _strategy | ||
) internal returns (bool) { | ||
for (uint256 i; i < ghost_poolIds.length; i++) { | ||
if (_poolStrategy(ghost_poolIds[i]) == _strategy) return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also yes