Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into develop #1744

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next version

- Upgrade `examples/tutorials/on-the-fly-offer.js` to new Mangrove core protocol and SDK

# 2.0.4

- Upgrade to @mangrovedao/mangrove-deployments v2.0.0
Expand Down
16 changes: 10 additions & 6 deletions examples/tutorials/on-the-fly-offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,36 @@ const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // Use eith
// Connect the API to Mangrove
const mgv = await Mangrove.connect({ signer: wallet });

// Connect mgv to a DAI, USDC market
const market = await mgv.market({ base: "DAI", quote: "USDC" });
// Connect mgv to a USDC, USDT market
const market = await mgv.market({
base: "USDC",
quote: "USDT",
tickSpacing: 1,
});

// Check it's live, should display the best bids and asks of the DAI, USDC market
// Check it's live, should display the best bids and asks of the USDC, USDT market
market.consoleAsks();
market.consoleBids();

// Create a simple liquidity provider on `market`, using `wallet` as a source of liquidity
const directLP = await mgv.liquidityProvider(market);

// In order to post an ask, signer needs to approve Mangrove for transfer of base token (DAI) which
// In order to post an ask, signer needs to approve Mangrove for transfer of base token (USDT) which
// will be transferred from the wallet to Mangrove and then to the taker when the offer is taken.
const tx = await market.base.approve(mgv.address, { amount: 100.4 });
await tx.wait();

// Query mangrove to know the bounty for posting a new Ask on `market`
const provision = await directLP.computeAskProvision();

// Post a new ask (requesting 100.5 USDC for 100.4 DAI) at a price of 100.5/100.4~=1.00099
// Post a new ask (requesting 100.5 USDC for 100.4 USDT) at a price of 100.5/100.4~=1.00099
// Consider looking at the consoleAsks above and increase gives such that the offer becomes visible in this list
const { id: offerId } = await directLP.newAsk({
wants: 100.5,
gives: 100.4,
fund: provision,
});

// Check the order was posted (or look at https://testnet.mangrove.exchange)
// Check the order was posted (or look at https://testnet.mangrove.exchange, if you're not working locally)
console.log(offerId);
market.consoleAsks();
Loading