Source Code
Latest 25 from a total of 110 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Retract And With... | 8705808 | 500 days ago | IN | 0 ETH | 0.00058361 | ||||
| Populate From Of... | 8705723 | 500 days ago | IN | 0.0856 ETH | 0.00121804 | ||||
| Retract And With... | 8702618 | 500 days ago | IN | 0 ETH | 0.00010268 | ||||
| Populate From Of... | 8702600 | 500 days ago | IN | 0.00428 ETH | 0.00015863 | ||||
| Retract And With... | 5215337 | 580 days ago | IN | 0 ETH | 0.00082605 | ||||
| Populate From Of... | 5076252 | 584 days ago | IN | 0.13268 ETH | 0.00127983 | ||||
| Retract And With... | 5076223 | 584 days ago | IN | 0 ETH | 0.00078872 | ||||
| Populate From Of... | 5058217 | 584 days ago | IN | 0.1284 ETH | 0.00125216 | ||||
| Retract And With... | 1626599 | 664 days ago | IN | 0 ETH | 0.00031581 | ||||
| Populate From Of... | 1619485 | 664 days ago | IN | 0.0736 ETH | 0.00011415 | ||||
| Retract And With... | 1619346 | 664 days ago | IN | 0 ETH | 0.00010142 | ||||
| Populate From Of... | 1619302 | 664 days ago | IN | 0.07728 ETH | 0.00009785 | ||||
| Retract And With... | 1587190 | 664 days ago | IN | 0 ETH | 0.00023857 | ||||
| Populate From Of... | 1576695 | 665 days ago | IN | 0.0736 ETH | 0.00005346 | ||||
| Retract And With... | 1566047 | 665 days ago | IN | 0 ETH | 0.00004934 | ||||
| Populate From Of... | 1537935 | 666 days ago | IN | 0.07728 ETH | 0.0000549 | ||||
| Retract And With... | 1537897 | 666 days ago | IN | 0 ETH | 0.00005328 | ||||
| Populate From Of... | 1537774 | 666 days ago | IN | 0.07728 ETH | 0.00005479 | ||||
| Retract And With... | 1537653 | 666 days ago | IN | 0 ETH | 0.00005007 | ||||
| Populate From Of... | 1493455 | 667 days ago | IN | 0.08096 ETH | 0.0000559 | ||||
| Retract And With... | 1459063 | 667 days ago | IN | 0 ETH | 0.00011354 | ||||
| Populate From Of... | 1451539 | 668 days ago | IN | 0.07728 ETH | 0.00006948 | ||||
| Retract And With... | 1444490 | 668 days ago | IN | 0 ETH | 0.00006723 | ||||
| Populate From Of... | 1418119 | 668 days ago | IN | 0.0736 ETH | 0.00013983 | ||||
| Retract And With... | 1418018 | 668 days ago | IN | 0 ETH | 0.00015277 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 8705808 | 500 days ago | 0.0856 ETH | ||||
| 8705808 | 500 days ago | 0.0856 ETH | ||||
| 8705723 | 500 days ago | 0.0856 ETH | ||||
| 8702618 | 500 days ago | 0.00428 ETH | ||||
| 8702618 | 500 days ago | 0.00428 ETH | ||||
| 8702600 | 500 days ago | 0.00428 ETH | ||||
| 5215337 | 580 days ago | 0.13268 ETH | ||||
| 5215337 | 580 days ago | 0.13268 ETH | ||||
| 5076252 | 584 days ago | 0.13268 ETH | ||||
| 5076223 | 584 days ago | 0.1284 ETH | ||||
| 5076223 | 584 days ago | 0.1284 ETH | ||||
| 5058217 | 584 days ago | 0.1284 ETH | ||||
| 1626599 | 664 days ago | 0.0736 ETH | ||||
| 1626599 | 664 days ago | 0.0736 ETH | ||||
| 1619485 | 664 days ago | 0.0736 ETH | ||||
| 1619346 | 664 days ago | 0.07728 ETH | ||||
| 1619346 | 664 days ago | 0.07728 ETH | ||||
| 1619302 | 664 days ago | 0.07728 ETH | ||||
| 1587190 | 664 days ago | 0.0736 ETH | ||||
| 1587190 | 664 days ago | 0.0736 ETH | ||||
| 1576695 | 665 days ago | 0.0736 ETH | ||||
| 1566047 | 665 days ago | 0.07728 ETH | ||||
| 1566047 | 665 days ago | 0.07728 ETH | ||||
| 1537935 | 666 days ago | 0.07728 ETH | ||||
| 1537897 | 666 days ago | 0.07728 ETH |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x3f5640a9...9b193d606 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
BlastKandel
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
// import {MangroveOffer, RL} from "@mgv-strats/src/strategies/MangroveOffer.sol";
import {Kandel} from "@mgv-strats/src/strategies/offer_maker/market_making/kandel/Kandel.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {MgvLib, OLKey} from "@mgv/src/core/MgvLib.sol";
import {IBlast} from "@mgv/src/chains/blast/interfaces/IBlast.sol";
import {IBlastPoints} from "@mgv/src/chains/blast/interfaces/IBlastPoints.sol";
///@title The Kandel strat with geometric price progression.
contract BlastKandel is Kandel {
///@notice Constructor
///@param mgv The Mangrove deployment.
///@param olKeyBaseQuote The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
///@param gasreq the gasreq to use for offers
constructor(
IMangrove mgv,
OLKey memory olKeyBaseQuote,
uint gasreq,
IBlast blastContract,
address blastGovernor,
IBlastPoints blastPointsContract,
address blastPointsOperator
) Kandel(mgv, olKeyBaseQuote, gasreq) {
blastContract.configureClaimableGas();
blastContract.configureGovernor(blastGovernor);
blastPointsContract.configurePointsOperator(blastPointsOperator);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {MangroveOffer, RL} from "@mgv-strats/src/strategies/MangroveOffer.sol";
import {GeometricKandel} from "./abstract/GeometricKandel.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {MgvLib, OLKey} from "@mgv/src/core/MgvLib.sol";
///@title The Kandel strat with geometric price progression.
contract Kandel is GeometricKandel {
///@notice Constructor
///@param mgv The Mangrove deployment.
///@param olKeyBaseQuote The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
///@param gasreq the gasreq to use for offers
constructor(IMangrove mgv, OLKey memory olKeyBaseQuote, uint gasreq) GeometricKandel(mgv, olKeyBaseQuote, noRouter()) {
setGasreq(gasreq);
activate(BASE);
activate(QUOTE);
}
///@inheritdoc MangroveOffer
function __posthookSuccess__(MgvLib.SingleOrder calldata order, bytes32 makerData)
internal
virtual
override
returns (bytes32 repostStatus)
{
transportSuccessfulOrder(order);
repostStatus = super.__posthookSuccess__(order, makerData);
}
}// SPDX-License-Identifier: MIT
// This file must be kept up-to-date with the actual Mangrove interface.
pragma solidity >=0.7.0 <0.9.0;
import "@mgv/src/core/MgvLib.sol";
///@title Interface for the Mangrove contract.
interface IMangrove is HasMgvEvents {
// # Permit functions
///@notice See {IERC20Permit-DOMAIN_SEPARATOR}.
///@return the domain separator.
function DOMAIN_SEPARATOR() external view returns (bytes32);
///@notice See {IERC20Permit-PERMIT_TYPEHASH}.
///@return The permit type hash.
function PERMIT_TYPEHASH() external pure returns (bytes32);
///@notice Approves the spender to spend the amount of tokens on behalf of the caller.
///@param outbound_tkn The address of the (maker) outbound token.
///@param inbound_tkn The address of the (maker) inbound token.
///@param spender The address of the spender.
///@param value The amount of tokens to approve.
///@return true If the approval succeeded; always true.
function approve(address outbound_tkn, address inbound_tkn, address spender, uint value) external returns (bool);
///@notice Returns the allowance of the spender to spend tokens on behalf of the owner.
///@param outbound_tkn The address of the (maker) outbound token.
///@param inbound_tkn The address of the (maker) inbound token.
///@param owner The address of the owner.
///@param spender The address of the spender.
///@return amount The amount of tokens the spender is allowed to spend on behalf of the owner.
function allowance(address outbound_tkn, address inbound_tkn, address owner, address spender)
external
view
returns (uint amount);
///@notice Adapted from [Uniswap v2 contract](https://github.com/Uniswap/uniswap-v2-core/blob/55ae25109b7918565867e5c39f1e84b7edd19b2a/contracts/UniswapV2ERC20.sol#L81)
///@param outbound_tkn The address of the (maker) outbound token.
///@param inbound_tkn The address of the (maker) inbound token.
///@param owner The address of the owner.
///@param spender The address of the spender.
///@param value The amount of tokens to approve.
///@param deadline The deadline after which the permit is no longer valid.
///@param v The signature v parameter.
///@param r The signature r parameter.
///@param s The signature s parameter.
function permit(
address outbound_tkn,
address inbound_tkn,
address owner,
address spender,
uint value,
uint deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
///@notice See {IERC20Permit-nonces}.
///@param owner The address of the owner.
///@return nonce The current nonce of the owner.
function nonces(address owner) external view returns (uint nonce);
// # Taker functions
///@notice Performs a market order on a specified offer list taking offers up to a limit price.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param maxTick Must be `>= MIN_TICK` and `<= MAX_TICK`. The log of the limit price the taker is ready to pay (meaning: the log base 1.0001 of the ratio of inbound tokens over outbound tokens).
///@param fillVolume Must be `<= MAX_SAFE_VOLUME`. If `fillWants` is true, the amount of `olKey.outbound_tkn` the taker wants to buy; otherwise, the amount of `olKey.inbound_tkn` the taker wants to sell.
///@param fillWants If true, the matching engine tries to get the taker all they want; otherwise, the matching engine tries to sell all that the taker gives. In both cases subject to the price limit.
///@return takerGot The amount of `olKey.outbound_tkn` the taker got.
///@return takerGave The amount of `olKey.inbound_tkn` the taker gave.
///@return bounty The amount of native token the taker got as a bounty due to failing offers (in wei).
///@return feePaid The amount of `olKey.outbound_tkn` the taker paid as a fee to Mangrove.
///@dev The market order stops when there are no more offers at or below `maxTick`, when the end of the book has been reached, or:
///@dev - If `fillWants` is true, the market order stops when `fillVolume` units of `olKey.outbound_tkn` have been obtained. To buy a specific volume of `olKey.outbound_tkn` at any price, set `fillWants` to true, set `fillVolume` to the volume you want to buy, and set `maxTick` to the `MAX_TICK` constant.
///@dev - If `fillWants` is false, the market order stops when `fillVolume` units of `olKey.inbound_tkn` have been paid. To sell a specific volume of `olKey.inbound_tkn` at any price, set `fillWants` to false, set `fillVolume` to the volume you want to sell, and set `maxTick` to the `MAX_TICK` constant.
function marketOrderByTick(OLKey memory olKey, Tick maxTick, uint fillVolume, bool fillWants)
external
returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
///@notice Performs a market order on a specified offer list taking offers up to a limit price, while allowing to specify a custom `maxGasreqForFailingOffers`.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param maxTick Must be `>= MIN_TICK` and `<= MAX_TICK`. The log of the limit price the taker is ready to pay (meaning: the log base 1.0001 of the ratio of inbound tokens over outbound tokens).
///@param fillVolume Must be `<= MAX_SAFE_VOLUME`. If `fillWants` is true, the amount of `olKey.outbound_tkn` the taker wants to buy; otherwise, the amount of `olKey.inbound_tkn` the taker wants to sell.
///@param fillWants If true, the matching engine tries to get the taker all they want; otherwise, the matching engine tries to sell all that the taker gives. In both cases subject to the price limit.
///@param maxGasreqForFailingOffers The maximum allowed gas required for failing offers (in wei).
///@return takerGot The amount of `olKey.outbound_tkn` the taker got.
///@return takerGave The amount of `olKey.inbound_tkn` the taker gave.
///@return bounty The amount of native token the taker got as a bounty due to failing offers (in wei).
///@return feePaid The amount of `olKey.outbound_tkn` the taker paid as a fee to Mangrove.
///@dev Mangrove stops a market order after it has gone through failing offers such that their cumulative `gasreq` is greater than the global `maxGasreqForFailingOffers` parameter. This function can be used by the taker to override the default `maxGasreqForFailingOffers` parameter.
function marketOrderByTickCustom(
OLKey memory olKey,
Tick maxTick,
uint fillVolume,
bool fillWants,
uint maxGasreqForFailingOffers
) external returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
///@notice Performs a market order on a specified offer list taking offers up to a limit price defined by a ratio `inbound_tkn/outbound_tkn` of volumes.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param takerWants Must be `<= MAX_SAFE_VOLUME`. The amount the taker wants. This is used along with `takerGives` to derive a max price (`maxTick`) which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param takerGives Must be `<= MAX_SAFE_VOLUME`. The amount the taker gives. This is used along with `takerWants` to derive a max price (`maxTick`) which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param fillWants If true, the matching engine tries to get the taker all they want; otherwise, the matching engine tries to sell all that the taker gives. In both cases subject to the price limit.
///@return takerGot The amount of `olKey.outbound_tkn` the taker got.
///@return takerGave The amount of `olKey.inbound_tkn` the taker gave.
///@return bounty The amount of native token the taker got as a bounty due to failing offers (in wei).
///@return feePaid The amount of `olKey.outbound_tkn` the taker paid as a fee to Mangrove.
///@dev This function is just a wrapper for `marketOrderByTick`, see that function for details.
///@dev When deriving the tick, then `takerWants = 0` has a special meaning and the tick for the highest possible ratio between wants and gives will be used,
///@dev and if `takerGives = 0` and `takerWants != 0`, then the tick for the lowest possible ratio will be used.
function marketOrderByVolume(OLKey memory olKey, uint takerWants, uint takerGives, bool fillWants)
external
returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
///@notice Performs a market order on a specified offer list taking offers up to a limit price for a specified taker.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param maxTick Must be `>= MIN_TICK` and `<= MAX_TICK`. The log of the limit price the taker is ready to pay (meaning: the log base 1.0001 of the ratio of inbound tokens over outbound tokens).
///@param fillVolume Must be `<= MAX_SAFE_VOLUME`. If `fillWants` is true, the amount of `olKey.outbound_tkn` the taker wants to buy; otherwise, the amount of `olKey.inbound_tkn` the taker wants to sell.
///@param fillWants If true, the matching engine tries to get the taker all they want; otherwise, the matching engine tries to sell all that the taker gives. In both cases subject to the price limit.
///@param taker The taker from which amounts will be transferred from and to. If the `msg.sender`'s allowance for the given `olKey.outbound_tkn`,`olKey.inbound_tkn` is strictly less than the total amount eventually spent by `taker`, the call will fail.
///@return takerGot The amount of `olKey.outbound_tkn` the taker got.
///@return takerGave The amount of `olKey.inbound_tkn` the taker gave.
///@return bounty The amount of native token the taker got as a bounty due to failing offers (in wei).
///@return feePaid The amount of `olKey.outbound_tkn` the taker paid as a fee to Mangrove.
///@dev The `bounty` will be sent to `msg.sender` but transfers will be for `taker`. Requires prior permission.
///@dev See also `marketOrderByTick`.
function marketOrderForByTick(OLKey memory olKey, Tick maxTick, uint fillVolume, bool fillWants, address taker)
external
returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
///@notice Performs a market order on a specified offer list taking offers up to a limit price defined by a ratio `inbound_tkn/outbound_tkn` of volumes for a specified taker.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param takerWants Must be `<= MAX_SAFE_VOLUME`. The amount the taker wants. This is used along with `takerGives` to derive a max price (`maxTick`) which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param takerGives Must be `<= MAX_SAFE_VOLUME`. The amount the taker gives. This is used along with `takerGives` to derive a max price (`maxTick`) which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param fillWants If true, the matching engine tries to get the taker all they want; otherwise, the matching engine tries to sell all that the taker gives. In both cases subject to the price limit.
///@param taker The taker from which amounts will be transferred from and to the. If the `msg.sender`'s allowance for the given `olKey.outbound_tkn`,`olKey.inbound_tkn` are strictly less than the total amount eventually spent by `taker`, the call will fail.
///@return takerGot The amount of `olKey.outbound_tkn` the taker got.
///@return takerGave The amount of `olKey.inbound_tkn` the taker gave.
///@return bounty The amount of native token the taker got as a bounty due to failing offers (in wei).
///@return feePaid The amount of native token the taker paid as a fee (in wei of `olKey.outbound_tkn`).
///@dev The `bounty` will be send to `msg.sender` but transfers will be for `taker`. Requires prior permission.
///@dev See also `marketOrderByVolume`.
function marketOrderForByVolume(OLKey memory olKey, uint takerWants, uint takerGives, bool fillWants, address taker)
external
returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
// # Cleaning functions
/* # Cleaning */
///@notice Cleans multiple offers, i.e. executes them and removes them from the book if they fail, transferring the failure penalty as bounty to the caller.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param targets The offers to clean, identified by their (`offerId, tick, gasreq, takerWants`) that will make them fail.
///@param taker The taker used for transfers (should be able to deliver token amounts).
///@return successes The number of successfully cleaned offers.
///@return bounty The total bounty received by the caller.
///@dev If an offer succeeds, the execution of that offer is reverted, it stays in the book, and no bounty is paid; The `cleanByImpersonation` function itself will not revert.
///@dev Note that Mangrove won't attempt to execute an offer if the values in a target don't match its offer. To distinguish between a non-executed clean and a failed clean (due to the offer itself not failing), you must inspect the log (see `MgvLib.sol`) or check the received bounty.
///@dev Any `taker` can be impersonated when cleaning because:
///@dev - The function reverts if the offer succeeds, reverting any token transfers.
///@dev - After a `clean` where the offer has failed, all ERC20 token transfers have also been reverted -- but the sender will still have received the bounty of the failing offers. */
function cleanByImpersonation(OLKey memory olKey, MgvLib.CleanTarget[] calldata targets, address taker)
external
returns (uint successes, uint bounty);
// # Maker functions
///@notice Adds funds to Mangrove for the caller (the maker) to use for provisioning offers.
receive() external payable;
///@notice Adds funds to Mangrove for the caller (the maker) to use for provisioning offers.
function fund() external payable;
///@notice Adds funds to Mangrove for the maker to use for provisioning offers.
///@param maker The maker to add funds for.
function fund(address maker) external payable;
///@notice Withdraws the caller's (the maker's) free native tokens (funds for provisioning offers not locked by an offer) by transferring them to the caller.
///@param amount The amount to withdraw.
///@return noRevert Whether the transfer succeeded.
function withdraw(uint amount) external returns (bool noRevert);
///@notice Gets the maker's free balance of native tokens (funds for provisioning offers not locked by an offer).
///@param maker The maker to get the balance for.
///@return balance The maker's free balance of native tokens (funds for provisioning offers not locked by an offer).
function balanceOf(address maker) external view returns (uint balance);
///@notice Creates a new offer on Mangrove, where the caller is the maker. The maker can implement the `IMaker` interface to be called during offer execution.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param tick Must be `>= MIN_TICK` and `<= MAX_TICK`. The `tick` induces a price which is `1.0001^tick`. The actual tick of the offer will be the smallest tick `offerTick > tick` that satisfies `offerTick % tickSpacing == 0`.
///@param gives Must be `<= MAX_SAFE_VOLUME`. The amount of `olKey.outbound_tkn` the maker gives.
///@param gasreq The amount of gas required to execute the offer logic in the maker's `IMaker` implementation. This will limit the gas available, and the offer will fail if it spends more.
///@param gasprice The maximum gas price the maker is willing to pay a penalty for due to failing execution.
///@return offerId The id of the offer on Mangrove. Can be used to retract or update the offer (even to reuse a taken offer).
///@dev The gasreq and gasprice are used to derive the provision which will be used to pay a penalty if the offer fails.
///@dev This function is payable to enable delivery of the provision along with the offer creation.
function newOfferByTick(OLKey memory olKey, Tick tick, uint gives, uint gasreq, uint gasprice)
external
payable
returns (uint offerId);
///@notice Creates a new offer on Mangrove, where the caller is the maker. The maker can implement the `IMaker` interface to be called during offer execution.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param wants Must be less than MAX_SAFE_VOLUME. The amount of `olKey.inbound_tkn` the maker wants. This is used along with `gives` to derive a tick (price). which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param gives Must be less than MAX_SAFE_VOLUME. The amount of `olKey.outbound_tkn` the maker gives. This is used along with `wants` to derive a tick (price). which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`. Must be less than MAX_SAFE_VOLUME.
///@param gasreq The amount of gas required to execute the offer logic in the maker's `IMaker` implementation. This will limit the gas available, and the offer will fail if it spends more.
///@param gasprice The maximum gas price the maker is willing to pay a penalty for due to failing execution.
///@return offerId The id of the offer on Mangrove. Can be used to retract or update the offer (even to reuse a taken offer).
///@dev This function is just a wrapper for `newOfferByTick`, see that function for details.
function newOfferByVolume(OLKey memory olKey, uint wants, uint gives, uint gasreq, uint gasprice)
external
payable
returns (uint offerId);
///@notice Updates an existing offer on Mangrove, where the caller is the maker.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param tick Must be `>= MIN_TICK` and `<= MAX_TICK`. The `tick` induces a price which is `1.0001^tick`. The actual tick of the offer will be the smallest tick `offerTick > tick` that satisfies `offerTick % tickSpacing == 0`.
///@param gives The amount of `olKey.outbound_tkn` the maker gives. Must be less than MAX_SAFE_VOLUME.
///@param gasreq The amount of gas required to execute the offer logic in the maker's `IMaker` implementation.
///@param gasprice The maximum gas price the maker is willing to pay a penalty for due to failing execution.
///@param offerId The id of the offer on Mangrove.
///@dev See `newOfferByTick` for additional details.
function updateOfferByTick(OLKey memory olKey, Tick tick, uint gives, uint gasreq, uint gasprice, uint offerId)
external
payable;
///@notice Updates an existing, owned offer on Mangrove, where the caller is the maker.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param wants The amount of `olKey.inbound_tkn` the maker wants. This is used along with `gives` to derive a tick (price). which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`.
///@param gives The amount of `olKey.outbound_tkn` the maker gives. This is used along with `wants` to derive a tick (price). which is the lowest allowed tick in the offer list such that `log_1.0001(takerGives/takerWants) <= maxTick`. Must be less than MAX_SAFE_VOLUME.
///@param gasreq The amount of gas required to execute the offer logic in the maker's `IMaker` implementation.
///@param gasprice The maximum gas price the maker is willing to pay a penalty for due to failing execution.
///@param offerId The id of the offer on Mangrove.
///@dev This function is just a wrapper for `updateOfferByTick`, see that function for details.
function updateOfferByVolume(OLKey memory olKey, uint wants, uint gives, uint gasreq, uint gasprice, uint offerId)
external
payable;
///@notice Retracts an offer from Mangrove, where the caller is the maker.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offerId The id of the offer on Mangrove.
///@param deprovision Whether to deprovision the offer, i.e, return the provision to the maker's balance on Mangrove.
///@return provision The amount of native token deprovisioned for the offer (in wei).
///@dev `withdraw` can be used to withdraw the funds after deprovisioning.
///@dev Leaving funds provisioned can be used to save gas if offer is later updated.
function retractOffer(OLKey memory olKey, uint offerId, bool deprovision) external returns (uint provision);
// # Global config view functions
///@notice Gets the global configuration for Mangrove.
///@return _global The global configuration for Mangrove.
function global() external view returns (Global _global);
// # Offer list view functions
///@notice Gets the local configuration for a specific offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@return _local The local configuration for the offer list.
function local(OLKey memory olKey) external view returns (Local _local);
///@notice Gets the global configuration for Mangrove and local the configuration for a specific offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@return _global The global configuration for Mangrove.
///@return _local The local configuration for the offer list.
function config(OLKey memory olKey) external view returns (Global _global, Local _local);
///@notice Determines whether the reentrancy lock is in effect for the offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@return true If locked; otherwise, false.
///@dev The lock protects modifying or inspecting the offer list while an order is in progress.
function locked(OLKey memory olKey) external view returns (bool);
///@notice Gets the `offerId` of the best offer in the offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@return offerId The `offerId` of the best offer on the offer list.
function best(OLKey memory olKey) external view returns (uint offerId);
///@notice Gets the offer list key with the given hash (if the offer list key has been activated at least once).
///@param olKeyHash The hash of the offer list key.
///@return olKey The olKey.
function olKeys(bytes32 olKeyHash) external view returns (OLKey memory olKey);
// # Offer view functions
///@notice Gets an offer in packed format.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offerId The `offerId` of the offer on the offer list.
///@return offer The offer in packed format.
function offers(OLKey memory olKey, uint offerId) external view returns (Offer offer);
///@notice Gets an offer's details in packed format.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offerId The `offerId` of the offer on the offer list.
///@return offerDetail The offer details in packed format.
function offerDetails(OLKey memory olKey, uint offerId) external view returns (OfferDetail offerDetail);
///@notice Gets both an offer and its details in packed format.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offerId The `offerId` of the offer on the offer list.
///@return offer The offer in packed format.
///@return offerDetail The offer details in packed format.
function offerData(OLKey memory olKey, uint offerId) external view returns (Offer offer, OfferDetail offerDetail);
// # Governance functions
///@notice Gets the governance address.
///@return The governance address.
function governance() external view returns (address);
///@notice Activates an offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param fee In basis points, of `olKey.outbound_tkn` given to the taker. This fee is sent to Mangrove. Fee is capped to ~2.5%.
///@param density96X32 The density of the offer list used to define a minimum offer volume. See `setDensity96X32`.
///@param offer_gasbase The gasbase of the offer list used to define a minimum provision necessary for offers. See `setGasbase`.
///@dev If the flipped offer list is active then the offer lists are expected to have the same `tickSpacing`.
function activate(OLKey memory olKey, uint fee, uint density96X32, uint offer_gasbase) external;
///@notice Deactivates an offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
function deactivate(OLKey memory olKey) external;
///@notice Kills the Mangrove instance. A dead instance cannot have offers executed or funds received, but offers can be retracted and funds can be withdrawn.
function kill() external;
///@notice Sets the density.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param density96X32 Is given as a 96.32 fixed point number. It will be stored as a 9-bit float and be approximated towards 0. The maximum error is 20%. See `DensityLib` for more information.
///@dev Useless if `global.useOracle != 0` and oracle returns a valid density.
function setDensity96X32(OLKey memory olKey, uint density96X32) external;
///@notice Sets the fee for the offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param fee In basis points, of `olKey.outbound_tkn` given to the taker. This fee is sent to Mangrove. Fee is capped to ~2.5%.
function setFee(OLKey memory olKey, uint fee) external;
///@notice Sets the gasbase for the offer list.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offer_gasbase The gasbase of the offer list used to define a minimum provision necessary for offers. Represents the gas overhead used by processing the offer inside Mangrove + the overhead of initiating an entire order. Stored in thousands in a maximum of 9 bits.
function setGasbase(OLKey memory olKey, uint offer_gasbase) external;
///@notice Sets the gasmax for Mangrove, the maximum amount of gas an offer can require to execute.
///@param gasmax The maximum amount of gas required to execute an offer. Must fit in 24 bits.
function setGasmax(uint gasmax) external;
///@notice Sets the maximum number of times a market order can recursively execute offers. This is a protection against stack overflows.
///@param maxRecursionDepth The maximum number of times a market order can recursively execute offers.
function setMaxRecursionDepth(uint maxRecursionDepth) external;
///@notice Sets the maximum cumulative `gasreq` for failing offers during a market order before doing a partial fill.
///@param maxGasreqForFailingOffers The maximum cumulative `gasreq` for failing offers during a market order before doing a partial fill. 32 bits.
function setMaxGasreqForFailingOffers(uint maxGasreqForFailingOffers) external;
///@notice Sets the gasprice (in Mwei, 26 bits).
///@param gasprice The gasprice (in Mwei, 26 bits).
function setGasprice(uint gasprice) external;
///@notice Sets a new governance address.
///@param governanceAddress The new governance address.
function setGovernance(address governanceAddress) external;
///@notice Sets the monitor/oracle. The `monitor/oracle` can provide real-time values for `gasprice` and `density` to Mangrove. It can also receive liquidity event notifications.
///@param monitor The new monitor/oracle address.
function setMonitor(address monitor) external;
///@notice Sets whether Mangrove notifies the Monitor when and offer is taken.
///@param notify Whether Mangrove notifies the Monitor when and offer is taken.
function setNotify(bool notify) external;
///@notice Sets whether Mangrove uses the monitor as oracle for `gasprice` and `density` values.
///@param useOracle Whether Mangrove uses the monitor as oracle for `gasprice` and `density` values.
function setUseOracle(bool useOracle) external;
///@notice Transfer ERC20 tokens to governance.
///@param tokenAddress The address of the ERC20 token.
///@param value The amount of tokens to transfer.
function withdrawERC20(address tokenAddress, uint value) external;
// # Tick tree view functions
///@notice Gets a leaf.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param index The index.
///@return The leaf.
function leafs(OLKey memory olKey, int index) external view returns (Leaf);
///@notice Gets a level 3 field.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param index The index.
///@return The field.
function level3s(OLKey memory olKey, int index) external view returns (Field);
///@notice Gets a level 2 field.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param index The index.
///@return The field.
function level2s(OLKey memory olKey, int index) external view returns (Field);
///@notice Gets a level 1 field.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param index The index.
///@return Yhe field.
function level1s(OLKey memory olKey, int index) external view returns (Field);
///@notice Gets the root from local.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@return The root.
function root(OLKey memory olKey) external view returns (Field);
// # Internal functions
///@notice Internal function used to flashloan tokens from taker to maker, for maker to source the promised liquidity.
///@param sor Data about an order-offer match.
///@param taker The taker.
///@return gasused The amount of gas used for `makerExecute`.
///@return makerData The data returned by `makerExecute`.
///@dev Not to be called externally - only external to be able to revert.
function flashloan(MgvLib.SingleOrder memory sor, address taker) external returns (uint gasused, bytes32 makerData);
///@notice Internal function used to clean failing offers.
///@param olKey The offer list key given by (maker) `outbound_tkn`, (maker) `inbound_tkn`, and `tickSpacing`.
///@param offerId The id of the offer on Mangrove.
///@param tick Must be `>= MIN_TICK` and `<= MAX_TICK`. The `tick` induces a price which is `1.0001^tick`. The actual tick of the offer will be the smallest tick `offerTick > tick` that satisfies `offerTick % tickSpacing == 0`.
///@param gasreq The gas required for the offer.
///@param takerWants Must be `<= MAX_SAFE_VOLUME`. The amount of `olKey.outbound_tkn` the taker wants.
///@param taker The taker used for transfers (should be able to deliver token amounts).
///@return bounty The bounty paid.
///@dev Not to be called externally - only external to be able to revert.
function internalCleanByImpersonation(
OLKey memory olKey,
uint offerId,
Tick tick,
uint gasreq,
uint takerWants,
address taker
) external returns (uint bounty);
///@notice Fall back function (forwards calls to `MgvAppendix`).
///@param callData The call data.
///@return The result.
fallback(bytes calldata callData) external returns (bytes memory);
}// SPDX-License-Identifier: MIT
/* `MgvLib` contains data structures returned by external calls to Mangrove and the interfaces it uses for its own external calls. */
pragma solidity ^0.8.10;
import "@mgv/src/preprocessed/Structs.post.sol";
import {IERC20} from "@mgv/lib/IERC20.sol";
import {Density, DensityLib} from "@mgv/lib/core/DensityLib.sol";
import "@mgv/lib/core/TickTreeLib.sol";
import "@mgv/lib/core/TickLib.sol";
/* `OLKey` (for "OfferListKey") contains the information that characterizes an offer list:
* `outbound_tkn`, token that goes from the maker to the taker (to remember the direction, imagine the token as going out of the Mangrove offer, towards the taker)
* `inbound_tkn`, token that goes from the taker to the maker (to remember the direction, imagine the token as going into Mangrove from the taker)
* `tickSpacing`, how many ticks should be jumped between available price points. More volatile outbound/inbound pairs should have a larger `tickSpacing`. */
struct OLKey {
address outbound_tkn;
address inbound_tkn;
uint tickSpacing;
}
/* Globally enable `olKey.method(...)` */
using OLLib for OLKey global;
library OLLib {
/* The id of an `OLKey` should be `keccak256(abi.encode(olKey))`
To save gas, `id()` directly hashes the memory (which matches the ABI encoding; there is a fuzz test on that). If the memory layout changes, this function must be updated. */
function hash(OLKey memory olKey) internal pure returns (bytes32 _id) {
assembly ("memory-safe") {
_id := keccak256(olKey, 96)
}
}
/* Creates a flipped copy of the `olKey` with same `tickSpacing`. */
function flipped(OLKey memory olKey) internal pure returns (OLKey memory) {
return OLKey(olKey.inbound_tkn, olKey.outbound_tkn, olKey.tickSpacing);
}
/* Convert `tick` to bin according to `olKey.tickSpacing` */
function nearestBin(OLKey memory olKey, Tick _tick) internal pure returns (Bin) {
return _tick.nearestBin(olKey.tickSpacing);
}
/* Convert `bin` to `tick` according to `olKey.tickSpacing` */
function tick(OLKey memory olKey, Bin bin) internal pure returns (Tick) {
return bin.tick(olKey.tickSpacing);
}
}
/* # Structs
The structs defined in `structs.js` have their counterpart as solidity structs that are easy to manipulate for outside contracts / callers of view functions. */
library MgvLib {
/*
Some miscellaneous data types useful to `Mangrove` and external contracts */
//+clear+
/* `SingleOrder` holds data about an order-offer match in a struct. Used by `marketOrder` (and some of its nested functions) to avoid stack too deep errors. It is used in market order and cleaning. */
struct SingleOrder {
OLKey olKey;
uint offerId;
/* The `offer` given to the maker will be cleaned of `prev`/`next` pointers. */
Offer offer;
/* `takerWants`/`takerGives` mutate over execution. Initially the `wants`/`gives` from the taker's pov, then actual `wants`/`gives` adjusted by offer's price and volume. */
uint takerWants;
uint takerGives;
/* `offerDetail` is only populated when necessary. */
OfferDetail offerDetail;
Global global;
/* The `local` given to the maker will be cleaned of tick tree information. */
Local local;
}
/* <a id="MgvLib/OrderResult"></a> `OrderResult` holds additional data for the maker and is given to them _after_ they fulfilled an offer. It gives them their own returned data from the previous call and an `mgvData` specifying whether Mangrove encountered an error. */
struct OrderResult {
/* `makerData` holds a message that was either returned by the maker or passed as revert message at the end of the trade execution*/
bytes32 makerData;
/* `mgvData` is an [internal Mangrove status code](#MgvOfferTaking/statusCodes) code. */
bytes32 mgvData;
}
/* `CleanTarget` holds data about an offer that should be cleaned, i.e. made to fail by executing it with the specified volume. It is used in `MgvOfferTaking.cleanByImpersonation`. */
struct CleanTarget {
uint offerId;
Tick tick;
uint gasreq;
uint takerWants;
}
}
/* # Events
The events emitted are listed here: */
interface HasMgvEvents {
/*
Events in solidity is a hard thing to do in a optimal way. If you look at it as a purely gas efficient issue, you want to emit as few events as possible and with as few fields as possible. But as events also has to be usable for an off chain user, then doing this is not always the best solution.
We tried to list the main forces that drive which events and data to emit:
1. Use as little gas as possible.
2. An indexer should be able to keep track of the state of Mangrove.
3. Doing RPC calls directly, should be able to find offers and other information based on offer list, maker, taker, offer id, etc.
These forces are in conflict and it is impossible to find a solution that is optimal for all three.
The following events are therefore an attempt to balance the trade-offs.
*/
/* ### Mangrove Creation
Emitted at the creation of the new Mangrove contract */
event NewMgv();
/* ### Mangrove adds or removes wei from `maker`'s account */
/*
* Credit event occurs when an offer is removed from Mangrove or when the `fund` function is called
This is emitted when a user's account on Mangrove is credited with some native funds, to be used as provision for offers.
It emits the `maker`'s address and the `amount` credited
The `maker` address is indexed so that we can filter on it when doing RPC calls.
These are the scenarios where it can happen:
- Fund Mangrove directly
- Fund Mangrove when posting an offer
- When updating an offer
- Funding Mangrove or
- the updated offer needs less provision, than it already has. Meaning the user gets credited the difference.
- When retracting an offer and deprovisioning it. Meaning the user gets credited the provision that was locked by the offer.
- When an offer fails. The remaining provision gets credited back to the maker
A challenge for an indexer is to know how much provision each offer locks. With the current events, an indexer is going to have to know the liveness, gasreq and gasprice of the offer. If the offer is not live, then also know if it has been deprovisioned. And know what the gasbase of the offer list was when the offer was posted. With this information an indexer can calculate the exact provision locked by the offer.
The indexer also cannot deduce what scenario the credit event happened. E.g., we don't know if the credit event happened because an offer failed or because the user simply funded Mangrove.
*/
event Credit(address indexed maker, uint amount);
/*
* Debit event occurs when an offer is posted or when the `withdraw` function is called
This is emitted when a user's account on Mangrove is debited with some native funds.
It emits the `maker`'s address and the `amount` debited.
The `maker` address is indexed so that we can filter on it when doing RPC calls.
These are the scenarios where it can happen:
- Withdraw funds from Mangrove directly
- When posting an offer. The user gets debited the provision that the offer locks.
- When updating an offer and it requires more provision that it already has. Meaning the user gets debited the difference.
Same challenges as for Credit
*/
event Debit(address indexed maker, uint amount);
/* ### Mangrove reconfiguration */
/*
This event is emitted when an offer list is activated or deactivated. Meaning one half of a market is opened.
It emits the `olKeyHash` and the boolean `value`. By emitting this, an indexer will be able to keep track of what offer lists are active and what their hash is.
The `olKeyHash` and both token addresses are indexed, so that we can filter on it when doing RPC calls.
*/
event SetActive(
bytes32 indexed olKeyHash, address indexed outbound_tkn, address indexed inbound_tkn, uint tickSpacing, bool value
);
/*
This event is emitted when the fee of an offer list is changed.
It emits the `olKeyHash` and the `value`. By emitting this, an indexer will be able to keep track of what fee each offer list has.
The `olKeyHash` is indexed, so that we can filter on it when doing RPC calls.
*/
event SetFee(bytes32 indexed olKeyHash, uint value);
/*
This event is emitted when the gasbase of an offer list is changed.
It emits the `olKeyHash` and the `offer_gasbase`. By emitting this, an indexer will be able to keep track of what gasbase each offer list has.
The `olKeyHash` is indexed, so that we can filter on it when doing RPC calls.
*/
event SetGasbase(bytes32 indexed olKeyHash, uint offer_gasbase);
/*
This event is emitted when the governance of Mangrove is set.
It emits the `governance` address. By emitting this, an indexer will be able to keep track of what governance address Mangrove has.
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetGovernance(address value);
/*
This event is emitted when the monitor address of Mangrove is set. Be aware that the address for Monitor is also the address for the oracle.
It emits the `monitor` / `oracle` address. By emitting this, an indexer will be able to keep track of what monitor/oracle address Mangrove use.
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetMonitor(address value);
/*
This event is emitted when the configuration for whether to use an oracle or not is set.
It emits the `useOracle`, which is a boolean value, that controls whether or not Mangrove reads its `gasprice` and `density` from an oracle or uses its own local values. By emitting this, an indexer will be able to keep track of if Mangrove is using an oracle.
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetUseOracle(bool value);
/*
This event is emitted when the configuration for notify on Mangrove is set.
It emits a boolean value, to tell whether or not notify is active. By emitting this, an indexer will be able to keep track of whether or not Mangrove notifies the Monitor/Oracle when and offer is taken, either successfully or not.
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetNotify(bool value);
/*
This event is emitted when the gasmax of Mangrove is set.
It emits the `gasmax`. By emitting this, an indexer will be able to keep track of what gasmax Mangrove has. Read more about Mangroves gasmax on [docs.mangrove.exchange](https://docs.mangrove.exchange)
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetGasmax(uint value);
/*
This event is emitted when the density of an offer list is changed.
It emits the `olKeyHash` and the `density`. By emitting this, an indexer will be able to keep track of what density each offer list has.
The `olKeyHash` is indexed, so that we can filter on it when doing RPC calls.
*/
event SetDensity96X32(bytes32 indexed olKeyHash, uint value);
/*
This event is emitted when the max recursion depth of Mangrove is set.
It emits the max depth `value`. By emitting this, an indexer will be able to keep track of what max recursion depth Mangrove has. Read more about Mangroves max recursion depth on [docs.mangrove.exchange](https://docs.mangrove.exchange)
*/
event SetMaxRecursionDepth(uint value);
/*
This event is emitted when the max gasreq for failing offers of Mangrove is set.
It emits the max gasreq for failing offers `value`. By emitting this, an indexer will be able to keep track of what max gasreq for failing offers Mangrove has. Read more about Mangroves max gasreq for failing offers on [docs.mangrove.exchange](https://docs.mangrove.exchange)
*/
event SetMaxGasreqForFailingOffers(uint value);
/*
This event is emitted when the gasprice of Mangrove is set.
It emits the `gasprice`. By emitting this, an indexer will be able to keep track of what gasprice Mangrove has. Read more about Mangroves gasprice on [docs.mangrove.exchange](https://docs.mangrove.exchange)
No fields are indexed as there is no need for RPC calls to filter on this.
*/
event SetGasprice(uint value);
/* ### Clean order execution */
/*
This event is emitted when a user tries to clean offers on Mangrove, using the build in clean functionality.
It emits the `olKeyHash`, the `taker` address and `offersToBeCleaned`, which is the number of offers that should be cleaned. By emitting this event, an indexer can save what `offer list` the user is trying to clean and what `taker` is being used.
This way it can keep a context for the following events being emitted (Just like `OrderStart`). The `offersToBeCleaned` is emitted so that an indexer can keep track of how many offers the user tried to clean.
Combining this with the amount of `OfferFail` events emitted, then an indexer can know how many offers the user actually managed to clean. This could be used for analytics.
The fields `olKeyHash` and `taker` are indexed, so that we can filter on them when doing RPC calls.
*/
event CleanStart(bytes32 indexed olKeyHash, address indexed taker, uint offersToBeCleaned);
/*
This event is emitted when a Clean operation is completed.
It does not emit any fields. This event is only needed in order to know that the clean operation is completed. This way an indexer can know exactly in what context we are in.
It could emit the total bounty received, but in order to know who got the bounty, an indexer would still be needed or we would have to emit the taker address as well, in order for an RPC call to find the data.
But an indexer would still be able to find this info, by collecting all the previous events. So we do not emit the bounty.
*/
event CleanComplete();
/* ### Market order execution */
/*
This event is emitted when a market order is started on Mangrove.
It emits the `olKeyHash`, the `taker`, the `maxTick`, `fillVolume` and `fillWants`.
The fields `olKeyHash` and `taker` are indexed, so that we can filter on them when doing RPC calls.
By emitting this an indexer can keep track of what context the current market order is in.
E.g. if a user starts a market order and one of the offers taken also starts a market order, then we can in an indexer have a stack of started market orders and thereby know exactly what offer list the order is running on and the taker.
By emitting `maxTick`, `fillVolume` and `fillWants`, we can now also know how much of the market order was filled and if it matches the price given. See OrderComplete for more.
*/
event OrderStart(bytes32 indexed olKeyHash, address indexed taker, Tick maxTick, uint fillVolume, bool fillWants);
/*
This event is emitted when a market order is finished.
It emits `olKeyHash`, the `taker` and the total `fee paid`. We need this event, in order to know that a market order is completed. This way an indexer can know exactly in what context we are in.
The total `fee paid` for that market order, is needed, as we do not emit this any other places. The fields `olKeyHash` and `taker` is not needed for an indexer, but they are emitted and indexed in order for RPC calls to filter and find the fee.
*/
event OrderComplete(bytes32 indexed olKeyHash, address indexed taker, uint fee);
/* ### Offer execution */
/*
This event is emitted when an offer is successfully taken. Meaning both maker and taker has gotten their funds.
It emits the `olKeyHash`, `taker` address, the `offerId` and the `takerWants` and `takerGives` that the offer was taken at.
Just as for `OfferFail`, the `olKeyHash` and `taker` are not needed for an indexer to work, but are needed for RPC calls.
`olKeyHash` `taker` and `id` are indexed so that we can filter on them when doing RPC calls. As `maker` can be a strategy and not the actual owner, then we chose not to emit it here and to mark the field `id` indexed,
the strat should emit the relation between maker and offerId. This way you can still by RPC calls find the relevant offer successes
So they are emitted and indexed for that reason. Just like `OfferFail` this event is emitted during posthook end, so it is emitted in reverse order compared to what order they are taken.
This event could be emitted at offer execution, but for consistency we emit it at posthook end.
If the posthook of the offer fails. Then we emit `OfferSuccessWithPosthookData` instead of just `OfferSuccess`. This event has one extra field, which is the reason for the posthook failure.
By emitting the posthook data, an indexer can keep track of the reason posthook fails, this could for example be used for analytics.
By emitting `offerId`, `wants` and `gives`, an indexer can keep track of whether the offer was partially or fully taken, by looking at the what the offer was posted at.
*/
event OfferSuccess(
bytes32 indexed olKeyHash, address indexed taker, uint indexed id, uint takerWants, uint takerGives
);
event OfferSuccessWithPosthookData(
bytes32 indexed olKeyHash,
address indexed taker,
uint indexed id,
uint takerWants,
uint takerGives,
bytes32 posthookData
);
/*
This event is emitted when an offer fails, because of a maker error.
It emits `olKeyHash`, `taker`, the `offerId`, the offers `takerWants`, `takerGives`, `penalty` and the `reason` for failure.
`olKeyHash` and `taker` are all fields that we do not need, in order for an indexer to work, as an indexer will be able the get that info from the former `OrderStart` and `OfferWrite` events.
But in order for RPC call to filter on this, we need to emit them.
`olKeyHash` `taker` and `id` are indexed so that we can filter on them when doing RPC calls. As `maker` can be a strategy and not the actual owner, then we chose to not emit it here and to mark the field `id` indexed,
the strat should emit the relation between maker and offerId. This way you can still by RPC calls find the relevant offer successes
If the posthook of the offer fails. Then we emit `OfferFailWithPosthookData` instead of just `OfferFail`.
This event has one extra field, which is the reason for the posthook failure. By emitting the posthook data, an indexer can keep track of the reason posthook fails, this could for example be used for analytics.
This event is emitted during posthook end, we wait to emit this event to the end, because we need the information of `penalty`, which is only available at the end of the posthook.
This means that `OfferFail` events are emitted in reverse order, compared to what order they are taken. This is due to the way we handle posthooks. The same goes for `OfferSuccess`.
By emitting this event, an indexer can keep track of, if an offer failed and thereby if the offer is live.
By emitting the `takerWants` and `takerGives` that the offer was taken with, then an indexer can keep track of these amounts, which could be useful for e.g. strategy manager, to know if their offers fail at a certain amount.
*/
event OfferFail(
bytes32 indexed olKeyHash,
address indexed taker,
uint indexed id,
uint takerWants,
uint takerGives,
uint penalty,
// `mgvData` may only be `"mgv/makerRevert"`, `"mgv/makerTransferFail"` or `"mgv/makerReceiveFail"`
bytes32 mgvData
);
event OfferFailWithPosthookData(
bytes32 indexed olKeyHash,
address indexed taker,
uint indexed id,
uint takerWants,
uint takerGives,
uint penalty,
// `mgvData` may only be `"mgv/makerRevert"`, `"mgv/makerTransferFail"` or `"mgv/makerReceiveFail"`
bytes32 mgvData,
bytes32 posthookData
);
/*
### After `permit` and `approve`
This is emitted when a user permits another address to use a certain amount of its funds to do market orders, or when a user revokes another address to use a certain amount of its funds.
Approvals are based on the pair of outbound and inbound token. Be aware that it is not offer list bases, as an offer list also holds the tick spacing.
We emit `outbound` token, `inbound` token, `owner`, msg.sender (`spender`), `value`. Where `owner` is the one who owns the funds, `spender` is the one who is allowed to use the funds and `value` is the amount of funds that is allowed to be used.
Outbound, inbound and owner is indexed, this way one can filter on these fields when doing RPC calls. If we could somehow combine outbound and inbound into one field, then we could also index the spender.
*/
event Approval(
address indexed outbound_tkn, address indexed inbound_tkn, address indexed owner, address spender, uint value
);
/* ### Mangrove closure */
event Kill();
/* ### An offer was created or updated.
This event is emitted when an offer is posted on Mangrove.
It emits the `olKeyHash`, the `maker` address, the `tick`, the `gives`, the `gasprice`, `gasreq` and the offers `id`.
By emitting the `olKeyHash` and `id`, an indexer will be able to keep track of each offer, because offer list and id together create a unique id for the offer. By emitting the `maker` address, we are able to keep track of who has posted what offer. The `tick` and `gives`, enables an indexer to know exactly how much an offer is willing to give and at what price, this could for example be used to calculate a return. The `gasprice` and `gasreq`, enables an indexer to calculate how much provision is locked by the offer, see `Credit` for more information.
The fields `olKeyHash` and `maker` are indexed, so that we can filter on them when doing RPC calls.
*/
event OfferWrite(
bytes32 indexed olKeyHash, address indexed maker, int tick, uint gives, uint gasprice, uint gasreq, uint id
);
/*
This event is emitted when a user retracts his offer.
It emits the `olKeyHash`, the `maker` address, `offerId` and whether or not the user chose to `deprovision` the offer.
By emitting this event an indexer knows whether or not an offer is live. And whether or not an offer is deprovisioned. This is important because we need to know this, when we try to calculate how much an offer locks in provision. See the description of `Credit` for more info.
The `maker` is not needed for an indexer to work, but is needed for RPC calls, so it is emitted and indexed for that reason. The `olKeyHash` is only indexed because it is needed for RPC calls.
*/
event OfferRetract(bytes32 indexed olKeyHash, address indexed maker, uint id, bool deprovision);
}
/* # IMaker interface */
interface IMaker {
/* Called upon offer execution.
- If the call throws, Mangrove will not try to transfer funds and the first 32 bytes of revert reason are passed to `makerPosthook` as `makerData`
- If the call returns normally, `returnData` is passed to `makerPosthook` as `makerData` and Mangrove will attempt to transfer the funds.
*/
function makerExecute(MgvLib.SingleOrder calldata order) external returns (bytes32);
/* Called after all offers of an order have been executed. Posthook of the last executed order is called first and full reentrancy into Mangrove is enabled at this time. `order` recalls key arguments of the order that was processed and `result` recalls important information for updating the current offer. (see [above](#MgvLib/OrderResult))*/
function makerPosthook(MgvLib.SingleOrder calldata order, MgvLib.OrderResult calldata result) external;
}
/* # Monitor interface
If enabled, the monitor receives notification after each offer execution and is read for each offer list's `gasprice` and `density`. */
interface IMgvMonitor {
function notifySuccess(MgvLib.SingleOrder calldata sor, address taker) external;
function notifyFail(MgvLib.SingleOrder calldata sor, address taker) external;
function read(OLKey memory olKey) external view returns (uint gasprice, Density density);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
enum YieldMode {
AUTOMATIC,
VOID,
CLAIMABLE
}
enum GasMode {
VOID,
CLAIMABLE
}
interface IBlast {
// configure
function configureContract(address contractAddress, YieldMode _yield, GasMode gasMode, address governor) external;
function configure(YieldMode _yield, GasMode gasMode, address governor) external;
// base configuration options
function configureClaimableYield() external;
function configureClaimableYieldOnBehalf(address contractAddress) external;
function configureAutomaticYield() external;
function configureAutomaticYieldOnBehalf(address contractAddress) external;
function configureVoidYield() external;
function configureVoidYieldOnBehalf(address contractAddress) external;
function configureClaimableGas() external;
function configureClaimableGasOnBehalf(address contractAddress) external;
function configureVoidGas() external;
function configureVoidGasOnBehalf(address contractAddress) external;
function configureGovernor(address _governor) external;
function configureGovernorOnBehalf(address _newGovernor, address contractAddress) external;
// claim yield
function claimYield(address contractAddress, address recipientOfYield, uint amount) external returns (uint);
function claimAllYield(address contractAddress, address recipientOfYield) external returns (uint);
// claim gas
function claimAllGas(address contractAddress, address recipientOfGas) external returns (uint);
function claimGasAtMinClaimRate(address contractAddress, address recipientOfGas, uint minClaimRateBips)
external
returns (uint);
function claimMaxGas(address contractAddress, address recipientOfGas) external returns (uint);
function claimGas(address contractAddress, address recipientOfGas, uint gasToClaim, uint gasSecondsToConsume)
external
returns (uint);
// read functions
function readClaimableYield(address contractAddress) external view returns (uint);
function readYieldConfiguration(address contractAddress) external view returns (uint8);
function readGasParams(address contractAddress)
external
view
returns (uint etherSeconds, uint etherBalance, uint lastUpdated, GasMode);
function isGovernor(address contractAddress) external view returns (bool);
function governorNotSet(address contractAddress) external view returns (bool);
function isAuthorized(address contractAddress) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
/// @title IBlastPoints
/// @notice Interface to configure Blast Points
/// @dev Copied from the following sources on 2024-02-27:
/// - https://blastpublic.notion.site/PUBLIC-Blast-Mainnet-Points-API-f8abea9d6e67417890d4a300ecbe5827
/// - https://testnet.blastscan.io/address/0x2fc95838c71e76ec69ff817983BFf17c710F34E0/contract/168587773/code
interface IBlastPoints {
/// @notice Set the Blast Points operator for the calling contract.
/// @param operator The address of the Blast Points operator.
/// @dev Note that the operator address should be an EOA whose private key is accessible
/// to an internet connected server. We recommended setting this value to a distinct
/// address so that other admin responsibilities are not co-mingled with this address,
/// whose key must live on a hot server.
function configurePointsOperator(address operator) external;
function isOperator(address contractAddress) external view returns (bool);
function isAuthorized(address contractAddress) external view returns (bool);
function configurePointsOperatorOnBehalf(address contractAddress, address newOperator) external;
function readStatus(address contractAddress) external view returns (address operator, bool isBanned, uint codeLength);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {AccessControlled} from "@mgv-strats/src/strategies/utils/AccessControlled.sol";
import {IOfferLogic} from "@mgv-strats/src/strategies/interfaces/IOfferLogic.sol";
import {MgvLib, IERC20, OLKey, OfferDetail} from "@mgv/src/core/MgvLib.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {AbstractRouter, RL} from "@mgv-strats/src/strategies/routers/abstract/AbstractRouter.sol";
import {TransferLib} from "@mgv/lib/TransferLib.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
/// @title This contract is the basic building block for Mangrove strats.
/// @notice It contains the mandatory interface expected by Mangrove (`IOfferLogic` is `IMaker`) and enforces additional functions implementations (via `IOfferLogic`).
/// @dev Naming scheme:
/// `f() public`: can be used, as is, in all descendants of `this` contract
/// `_f() internal`: descendant of this contract should provide a public wrapper for this function, with necessary guards.
/// `__f__() virtual internal`: descendant of this contract should override this function to specialize it to the needs of the strat.
abstract contract MangroveOffer is AccessControlled, IOfferLogic {
///@notice The Mangrove deployment that is allowed to call `this` for trade execution and posthook.
IMangrove public immutable MGV;
/// @notice router contract which implements routing functions -- this can be 0x in Direct strats
AbstractRouter public immutable ROUTER_IMPLEMENTATION;
///@notice The offer was successfully reposted.
bytes32 internal constant REPOST_SUCCESS = "offer/updated";
///@notice New offer successfully created.
bytes32 internal constant NEW_OFFER_SUCCESS = "offer/created";
///@notice The offer was completely filled.
bytes32 internal constant COMPLETE_FILL = "offer/filled";
///@notice Mandatory function to allow `this` to receive native tokens
///@dev this happens when `this` calls `withdrawFromMangrove` with `deprovision=true` or if `this` becomes the recipient of a `makerExecute` bounty.
receive() external payable virtual {}
/**
* @notice `MangroveOffer`'s constructor
* @param mgv The Mangrove deployment that is allowed to call `this` for trade execution and posthook.
* @param routerImplementation sets the type of router that the router factory can spawn
*/
constructor(IMangrove mgv, AbstractRouter routerImplementation) AccessControlled(msg.sender) {
require(address(mgv) != address(0), "MgvOffer/0xMangrove");
MGV = mgv;
ROUTER_IMPLEMENTATION = routerImplementation; // this may be 0x
}
///*****************************
/// Mandatory callback functions
///*****************************
///@notice `makerExecute` is the callback function to execute all offers that were posted on Mangrove by `this` contract.
///@param order a data structure that recapitulates the taker order and the offer as it was posted on mangrove
///@return ret a bytes32 word to pass information (if needed) to the posthook (under `result.makerData`)
///@dev it may not be overriden although it can be customized using `__lastLook__`, `__put__` and `__get__` hooks.
/// NB #1: if `makerExecute` reverts, the offer will be considered to be refusing the trade.
/// NB #2: `makerExecute` may return a `bytes32` word to pass information to posthook w/o using storage reads/writes.
/// NB #3: Reneging on trade will have the following effects:
/// * Offer is removed from the Offer List
/// * Offer bounty will be withdrawn from offer provision and sent to the offer taker. The remaining provision will be credited to `this` contract's account on Mangrove
function makerExecute(MgvLib.SingleOrder calldata order)
external
override
onlyCaller(address(MGV))
returns (bytes32 ret)
{
// Invoke hook that implements a last look check during execution - it may renege on trade by reverting.
ret = __lastLook__(order);
// Invoke hook to put the inbound_tkn, which are brought by the taker, into a specific reserve.
require(__put__(order.takerGives, order) == 0, "mgvOffer/abort/putFailed");
// Invoke hook to fetch the outbound_tkn, which are promised to the taker, from a specific reserve.
require(__get__(order.takerWants, order) == 0, "mgvOffer/abort/getFailed");
}
/// @notice `makerPosthook` is the callback function that is called by Mangrove *after* the offer execution.
/// @notice reverting during its execution will not renege on trade. Revert reason (casted to 32 bytes) is then logged by Mangrove in event `PosthookFail`.
/// @param order a data structure that recapitulates the taker order and the offer as it was posted on mangrove
/// @param result a data structure that gathers information about trade execution
/// @dev It cannot be overridden but can be customized via the hooks `__posthookSuccess__`, `__posthookFallback__` and `__handleResidualProvision__` (see below).
function makerPosthook(MgvLib.SingleOrder calldata order, MgvLib.OrderResult calldata result)
external
override
onlyCaller(address(MGV))
{
if (result.mgvData == "mgv/tradeSuccess") {
__posthookSuccess__(order, result.makerData);
} else {
// logging what went wrong during `makerExecute`
emit LogIncident(order.olKey.hash(), order.offerId, result.makerData, result.mgvData);
// calling strat specific handlers in case of failure
__posthookFallback__(order, result);
__handleResidualProvision__(order);
}
}
///@notice whether this contract has enabled liquidity routing
///@return true if this contracts routes liquidity using an external router
function _isRouting() internal view returns (bool) {
return address(ROUTER_IMPLEMENTATION) != address(0);
}
///@notice takes care of status for reposting residual offer in case of a partial fill and logging of potential issues.
///@param order a recap of the taker order
///@param makerData generated during `makerExecute` so as to log it if necessary
///@param repostStatus from the posthook that handles residual reposting
function logRepostStatus(MgvLib.SingleOrder calldata order, bytes32 makerData, bytes32 repostStatus) internal {
// reposting below density is not considered an incident in order to allow the contract not to check density before posting residual
if (
repostStatus == COMPLETE_FILL || repostStatus == REPOST_SUCCESS || repostStatus == "mgv/writeOffer/density/tooLow"
) {
return;
} else {
// Offer failed to repost for bad reason, logging the incident
emit LogIncident(order.olKey.hash(), order.offerId, makerData, repostStatus);
}
}
/// @inheritdoc IOfferLogic
function approve(IERC20 token, address spender, uint amount) public override onlyAdmin returns (bool) {
require(TransferLib.approveToken(token, spender, amount), "mgvOffer/approve/failed");
return true;
}
/// @inheritdoc IOfferLogic
function withdrawFromMangrove(uint amount, address payable receiver) public onlyAdmin {
if (amount == type(uint).max) {
amount = MGV.balanceOf(address(this));
}
// the require below is necessary if the `receive()` function is overriden
require(MGV.withdraw(amount), "mgvOffer/withdrawFail");
(bool noRevert,) = receiver.call{value: amount}("");
// if `receiver` is actually not payable
require(noRevert, "mgvOffer/weiTransferFail");
}
///@notice Hook that implements where the inbound token, which are brought by the Offer Taker, should go during Taker Order's execution.
///@param amount of `inbound` tokens that are on `this` contract's balance and still need to be deposited somewhere
///@param order is a recall of the taker order that is at the origin of the current trade.
///@return missingPut (<=`amount`) is the amount of `inbound` tokens whose deposit location has not been decided (possibly because of a failure) during this function execution
///@dev if the last nested call to `__put__` returns a non zero value, trade execution will revert
function __put__(uint amount, MgvLib.SingleOrder calldata order) internal virtual returns (uint missingPut);
///@notice Hook that implements where the outbound token, which are promised to the taker, should be fetched from, during Taker Order's execution.
///@param amount of `outbound` tokens that still needs to be brought to the balance of `this` contract when entering this function
///@param order is a recall of the taker order that is at the origin of the current trade.
///@return missingGet (<=`amount`), which is the amount of `outbound` tokens still need to be fetched at the end of this function
///@dev if the last nested call to `__get__` returns a non zero value, trade execution will revert
function __get__(uint amount, MgvLib.SingleOrder calldata order) internal virtual returns (uint missingGet);
/// @notice Hook that implements a last look check during Taker Order's execution.
/// @param order is a recall of the taker order that is at the origin of the current trade.
/// @return data is a message that will be passed to posthook provided `makerExecute` does not revert.
/// @dev __lastLook__ should revert if trade is to be reneged on. If not, returned `bytes32` are passed to `makerPosthook` in the `makerData` field.
/// @custom:hook overrides of this hook should be conservative and call `super.__lastLook__(order)`.
function __lastLook__(MgvLib.SingleOrder calldata order) internal virtual returns (bytes32 data) {
order; //shh
data = bytes32(0);
}
/// @inheritdoc IOfferLogic
function activate(IERC20 token) public virtual override {
require(TransferLib.approveToken(token, address(MGV), type(uint).max), "MgvOffer/ActivationFailed");
}
///@notice Post-hook that implements fallback behavior when Taker Order's execution failed unexpectedly.
///@param order is a recall of the taker order that is at the origin of the current trade.
///@param result contains information about trade.
///@return data contains verdict and reason about the executed trade.
///@dev `result.mgvData` is Mangrove's verdict about trade success
///@dev `result.makerData` either contains the first 32 bytes of revert reason if `makerExecute` reverted or the returned `bytes32`.
/// @custom:hook overrides of this hook should be conservative and call `super.__posthookFallback__(order, result)`
function __posthookFallback__(MgvLib.SingleOrder calldata order, MgvLib.OrderResult calldata result)
internal
virtual
returns (bytes32 data)
{
order;
result;
data = bytes32(0);
}
///@notice Given the current taker order that (partially) consumes an offer, this hook is used to declare how much `order.olKey.outbound_tkn` the offer gives after it is reposted, while also allowing adjustment to the tick.
///@param order is a recall of the taker order that is being treated.
///@return newGives the new volume of `outbound_tkn` the offer will give if fully taken.
///@return newTick the new tick of the reposted offer.
///@dev default is to require the original amount of tokens minus those that have been sent to the taker during trade execution and keep the tick.
function __residualValues__(MgvLib.SingleOrder calldata order) internal virtual returns (uint newGives, Tick newTick) {
newGives = order.offer.gives() - order.takerWants;
newTick = order.offer.tick();
}
///@notice Hook that defines what needs to be done to the part of an offer provision that was added to the balance of `this` on Mangrove after an offer has failed.
///@param order is a recall of the taker order that failed
function __handleResidualProvision__(MgvLib.SingleOrder calldata order) internal virtual {
order; // we leave the provision on Mangrove
}
///@notice Post-hook that implements default behavior when Taker Order's execution succeeded.
///@param order is a recall of the taker order that is at the origin of the current trade.
///@param makerData is the returned value of the `__lastLook__` hook, triggered during trade execution. The special value `"lastLook/retract"` should be treated as an instruction not to repost the offer on the list.
///@return data can be:
/// * `COMPLETE_FILL` when offer was completely filled
/// * returned data of `_updateOffer` signalling the status of the reposting attempt.
/// @custom:hook overrides of this hook should be conservative and call `super.__posthookSuccess__(order, maker_data)`
function __posthookSuccess__(MgvLib.SingleOrder calldata order, bytes32 makerData)
internal
virtual
returns (bytes32 data)
{
// now trying to repost residual
(uint newGives, Tick newTick) = __residualValues__(order);
// Density check at each repost would be too gas costly.
// We only treat the special case of `gives==0` or `wants==0` (total fill).
// Note: wants (given by `inboundFromOutbound`) can be 0 due to rounding given the price. We could repost to get rid of the last gives at 0 wants,
// but the maker does not need to give away these tokens for free, so we skip it.
// Offer below the density will cause Mangrove to throw so we encapsulate the call to `updateOffer` in order not to revert posthook for posting at dust level.
if (newGives == 0 || newTick.inboundFromOutbound(newGives) == 0) {
return COMPLETE_FILL;
}
data = _updateOffer(
OfferArgs({
olKey: order.olKey,
tick: newTick,
gives: newGives,
gasreq: order.offerDetail.gasreq(),
gasprice: order.offerDetail.gasprice(),
noRevert: true,
fund: 0
}),
order.offerId
);
// logs if anything went wrong
logRepostStatus(order, makerData, data);
}
///@notice Updates the offer specified by `offerId` on Mangrove with the parameters in `args`.
///@param args A memory struct containing the offer parameters to update.
///@param offerId An unsigned integer representing the identifier of the offer to be updated.
///@return status a `bytes32` value representing either `REPOST_SUCCESS` if the update is successful, or an error message if an error occurs and `OfferArgs.noRevert` is `true`. If `OfferArgs.noRevert` is `false`, the function reverts with the error message as the reason.
function _updateOffer(OfferArgs memory args, uint offerId) internal virtual returns (bytes32);
///@notice computes the provision that can be redeemed if deprovisioning a certain offer
///@param olKey the offer list key.
///@param offerId the id of the offer
///@return provision the provision that can be redeemed
function _provisionOf(OLKey memory olKey, uint offerId) internal view returns (uint provision) {
OfferDetail offerDetail = MGV.offerDetails(olKey, offerId);
unchecked {
provision = offerDetail.gasprice() * 1e6 * (offerDetail.offer_gasbase() + offerDetail.gasreq());
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {CoreKandel} from "./CoreKandel.sol";
import {MAX_TICK, MIN_TICK} from "@mgv/lib/core/Constants.sol";
import {OLKey} from "@mgv/src/core/MgvLib.sol";
import {KandelLib} from "./KandelLib.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
///@title Adds a geometric price progression to a `CoreKandel` strat without storing prices for individual price points.
abstract contract GeometricKandel is CoreKandel {
///@notice The tick offset for absolute price used for the on-chain geometric progression deployment in `createDistribution`. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param value the tick offset.
event SetBaseQuoteTickOffset(uint value);
///@notice By emitting this data, an indexer will be able to keep track of what the stepSize and tickOffset is for the Kandel instance.
///@notice The tick offset for absolute price used for the on-chain geometric progression deployment in `createDistribution`. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
uint public baseQuoteTickOffset;
///@notice Constructor
///@param mgv The Mangrove deployment.
///@param olKeyBaseQuote The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
///@param routerParams parameters if this contract is using a router
constructor(IMangrove mgv, OLKey memory olKeyBaseQuote, RouterParams memory routerParams)
CoreKandel(mgv, olKeyBaseQuote, routerParams)
{}
///@notice sets the tick offset if different from existing.
///@param _baseQuoteTickOffset the new tick offset.
function setBaseQuoteTickOffset(uint _baseQuoteTickOffset) public onlyAdmin {
require(uint24(_baseQuoteTickOffset) == _baseQuoteTickOffset, "Kandel/tickOffsetTooHigh");
if (baseQuoteTickOffset != _baseQuoteTickOffset) {
baseQuoteTickOffset = _baseQuoteTickOffset;
emit SetBaseQuoteTickOffset(_baseQuoteTickOffset);
}
}
///@notice Creates a distribution of bids and asks given by the parameters. Dual offers are included with gives=0.
///@param from populate offers starting from this index (inclusive). Must be at most `pricePoints`.
///@param to populate offers until this index (exclusive). Must be at most `pricePoints`.
///@param baseQuoteTickIndex0 the tick for the price point at index 0 given as a tick on the `base, quote` offer list, i.e. corresponding to an ask with a quote/base ratio. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param _baseQuoteTickOffset the tick offset used for the geometric progression deployment. Must be at least 1. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param firstAskIndex the (inclusive) index after which offer should be an ask. Must be at most `pricePoints`.
///@param bidGives The initial amount of quote to give for all bids. If 0, only book the offer, if type(uint).max then askGives is used as base for bids, and the quote the bid gives is set to according to the price.
///@param askGives The initial amount of base to give for all asks. If 0, only book the offer, if type(uint).max then bidGives is used as quote for asks, and the base the ask gives is set to according to the price.
///@param stepSize in amount of price points to jump for posting dual offer. Must be less than `pricePoints`.
///@param pricePoints the number of price points for the Kandel instance. Must be at least 2.
///@return distribution the distribution of bids and asks to populate
///@dev the absolute price of an offer is the ratio of quote/base volumes of tokens it trades
///@dev the tick of offers on Mangrove are in relative taker price of maker's inbound/outbound volumes of tokens it trades
///@dev for Bids, outbound_tkn=quote, inbound_tkn=base so relative taker price of a a bid is the inverse of the absolute price.
///@dev for Asks, outbound_tkn=base, inbound_tkn=quote so relative taker price of an ask coincides with absolute price.
///@dev Index0 will contain the ask with the lowest relative price and the bid with the highest relative price. Absolute price is geometrically increasing over indexes.
///@dev tickOffset moves an offer relative price s.t. `AskTick_{i+1} = AskTick_i + tickOffset` and `BidTick_{i+1} = BidTick_i - tickOffset`
///@dev A hole is left in the middle at the size of stepSize - either an offer or its dual is posted, not both.
///@dev The caller should make sure the minimum and maximum tick does not exceed the MIN_TICK and MAX_TICK from respectively; otherwise, populate will fail for those offers.
///@dev If type(uint).max is used for `bidGives` or `askGives` then very high or low prices can yield gives=0 (which results in both offer an dual being dead) or gives>=type(uin96).max which is not supported by Mangrove.
function createDistribution(
uint from,
uint to,
Tick baseQuoteTickIndex0,
uint _baseQuoteTickOffset,
uint firstAskIndex,
uint bidGives,
uint askGives,
uint pricePoints,
uint stepSize
) public pure returns (Distribution memory distribution) {
return KandelLib.createGeometricDistribution(
from, to, baseQuoteTickIndex0, _baseQuoteTickOffset, firstAskIndex, bidGives, askGives, pricePoints, stepSize
);
}
///@notice publishes bids/asks according to a geometric distribution, and sets all parameters according to inputs.
///@param from populate offers starting from this index (inclusive).
///@param to populate offers until this index (exclusive).
///@param baseQuoteTickIndex0 the tick for the price point at index 0 given as a tick on the `base, quote` offer list, i.e. corresponding to an ask with a quote/base ratio. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param _baseQuoteTickOffset the tick offset used for the geometric progression deployment. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param firstAskIndex the (inclusive) index after which offer should be an ask.
///@param bidGives The initial amount of quote to give for all bids. If 0, only book the offer, if type(uint).max then askGives is used as base for bids, and the quote the bid gives is set to according to the price.
///@param askGives The initial amount of base to give for all asks. If 0, only book the offer, if type(uint).max then bidGives is used as quote for asks, and the base the ask gives is set to according to the price.
///@param parameters the parameters for Kandel. Only changed parameters will cause updates. Set `gasreq` and `gasprice` to 0 to keep existing values.
///@param baseAmount base amount to deposit
///@param quoteAmount quote amount to deposit
///@dev See `createDistribution` for further details.
function populateFromOffset(
uint from,
uint to,
Tick baseQuoteTickIndex0,
uint _baseQuoteTickOffset,
uint firstAskIndex,
uint bidGives,
uint askGives,
Params calldata parameters,
uint baseAmount,
uint quoteAmount
) public payable onlyAdmin {
if (msg.value > 0) {
MGV.fund{value: msg.value}();
}
setParams(parameters);
setBaseQuoteTickOffset(_baseQuoteTickOffset);
depositFunds(baseAmount, quoteAmount);
populateChunkFromOffset(from, to, baseQuoteTickIndex0, firstAskIndex, bidGives, askGives);
}
///@notice publishes bids/asks according to a geometric distribution, and reads parameters from the Kandel instance.
///@param from populate offers starting from this index (inclusive).
///@param to populate offers until this index (exclusive).
///@param baseQuoteTickIndex0 the tick for the price point at index 0 given as a tick on the `base, quote` offer list, i.e. corresponding to an ask with a quote/base ratio. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param firstAskIndex the (inclusive) index after which offer should be an ask.
///@param bidGives The initial amount of quote to give for all bids. If 0, only book the offer, if type(uint).max then askGives is used as base for bids, and the quote the bid gives is set to according to the price.
///@param askGives The initial amount of base to give for all asks. If 0, only book the offer, if type(uint).max then bidGives is used as quote for asks, and the base the ask gives is set to according to the price.
///@dev This is typically used after a call to `populateFromOffset` to populate the rest of the offers with the same parameters. See that function for further details.
function populateChunkFromOffset(
uint from,
uint to,
Tick baseQuoteTickIndex0,
uint firstAskIndex,
uint bidGives,
uint askGives
) public payable onlyAdmin {
Params memory parameters = params;
Distribution memory distribution = createDistribution(
from,
to,
baseQuoteTickIndex0,
baseQuoteTickOffset,
firstAskIndex,
bidGives,
askGives,
parameters.pricePoints,
parameters.stepSize
);
populateChunkInternal(distribution, parameters.gasreq, parameters.gasprice);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/* ************************************************** *
GENERATED FILE. DO NOT EDIT.
* ************************************************** */
import {Offer, OfferUnpacked, OfferLib} from "./Offer.post.sol";
import {OfferDetail, OfferDetailUnpacked, OfferDetailLib} from "./OfferDetail.post.sol";
import {Global, GlobalUnpacked, GlobalLib} from "./Global.post.sol";
import {Local, LocalUnpacked, LocalLib} from "./Local.post.sol";// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;
interface IERC20 {
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
function symbol() external view returns (string memory);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
function decimals() external view returns (uint8);
function name() external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Field} from "@mgv/lib/core/TickTreeLib.sol";
import {ONES} from "@mgv/lib/core/Constants.sol";
import {BitLib} from "@mgv/lib/core/BitLib.sol";
/*
The density of a semibook is the number of outbound tokens per gas required. An offer must a respect a semibook's density.
Density can be < 1.
The density of a semibook is stored as a 9 bits float. For convenience, governance functions read density as a 96.32 fixed point number. The functions below give conversion utilities between the two formats
As a guideline, fixed-point densities should be uints and should use hungarian notation (for instance `uint density96X32`). Floating-point densities should use the Density user-defined type.
The float <-> fixed conversion is format agnostic but the expectation is that fixed points are 96x32, and floats are 2-bit mantissa, 7bit exponent with bias 32.
The encoding is nonstandard so the code can be simpler.
There are no subnormal floats in this encoding, `[exp][mantissa]` means:
```
if exp is 0 or 1: 0bmantissa * 2^-32
otherwise: 0b1.mantissa * 2^(exp-32)
```
so the small values have some holes:
```
coeff exponent available | coeff exponent available
--------------------------------------------------------------
0b0.00 | 0b1.10 -31
0b1.00 -32 | 0b1.11 -31 no
0b1.01 -32 no | 0b1.00 -30
0b1.10 -32 no | 0b1.01 -30
0b1.11 -32 no | 0b1.10 -30
0b1.00 -31 | 0b1.11 -30
0b1.01 -31 no | 0b1.00 -29
```
*/
type Density is uint;
using DensityLib for Density global;
library DensityLib {
/* Numbers in this file assume that density is 9 bits in structs.ts */
uint constant BITS = 9; // must match structs.ts
uint constant MANTISSA_BITS = 2;
uint constant SUBNORMAL_LIMIT = ~(ONES << (MANTISSA_BITS+1));
uint constant MANTISSA_MASK = ~(ONES << MANTISSA_BITS);
uint constant MASK = ~(ONES << BITS);
uint constant MANTISSA_INTEGER = 1 << MANTISSA_BITS;
uint constant EXPONENT_BITS = BITS - MANTISSA_BITS;
function eq(Density a, Density b) internal pure returns (bool) { unchecked {
return Density.unwrap(a) == Density.unwrap(b);
}}
/* Check the size of a fixed-point formatted density */
function checkDensity96X32(uint density96X32) internal pure returns (bool) { unchecked {
return density96X32 < (1<<(96+32));
}}
/* fixed-point -> float conversion */
/* Warning: no bit cleaning (expected to be done by Local's code), no checking that the input is on 128 bits. */
/* floats with `[exp=1]` are not in the image of fromFixed. They are considered noncanonical. */
function from96X32(uint density96X32) internal pure returns (Density) { unchecked {
if (density96X32 <= MANTISSA_MASK) {
return Density.wrap(density96X32);
}
// invariant: `exp >= 2` (so not 0)
uint exp = BitLib.fls(density96X32);
return make(density96X32 >> (exp-MANTISSA_BITS),exp);
}}
/* float -> fixed-point conversion */
function to96X32(Density density) internal pure returns (uint) { unchecked {
/* also accepts floats not generated by fixedToFloat, i.e. with exp=1 */
if (Density.unwrap(density) <= SUBNORMAL_LIMIT) {
return Density.unwrap(density) & MANTISSA_MASK;
}
/* assumes exp is on the right number of bits */
// invariant: `exp >= 2`
uint shift = (Density.unwrap(density) >> MANTISSA_BITS) - MANTISSA_BITS;
return ((Density.unwrap(density) & MANTISSA_MASK) | MANTISSA_INTEGER) << shift;
}}
function mantissa(Density density) internal pure returns (uint) { unchecked {
return Density.unwrap(density) & MANTISSA_MASK;
}}
function exponent(Density density) internal pure returns (uint) { unchecked {
return Density.unwrap(density) >> MANTISSA_BITS;
}}
/* Make a float from a mantissa and an exponent. May make a noncanonical float. */
/* Warning: no checks */
function make(uint _mantissa, uint _exponent) internal pure returns (Density) { unchecked {
return Density.wrap((_exponent << MANTISSA_BITS) | (_mantissa & MANTISSA_MASK));
}}
/* None of the functions below will overflow if m is 96bit wide.
Density being a 96.32 number is useful because:
- Most of its range is representable with the 9-bits float format chosen
- It does not overflow when multiplied with a 96bit number, which is the size chosen to represent token amounts in Mangrove.
- Densities below `2^-32` need `> 4e9` gasreq to force gives > 0, which is not realistic
*/
/* Multiply the density with m, rounded towards zero. */
/* May overflow if `|m|>9` */
function multiply(Density density, uint m) internal pure returns (uint) { unchecked {
return (m * density.to96X32())>>32;
}}
/* Multiply the density with m, rounded towards +infinity. */
/* May overflow if `|m|>96` */
function multiplyUp(Density density, uint m) internal pure returns (uint) { unchecked {
uint part = m * density.to96X32();
return (part >> 32) + (part%(2<<32) == 0 ? 0 : 1);
}}
/* Convenience function: get a fixed-point density from the given parameters. Computes the price of gas in outbound tokens (base units), then multiplies by cover_factor. */
/* Warning: you must multiply input usd prices by 100 */
/* not supposed to be gas optimized */
function paramsTo96X32(
uint outbound_decimals,
uint gasprice_in_Mwei,
uint eth_in_centiusd,
uint outbound_display_in_centiusd,
uint cover_factor
) internal pure returns (uint) {
// Do not use unchecked here
require(uint8(outbound_decimals) == outbound_decimals,"DensityLib/fixedFromParams1/decimals/wrong");
uint num = cover_factor * gasprice_in_Mwei * (10**outbound_decimals) * eth_in_centiusd;
// use * instead of << to trigger overflow check
return (num * (1 << 32)) / (outbound_display_in_centiusd * 1e12);
}
/* Version with token in Mwei instead of usd */
function paramsTo96X32(
uint outbound_decimals,
uint gasprice_in_Mwei,
uint outbound_display_in_Mwei,
uint cover_factor
) internal pure returns (uint) {
/* **Do not** use unchecked here. */
require(uint8(outbound_decimals) == outbound_decimals,"DensityLib/fixedFromParams2/decimals/wrong");
uint num = cover_factor * gasprice_in_Mwei * (10**outbound_decimals);
/* use `*` instead of `<<` to trigger overflow check */
return (num * (1 << 32)) / outbound_display_in_Mwei;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;
import "@mgv/lib/core/Constants.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
import {BitLib} from "@mgv/lib/core/BitLib.sol";
import {console2 as csf} from "@mgv/forge-std/console2.sol";
import {Local} from "@mgv/src/preprocessed/Local.post.sol";
/* # Libraries for tick tree manipulation
Offers in Mangrove are structured in a tree so that offer insertion, removal, and update can happen in constant time.
The tree has the following structure: nodes at height 0, 1, 2 and 3 are bit fields (type `Field`) and nodes at height 4 (leaves) are arrays of pairs of offers (type `Leaf`).
- The root node is a 2-bit `Field` and has 2 child nodes.
- The nodes below are called `level1` nodes and are 64-bit `Field`s, with 64 child nodes each.
- The nodes below are called `level2` nodes and are 64-bit `Field`s with 64 child nodes each.
- The nodes below are called `level3` nodes and are 64-bit `Field`s with 64 child nodes each.
- The nodes below are called `leaf` nodes and are arrays of pairs of offers. Each pair of offers represents the first and last offer of a bin.
- Bins are linked lists of offers.
For each field, the i-th bit (starting from least significant) is set if there is at least one bin holding offers below the i-th child of the field. */
/* Globally enable `leaf.method(...)` */
type Leaf is uint;
using LeafLib for Leaf global;
/* Each `Leaf` holds information about 4 bins as follows: `[firstId,lastId] [firstId,lastId] [firstId,lastId] [firstId,lastId]`. For each bin `firstId` is used by `marketOrder` to start consuming offers in the bin (each offer contains a pointer to the next offer in the bin, until `lastId` is reacher). `lastId` is used when inserting offers in the bin: the newly inserted offer replaces the last offer.
Each `leaf` has an `index`: it is the number of leaves before it.
*/
library LeafLib {
Leaf constant EMPTY = Leaf.wrap(uint(0));
/* Checks if a leaf is dirty or not (see below for more on dirty leaves). */
function dirty(Leaf leaf) internal pure returns (DirtyLeaf) {
unchecked {
assembly ("memory-safe") {
leaf := or(iszero(leaf),leaf)
}
return DirtyLeaf.wrap(Leaf.unwrap(leaf));
}
}
function eq(Leaf leaf1, Leaf leaf2) internal pure returns (bool) {
unchecked {
return Leaf.unwrap(leaf1) == Leaf.unwrap(leaf2);
}
}
function isEmpty(Leaf leaf) internal pure returns (bool) {
unchecked {
return Leaf.unwrap(leaf) == Leaf.unwrap(EMPTY);
}
}
/* `bool -> int` cast */
function uint_of_bool(bool b) internal pure returns (uint u) {
unchecked {
assembly ("memory-safe") {
u := b
}
}
}
/* Set either tick's first (at pos*size) or last (at pos*size + 1) */
function setPosFirstOrLast(Leaf leaf, uint pos, uint id, bool last) internal pure returns (Leaf) {
unchecked {
uint before = OFFER_BITS * ((pos * 2) + uint_of_bool(last));
uint cleanupMask = ~(OFFER_MASK << (256 - OFFER_BITS - before));
uint shiftedId = id << (256 - OFFER_BITS - before);
uint newLeaf = Leaf.unwrap(leaf) & cleanupMask | shiftedId;
return Leaf.wrap(newLeaf);
}
}
/* Assume `leaf` is the leaf of `bin`. Set the first offer of `bin` in leaf to `id`. */
function setBinFirst(Leaf leaf, Bin bin, uint id) internal pure returns (Leaf) {
unchecked {
uint posInLeaf = bin.posInLeaf();
return setPosFirstOrLast(leaf, posInLeaf, id, false);
}
}
/* Assume `leaf` is the leaf of `bin`. Set the last offer of `bin` in leaf to `id`. */
function setBinLast(Leaf leaf, Bin bin, uint id) internal pure returns (Leaf) {
unchecked {
uint posInLeaf = bin.posInLeaf();
return setPosFirstOrLast(leaf, posInLeaf, id, true);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `leaf` is the leaf of `bin`. Erase contents of bins in `leaf` to (not including) `bin`. */
function eraseBelow(Leaf leaf, Bin bin) internal pure returns (Leaf) {
unchecked {
uint mask = ONES >> ((bin.posInLeaf() + 1) * OFFER_BITS * 2);
return Leaf.wrap(Leaf.unwrap(leaf) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `leaf` is the leaf of `bin`. Erase contents of bins in `leaf` from (not including) `bin`. */
function eraseAbove(Leaf leaf, Bin bin) internal pure returns (Leaf) {
unchecked {
uint mask = ~(ONES >> (bin.posInLeaf() * OFFER_BITS * 2));
return Leaf.wrap(Leaf.unwrap(leaf) & mask);
}
}
// _This function is not used by Mangrove but is part of the library._
/* Return the id of the first offer in `bin`, assuming `bin`'s leaf is `leaf`. */
function firstOfBin(Leaf leaf, Bin bin) internal pure returns (uint) {
unchecked {
return firstOfPos(leaf, bin.posInLeaf());
}
}
/* Return the id of the last offer in `bin`, assuming `bin`'s leaf is `leaf`. */
function lastOfBin(Leaf leaf, Bin bin) internal pure returns (uint) {
unchecked {
return lastOfPos(leaf, bin.posInLeaf());
}
}
/* Return first offer of pair in position `pos` */
function firstOfPos(Leaf leaf, uint pos) internal pure returns (uint) {
unchecked {
uint raw = Leaf.unwrap(leaf);
return uint(raw << (pos * OFFER_BITS * 2) >> (256 - OFFER_BITS));
}
}
/* Return second offer of pair in position `pos` */
function lastOfPos(Leaf leaf, uint pos) internal pure returns (uint) {
unchecked {
uint raw = Leaf.unwrap(leaf);
return uint(raw << (OFFER_BITS * ((pos * 2) + 1)) >> (256 - OFFER_BITS));
}
}
/* Return the position of the first pair of `leaf` (0, 1, 2 or 3) that has a nonzero offer.
Explanation:
Note that unlike in fields, have their low bin on the most significant bits.
`pos` is initially 1 if `leaf` has some nonzero bit in its MSB half, 0 otherwise. Then `pos` is `A | B`, where `A` is `iszero(pos)<<1`, so `A` is 0 if leaf has some nonzero bit in its MSB half, 2 otherwise. And `B` is 0 if `leaf >> (pos << 7)` has some nonzero bit in its most significant 192 bits, 1 otherwise.
*/
function bestNonEmptyBinPos(Leaf leaf) internal pure returns (uint pos) {
assembly("memory-safe") {
pos := gt(leaf,0xffffffffffffffffffffffffffffffff)
pos := or(shl(1,iszero(pos)),iszero(gt(shr(shl(7,pos),leaf),0xffffffffffffffff)))
}
}
/* Return the offer id of the first offer of the first non-empty pair in `leaf`. */
function bestOfferId(Leaf leaf) internal pure returns (uint offerId) {
unchecked {
return firstOfPos(leaf,bestNonEmptyBinPos(leaf));
}
}
}
/* Bins are numbered from MIN_BIN to MAX_BIN (inclusive). Each bin contains the offers at a given price. For a given `tickSpacing`, bins represent the following prices (centered on the central bin):
```
...
1.0001^-(tickSpacing*2)
1.0001^-(tickSpacing*1)
1.0001
1.0001^(tickSpacing*1)
1.0001^(tickSpacing*2)
...
```
There are 4 bins per leaf, `4 * 64` bins per level3, etc. The leaf of a bin is the leaf that holds its first/last offer id. The level3 of a bin is the level3 field above its leaf; the level2 of a bin is the level2 field above its level3, etc. */
/* Globally enable `bin.method(...)` */
type Bin is int;
using TickTreeLib for Bin global;
library TickTreeLib {
function eq(Bin bin1, Bin bin2) internal pure returns (bool) {
unchecked {
return Bin.unwrap(bin1) == Bin.unwrap(bin2);
}
}
function inRange(Bin bin) internal pure returns (bool) {
unchecked {
return Bin.unwrap(bin) >= MIN_BIN && Bin.unwrap(bin) <= MAX_BIN;
}
}
// _This function is not used by Mangrove but is part of the library for convenience._
/* Not optimized for gas. Returns the bin induced by the branch formed by the arguments. Returned value will make no sense if any of the `Field` arguments are empty. */
function bestBinFromBranch(uint binPosInLeaf,Field level3, Field level2, Field level1, Field root) internal pure returns (Bin) {
unchecked {
Local local;
local = local.binPosInLeaf(binPosInLeaf).level3(level3).level2(level2).level1(level1).root(root);
return bestBinFromLocal(local);
}
}
/* Returns tick held by the `bin`, given a `tickSpacing`. */
function tick(Bin bin, uint tickSpacing) internal pure returns (Tick) {
return Tick.wrap(Bin.unwrap(bin) * int(tickSpacing));
}
/* Returns the bin induced by the branch held in `local`. Returned value will make no sense if any of the fields of `local` are empty. */
function bestBinFromLocal(Local local) internal pure returns (Bin) {
unchecked {
uint ubin = local.binPosInLeaf() |
((BitLib.ctz64(Field.unwrap(local.level3())) |
(BitLib.ctz64(Field.unwrap(local.level2())) |
(BitLib.ctz64(Field.unwrap(local.level1())) |
uint(
(int(BitLib.ctz64(Field.unwrap(local.root())))-ROOT_SIZE/2) << LEVEL_SIZE_BITS))
<< LEVEL_SIZE_BITS)
<< LEVEL_SIZE_BITS)
<< LEAF_SIZE_BITS);
return Bin.wrap(int(ubin));
}
}
/* Returns the index of the leaf that holds `bin` */
function leafIndex(Bin bin) internal pure returns (int) {
unchecked {
return Bin.unwrap(bin) >> LEAF_SIZE_BITS;
}
}
/* Returns the position of `bin` in its leaf. */
function posInLeaf(Bin bin) internal pure returns (uint) {
unchecked {
return uint(Bin.unwrap(bin)) & LEAF_SIZE_MASK;
}
}
/* Returns the index of `bin`'s level3 */
function level3Index(Bin bin) internal pure returns (int) {
unchecked {
return Bin.unwrap(bin) >> (LEAF_SIZE_BITS + LEVEL_SIZE_BITS);
}
}
/* Returns the position of `bin`'s leaf in `bin`'s level3 */
function posInLevel3(Bin bin) internal pure returns (uint) {
unchecked {
return uint(bin.leafIndex()) & LEVEL_SIZE_MASK;
}
}
/* Returns the index of `bin`'s level2 */
function level2Index(Bin bin) internal pure returns (int) {
unchecked {
return Bin.unwrap(bin) >> (LEAF_SIZE_BITS + 2* LEVEL_SIZE_BITS);
}
}
/* Returns the position of `bin`'s level3 in `bin`'s level2 */
function posInLevel2(Bin bin) internal pure returns (uint) {
unchecked {
return uint(bin.level3Index()) & LEVEL_SIZE_MASK;
}
}
/* Returns the index of `bin`'s level1 */
function level1Index(Bin bin) internal pure returns (int) {
unchecked {
return Bin.unwrap(bin) >> (LEAF_SIZE_BITS + 3 * LEVEL_SIZE_BITS);
}
}
/* Returns the position of `bin`'s level2 in `bin`'s level1 */
function posInLevel1(Bin bin) internal pure returns (uint) {
unchecked {
return uint(bin.level2Index()) & LEVEL_SIZE_MASK;
}
}
/* Returns the position of `bin`'s level1 in root */
function posInRoot(Bin bin) internal pure returns (uint) {
unchecked {
return uint(bin.level1Index() + ROOT_SIZE / 2);
}
}
/* `<`, typed for bin */
function strictlyBetter(Bin bin1, Bin bin2) internal pure returns (bool) {
unchecked {
return Bin.unwrap(bin1) < Bin.unwrap(bin2);
}
}
/* `<=`, typed for bin */
function better(Bin bin1, Bin bin2) internal pure returns (bool) {
unchecked {
return Bin.unwrap(bin1) <= Bin.unwrap(bin2);
}
}
}
/* Globally enable `field.method(...)` */
type Field is uint;
using FieldLib for Field global;
/* Fields are bit fields. Each bit position of a field corresponds to a child of the node in the tick tree. The i-th bit of a field is set iff its child is the parent of at least one non-emtpy field.
Using bit fields market orders can locate the next bin containing an offer in constant time: once a leaf has been emptied, one must at most walk up along the branch of the current bin, up to the first 1 in a field, then go down to the of the tree, then go down the corresponding child to the nonempty bin found.
*/
/* In fields, positions are counted from the least significant bits */
library FieldLib {
Field constant EMPTY = Field.wrap(uint(0));
/* Checks if a field is dirty or not (see below for more on dirty fields). */
function dirty(Field field) internal pure returns (DirtyField) {
unchecked {
assembly ("memory-safe") {
field := or(TOPBIT,field)
}
return DirtyField.wrap(Field.unwrap(field));
}
}
function eq(Field field1, Field field2) internal pure returns (bool) {
unchecked {
return Field.unwrap(field1) == Field.unwrap(field2);
}
}
function isEmpty(Field field) internal pure returns (bool) {
unchecked {
return Field.unwrap(field) == Field.unwrap(EMPTY);
}
}
/* Flip the bit at the position of `bin`'s leaf */
function flipBitAtLevel3(Field level3, Bin bin) internal pure returns (Field) {
unchecked {
uint pos = bin.posInLevel3();
level3 = Field.wrap(Field.unwrap(level3) ^ (1 << pos));
return level3;
}
}
/* Flip the bit at the position of `bin`'s level3 */
function flipBitAtLevel2(Field level2, Bin bin) internal pure returns (Field) {
unchecked {
uint pos = bin.posInLevel2();
level2 = Field.wrap(Field.unwrap(level2) ^ (1 << pos));
return level2;
}
}
/* Flip the bit at the position of `bin`'s level2 */
function flipBitAtLevel1(Field level1, Bin bin) internal pure returns (Field) {
unchecked {
uint pos = bin.posInLevel1();
level1 = Field.wrap(Field.unwrap(level1) ^ (1 << pos));
return level1;
}
}
/* Flip the bit at the position of `bin`'s level1 */
function flipBitAtRoot(Field root, Bin bin) internal pure returns (Field) {
unchecked {
uint pos = bin.posInRoot();
root = Field.wrap(Field.unwrap(root) ^ (1 << pos));
return root;
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level3 of `bin`. Erase contents of field up to (not including) bin. */
function eraseBelowInLevel3(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ONES << (bin.posInLevel3() + 1);
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level3 of `bin`. Erase contents of field from (not including) bin. */
function eraseAboveInLevel3(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ~(ONES << bin.posInLevel3());
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level2 of `bin`. Erase contents of field up to (not including) bin. */
function eraseBelowInLevel2(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ONES << (bin.posInLevel2() + 1);
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level2 of `bin`. Erase contents of field from (not including) bin. */
function eraseAboveInLevel2(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ~(ONES << bin.posInLevel2());
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level1 of `bin`. Erase contents of field up to (not including) bin. */
function eraseBelowInLevel1(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ONES << (bin.posInLevel1() + 1);
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the level1 of `bin`. Erase contents of field from (not including) bin. */
function eraseAboveInLevel1(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ~(ONES << bin.posInLevel1());
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the root of `bin`. Erase contents of field up to (not including) bin. */
function eraseBelowInRoot(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ONES << (bin.posInRoot() + 1);
return Field.wrap(Field.unwrap(field) & mask);
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Assumes `field` is the root of `bin`. Erase contents of field from (not including) bin. */
function eraseAboveInRoot(Field field, Bin bin) internal pure returns (Field) {
unchecked {
uint mask = ~(ONES << bin.posInRoot());
return Field.wrap(Field.unwrap(field) & mask);
}
}
/* Returns first nonzero position of `field`. Will return 64 if field is empty */
function firstOnePosition(Field field) internal pure returns (uint) {
unchecked {
return BitLib.ctz64(Field.unwrap(field));
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Returns last nonzero position of `field`. Will return 256 if field is empty */
function lastOnePosition(Field field) internal pure returns (uint) {
unchecked {
return BitLib.fls(Field.unwrap(field));
}
}
/* Return index of the first nonempty level1 below `root` (`root` should not be empty) */
function firstLevel1Index(Field root) internal pure returns (int) {
unchecked {
return int(root.firstOnePosition()) - ROOT_SIZE / 2;
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Return index of the last nonempty level1 below `root` (root should not be empty) */
function lastLevel1Index(Field root) internal pure returns (int) {
unchecked {
return int(root.lastOnePosition()) - ROOT_SIZE / 2;
}
}
/* Return index of the first nonempty level2 below `level1` assuming its index is `level1Index` (`level1` should not be empty). */
function firstLevel2Index(Field level1, int level1Index) internal pure returns (int) {
unchecked {
return level1Index * LEVEL_SIZE + int(level1.firstOnePosition());
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Return index of the last nonempty level2 below `level1` assuming its index is `level1Index` (`level1` should not be empty). */
function lastLevel2Index(Field level1, int level1Index) internal pure returns (int) {
unchecked {
return level1Index * LEVEL_SIZE + int(level1.lastOnePosition());
}
}
/* Return index of the first nonempty level3 below `level2` assuming its index is `level2Index` (`level2` should not be empty). */
function firstLevel3Index(Field level2, int level2Index) internal pure returns (int) {
unchecked {
return level2Index * LEVEL_SIZE + int(level2.firstOnePosition());
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Return index of the last nonempty level3 below `level2` assuming its index is `level2Index` (`level2` should not be empty). */
function lastLevel3Index(Field level2, int level2Index) internal pure returns (int) {
unchecked {
return level2Index * LEVEL_SIZE + int(level2.lastOnePosition());
}
}
/* Return index of the first nonempty leaf below `level3` assuming its index is `level3Index` (`level3` should not be empty). */
function firstLeafIndex(Field level3, int level3Index) internal pure returns (int) {
unchecked {
return level3Index * LEVEL_SIZE + int(level3.firstOnePosition());
}
}
// _This function is not used by Mangrove but is useful for MgvReader._
/* Return index of the last nonempty leaf below `level3` assuming its index is `level3Index` (`level3` should not be empty). */
function lastLeafIndex(Field level3, int level3Index) internal pure returns (int) {
unchecked {
return level3Index * LEVEL_SIZE + int(level3.lastOnePosition());
}
}
}
/* ## Clean/Dirty Fields and Leaves
To save gas, leaves and fields at never zeroed out but written with a dirty bit. This is especially helpful when the price oscillates quickly between two nodes.
Leaves don't have 'available bits' so an empty leaf is encoded as 1. This is not a valid leaf because for every offer pair in a leaf, either both are 0 (the bin is empty) or both are nonzero (they are the same if the bin has a single offer).
*/
/* Globally enable `dirtyLeaf.method(...)` */
type DirtyLeaf is uint;
using DirtyLeafLib for DirtyLeaf global;
library DirtyLeafLib {
/* Return 0 if leaf is 1, leaf otherwise */
function clean(DirtyLeaf leaf) internal pure returns (Leaf) {
unchecked {
assembly ("memory-safe") {
leaf := xor(eq(leaf,ONE),leaf)
}
return Leaf.wrap(DirtyLeaf.unwrap(leaf));
}
}
function isDirty(DirtyLeaf leaf) internal pure returns (bool) {
unchecked {
return DirtyLeaf.unwrap(leaf) == ONE;
}
}
function eq(DirtyLeaf leaf1, DirtyLeaf leaf2) internal pure returns (bool) {
unchecked {
return DirtyLeaf.unwrap(leaf1) == DirtyLeaf.unwrap(leaf2);
}
}
}
/* We use `TOPBIT` as the optimized in-storage value since 1 is a valid Field value */
/* For fields, it's simpler, since they do not use 64 bits we store the word with top bit at 1 and everything else at 0 to mark emptiness. */
/* Globally enable `dirtyField.method(...)` */
type DirtyField is uint;
using DirtyFieldLib for DirtyField global;
library DirtyFieldLib {
DirtyField constant DIRTY_EMPTY = DirtyField.wrap(TOPBIT);
DirtyField constant CLEAN_EMPTY = DirtyField.wrap(0);
/* Return clean field with topbit set to 0 */
function clean(DirtyField field) internal pure returns (Field) {
unchecked {
assembly ("memory-safe") {
field := and(NOT_TOPBIT,field)
}
return Field.wrap(DirtyField.unwrap(field));
}
}
function isDirty(DirtyField field) internal pure returns (bool) {
unchecked {
return DirtyField.unwrap(field) & TOPBIT == TOPBIT;
}
}
function eq(DirtyField leaf1, DirtyField leaf2) internal pure returns (bool) {
unchecked {
return DirtyField.unwrap(leaf1) == DirtyField.unwrap(leaf2);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Bin} from "@mgv/lib/core/TickTreeLib.sol";
import "@mgv/lib/core/BitLib.sol";
import "@mgv/lib/core/Constants.sol";
/* This file is inspired by Uniswap's approach to ticks, with the following notable changes:
- directly compute ticks base 1.0001 (not base `sqrt(1.0001)`)
- directly compute ratios (not `sqrt(ratio)`) (simpler code elsewhere when dealing with actual ratios and logs of ratios)
- ratios are floating-point numbers, not fixed-point numbers (increases precision when computing amounts)
*/
/* # TickLib
The `TickLib` file contains tick math-related code and utilities for manipulating ticks. It also holds functions related to ratios, which are represented as (mantissa,exponent) pairs. */
/* Globally enable `tick.method(...)` */
type Tick is int;
using TickLib for Tick global;
library TickLib {
function inRange(Tick tick) internal pure returns (bool) {
return Tick.unwrap(tick) >= MIN_TICK && Tick.unwrap(tick) <= MAX_TICK;
}
function eq(Tick tick1, Tick tick2) internal pure returns (bool) {
unchecked {
return Tick.unwrap(tick1) == Tick.unwrap(tick2);
}
}
/* Returns the nearest, higher bin to the given `tick` at the given `tickSpacing`
We do not force ticks to fit the tickSpacing (aka `tick%tickSpacing==0`). Ratios are rounded up that the maker is always paid at least what they asked for
*/
function nearestBin(Tick tick, uint tickSpacing) internal pure returns (Bin bin) {
unchecked {
// By default division rounds towards 0. Since `smod` is signed we get the sign of `tick` and `tick%tickSpacing` in a single instruction.
assembly("memory-safe") {
bin := sdiv(tick,tickSpacing)
bin := add(bin,sgt(smod(tick,tickSpacing),0))
}
}
}
/* ## Conversion functions */
/* ### (inbound,tick) → outbound
`inboundFromOutbound[Up]` converts an outbound amount (i.e. an `offer.gives` or a `takerWants`), to an inbound amount, following the price induced by `tick`. There's a rounding-up and a rounding-down variant.
`outboundAmt` should not exceed 127 bits.
*/
function inboundFromOutbound(Tick tick, uint outboundAmt) internal pure returns (uint) {
(uint sig, uint exp) = ratioFromTick(tick);
return (sig * outboundAmt) >> exp;
}
function inboundFromOutboundUp(Tick tick, uint outboundAmt) internal pure returns (uint) {
unchecked {
(uint sig, uint exp) = ratioFromTick(tick);
return divExpUp(sig*outboundAmt,exp);
}
}
/* ### (outbound,tick) → inbound */
/* `outboundFromInbound[Up]` converts an inbound amount (i.e. an `offer.wants` or a `takerGives`), to an outbound amount, following the price induced by `tick`. There's a rounding-up and a rounding-down variant.
`inboundAmt` should not exceed 127 bits.
*/
function outboundFromInbound(Tick tick, uint inboundAmt) internal pure returns (uint) {
(uint sig, uint exp) = ratioFromTick(Tick.wrap(-Tick.unwrap(tick)));
return (sig * inboundAmt) >> exp;
}
function outboundFromInboundUp(Tick tick, uint inboundAmt) internal pure returns (uint) {
unchecked {
(uint sig, uint exp) = ratioFromTick(Tick.wrap(-Tick.unwrap(tick)));
return divExpUp(sig*inboundAmt,exp);
}
}
/* ## Ratio representation
Ratios are represented as a (mantissa,exponent) pair which represents the number `mantissa * 2**-exponent`.
The exponent is negated so that, for ratios in the accepted range, the exponent is `>= 0`. This simplifies the code.
Floats are normalized so that the mantissa uses exactly 128 bits. It enables easy comparison between floats and ensures they can be multiplied by amounts without overflow.
The accepted ratio range is between `ratioFromTick(MIN_TICK)` and `ratioFromTick(MAX_TICK)` (inclusive).
*/
/* ### (inbound,outbound) → ratio */
/* `ratioFromVolumes` converts a pair of (inbound,outbound) volumes to a floating-point, normalized ratio. It rounds down.
* `outboundAmt = 0` has a special meaning and the highest possible price will be returned.
* `inboundAmt = 0` has a special meaning if `outboundAmt != 0` and the lowest possible price will be returned.
*/
function ratioFromVolumes(uint inboundAmt, uint outboundAmt) internal pure returns (uint mantissa, uint exp) {
unchecked {
require(inboundAmt <= MAX_SAFE_VOLUME, "mgv/ratioFromVol/inbound/tooBig");
require(outboundAmt <= MAX_SAFE_VOLUME, "mgv/ratioFromVol/outbound/tooBig");
if (outboundAmt == 0) {
return (MAX_RATIO_MANTISSA,uint(MAX_RATIO_EXP));
} else if (inboundAmt == 0) {
return (MIN_RATIO_MANTISSA,uint(MIN_RATIO_EXP));
}
uint ratio = (inboundAmt << MANTISSA_BITS) / outboundAmt;
uint log2 = BitLib.fls(ratio);
require(ratio != 0,"mgv/ratioFromVolumes/zeroRatio");
if (log2 > MANTISSA_BITS_MINUS_ONE) {
uint diff = log2 - MANTISSA_BITS_MINUS_ONE;
return (ratio >> diff, MANTISSA_BITS - diff);
} else {
uint diff = MANTISSA_BITS_MINUS_ONE - log2;
return (ratio << diff, MANTISSA_BITS + diff);
}
}
}
/* ### (inbound,outbound) → tick */
function tickFromVolumes(uint inboundAmt, uint outboundAmt) internal pure returns (Tick tick) {
(uint man, uint exp) = ratioFromVolumes(inboundAmt, outboundAmt);
return tickFromNormalizedRatio(man,exp);
}
/* ### ratio → tick */
/* Does not require a normalized ratio. */
function tickFromRatio(uint mantissa, int exp) internal pure returns (Tick) {
uint normalized_exp;
(mantissa, normalized_exp) = normalizeRatio(mantissa, exp);
return tickFromNormalizedRatio(mantissa,normalized_exp);
}
/* ### low-level ratio → tick */
/* Given `ratio`, return greatest tick `t` such that `ratioFromTick(t) <= ratio`.
* Input ratio must be within the maximum and minimum ratios returned by the available ticks.
* Does _not_ expected a normalized float.
The function works as follows:
* Approximate log2(ratio) to the 13th fractional digit.
* Following <a href="https://hackmd.io/@mangrovedao/HJvl21zla">https://hackmd.io/@mangrovedao/HJvl21zla</a>, obtain `tickLow` and `tickHigh` such that $\log_{1.0001}(ratio)$ is between them
* Return the highest one that yields a ratio below the input ratio.
*/
function tickFromNormalizedRatio(uint mantissa, uint exp) internal pure returns (Tick tick) {
if (floatLt(mantissa, exp, MIN_RATIO_MANTISSA, uint(MIN_RATIO_EXP))) {
revert("mgv/tickFromRatio/tooLow");
}
if (floatLt(MAX_RATIO_MANTISSA, uint(MAX_RATIO_EXP), mantissa, exp)) {
revert("mgv/tickFromRatio/tooHigh");
}
int log2ratio = int(MANTISSA_BITS_MINUS_ONE) - int(exp) << 64;
uint mpow = mantissa >> MANTISSA_BITS_MINUS_ONE - 127; // give 129 bits of room left
/* How the fractional digits of the log are computed:
* for a given `n` compute $n^2$.
* If $\lfloor\log_2(n^2)\rfloor = 2\lfloor\log_2(n)\rfloor$ then the fractional part of $\log_2(n^2)$ was $< 0.5$ (first digit is 0).
* If $\lfloor\log_2(n^2)\rfloor = 1 + 2\lfloor\log_2(n)\rfloor$ then the fractional part of $\log_2(n^2)$ was $\geq 0.5$ (first digit is 1).
* Apply starting with `n=mpow` repeatedly by keeping `n` on 127 bits through right-shifts (has no impact on high fractional bits).
*/
assembly ("memory-safe") {
// 13 bits of precision
mpow := shr(127, mul(mpow, mpow))
let highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(63, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(62, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(61, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(60, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(59, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(58, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(57, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(56, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(55, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(54, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(53, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(52, highbit))
mpow := shr(highbit, mpow)
mpow := shr(127, mul(mpow, mpow))
highbit := shr(128, mpow)
log2ratio := or(log2ratio, shl(51, highbit))
}
// Convert log base 2 to log base 1.0001 (multiply by `log2(1.0001)^-1 << 64`), since log2ratio is x64 this yields a x128 number.
int log_bp_ratio = log2ratio * 127869479499801913173571;
// tickLow is approx - maximum error
int tickLow = int((log_bp_ratio - 1701496478404567508395759362389778998) >> 128);
// tickHigh is approx + minimum error
int tickHigh = int((log_bp_ratio + 289637967442836606107396900709005211253) >> 128);
(uint mantissaHigh, uint expHigh) = ratioFromTick(Tick.wrap(tickHigh));
bool ratioHighGt = floatLt(mantissa, exp, mantissaHigh, expHigh);
if (tickLow == tickHigh || ratioHighGt) {
tick = Tick.wrap(tickLow);
} else {
tick = Tick.wrap(tickHigh);
}
}
/* ### tick → ratio conversion function */
/* Returns a normalized (man,exp) ratio floating-point number. The mantissa is on 128 bits to avoid overflow when mulitplying with token amounts. The exponent has no bias. for easy comparison. */
function ratioFromTick(Tick tick) internal pure returns (uint man, uint exp) {
unchecked {
(man, exp) = nonNormalizedRatioFromTick(tick);
int shiftedTick = Tick.unwrap(tick) << LOG_BP_SHIFT;
int log2ratio;
// floor log2 of ratio towards negative infinity
assembly ("memory-safe") {
log2ratio := sdiv(shiftedTick,LOG_BP_2X235)
log2ratio := sub(log2ratio,slt(smod(shiftedTick,LOG_BP_2X235),0))
}
int diff = log2ratio+int(exp)-int(MANTISSA_BITS_MINUS_ONE);
if (diff > 0) {
// For |tick| <= 887272, this drops at most 5 bits of precision
man = man >> uint(diff);
} else {
man = man << uint(-diff);
}
// For |tick| << 887272, log2ratio <= 127
exp = uint(int(MANTISSA_BITS_MINUS_ONE)-log2ratio);
}
}
/* ### low-level tick → ratio conversion */
/* Compute 1.0001^tick and returns it as a (mantissa,exponent) pair. Works by checking each set bit of `|tick|` multiplying by `1.0001^(-2**i)<<128` if the ith bit of tick is set. Since we inspect the absolute value of `tick`, `-1048576` is not a valid tick. If the tick is positive this computes `1.0001^-tick`, and we take the inverse at the end. For maximum precision some powers of 1.0001 are shifted until they occupy 128 bits. The `extra_shift` is recorded and added to the exponent.
Since the resulting mantissa is left-shifted by 128 bits, if tick was positive, we divide `2**256` by the mantissa to get the 128-bit left-shifted inverse of the mantissa.
The error (relative to 1.0001^tick) may be negative or positive.
*/
function nonNormalizedRatioFromTick(Tick tick) internal pure returns (uint man, uint exp) {
uint absTick = Tick.unwrap(tick) < 0 ? uint(-Tick.unwrap(tick)) : uint(Tick.unwrap(tick));
require(absTick <= uint(MAX_TICK), "mgv/absTick/outOfBounds");
int extra_shift;
if (absTick & 0x1 != 0) {
man = 0xfff97272373d413259a46990580e2139;
} else {
man = 0x100000000000000000000000000000000;
}
if (absTick & 0x2 != 0) {
man = (man * 0xfff2e50f5f656932ef12357cf3c7fdcb) >> 128;
}
if (absTick & 0x4 != 0) {
man = (man * 0xffe5caca7e10e4e61c3624eaa0941ccf) >> 128;
}
if (absTick & 0x8 != 0) {
man = (man * 0xffcb9843d60f6159c9db58835c926643) >> 128;
}
if (absTick & 0x10 != 0) {
man = (man * 0xff973b41fa98c081472e6896dfb254bf) >> 128;
}
if (absTick & 0x20 != 0) {
man = (man * 0xff2ea16466c96a3843ec78b326b52860) >> 128;
}
if (absTick & 0x40 != 0) {
man = (man * 0xfe5dee046a99a2a811c461f1969c3052) >> 128;
}
if (absTick & 0x80 != 0) {
man = (man * 0xfcbe86c7900a88aedcffc83b479aa3a3) >> 128;
}
if (absTick & 0x100 != 0) {
man = (man * 0xf987a7253ac413176f2b074cf7815e53) >> 128;
}
if (absTick & 0x200 != 0) {
man = (man * 0xf3392b0822b70005940c7a398e4b70f2) >> 128;
}
if (absTick & 0x400 != 0) {
man = (man * 0xe7159475a2c29b7443b29c7fa6e889d8) >> 128;
}
if (absTick & 0x800 != 0) {
man = (man * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
}
if (absTick & 0x1000 != 0) {
man = (man * 0xa9f746462d870fdf8a65dc1f90e061e4) >> 128;
}
if (absTick & 0x2000 != 0) {
man = (man * 0xe1b0d342ada5437121767bec575e65ed) >> 128;
extra_shift += 1;
}
if (absTick & 0x4000 != 0) {
man = (man * 0xc6f84d7e5f423f66048c541550bf3e96) >> 128;
extra_shift += 2;
}
if (absTick & 0x8000 != 0) {
man = (man * 0x9aa508b5b7a84e1c677de54f3e99bc8f) >> 128;
extra_shift += 4;
}
if (absTick & 0x10000 != 0) {
man = (man * 0xbad5f1bdb70232cd33865244bdcc089c) >> 128;
extra_shift += 9;
}
if (absTick & 0x20000 != 0) {
man = (man * 0x885b9613d7e87aa498106fb7fa5edd37) >> 128;
extra_shift += 18;
}
if (absTick & 0x40000 != 0) {
man = (man * 0x9142e0723efb884889d1f447715afacd) >> 128;
extra_shift += 37;
}
if (absTick & 0x80000 != 0) {
man = (man * 0xa4d9a773d61316918f140bd96e8e6814) >> 128;
extra_shift += 75;
}
if (Tick.unwrap(tick) > 0) {
/* We use [Remco Bloemen's trick](https://xn--2-umb.com/17/512-bit-division/#divide-2-256-by-a-given-number) to divide `2**256` by `man`: */
assembly("memory-safe") {
man := add(div(sub(0, man), man), 1)
}
extra_shift = -extra_shift;
}
exp = uint(128 + extra_shift);
}
/* Shift mantissa so it occupies exactly `MANTISSA_BITS` and adjust `exp` in consequence.
A float is normalized when its mantissa occupies exactly 128 bits. All in-range normalized floats have `exp >= 0`, so we can use a `uint` for exponents everywhere we expect a normalized float.
When a non-normalized float is expected/used, `exp` can be negative since there is no constraint on the size of the mantissa.
*/
function normalizeRatio(uint mantissa, int exp) internal pure returns (uint, uint) {
require(mantissa != 0,"mgv/normalizeRatio/mantissaIs0");
uint log2ratio = BitLib.fls(mantissa);
int shift = int(MANTISSA_BITS_MINUS_ONE) - int(log2ratio);
if (shift < 0) {
mantissa = mantissa >> uint(-shift);
} else {
mantissa = mantissa << uint(shift);
}
exp = exp + shift;
if (exp < 0) {
revert("mgv/normalizeRatio/lowExp");
}
return (mantissa,uint(exp));
}
/* Return `a/(2**e)` rounded up */
function divExpUp(uint a, uint e) internal pure returns (uint) {
unchecked {
uint rem;
/*
Let mask be `(1<<e)-1`, `rem` is 1 if `a & mask > 0`, and 0 otherwise.
Explanation:
* if a is 0 then `rem` must be 0. `0 & mask` is 0.
* else if `e > 255` then `0 < a < 2^e`, so `rem` must be 1. `(1<<e)-1` is `type(uint).max`, so `a & mask is a > 0`.
* else `a & mask` is `a % 2**e`
*/
assembly("memory-safe") {
rem := gt(and(a,sub(shl(e,1),1)),0)
}
return (a>>e) + rem;
}
}
/* Floats are normalized to 128 bits to ensure no overflow when multiplying with amounts, and for easier comparisons. Normalized in-range floats have `exp>=0`. */
function floatLt(uint mantissa_a, uint exp_a, uint mantissa_b, uint exp_b) internal pure returns (bool) {
/* Exponents are negated (so that exponents of ratios within the accepted range as >= 0, which simplifies the code), which explains the direction of the `exp_a > exp_b` comparison. */
return (exp_a > exp_b || (exp_a == exp_b && mantissa_a < mantissa_b));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
/// @title This contract is used to restrict access to privileged functions of inheriting contracts through modifiers.
/// @notice The contract stores an admin address which is checked against `msg.sender` in the `onlyAdmin` modifier.
/// @notice Additionally, a specific `msg.sender` can be verified with the `onlyCaller` modifier.
contract AccessControlled {
/**
* @notice logs new `admin` of `this`
* @param admin The new admin.
* @notice By emitting this data, an indexer will be able to keep track of what address is the admin of this contract.
*/
event SetAdmin(address admin);
/**
* @notice The admin address.
*/
address internal _admin;
/**
* @notice `AccessControlled`'s constructor
* @param admin_ The address of the admin that can access privileged functions and also allowed to change the admin. Cannot be `address(0)`.
*/
constructor(address admin_) {
_setAdmin(admin_);
}
/**
* @notice This modifier verifies that `msg.sender` is the admin.
*/
modifier onlyAdmin() {
require(msg.sender == _admin, "AccessControlled/Invalid");
_;
}
/**
* @notice This modifier verifies that `msg.sender` is the caller.
* @param caller The address of the caller that can access the modified function.
*/
modifier onlyCaller(address caller) {
require(msg.sender == caller, "AccessControlled/Invalid");
_;
}
/**
* @notice This modifier verifies that `msg.sender` is either caller or the admin
* @param caller The address of a caller that can access the modified function.
*/
modifier adminOrCaller(address caller) {
// test _admin second to save a storage read when possible
require(msg.sender == caller || msg.sender == _admin, "AccessControlled/Invalid");
_;
}
/**
* @notice Retrieves the current admin.
* @return current admin.
*/
function admin() public view returns (address current) {
return _admin;
}
/**
* @notice This function is called to add logic on admin change for inheriting contracts.
* @param admin_ The new admin. Cannot be `address(0)`.
*/
function _onAdminChange(address admin_) internal virtual {}
/**
* @notice This sets and log a new admin
* @param admin_ The new admin. Cannot be `address(0)`.
*/
function _setAdmin(address admin_) internal {
require(admin_ != address(0), "AccessControlled/0xAdmin");
_admin = admin_;
emit SetAdmin(admin_);
_onAdminChange(admin_);
}
/**
* @notice This sets the admin. Only the current admin can change the admin.
* @param admin_ The new admin. Cannot be `address(0)`.
*/
function setAdmin(address admin_) external onlyAdmin {
_setAdmin(admin_);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {IERC20, IMaker, OLKey} from "@mgv/src/core/MgvLib.sol";
import {AbstractRouter, RL} from "@mgv-strats/src/strategies/routers/abstract/AbstractRouter.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
///@title IOfferLogic interface for offer management
///@notice It is an IMaker for Mangrove.
interface IOfferLogic is IMaker {
///@notice Log incident (during post trade execution)
///@param olKeyHash the hash of the offer list key. This is indexed so that RPC calls can filter on it.
///@param offerId the Mangrove offer id. This is indexed so that RPC calls can filter on it.
///@param makerData from the maker.
///@param mgvData from Mangrove.
///@notice By emitting this data, an indexer can keep track of what incidents has happened.
event LogIncident(bytes32 indexed olKeyHash, uint indexed offerId, bytes32 makerData, bytes32 mgvData);
///@notice Approves a spender to transfer a certain amount of tokens on behalf of `this`.
///@param token the ERC20 token contract
///@param spender the approved spender
///@param amount the spending amount
///@return result of token approval.
///@dev admin may use this function to revoke specific approvals of `this` that are set after a call to `activate`.
function approve(IERC20 token, address spender, uint amount) external returns (bool);
///@notice Performs approval that are necessary to trade a given asset
///@param token the traded asset
///@dev anyone can call since only max approval can be set
function activate(IERC20 token) external;
///@notice computes the amount of native tokens that can be redeemed when deprovisioning a given offer.
///@param olKey the offer list key.
///@param offerId the identifier of the offer in the offer list
///@return provision the amount of native tokens that can be redeemed when deprovisioning the offer
function provisionOf(OLKey memory olKey, uint offerId) external view returns (uint provision);
///@notice withdraws native tokens from `this` balance on Mangrove.
///@param amount the amount of WEI one wishes to withdraw.
///@param receiver the address of the receiver of the funds.
///@dev Since a call is made to the `receiver`, this function is subject to reentrancy.
function withdrawFromMangrove(uint amount, address payable receiver) external;
///@notice Memory allocation for `_new/updateOffer`'s arguments.
///@param olKey the offer list key.
///@param tick the tick.
///@param gives the amount of outbound tokens the maker gives for a complete fill.
///@param gasreq the amount of gas units that are required to execute the trade
///@param gasprice the gasprice used to compute offer's provision (use 0 to use Mangrove's gasprice)
///@param fund WEIs in `this` contract's balance that are used to provision the offer.
///@param noRevert is set to true if calling function does not wish `_newOffer` to revert on error.
struct OfferArgs {
OLKey olKey;
Tick tick;
uint gives;
uint gasreq;
uint gasprice;
uint fund;
bool noRevert;
}
/// @notice Contract's Mangrove getter
/// @return the Mangrove contract.
function MGV() external view returns (IMangrove);
///@notice returns the contract that routes owner's funds
///@param owner the fund owner
///@return router the router contract.
///@dev returns `AbstractRouter(address(0))` if the strat is not using a router.
function router(address owner) external view returns (AbstractRouter router);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {AccessControlled} from "@mgv-strats/src/strategies/utils/AccessControlled.sol";
import {RoutingOrderLib as RL} from "./RoutingOrderLib.sol";
/// @title AbstractRouter
/// @notice Partial implementation and requirements for liquidity routers.
abstract contract AbstractRouter is AccessControlled(msg.sender) {
///@notice This modifier verifies that `msg.sender` an allowed caller of this router.
modifier onlyBound() {
require(isBound(msg.sender), "AccessControlled/Invalid");
_;
}
///@notice This modifier verifies that `msg.sender` is the admin or an allowed caller of this router.
modifier boundOrAdmin() {
require(msg.sender == admin() || isBound(msg.sender), "AccessControlled/Invalid");
_;
}
///@notice logging bound maker contract
///@param maker the maker address. This is indexed, so that RPC calls can filter on it.
///@notice by emitting this data, an indexer will be able to keep track of what maker contracts are allowed to call this router.
event MakerBind(address indexed maker);
///@notice logging unbound maker contract
///@param maker the maker address. This is indexed, so that RPC calls can filter on it.
///@notice by emitting this data, an indexer will be able to keep track of what maker contracts are allowed to call this router.
event MakerUnbind(address indexed maker);
///@notice getter for the `makers: addr => bool` mapping
///@param mkr the address of a maker contract
///@return true if `mkr` is authorized to call this router.
function isBound(address mkr) public view virtual returns (bool) {
return RL.boundMakerContracts()[mkr];
}
///@notice pulls liquidity from the reserve and sends it to the calling maker contract.
///@param routingOrder the arguments of the pull order
///@param amount of token that needs to be routed
///@param strict if false the router may pull at more than `amount` to msg.sender. Otherwise it pulls at least `amount`.
///@return pulled the amount of `routingOrder.token` that has been sent to `msg.sender`
function pull(RL.RoutingOrder calldata routingOrder, uint amount, bool strict)
external
onlyBound
returns (uint pulled)
{
if (strict && amount == 0) {
return 0;
}
pulled = __pull__(routingOrder, amount, strict);
}
///@notice router dependent hook to customize pull orders.
///@param routingOrder the arguments of the pull order
///@param amount of token that needs to be routed
///@param strict if false the router may pull at more than `amount` to msg.sender. Otherwise it pulls at least `amount`.
///@return pulled the amount of `routingOrder.token` that has been sent to `msg.sender`
function __pull__(RL.RoutingOrder memory routingOrder, uint amount, bool strict) internal virtual returns (uint);
///@notice pushes liquidity from msg.sender to the reserve
///@param routingOrder the arguments of the push order
///@param amount of token that needs to be routed
///@return pushed the amount of `routingOrder.token` that has been taken from `msg.sender`
function push(RL.RoutingOrder calldata routingOrder, uint amount) external onlyBound returns (uint pushed) {
if (amount == 0) {
return 0;
}
pushed = __push__(routingOrder, amount);
}
///@notice router dependent hook to customize pull orders.
///@param routingOrder the arguments of the pull order
///@param amount of token that needs to be routed
///@return pushed the amount of `routingOrder.token` that has been sent to `msg.sender`
function __push__(RL.RoutingOrder memory routingOrder, uint amount) internal virtual returns (uint pushed);
///@notice iterative `push` of the whole maker contract's balance
///@dev minimizes external calls in case several assets needs to be pushed via the router.
///@param routingOrders to be executed
function flush(RL.RoutingOrder[] memory routingOrders) external onlyBound {
for (uint i = 0; i < routingOrders.length; ++i) {
uint amount = routingOrders[i].token.balanceOf(msg.sender);
if (amount > 0) {
require(__push__(routingOrders[i], amount) == amount, "router/flushFailed");
}
}
}
///@notice adds a maker contract address to the allowed makers of this router
///@dev this function is callable by router's admin to bootstrap, but later on an allowed maker contract can add another address
///@param makerContract the maker contract address
function bind(address makerContract) public onlyAdmin {
RL.boundMakerContracts()[makerContract] = true;
emit MakerBind(makerContract);
}
///@notice removes a maker contract address from the allowed makers of this router
///@param makerContract the maker contract address
function _unbind(address makerContract) internal {
RL.boundMakerContracts()[makerContract] = false;
emit MakerUnbind(makerContract);
}
///@notice removes `msg.sender` from the allowed makers of this router
function unbind() external onlyBound {
_unbind(msg.sender);
}
///@notice removes a makerContract from the allowed makers of this router
///@param makerContract the maker contract address
function unbind(address makerContract) external onlyAdmin {
_unbind(makerContract);
}
/**
* @notice Returns the token balance available for a specific routing order
* @param routingOrder The routing order to check the balance for
* @return balance The balance of the token in the routing order
*/
function tokenBalanceOf(RL.RoutingOrder calldata routingOrder) public view virtual returns (uint balance);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@mgv/src/core/MgvLib.sol";
///@title This library helps with safely interacting with ERC20 tokens
///@notice Transferring 0 or to self will be skipped.
///@notice ERC20 tokens returning bool instead of reverting are handled.
library TransferLib {
///@notice This transfer amount of token to recipient address
///@param token Token to be transferred
///@param recipient Address of the recipient the tokens will be transferred to
///@param amount The amount of tokens to be transferred
///@return true if transfer was successful; otherwise, false.
function transferToken(IERC20 token, address recipient, uint amount) internal returns (bool) {
if (amount == 0) {
return true;
}
if (recipient == address(this)) {
return token.balanceOf(recipient) >= amount;
}
return _transferToken(token, recipient, amount);
}
///@notice This transfer amount of token to recipient address
///@param token Token to be transferred
///@param recipient Address of the recipient the tokens will be transferred to
///@param amount The amount of tokens to be transferred
///@return true if transfer was successful; otherwise, false.
function _transferToken(IERC20 token, address recipient, uint amount) private returns (bool) {
// This low level call will not revert but instead return success=false if callee reverts, so we
// verify that it does not revert by checking success, but we also have to check
// the returned data if any since some ERC20 tokens to not strictly follow the standard of reverting
// but instead return false.
(bool success, bytes memory data) =
address(token).call(abi.encodeWithSelector(token.transfer.selector, recipient, amount));
return (success && (data.length == 0 || abi.decode(data, (bool))));
}
///@notice This transfer amount of token to recipient address from spender address
///@param token Token to be transferred
///@param spender Address of the spender, where the tokens will be transferred from
///@param recipient Address of the recipient, where the tokens will be transferred to
///@param amount The amount of tokens to be transferred
///@return true if transfer was successful; otherwise, false.
function transferTokenFrom(IERC20 token, address spender, address recipient, uint amount) internal returns (bool) {
if (amount == 0) {
return true;
}
if (spender == recipient) {
return token.balanceOf(spender) >= amount;
}
// optimization to avoid requiring contract to approve itself
if (spender == address(this)) {
return _transferToken(token, recipient, amount);
}
return _transferTokenFrom(token, spender, recipient, amount);
}
///@notice This transfer amount of token to recipient address from spender address
///@param token Token to be transferred
///@param spender Address of the spender, where the tokens will be transferred from
///@param recipient Address of the recipient, where the tokens will be transferred to
///@param amount The amount of tokens to be transferred
///@return true if transfer was successful; otherwise, false.
function _transferTokenFrom(IERC20 token, address spender, address recipient, uint amount) private returns (bool) {
// This low level call will not revert but instead return success=false if callee reverts, so we
// verify that it does not revert by checking success, but we also have to check
// the returned data if there since some ERC20 tokens to not strictly follow the standard of reverting
// but instead return false.
(bool success, bytes memory data) =
address(token).call(abi.encodeWithSelector(token.transferFrom.selector, spender, recipient, amount));
return (success && (data.length == 0 || abi.decode(data, (bool))));
}
///@notice ERC20 approval, handling non standard approvals that do not return a value
///@param token the ERC20
///@param spender the address whose allowance is to be given
///@param amount of the allowance
///@return true if approval was successful; otherwise, false.
function _approveToken(IERC20 token, address spender, uint amount) private returns (bool) {
// This low level call will not revert but instead return success=false if callee reverts, so we
// verify that it does not revert by checking success, but we also have to check
// the returned data if any since some ERC20 tokens to not strictly follow the standard of reverting
// but instead return false.
(bool success, bytes memory data) =
address(token).call(abi.encodeWithSelector(token.approve.selector, spender, amount));
return (success && (data.length == 0 || abi.decode(data, (bool))));
}
///@notice ERC20 approval, handling non standard approvals that do not return a value
///@param token the ERC20
///@param spender the address whose allowance is to be given
///@param amount of the allowance
///@return true if approval was successful; otherwise, false.
function approveToken(IERC20 token, address spender, uint amount) internal returns (bool) {
return _approveToken(token, spender, amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {MgvLib, OLKey, Offer} from "@mgv/src/core/MgvLib.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {IERC20} from "@mgv/lib/IERC20.sol";
import {OfferType} from "./TradesBaseQuotePair.sol";
import {DirectWithBidsAndAsksDistribution} from "./DirectWithBidsAndAsksDistribution.sol";
import {TradesBaseQuotePair} from "./TradesBaseQuotePair.sol";
import {TransferLib} from "@mgv/lib/TransferLib.sol";
import {KandelLib} from "./KandelLib.sol";
import {MAX_SAFE_VOLUME} from "@mgv/lib/core/Constants.sol";
///@title the core of Kandel strategies which creates or updates a dual offer whenever an offer is taken.
///@notice `CoreKandel` is agnostic to the chosen price distribution.
abstract contract CoreKandel is DirectWithBidsAndAsksDistribution, TradesBaseQuotePair {
///@notice the gasprice has been set.
///@param value the gasprice for offers.
///@notice By emitting this data, an indexer will be able to keep track of what gasprice is used.
event SetGasprice(uint value);
///@notice the gasreq has been set.
///@param value the gasreq (including router's gasreq) for offers
///@notice By emitting this data, an indexer will be able to keep track of what gasreq is used.
event SetGasreq(uint value);
///@notice the step size has been set.
///@param value the step size in amount of price points to jump for posting dual offer
event SetStepSize(uint value);
///@notice the Kandel instance is credited of `amount` by its owner.
///@param token the asset. This is indexed so that RPC calls can filter on it.
///@param amount the amount.
///@notice By emitting this data, an indexer will be able to keep track of what credits are made.
event Credit(IERC20 indexed token, uint amount);
///@notice the Kandel instance is debited of `amount` by its owner.
///@param token the asset. This is indexed so that RPC calls can filter on it.
///@param amount the amount.
///@notice By emitting this data, an indexer will be able to keep track of what debits are made.
event Debit(IERC20 indexed token, uint amount);
///@notice Core Kandel parameters
///@param gasprice the gasprice to use for offers. Must hold on 26 bits.
///@param gasreq the gasreq to use for offers
///@param stepSize in amount of price points to jump for posting dual offer.
///@param pricePoints the number of price points for the Kandel instance.
struct Params {
uint32 gasprice;
uint24 gasreq;
uint32 stepSize;
uint32 pricePoints;
}
///@notice Storage of the parameters for the strat.
Params public params;
///@notice sets the step size
///@param stepSize the step size.
function setStepSize(uint stepSize) public onlyAdmin {
uint32 stepSize_ = uint32(stepSize);
require(stepSize > 0, "Kandel/stepSizeTooLow");
require(stepSize_ == stepSize && stepSize < params.pricePoints, "Kandel/stepSizeTooHigh");
params.stepSize = stepSize_;
emit SetStepSize(stepSize);
}
///@notice sets the gasprice for offers
///@param gasprice the gasprice.
function setGasprice(uint gasprice) public onlyAdmin {
require(gasprice < 1 << 26, "Kandel/gaspriceTooHigh");
params.gasprice = uint32(gasprice);
emit SetGasprice(gasprice);
}
///@notice sets the gasreq (including router's gasreq) for offers
///@param gasreq the gasreq.
function setGasreq(uint gasreq) public onlyAdmin {
uint24 gasreq_ = uint24(gasreq);
require(gasreq_ == gasreq, "Kandel/gasreqTooHigh");
params.gasreq = gasreq_;
emit SetGasreq(gasreq_);
}
/// @notice Updates the params to new values.
/// @param newParams the new params to set.
function setParams(Params calldata newParams) internal {
Params memory oldParams = params;
if (oldParams.pricePoints != newParams.pricePoints) {
uint32 pricePoints_ = newParams.pricePoints;
require(pricePoints_ >= 2, "Kandel/invalidPricePoints");
setLength(pricePoints_);
params.pricePoints = pricePoints_;
}
if (oldParams.stepSize != newParams.stepSize) {
setStepSize(newParams.stepSize);
}
if (newParams.gasprice != 0 && newParams.gasprice != oldParams.gasprice) {
setGasprice(newParams.gasprice);
}
if (newParams.gasreq != 0 && newParams.gasreq != oldParams.gasreq) {
setGasreq(newParams.gasreq);
}
}
///@notice Constructor
///@param mgv The Mangrove deployment.
///@param olKeyBaseQuote The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
///@param routerParams parameters when using a router.
constructor(IMangrove mgv, OLKey memory olKeyBaseQuote, RouterParams memory routerParams)
TradesBaseQuotePair(olKeyBaseQuote)
DirectWithBidsAndAsksDistribution(mgv, routerParams)
{}
///@notice publishes bids/asks for the distribution in the `indices`. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead).
///@param distribution the distribution of bids and asks to populate
///@param parameters the parameters for Kandel. Only changed parameters will cause updates. Set `gasreq` and `gasprice` to 0 to keep existing values.
///@param baseAmount base amount to deposit
///@param quoteAmount quote amount to deposit
///@dev This function is used at initialization and can fund with provision for the offers.
///@dev Use `populateChunk` to split up initialization or re-initialization with same parameters, as this function will emit.
///@dev If this function is invoked with different pricePoints or stepSize, then first retract all offers.
///@dev msg.value must be enough to provision all posted offers (for chunked initialization only one call needs to send native tokens).
function populate(Distribution memory distribution, Params calldata parameters, uint baseAmount, uint quoteAmount)
public
payable
onlyAdmin
{
if (msg.value > 0) {
MGV.fund{value: msg.value}();
}
setParams(parameters);
depositFunds(baseAmount, quoteAmount);
populateChunkInternal(distribution, params.gasreq, params.gasprice);
}
///@notice Publishes bids/asks for the distribution in the `indices`. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead).
///@notice This function is used externally after `populate` to reinitialize some indices or if multiple transactions are needed to split initialization due to gas cost.
///@notice This function is not payable, use `populate` to fund along with populate.
///@param distribution the distribution of bids and asks to populate
function populateChunk(Distribution calldata distribution) external onlyAdmin {
Params memory parameters = params;
populateChunkInternal(distribution, parameters.gasreq, parameters.gasprice);
}
///@notice the total balance available for the strat of the offered token for the given offer type.
///@param ba the offer type.
///@return balance the balance of the token.
function reserveBalance(OfferType ba) public view virtual returns (uint balance) {
IERC20 token = outboundOfOfferType(ba);
return token.balanceOf(address(this));
}
///@notice takes care of status for updating dual and logging of potential issues.
///@param offerId the Mangrove offer id.
///@param args the arguments of the offer.
///@param updateOfferStatus the status returned from the `_updateOffer` function.
function logUpdateOfferStatus(uint offerId, OfferArgs memory args, bytes32 updateOfferStatus) internal {
if (updateOfferStatus == REPOST_SUCCESS || updateOfferStatus == "mgv/writeOffer/density/tooLow") {
// Low density will mean some amount is not posted and will be available for withdrawal or later posting via populate.
return;
}
emit LogIncident(args.olKey.hash(), offerId, "Kandel/updateOfferFailed", updateOfferStatus);
}
///@notice update or create dual offer according to transport logic
///@param order is a recall of the taker order that is at the origin of the current trade.
function transportSuccessfulOrder(MgvLib.SingleOrder calldata order) internal {
OfferType ba = offerTypeOfOutbound(IERC20(order.olKey.outbound_tkn));
// adds any unpublished liquidity to pending[Base/Quote]
// preparing arguments for the dual offer
(uint offerId, OfferArgs memory args) = transportLogic(ba, order);
// All offers are created up front (see populateChunk), so here we update to set new gives.
bytes32 updateOfferStatus = _updateOffer(args, offerId);
logUpdateOfferStatus(offerId, args, updateOfferStatus);
}
///@notice transport logic followed by Kandel
///@param ba whether the offer that was executed is a bid or an ask
///@param order a recap of the taker order (order.offer is the executed offer)
///@return dualOfferId the offer id of the dual offer
///@return args the argument for updating an offer
function transportLogic(OfferType ba, MgvLib.SingleOrder calldata order)
internal
virtual
returns (uint dualOfferId, OfferArgs memory args)
{
uint index = indexOfOfferId(ba, order.offerId);
Params memory memoryParams = params;
OfferType baDual = dual(ba);
uint dualIndex = KandelLib.transportDestination(baDual, index, memoryParams.stepSize, memoryParams.pricePoints);
dualOfferId = offerIdOfIndex(baDual, dualIndex);
args.olKey = offerListOfOfferType(baDual);
Offer dualOffer = MGV.offers(args.olKey, dualOfferId);
// gives from order.takerGives:127 dualOffer.gives():127, so args.gives:128
args.gives = order.takerGives + dualOffer.gives();
if (args.gives > MAX_SAFE_VOLUME) {
// this should not be reached under normal circumstances unless strat is posting on top of an existing offer with an abnormal volume
// to prevent gives to be too high, we let the surplus become "pending" (unpublished liquidity)
args.gives = MAX_SAFE_VOLUME;
// There is no similar limit to dualOffer.wants() for allowed ticks and gives.
}
// keep existing price of offer
args.tick = dualOffer.tick();
// args.fund = 0; the offers are already provisioned
// posthook should not fail if unable to post offers, we capture the error as incidents
args.noRevert = true;
// use newest gasreq and gasprice
args.gasprice = memoryParams.gasprice;
args.gasreq = memoryParams.gasreq;
}
/// @notice gets pending liquidity for base (ask) or quote (bid). Will be negative if funds are not enough to cover all offer's promises.
/// @param ba offer type.
/// @return the pending amount
/// @dev Gas costly function, better suited for off chain calls.
function pending(OfferType ba) external view returns (int) {
return int(reserveBalance(ba)) - int(offeredVolume(ba));
}
///@notice Deposits funds to the contract's reserve
///@param baseAmount the amount of base tokens to deposit.
///@param quoteAmount the amount of quote tokens to deposit.
function depositFunds(uint baseAmount, uint quoteAmount) public virtual {
require(TransferLib.transferTokenFrom(BASE, msg.sender, address(this), baseAmount), "Kandel/baseTransferFail");
emit Credit(BASE, baseAmount);
require(TransferLib.transferTokenFrom(QUOTE, msg.sender, address(this), quoteAmount), "Kandel/quoteTransferFail");
emit Credit(QUOTE, quoteAmount);
}
///@notice withdraws funds from the contract's reserve
///@param baseAmount the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
///@param quoteAmount the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
///@param recipient the address to which the withdrawn funds should be sent to.
///@dev it is up to the caller to make sure there are still enough funds for live offers.
function withdrawFunds(uint baseAmount, uint quoteAmount, address recipient) public virtual onlyAdmin {
withdrawFundsForToken(BASE, baseAmount, recipient);
withdrawFundsForToken(QUOTE, quoteAmount, recipient);
}
///@notice withdraws funds from the contract's reserve for the given token
///@param token the token to withdraw.
///@param amount the amount of tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
///@param recipient the address to which the withdrawn funds should be sent to.
function withdrawFundsForToken(IERC20 token, uint amount, address recipient) internal virtual {
if (amount == type(uint).max) {
amount = token.balanceOf(address(this));
}
require(TransferLib.transferToken(token, recipient, amount), "Kandel/transferFail");
emit Debit(token, amount);
}
///@notice Retracts offers, withdraws funds, and withdraws free wei from Mangrove.
///@param from retract offers starting from this index.
///@param to retract offers until this index.
///@param baseAmount the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
///@param quoteAmount the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
///@param freeWei the amount of wei to withdraw from Mangrove. Use type(uint).max to withdraw entire available balance.
///@param recipient the recipient of the funds.
function retractAndWithdraw(
uint from,
uint to,
uint baseAmount,
uint quoteAmount,
uint freeWei,
address payable recipient
) external onlyAdmin {
retractOffers(from, to);
withdrawFunds(baseAmount, quoteAmount, recipient);
withdrawFromMangrove(freeWei, recipient);
}
}// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; /* The constants below are written as literals to optimize gas. For all the relevant constants here, the non-literal expression that computes them is checked in `Constants.t.sol`. */ uint constant ONE = 1; uint constant ONES = type(uint).max; uint constant TOPBIT = 0x8000000000000000000000000000000000000000000000000000000000000000; uint constant NOT_TOPBIT = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /* **sizes must match field sizes in `structs.ts` where relevant** */ /* Number of bits used to represent a tick */ uint constant TICK_BITS = 21; /* Number of bits used to represent an offer id */ uint constant OFFER_BITS = 32; /* Maximum possible size of a field -- protects against wrong code changes. Constraint given by `BitLib.ctz64`. */ uint constant MAX_FIELD_SIZE = 64; /* `X_SIZE_BITS` is 1+log2 of the size of `X`, where size is the number of elements it holds.In a field, an element is a bit; in a leaf, an element is a pair of offer ids. For `LEVEL`s and `ROOT`, the value must be exact, so only power-of-2 sizes are allowed. */ uint constant LEAF_SIZE_BITS = 2; uint constant LEVEL_SIZE_BITS = 6; uint constant ROOT_SIZE_BITS = 1; /* `X_SIZE` is `2**X_SIZE_BITS` */ int constant LEAF_SIZE = 4; int constant LEVEL_SIZE = 64; int constant ROOT_SIZE = 2; /* `X_SIZE_MASK` is `0...01...1` where the number of 1s is `X_SIZE_BITS` */ uint constant LEAF_SIZE_MASK = 0x3; uint constant LEVEL_SIZE_MASK = 0x3f; uint constant ROOT_SIZE_MASK = 0x1; /* `0...01...1` with `OFFER_BITS` 1s at the end */ uint constant OFFER_MASK = 0xffffffff; /* Same as `ROOT_SIZE` */ int constant NUM_LEVEL1 = 2; /* Same as `NUM_LEVEL1 * LEVEL_SIZE` */ int constant NUM_LEVEL2 = 128; /* Same as `NUM_LEVEL2 * LEVEL_SIZE` */ int constant NUM_LEVEL3 = 8192; /* Same as `NUM_LEVEL3 * LEVEL_SIZE` */ int constant NUM_LEAFS = 524288; /* Same as `NUM_LEAFS * LEAF` */ int constant NUM_BINS = 2097152; /* min and max bins are defined like min and max int. */ int constant MIN_BIN = -1048576; int constant MAX_BIN = 1048575; /* The tick range is the largest such that the mantissa of `1.0001^MAX_TICK` fits on 128 bits (and thus can be multiplied by volumes). */ int constant MIN_TICK = -887272; int constant MAX_TICK = 887272; /* These are reference values for what the function `tickFromRatio` function will return, not the most possible accurate values for the min and max tick. */ uint constant MIN_RATIO_MANTISSA = 170153974464283981435225617938057077692; int constant MIN_RATIO_EXP = 255; uint constant MAX_RATIO_MANTISSA = 340256786836388094050805785052946541084; int constant MAX_RATIO_EXP = 0; /* `MANTISSA_BITS` is the number of bits used in the mantissa of normalized floats that represent ratios. 128 means we can multiply all allowed volumes by the mantissa and not overflow. */ uint constant MANTISSA_BITS = 128; uint constant MANTISSA_BITS_MINUS_ONE = 127; /* With `|tick|<=887272` and normalized mantissas on 128 bits, the maximum possible mantissa is `340282295208261841796968287475569060645`, so the maximum safe volume before overflow is `NO_OVERFLOW_AMOUNT = 340282438633630198193436196978374475856` (slightly above `2**128`). For ease of use, we could pick a simpler, slightly smaller max safe volume: `(1<<128)-1`. However the `*ByVolume` functions get a price by (abstractly) performing `outboundAmount/inboundAmount`. If we limit all volumes to `NO_OVERFLOW_AMOUNT` but aren't more restrictive than that, since `type(uint128).max > 1.0001**MAX_TICK`, we will get ratios that are outside the price boundaries. We thus pick a uniform, easy to remember constraint on volumes that works everywhere: `(1<<127)-1` */ uint constant MAX_SAFE_VOLUME = 170141183460469231731687303715884105727; /* When a market order consumes offers, the implementation uses recursion consumes additional EVM stack space at each new offer. To avoid reverting due to stack overflow, Mangrove keeps a counter and stops the market order when it reaches a maximum recursion depth. `INITIAL_MAX_RECURSION_DEPTH` is the maximum recursion depth given at deployment time. See `maxRecursionDepth` in `structs.ts` Without optimizer enabled it fails above 79. With optimizer and 200 runs it fails above 80. Set default a bit lower to be safe. */ uint constant INITIAL_MAX_RECURSION_DEPTH = 75; /* When a market order consumes offers, it may use gas on offers that fail to deliver. To avoid reverts after a string of failing offers that consumes more gas than is available in a block, Mangrove stops a market order after it has gone through failing offers such that their cumulative `gasreq` is greater than the global `maxGasreqForFailingOffers` parameter. At deployment, `maxGasreqForFailingOffers` is set to: ``` INITIAL_MAX_GASREQ_FOR_FAILING_OFFERS_MULTIPLIER * gasmax ``` */ uint constant INITIAL_MAX_GASREQ_FOR_FAILING_OFFERS_MULTIPLIER = 3; /* Those two constants are used in `TickLib.ratioFromTick` to convert a log base 1.0001 to a log base 2. */ uint constant LOG_BP_SHIFT = 235; uint constant LOG_BP_2X235 = 382733217082594961806491056566382061424140926068392360945012727618364717537;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {OfferType} from "./TradesBaseQuotePair.sol";
import {MAX_TICK, MIN_TICK} from "@mgv/lib/core/Constants.sol";
import {DirectWithBidsAndAsksDistribution} from "./DirectWithBidsAndAsksDistribution.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
///@title Library of helper functions for Kandel, mainly to reduce deployed size.
library KandelLib {
///@notice returns the destination index to transport received liquidity to - a better (for Kandel) price index for the offer type.
///@param ba the offer type to transport to
///@param index the price index one is willing to improve
///@param step the number of price steps improvements
///@param pricePoints the number of price points
///@return better destination index
function transportDestination(OfferType ba, uint index, uint step, uint pricePoints)
internal
pure
returns (uint better)
{
if (ba == OfferType.Ask) {
better = index + step;
if (better >= pricePoints) {
better = pricePoints - 1;
}
} else {
if (index >= step) {
better = index - step;
}
// else better = 0
}
}
///@notice Creates a distribution of bids and asks given by the parameters. Dual offers are included with gives=0.
///@param from populate offers starting from this index (inclusive). Must be at most `pricePoints`.
///@param to populate offers until this index (exclusive). Must be at most `pricePoints`.
///@param baseQuoteTickIndex0 the tick for the price point at index 0 given as a tick on the `base, quote` offer list, i.e. corresponding to an ask with a quote/base ratio. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param _baseQuoteTickOffset the tick offset used for the geometric progression deployment. Must be at least 1. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
///@param firstAskIndex the (inclusive) index after which offer should be an ask. Must be at most `pricePoints`.
///@param bidGives The initial amount of quote to give for all bids. If 0, only book the offer, if type(uint).max then askGives is used as base for bids, and the quote the bid gives is set to according to the price.
///@param askGives The initial amount of base to give for all asks. If 0, only book the offer, if type(uint).max then bidGives is used as quote for asks, and the base the ask gives is set to according to the price.
///@param stepSize in amount of price points to jump for posting dual offer. Must be less than `pricePoints`.
///@param pricePoints the number of price points for the Kandel instance. Must be at least 2.
///@return distribution the distribution of bids and asks to populate
///@dev the absolute price of an offer is the ratio of quote/base volumes of tokens it trades
///@dev the tick of offers on Mangrove are in relative taker price of maker's inbound/outbound volumes of tokens it trades
///@dev for Bids, outbound_tkn=quote, inbound_tkn=base so relative taker price of a a bid is the inverse of the absolute price.
///@dev for Asks, outbound_tkn=base, inbound_tkn=quote so relative taker price of an ask coincides with absolute price.
///@dev Index0 will contain the ask with the lowest relative price and the bid with the highest relative price. Absolute price is geometrically increasing over indexes.
///@dev tickOffset moves an offer relative price s.t. `AskTick_{i+1} = AskTick_i + tickOffset` and `BidTick_{i+1} = BidTick_i - tickOffset`
///@dev A hole is left in the middle at the size of stepSize - either an offer or its dual is posted, not both.
///@dev The caller should make sure the minimum and maximum tick does not exceed the MIN_TICK and MAX_TICK from respectively; otherwise, populate will fail for those offers.
///@dev If type(uint).max is used for `bidGives` or `askGives` then very high or low prices can yield gives=0 (which results in both offer an dual being dead) or gives>=type(uin96).max which is not supported by Mangrove.
function createGeometricDistribution(
uint from,
uint to,
Tick baseQuoteTickIndex0,
uint _baseQuoteTickOffset,
uint firstAskIndex,
uint bidGives,
uint askGives,
uint pricePoints,
uint stepSize
) external pure returns (DirectWithBidsAndAsksDistribution.Distribution memory distribution) {
require(bidGives != type(uint).max || askGives != type(uint).max, "Kandel/bothGivesVariable");
// First we restrict boundaries of bids and asks.
// Create live bids up till first ask, except stop where live asks will have a dual bid.
uint bidBound;
{
// Rounding - we skip an extra live bid if stepSize is odd.
uint bidHoleSize = stepSize / 2 + stepSize % 2;
// If first ask is close to start, then there are no room for live bids.
bidBound = firstAskIndex > bidHoleSize ? firstAskIndex - bidHoleSize : 0;
// If stepSize is large there is not enough room for dual outside
uint lastBidWithPossibleDualAsk = pricePoints - stepSize;
if (bidBound > lastBidWithPossibleDualAsk) {
bidBound = lastBidWithPossibleDualAsk;
}
}
// Here firstAskIndex becomes the index of the first actual ask, and not just the boundary - we need to take `stepSize` and `from` into account.
firstAskIndex = firstAskIndex + stepSize / 2;
// We should not place live asks near the beginning, there needs to be room for the dual bid.
if (firstAskIndex < stepSize) {
firstAskIndex = stepSize;
}
// Finally, account for the from/to boundaries
if (to < bidBound) {
bidBound = to;
}
if (firstAskIndex < from) {
firstAskIndex = from;
}
// Allocate distributions - there should be room for live bids and asks, and their duals.
{
uint count = (from < bidBound ? bidBound - from : 0) + (firstAskIndex < to ? to - firstAskIndex : 0);
distribution.bids = new DirectWithBidsAndAsksDistribution.DistributionOffer[](count);
distribution.asks = new DirectWithBidsAndAsksDistribution.DistributionOffer[](count);
}
// Start bids at from
uint index = from;
// Calculate the taker relative tick of the first price point
int tick = -(Tick.unwrap(baseQuoteTickIndex0) + int(_baseQuoteTickOffset) * int(index));
// A counter for insertion in the distribution structs
uint i = 0;
for (; index < bidBound; ++index) {
// Add live bid
// Use askGives unless it should be derived from bid at the price
distribution.bids[i] = DirectWithBidsAndAsksDistribution.DistributionOffer({
index: index,
tick: Tick.wrap(tick),
gives: bidGives == type(uint).max ? Tick.wrap(tick).outboundFromInbound(askGives) : bidGives
});
// Add dual (dead) ask
uint dualIndex = transportDestination(OfferType.Ask, index, stepSize, pricePoints);
distribution.asks[i] = DirectWithBidsAndAsksDistribution.DistributionOffer({
index: dualIndex,
tick: Tick.wrap((Tick.unwrap(baseQuoteTickIndex0) + int(_baseQuoteTickOffset) * int(dualIndex))),
gives: 0
});
// Next tick
tick -= int(_baseQuoteTickOffset);
++i;
}
// Start asks from (adjusted) firstAskIndex
index = firstAskIndex;
// Calculate the taker relative tick of the first ask
tick = (Tick.unwrap(baseQuoteTickIndex0) + int(_baseQuoteTickOffset) * int(index));
for (; index < to; ++index) {
// Add live ask
// Use askGives unless it should be derived from bid at the price
distribution.asks[i] = DirectWithBidsAndAsksDistribution.DistributionOffer({
index: index,
tick: Tick.wrap(tick),
gives: askGives == type(uint).max ? Tick.wrap(tick).outboundFromInbound(bidGives) : askGives
});
// Add dual (dead) bid
uint dualIndex = transportDestination(OfferType.Bid, index, stepSize, pricePoints);
distribution.bids[i] = DirectWithBidsAndAsksDistribution.DistributionOffer({
index: dualIndex,
tick: Tick.wrap(-(Tick.unwrap(baseQuoteTickIndex0) + int(_baseQuoteTickOffset) * int(dualIndex))),
gives: 0
});
// Next tick
tick += int(_baseQuoteTickOffset);
++i;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/* ************************************************** *
GENERATED FILE. DO NOT EDIT.
* ************************************************** */
/* since you can't convert bool to uint in an expression without conditionals,
* we add a file-level function and rely on compiler optimization
*/
function uint_of_bool(bool b) pure returns (uint u) {
assembly ("memory-safe") { u := b }
}
import "@mgv/lib/core/Constants.sol";
struct OfferUnpacked {
uint prev;
uint next;
Tick tick;
uint gives;
}
//some type safety for each struct
type Offer is uint;
using OfferLib for Offer global;
////////////// ADDITIONAL DEFINITIONS, IF ANY ////////////////
import {Bin} from "@mgv/lib/core/TickTreeLib.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
import {OfferExtra,OfferUnpackedExtra} from "@mgv/lib/core/OfferExtra.sol";
using OfferExtra for Offer global;
using OfferUnpackedExtra for OfferUnpacked global;
////////////// END OF ADDITIONAL DEFINITIONS /////////////////
library OfferLib {
// number of bits in each field
uint constant prev_bits = 32;
uint constant next_bits = 32;
uint constant tick_bits = 21;
uint constant gives_bits = 127;
// number of bits before each field
uint constant prev_before = 0 + 0;
uint constant next_before = prev_before + prev_bits;
uint constant tick_before = next_before + next_bits;
uint constant gives_before = tick_before + tick_bits;
// focus-mask: 1s at field location, 0s elsewhere
uint constant prev_mask_inv = (ONES << 256 - prev_bits) >> prev_before;
uint constant next_mask_inv = (ONES << 256 - next_bits) >> next_before;
uint constant tick_mask_inv = (ONES << 256 - tick_bits) >> tick_before;
uint constant gives_mask_inv = (ONES << 256 - gives_bits) >> gives_before;
// cleanup-mask: 0s at field location, 1s elsewhere
uint constant prev_mask = ~prev_mask_inv;
uint constant next_mask = ~next_mask_inv;
uint constant tick_mask = ~tick_mask_inv;
uint constant gives_mask = ~gives_mask_inv;
// cast-mask: 0s followed by |field| trailing 1s
uint constant prev_cast_mask = ~(ONES << prev_bits);
uint constant next_cast_mask = ~(ONES << next_bits);
uint constant tick_cast_mask = ~(ONES << tick_bits);
uint constant gives_cast_mask = ~(ONES << gives_bits);
// size-related error message
string constant prev_size_error = "mgv/config/prev/32bits";
string constant next_size_error = "mgv/config/next/32bits";
string constant tick_size_error = "mgv/config/tick/21bits";
string constant gives_size_error = "mgv/config/gives/127bits";
// from packed to in-memory struct
function to_struct(Offer __packed) internal pure returns (OfferUnpacked memory __s) { unchecked {
__s.prev = uint(Offer.unwrap(__packed) << prev_before) >> (256 - prev_bits);
__s.next = uint(Offer.unwrap(__packed) << next_before) >> (256 - next_bits);
__s.tick = Tick.wrap(int(int(Offer.unwrap(__packed) << tick_before) >> (256 - tick_bits)));
__s.gives = uint(Offer.unwrap(__packed) << gives_before) >> (256 - gives_bits);
}}
// equality checking
function eq(Offer __packed1, Offer __packed2) internal pure returns (bool) { unchecked {
return Offer.unwrap(__packed1) == Offer.unwrap(__packed2);
}}
// from packed to a tuple
function unpack(Offer __packed) internal pure returns (uint __prev, uint __next, Tick __tick, uint __gives) { unchecked {
__prev = uint(Offer.unwrap(__packed) << prev_before) >> (256 - prev_bits);
__next = uint(Offer.unwrap(__packed) << next_before) >> (256 - next_bits);
__tick = Tick.wrap(int(int(Offer.unwrap(__packed) << tick_before) >> (256 - tick_bits)));
__gives = uint(Offer.unwrap(__packed) << gives_before) >> (256 - gives_bits);
}}
// getters
function prev(Offer __packed) internal pure returns(uint) { unchecked {
return uint(Offer.unwrap(__packed) << prev_before) >> (256 - prev_bits);
}}
// setters
function prev(Offer __packed,uint val) internal pure returns(Offer) { unchecked {
return Offer.wrap((Offer.unwrap(__packed) & prev_mask) | (val << (256 - prev_bits)) >> prev_before);
}}
function next(Offer __packed) internal pure returns(uint) { unchecked {
return uint(Offer.unwrap(__packed) << next_before) >> (256 - next_bits);
}}
// setters
function next(Offer __packed,uint val) internal pure returns(Offer) { unchecked {
return Offer.wrap((Offer.unwrap(__packed) & next_mask) | (val << (256 - next_bits)) >> next_before);
}}
function tick(Offer __packed) internal pure returns(Tick) { unchecked {
return Tick.wrap(int(int(Offer.unwrap(__packed) << tick_before) >> (256 - tick_bits)));
}}
// setters
function tick(Offer __packed,Tick val) internal pure returns(Offer) { unchecked {
return Offer.wrap((Offer.unwrap(__packed) & tick_mask) | (uint(Tick.unwrap(val)) << (256 - tick_bits)) >> tick_before);
}}
function gives(Offer __packed) internal pure returns(uint) { unchecked {
return uint(Offer.unwrap(__packed) << gives_before) >> (256 - gives_bits);
}}
// setters
function gives(Offer __packed,uint val) internal pure returns(Offer) { unchecked {
return Offer.wrap((Offer.unwrap(__packed) & gives_mask) | (val << (256 - gives_bits)) >> gives_before);
}}
// from in-memory struct to packed
function t_of_struct(OfferUnpacked memory __s) internal pure returns (Offer) { unchecked {
return pack(__s.prev, __s.next, __s.tick, __s.gives);
}}
// from arguments to packed
function pack(uint __prev, uint __next, Tick __tick, uint __gives) internal pure returns (Offer) { unchecked {
uint __packed;
__packed |= (__prev << (256 - prev_bits)) >> prev_before;
__packed |= (__next << (256 - next_bits)) >> next_before;
__packed |= (uint(Tick.unwrap(__tick)) << (256 - tick_bits)) >> tick_before;
__packed |= (__gives << (256 - gives_bits)) >> gives_before;
return Offer.wrap(__packed);
}}
// input checking
function prev_check(uint __prev) internal pure returns (bool) { unchecked {
return (__prev & prev_cast_mask) == __prev;
}}
function next_check(uint __next) internal pure returns (bool) { unchecked {
return (__next & next_cast_mask) == __next;
}}
function tick_check(Tick __tick) internal pure returns (bool) { unchecked {
return (uint(Tick.unwrap(__tick)) & tick_cast_mask) == uint(Tick.unwrap(__tick));
}}
function gives_check(uint __gives) internal pure returns (bool) { unchecked {
return (__gives & gives_cast_mask) == __gives;
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/* ************************************************** *
GENERATED FILE. DO NOT EDIT.
* ************************************************** */
/* since you can't convert bool to uint in an expression without conditionals,
* we add a file-level function and rely on compiler optimization
*/
function uint_of_bool(bool b) pure returns (uint u) {
assembly ("memory-safe") { u := b }
}
import "@mgv/lib/core/Constants.sol";
struct OfferDetailUnpacked {
address maker;
uint gasreq;
uint kilo_offer_gasbase;
uint gasprice;
}
//some type safety for each struct
type OfferDetail is uint;
using OfferDetailLib for OfferDetail global;
////////////// ADDITIONAL DEFINITIONS, IF ANY ////////////////
import {OfferDetailExtra,OfferDetailUnpackedExtra} from "@mgv/lib/core/OfferDetailExtra.sol";
using OfferDetailExtra for OfferDetail global;
using OfferDetailUnpackedExtra for OfferDetailUnpacked global;
////////////// END OF ADDITIONAL DEFINITIONS /////////////////
library OfferDetailLib {
// number of bits in each field
uint constant maker_bits = 160;
uint constant gasreq_bits = 24;
uint constant kilo_offer_gasbase_bits = 9;
uint constant gasprice_bits = 26;
// number of bits before each field
uint constant maker_before = 0 + 0;
uint constant gasreq_before = maker_before + maker_bits;
uint constant kilo_offer_gasbase_before = gasreq_before + gasreq_bits;
uint constant gasprice_before = kilo_offer_gasbase_before + kilo_offer_gasbase_bits;
// focus-mask: 1s at field location, 0s elsewhere
uint constant maker_mask_inv = (ONES << 256 - maker_bits) >> maker_before;
uint constant gasreq_mask_inv = (ONES << 256 - gasreq_bits) >> gasreq_before;
uint constant kilo_offer_gasbase_mask_inv = (ONES << 256 - kilo_offer_gasbase_bits) >> kilo_offer_gasbase_before;
uint constant gasprice_mask_inv = (ONES << 256 - gasprice_bits) >> gasprice_before;
// cleanup-mask: 0s at field location, 1s elsewhere
uint constant maker_mask = ~maker_mask_inv;
uint constant gasreq_mask = ~gasreq_mask_inv;
uint constant kilo_offer_gasbase_mask = ~kilo_offer_gasbase_mask_inv;
uint constant gasprice_mask = ~gasprice_mask_inv;
// cast-mask: 0s followed by |field| trailing 1s
uint constant maker_cast_mask = ~(ONES << maker_bits);
uint constant gasreq_cast_mask = ~(ONES << gasreq_bits);
uint constant kilo_offer_gasbase_cast_mask = ~(ONES << kilo_offer_gasbase_bits);
uint constant gasprice_cast_mask = ~(ONES << gasprice_bits);
// size-related error message
string constant maker_size_error = "mgv/config/maker/160bits";
string constant gasreq_size_error = "mgv/config/gasreq/24bits";
string constant kilo_offer_gasbase_size_error = "mgv/config/kilo_offer_gasbase/9bits";
string constant gasprice_size_error = "mgv/config/gasprice/26bits";
// from packed to in-memory struct
function to_struct(OfferDetail __packed) internal pure returns (OfferDetailUnpacked memory __s) { unchecked {
__s.maker = address(uint160(uint(OfferDetail.unwrap(__packed) << maker_before) >> (256 - maker_bits)));
__s.gasreq = uint(OfferDetail.unwrap(__packed) << gasreq_before) >> (256 - gasreq_bits);
__s.kilo_offer_gasbase = uint(OfferDetail.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
__s.gasprice = uint(OfferDetail.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
}}
// equality checking
function eq(OfferDetail __packed1, OfferDetail __packed2) internal pure returns (bool) { unchecked {
return OfferDetail.unwrap(__packed1) == OfferDetail.unwrap(__packed2);
}}
// from packed to a tuple
function unpack(OfferDetail __packed) internal pure returns (address __maker, uint __gasreq, uint __kilo_offer_gasbase, uint __gasprice) { unchecked {
__maker = address(uint160(uint(OfferDetail.unwrap(__packed) << maker_before) >> (256 - maker_bits)));
__gasreq = uint(OfferDetail.unwrap(__packed) << gasreq_before) >> (256 - gasreq_bits);
__kilo_offer_gasbase = uint(OfferDetail.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
__gasprice = uint(OfferDetail.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
}}
// getters
function maker(OfferDetail __packed) internal pure returns(address) { unchecked {
return address(uint160(uint(OfferDetail.unwrap(__packed) << maker_before) >> (256 - maker_bits)));
}}
// setters
function maker(OfferDetail __packed,address val) internal pure returns(OfferDetail) { unchecked {
return OfferDetail.wrap((OfferDetail.unwrap(__packed) & maker_mask) | (uint(uint160(val)) << (256 - maker_bits)) >> maker_before);
}}
function gasreq(OfferDetail __packed) internal pure returns(uint) { unchecked {
return uint(OfferDetail.unwrap(__packed) << gasreq_before) >> (256 - gasreq_bits);
}}
// setters
function gasreq(OfferDetail __packed,uint val) internal pure returns(OfferDetail) { unchecked {
return OfferDetail.wrap((OfferDetail.unwrap(__packed) & gasreq_mask) | (val << (256 - gasreq_bits)) >> gasreq_before);
}}
function kilo_offer_gasbase(OfferDetail __packed) internal pure returns(uint) { unchecked {
return uint(OfferDetail.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
}}
// setters
function kilo_offer_gasbase(OfferDetail __packed,uint val) internal pure returns(OfferDetail) { unchecked {
return OfferDetail.wrap((OfferDetail.unwrap(__packed) & kilo_offer_gasbase_mask) | (val << (256 - kilo_offer_gasbase_bits)) >> kilo_offer_gasbase_before);
}}
function gasprice(OfferDetail __packed) internal pure returns(uint) { unchecked {
return uint(OfferDetail.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
}}
// setters
function gasprice(OfferDetail __packed,uint val) internal pure returns(OfferDetail) { unchecked {
return OfferDetail.wrap((OfferDetail.unwrap(__packed) & gasprice_mask) | (val << (256 - gasprice_bits)) >> gasprice_before);
}}
// from in-memory struct to packed
function t_of_struct(OfferDetailUnpacked memory __s) internal pure returns (OfferDetail) { unchecked {
return pack(__s.maker, __s.gasreq, __s.kilo_offer_gasbase, __s.gasprice);
}}
// from arguments to packed
function pack(address __maker, uint __gasreq, uint __kilo_offer_gasbase, uint __gasprice) internal pure returns (OfferDetail) { unchecked {
uint __packed;
__packed |= (uint(uint160(__maker)) << (256 - maker_bits)) >> maker_before;
__packed |= (__gasreq << (256 - gasreq_bits)) >> gasreq_before;
__packed |= (__kilo_offer_gasbase << (256 - kilo_offer_gasbase_bits)) >> kilo_offer_gasbase_before;
__packed |= (__gasprice << (256 - gasprice_bits)) >> gasprice_before;
return OfferDetail.wrap(__packed);
}}
// input checking
function maker_check(address __maker) internal pure returns (bool) { unchecked {
return (uint(uint160(__maker)) & maker_cast_mask) == uint(uint160(__maker));
}}
function gasreq_check(uint __gasreq) internal pure returns (bool) { unchecked {
return (__gasreq & gasreq_cast_mask) == __gasreq;
}}
function kilo_offer_gasbase_check(uint __kilo_offer_gasbase) internal pure returns (bool) { unchecked {
return (__kilo_offer_gasbase & kilo_offer_gasbase_cast_mask) == __kilo_offer_gasbase;
}}
function gasprice_check(uint __gasprice) internal pure returns (bool) { unchecked {
return (__gasprice & gasprice_cast_mask) == __gasprice;
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/* ************************************************** *
GENERATED FILE. DO NOT EDIT.
* ************************************************** */
/* since you can't convert bool to uint in an expression without conditionals,
* we add a file-level function and rely on compiler optimization
*/
function uint_of_bool(bool b) pure returns (uint u) {
assembly ("memory-safe") { u := b }
}
import "@mgv/lib/core/Constants.sol";
struct GlobalUnpacked {
address monitor;
bool useOracle;
bool notify;
uint gasprice;
uint gasmax;
bool dead;
uint maxRecursionDepth;
uint maxGasreqForFailingOffers;
}
//some type safety for each struct
type Global is uint;
using GlobalLib for Global global;
////////////// ADDITIONAL DEFINITIONS, IF ANY ////////////////
////////////// END OF ADDITIONAL DEFINITIONS /////////////////
library GlobalLib {
// number of bits in each field
uint constant monitor_bits = 160;
uint constant useOracle_bits = 1;
uint constant notify_bits = 1;
uint constant gasprice_bits = 26;
uint constant gasmax_bits = 24;
uint constant dead_bits = 1;
uint constant maxRecursionDepth_bits = 8;
uint constant maxGasreqForFailingOffers_bits = 32;
// number of bits before each field
uint constant monitor_before = 0 + 0;
uint constant useOracle_before = monitor_before + monitor_bits;
uint constant notify_before = useOracle_before + useOracle_bits;
uint constant gasprice_before = notify_before + notify_bits;
uint constant gasmax_before = gasprice_before + gasprice_bits;
uint constant dead_before = gasmax_before + gasmax_bits;
uint constant maxRecursionDepth_before = dead_before + dead_bits;
uint constant maxGasreqForFailingOffers_before = maxRecursionDepth_before + maxRecursionDepth_bits;
// focus-mask: 1s at field location, 0s elsewhere
uint constant monitor_mask_inv = (ONES << 256 - monitor_bits) >> monitor_before;
uint constant useOracle_mask_inv = (ONES << 256 - useOracle_bits) >> useOracle_before;
uint constant notify_mask_inv = (ONES << 256 - notify_bits) >> notify_before;
uint constant gasprice_mask_inv = (ONES << 256 - gasprice_bits) >> gasprice_before;
uint constant gasmax_mask_inv = (ONES << 256 - gasmax_bits) >> gasmax_before;
uint constant dead_mask_inv = (ONES << 256 - dead_bits) >> dead_before;
uint constant maxRecursionDepth_mask_inv = (ONES << 256 - maxRecursionDepth_bits) >> maxRecursionDepth_before;
uint constant maxGasreqForFailingOffers_mask_inv = (ONES << 256 - maxGasreqForFailingOffers_bits) >> maxGasreqForFailingOffers_before;
// cleanup-mask: 0s at field location, 1s elsewhere
uint constant monitor_mask = ~monitor_mask_inv;
uint constant useOracle_mask = ~useOracle_mask_inv;
uint constant notify_mask = ~notify_mask_inv;
uint constant gasprice_mask = ~gasprice_mask_inv;
uint constant gasmax_mask = ~gasmax_mask_inv;
uint constant dead_mask = ~dead_mask_inv;
uint constant maxRecursionDepth_mask = ~maxRecursionDepth_mask_inv;
uint constant maxGasreqForFailingOffers_mask = ~maxGasreqForFailingOffers_mask_inv;
// cast-mask: 0s followed by |field| trailing 1s
uint constant monitor_cast_mask = ~(ONES << monitor_bits);
uint constant useOracle_cast_mask = ~(ONES << useOracle_bits);
uint constant notify_cast_mask = ~(ONES << notify_bits);
uint constant gasprice_cast_mask = ~(ONES << gasprice_bits);
uint constant gasmax_cast_mask = ~(ONES << gasmax_bits);
uint constant dead_cast_mask = ~(ONES << dead_bits);
uint constant maxRecursionDepth_cast_mask = ~(ONES << maxRecursionDepth_bits);
uint constant maxGasreqForFailingOffers_cast_mask = ~(ONES << maxGasreqForFailingOffers_bits);
// size-related error message
string constant monitor_size_error = "mgv/config/monitor/160bits";
string constant useOracle_size_error = "mgv/config/useOracle/1bits";
string constant notify_size_error = "mgv/config/notify/1bits";
string constant gasprice_size_error = "mgv/config/gasprice/26bits";
string constant gasmax_size_error = "mgv/config/gasmax/24bits";
string constant dead_size_error = "mgv/config/dead/1bits";
string constant maxRecursionDepth_size_error = "mgv/config/maxRecursionDepth/8bits";
string constant maxGasreqForFailingOffers_size_error = "mgv/config/maxGasreqForFailingOffers/32bits";
// from packed to in-memory struct
function to_struct(Global __packed) internal pure returns (GlobalUnpacked memory __s) { unchecked {
__s.monitor = address(uint160(uint(Global.unwrap(__packed) << monitor_before) >> (256 - monitor_bits)));
__s.useOracle = ((Global.unwrap(__packed) & useOracle_mask_inv) > 0);
__s.notify = ((Global.unwrap(__packed) & notify_mask_inv) > 0);
__s.gasprice = uint(Global.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
__s.gasmax = uint(Global.unwrap(__packed) << gasmax_before) >> (256 - gasmax_bits);
__s.dead = ((Global.unwrap(__packed) & dead_mask_inv) > 0);
__s.maxRecursionDepth = uint(Global.unwrap(__packed) << maxRecursionDepth_before) >> (256 - maxRecursionDepth_bits);
__s.maxGasreqForFailingOffers = uint(Global.unwrap(__packed) << maxGasreqForFailingOffers_before) >> (256 - maxGasreqForFailingOffers_bits);
}}
// equality checking
function eq(Global __packed1, Global __packed2) internal pure returns (bool) { unchecked {
return Global.unwrap(__packed1) == Global.unwrap(__packed2);
}}
// from packed to a tuple
function unpack(Global __packed) internal pure returns (address __monitor, bool __useOracle, bool __notify, uint __gasprice, uint __gasmax, bool __dead, uint __maxRecursionDepth, uint __maxGasreqForFailingOffers) { unchecked {
__monitor = address(uint160(uint(Global.unwrap(__packed) << monitor_before) >> (256 - monitor_bits)));
__useOracle = ((Global.unwrap(__packed) & useOracle_mask_inv) > 0);
__notify = ((Global.unwrap(__packed) & notify_mask_inv) > 0);
__gasprice = uint(Global.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
__gasmax = uint(Global.unwrap(__packed) << gasmax_before) >> (256 - gasmax_bits);
__dead = ((Global.unwrap(__packed) & dead_mask_inv) > 0);
__maxRecursionDepth = uint(Global.unwrap(__packed) << maxRecursionDepth_before) >> (256 - maxRecursionDepth_bits);
__maxGasreqForFailingOffers = uint(Global.unwrap(__packed) << maxGasreqForFailingOffers_before) >> (256 - maxGasreqForFailingOffers_bits);
}}
// getters
function monitor(Global __packed) internal pure returns(address) { unchecked {
return address(uint160(uint(Global.unwrap(__packed) << monitor_before) >> (256 - monitor_bits)));
}}
// setters
function monitor(Global __packed,address val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & monitor_mask) | (uint(uint160(val)) << (256 - monitor_bits)) >> monitor_before);
}}
function useOracle(Global __packed) internal pure returns(bool) { unchecked {
return ((Global.unwrap(__packed) & useOracle_mask_inv) > 0);
}}
// setters
function useOracle(Global __packed,bool val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & useOracle_mask) | (uint_of_bool(val) << (256 - useOracle_bits)) >> useOracle_before);
}}
function notify(Global __packed) internal pure returns(bool) { unchecked {
return ((Global.unwrap(__packed) & notify_mask_inv) > 0);
}}
// setters
function notify(Global __packed,bool val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & notify_mask) | (uint_of_bool(val) << (256 - notify_bits)) >> notify_before);
}}
function gasprice(Global __packed) internal pure returns(uint) { unchecked {
return uint(Global.unwrap(__packed) << gasprice_before) >> (256 - gasprice_bits);
}}
// setters
function gasprice(Global __packed,uint val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & gasprice_mask) | (val << (256 - gasprice_bits)) >> gasprice_before);
}}
function gasmax(Global __packed) internal pure returns(uint) { unchecked {
return uint(Global.unwrap(__packed) << gasmax_before) >> (256 - gasmax_bits);
}}
// setters
function gasmax(Global __packed,uint val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & gasmax_mask) | (val << (256 - gasmax_bits)) >> gasmax_before);
}}
function dead(Global __packed) internal pure returns(bool) { unchecked {
return ((Global.unwrap(__packed) & dead_mask_inv) > 0);
}}
// setters
function dead(Global __packed,bool val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & dead_mask) | (uint_of_bool(val) << (256 - dead_bits)) >> dead_before);
}}
function maxRecursionDepth(Global __packed) internal pure returns(uint) { unchecked {
return uint(Global.unwrap(__packed) << maxRecursionDepth_before) >> (256 - maxRecursionDepth_bits);
}}
// setters
function maxRecursionDepth(Global __packed,uint val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & maxRecursionDepth_mask) | (val << (256 - maxRecursionDepth_bits)) >> maxRecursionDepth_before);
}}
function maxGasreqForFailingOffers(Global __packed) internal pure returns(uint) { unchecked {
return uint(Global.unwrap(__packed) << maxGasreqForFailingOffers_before) >> (256 - maxGasreqForFailingOffers_bits);
}}
// setters
function maxGasreqForFailingOffers(Global __packed,uint val) internal pure returns(Global) { unchecked {
return Global.wrap((Global.unwrap(__packed) & maxGasreqForFailingOffers_mask) | (val << (256 - maxGasreqForFailingOffers_bits)) >> maxGasreqForFailingOffers_before);
}}
// from in-memory struct to packed
function t_of_struct(GlobalUnpacked memory __s) internal pure returns (Global) { unchecked {
return pack(__s.monitor, __s.useOracle, __s.notify, __s.gasprice, __s.gasmax, __s.dead, __s.maxRecursionDepth, __s.maxGasreqForFailingOffers);
}}
// from arguments to packed
function pack(address __monitor, bool __useOracle, bool __notify, uint __gasprice, uint __gasmax, bool __dead, uint __maxRecursionDepth, uint __maxGasreqForFailingOffers) internal pure returns (Global) { unchecked {
uint __packed;
__packed |= (uint(uint160(__monitor)) << (256 - monitor_bits)) >> monitor_before;
__packed |= (uint_of_bool(__useOracle) << (256 - useOracle_bits)) >> useOracle_before;
__packed |= (uint_of_bool(__notify) << (256 - notify_bits)) >> notify_before;
__packed |= (__gasprice << (256 - gasprice_bits)) >> gasprice_before;
__packed |= (__gasmax << (256 - gasmax_bits)) >> gasmax_before;
__packed |= (uint_of_bool(__dead) << (256 - dead_bits)) >> dead_before;
__packed |= (__maxRecursionDepth << (256 - maxRecursionDepth_bits)) >> maxRecursionDepth_before;
__packed |= (__maxGasreqForFailingOffers << (256 - maxGasreqForFailingOffers_bits)) >> maxGasreqForFailingOffers_before;
return Global.wrap(__packed);
}}
// input checking
function monitor_check(address __monitor) internal pure returns (bool) { unchecked {
return (uint(uint160(__monitor)) & monitor_cast_mask) == uint(uint160(__monitor));
}}
function useOracle_check(bool __useOracle) internal pure returns (bool) { unchecked {
return (uint_of_bool(__useOracle) & useOracle_cast_mask) == uint_of_bool(__useOracle);
}}
function notify_check(bool __notify) internal pure returns (bool) { unchecked {
return (uint_of_bool(__notify) & notify_cast_mask) == uint_of_bool(__notify);
}}
function gasprice_check(uint __gasprice) internal pure returns (bool) { unchecked {
return (__gasprice & gasprice_cast_mask) == __gasprice;
}}
function gasmax_check(uint __gasmax) internal pure returns (bool) { unchecked {
return (__gasmax & gasmax_cast_mask) == __gasmax;
}}
function dead_check(bool __dead) internal pure returns (bool) { unchecked {
return (uint_of_bool(__dead) & dead_cast_mask) == uint_of_bool(__dead);
}}
function maxRecursionDepth_check(uint __maxRecursionDepth) internal pure returns (bool) { unchecked {
return (__maxRecursionDepth & maxRecursionDepth_cast_mask) == __maxRecursionDepth;
}}
function maxGasreqForFailingOffers_check(uint __maxGasreqForFailingOffers) internal pure returns (bool) { unchecked {
return (__maxGasreqForFailingOffers & maxGasreqForFailingOffers_cast_mask) == __maxGasreqForFailingOffers;
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/* ************************************************** *
GENERATED FILE. DO NOT EDIT.
* ************************************************** */
/* since you can't convert bool to uint in an expression without conditionals,
* we add a file-level function and rely on compiler optimization
*/
function uint_of_bool(bool b) pure returns (uint u) {
assembly ("memory-safe") { u := b }
}
import "@mgv/lib/core/Constants.sol";
struct LocalUnpacked {
bool active;
uint fee;
Density density;
uint binPosInLeaf;
Field level3;
Field level2;
Field level1;
Field root;
uint kilo_offer_gasbase;
bool lock;
uint last;
}
//some type safety for each struct
type Local is uint;
using LocalLib for Local global;
////////////// ADDITIONAL DEFINITIONS, IF ANY ////////////////
import {Density, DensityLib} from "@mgv/lib/core/DensityLib.sol";
import {Bin,TickTreeLib,Field} from "@mgv/lib/core/TickTreeLib.sol";
/* Globally enable global.method(...) */
import {LocalExtra,LocalUnpackedExtra} from "@mgv/lib/core/LocalExtra.sol";
using LocalExtra for Local global;
using LocalUnpackedExtra for LocalUnpacked global;
////////////// END OF ADDITIONAL DEFINITIONS /////////////////
library LocalLib {
// number of bits in each field
uint constant active_bits = 1;
uint constant fee_bits = 8;
uint constant density_bits = 9;
uint constant binPosInLeaf_bits = 2;
uint constant level3_bits = 64;
uint constant level2_bits = 64;
uint constant level1_bits = 64;
uint constant root_bits = 2;
uint constant kilo_offer_gasbase_bits = 9;
uint constant lock_bits = 1;
uint constant last_bits = 32;
// number of bits before each field
uint constant active_before = 0 + 0;
uint constant fee_before = active_before + active_bits;
uint constant density_before = fee_before + fee_bits;
uint constant binPosInLeaf_before = density_before + density_bits;
uint constant level3_before = binPosInLeaf_before + binPosInLeaf_bits;
uint constant level2_before = level3_before + level3_bits;
uint constant level1_before = level2_before + level2_bits;
uint constant root_before = level1_before + level1_bits;
uint constant kilo_offer_gasbase_before = root_before + root_bits;
uint constant lock_before = kilo_offer_gasbase_before + kilo_offer_gasbase_bits;
uint constant last_before = lock_before + lock_bits;
// focus-mask: 1s at field location, 0s elsewhere
uint constant active_mask_inv = (ONES << 256 - active_bits) >> active_before;
uint constant fee_mask_inv = (ONES << 256 - fee_bits) >> fee_before;
uint constant density_mask_inv = (ONES << 256 - density_bits) >> density_before;
uint constant binPosInLeaf_mask_inv = (ONES << 256 - binPosInLeaf_bits) >> binPosInLeaf_before;
uint constant level3_mask_inv = (ONES << 256 - level3_bits) >> level3_before;
uint constant level2_mask_inv = (ONES << 256 - level2_bits) >> level2_before;
uint constant level1_mask_inv = (ONES << 256 - level1_bits) >> level1_before;
uint constant root_mask_inv = (ONES << 256 - root_bits) >> root_before;
uint constant kilo_offer_gasbase_mask_inv = (ONES << 256 - kilo_offer_gasbase_bits) >> kilo_offer_gasbase_before;
uint constant lock_mask_inv = (ONES << 256 - lock_bits) >> lock_before;
uint constant last_mask_inv = (ONES << 256 - last_bits) >> last_before;
// cleanup-mask: 0s at field location, 1s elsewhere
uint constant active_mask = ~active_mask_inv;
uint constant fee_mask = ~fee_mask_inv;
uint constant density_mask = ~density_mask_inv;
uint constant binPosInLeaf_mask = ~binPosInLeaf_mask_inv;
uint constant level3_mask = ~level3_mask_inv;
uint constant level2_mask = ~level2_mask_inv;
uint constant level1_mask = ~level1_mask_inv;
uint constant root_mask = ~root_mask_inv;
uint constant kilo_offer_gasbase_mask = ~kilo_offer_gasbase_mask_inv;
uint constant lock_mask = ~lock_mask_inv;
uint constant last_mask = ~last_mask_inv;
// cast-mask: 0s followed by |field| trailing 1s
uint constant active_cast_mask = ~(ONES << active_bits);
uint constant fee_cast_mask = ~(ONES << fee_bits);
uint constant density_cast_mask = ~(ONES << density_bits);
uint constant binPosInLeaf_cast_mask = ~(ONES << binPosInLeaf_bits);
uint constant level3_cast_mask = ~(ONES << level3_bits);
uint constant level2_cast_mask = ~(ONES << level2_bits);
uint constant level1_cast_mask = ~(ONES << level1_bits);
uint constant root_cast_mask = ~(ONES << root_bits);
uint constant kilo_offer_gasbase_cast_mask = ~(ONES << kilo_offer_gasbase_bits);
uint constant lock_cast_mask = ~(ONES << lock_bits);
uint constant last_cast_mask = ~(ONES << last_bits);
// size-related error message
string constant active_size_error = "mgv/config/active/1bits";
string constant fee_size_error = "mgv/config/fee/8bits";
string constant density_size_error = "mgv/config/density/9bits";
string constant binPosInLeaf_size_error = "mgv/config/binPosInLeaf/2bits";
string constant level3_size_error = "mgv/config/level3/64bits";
string constant level2_size_error = "mgv/config/level2/64bits";
string constant level1_size_error = "mgv/config/level1/64bits";
string constant root_size_error = "mgv/config/root/2bits";
string constant kilo_offer_gasbase_size_error = "mgv/config/kilo_offer_gasbase/9bits";
string constant lock_size_error = "mgv/config/lock/1bits";
string constant last_size_error = "mgv/config/last/32bits";
// from packed to in-memory struct
function to_struct(Local __packed) internal pure returns (LocalUnpacked memory __s) { unchecked {
__s.active = ((Local.unwrap(__packed) & active_mask_inv) > 0);
__s.fee = uint(Local.unwrap(__packed) << fee_before) >> (256 - fee_bits);
__s.density = Density.wrap(uint(Local.unwrap(__packed) << density_before) >> (256 - density_bits));
__s.binPosInLeaf = uint(Local.unwrap(__packed) << binPosInLeaf_before) >> (256 - binPosInLeaf_bits);
__s.level3 = Field.wrap(uint(Local.unwrap(__packed) << level3_before) >> (256 - level3_bits));
__s.level2 = Field.wrap(uint(Local.unwrap(__packed) << level2_before) >> (256 - level2_bits));
__s.level1 = Field.wrap(uint(Local.unwrap(__packed) << level1_before) >> (256 - level1_bits));
__s.root = Field.wrap(uint(Local.unwrap(__packed) << root_before) >> (256 - root_bits));
__s.kilo_offer_gasbase = uint(Local.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
__s.lock = ((Local.unwrap(__packed) & lock_mask_inv) > 0);
__s.last = uint(Local.unwrap(__packed) << last_before) >> (256 - last_bits);
}}
// equality checking
function eq(Local __packed1, Local __packed2) internal pure returns (bool) { unchecked {
return Local.unwrap(__packed1) == Local.unwrap(__packed2);
}}
// from packed to a tuple
function unpack(Local __packed) internal pure returns (bool __active, uint __fee, Density __density, uint __binPosInLeaf, Field __level3, Field __level2, Field __level1, Field __root, uint __kilo_offer_gasbase, bool __lock, uint __last) { unchecked {
__active = ((Local.unwrap(__packed) & active_mask_inv) > 0);
__fee = uint(Local.unwrap(__packed) << fee_before) >> (256 - fee_bits);
__density = Density.wrap(uint(Local.unwrap(__packed) << density_before) >> (256 - density_bits));
__binPosInLeaf = uint(Local.unwrap(__packed) << binPosInLeaf_before) >> (256 - binPosInLeaf_bits);
__level3 = Field.wrap(uint(Local.unwrap(__packed) << level3_before) >> (256 - level3_bits));
__level2 = Field.wrap(uint(Local.unwrap(__packed) << level2_before) >> (256 - level2_bits));
__level1 = Field.wrap(uint(Local.unwrap(__packed) << level1_before) >> (256 - level1_bits));
__root = Field.wrap(uint(Local.unwrap(__packed) << root_before) >> (256 - root_bits));
__kilo_offer_gasbase = uint(Local.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
__lock = ((Local.unwrap(__packed) & lock_mask_inv) > 0);
__last = uint(Local.unwrap(__packed) << last_before) >> (256 - last_bits);
}}
// getters
function active(Local __packed) internal pure returns(bool) { unchecked {
return ((Local.unwrap(__packed) & active_mask_inv) > 0);
}}
// setters
function active(Local __packed,bool val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & active_mask) | (uint_of_bool(val) << (256 - active_bits)) >> active_before);
}}
function fee(Local __packed) internal pure returns(uint) { unchecked {
return uint(Local.unwrap(__packed) << fee_before) >> (256 - fee_bits);
}}
// setters
function fee(Local __packed,uint val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & fee_mask) | (val << (256 - fee_bits)) >> fee_before);
}}
function density(Local __packed) internal pure returns(Density) { unchecked {
return Density.wrap(uint(Local.unwrap(__packed) << density_before) >> (256 - density_bits));
}}
// setters
function density(Local __packed,Density val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & density_mask) | (Density.unwrap(val) << (256 - density_bits)) >> density_before);
}}
function binPosInLeaf(Local __packed) internal pure returns(uint) { unchecked {
return uint(Local.unwrap(__packed) << binPosInLeaf_before) >> (256 - binPosInLeaf_bits);
}}
// setters
function binPosInLeaf(Local __packed,uint val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & binPosInLeaf_mask) | (val << (256 - binPosInLeaf_bits)) >> binPosInLeaf_before);
}}
function level3(Local __packed) internal pure returns(Field) { unchecked {
return Field.wrap(uint(Local.unwrap(__packed) << level3_before) >> (256 - level3_bits));
}}
// setters
function level3(Local __packed,Field val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & level3_mask) | (Field.unwrap(val) << (256 - level3_bits)) >> level3_before);
}}
function level2(Local __packed) internal pure returns(Field) { unchecked {
return Field.wrap(uint(Local.unwrap(__packed) << level2_before) >> (256 - level2_bits));
}}
// setters
function level2(Local __packed,Field val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & level2_mask) | (Field.unwrap(val) << (256 - level2_bits)) >> level2_before);
}}
function level1(Local __packed) internal pure returns(Field) { unchecked {
return Field.wrap(uint(Local.unwrap(__packed) << level1_before) >> (256 - level1_bits));
}}
// setters
function level1(Local __packed,Field val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & level1_mask) | (Field.unwrap(val) << (256 - level1_bits)) >> level1_before);
}}
function root(Local __packed) internal pure returns(Field) { unchecked {
return Field.wrap(uint(Local.unwrap(__packed) << root_before) >> (256 - root_bits));
}}
// setters
function root(Local __packed,Field val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & root_mask) | (Field.unwrap(val) << (256 - root_bits)) >> root_before);
}}
function kilo_offer_gasbase(Local __packed) internal pure returns(uint) { unchecked {
return uint(Local.unwrap(__packed) << kilo_offer_gasbase_before) >> (256 - kilo_offer_gasbase_bits);
}}
// setters
function kilo_offer_gasbase(Local __packed,uint val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & kilo_offer_gasbase_mask) | (val << (256 - kilo_offer_gasbase_bits)) >> kilo_offer_gasbase_before);
}}
function lock(Local __packed) internal pure returns(bool) { unchecked {
return ((Local.unwrap(__packed) & lock_mask_inv) > 0);
}}
// setters
function lock(Local __packed,bool val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & lock_mask) | (uint_of_bool(val) << (256 - lock_bits)) >> lock_before);
}}
function last(Local __packed) internal pure returns(uint) { unchecked {
return uint(Local.unwrap(__packed) << last_before) >> (256 - last_bits);
}}
// setters
function last(Local __packed,uint val) internal pure returns(Local) { unchecked {
return Local.wrap((Local.unwrap(__packed) & last_mask) | (val << (256 - last_bits)) >> last_before);
}}
// from in-memory struct to packed
function t_of_struct(LocalUnpacked memory __s) internal pure returns (Local) { unchecked {
return pack(__s.active, __s.fee, __s.density, __s.binPosInLeaf, __s.level3, __s.level2, __s.level1, __s.root, __s.kilo_offer_gasbase, __s.lock, __s.last);
}}
// from arguments to packed
function pack(bool __active, uint __fee, Density __density, uint __binPosInLeaf, Field __level3, Field __level2, Field __level1, Field __root, uint __kilo_offer_gasbase, bool __lock, uint __last) internal pure returns (Local) { unchecked {
uint __packed;
__packed |= (uint_of_bool(__active) << (256 - active_bits)) >> active_before;
__packed |= (__fee << (256 - fee_bits)) >> fee_before;
__packed |= (Density.unwrap(__density) << (256 - density_bits)) >> density_before;
__packed |= (__binPosInLeaf << (256 - binPosInLeaf_bits)) >> binPosInLeaf_before;
__packed |= (Field.unwrap(__level3) << (256 - level3_bits)) >> level3_before;
__packed |= (Field.unwrap(__level2) << (256 - level2_bits)) >> level2_before;
__packed |= (Field.unwrap(__level1) << (256 - level1_bits)) >> level1_before;
__packed |= (Field.unwrap(__root) << (256 - root_bits)) >> root_before;
__packed |= (__kilo_offer_gasbase << (256 - kilo_offer_gasbase_bits)) >> kilo_offer_gasbase_before;
__packed |= (uint_of_bool(__lock) << (256 - lock_bits)) >> lock_before;
__packed |= (__last << (256 - last_bits)) >> last_before;
return Local.wrap(__packed);
}}
// input checking
function active_check(bool __active) internal pure returns (bool) { unchecked {
return (uint_of_bool(__active) & active_cast_mask) == uint_of_bool(__active);
}}
function fee_check(uint __fee) internal pure returns (bool) { unchecked {
return (__fee & fee_cast_mask) == __fee;
}}
function density_check(Density __density) internal pure returns (bool) { unchecked {
return (Density.unwrap(__density) & density_cast_mask) == Density.unwrap(__density);
}}
function binPosInLeaf_check(uint __binPosInLeaf) internal pure returns (bool) { unchecked {
return (__binPosInLeaf & binPosInLeaf_cast_mask) == __binPosInLeaf;
}}
function level3_check(Field __level3) internal pure returns (bool) { unchecked {
return (Field.unwrap(__level3) & level3_cast_mask) == Field.unwrap(__level3);
}}
function level2_check(Field __level2) internal pure returns (bool) { unchecked {
return (Field.unwrap(__level2) & level2_cast_mask) == Field.unwrap(__level2);
}}
function level1_check(Field __level1) internal pure returns (bool) { unchecked {
return (Field.unwrap(__level1) & level1_cast_mask) == Field.unwrap(__level1);
}}
function root_check(Field __root) internal pure returns (bool) { unchecked {
return (Field.unwrap(__root) & root_cast_mask) == Field.unwrap(__root);
}}
function kilo_offer_gasbase_check(uint __kilo_offer_gasbase) internal pure returns (bool) { unchecked {
return (__kilo_offer_gasbase & kilo_offer_gasbase_cast_mask) == __kilo_offer_gasbase;
}}
function lock_check(bool __lock) internal pure returns (bool) { unchecked {
return (uint_of_bool(__lock) & lock_cast_mask) == uint_of_bool(__lock);
}}
function last_check(uint __last) internal pure returns (bool) { unchecked {
return (__last & last_cast_mask) == __last;
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
library BitLib {
// - if x is a nonzero uint64:
// return number of zeroes in x that do not have a 1 to their right
// - otherwise:
// return 64
function ctz64(uint x) internal pure returns (uint256 c) {
unchecked {
assembly ("memory-safe") {
// clean
x:= and(x,0xffffffffffffffff)
// 7th bit
c:= shl(6,iszero(x))
// isolate lsb
x := and(x, add(not(x), 1))
// 6th bit
c := or(c,shl(5, lt(0xffffffff, x)))
// debruijn lookup
c := or(c, byte(shr(251, mul(shr(c, x), shl(224, 0x077cb531))),
0x00011c021d0e18031e16140f191104081f1b0d17151310071a0c12060b050a09))
}
}
}
// Function fls is MIT License. Copyright (c) 2022 Solady.
/// @dev find last set.
/// Returns the index of the most significant bit of `x`,
/// counting from the least significant bit position.
/// If `x` is zero, returns 256.
/// Equivalent to `log2(x)`, but without reverting for the zero case.
function fls(uint256 x) internal pure returns (uint256 r) {
assembly ("memory-safe") {
r := shl(8, iszero(x))
r := or(r, shl(7, lt(0xffffffffffffffffffffffffffffffff, x)))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
// For the remaining 32 bits, use a De Bruijn lookup.
x := shr(r, x)
x := or(x, shr(1, x))
x := or(x, shr(2, x))
x := or(x, shr(4, x))
x := or(x, shr(8, x))
x := or(x, shr(16, x))
// forgefmt: disable-next-item
r := or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))),
0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
/// @dev The original console.sol uses `int` and `uint` for computing function selectors, but it should
/// use `int256` and `uint256`. This modified version fixes that. This version is recommended
/// over `console.sol` if you don't need compatibility with Hardhat as the logs will show up in
/// forge stack traces. If you do need compatibility with Hardhat, you must use `console.sol`.
/// Reference: https://github.com/NomicFoundation/hardhat/issues/2178
library console2 {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _castLogPayloadViewToPure(
function(bytes memory) internal view fnIn
) internal pure returns (function(bytes memory) internal pure fnOut) {
assembly {
fnOut := fnIn
}
}
function _sendLogPayload(bytes memory payload) internal pure {
_castLogPayloadViewToPure(_sendLogPayloadView)(payload);
}
function _sendLogPayloadView(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
/// @solidity memory-safe-assembly
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal pure {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function logUint(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function logString(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function log(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function log(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint256 p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
}
function log(uint256 p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
}
function log(uint256 p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
}
function log(uint256 p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
}
function log(string memory p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
}
function log(string memory p0, int256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,int256)", p0, p1));
}
function log(string memory p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
}
function log(bool p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
}
function log(address p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint256 p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
}
function log(uint256 p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
}
function log(uint256 p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
}
function log(uint256 p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
}
function log(uint256 p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
}
function log(uint256 p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
}
function log(uint256 p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
}
function log(uint256 p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
}
function log(uint256 p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
}
function log(bool p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
}
function log(bool p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
}
function log(bool p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
}
function log(address p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
}
function log(address p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
}
function log(address p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}// SPDX-License-Identifier: BSD-2-Clause
pragma solidity ^0.8.10;
import {IERC20} from "@mgv/lib/IERC20.sol";
/// @title Library to obtain Routing orders of various kind
library RoutingOrderLib {
///@notice pointer to first storage slot used for randomized access
bytes32 private constant OFFSET = keccak256("MangroveStrats.RoutingOrderLib.Layout");
///@notice Argument to pull/push
///@param token the asset to be routed
///@param olKeyHash the id of the market that triggered the calling offer logic. Is bytes32(0) when routing is done outside offer logic.
///@param offerId the id of the offer that triggered the calling offer logic. Is uint(0) when routing is done outsider offer logic.
///@param fundOwner the owner of the routed funds. If calling router is a proxy, it address is determined by `fundOwner`.
struct RoutingOrder {
IERC20 token;
bytes32 olKeyHash;
uint offerId;
address fundOwner;
}
///@notice helper to create a RoutingOrder struct without zero'ed fields for market coordinates.
///@param token the asset to be routed
///@param fundOwner the owner of the routed funds
///@return ro the routing order struct
function createOrder(IERC20 token, address fundOwner) internal pure returns (RoutingOrder memory ro) {
ro.token = token;
ro.fundOwner = fundOwner;
}
///@notice the bound maker contracts which are allowed to call this router.
struct Layout {
mapping(address => bool) boundMakerContracts;
}
///@notice allowed pullers/pushers for this router
///@return bound contracts to this router, in the form of a storage mapping
function boundMakerContracts() internal view returns (mapping(address => bool) storage) {
bytes32 offset = OFFSET;
Layout storage st;
assembly ("memory-safe") {
st.slot := offset
}
return st.boundMakerContracts;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {OLKey} from "@mgv/src/core/MgvLib.sol";
import {IERC20} from "@mgv/lib/IERC20.sol";
///@title a bid or an ask.
enum OfferType {
Bid,
Ask
}
///@title Interface contract for strats needing offer type to offer list mapping.
abstract contract IHasOfferListOfOfferType {
///@notice turns an offer type into an (outbound_tkn, inbound_tkn, tickSpacing) pair identifying an offer list.
///@param ba whether one wishes to access the offer lists where asks or bids are posted.
///@return olKey the olKey defining the token pair
function offerListOfOfferType(OfferType ba) internal view virtual returns (OLKey memory olKey);
///@notice returns the offer type of the offer list whose outbound token is given in the argument.
///@param outbound_tkn the outbound token
///@return ba the offer type
function offerTypeOfOutbound(IERC20 outbound_tkn) internal view virtual returns (OfferType ba);
///@notice returns the outbound token for the offer type
///@param ba the offer type
///@return token the outbound token
function outboundOfOfferType(OfferType ba) internal view virtual returns (IERC20 token);
}
///@title Adds basic base/quote trading pair for bids and asks and couples it to Mangrove's gives, wants, outbound, inbound terminology.
///@dev Implements the IHasOfferListOfOfferType interface contract.
abstract contract TradesBaseQuotePair is IHasOfferListOfOfferType {
///@notice base of the market Kandel is making
IERC20 public immutable BASE;
///@notice quote of the market Kandel is making
IERC20 public immutable QUOTE;
///@notice tickSpacing of the market Kandel is making
uint public immutable TICK_SPACING;
///@notice The traded offer list
///@param olKeyHash of the market Kandel is making
///@notice we only emit this, so that the events for a Kandel is self contained. If one uses the KandelSeeder to deploy, then this information is already available from NewKandel or NewAaveKandel events.
event OfferListKey(bytes32 olKeyHash);
///@notice Constructor
///@param olKeyBaseQuote The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
constructor(OLKey memory olKeyBaseQuote) {
BASE = IERC20(olKeyBaseQuote.outbound_tkn);
QUOTE = IERC20(olKeyBaseQuote.inbound_tkn);
TICK_SPACING = olKeyBaseQuote.tickSpacing;
emit OfferListKey(olKeyBaseQuote.hash());
}
///@inheritdoc IHasOfferListOfOfferType
function offerListOfOfferType(OfferType ba) internal view override returns (OLKey memory olKey) {
return ba == OfferType.Bid
? OLKey(address(QUOTE), address(BASE), TICK_SPACING)
: OLKey(address(BASE), address(QUOTE), TICK_SPACING);
}
///@inheritdoc IHasOfferListOfOfferType
function offerTypeOfOutbound(IERC20 outbound_tkn) internal view override returns (OfferType) {
return outbound_tkn == BASE ? OfferType.Ask : OfferType.Bid;
}
///@inheritdoc IHasOfferListOfOfferType
function outboundOfOfferType(OfferType ba) internal view override returns (IERC20 token) {
token = ba == OfferType.Ask ? BASE : QUOTE;
}
///@notice returns the dual offer type
///@param ba whether the offer is an ask or a bid
///@return baDual is the dual offer type (ask for bid and conversely)
function dual(OfferType ba) internal pure returns (OfferType baDual) {
return OfferType((uint(ba) + 1) % 2);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {OLKey} from "@mgv/src/core/MgvLib.sol";
import {Direct} from "@mgv-strats/src/strategies/offer_maker/abstract/Direct.sol";
import {OfferType} from "./TradesBaseQuotePair.sol";
import {HasIndexedBidsAndAsks} from "./HasIndexedBidsAndAsks.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {Local, Offer} from "@mgv/src/core/MgvLib.sol";
import {Tick} from "@mgv/lib/core/TickLib.sol";
///@title `Direct` strat with an indexed collection of bids and asks which can be populated according to a desired base and quote distribution for gives and wants.
abstract contract DirectWithBidsAndAsksDistribution is Direct, HasIndexedBidsAndAsks {
///@notice logs the start of a call to populate
///@notice By emitting this, an indexer will be able to know that the following events are in the context of populate.
event PopulateStart();
///@notice logs the end of a call to populate
///@notice By emitting this, an indexer will know that the previous PopulateStart event is over.
event PopulateEnd();
///@notice logs the start of a call to retractOffers
///@notice By emitting this, an indexer will be able to know that the following events are in the context of retract.
event RetractStart();
///@notice logs the end of a call to retractOffers
///@notice By emitting this, an indexer will know that the previous RetractStart event is over.
event RetractEnd();
///@notice Constructor
///@param mgv The Mangrove deployment.
///@param routerParams parameters if this stract is using a router
constructor(IMangrove mgv, RouterParams memory routerParams) Direct(mgv, routerParams) {}
///@param index the index of the offer
///@param tick the tick for the index (the tick price of base per quote for bids and quote per base for asks)
///@param gives the gives for the index (the `quote` for bids and the `base` for asks)
struct DistributionOffer {
uint index;
Tick tick;
uint gives;
}
///@param asks the asks to populate
///@param bids the bids to populate
struct Distribution {
DistributionOffer[] asks;
DistributionOffer[] bids;
}
///@notice Publishes bids/asks for the distribution in the `indices`. Care must be taken to publish offers in meaningful chunks. For instance, for Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead).
///@param distribution the distribution of bids and asks to populate
///@param gasreq the amount of gas units that are required to execute the trade.
///@param gasprice the gasprice used to compute offer's provision.
///@dev Gives of 0 means create/update and then retract offer (but update price, gasreq, gasprice of the offer)
function populateChunkInternal(Distribution memory distribution, uint gasreq, uint gasprice) internal {
emit PopulateStart();
// Initialize static values of args
OfferArgs memory args;
// args.fund = 0; offers are already funded
// args.noRevert = false; we want revert in case of failure
args.gasreq = gasreq;
args.gasprice = gasprice;
// Populate bids
args.olKey = offerListOfOfferType(OfferType.Bid);
populateOfferListChunkInternal(distribution.bids, OfferType.Bid, args);
// Populate asks
args.olKey = args.olKey.flipped();
populateOfferListChunkInternal(distribution.asks, OfferType.Ask, args);
emit PopulateEnd();
}
///@notice populates one of the offer lists with the given offers
///@param offers the offers to populate
///@param ba whether to populate bids or asks
///@param args a reused offer creation args structure with defaults passed from caller.
function populateOfferListChunkInternal(DistributionOffer[] memory offers, OfferType ba, OfferArgs memory args)
internal
{
Local local = MGV.local(args.olKey);
// Minimum gives for offers (to post and retract)
uint minGives = local.density().multiplyUp(args.gasreq + local.offer_gasbase());
for (uint i; i < offers.length; ++i) {
DistributionOffer memory offer = offers[i];
uint index = offer.index;
args.tick = offer.tick;
args.gives = offer.gives;
populateIndex(ba, offerIdOfIndex(ba, index), index, args, minGives);
}
}
///@notice publishes (by either creating or updating) a bid/ask at a given price index.
///@param ba whether the offer is a bid or an ask.
///@param offerId the Mangrove offer id (0 for a new offer).
///@param index the price index.
///@param args the argument of the offer. `args.gives=0` means offer will be created/updated and then retracted.
///@param minGives the minimum gives to satisfy density requirement - used for creating/updating offers when args.gives=0.
function populateIndex(OfferType ba, uint offerId, uint index, OfferArgs memory args, uint minGives) internal {
// if offer does not exist on mangrove yet
if (offerId == 0) {
// and offer should be live
if (args.gives > 0) {
// create it - we revert in case of failure (see populateChunk), so offerId is always > 0
(offerId,) = _newOffer(args);
setIndexMapping(ba, index, offerId);
} else {
// else offerId && gives are 0 and the offer is posted and retracted to reserve the offerId and set the price
// set args.gives to minGives to be above density requirement, we do it here since we use the args.gives=0 to signal a dead offer.
args.gives = minGives;
// create it - we revert in case of failure (see populateChunk), so offerId is always > 0
(offerId,) = _newOffer(args);
// reset args.gives since args is reused
args.gives = 0;
// retract, keeping provision, thus the offer is reserved and ready for use in posthook.
_retractOffer(args.olKey, offerId, false);
setIndexMapping(ba, index, offerId);
}
}
// else offer exists
else {
// but the offer should be dead since gives is 0
if (args.gives == 0) {
// * `gives == 0` may happen from populate in case of re-population where some offers are then retracted by setting gives to 0.
// set args.gives to minGives to be above density requirement, we do it here since we use the args.gives=0 to signal a dead offer.
args.gives = minGives;
// Update offer to set correct price, gasreq, gasprice, then retract
_updateOffer(args, offerId);
// reset args.gives since args is reused
args.gives = 0;
// retract, keeping provision, thus the offer is reserved and ready for use in posthook.
_retractOffer(args.olKey, offerId, false);
} else {
// so the offer exists and it should, we simply update it with potentially new volume and price
_updateOffer(args, offerId);
}
}
}
///@notice retracts and deprovisions offers of the distribution interval `[from, to[`.
///@param from the start index.
///@param to the end index.
///@dev use in conjunction of `withdrawFromMangrove` if the user wishes to redeem the available WEIs.
function retractOffers(uint from, uint to) public onlyAdmin {
emit RetractStart();
retractOffersOnOfferList(from, to, OfferType.Ask);
retractOffersOnOfferList(from, to, OfferType.Bid);
emit RetractEnd();
}
///@notice retracts and deprovisions offers of the distribution interval `[from, to[` for the given offer type.
///@param from the start index.
///@param to the end index.
///@param ba the offer type.
function retractOffersOnOfferList(uint from, uint to, OfferType ba) internal {
OLKey memory olKey = offerListOfOfferType(ba);
for (uint index = from; index < to; ++index) {
// These offerIds could be recycled in a new populate
uint offerId = offerIdOfIndex(ba, index);
if (offerId != 0) {
_retractOffer(olKey, offerId, true);
}
}
}
///@notice gets the Mangrove offer at the given index for the offer type.
///@param ba the offer type.
///@param index the index.
///@return offer the Mangrove offer.
function getOffer(OfferType ba, uint index) public view returns (Offer offer) {
uint offerId = offerIdOfIndex(ba, index);
OLKey memory olKey = offerListOfOfferType(ba);
offer = MGV.offers(olKey, offerId);
}
/// @notice gets the total gives of all offers of the offer type.
/// @param ba offer type.
/// @return volume the total gives of all offers of the offer type.
/// @dev function is very gas costly, for external calls only.
function offeredVolume(OfferType ba) public view returns (uint volume) {
for (uint index = 0; index < length; ++index) {
Offer offer = getOffer(ba, index);
volume += offer.gives();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@mgv/lib/core/TickTreeLib.sol";
import "@mgv/lib/core/TickLib.sol";
import {Offer,OfferUnpacked,OfferLib} from "@mgv/src/preprocessed/Offer.post.sol";
/* cleanup-mask: 0s at location of fields to hide from maker, 1s elsewhere */
uint constant HIDE_FIELDS_FROM_MAKER_MASK = ~(OfferLib.prev_mask_inv | OfferLib.next_mask_inv);
/* Extra functions for the offer */
library OfferExtra {
/* Compute wants from tick and gives */
function wants(Offer offer) internal pure returns (uint) {
return offer.tick().inboundFromOutboundUp(offer.gives());
}
/* Sugar to test offer liveness */
function isLive(Offer offer) internal pure returns (bool resp) {
uint gives = offer.gives();
assembly ("memory-safe") {
resp := iszero(iszero(gives))
}
}
/* Get the bin where the offer is stored given an offer list that has `tickSpacing` */
function bin(Offer offer, uint tickSpacing) internal pure returns (Bin) {
return offer.tick().nearestBin(tickSpacing);
}
/* Removes prev/next pointers from an offer before sending it to the maker. Ensures that the maker has no information about the state of the book when it gets called. */
function clearFieldsForMaker(Offer offer) internal pure returns (Offer) {
unchecked {
return Offer.wrap(
Offer.unwrap(offer)
& HIDE_FIELDS_FROM_MAKER_MASK);
}
}
}
/* Extra functions for the struct version of the offer */
library OfferUnpackedExtra {
/* Compute wants from tick and gives */
function wants(OfferUnpacked memory offer) internal pure returns (uint) {
return offer.tick.inboundFromOutboundUp(offer.gives);
}
/* Sugar to test offer liveness */
function isLive(OfferUnpacked memory offer) internal pure returns (bool resp) {
uint gives = offer.gives;
assembly ("memory-safe") {
resp := iszero(iszero(gives))
}
}
/* Removes prev/next pointers from an offer before sending it to the maker; Ensures that the maker has no information about the state of the book when it gets called. */
function bin(OfferUnpacked memory offer, uint tickSpacing) internal pure returns (Bin) {
return offer.tick.nearestBin(tickSpacing);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {OfferDetail,OfferDetailUnpacked} from "@mgv/src/preprocessed/OfferDetail.post.sol";
/* Extra functions for the offer details */
library OfferDetailExtra {
function offer_gasbase(OfferDetail offerDetail) internal pure returns (uint) { unchecked {
return offerDetail.kilo_offer_gasbase() * 1e3;
}}
function offer_gasbase(OfferDetail offerDetail,uint val) internal pure returns (OfferDetail) { unchecked {
return offerDetail.kilo_offer_gasbase(val/1e3);
}}
}
/* Extra functions for the struct version of the offer details */
library OfferDetailUnpackedExtra {
function offer_gasbase(OfferDetailUnpacked memory offerDetail) internal pure returns (uint) { unchecked {
return offerDetail.kilo_offer_gasbase * 1e3;
}}
function offer_gasbase(OfferDetailUnpacked memory offerDetail,uint val) internal pure { unchecked {
offerDetail.kilo_offer_gasbase = val/1e3;
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Bin,TickTreeLib,Field} from "@mgv/lib/core/TickTreeLib.sol";
import {Density, DensityLib} from "@mgv/lib/core/DensityLib.sol";
import {Local,LocalUnpacked,LocalLib} from "@mgv/src/preprocessed/Local.post.sol";
// cleanup-mask: 0s at location of fields to hide from maker, 1s elsewhere
uint constant HIDE_FIELDS_FROM_MAKER_MASK = ~(LocalLib.binPosInLeaf_mask_inv | LocalLib.level3_mask_inv | LocalLib.level2_mask_inv | LocalLib.level1_mask_inv | LocalLib.root_mask_inv | LocalLib.last_mask_inv);
/* Extra functions for local */
library LocalExtra {
/* Sets the density in fixed-point 96X32 format (it is stored in floating-point, see `DensityLib` for more information). */
function densityFrom96X32(Local local, uint density96X32) internal pure returns (Local) { unchecked {
return local.density(DensityLib.from96X32(density96X32));
}}
/* Returns the gasbase in gas (it is stored in kilogas) */
function offer_gasbase(Local local) internal pure returns (uint) { unchecked {
return local.kilo_offer_gasbase() * 1e3;
}}
/* Sets the gasbase in gas (it is stored in kilogas) */
function offer_gasbase(Local local,uint val) internal pure returns (Local) { unchecked {
return local.kilo_offer_gasbase(val/1e3);
}}
/* Returns the bin that contains the best offer in \`local\`'s offer list */
function bestBin(Local local) internal pure returns (Bin) { unchecked {
return TickTreeLib.bestBinFromLocal(local);
}}
/* Erases field that give information about the current structure of the offer list. */
function clearFieldsForMaker(Local local) internal pure returns (Local) { unchecked {
return Local.wrap(
Local.unwrap(local)
& HIDE_FIELDS_FROM_MAKER_MASK);
}}
}
/* Extra functions for the struct version of local */
library LocalUnpackedExtra {
/* Sets the density in fixed-point 96X32 format (it is stored in floating-point, see `DensityLib` for more information). */
function densityFrom96X32(LocalUnpacked memory local, uint density96X32) internal pure { unchecked {
local.density = DensityLib.from96X32(density96X32);
}}
/* Returns the gasbase in gas (it is stored in kilogas) */
function offer_gasbase(LocalUnpacked memory local) internal pure returns (uint) { unchecked {
return local.kilo_offer_gasbase * 1e3;
}}
/* Sets the gasbase in gas (it is stored in kilogas) */
function offer_gasbase(LocalUnpacked memory local,uint val) internal pure { unchecked {
local.kilo_offer_gasbase = val/1e3;
}}
/* Returns the bin that contains the best offer in \`local\`'s offer list */
function bestBin(LocalUnpacked memory local) internal pure returns (Bin) { unchecked {
return TickTreeLib.bestBinFromBranch(local.binPosInLeaf,local.level3,local.level2,local.level1,local.root);
}}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {MangroveOffer, TransferLib} from "@mgv-strats/src/strategies/MangroveOffer.sol";
import {AbstractRouter, RL} from "@mgv-strats/src/strategies/routers/abstract/AbstractRouter.sol";
import {IMangrove} from "@mgv/src/IMangrove.sol";
import {MgvLib, OLKey} from "@mgv/src/core/MgvLib.sol";
import {IERC20} from "@mgv/lib/IERC20.sol";
import {IOfferLogic} from "@mgv-strats/src/strategies/interfaces/IOfferLogic.sol";
///@title `Direct` strats is an extension of MangroveOffer that allows contract's admin to manage offers on Mangrove.
abstract contract Direct is MangroveOffer {
///@notice address of the fund owner. Is used for the proxy owner if strat is using one.
address public immutable FUND_OWNER;
///@notice whether this contract requires that routing pull orders provide *at most* the required amount.
bool public immutable STRICT_PULLING;
struct RouterParams {
AbstractRouter routerImplementation; // 0x if not routing
address fundOwner; // address must be controlled by msg.sender
bool strict;
}
///@notice `Direct`'s constructor.
///@param mgv The Mangrove deployment that is allowed to call `this` for trade execution and posthook.
///@param routerParams routing parameters. Use `noRouter()` to get an empty struct
constructor(IMangrove mgv, RouterParams memory routerParams) MangroveOffer(mgv, routerParams.routerImplementation) {
address fundOwner = routerParams.fundOwner == address(0) ? address(this) : routerParams.fundOwner;
STRICT_PULLING = routerParams.strict;
FUND_OWNER = fundOwner;
}
///@notice convenience function to get an empty RouterParams struct
///@return an empty RouterParams struct
function noRouter() public pure returns (RouterParams memory) {}
///@inheritdoc IOfferLogic
///@dev Returns the router to which pull/push calls must be done.
///@dev if strat is not routing, the call does not revert but returns a casted `address(0)`
function router(address) public view override returns (AbstractRouter) {
return ROUTER_IMPLEMENTATION;
}
///@notice convenience function
///@return the router to which pull/push calls must be done.
function router() public view returns (AbstractRouter) {
return router(address(0));
}
///@inheritdoc IOfferLogic
///@notice activates asset exchange with router
function activate(IERC20 token) public virtual override {
super.activate(token);
if (_isRouting()) {
require(TransferLib.approveToken(token, address(router()), type(uint).max), "Direct/RouterActivationFailed");
}
}
/// @notice Inserts a new offer in Mangrove Offer List.
/// @param args Function arguments stored in memory.
/// @return offerId Identifier of the newly created offer. Returns 0 if offer creation was rejected by Mangrove and `args.noRevert` is set to `true`.
/// @return status NEW_OFFER_SUCCESS if the offer was successfully posted on Mangrove. Returns Mangrove's revert reason otherwise.
function _newOffer(OfferArgs memory args) internal returns (uint offerId, bytes32 status) {
try MGV.newOfferByTick{value: args.fund}(args.olKey, args.tick, args.gives, args.gasreq, args.gasprice) returns (
uint offerId_
) {
offerId = offerId_;
status = NEW_OFFER_SUCCESS;
} catch Error(string memory reason) {
require(args.noRevert, reason);
status = bytes32(bytes(reason));
}
}
///@inheritdoc MangroveOffer
function _updateOffer(OfferArgs memory args, uint offerId) internal override returns (bytes32 status) {
try MGV.updateOfferByTick{value: args.fund}(args.olKey, args.tick, args.gives, args.gasreq, args.gasprice, offerId)
{
status = REPOST_SUCCESS;
} catch Error(string memory reason) {
require(args.noRevert, reason);
status = bytes32(bytes(reason));
}
}
///@notice Retracts an offer from an Offer List of Mangrove.
///@param olKey the offer list key.
///@param offerId the identifier of the offer in the offer list
///@param deprovision if set to `true` if offer admin wishes to redeem the offer's provision.
///@return freeWei the amount of native tokens (in WEI) that have been retrieved by retracting the offer.
///@dev An offer that is retracted without `deprovision` is retracted from the offer list, but still has its provisions locked by Mangrove.
///@dev Calling this function, with the `deprovision` flag, on an offer that is already retracted must be used to retrieve the locked provisions.
function _retractOffer(
OLKey memory olKey,
uint offerId,
bool deprovision // if set to `true`, `this` contract will receive the remaining provision (in WEI) associated to `offerId`.
) internal returns (uint freeWei) {
freeWei = MGV.retractOffer(olKey, offerId, deprovision);
}
///@inheritdoc IOfferLogic
function provisionOf(OLKey memory olKey, uint offerId) external view override returns (uint provision) {
provision = _provisionOf(olKey, offerId);
}
///@notice direct contract do not need to do anything specific with incoming funds during trade
///@dev one should override this function if one wishes to leverage taker's fund during trade execution
///@inheritdoc MangroveOffer
function __put__(uint, MgvLib.SingleOrder calldata) internal virtual override returns (uint) {
return 0;
}
///@notice `__get__` hook for `Direct` is to ask the router to pull liquidity if using a router
/// otherwise the function simply returns what's missing in the local balance
///@inheritdoc MangroveOffer
function __get__(uint amount, MgvLib.SingleOrder calldata order) internal virtual override returns (uint) {
uint balance = IERC20(order.olKey.outbound_tkn).balanceOf(address(this));
uint missing = balance >= amount ? 0 : amount - balance;
if (!_isRouting()) {
return missing;
} else {
uint pulled = router().pull(
RL.RoutingOrder({
token: IERC20(order.olKey.outbound_tkn),
olKeyHash: order.olKey.hash(),
offerId: order.offerId,
fundOwner: FUND_OWNER
}),
missing,
STRICT_PULLING
);
return pulled >= missing ? 0 : missing - pulled;
}
}
///@notice Direct posthook flushes outbound and inbound token back to the router (if any)
///@inheritdoc MangroveOffer
function __posthookSuccess__(MgvLib.SingleOrder calldata order, bytes32 makerData)
internal
virtual
override
returns (bytes32)
{
bytes32 olKeyHash = order.olKey.hash();
if (_isRouting()) {
RL.RoutingOrder[] memory routingOrders = new RL.RoutingOrder[](2);
routingOrders[0].token = IERC20(order.olKey.outbound_tkn); // flushing outbound tokens if this contract pulled more liquidity than required during `makerExecute`
routingOrders[0].fundOwner = FUND_OWNER;
routingOrders[0].olKeyHash = olKeyHash;
routingOrders[0].offerId = order.offerId;
routingOrders[1].token = IERC20(order.olKey.inbound_tkn); // flushing liquidity brought by taker
routingOrders[1].fundOwner = FUND_OWNER;
routingOrders[1].olKeyHash = olKeyHash;
routingOrders[1].offerId = order.offerId;
router().flush(routingOrders);
}
// reposting offer residual if any
return super.__posthookSuccess__(order, makerData);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {IHasOfferListOfOfferType, OfferType} from "./TradesBaseQuotePair.sol";
///@title Adds a [0..length] index <--> offerId map to a strat.
///@dev utilizes the `IHasOfferListOfOfferType` contract.
abstract contract HasIndexedBidsAndAsks is IHasOfferListOfOfferType {
///@notice the length of the index has been set.
///@param value the length.
///@notice By emitting this data, an indexer will be able to keep track of what length is used.
event SetLength(uint value);
///@notice a new offer of type `ba` with `offerId` was created at price `index`
///@param ba the offer type
///@param index the index
///@param offerId the Mangrove offer id.
///@notice By emitting this data, an indexer will be able to keep track of what offer has what index.
event SetIndexMapping(OfferType indexed ba, uint index, uint offerId);
///@notice the length of the map.
uint internal length;
///@notice Mangrove's offer id of an ask at a given index.
mapping(uint => uint) private askOfferIdOfIndex;
///@notice Mangrove's offer id of a bid at a given index.
mapping(uint => uint) private bidOfferIdOfIndex;
///@notice An inverse mapping of askOfferIdOfIndex. E.g., indexOfAskOfferId[42] is the index in askOfferIdOfIndex at which ask of id #42 on Mangrove is stored.
mapping(uint => uint) private indexOfAskOfferId;
///@notice An inverse mapping of bidOfferIdOfIndex. E.g., indexOfBidOfferId[42] is the index in bidOfferIdOfIndex at which bid of id #42 on Mangrove is stored.
mapping(uint => uint) private indexOfBidOfferId;
///@notice maps index of offers to offer id on Mangrove.
///@param ba the offer type
///@param index the index
///@return offerId the Mangrove offer id.
function offerIdOfIndex(OfferType ba, uint index) public view returns (uint offerId) {
return ba == OfferType.Ask ? askOfferIdOfIndex[index] : bidOfferIdOfIndex[index];
}
///@notice Maps an offer type and Mangrove offer id to index.
///@param ba the offer type
///@param offerId the Mangrove offer id.
///@return index the index.
function indexOfOfferId(OfferType ba, uint offerId) public view returns (uint index) {
return ba == OfferType.Ask ? indexOfAskOfferId[offerId] : indexOfBidOfferId[offerId];
}
///@notice Sets the Mangrove offer id for an index and vice versa.
///@param ba the offer type
///@param index the index
///@param offerId the Mangrove offer id.
function setIndexMapping(OfferType ba, uint index, uint offerId) internal {
if (ba == OfferType.Ask) {
indexOfAskOfferId[offerId] = index;
askOfferIdOfIndex[index] = offerId;
} else {
indexOfBidOfferId[offerId] = index;
bidOfferIdOfIndex[index] = offerId;
}
emit SetIndexMapping(ba, index, offerId);
}
///@notice sets the length of the map.
///@param length_ the new length.
function setLength(uint length_) internal {
length = length_;
emit SetLength(length_);
}
}{
"remappings": [
"@mgv/src/=node_modules/@mangrovedao/mangrove-core/src/",
"@mgv/lib/=node_modules/@mangrovedao/mangrove-core/lib/",
"@mgv/test/=node_modules/@mangrovedao/mangrove-core/test/",
"@mgv/script/=node_modules/@mangrovedao/mangrove-core/script/",
"@mgv/forge-std/=node_modules/@mangrovedao/mangrove-core/lib/forge-std/src/",
"ds-test/=node_modules/@mangrovedao/mangrove-core/lib/forge-std/lib/ds-test/src/",
"@mgv-strats/src/=src/",
"@mgv-strats/lib/=lib/",
"@mgv-strats/test/=test/",
"@mgv-strats/script/=script/",
"@openzeppelin/contracts/=lib/openzeppelin/contracts/",
"@orbit-protocol/contracts/=lib/orbit-protocol/contracts/",
"erc4626-tests/=lib/openzeppelin/lib/erc4626-tests/",
"forge-std/=lib/openzeppelin/lib/forge-std/src/",
"openzeppelin/=lib/openzeppelin/",
"orbit-protocol/=lib/orbit-protocol/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false,
"libraries": {
"src/strategies/offer_maker/market_making/kandel/abstract/KandelLib.sol": {
"KandelLib": "0x0ea85F9E19763eeC0e376F988FE9A19c9328e3FA"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IMangrove","name":"mgv","type":"address"},{"components":[{"internalType":"address","name":"outbound_tkn","type":"address"},{"internalType":"address","name":"inbound_tkn","type":"address"},{"internalType":"uint256","name":"tickSpacing","type":"uint256"}],"internalType":"struct OLKey","name":"olKeyBaseQuote","type":"tuple"},{"internalType":"uint256","name":"gasreq","type":"uint256"},{"internalType":"contract IBlast","name":"blastContract","type":"address"},{"internalType":"address","name":"blastGovernor","type":"address"},{"internalType":"contract IBlastPoints","name":"blastPointsContract","type":"address"},{"internalType":"address","name":"blastPointsOperator","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Credit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Debit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"olKeyHash","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"makerData","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"mgvData","type":"bytes32"}],"name":"LogIncident","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"olKeyHash","type":"bytes32"}],"name":"OfferListKey","type":"event"},{"anonymous":false,"inputs":[],"name":"PopulateEnd","type":"event"},{"anonymous":false,"inputs":[],"name":"PopulateStart","type":"event"},{"anonymous":false,"inputs":[],"name":"RetractEnd","type":"event"},{"anonymous":false,"inputs":[],"name":"RetractStart","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"admin","type":"address"}],"name":"SetAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetBaseQuoteTickOffset","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetGasprice","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetGasreq","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum OfferType","name":"ba","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"SetIndexMapping","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetLength","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetStepSize","type":"event"},{"inputs":[],"name":"BASE","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FUND_OWNER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MGV","outputs":[{"internalType":"contract IMangrove","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"QUOTE","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROUTER_IMPLEMENTATION","outputs":[{"internalType":"contract AbstractRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STRICT_PULLING","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TICK_SPACING","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"activate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"current","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"baseQuoteTickOffset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"},{"internalType":"Tick","name":"baseQuoteTickIndex0","type":"int256"},{"internalType":"uint256","name":"_baseQuoteTickOffset","type":"uint256"},{"internalType":"uint256","name":"firstAskIndex","type":"uint256"},{"internalType":"uint256","name":"bidGives","type":"uint256"},{"internalType":"uint256","name":"askGives","type":"uint256"},{"internalType":"uint256","name":"pricePoints","type":"uint256"},{"internalType":"uint256","name":"stepSize","type":"uint256"}],"name":"createDistribution","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"asks","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"bids","type":"tuple[]"}],"internalType":"struct DirectWithBidsAndAsksDistribution.Distribution","name":"distribution","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"name":"depositFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getOffer","outputs":[{"internalType":"Offer","name":"offer","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"indexOfOfferId","outputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"outbound_tkn","type":"address"},{"internalType":"address","name":"inbound_tkn","type":"address"},{"internalType":"uint256","name":"tickSpacing","type":"uint256"}],"internalType":"struct OLKey","name":"olKey","type":"tuple"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"Offer","name":"offer","type":"uint256"},{"internalType":"uint256","name":"takerWants","type":"uint256"},{"internalType":"uint256","name":"takerGives","type":"uint256"},{"internalType":"OfferDetail","name":"offerDetail","type":"uint256"},{"internalType":"Global","name":"global","type":"uint256"},{"internalType":"Local","name":"local","type":"uint256"}],"internalType":"struct MgvLib.SingleOrder","name":"order","type":"tuple"}],"name":"makerExecute","outputs":[{"internalType":"bytes32","name":"ret","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"outbound_tkn","type":"address"},{"internalType":"address","name":"inbound_tkn","type":"address"},{"internalType":"uint256","name":"tickSpacing","type":"uint256"}],"internalType":"struct OLKey","name":"olKey","type":"tuple"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"Offer","name":"offer","type":"uint256"},{"internalType":"uint256","name":"takerWants","type":"uint256"},{"internalType":"uint256","name":"takerGives","type":"uint256"},{"internalType":"OfferDetail","name":"offerDetail","type":"uint256"},{"internalType":"Global","name":"global","type":"uint256"},{"internalType":"Local","name":"local","type":"uint256"}],"internalType":"struct MgvLib.SingleOrder","name":"order","type":"tuple"},{"components":[{"internalType":"bytes32","name":"makerData","type":"bytes32"},{"internalType":"bytes32","name":"mgvData","type":"bytes32"}],"internalType":"struct MgvLib.OrderResult","name":"result","type":"tuple"}],"name":"makerPosthook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"noRouter","outputs":[{"components":[{"internalType":"contract AbstractRouter","name":"routerImplementation","type":"address"},{"internalType":"address","name":"fundOwner","type":"address"},{"internalType":"bool","name":"strict","type":"bool"}],"internalType":"struct Direct.RouterParams","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"offerIdOfIndex","outputs":[{"internalType":"uint256","name":"offerId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"}],"name":"offeredVolume","outputs":[{"internalType":"uint256","name":"volume","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"params","outputs":[{"internalType":"uint32","name":"gasprice","type":"uint32"},{"internalType":"uint24","name":"gasreq","type":"uint24"},{"internalType":"uint32","name":"stepSize","type":"uint32"},{"internalType":"uint32","name":"pricePoints","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"}],"name":"pending","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"asks","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"bids","type":"tuple[]"}],"internalType":"struct DirectWithBidsAndAsksDistribution.Distribution","name":"distribution","type":"tuple"},{"components":[{"internalType":"uint32","name":"gasprice","type":"uint32"},{"internalType":"uint24","name":"gasreq","type":"uint24"},{"internalType":"uint32","name":"stepSize","type":"uint32"},{"internalType":"uint32","name":"pricePoints","type":"uint32"}],"internalType":"struct CoreKandel.Params","name":"parameters","type":"tuple"},{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"name":"populate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"asks","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"Tick","name":"tick","type":"int256"},{"internalType":"uint256","name":"gives","type":"uint256"}],"internalType":"struct DirectWithBidsAndAsksDistribution.DistributionOffer[]","name":"bids","type":"tuple[]"}],"internalType":"struct DirectWithBidsAndAsksDistribution.Distribution","name":"distribution","type":"tuple"}],"name":"populateChunk","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"},{"internalType":"Tick","name":"baseQuoteTickIndex0","type":"int256"},{"internalType":"uint256","name":"firstAskIndex","type":"uint256"},{"internalType":"uint256","name":"bidGives","type":"uint256"},{"internalType":"uint256","name":"askGives","type":"uint256"}],"name":"populateChunkFromOffset","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"},{"internalType":"Tick","name":"baseQuoteTickIndex0","type":"int256"},{"internalType":"uint256","name":"_baseQuoteTickOffset","type":"uint256"},{"internalType":"uint256","name":"firstAskIndex","type":"uint256"},{"internalType":"uint256","name":"bidGives","type":"uint256"},{"internalType":"uint256","name":"askGives","type":"uint256"},{"components":[{"internalType":"uint32","name":"gasprice","type":"uint32"},{"internalType":"uint24","name":"gasreq","type":"uint24"},{"internalType":"uint32","name":"stepSize","type":"uint32"},{"internalType":"uint32","name":"pricePoints","type":"uint32"}],"internalType":"struct CoreKandel.Params","name":"parameters","type":"tuple"},{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"name":"populateFromOffset","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"outbound_tkn","type":"address"},{"internalType":"address","name":"inbound_tkn","type":"address"},{"internalType":"uint256","name":"tickSpacing","type":"uint256"}],"internalType":"struct OLKey","name":"olKey","type":"tuple"},{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"provisionOf","outputs":[{"internalType":"uint256","name":"provision","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum OfferType","name":"ba","type":"uint8"}],"name":"reserveBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"},{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"internalType":"uint256","name":"freeWei","type":"uint256"},{"internalType":"address payable","name":"recipient","type":"address"}],"name":"retractAndWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"}],"name":"retractOffers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"router","outputs":[{"internalType":"contract AbstractRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"contract AbstractRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"admin_","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseQuoteTickOffset","type":"uint256"}],"name":"setBaseQuoteTickOffset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasprice","type":"uint256"}],"name":"setGasprice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasreq","type":"uint256"}],"name":"setGasreq","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stepSize","type":"uint256"}],"name":"setStepSize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"}],"name":"withdrawFromMangrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
0x6101606040523480156200001257600080fd5b50604051620051de380380620051de8339810160408190526200003591620006aa565b86868682826200005e604080516060810182526000808252602082018190529181019190915290565b8282828183828181818160000151336200007e81620002cc60201b60201c565b506001600160a01b038216620000db5760405162461bcd60e51b815260206004820152601360248201527f4d67764f666665722f30784d616e67726f76650000000000000000000000000060448201526064015b60405180910390fd5b6001600160a01b03918216608052811660a05260208201516000911615620001085781602001516200010a565b305b604092830151151560e0526001600160a01b0390811660c05286518116610100526020870151166101205250840151610140525050606082207fa1824a64387381916c722ef6d39d525cb7c1dcbdfc58fc2dcd8cf57c061fc4e9915060405190815260200160405180910390a1505050505050506200018f816200038960201b60201c565b610100516200019e9062000496565b61012051620001ad9062000496565b505050836001600160a01b0316634e606c476040518163ffffffff1660e01b8152600401600060405180830381600087803b158015620001ec57600080fd5b505af115801562000201573d6000803e3d6000fd5b5050604051631d70c8d360e31b81526001600160a01b0386811660048301528716925063eb8646989150602401600060405180830381600087803b1580156200024957600080fd5b505af11580156200025e573d6000803e3d6000fd5b50506040516336b91f2b60e01b81526001600160a01b038481166004830152851692506336b91f2b9150602401600060405180830381600087803b158015620002a657600080fd5b505af1158015620002bb573d6000803e3d6000fd5b505050505050505050505062000803565b6001600160a01b038116620003245760405162461bcd60e51b815260206004820152601860248201527f416363657373436f6e74726f6c6c65642f307841646d696e00000000000000006044820152606401620000d2565b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a19060200160405180910390a162000386816001600160e01b038216565b50565b6000546001600160a01b03163314620003e55760405162461bcd60e51b815260206004820152601860248201527f416363657373436f6e74726f6c6c65642f496e76616c696400000000000000006044820152606401620000d2565b8062ffffff811681146200043c5760405162461bcd60e51b815260206004820152601460248201527f4b616e64656c2f676173726571546f6f486967680000000000000000000000006044820152606401620000d2565b6006805462ffffff60201b191664010000000062ffffff8416908102919091179091556040519081527fafef3ad374c0b972e3c793be825735801fa05cc4c67157d98d9a111b4027988d9060200160405180910390a15050565b620004a18162000519565b60a0516001600160a01b0316156200038657620004cb81620004c26200057e565b6000196200058f565b620003865760405162461bcd60e51b815260206004820152601d60248201527f4469726563742f526f7574657241637469766174696f6e4661696c65640000006044820152606401620000d2565b62000530816080516000196200058f60201b60201c565b620003865760405162461bcd60e51b815260206004820152601960248201527f4d67764f666665722f41637469766174696f6e4661696c6564000000000000006044820152606401620000d2565b60006200058a60a05190565b905090565b60006200059e848484620005a6565b949350505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b17905291516000928392839291881691620006069190620007a7565b6000604051808303816000865af19150503d806000811462000645576040519150601f19603f3d011682016040523d82523d6000602084013e6200064a565b606091505b50915091508180156200067857508051158062000678575080806020019051810190620006789190620007d8565b9695505050505050565b6001600160a01b03811681146200038657600080fd5b8051620006a58162000682565b919050565b6000806000806000806000878903610120811215620006c857600080fd5b8851620006d58162000682565b97506060601f1982011215620006ea57600080fd5b50604051606081016001600160401b03811182821017156200071c57634e487b7160e01b600052604160045260246000fd5b60405260208901516200072f8162000682565b81526040890151620007418162000682565b602082015260608901516040820152608089015190965094506200076860a0890162000698565b93506200077860c0890162000698565b92506200078860e0890162000698565b915062000799610100890162000698565b905092959891949750929550565b6000825160005b81811015620007ca5760208186018101518583015201620007ae565b506000920191825250919050565b600060208284031215620007eb57600080fd5b81518015158114620007fc57600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161486f6200096f600039600081816103ad0152818161227c015261230e01526000818161057801528181610f8d015281816110020152818161145301528181611d530152818161224d01526122b00152600081816107e701528181610eb201528181610f270152818161142801528181611d790152818161221e015281816122df0152612e1e0152600081816104740152611fb601526000818161079301528181611f8801528181612b0c0152612bfd0152600081816104d80152818161075f0152818161083601528181610b2e01528181611e1901528181611f220152612ca0015260008181610544015281816108b501528181610ba8015281816110e20152818161116e01528181611303015281816116ad0152818161179c01528181611da401528181612444015281816125b70152818161299501528181612f2b0152818161302c01526132e3015261486f6000f3fe6080604052600436106102345760003560e01c806399fa5e2d1161012e578063cff0ab96116100ab578063ea0f394d1161006f578063ea0f394d146107b5578063ec342ad0146107d5578063f851a44014610809578063f887ea4014610827578063fcaa7e2e1461085a57600080fd5b8063cff0ab961461068d578063d2e498fe14610701578063e1f21c6714610721578063e4b643e314610741578063e910d6731461078157600080fd5b8063a2e241af116100f2578063a2e241af146105fa578063ace679021461061a578063b9c9cec21461063a578063bfc353f91461064d578063c7e1bb441461066d57600080fd5b806399fa5e2d146105325780639c579839146105665780639ee8a91c1461059a578063a224b5e9146105ba578063a24f2b2d146105da57600080fd5b806346ca626b116101bc5780637692c328116101805780637692c3281461044257806376a820e514610462578063790532a1146104a65780637b0b5fca146104c657806398ed53401461051257600080fd5b806346ca626b1461039b5780634f605c5b146103cf57806361638ed5146103e2578063704b6c02146104025780637144df241461042257600080fd5b80631c5a9d9c116102035780631c5a9d9c146102be5780632380fafd146102de57806334bd8931146102fe57806334be9cb61461031e5780633fce15c91461036e57600080fd5b8063100cd98d146102405780631450acd21461025557806314ee02bd1461027557806318acf82f1461029e57600080fd5b3661023b57005b600080fd5b61025361024e366004613d3c565b61087a565b005b34801561026157600080fd5b50610253610270366004613d9a565b610962565b34801561028157600080fd5b5061028b60075481565b6040519081526020015b60405180910390f35b3480156102aa57600080fd5b5061028b6102b9366004613dc7565b610a94565b3480156102ca57600080fd5b506102536102d9366004613df7565b610b12565b3480156102ea57600080fd5b5061028b6102f9366004613e27565b610ba4565b34801561030a57600080fd5b50610253610319366004613d9a565b610c54565b34801561032a57600080fd5b50604080516060808201835260008083526020808401828152938501828152855192835293516001600160a01b031690820152915115159282019290925201610295565b34801561037a57600080fd5b5061038e610389366004613e44565b610d20565b6040516102959190613ef4565b3480156103a757600080fd5b5061028b7f000000000000000000000000000000000000000000000000000000000000000081565b6102536103dd366004613f2d565b610df2565b3480156103ee57600080fd5b506102536103fd366004613f70565b610ead565b34801561040e57600080fd5b5061025361041d366004613df7565b611067565b34801561042e57600080fd5b5061025361043d366004613f92565b61109a565b34801561044e57600080fd5b5061028b61045d366004613fc2565b6112cf565b34801561046e57600080fd5b506104967f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610295565b3480156104b257600080fd5b506102536104c1366004613fec565b611384565b3480156104d257600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610295565b34801561051e57600080fd5b5061028b61052d366004613dc7565b6113d5565b34801561053e57600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b34801561057257600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b3480156105a657600080fd5b506102536105b5366004614041565b6113f9565b3480156105c657600080fd5b506102536105d5366004613d9a565b611479565b3480156105e657600080fd5b5061028b6105f53660046140cc565b61153c565b34801561060657600080fd5b50610253610615366004613f70565b611548565b34801561062657600080fd5b50610253610635366004614109565b6115e0565b61025361064836600461413e565b61167b565b34801561065957600080fd5b5061028b610668366004613fc2565b611756565b34801561067957600080fd5b506102536106883660046141ba565b61179a565b34801561069957600080fd5b506006546106cc9063ffffffff8082169162ffffff600160201b82041691600160381b8204811691600160581b90041684565b6040805163ffffffff958616815262ffffff909416602085015291841691830191909152919091166060820152608001610295565b34801561070d57600080fd5b5061028b61071c366004613dc7565b61186c565b34801561072d57600080fd5b5061049661073c3660046141f1565b6118b3565b34801561074d57600080fd5b506104fa61075c366004613df7565b507f000000000000000000000000000000000000000000000000000000000000000090565b34801561078d57600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b3480156107c157600080fd5b5061028b6107d0366004613fc2565b61193f565b3480156107e157600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b34801561081557600080fd5b506000546001600160a01b03166104fa565b34801561083357600080fd5b507f00000000000000000000000000000000000000000000000000000000000000006104fa565b34801561086657600080fd5b50610253610875366004613d9a565b611983565b6000546001600160a01b031633146108ad5760405162461bcd60e51b81526004016108a490614232565b60405180910390fd5b3415610928577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b60d4288346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561090e57600080fd5b505af1158015610922573d6000803e3d6000fd5b50505050505b61093183611a3e565b61093b8282610ead565b60065461095c90859062ffffff600160201b8204169063ffffffff16611c53565b50505050565b6000546001600160a01b0316331461098c5760405162461bcd60e51b81526004016108a490614232565b80806109d25760405162461bcd60e51b81526020600482015260156024820152744b616e64656c2f7374657053697a65546f6f4c6f7760581b60448201526064016108a4565b818163ffffffff161480156109f55750600654600160581b900463ffffffff1682105b610a3a5760405162461bcd60e51b8152602060048201526016602482015275096c2dcc8cad85ee6e8cae0a6d2f4caa8dede90d2ced60531b60448201526064016108a4565b600680546affffffff000000000000001916600160381b63ffffffff8416021790556040518281527f0408193baae9f2730f7be76d9be93983ed2dd45af2305c085920b8f00c25bbcd906020015b60405180910390a15050565b600080610aa083611d36565b6040516370a0823160e01b81523060048201529091506001600160a01b038216906370a0823190602401602060405180830381865afa158015610ae7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0b9190614269565b9392505050565b610b1b81611d9e565b610b23611e17565b15610ba157610b55817f0000000000000000000000000000000000000000000000000000000000000000600019611e46565b610ba15760405162461bcd60e51b815260206004820152601d60248201527f4469726563742f526f7574657241637469766174696f6e4661696c656400000060448201526064016108a4565b50565b60007f0000000000000000000000000000000000000000000000000000000000000000336001600160a01b03821614610bef5760405162461bcd60e51b81526004016108a490614232565b60009150610c018360a0013584611e5b565b15610c4e5760405162461bcd60e51b815260206004820152601860248201527f6d67764f666665722f61626f72742f6765744661696c6564000000000000000060448201526064016108a4565b50919050565b6000546001600160a01b03163314610c7e5760405162461bcd60e51b81526004016108a490614232565b8062ffffff81168114610cca5760405162461bcd60e51b8152602060048201526014602482015273096c2dcc8cad85ecec2e6e4cae2a8dede90d2ced60631b60448201526064016108a4565b6006805466ffffff000000001916600160201b62ffffff8416908102919091179091556040519081527fafef3ad374c0b972e3c793be825735801fa05cc4c67157d98d9a111b4027988d90602001610a88565b90565b60408051808201825260608082526020820152905163fbbd4a6560e01b8152600481018b9052602481018a905260448101899052606481018890526084810187905260a4810186905260c4810185905260e481018490526101048101839052730ea85f9e19763eec0e376f988fe9a19c9328e3fa9063fbbd4a659061012401600060405180830381865af4158015610dbc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610de49190810190614315565b9a9950505050505050505050565b6000546001600160a01b03163314610e1c5760405162461bcd60e51b81526004016108a490614232565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b82048116938301849052600160581b90910416606082018190526007549192600092610e83928b928b928b9290918b918b918b9190610d20565b9050610ea381836020015162ffffff16846000015163ffffffff16611c53565b5050505050505050565b610ed97f0000000000000000000000000000000000000000000000000000000000000000333085612064565b610f255760405162461bcd60e51b815260206004820152601760248201527f4b616e64656c2f626173655472616e736665724661696c00000000000000000060448201526064016108a4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f1bbf55d483639f8103dc4e035af71a4fbdb16c80be740fa3eef81198acefa09483604051610f8091815260200190565b60405180910390a2610fb47f0000000000000000000000000000000000000000000000000000000000000000333084612064565b6110005760405162461bcd60e51b815260206004820152601860248201527f4b616e64656c2f71756f74655472616e736665724661696c000000000000000060448201526064016108a4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f1bbf55d483639f8103dc4e035af71a4fbdb16c80be740fa3eef81198acefa0948260405161105b91815260200190565b60405180910390a25050565b6000546001600160a01b031633146110915760405162461bcd60e51b81526004016108a490614232565b610ba181612133565b6000546001600160a01b031633146110c45760405162461bcd60e51b81526004016108a490614232565b6000198203611158576040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015611131573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111559190614269565b91505b604051632e1a7d4d60e01b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d906024016020604051808303816000875af11580156111bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e391906143aa565b6112275760405162461bcd60e51b81526020600482015260156024820152741b59dd93d999995c8bddda5d1a191c985dd1985a5b605a1b60448201526064016108a4565b6000816001600160a01b03168360405160006040518083038185875af1925050503d8060008114611274576040519150601f19603f3d011682016040523d82523d6000602084013e611279565b606091505b50509050806112ca5760405162461bcd60e51b815260206004820152601860248201527f6d67764f666665722f7765695472616e736665724661696c000000000000000060448201526064016108a4565b505050565b6000806112dc8484611756565b905060006112e9856121dd565b604051630129e86d60e21b81529091506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906304a7a1b49061133a90849086906004016143f3565b602060405180830381865afa158015611357573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137b9190614269565b95945050505050565b6000546001600160a01b031633146113ae5760405162461bcd60e51b81526004016108a490614232565b6113b88686611548565b6113c38484836113f9565b6113cd828261109a565b505050505050565b60006113e08261186c565b6113e983610a94565b6113f39190614424565b92915050565b6000546001600160a01b031633146114235760405162461bcd60e51b81526004016108a490614232565b61144e7f00000000000000000000000000000000000000000000000000000000000000008483612336565b6112ca7f00000000000000000000000000000000000000000000000000000000000000008383612336565b6000546001600160a01b031633146114a35760405162461bcd60e51b81526004016108a490614232565b808162ffffff16146114f75760405162461bcd60e51b815260206004820152601860248201527f4b616e64656c2f7469636b4f6666736574546f6f48696768000000000000000060448201526064016108a4565b8060075414610ba15760078190556040518181527f286da08673f0eb4b3843f2824fb8e3e412534a62f6094fdc8b4008cfeba4ba66906020015b60405180910390a150565b6000610b0b838361243f565b6000546001600160a01b031633146115725760405162461bcd60e51b81526004016108a490614232565b6040517f97714c1c48a0b9a1a347710cb6a62f056f5a811d4006655e3b41959e1e72a40990600090a16115a782826001612500565b6115b382826000612500565b6040517fa9bc12cd7db30bdfe60fece3ec52cfa7c8d60e396e2ea5df439a7d458f05f9b690600090a15050565b6000546001600160a01b0316331461160a5760405162461bcd60e51b81526004016108a490614232565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b8204811693830193909352600160581b9004909116606082015261167761165d8361444b565b826020015162ffffff16836000015163ffffffff16611c53565b5050565b6000546001600160a01b031633146116a55760405162461bcd60e51b81526004016108a490614232565b3415611720577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b60d4288346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561170657600080fd5b505af115801561171a573d6000803e3d6000fd5b50505050505b61172983611a3e565b61173287611479565b61173c8282610ead565b61174a8a8a8a898989610df2565b50505050505050505050565b6000600183600181111561176c5761176c614457565b1461178557600082815260036020526040902054610b0b565b50600090815260026020526040902054919050565b7f0000000000000000000000000000000000000000000000000000000000000000336001600160a01b038216146117e35760405162461bcd60e51b81526004016108a490614232565b81602001356f6d67762f74726164655375636365737360801b0361180c5761095c838335612551565b606083013561182a6118233686900386018661446d565b6060902090565b6040805185358152602080870135908201527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c3910160405180910390a3505050565b6000805b600154811015610c4e57600061188684836112cf565b905061189f60016001607f1b03602c83901c1684614489565b925050806118ac9061449c565b9050611870565b600080546001600160a01b031633146118de5760405162461bcd60e51b81526004016108a490614232565b6118e9848484611e46565b6119355760405162461bcd60e51b815260206004820152601760248201527f6d67764f666665722f617070726f76652f6661696c656400000000000000000060448201526064016108a4565b5060019392505050565b6000600183600181111561195557611955614457565b1461196e57600082815260056020526040902054610b0b565b50600090815260046020526040902054919050565b6000546001600160a01b031633146119ad5760405162461bcd60e51b81526004016108a490614232565b630400000081106119f95760405162461bcd60e51b8152602060048201526016602482015275096c2dcc8cad85ecec2e6e0e4d2c6caa8dede90d2ced60531b60448201526064016108a4565b6006805463ffffffff191663ffffffff83161790556040518181527fdbebd814ae648f654dcc50c734aa76e55a32e96b7d85303a08e2ddf11874a0dd90602001611531565b604080516080808201835260065463ffffffff808216845262ffffff600160201b8304166020850152600160381b8204811694840194909452600160581b90049092166060808301919091529091611a9b919084019084016144b5565b63ffffffff16816060015163ffffffff1614611b50576000611ac360808401606085016144b5565b905060028163ffffffff161015611b1c5760405162461bcd60e51b815260206004820152601960248201527f4b616e64656c2f696e76616c69645072696365506f696e74730000000000000060448201526064016108a4565b611b2b8163ffffffff16612566565b6006805463ffffffff909216600160581b0263ffffffff60581b199092169190911790555b611b6060608301604084016144b5565b63ffffffff16816040015163ffffffff1614611b9457611b94611b8960608401604085016144b5565b63ffffffff16610962565b611ba160208301836144b5565b63ffffffff1615801590611bce5750805163ffffffff16611bc560208401846144b5565b63ffffffff1614155b15611bee57611bee611be360208401846144b5565b63ffffffff16611983565b611bfe60408301602084016144db565b62ffffff1615801590611c315750806020015162ffffff16826020016020810190611c2991906144db565b62ffffff1614155b1561167757611677611c4960408401602085016144db565b62ffffff16610c54565b6040517faab0a16d4cef87072f3977d7f1c066be401e0e6486526674f5f6172d42703db190600090a1611c84613b0d565b6060810183905260808101829052611c9c60006121dd565b81526020840151611caf9060008361259b565b80516040805160608082018352600080835260208084018290529284015282519081018352818401516001600160a01b03908116825284511691810191909152918101519082015281528351611d079060018361259b565b6040517fac65490b93de6b3189ca1e1653852249eb8680e816c258cff6ccf73d8501d3d090600090a150505050565b60006001826001811115611d4c57611d4c614457565b14611d77577f00000000000000000000000000000000000000000000000000000000000000006113f3565b7f000000000000000000000000000000000000000000000000000000000000000092915050565b611dcb817f0000000000000000000000000000000000000000000000000000000000000000600019611e46565b610ba15760405162461bcd60e51b815260206004820152601960248201527f4d67764f666665722f41637469766174696f6e4661696c65640000000000000060448201526064016108a4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316151590565b6000611e538484846126c9565b949350505050565b600080611e6b6020840184613df7565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed59190614269565b9050600084821015611ef057611eeb8286614500565b611ef3565b60005b9050611efd611e17565b611f0a5791506113f39050565b60408051608081019091526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063504db8e69080611f5760208a018a613df7565b6001600160a01b03168152602001611f77611823368b90038b018b61446d565b8152602001886060013581526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815250847f00000000000000000000000000000000000000000000000000000000000000006040518463ffffffff1660e01b8152600401611ff393929190614513565b6020604051808303816000875af1158015612012573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120369190614269565b90508181101561204f5761204a8183614500565b612052565b60005b93505050506113f3565b505092915050565b60008160000361207657506001611e53565b826001600160a01b0316846001600160a01b031603612105576040516370a0823160e01b81526001600160a01b0385811660048301528391908716906370a0823190602401602060405180830381865afa1580156120d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120fc9190614269565b10159050611e53565b306001600160a01b03851603612127576121208584846127af565b9050611e53565b61137b858585856127e5565b6001600160a01b0381166121895760405162461bcd60e51b815260206004820152601860248201527f416363657373436f6e74726f6c6c65642f307841646d696e000000000000000060448201526064016108a4565b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a19060200160405180910390a150565b604080516060810182526000808252602082018190529181018290529082600181111561220c5761220c614457565b146122a35760405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000008152506113f3565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000081525092915050565b60001982036123aa576040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa158015612383573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a79190614269565b91505b6123b58382846128c2565b6123f75760405162461bcd60e51b815260206004820152601360248201527212d85b99195b0bdd1c985b9cd9995c91985a5b606a1b60448201526064016108a4565b826001600160a01b03167f59c79d79be0fadf59fe689b6952b7ebe90201a3a1f00d4a31982377890bc60468360405161243291815260200190565b60405180910390a2505050565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e982fb8d85856040518363ffffffff1660e01b81526004016124909291906143f3565b602060405180830381865afa1580156124ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d19190614269565b9050604881901c62ffffff166124e682612965565b01602582901c6303ffffff1602620f424002949350505050565b600061250b826121dd565b9050835b8381101561254a5760006125238483611756565b90508015612539576125378382600161297b565b505b506125438161449c565b905061250f565b5050505050565b600061255c83612a11565b610b0b8383612a54565b60018190556040518181527f26003f10937c9ed98d59e0d595a28bc7d35537a044aeaad037fedaab24d1799890602001611531565b8051604051631c04321560e01b81526000916001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001691631c043215916125ea91600401614561565b602060405180830381865afa158015612607573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061262b9190614269565b9050600061265961263b83612d28565b846060015161264a9190614489565b60ee84901c6101ff1690612d38565b905060005b85518110156113cd57600086828151811061267b5761267b61456f565b602090810291909101810151805181830151928801929092526040808201519088015291506126b6876126ae8184611756565b838988612d71565b5050806126c29061449c565b905061265e565b6040516001600160a01b03838116602483015260448201839052600091829182919087169063095ea7b360e01b906064015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161273991906145a9565b6000604051808303816000865af19150503d8060008114612776576040519150601f19603f3d011682016040523d82523d6000602084013e61277b565b606091505b50915091508180156127a55750805115806127a55750808060200190518101906127a591906143aa565b9695505050505050565b6040516001600160a01b03838116602483015260448201839052600091829182919087169063a9059cbb60e01b906064016126fb565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b1790529151600092839283929189169161284b91906145a9565b6000604051808303816000865af19150503d8060008114612888576040519150601f19603f3d011682016040523d82523d6000602084013e61288d565b606091505b50915091508180156128b75750805115806128b75750808060200190518101906128b791906143aa565b979650505050505050565b6000816000036128d457506001610b0b565b306001600160a01b0384160361295a576040516370a0823160e01b81526001600160a01b0384811660048301528391908616906370a0823190602401602060405180830381865afa15801561292d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129519190614269565b10159050610b0b565b611e538484846127af565b6000603f82901c6101ff165b6103e80292915050565b604051630dcf4b9760e31b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636e7a5cb8906129ce908790879087906004016145c5565b6020604051808303816000875af11580156129ed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e539190614269565b6000612a28612a236020840184613df7565b612e1a565b9050600080612a378385612e64565b915091506000612a478284613028565b905061254a838383613149565b600080612a696118233686900386018661446d565b9050612a73611e17565b15612d1e5760408051600280825260608201909252600091816020015b604080516080810182526000808252602080830182905292820181905260608201528252600019909201910181612a90579050509050612ad36020860186613df7565b81600081518110612ae657612ae661456f565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000000000000000000000000000000000000000000081600081518110612b3e57612b3e61456f565b6020026020010151606001906001600160a01b031690816001600160a01b0316815250508181600081518110612b7657612b7661456f565b60200260200101516020018181525050846060013581600081518110612b9e57612b9e61456f565b60200260200101516040018181525050846000016020016020810190612bc49190613df7565b81600181518110612bd757612bd761456f565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000000000000000000000000000000000000000000081600181518110612c2f57612c2f61456f565b6020026020010151606001906001600160a01b031690816001600160a01b0316815250508181600181518110612c6757612c6761456f565b60200260200101516020018181525050846060013581600181518110612c8f57612c8f61456f565b6020908102919091010151604001527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b8b5cc48826040518263ffffffff1660e01b8152600401612cea91906145e9565b600060405180830381600087803b158015612d0457600080fd5b505af1158015612d18573d6000803e3d6000fd5b50505050505b611e5384846131f7565b6000602182901c6101ff16612971565b600080612d44846132b7565b83029050640200000000810615612d5c576001612d5f565b60005b60ff16602082901c0191505092915050565b83600003612dd657604082015115612d9f57612d8c826132de565b509350612d9a858486613403565b61254a565b60408201819052612daf826132de565b506000604084018190528351919550612dca9190869061297b565b50612d9a858486613403565b8160400151600003612e105760408201819052612df38285613028565b506000604083018190528251612e0a91869061297b565b5061254a565b6113cd8285613028565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614612e5c5760006113f3565b600192915050565b6000612e6e613b0d565b6000612e7e85856060013561193f565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b8204811693830193909352600160581b900490911660608201529091506000612ed3876134ac565b90506000612ef78285856040015163ffffffff16866060015163ffffffff166134e8565b9050612f038282611756565b9550612f0e826121dd565b808652604051630129e86d60e21b81526000916001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916304a7a1b491612f60918b906004016143f3565b602060405180830381865afa158015612f7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fa19190614269565b9050612fbe60016001607f1b03602c83901c1660c08a0135614489565b6040870181905260016001607f1b031015612fe15760016001607f1b0360408701525b612fee8160401b60eb1d90565b602080880191909152600160c0880152845163ffffffff166080880152939093015162ffffff166060860152509396929550919350505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a84b08c88460a0015185600001518660200151876040015188606001518960800151896040518863ffffffff1660e01b815260040161309996959493929190614661565b6000604051808303818588803b1580156130b257600080fd5b505af1935050505080156130c4575060015b613131576130d0614698565b806308c379a00361312557506130e46146b3565b806130ef5750613127565b8360c0015181906131135760405162461bcd60e51b81526004016108a4919061473d565b5061311d81614770565b9150506113f3565b505b3d6000803e3d6000fd5b506c1bd999995c8bdd5c19185d1959609a1b92915050565b6c1bd999995c8bdd5c19185d1959609a1b8114806131865750807f6d67762f77726974654f666665722f64656e736974792f746f6f4c6f77000000145b1561319057505050565b8151606090208390604080517f4b616e64656c2f7570646174654f666665724661696c656400000000000000008152602081018590527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c391015b60405180910390a3505050565b600080600061320585613537565b91509150816000148061321f575061321d818361356c565b155b1561323d576b1bd999995c8bd99a5b1b195960a21b925050506113f3565b6040805160e081019091526132aa908061325c3689900389018961446d565b8152602081018490526040810185905260600160e088013560481c62ffffff16815260200160e088013560251c6303ffffff1681526000602082015260016040909101526060870135613028565b925061205c858585613595565b6000600782116132c8575060031690565b506004600382161760029190911c600119011b90565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f95902aa8460a00151856000015186602001518760400151886060015189608001516040518763ffffffff1660e01b815260040161334e959493929190614794565b60206040518083038185885af193505050508015613389575060408051601f3d908101601f1916820190925261338691810190614269565b60015b6133ea57613395614698565b806308c379a00361312557506133a96146b3565b806133b45750613127565b8360c0015181906133d85760405162461bcd60e51b81526004016108a4919061473d565b506133e281614770565b915050915091565b936c1bd999995c8bd8dc99585d1959609a1b9350915050565b600183600181111561341757613417614457565b0361344257600081815260046020908152604080832085905584835260029091529020819055613464565b6000818152600560209081526040808320859055848352600390915290208190555b82600181111561347657613476614457565b60408051848152602081018490527f4414bf83296b9500de34e173e9e5b7ca010ff6de3f093002103e680a3a1051279101612432565b600060028260018111156134c2576134c2614457565b6134cd906001614489565b6134d791906147c4565b60018111156113f3576113f3614457565b600060018560018111156134fe576134fe614457565b036135265761350d8385614489565b905081811061352157612120600183614500565b611e53565b828410611e535761137b8385614500565b60008061355860a084013560016001607f1b036080860135602c1c16614500565b9150608083013560401b60eb1d9050915091565b600080600061357a85613642565b90925090508061358a85846147e6565b901c95945050505050565b6b1bd999995c8bd99a5b1b195960a21b8114806135c157506c1bd999995c8bdd5c19185d1959609a1b81145b806135eb5750807f6d67762f77726974654f666665722f64656e736974792f746f6f4c6f77000000145b156135f557505050565b606083013561360c6118233686900386018661446d565b60408051858152602081018590527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c391016131ea565b60008061364e836136b4565b909250905060eb83901b60007ed89e8c075c4155dd3213326cbbcf86fd1f63f5c205dd2ad2cf44f9349b39e180830782139083050390607e19828501019081131561369c5793841c936136a6565b8060000385901b94505b81607f039350505050915091565b60008060008084126136c657836136cf565b6136cf846147fd565b9050620d89e88111156137245760405162461bcd60e51b815260206004820152601760248201527f6d67762f6162735469636b2f6f75744f66426f756e647300000000000000000060448201526064016108a4565b60006001821615613747576ffff97272373d413259a46990580e2139935061374f565b600160801b93505b6002821615613779576080613774856ffff2e50f5f656932ef12357cf3c7fdcb6147e6565b901c93505b60048216156137a357608061379e856fffe5caca7e10e4e61c3624eaa0941ccf6147e6565b901c93505b60088216156137cd5760806137c8856fffcb9843d60f6159c9db58835c9266436147e6565b901c93505b60108216156137f75760806137f2856fff973b41fa98c081472e6896dfb254bf6147e6565b901c93505b602082161561382157608061381c856fff2ea16466c96a3843ec78b326b528606147e6565b901c93505b604082161561384b576080613846856ffe5dee046a99a2a811c461f1969c30526147e6565b901c93505b6080821615613875576080613870856ffcbe86c7900a88aedcffc83b479aa3a36147e6565b901c93505b6101008216156138a057608061389b856ff987a7253ac413176f2b074cf7815e536147e6565b901c93505b6102008216156138cb5760806138c6856ff3392b0822b70005940c7a398e4b70f26147e6565b901c93505b6104008216156138f65760806138f1856fe7159475a2c29b7443b29c7fa6e889d86147e6565b901c93505b61080082161561392157608061391c856fd097f3bdfd2022b8845ad8f792aa58256147e6565b901c93505b61100082161561394c576080613947856fa9f746462d870fdf8a65dc1f90e061e46147e6565b901c93505b612000821615613984576080613972856fe1b0d342ada5437121767bec575e65ed6147e6565b901c9350613981600182614819565b90505b6140008216156139bc5760806139aa856fc6f84d7e5f423f66048c541550bf3e966147e6565b901c93506139b9600282614819565b90505b6180008216156139f45760806139e2856f9aa508b5b7a84e1c677de54f3e99bc8f6147e6565b901c93506139f1600482614819565b90505b62010000821615613a2d576080613a1b856fbad5f1bdb70232cd33865244bdcc089c6147e6565b901c9350613a2a600982614819565b90505b62020000821615613a66576080613a54856f885b9613d7e87aa498106fb7fa5edd376147e6565b901c9350613a63601282614819565b90505b62040000821615613a9f576080613a8d856f9142e0723efb884889d1f447715afacd6147e6565b901c9350613a9c602582614819565b90505b62080000821615613ad8576080613ac6856fa4d9a773d61316918f140bd96e8e68146147e6565b901c9350613ad5604b82614819565b90505b6000851315613af957600184856000030401935080613af6906147fd565b90505b613b04816080614819565b92505050915091565b604080516101408101909152600060e0820181815261010083018290526101208301919091528190815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b634e487b7160e01b600052604160045260246000fd5b6060810181811067ffffffffffffffff82111715613b9d57613b9d613b67565b60405250565b6040810181811067ffffffffffffffff82111715613b9d57613b9d613b67565b601f8201601f1916810167ffffffffffffffff81118282101715613be957613be9613b67565b6040525050565b600067ffffffffffffffff821115613c0a57613c0a613b67565b5060051b60200190565b600082601f830112613c2557600080fd5b81356020613c3282613bf0565b60408051613c408382613bc3565b84815260609485028701840194848201935088861115613c5f57600080fd5b8488015b86811015613ca75781818b031215613c7b5760008081fd5b8351613c8681613b7d565b81358152868201358782015284820135858201528552938501938101613c63565b509098975050505050505050565b600060408284031215613cc757600080fd5b604051613cd381613ba3565b809150823567ffffffffffffffff80821115613cee57600080fd5b613cfa86838701613c14565b83526020850135915080821115613d1057600080fd5b50613d1d85828601613c14565b6020830152505092915050565b600060808284031215610c4e57600080fd5b60008060008060e08587031215613d5257600080fd5b843567ffffffffffffffff811115613d6957600080fd5b613d7587828801613cb5565b945050613d858660208701613d2a565b939693955050505060a08201359160c0013590565b600060208284031215613dac57600080fd5b5035919050565b803560028110613dc257600080fd5b919050565b600060208284031215613dd957600080fd5b610b0b82613db3565b6001600160a01b0381168114610ba157600080fd5b600060208284031215613e0957600080fd5b8135610b0b81613de2565b60006101408284031215610c4e57600080fd5b60006101408284031215613e3a57600080fd5b610b0b8383613e14565b60008060008060008060008060006101208a8c031215613e6357600080fd5b505087359960208901359950604089013598606081013598506080810135975060a0810135965060c0810135955060e08101359450610100013592509050565b600081518084526020808501945080840160005b83811015613ee95781518051885283810151848901526040908101519088015260609096019590820190600101613eb7565b509495945050505050565b602081526000825160406020840152613f106060840182613ea3565b90506020840151601f1984830301604085015261137b8282613ea3565b60008060008060008060c08789031215613f4657600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b60008060408385031215613f8357600080fd5b50508035926020909101359150565b60008060408385031215613fa557600080fd5b823591506020830135613fb781613de2565b809150509250929050565b60008060408385031215613fd557600080fd5b613fde83613db3565b946020939093013593505050565b60008060008060008060c0878903121561400557600080fd5b863595506020870135945060408701359350606087013592506080870135915060a087013561403381613de2565b809150509295509295509295565b60008060006060848603121561405657600080fd5b8335925060208401359150604084013561406f81613de2565b809150509250925092565b60006060828403121561408c57600080fd5b60405161409881613b7d565b80915082356140a681613de2565b815260208301356140b681613de2565b6020820152604092830135920191909152919050565b600080608083850312156140df57600080fd5b6140e9848461407a565b946060939093013593505050565b600060408284031215610c4e57600080fd5b60006020828403121561411b57600080fd5b813567ffffffffffffffff81111561413257600080fd5b611e53848285016140f7565b6000806000806000806000806000806101a08b8d03121561415e57600080fd5b8a35995060208b0135985060408b0135975060608b0135965060808b0135955060a08b0135945060c08b013593506141998c60e08d01613d2a565b92506101608b013591506101808b013590509295989b9194979a5092959850565b60008061018083850312156141ce57600080fd5b6141d88484613e14565b91506141e88461014085016140f7565b90509250929050565b60008060006060848603121561420657600080fd5b833561421181613de2565b9250602084013561422181613de2565b929592945050506040919091013590565b60208082526018908201527f416363657373436f6e74726f6c6c65642f496e76616c69640000000000000000604082015260600190565b60006020828403121561427b57600080fd5b5051919050565b600082601f83011261429357600080fd5b815160206142a082613bf0565b604080516142ae8382613bc3565b848152606094850287018401948482019350888611156142cd57600080fd5b8488015b86811015613ca75781818b0312156142e95760008081fd5b83516142f481613b7d565b815181528682015187820152848201518582015285529385019381016142d1565b60006020828403121561432757600080fd5b815167ffffffffffffffff8082111561433f57600080fd5b908301906040828603121561435357600080fd5b60405161435f81613ba3565b82518281111561436e57600080fd5b61437a87828601614282565b82525060208301518281111561438f57600080fd5b61439b87828601614282565b60208301525095945050505050565b6000602082840312156143bc57600080fd5b81518015158114610b0b57600080fd5b80516001600160a01b03908116835260208083015190911690830152604090810151910152565b6080810161440182856143cc565b8260608301529392505050565b634e487b7160e01b600052601160045260246000fd5b81810360008312801583831316838312821617156144445761444461440e565b5092915050565b60006113f33683613cb5565b634e487b7160e01b600052602160045260246000fd5b60006060828403121561447f57600080fd5b610b0b838361407a565b808201808211156113f3576113f361440e565b6000600182016144ae576144ae61440e565b5060010190565b6000602082840312156144c757600080fd5b813563ffffffff81168114610b0b57600080fd5b6000602082840312156144ed57600080fd5b813562ffffff81168114610b0b57600080fd5b818103818111156113f3576113f361440e565b60c0810161454b828680516001600160a01b039081168352602080830151908401526040808301519084015260609182015116910152565b83608083015282151560a0830152949350505050565b606081016113f382846143cc565b634e487b7160e01b600052603260045260246000fd5b60005b838110156145a0578181015183820152602001614588565b50506000910152565b600082516145bb818460208701614585565b9190910192915050565b60a081016145d382866143cc565b8360608301528215156080830152949350505050565b6020808252825182820181905260009190848201906040850190845b818110156146555761464283855180516001600160a01b039081168352602080830151908401526040808301519084015260609182015116910152565b9284019260809290920191600101614605565b50909695505050505050565b610100810161467082896143cc565b6060820196909652608081019490945260a084019290925260c083015260e090910152919050565b600060033d1115610d1d5760046000803e5060005160e01c90565b600060443d10156146c15790565b6040516003193d81016004833e81513d67ffffffffffffffff81602484011181841117156146f157505050505090565b82850191508151818111156147095750505050505090565b843d87010160208285010111156147235750505050505090565b61473260208286010187613bc3565b509095945050505050565b602081526000825180602084015261475c816040850160208701614585565b601f01601f19169190910160400192915050565b80516020808301519190811015610c4e5760001960209190910360031b1b16919050565b60e081016147a282886143cc565b8560608301528460808301528360a08301528260c08301529695505050505050565b6000826147e157634e487b7160e01b600052601260045260246000fd5b500690565b80820281158282048414176113f3576113f361440e565b6000600160ff1b82016148125761481261440e565b5060000390565b808201828112600083128015821682158216171561205c5761205c61440e56fea2646970667358221220efa8643fc61047e62d8ea1d90d102187bb65da448067ade3e120dfb6b893228d64736f6c63430008140033000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c000000000000000000000000430000000000000000000000000000000000000400000000000000000000000043000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000004300000000000000000000000000000000000002000000000000000000000000d70b96bcc12d45f347b9b70899dcbb3dfe13384f0000000000000000000000002536fe9ab3f511540f2f9e2ec2a805005c3dd800000000000000000000000000441f6a3d415708f89e4adbb6b995371554aa909e
Deployed Bytecode
0x6080604052600436106102345760003560e01c806399fa5e2d1161012e578063cff0ab96116100ab578063ea0f394d1161006f578063ea0f394d146107b5578063ec342ad0146107d5578063f851a44014610809578063f887ea4014610827578063fcaa7e2e1461085a57600080fd5b8063cff0ab961461068d578063d2e498fe14610701578063e1f21c6714610721578063e4b643e314610741578063e910d6731461078157600080fd5b8063a2e241af116100f2578063a2e241af146105fa578063ace679021461061a578063b9c9cec21461063a578063bfc353f91461064d578063c7e1bb441461066d57600080fd5b806399fa5e2d146105325780639c579839146105665780639ee8a91c1461059a578063a224b5e9146105ba578063a24f2b2d146105da57600080fd5b806346ca626b116101bc5780637692c328116101805780637692c3281461044257806376a820e514610462578063790532a1146104a65780637b0b5fca146104c657806398ed53401461051257600080fd5b806346ca626b1461039b5780634f605c5b146103cf57806361638ed5146103e2578063704b6c02146104025780637144df241461042257600080fd5b80631c5a9d9c116102035780631c5a9d9c146102be5780632380fafd146102de57806334bd8931146102fe57806334be9cb61461031e5780633fce15c91461036e57600080fd5b8063100cd98d146102405780631450acd21461025557806314ee02bd1461027557806318acf82f1461029e57600080fd5b3661023b57005b600080fd5b61025361024e366004613d3c565b61087a565b005b34801561026157600080fd5b50610253610270366004613d9a565b610962565b34801561028157600080fd5b5061028b60075481565b6040519081526020015b60405180910390f35b3480156102aa57600080fd5b5061028b6102b9366004613dc7565b610a94565b3480156102ca57600080fd5b506102536102d9366004613df7565b610b12565b3480156102ea57600080fd5b5061028b6102f9366004613e27565b610ba4565b34801561030a57600080fd5b50610253610319366004613d9a565b610c54565b34801561032a57600080fd5b50604080516060808201835260008083526020808401828152938501828152855192835293516001600160a01b031690820152915115159282019290925201610295565b34801561037a57600080fd5b5061038e610389366004613e44565b610d20565b6040516102959190613ef4565b3480156103a757600080fd5b5061028b7f000000000000000000000000000000000000000000000000000000000000000181565b6102536103dd366004613f2d565b610df2565b3480156103ee57600080fd5b506102536103fd366004613f70565b610ead565b34801561040e57600080fd5b5061025361041d366004613df7565b611067565b34801561042e57600080fd5b5061025361043d366004613f92565b61109a565b34801561044e57600080fd5b5061028b61045d366004613fc2565b6112cf565b34801561046e57600080fd5b506104967f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610295565b3480156104b257600080fd5b506102536104c1366004613fec565b611384565b3480156104d257600080fd5b506104fa7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610295565b34801561051e57600080fd5b5061028b61052d366004613dc7565b6113d5565b34801561053e57600080fd5b506104fa7f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c81565b34801561057257600080fd5b506104fa7f000000000000000000000000430000000000000000000000000000000000000381565b3480156105a657600080fd5b506102536105b5366004614041565b6113f9565b3480156105c657600080fd5b506102536105d5366004613d9a565b611479565b3480156105e657600080fd5b5061028b6105f53660046140cc565b61153c565b34801561060657600080fd5b50610253610615366004613f70565b611548565b34801561062657600080fd5b50610253610635366004614109565b6115e0565b61025361064836600461413e565b61167b565b34801561065957600080fd5b5061028b610668366004613fc2565b611756565b34801561067957600080fd5b506102536106883660046141ba565b61179a565b34801561069957600080fd5b506006546106cc9063ffffffff8082169162ffffff600160201b82041691600160381b8204811691600160581b90041684565b6040805163ffffffff958616815262ffffff909416602085015291841691830191909152919091166060820152608001610295565b34801561070d57600080fd5b5061028b61071c366004613dc7565b61186c565b34801561072d57600080fd5b5061049661073c3660046141f1565b6118b3565b34801561074d57600080fd5b506104fa61075c366004613df7565b507f000000000000000000000000000000000000000000000000000000000000000090565b34801561078d57600080fd5b506104fa7f0000000000000000000000004e44d45e57021c3ce22433c748669b6ca03f2d5c81565b3480156107c157600080fd5b5061028b6107d0366004613fc2565b61193f565b3480156107e157600080fd5b506104fa7f000000000000000000000000430000000000000000000000000000000000000481565b34801561081557600080fd5b506000546001600160a01b03166104fa565b34801561083357600080fd5b507f00000000000000000000000000000000000000000000000000000000000000006104fa565b34801561086657600080fd5b50610253610875366004613d9a565b611983565b6000546001600160a01b031633146108ad5760405162461bcd60e51b81526004016108a490614232565b60405180910390fd5b3415610928577f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031663b60d4288346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561090e57600080fd5b505af1158015610922573d6000803e3d6000fd5b50505050505b61093183611a3e565b61093b8282610ead565b60065461095c90859062ffffff600160201b8204169063ffffffff16611c53565b50505050565b6000546001600160a01b0316331461098c5760405162461bcd60e51b81526004016108a490614232565b80806109d25760405162461bcd60e51b81526020600482015260156024820152744b616e64656c2f7374657053697a65546f6f4c6f7760581b60448201526064016108a4565b818163ffffffff161480156109f55750600654600160581b900463ffffffff1682105b610a3a5760405162461bcd60e51b8152602060048201526016602482015275096c2dcc8cad85ee6e8cae0a6d2f4caa8dede90d2ced60531b60448201526064016108a4565b600680546affffffff000000000000001916600160381b63ffffffff8416021790556040518281527f0408193baae9f2730f7be76d9be93983ed2dd45af2305c085920b8f00c25bbcd906020015b60405180910390a15050565b600080610aa083611d36565b6040516370a0823160e01b81523060048201529091506001600160a01b038216906370a0823190602401602060405180830381865afa158015610ae7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0b9190614269565b9392505050565b610b1b81611d9e565b610b23611e17565b15610ba157610b55817f0000000000000000000000000000000000000000000000000000000000000000600019611e46565b610ba15760405162461bcd60e51b815260206004820152601d60248201527f4469726563742f526f7574657241637469766174696f6e4661696c656400000060448201526064016108a4565b50565b60007f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c336001600160a01b03821614610bef5760405162461bcd60e51b81526004016108a490614232565b60009150610c018360a0013584611e5b565b15610c4e5760405162461bcd60e51b815260206004820152601860248201527f6d67764f666665722f61626f72742f6765744661696c6564000000000000000060448201526064016108a4565b50919050565b6000546001600160a01b03163314610c7e5760405162461bcd60e51b81526004016108a490614232565b8062ffffff81168114610cca5760405162461bcd60e51b8152602060048201526014602482015273096c2dcc8cad85ecec2e6e4cae2a8dede90d2ced60631b60448201526064016108a4565b6006805466ffffff000000001916600160201b62ffffff8416908102919091179091556040519081527fafef3ad374c0b972e3c793be825735801fa05cc4c67157d98d9a111b4027988d90602001610a88565b90565b60408051808201825260608082526020820152905163fbbd4a6560e01b8152600481018b9052602481018a905260448101899052606481018890526084810187905260a4810186905260c4810185905260e481018490526101048101839052730ea85f9e19763eec0e376f988fe9a19c9328e3fa9063fbbd4a659061012401600060405180830381865af4158015610dbc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610de49190810190614315565b9a9950505050505050505050565b6000546001600160a01b03163314610e1c5760405162461bcd60e51b81526004016108a490614232565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b82048116938301849052600160581b90910416606082018190526007549192600092610e83928b928b928b9290918b918b918b9190610d20565b9050610ea381836020015162ffffff16846000015163ffffffff16611c53565b5050505050505050565b610ed97f0000000000000000000000004300000000000000000000000000000000000004333085612064565b610f255760405162461bcd60e51b815260206004820152601760248201527f4b616e64656c2f626173655472616e736665724661696c00000000000000000060448201526064016108a4565b7f00000000000000000000000043000000000000000000000000000000000000046001600160a01b03167f1bbf55d483639f8103dc4e035af71a4fbdb16c80be740fa3eef81198acefa09483604051610f8091815260200190565b60405180910390a2610fb47f0000000000000000000000004300000000000000000000000000000000000003333084612064565b6110005760405162461bcd60e51b815260206004820152601860248201527f4b616e64656c2f71756f74655472616e736665724661696c000000000000000060448201526064016108a4565b7f00000000000000000000000043000000000000000000000000000000000000036001600160a01b03167f1bbf55d483639f8103dc4e035af71a4fbdb16c80be740fa3eef81198acefa0948260405161105b91815260200190565b60405180910390a25050565b6000546001600160a01b031633146110915760405162461bcd60e51b81526004016108a490614232565b610ba181612133565b6000546001600160a01b031633146110c45760405162461bcd60e51b81526004016108a490614232565b6000198203611158576040516370a0823160e01b81523060048201527f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b0316906370a0823190602401602060405180830381865afa158015611131573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111559190614269565b91505b604051632e1a7d4d60e01b8152600481018390527f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031690632e1a7d4d906024016020604051808303816000875af11580156111bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e391906143aa565b6112275760405162461bcd60e51b81526020600482015260156024820152741b59dd93d999995c8bddda5d1a191c985dd1985a5b605a1b60448201526064016108a4565b6000816001600160a01b03168360405160006040518083038185875af1925050503d8060008114611274576040519150601f19603f3d011682016040523d82523d6000602084013e611279565b606091505b50509050806112ca5760405162461bcd60e51b815260206004820152601860248201527f6d67764f666665722f7765695472616e736665724661696c000000000000000060448201526064016108a4565b505050565b6000806112dc8484611756565b905060006112e9856121dd565b604051630129e86d60e21b81529091506001600160a01b037f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c16906304a7a1b49061133a90849086906004016143f3565b602060405180830381865afa158015611357573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137b9190614269565b95945050505050565b6000546001600160a01b031633146113ae5760405162461bcd60e51b81526004016108a490614232565b6113b88686611548565b6113c38484836113f9565b6113cd828261109a565b505050505050565b60006113e08261186c565b6113e983610a94565b6113f39190614424565b92915050565b6000546001600160a01b031633146114235760405162461bcd60e51b81526004016108a490614232565b61144e7f00000000000000000000000043000000000000000000000000000000000000048483612336565b6112ca7f00000000000000000000000043000000000000000000000000000000000000038383612336565b6000546001600160a01b031633146114a35760405162461bcd60e51b81526004016108a490614232565b808162ffffff16146114f75760405162461bcd60e51b815260206004820152601860248201527f4b616e64656c2f7469636b4f6666736574546f6f48696768000000000000000060448201526064016108a4565b8060075414610ba15760078190556040518181527f286da08673f0eb4b3843f2824fb8e3e412534a62f6094fdc8b4008cfeba4ba66906020015b60405180910390a150565b6000610b0b838361243f565b6000546001600160a01b031633146115725760405162461bcd60e51b81526004016108a490614232565b6040517f97714c1c48a0b9a1a347710cb6a62f056f5a811d4006655e3b41959e1e72a40990600090a16115a782826001612500565b6115b382826000612500565b6040517fa9bc12cd7db30bdfe60fece3ec52cfa7c8d60e396e2ea5df439a7d458f05f9b690600090a15050565b6000546001600160a01b0316331461160a5760405162461bcd60e51b81526004016108a490614232565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b8204811693830193909352600160581b9004909116606082015261167761165d8361444b565b826020015162ffffff16836000015163ffffffff16611c53565b5050565b6000546001600160a01b031633146116a55760405162461bcd60e51b81526004016108a490614232565b3415611720577f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031663b60d4288346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561170657600080fd5b505af115801561171a573d6000803e3d6000fd5b50505050505b61172983611a3e565b61173287611479565b61173c8282610ead565b61174a8a8a8a898989610df2565b50505050505050505050565b6000600183600181111561176c5761176c614457565b1461178557600082815260036020526040902054610b0b565b50600090815260026020526040902054919050565b7f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c336001600160a01b038216146117e35760405162461bcd60e51b81526004016108a490614232565b81602001356f6d67762f74726164655375636365737360801b0361180c5761095c838335612551565b606083013561182a6118233686900386018661446d565b6060902090565b6040805185358152602080870135908201527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c3910160405180910390a3505050565b6000805b600154811015610c4e57600061188684836112cf565b905061189f60016001607f1b03602c83901c1684614489565b925050806118ac9061449c565b9050611870565b600080546001600160a01b031633146118de5760405162461bcd60e51b81526004016108a490614232565b6118e9848484611e46565b6119355760405162461bcd60e51b815260206004820152601760248201527f6d67764f666665722f617070726f76652f6661696c656400000000000000000060448201526064016108a4565b5060019392505050565b6000600183600181111561195557611955614457565b1461196e57600082815260056020526040902054610b0b565b50600090815260046020526040902054919050565b6000546001600160a01b031633146119ad5760405162461bcd60e51b81526004016108a490614232565b630400000081106119f95760405162461bcd60e51b8152602060048201526016602482015275096c2dcc8cad85ecec2e6e0e4d2c6caa8dede90d2ced60531b60448201526064016108a4565b6006805463ffffffff191663ffffffff83161790556040518181527fdbebd814ae648f654dcc50c734aa76e55a32e96b7d85303a08e2ddf11874a0dd90602001611531565b604080516080808201835260065463ffffffff808216845262ffffff600160201b8304166020850152600160381b8204811694840194909452600160581b90049092166060808301919091529091611a9b919084019084016144b5565b63ffffffff16816060015163ffffffff1614611b50576000611ac360808401606085016144b5565b905060028163ffffffff161015611b1c5760405162461bcd60e51b815260206004820152601960248201527f4b616e64656c2f696e76616c69645072696365506f696e74730000000000000060448201526064016108a4565b611b2b8163ffffffff16612566565b6006805463ffffffff909216600160581b0263ffffffff60581b199092169190911790555b611b6060608301604084016144b5565b63ffffffff16816040015163ffffffff1614611b9457611b94611b8960608401604085016144b5565b63ffffffff16610962565b611ba160208301836144b5565b63ffffffff1615801590611bce5750805163ffffffff16611bc560208401846144b5565b63ffffffff1614155b15611bee57611bee611be360208401846144b5565b63ffffffff16611983565b611bfe60408301602084016144db565b62ffffff1615801590611c315750806020015162ffffff16826020016020810190611c2991906144db565b62ffffff1614155b1561167757611677611c4960408401602085016144db565b62ffffff16610c54565b6040517faab0a16d4cef87072f3977d7f1c066be401e0e6486526674f5f6172d42703db190600090a1611c84613b0d565b6060810183905260808101829052611c9c60006121dd565b81526020840151611caf9060008361259b565b80516040805160608082018352600080835260208084018290529284015282519081018352818401516001600160a01b03908116825284511691810191909152918101519082015281528351611d079060018361259b565b6040517fac65490b93de6b3189ca1e1653852249eb8680e816c258cff6ccf73d8501d3d090600090a150505050565b60006001826001811115611d4c57611d4c614457565b14611d77577f00000000000000000000000043000000000000000000000000000000000000036113f3565b7f000000000000000000000000430000000000000000000000000000000000000492915050565b611dcb817f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c600019611e46565b610ba15760405162461bcd60e51b815260206004820152601960248201527f4d67764f666665722f41637469766174696f6e4661696c65640000000000000060448201526064016108a4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316151590565b6000611e538484846126c9565b949350505050565b600080611e6b6020840184613df7565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed59190614269565b9050600084821015611ef057611eeb8286614500565b611ef3565b60005b9050611efd611e17565b611f0a5791506113f39050565b60408051608081019091526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063504db8e69080611f5760208a018a613df7565b6001600160a01b03168152602001611f77611823368b90038b018b61446d565b8152602001886060013581526020017f0000000000000000000000004e44d45e57021c3ce22433c748669b6ca03f2d5c6001600160a01b0316815250847f00000000000000000000000000000000000000000000000000000000000000006040518463ffffffff1660e01b8152600401611ff393929190614513565b6020604051808303816000875af1158015612012573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120369190614269565b90508181101561204f5761204a8183614500565b612052565b60005b93505050506113f3565b505092915050565b60008160000361207657506001611e53565b826001600160a01b0316846001600160a01b031603612105576040516370a0823160e01b81526001600160a01b0385811660048301528391908716906370a0823190602401602060405180830381865afa1580156120d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120fc9190614269565b10159050611e53565b306001600160a01b03851603612127576121208584846127af565b9050611e53565b61137b858585856127e5565b6001600160a01b0381166121895760405162461bcd60e51b815260206004820152601860248201527f416363657373436f6e74726f6c6c65642f307841646d696e000000000000000060448201526064016108a4565b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a19060200160405180910390a150565b604080516060810182526000808252602082018190529181018290529082600181111561220c5761220c614457565b146122a35760405180606001604052807f00000000000000000000000043000000000000000000000000000000000000046001600160a01b031681526020017f00000000000000000000000043000000000000000000000000000000000000036001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000018152506113f3565b60405180606001604052807f00000000000000000000000043000000000000000000000000000000000000036001600160a01b031681526020017f00000000000000000000000043000000000000000000000000000000000000046001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000181525092915050565b60001982036123aa576040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa158015612383573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a79190614269565b91505b6123b58382846128c2565b6123f75760405162461bcd60e51b815260206004820152601360248201527212d85b99195b0bdd1c985b9cd9995c91985a5b606a1b60448201526064016108a4565b826001600160a01b03167f59c79d79be0fadf59fe689b6952b7ebe90201a3a1f00d4a31982377890bc60468360405161243291815260200190565b60405180910390a2505050565b6000807f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031663e982fb8d85856040518363ffffffff1660e01b81526004016124909291906143f3565b602060405180830381865afa1580156124ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d19190614269565b9050604881901c62ffffff166124e682612965565b01602582901c6303ffffff1602620f424002949350505050565b600061250b826121dd565b9050835b8381101561254a5760006125238483611756565b90508015612539576125378382600161297b565b505b506125438161449c565b905061250f565b5050505050565b600061255c83612a11565b610b0b8383612a54565b60018190556040518181527f26003f10937c9ed98d59e0d595a28bc7d35537a044aeaad037fedaab24d1799890602001611531565b8051604051631c04321560e01b81526000916001600160a01b037f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c1691631c043215916125ea91600401614561565b602060405180830381865afa158015612607573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061262b9190614269565b9050600061265961263b83612d28565b846060015161264a9190614489565b60ee84901c6101ff1690612d38565b905060005b85518110156113cd57600086828151811061267b5761267b61456f565b602090810291909101810151805181830151928801929092526040808201519088015291506126b6876126ae8184611756565b838988612d71565b5050806126c29061449c565b905061265e565b6040516001600160a01b03838116602483015260448201839052600091829182919087169063095ea7b360e01b906064015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161273991906145a9565b6000604051808303816000865af19150503d8060008114612776576040519150601f19603f3d011682016040523d82523d6000602084013e61277b565b606091505b50915091508180156127a55750805115806127a55750808060200190518101906127a591906143aa565b9695505050505050565b6040516001600160a01b03838116602483015260448201839052600091829182919087169063a9059cbb60e01b906064016126fb565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b1790529151600092839283929189169161284b91906145a9565b6000604051808303816000865af19150503d8060008114612888576040519150601f19603f3d011682016040523d82523d6000602084013e61288d565b606091505b50915091508180156128b75750805115806128b75750808060200190518101906128b791906143aa565b979650505050505050565b6000816000036128d457506001610b0b565b306001600160a01b0384160361295a576040516370a0823160e01b81526001600160a01b0384811660048301528391908616906370a0823190602401602060405180830381865afa15801561292d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129519190614269565b10159050610b0b565b611e538484846127af565b6000603f82901c6101ff165b6103e80292915050565b604051630dcf4b9760e31b81526000906001600160a01b037f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c1690636e7a5cb8906129ce908790879087906004016145c5565b6020604051808303816000875af11580156129ed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e539190614269565b6000612a28612a236020840184613df7565b612e1a565b9050600080612a378385612e64565b915091506000612a478284613028565b905061254a838383613149565b600080612a696118233686900386018661446d565b9050612a73611e17565b15612d1e5760408051600280825260608201909252600091816020015b604080516080810182526000808252602080830182905292820181905260608201528252600019909201910181612a90579050509050612ad36020860186613df7565b81600081518110612ae657612ae661456f565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000004e44d45e57021c3ce22433c748669b6ca03f2d5c81600081518110612b3e57612b3e61456f565b6020026020010151606001906001600160a01b031690816001600160a01b0316815250508181600081518110612b7657612b7661456f565b60200260200101516020018181525050846060013581600081518110612b9e57612b9e61456f565b60200260200101516040018181525050846000016020016020810190612bc49190613df7565b81600181518110612bd757612bd761456f565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000004e44d45e57021c3ce22433c748669b6ca03f2d5c81600181518110612c2f57612c2f61456f565b6020026020010151606001906001600160a01b031690816001600160a01b0316815250508181600181518110612c6757612c6761456f565b60200260200101516020018181525050846060013581600181518110612c8f57612c8f61456f565b6020908102919091010151604001527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b8b5cc48826040518263ffffffff1660e01b8152600401612cea91906145e9565b600060405180830381600087803b158015612d0457600080fd5b505af1158015612d18573d6000803e3d6000fd5b50505050505b611e5384846131f7565b6000602182901c6101ff16612971565b600080612d44846132b7565b83029050640200000000810615612d5c576001612d5f565b60005b60ff16602082901c0191505092915050565b83600003612dd657604082015115612d9f57612d8c826132de565b509350612d9a858486613403565b61254a565b60408201819052612daf826132de565b506000604084018190528351919550612dca9190869061297b565b50612d9a858486613403565b8160400151600003612e105760408201819052612df38285613028565b506000604083018190528251612e0a91869061297b565b5061254a565b6113cd8285613028565b60007f00000000000000000000000043000000000000000000000000000000000000046001600160a01b0316826001600160a01b031614612e5c5760006113f3565b600192915050565b6000612e6e613b0d565b6000612e7e85856060013561193f565b6040805160808101825260065463ffffffff808216835262ffffff600160201b8304166020840152600160381b8204811693830193909352600160581b900490911660608201529091506000612ed3876134ac565b90506000612ef78285856040015163ffffffff16866060015163ffffffff166134e8565b9050612f038282611756565b9550612f0e826121dd565b808652604051630129e86d60e21b81526000916001600160a01b037f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c16916304a7a1b491612f60918b906004016143f3565b602060405180830381865afa158015612f7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fa19190614269565b9050612fbe60016001607f1b03602c83901c1660c08a0135614489565b6040870181905260016001607f1b031015612fe15760016001607f1b0360408701525b612fee8160401b60eb1d90565b602080880191909152600160c0880152845163ffffffff166080880152939093015162ffffff166060860152509396929550919350505050565b60007f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031663a84b08c88460a0015185600001518660200151876040015188606001518960800151896040518863ffffffff1660e01b815260040161309996959493929190614661565b6000604051808303818588803b1580156130b257600080fd5b505af1935050505080156130c4575060015b613131576130d0614698565b806308c379a00361312557506130e46146b3565b806130ef5750613127565b8360c0015181906131135760405162461bcd60e51b81526004016108a4919061473d565b5061311d81614770565b9150506113f3565b505b3d6000803e3d6000fd5b506c1bd999995c8bdd5c19185d1959609a1b92915050565b6c1bd999995c8bdd5c19185d1959609a1b8114806131865750807f6d67762f77726974654f666665722f64656e736974792f746f6f4c6f77000000145b1561319057505050565b8151606090208390604080517f4b616e64656c2f7570646174654f666665724661696c656400000000000000008152602081018590527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c391015b60405180910390a3505050565b600080600061320585613537565b91509150816000148061321f575061321d818361356c565b155b1561323d576b1bd999995c8bd99a5b1b195960a21b925050506113f3565b6040805160e081019091526132aa908061325c3689900389018961446d565b8152602081018490526040810185905260600160e088013560481c62ffffff16815260200160e088013560251c6303ffffff1681526000602082015260016040909101526060870135613028565b925061205c858585613595565b6000600782116132c8575060031690565b506004600382161760029190911c600119011b90565b6000807f000000000000000000000000b1a49c54192ea59b233200ea38ab56650dfb448c6001600160a01b031663f95902aa8460a00151856000015186602001518760400151886060015189608001516040518763ffffffff1660e01b815260040161334e959493929190614794565b60206040518083038185885af193505050508015613389575060408051601f3d908101601f1916820190925261338691810190614269565b60015b6133ea57613395614698565b806308c379a00361312557506133a96146b3565b806133b45750613127565b8360c0015181906133d85760405162461bcd60e51b81526004016108a4919061473d565b506133e281614770565b915050915091565b936c1bd999995c8bd8dc99585d1959609a1b9350915050565b600183600181111561341757613417614457565b0361344257600081815260046020908152604080832085905584835260029091529020819055613464565b6000818152600560209081526040808320859055848352600390915290208190555b82600181111561347657613476614457565b60408051848152602081018490527f4414bf83296b9500de34e173e9e5b7ca010ff6de3f093002103e680a3a1051279101612432565b600060028260018111156134c2576134c2614457565b6134cd906001614489565b6134d791906147c4565b60018111156113f3576113f3614457565b600060018560018111156134fe576134fe614457565b036135265761350d8385614489565b905081811061352157612120600183614500565b611e53565b828410611e535761137b8385614500565b60008061355860a084013560016001607f1b036080860135602c1c16614500565b9150608083013560401b60eb1d9050915091565b600080600061357a85613642565b90925090508061358a85846147e6565b901c95945050505050565b6b1bd999995c8bd99a5b1b195960a21b8114806135c157506c1bd999995c8bdd5c19185d1959609a1b81145b806135eb5750807f6d67762f77726974654f666665722f64656e736974792f746f6f4c6f77000000145b156135f557505050565b606083013561360c6118233686900386018661446d565b60408051858152602081018590527f45b7a2e43f35c7d127ad18416b3d34235d187b2060d4050bb82bb11de272a7c391016131ea565b60008061364e836136b4565b909250905060eb83901b60007ed89e8c075c4155dd3213326cbbcf86fd1f63f5c205dd2ad2cf44f9349b39e180830782139083050390607e19828501019081131561369c5793841c936136a6565b8060000385901b94505b81607f039350505050915091565b60008060008084126136c657836136cf565b6136cf846147fd565b9050620d89e88111156137245760405162461bcd60e51b815260206004820152601760248201527f6d67762f6162735469636b2f6f75744f66426f756e647300000000000000000060448201526064016108a4565b60006001821615613747576ffff97272373d413259a46990580e2139935061374f565b600160801b93505b6002821615613779576080613774856ffff2e50f5f656932ef12357cf3c7fdcb6147e6565b901c93505b60048216156137a357608061379e856fffe5caca7e10e4e61c3624eaa0941ccf6147e6565b901c93505b60088216156137cd5760806137c8856fffcb9843d60f6159c9db58835c9266436147e6565b901c93505b60108216156137f75760806137f2856fff973b41fa98c081472e6896dfb254bf6147e6565b901c93505b602082161561382157608061381c856fff2ea16466c96a3843ec78b326b528606147e6565b901c93505b604082161561384b576080613846856ffe5dee046a99a2a811c461f1969c30526147e6565b901c93505b6080821615613875576080613870856ffcbe86c7900a88aedcffc83b479aa3a36147e6565b901c93505b6101008216156138a057608061389b856ff987a7253ac413176f2b074cf7815e536147e6565b901c93505b6102008216156138cb5760806138c6856ff3392b0822b70005940c7a398e4b70f26147e6565b901c93505b6104008216156138f65760806138f1856fe7159475a2c29b7443b29c7fa6e889d86147e6565b901c93505b61080082161561392157608061391c856fd097f3bdfd2022b8845ad8f792aa58256147e6565b901c93505b61100082161561394c576080613947856fa9f746462d870fdf8a65dc1f90e061e46147e6565b901c93505b612000821615613984576080613972856fe1b0d342ada5437121767bec575e65ed6147e6565b901c9350613981600182614819565b90505b6140008216156139bc5760806139aa856fc6f84d7e5f423f66048c541550bf3e966147e6565b901c93506139b9600282614819565b90505b6180008216156139f45760806139e2856f9aa508b5b7a84e1c677de54f3e99bc8f6147e6565b901c93506139f1600482614819565b90505b62010000821615613a2d576080613a1b856fbad5f1bdb70232cd33865244bdcc089c6147e6565b901c9350613a2a600982614819565b90505b62020000821615613a66576080613a54856f885b9613d7e87aa498106fb7fa5edd376147e6565b901c9350613a63601282614819565b90505b62040000821615613a9f576080613a8d856f9142e0723efb884889d1f447715afacd6147e6565b901c9350613a9c602582614819565b90505b62080000821615613ad8576080613ac6856fa4d9a773d61316918f140bd96e8e68146147e6565b901c9350613ad5604b82614819565b90505b6000851315613af957600184856000030401935080613af6906147fd565b90505b613b04816080614819565b92505050915091565b604080516101408101909152600060e0820181815261010083018290526101208301919091528190815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b634e487b7160e01b600052604160045260246000fd5b6060810181811067ffffffffffffffff82111715613b9d57613b9d613b67565b60405250565b6040810181811067ffffffffffffffff82111715613b9d57613b9d613b67565b601f8201601f1916810167ffffffffffffffff81118282101715613be957613be9613b67565b6040525050565b600067ffffffffffffffff821115613c0a57613c0a613b67565b5060051b60200190565b600082601f830112613c2557600080fd5b81356020613c3282613bf0565b60408051613c408382613bc3565b84815260609485028701840194848201935088861115613c5f57600080fd5b8488015b86811015613ca75781818b031215613c7b5760008081fd5b8351613c8681613b7d565b81358152868201358782015284820135858201528552938501938101613c63565b509098975050505050505050565b600060408284031215613cc757600080fd5b604051613cd381613ba3565b809150823567ffffffffffffffff80821115613cee57600080fd5b613cfa86838701613c14565b83526020850135915080821115613d1057600080fd5b50613d1d85828601613c14565b6020830152505092915050565b600060808284031215610c4e57600080fd5b60008060008060e08587031215613d5257600080fd5b843567ffffffffffffffff811115613d6957600080fd5b613d7587828801613cb5565b945050613d858660208701613d2a565b939693955050505060a08201359160c0013590565b600060208284031215613dac57600080fd5b5035919050565b803560028110613dc257600080fd5b919050565b600060208284031215613dd957600080fd5b610b0b82613db3565b6001600160a01b0381168114610ba157600080fd5b600060208284031215613e0957600080fd5b8135610b0b81613de2565b60006101408284031215610c4e57600080fd5b60006101408284031215613e3a57600080fd5b610b0b8383613e14565b60008060008060008060008060006101208a8c031215613e6357600080fd5b505087359960208901359950604089013598606081013598506080810135975060a0810135965060c0810135955060e08101359450610100013592509050565b600081518084526020808501945080840160005b83811015613ee95781518051885283810151848901526040908101519088015260609096019590820190600101613eb7565b509495945050505050565b602081526000825160406020840152613f106060840182613ea3565b90506020840151601f1984830301604085015261137b8282613ea3565b60008060008060008060c08789031215613f4657600080fd5b505084359660208601359650604086013595606081013595506080810135945060a0013592509050565b60008060408385031215613f8357600080fd5b50508035926020909101359150565b60008060408385031215613fa557600080fd5b823591506020830135613fb781613de2565b809150509250929050565b60008060408385031215613fd557600080fd5b613fde83613db3565b946020939093013593505050565b60008060008060008060c0878903121561400557600080fd5b863595506020870135945060408701359350606087013592506080870135915060a087013561403381613de2565b809150509295509295509295565b60008060006060848603121561405657600080fd5b8335925060208401359150604084013561406f81613de2565b809150509250925092565b60006060828403121561408c57600080fd5b60405161409881613b7d565b80915082356140a681613de2565b815260208301356140b681613de2565b6020820152604092830135920191909152919050565b600080608083850312156140df57600080fd5b6140e9848461407a565b946060939093013593505050565b600060408284031215610c4e57600080fd5b60006020828403121561411b57600080fd5b813567ffffffffffffffff81111561413257600080fd5b611e53848285016140f7565b6000806000806000806000806000806101a08b8d03121561415e57600080fd5b8a35995060208b0135985060408b0135975060608b0135965060808b0135955060a08b0135945060c08b013593506141998c60e08d01613d2a565b92506101608b013591506101808b013590509295989b9194979a5092959850565b60008061018083850312156141ce57600080fd5b6141d88484613e14565b91506141e88461014085016140f7565b90509250929050565b60008060006060848603121561420657600080fd5b833561421181613de2565b9250602084013561422181613de2565b929592945050506040919091013590565b60208082526018908201527f416363657373436f6e74726f6c6c65642f496e76616c69640000000000000000604082015260600190565b60006020828403121561427b57600080fd5b5051919050565b600082601f83011261429357600080fd5b815160206142a082613bf0565b604080516142ae8382613bc3565b848152606094850287018401948482019350888611156142cd57600080fd5b8488015b86811015613ca75781818b0312156142e95760008081fd5b83516142f481613b7d565b815181528682015187820152848201518582015285529385019381016142d1565b60006020828403121561432757600080fd5b815167ffffffffffffffff8082111561433f57600080fd5b908301906040828603121561435357600080fd5b60405161435f81613ba3565b82518281111561436e57600080fd5b61437a87828601614282565b82525060208301518281111561438f57600080fd5b61439b87828601614282565b60208301525095945050505050565b6000602082840312156143bc57600080fd5b81518015158114610b0b57600080fd5b80516001600160a01b03908116835260208083015190911690830152604090810151910152565b6080810161440182856143cc565b8260608301529392505050565b634e487b7160e01b600052601160045260246000fd5b81810360008312801583831316838312821617156144445761444461440e565b5092915050565b60006113f33683613cb5565b634e487b7160e01b600052602160045260246000fd5b60006060828403121561447f57600080fd5b610b0b838361407a565b808201808211156113f3576113f361440e565b6000600182016144ae576144ae61440e565b5060010190565b6000602082840312156144c757600080fd5b813563ffffffff81168114610b0b57600080fd5b6000602082840312156144ed57600080fd5b813562ffffff81168114610b0b57600080fd5b818103818111156113f3576113f361440e565b60c0810161454b828680516001600160a01b039081168352602080830151908401526040808301519084015260609182015116910152565b83608083015282151560a0830152949350505050565b606081016113f382846143cc565b634e487b7160e01b600052603260045260246000fd5b60005b838110156145a0578181015183820152602001614588565b50506000910152565b600082516145bb818460208701614585565b9190910192915050565b60a081016145d382866143cc565b8360608301528215156080830152949350505050565b6020808252825182820181905260009190848201906040850190845b818110156146555761464283855180516001600160a01b039081168352602080830151908401526040808301519084015260609182015116910152565b9284019260809290920191600101614605565b50909695505050505050565b610100810161467082896143cc565b6060820196909652608081019490945260a084019290925260c083015260e090910152919050565b600060033d1115610d1d5760046000803e5060005160e01c90565b600060443d10156146c15790565b6040516003193d81016004833e81513d67ffffffffffffffff81602484011181841117156146f157505050505090565b82850191508151818111156147095750505050505090565b843d87010160208285010111156147235750505050505090565b61473260208286010187613bc3565b509095945050505050565b602081526000825180602084015261475c816040850160208701614585565b601f01601f19169190910160400192915050565b80516020808301519190811015610c4e5760001960209190910360031b1b16919050565b60e081016147a282886143cc565b8560608301528460808301528360a08301528260c08301529695505050505050565b6000826147e157634e487b7160e01b600052601260045260246000fd5b500690565b80820281158282048414176113f3576113f361440e565b6000600160ff1b82016148125761481261440e565b5060000390565b808201828112600083128015821682158216171561205c5761205c61440e56fea2646970667358221220efa8643fc61047e62d8ea1d90d102187bb65da448067ade3e120dfb6b893228d64736f6c63430008140033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.