Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions contracts/LastPoolOwnerState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./interfaces/IBeforeTransfer.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
* @title LastPoolOwnerState
* @dev Contract to keep track of the last owner of a Provider pool before a transfer.
*/
abstract contract LastPoolOwnerState is IBeforeTransfer, IERC165 {
// Mapping to store the last owner of each Provider pool before a transfer
mapping(uint256 => address) internal lastPoolOwner;

/**
* @dev Function to be called before a transfer.
* @param from Address from which the transfer is initiated.
* @param to Address to which the transfer is directed.
* @param poolId Identifier of the Provider pool.
*/
function beforeTransfer(address from, address to, uint256 poolId) external virtual override;

/**
* @dev Checks whether a contract supports the specified interface.
* @param interfaceId Interface identifier.
* @return A boolean indicating whether the contract supports the specified interface.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IBeforeTransfer).interfaceId;
}
}
28 changes: 28 additions & 0 deletions contracts/mocks/MockLastPoolOwner.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../LastPoolOwnerState.sol";

/**
* @title MockLastPoolOwner
* @dev Mock contract to keep track of the last owner of a Provider pool before a transfer.
*/
contract MockLastPoolOwner is LastPoolOwnerState {
/**
* @dev Function to be called before a transfer.
* @param from Address from which the transfer is initiated.
* @param poolId Identifier of the Provider pool.
*/
function beforeTransfer(address from, address, uint256 poolId) external override {
lastPoolOwner[poolId] = from;
}

/**
* @dev Function to get the last owner of a Provider pool.
* @param poolId Identifier of the Provider pool.
* @return Address of the last owner of the Provider pool.
*/
function getLastPoolOwner(uint256 poolId) external view returns (address) {
return lastPoolOwner[poolId];
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poolzfinance/poolz-helper-v2",
"version": "3.0.3",
"version": "3.0.4",
"description": "A single source of truth of helper contracts used by Poolz.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
29 changes: 29 additions & 0 deletions test/11_LastPoolOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ethers } from 'hardhat';
import { deployed } from '../scripts/deploy';
import { MockLastPoolOwner } from '../typechain-types';
import { expect } from 'chai';

describe('LastPoolOwner abstract contract', function () {
let lastPoolOwner: MockLastPoolOwner;
const poolId = ethers.parseUnits('100', 18);

before(async () => {
lastPoolOwner = await deployed('MockLastPoolOwner');
});

it('should support IBeforeTransfer interface', async () => {
const IBeforeTransferInterfaceId = '0x1ffb811f';
expect(await lastPoolOwner.supportsInterface(IBeforeTransferInterfaceId)).to.equal(true);
});

it('should support IERC165 interface', async () => {
const IERC165InterfaceId = '0x01ffc9a7';
expect(await lastPoolOwner.supportsInterface(IERC165InterfaceId)).to.equal(true);
});

it('should return lastPoolOwner', async () => {
const [addr0] = await ethers.getSigners();
await lastPoolOwner.beforeTransfer(addr0.address, addr0.address, poolId);
expect(await lastPoolOwner.getLastPoolOwner(poolId)).to.equal(addr0.address);
});
});