Skip to content

Commit

Permalink
Feat/improve position mover (#422)
Browse files Browse the repository at this point in the history
* feat: add to support for moving bendao position

Signed-off-by: GopherJ <[email protected]>

* fix: tests

Signed-off-by: GopherJ <[email protected]>

* fix: the import path of ScaledBalanceTokenBaseERC20

---------

Signed-off-by: GopherJ <[email protected]>
Co-authored-by: jfzhou5 <[email protected]>
  • Loading branch information
GopherJ and jfzhou5 authored Nov 1, 2023
1 parent eb89afb commit 763902c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
5 changes: 4 additions & 1 deletion contracts/interfaces/IPoolPositionMover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {ApeCoinStaking} from "../dependencies/yoga-labs/ApeCoinStaking.sol";
* @notice Defines the basic interface for an ParaSpace Pool.
**/
interface IPoolPositionMover {
function movePositionFromBendDAO(uint256[] calldata loanIds) external;
function movePositionFromBendDAO(
uint256[] calldata loanIds,
address to
) external;

//# Migration step
//
Expand Down
23 changes: 15 additions & 8 deletions contracts/protocol/libraries/logic/PositionMoverLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ library PositionMoverLogic {
IPoolAddressesProvider poolAddressProvider,
ILendPoolLoan lendPoolLoan,
ILendPool lendPool,
uint256[] calldata loandIds
uint256[] calldata loandIds,
address to
) external {
BendDAOPositionMoverVars memory tmpVar;

Expand All @@ -97,7 +98,7 @@ library PositionMoverLogic {
loandIds[index]
);

supplyNFTandBorrowWETH(ps, poolAddressProvider, tmpVar);
supplyNFTandBorrowWETH(ps, poolAddressProvider, tmpVar, to);

emit PositionMovedFromBendDAO(
tmpVar.nftAsset,
Expand Down Expand Up @@ -143,8 +144,14 @@ library PositionMoverLogic {
function supplyNFTandBorrowWETH(
DataTypes.PoolStorage storage ps,
IPoolAddressesProvider poolAddressProvider,
BendDAOPositionMoverVars memory tmpVar
BendDAOPositionMoverVars memory tmpVar,
address to
) internal {
require(
to == msg.sender || IAccount(to).owner() == msg.sender,
Errors.NOT_THE_OWNER
);

DataTypes.ERC721SupplyParams[]
memory tokenData = new DataTypes.ERC721SupplyParams[](1);
tokenData[0] = DataTypes.ERC721SupplyParams({
Expand All @@ -154,11 +161,11 @@ library PositionMoverLogic {

SupplyLogic.executeSupplyERC721(
ps._reserves,
ps._usersConfig[msg.sender],
ps._usersConfig[to],
DataTypes.ExecuteSupplyERC721Params({
asset: tmpVar.nftAsset,
tokenData: tokenData,
onBehalfOf: msg.sender,
onBehalfOf: to,
payer: msg.sender,
referralCode: 0x0
})
Expand All @@ -167,11 +174,11 @@ library PositionMoverLogic {
BorrowLogic.executeBorrow(
ps._reserves,
ps._reservesList,
ps._usersConfig[msg.sender],
ps._usersConfig[to],
DataTypes.ExecuteBorrowParams({
asset: tmpVar.weth,
user: msg.sender,
onBehalfOf: msg.sender,
user: to,
onBehalfOf: to,
amount: tmpVar.borrowAmount,
referralCode: 0x0,
releaseUnderlying: false,
Expand Down
6 changes: 4 additions & 2 deletions contracts/protocol/pool/PoolPositionMover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ contract PoolPositionMover is
}

function movePositionFromBendDAO(
uint256[] calldata loanIds
uint256[] calldata loanIds,
address to
) external nonReentrant {
DataTypes.PoolStorage storage ps = poolStorage();

Expand All @@ -83,7 +84,8 @@ contract PoolPositionMover is
ADDRESSES_PROVIDER,
BENDDAO_LEND_POOL_LOAN,
BENDDAO_LEND_POOL,
loanIds
loanIds,
to
);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/tokenization/PTokenSApe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {IERC20} from "../../dependencies/openzeppelin/contracts/IERC20.sol";
import {IScaledBalanceToken} from "../../interfaces/IScaledBalanceToken.sol";
import {IncentivizedERC20} from "./base/IncentivizedERC20.sol";
import {DataTypes} from "../libraries/types/DataTypes.sol";
import {ScaledBalanceTokenBaseERC20} from "contracts/protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";
import {ScaledBalanceTokenBaseERC20} from "../../protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";

/**
* @title sApe PToken
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/tokenization/RebasingDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {WadRayMath} from "../libraries/math/WadRayMath.sol";
import {Errors} from "../libraries/helpers/Errors.sol";
import {SafeCast} from "../../dependencies/openzeppelin/contracts/SafeCast.sol";
import {IScaledBalanceToken} from "../../interfaces/IScaledBalanceToken.sol";
import {ScaledBalanceTokenBaseERC20} from "contracts/protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";
import {ScaledBalanceTokenBaseERC20} from "../../protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";

/**
* @title Rebasing Debt Token
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/tokenization/RebasingPToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Errors} from "../libraries/helpers/Errors.sol";
import {IERC20} from "../../dependencies/openzeppelin/contracts/IERC20.sol";
import {GPv2SafeERC20} from "../../dependencies/gnosis/contracts/GPv2SafeERC20.sol";
import {IScaledBalanceToken} from "../../interfaces/IScaledBalanceToken.sol";
import {ScaledBalanceTokenBaseERC20} from "contracts/protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";
import {ScaledBalanceTokenBaseERC20} from "../../protocol/tokenization/base/ScaledBalanceTokenBaseERC20.sol";

/**
* @title Rebasing PToken
Expand Down
32 changes: 21 additions & 11 deletions test/_pool_position_mover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ describe("Pool: rescue tokens", () => {
2
);

await expect(pool.connect(user1.signer).movePositionFromBendDAO([1])).to.be
.reverted;
await expect(
pool.connect(user1.signer).movePositionFromBendDAO([1], user1.address)
).to.be.reverted;
});

it("moving position should succeed for an active loan", async () => {
Expand All @@ -81,7 +82,11 @@ describe("Pool: rescue tokens", () => {
} = testEnv;
await supplyAndValidate(weth, "20000000000", user1, true);

await expect(await pool.connect(user1.signer).movePositionFromBendDAO([1]));
await expect(
await pool
.connect(user1.signer)
.movePositionFromBendDAO([1], user1.address)
);

await expect(await variableDebtWeth.balanceOf(user1.address)).to.be.eq(
"200000"
Expand All @@ -96,7 +101,7 @@ describe("Pool: rescue tokens", () => {
} = testEnv;

await expect(
pool.connect(user1.signer).movePositionFromBendDAO([1])
pool.connect(user1.signer).movePositionFromBendDAO([1], user1.address)
).to.be.revertedWith("Loan not active");
});

Expand All @@ -119,8 +124,9 @@ describe("Pool: rescue tokens", () => {
const agg = await getAggregator(undefined, await bayc.symbol());
await agg.updateLatestAnswer("100000");

await expect(pool.connect(user2.signer).movePositionFromBendDAO([2])).to.be
.reverted;
await expect(
pool.connect(user2.signer).movePositionFromBendDAO([2], user2.address)
).to.be.reverted;

await changePriceAndValidate(bayc, "50");
});
Expand All @@ -141,8 +147,9 @@ describe("Pool: rescue tokens", () => {
2
);

await expect(pool.connect(user2.signer).movePositionFromBendDAO([3])).to.be
.reverted;
await expect(
pool.connect(user2.signer).movePositionFromBendDAO([3], user2.address)
).to.be.reverted;
});

it("moving position should fail if the asset is not supported", async () => {
Expand Down Expand Up @@ -174,8 +181,9 @@ describe("Pool: rescue tokens", () => {
2
);

await expect(pool.connect(user1.signer).movePositionFromBendDAO([4])).to.be
.reverted;
await expect(
pool.connect(user1.signer).movePositionFromBendDAO([4], user1.address)
).to.be.reverted;
});

it("moving multiple positions should succeed for active loans", async () => {
Expand All @@ -196,7 +204,9 @@ describe("Pool: rescue tokens", () => {
);

await expect(
await pool.connect(user1.signer).movePositionFromBendDAO([3, 4])
await pool
.connect(user1.signer)
.movePositionFromBendDAO([3, 4], user1.address)
);

await expect(await variableDebtWeth.balanceOf(user1.address)).to.be.eq(
Expand Down

0 comments on commit 763902c

Please sign in to comment.