Skip to content

Commit

Permalink
Add temporary functions to add data
Browse files Browse the repository at this point in the history
  • Loading branch information
valar999 committed Jul 13, 2024
1 parent f8943ab commit 89bd6cc
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions contracts/src/Wingman.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import { ERC7579ValidatorBase } from "modulekit/Modules.sol";
import { PackedUserOperation } from "modulekit/external/ERC4337.sol";

contract Wingman is ERC7579ValidatorBase {
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS & STORAGE
//////////////////////////////////////////////////////////////////////////*/
mapping(address => string[]) public backupNames;
mapping(address => mapping(string => Backup)) public backups;

/*//////////////////////////////////////////////////////////////////////////
CONFIG
//////////////////////////////////////////////////////////////////////////*/
struct Backup {
uint48 createdAt;
uint48 initiatedAt;
uint48 expiresAt;
Beneficiary[] beneficiaries;
}

struct Beneficiary {
address account;
uint8 percentage;
uint256 amount;
}

/**
* Initialize the module with the given data
Expand All @@ -35,10 +43,6 @@ contract Wingman is ERC7579ValidatorBase {
*/
function isInitialized(address smartAccount) external view returns (bool) { }

/*//////////////////////////////////////////////////////////////////////////
MODULE LOGIC
//////////////////////////////////////////////////////////////////////////*/

/**
* Validates PackedUserOperation
*
Expand Down Expand Up @@ -88,13 +92,33 @@ contract Wingman is ERC7579ValidatorBase {
return EIP1271_FAILED;
}

/*//////////////////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////////////////*/
function createBackup(
string memory name,
uint48 expiresAt
) public {
Backup storage backup = backups[msg.sender][name];
backupNames[msg.sender].push(name);
backup.createdAt = uint48(block.timestamp);
backup.initiatedAt = uint48(block.timestamp);
backup.expiresAt = expiresAt;
}

function addBeneficiary(
string calldata name,
address account,
uint8 percentage
) public {
Backup storage backup = backups[msg.sender][name];
backup.beneficiaries.push(Beneficiary(account, percentage, 0));
}

/*//////////////////////////////////////////////////////////////////////////
METADATA
//////////////////////////////////////////////////////////////////////////*/
function getBackups() public view returns (string[] memory) {
return backupNames[msg.sender];
}

function getBackup(string calldata name) public view returns (Backup memory) {
return backups[msg.sender][name];
}

/**
* The name of the module
Expand Down

0 comments on commit 89bd6cc

Please sign in to comment.