ETH Price: $2,444.40 (+0.88%)

Transaction Decoder

Block:
11704651 at Jan-22-2021 10:03:11 AM +UTC
Transaction Fee:
0.08333896 ETH $203.71
Gas Used:
1,041,737 Gas / 80 Gwei

Account State Difference:

  Address   Before After State Difference Code
(2Miners: PPLNS)
359.32282455555343282 Eth359.40616351555343282 Eth0.08333896
0x16CC37d0...AbB396A2b
2.0102096 Eth
Nonce: 14
1.92687064 Eth
Nonce: 15
0.08333896
0x72d220cE...AD8598f6C
(DODO: Vending Machine Factory)
0 Eth
Nonce: 0
0 Eth
Nonce: 1
From: 0 To: 2120993065236128854363807625810114104870330044173451237787850064461944395652640216169254974749973234251951702049001727832160166475020983740549551387822272680783387401822488157792688428190379174009409050866475407360013428944093081759997666140709385446509107656340036053188261737899838773498978294427720544712918450836007782914714710725387625693402398891271303413641706272457008172720180944556870059212787455757301989058943367682580840993108809837254850510707592956686304652807901246573177798271420518937292121261321610630844172865211849115813321265874631197480034175080474430731919230666867437511013089752126484712871409410310755927022898596547237375991579973097270532862339278352435868994573465299201626564579997846172632724312691311515425239846699558404046745472591577002429661084159537689947387407829266081835625351175693023743907810919986769539021286411859046345734990321100460554549370601535573780523696190238161438379836631847079621961653202558252502296794820418265211518896061180917582806446341892538473483119054584880737987824152851817170022565889696694327379981313971193993883242587906231181621457859307753279675547399745726196785305937915813960565128019363095394903466778637313435123732847971471358831097083345722234026433822472024991502583079445062719960024174499961748077752199070941562992192085742457140996261101635875248062568783958355764215022314588702412565043114290132042168076724328376402627386878927047206999075503859555465932559732940171335868143669274675395871409757963870202749430517149754844874641880292411253389171478410781799352823138761780739109079379036952117103731088852645886657759130588230200796084607519748309968639741496808188570421939696288440929093915728889422007626528444653652204220938400546440877651520750291425378887953407915039453297209251839130486903838021605279857440844655726450780080558952893819002856033367062282767709559130402001546151392208568518619179886828777660132043488817294728392286881824693843099631018295695462674829604063489976843214699903053983838529157318979273703756783744539713491526631443030958036391607998693415761621612920865563370676685066746569045043791379934456519386831253929612752608807769108754618046472906108011633569219111465553166483938287922674481987092794896983826251131091500175401455925041798056327562752423401716102584724869661557038391798247787962066296305584564373569881147170947093344465052980701973981907730306858398975779798149196936278153668263610110249395707244056816713591525259054968405197360421316479440742623564757858773598641690035036072797761483100504681182521469295619915925718725622928389538082933145600459936534066209824104946951940767189162849207762926698776231112012081573937807224065894191983744202910475582583104699518921431195981754565041686580444389700819740436477909740697330889068921405739522920350424001380401879997136700232470798074106892613462225898539544974817786378256787287087162877766004400546557803200697724916565539692070146473155850458089189586229069965595517034543295790776967699329833586932633002069946628206663628986972469249882735710033402253238532134537524176268490876236144571852548642131770664476099334950426115926329233206631592283857189027836212725660730950961379821247569949876756670879078953965632764512897410505202225114214288060237917472133475932114067118800193697008732110060279281816048613205370751571159784638010651707026797346927115217072393408062008435231684462654096556788026668613998959956782523308483491121316012051515195450576088271168276695155384781603895624299343446542732764094639374412629095946783330077936378264101708546580320975626494791748762553172532678905576383548137467873336356849911605073764680898051983248419477114755272393529250335658498312282171539727492696092110295555364139297642670648210802639805378401658733064209079654017855281235787111248431070603520171361872367709125490309934745092210133604274839837777541842097801999439334763175005511049954731981250871651248531121968235566198306424519727329128592163543220099015239078869593904312668862085853744176101817440897910460666646723790833811661033480247804612944800535872738718642050972420235174146465233655014430528833090004088860031665541848151434131489210460988634093268835668114080513879841683463683154390068485549358025447838500012450536141421637770106304342246166071658197449954384065052298832050078346357180510270597515202899969463531358908645048196460268806768321145702460712826559894827306611952661565745301282045745770073377703303790486948299977189067230489712225014363215875339225347228214557352162994164290840525214182689103616036906505001686774586128027666148423491868440785563686962173949811981165681569812682657794529991572130700906570506611318654573868579690639995797407792324064377406122512225066943899472503438689260832313398319248349953833258291162961512552104843122939671572380267490831540296221795200062717408750500223789475119122900240180189092891134782382594795107286415014772274630139943867448248230035386843425100705916416708696341688911722377102536996094549863479228780819313674583515037437454128690507537162979082430419628535297932680805016522825278014691836714264858717636237075898916455305644986868043465122308979679194981594053802662763877155144237216880203282496628192727417243604562399359028283723241646620576459222437795717878774413080498266347914981271310709436926490500244884183523908677572455484323316623928221739190555280167815848396999110726666981894935696209871988162198909580561366361101149251119821256475293135460107119321838080777936275339479916945477486845665877771518629402477322943565568392698725428855647460973789012731497451729112152279131725392601924913820594593862934196206726948162842384501802397860072713826391541200679027347055198941328444203894992839760249954857880410431076443539666069406765637047530827202305107570251813613593888241528605243158546425622740753608844459244094044890042802817968171386857840584584467494619077618395914840629730934590510309298641138412000111822889509635032530731275886973350592932959810381407321781609360957319166514418664801132635680105659814833031537574995570488512635142792809988603463359922706455535275035945410736962831235776570852587498112280658199631216310010184215500340807552886760336516774869842532843642248973469926747396479344170583868648028359712609471176954601581828321267273759928330332579268655429803294296445368416352307224921372763949080592098509241782719719012816486054680990860192356071129382039974843837007975531982222803477988276283524504896567132602483630748974508027127720328212466032267506317115578704365267535765277925919280252552187284956248226926816654971831695655757951470166989341124127484109890398951528532960580587245245988981148666948162253306728537980366468767674463487530156829343126575800805732166948697907368982195145834898565030905340940288885953095800141205935050573214081598290621869029765627995180800495096275697375029508755431933687237341902355946272400900200394089818012831550964576832301771345097376262635812566881271305857225277280741470653614485777523202352705420764308403342489363471869606834489540749737323587038192258492365604856676236301181951411366988221154092542445396118266638575879611964960515723708692480523979788509849521792819728959910963254962396272183237837789398123580902727056153581389685380201706655671268232206198981029813183426862241164252779161755490686027429078194954073123780226697355028159017013908735839166561962497335673826137288517414965569479679374823382184317280190025164334986198589987918574733140474526139994639845245831193107368428809742566949521743116890243725393363484325877895389066209880146929060282622530518746661477253991779083032511275481383956483646098904338306718245002673627673470226140408124522696720884552247402007179394951494053657924139529795427415627544389657130569128220159996965149792301075062332563868037255136573806526887444417571005484644511203690937023807513630991059196015160951731171919895947895491583836462133233116953510106003118449638713705640168961627167745122958613116387135323756479096646272324952853785443027999469756871460106676913741857177112723167916210505451145969365695295051781879986899928543888830712501128851353744056303323202945258746321874056048192960141446173908765490814400546393680802386186735768177414830004029570522958139955617237533531324716191725516859375560883308789028552566478833026143576375782761409933276349274949485296445822525484521459068141271870012689345331603005337959749353621604072558041510131584082561783824977566090871404386484648691470162190701700235567353728695968501624344150537078180117867679852275330969570851588409261780302287861126301359785000455574496053703919908258657014122149687431500089594496875939642046057747003917250309976121862629354093156891781054317281343455090706183720480183504149230758138141775859888529138952151878067886449517091696478312385208533979547516166169185428710377493495066838682741998189194702804439501334966718886394057436294823660672859590816545890254362021565360423570185130054322044513924236475981326744242078892562640387053242493900295244838486548405096038906698730383006347348927715166582225975093927009565845824684186043344505460092246676086737205423259962285257995616595716241986742857831365678737038300146896730193134178387481516796391303388497795728060399230837222041723758049340917260530087551594655065575589778979553997573724800358728964493851367844786111648978485664230024846901903437664000627144921984771197034491098755095062513289696715036708751935717120665889841241857792005594760095774290132031717071604035613597778740779104228999232766957941739392322788686494333844577270980616283851107889070208384034667079144250986027088524544912326212581634608147336609193738069900257363391284588449006526723386361999774780548229135234125620016749661509455765995119195627117283056159303625046780827307843427085854737871883477864456319701630568675542227776246462195193682554557698893537364036938446279509121901619080124863960121099273220390147260508945235377290965490777285284897101786188657234341669147690182314547919935892049371747812344539068241224884715368042896916429357127946967178536250756971835672007537945808235863316841894337083618773143979093915349110497674149118521688492549426502394615243579781100125913920775021636902005399704306617337847548153096631307246552422937592531874009765883311361525789211973096155515348873198162247216090372489253680879650789974013150553340453476561623110393425482167627696966705645615498569217934052510359100171411007270373678923829575995286148033984544247544153171867349026293669598847354986412082393872057269638495349353938242778607510524219027122487601682889875086863186326654829638002081008882193663894675311429092034876132480745937931081005810728301401381952853125993488662590081881950936683688838638388275411127092805296976311769604096051

Execution Trace

DVMFactory.60e06040( )
// File: contracts/lib/InitializableOwnable.sol

/*

    Copyright 2020 DODO ZOO.
    SPDX-License-Identifier: Apache-2.0

*/

pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;

/**
 * @title Ownable
 * @author DODO Breeder
 *
 * @notice Ownership related functions
 */
contract InitializableOwnable {
    address public _OWNER_;
    address public _NEW_OWNER_;
    bool internal _INITIALIZED_;

    // ============ Events ============

    event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    // ============ Modifiers ============

    modifier notInitialized() {
        require(!_INITIALIZED_, "DODO_INITIALIZED");
        _;
    }

    modifier onlyOwner() {
        require(msg.sender == _OWNER_, "NOT_OWNER");
        _;
    }

    // ============ Functions ============

    function initOwner(address newOwner) public notInitialized {
        _INITIALIZED_ = true;
        _OWNER_ = newOwner;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        emit OwnershipTransferPrepared(_OWNER_, newOwner);
        _NEW_OWNER_ = newOwner;
    }

    function claimOwnership() public {
        require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
        emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
        _OWNER_ = _NEW_OWNER_;
        _NEW_OWNER_ = address(0);
    }
}

// File: contracts/lib/CloneFactory.sol


interface ICloneFactory {
    function clone(address prototype) external returns (address proxy);
}

// introduction of proxy mode design: https://docs.openzeppelin.com/upgrades/2.8/
// minimum implementation of transparent proxy: https://eips.ethereum.org/EIPS/eip-1167

contract CloneFactory is ICloneFactory {
    function clone(address prototype) external override returns (address proxy) {
        bytes20 targetBytes = bytes20(prototype);
        assembly {
            let clone := mload(0x40)
            mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(clone, 0x14), targetBytes)
            mstore(
                add(clone, 0x28),
                0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
            )
            proxy := create(0, clone, 0x37)
        }
        return proxy;
    }
}

// File: contracts/DODOVendingMachine/intf/IDVM.sol

interface IDVM {
    function init(
        address maintainer,
        address baseTokenAddress,
        address quoteTokenAddress,
        uint256 lpFeeRate,
        address mtFeeRateModel,
        uint256 i,
        uint256 k,
        bool isOpenTWAP
    ) external;

    function _BASE_TOKEN_() external returns (address);

    function _QUOTE_TOKEN_() external returns (address);

    function _MT_FEE_RATE_MODEL_() external returns (address);

    function getVaultReserve() external returns (uint256 baseReserve, uint256 quoteReserve);

    function sellBase(address to) external returns (uint256);

    function sellQuote(address to) external returns (uint256);

    function buyShares(address to) external returns (uint256);

}

// File: contracts/Factory/DVMFactory.sol




interface IDVMFactory {
    function createDODOVendingMachine(
        address baseToken,
        address quoteToken,
        uint256 lpFeeRate,
        uint256 i,
        uint256 k,
        bool isOpenTWAP
    ) external returns (address newVendingMachine);
}


/**
 * @title DODO VendingMachine Factory
 * @author DODO Breeder
 *
 * @notice Create And Register DVM Pools 
 */
contract DVMFactory is InitializableOwnable {
    // ============ Templates ============

    address public immutable _CLONE_FACTORY_;
    address public immutable _DEFAULT_MAINTAINER_;
    address public immutable _DEFAULT_MT_FEE_RATE_MODEL_;
    address public _DVM_TEMPLATE_;

    // ============ Registry ============

    // base -> quote -> DVM address list
    mapping(address => mapping(address => address[])) public _REGISTRY_;
    // creator -> DVM address list
    mapping(address => address[]) public _USER_REGISTRY_;

    // ============ Events ============

    event NewDVM(
        address baseToken,
        address quoteToken,
        address creator,
        address dvm
    );

    event RemoveDVM(address dvm);

    // ============ Functions ============

    constructor(
        address cloneFactory,
        address dvmTemplate,
        address defaultMaintainer,
        address defaultMtFeeRateModel
    ) public {
        _CLONE_FACTORY_ = cloneFactory;
        _DVM_TEMPLATE_ = dvmTemplate;
        _DEFAULT_MAINTAINER_ = defaultMaintainer;
        _DEFAULT_MT_FEE_RATE_MODEL_ = defaultMtFeeRateModel;
    }

    function createDODOVendingMachine(
        address baseToken,
        address quoteToken,
        uint256 lpFeeRate,
        uint256 i,
        uint256 k,
        bool isOpenTWAP
    ) external returns (address newVendingMachine) {
        newVendingMachine = ICloneFactory(_CLONE_FACTORY_).clone(_DVM_TEMPLATE_);
        {
            IDVM(newVendingMachine).init(
                _DEFAULT_MAINTAINER_,
                baseToken,
                quoteToken,
                lpFeeRate,
                _DEFAULT_MT_FEE_RATE_MODEL_,
                i,
                k,
                isOpenTWAP
            );
        }
        _REGISTRY_[baseToken][quoteToken].push(newVendingMachine);
        _USER_REGISTRY_[tx.origin].push(newVendingMachine);
        emit NewDVM(baseToken, quoteToken, tx.origin, newVendingMachine);
    }

    // ============ Admin Operation Functions ============

    function updateDvmTemplate(address _newDVMTemplate) external onlyOwner {
        _DVM_TEMPLATE_ = _newDVMTemplate;
    }

    function addPoolByAdmin(
        address creator,
        address baseToken, 
        address quoteToken,
        address pool
    ) external onlyOwner {
        _REGISTRY_[baseToken][quoteToken].push(pool);
        _USER_REGISTRY_[creator].push(pool);
        emit NewDVM(baseToken, quoteToken, creator, pool);
    }

    function removePoolByAdmin(
        address creator,
        address baseToken, 
        address quoteToken,
        address pool
    ) external onlyOwner {
        address[] memory registryList = _REGISTRY_[baseToken][quoteToken];
        for (uint256 i = 0; i < registryList.length; i++) {
            if (registryList[i] == pool) {
                registryList[i] = registryList[registryList.length - 1];
                break;
            }
        }
        _REGISTRY_[baseToken][quoteToken] = registryList;
        _REGISTRY_[baseToken][quoteToken].pop();
        address[] memory userRegistryList = _USER_REGISTRY_[creator];
        for (uint256 i = 0; i < userRegistryList.length; i++) {
            if (userRegistryList[i] == pool) {
                userRegistryList[i] = userRegistryList[userRegistryList.length - 1];
                break;
            }
        }
        _USER_REGISTRY_[creator] = userRegistryList;
        _USER_REGISTRY_[creator].pop();
        emit RemoveDVM(pool);
    }

    // ============ View Functions ============

    function getDODOPool(address baseToken, address quoteToken)
        external
        view
        returns (address[] memory machines)
    {
        return _REGISTRY_[baseToken][quoteToken];
    }

    function getDODOPoolBidirection(address token0, address token1)
        external
        view
        returns (address[] memory baseToken0Machines, address[] memory baseToken1Machines)
    {
        return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
    }

    function getDODOPoolByUser(address user)
        external
        view
        returns (address[] memory machines)
    {
        return _USER_REGISTRY_[user];
    }
}