Contract Address Details

0x1e84A781522CF3d8141578930FF7e5152B0bdaC0

Contract Name
DssProxyActionsDsr
Creator
0xb8f7fd–af46bc at 0x448cf6–ab2c51
Balance
0 VLX
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
69800119
Contract name:
DssProxyActionsDsr




Optimization enabled
true
Compiler version
v0.5.12+commit.7709ece9




Optimization runs
200
EVM Version
petersburg




Verified at
2021-10-28T21:02:30.305804Z

Contract source code

pragma solidity >=0.5.12;

interface GemLike {
    function approve(address, uint) external;
    function transfer(address, uint) external;
    function transferFrom(address, address, uint) external;
    function deposit() external payable;
    function withdraw(uint) external;
}

interface ManagerLike {
    function cdpCan(address, uint, address) external view returns (uint);
    function ilks(uint) external view returns (bytes32);
    function owns(uint) external view returns (address);
    function urns(uint) external view returns (address);
    function vat() external view returns (address);
    function open(bytes32, address) external returns (uint);
    function give(uint, address) external;
    function cdpAllow(uint, address, uint) external;
    function urnAllow(address, uint) external;
    function frob(uint, int, int) external;
    function flux(uint, address, uint) external;
    function move(uint, address, uint) external;
    function exit(address, uint, address, uint) external;
    function quit(uint, address) external;
    function enter(address, uint) external;
    function shift(uint, uint) external;
}

interface VatLike {
    function can(address, address) external view returns (uint);
    function ilks(bytes32) external view returns (uint, uint, uint, uint, uint);
    function usdv(address) external view returns (uint);
    function urns(bytes32, address) external view returns (uint, uint);
    function frob(bytes32, address, address, address, int, int) external;
    function hope(address) external;
    function move(address, address, uint) external;
}

interface GemJoinLike {
    function dec() external returns (uint);
    function gem() external returns (GemLike);
    function join(address, uint) external payable;
    function exit(address, uint) external;
}

interface GNTJoinLike {
    function bags(address) external view returns (address);
    function make(address) external returns (address);
}

interface UsdvJoinLike {
    function vat() external returns (VatLike);
    function usdv() external returns (GemLike);
    function join(address, uint) external payable;
    function exit(address, uint) external;
}

interface HopeLike {
    function hope(address) external;
    function nope(address) external;
}

interface EndLike {
    function fix(bytes32) external view returns (uint);
    function cash(bytes32, uint) external;
    function free(bytes32) external;
    function pack(uint) external;
    function skim(bytes32, address) external;
}

interface JugLike {
    function drip(bytes32) external returns (uint);
}

interface PotLike {
    function pie(address) external view returns (uint);
    function drip() external returns (uint);
    function join(uint) external;
    function exit(uint) external;
}

interface ProxyRegistryLike {
    function proxies(address) external view returns (address);
    function build(address) external returns (address);
}

interface ProxyLike {
    function owner() external view returns (address);
}

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// WARNING: These functions meant to be used as a a library for a DSProxy. Some are unsafe if you call them directly.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

contract Common {
    uint256 constant RAY = 10 ** 27;

    // Internal functions

    function mul(uint x, uint y) internal pure returns (uint z) {
        require(y == 0 || (z = x * y) / y == x, "mul-overflow");
    }

    // Public functions

    function usdvJoin_join(address apt, address urn, uint wad) public {
        // Gets USDV from the user's wallet
        UsdvJoinLike(apt).usdv().transferFrom(msg.sender, address(this), wad);
        // Approves adapter to take the USDV amount
        UsdvJoinLike(apt).usdv().approve(apt, wad);
        // Joins USDV into the vat
        UsdvJoinLike(apt).join(urn, wad);
    }
}

contract DssProxyActions is Common {
    // Internal functions

    function sub(uint x, uint y) internal pure returns (uint z) {
        require((z = x - y) <= x, "sub-overflow");
    }

    function toInt(uint x) internal pure returns (int y) {
        y = int(x);
        require(y >= 0, "int-overflow");
    }

    function toRad(uint wad) internal pure returns (uint rad) {
        rad = mul(wad, 10 ** 27);
    }

    function convertTo18(address gemJoin, uint256 amt) internal returns (uint256 wad) {
        // For those collaterals that have less than 18 decimals precision we need to do the conversion before passing to frob function
        // Adapters will automatically handle the difference of precision
        wad = mul(
            amt,
            10 ** (18 - GemJoinLike(gemJoin).dec())
        );
    }

    function _getDrawDart(
        address vat,
        address jug,
        address urn,
        bytes32 ilk,
        uint wad
    ) internal returns (int dart) {
        // Updates stability fee rate
        uint rate = JugLike(jug).drip(ilk);

        // Gets USDV balance of the urn in the vat
        uint usdv = VatLike(vat).usdv(urn);

        // If there was already enough USDV in the vat balance, just exits it without adding more debt
        if (usdv < mul(wad, RAY)) {
            // Calculates the needed dart so together with the existing usdv in the vat is enough to exit wad amount of USDV tokens
            dart = toInt(sub(mul(wad, RAY), usdv) / rate);
            // This is neeeded due lack of precision. It might need to sum an extra dart wei (for the given USDV wad amount)
            dart = mul(uint(dart), rate) < mul(wad, RAY) ? dart + 1 : dart;
        }
    }

    function _getWipeDart(
        address vat,
        uint usdv,
        address urn,
        bytes32 ilk
    ) internal view returns (int dart) {
        // Gets actual rate from the vat
        (, uint rate,,,) = VatLike(vat).ilks(ilk);
        // Gets actual art value of the urn
        (, uint art) = VatLike(vat).urns(ilk, urn);

        // Uses the whole usdv balance in the vat to reduce the debt
        dart = toInt(usdv / rate);
        // Checks the calculated dart is not higher than urn.art (total debt), otherwise uses its value
        dart = uint(dart) <= art ? - dart : - toInt(art);
    }

    function _getWipeAllWad(
        address vat,
        address usr,
        address urn,
        bytes32 ilk
    ) internal view returns (uint wad) {
        // Gets actual rate from the vat
        (, uint rate,,,) = VatLike(vat).ilks(ilk);
        // Gets actual art value of the urn
        (, uint art) = VatLike(vat).urns(ilk, urn);
        // Gets actual usdv amount in the urn
        uint usdv = VatLike(vat).usdv(usr);

        uint rad = sub(mul(art, rate), usdv);
        wad = rad / RAY;

        // If the rad precision has some dust, it will need to request for 1 extra wad wei
        wad = mul(wad, RAY) < rad ? wad + 1 : wad;
    }

    // Public functions

    function transfer(address gem, address dst, uint amt) public {
        GemLike(gem).transfer(dst, amt);
    }

    function vlxJoin_join(address apt, address urn) public payable {
        // Wraps VLX in WVLX
        GemJoinLike(apt).gem().deposit.value(msg.value)();
        // Approves adapter to take the WVLX amount
        GemJoinLike(apt).gem().approve(address(apt), msg.value);
        // Joins WVLX collateral into the vat
        GemJoinLike(apt).join(urn, msg.value);
    }

    function gemJoin_join(address apt, address urn, uint amt, bool transferFrom) public {
        // Only executes for tokens that have approval/transferFrom implementation
        if (transferFrom) {
            // Gets token from the user's wallet
            GemJoinLike(apt).gem().transferFrom(msg.sender, address(this), amt);
            // Approves adapter to take the token amount
            GemJoinLike(apt).gem().approve(apt, amt);
        }
        // Joins token collateral into the vat
        GemJoinLike(apt).join(urn, amt);
    }

    function hope(
        address obj,
        address usr
    ) public {
        HopeLike(obj).hope(usr);
    }

    function nope(
        address obj,
        address usr
    ) public {
        HopeLike(obj).nope(usr);
    }

    function open(
        address manager,
        bytes32 ilk,
        address usr
    ) public returns (uint cdp) {
        cdp = ManagerLike(manager).open(ilk, usr);
    }

    function give(
        address manager,
        uint cdp,
        address usr
    ) public {
        ManagerLike(manager).give(cdp, usr);
    }

    function giveToProxy(
        address proxyRegistry,
        address manager,
        uint cdp,
        address dst
    ) public {
        // Gets actual proxy address
        address proxy = ProxyRegistryLike(proxyRegistry).proxies(dst);
        // Checks if the proxy address already existed and dst address is still the owner
        if (proxy == address(0) || ProxyLike(proxy).owner() != dst) {
            uint csize;
            assembly {
                csize := extcodesize(dst)
            }
            // We want to avoid creating a proxy for a contract address that might not be able to handle proxies, then losing the CDP
            require(csize == 0, "Dst-is-a-contract");
            // Creates the proxy for the dst address
            proxy = ProxyRegistryLike(proxyRegistry).build(dst);
        }
        // Transfers CDP to the dst proxy
        give(manager, cdp, proxy);
    }

    function cdpAllow(
        address manager,
        uint cdp,
        address usr,
        uint ok
    ) public {
        ManagerLike(manager).cdpAllow(cdp, usr, ok);
    }

    function urnAllow(
        address manager,
        address usr,
        uint ok
    ) public {
        ManagerLike(manager).urnAllow(usr, ok);
    }

    function flux(
        address manager,
        uint cdp,
        address dst,
        uint wad
    ) public {
        ManagerLike(manager).flux(cdp, dst, wad);
    }

    function move(
        address manager,
        uint cdp,
        address dst,
        uint rad
    ) public {
        ManagerLike(manager).move(cdp, dst, rad);
    }

    function frob(
        address manager,
        uint cdp,
        int dink,
        int dart
    ) public {
        ManagerLike(manager).frob(cdp, dink, dart);
    }

    function quit(
        address manager,
        uint cdp,
        address dst
    ) public {
        ManagerLike(manager).quit(cdp, dst);
    }

    function enter(
        address manager,
        address src,
        uint cdp
    ) public {
        ManagerLike(manager).enter(src, cdp);
    }

    function shift(
        address manager,
        uint cdpSrc,
        uint cdpOrg
    ) public {
        ManagerLike(manager).shift(cdpSrc, cdpOrg);
    }

    function makeGemBag(
        address gemJoin
    ) public returns (address bag) {
        bag = GNTJoinLike(gemJoin).make(address(this));
    }

    function lockVLX(
        address manager,
        address vlxJoin,
        uint cdp
    ) public payable {
        // Receives VLX amount, converts it to WVLX and joins it into the vat
        vlxJoin_join(vlxJoin, address(this));
        // Locks WVLX amount into the CDP
        VatLike(ManagerLike(manager).vat()).frob(
            ManagerLike(manager).ilks(cdp),
            ManagerLike(manager).urns(cdp),
            address(this),
            address(this),
            toInt(msg.value),
            0
        );
    }

    function safeLockVLX(
        address manager,
        address vlxJoin,
        uint cdp,
        address owner
    ) public payable {
        require(ManagerLike(manager).owns(cdp) == owner, "owner-missmatch");
        lockVLX(manager, vlxJoin, cdp);
    }

    function lockGem(
        address manager,
        address gemJoin,
        uint cdp,
        uint amt,
        bool transferFrom
    ) public {
        // Takes token amount from user's wallet and joins into the vat
        gemJoin_join(gemJoin, address(this), amt, transferFrom);
        // Locks token amount into the CDP
        VatLike(ManagerLike(manager).vat()).frob(
            ManagerLike(manager).ilks(cdp),
            ManagerLike(manager).urns(cdp),
            address(this),
            address(this),
            toInt(convertTo18(gemJoin, amt)),
            0
        );
    }

    function safeLockGem(
        address manager,
        address gemJoin,
        uint cdp,
        uint amt,
        bool transferFrom,
        address owner
    ) public {
        require(ManagerLike(manager).owns(cdp) == owner, "owner-missmatch");
        lockGem(manager, gemJoin, cdp, amt, transferFrom);
    }

    function freeVLX(
        address manager,
        address vlxJoin,
        uint cdp,
        uint wad
    ) public {
        // Unlocks WVLX amount from the CDP
        frob(manager, cdp, -toInt(wad), 0);
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wad);
        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wad);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wad);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wad);
    }

    function freeGem(
        address manager,
        address gemJoin,
        uint cdp,
        uint amt
    ) public {
        uint wad = convertTo18(gemJoin, amt);
        // Unlocks token amount from the CDP
        frob(manager, cdp, -toInt(wad), 0);
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wad);
        // Exits token amount to the user's wallet as a token
        GemJoinLike(gemJoin).exit(msg.sender, amt);
    }

    function exitVLX(
        address manager,
        address vlxJoin,
        uint cdp,
        uint wad
    ) public {
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wad);

        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wad);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wad);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wad);
    }

    function exitGem(
        address manager,
        address gemJoin,
        uint cdp,
        uint amt
    ) public {
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), convertTo18(gemJoin, amt));

        // Exits token amount to the user's wallet as a token
        GemJoinLike(gemJoin).exit(msg.sender, amt);
    }

    function draw(
        address manager,
        address jug,
        address usdvJoin,
        uint cdp,
        uint wad
    ) public {
        address urn = ManagerLike(manager).urns(cdp);
        address vat = ManagerLike(manager).vat();
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        // Generates debt in the CDP
        frob(manager, cdp, 0, _getDrawDart(vat, jug, urn, ilk, wad));
        // Moves the USDV amount (balance in the vat in rad) to proxy's address
        move(manager, cdp, address(this), toRad(wad));
        // Allows adapter to access to proxy's USDV balance in the vat
        if (VatLike(vat).can(address(this), address(usdvJoin)) == 0) {
            VatLike(vat).hope(usdvJoin);
        }
        // Exits USDV to the user's wallet as a token
        UsdvJoinLike(usdvJoin).exit(msg.sender, wad);
    }

    function wipe(
        address manager,
        address usdvJoin,
        uint cdp,
        uint wad
    ) public {
        address vat = ManagerLike(manager).vat();
        address urn = ManagerLike(manager).urns(cdp);
        bytes32 ilk = ManagerLike(manager).ilks(cdp);

        address own = ManagerLike(manager).owns(cdp);
        if (own == address(this) || ManagerLike(manager).cdpCan(own, cdp, address(this)) == 1) {
            // Joins USDV amount into the vat
            usdvJoin_join(usdvJoin, urn, wad);
            // Paybacks debt to the CDP
            frob(manager, cdp, 0, _getWipeDart(vat, VatLike(vat).usdv(urn), urn, ilk));
        } else {
             // Joins USDV amount into the vat
            usdvJoin_join(usdvJoin, address(this), wad);
            // Paybacks debt to the CDP
            VatLike(vat).frob(
                ilk,
                urn,
                address(this),
                address(this),
                0,
                _getWipeDart(vat, wad * RAY, urn, ilk)
            );
        }
    }

    function safeWipe(
        address manager,
        address usdvJoin,
        uint cdp,
        uint wad,
        address owner
    ) public {
        require(ManagerLike(manager).owns(cdp) == owner, "owner-missmatch");
        wipe(manager, usdvJoin, cdp, wad);
    }

    function wipeAll(
        address manager,
        address usdvJoin,
        uint cdp
    ) public {
        address vat = ManagerLike(manager).vat();
        address urn = ManagerLike(manager).urns(cdp);
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        (, uint art) = VatLike(vat).urns(ilk, urn);

        address own = ManagerLike(manager).owns(cdp);
        if (own == address(this) || ManagerLike(manager).cdpCan(own, cdp, address(this)) == 1) {
            // Joins USDV amount into the vat
            usdvJoin_join(usdvJoin, urn, _getWipeAllWad(vat, urn, urn, ilk));
            // Paybacks debt to the CDP
            frob(manager, cdp, 0, -int(art));
        } else {
            // Joins USDV amount into the vat
            usdvJoin_join(usdvJoin, address(this), _getWipeAllWad(vat, address(this), urn, ilk));
            // Paybacks debt to the CDP
            VatLike(vat).frob(
                ilk,
                urn,
                address(this),
                address(this),
                0,
                -int(art)
            );
        }
    }

    function safeWipeAll(
        address manager,
        address usdvJoin,
        uint cdp,
        address owner
    ) public {
        require(ManagerLike(manager).owns(cdp) == owner, "owner-missmatch");
        wipeAll(manager, usdvJoin, cdp);
    }

    function lockVLXAndDraw(
        address manager,
        address jug,
        address vlxJoin,
        address usdvJoin,
        uint cdp,
        uint wadD
    ) public payable {
        address urn = ManagerLike(manager).urns(cdp);
        address vat = ManagerLike(manager).vat();
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        // Receives VLX amount, converts it to WVLX and joins it into the vat
        vlxJoin_join(vlxJoin, urn);
        // Locks WVLX amount into the CDP and generates debt
        frob(manager, cdp, toInt(msg.value), _getDrawDart(vat, jug, urn, ilk, wadD));
        // Moves the USDV amount (balance in the vat in rad) to proxy's address
        move(manager, cdp, address(this), toRad(wadD));
        // Allows adapter to access to proxy's USDV balance in the vat
        if (VatLike(vat).can(address(this), address(usdvJoin)) == 0) {
            VatLike(vat).hope(usdvJoin);
        }
        // Exits USDV to the user's wallet as a token
        UsdvJoinLike(usdvJoin).exit(msg.sender, wadD);
    }

    function openLockVLXAndDraw(
        address manager,
        address jug,
        address vlxJoin,
        address usdvJoin,
        bytes32 ilk,
        uint wadD
    ) public payable returns (uint cdp) {
        cdp = open(manager, ilk, address(this));
        lockVLXAndDraw(manager, jug, vlxJoin, usdvJoin, cdp, wadD);
    }

    function lockGemAndDraw(
        address manager,
        address jug,
        address gemJoin,
        address usdvJoin,
        uint cdp,
        uint amtC,
        uint wadD,
        bool transferFrom
    ) public {
        address urn = ManagerLike(manager).urns(cdp);
        address vat = ManagerLike(manager).vat();
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        // Takes token amount from user's wallet and joins into the vat
        gemJoin_join(gemJoin, urn, amtC, transferFrom);
        // Locks token amount into the CDP and generates debt
        frob(manager, cdp, toInt(convertTo18(gemJoin, amtC)), _getDrawDart(vat, jug, urn, ilk, wadD));
        // Moves the USDV amount (balance in the vat in rad) to proxy's address
        move(manager, cdp, address(this), toRad(wadD));
        // Allows adapter to access to proxy's USDV balance in the vat
        if (VatLike(vat).can(address(this), address(usdvJoin)) == 0) {
            VatLike(vat).hope(usdvJoin);
        }
        // Exits USDV to the user's wallet as a token
        UsdvJoinLike(usdvJoin).exit(msg.sender, wadD);
    }

    function openLockGemAndDraw(
        address manager,
        address jug,
        address gemJoin,
        address usdvJoin,
        bytes32 ilk,
        uint amtC,
        uint wadD,
        bool transferFrom
    ) public returns (uint cdp) {
        cdp = open(manager, ilk, address(this));
        lockGemAndDraw(manager, jug, gemJoin, usdvJoin, cdp, amtC, wadD, transferFrom);
    }

    function openLockGNTAndDraw(
        address manager,
        address jug,
        address gntJoin,
        address usdvJoin,
        bytes32 ilk,
        uint amtC,
        uint wadD
    ) public returns (address bag, uint cdp) {
        // Creates bag (if doesn't exist) to hold GNT
        bag = GNTJoinLike(gntJoin).bags(address(this));
        if (bag == address(0)) {
            bag = makeGemBag(gntJoin);
        }
        // Transfer funds to the funds which previously were sent to the proxy
        GemLike(GemJoinLike(gntJoin).gem()).transfer(bag, amtC);
        cdp = openLockGemAndDraw(manager, jug, gntJoin, usdvJoin, ilk, amtC, wadD, false);
    }

    function wipeAndFreeVLX(
        address manager,
        address vlxJoin,
        address usdvJoin,
        uint cdp,
        uint wadC,
        uint wadD
    ) public {
        address urn = ManagerLike(manager).urns(cdp);
        // Joins USDV amount into the vat
        usdvJoin_join(usdvJoin, urn, wadD);
        // Paybacks debt to the CDP and unlocks WVLX amount from it
        frob(
            manager,
            cdp,
            -toInt(wadC),
            _getWipeDart(ManagerLike(manager).vat(), VatLike(ManagerLike(manager).vat()).usdv(urn), urn, ManagerLike(manager).ilks(cdp))
        );
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wadC);
        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wadC);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wadC);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wadC);
    }

    function wipeAllAndFreeVLX(
        address manager,
        address vlxJoin,
        address usdvJoin,
        uint cdp,
        uint wadC
    ) public {
        address vat = ManagerLike(manager).vat();
        address urn = ManagerLike(manager).urns(cdp);
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        (, uint art) = VatLike(vat).urns(ilk, urn);

        // Joins USDV amount into the vat
        usdvJoin_join(usdvJoin, urn, _getWipeAllWad(vat, urn, urn, ilk));
        // Paybacks debt to the CDP and unlocks WVLX amount from it
        frob(
            manager,
            cdp,
            -toInt(wadC),
            -int(art)
        );
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wadC);
        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wadC);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wadC);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wadC);
    }

    function wipeAndFreeGem(
        address manager,
        address gemJoin,
        address usdvJoin,
        uint cdp,
        uint amtC,
        uint wadD
    ) public {
        address urn = ManagerLike(manager).urns(cdp);
        // Joins USDV amount into the vat
        usdvJoin_join(usdvJoin, urn, wadD);
        uint wadC = convertTo18(gemJoin, amtC);
        // Paybacks debt to the CDP and unlocks token amount from it
        frob(
            manager,
            cdp,
            -toInt(wadC),
            _getWipeDart(ManagerLike(manager).vat(), VatLike(ManagerLike(manager).vat()).usdv(urn), urn, ManagerLike(manager).ilks(cdp))
        );
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wadC);
        // Exits token amount to the user's wallet as a token
        GemJoinLike(gemJoin).exit(msg.sender, amtC);
    }

    function wipeAllAndFreeGem(
        address manager,
        address gemJoin,
        address usdvJoin,
        uint cdp,
        uint amtC
    ) public {
        address vat = ManagerLike(manager).vat();
        address urn = ManagerLike(manager).urns(cdp);
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        (, uint art) = VatLike(vat).urns(ilk, urn);

        // Joins USDV amount into the vat
        usdvJoin_join(usdvJoin, urn, _getWipeAllWad(vat, urn, urn, ilk));
        uint wadC = convertTo18(gemJoin, amtC);
        // Paybacks debt to the CDP and unlocks token amount from it
        frob(
            manager,
            cdp,
            -toInt(wadC),
            -int(art)
        );
        // Moves the amount from the CDP urn to proxy's address
        flux(manager, cdp, address(this), wadC);
        // Exits token amount to the user's wallet as a token
        GemJoinLike(gemJoin).exit(msg.sender, amtC);
    }
}

contract DssProxyActionsEnd is Common {
    // Internal functions

    function _free(
        address manager,
        address end,
        uint cdp
    ) internal returns (uint ink) {
        bytes32 ilk = ManagerLike(manager).ilks(cdp);
        address urn = ManagerLike(manager).urns(cdp);
        VatLike vat = VatLike(ManagerLike(manager).vat());
        uint art;
        (ink, art) = vat.urns(ilk, urn);

        // If CDP still has debt, it needs to be paid
        if (art > 0) {
            EndLike(end).skim(ilk, urn);
            (ink,) = vat.urns(ilk, urn);
        }
        // Approves the manager to transfer the position to proxy's address in the vat
        if (vat.can(address(this), address(manager)) == 0) {
            vat.hope(manager);
        }
        // Transfers position from CDP to the proxy address
        ManagerLike(manager).quit(cdp, address(this));
        // Frees the position and recovers the collateral in the vat registry
        EndLike(end).free(ilk);
    }

    // Public functions
    function freeVLX(
        address manager,
        address vlxJoin,
        address end,
        uint cdp
    ) public {
        uint wad = _free(manager, end, cdp);
        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wad);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wad);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wad);
    }

    function freeGem(
        address manager,
        address gemJoin,
        address end,
        uint cdp
    ) public {
        uint amt = _free(manager, end, cdp) / 10 ** (18 - GemJoinLike(gemJoin).dec());
        // Exits token amount to the user's wallet as a token
        GemJoinLike(gemJoin).exit(msg.sender, amt);
    }

    function pack(
        address usdvJoin,
        address end,
        uint wad
    ) public {
        usdvJoin_join(usdvJoin, address(this), wad);
        VatLike vat = UsdvJoinLike(usdvJoin).vat();
        // Approves the end to take out USDV from the proxy's balance in the vat
        if (vat.can(address(this), address(end)) == 0) {
            vat.hope(end);
        }
        EndLike(end).pack(wad);
    }

    function cashVLX(
        address vlxJoin,
        address end,
        bytes32 ilk,
        uint wad
    ) public {
        EndLike(end).cash(ilk, wad);
        uint wadC = mul(wad, EndLike(end).fix(ilk)) / RAY;
        // Exits WVLX amount to proxy address as a token
        GemJoinLike(vlxJoin).exit(address(this), wadC);
        // Converts WVLX to VLX
        GemJoinLike(vlxJoin).gem().withdraw(wadC);
        // Sends VLX back to the user's wallet
        msg.sender.transfer(wadC);
    }

    function cashGem(
        address gemJoin,
        address end,
        bytes32 ilk,
        uint wad
    ) public {
        EndLike(end).cash(ilk, wad);
        // Exits token amount to the user's wallet as a token
        uint amt = mul(wad, EndLike(end).fix(ilk)) / RAY / 10 ** (18 - GemJoinLike(gemJoin).dec());
        GemJoinLike(gemJoin).exit(msg.sender, amt);
    }
}

contract DssProxyActionsDsr is Common {
    function join(
        address usdvJoin,
        address pot,
        uint wad
    ) public {
        VatLike vat = UsdvJoinLike(usdvJoin).vat();
        // Executes drip to get the chi rate updated to rho == now, otherwise join will fail
        uint chi = PotLike(pot).drip();
        // Joins wad amount to the vat balance
        usdvJoin_join(usdvJoin, address(this), wad);
        // Approves the pot to take out USDV from the proxy's balance in the vat
        if (vat.can(address(this), address(pot)) == 0) {
            vat.hope(pot);
        }
        // Joins the pie value (equivalent to the USDV wad amount) in the pot
        PotLike(pot).join(mul(wad, RAY) / chi);
    }

    function exit(
        address usdvJoin,
        address pot,
        uint wad
    ) public {
        VatLike vat = UsdvJoinLike(usdvJoin).vat();
        // Executes drip to count the savings accumulated until this moment
        uint chi = PotLike(pot).drip();
        // Calculates the pie value in the pot equivalent to the USDV wad amount
        uint pie = mul(wad, RAY) / chi;
        // Exits USDV from the pot
        PotLike(pot).exit(pie);
        // Checks the actual balance of USDV in the vat after the pot exit
        uint bal = UsdvJoinLike(usdvJoin).vat().usdv(address(this));
        // Allows adapter to access to proxy's USDV balance in the vat
        if (vat.can(address(this), address(usdvJoin)) == 0) {
            vat.hope(usdvJoin);
        }
        // It is necessary to check if due rounding the exact wad amount can be exited by the adapter.
        // Otherwise it will do the maximum USDV balance in the vat
        UsdvJoinLike(usdvJoin).exit(
            msg.sender,
            bal >= mul(wad, RAY) ? wad : bal / RAY
        );
    }

    function exitAll(
        address usdvJoin,
        address pot
    ) public {
        VatLike vat = UsdvJoinLike(usdvJoin).vat();
        // Executes drip to count the savings accumulated until this moment
        uint chi = PotLike(pot).drip();
        // Gets the total pie belonging to the proxy address
        uint pie = PotLike(pot).pie(address(this));
        // Exits USDV from the pot
        PotLike(pot).exit(pie);
        // Allows adapter to access to proxy's USDV balance in the vat
        if (vat.can(address(this), address(usdvJoin)) == 0) {
            vat.hope(usdvJoin);
        }
        // Exits the USDV amount corresponding to the value of pie
        UsdvJoinLike(usdvJoin).exit(msg.sender, mul(chi, pie) / RAY);
    }
}
        

Contract ABI

[{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"exit","inputs":[{"type":"address","name":"usdvJoin","internalType":"address"},{"type":"address","name":"pot","internalType":"address"},{"type":"uint256","name":"wad","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"exitAll","inputs":[{"type":"address","name":"usdvJoin","internalType":"address"},{"type":"address","name":"pot","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"join","inputs":[{"type":"address","name":"usdvJoin","internalType":"address"},{"type":"address","name":"pot","internalType":"address"},{"type":"uint256","name":"wad","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"usdvJoin_join","inputs":[{"type":"address","name":"apt","internalType":"address"},{"type":"address","name":"urn","internalType":"address"},{"type":"uint256","name":"wad","internalType":"uint256"}],"constant":false}]
            

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061004c5760003560e01c8063388bdc7a1461005157806371006c09146100895780639f6c3dbd146100bf578063c77843b3146100f5575b600080fd5b6100876004803603606081101561006757600080fd5b506001600160a01b03813581169160208101359091169060400135610123565b005b6100876004803603606081101561009f57600080fd5b506001600160a01b03813581169160208101359091169060400135610346565b610087600480360360608110156100d557600080fd5b506001600160a01b03813581169160208101359091169060400135610729565b6100876004803603604081101561010b57600080fd5b506001600160a01b0381358116916020013516610986565b826001600160a01b0316639420069c6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561015e57600080fd5b505af1158015610172573d6000803e3d6000fd5b505050506040513d602081101561018857600080fd5b5051604080516323b872dd60e01b81523360048201523060248201526044810184905290516001600160a01b03909216916323b872dd9160648082019260009290919082900301818387803b1580156101e057600080fd5b505af11580156101f4573d6000803e3d6000fd5b50505050826001600160a01b0316639420069c6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561023357600080fd5b505af1158015610247573d6000803e3d6000fd5b505050506040513d602081101561025d57600080fd5b50516040805163095ea7b360e01b81526001600160a01b038681166004830152602482018590529151919092169163095ea7b391604480830192600092919082900301818387803b1580156102b157600080fd5b505af11580156102c5573d6000803e3d6000fd5b50505050826001600160a01b0316633b4da69f83836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561032957600080fd5b505af115801561033d573d6000803e3d6000fd5b50505050505050565b6000836001600160a01b03166336569e776040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561038357600080fd5b505af1158015610397573d6000803e3d6000fd5b505050506040513d60208110156103ad57600080fd5b505160408051634fb3c66560e11b815290519192506000916001600160a01b03861691639f678cca91600480830192602092919082900301818787803b1580156103f657600080fd5b505af115801561040a573d6000803e3d6000fd5b505050506040513d602081101561042057600080fd5b5051905060008161043d856b033b2e3c9fd0803ce8000000610cad565b8161044457fe5b049050846001600160a01b0316637f8661a1826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561048d57600080fd5b505af11580156104a1573d6000803e3d6000fd5b505050506000866001600160a01b03166336569e776040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156104e257600080fd5b505af11580156104f6573d6000803e3d6000fd5b505050506040513d602081101561050c57600080fd5b5051604080516334b482e560e01b815230600482015290516001600160a01b03909216916334b482e591602480820192602092909190829003018186803b15801561055657600080fd5b505afa15801561056a573d6000803e3d6000fd5b505050506040513d602081101561058057600080fd5b505160408051634538c4eb60e01b81523060048201526001600160a01b038a81166024830152915192935090861691634538c4eb91604480820192602092909190829003018186803b1580156105d557600080fd5b505afa1580156105e9573d6000803e3d6000fd5b505050506040513d60208110156105ff57600080fd5b505161067657836001600160a01b031663a3b22fc4886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b15801561065d57600080fd5b505af1158015610671573d6000803e3d6000fd5b505050505b866001600160a01b031663ef693bed3361069c886b033b2e3c9fd0803ce8000000610cad565b8410156106b7576b033b2e3c9fd0803ce800000084046106b9565b875b6040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561070857600080fd5b505af115801561071c573d6000803e3d6000fd5b5050505050505050505050565b6000836001600160a01b03166336569e776040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561076657600080fd5b505af115801561077a573d6000803e3d6000fd5b505050506040513d602081101561079057600080fd5b505160408051634fb3c66560e11b815290519192506000916001600160a01b03861691639f678cca91600480830192602092919082900301818787803b1580156107d957600080fd5b505af11580156107ed573d6000803e3d6000fd5b505050506040513d602081101561080357600080fd5b50519050610812853085610123565b60408051634538c4eb60e01b81523060048201526001600160a01b038681166024830152915191841691634538c4eb91604480820192602092909190829003018186803b15801561086257600080fd5b505afa158015610876573d6000803e3d6000fd5b505050506040513d602081101561088c57600080fd5b505161090357816001600160a01b031663a3b22fc4856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b1580156108ea57600080fd5b505af11580156108fe573d6000803e3d6000fd5b505050505b836001600160a01b031663049878f382610929866b033b2e3c9fd0803ce8000000610cad565b8161093057fe5b046040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561096757600080fd5b505af115801561097b573d6000803e3d6000fd5b505050505050505050565b6000826001600160a01b03166336569e776040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156109c357600080fd5b505af11580156109d7573d6000803e3d6000fd5b505050506040513d60208110156109ed57600080fd5b505160408051634fb3c66560e11b815290519192506000916001600160a01b03851691639f678cca91600480830192602092919082900301818787803b158015610a3657600080fd5b505af1158015610a4a573d6000803e3d6000fd5b505050506040513d6020811015610a6057600080fd5b5051604080516305f5d64360e11b815230600482015290519192506000916001600160a01b03861691630bebac86916024808301926020929190829003018186803b158015610aae57600080fd5b505afa158015610ac2573d6000803e3d6000fd5b505050506040513d6020811015610ad857600080fd5b505160408051637f8661a160e01b81526004810183905290519192506001600160a01b03861691637f8661a19160248082019260009290919082900301818387803b158015610b2657600080fd5b505af1158015610b3a573d6000803e3d6000fd5b505060408051634538c4eb60e01b81523060048201526001600160a01b03898116602483015291519187169350634538c4eb9250604480820192602092909190829003018186803b158015610b8e57600080fd5b505afa158015610ba2573d6000803e3d6000fd5b505050506040513d6020811015610bb857600080fd5b5051610c2f57826001600160a01b031663a3b22fc4866040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b158015610c1657600080fd5b505af1158015610c2a573d6000803e3d6000fd5b505050505b846001600160a01b031663ef693bed336b033b2e3c9fd0803ce8000000610c568686610cad565b81610c5d57fe5b046040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561096757600080fd5b6000811580610cc857505080820282828281610cc557fe5b04145b610d08576040805162461bcd60e51b815260206004820152600c60248201526b6d756c2d6f766572666c6f7760a01b604482015290519081900360640190fd5b9291505056fea265627a7a72315820f7a8c0efc92261cdd71e6e119f84c86157761bbf292475ecf91535a5b21d4b6e64736f6c634300050c0032