Optimized SafeTransferLib (Solady)

This commit is contained in:
PedroCailleret committed 2023-05-14 21:26:08 -03:00
1 parent 9d14f053d5
commit 8ebef3aaf1
12 files changed
+262 -73

No files matched your search

@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/e4fd58ee172659ae7bbfbfbb00ad761b.json"
"buildInfo": "../../../../build-info/cf6d26ad613ca851d9115e4f052bd17c.json"
}
@@ -2,7 +2,23 @@
"_format": "hh-sol-artifact-1",
"contractName": "SafeTransferLib",
"sourceName": "contracts/lib/utils/SafeTransferLib.sol",
"abi": [],
"abi": [
{
"inputs": [],
"name": "ETHTransferFailed",
"type": "error"
},
{
"inputs": [],
"name": "TransferFailed",
"type": "error"
},
{
"inputs": [],
"name": "TransferFromFailed",
"type": "error"
}
],
"bytecode": "0x602d6037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea164736f6c6343000809000a",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea164736f6c6343000809000a",
"linkReferences": {},
+1 -1
View File
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/577d08e3f9a8a685ac15a7ca46572ea5.json"
"buildInfo": "../../build-info/cf6d26ad613ca851d9115e4f052bd17c.json"
}
+2 -2
View File
@@ -1069,8 +1069,8 @@
"type": "receive"
}
],
"bytecode": "0x6080604052600180556040516200331c3803806200331c8339810160408190526200002a916200045c565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b6200009882826200026f565b5050505050620005c9565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806003557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60208101815160051b81015b3d6200023c5760018251600c1b5560208201915080821062000236576200023c565b62000214565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516200012891906200057a565b6000546001600160a01b03163314620002ba5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620002d05763df9578836000526004601cfd5b81518114620002e75763ff633a386000526004601cfd5b60208301602083018260051b82015b8083146200034e5763cbc9d1c4600c52825160005281516020600c2055815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a3602083019250602082019150620002f6565b505050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000397576200039762000356565b604052919050565b60006001600160401b03821115620003bb57620003bb62000356565b5060051b60200190565b6001600160a01b0381168114620003db57600080fd5b50565b600082601f830112620003f057600080fd5b815160206200040962000403836200039f565b6200036c565b82815260059290921b840181019181810190868411156200042957600080fd5b8286015b84811015620004515780516200044381620003c5565b83529183019183016200042d565b509695505050505050565b600080600080600060a086880312156200047557600080fd5b8551602080880151919650906001600160401b03808211156200049757600080fd5b620004a58a838b01620003de565b965060408901519150620004b982620003c5565b606089015191955080821115620004cf57600080fd5b620004dd8a838b01620003de565b94506080890151915080821115620004f457600080fd5b508701601f810189136200050757600080fd5b80516200051862000403826200039f565b81815260059190911b8201830190838101908b8311156200053857600080fd5b928401925b82841015620005685783518015158114620005585760008081fd5b825292840192908401906200053d565b80955050505050509295509295909350565b6020808252825182820181905260009190848201906040850190845b81811015620005bd5783516001600160a01b03168352928401929184019160010162000596565b50909695505050505050565b612d4380620005d96000396000f3fe6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e366004612411565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612562565b610740565b005b34801561026157600080fd5b5061025361027036600461259f565b610832565b34801561028157600080fd5b506102536102903660046125d8565b610923565b3480156102a157600080fd5b506103196102b0366004612411565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b610397366004612411565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461264b565b610b32565b60405161022a929190612746565b3480156103e55760Line truncated
"deployedBytecode": "0x6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e366004612411565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612562565b610740565b005b34801561026157600080fd5b5061025361027036600461259f565b610832565b34801561028157600080fd5b506102536102903660046125d8565b610923565b3480156102a157600080fd5b506103196102b0366004612411565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b610397366004612411565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461264b565b610b32565b60405161022a929190612746565b3480156103e557600080fd5b506102206103f436600461259f565b600c1b90565b34801561040657600080fd5b50610253610415366004612411565b610e15565b34801561042657600080fd5b50610253610ecb565b34801561043b57600080fd5b5061039b61044a36600461259f565b63cbc9d1c4600c908152600091909152602090205490565b34801561046e57600080fd5b50610220670de0b6b3a764000081565b34801561048a57600080fd5b506102536104993660046127d5565b610f8d565b3480156104aa57600080fd5b506102206104b9366004612411565b6374dfee70600c9081521c6000908152602090205490565b3480156104dd57600080fd5b506102536104ec36600461280a565b61109d565b3480156104fd57600080fd5b5061039b61050c366004612836565b6110f0565b34801561051d57600080fd5b5061053261052c366004612411565b600c1c90565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161022a565b34801561056357600080fd5b506102206105723660046128bb565b611127565b34801561058357600080fd5b506000546105329073ffffffffffffffffffffffffffffffffffffffff1681565b3480156105b057600080fd5b5061022060045481565b3480156105c657600080fd5b5061022060035481565b3480156105dc57600080fd5b506102206105eb366004612978565b60205263739094b1600c90815290811c600052603490205490565b34801561061257600080fd5b50610532610621366004612836565b611417565b34801561063257600080fd5b5061025361064136600461299d565b61143d565b34801561065257600080fd5b506002546105329073ffffffffffffffffffffffffffffffffffffffff1681565b34801561067f57600080fd5b5061025361068e3660046129d3565b611673565b34801561069f57600080fd5b506106b36106ae366004612a26565b611ae4565b60405161022a9190612a6d565b3480156106cc57600080fd5b506102206106db366004612836565b611b96565b3480156106ec57600080fd5b506102536106fb366004612a80565b611bc7565b34801561070c57600080fd5b5061025361071b36600461259f565b611ce0565b34801561072c57600080fd5b5061025361073b366004612b42565b611dac565b60005473ffffffffffffffffffffffffffffffffffffffff1633146107c6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a4544000000000000000000000000000000000000000060448201526064015b60405180910390fd5b60208101815160051b81015b3d6107f65760018251600c1b556020820191508082106107f1576107f6565b6107d2565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516108279190612b9e565b60405180910390a150565b60005473ffffffffffffffffffffffffffffffffffffffff1633146108b3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a4544000000000000000000000000000000000000000060448201526064016107bd565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d769190a350565b8433600c1b73ffffffffffffffffffffffffffffffffffffffff8516610975576040517f6a3bc53e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63cbc9d1c4600c908152600083905260209020546109bf576040517f1578328e000000000000000000000000000000000000000000000000000000008152600401Line truncated
"bytecode": "0x608060405260018055604051620031ec380380620031ec8339810160408190526200002a916200045c565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b6200009882826200026f565b5050505050620005c9565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806003557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60208101815160051b81015b3d6200023c5760018251600c1b5560208201915080821062000236576200023c565b62000214565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516200012891906200057a565b6000546001600160a01b03163314620002ba5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620002d05763df9578836000526004601cfd5b81518114620002e75763ff633a386000526004601cfd5b60208301602083018260051b82015b8083146200034e5763cbc9d1c4600c52825160005281516020600c2055815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a3602083019250602082019150620002f6565b505050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000397576200039762000356565b604052919050565b60006001600160401b03821115620003bb57620003bb62000356565b5060051b60200190565b6001600160a01b0381168114620003db57600080fd5b50565b600082601f830112620003f057600080fd5b815160206200040962000403836200039f565b6200036c565b82815260059290921b840181019181810190868411156200042957600080fd5b8286015b84811015620004515780516200044381620003c5565b83529183019183016200042d565b509695505050505050565b600080600080600060a086880312156200047557600080fd5b8551602080880151919650906001600160401b03808211156200049757600080fd5b620004a58a838b01620003de565b965060408901519150620004b982620003c5565b606089015191955080821115620004cf57600080fd5b620004dd8a838b01620003de565b94506080890151915080821115620004f457600080fd5b508701601f810189136200050757600080fd5b80516200051862000403826200039f565b81815260059190911b8201830190838101908b8311156200053857600080fd5b928401925b82841015620005685783518015158114620005585760008081fd5b825292840192908401906200053d565b80955050505050509295509295909350565b6020808252825182820181905260009190848201906040850190845b81811015620005bd5783516001600160a01b03168352928401929184019160010162000596565b50909695505050505050565b612c1380620005d96000396000f3fe6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e3660046122e1565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612432565b610740565b005b34801561026157600080fd5b5061025361027036600461246f565b610832565b34801561028157600080fd5b506102536102903660046124a8565b610923565b3480156102a157600080fd5b506103196102b03660046122e1565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b6103973660046122e1565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461251b565b610b32565b60405161022a929190612616565b3480156103e55760Line truncated
"deployedBytecode": "0x6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e3660046122e1565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612432565b610740565b005b34801561026157600080fd5b5061025361027036600461246f565b610832565b34801561028157600080fd5b506102536102903660046124a8565b610923565b3480156102a157600080fd5b506103196102b03660046122e1565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b6103973660046122e1565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461251b565b610b32565b60405161022a929190612616565b3480156103e557600080fd5b506102206103f436600461246f565b600c1b90565b34801561040657600080fd5b506102536104153660046122e1565b610e15565b34801561042657600080fd5b50610253610ecb565b34801561043b57600080fd5b5061039b61044a36600461246f565b63cbc9d1c4600c908152600091909152602090205490565b34801561046e57600080fd5b50610220670de0b6b3a764000081565b34801561048a57600080fd5b506102536104993660046126a5565b610f8d565b3480156104aa57600080fd5b506102206104b93660046122e1565b6374dfee70600c9081521c6000908152602090205490565b3480156104dd57600080fd5b506102536104ec3660046126da565b61109d565b3480156104fd57600080fd5b5061039b61050c366004612706565b6110f0565b34801561051d57600080fd5b5061053261052c3660046122e1565b600c1c90565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161022a565b34801561056357600080fd5b5061022061057236600461278b565b611127565b34801561058357600080fd5b506000546105329073ffffffffffffffffffffffffffffffffffffffff1681565b3480156105b057600080fd5b5061022060045481565b3480156105c657600080fd5b5061022060035481565b3480156105dc57600080fd5b506102206105eb366004612848565b60205263739094b1600c90815290811c600052603490205490565b34801561061257600080fd5b50610532610621366004612706565b611417565b34801561063257600080fd5b5061025361064136600461286d565b61143d565b34801561065257600080fd5b506002546105329073ffffffffffffffffffffffffffffffffffffffff1681565b34801561067f57600080fd5b5061025361068e3660046128a3565b611673565b34801561069f57600080fd5b506106b36106ae3660046128f6565b611ae4565b60405161022a919061293d565b3480156106cc57600080fd5b506102206106db366004612706565b611b96565b3480156106ec57600080fd5b506102536106fb366004612950565b611bc7565b34801561070c57600080fd5b5061025361071b36600461246f565b611ce0565b34801561072c57600080fd5b5061025361073b366004612a12565b611dac565b60005473ffffffffffffffffffffffffffffffffffffffff1633146107c6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a4544000000000000000000000000000000000000000060448201526064015b60405180910390fd5b60208101815160051b81015b3d6107f65760018251600c1b556020820191508082106107f1576107f6565b6107d2565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516108279190612a6e565b60405180910390a150565b60005473ffffffffffffffffffffffffffffffffffffffff1633146108b3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a4544000000000000000000000000000000000000000060448201526064016107bd565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d769190a350565b8433600c1b73ffffffffffffffffffffffffffffffffffffffff8516610975576040517f6a3bc53e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63cbc9d1c4600c908152600083905260209020546109bf576040517f1578328e000000000000000000000000000000000000000000000000000000008152600401Line truncated
"linkReferences": {},
"deployedLinkReferences": {}
}
+93 -67
View File
@@ -4,114 +4,140 @@ pragma solidity >=0.8.4;
import { ERC20 } from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Caution! This library won't check that a token has code, responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The ERC20 `transferFrom` has failed.
error TransferFromFailed();
/// @dev The ERC20 `transfer` has failed.
error TransferFailed();
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
/// @dev Sends `amount` (in wei) ETH to `to`.
/// Reverts upon failure.
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)
// Transfer the ETH and check if it succeeded or not.
if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
// Store the function selector of `ETHTransferFailed()`.
mstore(0x00, 0xb12d13eb)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for
/// the current contract to manage.
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// We'll write our calldata to this slot below, but restore it later.
let memPointer := mload(0x40)
let m := mload(0x40) // Cache the free memory pointer.
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(
0,
0x23b872dd00000000000000000000000000000000000000000000000000000000
)
mstore(4, from) // Append the "from" argument.
mstore(36, to) // Append the "to" argument.
mstore(68, amount) // Append the "amount" argument.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
// Store the function selector of `transferFrom(address,address,uint256)`.
mstore(0x0c, 0x23b872dd000000000000000000000000)
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)
if iszero(
and(
// The arguments of `and` are evaluated from right to left.
// 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(
eq(mload(0x00), 1),
iszero(returndatasize())
),
iszero(returndatasize())
),
// We use 100 because that's the total length of our calldata (4 + 32 * 3)
// Counterintuitively, this call() must be positioned after the or() in the
// surrounding and() because and() evaluates its arguments from right to left.
call(gas(), token, 0, 0, 100, 0, 32)
)
call(
gas(),
token,
0,
0x1c,
0x64,
0x00,
0x20
)
)
) {
// Store the function selector of `TransferFromFailed()`.
mstore(0x00, 0x7939f424)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, memPointer) // Restore the memPointer.
mstore(0x40, m) // Restore the free memory pointer.
}
require(success, "TRANSFER_FROM_FAILED");
}
/// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// We'll write our calldata to this slot below, but restore it later.
let memPointer := mload(0x40)
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
// Store the function selector of `transfer(address,uint256)`.
mstore(0x00, 0xa9059cbb000000000000000000000000)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(
0,
0xa9059cbb00000000000000000000000000000000000000000000000000000000
)
mstore(4, to) // Append the "to" argument.
mstore(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)
if iszero(
and(
// The arguments of `and` are evaluated from right to left.
// 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(
eq(mload(0x00), 1),
iszero(returndatasize())
),
iszero(returndatasize())
),
// We use 68 because that's the total length of our calldata (4 + 32 * 2)
// Counterintuitively, this call() must be positioned after the or() in the
// surrounding and() because and() evaluates its arguments from right to left.
call(gas(), token, 0, 0, 68, 0, 32)
)
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, memPointer) // Restore the memPointer.
call(
gas(),
token,
0,
0x10,
0x44,
0x00,
0x20
)
)
) {
// Store the function selector of `TransferFailed()`.
mstore(0x00, 0x90b8ec18)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
// Restore the part of the free memory pointer that was overwritten.
mstore(0x34, 0)
}
require(success, "TRANSFER_FAILED");
}
}
@@ -0,0 +1,78 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
import type { Provider, TransactionRequest } from "@ethersproject/providers";
import type { PromiseOrValue } from "../../../common";
import type {
SafeTransferLib,
SafeTransferLibInterface,
} from "../../../lib/utils/SafeTransferLib";
const _abi = [
{
inputs: [],
name: "ETHTransferFailed",
type: "error",
},
{
inputs: [],
name: "TransferFailed",
type: "error",
},
{
inputs: [],
name: "TransferFromFailed",
type: "error",
},
];
const _bytecode =
"0x602d6037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea164736f6c6343000809000a";
type SafeTransferLibConstructorParams =
| [signer?: Signer]
| ConstructorParameters<typeof ContractFactory>;
const isSuperArgs = (
xs: SafeTransferLibConstructorParams
): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;
export class SafeTransferLib__factory extends ContractFactory {
constructor(...args: SafeTransferLibConstructorParams) {
if (isSuperArgs(args)) {
super(...args);
} else {
super(_abi, _bytecode, args[0]);
}
}
override deploy(
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<SafeTransferLib> {
return super.deploy(overrides || {}) as Promise<SafeTransferLib>;
}
override getDeployTransaction(
overrides?: Overrides & { from?: PromiseOrValue<string> }
): TransactionRequest {
return super.getDeployTransaction(overrides || {});
}
override attach(address: string): SafeTransferLib {
return super.attach(address) as SafeTransferLib;
}
override connect(signer: Signer): SafeTransferLib__factory {
return super.connect(signer) as SafeTransferLib__factory;
}
static readonly bytecode = _bytecode;
static readonly abi = _abi;
static createInterface(): SafeTransferLibInterface {
return new utils.Interface(_abi) as SafeTransferLibInterface;
}
static connect(
address: string,
signerOrProvider: Signer | Provider
): SafeTransferLib {
return new Contract(address, _abi, signerOrProvider) as SafeTransferLib;
}
}
+1
View File
@@ -3,3 +3,4 @@
/* eslint-disable */
export { Multicall__factory } from "./Multicall__factory";
export { ReentrancyGuard__factory } from "./ReentrancyGuard__factory";
export { SafeTransferLib__factory } from "./SafeTransferLib__factory";
@@ -1082,7 +1082,7 @@ const _abi = [
];
const _bytecode =
"0x6080604052600180556040516200331c3803806200331c8339810160408190526200002a916200045c565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b6200009882826200026f565b5050505050620005c9565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806003557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60208101815160051b81015b3d6200023c5760018251600c1b5560208201915080821062000236576200023c565b62000214565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516200012891906200057a565b6000546001600160a01b03163314620002ba5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620002d05763df9578836000526004601cfd5b81518114620002e75763ff633a386000526004601cfd5b60208301602083018260051b82015b8083146200034e5763cbc9d1c4600c52825160005281516020600c2055815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a3602083019250602082019150620002f6565b505050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000397576200039762000356565b604052919050565b60006001600160401b03821115620003bb57620003bb62000356565b5060051b60200190565b6001600160a01b0381168114620003db57600080fd5b50565b600082601f830112620003f057600080fd5b815160206200040962000403836200039f565b6200036c565b82815260059290921b840181019181810190868411156200042957600080fd5b8286015b84811015620004515780516200044381620003c5565b83529183019183016200042d565b509695505050505050565b600080600080600060a086880312156200047557600080fd5b8551602080880151919650906001600160401b03808211156200049757600080fd5b620004a58a838b01620003de565b965060408901519150620004b982620003c5565b606089015191955080821115620004cf57600080fd5b620004dd8a838b01620003de565b94506080890151915080821115620004f457600080fd5b508701601f810189136200050757600080fd5b80516200051862000403826200039f565b81815260059190911b8201830190838101908b8311156200053857600080fd5b928401925b82841015620005685783518015158114620005585760008081fd5b825292840192908401906200053d565b80955050505050509295509295909350565b6020808252825182820181905260009190848201906040850190845b81811015620005bd5783516001600160a01b03168352928401929184019160010162000596565b50909695505050505050565b612d4380620005d96000396000f3fe6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e366004612411565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612562565b610740565b005b34801561026157600080fd5b5061025361027036600461259f565b610832565b34801561028157600080fd5b506102536102903660046125d8565b610923565b3480156102a157600080fd5b506103196102b0366004612411565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b610397366004612411565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461264b565b610b32565b60405161022a929190612746565b3480156103e557600080fd5b5061Line truncated
"0x608060405260018055604051620031ec380380620031ec8339810160408190526200002a916200045c565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b6200009882826200026f565b5050505050620005c9565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806003557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60208101815160051b81015b3d6200023c5760018251600c1b5560208201915080821062000236576200023c565b62000214565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7816040516200012891906200057a565b6000546001600160a01b03163314620002ba5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620002d05763df9578836000526004601cfd5b81518114620002e75763ff633a386000526004601cfd5b60208301602083018260051b82015b8083146200034e5763cbc9d1c4600c52825160005281516020600c2055815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a3602083019250602082019150620002f6565b505050505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000397576200039762000356565b604052919050565b60006001600160401b03821115620003bb57620003bb62000356565b5060051b60200190565b6001600160a01b0381168114620003db57600080fd5b50565b600082601f830112620003f057600080fd5b815160206200040962000403836200039f565b6200036c565b82815260059290921b840181019181810190868411156200042957600080fd5b8286015b84811015620004515780516200044381620003c5565b83529183019183016200042d565b509695505050505050565b600080600080600060a086880312156200047557600080fd5b8551602080880151919650906001600160401b03808211156200049757600080fd5b620004a58a838b01620003de565b965060408901519150620004b982620003c5565b606089015191955080821115620004cf57600080fd5b620004dd8a838b01620003de565b94506080890151915080821115620004f457600080fd5b508701601f810189136200050757600080fd5b80516200051862000403826200039f565b81815260059190911b8201830190838101908b8311156200053857600080fd5b928401925b82841015620005685783518015158114620005585760008081fd5b825292840192908401906200053d565b80955050505050509295509295909350565b6020808252825182820181905260009190848201906040850190845b81811015620005bd5783516001600160a01b03168352928401929184019160010162000596565b50909695505050505050565b612c1380620005d96000396000f3fe6080604052600436106101e75760003560e01c806384ab1d2811610102578063b0983d3911610095578063d4fac45d11610064578063d4fac45d146106c0578063d6e8b973146106e0578063f7d0e04b14610700578063fb8c5ef01461072057600080fd5b8063b0983d3914610626578063c52164c614610646578063c593dfd814610673578063d1c070281461069357600080fd5b80639872dbfe116100d15780639872dbfe146105ba57806398a268711461037c5780639eee8d4b146105d0578063ad8f2eed1461060657600080fd5b806384ab1d28146105115780638a006225146105575780638da5cb5b146105775780638db564c2146105a457600080fd5b8063574983c81161017a5780636d82d9e0116101495780636d82d9e01461047e57806377cd38a41461049e5780637f94f65d146104d157806380e1d302146104f157600080fd5b8063574983c8146103fa5780635fd8c7101461041a57806369cc6af41461042f5780636a1460241461046257600080fd5b8063367821f0116101b6578063367821f014610295578063461f31201461037c57806349ef8448146103ab5780634b2ae980146103d957600080fd5b806304937320146101f35780630d2a2d441461023357806313af403514610255578063328a71811461027557600080fd5b366101ee57005b600080fd5b3480156101ff57600080fd5b5061022061020e3660046122e1565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561023f57600080fd5b5061025361024e366004612432565b610740565b005b34801561026157600080fd5b5061025361027036600461246f565b610832565b34801561028157600080fd5b506102536102903660046124a8565b610923565b3480156102a157600080fd5b506103196102b03660046122e1565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006860154600787015460089097015495979496939592949373ffffffffffffffffffffffffffffffffffffffff9283169391831692908116911689565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915273ffffffffffffffffffffffffffffffffffffffff90811660a086015290811660c085015290811660e0840152166101008201526101200161022a565b34801561038857600080fd5b5061039b6103973660046122e1565b5490565b604051901515815260200161022a565b3480156103b757600080fd5b506103cb6103c636600461251b565b610b32565b60405161022a929190612616565b3480156103e557600080fd5b5061Line truncated
type P2PIXConstructorParams =
| [signer?: Signer]
+9
View File
@@ -40,6 +40,10 @@ declare module "hardhat/types/runtime" {
name: "ReentrancyGuard",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.ReentrancyGuard__factory>;
getContractFactory(
name: "SafeTransferLib",
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<Contracts.SafeTransferLib__factory>;
getContractFactory(
name: "P2PIX",
signerOrOptions?: ethers.Signer | FactoryOptions
@@ -84,6 +88,11 @@ declare module "hardhat/types/runtime" {
address: string,
signer?: ethers.Signer
): Promise<Contracts.ReentrancyGuard>;
getContractAt(
name: "SafeTransferLib",
address: string,
signer?: ethers.Signer
): Promise<Contracts.SafeTransferLib>;
getContractAt(
name: "P2PIX",
address: string,
+2
View File
@@ -21,6 +21,8 @@ export type { Multicall } from "./lib/utils/Multicall";
export { Multicall__factory } from "./factories/lib/utils/Multicall__factory";
export type { ReentrancyGuard } from "./lib/utils/ReentrancyGuard";
export { ReentrancyGuard__factory } from "./factories/lib/utils/ReentrancyGuard__factory";
export type { SafeTransferLib } from "./lib/utils/SafeTransferLib";
export { SafeTransferLib__factory } from "./factories/lib/utils/SafeTransferLib__factory";
export type { P2PIX } from "./p2pix.sol/P2PIX";
export { P2PIX__factory } from "./factories/p2pix.sol/P2PIX__factory";
export { Reputation__factory } from "./factories/Reputation__factory";
+56
View File
@@ -0,0 +1,56 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type { BaseContract, Signer, utils } from "ethers";
import type { Listener, Provider } from "@ethersproject/providers";
import type {
TypedEventFilter,
TypedEvent,
TypedListener,
OnEvent,
PromiseOrValue,
} from "../../common";
export interface SafeTransferLibInterface extends utils.Interface {
functions: {};
events: {};
}
export interface SafeTransferLib extends BaseContract {
connect(signerOrProvider: Signer | Provider | string): this;
attach(addressOrName: string): this;
deployed(): Promise<this>;
interface: SafeTransferLibInterface;
queryFilter<TEvent extends TypedEvent>(
event: TypedEventFilter<TEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TEvent>>;
listeners<TEvent extends TypedEvent>(
eventFilter?: TypedEventFilter<TEvent>
): Array<TypedListener<TEvent>>;
listeners(eventName?: string): Array<Listener>;
removeAllListeners<TEvent extends TypedEvent>(
eventFilter: TypedEventFilter<TEvent>
): this;
removeAllListeners(eventName?: string): this;
off: OnEvent<this>;
on: OnEvent<this>;
once: OnEvent<this>;
removeListener: OnEvent<this>;
functions: {};
callStatic: {};
filters: {};
estimateGas: {};
populateTransaction: {};
}
+1
View File
@@ -3,3 +3,4 @@
/* eslint-disable */
export type { Multicall } from "./Multicall";
export type { ReentrancyGuard } from "./ReentrancyGuard";
export type { SafeTransferLib } from "./SafeTransferLib";