From 7b9661bda7640dd58029c11f5cf6149a7cd64361 Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Sun, 27 Oct 2024 11:52:26 +0100 Subject: [PATCH] Allows withdrawal of DAO tokens back to owner() account --- README.md | 13 ++-- app/contract_address.ts | 2 +- .../RaidGeld.s.sol/8453/run-1729970220.json | 68 +++++++++++++++++++ broadcast/RaidGeld.s.sol/8453/run-latest.json | 68 +++++++++++++++++++ src/Constants.sol | 2 +- src/RaidGeld.sol | 13 +++- test/RaidGeld.t.sol | 41 +++++++---- 7 files changed, 182 insertions(+), 25 deletions(-) create mode 100644 broadcast/RaidGeld.s.sol/8453/run-1729970220.json create mode 100644 broadcast/RaidGeld.s.sol/8453/run-latest.json diff --git a/README.md b/README.md index 03e38c0..f044f0b 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ Idle game & shitcoin advanture dedicated to cohort VII of Raid Guild. ## Set up for local DEV ### 1. Run `anvil` to setup local RPC as a fork of base mainnet -`anvil --rpc-url ` -you can get a free rpc url by registering with https://alchemy.com and creating and app +`anvil --block-time 5 --rpc-url ` + +You can get a free rpc url by registering with https://alchemy.com and creating and app ### 2. Deploy contract @@ -21,10 +22,6 @@ Move to `app` dir, install deps via `npm install` and run `npm run dev` to start #### 3. 2. Change `app/contract_address.ts` to match your program address if needed -### 4. Local development requires mining blocks by hand +### 4. Fork tests -Call `cast rpc anvil_mine` to mine next block, otherwise it wont ever progress and time "stands still" as far as the game is concerned - - -### 5. Fork tests -forge test --rpc-url +forge test --rpc-url diff --git a/app/contract_address.ts b/app/contract_address.ts index 712d987..5eaa84e 100644 --- a/app/contract_address.ts +++ b/app/contract_address.ts @@ -1,4 +1,4 @@ -const contractAddress = "0xbd06B0878888bf4c6895704fa603a5ADf7e65c66"; +const contractAddress = "0xb2fc8F28aD37290245241C6cb0E411c9fff6A1d7"; export default contractAddress diff --git a/broadcast/RaidGeld.s.sol/8453/run-1729970220.json b/broadcast/RaidGeld.s.sol/8453/run-1729970220.json new file mode 100644 index 0000000..da935d1 --- /dev/null +++ b/broadcast/RaidGeld.s.sol/8453/run-1729970220.json @@ -0,0 +1,68 @@ +{ + "transactions": [ + { + "hash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionType": "CREATE", + "contractName": "RaidGeld", + "contractAddress": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "function": null, + "arguments": [ + "0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8", + "0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926" + ], + "transaction": { + "from": "0x3295cca2d922c637d35b258fc6c9c7e471803b45", + "gas": "0x1e142b", + "value": "0x0", + "input": "0x60a060405234801561001057600080fd5b50604051611ccd380380611ccd83398101604081905261002f916101e2565b336040518060400160405280600981526020016814985a590811d95b1960ba1b8152506040518060400160405280600481526020016311d1531160e21b815250816003908161007e91906102b4565b50600461008b82826102b4565b5050506001600160a01b0381166100bc57604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b6100c581610174565b50600880546001600160a01b038085166001600160a01b0319928316811790935560098054918516919092161790556040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa15801561012f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101539190610372565b61015e90600a61049b565b6101699060326104aa565b608052506104c19050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b80516001600160a01b03811681146101dd57600080fd5b919050565b600080604083850312156101f557600080fd5b6101fe836101c6565b915061020c602084016101c6565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061023f57607f821691505b60208210810361025f57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156102af57806000526020600020601f840160051c8101602085101561028c5750805b601f840160051c820191505b818110156102ac5760008155600101610298565b50505b505050565b81516001600160401b038111156102cd576102cd610215565b6102e1816102db845461022b565b84610265565b6020601f82116001811461031557600083156102fd5750848201515b600019600385901b1c1916600184901b1784556102ac565b600084815260208120601f198516915b828110156103455787850151825560209485019460019092019101610325565b50848210156103635786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b60006020828403121561038457600080fd5b815160ff8116811461039557600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b6001815b60018411156103ed578085048111156103d1576103d161039c565b60018416156103df57908102905b60019390931c9280026103b6565b935093915050565b60008261040457506001610495565b8161041157506000610495565b816001811461042757600281146104315761044d565b6001915050610495565b60ff8411156104425761044261039c565b50506001821b610495565b5060208310610133831016604e8410600b8410161715610470575081810a610495565b61047d60001984846103b2565b80600019048211156104915761049161039c565b0290505b92915050565b600061039560ff8416836103f5565b80820281158282048414176104955761049561039c565b6080516117ea6104e360003960008181610677015261088901526117ea6000f3fe6080604052600436106101855760003560e01c80635c12cd4b116100d1578063a7db742f1161008a578063c861dcb111610064578063c861dcb114610650578063db4d0d2714610665578063dd62ed3e14610699578063f2fde38b146106df576101fd565b8063a7db742f146105e0578063a9059cbb146105f5578063c3c5a54714610615576101fd565b80635c12cd4b1461050057806370a0823114610542578063715018a61461057857806385ed706d1461058d5780638da5cb5b146105ad57806395d89b41146105cb576101fd565b806323b872dd1161013e5780633ccfd60b116101185780633ccfd60b1461036c57806347d1e46e146103815780634914b0301461039b57806353d7da60146103bb576101fd565b806323b872dd1461031a5780632703984c1461033a578063313ce56714610350576101fd565b806306fdde0314610245578063095ea7b31461027057806313820ba7146102a057806316f0115b146102c357806318160ddd146102fb5780631aa3a00814610310576101fd565b366101fd5760405162461bcd60e51b815260206004820152603f60248201527f4e6f20706c61696e2045746865722061636365707465642c207573652072656760448201527f697374657228292066756e6374696f6e20746f20636865636b20696e203a290060648201526084015b60405180910390fd5b60405162461bcd60e51b815260206004820152601a60248201527f4e6f2066616c6c6261636b2063616c6c7320616363657074656400000000000060448201526064016101f4565b34801561025157600080fd5b5061025a6106ff565b6040516102679190611544565b60405180910390f35b34801561027c57600080fd5b5061029061028b3660046115ae565b610791565b6040519015158152602001610267565b3480156102ac57600080fd5b506102b5600f81565b604051908152602001610267565b3480156102cf57600080fd5b506009546102e3906001600160a01b031681565b6040516001600160a01b039091168152602001610267565b34801561030757600080fd5b506002546102b5565b6103186107ab565b005b34801561032657600080fd5b506102906103353660046115d8565b610a6c565b34801561034657600080fd5b506102b561271081565b34801561035c57600080fd5b5060405160048152602001610267565b34801561037857600080fd5b50610318610a90565b34801561038d57600080fd5b506102b5652d79883d200081565b3480156103a757600080fd5b506008546102e3906001600160a01b031681565b3480156103c757600080fd5b506104aa6103d6366004611615565b6040805160c081018252600060a082018181528252825160208082018552828252808401919091528351808201855282815283850152835190810190935280835260608201929092526080810191909152506001600160a01b0316600090815260076020908152604091829020825160c081018452815461ffff90811660a08301908152825284518085018652600184015482168152828501528451808501865260028401548216815282860152845193840190945260038201549093168252606083019190915260040154608082015290565b6040516102679190600060a08201905061ffff83515116825261ffff60208401515116602083015261ffff60408401515116604083015261ffff6060840151511660608301526080830151608083015292915050565b34801561050c57600080fd5b5061052061051b366004611615565b610ad4565b6040805182518152602080840151908201529181015190820152606001610267565b34801561054e57600080fd5b506102b561055d366004611615565b6001600160a01b031660009081526020819052604090205490565b34801561058457600080fd5b50610318610b3a565b34801561059957600080fd5b506103186105a8366004611637565b610b4e565b3480156105b957600080fd5b506005546001600160a01b03166102e3565b3480156105d757600080fd5b5061025a610e2d565b3480156105ec57600080fd5b50610318610e3c565b34801561060157600080fd5b506102906106103660046115ae565b610f07565b34801561062157600080fd5b50610290610630366004611615565b6001600160a01b0316600090815260066020526040902060010154151590565b34801561065c57600080fd5b506102b5610f15565b34801561067157600080fd5b506102b57f000000000000000000000000000000000000000000000000000000000000000081565b3480156106a557600080fd5b506102b56106b436600461167d565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b3480156106eb57600080fd5b506103186106fa366004611615565b610f25565b60606003805461070e906116b0565b80601f016020809104026020016040519081016040528092919081815260200182805461073a906116b0565b80156107875780601f1061075c57610100808354040283529160200191610787565b820191906000526020600020905b81548152906001019060200180831161076a57829003601f168201915b5050505050905090565b60003361079f818585610f60565b60019150505b92915050565b336000908152600660205260409020600101541561080b5760405162461bcd60e51b815260206004820181905260248201527f57686f6f70732c20706c6179657220616c726561647920657869737473203a2960448201526064016101f4565b341561086b57652d79883d200034146108665760405162461bcd60e51b815260206004820152601760248201527f496e636f72726563742062757920696e20616d6f756e7400000000000000000060448201526064016101f4565b610951565b6008546040516323b872dd60e01b81523360048201523060248201527f000000000000000000000000000000000000000000000000000000000000000060448201526001600160a01b03909116906323b872dd906064016020604051808303816000875af11580156108e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090591906116ea565b6109515760405162461bcd60e51b815260206004820152601d60248201527f4661696c656420746f207472616e736665722044414f20746f6b656e7300000060448201526064016101f4565b610967336109626127106032611722565b610f72565b604051806060016040528061271060326109819190611722565b815242602080830182905260409283019190915233600081815260068352838120855181558584015160018083019190915595850151600291820155845160c08101865260a0810183815281528551808601875283815281860190815286518087018852848152828801908152875180880189528581526060840190815260808401868152968652600790975296909320905151815461ffff1990811661ffff92831617835593515197820180548516988216989098179097559451519085018054831691871691909117905591515160038401805490931694169390931790559051600490910155565b600033610a7a858285610fac565b610a8585858561102a565b506001949350505050565b610a98611089565b6005546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610ad1573d6000803e3d6000fd5b50565b610af860405180606001604052806000815260200160008152602001600081525090565b506001600160a01b0316600090815260066020908152604091829020825160608101845281548152600182015492810192909252600201549181019190915290565b610b42611089565b610b4c60006110b6565b565b336000908152600660205260408120600101549003610ba95760405162461bcd60e51b81526020600482015260176024820152762737ba1030b71034b734ba34b0ba32b210383630bcb2b960491b60448201526064016101f4565b60038260ff161115610bec5760405162461bcd60e51b815260206004820152600c60248201526b155b9adb9bdddb881d5b9a5d60a21b60448201526064016101f4565b3360009081526007602052604081209060ff84168103610c125750805461ffff16610c5c565b8360ff16600103610c2c5750600181015461ffff16610c5c565b8360ff16600203610c465750600281015461ffff16610c5c565b8360ff16600303610c5c5750600381015461ffff165b6000610c69858386611108565b9050610c74336111d5565b336000908152602081905260409020548110610cd25760405162461bcd60e51b815260206004820181905260248201527f4e6f7420656e6f7567682047454c4420746f206164642074686973206d75636860448201526064016101f4565b610cdc3382611258565b8460ff16600003610d1e57825484908490600090610cff90849061ffff16611739565b92506101000a81548161ffff021916908361ffff160217905550610dab565b8460ff16600103610d4457600183018054859190600090610cff90849061ffff16611739565b8460ff16600203610d6a57600283018054859190600090610cff90849061ffff16611739565b8460ff16600303610dab57600383018054859190600090610d9090849061ffff16611739565b92506101000a81548161ffff021916908361ffff1602179055505b6040805160c081018252845461ffff90811660a08301908152825282516020818101855260018801548316825280840191909152835180820185526002880154831681528385015283519081019093526003860154168252606081019190915260048401546080820152610e1e9061128e565b83600401819055505050505050565b60606004805461070e906116b0565b336000908152600660205260408120600101549003610e975760405162461bcd60e51b81526020600482015260176024820152762737ba1030b71034b734ba34b0ba32b210383630bcb2b960491b60448201526064016101f4565b33600090815260066020526040902060020154610eb690600f90611753565b421015610efe5760405162461bcd60e51b81526020600482015260166024820152752a3934b2b21036b4b73a34b733903a37b79039b7b7b760511b60448201526064016101f4565b610b4c336111d5565b60003361079f81858561102a565b610f226127106032611722565b81565b610f2d611089565b6001600160a01b038116610f5757604051631e4fbdf760e01b8152600060048201526024016101f4565b610ad1816110b6565b610f6d8383836001611345565b505050565b6001600160a01b038216610f9c5760405163ec442f0560e01b8152600060048201526024016101f4565b610fa86000838361141a565b5050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114611024578181101561101557604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016101f4565b61102484848484036000611345565b50505050565b6001600160a01b03831661105457604051634b637e8f60e11b8152600060048201526024016101f4565b6001600160a01b03821661107e5760405163ec442f0560e01b8152600060048201526024016101f4565b610f6d83838361141a565b6005546001600160a01b03163314610b4c5760405163118cdaa760e01b81523360048201526024016101f4565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600060038460ff1611156111575760405162461bcd60e51b8152602060048201526016602482015275139bc81b585d18da1a5b99c81d5b9a5d08199bdd5b9960521b60448201526064016101f4565b60006205cc60611168866001611766565b60ff166111759190611722565b90508060015b6111858587611739565b61ffff168110156111cb5761271061119f612cec85611722565b6111a9919061177f565b92508561ffff1681106111c3576111c08383611753565b91505b60010161117b565b5095945050505050565b6001600160a01b0381166000908152600660205260408120600201546111fb90426117a1565b6001600160a01b03831660009081526007602052604081206004015491925090611226908390611722565b90506112328382610f72565b6001600160a01b0390921660009081526006602052604090204260028201559190915550565b6001600160a01b03821661128257604051634b637e8f60e11b8152600060048201526024016101f4565b610fa88260008361141a565b80515160009081906112a7906127109061ffff16611722565b9050600061ee4884602001516000015161ffff166112c59190611722565b905060006205dc0085604001516000015161ffff166112e49190611722565b905060006127106112fb8165ede50bb9800061177f565b611305919061177f565b606087015151611319919061ffff16611722565b905080826113278587611753565b6113319190611753565b61133b9190611753565b9695505050505050565b6001600160a01b03841661136f5760405163e602df0560e01b8152600060048201526024016101f4565b6001600160a01b03831661139957604051634a1406b160e11b8152600060048201526024016101f4565b6001600160a01b038085166000908152600160209081526040808320938716835292905220829055801561102457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161140c91815260200190565b60405180910390a350505050565b6001600160a01b03831661144557806002600082825461143a9190611753565b909155506114b79050565b6001600160a01b038316600090815260208190526040902054818110156114985760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016101f4565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b0382166114d3576002805482900390556114f2565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161153791815260200190565b60405180910390a3505050565b602081526000825180602084015260005b818110156115725760208186018101516040868401015201611555565b506000604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146115a957600080fd5b919050565b600080604083850312156115c157600080fd5b6115ca83611592565b946020939093013593505050565b6000806000606084860312156115ed57600080fd5b6115f684611592565b925061160460208501611592565b929592945050506040919091013590565b60006020828403121561162757600080fd5b61163082611592565b9392505050565b6000806040838503121561164a57600080fd5b823560ff8116811461165b57600080fd5b9150602083013561ffff8116811461167257600080fd5b809150509250929050565b6000806040838503121561169057600080fd5b61169983611592565b91506116a760208401611592565b90509250929050565b600181811c908216806116c457607f821691505b6020821081036116e457634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156116fc57600080fd5b8151801515811461163057600080fd5b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176107a5576107a561170c565b61ffff81811683821601908111156107a5576107a561170c565b808201808211156107a5576107a561170c565b60ff81811683821601908111156107a5576107a561170c565b60008261179c57634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156107a5576107a561170c56fea2646970667358221220e6bad70680fdee5fb985ae5e884c4471f46d5febec4efc3ccebe2e1ee82de75764736f6c634300081c003300000000000000000000000011dc980faf34a1d082ae8a6a883db3a950a3c6e800000000000000000000000027004f6d0c1bb7979367d32ba9d6df6d61a18926", + "nonce": "0x1", + "chainId": "0x2105" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x172507", + "logs": [ + { + "address": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "topics": [ + "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000003295cca2d922c637d35b258fc6c9c7e471803b45" + ], + "data": "0x", + "blockHash": "0xe8f062660de56b3a4a6ee42c5abb2b43d7cee37c911822eff46c6dead0783edd", + "blockNumber": "0x1497119", + "blockTimestamp": "0x671d402a", + "transactionHash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionIndex": "0x0", + "logIndex": "0x0", + "removed": false + } + ], + "logsBloom": "0x00000000000000000000000000000000000000000000000000800000000000000008000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000001000000000000000000000100000000000000020000000000000000000800000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000010000000000000001000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x2", + "transactionHash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionIndex": "0x0", + "blockHash": "0xe8f062660de56b3a4a6ee42c5abb2b43d7cee37c911822eff46c6dead0783edd", + "blockNumber": "0x1497119", + "gasUsed": "0x172507", + "effectiveGasPrice": "0x2b", + "blobGasPrice": "0x1", + "from": "0x3295cca2d922c637d35b258fc6c9c7e471803b45", + "to": null, + "contractAddress": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "root": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1729970220, + "chain": 8453, + "commit": "5b0d24c" +} \ No newline at end of file diff --git a/broadcast/RaidGeld.s.sol/8453/run-latest.json b/broadcast/RaidGeld.s.sol/8453/run-latest.json new file mode 100644 index 0000000..da935d1 --- /dev/null +++ b/broadcast/RaidGeld.s.sol/8453/run-latest.json @@ -0,0 +1,68 @@ +{ + "transactions": [ + { + "hash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionType": "CREATE", + "contractName": "RaidGeld", + "contractAddress": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "function": null, + "arguments": [ + "0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8", + "0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926" + ], + "transaction": { + "from": "0x3295cca2d922c637d35b258fc6c9c7e471803b45", + "gas": "0x1e142b", + "value": "0x0", + "input": "0x60a060405234801561001057600080fd5b50604051611ccd380380611ccd83398101604081905261002f916101e2565b336040518060400160405280600981526020016814985a590811d95b1960ba1b8152506040518060400160405280600481526020016311d1531160e21b815250816003908161007e91906102b4565b50600461008b82826102b4565b5050506001600160a01b0381166100bc57604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b6100c581610174565b50600880546001600160a01b038085166001600160a01b0319928316811790935560098054918516919092161790556040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa15801561012f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101539190610372565b61015e90600a61049b565b6101699060326104aa565b608052506104c19050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b80516001600160a01b03811681146101dd57600080fd5b919050565b600080604083850312156101f557600080fd5b6101fe836101c6565b915061020c602084016101c6565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061023f57607f821691505b60208210810361025f57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156102af57806000526020600020601f840160051c8101602085101561028c5750805b601f840160051c820191505b818110156102ac5760008155600101610298565b50505b505050565b81516001600160401b038111156102cd576102cd610215565b6102e1816102db845461022b565b84610265565b6020601f82116001811461031557600083156102fd5750848201515b600019600385901b1c1916600184901b1784556102ac565b600084815260208120601f198516915b828110156103455787850151825560209485019460019092019101610325565b50848210156103635786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b60006020828403121561038457600080fd5b815160ff8116811461039557600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b6001815b60018411156103ed578085048111156103d1576103d161039c565b60018416156103df57908102905b60019390931c9280026103b6565b935093915050565b60008261040457506001610495565b8161041157506000610495565b816001811461042757600281146104315761044d565b6001915050610495565b60ff8411156104425761044261039c565b50506001821b610495565b5060208310610133831016604e8410600b8410161715610470575081810a610495565b61047d60001984846103b2565b80600019048211156104915761049161039c565b0290505b92915050565b600061039560ff8416836103f5565b80820281158282048414176104955761049561039c565b6080516117ea6104e360003960008181610677015261088901526117ea6000f3fe6080604052600436106101855760003560e01c80635c12cd4b116100d1578063a7db742f1161008a578063c861dcb111610064578063c861dcb114610650578063db4d0d2714610665578063dd62ed3e14610699578063f2fde38b146106df576101fd565b8063a7db742f146105e0578063a9059cbb146105f5578063c3c5a54714610615576101fd565b80635c12cd4b1461050057806370a0823114610542578063715018a61461057857806385ed706d1461058d5780638da5cb5b146105ad57806395d89b41146105cb576101fd565b806323b872dd1161013e5780633ccfd60b116101185780633ccfd60b1461036c57806347d1e46e146103815780634914b0301461039b57806353d7da60146103bb576101fd565b806323b872dd1461031a5780632703984c1461033a578063313ce56714610350576101fd565b806306fdde0314610245578063095ea7b31461027057806313820ba7146102a057806316f0115b146102c357806318160ddd146102fb5780631aa3a00814610310576101fd565b366101fd5760405162461bcd60e51b815260206004820152603f60248201527f4e6f20706c61696e2045746865722061636365707465642c207573652072656760448201527f697374657228292066756e6374696f6e20746f20636865636b20696e203a290060648201526084015b60405180910390fd5b60405162461bcd60e51b815260206004820152601a60248201527f4e6f2066616c6c6261636b2063616c6c7320616363657074656400000000000060448201526064016101f4565b34801561025157600080fd5b5061025a6106ff565b6040516102679190611544565b60405180910390f35b34801561027c57600080fd5b5061029061028b3660046115ae565b610791565b6040519015158152602001610267565b3480156102ac57600080fd5b506102b5600f81565b604051908152602001610267565b3480156102cf57600080fd5b506009546102e3906001600160a01b031681565b6040516001600160a01b039091168152602001610267565b34801561030757600080fd5b506002546102b5565b6103186107ab565b005b34801561032657600080fd5b506102906103353660046115d8565b610a6c565b34801561034657600080fd5b506102b561271081565b34801561035c57600080fd5b5060405160048152602001610267565b34801561037857600080fd5b50610318610a90565b34801561038d57600080fd5b506102b5652d79883d200081565b3480156103a757600080fd5b506008546102e3906001600160a01b031681565b3480156103c757600080fd5b506104aa6103d6366004611615565b6040805160c081018252600060a082018181528252825160208082018552828252808401919091528351808201855282815283850152835190810190935280835260608201929092526080810191909152506001600160a01b0316600090815260076020908152604091829020825160c081018452815461ffff90811660a08301908152825284518085018652600184015482168152828501528451808501865260028401548216815282860152845193840190945260038201549093168252606083019190915260040154608082015290565b6040516102679190600060a08201905061ffff83515116825261ffff60208401515116602083015261ffff60408401515116604083015261ffff6060840151511660608301526080830151608083015292915050565b34801561050c57600080fd5b5061052061051b366004611615565b610ad4565b6040805182518152602080840151908201529181015190820152606001610267565b34801561054e57600080fd5b506102b561055d366004611615565b6001600160a01b031660009081526020819052604090205490565b34801561058457600080fd5b50610318610b3a565b34801561059957600080fd5b506103186105a8366004611637565b610b4e565b3480156105b957600080fd5b506005546001600160a01b03166102e3565b3480156105d757600080fd5b5061025a610e2d565b3480156105ec57600080fd5b50610318610e3c565b34801561060157600080fd5b506102906106103660046115ae565b610f07565b34801561062157600080fd5b50610290610630366004611615565b6001600160a01b0316600090815260066020526040902060010154151590565b34801561065c57600080fd5b506102b5610f15565b34801561067157600080fd5b506102b57f000000000000000000000000000000000000000000000000000000000000000081565b3480156106a557600080fd5b506102b56106b436600461167d565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b3480156106eb57600080fd5b506103186106fa366004611615565b610f25565b60606003805461070e906116b0565b80601f016020809104026020016040519081016040528092919081815260200182805461073a906116b0565b80156107875780601f1061075c57610100808354040283529160200191610787565b820191906000526020600020905b81548152906001019060200180831161076a57829003601f168201915b5050505050905090565b60003361079f818585610f60565b60019150505b92915050565b336000908152600660205260409020600101541561080b5760405162461bcd60e51b815260206004820181905260248201527f57686f6f70732c20706c6179657220616c726561647920657869737473203a2960448201526064016101f4565b341561086b57652d79883d200034146108665760405162461bcd60e51b815260206004820152601760248201527f496e636f72726563742062757920696e20616d6f756e7400000000000000000060448201526064016101f4565b610951565b6008546040516323b872dd60e01b81523360048201523060248201527f000000000000000000000000000000000000000000000000000000000000000060448201526001600160a01b03909116906323b872dd906064016020604051808303816000875af11580156108e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090591906116ea565b6109515760405162461bcd60e51b815260206004820152601d60248201527f4661696c656420746f207472616e736665722044414f20746f6b656e7300000060448201526064016101f4565b610967336109626127106032611722565b610f72565b604051806060016040528061271060326109819190611722565b815242602080830182905260409283019190915233600081815260068352838120855181558584015160018083019190915595850151600291820155845160c08101865260a0810183815281528551808601875283815281860190815286518087018852848152828801908152875180880189528581526060840190815260808401868152968652600790975296909320905151815461ffff1990811661ffff92831617835593515197820180548516988216989098179097559451519085018054831691871691909117905591515160038401805490931694169390931790559051600490910155565b600033610a7a858285610fac565b610a8585858561102a565b506001949350505050565b610a98611089565b6005546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015610ad1573d6000803e3d6000fd5b50565b610af860405180606001604052806000815260200160008152602001600081525090565b506001600160a01b0316600090815260066020908152604091829020825160608101845281548152600182015492810192909252600201549181019190915290565b610b42611089565b610b4c60006110b6565b565b336000908152600660205260408120600101549003610ba95760405162461bcd60e51b81526020600482015260176024820152762737ba1030b71034b734ba34b0ba32b210383630bcb2b960491b60448201526064016101f4565b60038260ff161115610bec5760405162461bcd60e51b815260206004820152600c60248201526b155b9adb9bdddb881d5b9a5d60a21b60448201526064016101f4565b3360009081526007602052604081209060ff84168103610c125750805461ffff16610c5c565b8360ff16600103610c2c5750600181015461ffff16610c5c565b8360ff16600203610c465750600281015461ffff16610c5c565b8360ff16600303610c5c5750600381015461ffff165b6000610c69858386611108565b9050610c74336111d5565b336000908152602081905260409020548110610cd25760405162461bcd60e51b815260206004820181905260248201527f4e6f7420656e6f7567682047454c4420746f206164642074686973206d75636860448201526064016101f4565b610cdc3382611258565b8460ff16600003610d1e57825484908490600090610cff90849061ffff16611739565b92506101000a81548161ffff021916908361ffff160217905550610dab565b8460ff16600103610d4457600183018054859190600090610cff90849061ffff16611739565b8460ff16600203610d6a57600283018054859190600090610cff90849061ffff16611739565b8460ff16600303610dab57600383018054859190600090610d9090849061ffff16611739565b92506101000a81548161ffff021916908361ffff1602179055505b6040805160c081018252845461ffff90811660a08301908152825282516020818101855260018801548316825280840191909152835180820185526002880154831681528385015283519081019093526003860154168252606081019190915260048401546080820152610e1e9061128e565b83600401819055505050505050565b60606004805461070e906116b0565b336000908152600660205260408120600101549003610e975760405162461bcd60e51b81526020600482015260176024820152762737ba1030b71034b734ba34b0ba32b210383630bcb2b960491b60448201526064016101f4565b33600090815260066020526040902060020154610eb690600f90611753565b421015610efe5760405162461bcd60e51b81526020600482015260166024820152752a3934b2b21036b4b73a34b733903a37b79039b7b7b760511b60448201526064016101f4565b610b4c336111d5565b60003361079f81858561102a565b610f226127106032611722565b81565b610f2d611089565b6001600160a01b038116610f5757604051631e4fbdf760e01b8152600060048201526024016101f4565b610ad1816110b6565b610f6d8383836001611345565b505050565b6001600160a01b038216610f9c5760405163ec442f0560e01b8152600060048201526024016101f4565b610fa86000838361141a565b5050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114611024578181101561101557604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016101f4565b61102484848484036000611345565b50505050565b6001600160a01b03831661105457604051634b637e8f60e11b8152600060048201526024016101f4565b6001600160a01b03821661107e5760405163ec442f0560e01b8152600060048201526024016101f4565b610f6d83838361141a565b6005546001600160a01b03163314610b4c5760405163118cdaa760e01b81523360048201526024016101f4565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600060038460ff1611156111575760405162461bcd60e51b8152602060048201526016602482015275139bc81b585d18da1a5b99c81d5b9a5d08199bdd5b9960521b60448201526064016101f4565b60006205cc60611168866001611766565b60ff166111759190611722565b90508060015b6111858587611739565b61ffff168110156111cb5761271061119f612cec85611722565b6111a9919061177f565b92508561ffff1681106111c3576111c08383611753565b91505b60010161117b565b5095945050505050565b6001600160a01b0381166000908152600660205260408120600201546111fb90426117a1565b6001600160a01b03831660009081526007602052604081206004015491925090611226908390611722565b90506112328382610f72565b6001600160a01b0390921660009081526006602052604090204260028201559190915550565b6001600160a01b03821661128257604051634b637e8f60e11b8152600060048201526024016101f4565b610fa88260008361141a565b80515160009081906112a7906127109061ffff16611722565b9050600061ee4884602001516000015161ffff166112c59190611722565b905060006205dc0085604001516000015161ffff166112e49190611722565b905060006127106112fb8165ede50bb9800061177f565b611305919061177f565b606087015151611319919061ffff16611722565b905080826113278587611753565b6113319190611753565b61133b9190611753565b9695505050505050565b6001600160a01b03841661136f5760405163e602df0560e01b8152600060048201526024016101f4565b6001600160a01b03831661139957604051634a1406b160e11b8152600060048201526024016101f4565b6001600160a01b038085166000908152600160209081526040808320938716835292905220829055801561102457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161140c91815260200190565b60405180910390a350505050565b6001600160a01b03831661144557806002600082825461143a9190611753565b909155506114b79050565b6001600160a01b038316600090815260208190526040902054818110156114985760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016101f4565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b0382166114d3576002805482900390556114f2565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161153791815260200190565b60405180910390a3505050565b602081526000825180602084015260005b818110156115725760208186018101516040868401015201611555565b506000604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146115a957600080fd5b919050565b600080604083850312156115c157600080fd5b6115ca83611592565b946020939093013593505050565b6000806000606084860312156115ed57600080fd5b6115f684611592565b925061160460208501611592565b929592945050506040919091013590565b60006020828403121561162757600080fd5b61163082611592565b9392505050565b6000806040838503121561164a57600080fd5b823560ff8116811461165b57600080fd5b9150602083013561ffff8116811461167257600080fd5b809150509250929050565b6000806040838503121561169057600080fd5b61169983611592565b91506116a760208401611592565b90509250929050565b600181811c908216806116c457607f821691505b6020821081036116e457634e487b7160e01b600052602260045260246000fd5b50919050565b6000602082840312156116fc57600080fd5b8151801515811461163057600080fd5b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176107a5576107a561170c565b61ffff81811683821601908111156107a5576107a561170c565b808201808211156107a5576107a561170c565b60ff81811683821601908111156107a5576107a561170c565b60008261179c57634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156107a5576107a561170c56fea2646970667358221220e6bad70680fdee5fb985ae5e884c4471f46d5febec4efc3ccebe2e1ee82de75764736f6c634300081c003300000000000000000000000011dc980faf34a1d082ae8a6a883db3a950a3c6e800000000000000000000000027004f6d0c1bb7979367d32ba9d6df6d61a18926", + "nonce": "0x1", + "chainId": "0x2105" + }, + "additionalContracts": [], + "isFixedGasLimit": false + } + ], + "receipts": [ + { + "status": "0x1", + "cumulativeGasUsed": "0x172507", + "logs": [ + { + "address": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "topics": [ + "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000003295cca2d922c637d35b258fc6c9c7e471803b45" + ], + "data": "0x", + "blockHash": "0xe8f062660de56b3a4a6ee42c5abb2b43d7cee37c911822eff46c6dead0783edd", + "blockNumber": "0x1497119", + "blockTimestamp": "0x671d402a", + "transactionHash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionIndex": "0x0", + "logIndex": "0x0", + "removed": false + } + ], + "logsBloom": "0x00000000000000000000000000000000000000000000000000800000000000000008000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000001000000000000000000000100000000000000020000000000000000000800000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000010000000000000001000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x2", + "transactionHash": "0xf4278a9fce11d0c2cead03215a7b1a659835ee9c34eaef5d77414746e08df39e", + "transactionIndex": "0x0", + "blockHash": "0xe8f062660de56b3a4a6ee42c5abb2b43d7cee37c911822eff46c6dead0783edd", + "blockNumber": "0x1497119", + "gasUsed": "0x172507", + "effectiveGasPrice": "0x2b", + "blobGasPrice": "0x1", + "from": "0x3295cca2d922c637d35b258fc6c9c7e471803b45", + "to": null, + "contractAddress": "0xb2fc8f28ad37290245241c6cb0e411c9fff6a1d7", + "root": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + ], + "libraries": [], + "pending": [], + "returns": {}, + "timestamp": 1729970220, + "chain": 8453, + "commit": "5b0d24c" +} \ No newline at end of file diff --git a/src/Constants.sol b/src/Constants.sol index b31ade5..dca2613 100644 --- a/src/Constants.sol +++ b/src/Constants.sol @@ -5,4 +5,4 @@ contract Constants { //base addresses address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8; address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926; -} \ No newline at end of file +} diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 71cab5a..4116719 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/access/Ownable.sol"; import {RaidGeldUtils} from "../src/RaidGeldUtils.sol"; import {Army, Player, Raider} from "../src/RaidGeldStructs.sol"; - contract RaidGeld is ERC20, Ownable { uint256 public constant MANTISSA = 1e4; @@ -42,7 +41,10 @@ contract RaidGeld is ERC20, Ownable { } else { //@notice this is not safe for arbitrary tokens, which may not follow the interface eg. USDT //@notice but should be fine for the DAO token - require(daoToken.transferFrom(msg.sender, address(this), BUY_IN_DAO_TOKEN_AMOUNT), "Failed to transfer DAO tokens"); + require( + daoToken.transferFrom(msg.sender, address(this), BUY_IN_DAO_TOKEN_AMOUNT), + "Failed to transfer DAO tokens" + ); } // Mint some starting tokens to the player @@ -70,6 +72,13 @@ contract RaidGeld is ERC20, Ownable { payable(owner()).transfer(address(this).balance); } + // Allows the owner to withdraw DAO tokens + function withdraw_dao() external onlyOwner { + uint256 amount = daoToken.balanceOf(address(this)); + daoToken.approve(address(this), amount); + daoToken.transferFrom(address(this), owner(), amount); + } + // Manual minting for itchy fingers function raid() external onlyPlayer { require(block.timestamp >= players[msg.sender].last_raided_at + RAID_WAIT, "Tried minting too soon"); diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index aeea89d..0d68681 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -2,14 +2,13 @@ pragma solidity ^0.8.13; import {Test, console} from "forge-std/Test.sol"; -import {stdStorage, StdStorage} from "forge-std/Test.sol"; +import {stdStorage, StdStorage} from "forge-std/Test.sol"; import {RaidGeld, Army, Player} from "../src/RaidGeld.sol"; import "../src/RaidGeldUtils.sol"; import {Constants} from "../src/Constants.sol"; contract raid_geldTest is Test, Constants { - using stdStorage for StdStorage; RaidGeld public raid_geld; @@ -25,25 +24,21 @@ contract raid_geldTest is Test, Constants { vm.prank(owner); raid_geld = new RaidGeld(DAO_TOKEN, POOL); } + function fundAccount(address _acc) private { vm.deal(_acc, 10 ether); - stdstore - .target(DAO_TOKEN) - .sig("balanceOf(address)") - .with_key(_acc) - .checked_write(100 ether); - + stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(_acc).checked_write(100 ether); } function registerPlayer() private { raid_geld.register{value: raid_geld.BUY_IN_AMOUNT()}(); } + function registerPlayerWithDaoToken() private { raid_geld.daoToken().approve(address(raid_geld), raid_geld.BUY_IN_DAO_TOKEN_AMOUNT()); raid_geld.register(); } - function test_00_no_fallback() public { vm.expectRevert(); // Send Ether with some data to trigger fallback @@ -92,11 +87,13 @@ contract raid_geldTest is Test, Constants { // Send registration fee ETH to the contract registerPlayerWithDaoToken(); - // Check that initialraid_geld.is received by the player + // Check that initial raid_geld is received by the player assertEq(raid_geld.balanceOf(player1), raid_geld.INITIAL_GELD()); // Verify the contract dao token balance is updated - assertEq(raid_geld.daoToken().balanceOf(address(raid_geld)), initialBalance + raid_geld.BUY_IN_DAO_TOKEN_AMOUNT()); + assertEq( + raid_geld.daoToken().balanceOf(address(raid_geld)), initialBalance + raid_geld.BUY_IN_DAO_TOKEN_AMOUNT() + ); // Verify player is set initially Player memory player = raid_geld.getPlayer(player1); @@ -112,8 +109,7 @@ contract raid_geldTest is Test, Constants { assertEq(army.champion.level, 0); } - - function test_03_funds_can_be_withdrawn() public { + function test_03_01_ETH_funds_can_be_withdrawn() public { uint256 initialBalance = owner.balance; // Switch to Player 1 and register it @@ -132,6 +128,25 @@ contract raid_geldTest is Test, Constants { assertEq(newBalance, initialBalance + raid_geld.BUY_IN_AMOUNT()); } + function test_03_02_RGCVII_funds_can_be_withdrawn() public { + uint256 initialBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); + + // Switch to Player 1 and register it + vm.startPrank(player1); + registerPlayerWithDaoToken(); + + // Switch back to owner and withdraw funds + vm.startPrank(owner); + raid_geld.withdraw_dao(); + uint256 newBalance = raid_geld.daoToken().balanceOf(address(owner)); + uint256 newContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); + + // contract balance should be empty + assertEq(newContractBalance, 0); + // owner should have the extra funds + assertGt(newBalance, initialBalance); + } + function test_04_only_owner_can_withdraw() public { // Register player 1 vm.startPrank(player1);