Skip to content

Commit

Permalink
First TradingStrategyModuleV0 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Dec 30, 2024
1 parent 6d4a2c9 commit 1adcf0e
Showing 7 changed files with 294 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -53,7 +53,9 @@ safe-integration:
@(cd contracts/safe-integration && forge build)
@find contracts/safe-integration/out \
\( \
-name "TradingStrategyModule.json" \
-name "TradingStrategyModuleV0.json" \
-o \
-name "MockSafe.json" \
\) \
-exec cp {} eth_defi/abi/safe-integration \;

3 changes: 3 additions & 0 deletions contracts/safe-integration/src/MockSafe.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;

/**
* Mock enableModule()
*/
contract MockSafe {
address public module;

Original file line number Diff line number Diff line change
@@ -23,11 +23,13 @@ import "@guard/GuardV0Base.sol";
* - Support Lagoon, Gnosis Safe and other Gnosis Safe-based ecosystems which support Zodiac modules
* - Owner should point to Gnosis Safe / DAO
*
* This is initial, MVP, version.
*
*/
contract TradingStrategyModule is Module, GuardV0Base {
contract TradingStrategyModuleV0 is Module, GuardV0Base {

constructor(address _owner) {
bytes memory initializeParams = abi.encode(_owner);
constructor(address _owner, address _target) {
bytes memory initializeParams = abi.encode(_owner, _target);
setUp(initializeParams);
}

@@ -48,9 +50,9 @@ contract TradingStrategyModule is Module, GuardV0Base {
/// https://gist.github.com/auryn-macmillan/841906d0bc6c2624e83598cdfac17de8
function setUp(bytes memory initializeParams) public override initializer {
__Ownable_init(msg.sender);
(address _owner) = abi.decode(initializeParams, (address));

setAvatar(_owner);
(address _owner, address _target) = abi.decode(initializeParams, (address, address));
setAvatar(_target);
setTarget(_target);
transferOwnership(_owner);
}

@@ -74,7 +76,7 @@ contract TradingStrategyModule is Module, GuardV0Base {
target,
0,
callData,
Enum.Operation.Call
Enum.Operation.DelegateCall
);
}
}
1 change: 1 addition & 0 deletions eth_defi/abi/safe-integration/MockSafe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"abi":[{"type":"receive","stateMutability":"payable"},{"type":"function","name":"enableModule","inputs":[{"name":"_module","type":"address","internalType":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"exec","inputs":[{"name":"to","type":"address","internalType":"address payable"},{"name":"value","type":"uint256","internalType":"uint256"},{"name":"data","type":"bytes","internalType":"bytes"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"execTransactionFromModule","inputs":[{"name":"to","type":"address","internalType":"address payable"},{"name":"value","type":"uint256","internalType":"uint256"},{"name":"data","type":"bytes","internalType":"bytes"},{"name":"operation","type":"uint8","internalType":"uint8"}],"outputs":[{"name":"success","type":"bool","internalType":"bool"}],"stateMutability":"nonpayable"},{"type":"function","name":"module","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"error","name":"NotAuthorized","inputs":[{"name":"unacceptedAddress","type":"address","internalType":"address"}]}],"bytecode":{"object":"0x6080604052348015600f57600080fd5b506104468061001f6000396000f3fe6080604052600436106100435760003560e01c80630565bb671461004f578063468721a714610071578063610b5925146100a6578063b86d5298146100e357600080fd5b3661004a57005b600080fd5b34801561005b57600080fd5b5061006f61006a366004610306565b61011b565b005b34801561007d57600080fd5b5061009161008c366004610362565b610197565b60405190151581526020015b60405180910390f35b3480156100b257600080fd5b5061006f6100c13660046103dc565b600080546001600160a01b0319166001600160a01b0392909216919091179055565b3480156100ef57600080fd5b50600054610103906001600160a01b031681565b6040516001600160a01b03909116815260200161009d565b60006060856001600160a01b031685858560405161013a929190610400565b60006040518083038185875af1925050503d8060008114610177576040519150601f19603f3d011682016040523d82523d6000602084013e61017c565b606091505b5090925090508161018f57805160208201fd5b505050505050565b600080546001600160a01b031633146101c957604051634a0bfec160e01b815233600482015260240160405180910390fd5b8160ff1660010361023957856001600160a01b031684846040516101ee929190610400565b600060405180830381855af49150503d8060008114610229576040519150601f19603f3d011682016040523d82523d6000602084013e61022e565b606091505b50508091505061029c565b856001600160a01b0316858585604051610254929190610400565b60006040518083038185875af1925050503d8060008114610291576040519150601f19603f3d011682016040523d82523d6000602084013e610296565b606091505b50909150505b95945050505050565b6001600160a01b03811681146102ba57600080fd5b50565b60008083601f8401126102cf57600080fd5b50813567ffffffffffffffff8111156102e757600080fd5b6020830191508360208285010111156102ff57600080fd5b9250929050565b6000806000806060858703121561031c57600080fd5b8435610327816102a5565b935060208501359250604085013567ffffffffffffffff81111561034a57600080fd5b610356878288016102bd565b95989497509550505050565b60008060008060006080868803121561037a57600080fd5b8535610385816102a5565b945060208601359350604086013567ffffffffffffffff8111156103a857600080fd5b6103b4888289016102bd565b909450925050606086013560ff811681146103ce57600080fd5b809150509295509295909350565b6000602082840312156103ee57600080fd5b81356103f9816102a5565b9392505050565b818382376000910190815291905056fea26469706673582212200446d66091ce10af1428ad4b2f918c362021407997eb056c1cb84dfb481acccf64736f6c634300081a0033","sourceMap":"99:968:0:-:0;;;;;;;;;;;;;;;;;;;","linkReferences":{}},"deployedBytecode":{"object":"0x6080604052600436106100435760003560e01c80630565bb671461004f578063468721a714610071578063610b5925146100a6578063b86d5298146100e357600080fd5b3661004a57005b600080fd5b34801561005b57600080fd5b5061006f61006a366004610306565b61011b565b005b34801561007d57600080fd5b5061009161008c366004610362565b610197565b60405190151581526020015b60405180910390f35b3480156100b257600080fd5b5061006f6100c13660046103dc565b600080546001600160a01b0319166001600160a01b0392909216919091179055565b3480156100ef57600080fd5b50600054610103906001600160a01b031681565b6040516001600160a01b03909116815260200161009d565b60006060856001600160a01b031685858560405161013a929190610400565b60006040518083038185875af1925050503d8060008114610177576040519150601f19603f3d011682016040523d82523d6000602084013e61017c565b606091505b5090925090508161018f57805160208201fd5b505050505050565b600080546001600160a01b031633146101c957604051634a0bfec160e01b815233600482015260240160405180910390fd5b8160ff1660010361023957856001600160a01b031684846040516101ee929190610400565b600060405180830381855af49150503d8060008114610229576040519150601f19603f3d011682016040523d82523d6000602084013e61022e565b606091505b50508091505061029c565b856001600160a01b0316858585604051610254929190610400565b60006040518083038185875af1925050503d8060008114610291576040519150601f19603f3d011682016040523d82523d6000602084013e610296565b606091505b50909150505b95945050505050565b6001600160a01b03811681146102ba57600080fd5b50565b60008083601f8401126102cf57600080fd5b50813567ffffffffffffffff8111156102e757600080fd5b6020830191508360208285010111156102ff57600080fd5b9250929050565b6000806000806060858703121561031c57600080fd5b8435610327816102a5565b935060208501359250604085013567ffffffffffffffff81111561034a57600080fd5b610356878288016102bd565b95989497509550505050565b60008060008060006080868803121561037a57600080fd5b8535610385816102a5565b945060208601359350604086013567ffffffffffffffff8111156103a857600080fd5b6103b4888289016102bd565b909450925050606086013560ff811681146103ce57600080fd5b809150509295509295909350565b6000602082840312156103ee57600080fd5b81356103f9816102a5565b9392505050565b818382376000910190815291905056fea26469706673582212200446d66091ce10af1428ad4b2f918c362021407997eb056c1cb84dfb481acccf64736f6c634300081a0033","sourceMap":"99:968:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;326:359;;;;;;;;;;-1:-1:-1;326:359:0;;;;;:::i;:::-;;:::i;:::-;;691:374;;;;;;;;;;-1:-1:-1;691:374:0;;;;;:::i;:::-;;:::i;:::-;;;2211:14:1;;2204:22;2186:41;;2174:2;2159:18;691:374:0;;;;;;;;239:81;;;;;;;;;;-1:-1:-1;239:81:0;;;;;:::i;:::-;297:6;:16;;-1:-1:-1;;;;;;297:16:0;-1:-1:-1;;;;;297:16:0;;;;;;;;;;239:81;123:21;;;;;;;;;;-1:-1:-1;123:21:0;;;;-1:-1:-1;;;;;123:21:0;;;;;;-1:-1:-1;;;;;2662:32:1;;;2644:51;;2632:2;2617:18;123:21:0;2498:203:1;326:359:0;445:12;467:21;520:2;-1:-1:-1;;;;;520:7:0;535:5;542:4;;520:27;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;498:49:0;;-1:-1:-1;498:49:0;-1:-1:-1;498:49:0;557:122;;646:8;640:15;633:4;623:8;619:19;612:44;557:122;435:250;;326:359;;;;:::o;691:374::-;855:12;897:6;;-1:-1:-1;;;;;897:6:0;883:10;:20;879:58;;912:25;;-1:-1:-1;;;912:25:0;;926:10;912:25;;;2644:51:1;2617:18;;912:25:0;;;;;;;879:58;951:9;:14;;964:1;951:14;947:111;;981:2;-1:-1:-1;;;;;981:15:0;997:4;;981:21;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;967:35;;;;;947:111;;;1031:2;-1:-1:-1;;;;;1031:7:0;1046:5;1053:4;;1031:27;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1017:41:0;;-1:-1:-1;;947:111:0;691:374;;;;;;;:::o;14:139:1:-;-1:-1:-1;;;;;97:31:1;;87:42;;77:70;;143:1;140;133:12;77:70;14:139;:::o;158:347::-;209:8;219:6;273:3;266:4;258:6;254:17;250:27;240:55;;291:1;288;281:12;240:55;-1:-1:-1;314:20:1;;357:18;346:30;;343:50;;;389:1;386;379:12;343:50;426:4;418:6;414:17;402:29;;478:3;471:4;462:6;454;450:19;446:30;443:39;440:59;;;495:1;492;485:12;440:59;158:347;;;;;:::o;510:680::-;606:6;614;622;630;683:2;671:9;662:7;658:23;654:32;651:52;;;699:1;696;689:12;651:52;738:9;725:23;757:39;790:5;757:39;:::i;:::-;815:5;-1:-1:-1;893:2:1;878:18;;865:32;;-1:-1:-1;974:2:1;959:18;;946:32;1001:18;990:30;;987:50;;;1033:1;1030;1023:12;987:50;1072:58;1122:7;1113:6;1102:9;1098:22;1072:58;:::i;:::-;510:680;;;;-1:-1:-1;1149:8:1;-1:-1:-1;;;;510:680:1:o;1195:846::-;1298:6;1306;1314;1322;1330;1383:3;1371:9;1362:7;1358:23;1354:33;1351:53;;;1400:1;1397;1390:12;1351:53;1439:9;1426:23;1458:39;1491:5;1458:39;:::i;:::-;1516:5;-1:-1:-1;1594:2:1;1579:18;;1566:32;;-1:-1:-1;1675:2:1;1660:18;;1647:32;1702:18;1691:30;;1688:50;;;1734:1;1731;1724:12;1688:50;1773:58;1823:7;1814:6;1803:9;1799:22;1773:58;:::i;:::-;1850:8;;-1:-1:-1;1747:84:1;-1:-1:-1;;1937:2:1;1922:18;;1909:32;1985:4;1972:18;;1960:31;;1950:59;;2005:1;2002;1995:12;1950:59;2028:7;2018:17;;;1195:846;;;;;;;;:::o;2238:255::-;2297:6;2350:2;2338:9;2329:7;2325:23;2321:32;2318:52;;;2366:1;2363;2356:12;2318:52;2405:9;2392:23;2424:39;2457:5;2424:39;:::i;:::-;2482:5;2238:255;-1:-1:-1;;;2238:255:1:o;2706:271::-;2889:6;2881;2876:3;2863:33;2845:3;2915:16;;2940:13;;;2915:16;2706:271;-1:-1:-1;2706:271:1:o","linkReferences":{}},"methodIdentifiers":{"enableModule(address)":"610b5925","exec(address,uint256,bytes)":"0565bb67","execTransactionFromModule(address,uint256,bytes,uint8)":"468721a7","module()":"b86d5298"},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.26+commit.8a97fa7a\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"unacceptedAddress\",\"type\":\"address\"}],\"name\":\"NotAuthorized\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_module\",\"type\":\"address\"}],\"name\":\"enableModule\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address payable\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"exec\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address payable\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"},{\"internalType\":\"uint8\",\"name\":\"operation\",\"type\":\"uint8\"}],\"name\":\"execTransactionFromModule\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"module\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"Mock enableModule()\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/MockSafe.sol\":\"MockSafe\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@gnosis.pm/=lib/\",\":@guard/=../guard/src/\",\":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/\",\":@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/\",\":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/\",\":forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/\",\":halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/\",\":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/\",\":safe-contracts/=lib/safe-contracts/contracts/\",\":zodiac/=lib/zodiac/contracts/\"]},\"sources\":{\"src/MockSafe.sol\":{\"keccak256\":\"0xe7ca31646cacbc8d18220086972343ec6cd1691f86fcde14d9dd0849a1978271\",\"license\":\"LGPL-3.0-only\",\"urls\":[\"bzz-raw://57d1cbf6dcabb14156d4e965c81c5a0f0c034258709144e5e9bd1ac2219c3133\",\"dweb:/ipfs/Qmdch8e6TZxMUUo7AHPrSuLJADh3GQHwyQ7XBurtdqUuzw\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.26+commit.8a97fa7a"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"unacceptedAddress","type":"address"}],"type":"error","name":"NotAuthorized"},{"inputs":[{"internalType":"address","name":"_module","type":"address"}],"stateMutability":"nonpayable","type":"function","name":"enableModule"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function","name":"exec"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint8","name":"operation","type":"uint8"}],"stateMutability":"nonpayable","type":"function","name":"execTransactionFromModule","outputs":[{"internalType":"bool","name":"success","type":"bool"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"module","outputs":[{"internalType":"address","name":"","type":"address"}]},{"inputs":[],"stateMutability":"payable","type":"receive"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@gnosis.pm/=lib/","@guard/=../guard/src/","@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/","@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/","erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/","forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/","halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/","openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/","openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/","safe-contracts/=lib/safe-contracts/contracts/","zodiac/=lib/zodiac/contracts/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"ipfs"},"compilationTarget":{"src/MockSafe.sol":"MockSafe"},"evmVersion":"paris","libraries":{}},"sources":{"src/MockSafe.sol":{"keccak256":"0xe7ca31646cacbc8d18220086972343ec6cd1691f86fcde14d9dd0849a1978271","urls":["bzz-raw://57d1cbf6dcabb14156d4e965c81c5a0f0c034258709144e5e9bd1ac2219c3133","dweb:/ipfs/Qmdch8e6TZxMUUo7AHPrSuLJADh3GQHwyQ7XBurtdqUuzw"],"license":"LGPL-3.0-only"}},"version":1},"id":0}
1 change: 0 additions & 1 deletion eth_defi/abi/safe-integration/TradingStrategyModule.json

This file was deleted.

1 change: 1 addition & 0 deletions eth_defi/abi/safe-integration/TradingStrategyModuleV0.json

Large diffs are not rendered by default.

Loading

0 comments on commit 1adcf0e

Please sign in to comment.