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

fix MemoryLimitOOG issue #1854

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Next version

# 2.0.5-40
- Return both transaction (`ethers.ContractTransaction`) and result promises from `MangroveAmplifier` methods.

- add tx receipt in addbunddle
# 2.0.5-40

# 2.0.5-39
- add tx receipt in `MangroveAmplifier.addbunddle`

# 2.0.5-39

Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cache_path='cache'
fs_permissions = [{ access = "read-write", path = "./addresses/"}, { access = "read", path = "./out/" }, {access = "read", path = "./node_modules/@mangrovedao/mangrove-core/"}, {access = "read", path = "./node_modules/@mangrovedao/mangrove-strats/"}, { access = "read", path = "./mgvConfig.json" }]
solc_version="0.8.20"
ffi=true
# memory_limit=67108864
# optimizer=true
# optimizer_runs=20000

Expand Down
127 changes: 87 additions & 40 deletions src/amplifier/mangroveAmplifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class MangroveAmplifier {
*/
public async addBundle(
data: z.input<typeof addBundleParams>,
): Promise<ethers.ContractReceipt> {
): Promise<Transaction<BigNumber>> {
const {
outboundToken,
outboundVolume,
Expand Down Expand Up @@ -140,22 +140,31 @@ class MangroveAmplifier {
total = total.add(provision).add(BigNumber.from(64_000));
}

const response = await createTxWithOptionalGasEstimation(
const responsePromise = createTxWithOptionalGasEstimation(
this.amplifier.newBundle,
this.amplifier.estimateGas.newBundle,
1,
{},
[fx, vr, { value: total }],
);

const receipt = await response.wait();
return {
response: responsePromise,
result: responsePromise.then(async (response) => {
const receipt = await response.wait();

logger.debug("Amplified order raw receipt", {
contextInfo: "amplifiedOrder.addBundle",
data: { receipt },
});
logger.debug("Amplified order raw receipt", {
contextInfo: "amplifiedOrder.addBundle",
data: { receipt },
});

const bundleId = receipt.events?.filter(
(e) => e.event === "InitBundle",
)[0].args?.bundleId;

return receipt;
return BigNumber.from(bundleId);
}),
};
}

/**
Expand Down Expand Up @@ -245,35 +254,40 @@ class MangroveAmplifier {
*/
public async updateBundle(
data: z.input<typeof updateBundleParams>,
): Promise<ethers.ContractReceipt> {
): Promise<Transaction<void>> {
const {
bundleId,
outboundToken,
outboundVolume,
updateExpiry,
expiryDate,
} = updateBundleParams.parse(data);
const response = await createTxWithOptionalGasEstimation(
const responsePromise = createTxWithOptionalGasEstimation(
this.amplifier.updateBundle,
this.amplifier.estimateGas.updateBundle,
0,
{},
[bundleId, outboundToken, outboundVolume, updateExpiry, expiryDate],
);
const receipt = await response.wait();

logger.debug("Amplified order update raw receipt", {
contextInfo: "amplifiedOrder.updateBundle",
data: { receipt },
});
return receipt;
return {
response: responsePromise,
result: responsePromise.then(async (response) => {
const receipt = await response.wait();

logger.debug("Amplified order update raw receipt", {
contextInfo: "amplifiedOrder.updateBundle",
data: { receipt },
});
}),
};
}

/**
*/
public async updateOfferInBundle(
data: z.input<typeof updateBundleOfferParams>,
): Promise<ethers.ContractReceipt | undefined> {
): Promise<Transaction<any>[]> {
const { bundleId, inboundToken, newTick, newInboundLogic, outboundToken } =
updateBundleOfferParams.parse(data);

Expand All @@ -290,7 +304,7 @@ class MangroveAmplifier {

const olKeyHash = this.mgv.getOlKeyHash(olKey);

let receipt: ethers.ContractReceipt | undefined;
const transactions: Transaction<any>[] = [];

if (newTick) {
const base = await this.mgv.tokenFromAddress(inboundToken);
Expand All @@ -314,33 +328,61 @@ class MangroveAmplifier {
existingLogic?.gasOverhead ?? 0,
);

const response = await createTxWithOptionalGasEstimation(
const responsePromise = createTxWithOptionalGasEstimation(
this.amplifier.updateOffer,
this.amplifier.estimateGas.updateOffer,
0,
{},
[olKey, newTick, gives.gives.toString(), gasReq, offerId],
);

receipt = await response.wait();
transactions.push({
response: responsePromise,
result: responsePromise.then(async (response) => {
const receipt = await response.wait();

logger.debug("Amplified order update tick receipt", {
contextInfo: "amplifiedOrder.updateOfferInBundle",
data: { receipt },
logger.debug("Amplified order update tick receipt", {
contextInfo: "amplifiedOrder.updateOfferInBundle",
data: { receipt },
});
}),
});
}

const newRoutingLogicParams = {
token: inboundToken,
logic: newInboundLogic!,
offerId: offerId.toNumber(),
olKeyHash,
};

if (newInboundLogic) {
await this.setRoutingLogic(newRoutingLogicParams, {});
const newRoutingLogicParams = {
token: inboundToken,
logic: newInboundLogic,
offerId: offerId.toNumber(),
olKeyHash,
};

if (transactions.length === 0) {
transactions.push(
await this.setRoutingLogic(newRoutingLogicParams, {}),
);
return transactions;
}

const { result: prevTxResult } = transactions[0];

const responsePromise = prevTxResult.then(async () => {
const { response } = await this.setRoutingLogic(
newRoutingLogicParams,
{},
);
return response;
});

transactions.push({
response: responsePromise,
result: responsePromise.then(async (response) => {
await response.wait();
}),
});
}
return receipt;

return transactions;
}

private async setRoutingLogic(
Expand Down Expand Up @@ -381,22 +423,27 @@ class MangroveAmplifier {
*/
public async retractBundle(
data: z.input<typeof retractBundleParams>,
): Promise<ethers.ContractReceipt> {
): Promise<Transaction<void>> {
const { bundleId, outboundToken } = retractBundleParams.parse(data);
const response = await createTxWithOptionalGasEstimation(
const responsePromise = createTxWithOptionalGasEstimation(
this.amplifier.retractBundle,
this.amplifier.estimateGas.retractBundle,
0,
{},
[bundleId, outboundToken],
);
const receipt = await response.wait();

logger.debug("Amplified order update raw receipt", {
contextInfo: "amplifiedOrder.retractBundle",
data: { receipt },
});
return receipt;
return {
response: responsePromise,
result: responsePromise.then(async (response) => {
const receipt = await response.wait();

logger.debug("Amplified order update raw receipt", {
contextInfo: "amplifiedOrder.retractBundle",
data: { receipt },
});
}),
};
}
}

Expand Down
15 changes: 8 additions & 7 deletions test/integration/amplifier/amplifier.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { afterEach, beforeEach, describe, it } from "mocha";
import { toWei } from "../../util/helpers";
import * as mgvTestUtil from "../../../src/util/test/mgvIntegrationTestUtil";
import MangroveAmplifier from "../../../src/amplifier/mangroveAmplifier";
import { typechain } from "../../../src/types";

import { Mangrove } from "../../../src";

Expand Down Expand Up @@ -114,14 +113,16 @@ describe("Amplifier integration tests suite", () => {
it("Creates a bundle across 2 markets", async function () {
const inboundTokens = [simpleToken("TokenA"), simpleToken("TokenB")];

const bundleId = await amplifier.addBundle({
const { result } = await amplifier.addBundle({
outboundToken: mgv.getAddress("TokenC"),
outboundVolume: 10n ** 18n,
outboundLogic: mgv.logics.simple,
expiryDate: 0n,
inboundTokens: inboundTokens,
});

const bundleId = await result;

const bundleData = await amplifier.getBundle({
bundleId,
outboundToken: mgv.getAddress("TokenC"),
Expand All @@ -144,7 +145,7 @@ describe("Amplifier integration tests suite", () => {

describe("Succeeds", () => {
it("Retracts a bundle", async function () {
const bundleId = await addBundle();
const bundleId = await (await addBundle()).result;

await amplifier.retractBundle({
bundleId,
Expand All @@ -165,7 +166,7 @@ describe("Amplifier integration tests suite", () => {

describe("Succeeds", () => {
it("Updates a bundle (not date)", async function () {
const bundleId = await addBundle();
const bundleId = await (await addBundle()).result;

await amplifier.updateBundle({
bundleId,
Expand All @@ -183,7 +184,7 @@ describe("Amplifier integration tests suite", () => {
});

it("Updates a bundle (date)", async function () {
const bundleId = await addBundle();
const bundleId = await (await addBundle()).result;

await amplifier.updateBundle({
bundleId,
Expand All @@ -206,7 +207,7 @@ describe("Amplifier integration tests suite", () => {

describe("Succeeds", () => {
it("Updates an offer in a bundle (tick)", async function () {
const bundleId = await addBundle();
const bundleId = await (await addBundle()).result;

await amplifier.updateOfferInBundle({
bundleId,
Expand All @@ -223,7 +224,7 @@ describe("Amplifier integration tests suite", () => {
});

it("Updates an offer in a bundle (logic)", async function () {
const bundleId = await addBundle();
const bundleId = await (await addBundle()).result;

await amplifier.updateOfferInBundle({
bundleId,
Expand Down
Loading