Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0x06f7Bf937Dec0C413a2E0464Bb300C4d464bb891
Balance 0 ETH
Nonce 1
Code Size 22014 bytes
Indexed Transactions 0 (1 on-chain, 1.2% indexed)
External Etherscan · Sourcify

Contract Bytecode

22014 bytes
0x60806040526004361061036b5763ffffffff60e060020a6000350416630c87355e81146103705780630ca78923146103975780630e53aae9146103cb5780631120a7761461042057806315226b541461045157806319b64015146104725780631d000b611461048a5780631e1401f81461049f57806320d7d367146104e257806321e6b53d1461050b578063227425641461052c578063228d28201461059457806325f9bfef146105ae5780632a2e2f0c146105c35780632cc1cd65146105f057806338a5e0161461068d5780633aa0145a146106a25780633e8ff43f146106c05780633f4d2fc21461074a578063415f12401461077957806341a5b33d1461079157806342906029146107bb578063481c6a75146107d057806349d10b64146107e55780634af80f0e146107fa578063500573511461081b57806354fd4d5014610890578063579cd3ca146108bc5780635a46f06c146108ea5780635e35359e146108ff5780635e5144eb1461092957806361cd756e14610956578063677c08121461096b5780636a49d2c4146109875780636d7bd3fc146109b15780636ebf36c0146109c657806371f52bf3146109fe57806372b44b2c14610a1357806375892cf114610a3757806379ba509714610a645780637b10399914610a7957806383315b6e14610a8e5780638da5cb5b14610aa35780638e3047e014610ab85780639232494e14610ae25780639249993a14610af757806392d1abb714610b0c578063935e2ae114610b2157806394c275ad14610b455780639b99a8e214610b5a5780639e56855314610b6f578063a2c4c33614610b95578063a6a11c7114610bb9578063b3a426d514610bdf578063b4a176d314610c80578063bf75455814610c95578063c45d3d9214610caa578063c4a8598e14610cbf578063c8c2fe6c14610cd4578063ca1d209d14610ce9578063cc97b38f14610d01578063cf73266a14610d16578063d031370b14610d40578063d4ee1d9014610d58578063d55ec69714610d6d578063d66bd52414610d82578063d895951214610da3578063d924f0c314610dc4578063e4dd22f614610de5578063e4edf85214610e48578063ecbca55d14610e69578063f0843ba914610e87578063f2fde38b14610ed8578063f5286b9c14610ef9578063fa1c594e14610f0e578063fc0c546a14610f28578063fe417fa514610f3d575b600080fd5b34801561037c57600080fd5b50610385610f61565b60408051918252519081900360200190f35b3480156103a357600080fd5b506103c9600160a060020a036004351663ffffffff602435166044351515606435610f73565b005b3480156103d757600080fd5b506103ec600160a060020a0360043516610f83565b6040805195865263ffffffff9094166020860152911515848401521515606084015215156080830152519081900360a00190f35b34801561042c57600080fd5b50610435610fd5565b60408051600160a060020a039092168252519081900360200190f35b34801561045d57600080fd5b50610385600160a060020a0360043516610fe4565b34801561047e57600080fd5b506104356004356110d2565b34801561049657600080fd5b506103856110fe565b3480156104ab57600080fd5b506104c9600160a060020a0360043581169060243516604435611122565b6040805192835260208301919091528051918290030190f35b3480156104ee57600080fd5b506104f761119f565b604080519115158252519081900360200190f35b34801561051757600080fd5b506103c9600160a060020a03600435166111a8565b6040805160206004803580820135838102808601850190965280855261038595369593946024949385019291829185019084908082843750949750508435955050506020830135926040810135925060ff606082013516915060808101359060a0013561126c565b3480156105a057600080fd5b506103c96004351515611295565b3480156105ba57600080fd5b50610385611354565b3480156105cf57600080fd5b50610385600160a060020a0360043581169060243516604435606435611378565b3480156105fc57600080fd5b5060408051602060048035808201358381028086018501909652808552610385953695939460249493850192918291850190849080828437505060408051818801358901803560208181028481018201909552818452989b8a359b8a8c01359b919a909950606090910197509295509082019350918291850190849080828437509497506118609650505050505050565b34801561069957600080fd5b506103c9611d5f565b3480156106ae57600080fd5b5061038560043560ff60243516611e15565b3480156106cc57600080fd5b506106d5611e73565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561070f5781810151838201526020016106f7565b50505050905090810190601f16801561073c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561075657600080fd5b506103c9600160a060020a036004351663ffffffff602435166044351515611f01565b34801561078557600080fd5b506103c9600435611f10565b34801561079d57600080fd5b506103c9600160a060020a0360043581169060243516604435612195565b3480156107c757600080fd5b50610435612236565b3480156107dc57600080fd5b50610435612245565b3480156107f157600080fd5b506103c9612254565b34801561080657600080fd5b506103c9600160a060020a036004351661239c565b34801561082757600080fd5b506040805160206004803580820135838102808601850190965280855261038595369593946024949385019291829185019084908082843750949750508435955050506020830135926040810135925060ff606082013516915060808101359060a001356123ed565b34801561089c57600080fd5b506108a5612407565b6040805161ffff9092168252519081900360200190f35b3480156108c857600080fd5b506108d1612429565b6040805163ffffffff9092168252519081900360200190f35b3480156108f657600080fd5b50610385612441565b34801561090b57600080fd5b506103c9600160a060020a0360043581169060243516604435612465565b34801561093557600080fd5b50610385600160a060020a03600435811690602435166044356064356125e6565b34801561096257600080fd5b506104356125fd565b34801561097757600080fd5b506103c961ffff60043516612611565b34801561099357600080fd5b506103c9600160a060020a036004351663ffffffff6024351661285d565b3480156109bd57600080fd5b50610385612a95565b3480156109d257600080fd5b50610385600160a060020a0360043581169060243581169060443590606435906084351660a435612aa7565b348015610a0a57600080fd5b506108a5612b4d565b348015610a1f57600080fd5b506104c9600160a060020a0360043516602435612b5c565b348015610a4357600080fd5b50610385600160a060020a0360043581169060243516604435606435612eb0565b348015610a7057600080fd5b506103c9612ec1565b348015610a8557600080fd5b50610435612f3c565b348015610a9a57600080fd5b50610385612f4b565b348015610aaf57600080fd5b50610435612f6f565b348015610ac457600080fd5b506104c9600160a060020a0360043581169060243516604435612f7e565b348015610aee57600080fd5b50610385612f8c565b348015610b0357600080fd5b50610385612f9e565b348015610b1857600080fd5b50610385612fc2565b348015610b2d57600080fd5b506103c9600160a060020a0360043516602435612fc7565b348015610b5157600080fd5b506108d16130f0565b348015610b6657600080fd5b506108a5613104565b348015610b7b57600080fd5b506103c9600160a060020a0360043516602435151561310a565b348015610ba157600080fd5b506104c9600160a060020a0360043516602435613114565b348015610bc557600080fd5b506103c9600160a060020a03600435166024351515613435565b60408051602060048035808201358381028086018501909652808552610385953695939460249493850192918291850190849080828437505060408051818801358901803560208181028481018201909552818452989b8a359b8a8c01359b919a9099506060909101975092955090820193509182918501908490808284375094975050508335600160a060020a03169450505060209091013590506134bd565b348015610c8c57600080fd5b506103c9613807565b348015610ca157600080fd5b506104f7613860565b348015610cb657600080fd5b50610435613879565b348015610ccb57600080fd5b50610385613888565b348015610ce057600080fd5b506103c96138ac565b348015610cf557600080fd5b506103c9600435613929565b348015610d0d57600080fd5b50610385613bf0565b348015610d2257600080fd5b506104c9600160a060020a0360043581169060243516604435613c14565b348015610d4c57600080fd5b50610435600435613ed3565b348015610d6457600080fd5b50610435613efb565b348015610d7957600080fd5b506103c9613f0a565b348015610d8e57600080fd5b506103ec600160a060020a0360043516614055565b348015610daf57600080fd5b50610385600160a060020a036004351661409b565b348015610dd057600080fd5b506103c9600160a060020a03600435166140ac565b604080516020600480358082013583810280860185019096528085526103859536959394602494938501929182918501908490808284375094975050843595505050602083013592600160a060020a0360408201351692506060013590506140e5565b348015610e5457600080fd5b506103c9600160a060020a036004351661410b565b348015610e7557600080fd5b506103c963ffffffff60043516614176565b604080516020600480358082013583810280860185019096528085526103859536959394602494938501929182918501908490808284375094975050843595505050602090920135915061425b9050565b348015610ee457600080fd5b506103c9600160a060020a036004351661426b565b348015610f0557600080fd5b506103856142bf565b348015610f1a57600080fd5b506103c960043515156142e3565b348015610f3457600080fd5b50610435614323565b348015610f4957600080fd5b506103c9600160a060020a0360043516602435614332565b60008051602061559383398151915281565b610f7d8482612fc7565b50505050565b600160a060020a03166000908152600b602052604090208054600190910154909163ffffffff82169160ff64010000000082048116926501000000000083048216926601000000000000900490911690565b600354600160a060020a031681565b600160a060020a0381166000908152600b6020526040812060010154819083906601000000000000900460ff16151561101c57600080fd5b600160a060020a0384166000908152600b602052604090206001810154909250640100000000900460ff166110c7576040805160e060020a6370a082310281523060048201529051600160a060020a038616916370a082319160248083019260209291908290030181600087803b15801561109657600080fd5b505af11580156110aa573d6000803e3d6000fd5b505050506040513d60208110156110c057600080fd5b50516110ca565b81545b949350505050565b6000600a828154811015156110e357fe5b600091825260209091200154600160a060020a031692915050565b7f424e54546f6b656e00000000000000000000000000000000000000000000000081565b600080600160a060020a03858116908516141561113e57600080fd5b600254600160a060020a03858116911614156111675761115e8584613114565b91509150611197565b600254600160a060020a03868116911614156111875761115e8484612b5c565b611192858585613c14565b915091505b935093915050565b60075460ff1681565b600054600160a060020a031633146111bf57600080fd5b6008546040805160e260020a632ecd14d302815260008051602061559383398151915260048201529051600092600160a060020a03169163bb34534c91602480830192602092919082900301818787803b15801561121c57600080fd5b505af1158015611230573d6000803e3d6000fd5b505050506040513d602081101561124657600080fd5b5051905033600160a060020a0382161461125f57600080fd5b6112688261442b565b5050565b60006112898888886112818b8a8a8a8a6144c4565b6000806134bd565b98975050505050505050565b600054600160a060020a03163314806112b85750600454600160a060020a031633145b15156112c357600080fd5b600c5460ff6c01000000000000000000000000909104161515811515141561135157600c80546c01000000000000000000000000831581026cff000000000000000000000000199092169190911791829055604080519190920460ff161515815290517fb8e670608a57255ce4f35952b324cba70211a4200a91ce81d26e06d488c1f66b9181900360200190a15b50565b7f436f6e747261637452656769737472790000000000000000000000000000000081565b6008546040805160e260020a632ecd14d302815260008051602061557383398151915260048201529051600092839283928392839283928392600160a060020a03169163bb34534c91602480830192602092919082900301818787803b1580156113e157600080fd5b505af11580156113f5573d6000803e3d6000fd5b505050506040513d602081101561140b57600080fd5b5051905033600160a060020a0382161461142457600080fd5b600c546c01000000000000000000000000900460ff16151561144557600080fd5b876000811161145357600080fd5b600160a060020a038c8116908c16141561146c57600080fd5b600254600160a060020a038c8116911614156114945761148d8c8b8b6145b3565b9750611851565b600254600160a060020a038d8116911614156114b55761148d8b8b8b6147fb565b6114c08c8c8c613c14565b909750955086158015906114d45750888710155b15156114df57600080fd5b600160a060020a038c166000908152600b602052604090206001810154909550640100000000900460ff1615611524578454611521908b63ffffffff614bec16565b85555b600160a060020a038b166000908152600b602052604090206001810154909450640100000000900460ff1615611569578354611566908863ffffffff614c0916565b84555b6115728b610fe4565b925082871061157d57fe5b6115898c33308d614c1e565b6115948b3389614fad565b6115a18c8c8c8a8a615323565b8b600160a060020a03166000805160206155b3833981519152600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561160d57600080fd5b505af1158015611621573d6000803e3d6000fd5b505050506040513d602081101561163757600080fd5b81019080805190602001909291905050508e600160a060020a03166370a08231306040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b1580156116a357600080fd5b505af11580156116b7573d6000803e3d6000fd5b505050506040513d60208110156116cd57600080fd5b5051600189015460408051938452602084019290925263ffffffff1682820152519081900360600190a28a600160a060020a03166000805160206155b3833981519152600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561176357600080fd5b505af1158015611777573d6000803e3d6000fd5b505050506040513d602081101561178d57600080fd5b81019080805190602001909291905050508d600160a060020a03166370a08231306040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b1580156117f957600080fd5b505af115801561180d573d6000803e3d6000fd5b505050506040513d602081101561182357600080fd5b5051600188015460408051938452602084019290925263ffffffff1682820152519081900360600190a28697505b50505050505050949350505050565b60008060008084516000148061188d57508585600081518110151561188157fe5b90602001906020020151145b151561189857600080fd5b6008546040805160e260020a632ecd14d30281527f42616e636f72580000000000000000000000000000000000000000000000000060048201529051600160a060020a039092169163bb34534c916024808201926020929091908290030181600087803b15801561190857600080fd5b505af115801561191c573d6000803e3d6000fd5b505050506040513d602081101561193257600080fd5b50516008546040805160e260020a632ecd14d302815260008051602061557383398151915260048201529051929550600160a060020a039091169163bb34534c916024808201926020929091908290030181600087803b15801561199557600080fd5b505af11580156119a9573d6000803e3d6000fd5b505050506040513d60208110156119bf57600080fd5b50516008546040805160e260020a632ecd14d30281527f424e54546f6b656e00000000000000000000000000000000000000000000000060048201529051929450600160a060020a039091169163bb34534c916024808201926020929091908290030181600087803b158015611a3457600080fd5b505af1158015611a48573d6000803e3d6000fd5b505050506040513d6020811015611a5e57600080fd5b50518851600160a060020a039091169089906000908110611a7b57fe5b60209081029091010151600160a060020a031614611a9857600080fd5b604080517faafd6b76000000000000000000000000000000000000000000000000000000008152600481018890523360248201529051600160a060020a0385169163aafd6b769160448083019260209291908290030181600087803b158015611b0057600080fd5b505af1158015611b14573d6000803e3d6000fd5b505050506040513d6020811015611b2a57600080fd5b50516002546040805160e060020a63a24835d1028152336004820152602481018490529051929350600160a060020a039091169163a24835d19160448082019260009290919082900301818387803b158015611b8557600080fd5b505af1158015611b99573d6000803e3d6000fd5b50506002546040805160e260020a63219e412d028152600160a060020a03878116600483015260248201879052915191909216935063867904b49250604480830192600092919082900301818387803b158015611bf557600080fd5b505af1158015611c09573d6000803e3d6000fd5b5050505081600160a060020a0316634de006cb89838a338a6000806040518863ffffffff1660e060020a028152600401808060200188815260200187815260200186600160a060020a0316600160a060020a031681526020018060200185600160a060020a0316600160a060020a0316815260200184815260200183810383528a818151815260200191508051906020019060200280838360005b83811015611cbc578181015183820152602001611ca4565b50505050905001838103825286818151815260200191508051906020019060200280838360005b83811015611cfb578181015183820152602001611ce3565b505050509050019950505050505050505050602060405180830381600087803b158015611d2757600080fd5b505af1158015611d3b573d6000803e3d6000fd5b505050506040513d6020811015611d5157600080fd5b505198975050505050505050565b600054600160a060020a03163314611d7657600080fd5b600254604080517f18160ddd0000000000000000000000000000000000000000000000000000000081529051600092600160a060020a0316916318160ddd91600480830192602092919082900301818787803b158015611dd557600080fd5b505af1158015611de9573d6000803e3d6000fd5b505050506040513d6020811015611dff57600080fd5b505111611e0b57600080fd5b611e136153a6565b565b600c54600090611e6c9060ff8416620f424081810a67ffffffffffffffff90811693611e6093899363ffffffff680100000000000000009093048316900383160a9091169061542416565b9063ffffffff61545216565b9392505050565b6006805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015611ef95780601f10611ece57610100808354040283529160200191611ef9565b820191906000526020600020905b815481529060010190602001808311611edc57829003601f168201915b505050505081565b611f0b838361285d565b505050565b600c546000908190819081908190819063ffffffff16620f424014611f3457600080fd5b600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b158015611f8757600080fd5b505af1158015611f9b573d6000803e3d6000fd5b505050506040513d6020811015611fb157600080fd5b50516002546040805160e060020a63a24835d1028152336004820152602481018b90529051929850600160a060020a039091169163a24835d19160448082019260009290919082900301818387803b15801561200c57600080fd5b505af1158015612020573d6000803e3d6000fd5b50505050600091505b600a5461ffff8316101561218c57600a805461ffff841690811061204957fe5b60009182526020808320909101546040805160e060020a6370a082310281523060048201529051600160a060020a03909216985088936370a082319360248084019491939192918390030190829087803b1580156120a657600080fd5b505af11580156120ba573d6000803e3d6000fd5b505050506040513d60208110156120d057600080fd5b505193506120e886611e60898763ffffffff61542416565b600160a060020a0386166000908152600b6020526040902060018101549194509150640100000000900460ff161561212f57805461212c908463ffffffff614c0916565b81555b61213a853385614fad565b6001810154604080518989038152858703602082015263ffffffff9092168282015251600160a060020a038716916000805160206155b3833981519152919081900360600190a2600190910190612029565b50505050505050565b600054600160a060020a031633146121ac57600080fd5b600254604080517f5e35359e000000000000000000000000000000000000000000000000000000008152600160a060020a03868116600483015285811660248301526044820185905291519190921691635e35359e91606480830192600092919082900301818387803b15801561222257600080fd5b505af115801561218c573d6000803e3d6000fd5b600554600160a060020a031681565b600454600160a060020a031681565b60075460009060ff16806122725750600054600160a060020a031633145b151561227d57600080fd5b6008546040805160e260020a632ecd14d30281527f436f6e747261637452656769737472790000000000000000000000000000000060048201529051600160a060020a039092169163bb34534c916024808201926020929091908290030181600087803b1580156122ed57600080fd5b505af1158015612301573d6000803e3d6000fd5b505050506040513d602081101561231757600080fd5b5051600854909150600160a060020a038083169116148015906123425750600160a060020a03811615155b151561234d57600080fd5b600880546007805474ffffffffffffffffffffffffffffffffffffffff001916610100600160a060020a038085169190910291909117909155600160a060020a03199091169216919091179055565b600054600160a060020a031633146123b357600080fd5b80600160a060020a0381163014156123ca57600080fd5b5060098054600160a060020a031916600160a060020a0392909216919091179055565b60006112898888886124028a8a8a8a8a6144c4565b611860565b60055474010000000000000000000000000000000000000000900461ffff1681565b600c5468010000000000000000900463ffffffff1681565b7f42616e636f72436f6e766572746572466163746f72790000000000000000000081565b6008546040805160e260020a632ecd14d302815260008051602061559383398151915260048201529051600092600160a060020a03169163bb34534c91602480830192602092919082900301818787803b1580156124c257600080fd5b505af11580156124d6573d6000803e3d6000fd5b505050506040513d60208110156124ec57600080fd5b5051600160a060020a0385166000908152600b60205260409020600101549091506601000000000000900460ff1615806125b85750600254604080517f8da5cb5b00000000000000000000000000000000000000000000000000000000815290513092600160a060020a031691638da5cb5b9160048083019260209291908290030181600087803b15801561258057600080fd5b505af1158015612594573d6000803e3d6000fd5b505050506040513d60208110156125aa57600080fd5b5051600160a060020a031614155b806125d05750600054600160a060020a038281169116145b15156125db57600080fd5b610f7d848484615475565b60006125f485858585611378565b95945050505050565b6007546101009004600160a060020a031681565b60008054819081908190600160a060020a0316331461262f57600080fd5b600254604080517f8da5cb5b00000000000000000000000000000000000000000000000000000000815290513092600160a060020a031691638da5cb5b9160048083019260209291908290030181600087803b15801561268e57600080fd5b505af11580156126a2573d6000803e3d6000fd5b505050506040513d60208110156126b857600080fd5b5051600160a060020a0316146126cd57600080fd5b60648561ffff16101580156126e857506103e88561ffff1611155b15156126f357600080fd5b8461ffff16606414159350600091505b600a5461ffff8316101561282157600a805461ffff841690811061272357fe5b600091825260208083209190910154600160a060020a0316808352600b909152604090912060018101805464ff00000000191664010000000088151502179055909350905083612774576000612814565b6128146064611e608761ffff1686600160a060020a03166370a08231306040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b1580156127dc57600080fd5b505af11580156127f0573d6000803e3d6000fd5b505050506040513d602081101561280657600080fd5b50519063ffffffff61542416565b8155600190910190612703565b60408051851515815290517f64622fbd54039f76d87a876ecaea9bdb6b9b493d7a35ca38ae82b53dcddbe2e49181900360200190a15050505050565b600054600160a060020a0316331461287457600080fd5b600254604080517f8da5cb5b00000000000000000000000000000000000000000000000000000000815290513092600160a060020a031691638da5cb5b9160048083019260209291908290030181600087803b1580156128d357600080fd5b505af11580156128e7573d6000803e3d6000fd5b505050506040513d60208110156128fd57600080fd5b5051600160a060020a0316141561291357600080fd5b81600160a060020a038116151561292957600080fd5b82600160a060020a03811630141561294057600080fd5b8260008163ffffffff161180156129605750620f424063ffffffff821611155b151561296b57600080fd5b600254600160a060020a038681169116148015906129af5750600160a060020a0385166000908152600b60205260409020600101546601000000000000900460ff16155b80156129cd5750600c54620f424063ffffffff918216860190911611155b15156129d857600080fd5b505050600160a060020a03919091166000818152600b60205260408120600180820180549284905566010000000000006501000000000063ffffffff1994851663ffffffff808a169190911765ffff0000000019169190911766ff000000000000191691909117909155600a805492830181559093527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8018054600160a060020a031916909317909255600c805492831692821690930116179055565b60008051602061555383398151915281565b6040805160038082526080820190925260009160609190602082018380388339505060025482519293508a92600160a060020a039091169150899084906000908110612aef57fe5b906020019060200201846001815181101515612b0757fe5b906020019060200201856002815181101515612b1f57fe5b600160a060020a039485166020918202909201015292821690925291909116905261128981878787876140e5565b6000612b57613104565b905090565b60008060008060008060008030600160a060020a0316600260009054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a028152600401602060405180830381600087803b158015612bc557600080fd5b505af1158015612bd9573d6000803e3d6000fd5b505050506040513d6020811015612bef57600080fd5b5051600160a060020a031614612c0457600080fd5b600160a060020a038a166000908152600b60205260409020600101548a906601000000000000900460ff161515612c3a57600080fd5b600160a060020a03808c166000908152600b6020908152604080832060025482517f18160ddd0000000000000000000000000000000000000000000000000000000081529251919c50909416936318160ddd93600480840194938390030190829087803b158015612caa57600080fd5b505af1158015612cbe573d6000803e3d6000fd5b505050506040513d6020811015612cd457600080fd5b50516040805160e060020a6370a082310281523060048201529051919750600160a060020a038d16916370a08231916024808201926020929091908290030181600087803b158015612d2557600080fd5b505af1158015612d39573d6000803e3d6000fd5b505050506040513d6020811015612d4f57600080fd5b50516008546040805160e260020a632ecd14d302815260008051602061555383398151915260048201529051929750600160a060020a039091169163bb34534c916024808201926020929091908290030181600087803b158015612db257600080fd5b505af1158015612dc6573d6000803e3d6000fd5b505050506040513d6020811015612ddc57600080fd5b50516001880154604080517f49f9b0f7000000000000000000000000000000000000000000000000000000008152600481018a90526024810189905263ffffffff9092166044830152606482018d905251919550600160a060020a038616916349f9b0f7916084808201926020929091908290030181600087803b158015612e6357600080fd5b505af1158015612e77573d6000803e3d6000fd5b505050506040513d6020811015612e8d57600080fd5b50519250612e9c836001611e15565b9b928c90039a509198505050505050505050565b60006125f485858585600080612aa7565b600154600160a060020a03163314612ed857600080fd5b60015460008054604051600160a060020a0393841693909116917f343765429aea5a34b3ff6a3785a98a5abb2597aca87bfbb58632c173d585373a91a36001805460008054600160a060020a0319908116600160a060020a03841617909155169055565b600854600160a060020a031681565b7f436f6e747261637446656174757265730000000000000000000000000000000081565b600054600160a060020a031681565b600080611192858585613c14565b60008051602061557383398151915281565b7f42616e636f7247617350726963654c696d69740000000000000000000000000081565b600181565b60008054600160a060020a03163314612fdf57600080fd5b6008546040805160e260020a632ecd14d302815260008051602061559383398151915260048201529051600092600160a060020a03169163bb34534c91602480830192602092919082900301818787803b15801561303c57600080fd5b505af1158015613050573d6000803e3d6000fd5b505050506040513d602081101561306657600080fd5b5051905033600160a060020a0382161461307f57600080fd5b600160a060020a0384166000908152600b602052604090206001015484906601000000000000900460ff1615156130b557600080fd5b505050600160a060020a03919091166000908152600b6020526040902060018101805464ff0000000019168315156401000000000217905555565b600c54640100000000900463ffffffff1681565b600a5490565b6112688282613435565b60008060008060008060008030600160a060020a0316600260009054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561317d57600080fd5b505af1158015613191573d6000803e3d6000fd5b505050506040513d60208110156131a757600080fd5b5051600160a060020a0316146131bc57600080fd5b600160a060020a038a166000908152600b60205260409020600101548a906601000000000000900460ff1615156131f257600080fd5b600160a060020a038b166000908152600b60205260409020600181015490975065010000000000900460ff16151561322957600080fd5b600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561327c57600080fd5b505af1158015613290573d6000803e3d6000fd5b505050506040513d60208110156132a657600080fd5b50516040805160e060020a6370a082310281523060048201529051919750600160a060020a038d16916370a08231916024808201926020929091908290030181600087803b1580156132f757600080fd5b505af115801561330b573d6000803e3d6000fd5b505050506040513d602081101561332157600080fd5b50516008546040805160e260020a632ecd14d302815260008051602061555383398151915260048201529051929750600160a060020a039091169163bb34534c916024808201926020929091908290030181600087803b15801561338457600080fd5b505af1158015613398573d6000803e3d6000fd5b505050506040513d60208110156133ae57600080fd5b50516001880154604080517f29a00e7c000000000000000000000000000000000000000000000000000000008152600481018a90526024810189905263ffffffff9092166044830152606482018d905251919550600160a060020a038616916329a00e7c916084808201926020929091908290030181600087803b158015612e6357600080fd5b600054600160a060020a0316331461344c57600080fd5b600160a060020a0382166000908152600b602052604090206001015482906601000000000000900460ff16151561348257600080fd5b50600160a060020a03919091166000908152600b60205260409020600101805465ff0000000000191691156501000000000002919091179055565b6000808451600014806134e75750868560008151811015156134db57fe5b90602001906020020151145b15156134f257600080fd5b6008546040805160e260020a632ecd14d302815260008051602061557383398151915260048201529051600160a060020a039092169163bb34534c916024808201926020929091908290030181600087803b15801561355057600080fd5b505af1158015613564573d6000803e3d6000fd5b505050506040513d602081101561357a57600080fd5b505190503415156136c3576002548851600160a060020a0390911690899060009081106135a357fe5b90602001906020020151600160a060020a0316141561369f576002546040805160e060020a63a24835d1028152336004820152602481018a90529051600160a060020a039092169163a24835d19160448082019260009290919082900301818387803b15801561361257600080fd5b505af1158015613626573d6000803e3d6000fd5b50506002546040805160e260020a63219e412d028152600160a060020a038681166004830152602482018d9052915191909216935063867904b49250604480830192600092919082900301818387803b15801561368257600080fd5b505af1158015613696573d6000803e3d6000fd5b505050506136c3565b6136c38860008151811015156136b157fe5b9060200190602002015133838a614c1e565b80600160a060020a0316634de006cb348a8a8a338b8b8b6040518963ffffffff1660e060020a028152600401808060200188815260200187815260200186600160a060020a0316600160a060020a031681526020018060200185600160a060020a0316600160a060020a0316815260200184815260200183810383528a818151815260200191508051906020019060200280838360005b8381101561377257818101518382015260200161375a565b50505050905001838103825286818151815260200191508051906020019060200280838360005b838110156137b1578181015183820152602001613799565b5050505090500199505050505050505050506020604051808303818588803b1580156137dc57600080fd5b505af11580156137f0573d6000803e3d6000fd5b50505050506040513d6020811015611d5157600080fd5b600054600160a060020a031633148061382a5750600454600160a060020a031633145b151561383557600080fd5b6007805460088054600160a060020a031916600160a060020a0361010084041617905560ff19169055565b600c546c01000000000000000000000000900460ff1681565b600954600160a060020a031681565b7f42616e636f72580000000000000000000000000000000000000000000000000081565b600554600160a060020a031633146138c357600080fd5b600554600454604051600160a060020a0392831692909116907fbe4cc281795971a471c980e842627a7f1ea3892ddfce8c5b6357cd2611c1973290600090a36005805460048054600160a060020a0319908116600160a060020a03841617909155169055565b600c546000908190819081908190819063ffffffff16620f42401461394d57600080fd5b600c546c01000000000000000000000000900460ff16151561396e57600080fd5b600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b1580156139c157600080fd5b505af11580156139d5573d6000803e3d6000fd5b505050506040513d60208110156139eb57600080fd5b50519550600091505b600a5461ffff83161015613b7957600a805461ffff8416908110613a1457fe5b60009182526020808320909101546040805160e060020a6370a082310281523060048201529051600160a060020a03909216985088936370a082319360248084019491939192918390030190829087803b158015613a7157600080fd5b505af1158015613a85573d6000803e3d6000fd5b505050506040513d6020811015613a9b57600080fd5b50519350613ad46001613ac888611e6083613abc8d8b63ffffffff61542416565b9063ffffffff614c0916565b9063ffffffff614bec16565b600160a060020a0386166000908152600b6020526040902060018101549194509150640100000000900460ff1615613b1b578054613b18908463ffffffff614bec16565b81555b613b2785333086614c1e565b600181015460408051888a018152868601602082015263ffffffff9092168282015251600160a060020a038716916000805160206155b3833981519152919081900360600190a26001909101906139f4565b6002546040805160e260020a63219e412d028152336004820152602481018a90529051600160a060020a039092169163867904b49160448082019260009290919082900301818387803b158015613bcf57600080fd5b505af1158015613be3573d6000803e3d6000fd5b5050505050505050505050565b7f42616e636f72585570677261646572000000000000000000000000000000000081565b600080600080600080600030600160a060020a0316600260009054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a028152600401602060405180830381600087803b158015613c7c57600080fd5b505af1158015613c90573d6000803e3d6000fd5b505050506040513d6020811015613ca657600080fd5b5051600160a060020a031614613cbb57600080fd5b600160a060020a038a166000908152600b60205260409020600101548a906601000000000000900460ff161515613cf157600080fd5b600160a060020a038a166000908152600b60205260409020600101548a906601000000000000900460ff161515613d2757600080fd5b600160a060020a038c81166000908152600b6020526040808220928e16825290206001820154919850965065010000000000900460ff161515613d6957600080fd5b6008546040805160e260020a632ecd14d302815260008051602061555383398151915260048201529051600160a060020a039092169163bb34534c916024808201926020929091908290030181600087803b158015613dc757600080fd5b505af1158015613ddb573d6000803e3d6000fd5b505050506040513d6020811015613df157600080fd5b50519450600160a060020a0385166379c1b450613e0d8e610fe4565b60018a015463ffffffff16613e218f610fe4565b60018b01546040805163ffffffff87811660e060020a028252600482019690965293851660248501526044840192909252929092166064820152608481018e9052905160a48083019260209291908290030181600087803b158015613e8557600080fd5b505af1158015613e99573d6000803e3d6000fd5b505050506040513d6020811015613eaf57600080fd5b50519350613ebe846002611e15565b9c938d90039b50929950505050505050505050565b600a805482908110613ee157fe5b600091825260209091200154600160a060020a0316905081565b600154600160a060020a031681565b60008054600160a060020a03163314613f2257600080fd5b6008546040805160e260020a632ecd14d302815260008051602061559383398151915260048201529051600160a060020a039092169163bb34534c916024808201926020929091908290030181600087803b158015613f8057600080fd5b505af1158015613f94573d6000803e3d6000fd5b505050506040513d6020811015613faa57600080fd5b50519050613fb78161426b565b600554604080517f90f58c960000000000000000000000000000000000000000000000000000000081527401000000000000000000000000000000000000000090920461ffff16600483015251600160a060020a038316916390f58c9691602480830192600092919082900301818387803b15801561403557600080fd5b505af1158015614049573d6000803e3d6000fd5b50505050611351612ec1565b600b602052600090815260409020805460019091015463ffffffff81169060ff640100000000820481169165010000000000810482169166010000000000009091041685565b60006140a682610fe4565b92915050565b600054600160a060020a031633146140c357600080fd5b60038054600160a060020a031916600160a060020a0392909216919091179055565b60006141018686866140fa85808080806144c4565b87876134bd565b9695505050505050565b600054600160a060020a031633148061412e5750600454600160a060020a031633145b151561413957600080fd5b600454600160a060020a038281169116141561415457600080fd5b60058054600160a060020a031916600160a060020a0392909216919091179055565b600054600160a060020a03163314806141995750600454600160a060020a031633145b15156141a457600080fd5b60008163ffffffff16101580156141cf5750600c5463ffffffff640100000000909104811690821611155b15156141da57600080fd5b600c546040805163ffffffff6801000000000000000090930483168152918316602083015280517f81cd2ffb37dd237c0e4e2a3de5265fcf9deb43d3e7801e80db9f1ccfba7ee6009281900390910190a1600c805463ffffffff90921668010000000000000000026bffffffff000000000000000019909216919091179055565b60006110ca8484846000806140e5565b600054600160a060020a0316331461428257600080fd5b600054600160a060020a038281169116141561429d57600080fd5b60018054600160a060020a031916600160a060020a0392909216919091179055565b7f4e6f6e5374616e64617264546f6b656e5265676973747279000000000000000081565b600054600160a060020a03163314806143065750600454600160a060020a031633145b151561431157600080fd5b6007805460ff19169115919091179055565b600254600160a060020a031681565b600354600160a060020a0316331461434957600080fd5b6002546040805160e060020a63a24835d1028152600160a060020a038581166004830152602482018590529151919092169163a24835d191604480830192600092919082900301818387803b1580156143a157600080fd5b505af11580156143b5573d6000803e3d6000fd5b50506002546040805160e260020a63219e412d028152336004820152602481018690529051600160a060020a03909216935063867904b4925060448082019260009290919082900301818387803b15801561440f57600080fd5b505af1158015614423573d6000803e3d6000fd5b505050505050565b600054600160a060020a0316331461444257600080fd5b600254604080517ff2fde38b000000000000000000000000000000000000000000000000000000008152600160a060020a0384811660048301529151919092169163f2fde38b91602480830192600092919082900301818387803b1580156144a957600080fd5b505af11580156144bd573d6000803e3d6000fd5b5050505050565b60608060ff85161580156144d6575083155b80156144e0575082155b156144fb5760408051600081526020810190915291506145a9565b60408051600580825260c08201909252906020820160a0803883390190505090508681600081518110151561452c57fe5b60209081029091010152805186908290600190811061454757fe5b60209081029091010152805160ff8616908290600290811061456557fe5b60209081029091010152805184908290600390811061458057fe5b60209081029091010152805183908290600490811061459b57fe5b602090810290910101529050805b5095945050505050565b6000806000806145c38787613114565b909350915082158015906145d75750848310155b15156145e257600080fd5b50600160a060020a0386166000908152600b602052604090206001810154640100000000900460ff1615614625578054614622908763ffffffff614bec16565b81555b61463187333089614c1e565b6002546040805160e260020a63219e412d028152336004820152602481018690529051600160a060020a039092169163867904b49160448082019260009290919082900301818387803b15801561468757600080fd5b505af115801561469b573d6000803e3d6000fd5b50506002546146b99250899150600160a060020a0316888686615323565b86600160a060020a03166000805160206155b3833981519152600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561472557600080fd5b505af1158015614739573d6000803e3d6000fd5b505050506040513d602081101561474f57600080fd5b50516040805160e060020a6370a082310281523060048201529051600160a060020a038c16916370a082319160248083019260209291908290030181600087803b15801561479c57600080fd5b505af11580156147b0573d6000803e3d6000fd5b505050506040513d60208110156147c657600080fd5b5051600185015460408051938452602084019290925263ffffffff1682820152519081900360600190a2509095945050505050565b6002546040805160e060020a6370a08231028152336004820152905160009283928392839283928392600160a060020a03909216916370a082319160248082019260209290919082900301818787803b15801561485757600080fd5b505af115801561486b573d6000803e3d6000fd5b505050506040513d602081101561488157600080fd5b505188111561488f57600080fd5b6148998989612b5c565b909550935084158015906148ad5750868510155b15156148b857600080fd5b600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801561490b57600080fd5b505af115801561491f573d6000803e3d6000fd5b505050506040513d602081101561493557600080fd5b50516040805160e060020a6370a082310281523060048201529051919450600160a060020a038b16916370a08231916024808201926020929091908290030181600087803b15801561498657600080fd5b505af115801561499a573d6000803e3d6000fd5b505050506040513d60208110156149b057600080fd5b50519150818510806149cb575081851480156149cb57508288145b15156149d357fe5b50600160a060020a0388166000908152600b602052604090206001810154640100000000900460ff1615614a16578054614a13908663ffffffff614c0916565b81555b6002546040805160e060020a63a24835d1028152336004820152602481018b90529051600160a060020a039092169163a24835d19160448082019260009290919082900301818387803b158015614a6c57600080fd5b505af1158015614a80573d6000803e3d6000fd5b50505050614a8f893387614fad565b600254614aa890600160a060020a03168a8a8888615323565b88600160a060020a03166000805160206155b3833981519152600260009054906101000a9004600160a060020a0316600160a060020a03166318160ddd6040518163ffffffff1660e060020a028152600401602060405180830381600087803b158015614b1457600080fd5b505af1158015614b28573d6000803e3d6000fd5b505050506040513d6020811015614b3e57600080fd5b50516040805160e060020a6370a082310281523060048201529051600160a060020a038e16916370a082319160248083019260209291908290030181600087803b158015614b8b57600080fd5b505af1158015614b9f573d6000803e3d6000fd5b505050506040513d6020811015614bb557600080fd5b5051600185015460408051938452602084019290925263ffffffff1682820152519081900360600190a25092979650505050505050565b600082820183811015614bfe57600080fd5b8091505b5092915050565b600081831015614c1857600080fd5b50900390565b6008546040805160e260020a632ecd14d30281527f4e6f6e5374616e64617264546f6b656e526567697374727900000000000000006004820152905160009283928392600160a060020a039092169163bb34534c9160248082019260209290919082900301818787803b158015614c9457600080fd5b505af1158015614ca8573d6000803e3d6000fd5b505050506040513d6020811015614cbe57600080fd5b5051604080517faeea10bd000000000000000000000000000000000000000000000000000000008152600160a060020a038a8116600483015291519295509085169163aeea10bd916024808201926020929091908290030181600087803b158015614d2857600080fd5b505af1158015614d3c573d6000803e3d6000fd5b505050506040513d6020811015614d5257600080fd5b505115614f055786600160a060020a03166370a08231866040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b158015614db457600080fd5b505af1158015614dc8573d6000803e3d6000fd5b505050506040513d6020811015614dde57600080fd5b5051604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a0389811660048301528881166024830152604482018890529151929450908916916323b872dd9160648082019260009290919082900301818387803b158015614e5657600080fd5b505af1158015614e6a573d6000803e3d6000fd5b5050505086600160a060020a03166370a08231866040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b158015614ec957600080fd5b505af1158015614edd573d6000803e3d6000fd5b505050506040513d6020811015614ef357600080fd5b50519050818111614f0057fe5b61218c565b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a0388811660048301528781166024830152604482018790529151918916916323b872dd916064808201926020929091908290030181600087803b158015614f7957600080fd5b505af1158015614f8d573d6000803e3d6000fd5b505050506040513d6020811015614fa357600080fd5b5051151561218c57fe5b6008546040805160e260020a632ecd14d30281527f4e6f6e5374616e64617264546f6b656e526567697374727900000000000000006004820152905160009283928392600160a060020a039092169163bb34534c9160248082019260209290919082900301818787803b15801561502357600080fd5b505af1158015615037573d6000803e3d6000fd5b505050506040513d602081101561504d57600080fd5b5051604080517faeea10bd000000000000000000000000000000000000000000000000000000008152600160a060020a03898116600483015291519295509085169163aeea10bd916024808201926020929091908290030181600087803b1580156150b757600080fd5b505af11580156150cb573d6000803e3d6000fd5b505050506040513d60208110156150e157600080fd5b50511561528c5785600160a060020a03166370a08231866040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b15801561514357600080fd5b505af1158015615157573d6000803e3d6000fd5b505050506040513d602081101561516d57600080fd5b5051604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a0388811660048301526024820188905291519294509088169163a9059cbb9160448082019260009290919082900301818387803b1580156151dd57600080fd5b505af11580156151f1573d6000803e3d6000fd5b5050505085600160a060020a03166370a08231866040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050602060405180830381600087803b15801561525057600080fd5b505af1158015615264573d6000803e3d6000fd5b505050506040513d602081101561527a57600080fd5b5051905081811161528757fe5b614423565b85600160a060020a031663a9059cbb86866040518363ffffffff1660e060020a0281526004018083600160a060020a0316600160a060020a0316815260200182815260200192505050602060405180830381600087803b1580156152ef57600080fd5b505af1158015615303573d6000803e3d6000fd5b505050506040513d602081101561531957600080fd5b5051151561442357fe5b7f8000000000000000000000000000000000000000000000000000000000000000811061534c57fe5b604080518481526020810184905280820183905290513391600160a060020a0387811692908916917f276856b36cbc45526a0ba64f44611557a2a8b68662c5388e9fe6d72e86e1c8cb919081900360600190a45050505050565b600054600160a060020a031633146153bd57600080fd5b600260009054906101000a9004600160a060020a0316600160a060020a03166379ba50976040518163ffffffff1660e060020a028152600401600060405180830381600087803b15801561541057600080fd5b505af1158015610f7d573d6000803e3d6000fd5b6000808315156154375760009150614c02565b5082820282848281151561544757fe5b0414614bfe57600080fd5b60008080831161546157600080fd5b828481151561546c57fe5b04949350505050565b600054600160a060020a0316331461548c57600080fd5b82600160a060020a03811615156154a257600080fd5b82600160a060020a03811615156154b857600080fd5b83600160a060020a0381163014156154cf57600080fd5b85600160a060020a031663a9059cbb86866040518363ffffffff1660e060020a0281526004018083600160a060020a0316600160a060020a0316815260200182815260200192505050600060405180830381600087803b15801561553257600080fd5b505af1158015615546573d6000803e3d6000fd5b50505050505050505050560042616e636f72466f726d756c610000000000000000000000000000000000000042616e636f724e6574776f726b0000000000000000000000000000000000000042616e636f72436f6e76657274657255706772616465720000000000000000008a6a7f53b3c8fa1dc4b83e3f1be668c1b251ff8d44cdcb83eb3acec3fec6a788a165627a7a72305820a1d5240c498906975038de9bdb52dacf0a95be608af2600ce15c20774b5be07a0029

Verified Source Code Partial Match

Compiler: v0.4.26+commit.4563c3fc EVM: byzantium Optimization: Yes (200 runs)
BancorConverter.sol 1819 lines
pragma solidity 0.4.26;

// File: contracts/token/interfaces/IERC20Token.sol

/*
    ERC20 Standard Token interface
*/
contract IERC20Token {
    // these functions aren't abstract since the compiler emits automatically generated getter functions as external
    function name() public view returns (string) {this;}
    function symbol() public view returns (string) {this;}
    function decimals() public view returns (uint8) {this;}
    function totalSupply() public view returns (uint256) {this;}
    function balanceOf(address _owner) public view returns (uint256) {_owner; this;}
    function allowance(address _owner, address _spender) public view returns (uint256) {_owner; _spender; this;}

    function transfer(address _to, uint256 _value) public returns (bool success);
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
    function approve(address _spender, uint256 _value) public returns (bool success);
}

// File: contracts/utility/interfaces/IWhitelist.sol

/*
    Whitelist interface
*/
contract IWhitelist {
    function isWhitelisted(address _address) public view returns (bool);
}

// File: contracts/converter/interfaces/IBancorConverter.sol

/*
    Bancor Converter interface
*/
contract IBancorConverter {
    function getReturn(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount) public view returns (uint256, uint256);
    function convert2(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount, uint256 _minReturn, address _affiliateAccount, uint256 _affiliateFee) public returns (uint256);
    function quickConvert2(IERC20Token[] _path, uint256 _amount, uint256 _minReturn, address _affiliateAccount, uint256 _affiliateFee) public payable returns (uint256);
    function conversionWhitelist() public view returns (IWhitelist) {this;}
    function conversionFee() public view returns (uint32) {this;}
    function reserves(address _address) public view returns (uint256, uint32, bool, bool, bool) {_address; this;}
    function getReserveBalance(IERC20Token _reserveToken) public view returns (uint256);
    function reserveTokens(uint256 _index) public view returns (IERC20Token) {_index; this;}
    // deprecated, backward compatibility
    function change(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount, uint256 _minReturn) public returns (uint256);
    function convert(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount, uint256 _minReturn) public returns (uint256);
    function quickConvert(IERC20Token[] _path, uint256 _amount, uint256 _minReturn) public payable returns (uint256);
    function connectors(address _address) public view returns (uint256, uint32, bool, bool, bool);
    function getConnectorBalance(IERC20Token _connectorToken) public view returns (uint256);
    function connectorTokens(uint256 _index) public view returns (IERC20Token);
}

// File: contracts/converter/interfaces/IBancorConverterUpgrader.sol

/*
    Bancor Converter Upgrader interface
*/
contract IBancorConverterUpgrader {
    function upgrade(bytes32 _version) public;
    function upgrade(uint16 _version) public;
}

// File: contracts/converter/interfaces/IBancorFormula.sol

/*
    Bancor Formula interface
*/
contract IBancorFormula {
    function calculatePurchaseReturn(uint256 _supply, uint256 _reserveBalance, uint32 _reserveRatio, uint256 _depositAmount) public view returns (uint256);
    function calculateSaleReturn(uint256 _supply, uint256 _reserveBalance, uint32 _reserveRatio, uint256 _sellAmount) public view returns (uint256);
    function calculateCrossReserveReturn(uint256 _fromReserveBalance, uint32 _fromReserveRatio, uint256 _toReserveBalance, uint32 _toReserveRatio, uint256 _amount) public view returns (uint256);
    // deprecated, backward compatibility
    function calculateCrossConnectorReturn(uint256 _fromConnectorBalance, uint32 _fromConnectorWeight, uint256 _toConnectorBalance, uint32 _toConnectorWeight, uint256 _amount) public view returns (uint256);
}

// File: contracts/IBancorNetwork.sol

/*
    Bancor Network interface
*/
contract IBancorNetwork {
    function convert2(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _affiliateAccount,
        uint256 _affiliateFee
    ) public payable returns (uint256);

    function claimAndConvert2(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _affiliateAccount,
        uint256 _affiliateFee
    ) public returns (uint256);

    function convertFor2(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        address _affiliateAccount,
        uint256 _affiliateFee
    ) public payable returns (uint256);

    function claimAndConvertFor2(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        address _affiliateAccount,
        uint256 _affiliateFee
    ) public returns (uint256);

    function convertForPrioritized4(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        uint256[] memory _signature,
        address _affiliateAccount,
        uint256 _affiliateFee
    ) public payable returns (uint256);

    // deprecated, backward compatibility
    function convert(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn
    ) public payable returns (uint256);

    // deprecated, backward compatibility
    function claimAndConvert(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn
    ) public returns (uint256);

    // deprecated, backward compatibility
    function convertFor(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for
    ) public payable returns (uint256);

    // deprecated, backward compatibility
    function claimAndConvertFor(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for
    ) public returns (uint256);

    // deprecated, backward compatibility
    function convertForPrioritized3(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        uint256 _customVal,
        uint256 _block,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) public payable returns (uint256);

    // deprecated, backward compatibility
    function convertForPrioritized2(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        uint256 _block,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) public payable returns (uint256);

    // deprecated, backward compatibility
    function convertForPrioritized(
        IERC20Token[] _path,
        uint256 _amount,
        uint256 _minReturn,
        address _for,
        uint256 _block,
        uint256 _nonce,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) public payable returns (uint256);
}

// File: contracts/ContractIds.sol

/**
  * @dev Id definitions for bancor contracts
  * 
  * Can be used in conjunction with the contract registry to get contract addresses
*/
contract ContractIds {
    // generic
    bytes32 public constant CONTRACT_FEATURES = "ContractFeatures";
    bytes32 public constant CONTRACT_REGISTRY = "ContractRegistry";
    bytes32 public constant NON_STANDARD_TOKEN_REGISTRY = "NonStandardTokenRegistry";

    // bancor logic
    bytes32 public constant BANCOR_NETWORK = "BancorNetwork";
    bytes32 public constant BANCOR_FORMULA = "BancorFormula";
    bytes32 public constant BANCOR_GAS_PRICE_LIMIT = "BancorGasPriceLimit";
    bytes32 public constant BANCOR_CONVERTER_UPGRADER = "BancorConverterUpgrader";
    bytes32 public constant BANCOR_CONVERTER_FACTORY = "BancorConverterFactory";

    // BNT core
    bytes32 public constant BNT_TOKEN = "BNTToken";

    // BancorX
    bytes32 public constant BANCOR_X = "BancorX";
    bytes32 public constant BANCOR_X_UPGRADER = "BancorXUpgrader";
}

// File: contracts/FeatureIds.sol

/**
  * @dev Id definitions for bancor contract features
  * 
  * Can be used to query the ContractFeatures contract to check whether a certain feature is supported by a contract
*/
contract FeatureIds {
    // converter features
    uint256 public constant CONVERTER_CONVERSION_WHITELIST = 1 << 0;
}

// File: contracts/utility/interfaces/IOwned.sol

/*
    Owned contract interface
*/
contract IOwned {
    // this function isn't abstract since the compiler emits automatically generated getter functions as external
    function owner() public view returns (address) {this;}

    function transferOwnership(address _newOwner) public;
    function acceptOwnership() public;
}

// File: contracts/utility/Owned.sol

/**
  * @dev Provides support and utilities for contract ownership
*/
contract Owned is IOwned {
    address public owner;
    address public newOwner;

    /**
      * @dev triggered when the owner is updated
      * 
      * @param _prevOwner previous owner
      * @param _newOwner  new owner
    */
    event OwnerUpdate(address indexed _prevOwner, address indexed _newOwner);

    /**
      * @dev initializes a new Owned instance
    */
    constructor() public {
        owner = msg.sender;
    }

    // allows execution by the owner only
    modifier ownerOnly {
        require(msg.sender == owner);
        _;
    }

    /**
      * @dev allows transferring the contract ownership
      * the new owner still needs to accept the transfer
      * can only be called by the contract owner
      * 
      * @param _newOwner    new contract owner
    */
    function transferOwnership(address _newOwner) public ownerOnly {
        require(_newOwner != owner);
        newOwner = _newOwner;
    }

    /**
      * @dev used by a new owner to accept an ownership transfer
    */
    function acceptOwnership() public {
        require(msg.sender == newOwner);
        emit OwnerUpdate(owner, newOwner);
        owner = newOwner;
        newOwner = address(0);
    }
}

// File: contracts/utility/Managed.sol

/**
  * @dev Provides support and utilities for contract management
  * Note that a managed contract must also have an owner
*/
contract Managed is Owned {
    address public manager;
    address public newManager;

    /**
      * @dev triggered when the manager is updated
      * 
      * @param _prevManager previous manager
      * @param _newManager  new manager
    */
    event ManagerUpdate(address indexed _prevManager, address indexed _newManager);

    /**
      * @dev initializes a new Managed instance
    */
    constructor() public {
        manager = msg.sender;
    }

    // allows execution by the manager only
    modifier managerOnly {
        assert(msg.sender == manager);
        _;
    }

    // allows execution by either the owner or the manager only
    modifier ownerOrManagerOnly {
        require(msg.sender == owner || msg.sender == manager);
        _;
    }

    /**
      * @dev allows transferring the contract management
      * the new manager still needs to accept the transfer
      * can only be called by the contract manager
      * 
      * @param _newManager    new contract manager
    */
    function transferManagement(address _newManager) public ownerOrManagerOnly {
        require(_newManager != manager);
        newManager = _newManager;
    }

    /**
      * @dev used by a new manager to accept a management transfer
    */
    function acceptManagement() public {
        require(msg.sender == newManager);
        emit ManagerUpdate(manager, newManager);
        manager = newManager;
        newManager = address(0);
    }
}

// File: contracts/utility/Utils.sol

/**
  * @dev Utilities & Common Modifiers
*/
contract Utils {
    /**
      * constructor
    */
    constructor() public {
    }

    // verifies that an amount is greater than zero
    modifier greaterThanZero(uint256 _amount) {
        require(_amount > 0);
        _;
    }

    // validates an address - currently only checks that it isn't null
    modifier validAddress(address _address) {
        require(_address != address(0));
        _;
    }

    // verifies that the address is different than this contract address
    modifier notThis(address _address) {
        require(_address != address(this));
        _;
    }

}

// File: contracts/utility/SafeMath.sol

/**
  * @dev Library for basic math operations with overflow/underflow protection
*/
library SafeMath {
    /**
      * @dev returns the sum of _x and _y, reverts if the calculation overflows
      * 
      * @param _x   value 1
      * @param _y   value 2
      * 
      * @return sum
    */
    function add(uint256 _x, uint256 _y) internal pure returns (uint256) {
        uint256 z = _x + _y;
        require(z >= _x);
        return z;
    }

    /**
      * @dev returns the difference of _x minus _y, reverts if the calculation underflows
      * 
      * @param _x   minuend
      * @param _y   subtrahend
      * 
      * @return difference
    */
    function sub(uint256 _x, uint256 _y) internal pure returns (uint256) {
        require(_x >= _y);
        return _x - _y;
    }

    /**
      * @dev returns the product of multiplying _x by _y, reverts if the calculation overflows
      * 
      * @param _x   factor 1
      * @param _y   factor 2
      * 
      * @return product
    */
    function mul(uint256 _x, uint256 _y) internal pure returns (uint256) {
        // gas optimization
        if (_x == 0)
            return 0;

        uint256 z = _x * _y;
        require(z / _x == _y);
        return z;
    }

      /**
        * ev Integer division of two numbers truncating the quotient, reverts on division by zero.
        * 
        * aram _x   dividend
        * aram _y   divisor
        * 
        * eturn quotient
    */
    function div(uint256 _x, uint256 _y) internal pure returns (uint256) {
        require(_y > 0);
        uint256 c = _x / _y;

        return c;
    }
}

// File: contracts/utility/interfaces/IContractRegistry.sol

/*
    Contract Registry interface
*/
contract IContractRegistry {
    function addressOf(bytes32 _contractName) public view returns (address);

    // deprecated, backward compatibility
    function getAddress(bytes32 _contractName) public view returns (address);
}

// File: contracts/utility/interfaces/IContractFeatures.sol

/*
    Contract Features interface
*/
contract IContractFeatures {
    function isSupported(address _contract, uint256 _features) public view returns (bool);
    function enableFeatures(uint256 _features, bool _enable) public;
}

// File: contracts/utility/interfaces/IAddressList.sol

/*
    Address list interface
*/
contract IAddressList {
    mapping (address => bool) public listedAddresses;
}

// File: contracts/token/interfaces/ISmartToken.sol

/*
    Smart Token interface
*/
contract ISmartToken is IOwned, IERC20Token {
    function disableTransfers(bool _disable) public;
    function issue(address _to, uint256 _amount) public;
    function destroy(address _from, uint256 _amount) public;
}

// File: contracts/token/interfaces/ISmartTokenController.sol

/*
    Smart Token Controller interface
*/
contract ISmartTokenController {
    function claimTokens(address _from, uint256 _amount) public;
    function token() public view returns (ISmartToken) {this;}
}

// File: contracts/utility/interfaces/ITokenHolder.sol

/*
    Token Holder interface
*/
contract ITokenHolder is IOwned {
    function withdrawTokens(IERC20Token _token, address _to, uint256 _amount) public;
}

// File: contracts/token/interfaces/INonStandardERC20.sol

/*
    ERC20 Standard Token interface which doesn't return true/false for transfer, transferFrom and approve
*/
contract INonStandardERC20 {
    // these functions aren't abstract since the compiler emits automatically generated getter functions as external
    function name() public view returns (string) {this;}
    function symbol() public view returns (string) {this;}
    function decimals() public view returns (uint8) {this;}
    function totalSupply() public view returns (uint256) {this;}
    function balanceOf(address _owner) public view returns (uint256) {_owner; this;}
    function allowance(address _owner, address _spender) public view returns (uint256) {_owner; _spender; this;}

    function transfer(address _to, uint256 _value) public;
    function transferFrom(address _from, address _to, uint256 _value) public;
    function approve(address _spender, uint256 _value) public;
}

// File: contracts/utility/TokenHolder.sol

/**
  * @dev We consider every contract to be a 'token holder' since it's currently not possible
  * for a contract to deny receiving tokens.
  * 
  * The TokenHolder's contract sole purpose is to provide a safety mechanism that allows
  * the owner to send tokens that were sent to the contract by mistake back to their sender.
  * 
  * Note that we use the non standard ERC-20 interface which has no return value for transfer
  * in order to support both non standard as well as standard token contracts.
  * see https://github.com/ethereum/solidity/issues/4116
*/
contract TokenHolder is ITokenHolder, Owned, Utils {
    /**
      * @dev initializes a new TokenHolder instance
    */
    constructor() public {
    }

    /**
      * @dev withdraws tokens held by the contract and sends them to an account
      * can only be called by the owner
      * 
      * @param _token   ERC20 token contract address
      * @param _to      account to receive the new amount
      * @param _amount  amount to withdraw
    */
    function withdrawTokens(IERC20Token _token, address _to, uint256 _amount)
        public
        ownerOnly
        validAddress(_token)
        validAddress(_to)
        notThis(_to)
    {
        INonStandardERC20(_token).transfer(_to, _amount);
    }
}

// File: contracts/token/SmartTokenController.sol

/**
  * @dev The smart token controller is an upgradable part of the smart token that allows
  * more functionality as well as fixes for bugs/exploits.
  * Once it accepts ownership of the token, it becomes the token's sole controller
  * that can execute any of its functions.
  * 
  * To upgrade the controller, ownership must be transferred to a new controller, along with
  * any relevant data.
  * 
  * The smart token must be set on construction and cannot be changed afterwards.
  * Wrappers are provided (as opposed to a single 'execute' function) for each of the token's functions, for easier access.
  * 
  * Note that the controller can transfer token ownership to a new controller that
  * doesn't allow executing any function on the token, for a trustless solution.
  * Doing that will also remove the owner's ability to upgrade the controller.
*/
contract SmartTokenController is ISmartTokenController, TokenHolder {
    ISmartToken public token;   // Smart Token contract
    address public bancorX;     // BancorX contract

    /**
      * @dev initializes a new SmartTokenController instance
      * 
      * @param  _token      smart token governed by the controller
    */
    constructor(ISmartToken _token)
        public
        validAddress(_token)
    {
        token = _token;
    }

    // ensures that the controller is the token's owner
    modifier active() {
        require(token.owner() == address(this));
        _;
    }

    // ensures that the controller is not the token's owner
    modifier inactive() {
        require(token.owner() != address(this));
        _;
    }

    /**
      * @dev allows transferring the token ownership
      * the new owner needs to accept the transfer
      * can only be called by the contract owner
      * 
      * @param _newOwner    new token owner
    */
    function transferTokenOwnership(address _newOwner) public ownerOnly {
        token.transferOwnership(_newOwner);
    }

    /**
      * @dev used by a new owner to accept a token ownership transfer
      * can only be called by the contract owner
    */
    function acceptTokenOwnership() public ownerOnly {
        token.acceptOwnership();
    }

    /**
      * @dev withdraws tokens held by the controller and sends them to an account
      * can only be called by the owner
      * 
      * @param _token   ERC20 token contract address
      * @param _to      account to receive the new amount
      * @param _amount  amount to withdraw
    */
    function withdrawFromToken(IERC20Token _token, address _to, uint256 _amount) public ownerOnly {
        ITokenHolder(token).withdrawTokens(_token, _to, _amount);
    }

    /**
      * @dev allows the associated BancorX contract to claim tokens from any address (so that users
      * dont have to first give allowance when calling BancorX)
      * 
      * @param _from      address to claim the tokens from
      * @param _amount    the amount of tokens to claim
     */
    function claimTokens(address _from, uint256 _amount) public {
        // only the associated BancorX contract may call this method
        require(msg.sender == bancorX);

        // destroy the tokens belonging to _from, and issue the same amount to bancorX
        token.destroy(_from, _amount);
        token.issue(msg.sender, _amount);
    }

    /**
      * @dev allows the owner to set the associated BancorX contract
      * @param _bancorX    BancorX contract
     */
    function setBancorX(address _bancorX) public ownerOnly {
        bancorX = _bancorX;
    }
}

// File: contracts/token/interfaces/IEtherToken.sol

/*
    Ether Token interface
*/
contract IEtherToken is ITokenHolder, IERC20Token {
    function deposit() public payable;
    function withdraw(uint256 _amount) public;
    function withdrawTo(address _to, uint256 _amount) public;
}

// File: contracts/bancorx/interfaces/IBancorX.sol

contract IBancorX {
    function xTransfer(bytes32 _toBlockchain, bytes32 _to, uint256 _amount, uint256 _id) public;
    function getXTransferAmount(uint256 _xTransferId, address _for) public view returns (uint256);
}

// File: contracts/converter/BancorConverter.sol

/**
  * @dev Bancor Converter
  * 
  * The Bancor converter allows for conversions between a Smart Token and other ERC20 tokens and between different ERC20 tokens and themselves. 
  * 
  * The ERC20 reserve balance can be virtual, meaning that conversions between reserve tokens are based on the virtual balance instead of relying on the actual reserve balance.
  * 
  * This mechanism opens the possibility to create different financial tools (for example, lower slippage in conversions).
  * 
  * The converter is upgradable (just like any SmartTokenController) and all upgrades are opt-in. 
  * 
  * WARNING: It is NOT RECOMMENDED to use the converter with Smart Tokens that have less than 8 decimal digits or with very small numbers because of precision loss 
  * 
  * Open issues:
  * - Front-running attacks are currently mitigated by the following mechanisms:
  *     - minimum return argument for each conversion provides a way to define a minimum/maximum price for the transaction
  *     - gas price limit prevents users from having control over the order of execution
  *     - gas price limit check can be skipped if the transaction comes from a trusted, whitelisted signer
  * 
  * Other potential solutions might include a commit/reveal based schemes
  * - Possibly add getters for the reserve fields so that the client won't need to rely on the order in the struct
*/
contract BancorConverter is IBancorConverter, SmartTokenController, Managed, ContractIds, FeatureIds {
    using SafeMath for uint256;

    uint32 private constant RATIO_RESOLUTION = 1000000;
    uint64 private constant CONVERSION_FEE_RESOLUTION = 1000000;

    struct Reserve {
        uint256 virtualBalance;         // reserve virtual balance
        uint32 ratio;                   // reserve ratio, represented in ppm, 1-1000000
        bool isVirtualBalanceEnabled;   // true if virtual balance is enabled, false if not
        bool isSaleEnabled;             // is sale of the reserve token enabled, can be set by the owner
        bool isSet;                     // used to tell if the mapping element is defined
    }

    /**
      * @dev version number
    */
    uint16 public version = 20;
    string public converterType = 'bancor';

    bool public allowRegistryUpdate = true;             // allows the owner to prevent/allow the registry to be updated
    IContractRegistry public prevRegistry;              // address of previous registry as security mechanism
    IContractRegistry public registry;                  // contract registry contract
    IWhitelist public conversionWhitelist;              // whitelist contract with list of addresses that are allowed to use the converter
    IERC20Token[] public reserveTokens;                 // ERC20 standard token addresses (prior version 17, use 'connectorTokens' instead)
    mapping (address => Reserve) public reserves;       // reserve token addresses -> reserve data (prior version 17, use 'connectors' instead)
    uint32 private totalReserveRatio = 0;               // used to efficiently prevent increasing the total reserve ratio above 100%
    uint32 public maxConversionFee = 0;                 // maximum conversion fee for the lifetime of the contract,
                                                        // represented in ppm, 0...1000000 (0 = no fee, 100 = 0.01%, 1000000 = 100%)
    uint32 public conversionFee = 0;                    // current conversion fee, represented in ppm, 0...maxConversionFee
    bool public conversionsEnabled = true;              // true if token conversions is enabled, false if not

    /**
      * @dev triggered when a conversion between two tokens occurs
      * 
      * @param _fromToken       ERC20 token converted from
      * @param _toToken         ERC20 token converted to
      * @param _trader          wallet that initiated the trade
      * @param _amount          amount converted, in fromToken
      * @param _return          amount returned, minus conversion fee
      * @param _conversionFee   conversion fee
    */
    event Conversion(
        address indexed _fromToken,
        address indexed _toToken,
        address indexed _trader,
        uint256 _amount,
        uint256 _return,
        int256 _conversionFee
    );

    /**
      * @dev triggered after a conversion with new price data
      * 
      * @param  _connectorToken     reserve token
      * @param  _tokenSupply        smart token supply
      * @param  _connectorBalance   reserve balance
      * @param  _connectorWeight    reserve ratio
    */
    event PriceDataUpdate(
        address indexed _connectorToken,
        uint256 _tokenSupply,
        uint256 _connectorBalance,
        uint32 _connectorWeight
    );

    /**
      * @dev triggered when the conversion fee is updated
      * 
      * @param  _prevFee    previous fee percentage, represented in ppm
      * @param  _newFee     new fee percentage, represented in ppm
    */
    event ConversionFeeUpdate(uint32 _prevFee, uint32 _newFee);

    /**
      * @dev triggered when conversions are enabled/disabled
      * 
      * @param  _conversionsEnabled true if conversions are enabled, false if not
    */
    event ConversionsEnable(bool _conversionsEnabled);

    /**
      * @dev triggered when virtual balances are enabled/disabled
      * 
      * @param  _enabled true if virtual balances are enabled, false if not
    */
    event VirtualBalancesEnable(bool _enabled);

    /**
      * @dev initializes a new BancorConverter instance
      * 
      * @param  _token              smart token governed by the converter
      * @param  _registry           address of a contract registry contract
      * @param  _maxConversionFee   maximum conversion fee, represented in ppm
      * @param  _reserveToken       optional, initial reserve, allows defining the first reserve at deployment time
      * @param  _reserveRatio       optional, ratio for the initial reserve
    */
    constructor(
        ISmartToken _token,
        IContractRegistry _registry,
        uint32 _maxConversionFee,
        IERC20Token _reserveToken,
        uint32 _reserveRatio
    )
        public
        SmartTokenController(_token)
        validAddress(_registry)
        validConversionFee(_maxConversionFee)
    {
        registry = _registry;
        prevRegistry = _registry;
        IContractFeatures features = IContractFeatures(registry.addressOf(ContractIds.CONTRACT_FEATURES));

        // initialize supported features
        if (features != address(0))
            features.enableFeatures(FeatureIds.CONVERTER_CONVERSION_WHITELIST, true);

        maxConversionFee = _maxConversionFee;

        if (_reserveToken != address(0))
            addReserve(_reserveToken, _reserveRatio);
    }

    // validates a reserve token address - verifies that the address belongs to one of the reserve tokens
    modifier validReserve(IERC20Token _address) {
        require(reserves[_address].isSet);
        _;
    }

    // validates conversion fee
    modifier validConversionFee(uint32 _conversionFee) {
        require(_conversionFee >= 0 && _conversionFee <= CONVERSION_FEE_RESOLUTION);
        _;
    }

    // validates reserve ratio
    modifier validReserveRatio(uint32 _ratio) {
        require(_ratio > 0 && _ratio <= RATIO_RESOLUTION);
        _;
    }

    // allows execution only when the total ratio is 100%
    modifier fullTotalRatioOnly() {
        require(totalReserveRatio == RATIO_RESOLUTION);
        _;
    }

    // allows execution only when conversions aren't disabled
    modifier conversionsAllowed {
        require(conversionsEnabled);
        _;
    }

    // allows execution by the BancorNetwork contract only
    modifier bancorNetworkOnly {
        IBancorNetwork bancorNetwork = IBancorNetwork(registry.addressOf(ContractIds.BANCOR_NETWORK));
        require(msg.sender == address(bancorNetwork));
        _;
    }

    // allows execution by the converter upgrader contract only
    modifier converterUpgraderOnly {
        address converterUpgrader = registry.addressOf(ContractIds.BANCOR_CONVERTER_UPGRADER);
        require(msg.sender == converterUpgrader);
        _;
    }

    // allows execution only if the total-supply of the token is greater than zero
    modifier totalSupplyGreaterThanZeroOnly {
        require(token.totalSupply() > 0);
        _;
    }

    /**
      * @dev sets the contract registry to whichever address the current registry is pointing to
     */
    function updateRegistry() public {
        // require that upgrading is allowed or that the caller is the owner
        require(allowRegistryUpdate || msg.sender == owner);

        // get the address of whichever registry the current registry is pointing to
        address newRegistry = registry.addressOf(ContractIds.CONTRACT_REGISTRY);

        // if the new registry hasn't changed or is the zero address, revert
        require(newRegistry != address(registry) && newRegistry != address(0));

        // set the previous registry as current registry and current registry as newRegistry
        prevRegistry = registry;
        registry = IContractRegistry(newRegistry);
    }

    /**
      * @dev security mechanism allowing the converter owner to revert to the previous registry,
      * to be used in emergency scenario
    */
    function restoreRegistry() public ownerOrManagerOnly {
        // set the registry as previous registry
        registry = prevRegistry;

        // after a previous registry is restored, only the owner can allow future updates
        allowRegistryUpdate = false;
    }

    /**
      * @dev disables the registry update functionality
      * this is a safety mechanism in case of a emergency
      * can only be called by the manager or owner
      * 
      * @param _disable    true to disable registry updates, false to re-enable them
    */
    function disableRegistryUpdate(bool _disable) public ownerOrManagerOnly {
        allowRegistryUpdate = !_disable;
    }

    /**
      * @dev returns the number of reserve tokens defined
      * note that prior to version 17, you should use 'connectorTokenCount' instead
      * 
      * @return number of reserve tokens
    */
    function reserveTokenCount() public view returns (uint16) {
        return uint16(reserveTokens.length);
    }

    /**
      * @dev allows the owner to update & enable the conversion whitelist contract address
      * when set, only addresses that are whitelisted are actually allowed to use the converter
      * note that the whitelist check is actually done by the BancorNetwork contract
      * 
      * @param _whitelist    address of a whitelist contract
    */
    function setConversionWhitelist(IWhitelist _whitelist)
        public
        ownerOnly
        notThis(_whitelist)
    {
        conversionWhitelist = _whitelist;
    }

    /**
      * @dev disables the entire conversion functionality
      * this is a safety mechanism in case of a emergency
      * can only be called by the manager
      * 
      * @param _disable true to disable conversions, false to re-enable them
    */
    function disableConversions(bool _disable) public ownerOrManagerOnly {
        if (conversionsEnabled == _disable) {
            conversionsEnabled = !_disable;
            emit ConversionsEnable(conversionsEnabled);
        }
    }

    /**
      * @dev allows transferring the token ownership
      * the new owner needs to accept the transfer
      * can only be called by the contract owner
      * note that token ownership can only be transferred while the owner is the converter upgrader contract
      * 
      * @param _newOwner    new token owner
    */
    function transferTokenOwnership(address _newOwner)
        public
        ownerOnly
        converterUpgraderOnly
    {
        super.transferTokenOwnership(_newOwner);
    }

    /**
      * @dev used by a new owner to accept a token ownership transfer
      * can only be called by the contract owner
      * note that token ownership can only be accepted if its total-supply is greater than zero
    */
    function acceptTokenOwnership()
        public
        ownerOnly
        totalSupplyGreaterThanZeroOnly
    {
        super.acceptTokenOwnership();
    }

    /**
      * @dev updates the current conversion fee
      * can only be called by the manager
      * 
      * @param _conversionFee new conversion fee, represented in ppm
    */
    function setConversionFee(uint32 _conversionFee)
        public
        ownerOrManagerOnly
    {
        require(_conversionFee >= 0 && _conversionFee <= maxConversionFee);
        emit ConversionFeeUpdate(conversionFee, _conversionFee);
        conversionFee = _conversionFee;
    }

    /**
      * @dev given a return amount, returns the amount minus the conversion fee
      * 
      * @param _amount      return amount
      * @param _magnitude   1 for standard conversion, 2 for cross reserve conversion
      * 
      * @return return amount minus conversion fee
    */
    function getFinalAmount(uint256 _amount, uint8 _magnitude) public view returns (uint256) {
        return _amount.mul((CONVERSION_FEE_RESOLUTION - conversionFee) ** _magnitude).div(CONVERSION_FEE_RESOLUTION ** _magnitude);
    }

    /**
      * @dev withdraws tokens held by the converter and sends them to an account
      * can only be called by the owner
      * note that reserve tokens can only be withdrawn by the owner while the converter is inactive
      * unless the owner is the converter upgrader contract
      * 
      * @param _token   ERC20 token contract address
      * @param _to      account to receive the new amount
      * @param _amount  amount to withdraw
    */
    function withdrawTokens(IERC20Token _token, address _to, uint256 _amount) public {
        address converterUpgrader = registry.addressOf(ContractIds.BANCOR_CONVERTER_UPGRADER);

        // if the token is not a reserve token, allow withdrawal
        // otherwise verify that the converter is inactive or that the owner is the upgrader contract
        require(!reserves[_token].isSet || token.owner() != address(this) || owner == converterUpgrader);
        super.withdrawTokens(_token, _to, _amount);
    }

    /**
      * @dev upgrades the converter to the latest version
      * can only be called by the owner
      * note that the owner needs to call acceptOwnership/acceptManagement on the new converter after the upgrade
    */
    function upgrade() public ownerOnly {
        IBancorConverterUpgrader converterUpgrader = IBancorConverterUpgrader(registry.addressOf(ContractIds.BANCOR_CONVERTER_UPGRADER));

        transferOwnership(converterUpgrader);
        converterUpgrader.upgrade(version);
        acceptOwnership();
    }

    /**
      * @dev defines a new reserve for the token
      * can only be called by the owner while the converter is inactive
      * note that prior to version 17, you should use 'addConnector' instead
      * 
      * @param _token                  address of the reserve token
      * @param _ratio                  constant reserve ratio, represented in ppm, 1-1000000
    */
    function addReserve(IERC20Token _token, uint32 _ratio)
        public
        ownerOnly
        inactive
        validAddress(_token)
        notThis(_token)
        validReserveRatio(_ratio)
    {
        require(_token != token && !reserves[_token].isSet && totalReserveRatio + _ratio <= RATIO_RESOLUTION); // validate input

        reserves[_token].ratio = _ratio;
        reserves[_token].isVirtualBalanceEnabled = false;
        reserves[_token].virtualBalance = 0;
        reserves[_token].isSaleEnabled = true;
        reserves[_token].isSet = true;
        reserveTokens.push(_token);
        totalReserveRatio += _ratio;
    }

    /**
      * @dev updates a reserve's virtual balance
      * only used during an upgrade process
      * can only be called by the contract owner while the owner is the converter upgrader contract
      * note that prior to version 17, you should use 'updateConnector' instead
      * 
      * @param _reserveToken    address of the reserve token
      * @param _virtualBalance  new reserve virtual balance, or 0 to disable virtual balance
    */
    function updateReserveVirtualBalance(IERC20Token _reserveToken, uint256 _virtualBalance)
        public
        ownerOnly
        converterUpgraderOnly
        validReserve(_reserveToken)
    {
        Reserve storage reserve = reserves[_reserveToken];
        reserve.isVirtualBalanceEnabled = _virtualBalance != 0;
        reserve.virtualBalance = _virtualBalance;
    }

    /**
      * @dev enables virtual balance for the reserves
      * virtual balance only affects conversions between reserve tokens
      * virtual balance of all reserves can only scale by the same factor, to keep the ratio between them the same
      * note that the balance is determined during the execution of this function and set statically -
      * meaning that it's not calculated dynamically based on the factor after each conversion
      * can only be called by the contract owner while the converter is active
      * 
      * @param _scaleFactor  percentage, 100-1000 (100 = no virtual balance, 1000 = virtual balance = actual balance * 10)
    */
    function enableVirtualBalances(uint16 _scaleFactor)
        public
        ownerOnly
        active
    {
        // validate input
        require(_scaleFactor >= 100 && _scaleFactor <= 1000);
        bool enable = _scaleFactor != 100;

        // iterate through the reserves and scale their balance by the ratio provided,
        // or disable virtual balance altogether if a factor of 100% is passed in
        IERC20Token reserveToken;
        for (uint16 i = 0; i < reserveTokens.length; i++) {
            reserveToken = reserveTokens[i];
            Reserve storage reserve = reserves[reserveToken];
            reserve.isVirtualBalanceEnabled = enable;
            reserve.virtualBalance = enable ? reserveToken.balanceOf(this).mul(_scaleFactor).div(100) : 0;
        }

        emit VirtualBalancesEnable(enable);
    }

    /**
      * @dev disables converting from the given reserve token in case the reserve token got compromised
      * can only be called by the owner
      * note that converting to the token is still enabled regardless of this flag and it cannot be disabled by the owner
      * note that prior to version 17, you should use 'disableConnectorSale' instead
      * 
      * @param _reserveToken    reserve token contract address
      * @param _disable         true to disable the token, false to re-enable it
    */
    function disableReserveSale(IERC20Token _reserveToken, bool _disable)
        public
        ownerOnly
        validReserve(_reserveToken)
    {
        reserves[_reserveToken].isSaleEnabled = !_disable;
    }

    /**
      * @dev returns the reserve's virtual balance if one is defined, otherwise returns the actual balance
      * note that prior to version 17, you should use 'getConnectorBalance' instead
      * 
      * @param _reserveToken    reserve token contract address
      * 
      * @return reserve balance
    */
    function getReserveBalance(IERC20Token _reserveToken)
        public
        view
        validReserve(_reserveToken)
        returns (uint256)
    {
        Reserve storage reserve = reserves[_reserveToken];
        return reserve.isVirtualBalanceEnabled ? reserve.virtualBalance : _reserveToken.balanceOf(this);
    }

    /**
      * @dev calculates the expected return of converting a given amount of tokens
      * 
      * @param _fromToken  contract address of the token to convert from
      * @param _toToken    contract address of the token to convert to
      * @param _amount     amount of tokens received from the user
      * 
      * @return amount of tokens that the user will receive
      * @return amount of tokens that the user will pay as fee
    */
    function getReturn(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount) public view returns (uint256, uint256) {
        require(_fromToken != _toToken); // validate input

        // conversion between the token and one of its reserves
        if (_toToken == token)
            return getPurchaseReturn(_fromToken, _amount);
        else if (_fromToken == token)
            return getSaleReturn(_toToken, _amount);

        // conversion between 2 reserves
        return getCrossReserveReturn(_fromToken, _toToken, _amount);
    }

    /**
      * @dev calculates the expected return of buying with a given amount of tokens
      * 
      * @param _reserveToken    contract address of the reserve token
      * @param _depositAmount   amount of reserve-tokens received from the user
      * 
      * @return amount of supply-tokens that the user will receive
      * @return amount of supply-tokens that the user will pay as fee
    */
    function getPurchaseReturn(IERC20Token _reserveToken, uint256 _depositAmount)
        public
        view
        active
        validReserve(_reserveToken)
        returns (uint256, uint256)
    {
        Reserve storage reserve = reserves[_reserveToken];
        require(reserve.isSaleEnabled); // validate input

        uint256 tokenSupply = token.totalSupply();
        uint256 reserveBalance = _reserveToken.balanceOf(this);
        IBancorFormula formula = IBancorFormula(registry.addressOf(ContractIds.BANCOR_FORMULA));
        uint256 amount = formula.calculatePurchaseReturn(tokenSupply, reserveBalance, reserve.ratio, _depositAmount);
        uint256 finalAmount = getFinalAmount(amount, 1);

        // return the amount minus the conversion fee and the conversion fee
        return (finalAmount, amount - finalAmount);
    }

    /**
      * @dev calculates the expected return of selling a given amount of tokens
      * 
      * @param _reserveToken    contract address of the reserve token
      * @param _sellAmount      amount of supply-tokens received from the user
      * 
      * @return amount of reserve-tokens that the user will receive
      * @return amount of reserve-tokens that the user will pay as fee
    */
    function getSaleReturn(IERC20Token _reserveToken, uint256 _sellAmount)
        public
        view
        active
        validReserve(_reserveToken)
        returns (uint256, uint256)
    {
        Reserve storage reserve = reserves[_reserveToken];
        uint256 tokenSupply = token.totalSupply();
        uint256 reserveBalance = _reserveToken.balanceOf(this);
        IBancorFormula formula = IBancorFormula(registry.addressOf(ContractIds.BANCOR_FORMULA));
        uint256 amount = formula.calculateSaleReturn(tokenSupply, reserveBalance, reserve.ratio, _sellAmount);
        uint256 finalAmount = getFinalAmount(amount, 1);

        // return the amount minus the conversion fee and the conversion fee
        return (finalAmount, amount - finalAmount);
    }

    /**
      * @dev calculates the expected return of converting a given amount from one reserve to another
      * note that prior to version 17, you should use 'getCrossConnectorReturn' instead
      * 
      * @param _fromReserveToken    contract address of the reserve token to convert from
      * @param _toReserveToken      contract address of the reserve token to convert to
      * @param _amount              amount of tokens received from the user
      * 
      * @return amount of tokens that the user will receive
      * @return amount of tokens that the user will pay as fee
    */
    function getCrossReserveReturn(IERC20Token _fromReserveToken, IERC20Token _toReserveToken, uint256 _amount)
        public
        view
        active
        validReserve(_fromReserveToken)
        validReserve(_toReserveToken)
        returns (uint256, uint256)
    {
        Reserve storage fromReserve = reserves[_fromReserveToken];
        Reserve storage toReserve = reserves[_toReserveToken];
        require(fromReserve.isSaleEnabled); // validate input

        IBancorFormula formula = IBancorFormula(registry.addressOf(ContractIds.BANCOR_FORMULA));
        uint256 amount = formula.calculateCrossReserveReturn(
            getReserveBalance(_fromReserveToken), 
            fromReserve.ratio, 
            getReserveBalance(_toReserveToken), 
            toReserve.ratio, 
            _amount);
        uint256 finalAmount = getFinalAmount(amount, 2);

        // return the amount minus the conversion fee and the conversion fee
        // the fee is higher (magnitude = 2) since cross reserve conversion equals 2 conversions (from / to the smart token)
        return (finalAmount, amount - finalAmount);
    }

    /**
      * @dev converts a specific amount of _fromToken to _toToken
      * can only be called by the bancor network contract
      * 
      * @param _fromToken  ERC20 token to convert from
      * @param _toToken    ERC20 token to convert to
      * @param _amount     amount to convert, in fromToken
      * @param _minReturn  if the conversion results in an amount smaller than the minimum return - it is cancelled, must be nonzero
      * 
      * @return conversion return amount
    */
    function convertInternal(IERC20Token _fromToken, IERC20Token _toToken, uint256 _amount, uint256 _minReturn)
        public
        bancorNetworkOnly
        conversionsAllowed
        greaterThanZero(_minReturn)
        returns (uint256)
    {
        require(_fromToken != _toToken); // validate input

        // conversion between the token and one of its reserves
        if (_toToken == token)
            return buy(_fromToken, _amount, _minReturn);
        else if (_fromToken == token)
            return sell(_toToken, _amount, _minReturn);

        uint256 amount;
        uint256 feeAmount;

        // conversion between 2 reserves
        (amount, feeAmount) = getCrossReserveReturn(_fromToken, _toToken, _amount);
        // ensure the trade gives something in return and meets the minimum requested amount
        require(amount != 0 && amount >= _minReturn);

        // update the source token virtual balance if relevant
        Reserve storage fromReserve = reserves[_fromToken];
        if (fromReserve.isVirtualBalanceEnabled)
            fromReserve.virtualBalance = fromReserve.virtualBalance.add(_amount);

        // update the target token virtual balance if relevant
        Reserve storage toReserve = reserves[_toToken];
        if (toReserve.isVirtualBalanceEnabled)
            toReserve.virtualBalance = toReserve.virtualBalance.sub(amount);

        // ensure that the trade won't deplete the reserve balance
        uint256 toReserveBalance = getReserveBalance(_toToken);
        assert(amount < toReserveBalance);

        // transfer funds from the caller in the from reserve token
        ensureTransferFrom(_fromToken, msg.sender, this, _amount);
        // transfer funds to the caller in the to reserve token
        // the t...

// [truncated — 73777 bytes total]

Read Contract

BANCOR_CONVERTER_FACTORY 0x5a46f06c → bytes32
BANCOR_CONVERTER_UPGRADER 0x0c87355e → bytes32
BANCOR_FORMULA 0x6d7bd3fc → bytes32
BANCOR_GAS_PRICE_LIMIT 0x9249993a → bytes32
BANCOR_NETWORK 0x9232494e → bytes32
BANCOR_X 0xc4a8598e → bytes32
BANCOR_X_UPGRADER 0xcc97b38f → bytes32
BNT_TOKEN 0x1d000b61 → bytes32
CONTRACT_FEATURES 0x83315b6e → bytes32
CONTRACT_REGISTRY 0x25f9bfef → bytes32
CONVERTER_CONVERSION_WHITELIST 0x92d1abb7 → uint256
NON_STANDARD_TOKEN_REGISTRY 0xf5286b9c → bytes32
allowRegistryUpdate 0x20d7d367 → bool
bancorX 0x1120a776 → address
connectorTokenCount 0x71f52bf3 → uint16
connectorTokens 0x19b64015 → address
connectors 0x0e53aae9 → uint256, uint32, bool, bool, bool
conversionFee 0x579cd3ca → uint32
conversionWhitelist 0xc45d3d92 → address
conversionsEnabled 0xbf754558 → bool
converterType 0x3e8ff43f → string
getConnectorBalance 0xd8959512 → uint256
getCrossConnectorReturn 0x8e3047e0 → uint256, uint256
getCrossReserveReturn 0xcf73266a → uint256, uint256
getFinalAmount 0x3aa0145a → uint256
getPurchaseReturn 0xa2c4c336 → uint256, uint256
getReserveBalance 0x15226b54 → uint256
getReturn 0x1e1401f8 → uint256, uint256
getSaleReturn 0x72b44b2c → uint256, uint256
manager 0x481c6a75 → address
maxConversionFee 0x94c275ad → uint32
newManager 0x42906029 → address
newOwner 0xd4ee1d90 → address
owner 0x8da5cb5b → address
prevRegistry 0x61cd756e → address
registry 0x7b103999 → address
reserveTokenCount 0x9b99a8e2 → uint16
reserveTokens 0xd031370b → address
reserves 0xd66bd524 → uint256, uint32, bool, bool, bool
token 0xfc0c546a → address
version 0x54fd4d50 → uint16

Write Contract 36 functions

These functions modify contract state and require a wallet transaction to execute.

acceptManagement 0xc8c2fe6c
No parameters
acceptOwnership 0x79ba5097
No parameters
acceptTokenOwnership 0x38a5e016
No parameters
addConnector 0x3f4d2fc2
address _token
uint32 _weight
bool
addReserve 0x6a49d2c4
address _token
uint32 _ratio
change 0x5e5144eb
address _fromToken
address _toToken
uint256 _amount
uint256 _minReturn
returns: uint256
claimTokens 0xfe417fa5
address _from
uint256 _amount
completeXConversion 0x50057351
address[] _path
uint256 _minReturn
uint256 _conversionId
uint256 _block
uint8 _v
bytes32 _r
bytes32 _s
returns: uint256
completeXConversion2 0x2cc1cd65
address[] _path
uint256 _minReturn
uint256 _conversionId
uint256[] _signature
returns: uint256
convert 0x75892cf1
address _fromToken
address _toToken
uint256 _amount
uint256 _minReturn
returns: uint256
convert2 0x6ebf36c0
address _fromToken
address _toToken
uint256 _amount
uint256 _minReturn
address _affiliateAccount
uint256 _affiliateFee
returns: uint256
convertInternal 0x2a2e2f0c
address _fromToken
address _toToken
uint256 _amount
uint256 _minReturn
returns: uint256
disableConnectorSale 0x9e568553
address _connectorToken
bool _disable
disableConversions 0x228d2820
bool _disable
disableRegistryUpdate 0xfa1c594e
bool _disable
disableReserveSale 0xa6a11c71
address _reserveToken
bool _disable
enableVirtualBalances 0x677c0812
uint16 _scaleFactor
fund 0xca1d209d
uint256 _amount
liquidate 0x415f1240
uint256 _amount
quickConvert 0xf0843ba9
address[] _path
uint256 _amount
uint256 _minReturn
returns: uint256
quickConvert2 0xe4dd22f6
address[] _path
uint256 _amount
uint256 _minReturn
address _affiliateAccount
uint256 _affiliateFee
returns: uint256
quickConvertPrioritized 0x22742564
address[] _path
uint256 _amount
uint256 _minReturn
uint256 _block
uint8 _v
bytes32 _r
bytes32 _s
returns: uint256
quickConvertPrioritized2 0xb3a426d5
address[] _path
uint256 _amount
uint256 _minReturn
uint256[] _signature
address _affiliateAccount
uint256 _affiliateFee
returns: uint256
restoreRegistry 0xb4a176d3
No parameters
setBancorX 0xd924f0c3
address _bancorX
setConversionFee 0xecbca55d
uint32 _conversionFee
setConversionWhitelist 0x4af80f0e
address _whitelist
transferManagement 0xe4edf852
address _newManager
transferOwnership 0xf2fde38b
address _newOwner
transferTokenOwnership 0x21e6b53d
address _newOwner
updateConnector 0x0ca78923
address _connectorToken
uint32
bool
uint256 _virtualBalance
updateRegistry 0x49d10b64
No parameters
updateReserveVirtualBalance 0x935e2ae1
address _reserveToken
uint256 _virtualBalance
upgrade 0xd55ec697
No parameters
withdrawFromToken 0x41a5b33d
address _token
address _to
uint256 _amount
withdrawTokens 0x5e35359e
address _token
address _to
uint256 _amount

Token Balances (1)

View Transfers →
TokenBalancePriceValue
DAI 30.6915

Recent Transactions

This address has 1 on-chain transactions, but only 1.2% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →