Skip to content

Commit

Permalink
Updated Mortgage
Browse files Browse the repository at this point in the history
Added `spender` in `deposit` function
Added `recipient` in `withdraw` function
  • Loading branch information
MikletNg committed Nov 28, 2023
1 parent d8bb030 commit 2b588ea
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 20 deletions.
360 changes: 354 additions & 6 deletions .openzeppelin/goerli.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions contracts/mortgage/Mortgage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ contract Mortgage is IMortgage, ReentrancyGuardUpgradeable, AccessControlUpgrade
_token = token_;
}

function deposit(bytes32 name, bytes32 tld, address owner, uint256 amount) public whenNotPaused nonReentrant {
function deposit(bytes32 name, bytes32 tld, address owner, address spender, uint256 amount) public whenNotPaused nonReentrant {
require(isExists(name, tld), "DOMAIN_NOT_EXISTS");
require(_registry.isLive(name, tld), "DOMAIN_EXPIRED");
_token.safeTransferFrom(_msgSender(), address(this), getRequirement(name, tld));
_token.safeTransferFrom(spender, address(this), getRequirement(name, tld));
_funds[tld][name][owner] += amount;
emit Deposit(name, tld, owner, amount);
}

function withdraw(bytes32 name, bytes32 tld, uint256 amount) public whenNotPaused nonReentrant {
function withdraw(bytes32 name, bytes32 tld, address recipient, uint256 amount) public whenNotPaused nonReentrant {
require(_funds[tld][name][_msgSender()] >= amount, "FUND_AMOUNT_EXCEEDED");
_token.safeTransferFrom(address(this), _msgSender(), amount);
_token.safeTransferFrom(address(this), recipient, amount);
emit Withdraw(name, tld, _msgSender(), amount);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/mortgage/interfaces/IMortgage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ interface IMortgage {
event Deposit(bytes32 name, bytes32 tld, address owner, uint256 amount);
event Withdraw(bytes32 name, bytes32 tld, address to, uint256 amount);

function deposit(bytes32 name, bytes32 tld, address owner, uint256 amount) external;
function deposit(bytes32 name, bytes32 tld, address owner, address spender, uint256 amount) external;

function withdraw(bytes32 name, bytes32 tld, uint256 amount) external;
function withdraw(bytes32 name, bytes32 tld, address recipient, uint256 amount) external;

function setRequirement(bytes32 name, bytes32 tld, uint256 amount) external;

Expand Down
2 changes: 1 addition & 1 deletion scripts/B14_Setup_Mortgage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "hardhat";
import { getContracts } from "./src/lib/get-contracts";
import { setupMigrationManager, setupMortgage } from "./src/setup";
import { setupMortgage } from "./src/setup";

async function main() {
const [signer] = await ethers.getSigners();
Expand Down
2 changes: 2 additions & 0 deletions scripts/C01_Upgrade_Registry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ethers } from "hardhat";
import { getContracts } from "./src/lib/get-contracts";
import { setupRegistry } from "./src/setup";
import { upgradeRegistry } from "./src/upgrade";

async function main() {
const [signer] = await ethers.getSigners();
const chainId = await signer.getChainId();
const contracts = await getContracts(signer);
await upgradeRegistry({ signer, chainId, contracts });
await setupRegistry({ signer, chainId, contracts });
}

main().catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/C14_Upgrade_Mortgage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethers } from "hardhat";
import { getContracts } from "./src/lib/get-contracts";
import { upgradeMigrationManager } from "./src/upgrade";
import { upgradeMortgage } from "./src/upgrade";

async function main() {
const [signer] = await ethers.getSigners();
const chainId = await signer.getChainId();
const contracts = await getContracts(signer);
await upgradeMigrationManager({ signer, chainId, contracts });
await upgradeMortgage({ signer, chainId, contracts });
}

main().catch((error) => {
Expand Down
8 changes: 4 additions & 4 deletions static/contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
"Registry.DiamondCutFacet": "0x16F8202C66de13B843321d6947052d8BE68cC874",
"Registry.DiamondLoupeFacet": "0x0bE19b357eFD1E353704C4a7c5810e18fDBCad40",
"Registry.AccessControlFacet": "0x020A9D14a0B93676420DDAE8d7c0BC049815cE51",
"Registry.TldRecordFacet": "0xdc9A9FaE9c3e53B9df13c46F2E21c41562B0250D",
"Registry.DomainRecordFacet": "0x2FBBb72406e7b9cBac2fE139038C4b6a0be17E9B",
"Registry.HostRecordFacet": "0xDeaB37d64e8B1176d4b1a7fC35DC212bE3d277f0",
"Registry.BaseRegistryFacet": "0x4Cd9f4a4585D2E202e76766Dde7A063D19C30774",
"Registry.TldRecordFacet": "0x540621Ad648F66f25bfC9BCB550818985820C2aA",
"Registry.DomainRecordFacet": "0xb031aaDa447caAaa76A25Cd7282104cAe7C225F0",
"Registry.HostRecordFacet": "0x3429484d18B4ad3f3F53C32968b2dB7bf80b5888",
"Registry.BaseRegistryFacet": "0xD2714B1B539764037DaBe6172b855ED897d7e4A4",
"Registry.Diamond": "0x2B295aFC93E4f9eBa1A2170D531A42C0232B2102",
"DefaultWrapper": "0x2cbbF202b3977E3534cE8EDAd768c4742DeD11ae",
"PublicResolver": "0xe90EAE12B9A9CC3AB8BAF9dB06422D6c5922213f",
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe("Deploy & Setup", function () {
expect(await contracts.PublicResolver.getText(ethers.utils.toUtf8Bytes("@"), ethers.utils.toUtf8Bytes(name), ethers.utils.toUtf8Bytes(tld))).to.equal("");

expect(
contracts.PublicResolver.connect(signer_1)["setAddress"](ethers.utils.toUtf8Bytes("@"), ethers.utils.toUtf8Bytes(name), ethers.utils.toUtf8Bytes(tld), signer_1.address),
contracts.PublicResolver.connect(signer_1)["setAddress"](ethers.utils.toUtf8Bytes(host), ethers.utils.toUtf8Bytes(name), ethers.utils.toUtf8Bytes(tld), signer_1.address),
).to.be.revertedWith("DOMAIN_MORTGAGE_NOT_FULFILLED");

// Mint some token to signer_1
Expand Down

0 comments on commit 2b588ea

Please sign in to comment.