Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0x0df46950003EEd5b40bd94FDf0EFC4c148858eeB
Balance 0 ETH
Nonce 1
Code Size 10699 bytes
Indexed Transactions 0 (1 on-chain, 0.8% indexed)
External Etherscan · Sourcify

Contract Bytecode

10699 bytes
0x608060405234801561001057600080fd5b50600436106100a35760003560e01c806379ba5097116100765780638e18cdfc1161005b5780638e18cdfc14610167578063a375bb8614610188578063d9380519146101a857600080fd5b806379ba50971461013f5780638da5cb5b1461014757600080fd5b806335ef450c146100a85780635055374d146100bd57806353a47bb7146100e7578063686da2631461012c575b600080fd5b6100bb6100b6366004611ed8565b6101bb565b005b6100d06100cb366004611fc6565b61021c565b6040516100de92919061209a565b60405180910390f35b6001546101079073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100de565b6100bb61013a366004611fc6565b6102d0565b6100bb6103e9565b6000546101079073ffffffffffffffffffffffffffffffffffffffff1681565b61017a6101753660046120ba565b6104b7565b6040519081526020016100de565b61019b610196366004611fc6565b6107ff565b6040516100de9190612100565b6100bb6101b636600461212c565b610917565b60005473ffffffffffffffffffffffffffffffffffffffff16331461020c576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610217838383610d87565b505050565b60026020908152600092835260408084209091529082529020805460018201805460ff909216929161024d90612150565b80601f016020809104026020016040519081016040528092919081815260200182805461027990612150565b80156102c65780601f1061029b576101008083540402835291602001916102c6565b820191906000526020600020905b8154815290600101906020018083116102a957829003601f168201915b5050505050905082565b60005473ffffffffffffffffffffffffffffffffffffffff163314610321576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600260209081526040808320938516835292905290812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168155906103896001830182611d0c565b50508073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fc0870da31b80cb5ec8392bd4b6b3a0c00bbbdf2c342a1c5102b005ef63700aa660405160405180910390a35050565b60015473ffffffffffffffffffffffffffffffffffffffff16331461043a576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008054604051339273ffffffffffffffffffffffffffffffffffffffff909216917fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000009081163317909155600180549091169055565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260026020908152604080832093871683529290528181208251808401909352805491928392909190829060ff16600681111561051257610512611fff565b600681111561052357610523611fff565b815260200160018201805461053790612150565b80601f016020809104026020016040519081016040528092919081815260200182805461056390612150565b80156105b05780601f10610585576101008083540402835291602001916105b0565b820191906000526020600020905b81548152906001019060200180831161059357829003601f168201915b50505091909252509192508791506105e2905073ffffffffffffffffffffffffffffffffffffffff821633308861135a565b8151602083015160018260068111156105fd576105fd611fff565b14156106155761060e878783611420565b9450610729565b600282600681111561062957610629611fff565b141561063c5761060e89898989856114eb565b600382600681111561065057610650611fff565b14156106615761060e87878361163c565b600482600681111561067557610675611fff565b14156106865761060e878783611706565b600582600681111561069a5761069a611fff565b14156106ab5761060e878783611825565b60068260068111156106bf576106bf611fff565b14156106d25761060e8989898985611a30565b6040517fc532646c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808b166004830152891660248201526044015b60405180910390fd5b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8516906370a082319060240160206040518083038186803b15801561079157600080fd5b505afa1580156107a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107c991906121a4565b905080156107f2576107f273ffffffffffffffffffffffffffffffffffffffff85163383611b2c565b5050505050949350505050565b60408051808201909152600081526060602082015273ffffffffffffffffffffffffffffffffffffffff8084166000908152600260209081526040808320938616835292905281902081518083019092528054829060ff16600681111561086857610868611fff565b600681111561087957610879611fff565b815260200160018201805461088d90612150565b80601f01602080910402602001604051908101604052809291908181526020018280546108b990612150565b80156109065780601f106108db57610100808354040283529160200191610906565b820191906000526020600020905b8154815290600101906020018083116108e957829003601f168201915b505050505081525050905092915050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610968576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600080806109bd8482610b1b565b92506109ca846014610bab565b90506109e26109db600360146121ec565b8590610b1b565b91509193909250565b60006109f9600360146121ec565b6014610a066003826121ec565b610a1091906121ec565b610a1a91906121ec565b825110159050919050565b6060610a56610a36600360146121ec565b610a42600360146121ec565b8451610a4e9190612204565b849190610c2b565b92915050565b60006040517f095ea7b3000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080610b15576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f415050524f56455f4641494c45440000000000000000000000000000000000006044820152606401610720565b50505050565b6000610b288260146121ec565b83511015610b92576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e647300000000000000000000006044820152606401610720565b5001602001516c01000000000000000000000000900490565b6000610bb88260036121ec565b83511015610c22576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f746f55696e7432345f6f75744f66426f756e64730000000000000000000000006044820152606401610720565b50016003015190565b606081610c3981601f6121ec565b1015610ca1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f736c6963655f6f766572666c6f770000000000000000000000000000000000006044820152606401610720565b610cab82846121ec565b84511015610d15576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f736c6963655f6f75744f66426f756e64730000000000000000000000000000006044820152606401610720565b606082158015610d345760405191506000825260208201604052610d7e565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015610d6d578051835260209283019201610d55565b5050858452601f01601f1916604052505b50949350505050565b805160208201516001826006811115610da257610da2611fff565b1480610dbf57506004826006811115610dbd57610dbd611fff565b145b15610ee857600081806020019051810190610dda919061223f565b90508573ffffffffffffffffffffffffffffffffffffffff1681600081518110610e0657610e066122ce565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1614610e5b576040517f9d6e44d600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff168160018351610e819190612204565b81518110610e9157610e916122ce565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1614610ee6576040517f9d6e44d600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b6002826006811115610efc57610efc611fff565b1415610f185780806020019051810190610f1691906122fd565b505b6003826006811115610f2c57610f2c611fff565b141561103d57806000610f3e826109af565b505090508673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610fa7576040517f9d6e44d600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610fb0826109eb565b15610fc557610fbe82610a25565b9150610fa7565b6000610fd0836109af565b509150508673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614611039576040517f9d6e44d600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505b600682600681111561105157611051611fff565b14156111ea5760008180602001905181019061106d91906121a4565b6040517fb05f8e480000000000000000000000000000000000000000000000000000000081526004810182905273ffffffffffffffffffffffffffffffffffffffff8816602482015290915073ba12222222228d8ba445958a75a0704d566bf2c89063b05f8e489060440160806040518083038186803b1580156110f057600080fd5b505afa158015611104573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111289190612322565b50506040517fb05f8e480000000000000000000000000000000000000000000000000000000081526004810184905273ffffffffffffffffffffffffffffffffffffffff8816602482015273ba12222222228d8ba445958a75a0704d566bf2c8925063b05f8e48915060440160806040518083038186803b1580156111ac57600080fd5b505afa1580156111c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e49190612322565b50505050505b60006111f583611be5565b905061121973ffffffffffffffffffffffffffffffffffffffff8716826000610a5c565b61125a73ffffffffffffffffffffffffffffffffffffffff8716827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610a5c565b73ffffffffffffffffffffffffffffffffffffffff8087166000908152600260209081526040808320938916835292905220845181548692919082907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660018360068111156112cc576112cc611fff565b021790555060208281015180516112e99260018501920190611d49565b509050508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fd1b24a7df44b354e5023c2051e3ec8b010131ee4591d2c214c00847a1ed4422a8660405161134a9190612100565b60405180910390a3505050505050565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080611419576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c45440000000000000000000000006044820152606401610720565b5050505050565b60008082806020019051810190611437919061223f565b6040517f472b43f30000000000000000000000000000000000000000000000000000000081529091507368b3465833fb72a70ecdf485e0e4c7bd8665fc459063472b43f3906114909088908890869033906004016123b4565b602060405180830381600087803b1580156114aa57600080fd5b505af11580156114be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114e291906121a4565b95945050505050565b6000808280602001905181019061150291906122fd565b6040805160e08101825273ffffffffffffffffffffffffffffffffffffffff8a811682528981166020830190815262ffffff8581168486019081523360608601908152608086018d815260a087018d8152600060c0890190815298517f04e45aaf000000000000000000000000000000000000000000000000000000008152975187166004890152945186166024880152915190921660448601529051831660648501525160848401525160a4830152915190911660c48201529091507368b3465833fb72a70ecdf485e0e4c7bd8665fc45906304e45aaf9060e4015b602060405180830381600087803b1580156115f957600080fd5b505af115801561160d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163191906121a4565b979650505050505050565b604080516080810182528281523360208201528082018590526060810184905290517fb858183f0000000000000000000000000000000000000000000000000000000081526000917368b3465833fb72a70ecdf485e0e4c7bd8665fc459163b858183f916116ac916004016123fa565b602060405180830381600087803b1580156116c657600080fd5b505af11580156116da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116fe91906121a4565b949350505050565b6000808280602001905181019061171d919061223f565b6040517f38ed173900000000000000000000000000000000000000000000000000000000815290915060009073d9e1ce17f2641f24ae83637ab66a2cca9c378b9f906338ed17399061179b9089908990879033907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90600401612456565b600060405180830381600087803b1580156117b557600080fd5b505af11580156117c9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526117f1919081019061249f565b905080600182516118029190612204565b81518110611812576118126122ce565b6020026020010151925050509392505050565b60008060008380602001905181019061183e9190612594565b915091508582600081518110611856576118566122ce565b602002602001015160600181815250506000815167ffffffffffffffff81111561188257611882611e04565b6040519080825280602002602001820160405280156118ab578160200160208202803683370190505b50905086816000815181106118c2576118c26122ce565b60209081029190910101526118d686612700565b81600183516118e59190612204565b815181106118f5576118f56122ce565b60209081029190910181019190915260408051608081018252308152600092810183905233818301526060810183905290517f945bcec900000000000000000000000000000000000000000000000000000000815273ba12222222228d8ba445958a75a0704d566bf2c89163945bcec99161199c9185918991899189907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90600401612779565b600060405180830381600087803b1580156119b657600080fd5b505af11580156119ca573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526119f2919081019061249f565b90508060018251611a039190612204565b81518110611a1357611a136122ce565b6020026020010151611a2490612700565b98975050505050505050565b60008082806020019051810190611a4791906121a4565b6040805160c0810182528281526000602080830182905273ffffffffffffffffffffffffffffffffffffffff808d16848601528b1660608085019190915260808085018c90528551808401875284815260a086015285519081018652308152918201839052338286015281019190915291517f52bbbe2900000000000000000000000000000000000000000000000000000000815292935073ba12222222228d8ba445958a75a0704d566bf2c8926352bbbe29926115df929189907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff906004016128be565b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080610b15576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c454400000000000000000000000000000000006044820152606401610720565b60006004826006811115611bfb57611bfb611fff565b1415611c1c575073d9e1ce17f2641f24ae83637ab66a2cca9c378b9f919050565b6001826006811115611c3057611c30611fff565b1480611c4d57506002826006811115611c4b57611c4b611fff565b145b80611c6957506003826006811115611c6757611c67611fff565b145b15611c8957507368b3465833fb72a70ecdf485e0e4c7bd8665fc45919050565b6005826006811115611c9d57611c9d611fff565b1480611cba57506006826006811115611cb857611cb8611fff565b145b15611cda575073ba12222222228d8ba445958a75a0704d566bf2c8919050565b6040517f9d6e44d600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b508054611d1890612150565b6000825580601f10611d28575050565b601f016020900490600052602060002090810190611d469190611dcd565b50565b828054611d5590612150565b90600052602060002090601f016020900481019282611d775760008555611dbd565b82601f10611d9057805160ff1916838001178555611dbd565b82800160010185558215611dbd579182015b82811115611dbd578251825591602001919060010190611da2565b50611dc9929150611dcd565b5090565b5b80821115611dc95760008155600101611dce565b73ffffffffffffffffffffffffffffffffffffffff81168114611d4657600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040805190810167ffffffffffffffff81118282101715611e5657611e56611e04565b60405290565b60405160a0810167ffffffffffffffff81118282101715611e5657611e56611e04565b604051601f8201601f1916810167ffffffffffffffff81118282101715611ea857611ea8611e04565b604052919050565b600067ffffffffffffffff821115611eca57611eca611e04565b50601f01601f191660200190565b600080600060608486031215611eed57600080fd5b8335611ef881611de2565b9250602084810135611f0981611de2565b9250604085013567ffffffffffffffff80821115611f2657600080fd5b9086019060408289031215611f3a57600080fd5b611f42611e33565b823560078110611f5157600080fd5b81528284013582811115611f6457600080fd5b80840193505088601f840112611f7957600080fd5b82359150611f8e611f8983611eb0565b611e7f565b8281528985848601011115611fa257600080fd5b82858501868301376000858483010152808583015250809450505050509250925092565b60008060408385031215611fd957600080fd5b8235611fe481611de2565b91506020830135611ff481611de2565b809150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6007811061203e5761203e611fff565b9052565b60005b8381101561205d578181015183820152602001612045565b83811115610b155750506000910152565b60008151808452612086816020860160208601612042565b601f01601f19169290920160200192915050565b6120a4818461202e565b6040602082015260006116fe604083018461206e565b600080600080608085870312156120d057600080fd5b84356120db81611de2565b935060208501356120eb81611de2565b93969395505050506040820135916060013590565b6020815261211260208201835161202e565b600060208301516040808401526116fe606084018261206e565b60006020828403121561213e57600080fd5b813561214981611de2565b9392505050565b600181811c9082168061216457607f821691505b6020821081141561219e577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b6000602082840312156121b657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082198211156121ff576121ff6121bd565b500190565b600082821015612216576122166121bd565b500390565b600067ffffffffffffffff82111561223557612235611e04565b5060051b60200190565b6000602080838503121561225257600080fd5b825167ffffffffffffffff81111561226957600080fd5b8301601f8101851361227a57600080fd5b8051612288611f898261221b565b81815260059190911b820183019083810190878311156122a757600080fd5b928401925b828410156116315783516122bf81611de2565b825292840192908401906122ac565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006020828403121561230f57600080fd5b815162ffffff8116811461214957600080fd5b6000806000806080858703121561233857600080fd5b845193506020850151925060408501519150606085015161235881611de2565b939692955090935050565b600081518084526020808501945080840160005b838110156123a957815173ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101612377565b509495945050505050565b8481528360208201526080604082015260006123d36080830185612363565b905073ffffffffffffffffffffffffffffffffffffffff8316606083015295945050505050565b60208152600082516080602084015261241660a084018261206e565b905073ffffffffffffffffffffffffffffffffffffffff602085015116604084015260408401516060840152606084015160808401528091505092915050565b85815284602082015260a06040820152600061247560a0830186612363565b73ffffffffffffffffffffffffffffffffffffffff94909416606083015250608001529392505050565b600060208083850312156124b257600080fd5b825167ffffffffffffffff8111156124c957600080fd5b8301601f810185136124da57600080fd5b80516124e8611f898261221b565b81815260059190911b8201830190838101908783111561250757600080fd5b928401925b828410156116315783518252928401929084019061250c565b600082601f83011261253657600080fd5b81516020612546611f898361221b565b82815260059290921b8401810191818101908684111561256557600080fd5b8286015b8481101561258957805161257c81611de2565b8352918301918301612569565b509695505050505050565b60008060408084860312156125a857600080fd5b835167ffffffffffffffff808211156125c057600080fd5b818601915086601f8301126125d457600080fd5b815160206125e4611f898361221b565b82815260059290921b8401810191818101908a84111561260357600080fd5b8286015b848110156126ce5780518681111561261e57600080fd5b870160a0818e03601f1901121561263457600080fd5b61263c611e5c565b858201518152898201518682015260608201518a8201526080820151606082015260a0820151888111156126705760008081fd5b8083019250508d603f8301126126865760008081fd5b85820151612696611f8982611eb0565b8181528f8c8386010111156126ab5760008081fd5b6126ba828983018e8701612042565b608083015250845250918301918301612607565b50918901519197509094505050808311156126e857600080fd5b50506126f685828601612525565b9150509250929050565b60007f8000000000000000000000000000000000000000000000000000000000000000821415612732576127326121bd565b5060000390565b6002811061203e5761203e611fff565b600081518084526020808501945080840160005b838110156123a95781518752958201959082019060010161275d565b600061012080830161278b848b612739565b60208481019290925288519081905261014080850192600583901b8601909101918a820160005b82811015612832578785037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec00186528151805186528481015185870152604080820151908701526060808201519087015260809081015160a09187018290529061281e8188018361206e565b9786019796505050908301906001016127b2565b5050505083810360408501526128488189612363565b915050612897606084018773ffffffffffffffffffffffffffffffffffffffff808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b82810360e08401526128a98186612749565b91505082610100830152979650505050505050565b60e08152845160e0820152600060208601516128de610100840182612739565b50604086015173ffffffffffffffffffffffffffffffffffffffff908116610120840152606087015116610140830152608086015161016083015260a086015160c06101808401526129346101a084018261206e565b915050612983602083018673ffffffffffffffffffffffffffffffffffffffff808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c001529291505056fea26469706673582212201bf34f3b7123039eb7e3e481e95cc16e474e879287b552375d9c4f4dc275196d64736f6c63430008090033

Verified Source Code Full Match

Compiler: v0.8.9+commit.e5eed63a EVM: london Optimization: Yes (10000 runs)
Swap.sol 363 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.9;

import "solmate/tokens/ERC20.sol";
import "solmate/utils/SafeTransferLib.sol";
import "./external/uniswap/ISwapRouter02.sol";
import "./external/sushiswap/ISushiRouter.sol";
import {IAsset, IVault} from "./external/balancer/IVault.sol";
import "./libraries/Ownable.sol";
import "./libraries/Path.sol";

/**
 * @notice
 * Swap contract used by strategies to:
 * 1. swap strategy rewards to 'asset'
 * 2. zap similar tokens to asset (e.g. USDT to USDC)
 */
contract Swap is Ownable {
    using SafeTransferLib for ERC20;
    using Path for bytes;

    enum Route {
        Unsupported,
        UniswapV2,
        UniswapV3Direct,
        UniswapV3Path,
        SushiSwap,
        BalancerBatch,
        BalancerSingle
    }

    /**
     * @dev info depends on route:
     * 		UniswapV2: address[] path
     * 		UniswapV3Direct: uint24 fee
     * 		UniswapV3Path: bytes path (address, uint24 fee, address, uint24 fee, address)
     */
    struct RouteInfo {
        Route route;
        bytes info;
    }

    ISushiRouter internal constant sushiswap = ISushiRouter(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
    /// @dev single address which supports both uniswap v2 and v3 routes
    ISwapRouter02 internal constant uniswap = ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45);

    IVault internal constant balancer = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);

    /// @dev tokenIn => tokenOut => routeInfo
    mapping(address => mapping(address => RouteInfo)) public routes;

    /*//////////////////
    /      Events      /
    //////////////////*/

    event RouteSet(address indexed tokenIn, address indexed tokenOut, RouteInfo routeInfo);
    event RouteRemoved(address indexed tokenIn, address indexed tokenOut);

    /*//////////////////
    /      Errors      /
    //////////////////*/

    error UnsupportedRoute(address tokenIn, address tokenOut);
    error InvalidRouteInfo();

    constructor() Ownable() {
        address CRV = 0xD533a949740bb3306d119CC777fa900bA034cd52;
        address CVX = 0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B;
        address LDO = 0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32;

        address WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

        address STG = 0xAf5191B0De278C7286d6C7CC6ab6BB8A73bA2Cd6;
        address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
        address USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;

        address BAL = 0xba100000625a3754423978a60c9317c58a424e3D;
        address AURA = 0xC0c293ce456fF0ED870ADd98a0828Dd4d2903DBF;

        _setRoute(CRV, WETH, RouteInfo({route: Route.UniswapV3Direct, info: abi.encode(uint24(3_000))}));
        _setRoute(CVX, WETH, RouteInfo({route: Route.UniswapV3Direct, info: abi.encode(uint24(10_000))}));
        _setRoute(LDO, WETH, RouteInfo({route: Route.UniswapV3Direct, info: abi.encode(uint24(3_000))}));

        _setRoute(CRV, USDC, RouteInfo({route: Route.UniswapV3Direct, info: abi.encode(uint24(10_000))}));
        _setRoute(
            CVX,
            USDC,
            RouteInfo({route: Route.UniswapV3Path, info: abi.encodePacked(CVX, uint24(10_000), WETH, uint24(500), USDC)})
        );

        _setRoute(USDC, USDT, RouteInfo({route: Route.UniswapV3Direct, info: abi.encode(uint24(100))}));

        _setRoute(
            STG,
            USDC,
            RouteInfo({
                route: Route.BalancerSingle,
                info: abi.encode(0x3ff3a210e57cfe679d9ad1e9ba6453a716c56a2e0002000000000000000005d5)
            })
        );
        IAsset[] memory stgWethAssets = new IAsset[](4);
        stgWethAssets[0] = IAsset(STG);
        stgWethAssets[1] = IAsset(USDC);
        stgWethAssets[2] = IAsset(0x79c58f70905F734641735BC61e45c19dD9Ad60bC); // 3pool
        stgWethAssets[3] = IAsset(WETH);

        bytes32[] memory stgWethPoolIds = new bytes32[](3);
        stgWethPoolIds[0] = 0x3ff3a210e57cfe679d9ad1e9ba6453a716c56a2e0002000000000000000005d5; // STG/USDC
        stgWethPoolIds[1] = 0x79c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7; // 3pool
        stgWethPoolIds[2] = 0x08775ccb6674d6bdceb0797c364c2653ed84f3840002000000000000000004f0; // 3pool/WETH

        IVault.BatchSwapStep[] memory stgWethSteps = _constructBalancerBatchSwapSteps(stgWethPoolIds);

        _setRoute(STG, WETH, RouteInfo({route: Route.BalancerBatch, info: abi.encode(stgWethSteps, stgWethAssets)}));

        bytes32 balWethPoolId = 0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014;
        _setRoute(BAL, WETH, RouteInfo({route: Route.BalancerSingle, info: abi.encode(balWethPoolId)}));

        bytes32 auraWethPoolId = 0xcfca23ca9ca720b6e98e3eb9b6aa0ffc4a5c08b9000200000000000000000274;
        _setRoute(AURA, WETH, RouteInfo({route: Route.BalancerSingle, info: abi.encode(auraWethPoolId)}));
    }

    /*///////////////////////
    /      Public View      /
    ///////////////////////*/

    function getRoute(address _tokenIn, address _tokenOut) external view returns (RouteInfo memory routeInfo) {
        return routes[_tokenIn][_tokenOut];
    }

    /*////////////////////////////
    /      Public Functions      /
    ////////////////////////////*/

    function swapTokens(address _tokenIn, address _tokenOut, uint256 _amount, uint256 _minReceived)
        external
        returns (uint256 received)
    {
        RouteInfo memory routeInfo = routes[_tokenIn][_tokenOut];

        ERC20 tokenIn = ERC20(_tokenIn);
        tokenIn.safeTransferFrom(msg.sender, address(this), _amount);

        Route route = routeInfo.route;
        bytes memory info = routeInfo.info;

        if (route == Route.UniswapV2) {
            received = _uniswapV2(_amount, _minReceived, info);
        } else if (route == Route.UniswapV3Direct) {
            received = _uniswapV3Direct(_tokenIn, _tokenOut, _amount, _minReceived, info);
        } else if (route == Route.UniswapV3Path) {
            received = _uniswapV3Path(_amount, _minReceived, info);
        } else if (route == Route.SushiSwap) {
            received = _sushiswap(_amount, _minReceived, info);
        } else if (route == Route.BalancerBatch) {
            received = _balancerBatch(_amount, _minReceived, info);
        } else if (route == Route.BalancerSingle) {
            received = _balancerSingle(_tokenIn, _tokenOut, _amount, _minReceived, info);
        } else {
            revert UnsupportedRoute(_tokenIn, _tokenOut);
        }

        // return unswapped amount to sender
        uint256 balance = tokenIn.balanceOf(address(this));
        if (balance > 0) tokenIn.safeTransfer(msg.sender, balance);
    }

    /*///////////////////////////////////////////
    /      Restricted Functions: onlyOwner      /
    ///////////////////////////////////////////*/

    function setRoute(address _tokenIn, address _tokenOut, RouteInfo memory _routeInfo) external onlyOwner {
        _setRoute(_tokenIn, _tokenOut, _routeInfo);
    }

    function unsetRoute(address _tokenIn, address _tokenOut) external onlyOwner {
        delete routes[_tokenIn][_tokenOut];
        emit RouteRemoved(_tokenIn, _tokenOut);
    }

    /*//////////////////////////////
    /      Internal Functions      /
    //////////////////////////////*/

    function _setRoute(address _tokenIn, address _tokenOut, RouteInfo memory _routeInfo) internal {
        Route route = _routeInfo.route;
        bytes memory info = _routeInfo.info;

        if (route == Route.UniswapV2 || route == Route.SushiSwap) {
            address[] memory path = abi.decode(info, (address[]));

            if (path[0] != _tokenIn) revert InvalidRouteInfo();
            if (path[path.length - 1] != _tokenOut) revert InvalidRouteInfo();
        }

        // just check that this doesn't throw an error
        if (route == Route.UniswapV3Direct) abi.decode(info, (uint24));

        if (route == Route.UniswapV3Path) {
            bytes memory path = info;

            // check first tokenIn
            (address tokenIn,,) = path.decodeFirstPool();
            if (tokenIn != _tokenIn) revert InvalidRouteInfo();

            // check last tokenOut
            while (path.hasMultiplePools()) path = path.skipToken();
            (, address tokenOut,) = path.decodeFirstPool();
            if (tokenOut != _tokenOut) revert InvalidRouteInfo();
        }

        // just check that these don't throw an error, i.e. the poolId contains both _tokenIn
        if (route == Route.BalancerSingle) {
            bytes32 poolId = abi.decode(info, (bytes32));
            balancer.getPoolTokenInfo(poolId, _tokenIn);
            balancer.getPoolTokenInfo(poolId, _tokenOut);
        }

        address router = _getRouterAddress(route);

        ERC20(_tokenIn).safeApprove(router, 0);
        ERC20(_tokenIn).safeApprove(router, type(uint256).max);

        routes[_tokenIn][_tokenOut] = _routeInfo;
        emit RouteSet(_tokenIn, _tokenOut, _routeInfo);
    }

    function _uniswapV2(uint256 _amount, uint256 _minReceived, bytes memory _path) internal returns (uint256) {
        address[] memory path = abi.decode(_path, (address[]));

        return uniswap.swapExactTokensForTokens(_amount, _minReceived, path, msg.sender);
    }

    function _sushiswap(uint256 _amount, uint256 _minReceived, bytes memory _path) internal returns (uint256) {
        address[] memory path = abi.decode(_path, (address[]));

        uint256[] memory received =
            sushiswap.swapExactTokensForTokens(_amount, _minReceived, path, msg.sender, type(uint256).max);

        return received[received.length - 1];
    }

    function _uniswapV3Direct(
        address _tokenIn,
        address _tokenOut,
        uint256 _amount,
        uint256 _minReceived,
        bytes memory _info
    ) internal returns (uint256) {
        uint24 fee = abi.decode(_info, (uint24));

        return uniswap.exactInputSingle(
            ISwapRouter02.ExactInputSingleParams({
                tokenIn: _tokenIn,
                tokenOut: _tokenOut,
                fee: fee,
                recipient: msg.sender,
                amountIn: _amount,
                amountOutMinimum: _minReceived,
                sqrtPriceLimitX96: 0
            })
        );
    }

    function _uniswapV3Path(uint256 _amount, uint256 _minReceived, bytes memory _path) internal returns (uint256) {
        return uniswap.exactInput(
            ISwapRouter02.ExactInputParams({
                path: _path,
                recipient: msg.sender,
                amountIn: _amount,
                amountOutMinimum: _minReceived
            })
        );
    }

    function _balancerBatch(uint256 _amount, uint256 _minReceived, bytes memory _info) internal returns (uint256) {
        (IVault.BatchSwapStep[] memory steps, IAsset[] memory assets) =
            abi.decode(_info, (IVault.BatchSwapStep[], IAsset[]));

        steps[0].amount = _amount;

        int256[] memory limits = new int256[](assets.length);

        limits[0] = int256(_amount);
        limits[limits.length - 1] = -int256(_minReceived);

        int256[] memory received = balancer.batchSwap(
            IVault.SwapKind.GIVEN_IN,
            steps,
            assets,
            IVault.FundManagement({
                sender: address(this),
                fromInternalBalance: false,
                recipient: payable(address(msg.sender)),
                toInternalBalance: false
            }),
            limits,
            type(uint256).max
        );

        return uint256(-received[received.length - 1]);
    }

    function _balancerSingle(
        address _tokenIn,
        address _tokenOut,
        uint256 _amount,
        uint256 _minReceived,
        bytes memory _info
    ) internal returns (uint256) {
        bytes32 poolId = abi.decode(_info, (bytes32));

        return balancer.swap(
            IVault.SingleSwap({
                poolId: poolId,
                kind: IVault.SwapKind.GIVEN_IN,
                assetIn: IAsset(_tokenIn),
                assetOut: IAsset(_tokenOut),
                amount: _amount,
                userData: ""
            }),
            IVault.FundManagement({
                sender: address(this),
                fromInternalBalance: false,
                recipient: payable(address(msg.sender)),
                toInternalBalance: false
            }),
            _minReceived,
            type(uint256).max
        );
    }

    function _getRouterAddress(Route _route) internal pure returns (address) {
        if (_route == Route.SushiSwap) {
            return address(sushiswap);
        } else if (_route == Route.UniswapV2 || _route == Route.UniswapV3Direct || _route == Route.UniswapV3Path) {
            return address(uniswap);
        } else if (_route == Route.BalancerBatch || _route == Route.BalancerSingle) {
            return address(balancer);
        } else {
            revert InvalidRouteInfo();
        }
    }

    function _constructBalancerBatchSwapSteps(bytes32[] memory _poolIds)
        internal
        pure
        returns (IVault.BatchSwapStep[] memory steps)
    {
        uint256 length = _poolIds.length;
        steps = new IVault.BatchSwapStep[](length);

        for (uint8 i = 0; i < length; ++i) {
            steps[i] = IVault.BatchSwapStep({
                poolId: _poolIds[i],
                assetInIndex: i,
                assetOutIndex: i + 1,
                amount: 0,
                userData: ""
            });
        }
    }
}
Path.sol 63 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

// https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/Path.sol

import "./BytesLib.sol";

/// @title Functions for manipulating path data for multihop swaps
library Path {
    using BytesLib for bytes;

    /// @dev The length of the bytes encoded address
    uint256 private constant ADDR_SIZE = 20;
    /// @dev The length of the bytes encoded fee
    uint256 private constant FEE_SIZE = 3;

    /// @dev The offset of a single token address and pool fee
    uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE;
    /// @dev The offset of an encoded pool key
    uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE;
    /// @dev The minimum length of an encoding that contains 2 or more pools
    uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET;

    /// @notice Returns true iff the path contains two or more pools
    /// @param path The encoded swap path
    /// @return True if path contains two or more pools, otherwise false
    function hasMultiplePools(bytes memory path) internal pure returns (bool) {
        return path.length >= MULTIPLE_POOLS_MIN_LENGTH;
    }

    /// @notice Returns the number of pools in the path
    /// @param path The encoded swap path
    /// @return The number of pools in the path
    function numPools(bytes memory path) internal pure returns (uint256) {
        // Ignore the first token address. From then on every fee and token offset indicates a pool.
        return ((path.length - ADDR_SIZE) / NEXT_OFFSET);
    }

    /// @notice Decodes the first pool in path
    /// @param path The bytes encoded swap path
    /// @return tokenA The first token of the given pool
    /// @return tokenB The second token of the given pool
    /// @return fee The fee level of the pool
    function decodeFirstPool(bytes memory path) internal pure returns (address tokenA, address tokenB, uint24 fee) {
        tokenA = path.toAddress(0);
        fee = path.toUint24(ADDR_SIZE);
        tokenB = path.toAddress(NEXT_OFFSET);
    }

    /// @notice Gets the segment corresponding to the first pool in the path
    /// @param path The bytes encoded swap path
    /// @return The segment containing all data necessary to target the first pool in the path
    function getFirstPool(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(0, POP_OFFSET);
    }

    /// @notice Skips a token + fee element from the buffer and returns the remainder
    /// @param path The swap path
    /// @return The remaining token + fee elements in the path
    function skipToken(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET);
    }
}
Ownable.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

abstract contract Ownable {
    address public owner;
    address public nominatedOwner;

    error Unauthorized();

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

    constructor() {
        owner = msg.sender;
    }

    // Public Functions

    function acceptOwnership() external {
        if (msg.sender != nominatedOwner) revert Unauthorized();
        emit OwnerChanged(owner, msg.sender);
        owner = msg.sender;
        nominatedOwner = address(0);
    }

    // Restricted Functions: onlyOwner

    /// @dev nominating zero address revokes a pending nomination
    function nominateOwnership(address _newOwner) external onlyOwner {
        nominatedOwner = _newOwner;
    }

    // Modifiers

    modifier onlyOwner() {
        if (msg.sender != owner) revert Unauthorized();
        _;
    }
}
BytesLib.sol 88 lines
// SPDX-License-Identifier: Unlicense

//https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol

pragma solidity >=0.8.0 <0.9.0;

library BytesLib {
    function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } { mstore(mc, mload(cc)) }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
        require(_bytes.length >= _start + 3, "toUint24_outOfBounds");
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }
}
ERC20.sol 206 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}
IVault.sol 89 lines
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.9;

/// https://etherscan.io/address/0xBA12222222228d8Ba445958a75a0704d566BF2C8#code

interface IAsset {}

interface IVault {
    struct JoinPoolRequest {
        IAsset[] assets;
        uint256[] maxAmountsIn;
        bytes userData;
        bool fromInternalBalance;
    }

    enum PoolSpecialization {
        GENERAL,
        MINIMAL_SWAP_INFO,
        TWO_TOKEN
    }

    function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);

    function getPoolTokens(bytes32 poolId)
        external
        view
        returns (address[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock);

    function getPoolTokenInfo(bytes32 poolId, address token)
        external
        view
        returns (uint256 cash, uint256 managed, uint256 lastChangedBlock, address assetManager);

    function queryExit(bytes32 poolId, address sender, address recipient, IVault.ExitPoolRequest memory request)
        external
        returns (uint256 bptIn, uint256[] memory amountsOut);

    enum SwapKind {
        GIVEN_IN,
        GIVEN_OUT
    }

    struct BatchSwapStep {
        bytes32 poolId;
        uint256 assetInIndex;
        uint256 assetOutIndex;
        uint256 amount;
        bytes userData;
    }

    struct FundManagement {
        address sender;
        bool fromInternalBalance;
        address payable recipient;
        bool toInternalBalance;
    }

    function batchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds,
        int256[] memory limits,
        uint256 deadline
    ) external payable returns (int256[] memory);

    struct SingleSwap {
        bytes32 poolId;
        SwapKind kind;
        IAsset assetIn;
        IAsset assetOut;
        uint256 amount;
        bytes userData;
    }

    function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline)
        external
        returns (uint256 amountCalculated);

    function exitPool(bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request)
        external;

    struct ExitPoolRequest {
        IAsset[] assets;
        uint256[] minAmountsOut;
        bytes userData;
        bool toInternalBalance;
    }
}
ISwapRouter02.sol 42 lines
//SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

// https://github.com/Uniswap/swap-router-contracts/blob/main/contracts/interfaces/ISwapRouter02.sol

interface ISwapRouter02 {
    function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to)
        external
        payable
        returns (uint256 amountOut);

    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @dev Setting `amountIn` to 0 will cause the contract to look up its own balance,
    /// and swap the entire amount, enabling contracts to send tokens before calling this function.
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @dev Setting `amountIn` to 0 will cause the contract to look up its own balance,
    /// and swap the entire amount, enabling contracts to send tokens before calling this function.
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
}
ISushiRouter.sol 23 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

// https://etherscan.io/address/0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f
// it's actually a UniswapV2Router02 but renamed for clarity vs actual uniswap

interface ISushiRouter {
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}
SafeTransferLib.sol 128 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import {ERC20} from "../tokens/ERC20.sol";

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
    /*//////////////////////////////////////////////////////////////
                             ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(success, "ETH_TRANSFER_FAILED");
    }

    /*//////////////////////////////////////////////////////////////
                            ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        ERC20 token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
            mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        require(success, "TRANSFER_FROM_FAILED");
    }

    function safeTransfer(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "TRANSFER_FAILED");
    }

    function safeApprove(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "APPROVE_FAILED");
    }
}

Read Contract

getRoute 0xa375bb86 → tuple
nominatedOwner 0x53a47bb7 → address
owner 0x8da5cb5b → address
routes 0x5055374d → uint8, bytes

Write Contract 5 functions

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

acceptOwnership 0x79ba5097
No parameters
nominateOwnership 0xd9380519
address _newOwner
setRoute 0x2ba4ae8a
address _tokenIn
address _tokenOut
tuple _routeInfo
swapTokens 0x8e18cdfc
address _tokenIn
address _tokenOut
uint256 _amount
uint256 _minReceived
returns: uint256
unsetRoute 0x686da263
address _tokenIn
address _tokenOut

Recent Transactions

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