首页 > 其他分享 >Principles of Distributed Ledgers

Principles of Distributed Ledgers

时间:2024-11-13 10:56:40浏览次数:1  
标签:USDC Distributed Principles contract should Ledgers address employee ETH

Principles of Distributed Ledgers: Coursework

Objective The objective of this coursework is to develop a Solidity contract, HumanResources, which implements

a human resources (HR) payment system and to deploy it on Optimism. This contract will enablea human resources manager to manage employee registrations,terminations, and allow employees towithdraw their salary.

Key Goals

  • Implement role-based access control and enforce functions to be callable only by the HR manageror registered employees.
  • Allow to register and terminate employees.
  • Enable employees to withdraw salaries in USDC or ETH based on their preference.
  • Use an oracle to get the current ETH price and an AMM to perform swaps from USDC to ETHfor salary disbursement in ETH.

Instructions Your task is to build the HumanResources contract that implements the given IHumanResourcesinterface and deploy it to Optimism. You are free to use any Solidity library you want, and to interactwith any other contract on Optimism. However, you must ensure that you follow the specificationsvery carefully. The correctness of the contract will be graded automatically, so failure to follow thspecifications will result in deducted marks.Project Specifications

Assumptions

  • The HumanResources contract will hold USDC only. This USDC will be sent by the HR managerusing a normal transfer.
  • There are two versions of USDC on Optimism (USDC and USDC.e). In this coursework, we exclusively use the USDC version deployed at this address: 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85.
  • For the purpose of this coursework, we assume 1 USD = 1 USDC
  1. 1 Contract Setup and Role Management
  • Define the contract HumanResources that implements IHumanResources (see below). Do notmodify the given IHumanResources interface.The contract should have an hrManager. Only this address should be able to register andterminate employees. This address should be set when the contract is created and should not bemodifiable by anyone.
  • Use the NotAuthorized error when an unauthorized user tries to call restricted functions.
  1. Registering and Managing Employees
  • registerEmployee:

Register employees with an address and a weeklyUsdSalary in USD, scaled with 18 decimals.Emit the EmployeeRegistered event.If the employee is already registered, revert with EmployeeAlreadyRegistered.If an employee was terminated and is re-registered, his salary shall start accumulating againfrom the point at which he is registered again.

terminateEmployee:Allow only the HR Manager to terminate an employee’s contract.The employee’s salary accumulation should stop upon termination.

Emit the EmployeeTerminated event.If the employee is not registered, revert with EmployeeNotRegistered.

  1. Salary Accumulation and Withdrawal
  • Accrual Logic:Salary accrues continuously based on the weekly USD salary. For example, after 2 days,2/7ths of the weekly salary is available for withdrawal.We do not considerweekends and non-working hours in this coursework. The salary shouldbe accumulated linearly with time.

withdrawSalary:Allows employees to withdraw their accumulated salary in their preferred currency (USDCor ETH).When in ETH mode and a withdrawal is initiated, swap the appropriate amount of USDCto ETH. The swap can use wrapped ETH (WETH)1 , but the salary must be paid in ETH,not in WETH. The ETH should be sent in a re-entrancy safe manner (this will be coveredin depth i代写Principles of Distributed Ledgers n lecture 8).Use an oracle to get the current ETH price and protect against AMM price manipulation.Emit the SalaryWithdrawn event with isEth indicating the currency withdrawn.

1WETH is an ERC20 representation of ETH. The WETH smart contract allows anyone to lock ETH and mintWETH, an ERC20 token representation, where 1 WETH = 1 ETH. One may also redeem 1 ETH for 1 WETH token.The WETH address on Optimism is: 0x4200000000000000000000000000000000000006

2Note: USDC has six decimals. Hence, when performing calculations between USDC andother assets (e.g., ETH), be careful to scale the values appropriately.

Currency Switching:

Employees can call switchCurrency to toggle between receiving salary in USDC and ETH.

The current pending salary shall be withdrawn automatically when this is called.The default currency shall be USDC.Emit the CurrencySwitched event whenever an employee toggles their preferred currency.

  1. Using AMMs and Oracles

We do not enforce any AMM or oracle for this coursework but we recommend using Uniswap as the

AMM and Chainlink as the oracle.

  • Chainlink Integration (Oracle):

The Chainlink feed for ETH/USD on Optimism can be found at the following address:0x13e3Ee699D1909E989722E753853AE30b17e08c5. The interface of this contract can befound here: AggregatorV3Interface.sol.For the purpose of this coursework, you do not need to follow best practices such as checkingfor the time of the latest price update

  • Uniswap Integration (AMM):

We recommend using the Uniswap swap router that can be found here for Optimism:0xE592427A0AEce92De3Edee1F18E0157C05861564. The interface of this contractcan behere: IV3SwapRouter.sol.Ensure that the swap is protected against front-running and excessive slippage. The mostcommon way to protect against front-running slippageis to pass a minimumamount out tothe swap function used. For this coursework, if the ETH returned from the swap is under2% less that what would be expected at the current price, the function should .

  1. Views and Employee Information
  • salaryAvailable:

Returns the available salary for an employee in the preferred currency (USDC or ETH).The amount must be scaled with the correct number of decimals for the currency.hrManager:Returns the HR manager’s addressgetActiveEmployeeCount:Returns thcount of currently active (non-terminated) employees.

getEmployeeInfo:Returns the employee’s weeklyUsdSalary, employedSince timestamp (the time at which

the employee was registered, or re-registered after a termination), and terminatedAt timestamp if terminated, or zero if the employee is active (either non-terminated or re-registered).If the employee does not exist, the function shall not revert but all returned values must bezero.

3 Deployment to Optimism

  1. Claim some ETH from the faucet. Make sure that you have control over the address that receivesthe ETH. NOTE: the faucet has been reset so that everyone can claim again.
  1. Deploy the contract to Optimism. Do NOT verify the contract.
  2. Register the contract address you deployed by calling the submit function of this contract:0xbe41d42e2d1373120b24dd27a5465d8ef48b9d34. IMPORTANT: use the same address you used when claiming ETH in step 1 to call the submit function, since it is what  will useto identify your submission.
  1. You can re-submit as many times as you want. Your latest submission (until the deadline) will

be used to run the tests.

Testing Requirements Your submission should include a suite of tests covering all the functions in the interface for bothsuccess and failure cases (e.g., unauthorized user calling).To test integration with external contracts, you will need to use fork testing and use contractsdeployed on Optimism. Fork testing can be slow, so we recommend explicitly setting the block numberto make subsequent calls faster.

Submission Requirements

The submission should be a single zip file that follows the regular Foundry project structure. Please donot nest the project when zipping it (i.e., README.md and other foundry files should be at the rootof the zip file). The commands forge build and forge test MUST workwhen ran after unzippingthe submission.The submission must contain at least the following content:

  1. Contract Code: The code of the deployed contract. It should be in a file called src/HumanResources.sol.
  2. Other code: Any other code required to compile and test the application. This includes but isnot limited to foundry.toml and the content of the lib directory.Deployment Address: Provide the address of the deployed contract on Optimism. It shouldbe written in a file called deployed-address.txt, placed in the root folder, that only containsthis address.
  1. Transaction hash: Submit the transaction hash of calling the submit function described in 6above. It should be written in a file called submit-transaction.txt, placed in the root folder,that only contains this transaction hash.
  1. Test Suite: Include a full test suite for your contract (written in Solidity with Foundry). Testsshould be in the test directory.
  1. Documentation: Brief documentation explaining how your contract implements each functionin the IHumanResources interface and a summary of how the AMM and the oracle are integrated.The documentation should be in a README.md file placed in the rootfolder.You are free to add other relevant files to the submission but please do not include your .git folderor other files that are not relevant to it.

4Evaluation Criteria Your contract will be evaluated based on the following criteria:

  • Correctness: Does the contract meet all the interface requirements and handle edge cases?
  • Security: Is access control properly implemented? Are error messages used appropriately?
  • Integration: Does the contract integrate correctly with the AMM and the oracle?
  • Code Quality: Is the code readable, maintainable, and well-documented?
  • Testing: Does the test suite thoroughly cover different scenarios and edge cases?

IMPORTANT The correctness, security, and integration parts of the grade will be given bytesting your deployed contract against our test suite. If your contract is not deployed correctly ordoes not implement the provided interface, you will not get any points for this part.5Solidity Interface

标签:USDC,Distributed,Principles,contract,should,Ledgers,address,employee,ETH
From: https://www.cnblogs.com/comp9321/p/18543379

相关文章

  • 在 Windows 系统中,DFS (Distributed File System) 是一种用于文件共享和管理的技术,能
    在Windows系统中,DFS(DistributedFileSystem)是一种用于文件共享和管理的技术,能够让多个服务器上的共享文件夹(共享资源)通过一个统一的命名空间来访问。DFS主要通过DFS命名空间和DFS复制这两个组件来实现。DFS相关命令和功能在Windows中,DFS相关的命令通常是通过......
  • COMP3230 Principles of Operating Systems
    COMP3230PrinciplesofOperatingSystemsProgrammingAssignmentTwoDuedate:November17,2024,at23:59Total12points–ReleaseCandidateVersion2ProgrammingExercise–AccelerateLLMInferenceusingMulti-ThreadingObjectivesAnassessmenttask......
  • ECE6101/CSE6461  Distributed,  Independent random
    ECE6101/CSE6461Homework2AssignmentAutumn2024Expected Completion Date: October 11, 20241. Let {N1(t), t ≥ 0} be a Poisson Process with rate λ . Can Z(t) = αN1(t)+βN2 (t) ever bea Poisson Process, where α and β a......
  • 28_分布式文档系统_阶段性总结以及什么是distributed document store
    1、阶段性总结1~8讲:快速入门了一下,最基本的原理,最基本的操作9~13讲:在入门之后,对ES的分布式的基本原理,进行了相对深入一些的剖析14~27讲:围绕着document这个东西,进行操作,进行讲解和分析2、什么是distributeddocumentstore到目前为止,你觉得你在学什么东西,给大家一个直观的感觉......
  • COMP3230 Principles of Operating Systems
    COMP3230PrinciplesofOperatingSystemsProgrammingAssignmentOneDuedate:Oct.17,2024,at23:59Total13points–ReleaseCandidateVersion2ProgrammingExercise–ImplementaLLMChatbotInterfaceObjectivesAnassessmenttaskrelatedto......
  • 大数据-142 - ClickHouse 集群 副本和分片 Distributed 附带案例演示
    点一下关注吧!!!非常感谢!!持续更新!!!目前已经更新到了:Hadoop(已更完)HDFS(已更完)MapReduce(已更完)Hive(已更完)Flume(已更完)Sqoop(已更完)Zookeeper(已更完)HBase(已更完)Redis(已更完)Kafka(已更完)Spark(已更完)Flink(已更完)ClickHouse(正在更新···)章节内容上节我们完成了如下的内容:副本和分片,上节主要是......
  • torch.distributed.DistNetworkError: The server socket has failed to listen on an
    解决方案是在torchrun中添加参数--master_port改变masterport。且注意这个参数一定要加在要跑的文件即src/entry_point/train.py之前,否则会被忽略。引用:https://juejin.cn/post/7260668104752775228我的代码是:torchrun--nproc_per_node1--master_port29501-mtraining.......
  • Distributed Training: DeepSpeed ZeRO 1/2/3 + Accelerate, Megatron-LM
    1IntroductionGithub:https://github.com/microsoft/DeepSpeedZeRO:MemoryOptimizationsTowardTrainingTrillionParameterModelsZeRO-Offload:DemocratizingBillion-ScaleModelTrainingZeRO-Infinity:BreakingtheGPUMemoryWallforExtremeScaleDee......
  • Python - SOLID Principles
    •Singleresponsibilityprinciple(SRP)•Open-closedprinciple(OCP)Itemphasizesthatsoftwareentities, suchasclassesandmodules,shouldbeopenforextensionbutclosedformodification.Whatdoes thatmean?Itmeansthatonceasoftwareentityis......
  • Python - Foundational Design Principles
    EncapsulateWhatVariesOneofthemostcommonchallengesinsoftwaredevelopmentisdealingwithchange.Requirements evolve,technologiesadvance,anduserneedsalsochange.Therefore,itiscrucialtowritecodethat canadaptwithoutcausingaripple......