Skip to content

Commit 7bdcd47

Browse files
committed
update removeChainlinkPricefeed
1 parent 65809ea commit 7bdcd47

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

contracts/addon/SelfNftAddon.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,14 @@ contract SelfNftAddon is
428428
// Remove the Chainlink price feed for the payment token
429429
chainlinkPriceFeeds[_paymentToken].paymentToken = address(0);
430430

431-
// Transfer the collected tokens to the contract owner if any
431+
// Transfer the collected tokens to the contract owner if any and reset collected tokens
432432
uint _collectedTokens = chainlinkPriceFeeds[_paymentToken]
433433
.collectedTokens;
434434

435-
if (_collectedTokens > 0)
435+
if (_collectedTokens > 0) {
436+
chainlinkPriceFeeds[_paymentToken].collectedTokens = 0;
436437
IERC20(_paymentToken).safeTransfer(msg.sender, _collectedTokens);
438+
}
437439

438440
// Emit an event to log the removal of the Chainlink price feed
439441
emit ChainlinkPriceFeedRemoved(_paymentToken);

test/SelfNftAddon.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,30 @@ describe.only("SelfNftMultitokenAddon", () => {
912912
addon.removeChainlinkPricefeed(usdt.address)
913913
).changeTokenBalance(usdt, owner, parse(price, 6));
914914
});
915+
916+
it("should reset the collectedTokens var", async () => {
917+
// Arrange: Load fixture
918+
const { addon, usdt, usdtPricefeedMock, owner, selfNft } =
919+
await loadFixture(deployAddonSuite);
920+
921+
await usdt.approve(addon.address, parse("1000000", 6));
922+
923+
await addon.registerName("ruwaifa", usdt.address, ZERO_ADDRESS);
924+
925+
const price = await calculateNamePrice(
926+
selfNft,
927+
"ruwaifa",
928+
SELF_PRICE,
929+
USDT_PRICE
930+
);
931+
932+
// Act & Assert: Remove a chainlink pricefeed and verify that the token balance of the owner changes by the collected amount
933+
await addon.removeChainlinkPricefeed(usdt.address);
934+
935+
expect(
936+
(await addon.chainlinkPriceFeeds(usdt.address)).collectedTokens
937+
).to.equal(0);
938+
});
915939
it("should emit the ChainlinkPriceFeedRemoved event", async () => {
916940
// Arrange: Load fixture
917941
const { addon, usdt, usdtPricefeedMock } = await loadFixture(

0 commit comments

Comments
 (0)