-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19fa9ee
commit 4811a7a
Showing
4 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@poolzfinance/lockdeal-nft/contracts/mock/MockVaultManager.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
contract MockVaultManager { | ||
mapping(address => uint) public tokenToVaultId; | ||
mapping(uint256 => address) vaultIdtoToken; | ||
bool public transfers = true; | ||
uint256 public Id = 0; | ||
|
||
function safeDeposit(address _tokenAddress, uint _amount, address from, bytes memory signature) external returns (uint vaultId) { | ||
require(keccak256(abi.encodePacked(signature)) == keccak256(abi.encodePacked("signature")), "wrong signature"); | ||
IERC20(_tokenAddress).transferFrom(from, address(this), _amount); | ||
vaultId = _depositByToken(_tokenAddress); | ||
} | ||
|
||
function _depositByToken(address _tokenAddress) internal returns (uint vaultId) { | ||
vaultId = ++Id; | ||
vaultIdtoToken[vaultId] = _tokenAddress; | ||
tokenToVaultId[_tokenAddress] = vaultId; | ||
} | ||
|
||
function withdrawByVaultId(uint _vaultId, address _to, uint _amount) external { | ||
IERC20(vaultIdtoToken[_vaultId]).transfer(_to, _amount); | ||
} | ||
|
||
function vaultIdToTokenAddress(uint _vaultId) external view returns (address) { | ||
return vaultIdtoToken[_vaultId]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers" | ||
import { ethers } from "hardhat" | ||
|
||
export async function createSignature(signer: SignerWithAddress, data: any[]): Promise<string> { | ||
const types: string[] = [] | ||
const values: any[] = [] | ||
for (const element of data) { | ||
if (typeof element === "string") { | ||
types.push("address") | ||
values.push(element) | ||
} else if (typeof element === "object" && Array.isArray(element)) { | ||
types.push("uint256[]") | ||
values.push(element) | ||
} else if (typeof element === "number" || ethers.BigNumber.isBigNumber(element)) { | ||
types.push("uint256") | ||
values.push(element) | ||
} else if (typeof element === "object" && !Array.isArray(element)) { | ||
types.push("address") | ||
values.push(element.simpleProvider) | ||
types.push("uint256[]") | ||
values.push(element.params) | ||
} | ||
} | ||
const packedData = ethers.utils.solidityKeccak256(types, values) | ||
return signer.signMessage(ethers.utils.arrayify(packedData)) | ||
} |