Skip to content

Commit

Permalink
Change bonding curve endpoint (#187)
Browse files Browse the repository at this point in the history
* Change bonding curve endpoint

* Fix tests
  • Loading branch information
vtleonardo committed Aug 20, 2022
1 parent 2fe30e2 commit 70ee80d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bridge/contracts/libraries/math/Sigmoid.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract contract Sigmoid {
uint256 internal constant _P_A = 200;
uint256 internal constant _P_B = 2500 * 10**18;
uint256 internal constant _P_C = 5611050234958650739260304 + 125 * 10**39;
uint256 internal constant _P_D = 1;
uint256 internal constant _P_D = 4;
uint256 internal constant _P_S = 2524876234590519489452;

// Constants for P Inverse function
Expand Down
7 changes: 4 additions & 3 deletions bridge/test/bToken/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ describe("Testing BToken bridge methods", async () => {

it("Should deposit tokens into the bridge and destroy the correspondent BToken fee if no eth fee is sent", async () => {
expectedState = await getState(fixture);
const tx = await fixture.bToken
.connect(user)
.depositTokensOnBridges(_poolVersion, encodedDepositCallData);
ethsFromBurning = await fixture.bToken.getLatestEthFromBTokensBurn(
bTokenFee
);
const tx = await fixture.bToken
.connect(user)
.depositTokensOnBridges(_poolVersion, encodedDepositCallData);
console.log(ethsFromBurning);
expectedState.Balances.bToken.user -= BigInt(bTokenFee);
expectedState.Balances.eth.user -= getEthConsumedAsGas(await tx.wait());
expectedState.Balances.bToken.totalSupply -= BigInt(bTokenFee);
Expand Down
6 changes: 3 additions & 3 deletions bridge/test/bToken/burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe("Testing BToken Burning methods", async () => {
user,
[burnQuantity, 0]
);
expect(bTokens).to.be.equal(BigInt("3990217121585928137263"));
expect(eths).to.be.equal(BigInt("9749391845405398553"));
expect(bTokens).to.be.equal(BigInt("4020217121585928137263"));
expect(eths).to.be.equal(BigInt("9751261920046697614"));
expectedState.Balances.bToken.user -= burnQuantity;
expectedState.Balances.eth.user += eths.toBigInt();
expectedState.Balances.bToken.poolBalance -= eths.toBigInt();
Expand All @@ -58,7 +58,7 @@ describe("Testing BToken Burning methods", async () => {
user,
[burnQuantity, 0]
);
expect(eths).to.be.equal(BigInt("9749391845405398553"));
expect(eths).to.be.equal(BigInt("9751261920046697614"));
expectedState.Balances.bToken.user -= burnQuantity;
expectedState.Balances.eth.user += eths2.toBigInt();
expectedState.Balances.bToken.poolBalance -= eths2.toBigInt();
Expand Down
6 changes: 3 additions & 3 deletions bridge/test/bToken/destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ describe("Testing BToken Destroy methods", async () => {
it("Should burn btokens from sender and keep resulting eth on contract", async () => {
expectedState = await getState(fixture);
const tx = await fixture.bToken.connect(user).destroyBTokens(bTokens);
expect(bTokens).to.be.equal(BigInt("3990217121585928137263"));
expect(bTokens).to.be.equal(BigInt("4020217121585928137263"));
expectedState.Balances.bToken.user -= bTokens.toBigInt();
expectedState.Balances.bToken.totalSupply -= bTokens.toBigInt();
expectedState.Balances.bToken.poolBalance -= ethsFromBurning.toBigInt();
expectedState.Balances.eth.user -= getEthConsumedAsGas(await tx.wait());
expect(await getState(fixture)).to.be.deep.equal(expectedState);
});

it("Should not destroy more btokens than suply", async () => {
it("Should not destroy more bTokens than supply", async () => {
await expect(
fixture.bToken
.connect(user)
.destroyBTokens((await fixture.bToken.balanceOf(user.address)).add(100))
)
.to.be.revertedWithCustomError(fixture.bToken, "BurnAmountExceedsSupply")
.withArgs(3990217121585928137363n, 3990217121585928137263n);
.withArgs(4020217121585928137363n, 4020217121585928137263n);
});

it("Should not destroy more BTokens than on balance", async () => {
Expand Down
14 changes: 7 additions & 7 deletions bridge/test/bToken/mint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Testing BToken Minting methods", async () => {
[minBTokens],
ethInWeis
);
expect(bTokens).to.be.equal(BigInt("399028731704364116575"));
expect(bTokens).to.be.equal(BigInt("402028731704364116575"));
expectedState.Balances.eth.user -= ethInWeis.toBigInt();
expectedState.Balances.eth.user -= getEthConsumedAsGas(await tx.wait());
expectedState.Balances.bToken.user += bTokens.toBigInt();
Expand All @@ -60,7 +60,7 @@ describe("Testing BToken Minting methods", async () => {
expectedState.Balances.bToken.totalSupply += bTokens2.toBigInt();
expectedState.Balances.bToken.poolBalance += ethInWeis.div(4).toBigInt();
expectedState.Balances.eth.bToken += ethInWeis.toBigInt();
expect(bTokens2).to.be.equal(BigInt("399027176702820751481"));
expect(bTokens2).to.be.equal(BigInt("402027176702820751481"));
expect(await getState(fixture)).to.be.deep.equal(
expectedState,
"State 2 comp"
Expand All @@ -78,7 +78,7 @@ describe("Testing BToken Minting methods", async () => {
[minBTokens],
ethInWeis
);
expect(bTokens).to.be.equal(BigInt("17501004975246203818081563855"));
expect(bTokens).to.be.equal(BigInt("70001004975246203818081563855"));
expect(await fixture.bToken.getPoolBalance()).to.be.equal(
ethInWeis.div(marketSpread).toBigInt()
);
Expand All @@ -94,7 +94,7 @@ describe("Testing BToken Minting methods", async () => {
[user.address, minBTokens],
ethInWeis
);
expect(bTokens).to.be.equal(BigInt("399028731704364116575"));
expect(bTokens).to.be.equal(BigInt("402028731704364116575"));
expectedState.Balances.eth.admin -= ethInWeis.toBigInt();
expectedState.Balances.eth.admin -= getEthConsumedAsGas(await tx.wait());
expectedState.Balances.bToken.user += bTokens.toBigInt();
Expand All @@ -120,7 +120,7 @@ describe("Testing BToken Minting methods", async () => {
.div(marketSpread)
.toBigInt();
expectedState.Balances.eth.bToken += ethInWeis.toBigInt();
expect(bTokens2).to.be.equal(BigInt("399027176702820751481"));
expect(bTokens2).to.be.equal(BigInt("402027176702820751481"));
expect(await getState(fixture)).to.be.deep.equal(expectedState);
});

Expand All @@ -135,7 +135,7 @@ describe("Testing BToken Minting methods", async () => {
[user.address, minBTokens],
ethInWeis
);
expect(bTokens).to.be.equal(BigInt("17501004975246203818081563855"));
expect(bTokens).to.be.equal(BigInt("70001004975246203818081563855"));
expectedState.Balances.eth.admin -= ethInWeis.toBigInt();
expectedState.Balances.eth.admin -= getEthConsumedAsGas(await tx.wait());
expectedState.Balances.bToken.user += bTokens.toBigInt();
Expand All @@ -160,7 +160,7 @@ describe("Testing BToken Minting methods", async () => {
it("Should fail to mint with big min BToken quantity", async () => {
const oneBToken = ethers.utils.parseUnits("1", 18).toBigInt();
const minBTokens = 900n * oneBToken;
const expectedBTokensMintedForEthValue = "399028731704364116575";
const expectedBTokensMintedForEthValue = "402028731704364116575";
await expect(
fixture.bToken.connect(admin).mint(minBTokens, {
value: ethers.utils.parseEther(eth.toString()),
Expand Down
6 changes: 3 additions & 3 deletions bridge/test/bToken/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ describe("Testing BToken Utils methods", async () => {
let bTokens = await fixture.bToken.getLatestMintedBTokensFromEth(
ethers.utils.parseEther(eth.toString())
);
expect(bTokens).to.be.equal(BigInt("936764568799449143863271"));
expect(bTokens).to.be.equal(BigInt("944264568799449143863271"));
eth = 20000;
bTokens = await fixture.bToken.getLatestMintedBTokensFromEth(
ethers.utils.parseEther(eth.toString())
);
expect(bTokens).to.be.equal(BigInt("1005000000000000000000000"));
expect(bTokens).to.be.equal(BigInt("1020000000000000000000000"));
eth = 25000;
bTokens = await fixture.bToken.getLatestMintedBTokensFromEth(
ethers.utils.parseEther(eth.toString())
);
expect(bTokens).to.be.equal(BigInt("1007899288252135716968558"));
expect(bTokens).to.be.equal(BigInt("1026649288252135716968558"));
});
});
2 changes: 1 addition & 1 deletion bridge/test/math/sigmoid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe("Sigmoid unit tests", async () => {
expect(retC).to.be.equal(trueC);
});
it("P Constant D", async function () {
const trueD = 1;
const trueD = 4;
const retD = await sigmoid.pConstD();
expect(retD).to.be.equal(trueD);
});
Expand Down

0 comments on commit 70ee80d

Please sign in to comment.