From 67761ccf363751e15a3afb295e7befd090105971 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Thu, 15 Feb 2024 16:16:06 +0200 Subject: [PATCH 1/3] add ISimpleProvider, IInnerWithdraw, IBeforeTransfer --- contracts/interfaces/IBeforeTransfer.sol | 6 ++++++ contracts/interfaces/IInnerWithdraw.sol | 6 ++++++ contracts/interfaces/ISimpleProvider.sol | 9 +++++++++ 3 files changed, 21 insertions(+) create mode 100644 contracts/interfaces/IBeforeTransfer.sol create mode 100644 contracts/interfaces/IInnerWithdraw.sol create mode 100644 contracts/interfaces/ISimpleProvider.sol diff --git a/contracts/interfaces/IBeforeTransfer.sol b/contracts/interfaces/IBeforeTransfer.sol new file mode 100644 index 0000000..9f7e66e --- /dev/null +++ b/contracts/interfaces/IBeforeTransfer.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IBeforeTransfer { + function beforeTransfer(address from, address to, uint256 poolId) external; +} \ No newline at end of file diff --git a/contracts/interfaces/IInnerWithdraw.sol b/contracts/interfaces/IInnerWithdraw.sol new file mode 100644 index 0000000..6c8422d --- /dev/null +++ b/contracts/interfaces/IInnerWithdraw.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IInnerWithdraw { + function getInnerIdsArray(uint256 poolId) external returns (uint256[] calldata ids); +} \ No newline at end of file diff --git a/contracts/interfaces/ISimpleProvider.sol b/contracts/interfaces/ISimpleProvider.sol new file mode 100644 index 0000000..fe598f0 --- /dev/null +++ b/contracts/interfaces/ISimpleProvider.sol @@ -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); +} \ No newline at end of file From c96b58c596dd301837da83efd639685e9c765389 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Thu, 15 Feb 2024 17:47:03 +0200 Subject: [PATCH 2/3] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61c13bc..f478679 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poolzfinance/poolz-helper-v2", - "version": "2.3.3", + "version": "2.3.4", "description": "A single source of truth of helper contracts used by Poolz.", "main": "dist/index.js", "types": "dist/index.d.ts", From 5bf4492f417f1480cf44e52a329ba635c72079f7 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 16 Feb 2024 16:33:22 +0200 Subject: [PATCH 3/3] add CalcUtils library --- contracts/CalcUtils.sol | 12 ++++++++++++ contracts/mocks/CalcUtilsMock.sol | 16 ++++++++++++++++ package.json | 2 +- test/10_CalcUtils.ts | 22 ++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 contracts/CalcUtils.sol create mode 100644 contracts/mocks/CalcUtilsMock.sol create mode 100644 test/10_CalcUtils.ts diff --git a/contracts/CalcUtils.sol b/contracts/CalcUtils.sol new file mode 100644 index 0000000..9e87be4 --- /dev/null +++ b/contracts/CalcUtils.sol @@ -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; + } +} diff --git a/contracts/mocks/CalcUtilsMock.sol b/contracts/mocks/CalcUtilsMock.sol new file mode 100644 index 0000000..2438e21 --- /dev/null +++ b/contracts/mocks/CalcUtilsMock.sol @@ -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); + } +} diff --git a/package.json b/package.json index f478679..8a74c8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poolzfinance/poolz-helper-v2", - "version": "2.3.4", + "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", diff --git a/test/10_CalcUtils.ts b/test/10_CalcUtils.ts new file mode 100644 index 0000000..dc2034d --- /dev/null +++ b/test/10_CalcUtils.ts @@ -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); + }); +});