Skip to content

Commit

Permalink
implemented RedeemHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
roleengineer committed Dec 13, 2024
1 parent cc409d9 commit eb90bcc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ libs = ["lib"]
gnosis = "${GNOSIS_RPC}"

[etherscan]
gnoscan = { key = "${GNOSIS_SCAN_KEY}" }
gnosisscan = { key = "${GNOSIS_SCAN_KEY}", chain = 100 }

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
21 changes: 21 additions & 0 deletions script/DeployRedeemHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.28;

import {Script, console} from "forge-std/Script.sol";
import {RedeemHelper} from "src/helpers/RedeemHelper.sol";

contract DeployRedeemHelper is Script {
address deployer = address(0x6BF173798733623cc6c221eD52c010472247d861);
RedeemHelper public redeemHelper; // 0x8D46BA60Bf0c4A93d21dc1Db8F230Bdf1E7764A3

function setUp() public {}

function run() public {
vm.startBroadcast(deployer);

redeemHelper = new RedeemHelper();

vm.stopBroadcast();
console.log(address(redeemHelper), "RedeemHelper");
}
}
21 changes: 21 additions & 0 deletions src/helpers/RedeemHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.28;

import {TypeDefinitions} from "circles-contracts-v2/hub/TypeDefinitions.sol";
import {BaseMintPolicyDefinitions} from "circles-contracts-v2/groups/Definitions.sol";

contract RedeemHelper {
bytes32 public constant METADATATYPE_GROUPREDEEM = keccak256("CIRCLESv2:RESERVED_DATA:CirclesGroupRedeem");

/// @notice Converts the user's redemption values, including avatars and amounts, into a byte format suitable for use in a safeTransferFrom call.
function convertRedemptionToBytes(uint256[] memory redemptionIds, uint256[] memory redemptionValues)
external
pure
returns (bytes memory data)
{
bytes memory userData =
abi.encode(BaseMintPolicyDefinitions.BaseRedemptionPolicy(redemptionIds, redemptionValues));

data = abi.encode(TypeDefinitions.Metadata(METADATATYPE_GROUPREDEEM, "", userData));
}
}
11 changes: 6 additions & 5 deletions test/DepositFlow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {CirclesType} from "circles-contracts-v2/lift/IERC20Lift.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {TypeDefinitions} from "circles-contracts-v2/hub/TypeDefinitions.sol";
import {BaseMintPolicyDefinitions} from "circles-contracts-v2/groups/Definitions.sol";
import {RedeemHelper} from "src/helpers/RedeemHelper.sol";

contract DepositFlowTest is Test {
uint256 blockNumber = 37_456_676;
Expand All @@ -34,6 +35,8 @@ contract DepositFlowTest is Test {
Safe testGroupSafe = Safe(payable(address(0x8bD2e75661Af98037b1Fc9fa0f9435baAa6Dd5ac)));
address proxy;
address testAccount = address(0x2A6878e8e34647533C5AA46012008ABfdF496988);
// helper
RedeemHelper public redeemHelper;

function setUp() public {
gnosis = vm.createFork(vm.envString("GNOSIS_RPC"), blockNumber);
Expand All @@ -60,6 +63,8 @@ contract DepositFlowTest is Test {
// 3. third setup step for a TestGroup is to registerGroup in Hub with proxy as a mint policy
data = abi.encodeWithSelector(Hub.registerGroup.selector, proxy, "testGroup", "TG", bytes32(0));
_executeSafeTx(testGroupSafe, address(hub), data, Enum.Operation.Call);

redeemHelper = new RedeemHelper();
}

function testDepositFlow() public {
Expand All @@ -74,11 +79,7 @@ contract DepositFlowTest is Test {
uint256[] memory redemptionValues = new uint256[](1);
redemptionValues[0] = 5 ether;

bytes memory userData =
abi.encode(BaseMintPolicyDefinitions.BaseRedemptionPolicy(redemptionIds, redemptionValues));

bytes memory data = abi.encode(TypeDefinitions.Metadata(METADATATYPE_GROUPREDEEM, "", userData));

bytes memory data = redeemHelper.convertRedemptionToBytes(redemptionIds, redemptionValues);
vm.prank(testAccount);
hub.safeTransferFrom(testAccount, STANDARD_TREASURY, uint256(uint160(address(testGroupSafe))), 5 ether, data);

Expand Down

0 comments on commit eb90bcc

Please sign in to comment.