Skip to content

Instantly share code, notes, and snippets.

@maxencerb
Created April 9, 2024 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxencerb/41e0910d16e6d856a3994c7af5d9eeb8 to your computer and use it in GitHub Desktop.
Save maxencerb/41e0910d16e6d856a3994c7af5d9eeb8 to your computer and use it in GitHub Desktop.
import { Mangrove } from "@mangrovedao/mangrove.js";
import { ethers } from "ethers";
import {
createWalletClient,
http,
publicActions,
type Hex,
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { blast } from "viem/chains";
const client = createWalletClient({
chain: blast,
transport: http(),
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
}).extend(publicActions);
const provider = new ethers.providers.JsonRpcProvider(
blast.rpcUrls.default.http[0]
);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
const nonce = await provider.getTransactionCount(client.account.address);
const mgv = await Mangrove.connect({ signer: wallet });
const market = await mgv.market({
base: "WETH",
quote: "USDB",
tickSpacing: 1,
});
const weth = await mgv.token("WETH");
const usdb = await mgv.token("USDB");
console.log(await weth.balanceOf(client.account.address));
console.log(await usdb.balanceOf(client.account.address));
const lp = await mgv.liquidityProvider(market);
const provision = await lp.computeAskProvision();
const numOffers = 2;
console.log(`Adding ${numOffers} offers`);
const offers = await Promise.all(
Array.from({ length: numOffers }).map(async (_, i) => {
const { id: offerId, event } = await lp.newAsk(
{
wants: 1,
gives: 100.4,
fund: provision,
},
{ gasPrice: 1e6, nonce: nonce + i, gasLimit: 20e6}
);
// offerIds.push(offerId);
console.log("Offer ID:", offerId);
console.log("Event:", event);
return offerId;
})
);
console.log("Retracting offers");
await Promise.all(
offers.map(async (offerId, i) => {
await lp.retractAsk(offerId, true, {
gasPrice: 1e6,
nonce: nonce + numOffers + i,
gasLimit: 20e6,
});
})
);
console.log("Retracted");
process.exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment