diff --git a/deploy/001_deploy_simple_erc20.ts b/deploy/001_deploy_simple_erc20.ts index 7737f58..eb2bcc2 100644 --- a/deploy/001_deploy_simple_erc20.ts +++ b/deploy/001_deploy_simple_erc20.ts @@ -1,16 +1,16 @@ -import {HardhatRuntimeEnvironment} from 'hardhat/types'; -import {DeployFunction} from 'hardhat-deploy/types'; -import {parseEther} from 'ethers'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { parseEther } from 'ethers'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const {deployments, getNamedAccounts} = hre; - const {deploy} = deployments; + const { deployments, getNamedAccounts } = hre; + const { deploy } = deployments; - const {deployer, simpleERC20Beneficiary} = await getNamedAccounts(); + const { deployer, simpleERC20Beneficiary, simpleOffchainVerifier } = await getNamedAccounts(); await deploy('SimpleERC20', { from: deployer, - args: [simpleERC20Beneficiary, parseEther('1000000000')], + args: [simpleOffchainVerifier, parseEther('1000000000')], log: true, autoMine: true, // speed up deployment on local network (ganache, hardhat), no effect on live networks }); diff --git a/deploy/002_deploy_deramp_vault.ts b/deploy/002_deploy_deramp_vault.ts index 851e052..a05085e 100644 --- a/deploy/002_deploy_deramp_vault.ts +++ b/deploy/002_deploy_deramp_vault.ts @@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/types'; import { ethers } from 'hardhat'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const { deployer, simpleERC20Beneficiary } = await hre.getNamedAccounts(); + const { deployer, simpleOffchainVerifier } = await hre.getNamedAccounts(); const asset = await (await hre.ethers.getContract('SimpleERC20', deployer)).getAddress(); console.log('vault asset: ', asset); const { deploy } = hre.deployments; @@ -23,12 +23,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { execute: { init: { methodName: 'initialize', - args: [asset, 'DeRamp Token', 'RAMP', max, min, fee, simpleERC20Beneficiary], + args: [asset, 'DeRamp Token', 'RAMP', max, min, fee, simpleOffchainVerifier], }, onUpgrade: { methodName: 'postUpgrade', - args: [asset, 'DeRamp Token', 'RAMP', max, min, fee, simpleERC20Beneficiary], + args: [asset, 'DeRamp Token', 'RAMP', max, min, fee, simpleOffchainVerifier], }, }, }, diff --git a/hardhat.config.ts b/hardhat.config.ts index 971c37c..9f330fe 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,17 +1,18 @@ import 'dotenv/config'; -import {HardhatUserConfig} from 'hardhat/types'; +import { HardhatUserConfig } from 'hardhat/types'; import '@nomicfoundation/hardhat-chai-matchers'; import '@nomicfoundation/hardhat-ethers'; import '@typechain/hardhat'; import 'hardhat-gas-reporter'; import 'solidity-coverage'; +import '@nomicfoundation/hardhat-verify'; import 'hardhat-deploy'; import 'hardhat-deploy-ethers'; import 'hardhat-deploy-tenderly'; -import {node_url, accounts, addForkConfiguration} from './utils/network'; +import { node_url, accounts, addForkConfiguration } from './utils/network'; const config: HardhatUserConfig = { solidity: { @@ -32,6 +33,12 @@ const config: HardhatUserConfig = { simpleERC20Beneficiary: 1, onRamper: 2, offRamper: 3, + simpleOffchainVerifier: { + default: 4, + sepolia: '0x36e7Fda8CC503D5Ec7729A42eb86EF02Af315Bf9' + }, + + }, networks: addForkConfiguration({ hardhat: { @@ -82,19 +89,29 @@ const config: HardhatUserConfig = { }, external: process.env.HARDHAT_FORK ? { - deployments: { - // process.env.HARDHAT_FORK will specify the network that the fork is made from. - // these lines allow it to fetch the deployments from the network being forked from both for node and deploy task - hardhat: ['deployments/' + process.env.HARDHAT_FORK], - localhost: ['deployments/' + process.env.HARDHAT_FORK], - }, - } + deployments: { + // process.env.HARDHAT_FORK will specify the network that the fork is made from. + // these lines allow it to fetch the deployments from the network being forked from both for node and deploy task + hardhat: ['deployments/' + process.env.HARDHAT_FORK], + localhost: ['deployments/' + process.env.HARDHAT_FORK], + }, + } : undefined, tenderly: { project: 'template-ethereum-contracts', username: process.env.TENDERLY_USERNAME as string, }, + etherscan: { + // Your API key for Etherscan + // Obtain one at https://etherscan.io/ + apiKey: 'MSFGJM485PQKZ27XDN74RP5PKXAJYUWXSH', + }, + sourcify: { + // Disabled by default + // Doesn't need an API key + enabled: true, + }, }; export default config; diff --git a/package.json b/package.json index 6644bb7..6a06aab 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "solidity-coverage": "^0.8.6", "solmate": "github:transmissions11/solmate", "ts-node": "^10.9.2", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "@nomicfoundation/hardhat-verify": "^2.0.4" }, "scripts": { "prepare": "node ./.setup.js && hardhat typechain", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85c96e5..07bc518 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,9 @@ devDependencies: '@nomicfoundation/hardhat-ethers': specifier: ^3.0.5 version: 3.0.5(ethers@6.10.0)(hardhat@2.19.5) + '@nomicfoundation/hardhat-verify': + specifier: ^2.0.4 + version: 2.0.4(hardhat@2.19.5) '@openzeppelin/contracts': specifier: ^5.0.1 version: 5.0.1 @@ -733,6 +736,25 @@ packages: - supports-color dev: true + /@nomicfoundation/hardhat-verify@2.0.4(hardhat@2.19.5): + resolution: {integrity: sha512-B8ZjhOrmbbRWqJi65jvQblzjsfYktjqj2vmOm+oc2Vu8drZbT2cjeSCRHZKbS7lOtfW78aJZSFvw+zRLCiABJA==} + peerDependencies: + hardhat: ^2.0.4 + dependencies: + '@ethersproject/abi': 5.7.0 + '@ethersproject/address': 5.7.0 + cbor: 8.1.0 + chalk: 2.4.2 + debug: 4.3.4(supports-color@8.1.1) + hardhat: 2.19.5(ts-node@10.9.2)(typescript@5.3.3) + lodash.clonedeep: 4.5.0 + semver: 6.3.1 + table: 6.8.1 + undici: 5.28.3 + transitivePeerDependencies: + - supports-color + dev: true + /@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1: resolution: {integrity: sha512-KcTodaQw8ivDZyF+D76FokN/HdpgGpfjc/gFCImdLUyqB6eSWVaZPazMbeAjmfhx3R0zm/NYVzxwAokFKgrc0w==} engines: {node: '>= 10'} @@ -1185,6 +1207,15 @@ packages: indent-string: 4.0.0 dev: true + /ajv@8.12.0: + resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} + dependencies: + fast-deep-equal: 3.1.3 + json-schema-traverse: 1.0.0 + require-from-string: 2.0.2 + uri-js: 4.4.1 + dev: true + /amdefine@1.0.1: resolution: {integrity: sha512-S2Hw0TtNkMJhIabBwIojKL9YHO5T0n5eNqWJ7Lrlel/zDbftQpxpapi8tZs3X1HWa+u+QeydGmzzNU0m09+Rcg==} engines: {node: '>=0.4.2'} @@ -1293,6 +1324,11 @@ packages: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true + /astral-regex@2.0.0: + resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} + engines: {node: '>=8'} + dev: true + /async@1.5.2: resolution: {integrity: sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==} dev: true @@ -1499,6 +1535,13 @@ packages: engines: {node: '>=6'} dev: true + /cbor@8.1.0: + resolution: {integrity: sha512-DwGjNW9omn6EwP70aXsn7FQJx5kO12tX0bZkaTjzdVFM6/7nhA4t0EENocKGx6D2Bch9PE2KzCUf5SceBdeijg==} + engines: {node: '>=12.19'} + dependencies: + nofilter: 3.1.0 + dev: true + /chai-as-promised@7.1.1(chai@4.4.1): resolution: {integrity: sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==} peerDependencies: @@ -2099,6 +2142,10 @@ packages: safe-buffer: 5.2.1 dev: true + /fast-deep-equal@3.1.3: + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + dev: true + /fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -2809,6 +2856,10 @@ packages: argparse: 2.0.1 dev: true + /json-schema-traverse@1.0.0: + resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} + dev: true + /jsonfile@2.4.0: resolution: {integrity: sha512-PKllAqbgLgxHaj8TElYymKCAgrASebJrWpTnEkOaTowt23VKXXN0sUeriJ+eh7y6ufb/CC5ap11pz71/cM0hUw==} optionalDependencies: @@ -2903,10 +2954,18 @@ packages: resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==} dev: true + /lodash.clonedeep@4.5.0: + resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} + dev: true + /lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} dev: true + /lodash.truncate@4.4.2: + resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==} + dev: true + /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true @@ -3132,6 +3191,11 @@ packages: hasBin: true dev: true + /nofilter@3.1.0: + resolution: {integrity: sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==} + engines: {node: '>=12.19'} + dev: true + /nopt@3.0.6: resolution: {integrity: sha512-4GUt3kSEYmk4ITxzB/b9vaIDfUVWN/Ml1Fwl11IlnIG2iaJ9O6WXZ9SrYM9NLI8OCBieN2Y8SWC2oJV0RQ7qYg==} hasBin: true @@ -3327,6 +3391,11 @@ packages: resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} dev: true + /punycode@2.3.1: + resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} + engines: {node: '>=6'} + dev: true + /qs@6.11.2: resolution: {integrity: sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==} engines: {node: '>=0.6'} @@ -3630,6 +3699,15 @@ packages: engines: {node: '>=8'} dev: true + /slice-ansi@4.0.0: + resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} + engines: {node: '>=10'} + dependencies: + ansi-styles: 4.3.0 + astral-regex: 2.0.0 + is-fullwidth-code-point: 3.0.0 + dev: true + /solc@0.7.3(debug@4.3.4): resolution: {integrity: sha512-GAsWNAjGzIDg7VxzP6mPjdurby3IkGCjQcM8GFYZT6RyaoUZKmMU6Y7YwG+tFGhv7dwZ8rmR4iwFDrrD99JwqA==} engines: {node: '>=8.0.0'} @@ -3837,6 +3915,17 @@ packages: wordwrapjs: 4.0.1 dev: true + /table@6.8.1: + resolution: {integrity: sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==} + engines: {node: '>=10.0.0'} + dependencies: + ajv: 8.12.0 + lodash.truncate: 4.4.2 + slice-ansi: 4.0.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + dev: true + /then-request@6.0.2: resolution: {integrity: sha512-3ZBiG7JvP3wbDzA9iNY5zJQcHL4jn/0BWtXIkagfz7QgOL/LqjCEOBQuJNZfu0XYnv5JhKh+cDxCPM4ILrqruA==} engines: {node: '>=6.0.0'} @@ -4044,6 +4133,12 @@ packages: engines: {node: '>= 0.8'} dev: true + /uri-js@4.4.1: + resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + dependencies: + punycode: 2.3.1 + dev: true + /utf8@3.0.0: resolution: {integrity: sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==} dev: true diff --git a/scripts/directTransfer.ts b/scripts/directTransfer.ts new file mode 100644 index 0000000..36ed318 --- /dev/null +++ b/scripts/directTransfer.ts @@ -0,0 +1,37 @@ +import { deployments, getNamedAccounts, getUnnamedAccounts, ethers } from 'hardhat'; + +const { execute } = deployments; +// example script + +const args = process.argv.slice(2); +const account = args[0]; +const message = args[1]; + +async function main() { + const { owner, simpleOffchainVerifier, offRamper, onRamper } = await getNamedAccounts(); + const simpleOffchainVerifierSigner = await ethers.getSigner(simpleOffchainVerifier); + const bob = await ethers.getSigner(offRamper); + const alice = await ethers.getSigner(onRamper); + + + console.log('simpleOffchainVerifier: ', simpleOffchainVerifier); + console.log('bob.address: ', bob.address); + console.log('DeRampVault.address: ', DeRampVault.address); + + + const erc20Deployment = await deployments.get('SimpleERC20'); + const erc20ABI = await ethers.getContractFactory('SimpleERC20'); + const deRampABI = await ethers.getContractFactory('DeRampVault'); + + + + const DeRampHandle = await deRampABI.connect(simpleOffchainVerifierSigner).attach(DeRampVault.address); + const tx = await DeRampHandle.transferFrom(DeRampVault.address, alice.address, 100); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/getBalance.ts b/scripts/getBalance.ts index 947529a..16302ae 100644 --- a/scripts/getBalance.ts +++ b/scripts/getBalance.ts @@ -27,25 +27,50 @@ async function main() { console.log('deramp balance: ', supp2); */ - const { owner, simpleERC20Beneficiary, offRamper, onRamper } = await getNamedAccounts(); + const { owner, simpleOffchainVerifier, offRamper, onRamper } = await getNamedAccounts(); const SimpleERC20Factory = await deployments.get('SimpleERC20'); - const benefactor = await ethers.getSigner(simpleERC20Beneficiary); + const DeRampVault = await deployments.get('DeRampVault'); + + const benefactor = await ethers.getSigner(simpleOffchainVerifier); const bobby = await ethers.getSigner(offRamper); const alice = await ethers.getSigner(onRamper); const MyContract2 = await ethers.getContractFactory('SimpleERC20'); - const DeRampHandle = await MyContract2.connect(benefactor).attach(SimpleERC20Factory.address); + const DeRampVaultABI = await ethers.getContractFactory('DeRampVault'); + + + const USDCHandle = await MyContract2.connect(benefactor).attach(SimpleERC20Factory.address); + const ReUSDCHandle = await DeRampVaultABI.connect(benefactor).attach(DeRampVault.address); + + + const supp2 = await USDCHandle.balanceOf(benefactor.address); + const supp3 = await USDCHandle.balanceOf(bobby.address); + const supp4 = await USDCHandle.balanceOf(alice.address); + const supp5 = await USDCHandle.balanceOf(DeRampVault.address); + + const supp6 = await ReUSDCHandle.balanceOf(benefactor.address); + const supp7 = await ReUSDCHandle.balanceOf(bobby.address); + const supp8 = await ReUSDCHandle.balanceOf(alice.address); + const supp9 = await ReUSDCHandle.balanceOf(DeRampVault.address); - const supp2 = await DeRampHandle.balanceOf(benefactor.address); - const supp3 = await DeRampHandle.balanceOf(bobby.address); - const supp4 = await DeRampHandle.balanceOf(alice.address); - console.log('bal: ', benefactor.address, supp2); + + console.log('---USDC BALANCES----'); + + console.log('usdc owner: ', benefactor.address, supp2); console.log('offRamper balance: ', bobby.address, supp3); - console.log('onRamper balance: ', alice.address, supp3); + console.log('onRamper balance: ', alice.address, supp4); + console.log('DeRampVault balance: ', DeRampVault.address, supp5); + + console.log('---ReUSDC BALANCES----'); + + console.log('offRamper balance: ', bobby.address, supp7); + console.log('onRamper balance: ', alice.address, supp8); + console.log('DeRampVault balance: ', DeRampVault.address, supp9); + } diff --git a/scripts/onramp.ts b/scripts/onramp.ts index 1ac9013..0f7753b 100644 --- a/scripts/onramp.ts +++ b/scripts/onramp.ts @@ -8,7 +8,7 @@ const account = args[0]; const message = args[1]; async function main() { - const { owner, simpleERC20Beneficiary, onRamper, offRamper } = await getNamedAccounts(); + const { owner, simpleERC20Beneficiary, onRamper, offRamper, simpleOffchainVerifier } = await getNamedAccounts(); const DeRampVault = await deployments.get('DeRampVault'); const erc = await deployments.get('SimpleERC20'); const erc20imp = await ethers.getContractFactory('SimpleERC20'); @@ -16,12 +16,20 @@ async function main() { const benefactor = await ethers.getSigner(simpleERC20Beneficiary); const bob = await ethers.getSigner(offRamper); const alice = await ethers.getSigner(onRamper); + const backend = await ethers.getSigner(simpleOffchainVerifier); + + console.log("offramper addy: ", bob.address); + console.log("onramper addy: ", alice.address); + + console.log("backend addy: ", backend.address); + + const erc20Handle = await erc20imp.connect(bob).attach(erc.address); const see = await erc20Handle.approve(DeRampVault.address, ethers.parseEther('1000000000')); console.log("using erc20: ", erc.address); const MyContract2 = await ethers.getContractFactory('DeRampVault'); - const DeRampHandle = await MyContract2.connect(bob).attach(DeRampVault.address); + const DeRampHandle = await MyContract2.connect(backend).attach(DeRampVault.address); //const supp2 = await DeRampHandle.deposit(ethers.parseEther(".05"), bob.address); const supp2 = await DeRampHandle.onramp(100, bob.address, alice.address); diff --git a/scripts/transferERC20.ts b/scripts/transferERC20.ts index e826c3e..4956f52 100644 --- a/scripts/transferERC20.ts +++ b/scripts/transferERC20.ts @@ -8,11 +8,11 @@ const account = args[0]; const message = args[1]; async function main() { - const { owner, simpleERC20Beneficiary, offRamper } = await getNamedAccounts(); - const benefactor = await ethers.getSigner(simpleERC20Beneficiary); + const { owner, simpleOffchainVerifier, offRamper } = await getNamedAccounts(); + const benefactor = await ethers.getSigner(simpleOffchainVerifier); const bob = await ethers.getSigner(offRamper); - console.log('simpleERC20Beneficiary: ', simpleERC20Beneficiary); + console.log('simpleERC20Beneficiary: ', simpleOffchainVerifier); console.log('bob.address: ', bob.address); const erc20Deployment = await deployments.get('SimpleERC20'); diff --git a/scripts/withdrawDeposit.ts b/scripts/withdrawDeposit.ts index 322a910..572c1c7 100644 --- a/scripts/withdrawDeposit.ts +++ b/scripts/withdrawDeposit.ts @@ -8,9 +8,9 @@ const account = args[0]; const message = args[1]; async function main() { - const { owner, simpleERC20Beneficiary, onRamper } = await getNamedAccounts(); + const { owner, simpleERC20Beneficiary, offRamper } = await getNamedAccounts(); const benefactor = await ethers.getSigner(simpleERC20Beneficiary); - const bob = await ethers.getSigner(onRamper); + const bob = await ethers.getSigner(offRamper); console.log('account: ', simpleERC20Beneficiary); console.log('account: ', bob.address); diff --git a/src/DeRampVault/DeRampVault.sol b/src/DeRampVault/DeRampVault.sol index d4e88dd..6a16e9a 100644 --- a/src/DeRampVault/DeRampVault.sol +++ b/src/DeRampVault/DeRampVault.sol @@ -20,6 +20,8 @@ contract DeRampVault is Initializable, ERC4626Upgradeable, UUPSUpgradeable, Owna // a mapping that checks if a user has deposited the token mapping(address => uint256) public shareHolder; uint256 public minDepositAmount; + ERC20 public uasset; + uint256 public maxOnRampAmount; uint256 public sustainabilityFee; // Fee charged to on-rampers in preciseUnits (1e16 = 1%) address public sustainabilityFeeRecipient; @@ -51,6 +53,7 @@ contract DeRampVault is Initializable, ERC4626Upgradeable, UUPSUpgradeable, Owna uint256 fee, address benefactor ) public { + uasset = _asset; minDepositAmount = min; maxOnRampAmount = max; sustainabilityFee = fee; @@ -101,33 +104,65 @@ contract DeRampVault is Initializable, ERC4626Upgradeable, UUPSUpgradeable, Owna require(shareHolder[offRamper] >= _shares, "Not enough shares"); // Calculate 10% yield on the withdrawal amount - uint256 percent = (10 * _shares) / 100; + //uint256 percent = (10 * _shares) / 100; // Calculate the total asset amount as the sum of the share amount plus 10% of the share amount. - uint256 assets = _shares + percent; + //uint256 assets = _shares + percent; // calling the redeem function from the ERC-4626 library to perform all the necessary functionality - redeem(assets, _receiver, offRamper); + //redeem(assets, _receiver, offRamper); + //__Context_init + + //uint256 maxShares = maxRedeem(offRamper); + // if (_shares > maxShares) { + // revert ERC4626ExceededMaxRedeem(owner, _shares, maxShares); + // } + + uint256 totalOnramp = previewRedeem(_shares); + _burn(offRamper, totalOnramp); + SafeERC20.safeTransferFrom(uasset, address(this), _receiver, _shares); + + //emit Withdraw(offRamper, _receiver, owner, uasset, _shares); + + /// // Decrease the share of the user shareHolder[offRamper] -= _shares; } - - function withdrawDeposit(uint _shares, address _receiver) public { - console.log("withD: %s %s %s", msg.sender, _shares,_receiver ); + /** + * @notice Function to allow msg.sender to withdraw their deposit plus accrued interest + * @param _shares amount of shares the user wants to convert + * @param _receiver address of the user who will receive the assets + */ + function withdrawDeposit(uint _shares, address _receiver) public onlyOwner { // checks that the deposited amount is greater than zero. require(_shares > 0, "withdraw must be greater than Zero"); // Checks that the _receiver address is not zero. require(_receiver != address(0), "Zero Address"); // checks that the caller is a shareholder - require(shareHolder[msg.sender] > 0, "Not a share holder"); + require(shareHolder[_receiver] > 0, "Not a share holder"); // checks that the caller has more shares than they are trying to withdraw. - require(shareHolder[msg.sender] >= _shares, "Not enough shares"); + require(shareHolder[_receiver] >= _shares, "Not enough shares"); + // Calculate 10% yield on the withdrawal amount //uint256 percent = (10 * _shares) / 100; // Calculate the total asset amount as the sum of the share amount plus 10% of the share amount. - uint256 assets = _shares; + //uint256 assets = _shares + percent; // calling the redeem function from the ERC-4626 library to perform all the necessary functionality - redeem(assets, _receiver, msg.sender); + //redeem(assets, _receiver, offRamper); + //__Context_init + + //uint256 maxShares = maxRedeem(offRamper); + // if (_shares > maxShares) { + // revert ERC4626ExceededMaxRedeem(owner, _shares, maxShares); + // } + + uint256 totalOnramp = previewRedeem(_shares); + _burn(_receiver, totalOnramp); + SafeERC20.safeTransferFrom(uasset, address(this), _receiver, _shares); + + //emit Withdraw(offRamper, _receiver, owner, uasset, _shares); + + /// // Decrease the share of the user - shareHolder[msg.sender] -= _shares; + shareHolder[_receiver] -= _shares; } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} diff --git a/src/ERC20/SimpleERC20.sol b/src/ERC20/SimpleERC20.sol index d4bcc61..5762126 100644 --- a/src/ERC20/SimpleERC20.sol +++ b/src/ERC20/SimpleERC20.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: AGPL-1.0 +// SPDX-License-Identifier: MIT pragma solidity 0.8.20; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";