Skip to content

Commit 3a530ca

Browse files
committed
fix: add minPegIn getter
1 parent 2b7f2e0 commit 3a530ca

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

contracts/PegInContract.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ contract PegInContract is
5555
/// @param newThreshold The new dust threshold
5656
event DustThresholdSet(uint256 indexed oldThreshold, uint256 indexed newThreshold);
5757

58+
/// @notice Emitted when the minimum peg in amount is set
59+
/// @param oldMinPegIn The old minimum peg in amount
60+
/// @param newMinPegIn The new minimum peg in amount
61+
event MinPegInSet(uint256 indexed oldMinPegIn, uint256 indexed newMinPegIn);
62+
5863
// solhint-disable-next-line comprehensive-interface
5964
receive() external payable {
6065
if (msg.sender != address(_bridge)) {
@@ -111,6 +116,15 @@ contract PegInContract is
111116
dustThreshold = threshold;
112117
}
113118

119+
/// @notice This function is used to set the minimum peg in amount
120+
/// @param minPegIn the new minimum peg in amount
121+
/// @dev This function is only callable by the owner of the contract
122+
// solhint-disable-next-line comprehensive-interface
123+
function setMinPegIn(uint256 minPegIn) external onlyOwner {
124+
emit MinPegInSet(_minPegIn, minPegIn);
125+
_minPegIn = minPegIn;
126+
}
127+
114128
/// @inheritdoc IPegIn
115129
function deposit() external payable override {
116130
if(!_collateralManagement.isRegistered(_PEG_TYPE, msg.sender)) {
@@ -252,6 +266,11 @@ contract PegInContract is
252266
return BtcUtils.validateP2SHAdress(depositAddress, flyoverRedeemScript, _mainnet);
253267
}
254268

269+
/// @inheritdoc IPegIn
270+
function getMinPegIn() external view override returns (uint256) {
271+
return _minPegIn;
272+
}
273+
255274
/// @inheritdoc IPegIn
256275
function getBalance(address addr) external view override returns (uint256) {
257276
return _balances[addr];

contracts/interfaces/IPegIn.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,8 @@ interface IPegIn {
158158
/// @param quote The quote of the peg in
159159
/// @return quoteHash The hash of the quote
160160
function hashPegInQuote(Quotes.PegInQuote calldata quote) external view returns (bytes32);
161+
162+
/// @notice This function is used to get the minimum peg in amount allowed by the protocol
163+
/// @return minPegIn The minimum peg in amount
164+
function getMinPegIn() external view returns (uint256);
161165
}

test/pegin/configuration.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ describe("PegInContract configurations", () => {
3535
await expect(contract.dustThreshold()).to.eventually.eq(
3636
PEGIN_CONSTANTS.TEST_DUST_THRESHOLD
3737
);
38+
await expect(contract.getMinPegIn()).to.eventually.eq(
39+
PEGIN_CONSTANTS.TEST_MIN_PEGIN
40+
);
3841
await expect(contract.owner()).to.eventually.eq(owner.address);
3942
await expect(contract.getFeePercentage()).to.eventually.eq(0n);
4043
await expect(contract.getFeeCollector()).to.eventually.eq(ZERO_ADDRESS);
@@ -150,4 +153,24 @@ describe("PegInContract configurations", () => {
150153
.withArgs(initializationParams[4], otherContract);
151154
});
152155
});
156+
describe("setMinPegIn function should", function () {
157+
it("only allow the owner to modify the minimum peg in amount", async function () {
158+
const { contract, signers } = await loadFixture(
159+
deployPegInContractFixture
160+
);
161+
const notOwner = signers[0];
162+
await expect(
163+
contract.connect(notOwner).setMinPegIn(1n)
164+
).to.be.revertedWithCustomError(contract, "OwnableUnauthorizedAccount");
165+
});
166+
167+
it("modify the minimum peg in amount properly", async function () {
168+
const { contract, owner } = await loadFixture(deployPegInContractFixture);
169+
const tx = contract.connect(owner).setMinPegIn(1n);
170+
await expect(tx)
171+
.to.emit(contract, "MinPegInSet")
172+
.withArgs(PEGIN_CONSTANTS.TEST_MIN_PEGIN, 1n);
173+
await expect(contract.getMinPegIn()).to.eventually.eq(1n);
174+
});
175+
});
153176
});

0 commit comments

Comments
 (0)