ETH Price: $2,531.43 (-8.21%)

Transaction Decoder

Block:
8311832 at Aug-08-2019 07:25:46 PM +UTC
Transaction Fee:
0.0005740372 ETH $1.45
Gas Used:
521,852 Gas / 1.1 Gwei

Emitted Events:

60 DSProxy.0x1cff79cd00000000000000000000000000000000000000000000000000000000( 0x1cff79cd00000000000000000000000000000000000000000000000000000000, 0x000000000000000000000000c1a0a697990d56af43fb7738da38b3c174e4e49d, 0x000000000000000000000000526af336d614ade5cc252a407062b8861af998f5, 0x0000000000000000000000000000000000000000000000000000000000000040, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 000000000000000000000000000000000000000000000000000000e41cff79cd, 000000000000000000000000526af336d614ade5cc252a407062b8861af998f5, 0000000000000000000000000000000000000000000000000000000000000040, 0000000000000000000000000000000000000000000000000000000000000064, 792037e3000000000000000000000000448a5065aebb8e423f0896e6c5d525c0, 40f59af300000000000000000000000000000000000000000000000000000000, 0000554400000000000000000000000039755357759ce0d7f32dc8dc45414cca, 409ae24e00000000000000000000000000000000000000000000000000000000 )
61 SaiTub.0xf7c8d63400000000000000000000000000000000000000000000000000000000( 0xf7c8d63400000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000024f7c8d634, 0000000000000000000000000000000000000000000000000000000000005544 )
62 DSToken.Transfer( src=[Sender] 0xc1a0a697990d56af43fb7738da38b3c174e4e49d, dst=[Receiver] DSProxy, wad=1331712353853118800 )
63 SaiTub.0x6f78ee0d00000000000000000000000000000000000000000000000000000000( 0x6f78ee0d00000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 000000000000000000000000000000000000000000000000000000246f78ee0d, 0000000000000000000000000000000000000000000000000000000000005544 )
64 SaiTub.0x6f78ee0d00000000000000000000000000000000000000000000000000000000( 0x6f78ee0d00000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 000000000000000000000000000000000000000000000000000000246f78ee0d, 0000000000000000000000000000000000000000000000000000000000005544 )
65 SaiTub.0xf7c8d63400000000000000000000000000000000000000000000000000000000( 0xf7c8d63400000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000024f7c8d634, 0000000000000000000000000000000000000000000000000000000000005544 )
66 DSToken.Approval( src=[Receiver] DSProxy, guy=MatchingMarket, wad=115792089237316195423570985008687907853269984665640564039457584007913129639935 )
67 DSToken.Transfer( src=[Sender] 0xc1a0a697990d56af43fb7738da38b3c174e4e49d, dst=[Receiver] DSProxy, wad=1950507916582691 )
68 DSToken.Transfer( src=[Receiver] DSProxy, dst=0xAe34FFe5BF622684a251A28D8a9b05bC8c850629, wad=1950507916582691 )
69 DSToken.Transfer( from=MatchingMarket, to=[Receiver] DSProxy, value=3568505401351 )
70 MatchingMarket.LogItemUpdate( id=380584 )
71 MatchingMarket.LogTake( id=000000000000000000000000000000000000000000000000000000000005CEA8, pair=7509DEDA9E17580C94915865C0C0C56190CC733E6C835A6CA2E497C1E4A50A5D, maker=0xAe34FFe5BF622684a251A28D8a9b05bC8c850629, pay_gem=DSToken, buy_gem=DSToken, taker=[Receiver] DSProxy, take_amt=3568505401351, give_amt=1950507916582691, timestamp=1565292346 )
72 MatchingMarket.LogTrade( pay_amt=3568505401351, pay_gem=DSToken, buy_amt=1950507916582691, buy_gem=DSToken )
73 DSToken.Approval( owner=[Receiver] DSProxy, spender=SaiTub, value=115792089237316195423570985008687907853269984665640564039457584007913129639935 )
74 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
75 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
76 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
77 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
78 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
79 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
80 SaiTub.0x73b3810100000000000000000000000000000000000000000000000000000000( 0x73b3810100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000127b3154826a1950, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 0000000000000000000000000000000000000000000000000000004473b38101, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000127b3154826a1950 )
81 DSToken.Burn( guy=[Receiver] DSProxy, wad=1331712353853118800 )
82 DSToken.Transfer( from=[Receiver] DSProxy, to=GemPit, value=3568505401351 )
83 SaiTub.0xa5cd184e00000000000000000000000000000000000000000000000000000000( 0xa5cd184e00000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000001d5a0a2d27bac9, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000044a5cd184e, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000001d5a0a2d27bac9 )
84 DSToken.Transfer( src=SaiTub, dst=[Receiver] DSProxy, wad=8261774078360265 )
85 SaiVox.0x495d32cb00000000000000000000000000000000000000000000000000000000( 0x495d32cb00000000000000000000000000000000000000000000000000000000, 0x000000000000000000000000448a5065aebb8e423f0896e6c5d525c040f59af3, 0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000004495d32cb )
86 SaiTub.0xa5cd184e00000000000000000000000000000000000000000000000000000000( 0xa5cd184e00000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x000000000000000000000000000000000000000000000000001d5a0a2d27bac9, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000044a5cd184e, 0000000000000000000000000000000000000000000000000000000000005544, 000000000000000000000000000000000000000000000000001d5a0a2d27bac9 )
87 SaiTub.0x7f8661a100000000000000000000000000000000000000000000000000000000( 0x7f8661a100000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x000000000000000000000000000000000000000000000000001d5a0a2d27bac9, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 000000000000000000000000000000000000000000000000000000247f8661a1, 000000000000000000000000000000000000000000000000001d5a0a2d27bac9 )
88 WETH9.Transfer( src=SaiTub, dst=[Receiver] DSProxy, wad=8617994960811948 )
89 DSToken.Burn( guy=[Receiver] DSProxy, wad=8261774078360265 )
90 WETH9.Withdrawal( src=[Receiver] DSProxy, wad=8617994960811948 )
91 SaiTub.0xb84d210600000000000000000000000000000000000000000000000000000000( 0xb84d210600000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000024b84d2106, 0000000000000000000000000000000000000000000000000000000000005544 )
92 SaiTub.0xb84d210600000000000000000000000000000000000000000000000000000000( 0xb84d210600000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000005bedda658d5ab7d216a1dcce6758e1a7a5005385, 0x0000000000000000000000000000000000000000000000000000000000005544, 0x0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000004000000000, 00000000000000000000000000000000000000000000000000000024b84d2106, 0000000000000000000000000000000000000000000000000000000000005544 )

Account State Difference:

  Address   Before After State Difference Code
0x39755357...a409AE24e
(Eth2Dai: Old Contract)
0x448a5065...040f59af3
(Sky: Contract 1)
(Spark Pool)
3,468.425282781022142483 Eth3,468.425856818222142483 Eth0.0005740372
0x89d24A6b...a23260359
0x9B0F70Df...EA77f2d7A
(Sky: Contract 3)
0x9f8F72aA...cC3A579A2
0xC02aaA39...83C756Cc2 1,640,870.67327758475838463 Eth1,640,870.664659589797572682 Eth0.008617994960811948
0xc1a0a697...174e4e49d
0.05154238123125 Eth
Nonce: 18
0.059586338992061948 Eth
Nonce: 19
0.008043957760811948
0xf53AD2c6...1B2321C09

Execution Trace

DSProxy.execute( _target=0x526af336D614adE5cc252A407062B8861aF998F5, _data=0x792037E3000000000000000000000000448A5065AEBB8E423F0896E6C5D525C040F59AF3000000000000000000000000000000000000000000000000000000000000554400000000000000000000000039755357759CE0D7F32DC8DC45414CCA409AE24E ) => ( response=0000000000000000000000000000000000000000000000000000000000000000 )
  • SaiProxyCreateAndExecute.shut( tub_=0x448a5065aeBB8E423F0896E6c5D525C040f59af3, cup=0000000000000000000000000000000000000000000000000000000000005544, otc_=0x39755357759cE0d7f32dC8dC45414CCa409AE24e )
    • SaiTub.ink( cup=0000000000000000000000000000000000000000000000000000000000005544 ) => ( 8261774078360265 )
    • SaiTub.CALL( )
      • DSToken.CALL( )
      • WETH9.balanceOf( 0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 1314987112554170401767735 )
      • DSToken.CALL( )
      • SaiTub.tab( cup=0000000000000000000000000000000000000000000000000000000000005544 ) => ( 1331712353853118800 )
      • SaiTub.CALL( )
      • DSToken.transferFrom( src=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, dst=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=1331712353853118800 ) => ( True )
      • SaiTub.rap( cup=0000000000000000000000000000000000000000000000000000000000005544 ) => ( 1897401662859902 )
      • SaiTub.tab( cup=0000000000000000000000000000000000000000000000000000000000005544 ) => ( 1331712353853118800 )
      • SaiTub.CALL( )
      • OSM.CALL( )
      • SaiTub.CALL( )
      • SaiTub.CALL( )
      • MatchingMarket.getPayAmount( pay_gem=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359, buy_gem=0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2, buy_amt=3568505401351 ) => ( fill_amt=1950507916582691 )
      • SaiTub.CALL( )
      • DSToken.allowance( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, guy=0x39755357759cE0d7f32dC8dC45414CCa409AE24e ) => ( 0 )
      • SaiTub.CALL( )
      • DSToken.approve( guy=0x39755357759cE0d7f32dC8dC45414CCa409AE24e, wad=115792089237316195423570985008687907853269984665640564039457584007913129639935 ) => ( True )
      • SaiTub.CALL( )
      • DSToken.transferFrom( src=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, dst=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=1950507916582691 ) => ( True )
      • SaiTub.CALL( )
      • SaiTub.CALL( )
      • MatchingMarket.buyAllAmount( buy_gem=0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2, buy_amt=3568505401351, pay_gem=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359, max_fill_amount=1950507916582691 ) => ( fill_amt=1950507916582691 )
        • DSToken.transferFrom( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, dst=0xAe34FFe5BF622684a251A28D8a9b05bC8c850629, wad=1950507916582691 ) => ( True )
        • DSToken.transfer( dst=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=3568505401351 ) => ( True )
        • SaiTub.CALL( )
        • DSToken.allowance( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, guy=0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 115792089237316195423570985008687907853269984665640564039457584007913129639935 )
        • SaiTub.CALL( )
        • DSToken.allowance( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, guy=0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 0 )
        • SaiTub.CALL( )
        • DSToken.approve( guy=0x448a5065aeBB8E423F0896E6c5D525C040f59af3, wad=115792089237316195423570985008687907853269984665640564039457584007913129639935 ) => ( True )
        • SaiTub.wipe( cup=0000000000000000000000000000000000000000000000000000000000005544, wad=1331712353853118800 )
          • DSToken.burn( guy=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=1331712353853118800 )
            • DSGuard.canCall( src_=0x448a5065aeBB8E423F0896E6c5D525C040f59af3, dst_=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359, sig=System.Byte[] ) => ( True )
            • OSM.CALL( )
            • DSToken.move( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, dst=0x69076e44a9C70a67D5b79d95795Aba299083c275, wad=3568505401351 )
            • SaiTub.CALL( )
              • DSToken.CALL( )
              • WETH9.balanceOf( 0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 1314987112554170401767735 )
              • DSToken.CALL( )
              • SaiTub.CALL( )
                • DSToken.CALL( )
                • WETH9.balanceOf( 0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 1314987112554170401767735 )
                • DSToken.CALL( )
                • SaiTub.free( cup=0000000000000000000000000000000000000000000000000000000000005544, wad=8261774078360265 )
                  • DSToken.push( dst=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=8261774078360265 )
                  • DSToken.CALL( )
                  • WETH9.balanceOf( 0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 1314987112554170401767735 )
                  • DSToken.CALL( )
                  • Medianizer.CALL( )
                  • SaiVox.CALL( )
                  • SaiTub.CALL( )
                  • DSToken.allowance( src=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, guy=0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 115792089237316195423570985008687907853269984665640564039457584007913129639935 )
                  • SaiTub.exit( wad=8261774078360265 )
                    • DSToken.CALL( )
                    • WETH9.balanceOf( 0x448a5065aeBB8E423F0896E6c5D525C040f59af3 ) => ( 1314987112554170401767735 )
                    • DSToken.CALL( )
                    • WETH9.transfer( dst=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=8617994960811948 ) => ( True )
                    • DSToken.burn( guy=0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385, wad=8261774078360265 )
                      • DSGuard.canCall( src_=0x448a5065aeBB8E423F0896E6c5D525C040f59af3, dst_=0xf53AD2c6851052A81B42133467480961B2321C09, sig=System.Byte[] ) => ( True )
                      • SaiTub.CALL( )
                      • WETH9.balanceOf( 0x5Bedda658D5aB7d216A1DcCE6758e1A7A5005385 ) => ( 8617994960811948 )
                      • SaiTub.CALL( )
                      • WETH9.withdraw( wad=8617994960811948 )
                        • ETH 0.008617994960811948 DSProxy.CALL( )
                        • ETH 0.008617994960811948 0xc1a0a697990d56af43fb7738da38b3c174e4e49d.CALL( )
                        • SaiTub.shut( cup=0000000000000000000000000000000000000000000000000000000000005544 )
                          File 1 of 13: DSProxy
                          // proxy.sol - execute actions atomically through the proxy's identity
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.23;
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              constructor() public {
                                  owner = msg.sender;
                                  emit LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  emit LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  emit LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  emit LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          // DSProxy
                          // Allows code execution using a persistant identity This can be very
                          // useful to execute a sequence of atomic actions. Since the owner of
                          // the proxy can be changed, this allows for dynamic ownership models
                          // i.e. a multisig
                          contract DSProxy is DSAuth, DSNote {
                              DSProxyCache public cache;  // global cache for contracts
                          
                              constructor(address _cacheAddr) public {
                                  require(setCache(_cacheAddr));
                              }
                          
                              function() public payable {
                              }
                          
                              // use the proxy to execute calldata _data on contract _code
                              function execute(bytes _code, bytes _data)
                                  public
                                  payable
                                  returns (address target, bytes32 response)
                              {
                                  target = cache.read(_code);
                                  if (target == 0x0) {
                                      // deploy contract & store its address in cache
                                      target = cache.write(_code);
                                  }
                          
                                  response = execute(target, _data);
                              }
                          
                              function execute(address _target, bytes _data)
                                  public
                                  auth
                                  note
                                  payable
                                  returns (bytes32 response)
                              {
                                  require(_target != 0x0);
                          
                                  // call contract in current context
                                  assembly {
                                      let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 32)
                                      response := mload(0)      // load delegatecall output
                                      switch iszero(succeeded)
                                      case 1 {
                                          // throw if delegatecall failed
                                          revert(0, 0)
                                      }
                                  }
                              }
                          
                              //set new cache
                              function setCache(address _cacheAddr)
                                  public
                                  auth
                                  note
                                  returns (bool)
                              {
                                  require(_cacheAddr != 0x0);        // invalid cache address
                                  cache = DSProxyCache(_cacheAddr);  // overwrite cache
                                  return true;
                              }
                          }
                          
                          // DSProxyFactory
                          // This factory deploys new proxy instances through build()
                          // Deployed proxy addresses are logged
                          contract DSProxyFactory {
                              event Created(address indexed sender, address indexed owner, address proxy, address cache);
                              mapping(address=>bool) public isProxy;
                              DSProxyCache public cache = new DSProxyCache();
                          
                              // deploys a new proxy instance
                              // sets owner of proxy to caller
                              function build() public returns (DSProxy proxy) {
                                  proxy = build(msg.sender);
                              }
                          
                              // deploys a new proxy instance
                              // sets custom owner of proxy
                              function build(address owner) public returns (DSProxy proxy) {
                                  proxy = new DSProxy(cache);
                                  emit Created(msg.sender, owner, address(proxy), address(cache));
                                  proxy.setOwner(owner);
                                  isProxy[proxy] = true;
                              }
                          }
                          
                          // DSProxyCache
                          // This global cache stores addresses of contracts previously deployed
                          // by a proxy. This saves gas from repeat deployment of the same
                          // contracts and eliminates blockchain bloat.
                          
                          // By default, all proxies deployed from the same factory store
                          // contracts in the same cache. The cache a proxy instance uses can be
                          // changed.  The cache uses the sha3 hash of a contract's bytecode to
                          // lookup the address
                          contract DSProxyCache {
                              mapping(bytes32 => address) cache;
                          
                              function read(bytes _code) public view returns (address) {
                                  bytes32 hash = keccak256(_code);
                                  return cache[hash];
                              }
                          
                              function write(bytes _code) public returns (address target) {
                                  assembly {
                                      target := create(0, add(_code, 0x20), mload(_code))
                                      switch iszero(extcodesize(target))
                                      case 1 {
                                          // throw if contract failed to deploy
                                          revert(0, 0)
                                      }
                                  }
                                  bytes32 hash = keccak256(_code);
                                  cache[hash] = target;
                              }
                          }

                          File 2 of 13: SaiTub
                          // hevm: flattened sources of src/tub.sol
                          pragma solidity ^0.4.18;
                          
                          ////// lib/ds-guard/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-spell/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-thing/lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-thing/src/thing.sol
                          // thing.sol - `auth` with handy mixins. your things should be DSThings
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import 'ds-auth/auth.sol'; */
                          /* import 'ds-note/note.sol'; */
                          /* import 'ds-math/math.sol'; */
                          
                          contract DSThing is DSAuth, DSNote, DSMath {
                          
                              function S(string s) internal pure returns (bytes4) {
                                  return bytes4(keccak256(s));
                              }
                          
                          }
                          
                          ////// lib/ds-token/lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// lib/ds-token/lib/erc20/src/erc20.sol
                          /// erc20.sol -- API for the ERC20 token standard
                          
                          // See <https://github.com/ethereum/EIPs/issues/20>.
                          
                          // This file likely does not meet the threshold of originality
                          // required for copyright to apply.  As a result, this is free and
                          // unencumbered software belonging to the public domain.
                          
                          /* pragma solidity ^0.4.8; */
                          
                          contract ERC20Events {
                              event Approval(address indexed src, address indexed guy, uint wad);
                              event Transfer(address indexed src, address indexed dst, uint wad);
                          }
                          
                          contract ERC20 is ERC20Events {
                              function totalSupply() public view returns (uint);
                              function balanceOf(address guy) public view returns (uint);
                              function allowance(address src, address guy) public view returns (uint);
                          
                              function approve(address guy, uint wad) public returns (bool);
                              function transfer(address dst, uint wad) public returns (bool);
                              function transferFrom(
                                  address src, address dst, uint wad
                              ) public returns (bool);
                          }
                          
                          ////// lib/ds-token/src/base.sol
                          /// base.sol -- basic ERC20 implementation
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "erc20/erc20.sol"; */
                          /* import "ds-math/math.sol"; */
                          
                          contract DSTokenBase is ERC20, DSMath {
                              uint256                                            _supply;
                              mapping (address => uint256)                       _balances;
                              mapping (address => mapping (address => uint256))  _approvals;
                          
                              function DSTokenBase(uint supply) public {
                                  _balances[msg.sender] = supply;
                                  _supply = supply;
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return _supply;
                              }
                              function balanceOf(address src) public view returns (uint) {
                                  return _balances[src];
                              }
                              function allowance(address src, address guy) public view returns (uint) {
                                  return _approvals[src][guy];
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  if (src != msg.sender) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  _approvals[msg.sender][guy] = wad;
                          
                                  Approval(msg.sender, guy, wad);
                          
                                  return true;
                              }
                          }
                          
                          ////// lib/ds-token/src/token.sol
                          /// token.sol -- ERC20 implementation with minting and burning
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-stop/stop.sol"; */
                          
                          /* import "./base.sol"; */
                          
                          contract DSToken is DSTokenBase(0), DSStop {
                          
                              bytes32  public  symbol;
                              uint256  public  decimals = 18; // standard token precision. override to customize
                          
                              function DSToken(bytes32 symbol_) public {
                                  symbol = symbol_;
                              }
                          
                              event Mint(address indexed guy, uint wad);
                              event Burn(address indexed guy, uint wad);
                          
                              function approve(address guy) public stoppable returns (bool) {
                                  return super.approve(guy, uint(-1));
                              }
                          
                              function approve(address guy, uint wad) public stoppable returns (bool) {
                                  return super.approve(guy, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  stoppable
                                  returns (bool)
                              {
                                  if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function push(address dst, uint wad) public {
                                  transferFrom(msg.sender, dst, wad);
                              }
                              function pull(address src, uint wad) public {
                                  transferFrom(src, msg.sender, wad);
                              }
                              function move(address src, address dst, uint wad) public {
                                  transferFrom(src, dst, wad);
                              }
                          
                              function mint(uint wad) public {
                                  mint(msg.sender, wad);
                              }
                              function burn(uint wad) public {
                                  burn(msg.sender, wad);
                              }
                              function mint(address guy, uint wad) public auth stoppable {
                                  _balances[guy] = add(_balances[guy], wad);
                                  _supply = add(_supply, wad);
                                  Mint(guy, wad);
                              }
                              function burn(address guy, uint wad) public auth stoppable {
                                  if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) {
                                      _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad);
                                  }
                          
                                  _balances[guy] = sub(_balances[guy], wad);
                                  _supply = sub(_supply, wad);
                                  Burn(guy, wad);
                              }
                          
                              // Optional token name
                              bytes32   public  name = "";
                          
                              function setName(bytes32 name_) public auth {
                                  name = name_;
                              }
                          }
                          
                          ////// lib/ds-value/src/value.sol
                          /// value.sol - a value is a simple thing, it can be get and set
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import 'ds-thing/thing.sol'; */
                          
                          contract DSValue is DSThing {
                              bool    has;
                              bytes32 val;
                              function peek() public view returns (bytes32, bool) {
                                  return (val,has);
                              }
                              function read() public view returns (bytes32) {
                                  var (wut, haz) = peek();
                                  assert(haz);
                                  return wut;
                              }
                              function poke(bytes32 wut) public note auth {
                                  val = wut;
                                  has = true;
                              }
                              function void() public note auth {  // unset the value
                                  has = false;
                              }
                          }
                          
                          ////// src/vox.sol
                          /// vox.sol -- target price feed
                          
                          // Copyright (C) 2016, 2017  Nikolai Mushegian <[email protected]>
                          // Copyright (C) 2016, 2017  Daniel Brockman <[email protected]>
                          // Copyright (C) 2017        Rain Break <[email protected]>
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.18; */
                          
                          /* import "ds-thing/thing.sol"; */
                          
                          contract SaiVox is DSThing {
                              uint256  _par;
                              uint256  _way;
                          
                              uint256  public  fix;
                              uint256  public  how;
                              uint256  public  tau;
                          
                              function SaiVox(uint par_) public {
                                  _par = fix = par_;
                                  _way = RAY;
                                  tau  = era();
                              }
                          
                              function era() public view returns (uint) {
                                  return block.timestamp;
                              }
                          
                              function mold(bytes32 param, uint val) public note auth {
                                  if (param == 'way') _way = val;
                              }
                          
                              // Dai Target Price (ref per dai)
                              function par() public returns (uint) {
                                  prod();
                                  return _par;
                              }
                              function way() public returns (uint) {
                                  prod();
                                  return _way;
                              }
                          
                              function tell(uint256 ray) public note auth {
                                  fix = ray;
                              }
                              function tune(uint256 ray) public note auth {
                                  how = ray;
                              }
                          
                              function prod() public note {
                                  var age = era() - tau;
                                  if (age == 0) return;  // optimised
                                  tau = era();
                          
                                  if (_way != RAY) _par = rmul(_par, rpow(_way, age));  // optimised
                          
                                  if (how == 0) return;  // optimised
                                  var wag = int128(how * age);
                                  _way = inj(prj(_way) + (fix < _par ? wag : -wag));
                              }
                          
                              function inj(int128 x) internal pure returns (uint256) {
                                  return x >= 0 ? uint256(x) + RAY
                                      : rdiv(RAY, RAY + uint256(-x));
                              }
                              function prj(uint256 x) internal pure returns (int128) {
                                  return x >= RAY ? int128(x - RAY)
                                      : int128(RAY) - int128(rdiv(RAY, x));
                              }
                          }
                          
                          ////// src/tub.sol
                          /// tub.sol -- simplified CDP engine (baby brother of `vat')
                          
                          // Copyright (C) 2017  Nikolai Mushegian <[email protected]>
                          // Copyright (C) 2017  Daniel Brockman <[email protected]>
                          // Copyright (C) 2017  Rain Break <[email protected]>
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.18; */
                          
                          /* import "ds-thing/thing.sol"; */
                          /* import "ds-token/token.sol"; */
                          /* import "ds-value/value.sol"; */
                          
                          /* import "./vox.sol"; */
                          
                          contract SaiTubEvents {
                              event LogNewCup(address indexed lad, bytes32 cup);
                          }
                          
                          contract SaiTub is DSThing, SaiTubEvents {
                              DSToken  public  sai;  // Stablecoin
                              DSToken  public  sin;  // Debt (negative sai)
                          
                              DSToken  public  skr;  // Abstracted collateral
                              ERC20    public  gem;  // Underlying collateral
                          
                              DSToken  public  gov;  // Governance token
                          
                              SaiVox   public  vox;  // Target price feed
                              DSValue  public  pip;  // Reference price feed
                              DSValue  public  pep;  // Governance price feed
                          
                              address  public  tap;  // Liquidator
                              address  public  pit;  // Governance Vault
                          
                              uint256  public  axe;  // Liquidation penalty
                              uint256  public  cap;  // Debt ceiling
                              uint256  public  mat;  // Liquidation ratio
                              uint256  public  tax;  // Stability fee
                              uint256  public  fee;  // Governance fee
                              uint256  public  gap;  // Join-Exit Spread
                          
                              bool     public  off;  // Cage flag
                              bool     public  out;  // Post cage exit
                          
                              uint256  public  fit;  // REF per SKR (just before settlement)
                          
                              uint256  public  rho;  // Time of last drip
                              uint256         _chi;  // Accumulated Tax Rates
                              uint256         _rhi;  // Accumulated Tax + Fee Rates
                              uint256  public  rum;  // Total normalised debt
                          
                              uint256                   public  cupi;
                              mapping (bytes32 => Cup)  public  cups;
                          
                              struct Cup {
                                  address  lad;      // CDP owner
                                  uint256  ink;      // Locked collateral (in SKR)
                                  uint256  art;      // Outstanding normalised debt (tax only)
                                  uint256  ire;      // Outstanding normalised debt
                              }
                          
                              function lad(bytes32 cup) public view returns (address) {
                                  return cups[cup].lad;
                              }
                              function ink(bytes32 cup) public view returns (uint) {
                                  return cups[cup].ink;
                              }
                              function tab(bytes32 cup) public returns (uint) {
                                  return rmul(cups[cup].art, chi());
                              }
                              function rap(bytes32 cup) public returns (uint) {
                                  return sub(rmul(cups[cup].ire, rhi()), tab(cup));
                              }
                          
                              // Total CDP Debt
                              function din() public returns (uint) {
                                  return rmul(rum, chi());
                              }
                              // Backing collateral
                              function air() public view returns (uint) {
                                  return skr.balanceOf(this);
                              }
                              // Raw collateral
                              function pie() public view returns (uint) {
                                  return gem.balanceOf(this);
                              }
                          
                              //------------------------------------------------------------------
                          
                              function SaiTub(
                                  DSToken  sai_,
                                  DSToken  sin_,
                                  DSToken  skr_,
                                  ERC20    gem_,
                                  DSToken  gov_,
                                  DSValue  pip_,
                                  DSValue  pep_,
                                  SaiVox   vox_,
                                  address  pit_
                              ) public {
                                  gem = gem_;
                                  skr = skr_;
                          
                                  sai = sai_;
                                  sin = sin_;
                          
                                  gov = gov_;
                                  pit = pit_;
                          
                                  pip = pip_;
                                  pep = pep_;
                                  vox = vox_;
                          
                                  axe = RAY;
                                  mat = RAY;
                                  tax = RAY;
                                  fee = RAY;
                                  gap = WAD;
                          
                                  _chi = RAY;
                                  _rhi = RAY;
                          
                                  rho = era();
                              }
                          
                              function era() public constant returns (uint) {
                                  return block.timestamp;
                              }
                          
                              //--Risk-parameter-config-------------------------------------------
                          
                              function mold(bytes32 param, uint val) public note auth {
                                  if      (param == 'cap') cap = val;
                                  else if (param == 'mat') { require(val >= RAY); mat = val; }
                                  else if (param == 'tax') { require(val >= RAY); drip(); tax = val; }
                                  else if (param == 'fee') { require(val >= RAY); drip(); fee = val; }
                                  else if (param == 'axe') { require(val >= RAY); axe = val; }
                                  else if (param == 'gap') { require(val >= WAD); gap = val; }
                                  else return;
                              }
                          
                              //--Price-feed-setters----------------------------------------------
                          
                              function setPip(DSValue pip_) public note auth {
                                  pip = pip_;
                              }
                              function setPep(DSValue pep_) public note auth {
                                  pep = pep_;
                              }
                              function setVox(SaiVox vox_) public note auth {
                                  vox = vox_;
                              }
                          
                              //--Tap-setter------------------------------------------------------
                              function turn(address tap_) public note {
                                  require(tap  == 0);
                                  require(tap_ != 0);
                                  tap = tap_;
                              }
                          
                              //--Collateral-wrapper----------------------------------------------
                          
                              // Wrapper ratio (gem per skr)
                              function per() public view returns (uint ray) {
                                  return skr.totalSupply() == 0 ? RAY : rdiv(pie(), skr.totalSupply());
                              }
                              // Join price (gem per skr)
                              function ask(uint wad) public view returns (uint) {
                                  return rmul(wad, wmul(per(), gap));
                              }
                              // Exit price (gem per skr)
                              function bid(uint wad) public view returns (uint) {
                                  return rmul(wad, wmul(per(), sub(2 * WAD, gap)));
                              }
                              function join(uint wad) public note {
                                  require(!off);
                                  require(ask(wad) > 0);
                                  require(gem.transferFrom(msg.sender, this, ask(wad)));
                                  skr.mint(msg.sender, wad);
                              }
                              function exit(uint wad) public note {
                                  require(!off || out);
                                  require(gem.transfer(msg.sender, bid(wad)));
                                  skr.burn(msg.sender, wad);
                              }
                          
                              //--Stability-fee-accumulation--------------------------------------
                          
                              // Accumulated Rates
                              function chi() public returns (uint) {
                                  drip();
                                  return _chi;
                              }
                              function rhi() public returns (uint) {
                                  drip();
                                  return _rhi;
                              }
                              function drip() public note {
                                  if (off) return;
                          
                                  var rho_ = era();
                                  var age = rho_ - rho;
                                  if (age == 0) return;    // optimised
                                  rho = rho_;
                          
                                  var inc = RAY;
                          
                                  if (tax != RAY) {  // optimised
                                      var _chi_ = _chi;
                                      inc = rpow(tax, age);
                                      _chi = rmul(_chi, inc);
                                      sai.mint(tap, rmul(sub(_chi, _chi_), rum));
                                  }
                          
                                  // optimised
                                  if (fee != RAY) inc = rmul(inc, rpow(fee, age));
                                  if (inc != RAY) _rhi = rmul(_rhi, inc);
                              }
                          
                          
                              //--CDP-risk-indicator----------------------------------------------
                          
                              // Abstracted collateral price (ref per skr)
                              function tag() public view returns (uint wad) {
                                  return off ? fit : wmul(per(), uint(pip.read()));
                              }
                              // Returns true if cup is well-collateralized
                              function safe(bytes32 cup) public returns (bool) {
                                  var pro = rmul(tag(), ink(cup));
                                  var con = rmul(vox.par(), tab(cup));
                                  var min = rmul(con, mat);
                                  return pro >= min;
                              }
                          
                          
                              //--CDP-operations--------------------------------------------------
                          
                              function open() public note returns (bytes32 cup) {
                                  require(!off);
                                  cupi = add(cupi, 1);
                                  cup = bytes32(cupi);
                                  cups[cup].lad = msg.sender;
                                  LogNewCup(msg.sender, cup);
                              }
                              function give(bytes32 cup, address guy) public note {
                                  require(msg.sender == cups[cup].lad);
                                  require(guy != 0);
                                  cups[cup].lad = guy;
                              }
                          
                              function lock(bytes32 cup, uint wad) public note {
                                  require(!off);
                                  cups[cup].ink = add(cups[cup].ink, wad);
                                  skr.pull(msg.sender, wad);
                                  require(cups[cup].ink == 0 || cups[cup].ink > 0.005 ether);
                              }
                              function free(bytes32 cup, uint wad) public note {
                                  require(msg.sender == cups[cup].lad);
                                  cups[cup].ink = sub(cups[cup].ink, wad);
                                  skr.push(msg.sender, wad);
                                  require(safe(cup));
                                  require(cups[cup].ink == 0 || cups[cup].ink > 0.005 ether);
                              }
                          
                              function draw(bytes32 cup, uint wad) public note {
                                  require(!off);
                                  require(msg.sender == cups[cup].lad);
                                  require(rdiv(wad, chi()) > 0);
                          
                                  cups[cup].art = add(cups[cup].art, rdiv(wad, chi()));
                                  rum = add(rum, rdiv(wad, chi()));
                          
                                  cups[cup].ire = add(cups[cup].ire, rdiv(wad, rhi()));
                                  sai.mint(cups[cup].lad, wad);
                          
                                  require(safe(cup));
                                  require(sai.totalSupply() <= cap);
                              }
                              function wipe(bytes32 cup, uint wad) public note {
                                  require(!off);
                          
                                  var owe = rmul(wad, rdiv(rap(cup), tab(cup)));
                          
                                  cups[cup].art = sub(cups[cup].art, rdiv(wad, chi()));
                                  rum = sub(rum, rdiv(wad, chi()));
                          
                                  cups[cup].ire = sub(cups[cup].ire, rdiv(add(wad, owe), rhi()));
                                  sai.burn(msg.sender, wad);
                          
                                  var (val, ok) = pep.peek();
                                  if (ok && val != 0) gov.move(msg.sender, pit, wdiv(owe, uint(val)));
                              }
                          
                              function shut(bytes32 cup) public note {
                                  require(!off);
                                  require(msg.sender == cups[cup].lad);
                                  if (tab(cup) != 0) wipe(cup, tab(cup));
                                  if (ink(cup) != 0) free(cup, ink(cup));
                                  delete cups[cup];
                              }
                          
                              function bite(bytes32 cup) public note {
                                  require(!safe(cup) || off);
                          
                                  // Take on all of the debt, except unpaid fees
                                  var rue = tab(cup);
                                  sin.mint(tap, rue);
                                  rum = sub(rum, cups[cup].art);
                                  cups[cup].art = 0;
                                  cups[cup].ire = 0;
                          
                                  // Amount owed in SKR, including liquidation penalty
                                  var owe = rdiv(rmul(rmul(rue, axe), vox.par()), tag());
                          
                                  if (owe > cups[cup].ink) {
                                      owe = cups[cup].ink;
                                  }
                          
                                  skr.push(tap, owe);
                                  cups[cup].ink = sub(cups[cup].ink, owe);
                              }
                          
                              //------------------------------------------------------------------
                          
                              function cage(uint fit_, uint jam) public note auth {
                                  require(!off && fit_ != 0);
                                  off = true;
                                  axe = RAY;
                                  gap = WAD;
                                  fit = fit_;         // ref per skr
                                  require(gem.transfer(tap, jam));
                              }
                              function flow() public note auth {
                                  require(off);
                                  out = true;
                              }
                          }

                          File 3 of 13: DSToken
                          pragma solidity ^0.4.13;
                          
                          ////// lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// lib/erc20/src/erc20.sol
                          /// erc20.sol -- API for the ERC20 token standard
                          
                          // See <https://github.com/ethereum/EIPs/issues/20>.
                          
                          // This file likely does not meet the threshold of originality
                          // required for copyright to apply.  As a result, this is free and
                          // unencumbered software belonging to the public domain.
                          
                          /* pragma solidity ^0.4.8; */
                          
                          contract ERC20Events {
                              event Approval(address indexed src, address indexed guy, uint wad);
                              event Transfer(address indexed src, address indexed dst, uint wad);
                          }
                          
                          contract ERC20 is ERC20Events {
                              function totalSupply() public view returns (uint);
                              function balanceOf(address guy) public view returns (uint);
                              function allowance(address src, address guy) public view returns (uint);
                          
                              function approve(address guy, uint wad) public returns (bool);
                              function transfer(address dst, uint wad) public returns (bool);
                              function transferFrom(
                                  address src, address dst, uint wad
                              ) public returns (bool);
                          }
                          
                          ////// src/base.sol
                          /// base.sol -- basic ERC20 implementation
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "erc20/erc20.sol"; */
                          /* import "ds-math/math.sol"; */
                          
                          contract DSTokenBase is ERC20, DSMath {
                              uint256                                            _supply;
                              mapping (address => uint256)                       _balances;
                              mapping (address => mapping (address => uint256))  _approvals;
                          
                              function DSTokenBase(uint supply) public {
                                  _balances[msg.sender] = supply;
                                  _supply = supply;
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return _supply;
                              }
                              function balanceOf(address src) public view returns (uint) {
                                  return _balances[src];
                              }
                              function allowance(address src, address guy) public view returns (uint) {
                                  return _approvals[src][guy];
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  if (src != msg.sender) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  _approvals[msg.sender][guy] = wad;
                          
                                  Approval(msg.sender, guy, wad);
                          
                                  return true;
                              }
                          }
                          
                          ////// src/token.sol
                          /// token.sol -- ERC20 implementation with minting and burning
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-stop/stop.sol"; */
                          
                          /* import "./base.sol"; */
                          
                          contract DSToken is DSTokenBase(0), DSStop {
                          
                              bytes32  public  symbol;
                              uint256  public  decimals = 18; // standard token precision. override to customize
                          
                              function DSToken(bytes32 symbol_) public {
                                  symbol = symbol_;
                              }
                          
                              event Mint(address indexed guy, uint wad);
                              event Burn(address indexed guy, uint wad);
                          
                              function approve(address guy) public stoppable returns (bool) {
                                  return super.approve(guy, uint(-1));
                              }
                          
                              function approve(address guy, uint wad) public stoppable returns (bool) {
                                  return super.approve(guy, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  stoppable
                                  returns (bool)
                              {
                                  if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function push(address dst, uint wad) public {
                                  transferFrom(msg.sender, dst, wad);
                              }
                              function pull(address src, uint wad) public {
                                  transferFrom(src, msg.sender, wad);
                              }
                              function move(address src, address dst, uint wad) public {
                                  transferFrom(src, dst, wad);
                              }
                          
                              function mint(uint wad) public {
                                  mint(msg.sender, wad);
                              }
                              function burn(uint wad) public {
                                  burn(msg.sender, wad);
                              }
                              function mint(address guy, uint wad) public auth stoppable {
                                  _balances[guy] = add(_balances[guy], wad);
                                  _supply = add(_supply, wad);
                                  Mint(guy, wad);
                              }
                              function burn(address guy, uint wad) public auth stoppable {
                                  if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) {
                                      _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad);
                                  }
                          
                                  _balances[guy] = sub(_balances[guy], wad);
                                  _supply = sub(_supply, wad);
                                  Burn(guy, wad);
                              }
                          
                              // Optional token name
                              bytes32   public  name = "";
                          
                              function setName(bytes32 name_) public auth {
                                  name = name_;
                              }
                          }

                          File 4 of 13: MatchingMarket
                          /// matching_market.sol
                          
                          //
                          // 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.4.18;
                          
                          /// expiring_market.sol
                          
                          //
                          // 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.4.18;
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.13;
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          /// simple_market.sol
                          
                          //
                          // 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.4.18;
                          
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.13;
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          /// erc20.sol -- API for the ERC20 token standard
                          
                          // See <https://github.com/ethereum/EIPs/issues/20>.
                          
                          // This file likely does not meet the threshold of originality
                          // required for copyright to apply.  As a result, this is free and
                          // unencumbered software belonging to the public domain.
                          
                          pragma solidity ^0.4.8;
                          
                          contract ERC20Events {
                              event Approval(address indexed src, address indexed guy, uint wad);
                              event Transfer(address indexed src, address indexed dst, uint wad);
                          }
                          
                          contract ERC20 is ERC20Events {
                              function totalSupply() public view returns (uint);
                              function balanceOf(address guy) public view returns (uint);
                              function allowance(address src, address guy) public view returns (uint);
                          
                              function approve(address guy, uint wad) public returns (bool);
                              function transfer(address dst, uint wad) public returns (bool);
                              function transferFrom(
                                  address src, address dst, uint wad
                              ) public returns (bool);
                          }
                          
                          contract EventfulMarket {
                              event LogItemUpdate(uint id);
                              event LogTrade(uint pay_amt, address indexed pay_gem,
                                             uint buy_amt, address indexed buy_gem);
                          
                              event LogMake(
                                  bytes32  indexed  id,
                                  bytes32  indexed  pair,
                                  address  indexed  maker,
                                  ERC20             pay_gem,
                                  ERC20             buy_gem,
                                  uint128           pay_amt,
                                  uint128           buy_amt,
                                  uint64            timestamp
                              );
                          
                              event LogBump(
                                  bytes32  indexed  id,
                                  bytes32  indexed  pair,
                                  address  indexed  maker,
                                  ERC20             pay_gem,
                                  ERC20             buy_gem,
                                  uint128           pay_amt,
                                  uint128           buy_amt,
                                  uint64            timestamp
                              );
                          
                              event LogTake(
                                  bytes32           id,
                                  bytes32  indexed  pair,
                                  address  indexed  maker,
                                  ERC20             pay_gem,
                                  ERC20             buy_gem,
                                  address  indexed  taker,
                                  uint128           take_amt,
                                  uint128           give_amt,
                                  uint64            timestamp
                              );
                          
                              event LogKill(
                                  bytes32  indexed  id,
                                  bytes32  indexed  pair,
                                  address  indexed  maker,
                                  ERC20             pay_gem,
                                  ERC20             buy_gem,
                                  uint128           pay_amt,
                                  uint128           buy_amt,
                                  uint64            timestamp
                              );
                          }
                          
                          contract SimpleMarket is EventfulMarket, DSMath {
                          
                              uint public last_offer_id;
                          
                              mapping (uint => OfferInfo) public offers;
                          
                              bool locked;
                          
                              struct OfferInfo {
                                  uint     pay_amt;
                                  ERC20    pay_gem;
                                  uint     buy_amt;
                                  ERC20    buy_gem;
                                  address  owner;
                                  uint64   timestamp;
                              }
                          
                              modifier can_buy(uint id) {
                                  require(isActive(id));
                                  _;
                              }
                          
                              modifier can_cancel(uint id) {
                                  require(isActive(id));
                                  require(getOwner(id) == msg.sender);
                                  _;
                              }
                          
                              modifier can_offer {
                                  _;
                              }
                          
                              modifier synchronized {
                                  require(!locked);
                                  locked = true;
                                  _;
                                  locked = false;
                              }
                          
                              function isActive(uint id) public constant returns (bool active) {
                                  return offers[id].timestamp > 0;
                              }
                          
                              function getOwner(uint id) public constant returns (address owner) {
                                  return offers[id].owner;
                              }
                          
                              function getOffer(uint id) public constant returns (uint, ERC20, uint, ERC20) {
                                var offer = offers[id];
                                return (offer.pay_amt, offer.pay_gem,
                                        offer.buy_amt, offer.buy_gem);
                              }
                          
                              // ---- Public entrypoints ---- //
                          
                              function bump(bytes32 id_)
                                  public
                                  can_buy(uint256(id_))
                              {
                                  var id = uint256(id_);
                                  LogBump(
                                      id_,
                                      keccak256(offers[id].pay_gem, offers[id].buy_gem),
                                      offers[id].owner,
                                      offers[id].pay_gem,
                                      offers[id].buy_gem,
                                      uint128(offers[id].pay_amt),
                                      uint128(offers[id].buy_amt),
                                      offers[id].timestamp
                                  );
                              }
                          
                              // Accept given `quantity` of an offer. Transfers funds from caller to
                              // offer maker, and from market to caller.
                              function buy(uint id, uint quantity)
                                  public
                                  can_buy(id)
                                  synchronized
                                  returns (bool)
                              {
                                  OfferInfo memory offer = offers[id];
                                  uint spend = mul(quantity, offer.buy_amt) / offer.pay_amt;
                          
                                  require(uint128(spend) == spend);
                                  require(uint128(quantity) == quantity);
                          
                                  // For backwards semantic compatibility.
                                  if (quantity == 0 || spend == 0 ||
                                      quantity > offer.pay_amt || spend > offer.buy_amt)
                                  {
                                      return false;
                                  }
                          
                                  offers[id].pay_amt = sub(offer.pay_amt, quantity);
                                  offers[id].buy_amt = sub(offer.buy_amt, spend);
                                  require( offer.buy_gem.transferFrom(msg.sender, offer.owner, spend) );
                                  require( offer.pay_gem.transfer(msg.sender, quantity) );
                          
                                  LogItemUpdate(id);
                                  LogTake(
                                      bytes32(id),
                                      keccak256(offer.pay_gem, offer.buy_gem),
                                      offer.owner,
                                      offer.pay_gem,
                                      offer.buy_gem,
                                      msg.sender,
                                      uint128(quantity),
                                      uint128(spend),
                                      uint64(now)
                                  );
                                  LogTrade(quantity, offer.pay_gem, spend, offer.buy_gem);
                          
                                  if (offers[id].pay_amt == 0) {
                                    delete offers[id];
                                  }
                          
                                  return true;
                              }
                          
                              // Cancel an offer. Refunds offer maker.
                              function cancel(uint id)
                                  public
                                  can_cancel(id)
                                  synchronized
                                  returns (bool success)
                              {
                                  // read-only offer. Modify an offer by directly accessing offers[id]
                                  OfferInfo memory offer = offers[id];
                                  delete offers[id];
                          
                                  require( offer.pay_gem.transfer(offer.owner, offer.pay_amt) );
                          
                                  LogItemUpdate(id);
                                  LogKill(
                                      bytes32(id),
                                      keccak256(offer.pay_gem, offer.buy_gem),
                                      offer.owner,
                                      offer.pay_gem,
                                      offer.buy_gem,
                                      uint128(offer.pay_amt),
                                      uint128(offer.buy_amt),
                                      uint64(now)
                                  );
                          
                                  success = true;
                              }
                          
                              function kill(bytes32 id)
                                  public
                              {
                                  require(cancel(uint256(id)));
                              }
                          
                              function make(
                                  ERC20    pay_gem,
                                  ERC20    buy_gem,
                                  uint128  pay_amt,
                                  uint128  buy_amt
                              )
                                  public
                                  returns (bytes32 id)
                              {
                                  return bytes32(offer(pay_amt, pay_gem, buy_amt, buy_gem));
                              }
                          
                              // Make a new offer. Takes funds from the caller into market escrow.
                              function offer(uint pay_amt, ERC20 pay_gem, uint buy_amt, ERC20 buy_gem)
                                  public
                                  can_offer
                                  synchronized
                                  returns (uint id)
                              {
                                  require(uint128(pay_amt) == pay_amt);
                                  require(uint128(buy_amt) == buy_amt);
                                  require(pay_amt > 0);
                                  require(pay_gem != ERC20(0x0));
                                  require(buy_amt > 0);
                                  require(buy_gem != ERC20(0x0));
                                  require(pay_gem != buy_gem);
                          
                                  OfferInfo memory info;
                                  info.pay_amt = pay_amt;
                                  info.pay_gem = pay_gem;
                                  info.buy_amt = buy_amt;
                                  info.buy_gem = buy_gem;
                                  info.owner = msg.sender;
                                  info.timestamp = uint64(now);
                                  id = _next_id();
                                  offers[id] = info;
                          
                                  require( pay_gem.transferFrom(msg.sender, this, pay_amt) );
                          
                                  LogItemUpdate(id);
                                  LogMake(
                                      bytes32(id),
                                      keccak256(pay_gem, buy_gem),
                                      msg.sender,
                                      pay_gem,
                                      buy_gem,
                                      uint128(pay_amt),
                                      uint128(buy_amt),
                                      uint64(now)
                                  );
                              }
                          
                              function take(bytes32 id, uint128 maxTakeAmount)
                                  public
                              {
                                  require(buy(uint256(id), maxTakeAmount));
                              }
                          
                              function _next_id()
                                  internal
                                  returns (uint)
                              {
                                  last_offer_id++; return last_offer_id;
                              }
                          }
                          
                          // Simple Market with a market lifetime. When the close_time has been reached,
                          // offers can only be cancelled (offer and buy will throw).
                          
                          contract ExpiringMarket is DSAuth, SimpleMarket {
                              uint64 public close_time;
                              bool public stopped;
                          
                              // after close_time has been reached, no new offers are allowed
                              modifier can_offer {
                                  require(!isClosed());
                                  _;
                              }
                          
                              // after close, no new buys are allowed
                              modifier can_buy(uint id) {
                                  require(isActive(id));
                                  require(!isClosed());
                                  _;
                              }
                          
                              // after close, anyone can cancel an offer
                              modifier can_cancel(uint id) {
                                  require(isActive(id));
                                  require((msg.sender == getOwner(id)) || isClosed());
                                  _;
                              }
                          
                              function ExpiringMarket(uint64 _close_time)
                                  public
                              {
                                  close_time = _close_time;
                              }
                          
                              function isClosed() public constant returns (bool closed) {
                                  return stopped || getTime() > close_time;
                              }
                          
                              function getTime() public constant returns (uint64) {
                                  return uint64(now);
                              }
                          
                              function stop() public auth {
                                  stopped = true;
                              }
                          }
                          
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.13;
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          contract MatchingEvents {
                              event LogBuyEnabled(bool isEnabled);
                              event LogMinSell(address pay_gem, uint min_amount);
                              event LogMatchingEnabled(bool isEnabled);
                              event LogUnsortedOffer(uint id);
                              event LogSortedOffer(uint id);
                              event LogInsert(address keeper, uint id);
                              event LogDelete(address keeper, uint id);
                          }
                          
                          contract MatchingMarket is MatchingEvents, ExpiringMarket, DSNote {
                              bool public buyEnabled = true;      //buy enabled
                              bool public matchingEnabled = true; //true: enable matching,
                                                                   //false: revert to expiring market
                              struct sortInfo {
                                  uint next;  //points to id of next higher offer
                                  uint prev;  //points to id of previous lower offer
                                  uint delb;  //the blocknumber where this entry was marked for delete
                              }
                              mapping(uint => sortInfo) public _rank;                     //doubly linked lists of sorted offer ids
                              mapping(address => mapping(address => uint)) public _best;  //id of the highest offer for a token pair
                              mapping(address => mapping(address => uint)) public _span;  //number of offers stored for token pair in sorted orderbook
                              mapping(address => uint) public _dust;                      //minimum sell amount for a token to avoid dust offers
                              mapping(uint => uint) public _near;         //next unsorted offer id
                              uint _head;                                 //first unsorted offer id
                              uint public dustId;                         // id of the latest offer marked as dust
                          
                          
                              function MatchingMarket(uint64 close_time) ExpiringMarket(close_time) public {
                              }
                          
                              // After close, anyone can cancel an offer
                              modifier can_cancel(uint id) {
                                  require(isActive(id), "Offer was deleted or taken, or never existed.");
                                  require(
                                      isClosed() || msg.sender == getOwner(id) || id == dustId,
                                      "Offer can not be cancelled because user is not owner, and market is open, and offer sells required amount of tokens."
                                  );
                                  _;
                              }
                          
                              // ---- Public entrypoints ---- //
                          
                              function make(
                                  ERC20    pay_gem,
                                  ERC20    buy_gem,
                                  uint128  pay_amt,
                                  uint128  buy_amt
                              )
                                  public
                                  returns (bytes32)
                              {
                                  return bytes32(offer(pay_amt, pay_gem, buy_amt, buy_gem));
                              }
                          
                              function take(bytes32 id, uint128 maxTakeAmount) public {
                                  require(buy(uint256(id), maxTakeAmount));
                              }
                          
                              function kill(bytes32 id) public {
                                  require(cancel(uint256(id)));
                              }
                          
                              // Make a new offer. Takes funds from the caller into market escrow.
                              //
                              // If matching is enabled:
                              //     * creates new offer without putting it in
                              //       the sorted list.
                              //     * available to authorized contracts only!
                              //     * keepers should call insert(id,pos)
                              //       to put offer in the sorted list.
                              //
                              // If matching is disabled:
                              //     * calls expiring market's offer().
                              //     * available to everyone without authorization.
                              //     * no sorting is done.
                              //
                              function offer(
                                  uint pay_amt,    //maker (ask) sell how much
                                  ERC20 pay_gem,   //maker (ask) sell which token
                                  uint buy_amt,    //taker (ask) buy how much
                                  ERC20 buy_gem    //taker (ask) buy which token
                              )
                                  public
                                  returns (uint)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  var fn = matchingEnabled ? _offeru : super.offer;
                                  return fn(pay_amt, pay_gem, buy_amt, buy_gem);
                              }
                          
                              // Make a new offer. Takes funds from the caller into market escrow.
                              function offer(
                                  uint pay_amt,    //maker (ask) sell how much
                                  ERC20 pay_gem,   //maker (ask) sell which token
                                  uint buy_amt,    //maker (ask) buy how much
                                  ERC20 buy_gem,   //maker (ask) buy which token
                                  uint pos         //position to insert offer, 0 should be used if unknown
                              )
                                  public
                                  can_offer
                                  returns (uint)
                              {
                                  return offer(pay_amt, pay_gem, buy_amt, buy_gem, pos, true);
                              }
                          
                              function offer(
                                  uint pay_amt,    //maker (ask) sell how much
                                  ERC20 pay_gem,   //maker (ask) sell which token
                                  uint buy_amt,    //maker (ask) buy how much
                                  ERC20 buy_gem,   //maker (ask) buy which token
                                  uint pos,        //position to insert offer, 0 should be used if unknown
                                  bool rounding    //match "close enough" orders?
                              )
                                  public
                                  can_offer
                                  returns (uint)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  require(_dust[pay_gem] <= pay_amt);
                          
                                  if (matchingEnabled) {
                                    return _matcho(pay_amt, pay_gem, buy_amt, buy_gem, pos, rounding);
                                  }
                                  return super.offer(pay_amt, pay_gem, buy_amt, buy_gem);
                              }
                          
                              //Transfers funds from caller to offer maker, and from market to caller.
                              function buy(uint id, uint amount)
                                  public
                                  can_buy(id)
                                  returns (bool)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  var fn = matchingEnabled ? _buys : super.buy;
                                  return fn(id, amount);
                              }
                          
                              // Cancel an offer. Refunds offer maker.
                              function cancel(uint id)
                                  public
                                  can_cancel(id)
                                  returns (bool success)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  if (matchingEnabled) {
                                      if (isOfferSorted(id)) {
                                          require(_unsort(id));
                                      } else {
                                          require(_hide(id));
                                      }
                                  }
                                  return super.cancel(id);    //delete the offer.
                              }
                          
                              //insert offer into the sorted list
                              //keepers need to use this function
                              function insert(
                                  uint id,   //maker (ask) id
                                  uint pos   //position to insert into
                              )
                                  public
                                  returns (bool)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  require(!isOfferSorted(id));    //make sure offers[id] is not yet sorted
                                  require(isActive(id));          //make sure offers[id] is active
                          
                                  _hide(id);                      //remove offer from unsorted offers list
                                  _sort(id, pos);                 //put offer into the sorted offers list
                                  LogInsert(msg.sender, id);
                                  return true;
                              }
                          
                              //deletes _rank [id]
                              //  Function should be called by keepers.
                              function del_rank(uint id)
                                  public
                                  returns (bool)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  require(!isActive(id) && _rank[id].delb != 0 && _rank[id].delb < block.number - 10);
                                  delete _rank[id];
                                  LogDelete(msg.sender, id);
                                  return true;
                              }
                          
                              //set the minimum sell amount for a token
                              //    Function is used to avoid "dust offers" that have
                              //    very small amount of tokens to sell, and it would
                              //    cost more gas to accept the offer, than the value
                              //    of tokens received.
                              function setMinSell(
                                  ERC20 pay_gem,     //token to assign minimum sell amount to
                                  uint dust          //maker (ask) minimum sell amount
                              )
                                  public
                                  auth
                                  note
                                  returns (bool)
                              {
                                  _dust[pay_gem] = dust;
                                  LogMinSell(pay_gem, dust);
                                  return true;
                              }
                          
                              //returns the minimum sell amount for an offer
                              function getMinSell(
                                  ERC20 pay_gem      //token for which minimum sell amount is queried
                              )
                                  public
                                  constant
                                  returns (uint)
                              {
                                  return _dust[pay_gem];
                              }
                          
                              //set buy functionality enabled/disabled
                              function setBuyEnabled(bool buyEnabled_) public auth returns (bool) {
                                  buyEnabled = buyEnabled_;
                                  LogBuyEnabled(buyEnabled);
                                  return true;
                              }
                          
                              //set matching enabled/disabled
                              //    If matchingEnabled true(default), then inserted offers are matched.
                              //    Except the ones inserted by contracts, because those end up
                              //    in the unsorted list of offers, that must be later sorted by
                              //    keepers using insert().
                              //    If matchingEnabled is false then MatchingMarket is reverted to ExpiringMarket,
                              //    and matching is not done, and sorted lists are disabled.
                              function setMatchingEnabled(bool matchingEnabled_) public auth returns (bool) {
                                  matchingEnabled = matchingEnabled_;
                                  LogMatchingEnabled(matchingEnabled);
                                  return true;
                              }
                          
                              //return the best offer for a token pair
                              //      the best offer is the lowest one if it's an ask,
                              //      and highest one if it's a bid offer
                              function getBestOffer(ERC20 sell_gem, ERC20 buy_gem) public constant returns(uint) {
                                  return _best[sell_gem][buy_gem];
                              }
                          
                              //return the next worse offer in the sorted list
                              //      the worse offer is the higher one if its an ask,
                              //      a lower one if its a bid offer,
                              //      and in both cases the newer one if they're equal.
                              function getWorseOffer(uint id) public constant returns(uint) {
                                  return _rank[id].prev;
                              }
                          
                              //return the next better offer in the sorted list
                              //      the better offer is in the lower priced one if its an ask,
                              //      the next higher priced one if its a bid offer
                              //      and in both cases the older one if they're equal.
                              function getBetterOffer(uint id) public constant returns(uint) {
                          
                                  return _rank[id].next;
                              }
                          
                              //return the amount of better offers for a token pair
                              function getOfferCount(ERC20 sell_gem, ERC20 buy_gem) public constant returns(uint) {
                                  return _span[sell_gem][buy_gem];
                              }
                          
                              //get the first unsorted offer that was inserted by a contract
                              //      Contracts can't calculate the insertion position of their offer because it is not an O(1) operation.
                              //      Their offers get put in the unsorted list of offers.
                              //      Keepers can calculate the insertion position offchain and pass it to the insert() function to insert
                              //      the unsorted offer into the sorted list. Unsorted offers will not be matched, but can be bought with buy().
                              function getFirstUnsortedOffer() public constant returns(uint) {
                                  return _head;
                              }
                          
                              //get the next unsorted offer
                              //      Can be used to cycle through all the unsorted offers.
                              function getNextUnsortedOffer(uint id) public constant returns(uint) {
                                  return _near[id];
                              }
                          
                              function isOfferSorted(uint id) public constant returns(bool) {
                                  return _rank[id].next != 0
                                         || _rank[id].prev != 0
                                         || _best[offers[id].pay_gem][offers[id].buy_gem] == id;
                              }
                          
                              function sellAllAmount(ERC20 pay_gem, uint pay_amt, ERC20 buy_gem, uint min_fill_amount)
                                  public
                                  returns (uint fill_amt)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  uint offerId;
                                  while (pay_amt > 0) {                           //while there is amount to sell
                                      offerId = getBestOffer(buy_gem, pay_gem);   //Get the best offer for the token pair
                                      require(offerId != 0);                      //Fails if there are not more offers
                          
                                      // There is a chance that pay_amt is smaller than 1 wei of the other token
                                      if (pay_amt * 1 ether < wdiv(offers[offerId].buy_amt, offers[offerId].pay_amt)) {
                                          break;                                  //We consider that all amount is sold
                                      }
                                      if (pay_amt >= offers[offerId].buy_amt) {                       //If amount to sell is higher or equal than current offer amount to buy
                                          fill_amt = add(fill_amt, offers[offerId].pay_amt);          //Add amount bought to acumulator
                                          pay_amt = sub(pay_amt, offers[offerId].buy_amt);            //Decrease amount to sell
                                          take(bytes32(offerId), uint128(offers[offerId].pay_amt));   //We take the whole offer
                                      } else { // if lower
                                          var baux = rmul(pay_amt * 10 ** 9, rdiv(offers[offerId].pay_amt, offers[offerId].buy_amt)) / 10 ** 9;
                                          fill_amt = add(fill_amt, baux);         //Add amount bought to acumulator
                                          take(bytes32(offerId), uint128(baux));  //We take the portion of the offer that we need
                                          pay_amt = 0;                            //All amount is sold
                                      }
                                  }
                                  require(fill_amt >= min_fill_amount);
                              }
                          
                              function buyAllAmount(ERC20 buy_gem, uint buy_amt, ERC20 pay_gem, uint max_fill_amount)
                                  public
                                  returns (uint fill_amt)
                              {
                                  require(!locked, "Reentrancy attempt");
                                  uint offerId;
                                  while (buy_amt > 0) {                           //Meanwhile there is amount to buy
                                      offerId = getBestOffer(buy_gem, pay_gem);   //Get the best offer for the token pair
                                      require(offerId != 0);
                          
                                      // There is a chance that buy_amt is smaller than 1 wei of the other token
                                      if (buy_amt * 1 ether < wdiv(offers[offerId].pay_amt, offers[offerId].buy_amt)) {
                                          break;                                  //We consider that all amount is sold
                                      }
                                      if (buy_amt >= offers[offerId].pay_amt) {                       //If amount to buy is higher or equal than current offer amount to sell
                                          fill_amt = add(fill_amt, offers[offerId].buy_amt);          //Add amount sold to acumulator
                                          buy_amt = sub(buy_amt, offers[offerId].pay_amt);            //Decrease amount to buy
                                          take(bytes32(offerId), uint128(offers[offerId].pay_amt));   //We take the whole offer
                                      } else {                                                        //if lower
                                          fill_amt = add(fill_amt, rmul(buy_amt * 10 ** 9, rdiv(offers[offerId].buy_amt, offers[offerId].pay_amt)) / 10 ** 9); //Add amount sold to acumulator
                                          take(bytes32(offerId), uint128(buy_amt));                   //We take the portion of the offer that we need
                                          buy_amt = 0;                                                //All amount is bought
                                      }
                                  }
                                  require(fill_amt <= max_fill_amount);
                              }
                          
                              function getBuyAmount(ERC20 buy_gem, ERC20 pay_gem, uint pay_amt) public constant returns (uint fill_amt) {
                                  var offerId = getBestOffer(buy_gem, pay_gem);           //Get best offer for the token pair
                                  while (pay_amt > offers[offerId].buy_amt) {
                                      fill_amt = add(fill_amt, offers[offerId].pay_amt);  //Add amount to buy accumulator
                                      pay_amt = sub(pay_amt, offers[offerId].buy_amt);    //Decrease amount to pay
                                      if (pay_amt > 0) {                                  //If we still need more offers
                                          offerId = getWorseOffer(offerId);               //We look for the next best offer
                                          require(offerId != 0);                          //Fails if there are not enough offers to complete
                                      }
                                  }
                                  fill_amt = add(fill_amt, rmul(pay_amt * 10 ** 9, rdiv(offers[offerId].pay_amt, offers[offerId].buy_amt)) / 10 ** 9); //Add proportional amount of last offer to buy accumulator
                              }
                          
                              function getPayAmount(ERC20 pay_gem, ERC20 buy_gem, uint buy_amt) public constant returns (uint fill_amt) {
                                  var offerId = getBestOffer(buy_gem, pay_gem);           //Get best offer for the token pair
                                  while (buy_amt > offers[offerId].pay_amt) {
                                      fill_amt = add(fill_amt, offers[offerId].buy_amt);  //Add amount to pay accumulator
                                      buy_amt = sub(buy_amt, offers[offerId].pay_amt);    //Decrease amount to buy
                                      if (buy_amt > 0) {                                  //If we still need more offers
                                          offerId = getWorseOffer(offerId);               //We look for the next best offer
                                          require(offerId != 0);                          //Fails if there are not enough offers to complete
                                      }
                                  }
                                  fill_amt = add(fill_amt, rmul(buy_amt * 10 ** 9, rdiv(offers[offerId].buy_amt, offers[offerId].pay_amt)) / 10 ** 9); //Add proportional amount of last offer to pay accumulator
                              }
                          
                              // ---- Internal Functions ---- //
                          
                              function _buys(uint id, uint amount)
                                  internal
                                  returns (bool)
                              {
                                  require(buyEnabled);
                                  if (amount == offers[id].pay_amt) {
                                      if (isOfferSorted(id)) {
                                          //offers[id] must be removed from sorted list because all of it is bought
                                          _unsort(id);
                                      }else{
                                          _hide(id);
                                      }
                                  }
                                  require(super.buy(id, amount));
                                  // If offer has become dust during buy, we cancel it
                                  if (isActive(id) && offers[id].pay_amt < _dust[offers[id].pay_gem]) {
                                      dustId = id; //enable current msg.sender to call cancel(id)
                                      cancel(id);
                                  }
                                  return true;
                              }
                          
                              //find the id of the next higher offer after offers[id]
                              function _find(uint id)
                                  internal
                                  view
                                  returns (uint)
                              {
                                  require( id > 0 );
                          
                                  address buy_gem = address(offers[id].buy_gem);
                                  address pay_gem = address(offers[id].pay_gem);
                                  uint top = _best[pay_gem][buy_gem];
                                  uint old_top = 0;
                          
                                  // Find the larger-than-id order whose successor is less-than-id.
                                  while (top != 0 && _isPricedLtOrEq(id, top)) {
                                      old_top = top;
                                      top = _rank[top].prev;
                                  }
                                  return old_top;
                              }
                          
                              //find the id of the next higher offer after offers[id]
                              function _findpos(uint id, uint pos)
                                  internal
                                  view
                                  returns (uint)
                              {
                                  require(id > 0);
                          
                                  // Look for an active order.
                                  while (pos != 0 && !isActive(pos)) {
                                      pos = _rank[pos].prev;
                                  }
                          
                                  if (pos == 0) {
                                      //if we got to the end of list without a single active offer
                                      return _find(id);
                          
                                  } else {
                                      // if we did find a nearby active offer
                                      // Walk the order book down from there...
                                      if(_isPricedLtOrEq(id, pos)) {
                                          uint old_pos;
                          
                                          // Guaranteed to run at least once because of
                                          // the prior if statements.
                                          while (pos != 0 && _isPricedLtOrEq(id, pos)) {
                                              old_pos = pos;
                                              pos = _rank[pos].prev;
                                          }
                                          return old_pos;
                          
                                      // ...or walk it up.
                                      } else {
                                          while (pos != 0 && !_isPricedLtOrEq(id, pos)) {
                                              pos = _rank[pos].next;
                                          }
                                          return pos;
                                      }
                                  }
                              }
                          
                              //return true if offers[low] priced less than or equal to offers[high]
                              function _isPricedLtOrEq(
                                  uint low,   //lower priced offer's id
                                  uint high   //higher priced offer's id
                              )
                                  internal
                                  view
                                  returns (bool)
                              {
                                  return mul(offers[low].buy_amt, offers[high].pay_amt)
                                    >= mul(offers[high].buy_amt, offers[low].pay_amt);
                              }
                          
                              //these variables are global only because of solidity local variable limit
                          
                              //match offers with taker offer, and execute token transactions
                              function _matcho(
                                  uint t_pay_amt,    //taker sell how much
                                  ERC20 t_pay_gem,   //taker sell which token
                                  uint t_buy_amt,    //taker buy how much
                                  ERC20 t_buy_gem,   //taker buy which token
                                  uint pos,          //position id
                                  bool rounding      //match "close enough" orders?
                              )
                                  internal
                                  returns (uint id)
                              {
                                  uint best_maker_id;    //highest maker id
                                  uint t_buy_amt_old;    //taker buy how much saved
                                  uint m_buy_amt;        //maker offer wants to buy this much token
                                  uint m_pay_amt;        //maker offer wants to sell this much token
                          
                                  // there is at least one offer stored for token pair
                                  while (_best[t_buy_gem][t_pay_gem] > 0) {
                                      best_maker_id = _best[t_buy_gem][t_pay_gem];
                                      m_buy_amt = offers[best_maker_id].buy_amt;
                                      m_pay_amt = offers[best_maker_id].pay_amt;
                          
                                      // Ugly hack to work around rounding errors. Based on the idea that
                                      // the furthest the amounts can stray from their "true" values is 1.
                                      // Ergo the worst case has t_pay_amt and m_pay_amt at +1 away from
                                      // their "correct" values and m_buy_amt and t_buy_amt at -1.
                                      // Since (c - 1) * (d - 1) > (a + 1) * (b + 1) is equivalent to
                                      // c * d > a * b + a + b + c + d, we write...
                                      if (mul(m_buy_amt, t_buy_amt) > mul(t_pay_amt, m_pay_amt) +
                                          (rounding ? m_buy_amt + t_buy_amt + t_pay_amt + m_pay_amt : 0))
                                      {
                                          break;
                                      }
                                      // ^ The `rounding` parameter is a compromise borne of a couple days
                                      // of discussion.
                                      buy(best_maker_id, min(m_pay_amt, t_buy_amt));
                                      t_buy_amt_old = t_buy_amt;
                                      t_buy_amt = sub(t_buy_amt, min(m_pay_amt, t_buy_amt));
                                      t_pay_amt = mul(t_buy_amt, t_pay_amt) / t_buy_amt_old;
                          
                                      if (t_pay_amt == 0 || t_buy_amt == 0) {
                                          break;
                                      }
                                  }
                          
                                  if (t_buy_amt > 0 && t_pay_amt > 0 && t_pay_amt >= _dust[t_pay_gem]) {
                                      //new offer should be created
                                      id = super.offer(t_pay_amt, t_pay_gem, t_buy_amt, t_buy_gem);
                                      //insert offer into the sorted list
                                      _sort(id, pos);
                                  }
                              }
                          
                              // Make a new offer without putting it in the sorted list.
                              // Takes funds from the caller into market escrow.
                              // ****Available to authorized contracts only!**********
                              // Keepers should call insert(id,pos) to put offer in the sorted list.
                              function _offeru(
                                  uint pay_amt,      //maker (ask) sell how much
                                  ERC20 pay_gem,     //maker (ask) sell which token
                                  uint buy_amt,      //maker (ask) buy how much
                                  ERC20 buy_gem      //maker (ask) buy which token
                              )
                                  internal
                                  returns (uint id)
                              {
                                  require(_dust[pay_gem] <= pay_amt);
                                  id = super.offer(pay_amt, pay_gem, buy_amt, buy_gem);
                                  _near[id] = _head;
                                  _head = id;
                                  LogUnsortedOffer(id);
                              }
                          
                              //put offer into the sorted list
                              function _sort(
                                  uint id,    //maker (ask) id
                                  uint pos    //position to insert into
                              )
                                  internal
                              {
                                  require(isActive(id));
                          
                                  address buy_gem = address(offers[id].buy_gem);
                                  address pay_gem = address(offers[id].pay_gem);
                                  uint prev_id;                                      //maker (ask) id
                          
                                  pos = pos == 0 || offers[pos].pay_gem != pay_gem || offers[pos].buy_gem != buy_gem || !isOfferSorted(pos)
                                  ?
                                      _find(id)
                                  :
                                      _findpos(id, pos);
                          
                                  if (pos != 0) {                                    //offers[id] is not the highest offer
                                      //requirement below is satisfied by statements above
                                      //require(_isPricedLtOrEq(id, pos));
                                      prev_id = _rank[pos].prev;
                                      _rank[pos].prev = id;
                                      _rank[id].next = pos;
                                  } else {                                           //offers[id] is the highest offer
                                      prev_id = _best[pay_gem][buy_gem];
                                      _best[pay_gem][buy_gem] = id;
                                  }
                          
                                  if (prev_id != 0) {                               //if lower offer does exist
                                      //requirement below is satisfied by statements above
                                      //require(!_isPricedLtOrEq(id, prev_id));
                                      _rank[prev_id].next = id;
                                      _rank[id].prev = prev_id;
                                  }
                          
                                  _span[pay_gem][buy_gem]++;
                                  LogSortedOffer(id);
                              }
                          
                              // Remove offer from the sorted list (does not cancel offer)
                              function _unsort(
                                  uint id    //id of maker (ask) offer to remove from sorted list
                              )
                                  internal
                                  returns (bool)
                              {
                                  address buy_gem = address(offers[id].buy_gem);
                                  address pay_gem = address(offers[id].pay_gem);
                                  require(_span[pay_gem][buy_gem] > 0);
                          
                                  require(_rank[id].delb == 0 &&                    //assert id is in the sorted list
                                           isOfferSorted(id));
                          
                                  if (id != _best[pay_gem][buy_gem]) {              // offers[id] is not the highest offer
                                      require(_rank[_rank[id].next].prev == id);
                                      _rank[_rank[id].next].prev = _rank[id].prev;
                                  } else {                                          //offers[id] is the highest offer
                                      _best[pay_gem][buy_gem] = _rank[id].prev;
                                  }
                          
                                  if (_rank[id].prev != 0) {                        //offers[id] is not the lowest offer
                                      require(_rank[_rank[id].prev].next == id);
                                      _rank[_rank[id].prev].next = _rank[id].next;
                                  }
                          
                                  _span[pay_gem][buy_gem]--;
                                  _rank[id].delb = block.number;                    //mark _rank[id] for deletion
                                  return true;
                              }
                          
                              //Hide offer from the unsorted order book (does not cancel offer)
                              function _hide(
                                  uint id     //id of maker offer to remove from unsorted list
                              )
                                  internal
                                  returns (bool)
                              {
                                  uint uid = _head;               //id of an offer in unsorted offers list
                                  uint pre = uid;                 //id of previous offer in unsorted offers list
                          
                                  require(!isOfferSorted(id));    //make sure offer id is not in sorted offers list
                          
                                  if (_head == id) {              //check if offer is first offer in unsorted offers list
                                      _head = _near[id];          //set head to new first unsorted offer
                                      _near[id] = 0;              //delete order from unsorted order list
                                      return true;
                                  }
                                  while (uid > 0 && uid != id) {  //find offer in unsorted order list
                                      pre = uid;
                                      uid = _near[uid];
                                  }
                                  if (uid != id) {                //did not find offer id in unsorted offers list
                                      return false;
                                  }
                                  _near[pre] = _near[id];         //set previous unsorted offer to point to offer after offer id
                                  _near[id] = 0;                  //delete order from unsorted order list
                                  return true;
                              }
                          }

                          File 5 of 13: DSToken
                          // MKR Token
                          
                          // hevm: flattened sources of src/mkr-499.sol
                          pragma solidity ^0.4.15;
                          
                          ////// lib/ds-roles/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-thing/lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-thing/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-thing/src/thing.sol
                          // thing.sol - `auth` with handy mixins. your things should be DSThings
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import 'ds-auth/auth.sol'; */
                          /* import 'ds-note/note.sol'; */
                          /* import 'ds-math/math.sol'; */
                          
                          contract DSThing is DSAuth, DSNote, DSMath {
                          }
                          
                          ////// lib/ds-token/lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// lib/ds-token/lib/erc20/src/erc20.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.8; */
                          
                          // Token standard API
                          // https://github.com/ethereum/EIPs/issues/20
                          
                          contract ERC20 {
                              function totalSupply() public view returns (uint supply);
                              function balanceOf( address who ) public view returns (uint value);
                              function allowance( address owner, address spender ) public view returns (uint _allowance);
                          
                              function transfer( address to, uint value) public returns (bool ok);
                              function transferFrom( address from, address to, uint value) public returns (bool ok);
                              function approve( address spender, uint value ) public returns (bool ok);
                          
                              event Transfer( address indexed from, address indexed to, uint value);
                              event Approval( address indexed owner, address indexed spender, uint value);
                          }
                          
                          ////// lib/ds-token/src/base.sol
                          /// base.sol -- basic ERC20 implementation
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "erc20/erc20.sol"; */
                          /* import "ds-math/math.sol"; */
                          
                          contract DSTokenBase is ERC20, DSMath {
                              uint256                                            _supply;
                              mapping (address => uint256)                       _balances;
                              mapping (address => mapping (address => uint256))  _approvals;
                          
                              function DSTokenBase(uint supply) public {
                                  _balances[msg.sender] = supply;
                                  _supply = supply;
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return _supply;
                              }
                              function balanceOf(address src) public view returns (uint) {
                                  return _balances[src];
                              }
                              function allowance(address src, address guy) public view returns (uint) {
                                  return _approvals[src][guy];
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  if (src != msg.sender) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  _approvals[msg.sender][guy] = wad;
                          
                                  Approval(msg.sender, guy, wad);
                          
                                  return true;
                              }
                          }
                          
                          ////// lib/ds-token/src/token.sol
                          /// token.sol -- ERC20 implementation with minting and burning
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-stop/stop.sol"; */
                          
                          /* import "./base.sol"; */
                          
                          contract DSToken is DSTokenBase(0), DSStop {
                          
                              bytes32  public  symbol;
                              uint256  public  decimals = 18; // standard token precision. override to customize
                          
                              function DSToken(bytes32 symbol_) public {
                                  symbol = symbol_;
                              }
                          
                              event Mint(address indexed guy, uint wad);
                              event Burn(address indexed guy, uint wad);
                          
                              function approve(address guy) public stoppable returns (bool) {
                                  return super.approve(guy, uint(-1));
                              }
                          
                              function approve(address guy, uint wad) public stoppable returns (bool) {
                                  return super.approve(guy, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  stoppable
                                  returns (bool)
                              {
                                  if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function push(address dst, uint wad) public {
                                  transferFrom(msg.sender, dst, wad);
                              }
                              function pull(address src, uint wad) public {
                                  transferFrom(src, msg.sender, wad);
                              }
                              function move(address src, address dst, uint wad) public {
                                  transferFrom(src, dst, wad);
                              }
                          
                              function mint(uint wad) public {
                                  mint(msg.sender, wad);
                              }
                              function burn(uint wad) public {
                                  burn(msg.sender, wad);
                              }
                              function mint(address guy, uint wad) public auth stoppable {
                                  _balances[guy] = add(_balances[guy], wad);
                                  _supply = add(_supply, wad);
                                  Mint(guy, wad);
                              }
                              function burn(address guy, uint wad) public auth stoppable {
                                  if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) {
                                      _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad);
                                  }
                          
                                  _balances[guy] = sub(_balances[guy], wad);
                                  _supply = sub(_supply, wad);
                                  Burn(guy, wad);
                              }
                          
                              // Optional token name
                              bytes32   public  name = "";
                          
                              function setName(bytes32 name_) public auth {
                                  name = name_;
                              }
                          }

                          File 6 of 13: GemPit
                          pragma solidity ^0.4.13;
                          
                          ////// lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// lib/erc20/src/erc20.sol
                          /// erc20.sol -- API for the ERC20 token standard
                          
                          // See <https://github.com/ethereum/EIPs/issues/20>.
                          
                          // This file likely does not meet the threshold of originality
                          // required for copyright to apply.  As a result, this is free and
                          // unencumbered software belonging to the public domain.
                          
                          /* pragma solidity ^0.4.8; */
                          
                          contract ERC20Events {
                              event Approval(address indexed src, address indexed guy, uint wad);
                              event Transfer(address indexed src, address indexed dst, uint wad);
                          }
                          
                          contract ERC20 is ERC20Events {
                              function totalSupply() public view returns (uint);
                              function balanceOf(address guy) public view returns (uint);
                              function allowance(address src, address guy) public view returns (uint);
                          
                              function approve(address guy, uint wad) public returns (bool);
                              function transfer(address dst, uint wad) public returns (bool);
                              function transferFrom(
                                  address src, address dst, uint wad
                              ) public returns (bool);
                          }
                          
                          ////// src/base.sol
                          /// base.sol -- basic ERC20 implementation
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "erc20/erc20.sol"; */
                          /* import "ds-math/math.sol"; */
                          
                          contract DSTokenBase is ERC20, DSMath {
                              uint256                                            _supply;
                              mapping (address => uint256)                       _balances;
                              mapping (address => mapping (address => uint256))  _approvals;
                          
                              function DSTokenBase(uint supply) public {
                                  _balances[msg.sender] = supply;
                                  _supply = supply;
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return _supply;
                              }
                              function balanceOf(address src) public view returns (uint) {
                                  return _balances[src];
                              }
                              function allowance(address src, address guy) public view returns (uint) {
                                  return _approvals[src][guy];
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  if (src != msg.sender) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  _approvals[msg.sender][guy] = wad;
                          
                                  Approval(msg.sender, guy, wad);
                          
                                  return true;
                              }
                          }
                          
                          ////// src/token.sol
                          /// token.sol -- ERC20 implementation with minting and burning
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-stop/stop.sol"; */
                          
                          /* import "./base.sol"; */
                          
                          contract DSToken is DSTokenBase(0), DSStop {
                          
                              bytes32  public  symbol;
                              uint256  public  decimals = 18; // standard token precision. override to customize
                          
                              function DSToken(bytes32 symbol_) public {
                                  symbol = symbol_;
                              }
                          
                              event Mint(address indexed guy, uint wad);
                              event Burn(address indexed guy, uint wad);
                          
                              function approve(address guy) public stoppable returns (bool) {
                                  return super.approve(guy, uint(-1));
                              }
                          
                              function approve(address guy, uint wad) public stoppable returns (bool) {
                                  return super.approve(guy, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  stoppable
                                  returns (bool)
                              {
                                  if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function push(address dst, uint wad) public {
                                  transferFrom(msg.sender, dst, wad);
                              }
                              function pull(address src, uint wad) public {
                                  transferFrom(src, msg.sender, wad);
                              }
                              function move(address src, address dst, uint wad) public {
                                  transferFrom(src, dst, wad);
                              }
                          
                              function mint(uint wad) public {
                                  mint(msg.sender, wad);
                              }
                              function burn(uint wad) public {
                                  burn(msg.sender, wad);
                              }
                              function mint(address guy, uint wad) public auth stoppable {
                                  _balances[guy] = add(_balances[guy], wad);
                                  _supply = add(_supply, wad);
                                  Mint(guy, wad);
                              }
                              function burn(address guy, uint wad) public auth stoppable {
                                  if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) {
                                      _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad);
                                  }
                          
                                  _balances[guy] = sub(_balances[guy], wad);
                                  _supply = sub(_supply, wad);
                                  Burn(guy, wad);
                              }
                          
                              // Optional token name
                              bytes32   public  name = "";
                          
                              function setName(bytes32 name_) public auth {
                                  name = name_;
                              }
                          }
                          
                          contract GemPit {
                              function burn(DSToken gem) public {
                                  gem.burn(gem.balanceOf(this));
                              }
                          }

                          File 7 of 13: DSToken
                          pragma solidity ^0.4.13;
                          
                          ////// lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// lib/erc20/src/erc20.sol
                          /// erc20.sol -- API for the ERC20 token standard
                          
                          // See <https://github.com/ethereum/EIPs/issues/20>.
                          
                          // This file likely does not meet the threshold of originality
                          // required for copyright to apply.  As a result, this is free and
                          // unencumbered software belonging to the public domain.
                          
                          /* pragma solidity ^0.4.8; */
                          
                          contract ERC20Events {
                              event Approval(address indexed src, address indexed guy, uint wad);
                              event Transfer(address indexed src, address indexed dst, uint wad);
                          }
                          
                          contract ERC20 is ERC20Events {
                              function totalSupply() public view returns (uint);
                              function balanceOf(address guy) public view returns (uint);
                              function allowance(address src, address guy) public view returns (uint);
                          
                              function approve(address guy, uint wad) public returns (bool);
                              function transfer(address dst, uint wad) public returns (bool);
                              function transferFrom(
                                  address src, address dst, uint wad
                              ) public returns (bool);
                          }
                          
                          ////// src/base.sol
                          /// base.sol -- basic ERC20 implementation
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "erc20/erc20.sol"; */
                          /* import "ds-math/math.sol"; */
                          
                          contract DSTokenBase is ERC20, DSMath {
                              uint256                                            _supply;
                              mapping (address => uint256)                       _balances;
                              mapping (address => mapping (address => uint256))  _approvals;
                          
                              function DSTokenBase(uint supply) public {
                                  _balances[msg.sender] = supply;
                                  _supply = supply;
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return _supply;
                              }
                              function balanceOf(address src) public view returns (uint) {
                                  return _balances[src];
                              }
                              function allowance(address src, address guy) public view returns (uint) {
                                  return _approvals[src][guy];
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  if (src != msg.sender) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  _approvals[msg.sender][guy] = wad;
                          
                                  Approval(msg.sender, guy, wad);
                          
                                  return true;
                              }
                          }
                          
                          ////// src/token.sol
                          /// token.sol -- ERC20 implementation with minting and burning
                          
                          // Copyright (C) 2015, 2016, 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-stop/stop.sol"; */
                          
                          /* import "./base.sol"; */
                          
                          contract DSToken is DSTokenBase(0), DSStop {
                          
                              bytes32  public  symbol;
                              uint256  public  decimals = 18; // standard token precision. override to customize
                          
                              function DSToken(bytes32 symbol_) public {
                                  symbol = symbol_;
                              }
                          
                              event Mint(address indexed guy, uint wad);
                              event Burn(address indexed guy, uint wad);
                          
                              function approve(address guy) public stoppable returns (bool) {
                                  return super.approve(guy, uint(-1));
                              }
                          
                              function approve(address guy, uint wad) public stoppable returns (bool) {
                                  return super.approve(guy, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  stoppable
                                  returns (bool)
                              {
                                  if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) {
                                      _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
                                  }
                          
                                  _balances[src] = sub(_balances[src], wad);
                                  _balances[dst] = add(_balances[dst], wad);
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          
                              function push(address dst, uint wad) public {
                                  transferFrom(msg.sender, dst, wad);
                              }
                              function pull(address src, uint wad) public {
                                  transferFrom(src, msg.sender, wad);
                              }
                              function move(address src, address dst, uint wad) public {
                                  transferFrom(src, dst, wad);
                              }
                          
                              function mint(uint wad) public {
                                  mint(msg.sender, wad);
                              }
                              function burn(uint wad) public {
                                  burn(msg.sender, wad);
                              }
                              function mint(address guy, uint wad) public auth stoppable {
                                  _balances[guy] = add(_balances[guy], wad);
                                  _supply = add(_supply, wad);
                                  Mint(guy, wad);
                              }
                              function burn(address guy, uint wad) public auth stoppable {
                                  if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) {
                                      _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad);
                                  }
                          
                                  _balances[guy] = sub(_balances[guy], wad);
                                  _supply = sub(_supply, wad);
                                  Burn(guy, wad);
                              }
                          
                              // Optional token name
                              bytes32   public  name = "";
                          
                              function setName(bytes32 name_) public auth {
                                  name = name_;
                              }
                          }

                          File 8 of 13: SaiVox
                          // hevm: flattened sources of src/vox.sol
                          pragma solidity ^0.4.18;
                          
                          ////// lib/ds-guard/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-spell/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-thing/lib/ds-math/src/math.sol
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          ////// lib/ds-thing/src/thing.sol
                          // thing.sol - `auth` with handy mixins. your things should be DSThings
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import 'ds-auth/auth.sol'; */
                          /* import 'ds-note/note.sol'; */
                          /* import 'ds-math/math.sol'; */
                          
                          contract DSThing is DSAuth, DSNote, DSMath {
                          
                              function S(string s) internal pure returns (bytes4) {
                                  return bytes4(keccak256(s));
                              }
                          
                          }
                          
                          ////// src/vox.sol
                          /// vox.sol -- target price feed
                          
                          // Copyright (C) 2016, 2017  Nikolai Mushegian <[email protected]>
                          // Copyright (C) 2016, 2017  Daniel Brockman <[email protected]>
                          // Copyright (C) 2017        Rain Break <[email protected]>
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.18; */
                          
                          /* import "ds-thing/thing.sol"; */
                          
                          contract SaiVox is DSThing {
                              uint256  _par;
                              uint256  _way;
                          
                              uint256  public  fix;
                              uint256  public  how;
                              uint256  public  tau;
                          
                              function SaiVox(uint par_) public {
                                  _par = fix = par_;
                                  _way = RAY;
                                  tau  = era();
                              }
                          
                              function era() public view returns (uint) {
                                  return block.timestamp;
                              }
                          
                              function mold(bytes32 param, uint val) public note auth {
                                  if (param == 'way') _way = val;
                              }
                          
                              // Dai Target Price (ref per dai)
                              function par() public returns (uint) {
                                  prod();
                                  return _par;
                              }
                              function way() public returns (uint) {
                                  prod();
                                  return _way;
                              }
                          
                              function tell(uint256 ray) public note auth {
                                  fix = ray;
                              }
                              function tune(uint256 ray) public note auth {
                                  how = ray;
                              }
                          
                              function prod() public note {
                                  var age = era() - tau;
                                  if (age == 0) return;  // optimised
                                  tau = era();
                          
                                  if (_way != RAY) _par = rmul(_par, rpow(_way, age));  // optimised
                          
                                  if (how == 0) return;  // optimised
                                  var wag = int128(how * age);
                                  _way = inj(prj(_way) + (fix < _par ? wag : -wag));
                              }
                          
                              function inj(int128 x) internal pure returns (uint256) {
                                  return x >= 0 ? uint256(x) + RAY
                                      : rdiv(RAY, RAY + uint256(-x));
                              }
                              function prj(uint256 x) internal pure returns (int128) {
                                  return x >= RAY ? int128(x - RAY)
                                      : int128(RAY) - int128(rdiv(RAY, x));
                              }
                          }

                          File 9 of 13: WETH9
                          // Copyright (C) 2015, 2016, 2017 Dapphub
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.18;
                          
                          contract WETH9 {
                              string public name     = "Wrapped Ether";
                              string public symbol   = "WETH";
                              uint8  public decimals = 18;
                          
                              event  Approval(address indexed src, address indexed guy, uint wad);
                              event  Transfer(address indexed src, address indexed dst, uint wad);
                              event  Deposit(address indexed dst, uint wad);
                              event  Withdrawal(address indexed src, uint wad);
                          
                              mapping (address => uint)                       public  balanceOf;
                              mapping (address => mapping (address => uint))  public  allowance;
                          
                              function() public payable {
                                  deposit();
                              }
                              function deposit() public payable {
                                  balanceOf[msg.sender] += msg.value;
                                  Deposit(msg.sender, msg.value);
                              }
                              function withdraw(uint wad) public {
                                  require(balanceOf[msg.sender] >= wad);
                                  balanceOf[msg.sender] -= wad;
                                  msg.sender.transfer(wad);
                                  Withdrawal(msg.sender, wad);
                              }
                          
                              function totalSupply() public view returns (uint) {
                                  return this.balance;
                              }
                          
                              function approve(address guy, uint wad) public returns (bool) {
                                  allowance[msg.sender][guy] = wad;
                                  Approval(msg.sender, guy, wad);
                                  return true;
                              }
                          
                              function transfer(address dst, uint wad) public returns (bool) {
                                  return transferFrom(msg.sender, dst, wad);
                              }
                          
                              function transferFrom(address src, address dst, uint wad)
                                  public
                                  returns (bool)
                              {
                                  require(balanceOf[src] >= wad);
                          
                                  if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
                                      require(allowance[src][msg.sender] >= wad);
                                      allowance[src][msg.sender] -= wad;
                                  }
                          
                                  balanceOf[src] -= wad;
                                  balanceOf[dst] += wad;
                          
                                  Transfer(src, dst, wad);
                          
                                  return true;
                              }
                          }
                          
                          
                          /*
                                              GNU GENERAL PUBLIC LICENSE
                                                 Version 3, 29 June 2007
                          
                           Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
                           Everyone is permitted to copy and distribute verbatim copies
                           of this license document, but changing it is not allowed.
                          
                                                      Preamble
                          
                            The GNU General Public License is a free, copyleft license for
                          software and other kinds of works.
                          
                            The licenses for most software and other practical works are designed
                          to take away your freedom to share and change the works.  By contrast,
                          the GNU General Public License is intended to guarantee your freedom to
                          share and change all versions of a program--to make sure it remains free
                          software for all its users.  We, the Free Software Foundation, use the
                          GNU General Public License for most of our software; it applies also to
                          any other work released this way by its authors.  You can apply it to
                          your programs, too.
                          
                            When we speak of free software, we are referring to freedom, not
                          price.  Our General Public Licenses are designed to make sure that you
                          have the freedom to distribute copies of free software (and charge for
                          them if you wish), that you receive source code or can get it if you
                          want it, that you can change the software or use pieces of it in new
                          free programs, and that you know you can do these things.
                          
                            To protect your rights, we need to prevent others from denying you
                          these rights or asking you to surrender the rights.  Therefore, you have
                          certain responsibilities if you distribute copies of the software, or if
                          you modify it: responsibilities to respect the freedom of others.
                          
                            For example, if you distribute copies of such a program, whether
                          gratis or for a fee, you must pass on to the recipients the same
                          freedoms that you received.  You must make sure that they, too, receive
                          or can get the source code.  And you must show them these terms so they
                          know their rights.
                          
                            Developers that use the GNU GPL protect your rights with two steps:
                          (1) assert copyright on the software, and (2) offer you this License
                          giving you legal permission to copy, distribute and/or modify it.
                          
                            For the developers' and authors' protection, the GPL clearly explains
                          that there is no warranty for this free software.  For both users' and
                          authors' sake, the GPL requires that modified versions be marked as
                          changed, so that their problems will not be attributed erroneously to
                          authors of previous versions.
                          
                            Some devices are designed to deny users access to install or run
                          modified versions of the software inside them, although the manufacturer
                          can do so.  This is fundamentally incompatible with the aim of
                          protecting users' freedom to change the software.  The systematic
                          pattern of such abuse occurs in the area of products for individuals to
                          use, which is precisely where it is most unacceptable.  Therefore, we
                          have designed this version of the GPL to prohibit the practice for those
                          products.  If such problems arise substantially in other domains, we
                          stand ready to extend this provision to those domains in future versions
                          of the GPL, as needed to protect the freedom of users.
                          
                            Finally, every program is threatened constantly by software patents.
                          States should not allow patents to restrict development and use of
                          software on general-purpose computers, but in those that do, we wish to
                          avoid the special danger that patents applied to a free program could
                          make it effectively proprietary.  To prevent this, the GPL assures that
                          patents cannot be used to render the program non-free.
                          
                            The precise terms and conditions for copying, distribution and
                          modification follow.
                          
                                                 TERMS AND CONDITIONS
                          
                            0. Definitions.
                          
                            "This License" refers to version 3 of the GNU General Public License.
                          
                            "Copyright" also means copyright-like laws that apply to other kinds of
                          works, such as semiconductor masks.
                          
                            "The Program" refers to any copyrightable work licensed under this
                          License.  Each licensee is addressed as "you".  "Licensees" and
                          "recipients" may be individuals or organizations.
                          
                            To "modify" a work means to copy from or adapt all or part of the work
                          in a fashion requiring copyright permission, other than the making of an
                          exact copy.  The resulting work is called a "modified version" of the
                          earlier work or a work "based on" the earlier work.
                          
                            A "covered work" means either the unmodified Program or a work based
                          on the Program.
                          
                            To "propagate" a work means to do anything with it that, without
                          permission, would make you directly or secondarily liable for
                          infringement under applicable copyright law, except executing it on a
                          computer or modifying a private copy.  Propagation includes copying,
                          distribution (with or without modification), making available to the
                          public, and in some countries other activities as well.
                          
                            To "convey" a work means any kind of propagation that enables other
                          parties to make or receive copies.  Mere interaction with a user through
                          a computer network, with no transfer of a copy, is not conveying.
                          
                            An interactive user interface displays "Appropriate Legal Notices"
                          to the extent that it includes a convenient and prominently visible
                          feature that (1) displays an appropriate copyright notice, and (2)
                          tells the user that there is no warranty for the work (except to the
                          extent that warranties are provided), that licensees may convey the
                          work under this License, and how to view a copy of this License.  If
                          the interface presents a list of user commands or options, such as a
                          menu, a prominent item in the list meets this criterion.
                          
                            1. Source Code.
                          
                            The "source code" for a work means the preferred form of the work
                          for making modifications to it.  "Object code" means any non-source
                          form of a work.
                          
                            A "Standard Interface" means an interface that either is an official
                          standard defined by a recognized standards body, or, in the case of
                          interfaces specified for a particular programming language, one that
                          is widely used among developers working in that language.
                          
                            The "System Libraries" of an executable work include anything, other
                          than the work as a whole, that (a) is included in the normal form of
                          packaging a Major Component, but which is not part of that Major
                          Component, and (b) serves only to enable use of the work with that
                          Major Component, or to implement a Standard Interface for which an
                          implementation is available to the public in source code form.  A
                          "Major Component", in this context, means a major essential component
                          (kernel, window system, and so on) of the specific operating system
                          (if any) on which the executable work runs, or a compiler used to
                          produce the work, or an object code interpreter used to run it.
                          
                            The "Corresponding Source" for a work in object code form means all
                          the source code needed to generate, install, and (for an executable
                          work) run the object code and to modify the work, including scripts to
                          control those activities.  However, it does not include the work's
                          System Libraries, or general-purpose tools or generally available free
                          programs which are used unmodified in performing those activities but
                          which are not part of the work.  For example, Corresponding Source
                          includes interface definition files associated with source files for
                          the work, and the source code for shared libraries and dynamically
                          linked subprograms that the work is specifically designed to require,
                          such as by intimate data communication or control flow between those
                          subprograms and other parts of the work.
                          
                            The Corresponding Source need not include anything that users
                          can regenerate automatically from other parts of the Corresponding
                          Source.
                          
                            The Corresponding Source for a work in source code form is that
                          same work.
                          
                            2. Basic Permissions.
                          
                            All rights granted under this License are granted for the term of
                          copyright on the Program, and are irrevocable provided the stated
                          conditions are met.  This License explicitly affirms your unlimited
                          permission to run the unmodified Program.  The output from running a
                          covered work is covered by this License only if the output, given its
                          content, constitutes a covered work.  This License acknowledges your
                          rights of fair use or other equivalent, as provided by copyright law.
                          
                            You may make, run and propagate covered works that you do not
                          convey, without conditions so long as your license otherwise remains
                          in force.  You may convey covered works to others for the sole purpose
                          of having them make modifications exclusively for you, or provide you
                          with facilities for running those works, provided that you comply with
                          the terms of this License in conveying all material for which you do
                          not control copyright.  Those thus making or running the covered works
                          for you must do so exclusively on your behalf, under your direction
                          and control, on terms that prohibit them from making any copies of
                          your copyrighted material outside their relationship with you.
                          
                            Conveying under any other circumstances is permitted solely under
                          the conditions stated below.  Sublicensing is not allowed; section 10
                          makes it unnecessary.
                          
                            3. Protecting Users' Legal Rights From Anti-Circumvention Law.
                          
                            No covered work shall be deemed part of an effective technological
                          measure under any applicable law fulfilling obligations under article
                          11 of the WIPO copyright treaty adopted on 20 December 1996, or
                          similar laws prohibiting or restricting circumvention of such
                          measures.
                          
                            When you convey a covered work, you waive any legal power to forbid
                          circumvention of technological measures to the extent such circumvention
                          is effected by exercising rights under this License with respect to
                          the covered work, and you disclaim any intention to limit operation or
                          modification of the work as a means of enforcing, against the work's
                          users, your or third parties' legal rights to forbid circumvention of
                          technological measures.
                          
                            4. Conveying Verbatim Copies.
                          
                            You may convey verbatim copies of the Program's source code as you
                          receive it, in any medium, provided that you conspicuously and
                          appropriately publish on each copy an appropriate copyright notice;
                          keep intact all notices stating that this License and any
                          non-permissive terms added in accord with section 7 apply to the code;
                          keep intact all notices of the absence of any warranty; and give all
                          recipients a copy of this License along with the Program.
                          
                            You may charge any price or no price for each copy that you convey,
                          and you may offer support or warranty protection for a fee.
                          
                            5. Conveying Modified Source Versions.
                          
                            You may convey a work based on the Program, or the modifications to
                          produce it from the Program, in the form of source code under the
                          terms of section 4, provided that you also meet all of these conditions:
                          
                              a) The work must carry prominent notices stating that you modified
                              it, and giving a relevant date.
                          
                              b) The work must carry prominent notices stating that it is
                              released under this License and any conditions added under section
                              7.  This requirement modifies the requirement in section 4 to
                              "keep intact all notices".
                          
                              c) You must license the entire work, as a whole, under this
                              License to anyone who comes into possession of a copy.  This
                              License will therefore apply, along with any applicable section 7
                              additional terms, to the whole of the work, and all its parts,
                              regardless of how they are packaged.  This License gives no
                              permission to license the work in any other way, but it does not
                              invalidate such permission if you have separately received it.
                          
                              d) If the work has interactive user interfaces, each must display
                              Appropriate Legal Notices; however, if the Program has interactive
                              interfaces that do not display Appropriate Legal Notices, your
                              work need not make them do so.
                          
                            A compilation of a covered work with other separate and independent
                          works, which are not by their nature extensions of the covered work,
                          and which are not combined with it such as to form a larger program,
                          in or on a volume of a storage or distribution medium, is called an
                          "aggregate" if the compilation and its resulting copyright are not
                          used to limit the access or legal rights of the compilation's users
                          beyond what the individual works permit.  Inclusion of a covered work
                          in an aggregate does not cause this License to apply to the other
                          parts of the aggregate.
                          
                            6. Conveying Non-Source Forms.
                          
                            You may convey a covered work in object code form under the terms
                          of sections 4 and 5, provided that you also convey the
                          machine-readable Corresponding Source under the terms of this License,
                          in one of these ways:
                          
                              a) Convey the object code in, or embodied in, a physical product
                              (including a physical distribution medium), accompanied by the
                              Corresponding Source fixed on a durable physical medium
                              customarily used for software interchange.
                          
                              b) Convey the object code in, or embodied in, a physical product
                              (including a physical distribution medium), accompanied by a
                              written offer, valid for at least three years and valid for as
                              long as you offer spare parts or customer support for that product
                              model, to give anyone who possesses the object code either (1) a
                              copy of the Corresponding Source for all the software in the
                              product that is covered by this License, on a durable physical
                              medium customarily used for software interchange, for a price no
                              more than your reasonable cost of physically performing this
                              conveying of source, or (2) access to copy the
                              Corresponding Source from a network server at no charge.
                          
                              c) Convey individual copies of the object code with a copy of the
                              written offer to provide the Corresponding Source.  This
                              alternative is allowed only occasionally and noncommercially, and
                              only if you received the object code with such an offer, in accord
                              with subsection 6b.
                          
                              d) Convey the object code by offering access from a designated
                              place (gratis or for a charge), and offer equivalent access to the
                              Corresponding Source in the same way through the same place at no
                              further charge.  You need not require recipients to copy the
                              Corresponding Source along with the object code.  If the place to
                              copy the object code is a network server, the Corresponding Source
                              may be on a different server (operated by you or a third party)
                              that supports equivalent copying facilities, provided you maintain
                              clear directions next to the object code saying where to find the
                              Corresponding Source.  Regardless of what server hosts the
                              Corresponding Source, you remain obligated to ensure that it is
                              available for as long as needed to satisfy these requirements.
                          
                              e) Convey the object code using peer-to-peer transmission, provided
                              you inform other peers where the object code and Corresponding
                              Source of the work are being offered to the general public at no
                              charge under subsection 6d.
                          
                            A separable portion of the object code, whose source code is excluded
                          from the Corresponding Source as a System Library, need not be
                          included in conveying the object code work.
                          
                            A "User Product" is either (1) a "consumer product", which means any
                          tangible personal property which is normally used for personal, family,
                          or household purposes, or (2) anything designed or sold for incorporation
                          into a dwelling.  In determining whether a product is a consumer product,
                          doubtful cases shall be resolved in favor of coverage.  For a particular
                          product received by a particular user, "normally used" refers to a
                          typical or common use of that class of product, regardless of the status
                          of the particular user or of the way in which the particular user
                          actually uses, or expects or is expected to use, the product.  A product
                          is a consumer product regardless of whether the product has substantial
                          commercial, industrial or non-consumer uses, unless such uses represent
                          the only significant mode of use of the product.
                          
                            "Installation Information" for a User Product means any methods,
                          procedures, authorization keys, or other information required to install
                          and execute modified versions of a covered work in that User Product from
                          a modified version of its Corresponding Source.  The information must
                          suffice to ensure that the continued functioning of the modified object
                          code is in no case prevented or interfered with solely because
                          modification has been made.
                          
                            If you convey an object code work under this section in, or with, or
                          specifically for use in, a User Product, and the conveying occurs as
                          part of a transaction in which the right of possession and use of the
                          User Product is transferred to the recipient in perpetuity or for a
                          fixed term (regardless of how the transaction is characterized), the
                          Corresponding Source conveyed under this section must be accompanied
                          by the Installation Information.  But this requirement does not apply
                          if neither you nor any third party retains the ability to install
                          modified object code on the User Product (for example, the work has
                          been installed in ROM).
                          
                            The requirement to provide Installation Information does not include a
                          requirement to continue to provide support service, warranty, or updates
                          for a work that has been modified or installed by the recipient, or for
                          the User Product in which it has been modified or installed.  Access to a
                          network may be denied when the modification itself materially and
                          adversely affects the operation of the network or violates the rules and
                          protocols for communication across the network.
                          
                            Corresponding Source conveyed, and Installation Information provided,
                          in accord with this section must be in a format that is publicly
                          documented (and with an implementation available to the public in
                          source code form), and must require no special password or key for
                          unpacking, reading or copying.
                          
                            7. Additional Terms.
                          
                            "Additional permissions" are terms that supplement the terms of this
                          License by making exceptions from one or more of its conditions.
                          Additional permissions that are applicable to the entire Program shall
                          be treated as though they were included in this License, to the extent
                          that they are valid under applicable law.  If additional permissions
                          apply only to part of the Program, that part may be used separately
                          under those permissions, but the entire Program remains governed by
                          this License without regard to the additional permissions.
                          
                            When you convey a copy of a covered work, you may at your option
                          remove any additional permissions from that copy, or from any part of
                          it.  (Additional permissions may be written to require their own
                          removal in certain cases when you modify the work.)  You may place
                          additional permissions on material, added by you to a covered work,
                          for which you have or can give appropriate copyright permission.
                          
                            Notwithstanding any other provision of this License, for material you
                          add to a covered work, you may (if authorized by the copyright holders of
                          that material) supplement the terms of this License with terms:
                          
                              a) Disclaiming warranty or limiting liability differently from the
                              terms of sections 15 and 16 of this License; or
                          
                              b) Requiring preservation of specified reasonable legal notices or
                              author attributions in that material or in the Appropriate Legal
                              Notices displayed by works containing it; or
                          
                              c) Prohibiting misrepresentation of the origin of that material, or
                              requiring that modified versions of such material be marked in
                              reasonable ways as different from the original version; or
                          
                              d) Limiting the use for publicity purposes of names of licensors or
                              authors of the material; or
                          
                              e) Declining to grant rights under trademark law for use of some
                              trade names, trademarks, or service marks; or
                          
                              f) Requiring indemnification of licensors and authors of that
                              material by anyone who conveys the material (or modified versions of
                              it) with contractual assumptions of liability to the recipient, for
                              any liability that these contractual assumptions directly impose on
                              those licensors and authors.
                          
                            All other non-permissive additional terms are considered "further
                          restrictions" within the meaning of section 10.  If the Program as you
                          received it, or any part of it, contains a notice stating that it is
                          governed by this License along with a term that is a further
                          restriction, you may remove that term.  If a license document contains
                          a further restriction but permits relicensing or conveying under this
                          License, you may add to a covered work material governed by the terms
                          of that license document, provided that the further restriction does
                          not survive such relicensing or conveying.
                          
                            If you add terms to a covered work in accord with this section, you
                          must place, in the relevant source files, a statement of the
                          additional terms that apply to those files, or a notice indicating
                          where to find the applicable terms.
                          
                            Additional terms, permissive or non-permissive, may be stated in the
                          form of a separately written license, or stated as exceptions;
                          the above requirements apply either way.
                          
                            8. Termination.
                          
                            You may not propagate or modify a covered work except as expressly
                          provided under this License.  Any attempt otherwise to propagate or
                          modify it is void, and will automatically terminate your rights under
                          this License (including any patent licenses granted under the third
                          paragraph of section 11).
                          
                            However, if you cease all violation of this License, then your
                          license from a particular copyright holder is reinstated (a)
                          provisionally, unless and until the copyright holder explicitly and
                          finally terminates your license, and (b) permanently, if the copyright
                          holder fails to notify you of the violation by some reasonable means
                          prior to 60 days after the cessation.
                          
                            Moreover, your license from a particular copyright holder is
                          reinstated permanently if the copyright holder notifies you of the
                          violation by some reasonable means, this is the first time you have
                          received notice of violation of this License (for any work) from that
                          copyright holder, and you cure the violation prior to 30 days after
                          your receipt of the notice.
                          
                            Termination of your rights under this section does not terminate the
                          licenses of parties who have received copies or rights from you under
                          this License.  If your rights have been terminated and not permanently
                          reinstated, you do not qualify to receive new licenses for the same
                          material under section 10.
                          
                            9. Acceptance Not Required for Having Copies.
                          
                            You are not required to accept this License in order to receive or
                          run a copy of the Program.  Ancillary propagation of a covered work
                          occurring solely as a consequence of using peer-to-peer transmission
                          to receive a copy likewise does not require acceptance.  However,
                          nothing other than this License grants you permission to propagate or
                          modify any covered work.  These actions infringe copyright if you do
                          not accept this License.  Therefore, by modifying or propagating a
                          covered work, you indicate your acceptance of this License to do so.
                          
                            10. Automatic Licensing of Downstream Recipients.
                          
                            Each time you convey a covered work, the recipient automatically
                          receives a license from the original licensors, to run, modify and
                          propagate that work, subject to this License.  You are not responsible
                          for enforcing compliance by third parties with this License.
                          
                            An "entity transaction" is a transaction transferring control of an
                          organization, or substantially all assets of one, or subdividing an
                          organization, or merging organizations.  If propagation of a covered
                          work results from an entity transaction, each party to that
                          transaction who receives a copy of the work also receives whatever
                          licenses to the work the party's predecessor in interest had or could
                          give under the previous paragraph, plus a right to possession of the
                          Corresponding Source of the work from the predecessor in interest, if
                          the predecessor has it or can get it with reasonable efforts.
                          
                            You may not impose any further restrictions on the exercise of the
                          rights granted or affirmed under this License.  For example, you may
                          not impose a license fee, royalty, or other charge for exercise of
                          rights granted under this License, and you may not initiate litigation
                          (including a cross-claim or counterclaim in a lawsuit) alleging that
                          any patent claim is infringed by making, using, selling, offering for
                          sale, or importing the Program or any portion of it.
                          
                            11. Patents.
                          
                            A "contributor" is a copyright holder who authorizes use under this
                          License of the Program or a work on which the Program is based.  The
                          work thus licensed is called the contributor's "contributor version".
                          
                            A contributor's "essential patent claims" are all patent claims
                          owned or controlled by the contributor, whether already acquired or
                          hereafter acquired, that would be infringed by some manner, permitted
                          by this License, of making, using, or selling its contributor version,
                          but do not include claims that would be infringed only as a
                          consequence of further modification of the contributor version.  For
                          purposes of this definition, "control" includes the right to grant
                          patent sublicenses in a manner consistent with the requirements of
                          this License.
                          
                            Each contributor grants you a non-exclusive, worldwide, royalty-free
                          patent license under the contributor's essential patent claims, to
                          make, use, sell, offer for sale, import and otherwise run, modify and
                          propagate the contents of its contributor version.
                          
                            In the following three paragraphs, a "patent license" is any express
                          agreement or commitment, however denominated, not to enforce a patent
                          (such as an express permission to practice a patent or covenant not to
                          sue for patent infringement).  To "grant" such a patent license to a
                          party means to make such an agreement or commitment not to enforce a
                          patent against the party.
                          
                            If you convey a covered work, knowingly relying on a patent license,
                          and the Corresponding Source of the work is not available for anyone
                          to copy, free of charge and under the terms of this License, through a
                          publicly available network server or other readily accessible means,
                          then you must either (1) cause the Corresponding Source to be so
                          available, or (2) arrange to deprive yourself of the benefit of the
                          patent license for this particular work, or (3) arrange, in a manner
                          consistent with the requirements of this License, to extend the patent
                          license to downstream recipients.  "Knowingly relying" means you have
                          actual knowledge that, but for the patent license, your conveying the
                          covered work in a country, or your recipient's use of the covered work
                          in a country, would infringe one or more identifiable patents in that
                          country that you have reason to believe are valid.
                          
                            If, pursuant to or in connection with a single transaction or
                          arrangement, you convey, or propagate by procuring conveyance of, a
                          covered work, and grant a patent license to some of the parties
                          receiving the covered work authorizing them to use, propagate, modify
                          or convey a specific copy of the covered work, then the patent license
                          you grant is automatically extended to all recipients of the covered
                          work and works based on it.
                          
                            A patent license is "discriminatory" if it does not include within
                          the scope of its coverage, prohibits the exercise of, or is
                          conditioned on the non-exercise of one or more of the rights that are
                          specifically granted under this License.  You may not convey a covered
                          work if you are a party to an arrangement with a third party that is
                          in the business of distributing software, under which you make payment
                          to the third party based on the extent of your activity of conveying
                          the work, and under which the third party grants, to any of the
                          parties who would receive the covered work from you, a discriminatory
                          patent license (a) in connection with copies of the covered work
                          conveyed by you (or copies made from those copies), or (b) primarily
                          for and in connection with specific products or compilations that
                          contain the covered work, unless you entered into that arrangement,
                          or that patent license was granted, prior to 28 March 2007.
                          
                            Nothing in this License shall be construed as excluding or limiting
                          any implied license or other defenses to infringement that may
                          otherwise be available to you under applicable patent law.
                          
                            12. No Surrender of Others' Freedom.
                          
                            If conditions are imposed on you (whether by court order, agreement or
                          otherwise) that contradict the conditions of this License, they do not
                          excuse you from the conditions of this License.  If you cannot convey a
                          covered work so as to satisfy simultaneously your obligations under this
                          License and any other pertinent obligations, then as a consequence you may
                          not convey it at all.  For example, if you agree to terms that obligate you
                          to collect a royalty for further conveying from those to whom you convey
                          the Program, the only way you could satisfy both those terms and this
                          License would be to refrain entirely from conveying the Program.
                          
                            13. Use with the GNU Affero General Public License.
                          
                            Notwithstanding any other provision of this License, you have
                          permission to link or combine any covered work with a work licensed
                          under version 3 of the GNU Affero General Public License into a single
                          combined work, and to convey the resulting work.  The terms of this
                          License will continue to apply to the part which is the covered work,
                          but the special requirements of the GNU Affero General Public License,
                          section 13, concerning interaction through a network will apply to the
                          combination as such.
                          
                            14. Revised Versions of this License.
                          
                            The Free Software Foundation may publish revised and/or new versions of
                          the GNU General Public License from time to time.  Such new versions will
                          be similar in spirit to the present version, but may differ in detail to
                          address new problems or concerns.
                          
                            Each version is given a distinguishing version number.  If the
                          Program specifies that a certain numbered version of the GNU General
                          Public License "or any later version" applies to it, you have the
                          option of following the terms and conditions either of that numbered
                          version or of any later version published by the Free Software
                          Foundation.  If the Program does not specify a version number of the
                          GNU General Public License, you may choose any version ever published
                          by the Free Software Foundation.
                          
                            If the Program specifies that a proxy can decide which future
                          versions of the GNU General Public License can be used, that proxy's
                          public statement of acceptance of a version permanently authorizes you
                          to choose that version for the Program.
                          
                            Later license versions may give you additional or different
                          permissions.  However, no additional obligations are imposed on any
                          author or copyright holder as a result of your choosing to follow a
                          later version.
                          
                            15. Disclaimer of Warranty.
                          
                            THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
                          APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
                          HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
                          OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
                          THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                          PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
                          IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
                          ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
                          
                            16. Limitation of Liability.
                          
                            IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                          WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
                          THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
                          GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
                          USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
                          DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
                          PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
                          EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                          SUCH DAMAGES.
                          
                            17. Interpretation of Sections 15 and 16.
                          
                            If the disclaimer of warranty and limitation of liability provided
                          above cannot be given local legal effect according to their terms,
                          reviewing courts shall apply local law that most closely approximates
                          an absolute waiver of all civil liability in connection with the
                          Program, unless a warranty or assumption of liability accompanies a
                          copy of the Program in return for a fee.
                          
                                               END OF TERMS AND CONDITIONS
                          
                                      How to Apply These Terms to Your New Programs
                          
                            If you develop a new program, and you want it to be of the greatest
                          possible use to the public, the best way to achieve this is to make it
                          free software which everyone can redistribute and change under these terms.
                          
                            To do so, attach the following notices to the program.  It is safest
                          to attach them to the start of each source file to most effectively
                          state the exclusion of warranty; and each file should have at least
                          the "copyright" line and a pointer to where the full notice is found.
                          
                              <one line to give the program's name and a brief idea of what it does.>
                              Copyright (C) <year>  <name of author>
                          
                              This program is free software: you can redistribute it and/or modify
                              it under the terms of the GNU 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 General Public License for more details.
                          
                              You should have received a copy of the GNU General Public License
                              along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          Also add information on how to contact you by electronic and paper mail.
                          
                            If the program does terminal interaction, make it output a short
                          notice like this when it starts in an interactive mode:
                          
                              <program>  Copyright (C) <year>  <name of author>
                              This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
                              This is free software, and you are welcome to redistribute it
                              under certain conditions; type `show c' for details.
                          
                          The hypothetical commands `show w' and `show c' should show the appropriate
                          parts of the General Public License.  Of course, your program's commands
                          might be different; for a GUI interface, you would use an "about box".
                          
                            You should also get your employer (if you work as a programmer) or school,
                          if any, to sign a "copyright disclaimer" for the program, if necessary.
                          For more information on this, and how to apply and follow the GNU GPL, see
                          <http://www.gnu.org/licenses/>.
                          
                            The GNU General Public License does not permit incorporating your program
                          into proprietary programs.  If your program is a subroutine library, you
                          may consider it more useful to permit linking proprietary applications with
                          the library.  If this is what you want to do, use the GNU Lesser General
                          Public License instead of this License.  But first, please read
                          <http://www.gnu.org/philosophy/why-not-lgpl.html>.
                          
                          */

                          File 10 of 13: SaiProxyCreateAndExecute
                          pragma solidity ^0.4.23;
                          
                          /// math.sol -- mixin for inline numerical wizardry
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          pragma solidity ^0.4.13;
                          
                          contract DSMath {
                              function add(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x + y) >= x);
                              }
                              function sub(uint x, uint y) internal pure returns (uint z) {
                                  require((z = x - y) <= x);
                              }
                              function mul(uint x, uint y) internal pure returns (uint z) {
                                  require(y == 0 || (z = x * y) / y == x);
                              }
                          
                              function min(uint x, uint y) internal pure returns (uint z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint x, uint y) internal pure returns (uint z) {
                                  return x >= y ? x : y;
                              }
                              function imin(int x, int y) internal pure returns (int z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int x, int y) internal pure returns (int z) {
                                  return x >= y ? x : y;
                              }
                          
                              uint constant WAD = 10 ** 18;
                              uint constant RAY = 10 ** 27;
                          
                              function wmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), WAD / 2) / WAD;
                              }
                              function rmul(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, y), RAY / 2) / RAY;
                              }
                              function wdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, WAD), y / 2) / y;
                              }
                              function rdiv(uint x, uint y) internal pure returns (uint z) {
                                  z = add(mul(x, RAY), y / 2) / y;
                              }
                          
                              // This famous algorithm is called "exponentiation by squaring"
                              // and calculates x^n with x as fixed-point and n as regular unsigned.
                              //
                              // It's O(log n), instead of O(n) for naive repeated multiplication.
                              //
                              // These facts are why it works:
                              //
                              //  If n is even, then x^n = (x^2)^(n/2).
                              //  If n is odd,  then x^n = x * x^(n-1),
                              //   and applying the equation for even x gives
                              //    x^n = x * (x^2)^((n-1) / 2).
                              //
                              //  Also, EVM division is flooring and
                              //    floor[(n-1) / 2] = floor[n / 2].
                              //
                              function rpow(uint x, uint n) internal pure returns (uint z) {
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          }
                          
                          contract TubInterface {
                              function open() public returns (bytes32);
                              function join(uint) public;
                              function exit(uint) public;
                              function lock(bytes32, uint) public;
                              function free(bytes32, uint) public;
                              function draw(bytes32, uint) public;
                              function wipe(bytes32, uint) public;
                              function give(bytes32, address) public;
                              function shut(bytes32) public;
                              function cups(bytes32) public view returns (address, uint, uint, uint);
                              function gem() public view returns (TokenInterface);
                              function gov() public view returns (TokenInterface);
                              function skr() public view returns (TokenInterface);
                              function sai() public view returns (TokenInterface);
                              function mat() public view returns (uint);
                              function ink(bytes32) public view returns (uint);
                              function tab(bytes32) public view returns (uint);
                              function rap(bytes32) public view returns (uint);
                              function per() public view returns (uint);
                              function pep() public view returns (PepInterface);
                          }
                          
                          contract TokenInterface {
                              function allowance(address, address) public view returns (uint);
                              function balanceOf(address) public view returns (uint);
                              function approve(address, uint) public;
                              function transfer(address, uint) public returns (bool);
                              function transferFrom(address, address, uint) public returns (bool);
                              function deposit() public payable;
                              function withdraw(uint) public;
                          }
                          
                          contract PepInterface {
                              function peek() public returns (bytes32, bool);
                          }
                          
                          contract OtcInterface {
                              function getPayAmount(address, address, uint) public view returns (uint);
                              function buyAllAmount(address, uint, address pay_gem, uint) public returns (uint);
                          }
                          
                          contract SaiProxy is DSMath {
                              function open(address tub_) public returns (bytes32) {
                                  return TubInterface(tub_).open();
                              }
                          
                              function give(address tub_, bytes32 cup, address lad) public {
                                  TubInterface(tub_).give(cup, lad);
                              }
                          
                              function lock(address tub_, bytes32 cup) public payable {
                                  if (msg.value > 0) {
                                      TubInterface tub = TubInterface(tub_);
                          
                                      (address lad,,,) = tub.cups(cup);
                                      require(lad == address(this), "cup-not-owned");
                          
                                      tub.gem().deposit.value(msg.value)();
                          
                                      uint ink = rdiv(msg.value, tub.per());
                                      ink = rmul(ink, tub.per()) <= msg.value ? ink : ink - 1;
                          
                                      if (tub.gem().allowance(this, tub) != uint(-1)) {
                                          tub.gem().approve(tub, uint(-1));
                                      }
                                      tub.join(ink);
                          
                                      if (tub.skr().allowance(this, tub) != uint(-1)) {
                                          tub.skr().approve(tub, uint(-1));
                                      }
                                      tub.lock(cup, ink);
                                  }
                              }
                          
                              function draw(address tub_, bytes32 cup, uint wad) public {
                                  if (wad > 0) {
                                      TubInterface tub = TubInterface(tub_);
                                      tub.draw(cup, wad);
                                      tub.sai().transfer(msg.sender, wad);
                                  }
                              }
                          
                              function handleGovFee(TubInterface tub, uint saiDebtFee, address otc_) internal {
                                  bytes32 val;
                                  bool ok;
                                  (val, ok) = tub.pep().peek();
                                  if (ok && val != 0) {
                                      uint govAmt = wdiv(saiDebtFee, uint(val));
                                      if (otc_ != address(0)) {
                                          uint saiGovAmt = OtcInterface(otc_).getPayAmount(tub.sai(), tub.gov(), govAmt);
                                          if (tub.sai().allowance(this, otc_) != uint(-1)) {
                                              tub.sai().approve(otc_, uint(-1));
                                          }
                                          tub.sai().transferFrom(msg.sender, this, saiGovAmt);
                                          OtcInterface(otc_).buyAllAmount(tub.gov(), govAmt, tub.sai(), saiGovAmt);
                                      } else {
                                          tub.gov().transferFrom(msg.sender, this, govAmt);
                                      }
                                  }
                              }
                          
                              function wipe(address tub_, bytes32 cup, uint wad, address otc_) public {
                                  if (wad > 0) {
                                      TubInterface tub = TubInterface(tub_);
                          
                                      tub.sai().transferFrom(msg.sender, this, wad);
                                      handleGovFee(tub, rmul(wad, rdiv(tub.rap(cup), tub.tab(cup))), otc_);
                          
                                      if (tub.sai().allowance(this, tub) != uint(-1)) {
                                          tub.sai().approve(tub, uint(-1));
                                      }
                                      if (tub.gov().allowance(this, tub) != uint(-1)) {
                                          tub.gov().approve(tub, uint(-1));
                                      }
                                      tub.wipe(cup, wad);
                                  }
                              }
                          
                              function wipe(address tub_, bytes32 cup, uint wad) public {
                                  wipe(tub_, cup, wad, address(0));
                              }
                          
                              function free(address tub_, bytes32 cup, uint jam) public {
                                  if (jam > 0) {
                                      TubInterface tub = TubInterface(tub_);
                                      uint ink = rdiv(jam, tub.per());
                                      ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
                                      tub.free(cup, ink);
                                      if (tub.skr().allowance(this, tub) != uint(-1)) {
                                          tub.skr().approve(tub, uint(-1));
                                      }
                                      tub.exit(ink);
                                      uint freeJam = tub.gem().balanceOf(this); // Withdraw possible previous stuck WETH as well
                                      tub.gem().withdraw(freeJam);
                                      address(msg.sender).transfer(freeJam);
                                  }
                              }
                          
                              function lockAndDraw(address tub_, bytes32 cup, uint wad) public payable {
                                  lock(tub_, cup);
                                  draw(tub_, cup, wad);
                              }
                          
                              function lockAndDraw(address tub_, uint wad) public payable returns (bytes32 cup) {
                                  cup = open(tub_);
                                  lockAndDraw(tub_, cup, wad);
                              }
                          
                              function wipeAndFree(address tub_, bytes32 cup, uint jam, uint wad) public payable {
                                  wipe(tub_, cup, wad);
                                  free(tub_, cup, jam);
                              }
                          
                              function wipeAndFree(address tub_, bytes32 cup, uint jam, uint wad, address otc_) public payable {
                                  wipe(tub_, cup, wad, otc_);
                                  free(tub_, cup, jam);
                              }
                          
                              function shut(address tub_, bytes32 cup) public {
                                  TubInterface tub = TubInterface(tub_);
                                  wipeAndFree(tub_, cup, rmul(tub.ink(cup), tub.per()), tub.tab(cup));
                                  tub.shut(cup);
                              }
                          
                              function shut(address tub_, bytes32 cup, address otc_) public {
                                  TubInterface tub = TubInterface(tub_);
                                  wipeAndFree(tub_, cup, rmul(tub.ink(cup), tub.per()), tub.tab(cup), otc_);
                                  tub.shut(cup);
                              }
                          }
                          
                          contract ProxyRegistryInterface {
                              function build(address) public returns (address);
                          }
                          
                          contract SaiProxyCreateAndExecute is SaiProxy {
                          
                              // Create a DSProxy instance and open a cup
                              function createAndOpen(address registry_, address tub_) public returns (address proxy, bytes32 cup) {
                                  proxy = ProxyRegistryInterface(registry_).build(msg.sender);
                                  cup = open(tub_);
                                  TubInterface(tub_).give(cup, proxy);
                              }
                          
                              // Create a DSProxy instance, open a cup, and lock collateral
                              function createOpenAndLock(address registry_, address tub_) public payable returns (address proxy, bytes32 cup) {
                                  proxy = ProxyRegistryInterface(registry_).build(msg.sender);
                                  cup = open(tub_);
                                  lock(tub_, cup);
                                  TubInterface(tub_).give(cup, proxy);
                              }
                          
                              // Create a DSProxy instance, open a cup, lock collateral, and draw DAI
                              function createOpenLockAndDraw(address registry_, address tub_, uint wad) public payable returns (address proxy, bytes32 cup) {
                                  proxy = ProxyRegistryInterface(registry_).build(msg.sender);
                                  cup = open(tub_);
                                  lockAndDraw(tub_, cup, wad);
                                  TubInterface(tub_).give(cup, proxy);
                              }
                          }

                          File 11 of 13: OSM
                          // hevm: flattened sources of src/osm.sol
                          pragma solidity ^0.4.24;
                          
                          ////// lib/ds-stop/lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.23; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              constructor() public {
                                  owner = msg.sender;
                                  emit LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  emit LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  emit LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// lib/ds-stop/lib/ds-note/src/note.sol
                          /// note.sol -- the `note' modifier, for logging calls as events
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.23; */
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                                  uint              wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  emit LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          ////// lib/ds-stop/src/stop.sol
                          /// stop.sol -- mixin for enable/disable functionality
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.23; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-note/note.sol"; */
                          
                          contract DSStop is DSNote, DSAuth {
                          
                              bool public stopped;
                          
                              modifier stoppable {
                                  require(!stopped);
                                  _;
                              }
                              function stop() public auth note {
                                  stopped = true;
                              }
                              function start() public auth note {
                                  stopped = false;
                              }
                          
                          }
                          
                          ////// src/osm.sol
                          /// osm.sol - oracle security module
                          
                          // Copyright (C) 2018  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.24; */
                          
                          /* import "ds-auth/auth.sol"; */
                          /* import "ds-stop/stop.sol"; */
                          // import "ds-value/value.sol";
                          
                          interface DSValue {
                              function peek() external returns (bytes32,bool);
                              function read() external returns (bytes32);
                          }
                          
                          contract OSM is DSAuth, DSStop {
                              DSValue public src;
                              
                              uint16 constant ONE_HOUR = uint16(3600);
                          
                              uint16 public hop = ONE_HOUR;
                              uint64 public zzz;
                          
                              struct Feed {
                                  uint128 val;
                                  bool    has;
                              }
                          
                              Feed cur;
                              Feed nxt;
                          
                              event LogValue(bytes32 val);
                              
                              constructor (DSValue src_) public {
                                  src = src_;
                                  (bytes32 wut, bool ok) = src_.peek();
                                  if (ok) {
                                      cur = nxt = Feed(uint128(wut), ok);
                                      zzz = prev(era());
                                  }
                              }
                          
                              function era() internal view returns (uint) {
                                  return block.timestamp;
                              }
                          
                              function prev(uint ts) internal view returns (uint64) {
                                  return uint64(ts - (ts % hop));
                              }
                          
                              function step(uint16 ts) external auth {
                                  require(ts > 0);
                                  hop = ts;
                              }
                          
                              function void() external auth {
                                  cur = nxt = Feed(0, false);
                                  stopped = true;
                              }
                          
                              function pass() public view returns (bool ok) {
                                  return era() >= zzz + hop;
                              }
                          
                              function poke() external stoppable {
                                  require(pass());
                                  (bytes32 wut, bool ok) = src.peek();
                                  cur = nxt;
                                  nxt = Feed(uint128(wut), ok);
                                  zzz = prev(era());
                                  emit LogValue(bytes32(cur.val));
                              }
                          
                              function peek() external view returns (bytes32,bool) {
                                  return (bytes32(cur.val), cur.has);
                              }
                          
                              function peep() external view returns (bytes32,bool) {
                                  return (bytes32(nxt.val), nxt.has);
                              }
                          
                              function read() external view returns (bytes32) {
                                  require(cur.has);
                                  return (bytes32(cur.val));
                              }
                          }

                          File 12 of 13: DSGuard
                          // hevm: flattened sources of src/guard.sol
                          pragma solidity ^0.4.13;
                          
                          ////// lib/ds-auth/src/auth.sol
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) public view returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() public {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  public
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  public
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  require(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          }
                          
                          ////// src/guard.sol
                          // guard.sol -- simple whitelist implementation of DSAuthority
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // This program is free software: you can redistribute it and/or modify
                          // it under the terms of the GNU 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 General Public License for more details.
                          
                          // You should have received a copy of the GNU General Public License
                          // along with this program.  If not, see <http://www.gnu.org/licenses/>.
                          
                          /* pragma solidity ^0.4.13; */
                          
                          /* import "ds-auth/auth.sol"; */
                          
                          contract DSGuardEvents {
                              event LogPermit(
                                  bytes32 indexed src,
                                  bytes32 indexed dst,
                                  bytes32 indexed sig
                              );
                          
                              event LogForbid(
                                  bytes32 indexed src,
                                  bytes32 indexed dst,
                                  bytes32 indexed sig
                              );
                          }
                          
                          contract DSGuard is DSAuth, DSAuthority, DSGuardEvents {
                              bytes32 constant public ANY = bytes32(uint(-1));
                          
                              mapping (bytes32 => mapping (bytes32 => mapping (bytes32 => bool))) acl;
                          
                              function canCall(
                                  address src_, address dst_, bytes4 sig
                              ) public view returns (bool) {
                                  var src = bytes32(src_);
                                  var dst = bytes32(dst_);
                          
                                  return acl[src][dst][sig]
                                      || acl[src][dst][ANY]
                                      || acl[src][ANY][sig]
                                      || acl[src][ANY][ANY]
                                      || acl[ANY][dst][sig]
                                      || acl[ANY][dst][ANY]
                                      || acl[ANY][ANY][sig]
                                      || acl[ANY][ANY][ANY];
                              }
                          
                              function permit(bytes32 src, bytes32 dst, bytes32 sig) public auth {
                                  acl[src][dst][sig] = true;
                                  LogPermit(src, dst, sig);
                              }
                          
                              function forbid(bytes32 src, bytes32 dst, bytes32 sig) public auth {
                                  acl[src][dst][sig] = false;
                                  LogForbid(src, dst, sig);
                              }
                          
                              function permit(address src, address dst, bytes32 sig) public {
                                  permit(bytes32(src), bytes32(dst), sig);
                              }
                              function forbid(address src, address dst, bytes32 sig) public {
                                  forbid(bytes32(src), bytes32(dst), sig);
                              }
                          
                          }
                          
                          contract DSGuardFactory {
                              mapping (address => bool)  public  isGuard;
                          
                              function newGuard() public returns (DSGuard guard) {
                                  guard = new DSGuard();
                                  guard.setOwner(msg.sender);
                                  isGuard[guard] = true;
                              }
                          }

                          File 13 of 13: Medianizer
                          /// return median value of feeds
                          
                          // Copyright (C) 2017  DappHub, LLC
                          
                          // Licensed under the Apache License, Version 2.0 (the "License").
                          // You may not use this file except in compliance with the License.
                          
                          // Unless required by applicable law or agreed to in writing, software
                          // distributed under the License is distributed on an "AS IS" BASIS,
                          // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND (express or implied).
                          
                          pragma solidity ^0.4.8;
                          
                          contract DSAuthority {
                              function canCall(
                                  address src, address dst, bytes4 sig
                              ) constant returns (bool);
                          }
                          
                          contract DSAuthEvents {
                              event LogSetAuthority (address indexed authority);
                              event LogSetOwner     (address indexed owner);
                          }
                          
                          contract DSAuth is DSAuthEvents {
                              DSAuthority  public  authority;
                              address      public  owner;
                          
                              function DSAuth() {
                                  owner = msg.sender;
                                  LogSetOwner(msg.sender);
                              }
                          
                              function setOwner(address owner_)
                                  auth
                              {
                                  owner = owner_;
                                  LogSetOwner(owner);
                              }
                          
                              function setAuthority(DSAuthority authority_)
                                  auth
                              {
                                  authority = authority_;
                                  LogSetAuthority(authority);
                              }
                          
                              modifier auth {
                                  assert(isAuthorized(msg.sender, msg.sig));
                                  _;
                              }
                          
                              modifier authorized(bytes4 sig) {
                                  assert(isAuthorized(msg.sender, sig));
                                  _;
                              }
                          
                              function isAuthorized(address src, bytes4 sig) internal returns (bool) {
                                  if (src == address(this)) {
                                      return true;
                                  } else if (src == owner) {
                                      return true;
                                  } else if (authority == DSAuthority(0)) {
                                      return false;
                                  } else {
                                      return authority.canCall(src, this, sig);
                                  }
                              }
                          
                              function assert(bool x) internal {
                                  if (!x) throw;
                              }
                          }
                          
                          contract DSNote {
                              event LogNote(
                                  bytes4   indexed  sig,
                                  address  indexed  guy,
                                  bytes32  indexed  foo,
                                  bytes32  indexed  bar,
                          	uint	 	  wad,
                                  bytes             fax
                              ) anonymous;
                          
                              modifier note {
                                  bytes32 foo;
                                  bytes32 bar;
                          
                                  assembly {
                                      foo := calldataload(4)
                                      bar := calldataload(36)
                                  }
                          
                                  LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data);
                          
                                  _;
                              }
                          }
                          
                          contract DSMath {
                              
                              /*
                              standard uint256 functions
                               */
                          
                              function add(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  assert((z = x + y) >= x);
                              }
                          
                              function sub(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  assert((z = x - y) <= x);
                              }
                          
                              function mul(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  assert((z = x * y) >= x);
                              }
                          
                              function div(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  z = x / y;
                              }
                          
                              function min(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  return x <= y ? x : y;
                              }
                              function max(uint256 x, uint256 y) constant internal returns (uint256 z) {
                                  return x >= y ? x : y;
                              }
                          
                              /*
                              uint128 functions (h is for half)
                               */
                          
                          
                              function hadd(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  assert((z = x + y) >= x);
                              }
                          
                              function hsub(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  assert((z = x - y) <= x);
                              }
                          
                              function hmul(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  assert((z = x * y) >= x);
                              }
                          
                              function hdiv(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  z = x / y;
                              }
                          
                              function hmin(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  return x <= y ? x : y;
                              }
                              function hmax(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  return x >= y ? x : y;
                              }
                          
                          
                              /*
                              int256 functions
                               */
                          
                              function imin(int256 x, int256 y) constant internal returns (int256 z) {
                                  return x <= y ? x : y;
                              }
                              function imax(int256 x, int256 y) constant internal returns (int256 z) {
                                  return x >= y ? x : y;
                              }
                          
                              /*
                              WAD math
                               */
                          
                              uint128 constant WAD = 10 ** 18;
                          
                              function wadd(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hadd(x, y);
                              }
                          
                              function wsub(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hsub(x, y);
                              }
                          
                              function wmul(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  z = cast((uint256(x) * y + WAD / 2) / WAD);
                              }
                          
                              function wdiv(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  z = cast((uint256(x) * WAD + y / 2) / y);
                              }
                          
                              function wmin(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hmin(x, y);
                              }
                              function wmax(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hmax(x, y);
                              }
                          
                              /*
                              RAY math
                               */
                          
                              uint128 constant RAY = 10 ** 27;
                          
                              function radd(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hadd(x, y);
                              }
                          
                              function rsub(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hsub(x, y);
                              }
                          
                              function rmul(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  z = cast((uint256(x) * y + RAY / 2) / RAY);
                              }
                          
                              function rdiv(uint128 x, uint128 y) constant internal returns (uint128 z) {
                                  z = cast((uint256(x) * RAY + y / 2) / y);
                              }
                          
                              function rpow(uint128 x, uint64 n) constant internal returns (uint128 z) {
                                  // This famous algorithm is called "exponentiation by squaring"
                                  // and calculates x^n with x as fixed-point and n as regular unsigned.
                                  //
                                  // It's O(log n), instead of O(n) for naive repeated multiplication.
                                  //
                                  // These facts are why it works:
                                  //
                                  //  If n is even, then x^n = (x^2)^(n/2).
                                  //  If n is odd,  then x^n = x * x^(n-1),
                                  //   and applying the equation for even x gives
                                  //    x^n = x * (x^2)^((n-1) / 2).
                                  //
                                  //  Also, EVM division is flooring and
                                  //    floor[(n-1) / 2] = floor[n / 2].
                          
                                  z = n % 2 != 0 ? x : RAY;
                          
                                  for (n /= 2; n != 0; n /= 2) {
                                      x = rmul(x, x);
                          
                                      if (n % 2 != 0) {
                                          z = rmul(z, x);
                                      }
                                  }
                              }
                          
                              function rmin(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hmin(x, y);
                              }
                              function rmax(uint128 x, uint128 y) constant internal returns (uint128) {
                                  return hmax(x, y);
                              }
                          
                              function cast(uint256 x) constant internal returns (uint128 z) {
                                  assert((z = uint128(x)) == x);
                              }
                          
                          }
                          
                          contract DSThing is DSAuth, DSNote, DSMath {
                          }
                          
                          contract DSValue is DSThing {
                              bool    has;
                              bytes32 val;
                              function peek() constant returns (bytes32, bool) {
                                  return (val,has);
                              }
                              function read() constant returns (bytes32) {
                                  var (wut, has) = peek();
                                  assert(has);
                                  return wut;
                              }
                              function poke(bytes32 wut) note auth {
                                  val = wut;
                                  has = true;
                              }
                              function void() note auth { // unset the value
                                  has = false;
                              }
                          }
                          
                          contract Medianizer is DSValue {
                              mapping (bytes12 => address) public values;
                              mapping (address => bytes12) public indexes;
                              bytes12 public next = 0x1;
                          
                              uint96 public min = 0x1;
                          
                              function set(address wat) auth {
                                  bytes12 nextId = bytes12(uint96(next) + 1);
                                  assert(nextId != 0x0);
                                  set(next, wat);
                                  next = nextId;
                              }
                          
                              function set(bytes12 pos, address wat) note auth {
                                  if (pos == 0x0) throw;
                          
                                  if (wat != 0 && indexes[wat] != 0) throw;
                          
                                  indexes[values[pos]] = 0; // Making sure to remove a possible existing address in that position
                          
                                  if (wat != 0) {
                                      indexes[wat] = pos;
                                  }
                          
                                  values[pos] = wat;
                              }
                          
                              function setMin(uint96 min_) note auth {
                                  if (min_ == 0x0) throw;
                                  min = min_;
                              }
                          
                              function setNext(bytes12 next_) note auth {
                                  if (next_ == 0x0) throw;
                                  next = next_;
                              }
                          
                              function unset(bytes12 pos) {
                                  set(pos, 0);
                              }
                          
                              function unset(address wat) {
                                  set(indexes[wat], 0);
                              }
                          
                              function poke() {
                                  poke(0);
                              }
                          
                              function poke(bytes32) note {
                                  (val, has) = compute();
                              }
                          
                              function compute() constant returns (bytes32, bool) {
                                  bytes32[] memory wuts = new bytes32[](uint96(next) - 1);
                                  uint96 ctr = 0;
                                  for (uint96 i = 1; i < uint96(next); i++) {
                                      if (values[bytes12(i)] != 0) {
                                          var (wut, wuz) = DSValue(values[bytes12(i)]).peek();
                                          if (wuz) {
                                              if (ctr == 0 || wut >= wuts[ctr - 1]) {
                                                  wuts[ctr] = wut;
                                              } else {
                                                  uint96 j = 0;
                                                  while (wut >= wuts[j]) {
                                                      j++;
                                                  }
                                                  for (uint96 k = ctr; k > j; k--) {
                                                      wuts[k] = wuts[k - 1];
                                                  }
                                                  wuts[j] = wut;
                                              }
                                              ctr++;
                                          }
                                      }
                                  }
                          
                                  if (ctr < min) return (val, false);
                          
                                  bytes32 value;
                                  if (ctr % 2 == 0) {
                                      uint128 val1 = uint128(wuts[(ctr / 2) - 1]);
                                      uint128 val2 = uint128(wuts[ctr / 2]);
                                      value = bytes32(wdiv(hadd(val1, val2), 2 ether));
                                  } else {
                                      value = wuts[(ctr - 1) / 2];
                                  }
                          
                                  return (value, true);
                              }
                          
                          }