Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Revert "Remove all this pesky code (for review)" #90

Open
wants to merge 1 commit into
base: godsflaw-20220629
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/TeleportConstantFee.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.14;

import {TeleportFees} from "./TeleportFees.sol";
import {TeleportGUID} from "./TeleportGUID.sol";

contract TeleportConstantFee is TeleportFees {
uint256 immutable public fee;
uint256 immutable public ttl;

/**
* @param _fee Constant fee in WAD
* @param _ttl Time in seconds to finalize flush (not teleport)
**/
constructor(uint256 _fee, uint256 _ttl) {
fee = _fee;
ttl = _ttl;
}

function getFee(TeleportGUID calldata guid, uint256, int256, uint256, uint256 amtToTake) override external view returns (uint256) {
// is slow withdrawal?
if (block.timestamp >= uint256(guid.timestamp) + ttl) {
return 0;
}

// is empty teleport?
if (guid.amount == 0) {
return 0;
}

return fee * amtToTake / guid.amount;
}
}
36 changes: 36 additions & 0 deletions src/TeleportFees.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.14;

import "./TeleportGUID.sol";

// Calculate fees for a given Teleport GUID
interface TeleportFees {
/**
* @dev Return fee for particular teleport. It should return 0 for teleports that are being slow withdrawn.
* note: We define slow withdrawal as teleport older than x. x has to be enough to finalize flush (not teleport itself).
* @param teleportGUID Struct which contains the whole teleport data
* @param line Debt ceiling
* @param debt Current debt
* @param pending Amount left to withdraw
* @param amtToTake Amount to take. Can be less or equal to teleportGUID.amount b/c of debt ceiling or because it is pending
* @return fees Fee amount [WAD]
**/
function getFee(
TeleportGUID calldata teleportGUID, uint256 line, int256 debt, uint256 pending, uint256 amtToTake
) external view returns (uint256 fees);
}
51 changes: 51 additions & 0 deletions src/TeleportGUID.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.14;

// Standard Maker Teleport GUID
struct TeleportGUID {
bytes32 sourceDomain;
bytes32 targetDomain;
bytes32 receiver;
bytes32 operator;
uint128 amount;
uint80 nonce;
uint48 timestamp;
}

// solhint-disable-next-line func-visibility
function bytes32ToAddress(bytes32 addr) pure returns (address) {
return address(uint160(uint256(addr)));
}

// solhint-disable-next-line func-visibility
function addressToBytes32(address addr) pure returns (bytes32) {
return bytes32(uint256(uint160(addr)));
}

// solhint-disable-next-line func-visibility
function getGUIDHash(TeleportGUID memory teleportGUID) pure returns (bytes32 guidHash) {
guidHash = keccak256(abi.encode(
teleportGUID.sourceDomain,
teleportGUID.targetDomain,
teleportGUID.receiver,
teleportGUID.operator,
teleportGUID.amount,
teleportGUID.nonce,
teleportGUID.timestamp
));
}
Loading