diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fdf37257..51e66f682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Next version +- Upgrade or remove `examples/how-tos` so they match the new version of the Mangrove core protocol and SDK - Upgrade `examples/tutorials/on-the-fly-offer.js` to new Mangrove core protocol and SDK - fix: Coerce ticks to tickSpacing when given as arguments - feat: Add integration test of tickSpacing>1 diff --git a/examples/how-tos/fill-or-kill.js b/examples/how-tos/fill-or-kill.js index 7626e41ff..b1fc91c6d 100644 --- a/examples/how-tos/fill-or-kill.js +++ b/examples/how-tos/fill-or-kill.js @@ -12,26 +12,32 @@ 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, +}); + +const usdtToken = await mgv.token("USDT"); -// await market.quote.contract.mintTo( // minting USDC if you are on testnet +// await market.quote.contract.mintTo( // minting USDT if you are on testnet // process.env.ADMIN_ADDRESS, -// mgv.toUnits(10000, market.quote.decimals) +// usdtToken.toUnits(100000) // ); -// Check it's live, should display the best asks of the DAI, USDC market +// Check that we're live. Should display the best asks of the USDC, USDT market. market.consoleAsks(); -// approve that the mangroveOrder contract can use your USDC (quote) funds -await mgv.offerLogic(mgv.orderContract.address).approveToken(market.quote.name); +const restingOrderRouterAddress = await mgv.getRestingOrderRouterAddress(); + +await usdtToken.approve(restingOrderRouterAddress); let buyPromises = await market.buy({ volume: 2000, - price: 1.3, + limitPrice: 1.3, fillOrKill: true, }); const result = await buyPromises.result; - console.log(result); diff --git a/examples/how-tos/reuse-offer.js b/examples/how-tos/reuse-offer.js deleted file mode 100644 index 66cef48fb..000000000 --- a/examples/how-tos/reuse-offer.js +++ /dev/null @@ -1,78 +0,0 @@ -// Load the RPC_URL and PRIVATE_KEY from .env file into process.env -// This script assumes RPC_URL points to your access point and PRIVATE_KEY contains private key from which one wishes to post offers -var parsed = require("dotenv").config(); -// Import the Mangrove API -const { Mangrove, ethers } = require("@mangrovedao/mangrove.js"); - -// Create a wallet with a provider to interact with the chain. -// const provider = new ethers.providers.WebSocketProvider(process.env.RPC_URL); // For real chain use -const provider = new ethers.providers.WebSocketProvider(process.env.LOCAL_URL); // For local chain use -const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // Use either own account or if on local chain use an anvil account - -// 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" }); - -market.consoleAsks(); - -// comment this in, if you need to mint quote token -/* -await market.quote.contract.mintTo( - process.env.ADMIN_ADDRESS, - mgv.toUnits(10000, market.quote.decimals) -); -*/ - -// comment this in, if you need to mint base token -/* -await market.quote.contract.mintTo( - process.env.ADMIN_ADDRESS, - mgv.toUnits(10000, market.base.decimals) -); -*/ - -// comment this in, if you do not have a "dead" offer -/* -let directLP = await mgv.liquidityProvider(market); -let tx = await market.base.approveMangrove(); -await tx.wait(); -let provision = await directLP.computeAskProvision(); -let { id: offerId } = await directLP.newAsk({ - wants: 100.5, - gives: 100.4, - fund: provision, -}); - -await mgv.approveMangrove("USDC"); - -let snipePromises = await market.snipe({ - targets: [ - { - offerId: offerId, - takerWants: 100.4, - takerGives: 100.5, - // gasLimit: offer.gasreq, // not mandatory - }, - ], - ba: "asks", -}); - -let snipeResult = await snipePromises.result; -console.log(snipeResult); -*/ - -let lp = await mgv.liquidityProvider(market); -let provisionForUpdateOffer = await lp.computeAskProvision({ - id: offerIdToUpdate, -}); -let result = await lp.updateAsk(offerIdToUpdate, { - wants: 1000.5, - gives: 1000.4, - fund: provisionForUpdateOffer, -}); - -console.log(result); - -market.consoleAsks(); diff --git a/examples/how-tos/snipe-offer.js b/examples/how-tos/snipe-offer.js deleted file mode 100644 index 39cbbd241..000000000 --- a/examples/how-tos/snipe-offer.js +++ /dev/null @@ -1,56 +0,0 @@ -// Load the RPC_URL and PRIVATE_KEY from .env file into process.env -// This script assumes RPC_URL points to your access point and PRIVATE_KEY contains private key from which one wishes to post offers -var parsed = require("dotenv").config(); -// Import the Mangrove API -const { Mangrove, ethers } = require("@mangrovedao/mangrove.js"); - -// Create a wallet with a provider to interact with the chain. -// const provider = new ethers.providers.WebSocketProvider(process.env.RPC_URL); // For real chain use -const provider = new ethers.providers.WebSocketProvider(process.env.LOCAL_URL); // For local chain use -const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // Use either own account or if on local chain use an anvil account - -// 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" }); - -// await market.quote.contract.mintTo( // minting USDC if you are on testnet -// process.env.ADMIN_ADDRESS, -// mgv.toUnits(10000, market.quote.decimals) -// ); - -// Check it's live, should display the best asks of the DAI, USDC market -market.consoleAsks(); - -// Make sure to use the correct offerID -let offerId = 5572; - -// Get all the info about the offer -let offer = await market.getSemibook("asks").offerInfo(offerId); - -// Log offer to see what data in holds -console.log(offer); - -// Approve Mangrove to take USDC from your account -await mgv.approveMangrove("USDC"); - -// Snipe the offer using the information about the offer. -let snipePromises = await market.snipe({ - targets: [ - { - offerId: offer.id, - takerWants: offer.gives, - takerGives: offer.wants, - // gasLimit: offer.gasreq, // not mandatory - }, - ], - ba: "asks", -}); -const result = await snipePromises.result; - -// Log the result of snipe -console.log(result); - -// Log asks to see that the offer is gone. -market.consoleAsks(); diff --git a/examples/how-tos/update-offer.js b/examples/how-tos/update-offer.js deleted file mode 100644 index cf7453d1c..000000000 --- a/examples/how-tos/update-offer.js +++ /dev/null @@ -1,67 +0,0 @@ -// Load the RPC_URL and PRIVATE_KEY from .env file into process.env -// This script assumes RPC_URL points to your access point and PRIVATE_KEY contains private key from which one wishes to post offers -var parsed = require("dotenv").config(); -// Import the Mangrove API -const { Mangrove, ethers, OfferLogic } = require("@mangrovedao/mangrove.js"); - -// Create a wallet with a provider to interact with the chain. -// const provider = new ethers.providers.WebSocketProvider(process.env.RPC_URL); // For real chain use -const provider = new ethers.providers.WebSocketProvider(process.env.LOCAL_URL); // For local chain use -const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // Use either own account or if on local chain use an anvil account - -// 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" }); - -// Check it's live, should display the best bids and asks of the DAI, USDC 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); - -// Show best asks -market.consoleAsks(); - -// Change this to your own offer id. -let offerId = 5572; - -// await directLP.updateAsk( offerId, { -// wants: 100.5, -// gives: 100.1494 -// }) - -await directLP.updateAsk(offerId, { - volume: 100.5, - price: 1.00345, -}); - -market.consoleAsks(); - -let offerLogic = new OfferLogic( - mgv, - "", //Write your contract address here -); - -// We recommend to use a liquidityProvider -let result = await offerLogic.contract.updateOffer( - market.base.address, // outbound_tkn - market.quote.address, // inbound_tkn - market.quote.toUnits(100.5), // wants - market.base.toUnits(1.00345), // gives - 0, // pivot - give pivot that makes sense - offerId, // offerId - { - // overrides - value: mgv.toUnits(123, 18), // give correct value - }, -); - -let lp = await offerLogic.liquidityProvider(market); - -await lp.updateAsk(offerId, { - volume: 100.5, - price: 1.00345, -});