Skip to content

Commit 304e86a

Browse files
add ISimpleProvider, IInnerWithdraw, IBeforeTransfer (#96)
* add ISimpleProvider, IInnerWithdraw, IBeforeTransfer * update version * add CalcUtils library
1 parent 863eaf7 commit 304e86a

File tree

7 files changed

+72
-1
lines changed

7 files changed

+72
-1
lines changed

contracts/CalcUtils.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
library CalcUtils {
5+
function calcAmount(uint256 amount, uint256 rate) internal pure returns (uint256 tokenA) {
6+
return (amount * rate) / 1e21;
7+
}
8+
9+
function calcRate(uint256 tokenAValue, uint256 tokenBValue) internal pure returns (uint256 rate) {
10+
return (tokenAValue * 1e21) / tokenBValue;
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
interface IBeforeTransfer {
5+
function beforeTransfer(address from, address to, uint256 poolId) external;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
interface IInnerWithdraw {
5+
function getInnerIdsArray(uint256 poolId) external returns (uint256[] calldata ids);
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "./IProvider.sol";
5+
6+
///@dev Interface for the simple providers
7+
interface ISimpleProvider is IProvider {
8+
function withdraw(uint256 poolId, uint256 amount) external returns (uint256 withdrawnAmount, bool isFinal);
9+
}

contracts/mocks/CalcUtilsMock.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "../CalcUtils.sol";
5+
6+
contract CalcUtilsMock {
7+
using CalcUtils for uint256;
8+
9+
function calcAmount(uint256 amount, uint256 rate) external pure returns (uint256 tokenA) {
10+
return amount.calcAmount(rate);
11+
}
12+
13+
function calcRate(uint256 tokenAValue, uint256 tokenBValue) external pure returns (uint256 rate) {
14+
return tokenAValue.calcRate(tokenBValue);
15+
}
16+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@poolzfinance/poolz-helper-v2",
3-
"version": "2.3.3",
3+
"version": "2.3.5",
44
"description": "A single source of truth of helper contracts used by Poolz.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

test/10_CalcUtils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ethers } from 'hardhat';
2+
import { deployed } from '../scripts/deploy';
3+
import { CalcUtilsMock } from '../typechain-types';
4+
import { expect } from 'chai';
5+
6+
describe('CalcUtils library tests', function () {
7+
let calcUtils: CalcUtilsMock;
8+
const amount = ethers.utils.parseUnits('100', 18);
9+
const halfRate = ethers.utils.parseUnits('5', 20); // 50%
10+
11+
before(async () => {
12+
calcUtils = await deployed('CalcUtilsMock');
13+
});
14+
15+
it('should Calc Amount', async () => {
16+
expect(await calcUtils.calcAmount(amount, halfRate)).to.equal(amount.div(2));
17+
});
18+
19+
it('should Calc Rate', async () => {
20+
expect(await calcUtils.calcRate(amount.div(2), amount)).to.equal(halfRate);
21+
});
22+
});

0 commit comments

Comments
 (0)