From e0f11c31d935dd51fb360af12495d52f9be0c946 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:33:46 +0000 Subject: [PATCH] feat: remove admin lock, fix price changer --- contracts/utils/src/LiquidExchange.sol | 8 +---- src/bindings/liquidexchange.rs | 41 ++++++++++++++++++-------- src/deployer.rs | 1 + src/lib.rs | 41 ++++++++++++++++---------- src/price_changer.rs | 32 ++++++++++++++++++-- src/types/process.rs | 14 +++++---- 6 files changed, 93 insertions(+), 44 deletions(-) diff --git a/contracts/utils/src/LiquidExchange.sol b/contracts/utils/src/LiquidExchange.sol index 22de40c..639d84f 100644 --- a/contracts/utils/src/LiquidExchange.sol +++ b/contracts/utils/src/LiquidExchange.sol @@ -32,17 +32,11 @@ contract LiquidExchange { price = price_; } - // Our admin lock - modifier onlyAdmin() { - require(msg.sender == admin, "Only admin can call this function"); - _; - } - event PriceChange(uint256 price); event Swap(address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, address to); // Admin only function to set the price of x in terms of y - function setPrice(uint256 _price) public onlyAdmin { + function setPrice(uint256 _price) public { price = _price; emit PriceChange(price); } diff --git a/src/bindings/liquidexchange.rs b/src/bindings/liquidexchange.rs index ec93e91..cd083a3 100644 --- a/src/bindings/liquidexchange.rs +++ b/src/bindings/liquidexchange.rs @@ -182,23 +182,24 @@ interface LiquidExchange { pub mod LiquidExchange { use alloy::sol_types as alloy_sol_types; + use super::*; /// The creation / init bytecode of the contract. /// /// ```text - ///0x6080604052348015600f57600080fd5b506040516105d13803806105d1833981016040819052602c916089565b600080546001600160a01b03199081163317909155600180546001600160a01b03958616908316179055600280549390941692169190911790915560035560c0565b80516001600160a01b0381168114608457600080fd5b919050565b600080600060608486031215609d57600080fd5b60a484606e565b925060b060208501606e565b9150604084015190509250925092565b610502806100cf6000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80633b2049481461006757806391b7f5ed14610097578063a035b1fe146100ac578063d004f0f7146100c3578063d0c472ec146100d6578063f851a440146100e9575b600080fd5b60015461007a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6100aa6100a5366004610459565b6100fc565b005b6100b560035481565b60405190815260200161008e565b6100aa6100d1366004610472565b6101a0565b60025461007a906001600160a01b031681565b60005461007a906001600160a01b031681565b6000546001600160a01b031633146101655760405162461bcd60e51b815260206004820152602160248201527f4f6e6c792061646d696e2063616e2063616c6c20746869732066756e6374696f6044820152603760f91b60648201526084015b60405180910390fd5b60038190556040518181527ff347ee99503bf19c028bd6b18f3c676e82a9bb5b2bb5225aebe0fd62fd6a0d199060200160405180910390a150565b60015460009081906001600160a01b03908116908516036101e057506002546003546001600160a01b03909116906101d990849061040e565b915061024c565b6002546001600160a01b039081169085160361021457506001546003546001600160a01b03909116906101d990849061042a565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b604482015260640161015c565b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038516906323b872dd906064016020604051808303816000875af115801561029f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c391906104aa565b6103015760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b604482015260640161015c565b60405163a9059cbb60e01b8152336004820152602481018390526001600160a01b0382169063a9059cbb906044016020604051808303816000875af115801561034e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061037291906104aa565b6103b05760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b604482015260640161015c565b604080516001600160a01b03808716825283166020820152908101849052606081018390523360808201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d09060a00160405180910390a150505050565b60006104238383670de0b6b3a764000061043b565b9392505050565b600061042383670de0b6b3a7640000845b600082600019048411830215820261045257600080fd5b5091020490565b60006020828403121561046b57600080fd5b5035919050565b6000806040838503121561048557600080fd5b82356001600160a01b038116811461049c57600080fd5b946020939093013593505050565b6000602082840312156104bc57600080fd5b8151801515811461042357600080fdfea2646970667358221220026041555962859b339c7c22e07468ebf4c8b3b54d1c2f1d36aaea41f6bc4c5c64736f6c634300081a0033 + ///0x6080604052348015600f57600080fd5b5060405161056d38038061056d833981016040819052602c916089565b600080546001600160a01b03199081163317909155600180546001600160a01b03958616908316179055600280549390941692169190911790915560035560c0565b80516001600160a01b0381168114608457600080fd5b919050565b600080600060608486031215609d57600080fd5b60a484606e565b925060b060208501606e565b9150604084015190509250925092565b61049e806100cf6000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80633b2049481461006757806391b7f5ed14610097578063a035b1fe146100ac578063d004f0f7146100c3578063d0c472ec146100d6578063f851a440146100e9575b600080fd5b60015461007a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6100aa6100a53660046103f5565b6100fc565b005b6100b560035481565b60405190815260200161008e565b6100aa6100d136600461040e565b610137565b60025461007a906001600160a01b031681565b60005461007a906001600160a01b031681565b60038190556040518181527ff347ee99503bf19c028bd6b18f3c676e82a9bb5b2bb5225aebe0fd62fd6a0d199060200160405180910390a150565b60015460009081906001600160a01b039081169085160361017757506002546003546001600160a01b03909116906101709084906103aa565b91506101e8565b6002546001600160a01b03908116908516036101ab57506001546003546001600160a01b03909116906101709084906103c6565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b60448201526064015b60405180910390fd5b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038516906323b872dd906064016020604051808303816000875af115801561023b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061025f9190610446565b61029d5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064016101df565b60405163a9059cbb60e01b8152336004820152602481018390526001600160a01b0382169063a9059cbb906044016020604051808303816000875af11580156102ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030e9190610446565b61034c5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064016101df565b604080516001600160a01b03808716825283166020820152908101849052606081018390523360808201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d09060a00160405180910390a150505050565b60006103bf8383670de0b6b3a76400006103d7565b9392505050565b60006103bf83670de0b6b3a7640000845b60008260001904841183021582026103ee57600080fd5b5091020490565b60006020828403121561040757600080fd5b5035919050565b6000806040838503121561042157600080fd5b82356001600160a01b038116811461043857600080fd5b946020939093013593505050565b60006020828403121561045857600080fd5b815180151581146103bf57600080fdfea264697066735822122059a5d06c4c798ce91aeb9bb91f9587c0a353fc7f0007b7e83cb0b3784431e3d164736f6c634300081a0033 /// ``` #[rustfmt::skip] pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static( - b"`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`@Qa\x05\xD18\x03\x80a\x05\xD1\x839\x81\x01`@\x81\x90R`,\x91`\x89V[`\0\x80T`\x01`\x01`\xA0\x1B\x03\x19\x90\x81\x163\x17\x90\x91U`\x01\x80T`\x01`\x01`\xA0\x1B\x03\x95\x86\x16\x90\x83\x16\x17\x90U`\x02\x80T\x93\x90\x94\x16\x92\x16\x91\x90\x91\x17\x90\x91U`\x03U`\xC0V[\x80Q`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14`\x84W`\0\x80\xFD[\x91\x90PV[`\0\x80`\0``\x84\x86\x03\x12\x15`\x9DW`\0\x80\xFD[`\xA4\x84`nV[\x92P`\xB0` \x85\x01`nV[\x91P`@\x84\x01Q\x90P\x92P\x92P\x92V[a\x05\x02\x80a\0\xCF`\09`\0\xF3\xFE`\x80`@R4\x80\x15a\0\x10W`\0\x80\xFD[P`\x046\x10a\0bW`\x005`\xE0\x1C\x80c; IH\x14a\0gW\x80c\x91\xB7\xF5\xED\x14a\0\x97W\x80c\xA05\xB1\xFE\x14a\0\xACW\x80c\xD0\x04\xF0\xF7\x14a\0\xC3W\x80c\xD0\xC4r\xEC\x14a\0\xD6W\x80c\xF8Q\xA4@\x14a\0\xE9W[`\0\x80\xFD[`\x01Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`@Q`\x01`\x01`\xA0\x1B\x03\x90\x91\x16\x81R` \x01[`@Q\x80\x91\x03\x90\xF3[a\0\xAAa\0\xA56`\x04a\x04YV[a\0\xFCV[\0[a\0\xB5`\x03T\x81V[`@Q\x90\x81R` \x01a\0\x8EV[a\0\xAAa\0\xD16`\x04a\x04rV[a\x01\xA0V[`\x02Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0T`\x01`\x01`\xA0\x1B\x03\x163\x14a\x01eW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`!`$\x82\x01R\x7FOnly admin can call this functio`D\x82\x01R`7`\xF9\x1B`d\x82\x01R`\x84\x01[`@Q\x80\x91\x03\x90\xFD[`\x03\x81\x90U`@Q\x81\x81R\x7F\xF3G\xEE\x99P;\xF1\x9C\x02\x8B\xD6\xB1\x8F=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x02\xC3\x91\x90a\x04\xAAV[a\x03\x01W`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\\V[`@Qc\xA9\x05\x9C\xBB`\xE0\x1B\x81R3`\x04\x82\x01R`$\x81\x01\x83\x90R`\x01`\x01`\xA0\x1B\x03\x82\x16\x90c\xA9\x05\x9C\xBB\x90`D\x01` `@Q\x80\x83\x03\x81`\0\x87Z\xF1\x15\x80\x15a\x03NW=`\0\x80>=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x03r\x91\x90a\x04\xAAV[a\x03\xB0W`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\\V[`@\x80Q`\x01`\x01`\xA0\x1B\x03\x80\x87\x16\x82R\x83\x16` \x82\x01R\x90\x81\x01\x84\x90R``\x81\x01\x83\x90R3`\x80\x82\x01R\x7F\xB3\x9C\x9B\xC4?\x81\x1E\x1A|\xE1Y\xC5\xF1GE\x8F\xDB\x80&k\xF2<\x172 \x131n'\xE0\x86\xD0\x90`\xA0\x01`@Q\x80\x91\x03\x90\xA1PPPPV[`\0a\x04#\x83\x83g\r\xE0\xB6\xB3\xA7d\0\0a\x04;V[\x93\x92PPPV[`\0a\x04#\x83g\r\xE0\xB6\xB3\xA7d\0\0\x84[`\0\x82`\0\x19\x04\x84\x11\x83\x02\x15\x82\x02a\x04RW`\0\x80\xFD[P\x91\x02\x04\x90V[`\0` \x82\x84\x03\x12\x15a\x04kW`\0\x80\xFD[P5\x91\x90PV[`\0\x80`@\x83\x85\x03\x12\x15a\x04\x85W`\0\x80\xFD[\x825`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14a\x04\x9CW`\0\x80\xFD[\x94` \x93\x90\x93\x015\x93PPPV[`\0` \x82\x84\x03\x12\x15a\x04\xBCW`\0\x80\xFD[\x81Q\x80\x15\x15\x81\x14a\x04#W`\0\x80\xFD\xFE\xA2dipfsX\"\x12 \x02`AUYb\x85\x9B3\x9C|\"\xE0th\xEB\xF4\xC8\xB3\xB5M\x1C/\x1D6\xAA\xEAA\xF6\xBCL\\dsolcC\0\x08\x1A\x003", + b"`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`@Qa\x05m8\x03\x80a\x05m\x839\x81\x01`@\x81\x90R`,\x91`\x89V[`\0\x80T`\x01`\x01`\xA0\x1B\x03\x19\x90\x81\x163\x17\x90\x91U`\x01\x80T`\x01`\x01`\xA0\x1B\x03\x95\x86\x16\x90\x83\x16\x17\x90U`\x02\x80T\x93\x90\x94\x16\x92\x16\x91\x90\x91\x17\x90\x91U`\x03U`\xC0V[\x80Q`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14`\x84W`\0\x80\xFD[\x91\x90PV[`\0\x80`\0``\x84\x86\x03\x12\x15`\x9DW`\0\x80\xFD[`\xA4\x84`nV[\x92P`\xB0` \x85\x01`nV[\x91P`@\x84\x01Q\x90P\x92P\x92P\x92V[a\x04\x9E\x80a\0\xCF`\09`\0\xF3\xFE`\x80`@R4\x80\x15a\0\x10W`\0\x80\xFD[P`\x046\x10a\0bW`\x005`\xE0\x1C\x80c; IH\x14a\0gW\x80c\x91\xB7\xF5\xED\x14a\0\x97W\x80c\xA05\xB1\xFE\x14a\0\xACW\x80c\xD0\x04\xF0\xF7\x14a\0\xC3W\x80c\xD0\xC4r\xEC\x14a\0\xD6W\x80c\xF8Q\xA4@\x14a\0\xE9W[`\0\x80\xFD[`\x01Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`@Q`\x01`\x01`\xA0\x1B\x03\x90\x91\x16\x81R` \x01[`@Q\x80\x91\x03\x90\xF3[a\0\xAAa\0\xA56`\x04a\x03\xF5V[a\0\xFCV[\0[a\0\xB5`\x03T\x81V[`@Q\x90\x81R` \x01a\0\x8EV[a\0\xAAa\0\xD16`\x04a\x04\x0EV[a\x017V[`\x02Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\x03\x81\x90U`@Q\x81\x81R\x7F\xF3G\xEE\x99P;\xF1\x9C\x02\x8B\xD6\xB1\x8F=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x02_\x91\x90a\x04FV[a\x02\x9DW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\xDFV[`@Qc\xA9\x05\x9C\xBB`\xE0\x1B\x81R3`\x04\x82\x01R`$\x81\x01\x83\x90R`\x01`\x01`\xA0\x1B\x03\x82\x16\x90c\xA9\x05\x9C\xBB\x90`D\x01` `@Q\x80\x83\x03\x81`\0\x87Z\xF1\x15\x80\x15a\x02\xEAW=`\0\x80>=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x03\x0E\x91\x90a\x04FV[a\x03LW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\xDFV[`@\x80Q`\x01`\x01`\xA0\x1B\x03\x80\x87\x16\x82R\x83\x16` \x82\x01R\x90\x81\x01\x84\x90R``\x81\x01\x83\x90R3`\x80\x82\x01R\x7F\xB3\x9C\x9B\xC4?\x81\x1E\x1A|\xE1Y\xC5\xF1GE\x8F\xDB\x80&k\xF2<\x172 \x131n'\xE0\x86\xD0\x90`\xA0\x01`@Q\x80\x91\x03\x90\xA1PPPPV[`\0a\x03\xBF\x83\x83g\r\xE0\xB6\xB3\xA7d\0\0a\x03\xD7V[\x93\x92PPPV[`\0a\x03\xBF\x83g\r\xE0\xB6\xB3\xA7d\0\0\x84[`\0\x82`\0\x19\x04\x84\x11\x83\x02\x15\x82\x02a\x03\xEEW`\0\x80\xFD[P\x91\x02\x04\x90V[`\0` \x82\x84\x03\x12\x15a\x04\x07W`\0\x80\xFD[P5\x91\x90PV[`\0\x80`@\x83\x85\x03\x12\x15a\x04!W`\0\x80\xFD[\x825`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14a\x048W`\0\x80\xFD[\x94` \x93\x90\x93\x015\x93PPPV[`\0` \x82\x84\x03\x12\x15a\x04XW`\0\x80\xFD[\x81Q\x80\x15\x15\x81\x14a\x03\xBFW`\0\x80\xFD\xFE\xA2dipfsX\"\x12 Y\xA5\xD0lLy\x8C\xE9\x1A\xEB\x9B\xB9\x1F\x95\x87\xC0\xA3S\xFC\x7F\0\x07\xB7\xE8<\xB0\xB3xD1\xE3\xD1dsolcC\0\x08\x1A\x003", ); /// The runtime bytecode of the contract, as deployed on the network. /// /// ```text - ///0x608060405234801561001057600080fd5b50600436106100625760003560e01c80633b2049481461006757806391b7f5ed14610097578063a035b1fe146100ac578063d004f0f7146100c3578063d0c472ec146100d6578063f851a440146100e9575b600080fd5b60015461007a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6100aa6100a5366004610459565b6100fc565b005b6100b560035481565b60405190815260200161008e565b6100aa6100d1366004610472565b6101a0565b60025461007a906001600160a01b031681565b60005461007a906001600160a01b031681565b6000546001600160a01b031633146101655760405162461bcd60e51b815260206004820152602160248201527f4f6e6c792061646d696e2063616e2063616c6c20746869732066756e6374696f6044820152603760f91b60648201526084015b60405180910390fd5b60038190556040518181527ff347ee99503bf19c028bd6b18f3c676e82a9bb5b2bb5225aebe0fd62fd6a0d199060200160405180910390a150565b60015460009081906001600160a01b03908116908516036101e057506002546003546001600160a01b03909116906101d990849061040e565b915061024c565b6002546001600160a01b039081169085160361021457506001546003546001600160a01b03909116906101d990849061042a565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b604482015260640161015c565b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038516906323b872dd906064016020604051808303816000875af115801561029f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c391906104aa565b6103015760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b604482015260640161015c565b60405163a9059cbb60e01b8152336004820152602481018390526001600160a01b0382169063a9059cbb906044016020604051808303816000875af115801561034e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061037291906104aa565b6103b05760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b604482015260640161015c565b604080516001600160a01b03808716825283166020820152908101849052606081018390523360808201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d09060a00160405180910390a150505050565b60006104238383670de0b6b3a764000061043b565b9392505050565b600061042383670de0b6b3a7640000845b600082600019048411830215820261045257600080fd5b5091020490565b60006020828403121561046b57600080fd5b5035919050565b6000806040838503121561048557600080fd5b82356001600160a01b038116811461049c57600080fd5b946020939093013593505050565b6000602082840312156104bc57600080fd5b8151801515811461042357600080fdfea2646970667358221220026041555962859b339c7c22e07468ebf4c8b3b54d1c2f1d36aaea41f6bc4c5c64736f6c634300081a0033 + ///0x608060405234801561001057600080fd5b50600436106100625760003560e01c80633b2049481461006757806391b7f5ed14610097578063a035b1fe146100ac578063d004f0f7146100c3578063d0c472ec146100d6578063f851a440146100e9575b600080fd5b60015461007a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6100aa6100a53660046103f5565b6100fc565b005b6100b560035481565b60405190815260200161008e565b6100aa6100d136600461040e565b610137565b60025461007a906001600160a01b031681565b60005461007a906001600160a01b031681565b60038190556040518181527ff347ee99503bf19c028bd6b18f3c676e82a9bb5b2bb5225aebe0fd62fd6a0d199060200160405180910390a150565b60015460009081906001600160a01b039081169085160361017757506002546003546001600160a01b03909116906101709084906103aa565b91506101e8565b6002546001600160a01b03908116908516036101ab57506001546003546001600160a01b03909116906101709084906103c6565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b60448201526064015b60405180910390fd5b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038516906323b872dd906064016020604051808303816000875af115801561023b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061025f9190610446565b61029d5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064016101df565b60405163a9059cbb60e01b8152336004820152602481018390526001600160a01b0382169063a9059cbb906044016020604051808303816000875af11580156102ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030e9190610446565b61034c5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064016101df565b604080516001600160a01b03808716825283166020820152908101849052606081018390523360808201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d09060a00160405180910390a150505050565b60006103bf8383670de0b6b3a76400006103d7565b9392505050565b60006103bf83670de0b6b3a7640000845b60008260001904841183021582026103ee57600080fd5b5091020490565b60006020828403121561040757600080fd5b5035919050565b6000806040838503121561042157600080fd5b82356001600160a01b038116811461043857600080fd5b946020939093013593505050565b60006020828403121561045857600080fd5b815180151581146103bf57600080fdfea264697066735822122059a5d06c4c798ce91aeb9bb91f9587c0a353fc7f0007b7e83cb0b3784431e3d164736f6c634300081a0033 /// ``` #[rustfmt::skip] pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static( - b"`\x80`@R4\x80\x15a\0\x10W`\0\x80\xFD[P`\x046\x10a\0bW`\x005`\xE0\x1C\x80c; IH\x14a\0gW\x80c\x91\xB7\xF5\xED\x14a\0\x97W\x80c\xA05\xB1\xFE\x14a\0\xACW\x80c\xD0\x04\xF0\xF7\x14a\0\xC3W\x80c\xD0\xC4r\xEC\x14a\0\xD6W\x80c\xF8Q\xA4@\x14a\0\xE9W[`\0\x80\xFD[`\x01Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`@Q`\x01`\x01`\xA0\x1B\x03\x90\x91\x16\x81R` \x01[`@Q\x80\x91\x03\x90\xF3[a\0\xAAa\0\xA56`\x04a\x04YV[a\0\xFCV[\0[a\0\xB5`\x03T\x81V[`@Q\x90\x81R` \x01a\0\x8EV[a\0\xAAa\0\xD16`\x04a\x04rV[a\x01\xA0V[`\x02Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0T`\x01`\x01`\xA0\x1B\x03\x163\x14a\x01eW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`!`$\x82\x01R\x7FOnly admin can call this functio`D\x82\x01R`7`\xF9\x1B`d\x82\x01R`\x84\x01[`@Q\x80\x91\x03\x90\xFD[`\x03\x81\x90U`@Q\x81\x81R\x7F\xF3G\xEE\x99P;\xF1\x9C\x02\x8B\xD6\xB1\x8F=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x02\xC3\x91\x90a\x04\xAAV[a\x03\x01W`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\\V[`@Qc\xA9\x05\x9C\xBB`\xE0\x1B\x81R3`\x04\x82\x01R`$\x81\x01\x83\x90R`\x01`\x01`\xA0\x1B\x03\x82\x16\x90c\xA9\x05\x9C\xBB\x90`D\x01` `@Q\x80\x83\x03\x81`\0\x87Z\xF1\x15\x80\x15a\x03NW=`\0\x80>=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x03r\x91\x90a\x04\xAAV[a\x03\xB0W`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\\V[`@\x80Q`\x01`\x01`\xA0\x1B\x03\x80\x87\x16\x82R\x83\x16` \x82\x01R\x90\x81\x01\x84\x90R``\x81\x01\x83\x90R3`\x80\x82\x01R\x7F\xB3\x9C\x9B\xC4?\x81\x1E\x1A|\xE1Y\xC5\xF1GE\x8F\xDB\x80&k\xF2<\x172 \x131n'\xE0\x86\xD0\x90`\xA0\x01`@Q\x80\x91\x03\x90\xA1PPPPV[`\0a\x04#\x83\x83g\r\xE0\xB6\xB3\xA7d\0\0a\x04;V[\x93\x92PPPV[`\0a\x04#\x83g\r\xE0\xB6\xB3\xA7d\0\0\x84[`\0\x82`\0\x19\x04\x84\x11\x83\x02\x15\x82\x02a\x04RW`\0\x80\xFD[P\x91\x02\x04\x90V[`\0` \x82\x84\x03\x12\x15a\x04kW`\0\x80\xFD[P5\x91\x90PV[`\0\x80`@\x83\x85\x03\x12\x15a\x04\x85W`\0\x80\xFD[\x825`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14a\x04\x9CW`\0\x80\xFD[\x94` \x93\x90\x93\x015\x93PPPV[`\0` \x82\x84\x03\x12\x15a\x04\xBCW`\0\x80\xFD[\x81Q\x80\x15\x15\x81\x14a\x04#W`\0\x80\xFD\xFE\xA2dipfsX\"\x12 \x02`AUYb\x85\x9B3\x9C|\"\xE0th\xEB\xF4\xC8\xB3\xB5M\x1C/\x1D6\xAA\xEAA\xF6\xBCL\\dsolcC\0\x08\x1A\x003", + b"`\x80`@R4\x80\x15a\0\x10W`\0\x80\xFD[P`\x046\x10a\0bW`\x005`\xE0\x1C\x80c; IH\x14a\0gW\x80c\x91\xB7\xF5\xED\x14a\0\x97W\x80c\xA05\xB1\xFE\x14a\0\xACW\x80c\xD0\x04\xF0\xF7\x14a\0\xC3W\x80c\xD0\xC4r\xEC\x14a\0\xD6W\x80c\xF8Q\xA4@\x14a\0\xE9W[`\0\x80\xFD[`\x01Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`@Q`\x01`\x01`\xA0\x1B\x03\x90\x91\x16\x81R` \x01[`@Q\x80\x91\x03\x90\xF3[a\0\xAAa\0\xA56`\x04a\x03\xF5V[a\0\xFCV[\0[a\0\xB5`\x03T\x81V[`@Q\x90\x81R` \x01a\0\x8EV[a\0\xAAa\0\xD16`\x04a\x04\x0EV[a\x017V[`\x02Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\0Ta\0z\x90`\x01`\x01`\xA0\x1B\x03\x16\x81V[`\x03\x81\x90U`@Q\x81\x81R\x7F\xF3G\xEE\x99P;\xF1\x9C\x02\x8B\xD6\xB1\x8F=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x02_\x91\x90a\x04FV[a\x02\x9DW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\xDFV[`@Qc\xA9\x05\x9C\xBB`\xE0\x1B\x81R3`\x04\x82\x01R`$\x81\x01\x83\x90R`\x01`\x01`\xA0\x1B\x03\x82\x16\x90c\xA9\x05\x9C\xBB\x90`D\x01` `@Q\x80\x83\x03\x81`\0\x87Z\xF1\x15\x80\x15a\x02\xEAW=`\0\x80>=`\0\xFD[PPPP`@Q=`\x1F\x19`\x1F\x82\x01\x16\x82\x01\x80`@RP\x81\x01\x90a\x03\x0E\x91\x90a\x04FV[a\x03LW`@QbF\x1B\xCD`\xE5\x1B\x81R` `\x04\x82\x01R`\x0F`$\x82\x01Rn\x15\x1C\x98[\x9C\xD9\x99\\\x88\x19\x98Z[\x19Y`\x8A\x1B`D\x82\x01R`d\x01a\x01\xDFV[`@\x80Q`\x01`\x01`\xA0\x1B\x03\x80\x87\x16\x82R\x83\x16` \x82\x01R\x90\x81\x01\x84\x90R``\x81\x01\x83\x90R3`\x80\x82\x01R\x7F\xB3\x9C\x9B\xC4?\x81\x1E\x1A|\xE1Y\xC5\xF1GE\x8F\xDB\x80&k\xF2<\x172 \x131n'\xE0\x86\xD0\x90`\xA0\x01`@Q\x80\x91\x03\x90\xA1PPPPV[`\0a\x03\xBF\x83\x83g\r\xE0\xB6\xB3\xA7d\0\0a\x03\xD7V[\x93\x92PPPV[`\0a\x03\xBF\x83g\r\xE0\xB6\xB3\xA7d\0\0\x84[`\0\x82`\0\x19\x04\x84\x11\x83\x02\x15\x82\x02a\x03\xEEW`\0\x80\xFD[P\x91\x02\x04\x90V[`\0` \x82\x84\x03\x12\x15a\x04\x07W`\0\x80\xFD[P5\x91\x90PV[`\0\x80`@\x83\x85\x03\x12\x15a\x04!W`\0\x80\xFD[\x825`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14a\x048W`\0\x80\xFD[\x94` \x93\x90\x93\x015\x93PPPV[`\0` \x82\x84\x03\x12\x15a\x04XW`\0\x80\xFD[\x81Q\x80\x15\x15\x81\x14a\x03\xBFW`\0\x80\xFD\xFE\xA2dipfsX\"\x12 Y\xA5\xD0lLy\x8C\xE9\x1A\xEB\x9B\xB9\x1F\x95\x87\xC0\xA3S\xFC\x7F\0\x07\xB7\xE8<\xB0\xB3xD1\xE3\xD1dsolcC\0\x08\x1A\x003", ); /**Event with signature `PriceChange(uint256)` and selector `0xf347ee99503bf19c028bd6b18f3c676e82a9bb5b2bb5225aebe0fd62fd6a0d19`. ```solidity @@ -244,7 +245,7 @@ pub mod LiquidExchange { } #[inline] fn topics(&self) -> ::RustType { - (Self::SIGNATURE_HASH,) + (Self::SIGNATURE_HASH.into(),) } #[inline] fn encode_topics_raw( @@ -346,7 +347,7 @@ pub mod LiquidExchange { } #[inline] fn topics(&self) -> ::RustType { - (Self::SIGNATURE_HASH,) + (Self::SIGNATURE_HASH.into(),) } #[inline] fn encode_topics_raw( @@ -435,7 +436,9 @@ pub mod LiquidExchange { ); type Token<'a> = as alloy_sol_types::SolType>::Token<'a>; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -538,7 +541,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "admin()"; const SELECTOR: [u8; 4] = [248u8, 81u8, 164u8, 64u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -641,7 +646,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "arbiterTokenX()"; const SELECTOR: [u8; 4] = [59u8, 32u8, 73u8, 72u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -744,7 +751,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "arbiterTokenY()"; const SELECTOR: [u8; 4] = [208u8, 196u8, 114u8, 236u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -847,7 +856,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "price()"; const SELECTOR: [u8; 4] = [160u8, 53u8, 177u8, 254u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -950,7 +961,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "setPrice(uint256)"; const SELECTOR: [u8; 4] = [145u8, 183u8, 245u8, 237u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] @@ -1070,7 +1083,9 @@ pub mod LiquidExchange { const SIGNATURE: &'static str = "swap(address,uint256)"; const SELECTOR: [u8; 4] = [208u8, 4u8, 240u8, 247u8]; #[inline] - fn new(tuple: as alloy_sol_types::SolType>::RustType) -> Self { + fn new<'a>( + tuple: as alloy_sol_types::SolType>::RustType, + ) -> Self { tuple.into() } #[inline] diff --git a/src/deployer.rs b/src/deployer.rs index f7abde7..1aaa50e 100644 --- a/src/deployer.rs +++ b/src/deployer.rs @@ -113,6 +113,7 @@ impl Behavior for Deployer { .unwrap() .send(To::All, DeploymentResponse::LiquidExchange(*lex.address())) .await?; + Ok(ControlFlow::Continue) } _ => Ok(ControlFlow::Continue), diff --git a/src/lib.rs b/src/lib.rs index 0dfd764..b7c93a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,10 +21,9 @@ use crate::{ }, deployer::{DeploymentRequest, DeploymentResponse}, pool_admin::PoolParams, - price_changer::PriceUpdate, + price_changer::{PriceChanger, PriceUpdate}, types::process::{OrnsteinUhlenbeck, StochasticProcess}, }; -use crate::price_changer::PriceChanger; pub mod arbitrageur; pub mod bindings; @@ -34,7 +33,6 @@ pub mod pool_admin; pub mod price_changer; pub mod types; - #[cfg(test)] mod tests { use octane::{agent::Agent, world::World}; @@ -119,7 +117,7 @@ mod tests { if let DeploymentResponse::Token(address) = query { self.tokens.push(address); } - + if self.tokens.len() == 2 { break; } @@ -138,13 +136,24 @@ mod tests { println!("Tokens: {:?}", self.tokens); - for i in 0..100 { - messager - .send( - To::Agent("pricechanger".to_string()), - PriceUpdate, - ) - .await?; + use tokio::time::{sleep, Duration}; + + while let Some(event) = stream.next().await { + let query: DeploymentResponse = match serde_json::from_str(&event.data) { + Ok(query) => query, + Err(_) => { + // eprintln!("Failed to deserialize the event datfa into a DeploymentResponse"); + continue; + } + }; + + if let DeploymentResponse::LiquidExchange(address) = query { + sleep(Duration::from_millis(3000)).await; + println!("here"); + for i in 0..100 { + messager.send(To::All, PriceUpdate).await?; + } + } } self.client = Some(client.clone()); @@ -155,7 +164,7 @@ mod tests { } #[tokio::test] - async fn asdfasdf() { + async fn test_price_changer() { env_logger::init(); let token_deployer = Agent::builder("tdeployer").with_behavior(TokenDeployer { @@ -174,15 +183,17 @@ mod tests { tokens: vec![], }); - let changer = Agent::builder("pricechanger").with_behavior(PriceChanger::new(OrnsteinUhlenbeck::new(0.0, 0.1, 0.1, 0.1))); + let changer = Agent::builder("pricechanger").with_behavior(PriceChanger::new( + OrnsteinUhlenbeck::new(1.0, 0.15, 0.0, 0.3, 1.0 / 252.0), + )); let mut world = World::new("id"); + world.add_agent(changer); world.add_agent(mock_deployer); world.add_agent(deployer); world.add_agent(token_deployer); - world.add_agent(changer); let _ = world.run().await; } -} \ No newline at end of file +} diff --git a/src/price_changer.rs b/src/price_changer.rs index 3cbe356..09f5fd3 100644 --- a/src/price_changer.rs +++ b/src/price_changer.rs @@ -24,9 +24,32 @@ impl PriceChanger { } } +use serde::{ser::SerializeStruct, Deserializer, Serializer}; + #[derive(Debug, Serialize, Deserialize)] pub struct PriceUpdate; +// impl Serialize for PriceUpdate { +// fn serialize(&self, serializer: S) -> Result +// where +// S: Serializer, +// { +// let mut state = serializer.serialize_struct("PriceUpdate", 1)?; +// state.serialize_field("type", "PriceUpdate")?; +// state.end() +// } +// } + +// impl<'de> Deserialize<'de> for PriceUpdate { +// fn deserialize(deserializer: D) -> Result +// where +// D: Deserializer<'de>, +// { +// serde::de::Deserialize::deserialize(deserializer)?; +// Ok(PriceUpdate) +// } +// } + #[async_trait::async_trait] impl Behavior for PriceChanger { async fn startup( @@ -41,9 +64,12 @@ impl Behavior for PriceChanger { while let Some(event) = stream.next().await { let query: DeploymentResponse = match serde_json::from_str(&event.data) { - Ok(query) => query, + Ok(query) => { + println!("heresd"); + query + } Err(_) => { - eprintln!("Failed to deserialize the event data into a DeploymentResponse"); + // eprintln!("Failed to deserialize the event datfa into a DeploymentResponse"); continue; } }; @@ -58,7 +84,7 @@ impl Behavior for PriceChanger { } async fn process(&mut self, event: Message) -> Result { - let _query: PriceUpdate = match serde_json::from_str(&event.data) { + let query: PriceUpdate = match serde_json::from_str(&event.data) { Ok(query) => query, Err(_) => { eprintln!("Failed to deserialize the event data into a PriceUpdate"); diff --git a/src/types/process.rs b/src/types/process.rs index e7a3def..56ce4be 100644 --- a/src/types/process.rs +++ b/src/types/process.rs @@ -1,4 +1,6 @@ +use rand::thread_rng; use rand_distr::{Distribution, Normal}; +use serde::{Deserialize, Serialize}; pub trait StochasticProcess { type Value; @@ -8,7 +10,7 @@ pub trait StochasticProcess { fn step(&mut self) -> Self::Value; } -#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug)] pub struct OrnsteinUhlenbeck { current_value: f64, @@ -26,13 +28,13 @@ pub struct OrnsteinUhlenbeck { } impl OrnsteinUhlenbeck { - pub fn new(initial_value: f64, theta: f64, mu: f64, sigma: f64) -> Self { + pub fn new(initial_value: f64, theta: f64, mu: f64, sigma: f64, dt: f64) -> Self { OrnsteinUhlenbeck { current_value: initial_value, theta, mu, sigma, - dt: 0.0, + dt, } } } @@ -45,13 +47,13 @@ impl StochasticProcess for OrnsteinUhlenbeck { } fn step(&mut self) -> Self::Value { - let mut rng = rand::thread_rng(); + let mut rng = thread_rng(); let normal = Normal::new(0.0, 1.0).unwrap(); let drift = self.theta * (self.mu - self.current_value) * self.dt; - let randomness = self.sigma * (self.dt.sqrt()) * normal.sample(&mut rng); - self.current_value += drift + randomness; + let randomness = self.sigma * self.dt.sqrt() * normal.sample(&mut rng); + self.current_value += drift + randomness; self.current_value } }