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 #1533

Merged
merged 2 commits into from
Oct 5, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Next version

# 1.4.25

- Bump: mangrove-core to v1.5.10
- fix: infiniteApproval checks for larger than 2^200, instead of 2^256

# 1.4.24

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mangrovedao/mangrove.js",
"version": "1.4.24",
"version": "1.4.25",
"author": "Mangrove DAO",
"description": "A Typescript SDK for the Mangrove Protocol.",
"license": "(BSD-2-Clause OR BSD-3-Clause)",
Expand Down
4 changes: 2 additions & 2 deletions src/mgvtoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ class MgvToken {
}

/**
* Returns whether allowance of `owner` given to `spender` is infinite.
* Returns whether allowance of `owner` given to `spender` is more than 2^200.
* If `owner` is not specified, defaults to current signer.
* If `spender` is not specified, defaults to Mangrove instance.
*/
async allowanceInfinite(params: { owner?: string; spender?: string } = {}) {
const rawAllowance = await this.getRawAllowance({
spender: params.spender,
});
return rawAllowance.eq(ethers.constants.MaxUint256);
return rawAllowance.gt(ethers.BigNumber.from(2).pow(200));
}

private async getRawAllowance(
Expand Down
23 changes: 22 additions & 1 deletion test/integration/mgvtoken.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, it } from "mocha";
import assert from "assert";
import { afterEach, beforeEach, describe, it } from "mocha";
import { Mangrove, ethers } from "../../src";

import { Big } from "big.js";
Expand Down Expand Up @@ -48,6 +48,27 @@ describe("MGV Token integration tests suite", () => {
assert.ok(await usdc.allowanceInfinite());
});

it("allowanceInfinite is true if allowance is 2^200 + 1 ", async function () {
const usdc = await mgv.token("USDC");
assert.ok(!(await usdc.allowanceInfinite()));
await waitForTransaction(
usdc.approve(
mgv.address,
Big(2).pow(200).add(1).div(Big(10).pow(usdc.decimals))
)
);
assert.ok(await usdc.allowanceInfinite());
});

it("allowanceInfinite is false if allowance is 2^200 ", async function () {
const usdc = await mgv.token("USDC");
assert.ok(!(await usdc.allowanceInfinite()));
await waitForTransaction(
usdc.approve(mgv.address, Big(2).pow(200).div(Big(10).pow(usdc.decimals)))
);
assert.ok(!(await usdc.allowanceInfinite()));
});

it("approve sets approved amount", async function () {
const usdc = await mgv.token("USDC");
await waitForTransaction(await usdc.approve(mgv.address, 100));
Expand Down
Loading