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

[VEN-1462]: Risk Fund and XVS Converter #9

Merged
merged 213 commits into from
Jan 24, 2024
Merged
Changes from 4 commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
f473ffc
refactor: removed duplicate folders and files
Debugger022 Jul 17, 2023
89138f0
upgrade: oracle dependency verion
Debugger022 Jul 18, 2023
848271f
feat: absract token transformer
Debugger022 Jul 18, 2023
08d449b
feat: risk fund contract
Debugger022 Jul 18, 2023
89c4bf8
feat: ven-1471 risk fund transformer
Debugger022 Jul 18, 2023
6a90a8a
tests: ven-1471 risk fund transformer
Debugger022 Jul 18, 2023
78c27c7
refactor: upgrade oracle dependency version
Debugger022 Jul 18, 2023
b380587
refactor: risk fund storage layout
Debugger022 Jul 19, 2023
443eedb
refactor: folder and files structure
Debugger022 Jul 19, 2023
57a465e
refactor: changes name from swap to transform
Debugger022 Jul 19, 2023
23b6698
refactor: files names
Debugger022 Jul 19, 2023
f18c2a0
refactor: ven-1748 risk fund V2
Debugger022 Jul 19, 2023
a2ddf1e
tests: ven-1748 riskfund unit tests
Debugger022 Jul 20, 2023
8319971
feat: ven-1472 xvs vault transformer
Debugger022 Jul 21, 2023
cf8f101
feat: ven-1473 xvs vault treasury
Debugger022 Jul 21, 2023
66b33fe
refactor: added preSweepToken and updateAssetsPrice
Debugger022 Jul 24, 2023
ecbb1ab
fix: pr comments
Debugger022 Jul 25, 2023
c3f500e
refactor: abstract transformer
Debugger022 Jul 26, 2023
1f7fa40
refactor: RiskFund and AbstractTransformer
Debugger022 Jul 26, 2023
6622481
refactor: remove redundant reading of assetsReserves storage
Debugger022 Jul 26, 2023
3b21bc7
fix: get amount method
Debugger022 Jul 26, 2023
f64f521
tests: fixed transformer tests
Debugger022 Jul 27, 2023
759887a
wip
Debugger022 Jul 27, 2023
a348fc0
tests: ven-1785 getAmount() risk fund transformer
Debugger022 Jul 31, 2023
631c1a9
tests: ven-1785 risk fund transformer
Debugger022 Aug 1, 2023
e80fbf4
refactor: abstract transformer tests
Debugger022 Aug 2, 2023
e45db93
refactor: added reserve helpers methods
Debugger022 Aug 3, 2023
3743f49
fix: lint issues
Debugger022 Aug 3, 2023
20ccc98
refactor: ven-1790 transformer to converter
Debugger022 Aug 3, 2023
caf7c41
fix: updatedsolidity-coverage depedency package
Debugger022 Aug 4, 2023
628a46c
Merge branch 'develop' into feat/passive-swap
Debugger022 Aug 4, 2023
b6ba439
update: yarn.lock
Debugger022 Aug 4, 2023
cbb1651
fix: gas optimization for riskfundv2
Debugger022 Aug 16, 2023
81bfa06
fix: pr comments
Debugger022 Aug 16, 2023
1d037fd
merge branch 'develop' into feat/passive-swap
Debugger022 Aug 16, 2023
57dceb0
feat: ven-1827 added core pool in risk fund converter
Debugger022 Aug 16, 2023
91bbfbb
feat: ven-1828 added sweep token in risk fund
Debugger022 Aug 16, 2023
a8068a7
tests: ven-1827 added core pool in the risk fund
Debugger022 Aug 16, 2023
64218e3
tests: ven-1828 added sweepToken method for risk fund v2
Debugger022 Aug 16, 2023
bbaf19a
feat: ven-1834 functionality for multiple assets in risk fund
Debugger022 Aug 17, 2023
e9a5c0f
refactor: undo base asset changes
Debugger022 Aug 18, 2023
46cd2cb
feat: added setter for the direct transfer assets for riskfund
Debugger022 Aug 18, 2023
e1bd562
refactor: ensure market listed in any pool
Debugger022 Aug 18, 2023
5cc6107
refactor: risk fund storage
Debugger022 Aug 18, 2023
0fb7f1d
Merge pull request #12 from VenusProtocol/VEN-1827/1828
Debugger022 Aug 20, 2023
d4240a0
refactor: is market listed for core pool logic
Debugger022 Aug 21, 2023
e766511
refactor: added functionality to set false in pool assets direct tran…
Debugger022 Aug 23, 2023
3d64345
fix: pr comments
Debugger022 Aug 24, 2023
3ca655c
Merge pull request #13 from VenusProtocol/fix/ven-1827
Debugger022 Aug 25, 2023
d099e97
tests: refactor converter fork tests
Debugger022 Aug 25, 2023
255e01a
fix: fork tests for risk fund converter
Debugger022 Aug 28, 2023
6871238
fix: make comptroller and vBNB immutable
Debugger022 Aug 29, 2023
1a41ef5
feat: support for native wrapped token
Debugger022 Aug 29, 2023
571b3bb
Merge pull request #15 from VenusProtocol/fix/ven-1827
chechu Aug 29, 2023
a314d49
Merge branch 'develop' into feat/passive-swap
chechu Aug 29, 2023
cc3d674
refactor: fixing the order of functions following linter
chechu Aug 29, 2023
f05bba5
refactor: isMarketListed method
Debugger022 Sep 1, 2023
a45d994
tests: fork tests for resume/pause and set oracle in conversion
Debugger022 Sep 1, 2023
aee3c6c
feat: ven-1883 deployment script for riskFundConverter
Debugger022 Sep 1, 2023
cdf4466
fix: resolved merge conflicts
Debugger022 Sep 3, 2023
14d56fb
fix: postConversionHook error
Debugger022 Sep 3, 2023
22865a0
tests: fork tests for native wrapped tokens
Debugger022 Sep 3, 2023
15c252d
fix: post conversion hook bug
Debugger022 Sep 4, 2023
26e3828
feat: add getters for getAmountIn and getAmountOut
Debugger022 Sep 8, 2023
7fd547e
fix: n1
Debugger022 Sep 9, 2023
2d18458
fix: n2
Debugger022 Sep 9, 2023
624b0f1
fix: n3
Debugger022 Sep 9, 2023
a1e6697
fix: pve-001
Debugger022 Sep 9, 2023
fd20124
fix: pve-002
Debugger022 Sep 9, 2023
74f9cb2
fix: pve-005
Debugger022 Sep 9, 2023
92342eb
fix: pve-003
Debugger022 Sep 9, 2023
057dcee
fix: pve-003-2
Debugger022 Sep 9, 2023
3de3561
Merge pull request #17 from VenusProtocol/VEN-1911
Debugger022 Sep 11, 2023
5d1c6b3
fix: added miannet addresses in the convertor script
Debugger022 Sep 11, 2023
0e46af5
Merge pull request #16 from VenusProtocol/VEN-1882/1883
Debugger022 Sep 11, 2023
87f0532
merge branch 'feat/passive-swap' into feat/abstract-token-converter-g…
Debugger022 Sep 11, 2023
a0d3f2a
fix: pr comments
Debugger022 Sep 11, 2023
ca8f8ba
Merge pull request #19 from VenusProtocol/feat/abstract-token-convert…
Debugger022 Sep 11, 2023
b467b46
fix:ven-2007 l-01
Debugger022 Sep 26, 2023
0f58716
fix: ven-2007 l-02
Debugger022 Sep 26, 2023
a555053
fix: ven-2007 l-04
Debugger022 Sep 26, 2023
e558b15
fix: ven-2007 l-06
Debugger022 Sep 26, 2023
5d0f03b
fix: ven-2007 n-01
Debugger022 Sep 26, 2023
91eb7a6
fix: ven-2007 n-02
Debugger022 Sep 26, 2023
1e367e1
fix: ven-2007 n-03
Debugger022 Sep 26, 2023
8d6389c
fix: ven-2007 n-04
Debugger022 Sep 26, 2023
8227f4b
fix: ven-2007 n-06
Debugger022 Sep 26, 2023
78150be
fix: ven-2007 n-09
Debugger022 Sep 27, 2023
bda9bea
fix: ven-2007 n-08
Debugger022 Sep 27, 2023
3876d3b
fix: ven-2007 n-10
Debugger022 Sep 27, 2023
2be108d
fix: ven-2007 l-08
Debugger022 Sep 27, 2023
35dc0a1
fix: ven-2007 l-05
Debugger022 Sep 27, 2023
4025db0
fix: ven-2007 m-01
Debugger022 Sep 27, 2023
939da0a
fix: ven-2007 m-02
Debugger022 Sep 27, 2023
a842667
fix: ven-2007 l-03
Debugger022 Sep 27, 2023
7c18feb
fix: minor fixes
Debugger022 Sep 28, 2023
39eea6f
refactor: used unchecked for variables and added netspec for events
Debugger022 Oct 3, 2023
08bacb3
fix: ven-2007 n-07
Debugger022 Oct 3, 2023
9c2d122
Merge pull request #24 from VenusProtocol/VEN-2007
Debugger022 Oct 3, 2023
e5ad0df
fix: resolved conflicts
Debugger022 Oct 4, 2023
a71fe6f
fix: ATC-05
Debugger022 Oct 11, 2023
ecc0c21
fix: VPB-04
Debugger022 Oct 11, 2023
2848374
fix: VPB-05
Debugger022 Oct 11, 2023
20cd1b1
fix: VPB-12
Debugger022 Oct 11, 2023
83e5e1b
fix: RFC-04
Debugger022 Oct 11, 2023
42e67b7
fix: RFV-06
Debugger022 Oct 11, 2023
17a377c
fix: VPB-03
Debugger022 Oct 11, 2023
f76345d
fix: ATC-01
Debugger022 Oct 11, 2023
9f579b1
fix: TCV-01
Debugger022 Oct 11, 2023
06914bd
fix: RFC-02
Debugger022 Oct 11, 2023
df2eeb4
fix: VPB-10
Debugger022 Oct 11, 2023
e991342
fix: VPB-14
Debugger022 Oct 12, 2023
ade9bda
fix: VPB-01
Debugger022 Oct 12, 2023
cf5e371
fix: RFV-03
Debugger022 Oct 12, 2023
e37341c
fix: ATC-04
Debugger022 Oct 12, 2023
b04357d
fix: VPB-06
Debugger022 Oct 16, 2023
1c558e8
fix: ATC-04
Debugger022 Oct 16, 2023
9145119
fix: VPB-09
Debugger022 Oct 16, 2023
dc70688
fix: pr comments
Debugger022 Oct 16, 2023
6205aac
refactor: updated deployment script for riskFundConverter
Debugger022 Oct 16, 2023
a5caf65
fix: ATC-03
Debugger022 Oct 18, 2023
b8e3e7b
fix: VPB-13
Debugger022 Oct 18, 2023
91402dc
refactor: VEN-2064
Debugger022 Oct 18, 2023
7f289d0
refactor: added some checks for the non supporting fee tokens
Debugger022 Oct 20, 2023
df13780
refactor: updated function names and getters for token amount to not …
Debugger022 Oct 23, 2023
98779f0
refactor: updated deployment script to add poolLiquidStakedBNB
Debugger022 Oct 23, 2023
bcf659b
chore: updated natspec comments for AbstractTokenConverter
Debugger022 Oct 25, 2023
188562d
feat: added ConverterNetwork contract and tests
Debugger022 Oct 26, 2023
268a107
feat: added private conversion functionality
Debugger022 Oct 26, 2023
fa43b9a
refactor: added checks for private conversion
Debugger022 Oct 27, 2023
e139c4b
refactor: added or updated some checks for the token converter
Debugger022 Oct 27, 2023
2d3c3f8
tests: added integration tests for converter and converterNetwork
Debugger022 Oct 27, 2023
108897b
tests: added tests for checks in token converter
Debugger022 Oct 30, 2023
7458733
fixup: VPB-03
Debugger022 Oct 31, 2023
b483870
fixup: VPB-06
Debugger022 Oct 31, 2023
d0c5d17
fixup: VPU-01
Debugger022 Oct 31, 2023
f2021e5
fixup: ATC-06
Debugger022 Oct 31, 2023
24aa165
tests: added ut for private conversions
Debugger022 Nov 1, 2023
cd353bd
fix: resolved merge conflicts
Debugger022 Nov 1, 2023
edd7361
fixup: undo ATC-06
Debugger022 Nov 1, 2023
3e60089
fix: resolve comments
Debugger022 Nov 1, 2023
5e6aa8b
fix: merge conflicts
Debugger022 Nov 2, 2023
176a6f5
fix: pr comments
Debugger022 Nov 2, 2023
921b5d8
refactor: added states for conversion accessibility
Debugger022 Nov 5, 2023
3aebab5
Merge pull request #29 from VenusProtocol/VEN-2043
Debugger022 Nov 6, 2023
23d4e99
fix: pr comments
Debugger022 Nov 6, 2023
f8a8179
fix: TCP-04
Debugger022 Nov 9, 2023
cdd9e14
fix: TCP-05
Debugger022 Nov 9, 2023
11352cd
fix: ATT-02
Debugger022 Nov 9, 2023
abe7ead
fix: ATT-01
Debugger022 Nov 9, 2023
f52d56a
fix: CNC-02
Debugger022 Nov 9, 2023
2ba7503
fix: CNC-04
chechu Nov 20, 2023
73bc544
fix: TCP-06
Debugger022 Nov 21, 2023
f4c8d1e
fix: TCP-03
Debugger022 Nov 21, 2023
72e1b37
fix: add reentrancy guard to getPoolAssetReserve function
Debugger022 Nov 22, 2023
8467d36
Merge pull request #38 from VenusProtocol/VEN-2140
Debugger022 Nov 22, 2023
3a6c78e
refactor: gas optimizations
Debugger022 Nov 23, 2023
c8588a0
fix: ATT-02
Debugger022 Nov 23, 2023
8b8c5a1
tests: added tests for quicksort
Debugger022 Nov 24, 2023
dd07dae
Merge pull request #40 from VenusProtocol/fix/VEN-2140
chechu Nov 27, 2023
23662c0
fix: resolved merge conflicts
Debugger022 Nov 29, 2023
b9c63a8
Merge branch 'develop' into feat/passive-swap
Debugger022 Nov 29, 2023
b176ddb
fix: pr comments
Debugger022 Dec 4, 2023
8d8f8c7
fix: pr comments
Debugger022 Dec 4, 2023
9a915e7
Merge branch 'develop' into feat/passive-swap
Debugger022 Dec 4, 2023
4d93597
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 5, 2023
5088e0f
fix: convertForExactTokens bug regarding deflationary token
Debugger022 Dec 5, 2023
e6578b3
test: added commented tests for convertForExactTokensSupportingFeeOnT…
Debugger022 Dec 5, 2023
d550be6
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 5, 2023
1af57c2
fix: N-01
Debugger022 Dec 6, 2023
b1244b3
fix: N-02
Debugger022 Dec 6, 2023
9994f12
fix: N-03
Debugger022 Dec 6, 2023
a265d02
fix: N-07
Debugger022 Dec 7, 2023
af3d4fc
fix: N-04
Debugger022 Dec 7, 2023
ae9e07b
fix: N-05
Debugger022 Dec 7, 2023
84cbf18
fix: N-06
Debugger022 Dec 7, 2023
52eb722
fix: L-01
Debugger022 Dec 7, 2023
6b6e9e4
fix: L-02
Debugger022 Dec 7, 2023
6bd7f9a
fix: L-03
Debugger022 Dec 7, 2023
f7dd3a2
refactor: remove immutability from baseAsset
Debugger022 Dec 7, 2023
f3e40c3
fix: L-04
Debugger022 Dec 7, 2023
166d40b
fix: minor fixes
Debugger022 Dec 7, 2023
554d804
fix: pr comments
Debugger022 Dec 7, 2023
6286a0a
feat: add deployment scripts for converters, ConverterNetwork and XVS…
Debugger022 Dec 8, 2023
baf6dfb
feat: add conversion config method for setting configs in batch
Debugger022 Dec 11, 2023
8ef869a
fix: pr comments
Debugger022 Dec 13, 2023
66d11be
Merge branch 'develop' into feat/passive-swap
Debugger022 Dec 13, 2023
136714d
Merge branch 'feat/passive-swap' into feat/private-conversions
Debugger022 Dec 13, 2023
1b16c45
Merge branch 'feat/private-conversions' into VEN-2226
Debugger022 Dec 13, 2023
511c89d
refactor: variable name in singleTokenConverter deployment script and…
Debugger022 Dec 13, 2023
fc27510
Merge pull request #48 from VenusProtocol/VEN-2226
Debugger022 Dec 18, 2023
27569a3
Merge pull request #35 from VenusProtocol/feat/private-conversions
Debugger022 Dec 18, 2023
34ca45a
feat: updating deployment files
Debugger022 Dec 18, 2023
5468dc9
fix: deployment scripts and updated deployment files
Debugger022 Dec 19, 2023
13813be
feat: updating deployment files
Debugger022 Dec 19, 2023
22a231a
fix: N-05
Debugger022 Dec 22, 2023
605f5b6
refactor: replace conditional check with ensureNonzeroAddress function
Debugger022 Dec 22, 2023
2339328
fix: pr comments
Debugger022 Jan 9, 2024
7b31bf4
Merge branch 'develop' into feat/passive-swap
Debugger022 Jan 9, 2024
2ba62d3
refactor: deployment scripts to be compatible for non-live networks
Debugger022 Jan 9, 2024
781890c
refactor: replace local file validators with solidity-utilities function
Debugger022 Jan 10, 2024
343dd16
Merge pull request #52 from VenusProtocol/fix/oz-audit-private-conver…
Debugger022 Jan 10, 2024
2abea71
feat: add deployment files for bsc mainnet
Debugger022 Jan 11, 2024
45481a3
feat: updating deployment files
Debugger022 Jan 11, 2024
bbb9661
refactor: updated addresses in deployment files for bsc testnet
Debugger022 Jan 11, 2024
7f148a9
feat: updating deployment files
Debugger022 Jan 11, 2024
72ebb08
refactor: add comment in hardhat config about preventing deployment e…
Debugger022 Jan 12, 2024
768a392
feat: sweep token for pools
Debugger022 Jan 22, 2024
f31dc8b
docs: add audit reports for token converter and private conversions
chechu Jan 22, 2024
f11b8e9
fixup! : update method name SweepTokenToPool to SweepTokenFromPool
Debugger022 Jan 23, 2024
6be027e
fixup! : riskFundV2 natspec
Debugger022 Jan 24, 2024
7bd2a5e
Merge pull request #58 from VenusProtocol/refactor/sweep-token
Debugger022 Jan 24, 2024
e5b95c4
Merge branch 'develop' into feat/passive-swap
Debugger022 Jan 24, 2024
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
14 changes: 14 additions & 0 deletions contracts/Test/Mocks/MockArraySorter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
import { sort } from "../../Utils/ArrayHelpers.sol";

contract MockArraySorter {
function sortArray(uint256[] memory balances, address[] memory addrs)
external
view
returns (address[] memory, uint256[] memory)
{
sort(balances, addrs);
return (addrs, balances);
}
}
11 changes: 11 additions & 0 deletions contracts/TokenConverter/AbstractTokenConverter.sol
Debugger022 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -206,6 +206,9 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
/// @notice When address of the ConverterNetwork is not set or Zero address
error InvalidConverterNetwork();

/// @notice Thrown when trying to set non zero incentive for private conversion
error NonZeroIncentiveForPrivateConversion();

/// @notice Pause conversion of tokens
/// @custom:event Emits ConversionPaused on success
/// @custom:error ConversionTokensPaused thrown when conversion is already paused
@@ -259,6 +262,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
/// @custom:event Emits ConversionConfigUpdated event on success
/// @custom:error Unauthorized error is thrown when the call is not authorized by AccessControlManager
/// @custom:error ZeroAddressNotAllowed is thrown when pool registry address is zero
/// @custom:error NonZeroIncentiveForPrivateConversion is thrown when incentive is non zero for private conversion
/// @custom:access Controlled by AccessControlManager
function setConversionConfig(
address tokenAddressIn,
@@ -281,6 +285,13 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
revert InvalidTokenConfigAddresses();
}

if (
(conversionConfig.conversionAccess == ConversionAccessibility.ONLY_FOR_CONVERTERS) &&
conversionConfig.incentive != 0
) {
revert NonZeroIncentiveForPrivateConversion();
}

if (
((conversionConfig.conversionAccess == ConversionAccessibility.ONLY_FOR_CONVERTERS) ||
(conversionConfig.conversionAccess == ConversionAccessibility.ALL)) &&
21 changes: 11 additions & 10 deletions contracts/TokenConverter/ConverterNetwork.sol
Original file line number Diff line number Diff line change
@@ -180,22 +180,27 @@ contract ConverterNetwork is IConverterNetwork, AccessControlledV8, MaxLoopsLimi

for (uint128 i; i < convertersLength; ) {
IAbstractTokenConverter converter = allConverters[i];

unchecked {
++i;
}

if (msg.sender == address(converter)) {
continue;
}

(, IAbstractTokenConverter.ConversionAccessibility conversionAccess) = converter.conversionConfigurations(
_tokenAddressIn,
_tokenAddressOut
);

if (
(conversionAccess == IAbstractTokenConverter.ConversionAccessibility.ALL) &&
(msg.sender != address(converter))
) {
if (conversionAccess == IAbstractTokenConverter.ConversionAccessibility.ALL) {
converters[count] = address(converter);
convertersBalance[count] = converter.balanceOf(_tokenAddressOut);
++count;
} else if (
forConverters &&
(conversionAccess == IAbstractTokenConverter.ConversionAccessibility.ONLY_FOR_CONVERTERS) &&
(msg.sender != address(converter))
(conversionAccess == IAbstractTokenConverter.ConversionAccessibility.ONLY_FOR_CONVERTERS)
) {
converters[count] = address(converter);
convertersBalance[count] = converter.balanceOf(_tokenAddressOut);
@@ -207,10 +212,6 @@ contract ConverterNetwork is IConverterNetwork, AccessControlledV8, MaxLoopsLimi
convertersBalance[count] = converter.balanceOf(_tokenAddressOut);
++count;
}

unchecked {
++i;
}
}

// Resize the array to the actual number of matching converters
27 changes: 19 additions & 8 deletions tests/TokenConverter/AbstractTokenConverter.ts
Original file line number Diff line number Diff line change
@@ -155,8 +155,8 @@ describe("MockConverter: tests", () => {

it("Revert for user if onlyForPrivateConversion is enabled", async () => {
const updatedConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};
await converter.setConversionConfig(tokenIn.address, tokenOut.address, updatedConfig);

@@ -237,8 +237,8 @@ describe("MockConverter: tests", () => {

it("Revert for user if onlyForPrivateConversion is enabled", async () => {
const updatedConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};
await converter.setConversionConfig(tokenIn.address, tokenOut.address, updatedConfig);

@@ -346,8 +346,8 @@ describe("MockConverter: tests", () => {

it("Revert for user if onlyForPrivateConversion is enabled", async () => {
const updatedConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};
await converter.setConversionConfig(tokenInDeflationary.address, tokenOut.address, updatedConfig);

@@ -425,7 +425,7 @@ describe("MockConverter: tests", () => {

it("Revert for user if onlyForPrivateConversion is enabled", async () => {
const updatedConfig = {
incentive: INCENTIVE,
incentive: 0,
conversionAccess: 2,
};
await converter.setConversionConfig(tokenIn.address, tokenOut.address, updatedConfig);
@@ -487,6 +487,17 @@ describe("MockConverter: tests", () => {
).to.be.revertedWithCustomError(converter, "IncentiveTooHigh");
});

it("Revert on non zero incentive for private conversion", async () => {
const ConverterConfig = {
...ConversionConfig,
conversionAccess: 2,
};

await expect(
converter.setConversionConfig(tokenIn.address, tokenOut.address, ConverterConfig),
).to.be.revertedWithCustomError(converter, "NonZeroIncentiveForPrivateConversion");
});

it("Set converter config for first time", async () => {
let isExist = await converter.conversionConfigurations(tokenIn.address, tokenOut.address);

@@ -528,13 +539,13 @@ describe("MockConverter: tests", () => {
expect(value[1]).to.equal(1);

const ConverterConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};

await expect(converter.setConversionConfig(tokenIn.address, tokenOut.address, ConverterConfig))
.to.emit(converter, "ConversionConfigUpdated")
.withArgs(tokenIn.address, tokenOut.address, INCENTIVE, INCENTIVE, 1, 2);
.withArgs(tokenIn.address, tokenOut.address, INCENTIVE, 0, 1, 2);

value = await converter.conversionConfigurations(tokenIn.address, tokenOut.address);
expect(value[1]).to.equal(2);
@@ -605,8 +616,8 @@ describe("MockConverter: tests", () => {

it("Revert on onlyForPrivateConversions enabled", async () => {
const updatedConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};
await converter.setConversionConfig(tokenIn.address, tokenOut.address, updatedConfig);

@@ -674,8 +685,8 @@ describe("MockConverter: tests", () => {

it("Revert on onlyForPrivateConversions enabled", async () => {
const updatedConfig = {
...ConversionConfig,
conversionAccess: 2,
incentive: 0,
};
await converter.setConversionConfig(tokenIn.address, tokenOut.address, updatedConfig);

78 changes: 78 additions & 0 deletions tests/TokenConverter/Quicksort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { MockContract, smock } from "@defi-wonderland/smock";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import chai from "chai";
import { ethers } from "hardhat";
import { Address } from "hardhat-deploy/dist/types";

import { MockArraySorter, MockArraySorter__factory } from "../../typechain";
import { convertToUnit } from "../utils";

const { expect } = chai;
chai.use(smock.matchers);

let mockArraySorter: MockContract<MockArraySorter>;
let user1Address: Address;
let user2Address: Address;
let user3Address: Address;
let user4Address: Address;
let user5Address: Address;
let user1Balance: string = convertToUnit("3", 18);
let user2Balance: string = convertToUnit("2", 18);
let user3Balance: string = convertToUnit("3", 18);
let user4Balance: string = convertToUnit("0.5", 18);
let user5Balance: string = convertToUnit("0.1", 18);

async function fixture(): Promise<void> {
const [, user1, user2, user3, user4, user5] = await ethers.getSigners();
user1Address = user1.address;
user2Address = user2.address;
user3Address = user3.address;
user4Address = user4.address;
user5Address = user5.address;

const MockArraySorterFactory = await smock.mock<MockArraySorter__factory>("MockArraySorter");
mockArraySorter = await MockArraySorterFactory.deploy();
}

describe("Quicksort Tests", () => {
let addrsArray;
let balancesArray;

beforeEach(async () => {
await loadFixture(fixture);
addrsArray = [user1Address, user2Address, user3Address, user4Address, user5Address];
balancesArray = [user1Balance, user2Balance, user3Balance, user4Balance, user5Balance];
});

it("Should sort multiple addresses correctly corresponding to their balances", async () => {
let resultArray = await mockArraySorter.sortArray(balancesArray, addrsArray);

let expectedAddressesResult = [user1Address, user3Address, user2Address, user4Address, user5Address];
let expectedBalancesResult = [user1Balance, user3Balance, user2Balance, user4Balance, user5Balance];

expect(resultArray[0]).to.deep.equal(expectedAddressesResult);
expect(resultArray[1]).to.deep.equal(expectedBalancesResult);

user1Balance = convertToUnit("10", 18);
user2Balance = convertToUnit("16", 18);
addrsArray = [user1Address, user2Address];
balancesArray = [user1Balance, user2Balance];

resultArray = await mockArraySorter.sortArray(balancesArray, addrsArray);
expectedAddressesResult = [user2Address, user1Address];
expectedBalancesResult = [user2Balance, user1Balance];

expect(resultArray[0]).to.deep.equal(expectedAddressesResult);
expect(resultArray[1]).to.deep.equal(expectedBalancesResult);

user1Balance = user2Balance = user3Balance = user4Balance = user5Balance = convertToUnit("8", 18);

balancesArray = [user1Balance, user2Balance, user3Balance, user4Balance, user5Balance];
addrsArray = [user1Address, user2Address, user3Address, user4Address, user5Address];

resultArray = await mockArraySorter.sortArray(balancesArray, addrsArray);

expect(resultArray[0]).to.deep.equal(addrsArray);
expect(resultArray[1]).to.deep.equal(balancesArray);
});
});