Skip to content

Commit

Permalink
move developer/contracts to developer/protocol (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
espendk authored Jan 17, 2024
1 parent 09b601a commit 946ad04
Show file tree
Hide file tree
Showing 82 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions docs/developers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ sidebar_position: 1

The Mangrove Developers documentation section exists to help developers:

* learn about Mangrove [core protocol](./contracts/README.md),
* learn about Mangrove [core protocol](./protocol/README.md),
* understand how trading [strategies](./strat-lib/README.md) can be created and plugged in,
* use and integrate our [SDK](./SDK/README.md),
* set up [Keeper bots](./keeper-bots/README.md).


We suggest you start by reading [this introduction](./contracts/README.md).
We suggest you start by reading [this introduction](./protocol/README.md).
If there's anything that is missing, or if you have questions, feel free to reach out via [Discord](https://discord.gg/rk9Qthz5YE).
2 changes: 1 addition & 1 deletion docs/developers/SDK/getting-started/_preparation-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chain that anvil star

## Local chain

The tutorials can be run directly on networks where Mangrove is deployed (see [Addresses](../../contracts/technical-references/contract-addresses.md)). However on a real network you will spend real tokens, so we recommend starting on test networks with a test account.
The tutorials can be run directly on networks where Mangrove is deployed (see [Addresses](../../protocol/technical-references/contract-addresses.md)). However on a real network you will spend real tokens, so we recommend starting on test networks with a test account.

To further speed things up we run tutorials on a local fork of a chain using Foundry's `anvil` tool.

Expand Down
2 changes: 1 addition & 1 deletion docs/developers/SDK/getting-started/basic-offer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Posting a simple offer is also referred to as an %%on-the-fly offer|on-the-fly-o

The tutorial assumes knowledge of JavaScript. Follow [preparation](./preparation.md) to create a new `tutorial` folder.

Make sure to use a chain where Mangrove is live. You can find all live addresses for Mangrove [here](../../contracts/technical-references/contract-addresses.md)
Make sure to use a chain where Mangrove is live. You can find all live addresses for Mangrove [here](../../protocol/technical-references/contract-addresses.md)

:::info

Expand Down
2 changes: 1 addition & 1 deletion docs/developers/SDK/getting-started/deploy-kandel.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This tutorial covers how to deploy a Kandel strategy from a developer standpoint

* The tutorial assumes knowledge of JavaScript
* Follow [preparation](./preparation.md) to create a new `tutorial` folder.
* Make sure to use a chain where Mangrove is live - you can find all live addresses for Mangrove [here](../../contracts/technical-references/contract-addresses.md)
* Make sure to use a chain where Mangrove is live - you can find all live addresses for Mangrove [here](../../protocol/technical-references/contract-addresses.md)
* For a more simple tutorial to get acquainted with Mangrove, we recommend [Deploy a simple offer](./basic-offer.md)

### Start local node
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/SDK/guides/fill-or-kill.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We assume you know how to connect to Mangrove. We are going to be buying 2000 US

### Approvals

After having connected to Mangrove, we then have to make sure that we have the correct approvals for transferring our USDC tokens. When approving for transfers we have to determine what contract is going to make the actual transfers. If we were to use the normal [`buy`](../technical-references/code/classes/Market#-buy) function for a market, we would be using the Mangrove protocol, to make a standard [market order](../../contracts/technical-references/taking-and-making-offers/taker-order/README.md#market-order). This would mean that we would have to approve Mangrove to make transfers of USDC on our behalf.
After having connected to Mangrove, we then have to make sure that we have the correct approvals for transferring our USDC tokens. When approving for transfers we have to determine what contract is going to make the actual transfers. If we were to use the normal [`buy`](../technical-references/code/classes/Market#-buy) function for a market, we would be using the Mangrove protocol, to make a standard [market order](../../protocol/technical-references/taking-and-making-offers/taker-order/README.md#market-order). This would mean that we would have to approve Mangrove to make transfers of USDC on our behalf.

In this case we are not going to be using the Mangrove protocol directly. Instead we are going to be using a different contract, provided by the [Mangrove strat lib](../../strat-lib/README.md) - the [MangroveOrder](../../strat-lib/technical-references/code/strats/src/strategies/MangroveOrder) contract. This contract makes it possible to make a real FoK order and not just a normal market order. This means that we need to approve the MangroveOrder contract to handle all our USDC transfers. One way of doing this, would be to just call approve directly on the USDC token, with the MangroveOrder contract as spender. But because strategies made with the Mangrove strat lib, can be using a more complex way of dealing with transfers, we should not rely on calling approve directly on the token. Instead we will create an %%OfferLogic|offer-logic%% using the MangroveOrder contract. This will provide us with an 'approveToken' function. This function will handle all the necessary approvals in order to use a token with the contract.

Expand Down
2 changes: 1 addition & 1 deletion docs/developers/SDK/technical-references/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mgv = await Mangrove.connect( {
});
```

You can test you are indeed connected to the [deployed Mangrove](../../contracts/technical-references/contract-addresses.md) by asking for the current global configuration of Mangrove:
You can test you are indeed connected to the [deployed Mangrove](../../protocol/technical-references/contract-addresses.md) by asking for the current global configuration of Mangrove:

`config = await mgv.config()`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 2

# The role of gas price updater bots in Mangrove

Mangrove needs the gas price to [determine the remuneration](../../contracts/technical-references/taking-and-making-offers/reactive-offer/offer-provision.md#bounty) of takers for removing a failing offer from a list. On chains where the gas price varies, Mangrove [uses](../../contracts/technical-references/governance-parameters/global-variables) an [oracle](../../contracts/technical-references/periphery/oracle) to get the gas price.
Mangrove needs the gas price to [determine the remuneration](../../protocol/technical-references/taking-and-making-offers/reactive-offer/offer-provision.md#bounty) of takers for removing a failing offer from a list. On chains where the gas price varies, Mangrove [uses](../../protocol/technical-references/governance-parameters/global-variables) an [oracle](../../protocol/technical-references/periphery/oracle) to get the gas price.

The role of the gas price updater bot is simply to push up-to-date gas prices to the oracle contract whenever the gas price changes significantly.

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/developers/strat-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you have questions about how to use the Strat library, which are not answered

### Choosing the right starting point

Depending on the complexity of the %%offer logic|offer-logic%% your contract implements, you need to choose from which building block you will start to build your %%maker contract|maker-contract%% from. At the very least your logic must provide an implementation of the [`IMaker`](https://github.com/mangrovedao/mangrove-core/blob/2ae172805fd8b309c30b2dc877dba66245abbb3e/src/core/MgvLib.sol#L420-L430) interface [required by Mangrove](../contracts/technical-references/taking-and-making-offers/reactive-offer/maker-contract.md).
Depending on the complexity of the %%offer logic|offer-logic%% your contract implements, you need to choose from which building block you will start to build your %%maker contract|maker-contract%% from. At the very least your logic must provide an implementation of the [`IMaker`](https://github.com/mangrovedao/mangrove-core/blob/2ae172805fd8b309c30b2dc877dba66245abbb3e/src/core/MgvLib.sol#L420-L430) interface [required by Mangrove](../protocol/technical-references/taking-and-making-offers/reactive-offer/maker-contract.md).

However, we suggest utilizing the building blocks in the strat lib. The first design choice is to decide whether owning offers posted by your contract is the sole privilege of the contract's admin or whether your contract's logic wishes to support multiple offer owners, in a permissionless fashion. In the first case, you want your contract to inherit [Direct](./background/offer-maker/direct.md), in the latter you want to start from a [Forwarder](./background/offer-maker/forwarder.md) contract which has a pre-established code infrastructure to handle multiple ownership.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ When an offer is taken, Mangrove transfers the funds from the taker to Mangrove

### Pre trade hooks

* [Lastlook](../../technical-references/main-hooks.md#last-look-before-trade) is meant for having a lastlook before the funds are transferred to the taker. It then returns a value that `makerPosthook` can use, to get information of how e.g. the markets looked, when `makerExecute` was executed. This can be useful since, `makerPosthook` may be called several orders later. See [Executing offers](../../../contracts/technical-references/taking-and-making-offers/reactive-offer/executing-offers.md) for more information.
* [Lastlook](../../technical-references/main-hooks.md#last-look-before-trade) is meant for having a lastlook before the funds are transferred to the taker. It then returns a value that `makerPosthook` can use, to get information of how e.g. the markets looked, when `makerExecute` was executed. This can be useful since, `makerPosthook` may be called several orders later. See [Executing offers](../../../protocol/technical-references/taking-and-making-offers/reactive-offer/executing-offers.md) for more information.

* [Put](../../technical-references/main-hooks.md#managing-takers-payment) is meant as an option for the maker to transfer the given funds from the contract to e.g. the reserve. This could be useful if you don't want to leave the funds on the contract.

Expand Down
4 changes: 2 additions & 2 deletions docs/developers/strat-lib/getting-started/smart-offer.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Start another terminal and import environment variables again
source .env
```

Now, create the `OfferMakerTutorial` contract on the `anvil` node with your private key by pointing to its local `rpc-url`, and supplying the parameters for Mangrove core contract (get it from [Addresses](../../contracts/technical-references/contract-addresses.md) for the network you have forked).
Now, create the `OfferMakerTutorial` contract on the `anvil` node with your private key by pointing to its local `rpc-url`, and supplying the parameters for Mangrove core contract (get it from [Addresses](../../protocol/technical-references/contract-addresses.md) for the network you have forked).
You can also add it to your `.env` file.

```bash
Expand Down Expand Up @@ -154,7 +154,7 @@ Now that the contract is ready, we can use it to post an offer - note that we ha
In our example, we are offering 1 WBTC (gives) at tick 50 (tick 50 means the price ratio is `1.0001^50`).

:::info Note
Later, if you'd like to take your own offer with a [market order](../../contracts/technical-references/taking-and-making-offers/taker-order/README.md#market-order) for testing purpose, it would be handy to have your offer at the very top of the book (i.e. with the best price possible). To do this, you could post your offer with the smallest tick (`-887272`), or use the [`MIN_TICK`](https://github.com/mangrovedao/mangrove-core/blob/2ae172805fd8b309c30b2dc877dba66245abbb3e/lib/core/Constants.sol#L52) constant in your test contract.
Later, if you'd like to take your own offer with a [market order](../../protocol/technical-references/taking-and-making-offers/taker-order/README.md#market-order) for testing purpose, it would be handy to have your offer at the very top of the book (i.e. with the best price possible). To do this, you could post your offer with the smallest tick (`-887272`), or use the [`MIN_TICK`](https://github.com/mangrovedao/mangrove-core/blob/2ae172805fd8b309c30b2dc877dba66245abbb3e/lib/core/Constants.sol#L52) constant in your test contract.
:::

```bash
Expand Down
12 changes: 6 additions & 6 deletions docs/developers/strat-lib/guides/DirectHowTo.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ We use 30K for default %%`gasreq`|gasreq%% of our strat. This does not leave roo

With this constructor in place we almost have a deployable maker contract. `Direct` already provides the implementation of a default %%offer logic|offer-logic%% as well as internal functions to post, update and retract offers posted by our contract.

However, `Direct` does not expose any function able to [create new offers](../../contracts/technical-references/taking-and-making-offers/reactive-offer/README.md#posting-a-new-offer) on Mangrove, since the [`_newOffer`](../technical-references/code/strats/src/strategies/offer_maker/abstract/Direct.md) function of Direct is internal. The requirement in our constructor to implement `ILiquidityProvider` imposes on us to have a public `newOffer` function. Using `ILiquidityProvider` ensures our contract is compatible with the [Mangrove SDK](../../SDK/README.md), which expects the `ILiquidityProvider` ABI.
However, `Direct` does not expose any function able to [create new offers](../../protocol/technical-references/taking-and-making-offers/reactive-offer/README.md#posting-a-new-offer) on Mangrove, since the [`_newOffer`](../technical-references/code/strats/src/strategies/offer_maker/abstract/Direct.md) function of Direct is internal. The requirement in our constructor to implement `ILiquidityProvider` imposes on us to have a public `newOffer` function. Using `ILiquidityProvider` ensures our contract is compatible with the [Mangrove SDK](../../SDK/README.md), which expects the `ILiquidityProvider` ABI.

Our implementation of `newOffer` is simply to expose the internal `_newOffer` provided by Direct making sure the function is admin restricted (`Direct` provides the appropriate modifier `onlyAdmin`):

Expand Down Expand Up @@ -81,7 +81,7 @@ Of course, if we offer `N` tokens *both* on the (`BASE`, `STABLE1`) and the (`BA
We have a design choice here. Either we

1. let the second offer fail and compensate the taker with our offer's %%bounty|bounty%%, or,
2. incorporate in our offer logic that we wish to [retract](../../contracts/technical-references/taking-and-making-offers/reactive-offer/README.md#retracting-an-offer) the second offer when the first one is taken.
2. incorporate in our offer logic that we wish to [retract](../../protocol/technical-references/taking-and-making-offers/reactive-offer/README.md#retracting-an-offer) the second offer when the first one is taken.

Let's follow the second design principle as it allows us to illustrate how to use the %%hooks|hook%% provided by `Direct` to update offer prices or to retract offers.

Expand All @@ -103,19 +103,19 @@ As in the example above, we need to create a way for the maker contract to post

We already know some of the parameters we need to implement posting new offers, since we gave them in the constructor: We know the %%inbound|inbound%% and the %%outbound|outbound%% tokens of both offers. Also, we do not want the %%offer owner|offer-owner%% to have to specify new offer's %%`gasprice`|gasprice%% and %%`gasreq`|gasreq%% so we just use default values.

If we specify a `gasprice` of zero when posting the offer, Mangrove will use [its own gas price](../../contracts/technical-references/governance-parameters/global-variables.md#gas-price-and-oracle). For `gasreq`, we can use the public getter `offerGasreq()`, which returns the default gas requirement for the contract plus the gas required for the %%router|router%%.
If we specify a `gasprice` of zero when posting the offer, Mangrove will use [its own gas price](../../protocol/technical-references/governance-parameters/global-variables.md#gas-price-and-oracle). For `gasreq`, we can use the public getter `offerGasreq()`, which returns the default gas requirement for the contract plus the gas required for the %%router|router%%.

This leaves us having to provide the amount that the offer should %%`give`|gives%% in `BASE` token, and the amount of `STABLE1` and `STABLE2`, which the offer %%wants|wants%% - `wants1` and `wants2`. We also need to specify the TODO:%pivot ids|pivot-id% for insertion of the two offers (`pivot1` and `pivot2`) in the relevant %%offer lists|offer-list%%. As for `OfferMaker`, we only want the admin of the contract to able to post offers, so we use the modifier `onlyAdmin` again.

```solidity reference title="Amplifier - Publishing amplified offers"
https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/src/toy_strategies/offer_maker/Amplifier.sol#L60-L115
```

In the implementation of `newAmplifiedOffers` notice the calls to the offer data getter `MGV.offers(address, address, uint)`: This returns a packed data structure `offer` whose fields `f` can be unpacked by doing `offer.f()` (see the documentation for the [offer data structure](../../contracts/technical-references/taking-and-making-offers/views-on-offers.md#views-on-offers)).
In the implementation of `newAmplifiedOffers` notice the calls to the offer data getter `MGV.offers(address, address, uint)`: This returns a packed data structure `offer` whose fields `f` can be unpacked by doing `offer.f()` (see the documentation for the [offer data structure](../../protocol/technical-references/taking-and-making-offers/views-on-offers.md#views-on-offers)).

:::info possible gas optimization

If both our amplified offers were once live on Mangrove, but are no longer (either after a retract or because one of them was consumed by a taker), it is more gas efficient to [update the offers](../../contracts/technical-references/taking-and-making-offers/reactive-offer/README.md#updating-an-existing-offer) to reinstate them on the %%offer list|offer-list%%, rather than creating new ones as we do in the above code.
If both our amplified offers were once live on Mangrove, but are no longer (either after a retract or because one of them was consumed by a taker), it is more gas efficient to [update the offers](../../protocol/technical-references/taking-and-making-offers/reactive-offer/README.md#updating-an-existing-offer) to reinstate them on the %%offer list|offer-list%%, rather than creating new ones as we do in the above code.

:::

Expand Down Expand Up @@ -153,7 +153,7 @@ During the execution of the %%offer logic|offer-logic%% it may occur that the ta

* the offer was completely filled
* the offer is %%partially filled|maker-partial-fill%% but its residual is below the offer list's %%density|density%%
* the offer no longer has enough %%provision|provision%%. This last case may occur if one is reposting an offer that has failed (because a part of the %%provision|provision%% was turned into a %%bounty|bounty%%), or because Mangrove's %%gasprice|gasprice%% is now above the offer's gasprice. (This may happen, if Mangrove updated its [own gasprice](../../contracts/technical-references/governance-parameters/global-variables.md#gas-price-and-oracle) after the offer was last posted.)
* the offer no longer has enough %%provision|provision%%. This last case may occur if one is reposting an offer that has failed (because a part of the %%provision|provision%% was turned into a %%bounty|bounty%%), or because Mangrove's %%gasprice|gasprice%% is now above the offer's gasprice. (This may happen, if Mangrove updated its [own gasprice](../../protocol/technical-references/governance-parameters/global-variables.md#gas-price-and-oracle) after the offer was last posted.)

In all of these cases we wish to retract the other offer from the book.

Expand Down
Loading

0 comments on commit 946ad04

Please sign in to comment.