{"id":13795260,"url":"https://github.com/makerdao/dss-psm","last_synced_at":"2025-04-18T16:31:01.196Z","repository":{"id":38383035,"uuid":"397624310","full_name":"makerdao/dss-psm","owner":"makerdao","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-13T22:08:12.000Z","size":572,"stargazers_count":16,"open_issues_count":3,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-04T23:09:30.450Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makerdao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":"audits/MakerDAO Dai Peg Stability Module - Final Report.pdf","citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-08-18T14:11:16.000Z","updated_at":"2024-07-30T16:14:35.000Z","dependencies_parsed_at":"2024-04-06T09:43:23.718Z","dependency_job_id":null,"html_url":"https://github.com/makerdao/dss-psm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makerdao%2Fdss-psm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makerdao%2Fdss-psm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makerdao%2Fdss-psm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makerdao%2Fdss-psm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makerdao","download_url":"https://codeload.github.com/makerdao/dss-psm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783353,"owners_count":17201901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T23:00:53.896Z","updated_at":"2024-11-09T03:37:43.862Z","avatar_url":"https://github.com/makerdao.png","language":"Solidity","funding_links":[],"categories":["Projects","Projects Using Dapp"],"sub_categories":["DappTools"],"readme":"# DssPsm\n\nThe official implementation of the [Peg Stability Module](https://forum.makerdao.com/t/mip29-peg-stability-module/5071). There are two main components to the PSM:\n\n### AuthGemJoinX\n\nThis is an exact duplicate of the `GemJoinX` adapter for the given collateral type with two modifications.\n\nFirst the method signature of `join()` is changed to include the original message sender at the end as well as adding the `auth` modifier. This should look like:\n\n`function join(address urn, uint256 wad) external note` -\u003e `function join(address urn, uint256 wad, address _msgSender) external note auth`\n\nSecond, all instances of `msg.sender` are replaced with `_msgSender` in the `join()` function.\n\nIn this repository I have added [join-5-auth.sol](https://github.com/BellwoodStudios/dss-psm/blob/master/src/join-5-auth.sol) for the PSM-friendly version of [join-5.sol](https://github.com/makerdao/dss-gem-joins/blob/master/src/join-5.sol) which is used for USDC. This can be applied to any other gem join adapter.\n\n### DssPsm\n\nThis is the actual PSM module which acts as a authed special vault sitting behind the `AuthGemJoinX` contract. `DssPsm` allows you to either call `sellGem()` or `buyGem()` to trade ERC20 DAI for the gem or vice versa. Upon calling one of these functions the PSM vault will either lock gems in the join adapter, take out a dai loan and issue ERC20 DAI to the specified user or do that process in reverse.\n\n#### Approvals\n\nThe PSM requires ERC20 approvals to pull in the tokens.\n\nTo use `sellGem(usr, amt)` you must first call `gem.approve(\u003cgemJoinAddress\u003e, amt)`. Example:\n\n    // Trade 100 USDC for 100 DAI - fee\n    usdc.approve(0x0A59649758aa4d66E25f08Dd01271e891fe52199, 100 * (10 ** 6));\n    psm.sellGem(address(this), 100 * (10 ** 6));\n\nTo use `buyGem(usr, amt)` you must first call `dai.approve(\u003cpsmAddress\u003e, amt + fee)`. Example:\n\n    // Trade DAI + fee for 100 USDC\n    uint256 WAD = 10 ** 18;\n    dai.approve(0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A, 100 * (psm.tout() + WAD));\n    psm.buyGem(address(this), 100 * (10 ** 6));\n\n#### Notes on Fees\n\nPlease note the fee behaviour is not the same for both functions.\n\nWhen calling `sellGem()`, DAI is minted at a 1:1 rate to which the fee is removed from that amount. So if you have 100 USDC with 1% fee and you call `sellGem()` then you will recieve `100 DAI - 1% * 100 DAI` = `99 DAI`. In this case the fee is subtracted from the result amount.\n\nWhen calling `buyGem()`, you specify the amount of the gem you want to recieve. This fee is then added on top of this value to determine how much ERC20 DAI you require in your account. So if you call `buyGem()` for 100 USDC with a 1% fee then you require `100 DAI + 1% * 100 DAI` = `101 DAI`.\n\nPlease note this was a conscious decision to avoid dealing with decimal division and rounding leftovers. \n\n## Contracts\n\n### Mainnet\n\nUSDC GemJoin: [0x0A59649758aa4d66E25f08Dd01271e891fe52199](https://etherscan.io/address/0x0A59649758aa4d66E25f08Dd01271e891fe52199#code)  \nUSDC PSM: [0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A](https://etherscan.io/address/0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A#code)  \nUSDP GemJoin: [0x7bbd8cA5e413bCa521C2c80D8d1908616894Cf21](https://etherscan.io/address/0x7bbd8cA5e413bCa521C2c80D8d1908616894Cf21#code)  \nUSDP PSM: [0x961Ae24a1Ceba861D1FDf723794f6024Dc5485Cf](https://etherscan.io/address/0x961Ae24a1Ceba861D1FDf723794f6024Dc5485Cf#code)  \n\n### Kovan\n\nUSDC GemJoin: [0x4BA159Ad37FD80D235b4a948A8682747c74fDc0E](https://kovan.etherscan.io/address/0x4BA159Ad37FD80D235b4a948A8682747c74fDc0E#code)  \nUSDC PSM: [0xe4dC42e438879987e287A6d9519379936d7b065A](https://kovan.etherscan.io/address/0xe4dC42e438879987e287A6d9519379936d7b065A#code)  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakerdao%2Fdss-psm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakerdao%2Fdss-psm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakerdao%2Fdss-psm/lists"}