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

add ISimpleProvider, IInnerWithdraw, IBeforeTransfer #96

Merged
merged 3 commits into from
Feb 17, 2024
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
12 changes: 12 additions & 0 deletions contracts/CalcUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library CalcUtils {
function calcAmount(uint256 amount, uint256 rate) internal pure returns (uint256 tokenA) {
return (amount * rate) / 1e21;
}

function calcRate(uint256 tokenAValue, uint256 tokenBValue) internal pure returns (uint256 rate) {
return (tokenAValue * 1e21) / tokenBValue;
}
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IBeforeTransfer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IBeforeTransfer {
function beforeTransfer(address from, address to, uint256 poolId) external;
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IInnerWithdraw.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IInnerWithdraw {
function getInnerIdsArray(uint256 poolId) external returns (uint256[] calldata ids);
}
9 changes: 9 additions & 0 deletions contracts/interfaces/ISimpleProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./IProvider.sol";

///@dev Interface for the simple providers
interface ISimpleProvider is IProvider {
function withdraw(uint256 poolId, uint256 amount) external returns (uint256 withdrawnAmount, bool isFinal);
}
16 changes: 16 additions & 0 deletions contracts/mocks/CalcUtilsMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../CalcUtils.sol";

contract CalcUtilsMock {
using CalcUtils for uint256;

function calcAmount(uint256 amount, uint256 rate) external pure returns (uint256 tokenA) {
return amount.calcAmount(rate);
}

function calcRate(uint256 tokenAValue, uint256 tokenBValue) external pure returns (uint256 rate) {
return tokenAValue.calcRate(tokenBValue);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poolzfinance/poolz-helper-v2",
"version": "2.3.3",
"version": "2.3.5",
"description": "A single source of truth of helper contracts used by Poolz.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions test/10_CalcUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ethers } from 'hardhat';
import { deployed } from '../scripts/deploy';
import { CalcUtilsMock } from '../typechain-types';
import { expect } from 'chai';

describe('CalcUtils library tests', function () {
let calcUtils: CalcUtilsMock;
const amount = ethers.utils.parseUnits('100', 18);
const halfRate = ethers.utils.parseUnits('5', 20); // 50%

before(async () => {
calcUtils = await deployed('CalcUtilsMock');
});

it('should Calc Amount', async () => {
expect(await calcUtils.calcAmount(amount, halfRate)).to.equal(amount.div(2));
});

it('should Calc Rate', async () => {
expect(await calcUtils.calcRate(amount.div(2), amount)).to.equal(halfRate);
});
});